kerfjs 5.0.0-beta.124 → 5.0.0-beta.125

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.
@@ -1,8 +1,8 @@
1
1
  import { itemVersion } from './chunk-5WRGJZV6.js';
2
- import { seedRenderedAttrs, RENDERED_ATTRS, isUserAgentOwnedAttr, hasCustomTag, parseRowTemplate, rowContractError, parseSingleRow, collectTemplateChildren } from './chunk-6LXUC4ZY.js';
3
- import { captureRowBindings, listSafeHtml, boundTextNodeOf, syncFormProp, newBindingContext, wireBindings, disposeRowBindings, isSafeHtml, _setBindingContext, TEXT_MARKER_PREFIX, ROW_TEXT_PREFIX, wireRowBindings, carryOrRewireRowBindings, granularListSafeHtml } from './chunk-XL35DIZ2.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-4P6Z33YK.js';
4
4
  import { effect } from './chunk-N4VHHOCM.js';
5
- import { LIST_MARKER_PREFIX, flattenWithoutListItems, collectLists, isOverlayHost, flatten } from './chunk-4TX6YJDM.js';
5
+ import { flattenWithoutListItems, collectLists, LIST_MARKER_PREFIX, isOverlayHost, flatten } from './chunk-4TX6YJDM.js';
6
6
  import { devHooks } from './chunk-KUHXPPJ4.js';
7
7
 
8
8
  // src/list-render-state.ts
@@ -35,14 +35,17 @@ function isArraySignal(value) {
35
35
  }
36
36
  var context = null;
37
37
  var renderingRow = false;
38
- function inRowScope(fn) {
39
- const prev = renderingRow;
40
- renderingRow = true;
41
- try {
42
- return fn();
43
- } finally {
44
- renderingRow = prev;
45
- }
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
+ });
46
49
  }
47
50
  function _setRenderContext(c) {
48
51
  context = c;
@@ -66,7 +69,8 @@ function assertValidKey(key) {
66
69
  );
67
70
  }
68
71
  }
