@vaadin/component-base 23.2.14 → 23.2.16
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/custom_typings/vaadin-usage-statistics.d.ts +2 -2
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +3 -3
- package/src/a11y-announcer.d.ts +1 -1
- package/src/a11y-announcer.js +1 -1
- package/src/active-mixin.d.ts +1 -1
- package/src/active-mixin.js +1 -1
- package/src/async.d.ts +3 -0
- package/src/async.js +2 -1
- package/src/browser-utils.js +7 -7
- package/src/controller-mixin.d.ts +1 -1
- package/src/controller-mixin.js +1 -1
- package/src/debounce.js +2 -2
- package/src/delegate-focus-mixin.d.ts +48 -0
- package/src/delegate-focus-mixin.js +228 -0
- package/src/delegate-state-mixin.d.ts +20 -0
- package/src/delegate-state-mixin.js +125 -0
- package/src/dir-mixin.d.ts +2 -4
- package/src/dir-mixin.js +17 -39
- package/src/dir-utils.d.ts +19 -0
- package/src/dir-utils.js +36 -0
- package/src/disabled-mixin.d.ts +1 -1
- package/src/disabled-mixin.js +1 -1
- package/src/dom-utils.d.ts +6 -1
- package/src/dom-utils.js +11 -1
- package/src/element-mixin.d.ts +1 -1
- package/src/element-mixin.js +11 -5
- package/src/focus-mixin.d.ts +1 -1
- package/src/focus-mixin.js +2 -2
- package/src/focus-trap-controller.d.ts +1 -1
- package/src/focus-trap-controller.js +22 -22
- package/src/focus-utils.d.ts +1 -1
- package/src/focus-utils.js +57 -57
- package/src/gestures.d.ts +6 -12
- package/src/gestures.js +6 -4
- package/src/iron-list-core.js +22 -44
- package/src/keyboard-direction-mixin.d.ts +41 -0
- package/src/keyboard-direction-mixin.js +192 -0
- package/src/keyboard-mixin.d.ts +1 -1
- package/src/keyboard-mixin.js +1 -1
- package/src/list-mixin.d.ts +57 -0
- package/src/list-mixin.js +354 -0
- package/src/media-query-controller.d.ts +1 -1
- package/src/media-query-controller.js +1 -1
- package/src/overflow-controller.d.ts +1 -1
- package/src/overflow-controller.js +3 -3
- package/src/overlay-class-mixin.d.ts +33 -0
- package/src/overlay-class-mixin.js +79 -0
- package/src/polylit-mixin.d.ts +3 -3
- package/src/polylit-mixin.js +9 -4
- package/src/resize-mixin.d.ts +1 -1
- package/src/resize-mixin.js +11 -21
- package/src/slot-child-observe-controller.d.ts +28 -0
- package/src/slot-child-observe-controller.js +176 -0
- package/src/slot-controller.d.ts +33 -5
- package/src/slot-controller.js +103 -40
- package/src/tabindex-mixin.d.ts +1 -1
- package/src/tabindex-mixin.js +1 -1
- package/src/templates.js +1 -1
- package/src/tooltip-controller.d.ts +86 -0
- package/src/tooltip-controller.js +130 -0
- package/src/unique-id-utils.d.ts +1 -1
- package/src/unique-id-utils.js +1 -1
- package/src/virtualizer-iron-list-adapter.js +56 -2
- package/src/virtualizer.js +18 -18
- package/src/dir-helper.d.ts +0 -42
- package/src/dir-helper.js +0 -93
- package/src/slot-mixin.d.ts +0 -18
- package/src/slot-mixin.js +0 -60
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2022 - 2023 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { SlotController } from './slot-controller.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A controller that manages the slotted tooltip element.
|
|
10
|
+
*/
|
|
11
|
+
export class TooltipController extends SlotController {
|
|
12
|
+
constructor(host) {
|
|
13
|
+
// Do not provide slot factory to create tooltip lazily.
|
|
14
|
+
super(host, 'tooltip');
|
|
15
|
+
|
|
16
|
+
this.setTarget(host);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Override to initialize the newly added custom tooltip.
|
|
21
|
+
*
|
|
22
|
+
* @param {Node} tooltipNode
|
|
23
|
+
* @protected
|
|
24
|
+
* @override
|
|
25
|
+
*/
|
|
26
|
+
initCustomNode(tooltipNode) {
|
|
27
|
+
tooltipNode.target = this.target;
|
|
28
|
+
|
|
29
|
+
if (this.context !== undefined) {
|
|
30
|
+
tooltipNode.context = this.context;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (this.manual !== undefined) {
|
|
34
|
+
tooltipNode.manual = this.manual;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (this.opened !== undefined) {
|
|
38
|
+
tooltipNode.opened = this.opened;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (this.position !== undefined) {
|
|
42
|
+
tooltipNode._position = this.position;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.shouldShow !== undefined) {
|
|
46
|
+
tooltipNode.shouldShow = this.shouldShow;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Set a context object to be used by generator.
|
|
52
|
+
* @param {object} context
|
|
53
|
+
*/
|
|
54
|
+
setContext(context) {
|
|
55
|
+
this.context = context;
|
|
56
|
+
|
|
57
|
+
const tooltipNode = this.node;
|
|
58
|
+
if (tooltipNode) {
|
|
59
|
+
tooltipNode.context = context;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Toggle manual state on the slotted tooltip.
|
|
65
|
+
* @param {boolean} manual
|
|
66
|
+
*/
|
|
67
|
+
setManual(manual) {
|
|
68
|
+
this.manual = manual;
|
|
69
|
+
|
|
70
|
+
const tooltipNode = this.node;
|
|
71
|
+
if (tooltipNode) {
|
|
72
|
+
tooltipNode.manual = manual;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Toggle opened state on the slotted tooltip.
|
|
78
|
+
* @param {boolean} opened
|
|
79
|
+
*/
|
|
80
|
+
setOpened(opened) {
|
|
81
|
+
this.opened = opened;
|
|
82
|
+
|
|
83
|
+
const tooltipNode = this.node;
|
|
84
|
+
if (tooltipNode) {
|
|
85
|
+
tooltipNode.opened = opened;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set default position for the slotted tooltip.
|
|
91
|
+
* This can be overridden by setting the position
|
|
92
|
+
* using corresponding property or attribute.
|
|
93
|
+
* @param {string} position
|
|
94
|
+
*/
|
|
95
|
+
setPosition(position) {
|
|
96
|
+
this.position = position;
|
|
97
|
+
|
|
98
|
+
const tooltipNode = this.node;
|
|
99
|
+
if (tooltipNode) {
|
|
100
|
+
tooltipNode._position = position;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Set function used to detect whether to show
|
|
106
|
+
* the tooltip based on a condition.
|
|
107
|
+
* @param {Function} shouldShow
|
|
108
|
+
*/
|
|
109
|
+
setShouldShow(shouldShow) {
|
|
110
|
+
this.shouldShow = shouldShow;
|
|
111
|
+
|
|
112
|
+
const tooltipNode = this.node;
|
|
113
|
+
if (tooltipNode) {
|
|
114
|
+
tooltipNode.shouldShow = shouldShow;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Set an HTML element to attach the tooltip to.
|
|
120
|
+
* @param {HTMLElement} target
|
|
121
|
+
*/
|
|
122
|
+
setTarget(target) {
|
|
123
|
+
this.target = target;
|
|
124
|
+
|
|
125
|
+
const tooltipNode = this.node;
|
|
126
|
+
if (tooltipNode) {
|
|
127
|
+
tooltipNode.target = target;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/unique-id-utils.d.ts
CHANGED
package/src/unique-id-utils.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright (c) 2021 -
|
|
3
|
+
* Copyright (c) 2021 - 2023 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
/* eslint-disable @typescript-eslint/member-ordering */
|
|
7
|
+
// https://github.com/vaadin/eslint-config-vaadin/issues/33
|
|
6
8
|
import { animationFrame, timeOut } from './async.js';
|
|
7
9
|
import { isSafari } from './browser-utils.js';
|
|
8
10
|
import { Debouncer, flush } from './debounce.js';
|
|
@@ -141,6 +143,56 @@ export class IronListAdapter {
|
|
|
141
143
|
});
|
|
142
144
|
}
|
|
143
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Updates the height for a given set of items.
|
|
148
|
+
*
|
|
149
|
+
* @param {!Array<number>=} itemSet
|
|
150
|
+
*/
|
|
151
|
+
_updateMetrics(itemSet) {
|
|
152
|
+
// Make sure we distributed all the physical items
|
|
153
|
+
// so we can measure them.
|
|
154
|
+
flush();
|
|
155
|
+
|
|
156
|
+
let newPhysicalSize = 0;
|
|
157
|
+
let oldPhysicalSize = 0;
|
|
158
|
+
const prevAvgCount = this._physicalAverageCount;
|
|
159
|
+
const prevPhysicalAvg = this._physicalAverage;
|
|
160
|
+
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
162
|
+
this._iterateItems((pidx, vidx) => {
|
|
163
|
+
oldPhysicalSize += this._physicalSizes[pidx];
|
|
164
|
+
this._physicalSizes[pidx] = Math.ceil(this.__getBorderBoxHeight(this._physicalItems[pidx]));
|
|
165
|
+
newPhysicalSize += this._physicalSizes[pidx];
|
|
166
|
+
this._physicalAverageCount += this._physicalSizes[pidx] ? 1 : 0;
|
|
167
|
+
}, itemSet);
|
|
168
|
+
|
|
169
|
+
this._physicalSize = this._physicalSize + newPhysicalSize - oldPhysicalSize;
|
|
170
|
+
|
|
171
|
+
// Update the average if it measured something.
|
|
172
|
+
if (this._physicalAverageCount !== prevAvgCount) {
|
|
173
|
+
this._physicalAverage = Math.round(
|
|
174
|
+
(prevPhysicalAvg * prevAvgCount + newPhysicalSize) / this._physicalAverageCount,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
__getBorderBoxHeight(el) {
|
|
180
|
+
const style = getComputedStyle(el);
|
|
181
|
+
|
|
182
|
+
const itemHeight = parseFloat(style.height) || 0;
|
|
183
|
+
|
|
184
|
+
if (style.boxSizing === 'border-box') {
|
|
185
|
+
return itemHeight;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const paddingBottom = parseFloat(style.paddingBottom) || 0;
|
|
189
|
+
const paddingTop = parseFloat(style.paddingTop) || 0;
|
|
190
|
+
const borderBottomWidth = parseFloat(style.borderBottomWidth) || 0;
|
|
191
|
+
const borderTopWidth = parseFloat(style.borderTopWidth) || 0;
|
|
192
|
+
|
|
193
|
+
return itemHeight + paddingBottom + paddingTop + borderBottomWidth + borderTopWidth;
|
|
194
|
+
}
|
|
195
|
+
|
|
144
196
|
__updateElement(el, index, forceSameIndexUpdates) {
|
|
145
197
|
// Clean up temporary placeholder sizing
|
|
146
198
|
if (el.style.paddingTop) {
|
|
@@ -430,7 +482,9 @@ export class IronListAdapter {
|
|
|
430
482
|
deltaY *= this._scrollPageHeight;
|
|
431
483
|
}
|
|
432
484
|
|
|
433
|
-
|
|
485
|
+
if (!this._deltaYAcc) {
|
|
486
|
+
this._deltaYAcc = 0;
|
|
487
|
+
}
|
|
434
488
|
|
|
435
489
|
if (this._wheelAnimationFrame) {
|
|
436
490
|
// Accumulate wheel delta while a frame is being processed
|
package/src/virtualizer.js
CHANGED
|
@@ -15,6 +15,24 @@ export class Virtualizer {
|
|
|
15
15
|
this.__adapter = new IronListAdapter(config);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Gets the index of the first visible item in the viewport.
|
|
20
|
+
*
|
|
21
|
+
* @return {number}
|
|
22
|
+
*/
|
|
23
|
+
get firstVisibleIndex() {
|
|
24
|
+
return this.__adapter.adjustedFirstVisibleIndex;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Gets the index of the last visible item in the viewport.
|
|
29
|
+
*
|
|
30
|
+
* @return {number}
|
|
31
|
+
*/
|
|
32
|
+
get lastVisibleIndex() {
|
|
33
|
+
return this.__adapter.adjustedLastVisibleIndex;
|
|
34
|
+
}
|
|
35
|
+
|
|
18
36
|
/**
|
|
19
37
|
* The size of the virtualizer
|
|
20
38
|
* @return {number | undefined} The size of the virtualizer
|
|
@@ -62,22 +80,4 @@ export class Virtualizer {
|
|
|
62
80
|
flush() {
|
|
63
81
|
this.__adapter.flush();
|
|
64
82
|
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Gets the index of the first visible item in the viewport.
|
|
68
|
-
*
|
|
69
|
-
* @return {number}
|
|
70
|
-
*/
|
|
71
|
-
get firstVisibleIndex() {
|
|
72
|
-
return this.__adapter.adjustedFirstVisibleIndex;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Gets the index of the last visible item in the viewport.
|
|
77
|
-
*
|
|
78
|
-
* @return {number}
|
|
79
|
-
*/
|
|
80
|
-
get lastVisibleIndex() {
|
|
81
|
-
return this.__adapter.adjustedLastVisibleIndex;
|
|
82
|
-
}
|
|
83
83
|
}
|
package/src/dir-helper.d.ts
DELETED
|
@@ -1,42 +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
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Helper that provides a set of functions for RTL.
|
|
9
|
-
*/
|
|
10
|
-
declare class DirHelper {
|
|
11
|
-
/**
|
|
12
|
-
* Get the scroll type in the current browser view.
|
|
13
|
-
*
|
|
14
|
-
* @returns the scroll type. Possible values are `default|reverse|negative`
|
|
15
|
-
*/
|
|
16
|
-
static detectScrollType(): string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get the scrollLeft value of the element relative to the direction
|
|
20
|
-
*
|
|
21
|
-
* @param scrollType type of the scroll detected with `detectScrollType`
|
|
22
|
-
* @param direction current direction of the element
|
|
23
|
-
* @returns the scrollLeft value.
|
|
24
|
-
*/
|
|
25
|
-
static getNormalizedScrollLeft(scrollType: string, direction: string, element: Element | null): number;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Set the scrollLeft value of the element relative to the direction
|
|
29
|
-
*
|
|
30
|
-
* @param scrollType type of the scroll detected with `detectScrollType`
|
|
31
|
-
* @param direction current direction of the element
|
|
32
|
-
* @param scrollLeft the scrollLeft value to be set
|
|
33
|
-
*/
|
|
34
|
-
static setNormalizedScrollLeft(
|
|
35
|
-
scrollType: string,
|
|
36
|
-
direction: string,
|
|
37
|
-
element: Element | null,
|
|
38
|
-
scrollLeft: number,
|
|
39
|
-
): void;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { DirHelper };
|
package/src/dir-helper.js
DELETED
|
@@ -1,93 +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
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Helper that provides a set of functions for RTL.
|
|
9
|
-
*/
|
|
10
|
-
class DirHelper {
|
|
11
|
-
/**
|
|
12
|
-
* Get the scroll type in the current browser view.
|
|
13
|
-
*
|
|
14
|
-
* @return {string} the scroll type. Possible values are `default|reverse|negative`
|
|
15
|
-
*/
|
|
16
|
-
static detectScrollType() {
|
|
17
|
-
const dummy = document.createElement('div');
|
|
18
|
-
dummy.textContent = 'ABCD';
|
|
19
|
-
dummy.dir = 'rtl';
|
|
20
|
-
dummy.style.fontSize = '14px';
|
|
21
|
-
dummy.style.width = '4px';
|
|
22
|
-
dummy.style.height = '1px';
|
|
23
|
-
dummy.style.position = 'absolute';
|
|
24
|
-
dummy.style.top = '-1000px';
|
|
25
|
-
dummy.style.overflow = 'scroll';
|
|
26
|
-
document.body.appendChild(dummy);
|
|
27
|
-
|
|
28
|
-
let cachedType = 'reverse';
|
|
29
|
-
if (dummy.scrollLeft > 0) {
|
|
30
|
-
cachedType = 'default';
|
|
31
|
-
} else {
|
|
32
|
-
dummy.scrollLeft = 2;
|
|
33
|
-
if (dummy.scrollLeft < 2) {
|
|
34
|
-
cachedType = 'negative';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
document.body.removeChild(dummy);
|
|
38
|
-
return cachedType;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Get the scrollLeft value of the element relative to the direction
|
|
43
|
-
*
|
|
44
|
-
* @param {string} scrollType type of the scroll detected with `detectScrollType`
|
|
45
|
-
* @param {string} direction current direction of the element
|
|
46
|
-
* @param {Element} element
|
|
47
|
-
* @return {number} the scrollLeft value.
|
|
48
|
-
*/
|
|
49
|
-
static getNormalizedScrollLeft(scrollType, direction, element) {
|
|
50
|
-
const { scrollLeft } = element;
|
|
51
|
-
if (direction !== 'rtl' || !scrollType) {
|
|
52
|
-
return scrollLeft;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
switch (scrollType) {
|
|
56
|
-
case 'negative':
|
|
57
|
-
return element.scrollWidth - element.clientWidth + scrollLeft;
|
|
58
|
-
case 'reverse':
|
|
59
|
-
return element.scrollWidth - element.clientWidth - scrollLeft;
|
|
60
|
-
default:
|
|
61
|
-
return scrollLeft;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Set the scrollLeft value of the element relative to the direction
|
|
67
|
-
*
|
|
68
|
-
* @param {string} scrollType type of the scroll detected with `detectScrollType`
|
|
69
|
-
* @param {string} direction current direction of the element
|
|
70
|
-
* @param {Element} element
|
|
71
|
-
* @param {number} scrollLeft the scrollLeft value to be set
|
|
72
|
-
*/
|
|
73
|
-
static setNormalizedScrollLeft(scrollType, direction, element, scrollLeft) {
|
|
74
|
-
if (direction !== 'rtl' || !scrollType) {
|
|
75
|
-
element.scrollLeft = scrollLeft;
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
switch (scrollType) {
|
|
80
|
-
case 'negative':
|
|
81
|
-
element.scrollLeft = element.clientWidth - element.scrollWidth + scrollLeft;
|
|
82
|
-
break;
|
|
83
|
-
case 'reverse':
|
|
84
|
-
element.scrollLeft = element.scrollWidth - element.clientWidth - scrollLeft;
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
element.scrollLeft = scrollLeft;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { DirHelper };
|
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
|
-
);
|