@vaadin/component-base 24.0.0-alpha2 → 24.0.0-alpha3
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/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +2 -2
- package/src/element-mixin.js +1 -1
- package/src/slot-controller.d.ts +7 -4
- package/src/slot-controller.js +14 -10
- package/src/slot-mixin.d.ts +0 -18
- package/src/slot-mixin.js +0 -60
package/index.d.ts
CHANGED
|
@@ -8,5 +8,4 @@ export { FocusTrapController } from './src/focus-trap-controller.js';
|
|
|
8
8
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
9
9
|
export { ResizeMixin } from './src/resize-mixin.js';
|
|
10
10
|
export { SlotController } from './src/slot-controller.js';
|
|
11
|
-
export { SlotMixin } from './src/slot-mixin.js';
|
|
12
11
|
export { TabindexMixin } from './src/tabindex-mixin.js';
|
package/index.js
CHANGED
|
@@ -7,5 +7,4 @@ export { FocusMixin } from './src/focus-mixin.js';
|
|
|
7
7
|
export { FocusTrapController } from './src/focus-trap-controller.js';
|
|
8
8
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
9
9
|
export { SlotController } from './src/slot-controller.js';
|
|
10
|
-
export { SlotMixin } from './src/slot-mixin.js';
|
|
11
10
|
export { TabindexMixin } from './src/tabindex-mixin.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "24.0.0-
|
|
3
|
+
"version": "24.0.0-alpha3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
43
43
|
"sinon": "^13.0.2"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "7a013a3c5a56abd61dd4f7773c6ec77c3541bdf2"
|
|
46
46
|
}
|
package/src/element-mixin.js
CHANGED
package/src/slot-controller.d.ts
CHANGED
|
@@ -25,9 +25,12 @@ export class SlotController extends EventTarget implements ReactiveController {
|
|
|
25
25
|
constructor(
|
|
26
26
|
host: HTMLElement,
|
|
27
27
|
slotName: string,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
tagName?: string,
|
|
29
|
+
config?: {
|
|
30
|
+
observe?: boolean;
|
|
31
|
+
useUniqueId?: boolean;
|
|
32
|
+
initializer?(host: HTMLElement, node: HTMLElement): void;
|
|
33
|
+
},
|
|
31
34
|
);
|
|
32
35
|
|
|
33
36
|
hostConnected(): void;
|
|
@@ -54,5 +57,5 @@ export class SlotController extends EventTarget implements ReactiveController {
|
|
|
54
57
|
/**
|
|
55
58
|
* Setup the observer to manage slot content changes.
|
|
56
59
|
*/
|
|
57
|
-
protected
|
|
60
|
+
protected observeSlot(): void;
|
|
58
61
|
}
|
package/src/slot-controller.js
CHANGED
|
@@ -23,13 +23,16 @@ export class SlotController extends EventTarget {
|
|
|
23
23
|
return `${prefix}-${host.localName}-${generateUniqueId()}`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
constructor(host, slotName,
|
|
26
|
+
constructor(host, slotName, tagName, config = {}) {
|
|
27
27
|
super();
|
|
28
28
|
|
|
29
|
+
const { initializer, observe, useUniqueId } = config;
|
|
30
|
+
|
|
29
31
|
this.host = host;
|
|
30
32
|
this.slotName = slotName;
|
|
31
|
-
this.
|
|
32
|
-
this.
|
|
33
|
+
this.tagName = tagName;
|
|
34
|
+
this.observe = typeof observe === 'boolean' ? observe : true;
|
|
35
|
+
this.slotInitializer = initializer;
|
|
33
36
|
|
|
34
37
|
// Only generate the default ID if requested by the controller.
|
|
35
38
|
if (useUniqueId) {
|
|
@@ -50,8 +53,9 @@ export class SlotController extends EventTarget {
|
|
|
50
53
|
|
|
51
54
|
this.initNode(node);
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (this.observe) {
|
|
57
|
+
this.observeSlot();
|
|
58
|
+
}
|
|
55
59
|
|
|
56
60
|
this.initialized = true;
|
|
57
61
|
}
|
|
@@ -63,14 +67,14 @@ export class SlotController extends EventTarget {
|
|
|
63
67
|
* @protected
|
|
64
68
|
*/
|
|
65
69
|
attachDefaultNode() {
|
|
66
|
-
const { host, slotName,
|
|
70
|
+
const { host, slotName, tagName } = this;
|
|
67
71
|
|
|
68
72
|
// Check if the node was created previously and if so, reuse it.
|
|
69
73
|
let node = this.defaultNode;
|
|
70
74
|
|
|
71
75
|
// Slot factory is optional, some slots don't have default content.
|
|
72
|
-
if (!node &&
|
|
73
|
-
node =
|
|
76
|
+
if (!node && tagName) {
|
|
77
|
+
node = document.createElement(tagName);
|
|
74
78
|
if (node instanceof Element) {
|
|
75
79
|
if (slotName !== '') {
|
|
76
80
|
node.setAttribute('slot', slotName);
|
|
@@ -111,7 +115,7 @@ export class SlotController extends EventTarget {
|
|
|
111
115
|
// Don't try to bind `this` to initializer (normally it's arrow function).
|
|
112
116
|
// Instead, pass the host as a first argument to access component's state.
|
|
113
117
|
if (slotInitializer) {
|
|
114
|
-
slotInitializer(this.host
|
|
118
|
+
slotInitializer(node, this.host);
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
@@ -135,7 +139,7 @@ export class SlotController extends EventTarget {
|
|
|
135
139
|
* Setup the observer to manage slot content changes.
|
|
136
140
|
* @protected
|
|
137
141
|
*/
|
|
138
|
-
|
|
142
|
+
observeSlot() {
|
|
139
143
|
const { slotName } = this;
|
|
140
144
|
const selector = slotName === '' ? 'slot:not([name])' : `slot[name=${slotName}]`;
|
|
141
145
|
const slot = this.host.shadowRoot.querySelector(selector);
|
package/src/slot-mixin.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin to provide content for named slots defined by component.
|
|
10
|
-
*/
|
|
11
|
-
export declare function SlotMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<SlotMixinClass> & T;
|
|
12
|
-
|
|
13
|
-
export declare class SlotMixinClass {
|
|
14
|
-
/**
|
|
15
|
-
* List of named slots to initialize.
|
|
16
|
-
*/
|
|
17
|
-
protected readonly slots: Record<string, () => HTMLElement>;
|
|
18
|
-
}
|
package/src/slot-mixin.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
|
-
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
-
*/
|
|
6
|
-
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A mixin to provide content for named slots defined by component.
|
|
10
|
-
*
|
|
11
|
-
* @polymerMixin
|
|
12
|
-
*/
|
|
13
|
-
export const SlotMixin = dedupingMixin(
|
|
14
|
-
(superclass) =>
|
|
15
|
-
class SlotMixinClass extends superclass {
|
|
16
|
-
/**
|
|
17
|
-
* List of named slots to initialize.
|
|
18
|
-
* @protected
|
|
19
|
-
*/
|
|
20
|
-
get slots() {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** @protected */
|
|
25
|
-
ready() {
|
|
26
|
-
super.ready();
|
|
27
|
-
this._connectSlotMixin();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** @private */
|
|
31
|
-
_connectSlotMixin() {
|
|
32
|
-
Object.keys(this.slots).forEach((slotName) => {
|
|
33
|
-
// Ignore labels of nested components, if any
|
|
34
|
-
const hasContent = this._getDirectSlotChild(slotName) !== undefined;
|
|
35
|
-
|
|
36
|
-
if (!hasContent) {
|
|
37
|
-
const slotFactory = this.slots[slotName];
|
|
38
|
-
const slotContent = slotFactory();
|
|
39
|
-
if (slotContent instanceof Element) {
|
|
40
|
-
if (slotName !== '') {
|
|
41
|
-
slotContent.setAttribute('slot', slotName);
|
|
42
|
-
}
|
|
43
|
-
this.appendChild(slotContent);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** @protected */
|
|
50
|
-
_getDirectSlotChild(slotName) {
|
|
51
|
-
return Array.from(this.childNodes).find((node) => {
|
|
52
|
-
// Either an element (any slot) or a text node (only un-named slot).
|
|
53
|
-
return (
|
|
54
|
-
(node.nodeType === Node.ELEMENT_NODE && node.slot === slotName) ||
|
|
55
|
-
(node.nodeType === Node.TEXT_NODE && node.textContent.trim() && slotName === '')
|
|
56
|
-
);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
);
|