69
- function claimKey(ctx, key) {
72
+ function listId(ctx, key) {
73
+ if (key === void 0) return String(ctx.counter++);
70
74
  assertValidKey(key);
71
75
  if (renderingRow) {
72
76
  throw new Error(
@@ -92,12 +96,7 @@ function each(items, render, cacheKeyOrOptions) {
92
96
  return eachSnapshot(snapshotItems, render, cacheKey, listKey);
93
97
  }
94
98
  function eachSnapshot(items, render, cacheKey, listKey) {
95
- let id;
96
- if (context !== null) {
97
- id = listKey !== void 0 ? claimKey(context, listKey) : String(context.counter++);
98
- } else {
99
- id = "orphan";
100
- }
99
+ const id = context !== null ? listId(context, listKey) : "orphan";
101
100
  return eachSnapshotById(items, render, cacheKey, id);
102
101
  }
103
102
  function assertObjectItem(item, index) {
@@ -138,7 +137,7 @@ function _hasGranularCacheKeyDrift(snapshot, cacheKey, cache) {
138
137
  }
139
138
  function eachGranular(sig, render, cacheKey, listKey) {
140
139
  const ctx = context;
141
- const id = listKey !== void 0 ? claimKey(ctx, listKey) : String(ctx.counter++);
140
+ const id = listId(ctx, listKey);
142
141
  const previousBindingCount = ctx.bindingCounts.get(id);
143
142
  const patches = sig._consumePatches();
144
143
  const snapshot = sig.value;
@@ -161,12 +160,6 @@ function eachGranular(sig, render, cacheKey, listKey) {
161
160
  return eachSnapshotById(snapshot, render, cacheKey, id, sig);
162
161
  }
163
162
  }
164
- const renderRow = (item, index) => captureRowBindings(
165
- () => inRowScope(() => {
166
- const out = render(item, index);
167
- return isSafeHtml(out) ? out.toString() : out;
168
- })
169
- );
170
163
  const internalPatches = new Array(patches.length);
171
164
  const cache = ctx.caches.get(id);
172
165
  try {
@@ -174,7 +167,7 @@ function eachGranular(sig, render, cacheKey, listKey) {
174
167
  const p = patches[i];
175
168
  if (p.type === "insert" || p.type === "update") {
176
169
  assertObjectItem(p.item, p.index);
177
- const { html, bindings } = renderRow(p.item, p.index);
170
+ const { html, bindings } = renderRow(render, p.item, p.index);
178
171
  internalPatches[i] = {
179
172
  type: p.type,
180
173
  index: p.index,
@@ -237,12 +230,7 @@ function eachSnapshotById(items, render, cacheKey, id, source) {
237
230
  devHooks.staleIndex?.(id);
238
231
  }
239
232
  } else {
240
- const captured = captureRowBindings(
241
- () => inRowScope(() => {
242
- const out = render(item, i);
243
- return isSafeHtml(out) ? out.toString() : out;
244
- })
245
- );
233
+ const captured = renderRow(render, item, i);
246
234
  html = captured.html;
247
235
  bindings = captured.bindings;
248
236
  if (cache !== null)
@@ -340,9 +328,6 @@ function morph(liveRoot, template, ownedItems = EMPTY_OWNED) {
340
328
  morphChildren(liveRoot, templateEl, ownedItems);
341
329
  if (focusSnap !== null) restoreFocus(focusSnap);
342
330
  }
343
- function _morphElement(fromEl, toEl, ownedItems = EMPTY_OWNED) {
344
- morphElement(fromEl, toEl, ownedItems);
345
- }
346
331
  function isElementNode(t) {
347
332
  return typeof t === "object" && t !== null && t.nodeType === ELEMENT_NODE;
348
333
  }
@@ -434,7 +419,7 @@ function morphChildren(fromParent, toParent, ownedItems) {
434
419
  break;
435
420
  }
436
421
  }
437
- if (matched === null && fromChild !== null && toChild.nodeType === COMMENT_NODE && toChild.data.startsWith(LIST_MARKER_PREFIX)) {
422
+ if (matched === null && fromChild !== null && isListMarker(toChild)) {
438
423
  const wantData = toChild.data;
439
424
  for (let scan = fromChild.nextSibling; scan !== null; scan = scan.nextSibling) {
440
425
  if (scan.nodeType !== COMMENT_NODE || scan.data !== wantData)
@@ -486,7 +471,7 @@ function morphNode(fromNode, toNode, ownedItems) {
486
471
  if (fromText.data !== toText.data) fromText.data = toText.data;
487
472
  }
488
473
  }
489
- function morphElement(fromEl, toEl, ownedItems) {
474
+ function morphElement(fromEl, toEl, ownedItems = EMPTY_OWNED) {
490
475
  if (fromEl.tagName !== toEl.tagName) {
491
476
  const replacement = toEl.cloneNode(true);
492
477
  seedRenderedAttrs(toEl, replacement);
@@ -498,7 +483,7 @@ function morphElement(fromEl, toEl, ownedItems) {
498
483
  if (fromEl === document.activeElement) {
499
484
  const ce = fromEl.getAttribute("contenteditable");
500
485
  if (ce !== null && ce.toLowerCase() !== "false") return;
501
- if (isTextInputOrTextarea(fromEl)) preserveTextEntryState(fromEl, toEl);
486
+ preserveTextEntryState(fromEl, toEl);
502
487
  }
503
488
  morphAttributes(fromEl, toEl);
504
489
  if (fromEl.dataset.morphSkipChildren !== void 0) return;
@@ -541,16 +526,10 @@ function morphAttributes(fromEl, toEl) {
541
526
  }
542
527
  if (fromTag.includes("-")) host[RENDERED_ATTRS] = toEl.getAttributeNames();
543
528
  }
544
- function isTextInputOrTextarea(el) {
545
- if (el.tagName === "TEXTAREA") return true;
546
- if (el.tagName === "INPUT") {
547
- const type = el.type;
548
- return type === "text" || type === "search" || type === "url" || type === "email" || type === "tel" || type === "password" || type === "";
549
- }
550
- return false;
551
- }
552
529
  function preserveTextEntryState(fromEl, toEl) {
553
- if (fromEl.tagName === "TEXTAREA" || fromEl.tagName === "INPUT") {
530
+ if (fromEl.tagName === "TEXTAREA" || fromEl.tagName === "INPUT" && /^(text|search|url|email|tel|password|)$/.test(
531
+ fromEl.type
532
+ )) {
554
533
  const fromInput = fromEl;
555
534
  const toInput = toEl;
556
535
  toInput.value = fromInput.value;
@@ -867,7 +846,7 @@ function applySingleUpdate(liveParent, items, patch) {
867
846
  function applyParsedRowUpdate(liveParent, items, patch, html, newNode) {
868
847
  const oldEntry = items[patch.index];
869
848
  if (oldEntry.node.tagName === newNode.tagName) {
870
- _morphElement(oldEntry.node, newNode);
849
+ morphElement(oldEntry.node, newNode);
871
850
  items[patch.index] = reuseBound(patch, html, oldEntry);
872
851
  } else {
873
852
  disposeRowBindings(oldEntry.bindingDisposers);
@@ -914,14 +893,11 @@ function applyBulkUpdate(liveParent, items, patches, start, end) {
914
893
  morphChanges.push({ patchIdx: k, html: p.html });
915
894
  }
916
895
  if (morphChanges.length === 0) return;
917
- const { content, count } = parseRowTemplate(
918
- morphChanges.map((c) => c.html).join(""),
919
- liveParent
896
+ const newNodes = parseRows(
897
+ morphChanges.map((c) => c.html),
898
+ liveParent,
899
+ (k) => patches[morphChanges[k].patchIdx].index
920
900
  );
921
- if (count !== morphChanges.length) {
922
- throw findOffendingChange(patches, morphChanges, liveParent);
923
- }
924
- const newNodes = collectTemplateChildren(content, morphChanges.length);
925
901
  for (let k = 0; k < morphChanges.length; k++) {
926
902
  const c = morphChanges[k];
927
903
  const p = patches[c.patchIdx];
@@ -934,13 +910,13 @@ function applyBulkInsert(liveParent, items, patches, start, end, tailAnchor) {
934
910
  for (let k = start; k < end; k++) {
935
911
  htmls[k - start] = patches[k].html;
936
912
  }
937
- const { content, count } = parseRowTemplate(htmls.join(""), liveParent);
938
- if (count !== htmls.length) {
939
- throw findOffendingInsert(patches, start, htmls, liveParent);
940
- }
941
- const newNodes = collectTemplateChildren(content, end - start);
913
+ const newNodes = parseRows(
914
+ htmls,
915
+ liveParent,
916
+ (k) => patches[start + k].index
917
+ );
942
918
  const anchor = startIdx < items.length ? items[startIdx].node : tailAnchor;
943
- liveParent.insertBefore(content, anchor);
919
+ liveParent.insertBefore(newNodes[0].parentNode, anchor);
944
920
  const newEntries = new Array(end - start);
945
921
  for (let k = 0; k < newEntries.length; k++) {
946
922
  const p = patches[start + k];
@@ -957,34 +933,6 @@ function applyBulkInsert(liveParent, items, patches, start, end, tailAnchor) {
957
933
  }
958
934
  items.splice(startIdx, 0, ...newEntries);
959
935
  }
960
- function findOffendingInsert(patches, start, htmls, liveParent) {
961
- for (let i = 0; i < htmls.length; i++) {
962
- if (parseRowTemplate(htmls[i], liveParent).count !== 1) {
963
- return rowContractError(
964
- patches[start + i].index,
965
- htmls[i],
966
- liveParent
967
- );
968
- }
969
- }
970
- return new Error(
971
- "each(): bulk-insert mismatch with no per-row offender (kerf bug)."
972
- );
973
- }
974
- function findOffendingChange(patches, changes, liveParent) {
975
- for (const c of changes) {
976
- if (parseRowTemplate(c.html, liveParent).count !== 1) {
977
- return rowContractError(
978
- patches[c.patchIdx].index,
979
- c.html,
980
- liveParent
981
- );
982
- }
983
- }
984
- return new Error(
985
- "each(): bulk-update mismatch with no per-row offender (kerf bug)."
986
- );
987
- }
988
936
 
989
937
  // src/list-reconcile-inplace.ts
990
938
  function tryInPlaceContentUpdate(binding, listSeg) {
@@ -1025,7 +973,7 @@ function updateRowInPlace(liveParent, old, ni, index, parsedNode) {
1025
973
  }
1026
974
  const newNode = parsedNode ?? parseSingleRow(ni.html, index, liveParent);
1027
975
  if (old.node.tagName === newNode.tagName) {
1028
- _morphElement(old.node, newNode);
976
+ morphElement(old.node, newNode);
1029
977
  const kept = carryOrRewireRowBindings(
1030
978
  old.node,
1031
979
  old.bindings,
@@ -1165,34 +1113,14 @@ function classifyItems(oldItems, listSeg) {
1165
1113
  }
1166
1114
  function buildFreshNodes(newRecord, freshIndices, freshHtmls, liveParent) {
1167
1115
  if (freshHtmls.length === 0) return;
1168
- const { content, count } = parseRowTemplate(freshHtmls.join(""), liveParent);
1169
- if (count !== freshHtmls.length) {
1170
- throw findOffendingRow(newRecord, freshIndices, freshHtmls, liveParent);
1171
- }
1172
- let node = content.firstElementChild;
1173
- for (const idx of freshIndices) {
1174
- const next = node.nextElementSibling;
1116
+ const rows = parseRows(freshHtmls, liveParent, (i) => freshIndices[i]);
1117
+ freshIndices.forEach((idx, k) => {
1175
1118
  const item = newRecord[idx];
1176
- item.node = node;
1119
+ item.node = rows[k];
1177
1120
  if (item.bindings !== void 0 && item.bindings.length > 0) {
1178
1121
  item.bindingDisposers = wireRowBindings(item.node, item.bindings);
1179
1122
  }
1180
- node = next;
1181
- }
1182
- }
1183
- function findOffendingRow(newRecord, freshIndices, freshHtmls, liveParent) {
1184
- for (let i = 0; i < freshHtmls.length; i++) {
1185
- if (parseRowTemplate(freshHtmls[i], liveParent).count !== 1) {
1186
- return rowContractError(
1187
- freshIndices[i],
1188
- newRecord[freshIndices[i]].html,
1189
- liveParent
1190
- );
1191
- }
1192
- }
1193
- return new Error(
1194
- "each(): bulk-parse mismatch with no per-row offender (kerf bug)."
1195
- );
1123
+ });
1196
1124
  }
1197
1125
  function removeOldNodes(liveParent, removedItems) {
1198
1126
  for (const item of removedItems) {
@@ -1313,9 +1241,8 @@ function bindListsFromMarkers(rootEl, segment, bindings, inlinedItems, rebuiltLi
1313
1241
  }
1314
1242
  function validateInlinedRowMatch(expectedHtml, index, boundEl, liveParent) {
1315
1243
  if (boundEl.outerHTML === expectedHtml) return;
1316
- const { content, count } = parseRowTemplate(expectedHtml, liveParent);
1317
- if (count !== 1) throw rowContractError(index, expectedHtml, liveParent);
1318
- const expectedTag = content.firstElementChild.tagName;
1244
+ const expected = parseSingleRow(expectedHtml, index, liveParent);
1245
+ const expectedTag = expected.tagName;
1319
1246
  if (boundEl.tagName !== expectedTag)
1320
1247
  throw rowStructureError(index, boundEl.tagName, expectedTag);
1321
1248
  }
@@ -1597,7 +1524,7 @@ function morphStaticChange(rootEl, prev, next, cache, ownedItems) {
1597
1524
  }
1598
1525
  const focusSnap = captureFocus(live);
1599
1526
  for (let m = 0; m < lives.length; m++)
1600
- _morphElement(lives[m], tos[m], ownedItems);
1527
+ morphElement(lives[m], tos[m], ownedItems);
1601
1528
  if (focusSnap !== null) restoreFocus(focusSnap);
1602
1529
  return true;
1603
1530
  }
@@ -1638,14 +1565,11 @@ function assertNotInsideMountedTree(rootEl) {
1638
1565
  if (isMounted(ancestor)) throw new Error(NESTED_MOUNT_MSG);
1639
1566
  ancestor = ancestor.parentElement;
1640
1567
  }
1641
- const stack = [];
1642
- for (let i = 0; i < rootEl.children.length; i++)
1643
- stack.push(rootEl.children[i]);
1644
- while (stack.length > 0) {
1645
- const cur = stack.pop();
1568
+ const stack = [...rootEl.children];
1569
+ for (let cur; cur = stack.pop(); ) {
1646
1570
  if (isMounted(cur)) throw new Error(NESTED_MOUNT_MSG);
1647
- if (isOverlayHost(cur)) continue;
1648
- for (let i = 0; i < cur.children.length; i++) stack.push(cur.children[i]);
1571
+ if (!isOverlayHost(cur))
1572
+ for (const child of cur.children) stack.push(child);
1649
1573
  }
1650
1574
  }
1651
1575
  function mount(rootEl, render) {
@@ -1853,14 +1777,10 @@ function runSubsequentRender(rootEl, segment, bindings, renderCtx, prevStaticHtm
1853
1777
  );
1854
1778
  return currentStaticHtml;
1855
1779
  }
1856
- function coerceRenderResult(result) {
1857
- if (result == null || typeof result === "boolean") return "";
1858
- return String(result);
1859
- }
1860
1780
  function resultToSegment(result) {
1861
- return isSafeHtml(result) ? result.__segment ?? { kind: "static", html: result.__html } : { kind: "static", html: coerceRenderResult(result) };
1781
+ return isSafeHtml(result) ? result.__segment ?? { kind: "static", html: result.__html } : { kind: "static", html: coerceText(result) };
1862
1782
  }
1863
1783
 
1864
1784
  export { captureFocus, each, morph, mount, moveNode, restoreFocus };
1865
1785
 
1866
- //# sourceMappingURL=chunk-MFRXN2G4.js.map
1786
+ //# sourceMappingURL=chunk-LE324N5S.js.map