@schukai/monster 3.43.0 → 3.44.1
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
CHANGED
|
@@ -60,6 +60,12 @@ const assembleMethodSymbol = Symbol.for("@schukai/monster/dom/@@assembleMethodSy
|
|
|
60
60
|
*/
|
|
61
61
|
const attributeObserverSymbol = Symbol.for("@schukai/monster/dom/@@attributeObserver");
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* @private
|
|
65
|
+
* @type {symbol}
|
|
66
|
+
*/
|
|
67
|
+
const attributeMutationObserverSymbol = Symbol("@schukai/monster/dom/@@mutationObserver");
|
|
68
|
+
|
|
63
69
|
/**
|
|
64
70
|
* HTMLElement
|
|
65
71
|
* @external HTMLElement
|
|
@@ -203,9 +209,9 @@ class CustomElement extends HTMLElement {
|
|
|
203
209
|
this[internalSymbol] = new ProxyObserver({
|
|
204
210
|
options: initOptionsFromAttributes(this, extend({}, this.defaults)),
|
|
205
211
|
});
|
|
206
|
-
initAttributeChangeMutationObserver.call(this);
|
|
207
|
-
initOptionObserver.call(this);
|
|
208
212
|
this[initMethodSymbol]();
|
|
213
|
+
initOptionObserver.call(this);
|
|
214
|
+
|
|
209
215
|
}
|
|
210
216
|
|
|
211
217
|
/**
|
|
@@ -229,6 +235,28 @@ class CustomElement extends HTMLElement {
|
|
|
229
235
|
return [ATTRIBUTE_OPTIONS, ATTRIBUTE_DISABLED];
|
|
230
236
|
}
|
|
231
237
|
|
|
238
|
+
/**
|
|
239
|
+
*
|
|
240
|
+
* @param attribute
|
|
241
|
+
* @param callback
|
|
242
|
+
* @returns {Monster.DOM.CustomElement}
|
|
243
|
+
*/
|
|
244
|
+
addAttributeObserver(attribute, callback) {
|
|
245
|
+
validateFunction(callback);
|
|
246
|
+
this[attributeObserverSymbol][attribute] = callback;
|
|
247
|
+
return this;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
*
|
|
252
|
+
* @param attribute
|
|
253
|
+
* @returns {Monster.DOM.CustomElement}
|
|
254
|
+
*/
|
|
255
|
+
removeAttributeObserver(attribute) {
|
|
256
|
+
delete this[attributeObserverSymbol][attribute];
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
|
|
232
260
|
/**
|
|
233
261
|
* Derived classes can override and extend this method as follows.
|
|
234
262
|
*
|
|
@@ -524,6 +552,9 @@ class CustomElement extends HTMLElement {
|
|
|
524
552
|
customElementUpdaterLinkSymbol,
|
|
525
553
|
clone(self[internalSymbol].getRealSubject()["options"]),
|
|
526
554
|
);
|
|
555
|
+
|
|
556
|
+
attachAttributeChangeMutationObserver.call(this);
|
|
557
|
+
|
|
527
558
|
return self;
|
|
528
559
|
}
|
|
529
560
|
|
|
@@ -539,6 +570,7 @@ class CustomElement extends HTMLElement {
|
|
|
539
570
|
if (!hasObjectLink(self, customElementUpdaterLinkSymbol)) {
|
|
540
571
|
self[assembleMethodSymbol]();
|
|
541
572
|
}
|
|
573
|
+
|
|
542
574
|
}
|
|
543
575
|
|
|
544
576
|
/**
|
|
@@ -576,7 +608,12 @@ class CustomElement extends HTMLElement {
|
|
|
576
608
|
const callback = self[attributeObserverSymbol]?.[attrName];
|
|
577
609
|
|
|
578
610
|
if (isFunction(callback)) {
|
|
579
|
-
|
|
611
|
+
try {
|
|
612
|
+
callback.call(self, newVal, oldVal);
|
|
613
|
+
} catch (e) {
|
|
614
|
+
addAttributeToken(self, ATTRIBUTE_ERRORMESSAGE, e.toString());
|
|
615
|
+
}
|
|
616
|
+
|
|
580
617
|
}
|
|
581
618
|
}
|
|
582
619
|
|
|
@@ -604,32 +641,34 @@ class CustomElement extends HTMLElement {
|
|
|
604
641
|
|
|
605
642
|
/**
|
|
606
643
|
* This method is called when the element is first created.
|
|
607
|
-
*
|
|
644
|
+
*
|
|
608
645
|
* @private
|
|
609
646
|
* @this CustomElement
|
|
610
647
|
*/
|
|
611
|
-
function
|
|
648
|
+
function attachAttributeChangeMutationObserver() {
|
|
612
649
|
const self = this;
|
|
613
650
|
|
|
614
|
-
if (self[
|
|
615
|
-
self[attributeObserverSymbol] = {};
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
if(Object.keys(self[attributeObserverSymbol]).length === 0) {
|
|
651
|
+
if (typeof self[attributeMutationObserverSymbol] !== "undefined") {
|
|
619
652
|
return;
|
|
620
653
|
}
|
|
621
654
|
|
|
622
|
-
new MutationObserver(function (mutations) {
|
|
655
|
+
self[attributeMutationObserverSymbol] = new MutationObserver(function (mutations, observer) {
|
|
623
656
|
for (const mutation of mutations) {
|
|
624
657
|
if (mutation.type === "attributes") {
|
|
625
658
|
self.attributeChangedCallback(mutation.attributeName, mutation.oldValue, mutation.target.getAttribute(mutation.attributeName));
|
|
626
659
|
}
|
|
627
660
|
}
|
|
628
|
-
}).observe(self, {
|
|
629
|
-
attributes: true,
|
|
630
|
-
attributeOldValue: true,
|
|
631
|
-
attributeFilter: Object.keys(self[attributeObserverSymbol]),
|
|
632
661
|
});
|
|
662
|
+
|
|
663
|
+
try {
|
|
664
|
+
self[attributeMutationObserverSymbol].observe(self, {
|
|
665
|
+
attributes: true,
|
|
666
|
+
attributeOldValue: true,
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
} catch (e) {
|
|
670
|
+
addAttributeToken(self, ATTRIBUTE_ERRORMESSAGE, e.toString());
|
|
671
|
+
}
|
|
633
672
|
}
|
|
634
673
|
|
|
635
674
|
/**
|
package/source/dom/updater.mjs
CHANGED
|
@@ -37,7 +37,7 @@ export { Updater, addObjectWithUpdaterToElement };
|
|
|
37
37
|
* The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes.
|
|
38
38
|
*
|
|
39
39
|
* For example, to include a string from an object, the attribute `data-monster-replace` can be used.
|
|
40
|
-
* a further explanation can be found under
|
|
40
|
+
* a further explanation can be found under [monsterjs.org](https://monsterjs.org/)
|
|
41
41
|
*
|
|
42
42
|
* Changes to attributes are made only when the direct values are changed. If you want to assign changes to other values
|
|
43
43
|
* as well, you have to insert the attribute `data-monster-select-this`. This should be done with care, as it can reduce performance.
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED