@schukai/monster 4.148.1 → 4.148.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/package.json +1 -1
- package/source/components/datatable/filter/date-presets.mjs +13 -0
- package/source/components/datatable/filter/date-range.mjs +12 -0
- package/source/components/datatable/filter/date-time.mjs +14 -1
- package/source/components/datatable/filter/date.mjs +14 -1
- package/source/components/datatable/filter/input.mjs +14 -1
- package/source/components/datatable/filter/range.mjs +11 -0
- package/source/components/datatable/filter/text-operator.mjs +19 -0
- package/source/components/datatable/filter/time.mjs +14 -1
- package/source/components/form/buy-box.mjs +2 -0
- package/source/components/form/cart-control.mjs +2 -0
- package/source/components/state/state.mjs +2 -0
- package/source/data/extend.mjs +7 -1
- package/source/data/pathfinder.mjs +44 -6
- package/source/dom/customcontrol.mjs +28 -23
- package/source/dom/customelement.mjs +105 -39
- package/source/dom/updater.mjs +76 -25
- package/source/dom/util/extract-keys.mjs +2 -1
- package/source/dom/util/init-options-from-attributes.mjs +1 -1
- package/source/dom/util/set-option-from-attribute.mjs +14 -3
- package/source/types/proxyobserver.mjs +15 -0
- package/source/util/clone.mjs +8 -6
- package/test/cases/components/datatable/filter-form-value.mjs +98 -0
- package/test/cases/components/form/non-value-form-association.mjs +53 -0
- package/test/cases/data/extend.mjs +27 -1
- package/test/cases/data/pathfinder.mjs +105 -1
- package/test/cases/dom/customcontrol.mjs +188 -6
- package/test/cases/dom/customelement-initfromscripthost.mjs +62 -0
- package/test/cases/dom/customelement.mjs +123 -2
- package/test/cases/dom/updater.mjs +293 -0
- package/test/cases/dom/util/extract-keys.mjs +14 -0
- package/test/cases/dom/util/init-options-from-attributes.mjs +18 -0
- package/test/cases/dom/util/set-option-from-attribute.mjs +151 -0
- package/test/cases/types/proxyobserver.mjs +52 -0
- package/test/cases/util/clone.mjs +24 -0
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.148.
|
|
1
|
+
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.6"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"4.148.3"}
|
|
@@ -88,6 +88,8 @@ class DatePresets extends CustomControl {
|
|
|
88
88
|
|
|
89
89
|
initControlReferences.call(this);
|
|
90
90
|
updateOptions.call(this);
|
|
91
|
+
initEventHandler.call(this);
|
|
92
|
+
syncFormValue.call(this);
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/**
|
|
@@ -104,6 +106,7 @@ class DatePresets extends CustomControl {
|
|
|
104
106
|
*/
|
|
105
107
|
set value(value) {
|
|
106
108
|
this[selectElementSymbol].value = value;
|
|
109
|
+
syncFormValue.call(this);
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
/**
|
|
@@ -340,6 +343,16 @@ function initControlReferences() {
|
|
|
340
343
|
return this;
|
|
341
344
|
}
|
|
342
345
|
|
|
346
|
+
function initEventHandler() {
|
|
347
|
+
this[selectElementSymbol].addEventListener("change", () => {
|
|
348
|
+
syncFormValue.call(this);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function syncFormValue() {
|
|
353
|
+
this.setFormValue(this.value);
|
|
354
|
+
}
|
|
355
|
+
|
|
343
356
|
/**
|
|
344
357
|
* @private
|
|
345
358
|
* @return {void}
|
|
@@ -166,6 +166,7 @@ class DateRange extends AbstractBase {
|
|
|
166
166
|
|
|
167
167
|
initControlReferences.call(this);
|
|
168
168
|
initEventHandler.call(this);
|
|
169
|
+
syncFormValue.call(this);
|
|
169
170
|
}
|
|
170
171
|
|
|
171
172
|
/**
|
|
@@ -175,6 +176,7 @@ class DateRange extends AbstractBase {
|
|
|
175
176
|
*/
|
|
176
177
|
set value(value) {
|
|
177
178
|
this[inputElementSymbol].value = value;
|
|
179
|
+
syncFormValue.call(this);
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
/**
|
|
@@ -580,6 +582,7 @@ function initEventHandler() {
|
|
|
580
582
|
|
|
581
583
|
if (type === "today") {
|
|
582
584
|
this[inputElementSymbol].value = new Date().toISOString().slice(0, 10);
|
|
585
|
+
syncFormValue.call(this);
|
|
583
586
|
return;
|
|
584
587
|
}
|
|
585
588
|
|
|
@@ -609,10 +612,14 @@ function initEventHandler() {
|
|
|
609
612
|
|
|
610
613
|
// change the input value if the user change the value of the radio button
|
|
611
614
|
this[inputElementSymbol].addEventListener("change", (event) => {
|
|
615
|
+
syncFormValue.call(this);
|
|
612
616
|
queueMicrotask(() => {
|
|
613
617
|
updatePopperInputsFromMainValue.call(this);
|
|
614
618
|
});
|
|
615
619
|
});
|
|
620
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
621
|
+
syncFormValue.call(this);
|
|
622
|
+
});
|
|
616
623
|
|
|
617
624
|
// if the user change the value of on of the input fields, we should update the value of the input field
|
|
618
625
|
this[formContainerElementSymbol].addEventListener("change", (event) => {
|
|
@@ -636,6 +643,7 @@ function initEventHandler() {
|
|
|
636
643
|
|
|
637
644
|
const type = group.getAttribute("data-monster-range-type");
|
|
638
645
|
updateMainFilterValueFromPopperChange.call(this, group, type);
|
|
646
|
+
syncFormValue.call(this);
|
|
639
647
|
});
|
|
640
648
|
|
|
641
649
|
this.addEventListener("keydown", (event) => {
|
|
@@ -669,6 +677,10 @@ function initEventHandler() {
|
|
|
669
677
|
return this;
|
|
670
678
|
}
|
|
671
679
|
|
|
680
|
+
function syncFormValue() {
|
|
681
|
+
this.setFormValue(this.value);
|
|
682
|
+
}
|
|
683
|
+
|
|
672
684
|
/**
|
|
673
685
|
* @private
|
|
674
686
|
*/
|
|
@@ -85,6 +85,7 @@ class DateTimeFilter extends CustomControl {
|
|
|
85
85
|
|
|
86
86
|
initControlReferences.call(this);
|
|
87
87
|
initEventHandler.call(this);
|
|
88
|
+
syncFormValue.call(this);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
@@ -101,6 +102,7 @@ class DateTimeFilter extends CustomControl {
|
|
|
101
102
|
*/
|
|
102
103
|
set value(value) {
|
|
103
104
|
this[inputElementSymbol].value = value;
|
|
105
|
+
syncFormValue.call(this);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/**
|
|
@@ -129,7 +131,18 @@ function initControlReferences() {
|
|
|
129
131
|
/**
|
|
130
132
|
* @private
|
|
131
133
|
*/
|
|
132
|
-
function initEventHandler() {
|
|
134
|
+
function initEventHandler() {
|
|
135
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
136
|
+
syncFormValue.call(this);
|
|
137
|
+
});
|
|
138
|
+
this[inputElementSymbol].addEventListener("change", () => {
|
|
139
|
+
syncFormValue.call(this);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function syncFormValue() {
|
|
144
|
+
this.setFormValue(this.value);
|
|
145
|
+
}
|
|
133
146
|
|
|
134
147
|
/**
|
|
135
148
|
* @private
|
|
@@ -85,6 +85,7 @@ class DateFilter extends CustomControl {
|
|
|
85
85
|
|
|
86
86
|
initControlReferences.call(this);
|
|
87
87
|
initEventHandler.call(this);
|
|
88
|
+
syncFormValue.call(this);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
@@ -101,6 +102,7 @@ class DateFilter extends CustomControl {
|
|
|
101
102
|
*/
|
|
102
103
|
set value(value) {
|
|
103
104
|
this[inputElementSymbol].value = value;
|
|
105
|
+
syncFormValue.call(this);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/**
|
|
@@ -129,7 +131,18 @@ function initControlReferences() {
|
|
|
129
131
|
/**
|
|
130
132
|
* @private
|
|
131
133
|
*/
|
|
132
|
-
function initEventHandler() {
|
|
134
|
+
function initEventHandler() {
|
|
135
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
136
|
+
syncFormValue.call(this);
|
|
137
|
+
});
|
|
138
|
+
this[inputElementSymbol].addEventListener("change", () => {
|
|
139
|
+
syncFormValue.call(this);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function syncFormValue() {
|
|
144
|
+
this.setFormValue(this.value);
|
|
145
|
+
}
|
|
133
146
|
|
|
134
147
|
/**
|
|
135
148
|
* @private
|
|
@@ -84,6 +84,7 @@ class Input extends AbstractBase {
|
|
|
84
84
|
|
|
85
85
|
initControlReferences.call(this);
|
|
86
86
|
initEventHandler.call(this);
|
|
87
|
+
syncFormValue.call(this);
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
/**
|
|
@@ -100,6 +101,7 @@ class Input extends AbstractBase {
|
|
|
100
101
|
*/
|
|
101
102
|
set value(value) {
|
|
102
103
|
this[inputElementSymbol].value = value;
|
|
104
|
+
syncFormValue.call(this);
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
/**
|
|
@@ -175,7 +177,18 @@ function initControlReferences() {
|
|
|
175
177
|
/**
|
|
176
178
|
* @private
|
|
177
179
|
*/
|
|
178
|
-
function initEventHandler() {
|
|
180
|
+
function initEventHandler() {
|
|
181
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
182
|
+
syncFormValue.call(this);
|
|
183
|
+
});
|
|
184
|
+
this[inputElementSymbol].addEventListener("change", () => {
|
|
185
|
+
syncFormValue.call(this);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function syncFormValue() {
|
|
190
|
+
this.setFormValue(this.value);
|
|
191
|
+
}
|
|
179
192
|
|
|
180
193
|
/**
|
|
181
194
|
* @private
|
|
@@ -136,6 +136,7 @@ class Range extends AbstractBase {
|
|
|
136
136
|
|
|
137
137
|
initControlReferences.call(this);
|
|
138
138
|
initEventHandler.call(this);
|
|
139
|
+
syncFormValue.call(this);
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
/**
|
|
@@ -145,6 +146,7 @@ class Range extends AbstractBase {
|
|
|
145
146
|
*/
|
|
146
147
|
set value(value) {
|
|
147
148
|
this[inputElementSymbol].value = value;
|
|
149
|
+
syncFormValue.call(this);
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/**
|
|
@@ -484,12 +486,17 @@ function initEventHandler() {
|
|
|
484
486
|
const type = typeElement.getAttribute("data-monster-range-type");
|
|
485
487
|
const value = element.value;
|
|
486
488
|
updateFilterValue(type, this, value, element);
|
|
489
|
+
syncFormValue.call(this);
|
|
487
490
|
});
|
|
488
491
|
|
|
489
492
|
// we should watch the change event of self[inputElementSymbol] and call updateInputFromValue
|
|
490
493
|
// if the value is changed from outside
|
|
491
494
|
this[inputElementSymbol].addEventListener("change", () => {
|
|
492
495
|
updateInputFromValue.call(this);
|
|
496
|
+
syncFormValue.call(this);
|
|
497
|
+
});
|
|
498
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
499
|
+
syncFormValue.call(this);
|
|
493
500
|
});
|
|
494
501
|
|
|
495
502
|
this.addEventListener("keydown", (event) => {
|
|
@@ -537,6 +544,10 @@ function initEventHandler() {
|
|
|
537
544
|
return this;
|
|
538
545
|
}
|
|
539
546
|
|
|
547
|
+
function syncFormValue() {
|
|
548
|
+
this.setFormValue(this.value);
|
|
549
|
+
}
|
|
550
|
+
|
|
540
551
|
/**
|
|
541
552
|
* @private
|
|
542
553
|
*/
|
|
@@ -103,6 +103,8 @@ class TextOperator extends CustomControl {
|
|
|
103
103
|
|
|
104
104
|
initControlReferences.call(this);
|
|
105
105
|
updateOptions.call(this);
|
|
106
|
+
initEventHandler.call(this);
|
|
107
|
+
syncFormValue.call(this);
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
/**
|
|
@@ -121,6 +123,7 @@ class TextOperator extends CustomControl {
|
|
|
121
123
|
const parsed = parseValue(value);
|
|
122
124
|
this[operatorElementSymbol].value = parsed.operator;
|
|
123
125
|
this[inputElementSymbol].value = parsed.query;
|
|
126
|
+
syncFormValue.call(this);
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
/**
|
|
@@ -327,6 +330,22 @@ function initControlReferences() {
|
|
|
327
330
|
return this;
|
|
328
331
|
}
|
|
329
332
|
|
|
333
|
+
function initEventHandler() {
|
|
334
|
+
this[operatorElementSymbol].addEventListener("change", () => {
|
|
335
|
+
syncFormValue.call(this);
|
|
336
|
+
});
|
|
337
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
338
|
+
syncFormValue.call(this);
|
|
339
|
+
});
|
|
340
|
+
this[inputElementSymbol].addEventListener("change", () => {
|
|
341
|
+
syncFormValue.call(this);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function syncFormValue() {
|
|
346
|
+
this.setFormValue(this.value);
|
|
347
|
+
}
|
|
348
|
+
|
|
330
349
|
/**
|
|
331
350
|
* @private
|
|
332
351
|
* @return {void}
|
|
@@ -85,6 +85,7 @@ class TimeFilter extends CustomControl {
|
|
|
85
85
|
|
|
86
86
|
initControlReferences.call(this);
|
|
87
87
|
initEventHandler.call(this);
|
|
88
|
+
syncFormValue.call(this);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/**
|
|
@@ -101,6 +102,7 @@ class TimeFilter extends CustomControl {
|
|
|
101
102
|
*/
|
|
102
103
|
set value(value) {
|
|
103
104
|
this[inputElementSymbol].value = value;
|
|
105
|
+
syncFormValue.call(this);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/**
|
|
@@ -129,7 +131,18 @@ function initControlReferences() {
|
|
|
129
131
|
/**
|
|
130
132
|
* @private
|
|
131
133
|
*/
|
|
132
|
-
function initEventHandler() {
|
|
134
|
+
function initEventHandler() {
|
|
135
|
+
this[inputElementSymbol].addEventListener("input", () => {
|
|
136
|
+
syncFormValue.call(this);
|
|
137
|
+
});
|
|
138
|
+
this[inputElementSymbol].addEventListener("change", () => {
|
|
139
|
+
syncFormValue.call(this);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function syncFormValue() {
|
|
144
|
+
this.setFormValue(this.value);
|
|
145
|
+
}
|
|
133
146
|
|
|
134
147
|
/**
|
|
135
148
|
* @private
|
|
@@ -200,6 +200,8 @@ const pricingCacheSymbol = Symbol("pricingCache");
|
|
|
200
200
|
* @fires monster-buy-box-loaded
|
|
201
201
|
*/
|
|
202
202
|
class BuyBox extends CustomControl {
|
|
203
|
+
static formAssociated = false;
|
|
204
|
+
|
|
203
205
|
/**
|
|
204
206
|
* This method is called by the `instanceof` operator.
|
|
205
207
|
* @return {symbol}
|
|
@@ -89,6 +89,8 @@ const pendingRequestSymbol = Symbol("pendingRequest");
|
|
|
89
89
|
* @fires monster-cart-control-update
|
|
90
90
|
*/
|
|
91
91
|
class CartControl extends CustomControl {
|
|
92
|
+
static formAssociated = false;
|
|
93
|
+
|
|
92
94
|
static get [instanceSymbol]() {
|
|
93
95
|
return Symbol.for(
|
|
94
96
|
"@schukai/monster/components/form/cart-control@@instance",
|
package/source/data/extend.mjs
CHANGED
|
@@ -17,6 +17,8 @@ import { typeOf } from "../types/typeof.mjs";
|
|
|
17
17
|
|
|
18
18
|
export { extend };
|
|
19
19
|
|
|
20
|
+
const unsafeMutationKeys = new Set(["__proto__", "prototype", "constructor"]);
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* Extend copies all enumerable own properties from one or
|
|
22
24
|
* more source objects to a target object. It returns the modified target object.
|
|
@@ -50,7 +52,11 @@ function extend(...args) {
|
|
|
50
52
|
continue;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
for (const k
|
|
55
|
+
for (const k of Object.keys(a)) {
|
|
56
|
+
if (unsafeMutationKeys.has(k)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
const v = a?.[k];
|
|
55
61
|
|
|
56
62
|
if (k in o && v === o?.[k]) {
|
|
@@ -43,6 +43,17 @@ const DELIMITER = ".";
|
|
|
43
43
|
*/
|
|
44
44
|
const WILDCARD = "*";
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Path segments that must never be traversed by mutation operations.
|
|
48
|
+
* @private
|
|
49
|
+
* @type {Set<string>}
|
|
50
|
+
*/
|
|
51
|
+
const UNSAFE_MUTATION_PATH_SEGMENTS = new Set([
|
|
52
|
+
"__proto__",
|
|
53
|
+
"constructor",
|
|
54
|
+
"prototype",
|
|
55
|
+
]);
|
|
56
|
+
|
|
46
57
|
/**
|
|
47
58
|
* Pathfinder is a class to find a path to an object.
|
|
48
59
|
*
|
|
@@ -245,7 +256,12 @@ function getValueViaPath(subject, path, check) {
|
|
|
245
256
|
}
|
|
246
257
|
|
|
247
258
|
let parts;
|
|
248
|
-
if (
|
|
259
|
+
if (isArray(path)) {
|
|
260
|
+
if (path.length === 0) {
|
|
261
|
+
return subject;
|
|
262
|
+
}
|
|
263
|
+
parts = [...path];
|
|
264
|
+
} else {
|
|
249
265
|
if (path === "") {
|
|
250
266
|
return subject;
|
|
251
267
|
}
|
|
@@ -263,10 +279,12 @@ function getValueViaPath(subject, path, check) {
|
|
|
263
279
|
let anchor;
|
|
264
280
|
if (subject instanceof Map || subject instanceof WeakMap) {
|
|
265
281
|
anchor = subject.get(current);
|
|
266
|
-
} else if (subject instanceof Set
|
|
282
|
+
} else if (subject instanceof Set) {
|
|
267
283
|
current = parseInt(current);
|
|
268
284
|
validateInteger(current);
|
|
269
285
|
anchor = [...subject]?.[current];
|
|
286
|
+
} else if (subject instanceof WeakSet) {
|
|
287
|
+
throw Error("unsupported action for this data type (WeakSet)");
|
|
270
288
|
} else if (typeof WeakRef === "function" && subject instanceof WeakRef) {
|
|
271
289
|
throw Error("unsupported action for this data type (WeakRef)");
|
|
272
290
|
} else if (isArray(subject)) {
|
|
@@ -318,6 +336,7 @@ function setValueViaPath(subject, path, value) {
|
|
|
318
336
|
if (!(isArray(path) || isString(path))) {
|
|
319
337
|
throw new Error("type error: a path must be a string or an array");
|
|
320
338
|
}
|
|
339
|
+
validateMutationPath(path);
|
|
321
340
|
|
|
322
341
|
let parts;
|
|
323
342
|
if (isArray(path)) {
|
|
@@ -325,7 +344,7 @@ function setValueViaPath(subject, path, value) {
|
|
|
325
344
|
return;
|
|
326
345
|
}
|
|
327
346
|
|
|
328
|
-
parts = path;
|
|
347
|
+
parts = [...path];
|
|
329
348
|
} else {
|
|
330
349
|
parts = path.split(DELIMITER);
|
|
331
350
|
}
|
|
@@ -370,8 +389,10 @@ function setValueViaPath(subject, path, value) {
|
|
|
370
389
|
|
|
371
390
|
if (anchor instanceof Map || anchor instanceof WeakMap) {
|
|
372
391
|
anchor.set(last, value);
|
|
373
|
-
} else if (anchor instanceof Set
|
|
374
|
-
anchor.
|
|
392
|
+
} else if (anchor instanceof Set) {
|
|
393
|
+
anchor.add(value);
|
|
394
|
+
} else if (anchor instanceof WeakSet) {
|
|
395
|
+
throw Error("unsupported action for this data type in setValueViaPath");
|
|
375
396
|
} else if (typeof WeakRef === "function" && anchor instanceof WeakRef) {
|
|
376
397
|
throw Error("unsupported action for this data type in setValueViaPath");
|
|
377
398
|
} else if (isArray(anchor)) {
|
|
@@ -421,6 +442,7 @@ function deleteValueViaPath(subject, path) {
|
|
|
421
442
|
"type error: a path must be a string or an array in deleteValueViaPath",
|
|
422
443
|
);
|
|
423
444
|
}
|
|
445
|
+
validateMutationPath(path);
|
|
424
446
|
|
|
425
447
|
let parts;
|
|
426
448
|
if (isArray(path)) {
|
|
@@ -428,7 +450,7 @@ function deleteValueViaPath(subject, path) {
|
|
|
428
450
|
return;
|
|
429
451
|
}
|
|
430
452
|
|
|
431
|
-
parts = path;
|
|
453
|
+
parts = [...path];
|
|
432
454
|
} else {
|
|
433
455
|
parts = path.split(DELIMITER);
|
|
434
456
|
}
|
|
@@ -455,3 +477,19 @@ function deleteValueViaPath(subject, path) {
|
|
|
455
477
|
delete anchor[last];
|
|
456
478
|
}
|
|
457
479
|
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Reject paths that could mutate an object's prototype chain.
|
|
483
|
+
* @param {string|array} path
|
|
484
|
+
* @return {void}
|
|
485
|
+
* @throws {Error} unsafe mutation path segment
|
|
486
|
+
* @private
|
|
487
|
+
*/
|
|
488
|
+
function validateMutationPath(path) {
|
|
489
|
+
const parts = isArray(path) ? path : path.split(DELIMITER);
|
|
490
|
+
for (const part of parts) {
|
|
491
|
+
if (UNSAFE_MUTATION_PATH_SEGMENTS.has(`${part}`)) {
|
|
492
|
+
throw new Error(`unsafe mutation path segment: ${part}`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
@@ -16,7 +16,7 @@ import { extend } from "../data/extend.mjs";
|
|
|
16
16
|
import { addAttributeToken } from "./attributes.mjs";
|
|
17
17
|
import { ATTRIBUTE_ERRORMESSAGE } from "./constants.mjs";
|
|
18
18
|
import { CustomElement, attributeObserverSymbol } from "./customelement.mjs";
|
|
19
|
-
import { instanceSymbol } from "../constants.mjs";
|
|
19
|
+
import { instanceSymbol, internalSymbol } from "../constants.mjs";
|
|
20
20
|
import { DeadMansSwitch } from "../util/deadmansswitch.mjs";
|
|
21
21
|
import { addErrorAttribute } from "./error.mjs";
|
|
22
22
|
import { Observer } from "../types/observer.mjs";
|
|
@@ -28,6 +28,8 @@ export { CustomControl };
|
|
|
28
28
|
* @type {symbol}
|
|
29
29
|
*/
|
|
30
30
|
const attachedInternalSymbol = Symbol("attachedInternal");
|
|
31
|
+
const preUpgradeValueSymbol = Symbol("preUpgradeValue");
|
|
32
|
+
const preUpgradeValuePendingSymbol = Symbol("preUpgradeValuePending");
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* This is a base class for creating custom controls using the power of CustomElement.
|
|
@@ -77,6 +79,12 @@ class CustomControl extends CustomElement {
|
|
|
77
79
|
constructor() {
|
|
78
80
|
super();
|
|
79
81
|
|
|
82
|
+
if (Object.prototype.hasOwnProperty.call(this, "value")) {
|
|
83
|
+
this[preUpgradeValueSymbol] = this.value;
|
|
84
|
+
this[preUpgradeValuePendingSymbol] = true;
|
|
85
|
+
delete this.value;
|
|
86
|
+
}
|
|
87
|
+
|
|
80
88
|
// check if element supports `attachInternals()`
|
|
81
89
|
if (typeof this["attachInternals"] === "function") {
|
|
82
90
|
this[attachedInternalSymbol] = this.attachInternals();
|
|
@@ -130,6 +138,13 @@ class CustomControl extends CustomElement {
|
|
|
130
138
|
if (typeof disabledObserver === "function") {
|
|
131
139
|
disabledObserver();
|
|
132
140
|
}
|
|
141
|
+
|
|
142
|
+
if (this[preUpgradeValuePendingSymbol] === true) {
|
|
143
|
+
const value = this[preUpgradeValueSymbol];
|
|
144
|
+
this[preUpgradeValuePendingSymbol] = false;
|
|
145
|
+
delete this[preUpgradeValueSymbol];
|
|
146
|
+
this.value = value;
|
|
147
|
+
}
|
|
133
148
|
}
|
|
134
149
|
|
|
135
150
|
/**
|
|
@@ -309,35 +324,23 @@ class CustomControl extends CustomElement {
|
|
|
309
324
|
}
|
|
310
325
|
|
|
311
326
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
327
|
+
* Receives changes to the browser-managed form association. The author-provided
|
|
328
|
+
* `form` attribute remains the source of explicit associations.
|
|
314
329
|
*
|
|
315
330
|
* @param {HTMLFormElement} form - The form element to associate with the control
|
|
316
331
|
*/
|
|
317
|
-
formAssociatedCallback(form) {
|
|
318
|
-
if (form) {
|
|
319
|
-
if (form.id) {
|
|
320
|
-
this.setAttribute("form", form.id);
|
|
321
|
-
}
|
|
322
|
-
} else {
|
|
323
|
-
this.removeAttribute("form");
|
|
324
|
-
}
|
|
325
|
-
}
|
|
332
|
+
formAssociatedCallback(form) {}
|
|
326
333
|
|
|
327
334
|
/**
|
|
328
|
-
*
|
|
335
|
+
* Synchronizes browser-computed disabledness without changing the author-provided
|
|
336
|
+
* `disabled` attribute or option.
|
|
329
337
|
*
|
|
330
338
|
* @param {boolean} disabled - Whether or not the control should be disabled
|
|
331
339
|
*/
|
|
332
340
|
formDisabledCallback(disabled) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
if (this.hasAttribute("disabled")) {
|
|
339
|
-
this.removeAttribute("disabled");
|
|
340
|
-
}
|
|
341
|
+
this[internalSymbol].formDisabledValue = disabled === true;
|
|
342
|
+
if (typeof this[internalSymbol].syncDisabledState === "function") {
|
|
343
|
+
this[internalSymbol].syncDisabledState(true);
|
|
341
344
|
}
|
|
342
345
|
}
|
|
343
346
|
|
|
@@ -345,7 +348,9 @@ class CustomControl extends CustomElement {
|
|
|
345
348
|
* @param {string} state
|
|
346
349
|
* @param {string} mode
|
|
347
350
|
*/
|
|
348
|
-
formStateRestoreCallback(state, mode) {
|
|
351
|
+
formStateRestoreCallback(state, mode) {
|
|
352
|
+
this.value = state;
|
|
353
|
+
}
|
|
349
354
|
|
|
350
355
|
/**
|
|
351
356
|
*
|
|
@@ -402,7 +407,7 @@ function initValueAttributeObserver() {
|
|
|
402
407
|
|
|
403
408
|
if (oldValue !== newValue) {
|
|
404
409
|
setTimeout(() => {
|
|
405
|
-
self.value = self.getAttribute("value");
|
|
410
|
+
self.value = self.getAttribute("value") ?? "";
|
|
406
411
|
}, 0);
|
|
407
412
|
}
|
|
408
413
|
});
|