@torpor/view 1.2.2 → 1.2.4
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/compile.cjs +18 -6
- package/dist/compile.mjs +18 -6
- package/dist/compile.mjs.map +1 -1
- package/dist/index.cjs +139 -11
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +139 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -907,6 +907,7 @@ function pushRegion(region, toParent = false) {
|
|
|
907
907
|
function fillLayoutSlot(component, slot, parent, anchor, $props, $context) {
|
|
908
908
|
const region = newRegion(require_devContext.devContext.enabled ? "Layout slot" : void 0);
|
|
909
909
|
const oldRegion = pushRegion(region, true);
|
|
910
|
+
region.depth = region.previousRegion === null ? 0 : region.previousRegion.depth + 1;
|
|
910
911
|
component(parent, anchor, $props, $context, { _: slot });
|
|
911
912
|
popRegion(oldRegion);
|
|
912
913
|
return region;
|
|
@@ -1030,6 +1031,12 @@ function hydrate(parent, component, props, slots) {
|
|
|
1030
1031
|
/**
|
|
1031
1032
|
* Mounts a component into a DOM node
|
|
1032
1033
|
*
|
|
1034
|
+
* The parent should be connected to the document: delegated events (click,
|
|
1035
|
+
* input, keydown, ...) are handled by a single listener per event type on
|
|
1036
|
+
* `document`, so events raised inside a detached container never reach their
|
|
1037
|
+
* handlers. (`hydrate` mounts into server-rendered markup, which is already
|
|
1038
|
+
* connected.)
|
|
1039
|
+
*
|
|
1033
1040
|
* @param parent The node to mount the component into
|
|
1034
1041
|
* @param component The component to mount
|
|
1035
1042
|
* @param props An object containing component props
|
|
@@ -1085,6 +1092,51 @@ function newListItem(data, key, name) {
|
|
|
1085
1092
|
};
|
|
1086
1093
|
}
|
|
1087
1094
|
//#endregion
|
|
1095
|
+
//#region src/render/branchIndex.ts
|
|
1096
|
+
/**
|
|
1097
|
+
* During hydration, the server writes the index of the branch it rendered for
|
|
1098
|
+
* a control statement (`@if`/`@switch`) into the block's leading branch-break
|
|
1099
|
+
* marker (`<!^2>`). `nodeAnchor` reads that marker while consuming the block's
|
|
1100
|
+
* markers and stashes the index here, keyed by the anchor node it returns —
|
|
1101
|
+
* the same pattern as `firstInsideNode`, since the marker is gone by the time
|
|
1102
|
+
* the index is needed. `runControl` picks the index up from the anchor so
|
|
1103
|
+
* `runControlBranch` can compare it with the branch the client picks: server
|
|
1104
|
+
* and client conditions can legitimately differ (browser-only state, effects
|
|
1105
|
+
* that no-op on the server), and a branch the server rendered but the client
|
|
1106
|
+
* didn't pick must be recreated rather than adopted.
|
|
1107
|
+
*/
|
|
1108
|
+
const branchIndexes = /* @__PURE__ */ new WeakMap();
|
|
1109
|
+
function setBranchIndex(anchor, index) {
|
|
1110
|
+
branchIndexes.set(anchor, index);
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Takes (and clears) the server-rendered branch index stashed for the given
|
|
1114
|
+
* anchor node, or `undefined` if the anchor wasn't hydrated through a
|
|
1115
|
+
* branch-indexed hydration block.
|
|
1116
|
+
*/
|
|
1117
|
+
function takeBranchIndex(anchor) {
|
|
1118
|
+
const index = branchIndexes.get(anchor);
|
|
1119
|
+
if (index !== void 0) branchIndexes.delete(anchor);
|
|
1120
|
+
return index;
|
|
1121
|
+
}
|
|
1122
|
+
const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
|
|
1123
|
+
/**
|
|
1124
|
+
* Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
|
|
1125
|
+
* when the server recorded the branch it rendered).
|
|
1126
|
+
*/
|
|
1127
|
+
function isHydrationBreak(data) {
|
|
1128
|
+
return HYDRATION_BREAK_REGEX.test(data);
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* The branch index encoded in a `^<index>` branch-break marker, or `undefined`
|
|
1132
|
+
* for a plain `^` marker (e.g. from `@for`, which has no branch index).
|
|
1133
|
+
*/
|
|
1134
|
+
function hydrationBreakIndex(data) {
|
|
1135
|
+
if (!data.startsWith("^") || data.length === 1) return;
|
|
1136
|
+
const index = Number(data.slice(1));
|
|
1137
|
+
return Number.isNaN(index) ? void 0 : index;
|
|
1138
|
+
}
|
|
1139
|
+
//#endregion
|
|
1088
1140
|
//#region src/render/isCommentNode.ts
|
|
1089
1141
|
function isCommentNode(node) {
|
|
1090
1142
|
return node.nodeType === 8;
|
|
@@ -1105,7 +1157,7 @@ function isTextNode(node) {
|
|
|
1105
1157
|
* @returns The next node.
|
|
1106
1158
|
*/
|
|
1107
1159
|
function nodeCheckHydrationBreak(node) {
|
|
1108
|
-
if (node !== null && isCommentNode(node) && node.data
|
|
1160
|
+
if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
|
|
1109
1161
|
let comment = node;
|
|
1110
1162
|
node = node.nextSibling;
|
|
1111
1163
|
comment.remove();
|
|
@@ -1156,9 +1208,14 @@ function nodeAnchor(node) {
|
|
|
1156
1208
|
if (context.hydrationNode !== null) {
|
|
1157
1209
|
if (isCommentNode(node) && node.data === "[") {
|
|
1158
1210
|
const startParent = node.parentNode;
|
|
1211
|
+
let branchIndex = void 0;
|
|
1212
|
+
let peek = node.nextSibling;
|
|
1213
|
+
while (peek !== null && isTextNode(peek) && (peek.textContent ?? "").trim() === "") peek = peek.nextSibling;
|
|
1214
|
+
if (peek !== null && isCommentNode(peek) && isHydrationBreak(peek.data)) branchIndex = hydrationBreakIndex(peek.data);
|
|
1159
1215
|
let currentNode = nodeNext(node);
|
|
1160
1216
|
node.remove();
|
|
1161
|
-
while (currentNode !== null && isCommentNode(currentNode) && currentNode.data
|
|
1217
|
+
while (currentNode !== null && isCommentNode(currentNode) && isHydrationBreak(currentNode.data)) {
|
|
1218
|
+
if (branchIndex === void 0) branchIndex = hydrationBreakIndex(currentNode.data);
|
|
1162
1219
|
const next = currentNode.nextSibling;
|
|
1163
1220
|
currentNode.remove();
|
|
1164
1221
|
currentNode = next;
|
|
@@ -1179,6 +1236,7 @@ function nodeAnchor(node) {
|
|
|
1179
1236
|
const region = context.activeRegion;
|
|
1180
1237
|
if (region.startNode === null) region.startNode = firstContent ?? endNode;
|
|
1181
1238
|
setFirstInsideNode(endNode, firstContent);
|
|
1239
|
+
if (branchIndex !== void 0) setBranchIndex(endNode, branchIndex);
|
|
1182
1240
|
return endNode;
|
|
1183
1241
|
}
|
|
1184
1242
|
}
|
|
@@ -1232,7 +1290,7 @@ function walkHydrationRoot() {
|
|
|
1232
1290
|
let rootNode = context.hydrationNode;
|
|
1233
1291
|
while (rootNode !== null && isSkippable(rootNode)) {
|
|
1234
1292
|
const next = rootNode.nextSibling;
|
|
1235
|
-
if (isCommentNode(rootNode) && rootNode.data
|
|
1293
|
+
if (isCommentNode(rootNode) && isHydrationBreak(rootNode.data)) rootNode.remove();
|
|
1236
1294
|
rootNode = next;
|
|
1237
1295
|
context.hydrationNode = rootNode;
|
|
1238
1296
|
}
|
|
@@ -1247,7 +1305,7 @@ function walkHydrationRoot() {
|
|
|
1247
1305
|
}
|
|
1248
1306
|
function isSkippable(node) {
|
|
1249
1307
|
if (isTextNode(node) && (node.textContent ?? "").trim() === "") return true;
|
|
1250
|
-
if (isCommentNode(node)) return node.data
|
|
1308
|
+
if (isCommentNode(node)) return isHydrationBreak(node.data) || node.data === "";
|
|
1251
1309
|
return false;
|
|
1252
1310
|
}
|
|
1253
1311
|
//#endregion
|
|
@@ -1428,6 +1486,11 @@ function widenAncestorsAtAnchor(region, anchor) {
|
|
|
1428
1486
|
*/
|
|
1429
1487
|
function runControl(region, anchor, create, name) {
|
|
1430
1488
|
let first = true;
|
|
1489
|
+
if (context.hydrationNode !== null && anchor !== null) {
|
|
1490
|
+
region.ssrBranchAnchor = anchor;
|
|
1491
|
+
const ssrBranchIndex = takeBranchIndex(anchor);
|
|
1492
|
+
if (ssrBranchIndex !== void 0) region.ssrBranchIndex = ssrBranchIndex;
|
|
1493
|
+
}
|
|
1431
1494
|
const gen = region.generation = (region.generation ?? 0) + 1;
|
|
1432
1495
|
$run(function runControl() {
|
|
1433
1496
|
if (region.generation !== gen) return;
|
|
@@ -1437,7 +1500,10 @@ function runControl(region, anchor, create, name) {
|
|
|
1437
1500
|
create(anchor);
|
|
1438
1501
|
popRegion(oldRegion);
|
|
1439
1502
|
widenAncestorsAtAnchor(region, anchor);
|
|
1440
|
-
if (
|
|
1503
|
+
if (anchor !== null && (context.hydrationNode !== null || region.ssrBranchRecreated === true)) {
|
|
1504
|
+
region.ssrBranchRecreated = void 0;
|
|
1505
|
+
context.hydrationNode = anchor;
|
|
1506
|
+
}
|
|
1441
1507
|
}, name);
|
|
1442
1508
|
}
|
|
1443
1509
|
//#endregion
|
|
@@ -1445,6 +1511,17 @@ function runControl(region, anchor, create, name) {
|
|
|
1445
1511
|
function runControlBranch(region, oldIndex, index) {
|
|
1446
1512
|
const recreate = region.recreate;
|
|
1447
1513
|
if (recreate) region.recreate = false;
|
|
1514
|
+
const anchor = region.ssrBranchAnchor;
|
|
1515
|
+
if (anchor !== void 0) {
|
|
1516
|
+
region.ssrBranchAnchor = void 0;
|
|
1517
|
+
const ssrBranchIndex = region.ssrBranchIndex;
|
|
1518
|
+
region.ssrBranchIndex = void 0;
|
|
1519
|
+
const hydrationNode = context.hydrationNode;
|
|
1520
|
+
if (hydrationNode !== null && (ssrBranchIndex !== void 0 && ssrBranchIndex !== index || ssrBranchIndex === void 0 && hydrationNode === anchor)) {
|
|
1521
|
+
region.ssrBranchRecreated = true;
|
|
1522
|
+
clearServerBranch(region, hydrationNode, anchor);
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1448
1525
|
const firstRender = region.hasRenderedBranch !== true;
|
|
1449
1526
|
region.hasRenderedBranch = true;
|
|
1450
1527
|
if (oldIndex === index) {
|
|
@@ -1457,6 +1534,38 @@ function runControlBranch(region, oldIndex, index) {
|
|
|
1457
1534
|
if (!firstRender && region.nextRegion !== null && region.nextRegion.depth > region.depth) clearRegion(region.nextRegion);
|
|
1458
1535
|
return true;
|
|
1459
1536
|
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Clears a server-rendered control branch that the client didn't pick, so the
|
|
1539
|
+
* client's branch renders fresh DOM (hydration is disabled for the render,
|
|
1540
|
+
* which makes `addFragment` insert instead of adopt) and the parent resumes
|
|
1541
|
+
* hydrating at the control's anchor afterwards (see `runControl`).
|
|
1542
|
+
*
|
|
1543
|
+
* No client regions or effects exist for the server's markup — it was never
|
|
1544
|
+
* rendered through the client pipeline — so the nodes can simply be removed.
|
|
1545
|
+
* The nodes span from the first node inside the hydration block (the
|
|
1546
|
+
* hydration cursor) up to (not including) the control's anchor.
|
|
1547
|
+
*
|
|
1548
|
+
* Ancestor regions whose window starts at the removed node are reset to the
|
|
1549
|
+
* anchor: the same shape a mount-time block whose region owns only the anchor
|
|
1550
|
+
* has. `widenAncestorsAtAnchor` widens those to the fresh branch's first node
|
|
1551
|
+
* once the branch has rendered.
|
|
1552
|
+
*/
|
|
1553
|
+
function clearServerBranch(region, removedFirst, anchor) {
|
|
1554
|
+
let ancestor = region.previousRegion;
|
|
1555
|
+
let ancestorDepth = region.depth;
|
|
1556
|
+
while (ancestor !== null && ancestor.depth < ancestorDepth) {
|
|
1557
|
+
if (ancestor.startNode === removedFirst) ancestor.startNode = anchor;
|
|
1558
|
+
ancestorDepth = ancestor.depth;
|
|
1559
|
+
ancestor = ancestor.previousRegion;
|
|
1560
|
+
}
|
|
1561
|
+
context.hydrationNode = null;
|
|
1562
|
+
let node = removedFirst;
|
|
1563
|
+
while (node !== null && node !== anchor) {
|
|
1564
|
+
const next = node.nextSibling;
|
|
1565
|
+
node.remove();
|
|
1566
|
+
node = next;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1460
1569
|
//#endregion
|
|
1461
1570
|
//#region src/render/checkListKeys.ts
|
|
1462
1571
|
const warnedByRegion = /* @__PURE__ */ new WeakMap();
|
|
@@ -2165,13 +2274,17 @@ const SHALLOW_WATCH_OPTIONS = { shallow: true };
|
|
|
2165
2274
|
* caller can slot it into the live list. The sibling chain is left for the
|
|
2166
2275
|
* end-of-pass relink.
|
|
2167
2276
|
*/
|
|
2168
|
-
function mountSpec(spec, region, before, create, noWatch) {
|
|
2277
|
+
function mountSpec(spec, region, before, anchor, create, noWatch) {
|
|
2169
2278
|
const item = newListItem(spec.data, spec.key);
|
|
2170
2279
|
const savedActiveRegion = context.activeRegion;
|
|
2171
2280
|
item.depth = region.depth + 1;
|
|
2172
2281
|
context.activeRegion = item;
|
|
2173
2282
|
if (noWatch !== true) item.data = $watch(item.data, SHALLOW_WATCH_OPTIONS);
|
|
2283
|
+
const suspendHydration = context.hydrationNode !== null && context.hydrationNode === anchor;
|
|
2284
|
+
const savedHydrationNode = context.hydrationNode;
|
|
2285
|
+
if (suspendHydration) context.hydrationNode = null;
|
|
2174
2286
|
create(item, before);
|
|
2287
|
+
if (suspendHydration) context.hydrationNode = savedHydrationNode;
|
|
2175
2288
|
context.activeRegion = savedActiveRegion;
|
|
2176
2289
|
return item;
|
|
2177
2290
|
}
|
|
@@ -2240,7 +2353,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2240
2353
|
} else break;
|
|
2241
2354
|
if (oldStart > oldEnd && newStart <= newEnd) {
|
|
2242
2355
|
const before = newEnd + 1 < newSpecs.length ? newItems[newEnd + 1].startNode : anchor;
|
|
2243
|
-
for (let i = newStart; i <= newEnd; i++) newItems[i] = mountSpec(newSpecs[i], region, before, create, noWatch);
|
|
2356
|
+
for (let i = newStart; i <= newEnd; i++) newItems[i] = mountSpec(newSpecs[i], region, before, anchor, create, noWatch);
|
|
2244
2357
|
chainNeedsRelink = true;
|
|
2245
2358
|
} else if (newStart > newEnd) for (let i = oldStart; i <= oldEnd; i++) clearRegion(oldItems[i]);
|
|
2246
2359
|
else {
|
|
@@ -2255,7 +2368,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2255
2368
|
let before = oldItems[oldEnd]?.endNode?.nextSibling ?? anchor;
|
|
2256
2369
|
for (let i = oldEnd; i >= oldStart; i--) clearRegion(oldItems[i]);
|
|
2257
2370
|
for (let i = newStart; i <= newEnd; i++) {
|
|
2258
|
-
newItems[i] = mountSpec(newSpecs[i], region, before, create, noWatch);
|
|
2371
|
+
newItems[i] = mountSpec(newSpecs[i], region, before, anchor, create, noWatch);
|
|
2259
2372
|
before = newItems[i].endNode.nextSibling;
|
|
2260
2373
|
}
|
|
2261
2374
|
chainNeedsRelink = true;
|
|
@@ -2277,7 +2390,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2277
2390
|
const newIdx = newStart + i;
|
|
2278
2391
|
const before = newIdx + 1 < newSpecs.length ? newItems[newIdx + 1].startNode : anchor;
|
|
2279
2392
|
if (newIndexToOld[i] === 0) {
|
|
2280
|
-
newItems[newIdx] = mountSpec(newSpecs[newIdx], region, before, create, noWatch);
|
|
2393
|
+
newItems[newIdx] = mountSpec(newSpecs[newIdx], region, before, anchor, create, noWatch);
|
|
2281
2394
|
chainNeedsRelink = true;
|
|
2282
2395
|
} else if (j < 0 || i !== seq[j]) {
|
|
2283
2396
|
moveRegion(parent, newItems[newIdx], before);
|
|
@@ -2619,8 +2732,23 @@ function headElement(tagName, selector) {
|
|
|
2619
2732
|
//#endregion
|
|
2620
2733
|
//#region src/render/setAttribute.ts
|
|
2621
2734
|
function setAttribute(el, name, value) {
|
|
2622
|
-
if (value === false || value === void 0 || value === null)
|
|
2623
|
-
|
|
2735
|
+
if (value === false || value === void 0 || value === null) {
|
|
2736
|
+
el.removeAttribute(name);
|
|
2737
|
+
if (name === "value") setValueProperty(el, "");
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
if (name === "value") {
|
|
2741
|
+
if (setValueProperty(el, String(value))) return;
|
|
2742
|
+
}
|
|
2743
|
+
el.setAttribute(name, value);
|
|
2744
|
+
}
|
|
2745
|
+
/** Sets the `value` property on a form control; returns false for other elements. */
|
|
2746
|
+
function setValueProperty(el, value) {
|
|
2747
|
+
if (el.tagName === "INPUT" || el.tagName === "SELECT" || el.tagName === "TEXTAREA") {
|
|
2748
|
+
el.value = value;
|
|
2749
|
+
return true;
|
|
2750
|
+
}
|
|
2751
|
+
return false;
|
|
2624
2752
|
}
|
|
2625
2753
|
//#endregion
|
|
2626
2754
|
//#region src/render/setDynamicElement.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -124,6 +124,12 @@ declare function hydrate(parent: ParentNode, component: Component, props?: Recor
|
|
|
124
124
|
/**
|
|
125
125
|
* Mounts a component into a DOM node
|
|
126
126
|
*
|
|
127
|
+
* The parent should be connected to the document: delegated events (click,
|
|
128
|
+
* input, keydown, ...) are handled by a single listener per event type on
|
|
129
|
+
* `document`, so events raised inside a detached container never reach their
|
|
130
|
+
* handlers. (`hydrate` mounts into server-rendered markup, which is already
|
|
131
|
+
* connected.)
|
|
132
|
+
*
|
|
127
133
|
* @param parent The node to mount the component into
|
|
128
134
|
* @param component The component to mount
|
|
129
135
|
* @param props An object containing component props
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WACX,MAAM,YACN,QAAQ,YACR,QAAQ,aACR,SAAS,OAAO,mBAChB,WAAW,OAAO,oBAChB;;;iBC5BqB,WAAW;;;;;;;;iBCiBX,gBAAgB,QAAQ,YAAY;;;iBCnBpC,YACvB,UAAU,UACV,OAAO,oBACP,eACA,cACA,eACE;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCkBqB,mBACvB,UAAU,UACV,OAAO,WACP,eACA,cACA,eACE;;;;;;;;;iBCfqB,QACvB,QAAQ,YACR,WAAW,WACX,QAAQ,qBACR,QAAQ,eAAe
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WAC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;;;iBCrCW,QAAQ,UAAU,OAAO,mBAAmB,QAAQ,IAAI;;;;;;UCJvD;;;;EAIxB;;;;;;;;;;;;;iBCoBuB,OAAO,kBAAkB,QAAQ,GAAG,UAAU,eAAe"}
|
package/dist/index.d.mts
CHANGED
|
@@ -124,6 +124,12 @@ declare function hydrate(parent: ParentNode, component: Component, props?: Recor
|
|
|
124
124
|
/**
|
|
125
125
|
* Mounts a component into a DOM node
|
|
126
126
|
*
|
|
127
|
+
* The parent should be connected to the document: delegated events (click,
|
|
128
|
+
* input, keydown, ...) are handled by a single listener per event type on
|
|
129
|
+
* `document`, so events raised inside a detached container never reach their
|
|
130
|
+
* handlers. (`hydrate` mounts into server-rendered markup, which is already
|
|
131
|
+
* connected.)
|
|
132
|
+
*
|
|
127
133
|
* @param parent The node to mount the component into
|
|
128
134
|
* @param component The component to mount
|
|
129
135
|
* @param props An object containing component props
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WACX,MAAM,YACN,QAAQ,YACR,QAAQ,aACR,SAAS,OAAO,mBAChB,WAAW,OAAO,oBAChB;;;iBC5BqB,WAAW;;;;;;;;iBCiBX,gBAAgB,QAAQ,YAAY;;;iBCnBpC,YACvB,UAAU,UACV,OAAO,oBACP,eACA,cACA,eACE;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCkBqB,mBACvB,UAAU,UACV,OAAO,WACP,eACA,cACA,eACE;;;;;;;;;iBCfqB,QACvB,QAAQ,YACR,WAAW,WACX,QAAQ,qBACR,QAAQ,eAAe
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/Animation.ts","../src/render/addAnimation.ts","../src/render/addEvent.ts","../src/render/addElement.ts","../src/render/addFragment.ts","../src/render/applyProps.ts","../src/render/clearLayoutSlot.ts","../src/render/fillLayoutSlot.ts","../src/render/formatText.ts","../src/render/firstInsideNode.ts","../src/render/getFragment.ts","../src/render/getElementFragment.ts","../src/render/hydrate.ts","../src/render/mount.ts","../src/render/unmount.ts","../src/types/ListItemSpec.ts","../src/types/ListItem.ts","../src/render/newListItem.ts","../src/render/newRegion.ts","../src/render/nodeAnchor.ts","../src/render/nodeChild.ts","../src/render/nodeNext.ts","../src/render/nodeRootElement.ts","../src/render/nodeRoot.ts","../src/render/nodeSkip.ts","../src/render/popRegion.ts","../src/render/pushRegion.ts","../src/render/rerunRegionEffects.ts","../src/render/restoreHydration.ts","../src/render/runControl.ts","../src/render/runControlBranch.ts","../src/render/runList.ts","../src/render/runAwait.ts","../src/render/runTry.ts","../src/render/saveHydration.ts","../src/render/headElement.ts","../src/render/setAttribute.ts","../src/render/setDynamicElement.ts","../src/types/Bindable.ts","../src/watch/$batch.ts","../src/watch/$async.ts","../src/watch/$bind.ts","../src/watch/$cache.ts","../src/watch/$onmount.ts","../src/watch/$peek.ts","../src/watch/$pending.ts","../src/watch/$refresh.ts","../src/watch/$run.ts","../src/watch/$stream.ts","../src/watch/$unwrap.ts","../src/types/WatchOptions.ts","../src/watch/$watch.ts"],"mappings":";;;;;UAAyB;EACxB,WAAW,aAAa;EACxB,mBAAmB;;;;iBCCI,aAAa,IAAI,aAAa,QAAQ,WAAW,OAAO;;;iBCDxD,SACvB,IAAI,SACJ,cACA,YAAA,MAAkB,SAAS;;;;;;;;;;;;;;;;;;;;;;iBCiBJ,WAAW,MAAM,SAAS,QAAQ,YAAY,QAAQ;;;iBCnBtD,YACvB,UAAU,kBACV,QAAQ,YACR,QAAQ,aACR,UAAU,WACV,YAAY;;;iBCLW,WACvB,IAAI,SACJ,OAAO,iCACP;;;;;;;;;;iBCKuB,gBAAgB,QAAQ;;;;;;;;;;;;;;;;;;iBCYxB,eACvB,WAAW,WACX,MAAM,YACN,QAAQ,YACR,QAAQ,aACR,SAAS,OAAO,mBAChB,WAAW,OAAO,oBAChB;;;iBC5BqB,WAAW;;;;;;;;iBCiBX,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AkB,QAAQ,GAAG,UAAU,eAAe"}
|
package/dist/index.mjs
CHANGED
|
@@ -906,6 +906,7 @@ function pushRegion(region, toParent = false) {
|
|
|
906
906
|
function fillLayoutSlot(component, slot, parent, anchor, $props, $context) {
|
|
907
907
|
const region = newRegion(devContext.enabled ? "Layout slot" : void 0);
|
|
908
908
|
const oldRegion = pushRegion(region, true);
|
|
909
|
+
region.depth = region.previousRegion === null ? 0 : region.previousRegion.depth + 1;
|
|
909
910
|
component(parent, anchor, $props, $context, { _: slot });
|
|
910
911
|
popRegion(oldRegion);
|
|
911
912
|
return region;
|
|
@@ -1029,6 +1030,12 @@ function hydrate(parent, component, props, slots) {
|
|
|
1029
1030
|
/**
|
|
1030
1031
|
* Mounts a component into a DOM node
|
|
1031
1032
|
*
|
|
1033
|
+
* The parent should be connected to the document: delegated events (click,
|
|
1034
|
+
* input, keydown, ...) are handled by a single listener per event type on
|
|
1035
|
+
* `document`, so events raised inside a detached container never reach their
|
|
1036
|
+
* handlers. (`hydrate` mounts into server-rendered markup, which is already
|
|
1037
|
+
* connected.)
|
|
1038
|
+
*
|
|
1032
1039
|
* @param parent The node to mount the component into
|
|
1033
1040
|
* @param component The component to mount
|
|
1034
1041
|
* @param props An object containing component props
|
|
@@ -1084,6 +1091,51 @@ function newListItem(data, key, name) {
|
|
|
1084
1091
|
};
|
|
1085
1092
|
}
|
|
1086
1093
|
//#endregion
|
|
1094
|
+
//#region src/render/branchIndex.ts
|
|
1095
|
+
/**
|
|
1096
|
+
* During hydration, the server writes the index of the branch it rendered for
|
|
1097
|
+
* a control statement (`@if`/`@switch`) into the block's leading branch-break
|
|
1098
|
+
* marker (`<!^2>`). `nodeAnchor` reads that marker while consuming the block's
|
|
1099
|
+
* markers and stashes the index here, keyed by the anchor node it returns —
|
|
1100
|
+
* the same pattern as `firstInsideNode`, since the marker is gone by the time
|
|
1101
|
+
* the index is needed. `runControl` picks the index up from the anchor so
|
|
1102
|
+
* `runControlBranch` can compare it with the branch the client picks: server
|
|
1103
|
+
* and client conditions can legitimately differ (browser-only state, effects
|
|
1104
|
+
* that no-op on the server), and a branch the server rendered but the client
|
|
1105
|
+
* didn't pick must be recreated rather than adopted.
|
|
1106
|
+
*/
|
|
1107
|
+
const branchIndexes = /* @__PURE__ */ new WeakMap();
|
|
1108
|
+
function setBranchIndex(anchor, index) {
|
|
1109
|
+
branchIndexes.set(anchor, index);
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Takes (and clears) the server-rendered branch index stashed for the given
|
|
1113
|
+
* anchor node, or `undefined` if the anchor wasn't hydrated through a
|
|
1114
|
+
* branch-indexed hydration block.
|
|
1115
|
+
*/
|
|
1116
|
+
function takeBranchIndex(anchor) {
|
|
1117
|
+
const index = branchIndexes.get(anchor);
|
|
1118
|
+
if (index !== void 0) branchIndexes.delete(anchor);
|
|
1119
|
+
return index;
|
|
1120
|
+
}
|
|
1121
|
+
const HYDRATION_BREAK_REGEX = /^\^(?:\d+)?$/;
|
|
1122
|
+
/**
|
|
1123
|
+
* Whether a comment node's data is a branch-break marker (`^`, or `^<index>`
|
|
1124
|
+
* when the server recorded the branch it rendered).
|
|
1125
|
+
*/
|
|
1126
|
+
function isHydrationBreak(data) {
|
|
1127
|
+
return HYDRATION_BREAK_REGEX.test(data);
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* The branch index encoded in a `^<index>` branch-break marker, or `undefined`
|
|
1131
|
+
* for a plain `^` marker (e.g. from `@for`, which has no branch index).
|
|
1132
|
+
*/
|
|
1133
|
+
function hydrationBreakIndex(data) {
|
|
1134
|
+
if (!data.startsWith("^") || data.length === 1) return;
|
|
1135
|
+
const index = Number(data.slice(1));
|
|
1136
|
+
return Number.isNaN(index) ? void 0 : index;
|
|
1137
|
+
}
|
|
1138
|
+
//#endregion
|
|
1087
1139
|
//#region src/render/isCommentNode.ts
|
|
1088
1140
|
function isCommentNode(node) {
|
|
1089
1141
|
return node.nodeType === 8;
|
|
@@ -1104,7 +1156,7 @@ function isTextNode(node) {
|
|
|
1104
1156
|
* @returns The next node.
|
|
1105
1157
|
*/
|
|
1106
1158
|
function nodeCheckHydrationBreak(node) {
|
|
1107
|
-
if (node !== null && isCommentNode(node) && node.data
|
|
1159
|
+
if (node !== null && isCommentNode(node) && isHydrationBreak(node.data)) {
|
|
1108
1160
|
let comment = node;
|
|
1109
1161
|
node = node.nextSibling;
|
|
1110
1162
|
comment.remove();
|
|
@@ -1155,9 +1207,14 @@ function nodeAnchor(node) {
|
|
|
1155
1207
|
if (context.hydrationNode !== null) {
|
|
1156
1208
|
if (isCommentNode(node) && node.data === "[") {
|
|
1157
1209
|
const startParent = node.parentNode;
|
|
1210
|
+
let branchIndex = void 0;
|
|
1211
|
+
let peek = node.nextSibling;
|
|
1212
|
+
while (peek !== null && isTextNode(peek) && (peek.textContent ?? "").trim() === "") peek = peek.nextSibling;
|
|
1213
|
+
if (peek !== null && isCommentNode(peek) && isHydrationBreak(peek.data)) branchIndex = hydrationBreakIndex(peek.data);
|
|
1158
1214
|
let currentNode = nodeNext(node);
|
|
1159
1215
|
node.remove();
|
|
1160
|
-
while (currentNode !== null && isCommentNode(currentNode) && currentNode.data
|
|
1216
|
+
while (currentNode !== null && isCommentNode(currentNode) && isHydrationBreak(currentNode.data)) {
|
|
1217
|
+
if (branchIndex === void 0) branchIndex = hydrationBreakIndex(currentNode.data);
|
|
1161
1218
|
const next = currentNode.nextSibling;
|
|
1162
1219
|
currentNode.remove();
|
|
1163
1220
|
currentNode = next;
|
|
@@ -1178,6 +1235,7 @@ function nodeAnchor(node) {
|
|
|
1178
1235
|
const region = context.activeRegion;
|
|
1179
1236
|
if (region.startNode === null) region.startNode = firstContent ?? endNode;
|
|
1180
1237
|
setFirstInsideNode(endNode, firstContent);
|
|
1238
|
+
if (branchIndex !== void 0) setBranchIndex(endNode, branchIndex);
|
|
1181
1239
|
return endNode;
|
|
1182
1240
|
}
|
|
1183
1241
|
}
|
|
@@ -1231,7 +1289,7 @@ function walkHydrationRoot() {
|
|
|
1231
1289
|
let rootNode = context.hydrationNode;
|
|
1232
1290
|
while (rootNode !== null && isSkippable(rootNode)) {
|
|
1233
1291
|
const next = rootNode.nextSibling;
|
|
1234
|
-
if (isCommentNode(rootNode) && rootNode.data
|
|
1292
|
+
if (isCommentNode(rootNode) && isHydrationBreak(rootNode.data)) rootNode.remove();
|
|
1235
1293
|
rootNode = next;
|
|
1236
1294
|
context.hydrationNode = rootNode;
|
|
1237
1295
|
}
|
|
@@ -1246,7 +1304,7 @@ function walkHydrationRoot() {
|
|
|
1246
1304
|
}
|
|
1247
1305
|
function isSkippable(node) {
|
|
1248
1306
|
if (isTextNode(node) && (node.textContent ?? "").trim() === "") return true;
|
|
1249
|
-
if (isCommentNode(node)) return node.data
|
|
1307
|
+
if (isCommentNode(node)) return isHydrationBreak(node.data) || node.data === "";
|
|
1250
1308
|
return false;
|
|
1251
1309
|
}
|
|
1252
1310
|
//#endregion
|
|
@@ -1427,6 +1485,11 @@ function widenAncestorsAtAnchor(region, anchor) {
|
|
|
1427
1485
|
*/
|
|
1428
1486
|
function runControl(region, anchor, create, name) {
|
|
1429
1487
|
let first = true;
|
|
1488
|
+
if (context.hydrationNode !== null && anchor !== null) {
|
|
1489
|
+
region.ssrBranchAnchor = anchor;
|
|
1490
|
+
const ssrBranchIndex = takeBranchIndex(anchor);
|
|
1491
|
+
if (ssrBranchIndex !== void 0) region.ssrBranchIndex = ssrBranchIndex;
|
|
1492
|
+
}
|
|
1430
1493
|
const gen = region.generation = (region.generation ?? 0) + 1;
|
|
1431
1494
|
$run(function runControl() {
|
|
1432
1495
|
if (region.generation !== gen) return;
|
|
@@ -1436,7 +1499,10 @@ function runControl(region, anchor, create, name) {
|
|
|
1436
1499
|
create(anchor);
|
|
1437
1500
|
popRegion(oldRegion);
|
|
1438
1501
|
widenAncestorsAtAnchor(region, anchor);
|
|
1439
|
-
if (
|
|
1502
|
+
if (anchor !== null && (context.hydrationNode !== null || region.ssrBranchRecreated === true)) {
|
|
1503
|
+
region.ssrBranchRecreated = void 0;
|
|
1504
|
+
context.hydrationNode = anchor;
|
|
1505
|
+
}
|
|
1440
1506
|
}, name);
|
|
1441
1507
|
}
|
|
1442
1508
|
//#endregion
|
|
@@ -1444,6 +1510,17 @@ function runControl(region, anchor, create, name) {
|
|
|
1444
1510
|
function runControlBranch(region, oldIndex, index) {
|
|
1445
1511
|
const recreate = region.recreate;
|
|
1446
1512
|
if (recreate) region.recreate = false;
|
|
1513
|
+
const anchor = region.ssrBranchAnchor;
|
|
1514
|
+
if (anchor !== void 0) {
|
|
1515
|
+
region.ssrBranchAnchor = void 0;
|
|
1516
|
+
const ssrBranchIndex = region.ssrBranchIndex;
|
|
1517
|
+
region.ssrBranchIndex = void 0;
|
|
1518
|
+
const hydrationNode = context.hydrationNode;
|
|
1519
|
+
if (hydrationNode !== null && (ssrBranchIndex !== void 0 && ssrBranchIndex !== index || ssrBranchIndex === void 0 && hydrationNode === anchor)) {
|
|
1520
|
+
region.ssrBranchRecreated = true;
|
|
1521
|
+
clearServerBranch(region, hydrationNode, anchor);
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1447
1524
|
const firstRender = region.hasRenderedBranch !== true;
|
|
1448
1525
|
region.hasRenderedBranch = true;
|
|
1449
1526
|
if (oldIndex === index) {
|
|
@@ -1456,6 +1533,38 @@ function runControlBranch(region, oldIndex, index) {
|
|
|
1456
1533
|
if (!firstRender && region.nextRegion !== null && region.nextRegion.depth > region.depth) clearRegion(region.nextRegion);
|
|
1457
1534
|
return true;
|
|
1458
1535
|
}
|
|
1536
|
+
/**
|
|
1537
|
+
* Clears a server-rendered control branch that the client didn't pick, so the
|
|
1538
|
+
* client's branch renders fresh DOM (hydration is disabled for the render,
|
|
1539
|
+
* which makes `addFragment` insert instead of adopt) and the parent resumes
|
|
1540
|
+
* hydrating at the control's anchor afterwards (see `runControl`).
|
|
1541
|
+
*
|
|
1542
|
+
* No client regions or effects exist for the server's markup — it was never
|
|
1543
|
+
* rendered through the client pipeline — so the nodes can simply be removed.
|
|
1544
|
+
* The nodes span from the first node inside the hydration block (the
|
|
1545
|
+
* hydration cursor) up to (not including) the control's anchor.
|
|
1546
|
+
*
|
|
1547
|
+
* Ancestor regions whose window starts at the removed node are reset to the
|
|
1548
|
+
* anchor: the same shape a mount-time block whose region owns only the anchor
|
|
1549
|
+
* has. `widenAncestorsAtAnchor` widens those to the fresh branch's first node
|
|
1550
|
+
* once the branch has rendered.
|
|
1551
|
+
*/
|
|
1552
|
+
function clearServerBranch(region, removedFirst, anchor) {
|
|
1553
|
+
let ancestor = region.previousRegion;
|
|
1554
|
+
let ancestorDepth = region.depth;
|
|
1555
|
+
while (ancestor !== null && ancestor.depth < ancestorDepth) {
|
|
1556
|
+
if (ancestor.startNode === removedFirst) ancestor.startNode = anchor;
|
|
1557
|
+
ancestorDepth = ancestor.depth;
|
|
1558
|
+
ancestor = ancestor.previousRegion;
|
|
1559
|
+
}
|
|
1560
|
+
context.hydrationNode = null;
|
|
1561
|
+
let node = removedFirst;
|
|
1562
|
+
while (node !== null && node !== anchor) {
|
|
1563
|
+
const next = node.nextSibling;
|
|
1564
|
+
node.remove();
|
|
1565
|
+
node = next;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1459
1568
|
//#endregion
|
|
1460
1569
|
//#region src/render/checkListKeys.ts
|
|
1461
1570
|
const warnedByRegion = /* @__PURE__ */ new WeakMap();
|
|
@@ -2164,13 +2273,17 @@ const SHALLOW_WATCH_OPTIONS = { shallow: true };
|
|
|
2164
2273
|
* caller can slot it into the live list. The sibling chain is left for the
|
|
2165
2274
|
* end-of-pass relink.
|
|
2166
2275
|
*/
|
|
2167
|
-
function mountSpec(spec, region, before, create, noWatch) {
|
|
2276
|
+
function mountSpec(spec, region, before, anchor, create, noWatch) {
|
|
2168
2277
|
const item = newListItem(spec.data, spec.key);
|
|
2169
2278
|
const savedActiveRegion = context.activeRegion;
|
|
2170
2279
|
item.depth = region.depth + 1;
|
|
2171
2280
|
context.activeRegion = item;
|
|
2172
2281
|
if (noWatch !== true) item.data = $watch(item.data, SHALLOW_WATCH_OPTIONS);
|
|
2282
|
+
const suspendHydration = context.hydrationNode !== null && context.hydrationNode === anchor;
|
|
2283
|
+
const savedHydrationNode = context.hydrationNode;
|
|
2284
|
+
if (suspendHydration) context.hydrationNode = null;
|
|
2173
2285
|
create(item, before);
|
|
2286
|
+
if (suspendHydration) context.hydrationNode = savedHydrationNode;
|
|
2174
2287
|
context.activeRegion = savedActiveRegion;
|
|
2175
2288
|
return item;
|
|
2176
2289
|
}
|
|
@@ -2239,7 +2352,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2239
2352
|
} else break;
|
|
2240
2353
|
if (oldStart > oldEnd && newStart <= newEnd) {
|
|
2241
2354
|
const before = newEnd + 1 < newSpecs.length ? newItems[newEnd + 1].startNode : anchor;
|
|
2242
|
-
for (let i = newStart; i <= newEnd; i++) newItems[i] = mountSpec(newSpecs[i], region, before, create, noWatch);
|
|
2355
|
+
for (let i = newStart; i <= newEnd; i++) newItems[i] = mountSpec(newSpecs[i], region, before, anchor, create, noWatch);
|
|
2243
2356
|
chainNeedsRelink = true;
|
|
2244
2357
|
} else if (newStart > newEnd) for (let i = oldStart; i <= oldEnd; i++) clearRegion(oldItems[i]);
|
|
2245
2358
|
else {
|
|
@@ -2254,7 +2367,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2254
2367
|
let before = oldItems[oldEnd]?.endNode?.nextSibling ?? anchor;
|
|
2255
2368
|
for (let i = oldEnd; i >= oldStart; i--) clearRegion(oldItems[i]);
|
|
2256
2369
|
for (let i = newStart; i <= newEnd; i++) {
|
|
2257
|
-
newItems[i] = mountSpec(newSpecs[i], region, before, create, noWatch);
|
|
2370
|
+
newItems[i] = mountSpec(newSpecs[i], region, before, anchor, create, noWatch);
|
|
2258
2371
|
before = newItems[i].endNode.nextSibling;
|
|
2259
2372
|
}
|
|
2260
2373
|
chainNeedsRelink = true;
|
|
@@ -2276,7 +2389,7 @@ function runListItems(region, parent, anchor, oldItems, newSpecs, create, update
|
|
|
2276
2389
|
const newIdx = newStart + i;
|
|
2277
2390
|
const before = newIdx + 1 < newSpecs.length ? newItems[newIdx + 1].startNode : anchor;
|
|
2278
2391
|
if (newIndexToOld[i] === 0) {
|
|
2279
|
-
newItems[newIdx] = mountSpec(newSpecs[newIdx], region, before, create, noWatch);
|
|
2392
|
+
newItems[newIdx] = mountSpec(newSpecs[newIdx], region, before, anchor, create, noWatch);
|
|
2280
2393
|
chainNeedsRelink = true;
|
|
2281
2394
|
} else if (j < 0 || i !== seq[j]) {
|
|
2282
2395
|
moveRegion(parent, newItems[newIdx], before);
|
|
@@ -2618,8 +2731,23 @@ function headElement(tagName, selector) {
|
|
|
2618
2731
|
//#endregion
|
|
2619
2732
|
//#region src/render/setAttribute.ts
|
|
2620
2733
|
function setAttribute(el, name, value) {
|
|
2621
|
-
if (value === false || value === void 0 || value === null)
|
|
2622
|
-
|
|
2734
|
+
if (value === false || value === void 0 || value === null) {
|
|
2735
|
+
el.removeAttribute(name);
|
|
2736
|
+
if (name === "value") setValueProperty(el, "");
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2739
|
+
if (name === "value") {
|
|
2740
|
+
if (setValueProperty(el, String(value))) return;
|
|
2741
|
+
}
|
|
2742
|
+
el.setAttribute(name, value);
|
|
2743
|
+
}
|
|
2744
|
+
/** Sets the `value` property on a form control; returns false for other elements. */
|
|
2745
|
+
function setValueProperty(el, value) {
|
|
2746
|
+
if (el.tagName === "INPUT" || el.tagName === "SELECT" || el.tagName === "TEXTAREA") {
|
|
2747
|
+
el.value = value;
|
|
2748
|
+
return true;
|
|
2749
|
+
}
|
|
2750
|
+
return false;
|
|
2623
2751
|
}
|
|
2624
2752
|
//#endregion
|
|
2625
2753
|
//#region src/render/setDynamicElement.ts
|