@torpor/view 1.2.5 → 1.3.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/{AsyncOptions-ClS1_ERX.d.mts → AsyncOptions-BDtArmeL.d.mts} +2 -8
- package/dist/AsyncOptions-BDtArmeL.d.mts.map +1 -0
- package/dist/{AsyncOptions-BtMe2PAd.d.cts → AsyncOptions-C_7mWR6F.d.cts} +2 -8
- package/dist/AsyncOptions-C_7mWR6F.d.cts.map +1 -0
- package/dist/{Effect-DazmAdyC.d.mts → Effect-99HYQdzZ.d.mts} +50 -33
- package/dist/Effect-99HYQdzZ.d.mts.map +1 -0
- package/dist/{Effect-Dewn7MLc.d.cts → Effect-Bf8fz_zC.d.cts} +50 -33
- package/dist/Effect-Bf8fz_zC.d.cts.map +1 -0
- package/dist/compile.cjs +1509 -120
- package/dist/compile.d.cts +268 -1
- package/dist/compile.d.cts.map +1 -1
- package/dist/compile.d.mts +268 -1
- package/dist/compile.d.mts.map +1 -1
- package/dist/compile.mjs +1506 -121
- package/dist/compile.mjs.map +1 -1
- package/dist/dev.d.cts +1 -1
- package/dist/dev.d.mts +1 -1
- package/dist/{fromWebSocket-DrN-IduP.cjs → fromWebSocket-Cdoghvmh.cjs} +15 -0
- package/dist/{fromWebSocket-CFGoMkV2.mjs → fromWebSocket-ERhd9KZR.mjs} +11 -2
- package/dist/fromWebSocket-ERhd9KZR.mjs.map +1 -0
- package/dist/index.cjs +223 -158
- package/dist/index.d.cts +24 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +24 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +223 -158
- package/dist/index.mjs.map +1 -1
- package/dist/runtime.iife.js +1 -0
- package/dist/slotAutoClose-BbKfzpkz.cjs +177 -0
- package/dist/slotAutoClose-CgDkf8fM.mjs +156 -0
- package/dist/slotAutoClose-CgDkf8fM.mjs.map +1 -0
- package/dist/ssr.cjs +57 -3
- package/dist/ssr.d.cts +53 -2
- package/dist/ssr.d.cts.map +1 -1
- package/dist/ssr.d.mts +53 -2
- package/dist/ssr.d.mts.map +1 -1
- package/dist/ssr.mjs +51 -2
- package/dist/ssr.mjs.map +1 -1
- package/package.json +8 -5
- package/dist/AsyncOptions-BtMe2PAd.d.cts.map +0 -1
- package/dist/AsyncOptions-ClS1_ERX.d.mts.map +0 -1
- package/dist/Effect-DazmAdyC.d.mts.map +0 -1
- package/dist/Effect-Dewn7MLc.d.cts.map +0 -1
- package/dist/fromWebSocket-CFGoMkV2.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_devContext = require("./devContext-BulTn3U5.cjs");
|
|
3
|
-
const require_fromWebSocket = require("./fromWebSocket-
|
|
3
|
+
const require_fromWebSocket = require("./fromWebSocket-Cdoghvmh.cjs");
|
|
4
4
|
//#region src/render/context.ts
|
|
5
5
|
const CONTEXT_SYMBOL = Symbol.for("torp.Context");
|
|
6
6
|
const context = globalThis[CONTEXT_SYMBOL] ??= {
|
|
@@ -47,6 +47,92 @@ function addEvent(el, type, listener) {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
|
50
|
+
//#region src/render/isTextNode.ts
|
|
51
|
+
function isTextNode(node) {
|
|
52
|
+
return node.nodeType === 3;
|
|
53
|
+
}
|
|
54
|
+
const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
|
|
55
|
+
/**
|
|
56
|
+
* Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
|
|
57
|
+
* when the server recorded the branch it rendered).
|
|
58
|
+
*/
|
|
59
|
+
function isHydrationBreak(data) {
|
|
60
|
+
return HYDRATION_BREAK_REGEX.test(data);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The branch index encoded in a `^<index>` branch-break marker, or `undefined`
|
|
64
|
+
* for a plain `^` marker (e.g. from `@for`, which has no branch index).
|
|
65
|
+
*/
|
|
66
|
+
function hydrationBreakIndex(data) {
|
|
67
|
+
if (!data.startsWith("^") || data.length === 1) return;
|
|
68
|
+
const index = Number(data.slice(1));
|
|
69
|
+
return Number.isNaN(index) ? void 0 : index;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/render/isCommentNode.ts
|
|
73
|
+
function isCommentNode(node) {
|
|
74
|
+
return node.nodeType === 8;
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/render/nodeCheckHydrationBreak.ts
|
|
78
|
+
/**
|
|
79
|
+
* When hydrating, removes and skips hydration comments that are inserted at the
|
|
80
|
+
* start of branches and used to split up text nodes that would otherwise be
|
|
81
|
+
* joined in HTML.
|
|
82
|
+
*
|
|
83
|
+
* @param node The node to check and maybe skip.
|
|
84
|
+
* @returns The next node.
|
|
85
|
+
*/
|
|
86
|
+
function nodeCheckHydrationBreak(node) {
|
|
87
|
+
if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
|
|
88
|
+
let comment = node;
|
|
89
|
+
node = node.nextSibling;
|
|
90
|
+
comment.remove();
|
|
91
|
+
}
|
|
92
|
+
context.hydrationNode = node;
|
|
93
|
+
return node;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/render/nodeNext.ts
|
|
97
|
+
/**
|
|
98
|
+
* Gets the next sibling of a node.
|
|
99
|
+
*
|
|
100
|
+
* When hydrating, sets the hydration node.
|
|
101
|
+
*
|
|
102
|
+
* @param node The node.
|
|
103
|
+
* @param text Whether we require a text node.
|
|
104
|
+
*/
|
|
105
|
+
function nodeNext(node, text = false) {
|
|
106
|
+
if (context.hydrationNode !== null) {
|
|
107
|
+
if (text && isTextNode(node)) return node;
|
|
108
|
+
let next = nodeCheckHydrationBreak(node.nextSibling);
|
|
109
|
+
while (!text && next !== null && isTextNode(next) && next.textContent?.trim() === "") next = nodeCheckHydrationBreak(next.nextSibling);
|
|
110
|
+
if (!text && next !== null && next.nodeName === "TBODY" && next.firstChild && isTextNode(node)) {
|
|
111
|
+
next = next.firstChild;
|
|
112
|
+
context.hydrationNode = next;
|
|
113
|
+
}
|
|
114
|
+
return next;
|
|
115
|
+
}
|
|
116
|
+
return node.nextSibling;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/dev/devAssert.ts
|
|
120
|
+
/**
|
|
121
|
+
* Throws when `condition` is false — but only when dev mode is enabled (the
|
|
122
|
+
* dev-tools build calls `setDevMode`). Used for invariant checks on the
|
|
123
|
+
* runtime's implicit state machines (the batch counter, the signal update
|
|
124
|
+
* chain, the `$async` settle latch): violations mean the machine's
|
|
125
|
+
* bookkeeping is corrupt, and failing loudly in dev beats silently leaking
|
|
126
|
+
* subscriptions or dropping settles in ways that only show up as subtle UI
|
|
127
|
+
* glitches later. Production builds pay one boolean read per check.
|
|
128
|
+
*
|
|
129
|
+
* @param condition The invariant to hold.
|
|
130
|
+
* @param message What the violation means — the thrown error's message.
|
|
131
|
+
*/
|
|
132
|
+
function devAssert(condition, message) {
|
|
133
|
+
if (require_devContext.devContext.enabled && !condition) throw new Error(message);
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
50
136
|
//#region src/watch/clearSources.ts
|
|
51
137
|
/**
|
|
52
138
|
* Clear unused source subscriptions after each Computed or Effect has been run.
|
|
@@ -316,6 +402,7 @@ function triggerEffects() {
|
|
|
316
402
|
//#endregion
|
|
317
403
|
//#region src/watch/batchEnd.ts
|
|
318
404
|
function batchEnd() {
|
|
405
|
+
devAssert(context.batch > 0, "batchEnd called without a matching batchStart");
|
|
319
406
|
if (context.batch > 1) {
|
|
320
407
|
context.batch--;
|
|
321
408
|
return;
|
|
@@ -840,6 +927,7 @@ function addElement(node, parent, before) {
|
|
|
840
927
|
parent = before?.parentNode ?? parent;
|
|
841
928
|
if (hydrationNode === null) parent.insertBefore(node, before);
|
|
842
929
|
runMountSideEffects(parent, activeRegion, hydrationNode);
|
|
930
|
+
if (hydrationNode !== null) nodeNext(node);
|
|
843
931
|
}
|
|
844
932
|
//#endregion
|
|
845
933
|
//#region src/render/addFragment.ts
|
|
@@ -856,6 +944,7 @@ function addFragment(fragment, parent, before, endNode, startNode) {
|
|
|
856
944
|
parent = before?.parentNode ?? parent;
|
|
857
945
|
if (hydrationNode === null) parent.insertBefore(fragment, before);
|
|
858
946
|
runMountSideEffects(parent, activeRegion, hydrationNode);
|
|
947
|
+
if (hydrationNode !== null && endNode !== void 0) nodeNext(endNode);
|
|
859
948
|
}
|
|
860
949
|
//#endregion
|
|
861
950
|
//#region src/render/applyProps.ts
|
|
@@ -966,19 +1055,6 @@ function releaseRegion(region) {
|
|
|
966
1055
|
region.effects.length = 0;
|
|
967
1056
|
}
|
|
968
1057
|
//#endregion
|
|
969
|
-
//#region src/render/clearLayoutSlot.ts
|
|
970
|
-
/**
|
|
971
|
-
* Clears a region that was created by `fillLayoutSlot`: tears down the
|
|
972
|
-
* rendered content and its effects, leaving the surrounding layout intact
|
|
973
|
-
* so the slot can be refilled.
|
|
974
|
-
*
|
|
975
|
-
* @param region The region to clear
|
|
976
|
-
*/
|
|
977
|
-
function clearLayoutSlot(region) {
|
|
978
|
-
context.previousRegion = region.previousRegion;
|
|
979
|
-
clearRegion(region);
|
|
980
|
-
}
|
|
981
|
-
//#endregion
|
|
982
1058
|
//#region src/render/newRegion.ts
|
|
983
1059
|
function newRegion(name) {
|
|
984
1060
|
return {
|
|
@@ -1018,6 +1094,17 @@ function pushRegion(region, toParent = false) {
|
|
|
1018
1094
|
}
|
|
1019
1095
|
//#endregion
|
|
1020
1096
|
//#region src/render/fillLayoutSlot.ts
|
|
1097
|
+
const refillDepths = /* @__PURE__ */ new WeakMap();
|
|
1098
|
+
/**
|
|
1099
|
+
* Records the depth of a cleared layout-slot region for the fill that replaces
|
|
1100
|
+
* it (see `clearLayoutSlot`).
|
|
1101
|
+
*
|
|
1102
|
+
* @param parent The node the slot renders into
|
|
1103
|
+
* @param depth The cleared region's depth
|
|
1104
|
+
*/
|
|
1105
|
+
function rememberSlotRefillDepth(parent, depth) {
|
|
1106
|
+
refillDepths.set(parent, depth);
|
|
1107
|
+
}
|
|
1021
1108
|
/**
|
|
1022
1109
|
* Renders a component into a persistent layout slot, and returns the region
|
|
1023
1110
|
* it was rendered into. Used by the layout engine during navigation: the
|
|
@@ -1036,12 +1123,31 @@ function pushRegion(region, toParent = false) {
|
|
|
1036
1123
|
function fillLayoutSlot(component, slot, parent, anchor, $props, $context) {
|
|
1037
1124
|
const region = newRegion(require_devContext.devContext.enabled ? "Layout slot" : void 0);
|
|
1038
1125
|
const oldRegion = pushRegion(region, true);
|
|
1039
|
-
|
|
1126
|
+
const refillDepth = refillDepths.get(parent);
|
|
1127
|
+
if (refillDepth !== void 0) {
|
|
1128
|
+
region.depth = refillDepth;
|
|
1129
|
+
refillDepths.delete(parent);
|
|
1130
|
+
}
|
|
1040
1131
|
component(parent, anchor, $props, $context, { _: slot });
|
|
1041
1132
|
popRegion(oldRegion);
|
|
1042
1133
|
return region;
|
|
1043
1134
|
}
|
|
1044
1135
|
//#endregion
|
|
1136
|
+
//#region src/render/clearLayoutSlot.ts
|
|
1137
|
+
/**
|
|
1138
|
+
* Clears a region that was created by `fillLayoutSlot`: tears down the
|
|
1139
|
+
* rendered content and its effects, leaving the surrounding layout intact
|
|
1140
|
+
* so the slot can be refilled.
|
|
1141
|
+
*
|
|
1142
|
+
* @param region The region to clear
|
|
1143
|
+
*/
|
|
1144
|
+
function clearLayoutSlot(region) {
|
|
1145
|
+
context.previousRegion = region.previousRegion;
|
|
1146
|
+
const parent = region.startNode?.parentNode;
|
|
1147
|
+
if (parent) rememberSlotRefillDepth(parent, region.depth);
|
|
1148
|
+
clearRegion(region);
|
|
1149
|
+
}
|
|
1150
|
+
//#endregion
|
|
1045
1151
|
//#region src/render/firstInsideNode.ts
|
|
1046
1152
|
/**
|
|
1047
1153
|
* During hydration, `nodeAnchor` finds the first node inside a hydration
|
|
@@ -1248,75 +1354,6 @@ function takeBranchIndex(anchor) {
|
|
|
1248
1354
|
if (index !== void 0) branchIndexes.delete(anchor);
|
|
1249
1355
|
return index;
|
|
1250
1356
|
}
|
|
1251
|
-
const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
|
|
1252
|
-
/**
|
|
1253
|
-
* Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
|
|
1254
|
-
* when the server recorded the branch it rendered).
|
|
1255
|
-
*/
|
|
1256
|
-
function isHydrationBreak(data) {
|
|
1257
|
-
return HYDRATION_BREAK_REGEX.test(data);
|
|
1258
|
-
}
|
|
1259
|
-
/**
|
|
1260
|
-
* The branch index encoded in a `^<index>` branch-break marker, or `undefined`
|
|
1261
|
-
* for a plain `^` marker (e.g. from `@for`, which has no branch index).
|
|
1262
|
-
*/
|
|
1263
|
-
function hydrationBreakIndex(data) {
|
|
1264
|
-
if (!data.startsWith("^") || data.length === 1) return;
|
|
1265
|
-
const index = Number(data.slice(1));
|
|
1266
|
-
return Number.isNaN(index) ? void 0 : index;
|
|
1267
|
-
}
|
|
1268
|
-
//#endregion
|
|
1269
|
-
//#region src/render/isCommentNode.ts
|
|
1270
|
-
function isCommentNode(node) {
|
|
1271
|
-
return node.nodeType === 8;
|
|
1272
|
-
}
|
|
1273
|
-
//#endregion
|
|
1274
|
-
//#region src/render/isTextNode.ts
|
|
1275
|
-
function isTextNode(node) {
|
|
1276
|
-
return node.nodeType === 3;
|
|
1277
|
-
}
|
|
1278
|
-
//#endregion
|
|
1279
|
-
//#region src/render/nodeCheckHydrationBreak.ts
|
|
1280
|
-
/**
|
|
1281
|
-
* When hydrating, removes and skips hydration comments that are inserted at the
|
|
1282
|
-
* start of branches and used to split up text nodes that would otherwise be
|
|
1283
|
-
* joined in HTML.
|
|
1284
|
-
*
|
|
1285
|
-
* @param node The node to check and maybe skip.
|
|
1286
|
-
* @returns The next node.
|
|
1287
|
-
*/
|
|
1288
|
-
function nodeCheckHydrationBreak(node) {
|
|
1289
|
-
if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
|
|
1290
|
-
let comment = node;
|
|
1291
|
-
node = node.nextSibling;
|
|
1292
|
-
comment.remove();
|
|
1293
|
-
}
|
|
1294
|
-
context.hydrationNode = node;
|
|
1295
|
-
return node;
|
|
1296
|
-
}
|
|
1297
|
-
//#endregion
|
|
1298
|
-
//#region src/render/nodeNext.ts
|
|
1299
|
-
/**
|
|
1300
|
-
* Gets the next sibling of a node.
|
|
1301
|
-
*
|
|
1302
|
-
* When hydrating, sets the hydration node.
|
|
1303
|
-
*
|
|
1304
|
-
* @param node The node.
|
|
1305
|
-
* @param text Whether we require a text node.
|
|
1306
|
-
*/
|
|
1307
|
-
function nodeNext(node, text = false) {
|
|
1308
|
-
if (context.hydrationNode !== null) {
|
|
1309
|
-
if (text && isTextNode(node)) return node;
|
|
1310
|
-
let next = nodeCheckHydrationBreak(node.nextSibling);
|
|
1311
|
-
while (!text && next !== null && isTextNode(next) && next.textContent?.trim() === "") next = nodeCheckHydrationBreak(next.nextSibling);
|
|
1312
|
-
if (!text && next !== null && next.nodeName === "TBODY" && next.firstChild && isTextNode(node)) {
|
|
1313
|
-
next = next.firstChild;
|
|
1314
|
-
context.hydrationNode = next;
|
|
1315
|
-
}
|
|
1316
|
-
return next;
|
|
1317
|
-
}
|
|
1318
|
-
return node.nextSibling;
|
|
1319
|
-
}
|
|
1320
1357
|
//#endregion
|
|
1321
1358
|
//#region src/render/nodeAnchor.ts
|
|
1322
1359
|
/**
|
|
@@ -1498,15 +1535,23 @@ function nodeRoot(parent, text = false) {
|
|
|
1498
1535
|
/**
|
|
1499
1536
|
* Gets the sibling of a node, x nodes after it.
|
|
1500
1537
|
*
|
|
1501
|
-
* When hydrating, sets the hydration node.
|
|
1538
|
+
* When hydrating, sets the hydration node. `textMask` marks steps that
|
|
1539
|
+
* should land on a text node (bit i = the i-th step, counting from
|
|
1540
|
+
* `node`): such a step reuses the current node when it is already text
|
|
1541
|
+
* (text nodes get merged in HTML) and does not skip whitespace-only text
|
|
1542
|
+
* nodes — matching `nodeNext(node, true)`. Steps without their bit set
|
|
1543
|
+
* match `nodeNext(node, false)`.
|
|
1502
1544
|
*
|
|
1503
1545
|
* @param node The node.
|
|
1504
1546
|
* @param count The number of nodes to skip.
|
|
1547
|
+
* @param textMask Bitmask of text steps.
|
|
1505
1548
|
*/
|
|
1506
|
-
function nodeSkip(node, count) {
|
|
1549
|
+
function nodeSkip(node, count, textMask = 0) {
|
|
1507
1550
|
let nextNode = node;
|
|
1508
|
-
if (context.hydrationNode !== null)
|
|
1509
|
-
|
|
1551
|
+
if (context.hydrationNode !== null) {
|
|
1552
|
+
if (textMask === 0) for (let i = 0; i < count; i++) nextNode = nodeCheckHydrationBreak(nextNode.nextSibling);
|
|
1553
|
+
else for (let i = 0; i < count; i++) nextNode = nodeNext(nextNode, (textMask & 1 << i) !== 0);
|
|
1554
|
+
} else for (let i = 0; i < count; i++) nextNode = nextNode.nextSibling;
|
|
1510
1555
|
return nextNode;
|
|
1511
1556
|
}
|
|
1512
1557
|
//#endregion
|
|
@@ -1742,47 +1787,6 @@ function formatKey(key) {
|
|
|
1742
1787
|
}
|
|
1743
1788
|
}
|
|
1744
1789
|
//#endregion
|
|
1745
|
-
//#region src/render/AwaitSuspend.ts
|
|
1746
|
-
/**
|
|
1747
|
-
* Thrown when content rendered speculatively inside an `@await` boundary
|
|
1748
|
-
* dereferences (or calls) a first-load pending `$async` value.
|
|
1749
|
-
*
|
|
1750
|
-
* `suspendRead` normally returns `staleValue` so refresh suspends can keep
|
|
1751
|
-
* stale content mounted. On a first load there is no stale value, so returning
|
|
1752
|
-
* `undefined` would let user code throw a `TypeError` before the boundary can
|
|
1753
|
-
* switch to its `with` branch. Throwing this sentinel aborts the speculative
|
|
1754
|
-
* render instead; `runAwait` catches it and renders the fallback.
|
|
1755
|
-
*/
|
|
1756
|
-
var AwaitSuspend = class extends Error {
|
|
1757
|
-
constructor() {
|
|
1758
|
-
super("Suspended async value");
|
|
1759
|
-
this.name = "AwaitSuspend";
|
|
1760
|
-
}
|
|
1761
|
-
};
|
|
1762
|
-
//#endregion
|
|
1763
|
-
//#region src/watch/deepWrap.ts
|
|
1764
|
-
/**
|
|
1765
|
-
* Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
|
|
1766
|
-
* is not already watched and is not a promise. Returns the value unchanged
|
|
1767
|
-
* otherwise.
|
|
1768
|
-
*
|
|
1769
|
-
* Used by the `get` trap (wrap values on read) and the `set` trap (wrap
|
|
1770
|
-
* values on write), so a value stored in watched state is reactive whether
|
|
1771
|
-
* it's been read yet or not.
|
|
1772
|
-
*/
|
|
1773
|
-
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
1774
|
-
function deepWrap(value) {
|
|
1775
|
-
if (value === void 0 || value === null || typeof value !== "object") return value;
|
|
1776
|
-
if (value[require_fromWebSocket.proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
|
|
1777
|
-
if (value.then !== void 0) return value;
|
|
1778
|
-
if (value.nodeType !== void 0) return value;
|
|
1779
|
-
const cached = proxyCache.get(value);
|
|
1780
|
-
if (cached !== void 0) return cached;
|
|
1781
|
-
const proxy = $watch(value);
|
|
1782
|
-
proxyCache.set(value, proxy);
|
|
1783
|
-
return proxy;
|
|
1784
|
-
}
|
|
1785
|
-
//#endregion
|
|
1786
1790
|
//#region src/watch/propagateSignal.ts
|
|
1787
1791
|
/**
|
|
1788
1792
|
* Walk the target graph from a signal source (ProxySignal or Computed),
|
|
@@ -1840,6 +1844,7 @@ function propagateSignal(proxy, key) {
|
|
|
1840
1844
|
if (signal !== void 0 && signal.firstTarget !== null) {
|
|
1841
1845
|
batchStart();
|
|
1842
1846
|
try {
|
|
1847
|
+
devAssert(context.firstSignalToUpdate === null === (context.lastSignalToUpdate === null), "Signal update chain head/tail out of sync");
|
|
1843
1848
|
if (context.lastSignalToUpdate === null) {
|
|
1844
1849
|
context.firstSignalToUpdate = signal;
|
|
1845
1850
|
context.lastSignalToUpdate = signal;
|
|
@@ -1854,6 +1859,48 @@ function propagateSignal(proxy, key) {
|
|
|
1854
1859
|
}
|
|
1855
1860
|
}
|
|
1856
1861
|
//#endregion
|
|
1862
|
+
//#region src/render/AwaitSuspend.ts
|
|
1863
|
+
/**
|
|
1864
|
+
* Thrown when content rendered speculatively inside an `@await` boundary
|
|
1865
|
+
* dereferences (or calls) a first-load pending `$async` value.
|
|
1866
|
+
*
|
|
1867
|
+
* `suspendRead` normally returns the retained settle value so refresh suspends
|
|
1868
|
+
* can keep
|
|
1869
|
+
* stale content mounted. On a first load there is no stale value, so returning
|
|
1870
|
+
* `undefined` would let user code throw a `TypeError` before the boundary can
|
|
1871
|
+
* switch to its `with` branch. Throwing this sentinel aborts the speculative
|
|
1872
|
+
* render instead; `runAwait` catches it and renders the fallback.
|
|
1873
|
+
*/
|
|
1874
|
+
var AwaitSuspend = class extends Error {
|
|
1875
|
+
constructor() {
|
|
1876
|
+
super("Suspended async value");
|
|
1877
|
+
this.name = "AwaitSuspend";
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
//#endregion
|
|
1881
|
+
//#region src/watch/deepWrap.ts
|
|
1882
|
+
/**
|
|
1883
|
+
* Wraps a value with `$watch` if it is a plain object (or Date/Map/Set) that
|
|
1884
|
+
* is not already watched and is not a promise. Returns the value unchanged
|
|
1885
|
+
* otherwise.
|
|
1886
|
+
*
|
|
1887
|
+
* Used by the `get` trap (wrap values on read) and the `set` trap (wrap
|
|
1888
|
+
* values on write), so a value stored in watched state is reactive whether
|
|
1889
|
+
* it's been read yet or not.
|
|
1890
|
+
*/
|
|
1891
|
+
const proxyCache = /* @__PURE__ */ new WeakMap();
|
|
1892
|
+
function deepWrap(value) {
|
|
1893
|
+
if (value === void 0 || value === null || typeof value !== "object") return value;
|
|
1894
|
+
if (value[require_fromWebSocket.proxyDataSymbol] !== void 0) return proxyCache.get(value) ?? value;
|
|
1895
|
+
if (value.then !== void 0) return value;
|
|
1896
|
+
if (value.nodeType !== void 0) return value;
|
|
1897
|
+
const cached = proxyCache.get(value);
|
|
1898
|
+
if (cached !== void 0) return cached;
|
|
1899
|
+
const proxy = $watch(value);
|
|
1900
|
+
proxyCache.set(value, proxy);
|
|
1901
|
+
return proxy;
|
|
1902
|
+
}
|
|
1903
|
+
//#endregion
|
|
1857
1904
|
//#region src/watch/trackProxySignal.ts
|
|
1858
1905
|
function trackProxySignal(data, key) {
|
|
1859
1906
|
let signal = data.signals.get(key);
|
|
@@ -1876,8 +1923,8 @@ function trackProxySignal(data, key) {
|
|
|
1876
1923
|
* nearest `@await` boundary.
|
|
1877
1924
|
*
|
|
1878
1925
|
* Return value (ASYNC.md → "Stale-while-revalidate"): on a refresh suspend
|
|
1879
|
-
* (the computed has
|
|
1880
|
-
* held in `
|
|
1926
|
+
* (the computed has settled before) returns the previously resolved value
|
|
1927
|
+
* held in `settle`, so readers keep displaying the old content instead of
|
|
1881
1928
|
* a placeholder — an `@await` boundary thus keeps its content mounted
|
|
1882
1929
|
* rather than flashing the `with` branch. On a first load (or a retry after a
|
|
1883
1930
|
* rejection, both of which have no stale value), inside an `@await` boundary,
|
|
@@ -1910,9 +1957,9 @@ function suspendRead(signal) {
|
|
|
1910
1957
|
trackSignal(signal);
|
|
1911
1958
|
context.activeTarget = oldActive;
|
|
1912
1959
|
}
|
|
1913
|
-
if (
|
|
1960
|
+
if (signal.settle === void 0 || !signal.settle.ok) throw new AwaitSuspend();
|
|
1914
1961
|
}
|
|
1915
|
-
return signal.
|
|
1962
|
+
return signal.settle !== void 0 && signal.settle.ok ? signal.settle.value : void 0;
|
|
1916
1963
|
}
|
|
1917
1964
|
function proxyGet(target, key, receiver) {
|
|
1918
1965
|
let data = target[require_fromWebSocket.proxyDataSymbol];
|
|
@@ -2051,6 +2098,7 @@ function arrayHandle(data, target, key) {
|
|
|
2051
2098
|
return function(...args) {
|
|
2052
2099
|
const result = target[key].apply(target, args);
|
|
2053
2100
|
propagateSignal(data, "length");
|
|
2101
|
+
if (key !== "sort" && key !== "reverse") propagateSignal(data, require_fromWebSocket.proxyKeysSymbol);
|
|
2054
2102
|
return result;
|
|
2055
2103
|
};
|
|
2056
2104
|
}
|
|
@@ -2284,8 +2332,10 @@ function proxySet(target, key, value, receiver) {
|
|
|
2284
2332
|
let data = target[require_fromWebSocket.proxyDataSymbol];
|
|
2285
2333
|
require_devContext.devContext.signalSet(data, key);
|
|
2286
2334
|
if (data.shallow !== true) value = deepWrap(value);
|
|
2335
|
+
const isNewKey = !Object.prototype.hasOwnProperty.call(target, key);
|
|
2287
2336
|
Reflect.set(target, key, value, receiver);
|
|
2288
2337
|
propagateSignal(data, key);
|
|
2338
|
+
if (isNewKey) propagateSignal(data, require_fromWebSocket.proxyKeysSymbol);
|
|
2289
2339
|
if (data.isArray && typeof key !== "symbol" && !isNaN(+key)) propagateSignal(data, "length");
|
|
2290
2340
|
}
|
|
2291
2341
|
return true;
|
|
@@ -2294,7 +2344,21 @@ function proxySet(target, key, value, receiver) {
|
|
|
2294
2344
|
//#region src/watch/$watch.ts
|
|
2295
2345
|
const sharedHandler = {
|
|
2296
2346
|
get: proxyGet,
|
|
2297
|
-
set: proxySet
|
|
2347
|
+
set: proxySet,
|
|
2348
|
+
ownKeys: (target) => {
|
|
2349
|
+
const data = target[require_fromWebSocket.proxyDataSymbol];
|
|
2350
|
+
if (data !== void 0) trackProxySignal(data, require_fromWebSocket.proxyKeysSymbol);
|
|
2351
|
+
return Reflect.ownKeys(target);
|
|
2352
|
+
},
|
|
2353
|
+
deleteProperty: (target, key) => {
|
|
2354
|
+
const deleted = Reflect.deleteProperty(target, key);
|
|
2355
|
+
const data = target[require_fromWebSocket.proxyDataSymbol];
|
|
2356
|
+
if (deleted && data !== void 0) {
|
|
2357
|
+
propagateSignal(data, key);
|
|
2358
|
+
propagateSignal(data, require_fromWebSocket.proxyKeysSymbol);
|
|
2359
|
+
}
|
|
2360
|
+
return deleted;
|
|
2361
|
+
}
|
|
2298
2362
|
};
|
|
2299
2363
|
/**
|
|
2300
2364
|
* Watches an object and runs effects when its properties are changed.
|
|
@@ -2453,13 +2517,13 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2453
2517
|
let chainNeedsRelink = false;
|
|
2454
2518
|
while (oldStart <= oldEnd && newStart <= newEnd) if (oldItems[oldStart].key === newSpecs[newStart].key) {
|
|
2455
2519
|
const item = oldItems[oldStart];
|
|
2456
|
-
update(item, newSpecs[newStart]);
|
|
2520
|
+
if (item.data !== newSpecs[newStart].data) update(item, newSpecs[newStart]);
|
|
2457
2521
|
newItems[newStart] = item;
|
|
2458
2522
|
oldStart++;
|
|
2459
2523
|
newStart++;
|
|
2460
2524
|
} else if (oldItems[oldEnd].key === newSpecs[newEnd].key) {
|
|
2461
2525
|
const item = oldItems[oldEnd];
|
|
2462
|
-
update(item, newSpecs[newEnd]);
|
|
2526
|
+
if (item.data !== newSpecs[newEnd].data) update(item, newSpecs[newEnd]);
|
|
2463
2527
|
newItems[newEnd] = item;
|
|
2464
2528
|
oldEnd--;
|
|
2465
2529
|
newEnd--;
|
|
@@ -2467,7 +2531,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2467
2531
|
const item = oldItems[oldStart];
|
|
2468
2532
|
moveRegion(parent, item, oldItems[oldEnd].endNode?.nextSibling ?? anchor);
|
|
2469
2533
|
chainNeedsRelink = true;
|
|
2470
|
-
update(item, newSpecs[newEnd]);
|
|
2534
|
+
if (item.data !== newSpecs[newEnd].data) update(item, newSpecs[newEnd]);
|
|
2471
2535
|
newItems[newEnd] = item;
|
|
2472
2536
|
oldStart++;
|
|
2473
2537
|
newEnd--;
|
|
@@ -2475,7 +2539,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2475
2539
|
const item = oldItems[oldEnd];
|
|
2476
2540
|
moveRegion(parent, item, oldItems[oldStart].startNode);
|
|
2477
2541
|
chainNeedsRelink = true;
|
|
2478
|
-
update(item, newSpecs[newStart]);
|
|
2542
|
+
if (item.data !== newSpecs[newStart].data) update(item, newSpecs[newStart]);
|
|
2479
2543
|
newItems[newStart] = item;
|
|
2480
2544
|
oldEnd--;
|
|
2481
2545
|
newStart++;
|
|
@@ -2509,7 +2573,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2509
2573
|
const newIdx = newKeyToIndex.get(oldItem.key);
|
|
2510
2574
|
if (newIdx !== void 0) {
|
|
2511
2575
|
newIndexToOld[newIdx - newStart] = i + 1;
|
|
2512
|
-
update(oldItem, newSpecs[newIdx]);
|
|
2576
|
+
if (oldItem.data !== newSpecs[newIdx].data) update(oldItem, newSpecs[newIdx]);
|
|
2513
2577
|
newItems[newIdx] = oldItem;
|
|
2514
2578
|
} else clearRegion(oldItem);
|
|
2515
2579
|
}
|
|
@@ -2627,7 +2691,7 @@ const SERVER_VALUES_PREFIX = "t-await:";
|
|
|
2627
2691
|
* Stale-while-revalidate (ASYNC.md): once content has been produced
|
|
2628
2692
|
* (`hasContent`), a subsequent suspend during a refresh does NOT switch to
|
|
2629
2693
|
* the `with` branch — the boundary keeps the stale content mounted. `$async`
|
|
2630
|
-
* retains the previous resolved value (`Computed.
|
|
2694
|
+
* retains the previous resolved value (`Computed.settle.value`) and
|
|
2631
2695
|
* `suspendRead` returns it, so child effects keep displaying the old value
|
|
2632
2696
|
* until the new promise resolves and updates them in place. The `with` branch
|
|
2633
2697
|
* is shown only on the first load, before content has ever rendered
|
|
@@ -2954,10 +3018,8 @@ function $async(fn, _options) {
|
|
|
2954
3018
|
didError: false,
|
|
2955
3019
|
didSuspend: false,
|
|
2956
3020
|
generation: 0,
|
|
2957
|
-
|
|
2958
|
-
lastErrored: false,
|
|
3021
|
+
settle: void 0,
|
|
2959
3022
|
suspendQuiet: false,
|
|
2960
|
-
staleValue: void 0,
|
|
2961
3023
|
rollback: null
|
|
2962
3024
|
};
|
|
2963
3025
|
const serverValues = context.serverValues;
|
|
@@ -2969,25 +3031,29 @@ function $async(fn, _options) {
|
|
|
2969
3031
|
if (value !== null && value !== void 0 && typeof value.then === "function") {
|
|
2970
3032
|
const gen = ++computed.generation;
|
|
2971
3033
|
computed.didSuspend = true;
|
|
2972
|
-
computed.suspendQuiet = computed.
|
|
3034
|
+
computed.suspendQuiet = computed.settle !== void 0 && !computed.recalc;
|
|
2973
3035
|
value.then((v) => {
|
|
2974
3036
|
if (computed.generation !== gen) return;
|
|
3037
|
+
devAssert(computed.didSuspend, "$async: resolved while not suspended (settle bookkeeping is broken)");
|
|
2975
3038
|
computed.value = v;
|
|
2976
3039
|
computed.didSuspend = false;
|
|
2977
|
-
computed.
|
|
2978
|
-
|
|
2979
|
-
|
|
3040
|
+
computed.settle = {
|
|
3041
|
+
ok: true,
|
|
3042
|
+
value: v
|
|
3043
|
+
};
|
|
2980
3044
|
batchStart();
|
|
2981
3045
|
propagateFromSignal(computed);
|
|
2982
3046
|
batchEnd();
|
|
2983
3047
|
}, (e) => {
|
|
2984
3048
|
if (computed.generation !== gen) return;
|
|
3049
|
+
devAssert(computed.didSuspend, "$async: rejected while not suspended (settle bookkeeping is broken)");
|
|
2985
3050
|
computed.value = e;
|
|
2986
3051
|
computed.didError = true;
|
|
2987
3052
|
computed.didSuspend = false;
|
|
2988
|
-
computed.
|
|
2989
|
-
|
|
2990
|
-
|
|
3053
|
+
computed.settle = {
|
|
3054
|
+
ok: false,
|
|
3055
|
+
error: e
|
|
3056
|
+
};
|
|
2991
3057
|
batchStart();
|
|
2992
3058
|
propagateFromSignal(computed);
|
|
2993
3059
|
batchEnd();
|
|
@@ -3001,10 +3067,11 @@ function $async(fn, _options) {
|
|
|
3001
3067
|
computed.generation++;
|
|
3002
3068
|
computed.didSuspend = false;
|
|
3003
3069
|
computed.didError = false;
|
|
3004
|
-
computed.hasResolved = true;
|
|
3005
|
-
computed.lastErrored = false;
|
|
3006
3070
|
computed.value = serverValues.values[serverValues.index++];
|
|
3007
|
-
computed.
|
|
3071
|
+
computed.settle = {
|
|
3072
|
+
ok: true,
|
|
3073
|
+
value: computed.value
|
|
3074
|
+
};
|
|
3008
3075
|
}
|
|
3009
3076
|
return computed.value;
|
|
3010
3077
|
}
|
|
@@ -3080,10 +3147,8 @@ function $cache(fn) {
|
|
|
3080
3147
|
didError: false,
|
|
3081
3148
|
didSuspend: false,
|
|
3082
3149
|
generation: 0,
|
|
3083
|
-
|
|
3084
|
-
lastErrored: false,
|
|
3150
|
+
settle: void 0,
|
|
3085
3151
|
suspendQuiet: false,
|
|
3086
|
-
staleValue: void 0,
|
|
3087
3152
|
rollback: null
|
|
3088
3153
|
};
|
|
3089
3154
|
context.registerComputed(computed);
|
|
@@ -3140,7 +3205,7 @@ function $onmount(fn) {
|
|
|
3140
3205
|
* re-asking the same question shouldn't ping the user. First loads and
|
|
3141
3206
|
* dependency-change refreshes are loud (`true`), as is the default (loud)
|
|
3142
3207
|
* `$refresh(fn)`. Quiet-ness is captured per computed at suspend time via
|
|
3143
|
-
* `suspendQuiet` (computed in `$async`'s run from `
|
|
3208
|
+
* `suspendQuiet` (computed in `$async`'s run from `settle` and `recalc`).
|
|
3144
3209
|
*
|
|
3145
3210
|
* @param fn A function that reads the reactive values to check.
|
|
3146
3211
|
*/
|
|
@@ -3168,7 +3233,7 @@ function $pending(fn) {
|
|
|
3168
3233
|
* *loud*: `$pending(fn)` returns `true` while the re-fetch is in flight and
|
|
3169
3234
|
* subscribers are notified at suspend *start*, so an inline "updating…"
|
|
3170
3235
|
* indicator appears immediately. Readers keep displaying the previous
|
|
3171
|
-
* resolved value (`Computed.
|
|
3236
|
+
* resolved value (`Computed.settle.value`) until the new promise resolves and
|
|
3172
3237
|
* propagates through the reactive graph; an `@await` boundary keeps its
|
|
3173
3238
|
* content mounted instead of flashing fallback.
|
|
3174
3239
|
*
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as SlotRender, t as Component } from "./Component-0MH0zd-m.cjs";
|
|
2
2
|
import { t as Cleanup } from "./Cleanup-D0wvGW5d.cjs";
|
|
3
|
-
import { n as Region, t as Effect } from "./Effect-
|
|
4
|
-
import { a as StreamSource,
|
|
3
|
+
import { n as Region, t as Effect } from "./Effect-Bf8fz_zC.cjs";
|
|
4
|
+
import { a as StreamSource, i as fromElement, n as fromWebSocket, o as StyleValue, r as fromServer, s as ClassValue, t as AsyncOptions } from "./AsyncOptions-C_7mWR6F.cjs";
|
|
5
5
|
//#region src/types/Animation.d.ts
|
|
6
6
|
interface Animation {
|
|
7
7
|
keyframes: Keyframe[] | PropertyIndexedKeyframes;
|
|
@@ -42,6 +42,12 @@ declare function addFragment(fragment: DocumentFragment, parent: ParentNode, bef
|
|
|
42
42
|
//#region src/render/applyProps.d.ts
|
|
43
43
|
declare function applyProps(el: Element, props: Record<string, any> | undefined, propNamesUsed: string[]): void;
|
|
44
44
|
//#endregion
|
|
45
|
+
//#region src/render/buildClasses.d.ts
|
|
46
|
+
declare function buildClasses(value: ClassValue, styleHash?: string): string;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/render/buildStyles.d.ts
|
|
49
|
+
declare function buildStyles(value: StyleValue): string;
|
|
50
|
+
//#endregion
|
|
45
51
|
//#region src/render/clearLayoutSlot.d.ts
|
|
46
52
|
/**
|
|
47
53
|
* Clears a region that was created by `fillLayoutSlot`: tears down the
|
|
@@ -167,9 +173,13 @@ declare function unmount(parent: ParentNode): void;
|
|
|
167
173
|
* NOTE: `data` is `any` rather than `Record<string, any>` -- when a `@for`
|
|
168
174
|
* body binds a single loop variable and is proxy-safe, the variable is stored
|
|
169
175
|
* directly (e.g. `data: page` for a number), not as a bag.
|
|
176
|
+
*
|
|
177
|
+
* NOTE: `key` is optional -- the compiler only emits it when the `@for` has
|
|
178
|
+
* an `@key` block; unkeyed loops omit it (a missing key behaves the same as
|
|
179
|
+
* an `undefined` one during reconciliation).
|
|
170
180
|
*/
|
|
171
181
|
interface ListItemSpec {
|
|
172
|
-
key
|
|
182
|
+
key?: any;
|
|
173
183
|
data: any;
|
|
174
184
|
}
|
|
175
185
|
//#endregion
|
|
@@ -264,12 +274,18 @@ declare function nodeRoot(parent: Node, text?: boolean): ChildNode;
|
|
|
264
274
|
/**
|
|
265
275
|
* Gets the sibling of a node, x nodes after it.
|
|
266
276
|
*
|
|
267
|
-
* When hydrating, sets the hydration node.
|
|
277
|
+
* When hydrating, sets the hydration node. `textMask` marks steps that
|
|
278
|
+
* should land on a text node (bit i = the i-th step, counting from
|
|
279
|
+
* `node`): such a step reuses the current node when it is already text
|
|
280
|
+
* (text nodes get merged in HTML) and does not skip whitespace-only text
|
|
281
|
+
* nodes — matching `nodeNext(node, true)`. Steps without their bit set
|
|
282
|
+
* match `nodeNext(node, false)`.
|
|
268
283
|
*
|
|
269
284
|
* @param node The node.
|
|
270
285
|
* @param count The number of nodes to skip.
|
|
286
|
+
* @param textMask Bitmask of text steps.
|
|
271
287
|
*/
|
|
272
|
-
declare function nodeSkip(node: ChildNode, count: number): ChildNode;
|
|
288
|
+
declare function nodeSkip(node: ChildNode, count: number, textMask?: number): ChildNode;
|
|
273
289
|
//#endregion
|
|
274
290
|
//#region src/render/popRegion.d.ts
|
|
275
291
|
declare function popRegion(oldRegion: Region): void;
|
|
@@ -374,7 +390,7 @@ declare function runList(region: Region, parent: ParentNode, anchor: Node | null
|
|
|
374
390
|
* Stale-while-revalidate (ASYNC.md): once content has been produced
|
|
375
391
|
* (`hasContent`), a subsequent suspend during a refresh does NOT switch to
|
|
376
392
|
* the `with` branch — the boundary keeps the stale content mounted. `$async`
|
|
377
|
-
* retains the previous resolved value (`Computed.
|
|
393
|
+
* retains the previous resolved value (`Computed.settle.value`) and
|
|
378
394
|
* `suspendRead` returns it, so child effects keep displaying the old value
|
|
379
395
|
* until the new promise resolves and updates them in place. The `with` branch
|
|
380
396
|
* is shown only on the first load, before content has ever rendered
|
|
@@ -616,7 +632,7 @@ declare function $peek<T>(fn: () => T): T;
|
|
|
616
632
|
* re-asking the same question shouldn't ping the user. First loads and
|
|
617
633
|
* dependency-change refreshes are loud (`true`), as is the default (loud)
|
|
618
634
|
* `$refresh(fn)`. Quiet-ness is captured per computed at suspend time via
|
|
619
|
-
* `suspendQuiet` (computed in `$async`'s run from `
|
|
635
|
+
* `suspendQuiet` (computed in `$async`'s run from `settle` and `recalc`).
|
|
620
636
|
*
|
|
621
637
|
* @param fn A function that reads the reactive values to check.
|
|
622
638
|
*/
|
|
@@ -647,7 +663,7 @@ interface RefreshOptions {
|
|
|
647
663
|
* *loud*: `$pending(fn)` returns `true` while the re-fetch is in flight and
|
|
648
664
|
* subscribers are notified at suspend *start*, so an inline "updating…"
|
|
649
665
|
* indicator appears immediately. Readers keep displaying the previous
|
|
650
|
-
* resolved value (`Computed.
|
|
666
|
+
* resolved value (`Computed.settle.value`) until the new promise resolves and
|
|
651
667
|
* propagates through the reactive graph; an `@await` boundary keeps its
|
|
652
668
|
* content mounted instead of flashing fallback.
|
|
653
669
|
*
|