@schukai/monster 4.148.2 → 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.
Files changed (27) hide show
  1. package/package.json +1 -1
  2. package/source/components/datatable/filter/date-presets.mjs +13 -0
  3. package/source/components/datatable/filter/date-range.mjs +12 -0
  4. package/source/components/datatable/filter/date-time.mjs +14 -1
  5. package/source/components/datatable/filter/date.mjs +14 -1
  6. package/source/components/datatable/filter/input.mjs +14 -1
  7. package/source/components/datatable/filter/range.mjs +11 -0
  8. package/source/components/datatable/filter/text-operator.mjs +19 -0
  9. package/source/components/datatable/filter/time.mjs +14 -1
  10. package/source/components/form/buy-box.mjs +2 -0
  11. package/source/components/form/cart-control.mjs +2 -0
  12. package/source/components/state/state.mjs +2 -0
  13. package/source/data/extend.mjs +7 -1
  14. package/source/dom/customcontrol.mjs +28 -23
  15. package/source/dom/customelement.mjs +105 -39
  16. package/source/dom/util/extract-keys.mjs +2 -1
  17. package/source/dom/util/init-options-from-attributes.mjs +1 -1
  18. package/source/dom/util/set-option-from-attribute.mjs +14 -3
  19. package/test/cases/components/datatable/filter-form-value.mjs +98 -0
  20. package/test/cases/components/form/non-value-form-association.mjs +53 -0
  21. package/test/cases/data/extend.mjs +27 -1
  22. package/test/cases/dom/customcontrol.mjs +188 -6
  23. package/test/cases/dom/customelement-initfromscripthost.mjs +62 -0
  24. package/test/cases/dom/customelement.mjs +123 -2
  25. package/test/cases/dom/util/extract-keys.mjs +14 -0
  26. package/test/cases/dom/util/init-options-from-attributes.mjs +18 -0
  27. package/test/cases/dom/util/set-option-from-attribute.mjs +151 -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.2"}
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",
@@ -35,6 +35,8 @@ export { State };
35
35
  * @summary A compact state indicator for statuses such as success, warning, error or informational workflow state.
36
36
  **/
