@vaadin/component-base 24.6.0-alpha8 → 24.6.0-alpha9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/define.js +43 -1
- package/src/polylit-mixin.js +22 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/component-base",
|
|
3
|
-
"version": "24.6.0-
|
|
3
|
+
"version": "24.6.0-alpha9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"lit": "^3.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@vaadin/chai-plugins": "24.6.0-
|
|
41
|
+
"@vaadin/chai-plugins": "24.6.0-alpha9",
|
|
42
42
|
"@vaadin/testing-helpers": "^1.0.0",
|
|
43
43
|
"sinon": "^18.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e303d77ba20c3089c9998be9a318733d9ec5b53c"
|
|
46
46
|
}
|
package/src/define.js
CHANGED
|
@@ -4,13 +4,55 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
window.Vaadin ||= {};
|
|
8
|
+
window.Vaadin.featureFlags ||= {};
|
|
9
|
+
|
|
10
|
+
function dashToCamelCase(dash) {
|
|
11
|
+
return dash.replace(/-[a-z]/gu, (m) => m[1].toUpperCase());
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const experimentalMap = {};
|
|
15
|
+
|
|
16
|
+
export function defineCustomElement(CustomElement, version = '24.6.0-alpha9') {
|
|
8
17
|
Object.defineProperty(CustomElement, 'version', {
|
|
9
18
|
get() {
|
|
10
19
|
return version;
|
|
11
20
|
},
|
|
12
21
|
});
|
|
13
22
|
|
|
23
|
+
if (CustomElement.experimental) {
|
|
24
|
+
const featureFlagKey =
|
|
25
|
+
typeof CustomElement.experimental === 'string'
|
|
26
|
+
? CustomElement.experimental
|
|
27
|
+
: `${dashToCamelCase(CustomElement.is.split('-').slice(1).join('-'))}Component`;
|
|
28
|
+
|
|
29
|
+
if (!window.Vaadin.featureFlags[featureFlagKey] && !experimentalMap[featureFlagKey]) {
|
|
30
|
+
// Add setter to define experimental component when it's set to true
|
|
31
|
+
experimentalMap[featureFlagKey] = new Set();
|
|
32
|
+
experimentalMap[featureFlagKey].add(CustomElement);
|
|
33
|
+
|
|
34
|
+
Object.defineProperty(window.Vaadin.featureFlags, featureFlagKey, {
|
|
35
|
+
get() {
|
|
36
|
+
return experimentalMap[featureFlagKey].size === 0;
|
|
37
|
+
},
|
|
38
|
+
set(value) {
|
|
39
|
+
if (!!value && experimentalMap[featureFlagKey].size > 0) {
|
|
40
|
+
experimentalMap[featureFlagKey].forEach((elementClass) => {
|
|
41
|
+
customElements.define(elementClass.is, elementClass);
|
|
42
|
+
});
|
|
43
|
+
experimentalMap[featureFlagKey].clear();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return;
|
|
49
|
+
} else if (experimentalMap[featureFlagKey]) {
|
|
50
|
+
// Allow to register multiple components with single flag
|
|
51
|
+
experimentalMap[featureFlagKey].add(CustomElement);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
14
56
|
const defined = customElements.get(CustomElement.is);
|
|
15
57
|
if (!defined) {
|
|
16
58
|
customElements.define(CustomElement.is, CustomElement);
|
package/src/polylit-mixin.js
CHANGED
|
@@ -217,12 +217,16 @@ const PolylitMixinImplementation = (superclass) => {
|
|
|
217
217
|
this.__runObservers(props, this.constructor.__observers);
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
if (this.__dynamicPropertyObservers) {
|
|
221
|
+
this.__runDynamicObservers(props, this.__dynamicPropertyObservers);
|
|
222
|
+
}
|
|
223
|
+
|
|
220
224
|
if (this.constructor.__complexObservers) {
|
|
221
225
|
this.__runComplexObservers(props, this.constructor.__complexObservers);
|
|
222
226
|
}
|
|
223
227
|
|
|
224
|
-
if (this.
|
|
225
|
-
this.__runComplexObservers(props, this.
|
|
228
|
+
if (this.__dynamicMethodObservers) {
|
|
229
|
+
this.__runComplexObservers(props, this.__dynamicMethodObservers);
|
|
226
230
|
}
|
|
227
231
|
|
|
228
232
|
if (this.constructor.__notifyProps) {
|
|
@@ -257,11 +261,17 @@ const PolylitMixinImplementation = (superclass) => {
|
|
|
257
261
|
|
|
258
262
|
/** @protected */
|
|
259
263
|
_createMethodObserver(observer) {
|
|
260
|
-
const dynamicObservers = getOrCreateMap(this, '
|
|
264
|
+
const dynamicObservers = getOrCreateMap(this, '__dynamicMethodObservers');
|
|
261
265
|
const { method, observerProps } = parseObserver(observer);
|
|
262
266
|
dynamicObservers.set(method, observerProps);
|
|
263
267
|
}
|
|
264
268
|
|
|
269
|
+
/** @protected */
|
|
270
|
+
_createPropertyObserver(property, method) {
|
|
271
|
+
const dynamicObservers = getOrCreateMap(this, '__dynamicPropertyObservers');
|
|
272
|
+
dynamicObservers.set(method, property);
|
|
273
|
+
}
|
|
274
|
+
|
|
265
275
|
/** @private */
|
|
266
276
|
__runComplexObservers(props, observers) {
|
|
267
277
|
observers.forEach((observerProps, method) => {
|
|
@@ -275,6 +285,15 @@ const PolylitMixinImplementation = (superclass) => {
|
|
|
275
285
|
});
|
|
276
286
|
}
|
|
277
287
|
|
|
288
|
+
/** @private */
|
|
289
|
+
__runDynamicObservers(props, observers) {
|
|
290
|
+
observers.forEach((prop, method) => {
|
|
291
|
+
if (props.has(prop) && this[method]) {
|
|
292
|
+
this[method](this[prop], props.get(prop));
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
278
297
|
/** @private */
|
|
279
298
|
__runObservers(props, observers) {
|
|
280
299
|
props.forEach((v, k) => {
|