@vaadin/component-base 25.4.0-alpha5 → 25.4.0-alpha6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "25.4.0-
|
|
3
|
+
"version": "25.4.0-alpha6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@polymer/polymer": "^3.0.0",
|
|
42
|
-
"@vaadin/chai-plugins": "25.4.0-
|
|
43
|
-
"@vaadin/test-runner-commands": "25.4.0-
|
|
42
|
+
"@vaadin/chai-plugins": "25.4.0-alpha6",
|
|
43
|
+
"@vaadin/test-runner-commands": "25.4.0-alpha6",
|
|
44
44
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
45
45
|
"sinon": "^22.0.0"
|
|
46
46
|
},
|
|
47
47
|
"customElements": "custom-elements.json",
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4ead7de23a27c47e5ef4cb172481f8c54e86691a"
|
|
49
49
|
}
|
package/src/define.js
CHANGED
|
@@ -13,7 +13,7 @@ function dashToCamelCase(dash) {
|
|
|
13
13
|
|
|
14
14
|
const experimentalMap = {};
|
|
15
15
|
|
|
16
|
-
export function defineCustomElement(CustomElement, version = '25.4.0-
|
|
16
|
+
export function defineCustomElement(CustomElement, version = '25.4.0-alpha6') {
|
|
17
17
|
Object.defineProperty(CustomElement, 'version', {
|
|
18
18
|
get() {
|
|
19
19
|
return version;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 - 2026 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import type { DirectiveResult } from 'lit/directive.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A directive that renders the content of a `<slot>` into the light DOM of
|
|
10
|
+
* the host element. The content must have the `slot` attribute of that slot.
|
|
11
|
+
*
|
|
12
|
+
* Use it as an element expression of the `<slot>` in the template returned by
|
|
13
|
+
* `render()`, e.g. `<slot name="form" ${slotContent(this._renderForm())}></slot>`.
|
|
14
|
+
*
|
|
15
|
+
* On the first render, the directive appends a comment marker to the host and
|
|
16
|
+
* renders the content before it. Children that the host already has stay before
|
|
17
|
+
* the content, and children added later go after the marker, so rendering again
|
|
18
|
+
* does not move or remove them.
|
|
19
|
+
*
|
|
20
|
+
* Always render the directive: pass `nothing` as content instead of removing it,
|
|
21
|
+
* which would leave the content in the light DOM. On the first render, the content
|
|
22
|
+
* is connected before the shadow DOM of the host.
|
|
23
|
+
*/
|
|
24
|
+
export declare function slotContent(content: unknown): DirectiveResult;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2026 - 2026 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { noChange, render } from 'lit';
|
|
7
|
+
import { Directive, directive, PartType } from 'lit/directive.js';
|
|
8
|
+
|
|
9
|
+
class SlotContentDirective extends Directive {
|
|
10
|
+
// Comment node in the light DOM of the host that the content is rendered before.
|
|
11
|
+
#marker = null;
|
|
12
|
+
|
|
13
|
+
constructor(partInfo) {
|
|
14
|
+
super(partInfo);
|
|
15
|
+
if (partInfo.type !== PartType.ELEMENT) {
|
|
16
|
+
throw new Error('`slotContent()` can only be used as an element expression of a `<slot>`.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
render(_content) {
|
|
21
|
+
return noChange;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
update(part, [content]) {
|
|
25
|
+
if (part.element.localName !== 'slot') {
|
|
26
|
+
throw new Error('`slotContent()` can only be used as an element expression of a `<slot>`.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const host = part.options?.host;
|
|
30
|
+
if (!host) {
|
|
31
|
+
throw new Error('`slotContent()` requires the template to be rendered with the `host` option.');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Create a new marker when it was removed, e.g. when the host light DOM was cleared
|
|
35
|
+
if (this.#marker?.parentNode !== host) {
|
|
36
|
+
this.#marker = document.createComment('');
|
|
37
|
+
host.appendChild(this.#marker);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
render(content, host, { host, renderBefore: this.#marker });
|
|
41
|
+
|
|
42
|
+
return noChange;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A directive that renders the content of a `<slot>` into the light DOM of
|
|
48
|
+
* the host element. The content must have the `slot` attribute of that slot.
|
|
49
|
+
*
|
|
50
|
+
* Use it as an element expression of the `<slot>` in the template returned by
|
|
51
|
+
* `render()`, e.g. `<slot name="form" ${slotContent(this._renderForm())}></slot>`.
|
|
52
|
+
*
|
|
53
|
+
* On the first render, the directive appends a comment marker to the host and
|
|
54
|
+
* renders the content before it. Children that the host already has stay before
|
|
55
|
+
* the content, and children added later go after the marker, so rendering again
|
|
56
|
+
* does not move or remove them.
|
|
57
|
+
*
|
|
58
|
+
* Always render the directive: pass `nothing` as content instead of removing it,
|
|
59
|
+
* which would leave the content in the light DOM. On the first render, the content
|
|
60
|
+
* is connected before the shadow DOM of the host.
|
|
61
|
+
*/
|
|
62
|
+
export const slotContent = directive(SlotContentDirective);
|