@oscarpalmer/abydon 0.9.0 → 0.11.0
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/dist/fragment.mjs +15 -6
- package/dist/helpers/dom.mjs +23 -6
- package/dist/helpers/index.mjs +11 -1
- package/dist/index.js +370 -66
- package/dist/node/attribute/index.mjs +4 -4
- package/dist/node/attribute/value.mjs +16 -16
- package/dist/node/event.mjs +22 -2
- package/dist/node/index.mjs +4 -4
- package/dist/node/value.mjs +83 -17
- package/package.json +3 -3
- package/src/fragment.ts +26 -11
- package/src/helpers/dom.ts +29 -6
- package/src/helpers/index.ts +19 -0
- package/src/models.ts +3 -1
- package/src/node/attribute/index.ts +25 -17
- package/src/node/attribute/value.ts +16 -19
- package/src/node/event.ts +28 -6
- package/src/node/index.ts +5 -4
- package/src/node/value.ts +154 -22
- package/types/fragment.d.ts +5 -1
- package/types/helpers/dom.d.ts +1 -0
- package/types/helpers/index.d.ts +1 -0
- package/types/index.d.cts +6 -1
- package/types/models.d.ts +3 -1
- package/types/node/event.d.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -163,6 +163,19 @@ function html(value3, sanitisation) {
|
|
|
163
163
|
var templates = {};
|
|
164
164
|
|
|
165
165
|
// node_modules/@oscarpalmer/sentinel/node_modules/@oscarpalmer/atoms/dist/js/queue.mjs
|
|
166
|
+
function queue(callback) {
|
|
167
|
+
_atomic_queued.add(callback);
|
|
168
|
+
if (_atomic_queued.size > 0) {
|
|
169
|
+
queueMicrotask(() => {
|
|
170
|
+
const callbacks = [..._atomic_queued];
|
|
171
|
+
const { length } = callbacks;
|
|
172
|
+
_atomic_queued.clear();
|
|
173
|
+
for (let index = 0;index < length; index += 1) {
|
|
174
|
+
callbacks[index]();
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
166
179
|
if (globalThis._atomic_queued == null) {
|
|
167
180
|
const queued = new Set;
|
|
168
181
|
Object.defineProperty(globalThis, "_atomic_queued", {
|
|
@@ -186,6 +199,22 @@ if (globalThis._sentinels == null) {
|
|
|
186
199
|
function effect(callback) {
|
|
187
200
|
return new Effect(callback);
|
|
188
201
|
}
|
|
202
|
+
function watch(reactive, key) {
|
|
203
|
+
const effect2 = globalThis._sentinels[globalThis._sentinels.length - 1];
|
|
204
|
+
if (effect2 != null) {
|
|
205
|
+
if (key == null) {
|
|
206
|
+
reactive.callbacks.any.add(effect2);
|
|
207
|
+
} else {
|
|
208
|
+
if (!reactive.callbacks.keys.has(key)) {
|
|
209
|
+
reactive.callbacks.keys.add(key);
|
|
210
|
+
reactive.callbacks.values.set(key, new Set);
|
|
211
|
+
}
|
|
212
|
+
reactive.callbacks.values.get(key)?.add(effect2);
|
|
213
|
+
}
|
|
214
|
+
effect2.reactives.add(reactive);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
189
218
|
class Effect {
|
|
190
219
|
$sentinel = "effect";
|
|
191
220
|
state;
|
|
@@ -230,7 +259,97 @@ function isSentinel(value3, expression) {
|
|
|
230
259
|
return expression.test(value3?.$sentinel ?? "");
|
|
231
260
|
}
|
|
232
261
|
|
|
262
|
+
// node_modules/@oscarpalmer/sentinel/node_modules/@oscarpalmer/atoms/dist/js/function.mjs
|
|
263
|
+
function noop() {
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// node_modules/@oscarpalmer/sentinel/dist/helpers/subscription.mjs
|
|
267
|
+
function subscribe(state, subscriber, key) {
|
|
268
|
+
let set5;
|
|
269
|
+
if (key != null) {
|
|
270
|
+
if (state.callbacks.keys.has(key)) {
|
|
271
|
+
set5 = state.callbacks.values.get(key);
|
|
272
|
+
} else {
|
|
273
|
+
set5 = new Set;
|
|
274
|
+
state.callbacks.keys.add(key);
|
|
275
|
+
state.callbacks.values.set(key, set5);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
set5 = state.callbacks.any;
|
|
279
|
+
}
|
|
280
|
+
if (set5 == null || set5.has(subscriber)) {
|
|
281
|
+
return noop;
|
|
282
|
+
}
|
|
283
|
+
set5.add(subscriber);
|
|
284
|
+
subscriber(state.value);
|
|
285
|
+
return () => {
|
|
286
|
+
unsubscribe(state, subscriber, key);
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
function unsubscribe(state, subscriber, key) {
|
|
290
|
+
if (key != null) {
|
|
291
|
+
const set5 = state.callbacks.values.get(key);
|
|
292
|
+
if (set5 != null) {
|
|
293
|
+
if (subscriber == null) {
|
|
294
|
+
set5.clear();
|
|
295
|
+
} else {
|
|
296
|
+
set5.delete(subscriber);
|
|
297
|
+
}
|
|
298
|
+
if (set5.size === 0) {
|
|
299
|
+
state.callbacks.keys.delete(key);
|
|
300
|
+
state.callbacks.values.delete(key);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
} else if (subscriber != null) {
|
|
304
|
+
state.callbacks.any.delete(subscriber);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// node_modules/@oscarpalmer/sentinel/dist/helpers/event.mjs
|
|
309
|
+
function disable(state) {
|
|
310
|
+
if (state.active) {
|
|
311
|
+
state.active = false;
|
|
312
|
+
const effects = [...state.callbacks.any, ...state.callbacks.values.values()].flatMap((value3) => value3 instanceof Set ? [...value3.values()] : value3).filter((value3) => typeof value3 !== "function");
|
|
313
|
+
for (const fx of effects) {
|
|
314
|
+
if (typeof fx !== "function") {
|
|
315
|
+
fx.reactives.delete(state);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function emit(state, keys) {
|
|
321
|
+
if (state.active) {
|
|
322
|
+
const subscribers = [
|
|
323
|
+
...state.callbacks.any,
|
|
324
|
+
...[...state.callbacks.values.entries()].filter(([key]) => keys == null || keys.includes(key)).map(([, value3]) => value3)
|
|
325
|
+
].flatMap((value3) => value3 instanceof Set ? [...value3.values()] : value3).map((value3) => typeof value3 === "function" ? value3 : value3.callback);
|
|
326
|
+
for (const subsriber of subscribers) {
|
|
327
|
+
if (typeof subsriber === "function") {
|
|
328
|
+
queue(() => {
|
|
329
|
+
subsriber(state.value);
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function enable(state) {
|
|
336
|
+
if (!state.active) {
|
|
337
|
+
state.active = true;
|
|
338
|
+
emit(state);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
233
342
|
// node_modules/@oscarpalmer/sentinel/dist/helpers/value.mjs
|
|
343
|
+
function getValue3(reactive, key) {
|
|
344
|
+
watch(reactive, typeof key === "symbol" ? undefined : key);
|
|
345
|
+
return key == null ? reactive.value : Array.isArray(reactive.value) ? reactive.value.at(key) : reactive.value[key];
|
|
346
|
+
}
|
|
347
|
+
function setValue3(reactive, value3) {
|
|
348
|
+
if (!Object.is(reactive.value, value3)) {
|
|
349
|
+
reactive.value = value3;
|
|
350
|
+
emit(reactive);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
234
353
|
var arrayOperations = new Set([
|
|
235
354
|
"copyWithin",
|
|
236
355
|
"fill",
|
|
@@ -242,10 +361,87 @@ var arrayOperations = new Set([
|
|
|
242
361
|
"splice",
|
|
243
362
|
"unshift"
|
|
244
363
|
]);
|
|
364
|
+
|
|
365
|
+
// node_modules/@oscarpalmer/sentinel/dist/reactive/instance.mjs
|
|
366
|
+
class ReactiveInstance {
|
|
367
|
+
state;
|
|
368
|
+
constructor(type, value22) {
|
|
369
|
+
this.$sentinel = type;
|
|
370
|
+
this.state = {
|
|
371
|
+
value: value22,
|
|
372
|
+
active: true,
|
|
373
|
+
callbacks: {
|
|
374
|
+
any: new Set,
|
|
375
|
+
keys: new Set,
|
|
376
|
+
values: new Map
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
get() {
|
|
381
|
+
return getValue3(this.state);
|
|
382
|
+
}
|
|
383
|
+
peek() {
|
|
384
|
+
return this.state.value;
|
|
385
|
+
}
|
|
386
|
+
run() {
|
|
387
|
+
enable(this.state);
|
|
388
|
+
}
|
|
389
|
+
stop() {
|
|
390
|
+
disable(this.state);
|
|
391
|
+
}
|
|
392
|
+
toJSON() {
|
|
393
|
+
return getValue3(this.state);
|
|
394
|
+
}
|
|
395
|
+
toString() {
|
|
396
|
+
return String(getValue3(this.state));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// node_modules/@oscarpalmer/sentinel/dist/reactive/value.mjs
|
|
401
|
+
class ReactiveValue extends ReactiveInstance {
|
|
402
|
+
subscribe(subscriber) {
|
|
403
|
+
return subscribe(this.state, subscriber);
|
|
404
|
+
}
|
|
405
|
+
unsubscribe(subscriber) {
|
|
406
|
+
if (subscriber == null) {
|
|
407
|
+
this.state.callbacks.any.clear();
|
|
408
|
+
} else {
|
|
409
|
+
this.state.callbacks.any.delete(subscriber);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// node_modules/@oscarpalmer/sentinel/dist/reactive/computed.mjs
|
|
415
|
+
function computed(value32) {
|
|
416
|
+
return new Computed(value32);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
class Computed extends ReactiveValue {
|
|
420
|
+
fx;
|
|
421
|
+
constructor(value32) {
|
|
422
|
+
super("computed", undefined);
|
|
423
|
+
this.fx = effect(() => setValue3(this.state, value32()));
|
|
424
|
+
}
|
|
425
|
+
run() {
|
|
426
|
+
this.fx.start();
|
|
427
|
+
}
|
|
428
|
+
stop() {
|
|
429
|
+
this.fx.stop();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
245
432
|
// node_modules/@oscarpalmer/sentinel/dist/reactive/index.mjs
|
|
246
433
|
var primitives = new Set(["boolean", "number", "string"]);
|
|
247
434
|
|
|
248
435
|
// src/helpers/index.ts
|
|
436
|
+
function compareArrays(first, second) {
|
|
437
|
+
const firstIsLarger = first.length > second.length;
|
|
438
|
+
const from = firstIsLarger ? first : second;
|
|
439
|
+
const to = firstIsLarger ? second : first;
|
|
440
|
+
if (!from.filter((key) => to.includes(key)).every((key, index) => to[index] === key)) {
|
|
441
|
+
return "dissimilar";
|
|
442
|
+
}
|
|
443
|
+
return firstIsLarger ? "removed" : "added";
|
|
444
|
+
}
|
|
249
445
|
function isFragment(value11) {
|
|
250
446
|
return typeof value11 === "object" && value11 != null && "$fragment" in value11 && value11.$fragment === true;
|
|
251
447
|
}
|
|
@@ -256,6 +452,42 @@ function isProperNode(value11) {
|
|
|
256
452
|
return value11 instanceof CharacterData || value11 instanceof Element;
|
|
257
453
|
}
|
|
258
454
|
|
|
455
|
+
// src/node/event.ts
|
|
456
|
+
function getController(element) {
|
|
457
|
+
let controller = controllers.get(element);
|
|
458
|
+
if (controller == null) {
|
|
459
|
+
controller = new AbortController;
|
|
460
|
+
controllers.set(element, controller);
|
|
461
|
+
}
|
|
462
|
+
return controller;
|
|
463
|
+
}
|
|
464
|
+
function getOptions(options) {
|
|
465
|
+
const parts = options.split(":");
|
|
466
|
+
return {
|
|
467
|
+
capture: parts.includes("c") || parts.includes("capture"),
|
|
468
|
+
once: parts.includes("o") || parts.includes("once"),
|
|
469
|
+
passive: !parts.includes("a") && !parts.includes("active")
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function mapEvent(element, name, value11) {
|
|
473
|
+
element.removeAttribute(name);
|
|
474
|
+
const [, type, options] = eventNamePattern.exec(name) ?? [];
|
|
475
|
+
if (typeof value11 === "function" && type != null) {
|
|
476
|
+
element.addEventListener(type, value11, {
|
|
477
|
+
...getOptions(options ?? ""),
|
|
478
|
+
signal: getController(element).signal
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function removeEvents(element) {
|
|
483
|
+
if (controllers.has(element)) {
|
|
484
|
+
controllers.get(element)?.abort();
|
|
485
|
+
controllers.delete(element);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
var controllers = new WeakMap;
|
|
489
|
+
var eventNamePattern = /^@([\w-]+)(?::([a-z:]+))?$/i;
|
|
490
|
+
|
|
259
491
|
// src/helpers/dom.ts
|
|
260
492
|
function createNodes(value11) {
|
|
261
493
|
if (isFragment(value11)) {
|
|
@@ -266,32 +498,30 @@ function createNodes(value11) {
|
|
|
266
498
|
}
|
|
267
499
|
return [new Text(getString(value11))];
|
|
268
500
|
}
|
|
269
|
-
function
|
|
270
|
-
|
|
501
|
+
function removeNodes(nodes) {
|
|
502
|
+
sanitiseNodes2(nodes);
|
|
503
|
+
const { length } = nodes;
|
|
271
504
|
for (let index = 0;index < length; index += 1) {
|
|
272
|
-
|
|
273
|
-
if (index === 0) {
|
|
274
|
-
node.replaceWith(...to);
|
|
275
|
-
} else {
|
|
276
|
-
node.remove();
|
|
277
|
-
}
|
|
505
|
+
nodes[index].remove();
|
|
278
506
|
}
|
|
279
507
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
once: parts.includes("o") || parts.includes("once"),
|
|
287
|
-
passive: !parts.includes("a") && !parts.includes("active")
|
|
288
|
-
};
|
|
508
|
+
function replaceNodes(from, to) {
|
|
509
|
+
from[0]?.replaceWith(...to);
|
|
510
|
+
const { length } = from;
|
|
511
|
+
for (let index = 1;index < length; index += 1) {
|
|
512
|
+
from[index].remove();
|
|
513
|
+
}
|
|
289
514
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
515
|
+
function sanitiseNodes2(nodes) {
|
|
516
|
+
const { length } = nodes;
|
|
517
|
+
for (let index = 0;index < length; index += 1) {
|
|
518
|
+
const node = nodes[index];
|
|
519
|
+
if (isProperElement(node)) {
|
|
520
|
+
removeEvents(node);
|
|
521
|
+
}
|
|
522
|
+
if (node.hasChildNodes()) {
|
|
523
|
+
sanitiseNodes2([...node.childNodes]);
|
|
524
|
+
}
|
|
295
525
|
}
|
|
296
526
|
}
|
|
297
527
|
|
|
@@ -299,10 +529,10 @@ function mapEvent(element, name, value11) {
|
|
|
299
529
|
function setAttribute2(element, name, value11) {
|
|
300
530
|
element.removeAttribute(name);
|
|
301
531
|
switch (true) {
|
|
302
|
-
case
|
|
532
|
+
case classExpression.test(name):
|
|
303
533
|
setClasses(element, name, value11);
|
|
304
534
|
return;
|
|
305
|
-
case
|
|
535
|
+
case stylePrefixExpression.test(name):
|
|
306
536
|
setStyle(element, name, value11);
|
|
307
537
|
return;
|
|
308
538
|
default:
|
|
@@ -312,7 +542,7 @@ function setAttribute2(element, name, value11) {
|
|
|
312
542
|
}
|
|
313
543
|
function setClasses(element, name, value11) {
|
|
314
544
|
function update(value12) {
|
|
315
|
-
if (
|
|
545
|
+
if (value12 === true) {
|
|
316
546
|
element.classList.add(...classes);
|
|
317
547
|
} else {
|
|
318
548
|
element.classList.remove(...classes);
|
|
@@ -335,16 +565,15 @@ function setStyle(element, name, value11) {
|
|
|
335
565
|
element.style.setProperty(property, value12 === true ? unit : getString(value12));
|
|
336
566
|
}
|
|
337
567
|
}
|
|
338
|
-
const [, property, unit] =
|
|
339
|
-
if (property
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
update(value11);
|
|
568
|
+
const [, property, unit] = styleFullExpression.exec(name) ?? [];
|
|
569
|
+
if (property != null) {
|
|
570
|
+
if (isReactive(value11)) {
|
|
571
|
+
effect(() => {
|
|
572
|
+
update(value11.get());
|
|
573
|
+
});
|
|
574
|
+
} else {
|
|
575
|
+
update(value11);
|
|
576
|
+
}
|
|
348
577
|
}
|
|
349
578
|
}
|
|
350
579
|
function setValue5(element, name, value11) {
|
|
@@ -363,7 +592,7 @@ function triggerSelectChange(select) {
|
|
|
363
592
|
}
|
|
364
593
|
}
|
|
365
594
|
function updateProperty(element, name, value11) {
|
|
366
|
-
element[name] =
|
|
595
|
+
element[name] = value11 === true;
|
|
367
596
|
}
|
|
368
597
|
function updateSelected(element, name, value11) {
|
|
369
598
|
const select = element.closest("select");
|
|
@@ -373,8 +602,9 @@ function updateSelected(element, name, value11) {
|
|
|
373
602
|
}
|
|
374
603
|
updateProperty(element, name, value11);
|
|
375
604
|
}
|
|
376
|
-
var
|
|
377
|
-
var
|
|
605
|
+
var classExpression = /^class\./;
|
|
606
|
+
var styleFullExpression = /^style\.([\w-]+)(?:\.([\w-]+))?$/;
|
|
607
|
+
var stylePrefixExpression = /^style\./;
|
|
378
608
|
|
|
379
609
|
// src/node/attribute/index.ts
|
|
380
610
|
function getValue5(data, original) {
|
|
@@ -389,7 +619,7 @@ function mapAttributes(data, element) {
|
|
|
389
619
|
const actual = getValue5(data, value12);
|
|
390
620
|
if (name.startsWith("@")) {
|
|
391
621
|
mapEvent(element, name, actual);
|
|
392
|
-
} else if (name.includes(".") || isReactive(actual)) {
|
|
622
|
+
} else if (name.includes(".") || typeof value12 === "function" || isReactive(actual)) {
|
|
393
623
|
mapValue(element, name, actual);
|
|
394
624
|
}
|
|
395
625
|
}
|
|
@@ -397,8 +627,8 @@ function mapAttributes(data, element) {
|
|
|
397
627
|
function mapValue(element, name, value12) {
|
|
398
628
|
switch (true) {
|
|
399
629
|
case typeof value12 === "function":
|
|
400
|
-
|
|
401
|
-
|
|
630
|
+
setAttribute2(element, name, computed(value12));
|
|
631
|
+
break;
|
|
402
632
|
default:
|
|
403
633
|
setAttribute2(element, name, value12);
|
|
404
634
|
break;
|
|
@@ -407,8 +637,66 @@ function mapValue(element, name, value12) {
|
|
|
407
637
|
var commentExpression = /^<!--abydon\.(\d+)-->$/;
|
|
408
638
|
|
|
409
639
|
// src/node/value.ts
|
|
410
|
-
function
|
|
411
|
-
|
|
640
|
+
function removeFragments(fragments) {
|
|
641
|
+
if (fragments != null) {
|
|
642
|
+
const { length } = fragments;
|
|
643
|
+
for (let index = 0;index < length; index += 1) {
|
|
644
|
+
fragments[index].remove();
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function setArray(fragments, nodes, comment, text, value12) {
|
|
649
|
+
if (value12.length === 0) {
|
|
650
|
+
return {
|
|
651
|
+
nodes: setText(fragments, nodes, comment, text, value12)
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
let templates2 = value12.filter((item) => isFragment(item) && item.identifier != null);
|
|
655
|
+
const identifiers = templates2.map((fragment) => fragment.identifier);
|
|
656
|
+
const oldIdentifiers = fragments?.map((fragment) => fragment.identifier) ?? [];
|
|
657
|
+
if (new Set(identifiers).size !== templates2.length) {
|
|
658
|
+
templates2 = [];
|
|
659
|
+
}
|
|
660
|
+
const noTemplates = templates2.length === 0;
|
|
661
|
+
if (noTemplates || nodes == null || oldIdentifiers.some((identifier) => identifier == null)) {
|
|
662
|
+
return {
|
|
663
|
+
fragments: noTemplates ? undefined : templates2,
|
|
664
|
+
nodes: setNodes(fragments, nodes, comment, text, noTemplates ? value12.flatMap((item) => createNodes(item)) : templates2.flatMap((template4) => template4.get()))
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
const next = templates2.map((template4) => fragments?.find((fragment) => fragment.identifier === template4.identifier) ?? template4);
|
|
668
|
+
const comparison = compareArrays(fragments ?? [], templates2);
|
|
669
|
+
if (comparison !== "removed") {
|
|
670
|
+
let position = nodes[0];
|
|
671
|
+
const before = comparison === "added" && !oldIdentifiers.includes(templates2[0].identifier);
|
|
672
|
+
const items = next.flatMap((fragment) => fragment.get().flatMap((node) => ({
|
|
673
|
+
identifier: fragment.identifier,
|
|
674
|
+
value: node
|
|
675
|
+
})));
|
|
676
|
+
const { length: length2 } = items;
|
|
677
|
+
for (let index = 0;index < length2; index += 1) {
|
|
678
|
+
const item = items[index];
|
|
679
|
+
if (comparison === "dissimilar" || !oldIdentifiers.includes(item.identifier)) {
|
|
680
|
+
if (index === 0 && before) {
|
|
681
|
+
position.before(item.value);
|
|
682
|
+
} else {
|
|
683
|
+
position.after(item.value);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
position = item.value;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
const toRemove = fragments?.filter((fragment) => !identifiers.includes(fragment.identifier)) ?? [];
|
|
690
|
+
const { length } = toRemove;
|
|
691
|
+
for (let index = 0;index < length; index += 1) {
|
|
692
|
+
toRemove[index].remove();
|
|
693
|
+
}
|
|
694
|
+
return {
|
|
695
|
+
fragments: next,
|
|
696
|
+
nodes: next.flatMap((fragment) => fragment.get())
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
function setNodes(fragments, nodes, comment, text, next) {
|
|
412
700
|
if (nodes == null) {
|
|
413
701
|
if (comment.parentNode != null) {
|
|
414
702
|
replaceNodes([comment], next);
|
|
@@ -418,42 +706,50 @@ function setNodes(nodes, comment, text, value12) {
|
|
|
418
706
|
} else {
|
|
419
707
|
replaceNodes(nodes, next);
|
|
420
708
|
}
|
|
709
|
+
removeFragments(fragments);
|
|
421
710
|
return next;
|
|
422
711
|
}
|
|
423
712
|
function setReactiveNode(data, comment, reactive3) {
|
|
424
713
|
const item = data.items.find((item2) => item2.nodes.includes(comment));
|
|
425
714
|
const text = new Text;
|
|
715
|
+
let fragments;
|
|
426
716
|
let nodes;
|
|
427
717
|
effect(() => {
|
|
428
718
|
const value12 = reactive3.get();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
719
|
+
if (Array.isArray(value12)) {
|
|
720
|
+
const result = setArray(fragments, nodes, comment, text, value12);
|
|
721
|
+
fragments = typeof result === "boolean" ? undefined : result?.fragments;
|
|
722
|
+
nodes = typeof result === "boolean" ? result ? [text] : undefined : result?.nodes;
|
|
432
723
|
} else {
|
|
433
|
-
|
|
724
|
+
const valueIsFragment = isFragment(value12);
|
|
725
|
+
fragments = valueIsFragment ? [value12] : undefined;
|
|
726
|
+
if (valueIsFragment || isProperNode(value12)) {
|
|
727
|
+
nodes = setNodes(fragments, nodes, comment, text, createNodes(value12));
|
|
728
|
+
} else {
|
|
729
|
+
nodes = setText(fragments, nodes, comment, text, value12);
|
|
730
|
+
}
|
|
434
731
|
}
|
|
435
732
|
if (item != null) {
|
|
436
|
-
item.
|
|
733
|
+
item.fragments = fragments;
|
|
437
734
|
item.nodes = [...nodes ?? [comment]];
|
|
438
735
|
}
|
|
439
736
|
});
|
|
440
737
|
}
|
|
441
|
-
function setText(nodes, comment, text, value12) {
|
|
738
|
+
function setText(fragments, nodes, comment, text, value12) {
|
|
442
739
|
const isNullable = isNullableOrWhitespace(value12);
|
|
443
740
|
text.textContent = isNullable ? "" : getString(value12);
|
|
741
|
+
let result = false;
|
|
444
742
|
if (nodes != null) {
|
|
445
743
|
replaceNodes(nodes, [isNullable ? comment : text]);
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
if (isNullable && comment.parentNode == null) {
|
|
744
|
+
result = !isNullable;
|
|
745
|
+
} else if (isNullable && comment.parentNode == null) {
|
|
449
746
|
text.replaceWith(comment);
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
if (!isNullable && text.parentNode == null) {
|
|
747
|
+
} else if (!isNullable && text.parentNode == null) {
|
|
453
748
|
comment.replaceWith(text);
|
|
454
|
-
|
|
749
|
+
result = true;
|
|
455
750
|
}
|
|
456
|
-
|
|
751
|
+
removeFragments(fragments);
|
|
752
|
+
return result ? [text] : undefined;
|
|
457
753
|
}
|
|
458
754
|
|
|
459
755
|
// src/node/index.ts
|
|
@@ -483,8 +779,8 @@ function mapNodes(data, nodes) {
|
|
|
483
779
|
function mapValue2(data, comment, value13) {
|
|
484
780
|
switch (true) {
|
|
485
781
|
case typeof value13 === "function":
|
|
486
|
-
|
|
487
|
-
|
|
782
|
+
setReactiveNode(data, comment, computed(value13));
|
|
783
|
+
break;
|
|
488
784
|
case isReactive(value13):
|
|
489
785
|
setReactiveNode(data, comment, value13);
|
|
490
786
|
break;
|
|
@@ -497,7 +793,7 @@ function replaceComment(data, comment, value13) {
|
|
|
497
793
|
const item = data.items.find((item2) => item2.nodes.includes(comment));
|
|
498
794
|
const nodes = createNodes(value13);
|
|
499
795
|
if (item != null) {
|
|
500
|
-
item.
|
|
796
|
+
item.fragments = isFragment(value13) ? [value13] : undefined;
|
|
501
797
|
item.nodes = nodes;
|
|
502
798
|
}
|
|
503
799
|
comment.replaceWith(...nodes);
|
|
@@ -508,6 +804,9 @@ var commentExpression2 = /^abydon\.(\d+)$/;
|
|
|
508
804
|
class Fragment {
|
|
509
805
|
$fragment = true;
|
|
510
806
|
data;
|
|
807
|
+
get identifier() {
|
|
808
|
+
return this.data.identifier;
|
|
809
|
+
}
|
|
511
810
|
constructor(strings, expressions) {
|
|
512
811
|
this.data = {
|
|
513
812
|
expressions,
|
|
@@ -528,20 +827,25 @@ class Fragment {
|
|
|
528
827
|
this.data.items.splice(0, this.data.items.length, ...templated.map((node2) => ({
|
|
529
828
|
nodes: [node2]
|
|
530
829
|
})));
|
|
531
|
-
mapNodes(this.data, this.data.items.flatMap((item) => item.fragment
|
|
830
|
+
mapNodes(this.data, this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes));
|
|
532
831
|
}
|
|
533
832
|
return [
|
|
534
|
-
...this.data.items.flatMap((item) => item.fragment
|
|
833
|
+
...this.data.items.flatMap((item) => item.fragments?.flatMap((fragment) => fragment.get()) ?? item.nodes)
|
|
535
834
|
];
|
|
536
835
|
}
|
|
836
|
+
identify(identifier) {
|
|
837
|
+
this.data.identifier = identifier;
|
|
838
|
+
return this;
|
|
839
|
+
}
|
|
537
840
|
remove() {
|
|
538
841
|
const { length } = this.data.items;
|
|
539
842
|
for (let index = 0;index < length; index += 1) {
|
|
540
|
-
const
|
|
541
|
-
|
|
542
|
-
for (
|
|
543
|
-
|
|
843
|
+
const { fragments, nodes } = this.data.items[index];
|
|
844
|
+
const { length: length2 } = fragments ?? [];
|
|
845
|
+
for (let index2 = 0;index2 < length2; index2 += 1) {
|
|
846
|
+
fragments?.[index2]?.remove();
|
|
544
847
|
}
|
|
848
|
+
removeNodes(nodes);
|
|
545
849
|
}
|
|
546
850
|
this.data.items.splice(0, length);
|
|
547
851
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/node/attribute/index.ts
|
|
2
|
-
import {isReactive} from "@oscarpalmer/sentinel";
|
|
2
|
+
import {computed, isReactive} from "@oscarpalmer/sentinel";
|
|
3
3
|
import {mapEvent} from "../event";
|
|
4
4
|
import {setAttribute} from "./value";
|
|
5
5
|
function getValue(data, original) {
|
|
@@ -14,7 +14,7 @@ function mapAttributes(data, element) {
|
|
|
14
14
|
const actual = getValue(data, value2);
|
|
15
15
|
if (name.startsWith("@")) {
|
|
16
16
|
mapEvent(element, name, actual);
|
|
17
|
-
} else if (name.includes(".") || isReactive(actual)) {
|
|
17
|
+
} else if (name.includes(".") || typeof value2 === "function" || isReactive(actual)) {
|
|
18
18
|
mapValue(element, name, actual);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -22,8 +22,8 @@ function mapAttributes(data, element) {
|
|
|
22
22
|
function mapValue(element, name, value2) {
|
|
23
23
|
switch (true) {
|
|
24
24
|
case typeof value2 === "function":
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
setAttribute(element, name, computed(value2));
|
|
26
|
+
break;
|
|
27
27
|
default:
|
|
28
28
|
setAttribute(element, name, value2);
|
|
29
29
|
break;
|
|
@@ -8,10 +8,10 @@ setAttribute as setAttr
|
|
|
8
8
|
function setAttribute(element, name, value) {
|
|
9
9
|
element.removeAttribute(name);
|
|
10
10
|
switch (true) {
|
|
11
|
-
case
|
|
11
|
+
case classExpression.test(name):
|
|
12
12
|
setClasses(element, name, value);
|
|
13
13
|
return;
|
|
14
|
-
case
|
|
14
|
+
case stylePrefixExpression.test(name):
|
|
15
15
|
setStyle(element, name, value);
|
|
16
16
|
return;
|
|
17
17
|
default:
|
|
@@ -21,7 +21,7 @@ function setAttribute(element, name, value) {
|
|
|
21
21
|
}
|
|
22
22
|
function setClasses(element, name, value) {
|
|
23
23
|
function update(value2) {
|
|
24
|
-
if (
|
|
24
|
+
if (value2 === true) {
|
|
25
25
|
element.classList.add(...classes);
|
|
26
26
|
} else {
|
|
27
27
|
element.classList.remove(...classes);
|
|
@@ -44,16 +44,15 @@ function setStyle(element, name, value) {
|
|
|
44
44
|
element.style.setProperty(property, value2 === true ? unit : getString(value2));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
const [, property, unit] =
|
|
48
|
-
if (property
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
update(value);
|
|
47
|
+
const [, property, unit] = styleFullExpression.exec(name) ?? [];
|
|
48
|
+
if (property != null) {
|
|
49
|
+
if (isReactive(value)) {
|
|
50
|
+
effect(() => {
|
|
51
|
+
update(value.get());
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
update(value);
|
|
55
|
+
}
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
function setValue(element, name, value) {
|
|
@@ -72,7 +71,7 @@ function triggerSelectChange(select) {
|
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
function updateProperty(element, name, value) {
|
|
75
|
-
element[name] =
|
|
74
|
+
element[name] = value === true;
|
|
76
75
|
}
|
|
77
76
|
function updateSelected(element, name, value) {
|
|
78
77
|
const select = element.closest("select");
|
|
@@ -82,8 +81,9 @@ function updateSelected(element, name, value) {
|
|
|
82
81
|
}
|
|
83
82
|
updateProperty(element, name, value);
|
|
84
83
|
}
|
|
85
|
-
var
|
|
86
|
-
var
|
|
84
|
+
var classExpression = /^class\./;
|
|
85
|
+
var styleFullExpression = /^style\.([\w-]+)(?:\.([\w-]+))?$/;
|
|
86
|
+
var stylePrefixExpression = /^style\./;
|
|
87
87
|
export {
|
|
88
88
|
setAttribute
|
|
89
89
|
};
|