Socket
Socket
Sign inDemoInstall

@lion/core

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/core - npm Package Compare versions

Comparing version 0.18.2 to 0.18.3

6

CHANGELOG.md
# Change Log
## 0.18.3
### Patch Changes
- ec03d209: Support scoped templates in SlotMixin
## 0.18.2

@@ -4,0 +10,0 @@

8

docs/guides/how-to/create-a-custom-field.md

@@ -76,5 +76,5 @@ # How To >> Create a custom field ||20

Custom Fields can be created in just a few steps. All you need is an interaction element (like for instance a slider, a listbox or a combobox) and connect it to the [LionField](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/components/inputs/input/overview.md).
Custom Fields can be created in just a few steps. All you need is an interaction element (like for instance a slider, a listbox or a combobox) and connect it to the [LionField](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/components/inputs/input/overview.md).
> In case you want to extend a native element, follow [Extend a native Input](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/how-to/extend-a-native-input.md).
> In case you want to extend a native element, follow [Extend a native Input](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/how-to/extend-a-native-input.md).

@@ -128,3 +128,3 @@ ## A) an interaction element

Now we want to integrate the slider in our form framework to enrich the user interface, get
validation support and all other [benefits of LionField](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/components/inputs/input/overview.md).
validation support and all other [benefits of LionField](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/components/inputs/input/overview.md).
We start by creating a component `<slider-field>` that extends from `LionField`.

@@ -142,3 +142,3 @@ Then we follow the steps below:

equivalent of the `input` event of the platform, but for custom built interaction elements.
You now synchronized [modelValue](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/docs/systems/form/model-value.md), which can be regarded as
You now synchronized [modelValue](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/docs/systems/form/model-value.md), which can be regarded as
the glue to integrate all other functionality like parsing/formatting/serializing, validating,

@@ -145,0 +145,0 @@ tracking interaction states etc.

@@ -14,5 +14,5 @@ # How To >> Extend a native Input ||20

Input fields can be created by extending [LionInput](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/components/inputs/input/overview.md).
Input fields can be created by extending [LionInput](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/components/inputs/input/overview.md).
> In case you want to wrap a custom form element, follow [Create a custom Field](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/how-to/create-a-custom-field.md).
> In case you want to wrap a custom form element, follow [Create a custom Field](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/how-to/create-a-custom-field.md).

@@ -19,0 +19,0 @@ For this tutorial, we create an input that wraps native `input[type=datetime-local]`.

@@ -15,5 +15,5 @@ # Guides

- [Definitions and Terms](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/principles/definitions-and-terms.md)
- [Styling](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/principles/styling.md)
- [Scoped Elements](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/principles/scoped-elements.md)
- [Definitions and Terms](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/principles/definitions-and-terms.md)
- [Styling](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/principles/styling.md)
- [Scoped Elements](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/principles/scoped-elements.md)

@@ -26,4 +26,4 @@ ## Extending Developer

- [Subclasser APIs](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/principles/subclasser-apis.md)
- [Extend documentation](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/blog/extending-documentation)
- [Subclasser APIs](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/principles/subclasser-apis.md)
- [Extend documentation](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/blog/extending-documentation)

@@ -34,3 +34,3 @@ ## How To

- [Get started](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/how-to/get-started.md)
- [Create a custom field](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/how-to/create-a-custom-field.md)
- [Get started](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/how-to/get-started.md)
- [Create a custom field](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/how-to/create-a-custom-field.md)

@@ -22,3 +22,3 @@ # Principles >> Styling ||30

readable by screen readers, but invisible for end users.
- When an html table is used, we allow [subclassers](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/guides/principles/subclasser-apis.md) to override the display property (`table-cell`) to `flex`. By putting the proper accessible roles (`role="cell"`) in the markup, we guarantee our markup stays accessible.
- When an html table is used, we allow [subclassers](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/guides/principles/subclasser-apis.md) to override the display property (`table-cell`) to `flex`. By putting the proper accessible roles (`role="cell"`) in the markup, we guarantee our markup stays accessible.

@@ -25,0 +25,0 @@ Although Lion components try to stay as unbiased as possible with regard to styling, defaults will be needed. In these cases we try to follow the platform as much as possible. If the platform doesn't provide defaults, the largest common denominator across existing UI frameworks is taken as a lead.

