@schukai/monster 1.23.0 → 1.26.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/CHANGELOG +53 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -2
- package/dist/modules/data/datasource/storage/localstorage.js +2 -2
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
- package/dist/modules/data/datasource/storage.js +2 -2
- package/dist/modules/data/datasource.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1684 -696
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +16 -7
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -11
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +87 -20
- package/source/data/datasource/storage/localstorage.js +4 -10
- package/source/data/datasource/storage/sessionstorage.js +4 -12
- package/source/data/datasource/storage.js +7 -14
- package/source/data/datasource.js +55 -17
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +121 -92
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +250 -0
- package/source/dom/locale.js +10 -5
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +52 -12
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +47 -33
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +10 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +24 -14
- package/source/i18n/translations.js +20 -10
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +244 -27
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +6 -3
- package/source/types/is.js +103 -85
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +6 -6
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +4 -5
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/datasource.js +4 -4
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +14 -16
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +28 -4
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +71 -8
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +15 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- package/test/web/tests.js +7 -7
|
@@ -3,46 +3,41 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @author schukai GmbH
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
import {
|
|
6
|
+
|
|
7
|
+
import {internalSymbol} from "../constants.js";
|
|
8
8
|
import {extend} from "../data/extend.js";
|
|
9
9
|
import {Pathfinder} from "../data/pathfinder.js";
|
|
10
10
|
import {assignToNamespace, Monster} from '../namespace.js';
|
|
11
11
|
import {parseDataURL} from "../types/dataurl.js";
|
|
12
12
|
import {getGlobalObject} from "../types/global.js";
|
|
13
|
-
import {isArray, isObject, isString} from "../types/is.js";
|
|
13
|
+
import {isArray, isFunction, isObject, isString} from "../types/is.js";
|
|
14
14
|
import {Observer} from "../types/observer.js";
|
|
15
15
|
import {ProxyObserver} from "../types/proxyobserver.js";
|
|
16
16
|
import {validateFunction, validateInstance, validateObject} from "../types/validate.js";
|
|
17
17
|
import {clone} from "../util/clone.js";
|
|
18
18
|
import {addToObjectLink, getLinkedObjects, hasObjectLink} from "./attributes.js";
|
|
19
|
-
import {ATTRIBUTE_OPTIONS,
|
|
19
|
+
import {ATTRIBUTE_DISABLED, ATTRIBUTE_OPTIONS, objectUpdaterLinkSymbol} from "./constants.js";
|
|
20
20
|
import {findDocumentTemplate, Template} from "./template.js";
|
|
21
21
|
import {Updater} from "./updater.js";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @
|
|
25
|
-
* @type {symbol}
|
|
26
|
-
*/
|
|
27
|
-
const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @private
|
|
24
|
+
* @memberOf Monster.DOM
|
|
31
25
|
* @type {symbol}
|
|
32
26
|
*/
|
|
33
|
-
const
|
|
27
|
+
const initMethodSymbol = Symbol('initMethodSymbol');
|
|
34
28
|
|
|
35
29
|
/**
|
|
36
30
|
* @memberOf Monster.DOM
|
|
37
31
|
* @type {symbol}
|
|
38
32
|
*/
|
|
39
|
-
const
|
|
33
|
+
const assembleMethodSymbol = Symbol('assembleMethodSymbol');
|
|
40
34
|
|
|
41
35
|
/**
|
|
36
|
+
* this symbol holds the attribute observer callbacks. The key is the attribute name.
|
|
42
37
|
* @memberOf Monster.DOM
|
|
43
38
|
* @type {symbol}
|
|
44
39
|
*/
|
|
45
|
-
const
|
|
40
|
+
const attributeObserverSymbol = Symbol('attributeObserver');
|
|
46
41
|
|
|
47
42
|
|
|
48
43
|
/**
|
|
@@ -97,19 +92,12 @@ const assembleMethodSymbol = Symbol('assembleMethodSymbol');
|
|
|
97
92
|
*
|
|
98
93
|
* <img src="./images/customelement-class.png">
|
|
99
94
|
*
|
|
100
|
-
* You can create the object via the
|
|
95
|
+
* You can create the object via the function `document.createElement()`.
|
|
101
96
|
*
|
|
102
97
|
* ```
|
|
103
98
|
* <script type="module">
|
|
104
|
-
* import {
|
|
105
|
-
*
|
|
106
|
-
* ```
|
|
107
|
-
*
|
|
108
|
-
* Alternatively, you can also integrate this function individually.
|
|
109
|
-
*
|
|
110
|
-
* ```
|
|
111
|
-
* <script type="module">
|
|
112
|
-
* import {CustomElement} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.23.0/dist/modules/dom/customelement.js';
|
|
99
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
100
|
+
* document.createElement('monster-')
|
|
113
101
|
* </script>
|
|
114
102
|
* ```
|
|
115
103
|
*
|
|
@@ -212,7 +200,8 @@ class CustomElement extends HTMLElement {
|
|
|
212
200
|
*/
|
|
213
201
|
constructor() {
|
|
214
202
|
super();
|
|
215
|
-
this[
|
|
203
|
+
this[internalSymbol] = new ProxyObserver({'options': extend({}, this.defaults, getOptionsFromAttributes.call(this))});
|
|
204
|
+
this[attributeObserverSymbol] = {};
|
|
216
205
|
initOptionObserver.call(this);
|
|
217
206
|
this[initMethodSymbol]();
|
|
218
207
|
}
|
|
@@ -224,7 +213,7 @@ class CustomElement extends HTMLElement {
|
|
|
224
213
|
* @since 1.15.0
|
|
225
214
|
*/
|
|
226
215
|
static get observedAttributes() {
|
|
227
|
-
return [ATTRIBUTE_OPTIONS];
|
|
216
|
+
return [ATTRIBUTE_OPTIONS, ATTRIBUTE_DISABLED];
|
|
228
217
|
}
|
|
229
218
|
|
|
230
219
|
/**
|
|
@@ -264,7 +253,7 @@ class CustomElement extends HTMLElement {
|
|
|
264
253
|
*/
|
|
265
254
|
get defaults() {
|
|
266
255
|
return {
|
|
267
|
-
|
|
256
|
+
ATTRIBUTE_DISABLED: this.getAttribute(ATTRIBUTE_DISABLED),
|
|
268
257
|
shadowMode: 'open',
|
|
269
258
|
delegatesFocus: true,
|
|
270
259
|
templates: {
|
|
@@ -319,7 +308,7 @@ class CustomElement extends HTMLElement {
|
|
|
319
308
|
* @returns {CustomElement}
|
|
320
309
|
*/
|
|
321
310
|
attachObserver(observer) {
|
|
322
|
-
this[
|
|
311
|
+
this[internalSymbol].attachObserver(observer)
|
|
323
312
|
return this;
|
|
324
313
|
}
|
|
325
314
|
|
|
@@ -330,7 +319,7 @@ class CustomElement extends HTMLElement {
|
|
|
330
319
|
* @returns {CustomElement}
|
|
331
320
|
*/
|
|
332
321
|
detachObserver(observer) {
|
|
333
|
-
this[
|
|
322
|
+
this[internalSymbol].detachObserver(observer)
|
|
334
323
|
return this;
|
|
335
324
|
}
|
|
336
325
|
|
|
@@ -339,7 +328,7 @@ class CustomElement extends HTMLElement {
|
|
|
339
328
|
* @returns {ProxyObserver}
|
|
340
329
|
*/
|
|
341
330
|
containsObserver(observer) {
|
|
342
|
-
return this[
|
|
331
|
+
return this[internalSymbol].containsObserver(observer)
|
|
343
332
|
}
|
|
344
333
|
|
|
345
334
|
/**
|
|
@@ -354,7 +343,7 @@ class CustomElement extends HTMLElement {
|
|
|
354
343
|
let value;
|
|
355
344
|
|
|
356
345
|
try {
|
|
357
|
-
value = new Pathfinder(this[
|
|
346
|
+
value = new Pathfinder(this[internalSymbol].getRealSubject()['options']).getVia(path);
|
|
358
347
|
} catch (e) {
|
|
359
348
|
|
|
360
349
|
}
|
|
@@ -372,7 +361,7 @@ class CustomElement extends HTMLElement {
|
|
|
372
361
|
* @since 1.14.0
|
|
373
362
|
*/
|
|
374
363
|
setOption(path, value) {
|
|
375
|
-
new Pathfinder(this[
|
|
364
|
+
new Pathfinder(this[internalSymbol].getSubject()['options']).setVia(path, value);
|
|
376
365
|
return this;
|
|
377
366
|
}
|
|
378
367
|
|
|
@@ -388,7 +377,7 @@ class CustomElement extends HTMLElement {
|
|
|
388
377
|
}
|
|
389
378
|
|
|
390
379
|
const self = this;
|
|
391
|
-
extend(self[
|
|
380
|
+
extend(self[internalSymbol].getSubject()['options'], self.defaults, options);
|
|
392
381
|
|
|
393
382
|
return self;
|
|
394
383
|
}
|
|
@@ -446,16 +435,10 @@ class CustomElement extends HTMLElement {
|
|
|
446
435
|
nodeList = elements
|
|
447
436
|
}
|
|
448
437
|
|
|
449
|
-
assignUpdaterToElement.call(self, nodeList, clone(self[
|
|
450
|
-
|
|
451
|
-
if (self.hasAttribute('disabled')) {
|
|
452
|
-
self.setOption('disabled', true);
|
|
453
|
-
}
|
|
454
|
-
|
|
438
|
+
assignUpdaterToElement.call(self, nodeList, clone(self[internalSymbol].getRealSubject()['options']));
|
|
455
439
|
return self;
|
|
456
440
|
}
|
|
457
441
|
|
|
458
|
-
|
|
459
442
|
/**
|
|
460
443
|
* Called every time the element is inserted into the DOM. Useful for running setup code, such as
|
|
461
444
|
* fetching resources or rendering. Generally, you should try to delay work until this time.
|
|
@@ -465,7 +448,7 @@ class CustomElement extends HTMLElement {
|
|
|
465
448
|
*/
|
|
466
449
|
connectedCallback() {
|
|
467
450
|
let self = this;
|
|
468
|
-
if (!hasObjectLink(self,
|
|
451
|
+
if (!hasObjectLink(self, objectUpdaterLinkSymbol)) {
|
|
469
452
|
self[assembleMethodSymbol]()
|
|
470
453
|
}
|
|
471
454
|
}
|
|
@@ -504,8 +487,10 @@ class CustomElement extends HTMLElement {
|
|
|
504
487
|
attributeChangedCallback(attrName, oldVal, newVal) {
|
|
505
488
|
const self = this;
|
|
506
489
|
|
|
507
|
-
|
|
508
|
-
|
|
490
|
+
const callback = self[attributeObserverSymbol]?.[attrName];
|
|
491
|
+
|
|
492
|
+
if (isFunction(callback)) {
|
|
493
|
+
callback.call(self, newVal, oldVal);
|
|
509
494
|
}
|
|
510
495
|
|
|
511
496
|
}
|
|
@@ -520,7 +505,6 @@ class CustomElement extends HTMLElement {
|
|
|
520
505
|
hasNode(node) {
|
|
521
506
|
const self = this;
|
|
522
507
|
|
|
523
|
-
|
|
524
508
|
if (containChildNode.call(self, validateInstance(node, Node))) {
|
|
525
509
|
return true;
|
|
526
510
|
}
|
|
@@ -536,19 +520,43 @@ class CustomElement extends HTMLElement {
|
|
|
536
520
|
}
|
|
537
521
|
|
|
538
522
|
/**
|
|
523
|
+
* @private
|
|
524
|
+
* @param {String} filter
|
|
525
|
+
* @return {*}
|
|
539
526
|
* @this CustomElement
|
|
540
527
|
* @since 1.23.0
|
|
541
|
-
* @private
|
|
542
528
|
*/
|
|
543
|
-
function getSlottedElements() {
|
|
529
|
+
function getSlottedElements(filter) {
|
|
544
530
|
const self = this;
|
|
545
|
-
const slots = self.shadowRoot.querySelectorAll('slot');
|
|
546
|
-
|
|
547
531
|
const result = new Set;
|
|
548
532
|
|
|
533
|
+
|
|
534
|
+
if (!(self.shadowRoot instanceof ShadowRoot)) {
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const slots = self.shadowRoot.querySelectorAll('slot');
|
|
539
|
+
|
|
549
540
|
for (const [, slot] of Object.entries(slots)) {
|
|
550
|
-
|
|
541
|
+
slot.assignedElements().forEach(function (node) {
|
|
542
|
+
|
|
543
|
+
if (!(node instanceof HTMLElement)) return;
|
|
544
|
+
|
|
545
|
+
if (filter !== undefined) {
|
|
546
|
+
node.querySelectorAll(filter).forEach(function (n) {
|
|
547
|
+
result.add(n);
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
if (node.matches(filter)) {
|
|
551
|
+
result.add(node);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
} else {
|
|
555
|
+
result.add(node);
|
|
556
|
+
}
|
|
557
|
+
})
|
|
551
558
|
}
|
|
559
|
+
|
|
552
560
|
return result;
|
|
553
561
|
}
|
|
554
562
|
|
|
@@ -593,63 +601,70 @@ function initOptionObserver() {
|
|
|
593
601
|
return;
|
|
594
602
|
}
|
|
595
603
|
|
|
596
|
-
|
|
597
|
-
const found = self.shadowRoot.querySelectorAll('button, command, fieldset, keygen, optgroup, option, select, textarea, input, [data-monster-objectlink]');
|
|
598
|
-
for (const [, element] of Object.entries(found)) {
|
|
599
|
-
if (flag === true) {
|
|
600
|
-
element.setAttribute('disabled', '');
|
|
601
|
-
} else {
|
|
602
|
-
element.removeAttribute('disabled');
|
|
603
|
-
}
|
|
604
|
+
lastDisabledValue = flag;
|
|
604
605
|
|
|
605
|
-
|
|
606
|
+
if (!(self.shadowRoot instanceof ShadowRoot)) {
|
|
607
|
+
return;
|
|
606
608
|
}
|
|
607
609
|
|
|
608
|
-
|
|
610
|
+
const query = 'button, command, fieldset, keygen, optgroup, option, select, textarea, input, [data-monster-objectlink]';
|
|
611
|
+
const elements = self.shadowRoot.querySelectorAll(query);
|
|
612
|
+
|
|
613
|
+
let nodeList;
|
|
614
|
+
try {
|
|
615
|
+
nodeList = new Set([
|
|
616
|
+
...elements,
|
|
617
|
+
...getSlottedElements.call(self, query)
|
|
618
|
+
])
|
|
619
|
+
} catch (e) {
|
|
620
|
+
nodeList = elements
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
for (const element of [...nodeList]) {
|
|
624
|
+
if (flag === true) {
|
|
625
|
+
element.setAttribute(ATTRIBUTE_DISABLED, '');
|
|
626
|
+
} else {
|
|
627
|
+
element.removeAttribute(ATTRIBUTE_DISABLED);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
609
630
|
|
|
610
631
|
}));
|
|
611
632
|
|
|
612
633
|
self.attachObserver(new Observer(function () {
|
|
613
634
|
|
|
614
635
|
// not initialised
|
|
615
|
-
if (!hasObjectLink(self,
|
|
636
|
+
if (!hasObjectLink(self, objectUpdaterLinkSymbol)) {
|
|
616
637
|
return;
|
|
617
638
|
}
|
|
618
639
|
// inform every element
|
|
619
|
-
const updaters = getLinkedObjects(self,
|
|
640
|
+
const updaters = getLinkedObjects(self, objectUpdaterLinkSymbol);
|
|
620
641
|
|
|
621
642
|
for (const list of updaters) {
|
|
622
643
|
for (const updater of list) {
|
|
623
|
-
let d = clone(self[
|
|
644
|
+
let d = clone(self[internalSymbol].getRealSubject()['options']);
|
|
624
645
|
Object.assign(updater.getSubject(), d);
|
|
625
646
|
}
|
|
626
647
|
}
|
|
627
648
|
|
|
628
649
|
}));
|
|
629
650
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
break;
|
|
639
|
-
case ATTRIBUTE_OPTIONS:
|
|
640
|
-
const options = getOptionsFromAttributes.call(self);
|
|
641
|
-
if (isObject(options)) {
|
|
642
|
-
self.setOptions(options);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
651
|
+
// disabled
|
|
652
|
+
self[attributeObserverSymbol][ATTRIBUTE_DISABLED] = (newVal) => {
|
|
653
|
+
if (self.hasAttribute(ATTRIBUTE_DISABLED)) {
|
|
654
|
+
self.setOption(ATTRIBUTE_DISABLED, true);
|
|
655
|
+
} else {
|
|
656
|
+
self.setOption(ATTRIBUTE_DISABLED, undefined);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
647
659
|
|
|
648
|
-
|
|
660
|
+
// data-monster-options
|
|
661
|
+
self[attributeObserverSymbol][ATTRIBUTE_OPTIONS] = () => {
|
|
662
|
+
const options = getOptionsFromAttributes.call(self);
|
|
663
|
+
if (isObject(options)) {
|
|
664
|
+
self.setOptions(options);
|
|
649
665
|
}
|
|
650
|
-
}
|
|
666
|
+
}
|
|
651
667
|
|
|
652
|
-
observer.observe(this, {attributes: true, attributeOldValue: true, childList: false, subtree: false});
|
|
653
668
|
|
|
654
669
|
}
|
|
655
670
|
|
|
@@ -807,14 +822,13 @@ function registerCustomElement(element) {
|
|
|
807
822
|
*
|
|
808
823
|
* @param element
|
|
809
824
|
* @param object
|
|
810
|
-
* @return {
|
|
825
|
+
* @return {Promise[]}
|
|
811
826
|
* @since 1.23.0
|
|
827
|
+
* @memberOf Monster.DOM
|
|
812
828
|
*/
|
|
813
829
|
function assignUpdaterToElement(elements, object) {
|
|
814
830
|
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
addToObjectLink(this, objectLinkSymbol, updater);
|
|
831
|
+
const updaters = new Set;
|
|
818
832
|
|
|
819
833
|
if (elements instanceof NodeList) {
|
|
820
834
|
elements = new Set([
|
|
@@ -822,20 +836,35 @@ function assignUpdaterToElement(elements, object) {
|
|
|
822
836
|
])
|
|
823
837
|
}
|
|
824
838
|
|
|
839
|
+
let result = [];
|
|
840
|
+
|
|
825
841
|
elements.forEach((element) => {
|
|
826
842
|
if (!(element instanceof HTMLElement)) return;
|
|
827
843
|
if ((element instanceof HTMLTemplateElement)) return;
|
|
844
|
+
|
|
828
845
|
const u = new Updater(element, object)
|
|
829
|
-
|
|
846
|
+
updaters.add(u);
|
|
830
847
|
|
|
831
|
-
u.run().then(() => {
|
|
832
|
-
u.enableEventProcessing();
|
|
833
|
-
});
|
|
848
|
+
result.push(u.run().then(() => {
|
|
849
|
+
return u.enableEventProcessing();
|
|
850
|
+
}));
|
|
834
851
|
|
|
835
852
|
});
|
|
836
853
|
|
|
837
|
-
|
|
854
|
+
if (updaters.size > 0) {
|
|
855
|
+
addToObjectLink(this, objectUpdaterLinkSymbol, updaters);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
return result;
|
|
838
859
|
}
|
|
839
860
|
|
|
840
861
|
assignToNamespace('Monster.DOM', CustomElement, registerCustomElement, assignUpdaterToElement);
|
|
841
|
-
export {
|
|
862
|
+
export {
|
|
863
|
+
Monster,
|
|
864
|
+
registerCustomElement,
|
|
865
|
+
CustomElement,
|
|
866
|
+
initMethodSymbol,
|
|
867
|
+
assembleMethodSymbol,
|
|
868
|
+
assignUpdaterToElement,
|
|
869
|
+
attributeObserverSymbol
|
|
870
|
+
}
|
package/source/dom/events.js
CHANGED
|
@@ -13,7 +13,7 @@ import {getDocument} from "./util.js";
|
|
|
13
13
|
*
|
|
14
14
|
* ```
|
|
15
15
|
* <script type="module">
|
|
16
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
16
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
17
17
|
* console.log(new Monster.DOM.fireEvent())
|
|
18
18
|
* </script>
|
|
19
19
|
* ```
|
|
@@ -22,7 +22,7 @@ import {getDocument} from "./util.js";
|
|
|
22
22
|
*
|
|
23
23
|
* ```
|
|
24
24
|
* <script type="module">
|
|
25
|
-
* import {fireEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
25
|
+
* import {fireEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/events.js';
|
|
26
26
|
* console.log(fireEvent())
|
|
27
27
|
* </script>
|
|
28
28
|
* ```
|
|
@@ -66,14 +66,14 @@ function fireEvent(element, type) {
|
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* This function gets the path `Event.composedPath()` from an event and tries to find the next element
|
|
69
|
-
* up the tree `element.closest()` with the attribute and value. If no value, or a value that is undefined or null,
|
|
69
|
+
* up the tree `element.closest()` with the attribute and value. If no value, or a value that is undefined or null,
|
|
70
70
|
* is specified, only the attribute is searched.
|
|
71
71
|
*
|
|
72
72
|
* You can call the function via the monster namespace `new Monster.DOM.findTargetElementFromEvent()`.
|
|
73
73
|
*
|
|
74
74
|
* ```
|
|
75
75
|
* <script type="module">
|
|
76
|
-
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
76
|
+
* import {Monster} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/monster.js';
|
|
77
77
|
* console.log(new Monster.DOM.findTargetElementFromEvent())
|
|
78
78
|
* </script>
|
|
79
79
|
* ```
|
|
@@ -82,7 +82,7 @@ function fireEvent(element, type) {
|
|
|
82
82
|
*
|
|
83
83
|
* ```
|
|
84
84
|
* <script type="module">
|
|
85
|
-
* import {findTargetElementFromEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.
|
|
85
|
+
* import {findTargetElementFromEvent} from 'https://cdn.jsdelivr.net/npm/@schukai/monster@1.26.1/dist/modules/dom/events.js';
|
|
86
86
|
* console.log(findTargetElementFromEvent())
|
|
87
87
|
* </script>
|
|
88
88
|
* ```
|
|
@@ -114,7 +114,7 @@ function findTargetElementFromEvent(event, attributeName, attributeValue) {
|
|
|
114
114
|
|
|
115
115
|
if (o instanceof HTMLElement &&
|
|
116
116
|
o.hasAttribute(attributeName)
|
|
117
|
-
&& (attributeValue===undefined || o.getAttribute(attributeName) === attributeValue)) {
|
|
117
|
+
&& (attributeValue === undefined || o.getAttribute(attributeName) === attributeValue)) {
|
|
118
118
|
return o;
|
|
119
119
|
}
|
|
120
120
|
}
|