@schukai/monster 3.20.0 → 3.21.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/source/dom/constants.mjs +9 -0
- package/source/dom/updater.mjs +52 -21
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
package/package.json
CHANGED
package/source/dom/constants.mjs
CHANGED
@@ -16,6 +16,7 @@ export {
|
|
16
16
|
ATTRIBUTE_UPDATER_SELECT_THIS,
|
17
17
|
ATTRIBUTE_UPDATER_REPLACE,
|
18
18
|
ATTRIBUTE_UPDATER_INSERT,
|
19
|
+
ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID,
|
19
20
|
ATTRIBUTE_UPDATER_INSERT_REFERENCE,
|
20
21
|
ATTRIBUTE_UPDATER_REMOVE,
|
21
22
|
ATTRIBUTE_UPDATER_BIND,
|
@@ -142,6 +143,14 @@ const ATTRIBUTE_UPDATER_REPLACE = `${ATTRIBUTE_PREFIX}replace`;
|
|
142
143
|
*/
|
143
144
|
const ATTRIBUTE_UPDATER_INSERT = `${ATTRIBUTE_PREFIX}insert`;
|
144
145
|
|
146
|
+
/**
|
147
|
+
* @memberOf Monster.DOM
|
148
|
+
* @type {string}
|
149
|
+
* @license AGPLv3
|
150
|
+
* @since 3.21.0
|
151
|
+
*/
|
152
|
+
const ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID = `${ATTRIBUTE_UPDATER_INSERT}-template-id`;
|
153
|
+
|
145
154
|
/**
|
146
155
|
* @memberOf Monster.DOM
|
147
156
|
* @type {string}
|
package/source/dom/updater.mjs
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
* License text available at https://www.gnu.org/licenses/agpl-3.0.en.html
|
6
6
|
*/
|
7
7
|
|
8
|
-
import {
|
9
|
-
import {
|
10
|
-
import {
|
11
|
-
import {
|
8
|
+
import {internalSymbol} from "../constants.mjs";
|
9
|
+
import {diff} from "../data/diff.mjs";
|
10
|
+
import {Pathfinder} from "../data/pathfinder.mjs";
|
11
|
+
import {Pipe} from "../data/pipe.mjs";
|
12
12
|
import {
|
13
13
|
ATTRIBUTE_ERRORMESSAGE,
|
14
14
|
ATTRIBUTE_UPDATER_ATTRIBUTES,
|
@@ -18,22 +18,21 @@ import {
|
|
18
18
|
ATTRIBUTE_UPDATER_REMOVE,
|
19
19
|
ATTRIBUTE_UPDATER_REPLACE,
|
20
20
|
ATTRIBUTE_UPDATER_SELECT_THIS,
|
21
|
-
|
21
|
+
ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID
|
22
22
|
} from "../dom/constants.mjs";
|
23
23
|
|
24
|
-
import {
|
25
|
-
import {
|
26
|
-
import {
|
27
|
-
import {
|
28
|
-
import {
|
29
|
-
import {
|
30
|
-
import {
|
31
|
-
import {
|
32
|
-
import {
|
33
|
-
import {
|
34
|
-
import { getDocument } from "./util.mjs";
|
24
|
+
import {Base} from "../types/base.mjs";
|
25
|
+
import {isArray, isInstance, isIterable} from "../types/is.mjs";
|
26
|
+
import {Observer} from "../types/observer.mjs";
|
27
|
+
import {ProxyObserver} from "../types/proxyobserver.mjs";
|
28
|
+
import {validateArray, validateInstance} from "../types/validate.mjs";
|
29
|
+
import {clone} from "../util/clone.mjs";
|
30
|
+
import {trimSpaces} from "../util/trimspaces.mjs";
|
31
|
+
import {addToObjectLink} from "./attributes.mjs";
|
32
|
+
import {findTargetElementFromEvent} from "./events.mjs";
|
33
|
+
import {findDocumentTemplate} from "./template.mjs";
|
35
34
|
|
36
|
-
export {
|
35
|
+
export {Updater, addObjectWithUpdaterToElement};
|
37
36
|
|
38
37
|
/**
|
39
38
|
* The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes.
|
@@ -174,7 +173,7 @@ class Updater extends Base {
|
|
174
173
|
run() {
|
175
174
|
// the key __init__has no further meaning and is only
|
176
175
|
// used to create the diff for empty objects.
|
177
|
-
this[internalSymbol].last = {
|
176
|
+
this[internalSymbol].last = {__init__: true};
|
178
177
|
return this[internalSymbol].subject.notifyObservers();
|
179
178
|
}
|
180
179
|
|
@@ -323,7 +322,7 @@ function retrieveAndSetValue(element) {
|
|
323
322
|
|
324
323
|
let options = element?.selectedOptions;
|
325
324
|
if (options === undefined) options = element.querySelectorAll(":scope option:checked");
|
326
|
-
value = Array.from(options).map(({
|
325
|
+
value = Array.from(options).map(({value}) => value);
|
327
326
|
|
328
327
|
break;
|
329
328
|
}
|
@@ -400,7 +399,6 @@ function removeElement(change) {
|
|
400
399
|
function insertElement(change) {
|
401
400
|
const self = this;
|
402
401
|
const subject = self[internalSymbol].subject.getRealSubject();
|
403
|
-
const document = getDocument();
|
404
402
|
|
405
403
|
let mem = new WeakSet();
|
406
404
|
let wd = 0;
|
@@ -516,6 +514,38 @@ function insertElement(change) {
|
|
516
514
|
}
|
517
515
|
}
|
518
516
|
|
517
|
+
/**
|
518
|
+
* @private
|
519
|
+
* @param container
|
520
|
+
* @param key
|
521
|
+
* @param ref
|
522
|
+
* @param path
|
523
|
+
* @returns {any}
|
524
|
+
*/
|
525
|
+
function internalTemplateLookUp(container, key, ref, path) {
|
526
|
+
|
527
|
+
let templateID = key;
|
528
|
+
let template;
|
529
|
+
|
530
|
+
if (container.hasAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID)) {
|
531
|
+
templateID = container.getAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID);
|
532
|
+
template = findDocumentTemplate(templateID, container);
|
533
|
+
if (template instanceof HTMLTemplateElement) {
|
534
|
+
return template;
|
535
|
+
}
|
536
|
+
}
|
537
|
+
|
538
|
+
if (container.closest(`[${ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID}]`)) {
|
539
|
+
templateID = container.closest(`[${ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID}]`).getAttribute(ATTRIBUTE_UPDATER_INSERT_TEMPLATE_ID);
|
540
|
+
template = findDocumentTemplate(templateID, container);
|
541
|
+
if (template instanceof HTMLTemplateElement) {
|
542
|
+
return template;
|
543
|
+
}
|
544
|
+
}
|
545
|
+
|
546
|
+
return findDocumentTemplate(templateID, container);
|
547
|
+
}
|
548
|
+
|
519
549
|
/**
|
520
550
|
*
|
521
551
|
* @private
|
@@ -528,7 +558,8 @@ function insertElement(change) {
|
|
528
558
|
* @throws {Error} no template was found with the specified key.
|
529
559
|
*/
|
530
560
|
function appendNewDocumentFragment(container, key, ref, path) {
|
531
|
-
|
561
|
+
|
562
|
+
let template = internalTemplateLookUp(container, key, ref, path);
|
532
563
|
|
533
564
|
let nodes = template.createDocumentFragment();
|
534
565
|
for (const [, node] of Object.entries(nodes.childNodes)) {
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED