@schukai/monster 3.102.3 → 3.102.5
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.md +19 -0
- package/package.json +1 -1
- package/source/components/datatable/dataset.mjs +2 -2
- package/source/components/datatable/datatable.mjs +1 -1
- package/source/components/datatable/filter.mjs +3 -5
- package/source/components/datatable/pagination.mjs +1 -1
- package/source/components/form/select.mjs +1 -1
- package/source/dom/customcontrol.mjs +321 -320
- package/source/dom/updater.mjs +796 -795
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +3 -3
package/source/dom/updater.mjs
CHANGED
@@ -12,36 +12,36 @@
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
13
13
|
*/
|
14
14
|
|
15
|
-
import {
|
16
|
-
import {
|
17
|
-
import {
|
18
|
-
import {
|
15
|
+
import {internalSymbol} from "../constants.mjs";
|
16
|
+
import {diff} from "../data/diff.mjs";
|
17
|
+
import {Pathfinder} from "../data/pathfinder.mjs";
|
18
|
+
import {Pipe} from "../data/pipe.mjs";
|
19
19
|
import {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
ATTRIBUTE_ERRORMESSAGE,
|
21
|
+
ATTRIBUTE_UPDATER_ATTRIBUTES,
|
22
|
+
ATTRIBUTE_UPDATER_BIND,
|
23
|
+
ATTRIBUTE_UPDATER_BIND_TYPE,
|
24
|
+
ATTRIBUTE_UPDATER_INSERT,
|
25
|
+
ATTRIBUTE_UPDATER_INSERT_REFERENCE,
|
26
|
+
ATTRIBUTE_UPDATER_REMOVE,
|
27
|
+
ATTRIBUTE_UPDATER_REPLACE,
|
28
|
+
ATTRIBUTE_UPDATER_SELECT_THIS,
|
29
29
|
} from "./constants.mjs";
|
30
30
|
|
31
|
-
import {
|
32
|
-
import {
|
33
|
-
import {
|
34
|
-
import {
|
35
|
-
import {
|
36
|
-
import {
|
37
|
-
import {
|
38
|
-
import {
|
39
|
-
import { updaterTransformerMethodsSymbol
|
40
|
-
import {
|
41
|
-
import {
|
42
|
-
import {
|
43
|
-
|
44
|
-
export {
|
31
|
+
import {Base} from "../types/base.mjs";
|
32
|
+
import {isArray, isString, isInstance, isIterable} from "../types/is.mjs";
|
33
|
+
import {Observer} from "../types/observer.mjs";
|
34
|
+
import {ProxyObserver} from "../types/proxyobserver.mjs";
|
35
|
+
import {validateArray, validateInstance} from "../types/validate.mjs";
|
36
|
+
import {clone} from "../util/clone.mjs";
|
37
|
+
import {trimSpaces} from "../util/trimspaces.mjs";
|
38
|
+
import {addAttributeToken, addToObjectLink} from "./attributes.mjs";
|
39
|
+
import {CustomElement, updaterTransformerMethodsSymbol} from "./customelement.mjs";
|
40
|
+
import {findTargetElementFromEvent} from "./events.mjs";
|
41
|
+
import {findDocumentTemplate} from "./template.mjs";
|
42
|
+
import {getWindow} from "./util.mjs";
|
43
|
+
|
44
|
+
export {Updater, addObjectWithUpdaterToElement};
|
45
45
|
|
46
46
|
/**
|
47
47
|
* The updater class connects an object with the DOM. In this way, structures and contents in the DOM can be
|
@@ -68,190 +68,190 @@ export { Updater, addObjectWithUpdaterToElement };
|
|
68
68
|
* @summary The updater class connects an object with the dom
|
69
69
|
*/
|
70
70
|
class Updater extends Base {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
71
|
+
/**
|
72
|
+
* @since 1.8.0
|
73
|
+
* @param {HTMLElement} element
|
74
|
+
* @param {object|ProxyObserver|undefined} subject
|
75
|
+
* @throws {TypeError} value is not a object
|
76
|
+
* @throws {TypeError} value is not an instance of HTMLElement
|
77
|
+
* @see {@link findDocumentTemplate}
|
78
|
+
*/
|
79
|
+
constructor(element, subject) {
|
80
|
+
super();
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @type {HTMLElement}
|
84
|
+
*/
|
85
|
+
if (subject === undefined) subject = {};
|
86
|
+
if (!isInstance(subject, ProxyObserver)) {
|
87
|
+
subject = new ProxyObserver(subject);
|
88
|
+
}
|
89
|
+
|
90
|
+
this[internalSymbol] = {
|
91
|
+
element: validateInstance(element, HTMLElement),
|
92
|
+
last: {},
|
93
|
+
callbacks: new Map(),
|
94
|
+
eventTypes: ["keyup", "click", "change", "drop", "touchend", "input"],
|
95
|
+
subject: subject,
|
96
|
+
};
|
97
|
+
|
98
|
+
this[internalSymbol].callbacks.set(
|
99
|
+
"checkstate",
|
100
|
+
getCheckStateCallback.call(this),
|
101
|
+
);
|
102
|
+
|
103
|
+
this[internalSymbol].subject.attachObserver(
|
104
|
+
new Observer(() => {
|
105
|
+
const s = this[internalSymbol].subject.getRealSubject();
|
106
|
+
|
107
|
+
const diffResult = diff(this[internalSymbol].last, s);
|
108
|
+
this[internalSymbol].last = clone(s);
|
109
|
+
|
110
|
+
const promises = [];
|
111
|
+
|
112
|
+
for (const [, change] of Object.entries(diffResult)) {
|
113
|
+
promises.push(
|
114
|
+
new Promise((resolve, reject) => {
|
115
|
+
getWindow().requestAnimationFrame(() => {
|
116
|
+
try {
|
117
|
+
removeElement.call(this, change);
|
118
|
+
insertElement.call(this, change);
|
119
|
+
updateContent.call(this, change);
|
120
|
+
updateAttributes.call(this, change);
|
121
|
+
|
122
|
+
resolve();
|
123
|
+
} catch (error) {
|
124
|
+
reject(error);
|
125
|
+
}
|
126
|
+
});
|
127
|
+
}),
|
128
|
+
);
|
129
|
+
}
|
130
|
+
|
131
|
+
return Promise.all(promises);
|
132
|
+
}),
|
133
|
+
);
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Defaults: 'keyup', 'click', 'change', 'drop', 'touchend'
|
138
|
+
*
|
139
|
+
* @see {@link https://developer.mozilla.org/de/docs/Web/Events}
|
140
|
+
* @since 1.9.0
|
141
|
+
* @param {Array} types
|
142
|
+
* @return {Updater}
|
143
|
+
*/
|
144
|
+
setEventTypes(types) {
|
145
|
+
this[internalSymbol].eventTypes = validateArray(types);
|
146
|
+
return this;
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* With this method, the eventlisteners are hooked in and the magic begins.
|
151
|
+
*
|
152
|
+
* ```js
|
153
|
+
* updater.run().then(() => {
|
154
|
+
* updater.enableEventProcessing();
|
155
|
+
* });
|
156
|
+
* ```
|
157
|
+
*
|
158
|
+
* @since 1.9.0
|
159
|
+
* @return {Updater}
|
160
|
+
* @throws {Error} the bind argument must start as a value with a path
|
161
|
+
*/
|
162
|
+
enableEventProcessing() {
|
163
|
+
this.disableEventProcessing();
|
164
|
+
|
165
|
+
for (const type of this[internalSymbol].eventTypes) {
|
166
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
167
|
+
this[internalSymbol].element.addEventListener(
|
168
|
+
type,
|
169
|
+
getControlEventHandler.call(this),
|
170
|
+
{
|
171
|
+
capture: true,
|
172
|
+
passive: true,
|
173
|
+
},
|
174
|
+
);
|
175
|
+
}
|
176
|
+
|
177
|
+
return this;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* This method turns off the magic or who loves it more profane it removes the eventListener.
|
182
|
+
*
|
183
|
+
* @since 1.9.0
|
184
|
+
* @return {Updater}
|
185
|
+
*/
|
186
|
+
disableEventProcessing() {
|
187
|
+
for (const type of this[internalSymbol].eventTypes) {
|
188
|
+
this[internalSymbol].element.removeEventListener(
|
189
|
+
type,
|
190
|
+
getControlEventHandler.call(this),
|
191
|
+
);
|
192
|
+
}
|
193
|
+
|
194
|
+
return this;
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* The run method must be called for the update to start working.
|
199
|
+
* The method ensures that changes are detected.
|
200
|
+
*
|
201
|
+
* ```js
|
202
|
+
* updater.run().then(() => {
|
203
|
+
* updater.enableEventProcessing();
|
204
|
+
* });
|
205
|
+
* ```
|
206
|
+
*
|
207
|
+
* @summary Let the magic begin
|
208
|
+
* @return {Promise}
|
209
|
+
*/
|
210
|
+
run() {
|
211
|
+
// the key __init__has no further meaning and is only
|
212
|
+
// used to create the diff for empty objects.
|
213
|
+
this[internalSymbol].last = {__init__: true};
|
214
|
+
return this[internalSymbol].subject.notifyObservers();
|
215
|
+
}
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Gets the values of bound elements and changes them in subject
|
219
|
+
*
|
220
|
+
* @since 1.27.0
|
221
|
+
* @return {Monster.DOM.Updater}
|
222
|
+
*/
|
223
|
+
retrieve() {
|
224
|
+
retrieveFromBindings.call(this);
|
225
|
+
return this;
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* If you have passed a ProxyObserver in the constructor, you will get the object that the ProxyObserver manages here.
|
230
|
+
* However, if you passed a simple object, here you will get a proxy for that object.
|
231
|
+
*
|
232
|
+
* For changes, the ProxyObserver must be used.
|
233
|
+
*
|
234
|
+
* @since 1.8.0
|
235
|
+
* @return {Proxy}
|
236
|
+
*/
|
237
|
+
getSubject() {
|
238
|
+
return this[internalSymbol].subject.getSubject();
|
239
|
+
}
|
240
|
+
|
241
|
+
/**
|
242
|
+
* This method can be used to register commands that can be called via call: instruction.
|
243
|
+
* This can be used to provide a pipe with its own functionality.
|
244
|
+
*
|
245
|
+
* @param {string} name
|
246
|
+
* @param {function} callback
|
247
|
+
* @return {Transformer}
|
248
|
+
* @throws {TypeError} value is not a string
|
249
|
+
* @throws {TypeError} value is not a function
|
250
|
+
*/
|
251
|
+
setCallback(name, callback) {
|
252
|
+
this[internalSymbol].callbacks.set(name, callback);
|
253
|
+
return this;
|
254
|
+
}
|
255
255
|
}
|
256
256
|
|
257
257
|
/**
|
@@ -262,20 +262,20 @@ class Updater extends Base {
|
|
262
262
|
* @this Updater
|
263
263
|
*/
|
264
264
|
function getCheckStateCallback() {
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
265
|
+
return function (current) {
|
266
|
+
// this is a reference to the current object (therefore no array function here)
|
267
|
+
if (this instanceof HTMLInputElement) {
|
268
|
+
if (["radio", "checkbox"].indexOf(this.type) !== -1) {
|
269
|
+
return `${this.value}` === `${current}` ? "true" : undefined;
|
270
|
+
}
|
271
|
+
} else if (this instanceof HTMLOptionElement) {
|
272
|
+
if (isArray(current) && current.indexOf(this.value) !== -1) {
|
273
|
+
return "true";
|
274
|
+
}
|
275
|
+
|
276
|
+
return undefined;
|
277
|
+
}
|
278
|
+
};
|
279
279
|
}
|
280
280
|
|
281
281
|
/**
|
@@ -290,32 +290,32 @@ const symbol = Symbol("@schukai/monster/updater@@EventHandler");
|
|
290
290
|
* @throws {Error} the bind argument must start as a value with a path
|
291
291
|
*/
|
292
292
|
function getControlEventHandler() {
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
293
|
+
if (this[symbol]) {
|
294
|
+
return this[symbol];
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* @throws {Error} the bind argument must start as a value with a path.
|
299
|
+
* @throws {Error} unsupported object
|
300
|
+
* @param {Event} event
|
301
|
+
*/
|
302
|
+
this[symbol] = (event) => {
|
303
|
+
const element = findTargetElementFromEvent(event, ATTRIBUTE_UPDATER_BIND);
|
304
|
+
|
305
|
+
if (element === undefined) {
|
306
|
+
return;
|
307
|
+
}
|
308
|
+
|
309
|
+
queueMicrotask(() => {
|
310
|
+
try {
|
311
|
+
retrieveAndSetValue.call(this, element);
|
312
|
+
} catch (e) {
|
313
|
+
addAttributeToken(element, ATTRIBUTE_ERRORMESSAGE, e.message || `${e}`);
|
314
|
+
}
|
315
|
+
});
|
316
|
+
};
|
317
|
+
|
318
|
+
return this[symbol];
|
319
319
|
}
|
320
320
|
|
321
321
|
/**
|
@@ -325,128 +325,129 @@ function getControlEventHandler() {
|
|
325
325
|
* @private
|
326
326
|
*/
|
327
327
|
function retrieveAndSetValue(element) {
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
328
|
+
const pathfinder = new Pathfinder(this[internalSymbol].subject.getSubject());
|
329
|
+
|
330
|
+
let path = element.getAttribute(ATTRIBUTE_UPDATER_BIND);
|
331
|
+
if (path === null)
|
332
|
+
throw new Error("the bind argument must start as a value with a path");
|
333
|
+
|
334
|
+
if (path.indexOf("path:") !== 0) {
|
335
|
+
throw new Error("the bind argument must start as a value with a path");
|
336
|
+
}
|
337
|
+
|
338
|
+
path = path.substring(5); // remove path: from the string
|
339
|
+
|
340
|
+
let value;
|
341
|
+
|
342
|
+
if (element instanceof HTMLInputElement) {
|
343
|
+
switch (element.type) {
|
344
|
+
case "checkbox":
|
345
|
+
value = element.checked ? element.value : undefined;
|
346
|
+
break;
|
347
|
+
default:
|
348
|
+
value = element.value;
|
349
|
+
break;
|
350
|
+
}
|
351
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
352
|
+
value = element.value;
|
353
|
+
} else if (element instanceof HTMLSelectElement) {
|
354
|
+
switch (element.type) {
|
355
|
+
case "select-one":
|
356
|
+
value = element.value;
|
357
|
+
break;
|
358
|
+
case "select-multiple":
|
359
|
+
value = element.value;
|
360
|
+
|
361
|
+
let options = element?.selectedOptions;
|
362
|
+
if (options === undefined)
|
363
|
+
options = element.querySelectorAll(":scope option:checked");
|
364
|
+
value = Array.from(options).map(({value}) => value);
|
365
|
+
|
366
|
+
break;
|
367
|
+
}
|
368
|
+
|
369
|
+
// values from custom elements
|
370
|
+
} else if (
|
371
|
+
(element?.constructor?.prototype &&
|
372
|
+
!!Object.getOwnPropertyDescriptor(
|
373
|
+
element.constructor.prototype,
|
374
|
+
"value",
|
375
|
+
)?.["get"]) ||
|
376
|
+
element.hasOwnProperty("value")
|
377
|
+
) {
|
378
|
+
value = element?.["value"];
|
379
|
+
} else {
|
380
|
+
throw new Error("unsupported object");
|
381
|
+
}
|
382
|
+
|
383
|
+
if (isString(value)) {
|
384
|
+
const type = element.getAttribute(ATTRIBUTE_UPDATER_BIND_TYPE);
|
385
|
+
switch (type) {
|
386
|
+
case "number":
|
387
|
+
case "int":
|
388
|
+
case "float":
|
389
|
+
case "integer":
|
390
|
+
value = Number(value);
|
391
|
+
if (isNaN(value)) {
|
392
|
+
value = 0;
|
393
|
+
}
|
394
|
+
break;
|
395
|
+
case "boolean":
|
396
|
+
case "bool":
|
397
|
+
case "checkbox":
|
398
|
+
value = value === "true" || value === "1" || value === "on";
|
399
|
+
break;
|
400
|
+
|
401
|
+
case "string[]":
|
402
|
+
if (value === "") {
|
403
|
+
value = [];
|
404
|
+
}
|
405
|
+
|
406
|
+
value = value.split(",").map((v) => `${v}`);
|
407
|
+
break;
|
408
|
+
|
409
|
+
case "int[]":
|
410
|
+
case "integer[]":
|
411
|
+
if (value === "") {
|
412
|
+
value = [];
|
413
|
+
} else {
|
414
|
+
value = value
|
415
|
+
.split(",")
|
416
|
+
.map((v) => {
|
417
|
+
try {
|
418
|
+
return parseInt(v, 10);
|
419
|
+
} catch (e) {
|
420
|
+
}
|
421
|
+
return -1;
|
422
|
+
})
|
423
|
+
.filter((v) => v !== -1);
|
424
|
+
}
|
425
|
+
|
426
|
+
break;
|
427
|
+
case "[]":
|
428
|
+
case "array":
|
429
|
+
case "list":
|
430
|
+
value = value.split(",");
|
431
|
+
break;
|
432
|
+
case "object":
|
433
|
+
case "json":
|
434
|
+
value = JSON.parse(value);
|
435
|
+
break;
|
436
|
+
default:
|
437
|
+
break;
|
438
|
+
}
|
439
|
+
}
|
440
|
+
|
441
|
+
const copy = clone(this[internalSymbol].subject.getRealSubject());
|
442
|
+
|
443
|
+
const pf = new Pathfinder(copy);
|
444
|
+
pf.setVia(path, value);
|
445
|
+
|
446
|
+
const diffResult = diff(copy, this[internalSymbol].subject.getRealSubject());
|
447
|
+
|
448
|
+
if (diffResult.length > 0) {
|
449
|
+
pathfinder.setVia(path, value);
|
450
|
+
}
|
450
451
|
}
|
451
452
|
|
452
453
|
/**
|
@@ -456,15 +457,15 @@ function retrieveAndSetValue(element) {
|
|
456
457
|
* @private
|
457
458
|
*/
|
458
459
|
function retrieveFromBindings() {
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
460
|
+
if (this[internalSymbol].element.matches(`[${ATTRIBUTE_UPDATER_BIND}]`)) {
|
461
|
+
retrieveAndSetValue.call(this, this[internalSymbol].element);
|
462
|
+
}
|
463
|
+
|
464
|
+
for (const [, element] of this[internalSymbol].element
|
465
|
+
.querySelectorAll(`[${ATTRIBUTE_UPDATER_BIND}]`)
|
466
|
+
.entries()) {
|
467
|
+
retrieveAndSetValue.call(this, element);
|
468
|
+
}
|
468
469
|
}
|
469
470
|
|
470
471
|
/**
|
@@ -475,11 +476,11 @@ function retrieveFromBindings() {
|
|
475
476
|
* @return {void}
|
476
477
|
*/
|
477
478
|
function removeElement(change) {
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
479
|
+
for (const [, element] of this[internalSymbol].element
|
480
|
+
.querySelectorAll(`:scope [${ATTRIBUTE_UPDATER_REMOVE}]`)
|
481
|
+
.entries()) {
|
482
|
+
element.parentNode.removeChild(element);
|
483
|
+
}
|
483
484
|
}
|
484
485
|
|
485
486
|
/**
|
@@ -495,133 +496,133 @@ function removeElement(change) {
|
|
495
496
|
* @this Updater
|
496
497
|
*/
|
497
498
|
function insertElement(change) {
|
498
|
-
|
499
|
+
const subject = this[internalSymbol].subject.getRealSubject();
|
499
500
|
|
500
|
-
|
501
|
-
|
501
|
+
const mem = new WeakSet();
|
502
|
+
let wd = 0;
|
502
503
|
|
503
|
-
|
504
|
+
const container = this[internalSymbol].element;
|
504
505
|
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
506
|
+
while (true) {
|
507
|
+
let found = false;
|
508
|
+
wd++;
|
509
|
+
|
510
|
+
const p = clone(change?.["path"]);
|
511
|
+
if (!isArray(p)) return;
|
512
|
+
|
513
|
+
while (p.length > 0) {
|
514
|
+
const current = p.join(".");
|
515
|
+
|
516
|
+
let iterator = new Set();
|
517
|
+
const query = `[${ATTRIBUTE_UPDATER_INSERT}*="path:${current}"]`;
|
518
|
+
|
519
|
+
const e = container.querySelectorAll(query);
|
520
|
+
|
521
|
+
if (e.length > 0) {
|
522
|
+
iterator = new Set([...e]);
|
523
|
+
}
|
524
|
+
|
525
|
+
if (container.matches(query)) {
|
526
|
+
iterator.add(container);
|
527
|
+
}
|
528
|
+
|
529
|
+
for (const [, containerElement] of iterator.entries()) {
|
530
|
+
if (mem.has(containerElement)) continue;
|
531
|
+
mem.add(containerElement);
|
532
|
+
|
533
|
+
found = true;
|
534
|
+
|
535
|
+
const attributes = containerElement.getAttribute(
|
536
|
+
ATTRIBUTE_UPDATER_INSERT,
|
537
|
+
);
|
538
|
+
if (attributes === null) continue;
|
539
|
+
|
540
|
+
const def = trimSpaces(attributes);
|
541
|
+
const i = def.indexOf(" ");
|
542
|
+
const key = trimSpaces(def.substr(0, i));
|
543
|
+
const refPrefix = `${key}-`;
|
544
|
+
const cmd = trimSpaces(def.substr(i));
|
545
|
+
|
546
|
+
// this case is actually excluded by the query but is nevertheless checked again here
|
547
|
+
if (cmd.indexOf("|") > 0) {
|
548
|
+
throw new Error("pipes are not allowed when cloning a node.");
|
549
|
+
}
|
550
|
+
|
551
|
+
const pipe = new Pipe(cmd);
|
552
|
+
this[internalSymbol].callbacks.forEach((f, n) => {
|
553
|
+
pipe.setCallback(n, f);
|
554
|
+
});
|
555
|
+
|
556
|
+
let value;
|
557
|
+
try {
|
558
|
+
containerElement.removeAttribute(ATTRIBUTE_ERRORMESSAGE);
|
559
|
+
value = pipe.run(subject);
|
560
|
+
} catch (e) {
|
561
|
+
containerElement.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.message);
|
562
|
+
}
|
563
|
+
|
564
|
+
const dataPath = cmd.split(":").pop();
|
565
|
+
|
566
|
+
let insertPoint;
|
567
|
+
if (containerElement.hasChildNodes()) {
|
568
|
+
insertPoint = containerElement.lastChild;
|
569
|
+
}
|
570
|
+
|
571
|
+
if (!isIterable(value)) {
|
572
|
+
throw new Error("the value is not iterable");
|
573
|
+
}
|
574
|
+
|
575
|
+
const available = new Set();
|
576
|
+
|
577
|
+
for (const [i] of Object.entries(value)) {
|
578
|
+
const ref = refPrefix + i;
|
579
|
+
const currentPath = `${dataPath}.${i}`;
|
580
|
+
|
581
|
+
available.add(ref);
|
582
|
+
const refElement = containerElement.querySelector(
|
583
|
+
`[${ATTRIBUTE_UPDATER_INSERT_REFERENCE}="${ref}"]`,
|
584
|
+
);
|
585
|
+
|
586
|
+
if (refElement instanceof HTMLElement) {
|
587
|
+
insertPoint = refElement;
|
588
|
+
continue;
|
589
|
+
}
|
590
|
+
|
591
|
+
appendNewDocumentFragment(containerElement, key, ref, currentPath);
|
592
|
+
}
|
593
|
+
|
594
|
+
const nodes = containerElement.querySelectorAll(
|
595
|
+
`[${ATTRIBUTE_UPDATER_INSERT_REFERENCE}*="${refPrefix}"]`,
|
596
|
+
);
|
597
|
+
|
598
|
+
for (const [, node] of Object.entries(nodes)) {
|
599
|
+
if (
|
600
|
+
!available.has(
|
601
|
+
node.getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE),
|
602
|
+
)
|
603
|
+
) {
|
604
|
+
try {
|
605
|
+
containerElement.removeChild(node);
|
606
|
+
} catch (e) {
|
607
|
+
containerElement.setAttribute(
|
608
|
+
ATTRIBUTE_ERRORMESSAGE,
|
609
|
+
`${containerElement.getAttribute(ATTRIBUTE_ERRORMESSAGE)}, ${
|
610
|
+
e.message
|
611
|
+
}`.trim(),
|
612
|
+
);
|
613
|
+
}
|
614
|
+
}
|
615
|
+
}
|
616
|
+
}
|
617
|
+
|
618
|
+
p.pop();
|
619
|
+
}
|
620
|
+
|
621
|
+
if (found === false) break;
|
622
|
+
if (wd++ > 200) {
|
623
|
+
throw new Error("the maximum depth for the recursion is reached.");
|
624
|
+
}
|
625
|
+
}
|
625
626
|
}
|
626
627
|
|
627
628
|
/**
|
@@ -636,17 +637,17 @@ function insertElement(change) {
|
|
636
637
|
* @throws {Error} no template was found with the specified key.
|
637
638
|
*/
|
638
639
|
function appendNewDocumentFragment(container, key, ref, path) {
|
639
|
-
|
640
|
+
const template = findDocumentTemplate(key, container);
|
640
641
|
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
642
|
+
const nodes = template.createDocumentFragment();
|
643
|
+
for (const [, node] of Object.entries(nodes.childNodes)) {
|
644
|
+
if (node instanceof HTMLElement) {
|
645
|
+
applyRecursive(node, key, path);
|
646
|
+
node.setAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE, ref);
|
647
|
+
}
|
647
648
|
|
648
|
-
|
649
|
-
|
649
|
+
container.appendChild(node);
|
650
|
+
}
|
650
651
|
}
|
651
652
|
|
652
653
|
/**
|
@@ -659,27 +660,27 @@ function appendNewDocumentFragment(container, key, ref, path) {
|
|
659
660
|
* @return {void}
|
660
661
|
*/
|
661
662
|
function applyRecursive(node, key, path) {
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
663
|
+
if (node instanceof HTMLElement) {
|
664
|
+
if (node.hasAttribute(ATTRIBUTE_UPDATER_REPLACE)) {
|
665
|
+
const value = node.getAttribute(ATTRIBUTE_UPDATER_REPLACE);
|
666
|
+
node.setAttribute(
|
667
|
+
ATTRIBUTE_UPDATER_REPLACE,
|
668
|
+
value.replaceAll(`path:${key}`, `path:${path}`),
|
669
|
+
);
|
670
|
+
}
|
671
|
+
|
672
|
+
if (node.hasAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)) {
|
673
|
+
const value = node.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES);
|
674
|
+
node.setAttribute(
|
675
|
+
ATTRIBUTE_UPDATER_ATTRIBUTES,
|
676
|
+
value.replaceAll(`path:${key}`, `path:${path}`),
|
677
|
+
);
|
678
|
+
}
|
679
|
+
|
680
|
+
for (const [, child] of Object.entries(node.childNodes)) {
|
681
|
+
applyRecursive(child, key, path);
|
682
|
+
}
|
683
|
+
}
|
683
684
|
}
|
684
685
|
|
685
686
|
/**
|
@@ -691,19 +692,19 @@ function applyRecursive(node, key, path) {
|
|
691
692
|
* @this Updater
|
692
693
|
*/
|
693
694
|
function updateContent(change) {
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
695
|
+
const subject = this[internalSymbol].subject.getRealSubject();
|
696
|
+
|
697
|
+
const p = clone(change?.["path"]);
|
698
|
+
runUpdateContent.call(this, this[internalSymbol].element, p, subject);
|
699
|
+
|
700
|
+
const slots = this[internalSymbol].element.querySelectorAll("slot");
|
701
|
+
if (slots.length > 0) {
|
702
|
+
for (const [, slot] of Object.entries(slots)) {
|
703
|
+
for (const [, element] of Object.entries(slot.assignedNodes())) {
|
704
|
+
runUpdateContent.call(this, element, p, subject);
|
705
|
+
}
|
706
|
+
}
|
707
|
+
}
|
707
708
|
}
|
708
709
|
|
709
710
|
/**
|
@@ -716,69 +717,69 @@ function updateContent(change) {
|
|
716
717
|
* @return {void}
|
717
718
|
*/
|
718
719
|
function runUpdateContent(container, parts, subject) {
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
720
|
+
if (!isArray(parts)) return;
|
721
|
+
if (!(container instanceof HTMLElement)) return;
|
722
|
+
parts = clone(parts);
|
723
|
+
|
724
|
+
const mem = new WeakSet();
|
725
|
+
|
726
|
+
while (parts.length > 0) {
|
727
|
+
const current = parts.join(".");
|
728
|
+
parts.pop();
|
729
|
+
|
730
|
+
// Unfortunately, static data is always changed as well, since it is not possible to react to changes here.
|
731
|
+
const query = `[${ATTRIBUTE_UPDATER_REPLACE}^="path:${current}"], [${ATTRIBUTE_UPDATER_REPLACE}^="static:"], [${ATTRIBUTE_UPDATER_REPLACE}^="i18n:"]`;
|
732
|
+
const e = container.querySelectorAll(`${query}`);
|
733
|
+
|
734
|
+
const iterator = new Set([...e]);
|
735
|
+
|
736
|
+
if (container.matches(query)) {
|
737
|
+
iterator.add(container);
|
738
|
+
}
|
739
|
+
|
740
|
+
/**
|
741
|
+
* @type {HTMLElement}
|
742
|
+
*/
|
743
|
+
for (const [element] of iterator.entries()) {
|
744
|
+
if (mem.has(element)) return;
|
745
|
+
mem.add(element);
|
746
|
+
|
747
|
+
const attributes = element.getAttribute(ATTRIBUTE_UPDATER_REPLACE);
|
748
|
+
const cmd = trimSpaces(attributes);
|
749
|
+
|
750
|
+
const pipe = new Pipe(cmd);
|
751
|
+
this[internalSymbol].callbacks.forEach((f, n) => {
|
752
|
+
pipe.setCallback(n, f);
|
753
|
+
});
|
754
|
+
|
755
|
+
let value;
|
756
|
+
try {
|
757
|
+
element.removeAttribute(ATTRIBUTE_ERRORMESSAGE);
|
758
|
+
value = pipe.run(subject);
|
759
|
+
} catch (e) {
|
760
|
+
element.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.message);
|
761
|
+
}
|
762
|
+
|
763
|
+
if (value instanceof HTMLElement) {
|
764
|
+
while (element.firstChild) {
|
765
|
+
element.removeChild(element.firstChild);
|
766
|
+
}
|
767
|
+
|
768
|
+
try {
|
769
|
+
element.appendChild(value);
|
770
|
+
} catch (e) {
|
771
|
+
element.setAttribute(
|
772
|
+
ATTRIBUTE_ERRORMESSAGE,
|
773
|
+
`${element.getAttribute(ATTRIBUTE_ERRORMESSAGE)}, ${
|
774
|
+
e.message
|
775
|
+
}`.trim(),
|
776
|
+
);
|
777
|
+
}
|
778
|
+
} else {
|
779
|
+
element.innerHTML = value;
|
780
|
+
}
|
781
|
+
}
|
782
|
+
}
|
782
783
|
}
|
783
784
|
|
784
785
|
/**
|
@@ -788,9 +789,9 @@ function runUpdateContent(container, parts, subject) {
|
|
788
789
|
* @return {void}
|
789
790
|
*/
|
790
791
|
function updateAttributes(change) {
|
791
|
-
|
792
|
-
|
793
|
-
|
792
|
+
const subject = this[internalSymbol].subject.getRealSubject();
|
793
|
+
const p = clone(change?.["path"]);
|
794
|
+
runUpdateAttributes.call(this, this[internalSymbol].element, p, subject);
|
794
795
|
}
|
795
796
|
|
796
797
|
/**
|
@@ -802,70 +803,70 @@ function updateAttributes(change) {
|
|
802
803
|
* @this Updater
|
803
804
|
*/
|
804
805
|
function runUpdateAttributes(container, parts, subject) {
|
805
|
-
|
806
|
-
|
806
|
+
if (!isArray(parts)) return;
|
807
|
+
parts = clone(parts);
|
807
808
|
|
808
|
-
|
809
|
+
const mem = new WeakSet();
|
809
810
|
|
810
|
-
|
811
|
-
|
812
|
-
|
811
|
+
while (parts.length > 0) {
|
812
|
+
const current = parts.join(".");
|
813
|
+
parts.pop();
|
813
814
|
|
814
|
-
|
815
|
+
let iterator = new Set();
|
815
816
|
|
816
|
-
|
817
|
+
const query = `[${ATTRIBUTE_UPDATER_SELECT_THIS}][${ATTRIBUTE_UPDATER_ATTRIBUTES}], [${ATTRIBUTE_UPDATER_ATTRIBUTES}*="path:${current}"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="static:"], [${ATTRIBUTE_UPDATER_ATTRIBUTES}^="i18n:"]`;
|
817
818
|
|
818
|
-
|
819
|
+
const e = container.querySelectorAll(query);
|
819
820
|
|
820
|
-
|
821
|
-
|
822
|
-
|
821
|
+
if (e.length > 0) {
|
822
|
+
iterator = new Set([...e]);
|
823
|
+
}
|
823
824
|
|
824
|
-
|
825
|
-
|
826
|
-
|
825
|
+
if (container.matches(query)) {
|
826
|
+
iterator.add(container);
|
827
|
+
}
|
827
828
|
|
828
|
-
|
829
|
-
|
830
|
-
|
829
|
+
for (const [element] of iterator.entries()) {
|
830
|
+
if (mem.has(element)) return;
|
831
|
+
mem.add(element);
|
831
832
|
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
833
|
+
// this case occurs when the ATTRIBUTE_UPDATER_SELECT_THIS attribute is set
|
834
|
+
if (!element.hasAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES)) {
|
835
|
+
continue;
|
836
|
+
}
|
836
837
|
|
837
|
-
|
838
|
+
const attributes = element.getAttribute(ATTRIBUTE_UPDATER_ATTRIBUTES);
|
838
839
|
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
840
|
+
for (let [, def] of Object.entries(attributes.split(","))) {
|
841
|
+
def = trimSpaces(def);
|
842
|
+
const i = def.indexOf(" ");
|
843
|
+
const name = trimSpaces(def.substr(0, i));
|
844
|
+
const cmd = trimSpaces(def.substr(i));
|
844
845
|
|
845
|
-
|
846
|
+
const pipe = new Pipe(cmd);
|
846
847
|
|
847
|
-
|
848
|
-
|
849
|
-
|
848
|
+
this[internalSymbol].callbacks.forEach((f, n) => {
|
849
|
+
pipe.setCallback(n, f, element);
|
850
|
+
});
|
850
851
|
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
852
|
+
let value;
|
853
|
+
try {
|
854
|
+
element.removeAttribute(ATTRIBUTE_ERRORMESSAGE);
|
855
|
+
value = pipe.run(subject);
|
856
|
+
} catch (e) {
|
857
|
+
element.setAttribute(ATTRIBUTE_ERRORMESSAGE, e.message);
|
858
|
+
}
|
858
859
|
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
860
|
+
if (value === undefined) {
|
861
|
+
element.removeAttribute(name);
|
862
|
+
} else if (element.getAttribute(name) !== value) {
|
863
|
+
element.setAttribute(name, value);
|
864
|
+
}
|
864
865
|
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
866
|
+
handleInputControlAttributeUpdate.call(this, element, name, value);
|
867
|
+
}
|
868
|
+
}
|
869
|
+
}
|
869
870
|
}
|
870
871
|
|
871
872
|
/**
|
@@ -878,54 +879,54 @@ function runUpdateAttributes(container, parts, subject) {
|
|
878
879
|
*/
|
879
880
|
|
880
881
|
function handleInputControlAttributeUpdate(element, name, value) {
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
882
|
+
|
883
|
+
if (element instanceof HTMLSelectElement) {
|
884
|
+
switch (element.type) {
|
885
|
+
case "select-multiple":
|
886
|
+
for (const [index, opt] of Object.entries(element.options)) {
|
887
|
+
opt.selected = value.indexOf(opt.value) !== -1;
|
888
|
+
}
|
889
|
+
|
890
|
+
break;
|
891
|
+
case "select-one":
|
892
|
+
// Only one value may be selected
|
893
|
+
|
894
|
+
for (const [index, opt] of Object.entries(element.options)) {
|
895
|
+
if (opt.value === value) {
|
896
|
+
element.selectedIndex = index;
|
897
|
+
break;
|
898
|
+
}
|
899
|
+
}
|
900
|
+
|
901
|
+
break;
|
902
|
+
}
|
903
|
+
} else if (element instanceof HTMLInputElement) {
|
904
|
+
switch (element.type) {
|
905
|
+
case "radio":
|
906
|
+
if (name === "checked") {
|
907
|
+
element.checked = value !== undefined;
|
908
|
+
}
|
909
|
+
break;
|
910
|
+
|
911
|
+
case "checkbox":
|
912
|
+
if (name === "checked") {
|
913
|
+
element.checked = value !== undefined;
|
914
|
+
}
|
915
|
+
break;
|
916
|
+
|
917
|
+
case "text":
|
918
|
+
default:
|
919
|
+
if (name === "value") {
|
920
|
+
element.value = value === undefined ? "" : value;
|
921
|
+
}
|
922
|
+
break;
|
923
|
+
|
924
|
+
}
|
925
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
926
|
+
if (name === "value") {
|
927
|
+
element.value = value === undefined ? "" : value;
|
928
|
+
}
|
929
|
+
}
|
929
930
|
}
|
930
931
|
|
931
932
|
/**
|
@@ -944,83 +945,83 @@ function handleInputControlAttributeUpdate(element, name, value) {
|
|
944
945
|
* @throws {TypeError} symbol must be an instance of Symbol
|
945
946
|
*/
|
946
947
|
function addObjectWithUpdaterToElement(elements, symbol, object, config = {}) {
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
948
|
+
if (!(this instanceof HTMLElement)) {
|
949
|
+
throw new TypeError(
|
950
|
+
"the context of this function must be an instance of HTMLElement",
|
951
|
+
);
|
952
|
+
}
|
953
|
+
|
954
|
+
if (!(typeof symbol === "symbol")) {
|
955
|
+
throw new TypeError("symbol must be an instance of Symbol");
|
956
|
+
}
|
957
|
+
|
958
|
+
const updaters = new Set();
|
959
|
+
|
960
|
+
if (elements instanceof NodeList) {
|
961
|
+
elements = new Set([...elements]);
|
962
|
+
} else if (elements instanceof HTMLElement) {
|
963
|
+
elements = new Set([elements]);
|
964
|
+
} else if (elements instanceof Set) {
|
965
|
+
} else {
|
966
|
+
throw new TypeError(
|
967
|
+
`elements is not a valid type. (actual: ${typeof elements})`,
|
968
|
+
);
|
969
|
+
}
|
970
|
+
|
971
|
+
const result = [];
|
972
|
+
|
973
|
+
const updaterCallbacks = [];
|
974
|
+
const cb = this?.[updaterTransformerMethodsSymbol];
|
975
|
+
if (this instanceof HTMLElement && typeof cb === "function") {
|
976
|
+
const callbacks = cb.call(this);
|
977
|
+
if (typeof callbacks === "object") {
|
978
|
+
for (const [name, callback] of Object.entries(callbacks)) {
|
979
|
+
if (typeof callback === "function") {
|
980
|
+
updaterCallbacks.push([name, callback]);
|
981
|
+
} else {
|
982
|
+
addAttributeToken(
|
983
|
+
this,
|
984
|
+
ATTRIBUTE_ERRORMESSAGE,
|
985
|
+
`onUpdaterPipeCallbacks: ${name} is not a function`,
|
986
|
+
);
|
987
|
+
}
|
988
|
+
}
|
989
|
+
} else {
|
990
|
+
addAttributeToken(
|
991
|
+
this,
|
992
|
+
ATTRIBUTE_ERRORMESSAGE,
|
993
|
+
`onUpdaterPipeCallbacks do not return an object with functions`,
|
994
|
+
);
|
995
|
+
}
|
996
|
+
}
|
997
|
+
|
998
|
+
elements.forEach((element) => {
|
999
|
+
if (!(element instanceof HTMLElement)) return;
|
1000
|
+
if (element instanceof HTMLTemplateElement) return;
|
1001
|
+
|
1002
|
+
const u = new Updater(element, object);
|
1003
|
+
updaters.add(u);
|
1004
|
+
|
1005
|
+
if (updaterCallbacks.length > 0) {
|
1006
|
+
for (const [name, callback] of updaterCallbacks) {
|
1007
|
+
u.setCallback(name, callback);
|
1008
|
+
}
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
result.push(
|
1012
|
+
u.run().then(() => {
|
1013
|
+
if (config.eventProcessing === true) {
|
1014
|
+
u.enableEventProcessing();
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
return u;
|
1018
|
+
}),
|
1019
|
+
);
|
1020
|
+
});
|
1021
|
+
|
1022
|
+
if (updaters.size > 0) {
|
1023
|
+
addToObjectLink(this, symbol, updaters);
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
return result;
|
1026
1027
|
}
|