@source-crafter/xzor-runtime 0.1.16 → 0.1.17
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/fine.d.ts +11 -0
- package/{index-w2yxrgd1.js → index-45b6cjyv.js} +5 -3
- package/{index-w2yxrgd1.js.map → index-45b6cjyv.js.map} +3 -3
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/model.js +172 -42
- package/model.js.map +3 -3
- package/package.json +1 -1
package/model.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
patchIsland,
|
|
10
10
|
setFineHooks,
|
|
11
11
|
setRenderObserver
|
|
12
|
-
} from "./index-
|
|
12
|
+
} from "./index-45b6cjyv.js";
|
|
13
13
|
|
|
14
14
|
// runtime/entity-set.ts
|
|
15
15
|
class EntitySet extends Array {
|
|
@@ -238,6 +238,10 @@ var LOOSE = 64;
|
|
|
238
238
|
var ITEM = 128;
|
|
239
239
|
var OWNED = 256;
|
|
240
240
|
var FRESH = 512;
|
|
241
|
+
var SHOW = 1024;
|
|
242
|
+
var PAUSE = 2048;
|
|
243
|
+
var PAUSED = 4096;
|
|
244
|
+
var STALE = 8192;
|
|
241
245
|
var bitOf = (index) => index === -1 ? 1 << 31 : index < 30 ? 1 << index : 1 << 30;
|
|
242
246
|
var MEMOS = Symbol("xzor.fine.memos");
|
|
243
247
|
var EMPTY = Symbol("xzor.fine.empty");
|
|
@@ -363,7 +367,7 @@ class Binding {
|
|
|
363
367
|
}
|
|
364
368
|
}
|
|
365
369
|
#loose() {
|
|
366
|
-
if ((this.flags & (LOOSE | DEAD)) !== 0 || (this.flags & KIND) >= EFFECT || holder === undefined)
|
|
370
|
+
if ((this.flags & (LOOSE | DEAD | PAUSE)) !== 0 || (this.flags & KIND) >= EFFECT || holder === undefined)
|
|
367
371
|
return;
|
|
368
372
|
this.flags |= LOOSE;
|
|
369
373
|
holder.ctx.loose.push(this);
|
|
@@ -384,8 +388,13 @@ class Binding {
|
|
|
384
388
|
}
|
|
385
389
|
stateHasChanged() {
|
|
386
390
|
const flags = this.flags;
|
|
387
|
-
if ((flags & DEAD) !== 0)
|
|
391
|
+
if ((flags & (DEAD | PAUSED)) !== 0) {
|
|
392
|
+
if ((flags & DEAD) === 0)
|
|
393
|
+
this.flags |= STALE;
|
|
388
394
|
return;
|
|
395
|
+
}
|
|
396
|
+
if ((flags & SHOW) !== 0)
|
|
397
|
+
return this.#show();
|
|
389
398
|
switch (flags & KIND) {
|
|
390
399
|
case TEXT: {
|
|
391
400
|
const value = this.#run();
|
|
@@ -403,6 +412,13 @@ class Binding {
|
|
|
403
412
|
return setAttr(this.node, (flags & ITEM) !== 0 ? this.read.$n : this.data, this.#run());
|
|
404
413
|
case REGION: {
|
|
405
414
|
const region = this.data;
|
|
415
|
+
const branch = region.branch;
|
|
416
|
+
if (branch !== undefined) {
|
|
417
|
+
const index = this.#run();
|
|
418
|
+
if (index === region.index)
|
|
419
|
+
return;
|
|
420
|
+
region.index = index;
|
|
421
|
+
}
|
|
406
422
|
disposeAll(region);
|
|
407
423
|
const end = this.node;
|
|
408
424
|
const parent = end.parentNode;
|
|
@@ -412,7 +428,7 @@ class Binding {
|
|
|
412
428
|
node = next;
|
|
413
429
|
}
|
|
414
430
|
const frag = document.createDocumentFragment();
|
|
415
|
-
within(region, () => this.#run(frag));
|
|
431
|
+
within(region, () => branch !== undefined ? untracked(() => branch(frag)) : this.#run(frag));
|
|
416
432
|
parent.insertBefore(frag, end);
|
|
417
433
|
return;
|
|
418
434
|
}
|
|
@@ -431,6 +447,36 @@ class Binding {
|
|
|
431
447
|
return;
|
|
432
448
|
}
|
|
433
449
|
}
|
|
450
|
+
#show() {
|
|
451
|
+
const show = this.data;
|
|
452
|
+
const index = this.#run();
|
|
453
|
+
if (index === show.index)
|
|
454
|
+
return;
|
|
455
|
+
const shown = show.branches[show.index];
|
|
456
|
+
if (shown !== undefined)
|
|
457
|
+
hideBranch(shown);
|
|
458
|
+
show.index = index;
|
|
459
|
+
let branch = show.branches[index];
|
|
460
|
+
if (branch !== undefined)
|
|
461
|
+
return showBranch(branch);
|
|
462
|
+
branch = { bindings: undefined, ctx: show.ctx, start: show.start, item: undefined, branch: undefined, index: -1, first: null, els: [], display: [] };
|
|
463
|
+
show.branches[index] = branch;
|
|
464
|
+
const frag = document.createDocumentFragment();
|
|
465
|
+
within(branch, () => untracked(() => show.build(frag)));
|
|
466
|
+
branch.first = frag.firstChild;
|
|
467
|
+
for (let node = frag.firstChild;node !== null; node = node.nextSibling)
|
|
468
|
+
if (node.nodeType === 1)
|
|
469
|
+
branch.els.push(node);
|
|
470
|
+
let before = this.node;
|
|
471
|
+
for (let i = index + 1;i < show.branches.length; i++) {
|
|
472
|
+
const next = show.branches[i]?.first;
|
|
473
|
+
if (next) {
|
|
474
|
+
before = next;
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
before.parentNode.insertBefore(frag, before);
|
|
479
|
+
}
|
|
434
480
|
#becomeIsland() {
|
|
435
481
|
const read = this.read;
|
|
436
482
|
const h = this.data;
|
|
@@ -453,7 +499,10 @@ class Binding {
|
|
|
453
499
|
if ((this.flags & DEAD) !== 0)
|
|
454
500
|
return;
|
|
455
501
|
const kind = this.flags & KIND;
|
|
456
|
-
if (
|
|
502
|
+
if ((this.flags & SHOW) !== 0)
|
|
503
|
+
for (const branch of this.data.branches)
|
|
504
|
+
branch !== undefined && disposeAll(branch);
|
|
505
|
+
else if (kind === REGION)
|
|
457
506
|
disposeAll(this.data);
|
|
458
507
|
else if (kind === LIST || kind === KEYED)
|
|
459
508
|
for (const row of this.data.order)
|
|
@@ -529,12 +578,65 @@ function disposeAll(h) {
|
|
|
529
578
|
}
|
|
530
579
|
function refreshAll(h) {
|
|
531
580
|
for (let b = h.bindings;b !== undefined; b = b.next) {
|
|
532
|
-
b.stateHasChanged();
|
|
533
581
|
const kind = b.flags & KIND;
|
|
534
|
-
|
|
582
|
+
const kept = kind === REGION ? b.data.index : -1;
|
|
583
|
+
b.stateHasChanged();
|
|
584
|
+
if ((b.flags & SHOW) !== 0)
|
|
585
|
+
for (const branch of b.data.branches)
|
|
586
|
+
branch !== undefined && refreshAll(branch);
|
|
587
|
+
else if (kind === LIST || kind === KEYED)
|
|
535
588
|
for (const row of b.data.order)
|
|
536
589
|
refreshAll(row);
|
|
590
|
+
else if (kept !== -1 && kept === b.data.index)
|
|
591
|
+
refreshAll(b.data);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
function under(b, f) {
|
|
595
|
+
const kind = b.flags & KIND;
|
|
596
|
+
if ((b.flags & SHOW) !== 0)
|
|
597
|
+
for (const branch of b.data.branches)
|
|
598
|
+
branch !== undefined && f(branch);
|
|
599
|
+
else if (kind === REGION)
|
|
600
|
+
f(b.data);
|
|
601
|
+
else if (kind === LIST || kind === KEYED)
|
|
602
|
+
for (const row of b.data.order)
|
|
603
|
+
f(row);
|
|
604
|
+
}
|
|
605
|
+
function pauseIn(h) {
|
|
606
|
+
for (let b = h.bindings;b !== undefined; b = b.next) {
|
|
607
|
+
if ((b.flags & PAUSE) !== 0)
|
|
608
|
+
under(b, freeze);
|
|
609
|
+
else
|
|
610
|
+
under(b, pauseIn);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function freeze(h) {
|
|
614
|
+
for (let b = h.bindings;b !== undefined; b = b.next) {
|
|
615
|
+
b.flags |= PAUSED;
|
|
616
|
+
under(b, freeze);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
function thaw(h) {
|
|
620
|
+
for (let b = h.bindings;b !== undefined; b = b.next) {
|
|
621
|
+
const stale = (b.flags & STALE) !== 0;
|
|
622
|
+
b.flags &= ~(PAUSED | STALE);
|
|
623
|
+
if (stale)
|
|
624
|
+
b.stateHasChanged();
|
|
625
|
+
under(b, thaw);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
function hideBranch(branch) {
|
|
629
|
+
for (let i = 0;i < branch.els.length; i++) {
|
|
630
|
+
const style = branch.els[i].style;
|
|
631
|
+
branch.display[i] = style.display;
|
|
632
|
+
style.display = "none";
|
|
537
633
|
}
|
|
634
|
+
pauseIn(branch);
|
|
635
|
+
}
|
|
636
|
+
function showBranch(branch) {
|
|
637
|
+
for (let i = 0;i < branch.els.length; i++)
|
|
638
|
+
branch.els[i].style.display = branch.display[i] ?? "";
|
|
639
|
+
thaw(branch);
|
|
538
640
|
}
|
|
539
641
|
var textOf = (value) => value === null || value === undefined || value === false ? "" : String(value);
|
|
540
642
|
function setAttr(el, name, value) {
|
|
@@ -800,8 +902,8 @@ function on(el, event, handler, h) {
|
|
|
800
902
|
} else
|
|
801
903
|
el.addEventListener(event, (e) => afterHandler(h.ctx, handler(e)));
|
|
802
904
|
}
|
|
803
|
-
function region(start, end, build, item, flags) {
|
|
804
|
-
const region2 = { bindings: undefined, ctx: holder.ctx, start, item };
|
|
905
|
+
function region(start, end, build, item, flags, branch) {
|
|
906
|
+
const region2 = { bindings: undefined, ctx: holder.ctx, start, item, branch, index: -1 };
|
|
805
907
|
track(new Binding(REGION | flags, end, build, region2));
|
|
806
908
|
}
|
|
807
909
|
function list(end, items, reads, build, empty, key) {
|
|
@@ -809,6 +911,41 @@ function list(end, items, reads, build, empty, key) {
|
|
|
809
911
|
track(new Binding(LIST, end, items, state));
|
|
810
912
|
}
|
|
811
913
|
var anchor = (parent) => parent.appendChild(document.createComment(""));
|
|
914
|
+
function awaiting(end, pending, then, fail) {
|
|
915
|
+
const state = { phase: 0, value: undefined, seq: 0 };
|
|
916
|
+
const view = new Binding(REGION, end, (p) => {
|
|
917
|
+
if (state.phase === 0)
|
|
918
|
+
pending?.(p);
|
|
919
|
+
else if (state.phase === 1)
|
|
920
|
+
then?.(p, state.value);
|
|
921
|
+
else
|
|
922
|
+
fail?.(p, state.value);
|
|
923
|
+
}, { bindings: undefined, ctx: holder.ctx, start: end.previousSibling, item: undefined, branch: undefined, index: -1 });
|
|
924
|
+
const show = (phase, value) => {
|
|
925
|
+
if ((view.flags & DEAD) !== 0)
|
|
926
|
+
return;
|
|
927
|
+
state.phase = phase;
|
|
928
|
+
state.value = value;
|
|
929
|
+
view.stateHasChanged();
|
|
930
|
+
};
|
|
931
|
+
track(view);
|
|
932
|
+
return (result) => {
|
|
933
|
+
const seq = ++state.seq;
|
|
934
|
+
if (typeof result?.then !== "function")
|
|
935
|
+
return show(1, result);
|
|
936
|
+
if (state.phase !== 0)
|
|
937
|
+
show(0, undefined);
|
|
938
|
+
result.then((value) => seq === state.seq && show(1, value), (error) => {
|
|
939
|
+
if (seq !== state.seq)
|
|
940
|
+
return;
|
|
941
|
+
show(2, error);
|
|
942
|
+
if (fail === undefined)
|
|
943
|
+
queueMicrotask(() => {
|
|
944
|
+
throw error;
|
|
945
|
+
});
|
|
946
|
+
});
|
|
947
|
+
};
|
|
948
|
+
}
|
|
812
949
|
var fine = {
|
|
813
950
|
template(specs) {
|
|
814
951
|
let node;
|
|
@@ -879,6 +1016,16 @@ var fine = {
|
|
|
879
1016
|
regionAt(end, build) {
|
|
880
1017
|
region(end.previousSibling, end, build, undefined, 0);
|
|
881
1018
|
},
|
|
1019
|
+
branchAt(end, run) {
|
|
1020
|
+
region(end.previousSibling, end, run, undefined, 0, run);
|
|
1021
|
+
},
|
|
1022
|
+
showAt(end, run) {
|
|
1023
|
+
const show = { ctx: holder.ctx, start: end.previousSibling, index: -1, build: run, branches: [] };
|
|
1024
|
+
track(new Binding(REGION | SHOW, end, run, show));
|
|
1025
|
+
},
|
|
1026
|
+
pauseAt(end, build) {
|
|
1027
|
+
region(end.previousSibling, end, () => 0, undefined, PAUSE, build);
|
|
1028
|
+
},
|
|
882
1029
|
textOnce(node, read) {
|
|
883
1030
|
node.data = textOf(untracked(read));
|
|
884
1031
|
},
|
|
@@ -925,40 +1072,23 @@ var fine = {
|
|
|
925
1072
|
});
|
|
926
1073
|
},
|
|
927
1074
|
awaitAt(end, read, pending, then, fail) {
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
fail?.(p, state.value);
|
|
936
|
-
}, { bindings: undefined, ctx: holder.ctx, start: end.previousSibling, item: undefined });
|
|
937
|
-
const show = (phase, value) => {
|
|
938
|
-
if ((view.flags & DEAD) !== 0)
|
|
939
|
-
return;
|
|
940
|
-
state.phase = phase;
|
|
941
|
-
state.value = value;
|
|
942
|
-
view.stateHasChanged();
|
|
943
|
-
};
|
|
944
|
-
track(view);
|
|
1075
|
+
const show = awaiting(end, pending, then, fail);
|
|
1076
|
+
track(new Binding(EFFECT, end, () => show(read()), undefined));
|
|
1077
|
+
},
|
|
1078
|
+
awaitCallAt(end, args, call, pending, then, fail) {
|
|
1079
|
+
const show = awaiting(end, pending, then, fail);
|
|
1080
|
+
let last;
|
|
1081
|
+
const request = new Binding(EFFECT, end, () => show(call(...last)), undefined);
|
|
945
1082
|
track(new Binding(EFFECT, end, () => {
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
if (seq !== state.seq)
|
|
954
|
-
return;
|
|
955
|
-
show(2, error);
|
|
956
|
-
if (fail === undefined)
|
|
957
|
-
queueMicrotask(() => {
|
|
958
|
-
throw error;
|
|
959
|
-
});
|
|
960
|
-
});
|
|
1083
|
+
const next = args();
|
|
1084
|
+
if (last !== undefined && next.every((v, i) => Object.is(v, last[i])))
|
|
1085
|
+
return;
|
|
1086
|
+
const first = last === undefined;
|
|
1087
|
+
last = next;
|
|
1088
|
+
if (!first)
|
|
1089
|
+
request.stateHasChanged();
|
|
961
1090
|
}, undefined));
|
|
1091
|
+
track(request);
|
|
962
1092
|
},
|
|
963
1093
|
anchors(parent) {
|
|
964
1094
|
anchor(parent);
|
|
@@ -1770,5 +1900,5 @@ export {
|
|
|
1770
1900
|
requiredIdValue
|
|
1771
1901
|
};
|
|
1772
1902
|
|
|
1773
|
-
//# debugId=
|
|
1903
|
+
//# debugId=E7409C03C0112EDB64756E2164756E21
|
|
1774
1904
|
//# sourceMappingURL=model.js.map
|