@vaadin/component-base 22.0.0-rc1 → 22.0.3
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 +1 -0
- package/index.js +1 -0
- package/package.json +2 -2
- package/src/active-mixin.d.ts +1 -1
- package/src/active-mixin.js +1 -1
- package/src/browser-utils.js +1 -1
- package/src/controller-mixin.d.ts +1 -1
- package/src/controller-mixin.js +1 -1
- package/src/dir-helper.d.ts +1 -1
- package/src/dir-helper.js +1 -1
- package/src/dir-mixin.d.ts +1 -1
- package/src/dir-mixin.js +1 -1
- package/src/disabled-mixin.d.ts +1 -1
- package/src/disabled-mixin.js +1 -1
- package/src/element-mixin.d.ts +1 -1
- package/src/element-mixin.js +2 -2
- package/src/focus-mixin.d.ts +1 -1
- package/src/focus-mixin.js +1 -1
- package/src/keyboard-mixin.d.ts +1 -1
- package/src/keyboard-mixin.js +1 -1
- package/src/slot-controller.d.ts +57 -0
- package/src/slot-controller.js +169 -0
- package/src/slot-mixin.d.ts +1 -1
- package/src/slot-mixin.js +1 -1
- package/src/tabindex-mixin.d.ts +1 -1
- package/src/tabindex-mixin.js +1 -1
- package/src/templates.js +1 -1
- package/src/virtualizer-iron-list-adapter.js +1 -1
package/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export { DisabledMixin } from './src/disabled-mixin.js';
|
|
|
5
5
|
export { ElementMixin } from './src/element-mixin.js';
|
|
6
6
|
export { FocusMixin } from './src/focus-mixin.js';
|
|
7
7
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
8
|
+
export { SlotController } from './src/slot-controller.js';
|
|
8
9
|
export { SlotMixin } from './src/slot-mixin.js';
|
|
9
10
|
export { TabindexMixin } from './src/tabindex-mixin.js';
|
package/index.js
CHANGED
|
@@ -5,5 +5,6 @@ export { DisabledMixin } from './src/disabled-mixin.js';
|
|
|
5
5
|
export { ElementMixin } from './src/element-mixin.js';
|
|
6
6
|
export { FocusMixin } from './src/focus-mixin.js';
|
|
7
7
|
export { KeyboardMixin } from './src/keyboard-mixin.js';
|
|
8
|
+
export { SlotController } from './src/slot-controller.js';
|
|
8
9
|
export { SlotMixin } from './src/slot-mixin.js';
|
|
9
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": "22.0.
|
|
3
|
+
"version": "22.0.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
42
42
|
"sinon": "^9.2.4"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "935ad1ea65a79b0f9ecb10d767689479b36c4e07"
|
|
45
45
|
}
|
package/src/active-mixin.d.ts
CHANGED
package/src/active-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
|
package/src/browser-utils.js
CHANGED
package/src/controller-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
package/src/dir-helper.d.ts
CHANGED
package/src/dir-helper.js
CHANGED
package/src/dir-mixin.d.ts
CHANGED
package/src/dir-mixin.js
CHANGED
package/src/disabled-mixin.d.ts
CHANGED
package/src/disabled-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
package/src/element-mixin.d.ts
CHANGED
package/src/element-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { usageStatistics } from '@vaadin/vaadin-usage-statistics/vaadin-usage-statistics.js';
|
|
@@ -32,7 +32,7 @@ const registered = new Set();
|
|
|
32
32
|
export const ElementMixin = (superClass) =>
|
|
33
33
|
class VaadinElementMixin extends DirMixin(superClass) {
|
|
34
34
|
static get version() {
|
|
35
|
-
return '22.0.
|
|
35
|
+
return '22.0.3';
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** @protected */
|
package/src/focus-mixin.d.ts
CHANGED
package/src/focus-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
package/src/keyboard-mixin.d.ts
CHANGED
package/src/keyboard-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { ReactiveController } from 'lit';
|
|
7
|
+
|
|
8
|
+
export class SlotController extends EventTarget implements ReactiveController {
|
|
9
|
+
constructor(
|
|
10
|
+
host: HTMLElement,
|
|
11
|
+
slotName: string,
|
|
12
|
+
slotFactory?: () => HTMLElement,
|
|
13
|
+
slotInitializer?: (host: HTMLElement, node: HTMLElement) => void
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
hostConnected(): void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The controller host element.
|
|
20
|
+
*/
|
|
21
|
+
host: HTMLElement;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The slotted node managed by the controller.
|
|
25
|
+
*/
|
|
26
|
+
node: HTMLElement;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Return a reference to the node managed by the controller.
|
|
30
|
+
*/
|
|
31
|
+
getSlotChild(): Node;
|
|
32
|
+
|
|
33
|
+
protected initialized: boolean;
|
|
34
|
+
|
|
35
|
+
protected defaultNode: Node;
|
|
36
|
+
|
|
37
|
+
protected defaultId: string;
|
|
38
|
+
|
|
39
|
+
protected attachDefaultNode(): Node | undefined;
|
|
40
|
+
|
|
41
|
+
protected initNode(node: Node): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Override to initialize the newly added custom node.
|
|
45
|
+
*/
|
|
46
|
+
protected initCustomNode(node: Node): void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Override to cleanup slotted node when it's removed.
|
|
50
|
+
*/
|
|
51
|
+
protected teardownNode(node: Node): void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Setup the observer to manage slot content changes.
|
|
55
|
+
*/
|
|
56
|
+
protected observe(): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
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 { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller for providing content to slot element and observing changes.
|
|
10
|
+
*/
|
|
11
|
+
export class SlotController extends EventTarget {
|
|
12
|
+
constructor(host, slotName, slotFactory, slotInitializer) {
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
this.host = host;
|
|
16
|
+
this.slotName = slotName;
|
|
17
|
+
this.slotFactory = slotFactory;
|
|
18
|
+
this.slotInitializer = slotInitializer;
|
|
19
|
+
this.defaultId = SlotController.generateId(slotName, host);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Ensure that every instance has unique ID.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} slotName
|
|
26
|
+
* @param {HTMLElement} host
|
|
27
|
+
* @return {string}
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
static generateId(slotName, host) {
|
|
31
|
+
const prefix = slotName || 'default';
|
|
32
|
+
|
|
33
|
+
// Maintain the unique ID counter for a given prefix.
|
|
34
|
+
this[`${prefix}Id`] = 1 + this[`${prefix}Id`] || 0;
|
|
35
|
+
|
|
36
|
+
return `${prefix}-${host.localName}-${this[`${prefix}Id`]}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
hostConnected() {
|
|
40
|
+
if (!this.initialized) {
|
|
41
|
+
let node = this.getSlotChild();
|
|
42
|
+
|
|
43
|
+
if (!node) {
|
|
44
|
+
node = this.attachDefaultNode();
|
|
45
|
+
} else {
|
|
46
|
+
this.node = node;
|
|
47
|
+
this.initCustomNode(node);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.initNode(node);
|
|
51
|
+
|
|
52
|
+
// TODO: Consider making this behavior opt-in to improve performance.
|
|
53
|
+
this.observe();
|
|
54
|
+
|
|
55
|
+
this.initialized = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create and attach default node using the slot factory.
|
|
61
|
+
* @return {Node | undefined}
|
|
62
|
+
* @protected
|
|
63
|
+
*/
|
|
64
|
+
attachDefaultNode() {
|
|
65
|
+
const { host, slotName, slotFactory } = this;
|
|
66
|
+
|
|
67
|
+
// Check if the node was created previously and if so, reuse it.
|
|
68
|
+
let node = this.defaultNode;
|
|
69
|
+
|
|
70
|
+
// Slot factory is optional, some slots don't have default content.
|
|
71
|
+
if (!node && slotFactory) {
|
|
72
|
+
node = slotFactory(host);
|
|
73
|
+
if (node instanceof Element) {
|
|
74
|
+
if (slotName !== '') {
|
|
75
|
+
node.setAttribute('slot', slotName);
|
|
76
|
+
}
|
|
77
|
+
this.node = node;
|
|
78
|
+
this.defaultNode = node;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (node) {
|
|
83
|
+
host.appendChild(node);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return node;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Return a reference to the node managed by the controller.
|
|
91
|
+
* @return {Node}
|
|
92
|
+
*/
|
|
93
|
+
getSlotChild() {
|
|
94
|
+
const { slotName } = this;
|
|
95
|
+
return Array.from(this.host.childNodes).find((node) => {
|
|
96
|
+
// Either an element (any slot) or a text node (only un-named slot).
|
|
97
|
+
return (
|
|
98
|
+
(node.nodeType === Node.ELEMENT_NODE && node.slot === slotName) ||
|
|
99
|
+
(node.nodeType === Node.TEXT_NODE && node.textContent.trim() && slotName === '')
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {Node} node
|
|
106
|
+
* @protected
|
|
107
|
+
*/
|
|
108
|
+
initNode(node) {
|
|
109
|
+
const { slotInitializer } = this;
|
|
110
|
+
// Don't try to bind `this` to initializer (normally it's arrow function).
|
|
111
|
+
// Instead, pass the host as a first argument to access component's state.
|
|
112
|
+
if (slotInitializer) {
|
|
113
|
+
slotInitializer(this.host, node);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Override to initialize the newly added custom node.
|
|
119
|
+
*
|
|
120
|
+
* @param {Node} _node
|
|
121
|
+
* @protected
|
|
122
|
+
*/
|
|
123
|
+
initCustomNode(_node) {}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Override to teardown slotted node when it's removed.
|
|
127
|
+
*
|
|
128
|
+
* @param {Node} _node
|
|
129
|
+
* @protected
|
|
130
|
+
*/
|
|
131
|
+
teardownNode(_node) {}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Setup the observer to manage slot content changes.
|
|
135
|
+
* @protected
|
|
136
|
+
*/
|
|
137
|
+
observe() {
|
|
138
|
+
const { slotName } = this;
|
|
139
|
+
const selector = slotName === '' ? 'slot:not([name])' : `slot[name=${slotName}]`;
|
|
140
|
+
const slot = this.host.shadowRoot.querySelector(selector);
|
|
141
|
+
|
|
142
|
+
this.__slotObserver = new FlattenedNodesObserver(slot, (info) => {
|
|
143
|
+
// TODO: support default slot with multiple nodes (e.g. confirm-dialog)
|
|
144
|
+
const current = this.node;
|
|
145
|
+
const newNode = info.addedNodes.find((node) => node !== current);
|
|
146
|
+
|
|
147
|
+
if (info.removedNodes.length) {
|
|
148
|
+
info.removedNodes.forEach((node) => {
|
|
149
|
+
this.teardownNode(node);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (newNode) {
|
|
154
|
+
// Custom node is added, remove the current one.
|
|
155
|
+
if (current && current.isConnected) {
|
|
156
|
+
this.host.removeChild(current);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.node = newNode;
|
|
160
|
+
|
|
161
|
+
if (newNode !== this.defaultNode) {
|
|
162
|
+
this.initCustomNode(newNode);
|
|
163
|
+
|
|
164
|
+
this.initNode(newNode);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/slot-mixin.d.ts
CHANGED
package/src/slot-mixin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 Vaadin Ltd.
|
|
3
|
+
* Copyright (c) 2021 - 2022 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
|
package/src/tabindex-mixin.d.ts
CHANGED
package/src/tabindex-mixin.js
CHANGED
package/src/templates.js
CHANGED