37
37
  class State extends CustomControl {
38
+ static formAssociated = false;
39
+
38
40
  /**
39
41
  * @return {void}
40
42
  */
@@ -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 in a) {
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]) {
@@ -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
- * Sets the `form` attribute of the custom control to the `id` of the passed form element.
313
- * If no form element is passed, removes the `form` attribute.
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
- * Sets or removes the `disabled` attribute of the custom control based on the passed value.
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
- if (disabled) {
334
- if (!this.hasAttribute("disabled")) {
335
- this.setAttribute("disabled", "");
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
  });
@@ -117,6 +117,7 @@ const updateCloneDataSymbol = Symbol("@schukai/monster/dom/@@updateCloneData");
117
117
  * @type {symbol}
118
118
  */
119
119
  const scriptHostElementSymbol = Symbol("scriptHostElement");
120
+ const optionDefaultsSymbol = Symbol("optionDefaults");
120
121
  const managedShadowRootSymbol = Symbol("managedShadowRoot");
121
122
  const visibilityStateSymbol = Symbol("visibilityState");
122
123
  let hostVisibilityStyleSheet = null;
@@ -215,7 +216,11 @@ class CustomElement extends HTMLElement {
215
216
 
216
217
  this[attributeObserverSymbol] = {};
217
218
 
218
- const options = initOptionsFromAttributes(this, extend({}, this.defaults));
219
+ this[optionDefaultsSymbol] = this.defaults;
220
+ const options = initOptionsFromAttributes(
221
+ this,
222
+ extend({}, this[optionDefaultsSymbol]),
223
+ );
219
224
  if (!isObject(options)) {
220
225
  throw new Error(
221
226
  `The options are not defined correctly in the ${this.getTag()} element.`,
@@ -819,6 +824,9 @@ class CustomElement extends HTMLElement {
819
824
  this,
820
825
  attrName,
821
826
  this[internalSymbol].getSubject()["options"],
827
+ {},
828
+ "data-monster-option-",
829
+ this[optionDefaultsSymbol],
822
830
  );
823
831
  }
824
832
 
@@ -888,21 +896,22 @@ function callControlCallback(callBackFunctionName, ...args) {
888
896
  return;
889
897
  }
890
898
 
891
- if (this[scriptHostElementSymbol].length === 0) {
892
- const targetId = this.getAttribute(ATTRIBUTE_SCRIPT_HOST);
893
- if (!targetId) {
894
- return;
895
- }
896
-
897
- const list = targetId.split(",");
898
- for (const id of list) {
899
- const host = findElementWithIdUpwards(this, id.trim());
900
- if (!(host instanceof HTMLElement)) {
901
- continue;
902
- }
899
+ const targetId = this.getAttribute(ATTRIBUTE_SCRIPT_HOST);
900
+ if (!targetId) {
901
+ return;
902
+ }
903
903
 
904
- this[scriptHostElementSymbol].push(host);
904
+ // The attribute and DOM ancestry can change while the control remains alive.
905
+ // Resolve the small ordered host list against the current context for every call.
906
+ this[scriptHostElementSymbol].length = 0;
907
+ const list = targetId.split(",");
908
+ for (const id of list) {
909
+ const host = findElementWithIdUpwards(this, id.trim());
910
+ if (!(host instanceof HTMLElement)) {
911
+ continue;
905
912
  }
913
+
914
+ this[scriptHostElementSymbol].push(host);
906
915
  }
907
916
 
908
917
  for (const host of this[scriptHostElementSymbol]) {
@@ -1091,48 +1100,105 @@ function containChildNode(node) {
1091
1100
  */
1092
1101
  function initOptionObserver() {
1093
1102
  const self = this;
1103
+ const disabledQuery =
1104
+ "button, command, fieldset, keygen, optgroup, option, select, textarea, input, [data-monster-objectlink]";
1094
1105
 
1095
1106
  self[internalSymbol].lastDisabledValue = undefined;
1107
+ self[internalSymbol].parentDisabledElements = new Set();
1096
1108
 
1097
- const syncDisabledState = () => {
1098
- const flag = self.getOption("disabled", false);
1109
+ const getDisabledTargets = () => {
1110
+ const targets = new Set();
1111
+ const shadowRoot = getManagedShadowRoot.call(self);
1099
1112
 
1100
- if (flag === self[internalSymbol].lastDisabledValue) {
1101
- return;
1113
+ try {
1114
+ for (const element of self.querySelectorAll(disabledQuery)) {
1115
+ targets.add(element);
1116
+ }
1117
+ if (shadowRoot instanceof ShadowRoot) {
1118
+ for (const element of shadowRoot.querySelectorAll(disabledQuery)) {
1119
+ targets.add(element);
1120
+ }
1121
+ }
1122
+ for (const element of getSlottedElements.call(self, disabledQuery)) {
1123
+ targets.add(element);
1124
+ }
1125
+ } catch (e) {}
1126
+
1127
+ return targets;
1128
+ };
1129
+
1130
+ const disconnectDisabledObservers = () => {
1131
+ self[internalSymbol].disabledLightObserver?.disconnect();
1132
+ self[internalSymbol].disabledShadowObserver?.disconnect();
1133
+ delete self[internalSymbol].disabledLightObserver;
1134
+ delete self[internalSymbol].disabledShadowObserver;
1135
+ };
1136
+
1137
+ const observeDisabledTargets = () => {
1138
+ const callback = () => syncDisabledState(true);
1139
+ if (!self[internalSymbol].disabledLightObserver) {
1140
+ self[internalSymbol].disabledLightObserver = new MutationObserver(
1141
+ callback,
1142
+ );
1143
+ self[internalSymbol].disabledLightObserver.observe(self, {
1144
+ attributes: true,
1145
+ attributeFilter: [ATTRIBUTE_DISABLED, "slot"],
1146
+ childList: true,
1147
+ subtree: true,
1148
+ });
1102
1149
  }
1103
1150
 
1104
1151
  const shadowRoot = getManagedShadowRoot.call(self);
1105
- if (!(shadowRoot instanceof ShadowRoot) && !self.childNodes.length) {
1152
+ if (
1153
+ shadowRoot instanceof ShadowRoot &&
1154
+ !self[internalSymbol].disabledShadowObserver
1155
+ ) {
1156
+ self[internalSymbol].disabledShadowObserver = new MutationObserver(
1157
+ callback,
1158
+ );
1159
+ self[internalSymbol].disabledShadowObserver.observe(shadowRoot, {
1160
+ attributes: true,
1161
+ attributeFilter: [ATTRIBUTE_DISABLED, "slot"],
1162
+ childList: true,
1163
+ subtree: true,
1164
+ });
1165
+ }
1166
+ };
1167
+
1168
+ const syncDisabledState = (force = false) => {
1169
+ const flag =
1170
+ self.getOption("disabled", false) === true ||
1171
+ self[internalSymbol].formDisabledValue === true;
1172
+
1173
+ if (force !== true && flag === self[internalSymbol].lastDisabledValue) {
1106
1174
  return;
1107
1175
  }
1108
1176
 
1109
1177
  self[internalSymbol].lastDisabledValue = flag;
1178
+ const ownedElements = self[internalSymbol].parentDisabledElements;
1110
1179
 
1111
- const query =
1112
- "button, command, fieldset, keygen, optgroup, option, select, textarea, input, [data-monster-objectlink]";
1113
-
1114
- let elements = [];
1115
- if (shadowRoot instanceof ShadowRoot) {
1116
- elements = shadowRoot.querySelectorAll(query);
1180
+ if (flag !== true) {
1181
+ disconnectDisabledObservers();
1182
+ for (const element of ownedElements) {
1183
+ element.removeAttribute(ATTRIBUTE_DISABLED);
1184
+ }
1185
+ ownedElements.clear();
1186
+ return;
1117
1187
  }
1118
1188
 
1119
- let nodeList;
1120
- try {
1121
- const baseElements =
1122
- elements.length > 0 ? elements : self.querySelectorAll(query);
1123
- nodeList = new Set([
1124
- ...baseElements,
1125
- ...getSlottedElements.call(self, query),
1126
- ]);
1127
- } catch (e) {
1128
- nodeList = elements;
1189
+ observeDisabledTargets();
1190
+ const targets = getDisabledTargets();
1191
+ for (const element of [...ownedElements]) {
1192
+ if (!targets.has(element)) {
1193
+ element.removeAttribute(ATTRIBUTE_DISABLED);
1194
+ ownedElements.delete(element);
1195
+ }
1129
1196
  }
1130
1197
 
1131
- for (const element of [...nodeList]) {
1132
- if (flag === true) {
1198
+ for (const element of targets) {
1199
+ if (!element.hasAttribute(ATTRIBUTE_DISABLED)) {
1133
1200
  element.setAttribute(ATTRIBUTE_DISABLED, "");
1134
- } else {
1135
- element.removeAttribute(ATTRIBUTE_DISABLED);
1201
+ ownedElements.add(element);
1136
1202
  }
1137
1203
  }
1138
1204
  };