@@ -18,3 +18,3 @@ # Systems >> Core >> Overview ||10

- [function to deduplicate mixins (dedupeMixin)](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/docs/systems/core/#deduping-of-mixins)
- [function to deduplicate mixins (dedupeMixin)](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/docs/systems/core/#deduping-of-mixins)
- Mixin to handle disabled (DisabledMixin)

@@ -21,0 +21,0 @@ - Mixin to handle disabled AND tabIndex (DisabledWithTabIndexMixin)

{
"name": "@lion/core",
"version": "0.18.2",
"version": "0.18.3",
"description": "Core functionality that is shared across all Lion Web Components",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -18,3 +18,3 @@ # Systems >> Core >> Overview ||10

- [function to deduplicate mixins (dedupeMixin)](https://github.com/ing-bank/lion/blob/e03f8d2cc31563d46f910074d562ad68a2e41dfd/docs/docs/systems/core/#deduping-of-mixins)
- [function to deduplicate mixins (dedupeMixin)](https://github.com/ing-bank/lion/blob/519759cb09777d3b2b60480a5ef85860cba1310a/docs/docs/systems/core/#deduping-of-mixins)
- Mixin to handle disabled (DisabledMixin)

@@ -21,0 +21,0 @@ - Mixin to handle disabled AND tabIndex (DisabledWithTabIndexMixin)

@@ -6,1 +6,2 @@ export type SlotMixin = typeof import("../types/SlotMixinTypes").SlotMixinImplementation;

};
export type LitElement = import("lit").LitElement;
/* eslint-disable class-methods-use-this */
import { dedupeMixin } from '@open-wc/dedupe-mixin';
import { render } from 'lit';
import { isTemplateResult } from 'lit/directive-helpers.js';

@@ -7,2 +9,3 @@ /**

* @typedef {import('../types/SlotMixinTypes').SlotsMap} SlotsMap
* @typedef {import('../index').LitElement} LitElement
*/

@@ -12,7 +15,6 @@

* @type {SlotMixin}
* @param {import('@open-wc/dedupe-mixin').Constructor<HTMLElement>} superclass
* @param {import('@open-wc/dedupe-mixin').Constructor<LitElement>} superclass
*/
const SlotMixinImplementation = superclass =>
// eslint-disable-next-line no-unused-vars, no-shadow
class extends superclass {
class SlotMixin extends superclass {
/**

@@ -32,7 +34,3 @@ * @return {SlotsMap}

connectedCallback() {
// @ts-ignore checking this in case we pass LitElement, found no good way to type this...
if (super.connectedCallback) {
// @ts-ignore checking this in case we pass LitElement, found no good way to type this...
super.connectedCallback();
}
super.connectedCallback();
this._connectSlotMixin();

@@ -42,2 +40,12 @@ }

/**
* @private
* @param {import('@lion/core').TemplateResult} template
*/
__renderAsNodes(template) {
const tempRenderTarget = document.createElement('div');
render(template, tempRenderTarget, this.renderOptions);
return Array.from(tempRenderTarget.childNodes);
}
/**
* @protected

@@ -48,11 +56,23 @@ */

Object.keys(this.slots).forEach(slotName => {
if (!this.querySelector(`[slot=${slotName}]`)) {
const slotFactory = this.slots[slotName];
const slotContent = slotFactory();
// ignore non-elements to enable conditional slots
if (slotContent instanceof Element) {
slotContent.setAttribute('slot', slotName);
this.appendChild(slotContent);
if (!Array.from(this.children).find(el => el.slot === slotName)) {
const slotContent = this.slots[slotName]();
/** @type {Node[]} */
let nodes = [];
if (isTemplateResult(slotContent)) {
nodes = this.__renderAsNodes(slotContent);
} else if (!Array.isArray(slotContent)) {
nodes = [/** @type {Node} */ (slotContent)];
}
nodes.forEach(node => {
if (!(node instanceof Node)) {
return;
}
if (node instanceof Element) {
node.setAttribute('slot', slotName);
}
this.appendChild(node);
this.__privateSlots.add(slotName);
}
});
}

@@ -59,0 +79,0 @@ });

@@ -0,3 +1,5 @@

import sinon from 'sinon';
import { defineCE, expect, fixture } from '@open-wc/testing';
import { SlotMixin } from '../src/SlotMixin.js';
import { LitElement, ScopedElementsMixin, html } from '../index.js';

@@ -7,3 +9,3 @@ describe('SlotMixin', () => {

const tag = defineCE(
class extends SlotMixin(HTMLElement) {
class extends SlotMixin(LitElement) {
get slots() {

@@ -23,3 +25,3 @@ return {

const tag = defineCE(
class extends SlotMixin(HTMLElement) {
class extends SlotMixin(LitElement) {
get slots() {

@@ -38,5 +40,24 @@ return {

it('does add when user provided slots are not direct children', async () => {
const tag = defineCE(
class extends SlotMixin(LitElement) {
get slots() {
return {
...super.slots,
content: () => document.createElement('div'),
};
}
},
);
const el = await fixture(`<${tag}><p><span slot="content">user-content</span></p></${tag}>`);
const slot = /** @type HTMLDivElement */ (
Array.from(el.children).find(elm => elm.slot === 'content')
);
expect(slot.tagName).to.equal('DIV');
expect(slot.innerText).to.equal('');
});
it('supports complex dom trees as element', async () => {
const tag = defineCE(
class extends SlotMixin(HTMLElement) {
class extends SlotMixin(LitElement) {
constructor() {

@@ -73,3 +94,3 @@ super();

const tag = defineCE(
class extends SlotMixin(HTMLElement) {
class extends SlotMixin(LitElement) {
get slots() {

@@ -99,3 +120,3 @@ return {

let renderSlot = true;
class SlotPrivateText extends SlotMixin(HTMLElement) {
class SlotPrivateText extends SlotMixin(LitElement) {
get slots() {

@@ -124,2 +145,69 @@ return {

});
it('supports templates', async () => {
const tag = defineCE(
class extends SlotMixin(LitElement) {
get slots() {
return {
...super.slots,
template: () => html`<span>text</span>`,
};
}
render() {
return html`<slot name="template"></slot>`;
}
},
);
const el = await fixture(`<${tag}><${tag}>`);
const slot = /** @type HTMLSpanElement */ (
Array.from(el.children).find(elm => elm.slot === 'template')
);
expect(slot.slot).to.equal('template');
expect(slot.tagName).to.equal('SPAN');
});
it('supports scoped elements', async () => {
const scopedSpy = sinon.spy();
class ScopedEl extends LitElement {
connectedCallback() {
super.connectedCallback();
scopedSpy();
}
}
const tag = defineCE(
class extends ScopedElementsMixin(SlotMixin(LitElement)) {
static get scopedElements() {
return {
// @ts-expect-error
...super.scopedElements,
'scoped-el': ScopedEl,
};
}
get slots() {
return {
...super.slots,
template: () => html`<scoped-el></scoped-el>`,
};
}
connectedCallback() {
super.connectedCallback();
// Not rendered to shadowRoot, notScopedSpy should not be called
const notScoped = document.createElement('not-scoped');
this.appendChild(notScoped);
}
render() {
return html`<slot name="template"></slot>`;
}
},
);
await fixture(`<${tag}><${tag}>`);
expect(scopedSpy).to.have.been.called;
});
});
import { Constructor } from '@open-wc/dedupe-mixin';
import { TemplateResult, LitElement } from '../index.js';
declare function slotFunction(): HTMLElement | undefined;
declare function slotFunction(): HTMLElement | Node[] | TemplateResult | undefined;

@@ -51,3 +52,3 @@ export type SlotsMap = {

*/
export declare function SlotMixinImplementation<T extends Constructor<HTMLElement>>(
export declare function SlotMixinImplementation<T extends Constructor<LitElement>>(
superclass: T,

@@ -57,4 +58,4 @@ ): T &

Pick<typeof SlotHost, keyof typeof SlotHost> &
Pick<typeof HTMLElement, keyof typeof HTMLElement>;
Pick<typeof LitElement, keyof typeof LitElement>;
export type SlotMixin = typeof SlotMixinImplementation;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc