kerfjs 5.0.0-beta.13 → 5.0.0-beta.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3370 -108
- package/README.md +101 -37
- package/ai/cursorrules +127 -68
- package/ai/manifest.json +36 -7
- package/ai/skill.md +167 -86
- package/ai/ui-skill.md +18 -0
- package/dist/actions.d.ts +1 -1
- package/dist/actions.js +10 -6
- package/dist/actions.js.map +1 -1
- package/dist/array-signal.js +1 -1
- package/dist/async.d.ts +7 -3
- package/dist/async.js +39 -22
- package/dist/async.js.map +1 -1
- package/dist/attach.js +1 -66
- package/dist/attach.js.map +1 -1
- package/dist/{chunk-GY4XV2UV.js → chunk-4TX6YJDM.js} +10 -3
- package/dist/chunk-4TX6YJDM.js.map +1 -0
- package/dist/{chunk-SVATPF5R.js → chunk-5QDM6HPD.js} +637 -277
- package/dist/chunk-5QDM6HPD.js.map +1 -0
- package/dist/{chunk-QIP723L4.js → chunk-5WRGJZV6.js} +3 -2
- package/dist/chunk-5WRGJZV6.js.map +1 -0
- package/dist/chunk-AP2FT33F.js +87 -0
- package/dist/chunk-AP2FT33F.js.map +1 -0
- package/dist/chunk-BTOKH5FA.js +70 -0
- package/dist/chunk-BTOKH5FA.js.map +1 -0
- package/dist/{chunk-ZDCJZCNO.js → chunk-GGADRIQO.js} +168 -97
- package/dist/chunk-GGADRIQO.js.map +1 -0
- package/dist/chunk-KOEGJCIS.js +65 -0
- package/dist/chunk-KOEGJCIS.js.map +1 -0
- package/dist/{chunk-HW7KSM2Y.js → chunk-KUHXPPJ4.js} +1 -1
- package/dist/chunk-KUHXPPJ4.js.map +1 -0
- package/dist/{chunk-UZJ6I4T6.js → chunk-MK42GLPV.js} +1 -1
- package/dist/chunk-MK42GLPV.js.map +1 -0
- package/dist/chunk-N4VHHOCM.js +27 -0
- package/dist/chunk-N4VHHOCM.js.map +1 -0
- package/dist/{chunk-V46JKE44.js → chunk-NRPLVJVR.js} +43 -14
- package/dist/chunk-NRPLVJVR.js.map +1 -0
- package/dist/{chunk-LVH3GC6B.js → chunk-QOAB2ESQ.js} +3 -3
- package/dist/chunk-QOAB2ESQ.js.map +1 -0
- package/dist/{chunk-KZJXHFIB.js → chunk-V322Z7FX.js} +5 -5
- package/dist/chunk-V322Z7FX.js.map +1 -0
- package/dist/{delegate-CL9VTZFb.d.ts → delegate--CrfgYtC.d.ts} +0 -34
- package/dist/dev.d.ts +46 -15
- package/dist/dev.js +185 -40
- package/dist/dev.js.map +1 -1
- package/dist/html.js +20 -8
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +98 -13
- package/dist/index.js +49 -21
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +25 -10
- package/dist/jsx-runtime.js +1 -1
- package/dist/list.d.ts +7 -3
- package/dist/list.js +236 -78
- package/dist/list.js.map +1 -1
- package/dist/overlay.d.ts +287 -142
- package/dist/overlay.js +1039 -369
- package/dist/overlay.js.map +1 -1
- package/dist/remount.js +2 -2
- package/dist/remount.js.map +1 -1
- package/dist/router.d.ts +22 -6
- package/dist/router.js +58 -19
- package/dist/router.js.map +1 -1
- package/dist/scope.d.ts +45 -8
- package/dist/scope.js +69 -30
- package/dist/scope.js.map +1 -1
- package/dist/testing.js +1 -1
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +8 -3
- package/dist/timing.js.map +1 -1
- package/llms.txt +17 -6
- package/package.json +48 -12
- package/setup/apply.mjs +202 -0
- package/setup/cli.mjs +95 -0
- package/setup/common.mjs +77 -0
- package/setup/detect.mjs +274 -0
- package/setup/index.d.mts +39 -0
- package/setup/index.mjs +1226 -0
- package/setup/jsonc.mjs +201 -0
- package/setup/state.schema.json +57 -0
- package/setup/ui-baseline.mjs +210 -0
- package/dist/chunk-GY4XV2UV.js.map +0 -1
- package/dist/chunk-HW7KSM2Y.js.map +0 -1
- package/dist/chunk-KPXIOG2C.js +0 -54
- package/dist/chunk-KPXIOG2C.js.map +0 -1
- package/dist/chunk-KZJXHFIB.js.map +0 -1
- package/dist/chunk-LVH3GC6B.js.map +0 -1
- package/dist/chunk-QIP723L4.js.map +0 -1
- package/dist/chunk-SVATPF5R.js.map +0 -1
- package/dist/chunk-U6FK33SG.js +0 -20
- package/dist/chunk-U6FK33SG.js.map +0 -1
- package/dist/chunk-UZJ6I4T6.js.map +0 -1
- package/dist/chunk-V46JKE44.js.map +0 -1
- package/dist/chunk-ZDCJZCNO.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { itemVersion } from './chunk-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { effect } from './chunk-
|
|
5
|
-
import {
|
|
6
|
-
import { devHooks } from './chunk-
|
|
1
|
+
import { itemVersion } from './chunk-5WRGJZV6.js';
|
|
2
|
+
import { seedRenderedAttrs, RENDERED_ATTRS, isUserAgentOwnedAttr, hasCustomTag, parseSingleRow, parseRows } from './chunk-NRPLVJVR.js';
|
|
3
|
+
import { _listSafeHtml, boundTextNodeOf, syncFormProp, newBindingContext, wireBindings, disposeRowBindings, captureRowBindings, isSafeHtml, _setBindingContext, coerceText, TEXT_MARKER_PREFIX, ROW_TEXT_PREFIX, wireRowBindings, carryOrRewireRowBindings, _granularListSafeHtml } from './chunk-GGADRIQO.js';
|
|
4
|
+
import { effect } from './chunk-N4VHHOCM.js';
|
|
5
|
+
import { flattenWithoutListItems, collectLists, LIST_MARKER_PREFIX, isOverlayHost, flatten } from './chunk-4TX6YJDM.js';
|
|
6
|
+
import { devHooks } from './chunk-KUHXPPJ4.js';
|
|
7
7
|
|
|
8
8
|
// src/list-render-state.ts
|
|
9
9
|
function deriveListRenderState(bindingCount) {
|
|
@@ -18,7 +18,8 @@ function decideListPath(state, patches, snapshotLength, previousBindingCount) {
|
|
|
18
18
|
for (const p of patches) {
|
|
19
19
|
if (p.type === "insert") netDelta += 1;
|
|
20
20
|
else if (p.type === "remove") netDelta -= 1;
|
|
21
|
-
else if (p.type === "replace")
|
|
21
|
+
else if (p.type === "replace")
|
|
22
|
+
return { path: "snapshot", reason: "replace" };
|
|
22
23
|
}
|
|
23
24
|
const count = previousBindingCount ?? 0;
|
|
24
25
|
if (count + netDelta !== snapshotLength) {
|
|
@@ -34,14 +35,17 @@ function isArraySignal(value) {
|
|
|
34
35
|
}
|
|
35
36
|
var context = null;
|
|
36
37
|
var renderingRow = false;
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
function renderRow(render, item, index) {
|
|
39
|
+
return captureRowBindings(() => {
|
|
40
|
+
const prev = renderingRow;
|
|
41
|
+
renderingRow = true;
|
|
42
|
+
try {
|
|
43
|
+
const out = render(item, index);
|
|
44
|
+
return isSafeHtml(out) ? out.toString() : out;
|
|
45
|
+
} finally {
|
|
46
|
+
renderingRow = prev;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
45
49
|
}
|
|
46
50
|
function _setRenderContext(c) {
|
|
47
51
|
context = c;
|
|
@@ -65,7 +69,8 @@ function assertValidKey(key) {
|
|
|
65
69
|
);
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
|
-
function
|
|
72
|
+
function listId(ctx, key) {
|
|
73
|
+
if (key === void 0) return String(ctx.counter++);
|
|
69
74
|
assertValidKey(key);
|
|
70
75
|
if (renderingRow) {
|
|
71
76
|
throw new Error(
|
|
@@ -91,12 +96,7 @@ function each(items, render, cacheKeyOrOptions) {
|
|
|
91
96
|
return eachSnapshot(snapshotItems, render, cacheKey, listKey);
|
|
92
97
|
}
|
|
93
98
|
function eachSnapshot(items, render, cacheKey, listKey) {
|
|
94
|
-
|
|
95
|
-
if (context !== null) {
|
|
96
|
-
id = listKey !== void 0 ? claimKey(context, listKey) : String(context.counter++);
|
|
97
|
-
} else {
|
|
98
|
-
id = "orphan";
|
|
99
|
-
}
|
|
99
|
+
const id = context !== null ? listId(context, listKey) : "orphan";
|
|
100
100
|
return eachSnapshotById(items, render, cacheKey, id);
|
|
101
101
|
}
|
|
102
102
|
function assertObjectItem(item, index) {
|
|
@@ -110,11 +110,18 @@ function _hasGranularIndexShift(previousBindingCount, patches) {
|
|
|
110
110
|
const rendered = [];
|
|
111
111
|
for (let i = 0; i < previousBindingCount; i++) rendered.push(i);
|
|
112
112
|
for (const patch of patches) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
switch (patch.type) {
|
|
114
|
+
case "insert":
|
|
115
|
+
rendered.splice(patch.index, 0, patch.index);
|
|
116
|
+
break;
|
|
117
|
+
case "remove":
|
|
118
|
+
rendered.splice(patch.index, 1);
|
|
119
|
+
break;
|
|
120
|
+
case "move": {
|
|
121
|
+
const [moved] = rendered.splice(patch.from, 1);
|
|
122
|
+
rendered.splice(patch.to, 0, moved);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
return rendered.some((renderedAt, index) => renderedAt !== index);
|
|
@@ -130,7 +137,7 @@ function _hasGranularCacheKeyDrift(snapshot, cacheKey, cache) {
|
|
|
130
137
|
}
|
|
131
138
|
function eachGranular(sig, render, cacheKey, listKey) {
|
|
132
139
|
const ctx = context;
|
|
133
|
-
const id =
|
|
140
|
+
const id = listId(ctx, listKey);
|
|
134
141
|
const previousBindingCount = ctx.bindingCounts.get(id);
|
|
135
142
|
const patches = sig._consumePatches();
|
|
136
143
|
const snapshot = sig.value;
|
|
@@ -153,10 +160,6 @@ function eachGranular(sig, render, cacheKey, listKey) {
|
|
|
153
160
|
return eachSnapshotById(snapshot, render, cacheKey, id, sig);
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
|
-
const renderRow = (item, index) => captureRowBindings(() => inRowScope(() => {
|
|
157
|
-
const out = render(item, index);
|
|
158
|
-
return isSafeHtml(out) ? out.toString() : out;
|
|
159
|
-
}));
|
|
160
163
|
const internalPatches = new Array(patches.length);
|
|
161
164
|
const cache = ctx.caches.get(id);
|
|
162
165
|
try {
|
|
@@ -164,7 +167,7 @@ function eachGranular(sig, render, cacheKey, listKey) {
|
|
|
164
167
|
const p = patches[i];
|
|
165
168
|
if (p.type === "insert" || p.type === "update") {
|
|
166
169
|
assertObjectItem(p.item, p.index);
|
|
167
|
-
const { html, bindings } = renderRow(p.item, p.index);
|
|
170
|
+
const { html, bindings } = renderRow(render, p.item, p.index);
|
|
168
171
|
internalPatches[i] = {
|
|
169
172
|
type: p.type,
|
|
170
173
|
index: p.index,
|
|
@@ -188,7 +191,7 @@ function eachGranular(sig, render, cacheKey, listKey) {
|
|
|
188
191
|
return eachSnapshotById(snapshot, render, cacheKey, id, sig);
|
|
189
192
|
}
|
|
190
193
|
if (staleIndexShift) devHooks.staleIndex?.(id);
|
|
191
|
-
return
|
|
194
|
+
return _granularListSafeHtml(id, [], internalPatches, sig);
|
|
192
195
|
}
|
|
193
196
|
function eachSnapshotById(items, render, cacheKey, id, source) {
|
|
194
197
|
let cache = null;
|
|
@@ -201,16 +204,20 @@ function eachSnapshotById(items, render, cacheKey, id, source) {
|
|
|
201
204
|
cache = c;
|
|
202
205
|
}
|
|
203
206
|
const segItems = new Array(items.length);
|
|
204
|
-
const seen = /* @__PURE__ */ new
|
|
207
|
+
const seen = /* @__PURE__ */ new Map();
|
|
205
208
|
for (let i = 0; i < items.length; i++) {
|
|
206
209
|
const item = items[i];
|
|
207
210
|
assertObjectItem(item, i);
|
|
208
|
-
|
|
211
|
+
const first = seen.get(item);
|
|
212
|
+
if (first !== void 0) {
|
|
209
213
|
throw new Error(
|
|
210
|
-
`each(): the same object reference appears at multiple indices in items (first
|
|
214
|
+
`each(): the same object reference appears at multiple indices in items (first at index ${first}, again at index ${i}). The per-item HTML cache is keyed on object identity, so duplicate references break the keyed reconciler and can leak DOM nodes on re-render. Use a fresh object per row (e.g. items.map(o => ({ ...o })) before passing to each()).` + // KF-7HMTZQ: an arraySignal's push/insert/update renders through the
|
|
215
|
+
// granular path, which skips this O(N) check, so the duplicate may
|
|
216
|
+
// predate this render; say where to look instead of blaming it.
|
|
217
|
+
(source !== void 0 ? " (arraySignal: likely added by an earlier push/insert/update, not this render.)" : "")
|
|
211
218
|
);
|
|
212
219
|
}
|
|
213
|
-
seen.
|
|
220
|
+
seen.set(item, i);
|
|
214
221
|
const k = cacheKey ? cacheKey(item, i) : void 0;
|
|
215
222
|
const version = itemVersion(item);
|
|
216
223
|
let html;
|
|
@@ -223,20 +230,18 @@ function eachSnapshotById(items, render, cacheKey, id, source) {
|
|
|
223
230
|
devHooks.staleIndex?.(id);
|
|
224
231
|
}
|
|
225
232
|
} else {
|
|
226
|
-
const captured =
|
|
227
|
-
const out = render(item, i);
|
|
228
|
-
return isSafeHtml(out) ? out.toString() : out;
|
|
229
|
-
}));
|
|
233
|
+
const captured = renderRow(render, item, i);
|
|
230
234
|
html = captured.html;
|
|
231
235
|
bindings = captured.bindings;
|
|
232
|
-
if (cache !== null)
|
|
236
|
+
if (cache !== null)
|
|
237
|
+
cache.set(item, { cacheKey: k, html, bindings, version, index: i });
|
|
233
238
|
}
|
|
234
239
|
segItems[i] = { ref: item, cacheKey: k, html, bindings };
|
|
235
240
|
}
|
|
236
241
|
if (cacheKey !== void 0) {
|
|
237
242
|
devHooks.duplicateCacheKeys?.(id, segItems);
|
|
238
243
|
}
|
|
239
|
-
return
|
|
244
|
+
return _listSafeHtml(id, segItems, source);
|
|
240
245
|
}
|
|
241
246
|
|
|
242
247
|
// src/list-reconcile-focus.ts
|
|
@@ -281,16 +286,18 @@ function restoreFocus(snap) {
|
|
|
281
286
|
if (domSelection === null) return;
|
|
282
287
|
const [anchorNode, anchorOffset, focusNode, focusOffset] = domSelection;
|
|
283
288
|
try {
|
|
284
|
-
document.getSelection()?.setBaseAndExtent(
|
|
285
|
-
anchorNode,
|
|
286
|
-
anchorOffset,
|
|
287
|
-
focusNode,
|
|
288
|
-
focusOffset
|
|
289
|
-
);
|
|
289
|
+
document.getSelection()?.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
290
290
|
} catch {
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
// src/utils/morph-protection.ts
|
|
295
|
+
var MORPH_PRESERVE_ATTR = "data-morph-preserve";
|
|
296
|
+
function protectionOf(el) {
|
|
297
|
+
const d = el.dataset;
|
|
298
|
+
return (d.morphSkip !== void 0 ? 1 : 0) | (d.morphSkipChildren !== void 0 ? 2 : 0) | (d.morphPreserve !== void 0 ? 4 : 0);
|
|
299
|
+
}
|
|
300
|
+
|
|
294
301
|
// src/utils/moveNode.ts
|
|
295
302
|
function moveNode(parent, node, ref) {
|
|
296
303
|
const move = parent.moveBefore;
|
|
@@ -328,9 +335,6 @@ function morph(liveRoot, template, ownedItems = EMPTY_OWNED) {
|
|
|
328
335
|
morphChildren(liveRoot, templateEl, ownedItems);
|
|
329
336
|
if (focusSnap !== null) restoreFocus(focusSnap);
|
|
330
337
|
}
|
|
331
|
-
function _morphElement(fromEl, toEl, ownedItems = EMPTY_OWNED) {
|
|
332
|
-
morphElement(fromEl, toEl, ownedItems);
|
|
333
|
-
}
|
|
334
338
|
function isElementNode(t) {
|
|
335
339
|
return typeof t === "object" && t !== null && t.nodeType === ELEMENT_NODE;
|
|
336
340
|
}
|
|
@@ -339,11 +343,11 @@ function parseTemplate(liveRoot, template) {
|
|
|
339
343
|
el.innerHTML = String(template);
|
|
340
344
|
return el;
|
|
341
345
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
346
|
+
var MARKER_PREFIXES = [
|
|
347
|
+
LIST_MARKER_PREFIX,
|
|
348
|
+
TEXT_MARKER_PREFIX,
|
|
349
|
+
ROW_TEXT_PREFIX
|
|
350
|
+
];
|
|
347
351
|
function isMarker(node) {
|
|
348
352
|
if (node.nodeType !== COMMENT_NODE) return false;
|
|
349
353
|
const { data } = node;
|
|
@@ -392,7 +396,7 @@ function morphChildren(fromParent, toParent, ownedItems) {
|
|
|
392
396
|
fromChild = skipOwned(fromChild.nextSibling, ownedItems);
|
|
393
397
|
}
|
|
394
398
|
}
|
|
395
|
-
if (matched === null && fromChild !== null && fromChild.nodeType === toChild.nodeType && markersPairable(fromChild, toChild) && (toChild.nodeType !== ELEMENT_NODE || fromChild.tagName === toChild.tagName && getNodeKey(fromChild) === void 0 && toKey === void 0 &&
|
|
399
|
+
if (matched === null && fromChild !== null && fromChild.nodeType === toChild.nodeType && markersPairable(fromChild, toChild) && (toChild.nodeType !== ELEMENT_NODE || fromChild.tagName === toChild.tagName && getNodeKey(fromChild) === void 0 && toKey === void 0 && protectionOf(fromChild) === protectionOf(toChild))) {
|
|
396
400
|
matched = fromChild;
|
|
397
401
|
fromChild = skipOwned(
|
|
398
402
|
isListMarker(matched) ? afterListRegion(matched, ownedItems) : fromChild.nextSibling,
|
|
@@ -412,16 +416,17 @@ function morphChildren(fromParent, toParent, ownedItems) {
|
|
|
412
416
|
const el = scan;
|
|
413
417
|
if (ownedItems.has(el)) continue;
|
|
414
418
|
if (el.tagName !== toTag || getNodeKey(el) !== void 0) continue;
|
|
415
|
-
if (
|
|
419
|
+
if (protectionOf(el) !== protectionOf(toChild)) continue;
|
|
416
420
|
matched = el;
|
|
417
421
|
moveNode(fromParent, el, fromChild);
|
|
418
422
|
break;
|
|
419
423
|
}
|
|
420
424
|
}
|
|
421
|
-
if (matched === null && fromChild !== null && toChild
|
|
425
|
+
if (matched === null && fromChild !== null && isListMarker(toChild)) {
|
|
422
426
|
const wantData = toChild.data;
|
|
423
427
|
for (let scan = fromChild.nextSibling; scan !== null; scan = scan.nextSibling) {
|
|
424
|
-
if (scan.nodeType !== COMMENT_NODE || scan.data !== wantData)
|
|
428
|
+
if (scan.nodeType !== COMMENT_NODE || scan.data !== wantData)
|
|
429
|
+
continue;
|
|
425
430
|
const regionEnd = afterListRegion(scan, ownedItems);
|
|
426
431
|
const run = [];
|
|
427
432
|
for (let r = scan; r !== null && r !== regionEnd; r = r.nextSibling) {
|
|
@@ -438,6 +443,9 @@ function morphChildren(fromParent, toParent, ownedItems) {
|
|
|
438
443
|
morphNode(matched, toChild, ownedItems);
|
|
439
444
|
} else {
|
|
440
445
|
const cloned = toChild.cloneNode(true);
|
|
446
|
+
if (toChild.nodeType === ELEMENT_NODE) {
|
|
447
|
+
seedRenderedAttrs(toChild, cloned);
|
|
448
|
+
}
|
|
441
449
|
fromParent.insertBefore(cloned, fromChild);
|
|
442
450
|
}
|
|
443
451
|
toChild = toNext;
|
|
@@ -466,9 +474,10 @@ function morphNode(fromNode, toNode, ownedItems) {
|
|
|
466
474
|
if (fromText.data !== toText.data) fromText.data = toText.data;
|
|
467
475
|
}
|
|
468
476
|
}
|
|
469
|
-
function morphElement(fromEl, toEl, ownedItems) {
|
|
477
|
+
function morphElement(fromEl, toEl, ownedItems = EMPTY_OWNED) {
|
|
470
478
|
if (fromEl.tagName !== toEl.tagName) {
|
|
471
479
|
const replacement = toEl.cloneNode(true);
|
|
480
|
+
seedRenderedAttrs(toEl, replacement);
|
|
472
481
|
fromEl.parentNode?.replaceChild(replacement, fromEl);
|
|
473
482
|
return;
|
|
474
483
|
}
|
|
@@ -477,7 +486,7 @@ function morphElement(fromEl, toEl, ownedItems) {
|
|
|
477
486
|
if (fromEl === document.activeElement) {
|
|
478
487
|
const ce = fromEl.getAttribute("contenteditable");
|
|
479
488
|
if (ce !== null && ce.toLowerCase() !== "false") return;
|
|
480
|
-
|
|
489
|
+
preserveTextEntryState(fromEl, toEl);
|
|
481
490
|
}
|
|
482
491
|
morphAttributes(fromEl, toEl);
|
|
483
492
|
if (fromEl.dataset.morphSkipChildren !== void 0) return;
|
|
@@ -487,10 +496,10 @@ function morphElement(fromEl, toEl, ownedItems) {
|
|
|
487
496
|
fromEl.value = toEl.textContent;
|
|
488
497
|
}
|
|
489
498
|
}
|
|
490
|
-
function isUserAgentOwnedAttr(tagName, name) {
|
|
491
|
-
return name === "open" && (tagName === "DETAILS" || tagName === "DIALOG");
|
|
492
|
-
}
|
|
493
499
|
function morphAttributes(fromEl, toEl) {
|
|
500
|
+
const fromTag = fromEl.tagName;
|
|
501
|
+
const host = fromEl;
|
|
502
|
+
const rendered = host[RENDERED_ATTRS];
|
|
494
503
|
const toAttrs = toEl.attributes;
|
|
495
504
|
for (let i = 0; i < toAttrs.length; i++) {
|
|
496
505
|
const attr = toAttrs[i];
|
|
@@ -502,39 +511,36 @@ function morphAttributes(fromEl, toEl) {
|
|
|
502
511
|
fromEl.setAttributeNS(ns, attr.name, value);
|
|
503
512
|
}
|
|
504
513
|
} else if (fromEl.getAttribute(name) !== value) {
|
|
505
|
-
fromEl.setAttribute(name, value);
|
|
506
514
|
syncFormProp(fromEl, name, value, true);
|
|
515
|
+
fromEl.setAttribute(name, value);
|
|
507
516
|
}
|
|
508
517
|
}
|
|
509
518
|
const fromAttrs = fromEl.attributes;
|
|
510
|
-
const fromTag = fromEl.tagName;
|
|
511
519
|
for (let i = fromAttrs.length - 1; i >= 0; i--) {
|
|
512
520
|
const attr = fromAttrs[i];
|
|
513
521
|
const ns = attr.namespaceURI;
|
|
514
522
|
const name = attr.localName;
|
|
515
523
|
if (ns !== null) {
|
|
516
524
|
if (!toEl.hasAttributeNS(ns, name)) fromEl.removeAttributeNS(ns, name);
|
|
517
|
-
} else if (!toEl.hasAttribute(name) && !isUserAgentOwnedAttr(fromTag, name)) {
|
|
518
|
-
fromEl.removeAttribute(name);
|
|
525
|
+
} else if (!toEl.hasAttribute(name) && !isUserAgentOwnedAttr(fromTag, name) && (!rendered || rendered.includes(name))) {
|
|
519
526
|
syncFormProp(fromEl, name, "", false);
|
|
527
|
+
fromEl.removeAttribute(name);
|
|
520
528
|
}
|
|
521
529
|
}
|
|
522
|
-
|
|
523
|
-
function isTextInputOrTextarea(el) {
|
|
524
|
-
if (el.tagName === "TEXTAREA") return true;
|
|
525
|
-
if (el.tagName === "INPUT") {
|
|
526
|
-
const type = el.type;
|
|
527
|
-
return type === "text" || type === "search" || type === "url" || type === "email" || type === "tel" || type === "password" || type === "";
|
|
528
|
-
}
|
|
529
|
-
return false;
|
|
530
|
+
if (fromTag.includes("-")) host[RENDERED_ATTRS] = toEl.getAttributeNames();
|
|
530
531
|
}
|
|
531
532
|
function preserveTextEntryState(fromEl, toEl) {
|
|
532
|
-
if (fromEl.tagName === "TEXTAREA" || fromEl.tagName === "INPUT")
|
|
533
|
+
if (fromEl.tagName === "TEXTAREA" || fromEl.tagName === "INPUT" && /^(text|search|url|email|tel|password|)$/.test(
|
|
534
|
+
fromEl.type
|
|
535
|
+
)) {
|
|
533
536
|
const fromInput = fromEl;
|
|
534
537
|
const toInput = toEl;
|
|
535
538
|
toInput.value = fromInput.value;
|
|
536
539
|
try {
|
|
537
|
-
toInput.setSelectionRange(
|
|
540
|
+
toInput.setSelectionRange(
|
|
541
|
+
fromInput.selectionStart,
|
|
542
|
+
fromInput.selectionEnd
|
|
543
|
+
);
|
|
538
544
|
} catch {
|
|
539
545
|
}
|
|
540
546
|
}
|
|
@@ -567,7 +573,8 @@ function tryAttributeOnlyFastPath(liveNode, oldHtml, newHtml) {
|
|
|
567
573
|
if (oldGt === -1 || newGt === -1) return false;
|
|
568
574
|
if (oldHtml.length - oldGt !== newHtml.length - newGt) return false;
|
|
569
575
|
if (oldHtml.slice(oldGt) !== newHtml.slice(newGt)) return false;
|
|
570
|
-
if (containsDataMorphSkip(oldHtml) || containsDataMorphSkip(newHtml))
|
|
576
|
+
if (containsDataMorphSkip(oldHtml) || containsDataMorphSkip(newHtml))
|
|
577
|
+
return false;
|
|
571
578
|
const oldTag = parseOpeningTag(oldHtml, oldGt);
|
|
572
579
|
const newTag = parseOpeningTag(newHtml, newGt);
|
|
573
580
|
if (oldTag === null || newTag === null) return false;
|
|
@@ -583,19 +590,23 @@ function tryAttributeOnlyFastPath(liveNode, oldHtml, newHtml) {
|
|
|
583
590
|
const oldValue = oldTag.attrs.get(name);
|
|
584
591
|
if (oldValue === rawValue) continue;
|
|
585
592
|
const value = unescapeAttrValue(rawValue);
|
|
586
|
-
liveNode.setAttribute(name, value);
|
|
587
593
|
syncFormProp(liveNode, name, value, true);
|
|
594
|
+
liveNode.setAttribute(name, value);
|
|
588
595
|
}
|
|
589
596
|
for (const name of oldTag.attrs.keys()) {
|
|
590
597
|
if (newTag.attrs.has(name)) continue;
|
|
591
|
-
if (
|
|
592
|
-
liveNode.removeAttribute(name);
|
|
598
|
+
if (isUserAgentOwnedAttr(liveTagUpper, name)) continue;
|
|
593
599
|
syncFormProp(liveNode, name, "", false);
|
|
600
|
+
liveNode.removeAttribute(name);
|
|
594
601
|
}
|
|
602
|
+
delete liveNode[RENDERED_ATTRS];
|
|
595
603
|
return true;
|
|
596
604
|
}
|
|
597
605
|
function tryTextContentFastPath(liveNode, oldHtml, newHtml) {
|
|
598
|
-
if (containsDataMorphSkip(oldHtml) || containsDataMorphSkip(newHtml))
|
|
606
|
+
if (containsDataMorphSkip(oldHtml) || containsDataMorphSkip(newHtml))
|
|
607
|
+
return false;
|
|
608
|
+
if (oldHtml.indexOf(MORPH_PRESERVE_ATTR) !== -1 || newHtml.indexOf(MORPH_PRESERVE_ATTR) !== -1)
|
|
609
|
+
return false;
|
|
599
610
|
let p = 0;
|
|
600
611
|
const minLen = Math.min(oldHtml.length, newHtml.length);
|
|
601
612
|
while (p < minLen && oldHtml.charCodeAt(p) === newHtml.charCodeAt(p)) p++;
|
|
@@ -610,7 +621,8 @@ function tryTextContentFastPath(liveNode, oldHtml, newHtml) {
|
|
|
610
621
|
if (!isPureTextWindow(newHtml, p, newWinEnd)) return false;
|
|
611
622
|
if (p === 0) return false;
|
|
612
623
|
const boundaryCc = oldHtml.charCodeAt(p - 1);
|
|
613
|
-
if (boundaryCc === LT || boundaryCc === DQUOTE || boundaryCc === SQUOTE || boundaryCc === EQ || boundaryCc === AMP)
|
|
624
|
+
if (boundaryCc === LT || boundaryCc === DQUOTE || boundaryCc === SQUOTE || boundaryCc === EQ || boundaryCc === AMP)
|
|
625
|
+
return false;
|
|
614
626
|
const textStart = lastIndexOfChar(oldHtml, GT, p - 1);
|
|
615
627
|
if (textStart === -1) return false;
|
|
616
628
|
const textEnd = oldHtml.indexOf("<", p);
|
|
@@ -637,7 +649,8 @@ function containsDataMorphSkip(html) {
|
|
|
637
649
|
function isPureTextWindow(html, start, end) {
|
|
638
650
|
for (let i = start; i < end; i++) {
|
|
639
651
|
const cc = html.charCodeAt(i);
|
|
640
|
-
if (cc === LT || cc === GT || cc === DQUOTE || cc === SQUOTE || cc === AMP || cc === EQ)
|
|
652
|
+
if (cc === LT || cc === GT || cc === DQUOTE || cc === SQUOTE || cc === AMP || cc === EQ)
|
|
653
|
+
return false;
|
|
641
654
|
}
|
|
642
655
|
return true;
|
|
643
656
|
}
|
|
@@ -674,8 +687,9 @@ function nthTextNodeDescendant(root, n) {
|
|
|
674
687
|
return;
|
|
675
688
|
}
|
|
676
689
|
count++;
|
|
677
|
-
} else
|
|
678
|
-
|
|
690
|
+
} else {
|
|
691
|
+
if (c.nodeType !== ELEMENT_NODE2) continue;
|
|
692
|
+
if (!c.hasAttribute(MORPH_PRESERVE_ATTR)) walk(c);
|
|
679
693
|
}
|
|
680
694
|
}
|
|
681
695
|
}
|
|
@@ -730,9 +744,6 @@ function unescapeAttrValue(s) {
|
|
|
730
744
|
if (s.indexOf("&") === -1) return s;
|
|
731
745
|
return s.replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
732
746
|
}
|
|
733
|
-
function isUserAgentOwnedAttr2(tagNameUpper, name) {
|
|
734
|
-
return name === "open" && (tagNameUpper === "DETAILS" || tagNameUpper === "DIALOG");
|
|
735
|
-
}
|
|
736
747
|
|
|
737
748
|
// src/list-reconcile-granular.ts
|
|
738
749
|
function reconcileGranular(binding, patches) {
|
|
@@ -769,7 +780,14 @@ function reconcileGranular(binding, patches) {
|
|
|
769
780
|
if (runLen === 1) {
|
|
770
781
|
applySingleInsert(liveParent, items, patch, endAnchor(binding));
|
|
771
782
|
} else {
|
|
772
|
-
applyBulkInsert(
|
|
783
|
+
applyBulkInsert(
|
|
784
|
+
liveParent,
|
|
785
|
+
items,
|
|
786
|
+
patches,
|
|
787
|
+
i,
|
|
788
|
+
runEnd,
|
|
789
|
+
endAnchor(binding)
|
|
790
|
+
);
|
|
773
791
|
}
|
|
774
792
|
i = runEnd;
|
|
775
793
|
continue;
|
|
@@ -834,7 +852,7 @@ function applySingleUpdate(liveParent, items, patch) {
|
|
|
834
852
|
function applyParsedRowUpdate(liveParent, items, patch, html, newNode) {
|
|
835
853
|
const oldEntry = items[patch.index];
|
|
836
854
|
if (oldEntry.node.tagName === newNode.tagName) {
|
|
837
|
-
|
|
855
|
+
morphElement(oldEntry.node, newNode);
|
|
838
856
|
items[patch.index] = reuseBound(patch, html, oldEntry);
|
|
839
857
|
} else {
|
|
840
858
|
disposeRowBindings(oldEntry.bindingDisposers);
|
|
@@ -881,11 +899,11 @@ function applyBulkUpdate(liveParent, items, patches, start, end) {
|
|
|
881
899
|
morphChanges.push({ patchIdx: k, html: p.html });
|
|
882
900
|
}
|
|
883
901
|
if (morphChanges.length === 0) return;
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
902
|
+
const newNodes = parseRows(
|
|
903
|
+
morphChanges.map((c) => c.html),
|
|
904
|
+
liveParent,
|
|
905
|
+
(k) => patches[morphChanges[k].patchIdx].index
|
|
906
|
+
);
|
|
889
907
|
for (let k = 0; k < morphChanges.length; k++) {
|
|
890
908
|
const c = morphChanges[k];
|
|
891
909
|
const p = patches[c.patchIdx];
|
|
@@ -898,13 +916,13 @@ function applyBulkInsert(liveParent, items, patches, start, end, tailAnchor) {
|
|
|
898
916
|
for (let k = start; k < end; k++) {
|
|
899
917
|
htmls[k - start] = patches[k].html;
|
|
900
918
|
}
|
|
901
|
-
const
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
919
|
+
const newNodes = parseRows(
|
|
920
|
+
htmls,
|
|
921
|
+
liveParent,
|
|
922
|
+
(k) => patches[start + k].index
|
|
923
|
+
);
|
|
906
924
|
const anchor = startIdx < items.length ? items[startIdx].node : tailAnchor;
|
|
907
|
-
liveParent.insertBefore(
|
|
925
|
+
liveParent.insertBefore(newNodes[0].parentNode, anchor);
|
|
908
926
|
const newEntries = new Array(end - start);
|
|
909
927
|
for (let k = 0; k < newEntries.length; k++) {
|
|
910
928
|
const p = patches[start + k];
|
|
@@ -921,22 +939,6 @@ function applyBulkInsert(liveParent, items, patches, start, end, tailAnchor) {
|
|
|
921
939
|
}
|
|
922
940
|
items.splice(startIdx, 0, ...newEntries);
|
|
923
941
|
}
|
|
924
|
-
function findOffendingInsert(patches, start, htmls, liveParent) {
|
|
925
|
-
for (let i = 0; i < htmls.length; i++) {
|
|
926
|
-
if (parseRowTemplate(htmls[i], liveParent).count !== 1) {
|
|
927
|
-
return rowContractError(patches[start + i].index, htmls[i], liveParent);
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
return new Error("each(): bulk-insert mismatch with no per-row offender (kerf bug).");
|
|
931
|
-
}
|
|
932
|
-
function findOffendingChange(patches, changes, liveParent) {
|
|
933
|
-
for (const c of changes) {
|
|
934
|
-
if (parseRowTemplate(c.html, liveParent).count !== 1) {
|
|
935
|
-
return rowContractError(patches[c.patchIdx].index, c.html, liveParent);
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
return new Error("each(): bulk-update mismatch with no per-row offender (kerf bug).");
|
|
939
|
-
}
|
|
940
942
|
|
|
941
943
|
// src/list-reconcile-inplace.ts
|
|
942
944
|
function tryInPlaceContentUpdate(binding, listSeg) {
|
|
@@ -958,9 +960,14 @@ function tryInPlaceContentUpdate(binding, listSeg) {
|
|
|
958
960
|
devHooks.missingRowKey?.(newRecord[0].node, newRecord[0].html, binding);
|
|
959
961
|
return true;
|
|
960
962
|
}
|
|
961
|
-
function updateRowInPlace(liveParent, old, ni, index) {
|
|
963
|
+
function updateRowInPlace(liveParent, old, ni, index, parsedNode) {
|
|
962
964
|
if (old.html === ni.html || tryAttributeOnlyFastPath(old.node, old.html, ni.html) || tryTextContentFastPath(old.node, old.html, ni.html)) {
|
|
963
|
-
const kept = carryOrRewireRowBindings(
|
|
965
|
+
const kept = carryOrRewireRowBindings(
|
|
966
|
+
old.node,
|
|
967
|
+
old.bindings,
|
|
968
|
+
old.bindingDisposers,
|
|
969
|
+
ni.bindings
|
|
970
|
+
);
|
|
964
971
|
return {
|
|
965
972
|
ref: ni.ref,
|
|
966
973
|
cacheKey: ni.cacheKey,
|
|
@@ -970,10 +977,15 @@ function updateRowInPlace(liveParent, old, ni, index) {
|
|
|
970
977
|
bindingDisposers: kept.bindingDisposers
|
|
971
978
|
};
|
|
972
979
|
}
|
|
973
|
-
const newNode = parseSingleRow(ni.html, index, liveParent);
|
|
980
|
+
const newNode = parsedNode ?? parseSingleRow(ni.html, index, liveParent);
|
|
974
981
|
if (old.node.tagName === newNode.tagName) {
|
|
975
|
-
|
|
976
|
-
const kept = carryOrRewireRowBindings(
|
|
982
|
+
morphElement(old.node, newNode);
|
|
983
|
+
const kept = carryOrRewireRowBindings(
|
|
984
|
+
old.node,
|
|
985
|
+
old.bindings,
|
|
986
|
+
old.bindingDisposers,
|
|
987
|
+
ni.bindings
|
|
988
|
+
);
|
|
977
989
|
return {
|
|
978
990
|
ref: ni.ref,
|
|
979
991
|
cacheKey: ni.cacheKey,
|
|
@@ -985,7 +997,12 @@ function updateRowInPlace(liveParent, old, ni, index) {
|
|
|
985
997
|
}
|
|
986
998
|
disposeRowBindings(old.bindingDisposers);
|
|
987
999
|
liveParent.replaceChild(newNode, old.node);
|
|
988
|
-
const fresh = carryOrRewireRowBindings(
|
|
1000
|
+
const fresh = carryOrRewireRowBindings(
|
|
1001
|
+
newNode,
|
|
1002
|
+
void 0,
|
|
1003
|
+
void 0,
|
|
1004
|
+
ni.bindings
|
|
1005
|
+
);
|
|
989
1006
|
return {
|
|
990
1007
|
ref: ni.ref,
|
|
991
1008
|
cacheKey: ni.cacheKey,
|
|
@@ -1004,6 +1021,15 @@ function reconcileSnapshot(binding, listSeg) {
|
|
|
1004
1021
|
const tailAnchor = endAnchor(binding);
|
|
1005
1022
|
buildFreshNodes(newRecord, freshIndices, freshHtmls, liveParent);
|
|
1006
1023
|
const focusSnap = captureFocus(liveParent);
|
|
1024
|
+
reuseKeyedRows(
|
|
1025
|
+
binding.items,
|
|
1026
|
+
listSeg,
|
|
1027
|
+
newRecord,
|
|
1028
|
+
prevIdx,
|
|
1029
|
+
removedItems,
|
|
1030
|
+
freshIndices,
|
|
1031
|
+
liveParent
|
|
1032
|
+
);
|
|
1007
1033
|
removeOldNodes(liveParent, removedItems);
|
|
1008
1034
|
applyMoves(liveParent, newRecord, prevIdx, lis(prevIdx), tailAnchor);
|
|
1009
1035
|
if (focusSnap !== null) restoreFocus(focusSnap);
|
|
@@ -1012,6 +1038,47 @@ function reconcileSnapshot(binding, listSeg) {
|
|
|
1012
1038
|
devHooks.missingRowKey?.(newRecord[0].node, newRecord[0].html, binding);
|
|
1013
1039
|
}
|
|
1014
1040
|
}
|
|
1041
|
+
function reuseKeyedRows(oldItems, listSeg, newRecord, prevIdx, removedItems, freshIndices, liveParent) {
|
|
1042
|
+
if (freshIndices.length === 0 || removedItems.length === 0) return;
|
|
1043
|
+
const oldByKey = /* @__PURE__ */ new Map();
|
|
1044
|
+
for (let index = 0; index < oldItems.length; index++) {
|
|
1045
|
+
const key = getNodeKey(oldItems[index].node);
|
|
1046
|
+
if (key === void 0) continue;
|
|
1047
|
+
oldByKey.set(
|
|
1048
|
+
key,
|
|
1049
|
+
oldByKey.has(key) ? null : { item: oldItems[index], index }
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
const newKeyCounts = /* @__PURE__ */ new Map();
|
|
1053
|
+
for (const item of newRecord) {
|
|
1054
|
+
const key = getNodeKey(item.node);
|
|
1055
|
+
if (key !== void 0)
|
|
1056
|
+
newKeyCounts.set(key, (newKeyCounts.get(key) ?? 0) + 1);
|
|
1057
|
+
}
|
|
1058
|
+
const removedSet = new Set(removedItems);
|
|
1059
|
+
const reused = /* @__PURE__ */ new Set();
|
|
1060
|
+
for (const index of freshIndices) {
|
|
1061
|
+
const fresh = newRecord[index];
|
|
1062
|
+
const key = getNodeKey(fresh.node);
|
|
1063
|
+
if (key === void 0 || newKeyCounts.get(key) !== 1) continue;
|
|
1064
|
+
const prior = oldByKey.get(key);
|
|
1065
|
+
if (prior === void 0 || prior === null || !removedSet.has(prior.item) || prior.item.node.tagName !== fresh.node.tagName)
|
|
1066
|
+
continue;
|
|
1067
|
+
disposeRowBindings(fresh.bindingDisposers);
|
|
1068
|
+
newRecord[index] = updateRowInPlace(
|
|
1069
|
+
liveParent,
|
|
1070
|
+
prior.item,
|
|
1071
|
+
listSeg.items[index],
|
|
1072
|
+
index,
|
|
1073
|
+
fresh.node
|
|
1074
|
+
);
|
|
1075
|
+
prevIdx[index] = prior.index;
|
|
1076
|
+
reused.add(prior.item);
|
|
1077
|
+
}
|
|
1078
|
+
for (let i = removedItems.length - 1; i >= 0; i--) {
|
|
1079
|
+
if (reused.has(removedItems[i])) removedItems.splice(i, 1);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1015
1082
|
function classifyItems(oldItems, listSeg) {
|
|
1016
1083
|
const oldByRef = /* @__PURE__ */ new Map();
|
|
1017
1084
|
for (let i = 0; i < oldItems.length; i++) {
|
|
@@ -1052,33 +1119,20 @@ function classifyItems(oldItems, listSeg) {
|
|
|
1052
1119
|
}
|
|
1053
1120
|
function buildFreshNodes(newRecord, freshIndices, freshHtmls, liveParent) {
|
|
1054
1121
|
if (freshHtmls.length === 0) return;
|
|
1055
|
-
const
|
|
1056
|
-
|
|
1057
|
-
throw findOffendingRow(newRecord, freshIndices, freshHtmls, liveParent);
|
|
1058
|
-
}
|
|
1059
|
-
let node = content.firstElementChild;
|
|
1060
|
-
for (const idx of freshIndices) {
|
|
1061
|
-
const next = node.nextElementSibling;
|
|
1122
|
+
const rows = parseRows(freshHtmls, liveParent, (i) => freshIndices[i]);
|
|
1123
|
+
freshIndices.forEach((idx, k) => {
|
|
1062
1124
|
const item = newRecord[idx];
|
|
1063
|
-
item.node =
|
|
1125
|
+
item.node = rows[k];
|
|
1064
1126
|
if (item.bindings !== void 0 && item.bindings.length > 0) {
|
|
1065
1127
|
item.bindingDisposers = wireRowBindings(item.node, item.bindings);
|
|
1066
1128
|
}
|
|
1067
|
-
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
function findOffendingRow(newRecord, freshIndices, freshHtmls, liveParent) {
|
|
1071
|
-
for (let i = 0; i < freshHtmls.length; i++) {
|
|
1072
|
-
if (parseRowTemplate(freshHtmls[i], liveParent).count !== 1) {
|
|
1073
|
-
return rowContractError(freshIndices[i], newRecord[freshIndices[i]].html, liveParent);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
return new Error("each(): bulk-parse mismatch with no per-row offender (kerf bug).");
|
|
1129
|
+
});
|
|
1077
1130
|
}
|
|
1078
1131
|
function removeOldNodes(liveParent, removedItems) {
|
|
1079
1132
|
for (const item of removedItems) {
|
|
1080
1133
|
disposeRowBindings(item.bindingDisposers);
|
|
1081
|
-
if (item.node.parentElement === liveParent)
|
|
1134
|
+
if (item.node.parentElement === liveParent)
|
|
1135
|
+
liveParent.removeChild(item.node);
|
|
1082
1136
|
}
|
|
1083
1137
|
}
|
|
1084
1138
|
function applyMoves(liveParent, newRecord, prevIdx, stable, tailAnchor) {
|
|
@@ -1130,6 +1184,360 @@ function reconcileList(binding, listSeg) {
|
|
|
1130
1184
|
reconcileSnapshot(binding, listSeg);
|
|
1131
1185
|
}
|
|
1132
1186
|
|
|
1187
|
+
// src/mount-list-bindings.ts
|
|
1188
|
+
function anyRebuiltListIsGranular(segment, rebuilt) {
|
|
1189
|
+
if (!rebuilt.size) return false;
|
|
1190
|
+
const lists = collectLists(segment);
|
|
1191
|
+
for (const id of rebuilt) {
|
|
1192
|
+
if (lists.get(id)?.patches) return true;
|
|
1193
|
+
}
|
|
1194
|
+
return false;
|
|
1195
|
+
}
|
|
1196
|
+
function bindListsFromMarkers(rootEl, segment, bindings, inlinedItems, rebuiltLists, ownedItems) {
|
|
1197
|
+
const lists = collectLists(segment);
|
|
1198
|
+
if (lists.size === 0 && bindings.size === 0) return;
|
|
1199
|
+
const found = [];
|
|
1200
|
+
collectComments(rootEl, found, ownedItems);
|
|
1201
|
+
for (const marker of found) {
|
|
1202
|
+
if (!marker.data.startsWith(LIST_MARKER_PREFIX)) continue;
|
|
1203
|
+
const id = marker.data.slice(LIST_MARKER_PREFIX.length);
|
|
1204
|
+
const existing = bindings.get(id);
|
|
1205
|
+
if (existing) {
|
|
1206
|
+
if (existing.marker === marker && rootEl.contains(existing.marker))
|
|
1207
|
+
continue;
|
|
1208
|
+
for (const item of existing.items) {
|
|
1209
|
+
disposeRowBindings(item.bindingDisposers);
|
|
1210
|
+
if (rootEl.contains(item.node)) {
|
|
1211
|
+
item.node.parentElement?.removeChild(item.node);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
bindings.delete(id);
|
|
1215
|
+
rebuiltLists?.add(id);
|
|
1216
|
+
devHooks.listRebind?.(id, marker.parentElement);
|
|
1217
|
+
}
|
|
1218
|
+
const listSeg = lists.get(id);
|
|
1219
|
+
const liveParent = marker.parentElement;
|
|
1220
|
+
const items = [];
|
|
1221
|
+
if (inlinedItems) {
|
|
1222
|
+
let next = marker.nextElementSibling;
|
|
1223
|
+
for (let i = 0; i < listSeg.items.length && next !== null; i++) {
|
|
1224
|
+
validateInlinedRowMatch(listSeg.items[i].html, i, next, liveParent);
|
|
1225
|
+
items.push({
|
|
1226
|
+
ref: listSeg.items[i].ref,
|
|
1227
|
+
cacheKey: listSeg.items[i].cacheKey,
|
|
1228
|
+
html: listSeg.items[i].html,
|
|
1229
|
+
node: next,
|
|
1230
|
+
bindings: listSeg.items[i].bindings
|
|
1231
|
+
});
|
|
1232
|
+
next = next.nextElementSibling;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const binding = { liveParent, items, marker };
|
|
1236
|
+
if (items.length > 0) {
|
|
1237
|
+
devHooks.missingRowKey?.(items[0].node, items[0].html, binding);
|
|
1238
|
+
}
|
|
1239
|
+
devHooks.eachInMorphSkip?.(id, liveParent, rootEl);
|
|
1240
|
+
bindings.set(id, binding);
|
|
1241
|
+
for (const bound of items) {
|
|
1242
|
+
if (bound.bindings?.length) {
|
|
1243
|
+
bound.bindingDisposers = wireRowBindings(bound.node, bound.bindings);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
function validateInlinedRowMatch(expectedHtml, index, boundEl, liveParent) {
|
|
1249
|
+
if (boundEl.outerHTML === expectedHtml) return;
|
|
1250
|
+
const expected = parseSingleRow(expectedHtml, index, liveParent);
|
|
1251
|
+
const expectedTag = expected.tagName;
|
|
1252
|
+
if (boundEl.tagName !== expectedTag)
|
|
1253
|
+
throw rowStructureError(index, boundEl.tagName, expectedTag);
|
|
1254
|
+
}
|
|
1255
|
+
function rowStructureError(index, gotTag, wantTag) {
|
|
1256
|
+
const got = gotTag.toLowerCase();
|
|
1257
|
+
const want = wantTag.toLowerCase();
|
|
1258
|
+
return new Error(
|
|
1259
|
+
`each(): row ${index} renders <${want}>, but the HTML parser wrapped the rows in <${got}> \u2014 so kerf cannot bind one row per element. This happens when an each() of <${want}> sits directly inside a table: the parser inserts <${got}> around the whole run. Put the each() inside an explicit <${got}> (e.g. <table><${got}>{each(...)}</${got}></table>) so the rows are the direct children kerf binds.`
|
|
1260
|
+
);
|
|
1261
|
+
}
|
|
1262
|
+
function collectOwnedItems(bindings) {
|
|
1263
|
+
const owned = /* @__PURE__ */ new Set();
|
|
1264
|
+
for (const b of bindings.values()) {
|
|
1265
|
+
for (const item of b.items) owned.add(item.node);
|
|
1266
|
+
}
|
|
1267
|
+
return owned;
|
|
1268
|
+
}
|
|
1269
|
+
function cleanupOrphanBindings(segment, bindings, renderCtx) {
|
|
1270
|
+
const liveIds = collectLists(segment);
|
|
1271
|
+
for (const [id, binding] of bindings) {
|
|
1272
|
+
if (liveIds.has(id)) continue;
|
|
1273
|
+
for (const item of binding.items) {
|
|
1274
|
+
disposeRowBindings(item.bindingDisposers);
|
|
1275
|
+
item.node.remove();
|
|
1276
|
+
}
|
|
1277
|
+
binding.marker.remove();
|
|
1278
|
+
bindings.delete(id);
|
|
1279
|
+
renderCtx.bindingCounts.delete(id);
|
|
1280
|
+
renderCtx.bindingSources.delete(id);
|
|
1281
|
+
renderCtx.caches.delete(id);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
function collectComments(node, out, skip) {
|
|
1285
|
+
for (let c = node.firstChild; c; c = c.nextSibling) {
|
|
1286
|
+
if (c.nodeType === Node.COMMENT_NODE) out.push(c);
|
|
1287
|
+
else if (c.nodeType === Node.ELEMENT_NODE && !isOverlayHost(c) && !skip?.has(c))
|
|
1288
|
+
collectComments(c, out, skip);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// src/static-subtree-morph.ts
|
|
1293
|
+
var START = 0;
|
|
1294
|
+
var OPEN_END = 1;
|
|
1295
|
+
var CLOSE = 2;
|
|
1296
|
+
var END = 3;
|
|
1297
|
+
var PARENT = 4;
|
|
1298
|
+
var INDEX = 5;
|
|
1299
|
+
var COUNT = 6;
|
|
1300
|
+
var FIRST = 7;
|
|
1301
|
+
var NEXT = 8;
|
|
1302
|
+
var FLAG = 9;
|
|
1303
|
+
var LAST = 10;
|
|
1304
|
+
var W = 11;
|
|
1305
|
+
var VOID = 1;
|
|
1306
|
+
var RAW = 2;
|
|
1307
|
+
var REFUSE = 4;
|
|
1308
|
+
var BOX = 8;
|
|
1309
|
+
var SENSITIVE = 16;
|
|
1310
|
+
var FOREIGN = 32;
|
|
1311
|
+
var FLAGS = /* @__PURE__ */ new Map();
|
|
1312
|
+
for (const [tags, bit] of [
|
|
1313
|
+
[
|
|
1314
|
+
"area base basefont bgsound br col embed frame hr img input keygen link meta param source track wbr",
|
|
1315
|
+
VOID
|
|
1316
|
+
],
|
|
1317
|
+
["script style textarea title xmp iframe noembed noframes", RAW],
|
|
1318
|
+
["html head body frameset image noscript plaintext", REFUSE],
|
|
1319
|
+
["table tbody thead tfoot tr colgroup", BOX],
|
|
1320
|
+
[
|
|
1321
|
+
"p li dd dt a button nobr select option optgroup datalist ruby rb rt rtc rp svg math template h1 h2 h3 h4 h5 h6 b big code em font i s small strike strong tt u",
|
|
1322
|
+
SENSITIVE
|
|
1323
|
+
],
|
|
1324
|
+
["svg math", FOREIGN]
|
|
1325
|
+
]) {
|
|
1326
|
+
for (const t of tags.split(" ")) FLAGS.set(t, (FLAGS.get(t) ?? 0) | bit);
|
|
1327
|
+
}
|
|
1328
|
+
var TABLE_PARENT = {
|
|
1329
|
+
tr: " tbody thead tfoot ",
|
|
1330
|
+
td: " tr ",
|
|
1331
|
+
th: " tr ",
|
|
1332
|
+
tbody: " table ",
|
|
1333
|
+
thead: " table ",
|
|
1334
|
+
tfoot: " table ",
|
|
1335
|
+
caption: " table ",
|
|
1336
|
+
colgroup: " table ",
|
|
1337
|
+
col: " colgroup "
|
|
1338
|
+
};
|
|
1339
|
+
var isSpace = (c) => c === 32 || c === 9 || c === 10 || c === 12 || c === 13;
|
|
1340
|
+
function scanStatic(html, rootTag) {
|
|
1341
|
+
const len = html.length;
|
|
1342
|
+
const tag = [rootTag];
|
|
1343
|
+
const r = [-1, 0, len, len, -1, 0, 0, -1, -1, FLAGS.get(rootTag) ?? 0, -1];
|
|
1344
|
+
const stack = [0];
|
|
1345
|
+
let textFrom = 0;
|
|
1346
|
+
let dq = -1;
|
|
1347
|
+
let sq = -1;
|
|
1348
|
+
const blankUntil = (to) => {
|
|
1349
|
+
for (let k = textFrom; k < to; k++)
|
|
1350
|
+
if (!isSpace(html.charCodeAt(k))) return false;
|
|
1351
|
+
return true;
|
|
1352
|
+
};
|
|
1353
|
+
for (let i = 0; (i = html.indexOf("<", i)) !== -1; ) {
|
|
1354
|
+
const top = stack[stack.length - 1];
|
|
1355
|
+
const topFlag = r[top * W + FLAG];
|
|
1356
|
+
const c = html.charCodeAt(i + 1);
|
|
1357
|
+
if (c !== 33 && c !== 47 && !((c | 32) >= 97 && (c | 32) <= 122)) {
|
|
1358
|
+
i++;
|
|
1359
|
+
continue;
|
|
1360
|
+
}
|
|
1361
|
+
if (topFlag & BOX && !blankUntil(i)) return null;
|
|
1362
|
+
if (c === 33) {
|
|
1363
|
+
const e2 = html.indexOf("-->", i + 4);
|
|
1364
|
+
if (!html.startsWith("!--", i + 1) || e2 < 0) return null;
|
|
1365
|
+
const body = html.slice(i + 4, e2);
|
|
1366
|
+
if (body[0] === ">" || body.startsWith("->") || body.includes("--!>"))
|
|
1367
|
+
return null;
|
|
1368
|
+
i = textFrom = e2 + 3;
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
if (c === 47) {
|
|
1372
|
+
const gt = html.indexOf(">", i);
|
|
1373
|
+
if (top === 0 || gt < 0) return null;
|
|
1374
|
+
const t = tag[top];
|
|
1375
|
+
let j2 = i + 2 + t.length;
|
|
1376
|
+
if (!html.startsWith(t, i + 2)) {
|
|
1377
|
+
j2 = i + 2;
|
|
1378
|
+
while (j2 < gt && !isSpace(html.charCodeAt(j2))) j2++;
|
|
1379
|
+
if (html.slice(i + 2, j2).toLowerCase() !== t) return null;
|
|
1380
|
+
} else if (j2 !== gt && !isSpace(html.charCodeAt(j2))) return null;
|
|
1381
|
+
stack.pop();
|
|
1382
|
+
r[top * W + CLOSE] = i;
|
|
1383
|
+
i = textFrom = r[top * W + END] = gt + 1;
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
let j = i + 1;
|
|
1387
|
+
let ch;
|
|
1388
|
+
while (j < len && !isSpace(ch = html.charCodeAt(j)) && ch !== 47 && ch !== 62)
|
|
1389
|
+
j++;
|
|
1390
|
+
const name = html.slice(i + 1, j).toLowerCase();
|
|
1391
|
+
const flag = FLAGS.get(name) ?? 0;
|
|
1392
|
+
for (; ; ) {
|
|
1393
|
+
const gt = html.indexOf(">", j);
|
|
1394
|
+
if (gt < 0) return null;
|
|
1395
|
+
if (dq < j) dq = html.indexOf('"', j) >>> 0;
|
|
1396
|
+
if (sq < j) sq = html.indexOf("'", j) >>> 0;
|
|
1397
|
+
const qpos = dq < sq ? dq : sq;
|
|
1398
|
+
if (qpos > gt) {
|
|
1399
|
+
j = gt;
|
|
1400
|
+
break;
|
|
1401
|
+
}
|
|
1402
|
+
let k = qpos - 1;
|
|
1403
|
+
while (isSpace(html.charCodeAt(k))) k--;
|
|
1404
|
+
const close = html.indexOf(html[qpos], qpos + 1);
|
|
1405
|
+
if (html.charCodeAt(k) !== 61 || close < 0) return null;
|
|
1406
|
+
j = close + 1;
|
|
1407
|
+
}
|
|
1408
|
+
const want = TABLE_PARENT[name];
|
|
1409
|
+
if (flag & REFUSE || (want !== void 0 ? !want.includes(` ${tag[top]} `) : topFlag & BOX))
|
|
1410
|
+
return null;
|
|
1411
|
+
const e = tag.length;
|
|
1412
|
+
const p = top * W;
|
|
1413
|
+
const last = r[p + LAST];
|
|
1414
|
+
if (last < 0) r[p + FIRST] = e;
|
|
1415
|
+
else r[last * W + NEXT] = e;
|
|
1416
|
+
r[p + LAST] = e;
|
|
1417
|
+
tag.push(name);
|
|
1418
|
+
r.push(i, j + 1, j + 1, j + 1, top, r[p + COUNT]++, 0, -1, -1, flag, -1);
|
|
1419
|
+
i = textFrom = j + 1;
|
|
1420
|
+
if (flag & (FOREIGN | RAW)) {
|
|
1421
|
+
const re = new RegExp(`<(/?)${name}[\\s/>]`, "gi");
|
|
1422
|
+
re.lastIndex = i;
|
|
1423
|
+
let depth = flag & FOREIGN && html[j - 1] === "/" ? 0 : 1;
|
|
1424
|
+
while (depth > 0) {
|
|
1425
|
+
const m = re.exec(html);
|
|
1426
|
+
if (m === null) return null;
|
|
1427
|
+
const gt = html.indexOf(">", m.index);
|
|
1428
|
+
if (m[1] === "/") depth--;
|
|
1429
|
+
else if (flag & FOREIGN && html[gt - 1] !== "/") depth++;
|
|
1430
|
+
r[e * W + CLOSE] = m.index;
|
|
1431
|
+
i = textFrom = r[e * W + END] = gt + 1;
|
|
1432
|
+
}
|
|
1433
|
+
} else if (!(flag & VOID)) {
|
|
1434
|
+
stack.push(e);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return stack.length > 1 || r[FLAG] & BOX && !blankUntil(len) ? null : { tag, r };
|
|
1438
|
+
}
|
|
1439
|
+
function commonRun(a, b, max, fromEnd) {
|
|
1440
|
+
const at = (s, from, to) => fromEnd ? s.slice(s.length - to, s.length - from) : s.slice(from, to);
|
|
1441
|
+
let n = 0;
|
|
1442
|
+
for (let step = 1024; n < max; ) {
|
|
1443
|
+
const to = Math.min(n + step, max);
|
|
1444
|
+
if (at(a, n, to) === at(b, n, to)) {
|
|
1445
|
+
n = to;
|
|
1446
|
+
step *= 2;
|
|
1447
|
+
} else if (step > 16) step >>= 2;
|
|
1448
|
+
else break;
|
|
1449
|
+
}
|
|
1450
|
+
while (n < max && at(a, n, n + 1) === at(b, n, n + 1)) n++;
|
|
1451
|
+
return n;
|
|
1452
|
+
}
|
|
1453
|
+
function overlapping(s, host, p, to) {
|
|
1454
|
+
const out = [];
|
|
1455
|
+
for (let c = s.r[host * W + FIRST]; c >= 0; c = s.r[c * W + NEXT])
|
|
1456
|
+
if (s.r[c * W + END] > p && s.r[c * W + START] < to) out.push(c);
|
|
1457
|
+
return out;
|
|
1458
|
+
}
|
|
1459
|
+
function morphStaticChange(rootEl, prev, next, cache, ownedItems) {
|
|
1460
|
+
const rootTag = rootEl.localName;
|
|
1461
|
+
const sa = cache.html === prev ? cache.scan : scanStatic(prev, rootTag);
|
|
1462
|
+
const sb = scanStatic(next, rootTag);
|
|
1463
|
+
cache.html = next;
|
|
1464
|
+
cache.scan = sb;
|
|
1465
|
+
if (sa === null || sb === null) return false;
|
|
1466
|
+
const a = sa.r;
|
|
1467
|
+
const b = sb.r;
|
|
1468
|
+
const delta = next.length - prev.length;
|
|
1469
|
+
const p = commonRun(prev, next, Math.min(prev.length, next.length), false);
|
|
1470
|
+
const q = commonRun(prev, next, Math.min(prev.length, next.length) - p, true);
|
|
1471
|
+
const aEnd = prev.length - q;
|
|
1472
|
+
let host = 0;
|
|
1473
|
+
for (let lo = 1, hi = sa.tag.length - 1; lo <= hi; ) {
|
|
1474
|
+
const mid = lo + hi >> 1;
|
|
1475
|
+
if (a[mid * W + START] < p) {
|
|
1476
|
+
host = mid;
|
|
1477
|
+
lo = mid + 1;
|
|
1478
|
+
} else hi = mid - 1;
|
|
1479
|
+
}
|
|
1480
|
+
while (!(a[host * W + OPEN_END] <= p && a[host * W + CLOSE] >= aEnd))
|
|
1481
|
+
host = a[host * W + PARENT];
|
|
1482
|
+
for (let x = host; x > 0; x = a[x * W + PARENT])
|
|
1483
|
+
if (a[x * W + FLAG] & SENSITIVE) host = a[x * W + PARENT];
|
|
1484
|
+
let olds;
|
|
1485
|
+
let news;
|
|
1486
|
+
for (; ; host = a[host * W + PARENT]) {
|
|
1487
|
+
if (host < 0) return false;
|
|
1488
|
+
if (b[host * W + CLOSE] - delta !== a[host * W + CLOSE]) continue;
|
|
1489
|
+
olds = overlapping(sa, host, p, aEnd);
|
|
1490
|
+
news = overlapping(sb, host, p, next.length - q);
|
|
1491
|
+
const k = olds.length;
|
|
1492
|
+
let ok = k > 0 && k === news.length && a[olds[0] * W + START] <= p && b[news[0] * W + START] <= p && a[olds[k - 1] * W + END] >= aEnd && b[news[k - 1] * W + END] - delta === a[olds[k - 1] * W + END];
|
|
1493
|
+
for (let m = 0; ok && m < k; m++) {
|
|
1494
|
+
ok = sa.tag[olds[m]] === sb.tag[news[m]] && (m === 0 || prev.slice(a[olds[m - 1] * W + END], a[olds[m] * W + START]) === next.slice(b[news[m - 1] * W + END], b[news[m] * W + START]));
|
|
1495
|
+
}
|
|
1496
|
+
if (ok) break;
|
|
1497
|
+
}
|
|
1498
|
+
if (rootEl.childElementCount !== a[COUNT]) return false;
|
|
1499
|
+
const path = [];
|
|
1500
|
+
for (let x = host; x > 0; x = a[x * W + PARENT]) path.push(x);
|
|
1501
|
+
let live = rootEl;
|
|
1502
|
+
for (let m = path.length - 1; m >= 0; m--) {
|
|
1503
|
+
const x = path[m];
|
|
1504
|
+
const el = live.children[a[x * W + INDEX]];
|
|
1505
|
+
if (el.localName !== sa.tag[x] || el.childElementCount !== a[x * W + COUNT] || el.dataset.morphSkip !== void 0 || el.dataset.morphSkipChildren !== void 0 || el === document.activeElement)
|
|
1506
|
+
return false;
|
|
1507
|
+
live = el;
|
|
1508
|
+
}
|
|
1509
|
+
const lives = [];
|
|
1510
|
+
let html = "";
|
|
1511
|
+
for (let m = 0; m < olds.length; m++) {
|
|
1512
|
+
const o = olds[m] * W;
|
|
1513
|
+
const n = news[m] * W;
|
|
1514
|
+
const nextChild = next.slice(b[n + START], b[n + END]);
|
|
1515
|
+
if (prev.slice(a[o + START], a[o + END]) === nextChild) continue;
|
|
1516
|
+
const el = live.children[a[o + INDEX]];
|
|
1517
|
+
if (el.localName !== sa.tag[olds[m]]) return false;
|
|
1518
|
+
lives.push(el);
|
|
1519
|
+
html += nextChild;
|
|
1520
|
+
}
|
|
1521
|
+
const tpl = live.cloneNode(false);
|
|
1522
|
+
tpl.innerHTML = html;
|
|
1523
|
+
const tos = tpl.childNodes;
|
|
1524
|
+
if (tos.length !== lives.length) return false;
|
|
1525
|
+
for (let m = 0; m < lives.length; m++) {
|
|
1526
|
+
const from = lives[m];
|
|
1527
|
+
const to = tos[m];
|
|
1528
|
+
if (to.localName !== from.localName || keyOf(from) !== keyOf(to) || keyOf(from) === "" && protectionOf(from) !== protectionOf(to))
|
|
1529
|
+
return false;
|
|
1530
|
+
}
|
|
1531
|
+
const focusSnap = captureFocus(live);
|
|
1532
|
+
for (let m = 0; m < lives.length; m++)
|
|
1533
|
+
morphElement(lives[m], tos[m], ownedItems);
|
|
1534
|
+
if (focusSnap !== null) restoreFocus(focusSnap);
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
function keyOf(el) {
|
|
1538
|
+
return el.id !== "" ? `#${el.id}` : el.dataset.key !== void 0 ? `k${el.dataset.key}` : "";
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1133
1541
|
// src/mount.ts
|
|
1134
1542
|
var MOUNTED_MARKER = /* @__PURE__ */ Symbol.for("kerfjs.mounted");
|
|
1135
1543
|
var NESTED_MOUNT_MSG = "mount: rootEl is already inside (or contains) a mounted tree. kerf supports one mount per tree \u2014 compose with plain functions that return JSX instead of nesting mounts.";
|
|
@@ -1155,16 +1563,15 @@ function assertNotInsideMountedTree(rootEl) {
|
|
|
1155
1563
|
);
|
|
1156
1564
|
}
|
|
1157
1565
|
let ancestor = rootEl.parentElement;
|
|
1158
|
-
while (ancestor) {
|
|
1566
|
+
while (ancestor && !isOverlayHost(ancestor)) {
|
|
1159
1567
|
if (isMounted(ancestor)) throw new Error(NESTED_MOUNT_MSG);
|
|
1160
1568
|
ancestor = ancestor.parentElement;
|
|
1161
1569
|
}
|
|
1162
|
-
const stack = [];
|
|
1163
|
-
for (let
|
|
1164
|
-
while (stack.length > 0) {
|
|
1165
|
-
const cur = stack.pop();
|
|
1570
|
+
const stack = [...rootEl.children];
|
|
1571
|
+
for (let cur; cur = stack.pop(); ) {
|
|
1166
1572
|
if (isMounted(cur)) throw new Error(NESTED_MOUNT_MSG);
|
|
1167
|
-
|
|
1573
|
+
if (!isOverlayHost(cur))
|
|
1574
|
+
for (const child of cur.children) stack.push(child);
|
|
1168
1575
|
}
|
|
1169
1576
|
}
|
|
1170
1577
|
function mount(rootEl, render) {
|
|
@@ -1196,7 +1603,9 @@ function mount(rootEl, render) {
|
|
|
1196
1603
|
let prevWiredBindings = [];
|
|
1197
1604
|
let isFirst = true;
|
|
1198
1605
|
let prevStaticHtml = "";
|
|
1606
|
+
const scanCache = { html: "", scan: null };
|
|
1199
1607
|
const valueOnlyWarnCtx = { warned: false };
|
|
1608
|
+
const boundRows = () => bindingCtx.list.length > 0 && bindings.size > 0 ? collectOwnedItems(bindings) : void 0;
|
|
1200
1609
|
const runRenderPass = () => {
|
|
1201
1610
|
renderCtx.counter = 0;
|
|
1202
1611
|
renderCtx.keysThisRender.clear();
|
|
@@ -1228,7 +1637,12 @@ function mount(rootEl, render) {
|
|
|
1228
1637
|
runFirstRender(rootEl, segment, bindings);
|
|
1229
1638
|
prevStaticHtml = flattenWithoutListItems(segment);
|
|
1230
1639
|
devHooks.parserRepair?.(prevStaticHtml);
|
|
1231
|
-
bindingDisposers = wireBindings(
|
|
1640
|
+
bindingDisposers = wireBindings(
|
|
1641
|
+
rootEl,
|
|
1642
|
+
bindingCtx,
|
|
1643
|
+
bindingDisposers,
|
|
1644
|
+
boundRows()
|
|
1645
|
+
);
|
|
1232
1646
|
if (devHooks.staleBindingEnabled?.()) prevWiredBindings = bindingCtx.list;
|
|
1233
1647
|
isFirst = false;
|
|
1234
1648
|
} else {
|
|
@@ -1238,10 +1652,12 @@ function mount(rootEl, render) {
|
|
|
1238
1652
|
bindings,
|
|
1239
1653
|
renderCtx,
|
|
1240
1654
|
prevStaticHtml,
|
|
1241
|
-
valueOnlyWarnCtx
|
|
1655
|
+
valueOnlyWarnCtx,
|
|
1656
|
+
scanCache
|
|
1242
1657
|
);
|
|
1243
1658
|
if (anyRebuiltListIsGranular(segment, renderCtx.rebuiltLists)) {
|
|
1244
|
-
for (const id of renderCtx.rebuiltLists)
|
|
1659
|
+
for (const id of renderCtx.rebuiltLists)
|
|
1660
|
+
renderCtx.bindingCounts.delete(id);
|
|
1245
1661
|
result = runRenderPass();
|
|
1246
1662
|
segment = resultToSegment(result);
|
|
1247
1663
|
nextStaticHtml = runSubsequentRender(
|
|
@@ -1250,12 +1666,19 @@ function mount(rootEl, render) {
|
|
|
1250
1666
|
bindings,
|
|
1251
1667
|
renderCtx,
|
|
1252
1668
|
prevStaticHtml,
|
|
1253
|
-
valueOnlyWarnCtx
|
|
1669
|
+
valueOnlyWarnCtx,
|
|
1670
|
+
scanCache
|
|
1254
1671
|
);
|
|
1255
1672
|
}
|
|
1256
1673
|
if (nextStaticHtml !== prevStaticHtml) {
|
|
1257
|
-
bindingDisposers = wireBindings(
|
|
1258
|
-
|
|
1674
|
+
bindingDisposers = wireBindings(
|
|
1675
|
+
rootEl,
|
|
1676
|
+
bindingCtx,
|
|
1677
|
+
bindingDisposers,
|
|
1678
|
+
boundRows()
|
|
1679
|
+
);
|
|
1680
|
+
if (devHooks.staleBindingEnabled?.())
|
|
1681
|
+
prevWiredBindings = bindingCtx.list;
|
|
1259
1682
|
} else {
|
|
1260
1683
|
devHooks.staleBinding?.(prevWiredBindings, bindingCtx.list);
|
|
1261
1684
|
}
|
|
@@ -1283,11 +1706,7 @@ function mount(rootEl, render) {
|
|
|
1283
1706
|
renderCtx.previousCallCount = renderCtx.counter;
|
|
1284
1707
|
devHooks.listInvariants?.(rootEl, bindings, expectedCounts || void 0);
|
|
1285
1708
|
}
|
|
1286
|
-
const
|
|
1287
|
-
reconcileAndCommitListPhase(renderStaticPhase());
|
|
1288
|
-
});
|
|
1289
|
-
return () => {
|
|
1290
|
-
disposeEffect();
|
|
1709
|
+
const releaseResources = () => {
|
|
1291
1710
|
for (const d of bindingDisposers) d();
|
|
1292
1711
|
bindingDisposers = [];
|
|
1293
1712
|
for (const b of bindings.values()) {
|
|
@@ -1296,133 +1715,74 @@ function mount(rootEl, render) {
|
|
|
1296
1715
|
listenerWarnObserver?.disconnect();
|
|
1297
1716
|
setMounted(rootEl, false);
|
|
1298
1717
|
};
|
|
1718
|
+
const priorChildren = rootEl.firstChild ? Array.from(rootEl.childNodes) : [];
|
|
1719
|
+
let disposeEffect;
|
|
1720
|
+
try {
|
|
1721
|
+
disposeEffect = effect(() => {
|
|
1722
|
+
reconcileAndCommitListPhase(renderStaticPhase());
|
|
1723
|
+
});
|
|
1724
|
+
} catch (err) {
|
|
1725
|
+
releaseResources();
|
|
1726
|
+
rootEl.replaceChildren(...priorChildren);
|
|
1727
|
+
throw err;
|
|
1728
|
+
}
|
|
1729
|
+
return () => {
|
|
1730
|
+
disposeEffect();
|
|
1731
|
+
releaseResources();
|
|
1732
|
+
};
|
|
1299
1733
|
}
|
|
1300
1734
|
function runFirstRender(rootEl, segment, bindings) {
|
|
1301
|
-
|
|
1735
|
+
const html = flatten(segment, true);
|
|
1736
|
+
if (hasCustomTag(html)) {
|
|
1737
|
+
const tpl = rootEl.cloneNode(false);
|
|
1738
|
+
tpl.innerHTML = html;
|
|
1739
|
+
const content = document.createDocumentFragment();
|
|
1740
|
+
while (tpl.firstChild !== null) content.appendChild(tpl.firstChild);
|
|
1741
|
+
seedRenderedAttrs(content);
|
|
1742
|
+
rootEl.replaceChildren(content);
|
|
1743
|
+
} else {
|
|
1744
|
+
rootEl.innerHTML = html;
|
|
1745
|
+
}
|
|
1302
1746
|
bindListsFromMarkers(rootEl, segment, bindings, true);
|
|
1303
1747
|
}
|
|
1304
|
-
function runSubsequentRender(rootEl, segment, bindings, renderCtx, prevStaticHtml, valueOnlyWarnCtx) {
|
|
1748
|
+
function runSubsequentRender(rootEl, segment, bindings, renderCtx, prevStaticHtml, valueOnlyWarnCtx, scanCache) {
|
|
1305
1749
|
renderCtx.rebuiltLists.clear();
|
|
1306
1750
|
const currentStaticHtml = flattenWithoutListItems(segment);
|
|
1307
1751
|
if (currentStaticHtml === prevStaticHtml) {
|
|
1308
1752
|
return prevStaticHtml;
|
|
1309
1753
|
}
|
|
1310
|
-
devHooks.valueOnlyRerender?.(
|
|
1754
|
+
devHooks.valueOnlyRerender?.(
|
|
1755
|
+
prevStaticHtml,
|
|
1756
|
+
currentStaticHtml,
|
|
1757
|
+
valueOnlyWarnCtx
|
|
1758
|
+
);
|
|
1311
1759
|
cleanupOrphanBindings(segment, bindings, renderCtx);
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1760
|
+
const ownedItems = collectOwnedItems(bindings);
|
|
1761
|
+
if (!morphStaticChange(
|
|
1762
|
+
rootEl,
|
|
1763
|
+
prevStaticHtml,
|
|
1764
|
+
currentStaticHtml,
|
|
1765
|
+
scanCache,
|
|
1766
|
+
ownedItems
|
|
1767
|
+
)) {
|
|
1768
|
+
const template = rootEl.cloneNode(false);
|
|
1769
|
+
template.innerHTML = currentStaticHtml;
|
|
1770
|
+
morph(rootEl, template, ownedItems);
|
|
1771
|
+
}
|
|
1772
|
+
bindListsFromMarkers(
|
|
1773
|
+
rootEl,
|
|
1774
|
+
segment,
|
|
1775
|
+
bindings,
|
|
1776
|
+
false,
|
|
1777
|
+
renderCtx.rebuiltLists,
|
|
1778
|
+
ownedItems
|
|
1779
|
+
);
|
|
1316
1780
|
return currentStaticHtml;
|
|
1317
1781
|
}
|
|
1318
|
-
function coerceRenderResult(result) {
|
|
1319
|
-
if (result == null || typeof result === "boolean") return "";
|
|
1320
|
-
return String(result);
|
|
1321
|
-
}
|
|
1322
1782
|
function resultToSegment(result) {
|
|
1323
|
-
return isSafeHtml(result) ? result.__segment ?? { kind: "static", html: result.__html } : { kind: "static", html:
|
|
1324
|
-
}
|
|
1325
|
-
function anyRebuiltListIsGranular(segment, rebuilt) {
|
|
1326
|
-
if (!rebuilt.size) return false;
|
|
1327
|
-
const lists = collectLists(segment);
|
|
1328
|
-
for (const id of rebuilt) {
|
|
1329
|
-
if (lists.get(id)?.patches) return true;
|
|
1330
|
-
}
|
|
1331
|
-
return false;
|
|
1332
|
-
}
|
|
1333
|
-
function bindListsFromMarkers(rootEl, segment, bindings, inlinedItems, rebuiltLists) {
|
|
1334
|
-
const lists = collectLists(segment);
|
|
1335
|
-
const found = [];
|
|
1336
|
-
collectComments(rootEl, found);
|
|
1337
|
-
for (const marker of found) {
|
|
1338
|
-
if (!marker.data.startsWith(LIST_MARKER_PREFIX)) continue;
|
|
1339
|
-
const id = marker.data.slice(LIST_MARKER_PREFIX.length);
|
|
1340
|
-
const existing = bindings.get(id);
|
|
1341
|
-
if (existing) {
|
|
1342
|
-
if (existing.marker === marker && rootEl.contains(existing.marker)) continue;
|
|
1343
|
-
for (const item of existing.items) {
|
|
1344
|
-
disposeRowBindings(item.bindingDisposers);
|
|
1345
|
-
if (rootEl.contains(item.node)) {
|
|
1346
|
-
item.node.parentElement?.removeChild(item.node);
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
bindings.delete(id);
|
|
1350
|
-
rebuiltLists?.add(id);
|
|
1351
|
-
devHooks.listRebind?.(id, marker.parentElement);
|
|
1352
|
-
}
|
|
1353
|
-
const listSeg = lists.get(id);
|
|
1354
|
-
const liveParent = marker.parentElement;
|
|
1355
|
-
const items = [];
|
|
1356
|
-
if (inlinedItems) {
|
|
1357
|
-
let next = marker.nextElementSibling;
|
|
1358
|
-
for (let i = 0; i < listSeg.items.length && next !== null; i++) {
|
|
1359
|
-
validateInlinedRowMatch(listSeg.items[i].html, i, next, liveParent);
|
|
1360
|
-
const rowBindings = listSeg.items[i].bindings;
|
|
1361
|
-
const bound = {
|
|
1362
|
-
ref: listSeg.items[i].ref,
|
|
1363
|
-
cacheKey: listSeg.items[i].cacheKey,
|
|
1364
|
-
html: listSeg.items[i].html,
|
|
1365
|
-
node: next,
|
|
1366
|
-
bindings: rowBindings
|
|
1367
|
-
};
|
|
1368
|
-
if (rowBindings?.length) {
|
|
1369
|
-
bound.bindingDisposers = wireRowBindings(next, rowBindings);
|
|
1370
|
-
}
|
|
1371
|
-
items.push(bound);
|
|
1372
|
-
next = next.nextElementSibling;
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
const binding = { liveParent, items, marker };
|
|
1376
|
-
if (items.length > 0) {
|
|
1377
|
-
devHooks.missingRowKey?.(items[0].node, items[0].html, binding);
|
|
1378
|
-
}
|
|
1379
|
-
devHooks.eachInMorphSkip?.(id, liveParent, rootEl);
|
|
1380
|
-
bindings.set(id, binding);
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
function validateInlinedRowMatch(expectedHtml, index, boundEl, liveParent) {
|
|
1384
|
-
if (boundEl.outerHTML === expectedHtml) return;
|
|
1385
|
-
const { content, count } = parseRowTemplate(expectedHtml, liveParent);
|
|
1386
|
-
if (count !== 1) throw rowContractError(index, expectedHtml, liveParent);
|
|
1387
|
-
const expectedTag = content.firstElementChild.tagName;
|
|
1388
|
-
if (boundEl.tagName !== expectedTag) throw rowStructureError(index, boundEl.tagName, expectedTag);
|
|
1389
|
-
}
|
|
1390
|
-
function rowStructureError(index, gotTag, wantTag) {
|
|
1391
|
-
const got = gotTag.toLowerCase();
|
|
1392
|
-
const want = wantTag.toLowerCase();
|
|
1393
|
-
return new Error(
|
|
1394
|
-
`each(): row ${index} renders <${want}>, but the HTML parser wrapped the rows in <${got}> \u2014 so kerf cannot bind one row per element. This happens when an each() of <${want}> sits directly inside a table: the parser inserts <${got}> around the whole run. Put the each() inside an explicit <${got}> (e.g. <table><${got}>{each(...)}</${got}></table>) so the rows are the direct children kerf binds.`
|
|
1395
|
-
);
|
|
1396
|
-
}
|
|
1397
|
-
function collectOwnedItems(bindings) {
|
|
1398
|
-
const owned = /* @__PURE__ */ new Set();
|
|
1399
|
-
for (const b of bindings.values()) {
|
|
1400
|
-
for (const item of b.items) owned.add(item.node);
|
|
1401
|
-
}
|
|
1402
|
-
return owned;
|
|
1403
|
-
}
|
|
1404
|
-
function cleanupOrphanBindings(segment, bindings, renderCtx) {
|
|
1405
|
-
const liveIds = collectLists(segment);
|
|
1406
|
-
for (const [id, binding] of bindings) {
|
|
1407
|
-
if (liveIds.has(id)) continue;
|
|
1408
|
-
for (const item of binding.items) {
|
|
1409
|
-
disposeRowBindings(item.bindingDisposers);
|
|
1410
|
-
item.node.remove();
|
|
1411
|
-
}
|
|
1412
|
-
binding.marker.remove();
|
|
1413
|
-
bindings.delete(id);
|
|
1414
|
-
renderCtx.bindingCounts.delete(id);
|
|
1415
|
-
renderCtx.bindingSources.delete(id);
|
|
1416
|
-
renderCtx.caches.delete(id);
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
|
-
function collectComments(node, out) {
|
|
1420
|
-
for (let c = node.firstChild; c; c = c.nextSibling) {
|
|
1421
|
-
if (c.nodeType === Node.COMMENT_NODE) out.push(c);
|
|
1422
|
-
else if (c.nodeType === Node.ELEMENT_NODE) collectComments(c, out);
|
|
1423
|
-
}
|
|
1783
|
+
return isSafeHtml(result) ? result.__segment ?? { kind: "static", html: result.__html } : { kind: "static", html: coerceText(result) };
|
|
1424
1784
|
}
|
|
1425
1785
|
|
|
1426
1786
|
export { captureFocus, each, morph, mount, moveNode, restoreFocus };
|
|
1427
1787
|
|
|
1428
|
-
//# sourceMappingURL=chunk-
|
|
1788
|
+
//# sourceMappingURL=chunk-5QDM6HPD.js.map
|