@vaadin/component-base 25.3.0-dev.3a3c2d7d2a → 25.3.0
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-elements.json +2 -1
- package/package.json +5 -4
- package/src/define.js +1 -1
- package/src/delegate-state-mixin.js +2 -3
- package/src/dir-mixin.d.ts +14 -0
- package/src/dir-mixin.js +10 -0
- package/src/directives/part-map.d.ts +22 -0
- package/src/directives/part-map.js +86 -0
- package/src/dom-utils.d.ts +23 -5
- package/src/dom-utils.js +66 -20
- package/src/gestures.d.ts +12 -0
- package/src/i18n-mixin.js +3 -30
- package/src/media-query-controller.js +17 -19
- package/src/object-utils.d.ts +39 -0
- package/src/object-utils.js +109 -0
- package/src/overflow-controller.js +32 -34
- package/src/slot-child-observe-controller.d.ts +5 -0
- package/src/slot-child-observe-controller.js +19 -35
- package/src/slot-controller.js +2 -1
- package/src/slot-observer.d.ts +7 -1
- package/src/slot-observer.js +24 -4
- package/src/styles/style-props.js +2 -0
- package/src/tooltip-controller.js +8 -11
- package/src/virtualizer-iron-list-adapter.js +16 -35
package/custom-elements.json
CHANGED
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
{
|
|
51
51
|
"name": "superClass"
|
|
52
52
|
}
|
|
53
|
-
]
|
|
53
|
+
],
|
|
54
|
+
"deprecated": "This mixin is deprecated and will be removed in Vaadin 26,\nafter which components will no longer set the `dir` attribute on themselves.\nUse the `:dir(rtl)` CSS selector to style components in right-to-left mode,\nand `element.matches(':dir(rtl)')` to detect it in JavaScript."
|
|
54
55
|
}
|
|
55
56
|
],
|
|
56
57
|
"exports": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "25.3.0
|
|
3
|
+
"version": "25.3.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
"lit": "^3.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@vaadin/
|
|
41
|
+
"@polymer/polymer": "^3.0.0",
|
|
42
|
+
"@vaadin/chai-plugins": "~25.3.0",
|
|
43
|
+
"@vaadin/test-runner-commands": "~25.3.0",
|
|
43
44
|
"@vaadin/testing-helpers": "^2.0.0",
|
|
44
45
|
"sinon": "^22.0.0"
|
|
45
46
|
},
|
|
46
47
|
"customElements": "custom-elements.json",
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "4133747243c03bf544f6e82cc2ec9f295aaccd65"
|
|
48
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.3.0
|
|
16
|
+
export function defineCustomElement(CustomElement, version = '25.3.0') {
|
|
17
17
|
Object.defineProperty(CustomElement, 'version', {
|
|
18
18
|
get() {
|
|
19
19
|
return version;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
|
7
|
+
import { setOrRemoveAttribute } from './dom-utils.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* A mixin to delegate properties and attributes to a target element.
|
|
@@ -103,10 +104,8 @@ const DelegateStateMixinImplementation = (superclass) => {
|
|
|
103
104
|
|
|
104
105
|
if (typeof value === 'boolean') {
|
|
105
106
|
this.stateTarget.toggleAttribute(name, value);
|
|
106
|
-
} else if (value) {
|
|
107
|
-
this.stateTarget.setAttribute(name, value);
|
|
108
107
|
} else {
|
|
109
|
-
this.stateTarget
|
|
108
|
+
setOrRemoveAttribute(this.stateTarget, name, value);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
111
|
|
package/src/dir-mixin.d.ts
CHANGED
|
@@ -7,9 +7,23 @@ import type { Constructor } from '@open-wc/dedupe-mixin';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A mixin to handle `dir` attribute based on the one set on the `<html>` element.
|
|
10
|
+
*
|
|
11
|
+
* @deprecated This mixin is deprecated and will be removed in Vaadin 26,
|
|
12
|
+
* after which components will no longer set the `dir` attribute on themselves.
|
|
13
|
+
* Use the `:dir(rtl)` CSS selector to style components in right-to-left mode,
|
|
14
|
+
* and `element.matches(':dir(rtl)')` to detect it in JavaScript.
|
|
10
15
|
*/
|
|
11
16
|
export declare function DirMixin<T extends Constructor<HTMLElement>>(base: T): Constructor<DirMixinClass> & T;
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated This mixin is deprecated and will be removed in Vaadin 26,
|
|
20
|
+
* after which components will no longer set the `dir` attribute on themselves.
|
|
21
|
+
* Use the `:dir(rtl)` CSS selector to style components in right-to-left mode,
|
|
22
|
+
* and `element.matches(':dir(rtl)')` to detect it in JavaScript.
|
|
23
|
+
*/
|
|
13
24
|
export declare class DirMixinClass {
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use `this.matches(':dir(rtl)')` instead.
|
|
27
|
+
*/
|
|
14
28
|
protected readonly __isRTL: boolean;
|
|
15
29
|
}
|
package/src/dir-mixin.js
CHANGED
|
@@ -33,6 +33,11 @@ directionObserver.observe(document.documentElement, { attributes: true, attribut
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* A mixin to handle `dir` attribute based on the one set on the `<html>` element.
|
|
36
|
+
*
|
|
37
|
+
* @deprecated This mixin is deprecated and will be removed in Vaadin 26,
|
|
38
|
+
* after which components will no longer set the `dir` attribute on themselves.
|
|
39
|
+
* Use the `:dir(rtl)` CSS selector to style components in right-to-left mode,
|
|
40
|
+
* and `element.matches(':dir(rtl)')` to detect it in JavaScript.
|
|
36
41
|
*/
|
|
37
42
|
export const DirMixin = (superClass) =>
|
|
38
43
|
class VaadinDirMixin extends superClass {
|
|
@@ -60,6 +65,7 @@ export const DirMixin = (superClass) =>
|
|
|
60
65
|
/**
|
|
61
66
|
* @return {boolean}
|
|
62
67
|
* @protected
|
|
68
|
+
* @deprecated Use `this.matches(':dir(rtl)')` instead.
|
|
63
69
|
*/
|
|
64
70
|
get __isRTL() {
|
|
65
71
|
return this.getAttribute('dir') === 'rtl';
|
|
@@ -106,6 +112,10 @@ export const DirMixin = (superClass) =>
|
|
|
106
112
|
this.__unsubscribe();
|
|
107
113
|
}
|
|
108
114
|
|
|
115
|
+
// The two overrides below are only invoked by Polymer's property reflection.
|
|
116
|
+
// Vaadin components no longer extend `PolymerElement`, but some add-ons still
|
|
117
|
+
// apply this mixin to `PolymerElement`, so the overrides are kept for them.
|
|
118
|
+
|
|
109
119
|
/** @protected */
|
|
110
120
|
_valueToNodeAttribute(node, value, attribute) {
|
|
111
121
|
// Override default Polymer attribute reflection to match native behavior of HTMLElement.dir property
|
|
@@ -0,0 +1,22 @@
|
|
|
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 key-value set of part names to truthy values.
|
|
10
|
+
*/
|
|
11
|
+
export interface PartNameInfo {
|
|
12
|
+
readonly [name: string]: string | boolean | number | null | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A directive that applies dynamic shadow DOM part names.
|
|
17
|
+
*
|
|
18
|
+
* This must be used in the `part` attribute and must be the only binding in it.
|
|
19
|
+
* Each property name in `partNameInfo` is added to the element's `part` list
|
|
20
|
+
* if the property value is truthy, and removed if the value is falsy.
|
|
21
|
+
*/
|
|
22
|
+
export declare function partMap(partNameInfo: PartNameInfo): DirectiveResult;
|
|
@@ -0,0 +1,86 @@
|
|
|
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 } from 'lit';
|
|
7
|
+
import { Directive, directive, PartType } from 'lit/directive.js';
|
|
8
|
+
|
|
9
|
+
class PartMapDirective extends Directive {
|
|
10
|
+
// Part names applied by the directive on the previous render,
|
|
11
|
+
// used to remove names that no longer apply.
|
|
12
|
+
#previousParts;
|
|
13
|
+
|
|
14
|
+
// Part names declared statically in the attribute, never removed.
|
|
15
|
+
#staticParts;
|
|
16
|
+
|
|
17
|
+
constructor(partInfo) {
|
|
18
|
+
super(partInfo);
|
|
19
|
+
if (partInfo.type !== PartType.ATTRIBUTE || partInfo.name !== 'part' || partInfo.strings?.length > 2) {
|
|
20
|
+
throw new Error('`partMap()` can only be used in the `part` attribute and must be the only binding in it.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
render(partNameInfo) {
|
|
25
|
+
// Add spaces to ensure separation from static parts
|
|
26
|
+
return ` ${Object.keys(partNameInfo)
|
|
27
|
+
.filter((key) => partNameInfo[key])
|
|
28
|
+
.join(' ')} `;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
update(part, [partNameInfo]) {
|
|
32
|
+
// Remember dynamic parts on the first render
|
|
33
|
+
if (this.#previousParts === undefined) {
|
|
34
|
+
this.#previousParts = new Set();
|
|
35
|
+
if (part.strings !== undefined) {
|
|
36
|
+
this.#staticParts = new Set(
|
|
37
|
+
part.strings
|
|
38
|
+
.join(' ')
|
|
39
|
+
.split(/\s/u)
|
|
40
|
+
.filter((s) => s !== ''),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
Object.keys(partNameInfo).forEach((name) => {
|
|
44
|
+
if (partNameInfo[name] && !this.#staticParts?.has(name)) {
|
|
45
|
+
this.#previousParts.add(name);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return this.render(partNameInfo);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const partList = part.element.part;
|
|
52
|
+
|
|
53
|
+
// Remove old parts that no longer apply
|
|
54
|
+
this.#previousParts.forEach((name) => {
|
|
55
|
+
if (!(name in partNameInfo)) {
|
|
56
|
+
partList.remove(name);
|
|
57
|
+
this.#previousParts.delete(name);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Add or remove parts based on their partMap value
|
|
62
|
+
Object.keys(partNameInfo).forEach((name) => {
|
|
63
|
+
const value = !!partNameInfo[name];
|
|
64
|
+
if (value !== this.#previousParts.has(name) && !this.#staticParts?.has(name)) {
|
|
65
|
+
if (value) {
|
|
66
|
+
partList.add(name);
|
|
67
|
+
this.#previousParts.add(name);
|
|
68
|
+
} else {
|
|
69
|
+
partList.remove(name);
|
|
70
|
+
this.#previousParts.delete(name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return noChange;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A directive that applies dynamic shadow DOM part names.
|
|
81
|
+
*
|
|
82
|
+
* This must be used in the `part` attribute and must be the only binding in it.
|
|
83
|
+
* Each property name in `partNameInfo` is added to the element's `part` list
|
|
84
|
+
* if the property value is truthy, and removed if the value is falsy.
|
|
85
|
+
*/
|
|
86
|
+
export const partMap = directive(PartMapDirective);
|
package/src/dom-utils.d.ts
CHANGED
|
@@ -37,17 +37,35 @@ export function deserializeAttributeValue(value: string): Set<string>;
|
|
|
37
37
|
export function serializeAttributeValue(values: Set<string>): string;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Sets the attribute to the given value, or removes the attribute when the
|
|
41
|
+
* value is falsy (e.g. `null`, `undefined`, `false` or an empty string).
|
|
41
42
|
*/
|
|
42
|
-
export function
|
|
43
|
+
export function setOrRemoveAttribute(
|
|
44
|
+
element: HTMLElement,
|
|
45
|
+
attr: string,
|
|
46
|
+
value: string | boolean | null | undefined,
|
|
47
|
+
): void;
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
* If
|
|
50
|
+
* Adds one or more values to an attribute containing space-delimited values.
|
|
51
|
+
* If no values remain, the whole attribute is removed.
|
|
47
52
|
*/
|
|
48
|
-
export function
|
|
53
|
+
export function addValuesToAttribute(element: HTMLElement, attr: string, valuesToAdd: string | string[]): void;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Removes one or more values from an attribute containing space-delimited values.
|
|
57
|
+
* If no values remain, the whole attribute is removed.
|
|
58
|
+
*/
|
|
59
|
+
export function removeValuesFromAttribute(element: HTMLElement, attr: string, valuesToRemove: string | string[]): void;
|
|
49
60
|
|
|
50
61
|
/**
|
|
51
62
|
* Returns true if the given node is an empty text node, false otherwise.
|
|
52
63
|
*/
|
|
53
64
|
export function isEmptyTextNode(node: Node): boolean;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if the given node has content of its own: an element with
|
|
68
|
+
* children, a defined custom element — which may render content in its
|
|
69
|
+
* shadow root — or a node with non-empty text.
|
|
70
|
+
*/
|
|
71
|
+
export function hasNodeContent(node: Node | null | undefined): boolean;
|
package/src/dom-utils.js
CHANGED
|
@@ -84,11 +84,7 @@ export function getClosestElement(selector, node) {
|
|
|
84
84
|
* @return {Set<string>}
|
|
85
85
|
*/
|
|
86
86
|
export function deserializeAttributeValue(value) {
|
|
87
|
-
|
|
88
|
-
return new Set();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return new Set(value.split(' '));
|
|
87
|
+
return new Set(value ? value.split(' ').filter(Boolean) : []);
|
|
92
88
|
}
|
|
93
89
|
|
|
94
90
|
/**
|
|
@@ -102,34 +98,65 @@ export function serializeAttributeValue(values) {
|
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
/**
|
|
105
|
-
*
|
|
101
|
+
* Sets the attribute to the given value, or removes the attribute when the
|
|
102
|
+
* value is falsy (e.g. `null`, `undefined`, `false` or an empty string).
|
|
106
103
|
*
|
|
107
104
|
* @param {HTMLElement} element
|
|
108
105
|
* @param {string} attr
|
|
109
|
-
* @param {string} value
|
|
106
|
+
* @param {string | boolean | null | undefined} value
|
|
107
|
+
*/
|
|
108
|
+
export function setOrRemoveAttribute(element, attr, value) {
|
|
109
|
+
if (value) {
|
|
110
|
+
element.setAttribute(attr, value);
|
|
111
|
+
} else {
|
|
112
|
+
element.removeAttribute(attr);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Normalizes values passed to `addValuesToAttribute` and `removeValuesFromAttribute`
|
|
118
|
+
* into a set of values. Both a single string and every array entry may contain
|
|
119
|
+
* multiple values separated by space.
|
|
120
|
+
*
|
|
121
|
+
* @param {string | string[] | null | undefined} values
|
|
122
|
+
* @return {Set<string>}
|
|
110
123
|
*/
|
|
111
|
-
|
|
124
|
+
function normalizeAttributeValues(values) {
|
|
125
|
+
return deserializeAttributeValue(Array.isArray(values) ? values.join(' ') : values);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Adds one or more values to an attribute containing space-delimited values.
|
|
130
|
+
* If no values remain, the whole attribute is removed.
|
|
131
|
+
*
|
|
132
|
+
* @param {HTMLElement} element
|
|
133
|
+
* @param {string} attr
|
|
134
|
+
* @param {string | string[]} valuesToAdd a string or an array of strings with values separated by space
|
|
135
|
+
*/
|
|
136
|
+
export function addValuesToAttribute(element, attr, valuesToAdd) {
|
|
137
|
+
valuesToAdd = normalizeAttributeValues(valuesToAdd);
|
|
138
|
+
|
|
112
139
|
const values = deserializeAttributeValue(element.getAttribute(attr));
|
|
113
|
-
values.add(value);
|
|
114
|
-
|
|
140
|
+
valuesToAdd.forEach((value) => values.add(value));
|
|
141
|
+
|
|
142
|
+
setOrRemoveAttribute(element, attr, serializeAttributeValue(values));
|
|
115
143
|
}
|
|
116
144
|
|
|
117
145
|
/**
|
|
118
|
-
* Removes
|
|
119
|
-
* If
|
|
146
|
+
* Removes one or more values from an attribute containing space-delimited values.
|
|
147
|
+
* If no values remain, the whole attribute is removed.
|
|
120
148
|
*
|
|
121
149
|
* @param {HTMLElement} element
|
|
122
150
|
* @param {string} attr
|
|
123
|
-
* @param {string}
|
|
151
|
+
* @param {string | string[]} valuesToRemove a string or an array of strings with values separated by space
|
|
124
152
|
*/
|
|
125
|
-
export function
|
|
153
|
+
export function removeValuesFromAttribute(element, attr, valuesToRemove) {
|
|
154
|
+
valuesToRemove = normalizeAttributeValues(valuesToRemove);
|
|
155
|
+
|
|
126
156
|
const values = deserializeAttributeValue(element.getAttribute(attr));
|
|
127
|
-
values.delete(value);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
element.setAttribute(attr, serializeAttributeValue(values));
|
|
157
|
+
valuesToRemove.forEach((value) => values.delete(value));
|
|
158
|
+
|
|
159
|
+
setOrRemoveAttribute(element, attr, serializeAttributeValue(values));
|
|
133
160
|
}
|
|
134
161
|
|
|
135
162
|
/**
|
|
@@ -141,3 +168,22 @@ export function removeValueFromAttribute(element, attr, value) {
|
|
|
141
168
|
export function isEmptyTextNode(node) {
|
|
142
169
|
return node.nodeType === Node.TEXT_NODE && node.textContent.trim() === '';
|
|
143
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Returns true if the given node has content of its own: an element with
|
|
174
|
+
* children, a defined custom element — which may render content in its
|
|
175
|
+
* shadow root — or a node with non-empty text.
|
|
176
|
+
*
|
|
177
|
+
* @param {Node | null | undefined} node
|
|
178
|
+
* @return {boolean}
|
|
179
|
+
*/
|
|
180
|
+
export function hasNodeContent(node) {
|
|
181
|
+
if (!node) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return Boolean(
|
|
186
|
+
(node.nodeType === Node.ELEMENT_NODE && (customElements.get(node.localName) || node.children.length > 0)) ||
|
|
187
|
+
node.textContent?.trim(),
|
|
188
|
+
);
|
|
189
|
+
}
|
package/src/gestures.d.ts
CHANGED
|
@@ -43,6 +43,18 @@ export { removeListener };
|
|
|
43
43
|
declare function register(recog: GestureRecognizer): void;
|
|
44
44
|
export { register };
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The registered gesture event recognizers by their event type.
|
|
48
|
+
*/
|
|
49
|
+
declare const gestures: Record<string, GestureRecognizer | undefined>;
|
|
50
|
+
export { gestures };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The registered gesture event recognizers.
|
|
54
|
+
*/
|
|
55
|
+
declare const recognizers: GestureRecognizer[];
|
|
56
|
+
export { recognizers };
|
|
57
|
+
|
|
46
58
|
/**
|
|
47
59
|
* Sets scrolling direction on node.
|
|
48
60
|
*
|
package/src/i18n-mixin.js
CHANGED
|
@@ -3,34 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2025 - 2026 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
function deepMerge(target, ...sources) {
|
|
8
|
-
const isArray = (item) => Array.isArray(item);
|
|
9
|
-
const isObject = (item) => item && typeof item === 'object' && !isArray(item);
|
|
10
|
-
const merge = (target, source) => {
|
|
11
|
-
if (isObject(source) && isObject(target)) {
|
|
12
|
-
Object.keys(source).forEach((key) => {
|
|
13
|
-
const sourceValue = source[key];
|
|
14
|
-
if (isObject(sourceValue)) {
|
|
15
|
-
if (!target[key]) {
|
|
16
|
-
target[key] = {};
|
|
17
|
-
}
|
|
18
|
-
merge(target[key], sourceValue);
|
|
19
|
-
} else if (isArray(sourceValue)) {
|
|
20
|
-
target[key] = [...sourceValue];
|
|
21
|
-
} else if (sourceValue !== undefined && sourceValue !== null) {
|
|
22
|
-
target[key] = sourceValue;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
sources.forEach((source) => {
|
|
29
|
-
merge(target, source);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return target;
|
|
33
|
-
}
|
|
6
|
+
import { deepMergePartials } from './object-utils.js';
|
|
34
7
|
|
|
35
8
|
/**
|
|
36
9
|
* A mixin that allows to set partial I18N properties.
|
|
@@ -75,7 +48,7 @@ export const I18nMixin = (superClass) =>
|
|
|
75
48
|
constructor() {
|
|
76
49
|
super();
|
|
77
50
|
|
|
78
|
-
this.i18n =
|
|
51
|
+
this.i18n = deepMergePartials({}, this.constructor.defaultI18n);
|
|
79
52
|
}
|
|
80
53
|
|
|
81
54
|
/**
|
|
@@ -97,6 +70,6 @@ export const I18nMixin = (superClass) =>
|
|
|
97
70
|
return;
|
|
98
71
|
}
|
|
99
72
|
this.__customI18n = value;
|
|
100
|
-
this.__effectiveI18n =
|
|
73
|
+
this.__effectiveI18n = deepMergePartials({}, this.constructor.defaultI18n, this.__customI18n);
|
|
101
74
|
}
|
|
102
75
|
};
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* A controller for listening on media query changes.
|
|
9
9
|
*/
|
|
10
10
|
export class MediaQueryController {
|
|
11
|
+
/** @type {MediaQueryList | null} */
|
|
12
|
+
#mediaQuery = null;
|
|
13
|
+
|
|
11
14
|
constructor(query, callback) {
|
|
12
15
|
/**
|
|
13
16
|
* The CSS media query to evaluate.
|
|
@@ -24,44 +27,39 @@ export class MediaQueryController {
|
|
|
24
27
|
* @protected
|
|
25
28
|
*/
|
|
26
29
|
this.callback = callback;
|
|
27
|
-
|
|
28
|
-
this._boundQueryHandler = this._queryHandler.bind(this);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
hostConnected() {
|
|
32
|
-
this
|
|
33
|
+
this.#removeListener();
|
|
33
34
|
|
|
34
|
-
this
|
|
35
|
+
this.#mediaQuery = window.matchMedia(this.query);
|
|
35
36
|
|
|
36
|
-
this
|
|
37
|
+
this.#addListener();
|
|
37
38
|
|
|
38
|
-
this
|
|
39
|
+
this.#queryHandler(this.#mediaQuery);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
hostDisconnected() {
|
|
42
|
-
this
|
|
43
|
+
this.#removeListener();
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this._mediaQuery.addListener(this._boundQueryHandler);
|
|
46
|
+
#addListener() {
|
|
47
|
+
if (this.#mediaQuery) {
|
|
48
|
+
this.#mediaQuery.addListener(this.#queryHandler);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this._mediaQuery.removeListener(this._boundQueryHandler);
|
|
52
|
+
#removeListener() {
|
|
53
|
+
if (this.#mediaQuery) {
|
|
54
|
+
this.#mediaQuery.removeListener(this.#queryHandler);
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
this
|
|
57
|
+
this.#mediaQuery = null;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
_queryHandler(mediaQuery) {
|
|
60
|
+
#queryHandler = (mediaQuery) => {
|
|
63
61
|
if (typeof this.callback === 'function') {
|
|
64
62
|
this.callback(mediaQuery.matches);
|
|
65
63
|
}
|
|
66
|
-
}
|
|
64
|
+
};
|
|
67
65
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Recursively copies own properties of `source` into `target` and returns
|
|
9
|
+
* `target`. Plain objects are merged, other values are assigned as they are.
|
|
10
|
+
* An object is plain when it inherits from `Object.prototype` or from nothing,
|
|
11
|
+
* so values such as a `Date` or a class instance are assigned, not merged.
|
|
12
|
+
*
|
|
13
|
+
* Merges a single source. Use `deepMergePartials()` to merge several objects,
|
|
14
|
+
* or to merge objects that only provide some of the properties.
|
|
15
|
+
*
|
|
16
|
+
* Both arguments are expected to be plain objects. When either of them is not,
|
|
17
|
+
* `target` is returned without changes. A property of the target that is not a
|
|
18
|
+
* plain object is replaced with the merged object, unlike the arguments.
|
|
19
|
+
*
|
|
20
|
+
* Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
|
|
21
|
+
*/
|
|
22
|
+
export function deepMerge<T extends object>(target: T, source: object): T;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Recursively merges partial objects into `target` in order and returns
|
|
26
|
+
* `target`, so that a later source overrides an earlier one.
|
|
27
|
+
*
|
|
28
|
+
* Values that are `null` or `undefined` are skipped, so a source that only
|
|
29
|
+
* provides some of the properties does not remove the others. For the same
|
|
30
|
+
* reason, a property that the target already has is not replaced with an
|
|
31
|
+
* object when the source has one for the same key. Arrays are copied one level
|
|
32
|
+
* deep, so that the result does not share an array with any of the sources.
|
|
33
|
+
*
|
|
34
|
+
* Sources that are not plain objects are ignored. When `target` is not a plain
|
|
35
|
+
* object, it is returned without changes.
|
|
36
|
+
*
|
|
37
|
+
* Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
|
|
38
|
+
*/
|
|
39
|
+
export function deepMergePartials<T extends object>(target: T, ...sources: object[]): T;
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Keys that are not copied while merging, as assigning them would modify
|
|
9
|
+
* `Object.prototype` instead of the merge target, and so affect every
|
|
10
|
+
* object in the application.
|
|
11
|
+
*/
|
|
12
|
+
const IGNORED_KEYS = ['__proto__', 'constructor', 'prototype'];
|
|
13
|
+
|
|
14
|
+
const isPlainObject = (value) => {
|
|
15
|
+
if (!value || typeof value !== 'object') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const prototype = Object.getPrototypeOf(value);
|
|
19
|
+
return prototype === Object.prototype || prototype === null;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Merges `source` into `target`. With `partial`, the source is treated as an
|
|
24
|
+
* object that may provide only some of the properties: nullish values are
|
|
25
|
+
* skipped and arrays are copied instead of shared.
|
|
26
|
+
*/
|
|
27
|
+
function merge(target, source, partial) {
|
|
28
|
+
if (!isPlainObject(target) || !isPlainObject(source)) {
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Object.keys(source).forEach((key) => {
|
|
33
|
+
if (IGNORED_KEYS.includes(key)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const value = source[key];
|
|
38
|
+
|
|
39
|
+
if (isPlainObject(value)) {
|
|
40
|
+
// Only merge into an own plain object, so that the merge can never
|
|
41
|
+
// continue into an object inherited from the prototype chain.
|
|
42
|
+
if (!Object.hasOwn(target, key) || !isPlainObject(target[key])) {
|
|
43
|
+
// With `partial`, a value that the target already has is kept, so that
|
|
44
|
+
// a source property of an unexpected type does not remove a default.
|
|
45
|
+
if (partial && Object.hasOwn(target, key) && target[key]) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
target[key] = {};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
merge(target[key], value, partial);
|
|
53
|
+
} else if (partial && Array.isArray(value)) {
|
|
54
|
+
target[key] = [...value];
|
|
55
|
+
} else if (!partial || (value !== undefined && value !== null)) {
|
|
56
|
+
target[key] = value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Recursively copies own properties of `source` into `target` and returns
|
|
65
|
+
* `target`. Plain objects are merged, other values are assigned as they are.
|
|
66
|
+
* An object is plain when it inherits from `Object.prototype` or from nothing,
|
|
67
|
+
* so values such as a `Date` or a class instance are assigned, not merged.
|
|
68
|
+
*
|
|
69
|
+
* Merges a single source. Use `deepMergePartials()` to merge several objects,
|
|
70
|
+
* or to merge objects that only provide some of the properties.
|
|
71
|
+
*
|
|
72
|
+
* Both arguments are expected to be plain objects. When either of them is not,
|
|
73
|
+
* `target` is returned without changes. A property of the target that is not a
|
|
74
|
+
* plain object is replaced with the merged object, unlike the arguments.
|
|
75
|
+
*
|
|
76
|
+
* Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
|
|
77
|
+
*
|
|
78
|
+
* @param {object} target the object to merge into, modified in place
|
|
79
|
+
* @param {object} source the object to copy the properties from
|
|
80
|
+
* @return {object} the `target` object
|
|
81
|
+
*/
|
|
82
|
+
export function deepMerge(target, source) {
|
|
83
|
+
return merge(target, source, false);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Recursively merges partial objects into `target` in order and returns
|
|
88
|
+
* `target`, so that a later source overrides an earlier one.
|
|
89
|
+
*
|
|
90
|
+
* Values that are `null` or `undefined` are skipped, so a source that only
|
|
91
|
+
* provides some of the properties does not remove the others. For the same
|
|
92
|
+
* reason, a property that the target already has is not replaced with an
|
|
93
|
+
* object when the source has one for the same key. Arrays are copied one level
|
|
94
|
+
* deep, so that the result does not share an array with any of the sources.
|
|
95
|
+
*
|
|
96
|
+
* Sources that are not plain objects are ignored. When `target` is not a plain
|
|
97
|
+
* object, it is returned without changes.
|
|
98
|
+
*
|
|
99
|
+
* Keys that would modify `Object.prototype`, such as `__proto__`, are ignored.
|
|
100
|
+
*
|
|
101
|
+
* @param {object} target the object to merge into, modified in place
|
|
102
|
+
* @param {...object} sources the objects to copy the properties from
|
|
103
|
+
* @return {object} the `target` object
|
|
104
|
+
*/
|
|
105
|
+
export function deepMergePartials(target, ...sources) {
|
|
106
|
+
sources.forEach((source) => merge(target, source, true));
|
|
107
|
+
|
|
108
|
+
return target;
|
|
109
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2021 - 2026 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import { setOrRemoveAttribute } from './dom-utils.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* A controller that detects if content inside the element overflows its scrolling viewport,
|
|
@@ -10,6 +11,15 @@
|
|
|
10
11
|
* where content is overflowing. Supported values are: `top`, `bottom`, `start`, `end`.
|
|
11
12
|
*/
|
|
12
13
|
export class OverflowController {
|
|
14
|
+
/** @type {ResizeObserver} */
|
|
15
|
+
#resizeObserver;
|
|
16
|
+
|
|
17
|
+
/** @type {MutationObserver} */
|
|
18
|
+
#childObserver;
|
|
19
|
+
|
|
20
|
+
/** @type {number} */
|
|
21
|
+
#resizeRaf;
|
|
22
|
+
|
|
13
23
|
constructor(host, scrollTarget) {
|
|
14
24
|
/**
|
|
15
25
|
* The controller host element.
|
|
@@ -25,9 +35,6 @@ export class OverflowController {
|
|
|
25
35
|
* @type {HTMLElement}
|
|
26
36
|
*/
|
|
27
37
|
this.scrollTarget = scrollTarget || host;
|
|
28
|
-
|
|
29
|
-
/** @private */
|
|
30
|
-
this.__boundOnScroll = this.__onScroll.bind(this);
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
hostConnected() {
|
|
@@ -46,64 +53,60 @@ export class OverflowController {
|
|
|
46
53
|
observe() {
|
|
47
54
|
const { host } = this;
|
|
48
55
|
|
|
49
|
-
this
|
|
50
|
-
this.
|
|
56
|
+
this.#resizeObserver = new ResizeObserver(() => this.#onResize());
|
|
57
|
+
this.#resizeObserver.observe(host);
|
|
51
58
|
|
|
52
59
|
// Observe initial children
|
|
53
60
|
[...host.children].forEach((child) => {
|
|
54
|
-
this.
|
|
61
|
+
this.#resizeObserver.observe(child);
|
|
55
62
|
});
|
|
56
63
|
|
|
57
|
-
this
|
|
64
|
+
this.#childObserver = new MutationObserver((mutations) => {
|
|
58
65
|
mutations.forEach(({ addedNodes, removedNodes }) => {
|
|
59
66
|
addedNodes.forEach((node) => {
|
|
60
67
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
61
|
-
this.
|
|
68
|
+
this.#resizeObserver.observe(node);
|
|
62
69
|
}
|
|
63
70
|
});
|
|
64
71
|
|
|
65
72
|
removedNodes.forEach((node) => {
|
|
66
73
|
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
67
|
-
this.
|
|
74
|
+
this.#resizeObserver.unobserve(node);
|
|
68
75
|
}
|
|
69
76
|
});
|
|
70
77
|
|
|
71
78
|
if (addedNodes.length === 0 && removedNodes.length > 0) {
|
|
72
|
-
this
|
|
79
|
+
this.#updateState({ sync: true });
|
|
73
80
|
}
|
|
74
81
|
});
|
|
75
82
|
});
|
|
76
83
|
|
|
77
|
-
this.
|
|
84
|
+
this.#childObserver.observe(host, { childList: true });
|
|
78
85
|
|
|
79
86
|
// Update overflow attribute on scroll
|
|
80
|
-
this.scrollTarget.addEventListener('scroll', this
|
|
87
|
+
this.scrollTarget.addEventListener('scroll', this.#onScroll);
|
|
81
88
|
}
|
|
82
89
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.__updateState({ sync: false });
|
|
90
|
+
#onResize() {
|
|
91
|
+
this.#updateState({ sync: false });
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
94
|
+
#onScroll = () => {
|
|
95
|
+
this.#updateState({ sync: true });
|
|
96
|
+
};
|
|
92
97
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
cancelAnimationFrame(this.__resizeRaf);
|
|
98
|
+
#updateState({ sync }) {
|
|
99
|
+
cancelAnimationFrame(this.#resizeRaf);
|
|
96
100
|
|
|
97
|
-
const state = this
|
|
101
|
+
const state = this.#readState();
|
|
98
102
|
if (sync) {
|
|
99
|
-
this
|
|
103
|
+
this.#writeState(state);
|
|
100
104
|
} else {
|
|
101
|
-
this
|
|
105
|
+
this.#resizeRaf = requestAnimationFrame(() => this.#writeState(state));
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
__readState() {
|
|
109
|
+
#readState() {
|
|
107
110
|
const target = this.scrollTarget;
|
|
108
111
|
|
|
109
112
|
let overflow = '';
|
|
@@ -128,12 +131,7 @@ export class OverflowController {
|
|
|
128
131
|
return { overflow: overflow.trim() };
|
|
129
132
|
}
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (overflow) {
|
|
134
|
-
this.host.setAttribute('overflow', overflow);
|
|
135
|
-
} else {
|
|
136
|
-
this.host.removeAttribute('overflow');
|
|
137
|
-
}
|
|
134
|
+
#writeState({ overflow }) {
|
|
135
|
+
setOrRemoveAttribute(this.host, 'overflow', overflow);
|
|
138
136
|
}
|
|
139
137
|
}
|
|
@@ -25,4 +25,9 @@ export class SlotChildObserveController extends SlotController {
|
|
|
25
25
|
* Override to update default node text on property change.
|
|
26
26
|
*/
|
|
27
27
|
protected updateDefaultNode(node: Node): void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Fire an event to notify the controller host about node changes.
|
|
31
|
+
*/
|
|
32
|
+
protected _notifyChange(node: Node): void;
|
|
28
33
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2022 - 2026 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import { hasNodeContent } from './dom-utils.js';
|
|
6
7
|
import { SlotController } from './slot-controller.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -10,6 +11,9 @@ import { SlotController } from './slot-controller.js';
|
|
|
10
11
|
* and the text content, and fires an event to notify host element about those.
|
|
11
12
|
*/
|
|
12
13
|
export class SlotChildObserveController extends SlotController {
|
|
14
|
+
/** @type {MutationObserver} */
|
|
15
|
+
#nodeObserver;
|
|
16
|
+
|
|
13
17
|
constructor(host, slot, tagName, config = {}) {
|
|
14
18
|
super(host, slot, tagName, { ...config, useUniqueId: true });
|
|
15
19
|
}
|
|
@@ -22,8 +26,8 @@ export class SlotChildObserveController extends SlotController {
|
|
|
22
26
|
* @override
|
|
23
27
|
*/
|
|
24
28
|
initCustomNode(node) {
|
|
25
|
-
this
|
|
26
|
-
this.
|
|
29
|
+
this.#updateNodeId(node);
|
|
30
|
+
this._notifyChange(node);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
/**
|
|
@@ -39,7 +43,7 @@ export class SlotChildObserveController extends SlotController {
|
|
|
39
43
|
|
|
40
44
|
// Custom node is added to the slot
|
|
41
45
|
if (node && node !== this.defaultNode) {
|
|
42
|
-
this.
|
|
46
|
+
this._notifyChange(node);
|
|
43
47
|
} else {
|
|
44
48
|
this.restoreDefaultNode();
|
|
45
49
|
this.updateDefaultNode(this.node);
|
|
@@ -58,7 +62,7 @@ export class SlotChildObserveController extends SlotController {
|
|
|
58
62
|
const node = super.attachDefaultNode();
|
|
59
63
|
|
|
60
64
|
if (node) {
|
|
61
|
-
this
|
|
65
|
+
this.#updateNodeId(node);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
return node;
|
|
@@ -80,7 +84,7 @@ export class SlotChildObserveController extends SlotController {
|
|
|
80
84
|
* @protected
|
|
81
85
|
*/
|
|
82
86
|
updateDefaultNode(node) {
|
|
83
|
-
this.
|
|
87
|
+
this._notifyChange(node);
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
/**
|
|
@@ -92,11 +96,11 @@ export class SlotChildObserveController extends SlotController {
|
|
|
92
96
|
*/
|
|
93
97
|
observeNode(node) {
|
|
94
98
|
// Stop observing the previous node, if any.
|
|
95
|
-
if (this
|
|
96
|
-
this.
|
|
99
|
+
if (this.#nodeObserver) {
|
|
100
|
+
this.#nodeObserver.disconnect();
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
this
|
|
103
|
+
this.#nodeObserver = new MutationObserver((mutations) => {
|
|
100
104
|
mutations.forEach((mutation) => {
|
|
101
105
|
const target = mutation.target;
|
|
102
106
|
|
|
@@ -108,17 +112,17 @@ export class SlotChildObserveController extends SlotController {
|
|
|
108
112
|
// We use attributeFilter to only observe ID mutation,
|
|
109
113
|
// no need to check for attribute name separately.
|
|
110
114
|
if (isCurrentNodeMutation) {
|
|
111
|
-
this
|
|
115
|
+
this.#updateNodeId(target);
|
|
112
116
|
}
|
|
113
117
|
} else if (isCurrentNodeMutation || target.parentElement === this.node) {
|
|
114
118
|
// Node text content has changed.
|
|
115
|
-
this.
|
|
119
|
+
this._notifyChange(this.node);
|
|
116
120
|
}
|
|
117
121
|
});
|
|
118
122
|
});
|
|
119
123
|
|
|
120
124
|
// Observe changes to node ID attribute, text content and children.
|
|
121
|
-
this.
|
|
125
|
+
this.#nodeObserver.observe(node, {
|
|
122
126
|
attributes: true,
|
|
123
127
|
attributeFilter: ['id'],
|
|
124
128
|
childList: true,
|
|
@@ -127,35 +131,16 @@ export class SlotChildObserveController extends SlotController {
|
|
|
127
131
|
});
|
|
128
132
|
}
|
|
129
133
|
|
|
130
|
-
/**
|
|
131
|
-
* Returns true if a node is an HTML element with children,
|
|
132
|
-
* or is a defined custom element, or has non-empty text.
|
|
133
|
-
*
|
|
134
|
-
* @param {Node} node
|
|
135
|
-
* @return {boolean}
|
|
136
|
-
* @private
|
|
137
|
-
*/
|
|
138
|
-
__hasContent(node) {
|
|
139
|
-
if (!node) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
(node.nodeType === Node.ELEMENT_NODE && (customElements.get(node.localName) || node.children.length > 0)) ||
|
|
145
|
-
(node.textContent && node.textContent.trim() !== '')
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
134
|
/**
|
|
150
135
|
* Fire an event to notify the controller host about node changes.
|
|
151
136
|
*
|
|
152
137
|
* @param {Node} node
|
|
153
|
-
* @
|
|
138
|
+
* @protected
|
|
154
139
|
*/
|
|
155
|
-
|
|
140
|
+
_notifyChange(node) {
|
|
156
141
|
this.dispatchEvent(
|
|
157
142
|
new CustomEvent('slot-content-changed', {
|
|
158
|
-
detail: { hasContent:
|
|
143
|
+
detail: { hasContent: hasNodeContent(node), node },
|
|
159
144
|
}),
|
|
160
145
|
);
|
|
161
146
|
}
|
|
@@ -164,9 +149,8 @@ export class SlotChildObserveController extends SlotController {
|
|
|
164
149
|
* Set default ID on the node in case it is an HTML element.
|
|
165
150
|
*
|
|
166
151
|
* @param {Node} node
|
|
167
|
-
* @private
|
|
168
152
|
*/
|
|
169
|
-
|
|
153
|
+
#updateNodeId(node) {
|
|
170
154
|
// When in multiple mode, only set ID attribute on the element in default slot.
|
|
171
155
|
const isFirstNode = !this.nodes || node === this.nodes[0];
|
|
172
156
|
if (node.nodeType === Node.ELEMENT_NODE && (!this.multiple || isFirstNode) && !node.id) {
|
package/src/slot-controller.js
CHANGED
|
@@ -202,7 +202,8 @@ export class SlotController extends EventTarget {
|
|
|
202
202
|
const selector = slotName === '' ? 'slot:not([name])' : `slot[name=${slotName}]`;
|
|
203
203
|
const slot = this.host.shadowRoot.querySelector(selector);
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
// eslint-disable-next-line no-new
|
|
206
|
+
new SlotObserver(slot, ({ addedNodes, removedNodes }) => {
|
|
206
207
|
const current = this.multiple ? this.nodes : [this.node];
|
|
207
208
|
|
|
208
209
|
// Calling `slot.assignedNodes()` includes whitespace text nodes in case of default slot:
|
package/src/slot-observer.d.ts
CHANGED
|
@@ -14,12 +14,18 @@
|
|
|
14
14
|
* bubbling to it and diffs the **union** of `assignedNodes({ flatten: true })`
|
|
15
15
|
* every descendant `<slot>`. Cross-slot reassignment of the same node does
|
|
16
16
|
* not change the union and therefore fires no callback.
|
|
17
|
+
*
|
|
18
|
+
* The initial pass runs in a microtask by default. Use the `syncInitial` option
|
|
19
|
+
* when the callback sets state that affects the layout of the component, so that
|
|
20
|
+
* it has its final size once connected. Otherwise consumers that measure it
|
|
21
|
+
* synchronously, such as auto-width columns in `<vaadin-grid>`, would measure the
|
|
22
|
+
* component before that state is applied.
|
|
17
23
|
*/
|
|
18
24
|
export class SlotObserver {
|
|
19
25
|
constructor(
|
|
20
26
|
target: HTMLSlotElement | DocumentFragment,
|
|
21
27
|
callback: (info: { addedNodes: Node[]; currentNodes: Node[]; movedNodes: Node[]; removedNodes: Node[] }) => void,
|
|
22
|
-
forceInitial?: boolean,
|
|
28
|
+
options?: { forceInitial?: boolean; syncInitial?: boolean },
|
|
23
29
|
);
|
|
24
30
|
|
|
25
31
|
readonly target: HTMLSlotElement | DocumentFragment;
|
package/src/slot-observer.js
CHANGED
|
@@ -14,9 +14,20 @@
|
|
|
14
14
|
* bubbling to it and diffs the **union** of `assignedNodes({ flatten: true })`
|
|
15
15
|
* across every descendant `<slot>`. Cross-slot reassignment of the same node
|
|
16
16
|
* does not change the union and therefore fires no callback.
|
|
17
|
+
*
|
|
18
|
+
* The initial pass runs in a microtask by default. Use the `syncInitial` option
|
|
19
|
+
* when the callback sets state that affects the layout of the component, so that
|
|
20
|
+
* it has its final size once connected. Otherwise consumers that measure it
|
|
21
|
+
* synchronously, such as auto-width columns in `<vaadin-grid>`, would measure the
|
|
22
|
+
* component before that state is applied.
|
|
17
23
|
*/
|
|
18
24
|
export class SlotObserver {
|
|
19
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @param {HTMLSlotElement | DocumentFragment} target
|
|
27
|
+
* @param {Function} callback
|
|
28
|
+
* @param {{ forceInitial?: boolean, syncInitial?: boolean }} options
|
|
29
|
+
*/
|
|
30
|
+
constructor(target, callback, options = {}) {
|
|
20
31
|
/** @type {HTMLSlotElement | DocumentFragment} */
|
|
21
32
|
this.target = target;
|
|
22
33
|
|
|
@@ -24,7 +35,7 @@ export class SlotObserver {
|
|
|
24
35
|
this.callback = callback;
|
|
25
36
|
|
|
26
37
|
/** @type {boolean} */
|
|
27
|
-
this.forceInitial = forceInitial;
|
|
38
|
+
this.forceInitial = options.forceInitial;
|
|
28
39
|
|
|
29
40
|
/** @type {Node[]} */
|
|
30
41
|
this._storedNodes = [];
|
|
@@ -40,7 +51,12 @@ export class SlotObserver {
|
|
|
40
51
|
};
|
|
41
52
|
|
|
42
53
|
this.connect();
|
|
43
|
-
|
|
54
|
+
|
|
55
|
+
if (options.syncInitial) {
|
|
56
|
+
this.flush();
|
|
57
|
+
} else {
|
|
58
|
+
this._schedule();
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
|
|
46
62
|
/**
|
|
@@ -69,7 +85,11 @@ export class SlotObserver {
|
|
|
69
85
|
this._scheduled = true;
|
|
70
86
|
|
|
71
87
|
queueMicrotask(() => {
|
|
72
|
-
|
|
88
|
+
// Skip if the nodes have already been processed by an explicit `flush()`
|
|
89
|
+
// in the meantime, to avoid running the diff a second time for nothing.
|
|
90
|
+
if (this._scheduled) {
|
|
91
|
+
this.flush();
|
|
92
|
+
}
|
|
73
93
|
});
|
|
74
94
|
}
|
|
75
95
|
}
|
|
@@ -83,10 +83,12 @@ addGlobalStyles(
|
|
|
83
83
|
--_vaadin-icon-arrow-up: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m5 12 7-7 7 7"/><path d="M12 19V5"/></svg>');
|
|
84
84
|
--_vaadin-icon-calendar: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/></svg>');
|
|
85
85
|
--_vaadin-icon-checkmark: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" /></svg>');
|
|
86
|
+
--_vaadin-icon-checkmark-small: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" /></svg>');
|
|
86
87
|
--_vaadin-icon-chevron-down: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>');
|
|
87
88
|
--_vaadin-icon-chevron-right: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>');
|
|
88
89
|
--_vaadin-icon-clock: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 6v6l4 2"/><circle cx="12" cy="12" r="10"/></svg>');
|
|
89
90
|
--_vaadin-icon-cross: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" /></svg>');
|
|
91
|
+
--_vaadin-icon-cross-small: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" /></svg>');
|
|
90
92
|
--_vaadin-icon-drag: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"><path d="M11 7c0 .82843-.6716 1.5-1.5 1.5C8.67157 8.5 8 7.82843 8 7s.67157-1.5 1.5-1.5c.8284 0 1.5.67157 1.5 1.5Zm0 5c0 .8284-.6716 1.5-1.5 1.5-.82843 0-1.5-.6716-1.5-1.5s.67157-1.5 1.5-1.5c.8284 0 1.5.6716 1.5 1.5Zm0 5c0 .8284-.6716 1.5-1.5 1.5-.82843 0-1.5-.6716-1.5-1.5s.67157-1.5 1.5-1.5c.8284 0 1.5.6716 1.5 1.5Zm5-10c0 .82843-.6716 1.5-1.5 1.5S13 7.82843 13 7s.6716-1.5 1.5-1.5S16 6.17157 16 7Zm0 5c0 .8284-.6716 1.5-1.5 1.5S13 12.8284 13 12s.6716-1.5 1.5-1.5 1.5.6716 1.5 1.5Zm0 5c0 .8284-.6716 1.5-1.5 1.5S13 17.8284 13 17s.6716-1.5 1.5-1.5 1.5.6716 1.5 1.5Z" fill="currentColor"/></svg>');
|
|
91
93
|
--_vaadin-icon-ellipsis: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>');
|
|
92
94
|
--_vaadin-icon-eye: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" /><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" /></svg>');
|
|
@@ -14,7 +14,6 @@ export class TooltipController extends SlotController {
|
|
|
14
14
|
super(host, 'tooltip');
|
|
15
15
|
|
|
16
16
|
this.setTarget(host);
|
|
17
|
-
this.__onContentChange = this.__onContentChange.bind(this);
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -50,8 +49,8 @@ export class TooltipController extends SlotController {
|
|
|
50
49
|
if (!this.manual) {
|
|
51
50
|
this.host.setAttribute('has-tooltip', '');
|
|
52
51
|
}
|
|
53
|
-
this
|
|
54
|
-
tooltipNode.addEventListener('content-changed', this
|
|
52
|
+
this.#notifyChange(tooltipNode);
|
|
53
|
+
tooltipNode.addEventListener('content-changed', this.#onContentChange);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/**
|
|
@@ -65,8 +64,8 @@ export class TooltipController extends SlotController {
|
|
|
65
64
|
if (!this.manual) {
|
|
66
65
|
this.host.removeAttribute('has-tooltip');
|
|
67
66
|
}
|
|
68
|
-
tooltipNode.removeEventListener('content-changed', this
|
|
69
|
-
this
|
|
67
|
+
tooltipNode.removeEventListener('content-changed', this.#onContentChange);
|
|
68
|
+
this.#notifyChange(null);
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
/**
|
|
@@ -179,13 +178,11 @@ export class TooltipController extends SlotController {
|
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
180
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
181
|
+
#onContentChange = (event) => {
|
|
182
|
+
this.#notifyChange(event.target);
|
|
183
|
+
};
|
|
186
184
|
|
|
187
|
-
|
|
188
|
-
__notifyChange(node) {
|
|
185
|
+
#notifyChange(node) {
|
|
189
186
|
this.dispatchEvent(new CustomEvent('tooltip-changed', { detail: { node } }));
|
|
190
187
|
}
|
|
191
188
|
}
|
|
@@ -78,17 +78,17 @@ export class IronListAdapter {
|
|
|
78
78
|
});
|
|
79
79
|
attachObserver.observe(this.scrollTarget);
|
|
80
80
|
|
|
81
|
-
this.
|
|
82
|
-
this.elementsContainer.addEventListener('focusin', () => {
|
|
83
|
-
this.scrollTarget.dispatchEvent(
|
|
84
|
-
new CustomEvent('virtualizer-element-focused', { detail: { element: this.__getFocusedElement() } }),
|
|
85
|
-
);
|
|
86
|
-
});
|
|
81
|
+
this.elementsContainer.addEventListener('focusin', () => this.__onElementFocused());
|
|
87
82
|
|
|
88
83
|
if (this.reorderElements) {
|
|
89
84
|
// Reordering the physical elements cancels the user's grab of the scroll bar handle on Safari.
|
|
90
85
|
// Need to defer reordering until the user lets go of the scroll bar handle.
|
|
91
|
-
this.scrollTarget.addEventListener('mousedown', () => {
|
|
86
|
+
this.scrollTarget.addEventListener('mousedown', (event) => {
|
|
87
|
+
// Only handle clicks on the scroll target itself
|
|
88
|
+
if (event.target !== this.scrollTarget) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
92
|
this.__mouseDown = true;
|
|
93
93
|
});
|
|
94
94
|
this.scrollTarget.addEventListener('mouseup', () => {
|
|
@@ -156,7 +156,7 @@ export class IronListAdapter {
|
|
|
156
156
|
this.__skipNextVirtualIndexAdjust = true;
|
|
157
157
|
super.scrollToIndex(targetVirtualIndex);
|
|
158
158
|
|
|
159
|
-
if (this.adjustedFirstVisibleIndex !== index && this._scrollTop < this._maxScrollTop
|
|
159
|
+
if (this.adjustedFirstVisibleIndex !== index && this._scrollTop < this._maxScrollTop) {
|
|
160
160
|
// Workaround an iron-list issue by manually adjusting the scroll position
|
|
161
161
|
this._scrollTop -= this.__getIndexScrollOffset(index) || 0;
|
|
162
162
|
}
|
|
@@ -184,9 +184,6 @@ export class IronListAdapter {
|
|
|
184
184
|
if (this.__scrollReorderDebouncer) {
|
|
185
185
|
this.__scrollReorderDebouncer.flush();
|
|
186
186
|
}
|
|
187
|
-
if (this.__debouncerWheelAnimationFrame) {
|
|
188
|
-
this.__debouncerWheelAnimationFrame.flush();
|
|
189
|
-
}
|
|
190
187
|
}
|
|
191
188
|
|
|
192
189
|
hostConnected() {
|
|
@@ -409,6 +406,8 @@ export class IronListAdapter {
|
|
|
409
406
|
requestAnimationFrame(() => this._resizeHandler());
|
|
410
407
|
}
|
|
411
408
|
|
|
409
|
+
this._updateScrollerSize(true);
|
|
410
|
+
|
|
412
411
|
// Re-render items once the scroll position has been restored.
|
|
413
412
|
// This call also updates the cached scrollTarget height and
|
|
414
413
|
// rechecks whether more virtual elements are needed, since the
|
|
@@ -455,16 +454,10 @@ export class IronListAdapter {
|
|
|
455
454
|
|
|
456
455
|
/** @private */
|
|
457
456
|
updateViewportBoundaries() {
|
|
458
|
-
|
|
459
|
-
this._scrollerPaddingTop = this.scrollTarget === this ? 0 : parseInt(styles['padding-top'], 10);
|
|
460
|
-
this._isRTL = Boolean(styles.direction === 'rtl');
|
|
461
|
-
this._viewportWidth = this.elementsContainer.offsetWidth;
|
|
457
|
+
this._scrollerPaddingTop = parseInt(window.getComputedStyle(this.scrollTarget)['padding-top'], 10);
|
|
462
458
|
this._viewportHeight = this.scrollTarget.offsetHeight;
|
|
463
459
|
}
|
|
464
460
|
|
|
465
|
-
/** @private */
|
|
466
|
-
setAttribute() {}
|
|
467
|
-
|
|
468
461
|
/** @private */
|
|
469
462
|
_createPool(size) {
|
|
470
463
|
const physicalItems = this.createElements(size);
|
|
@@ -514,20 +507,8 @@ export class IronListAdapter {
|
|
|
514
507
|
toggleScrollListener() {}
|
|
515
508
|
|
|
516
509
|
/** @private */
|
|
517
|
-
__getFocusedElement(
|
|
518
|
-
|
|
519
|
-
// focus lives in a nested shadow tree. Descend through nested shadow
|
|
520
|
-
// roots' `activeElement`s to reach the real focused node, then walk up
|
|
521
|
-
// the flattened tree (via `assignedSlot`/`parentNode`/`host`) until a
|
|
522
|
-
// visible row is reached.
|
|
523
|
-
let node = document.activeElement;
|
|
524
|
-
while (node?.shadowRoot?.activeElement) {
|
|
525
|
-
node = node.shadowRoot.activeElement;
|
|
526
|
-
}
|
|
527
|
-
while (node && !visibleElements.includes(node)) {
|
|
528
|
-
node = node.assignedSlot || node.parentNode || node.host;
|
|
529
|
-
}
|
|
530
|
-
return node;
|
|
510
|
+
__getFocusedElement() {
|
|
511
|
+
return this.__getVisibleElements().find((element) => element.matches(':focus-within'));
|
|
531
512
|
}
|
|
532
513
|
|
|
533
514
|
/** @private */
|
|
@@ -551,12 +532,12 @@ export class IronListAdapter {
|
|
|
551
532
|
}
|
|
552
533
|
|
|
553
534
|
/** @private */
|
|
554
|
-
__onElementFocused(
|
|
535
|
+
__onElementFocused() {
|
|
555
536
|
if (!this.reorderElements) {
|
|
556
537
|
return;
|
|
557
538
|
}
|
|
558
539
|
|
|
559
|
-
const focusedElement =
|
|
540
|
+
const focusedElement = this.__getFocusedElement();
|
|
560
541
|
if (!focusedElement) {
|
|
561
542
|
return;
|
|
562
543
|
}
|
|
@@ -798,7 +779,7 @@ export class IronListAdapter {
|
|
|
798
779
|
|
|
799
780
|
// Which row to use as a target?
|
|
800
781
|
const visibleElements = this.__getVisibleElements();
|
|
801
|
-
const targetElement = this.__getFocusedElement(
|
|
782
|
+
const targetElement = this.__getFocusedElement() || visibleElements[0];
|
|
802
783
|
if (!targetElement) {
|
|
803
784
|
// All elements are hidden, don't reorder
|
|
804
785
|
return;
|