@pithyjs/core 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +513 -0
- package/dist/a11y/focus-trap.d.ts +109 -0
- package/dist/a11y/focus-trap.d.ts.map +1 -0
- package/dist/a11y/focus-trap.js +246 -0
- package/dist/a11y/focus-trap.js.map +1 -0
- package/dist/a11y/index.d.ts +12 -0
- package/dist/a11y/index.d.ts.map +1 -0
- package/dist/a11y/index.js +16 -0
- package/dist/a11y/index.js.map +1 -0
- package/dist/a11y/keyboard-utils.d.ts +165 -0
- package/dist/a11y/keyboard-utils.d.ts.map +1 -0
- package/dist/a11y/keyboard-utils.js +321 -0
- package/dist/a11y/keyboard-utils.js.map +1 -0
- package/dist/a11y/roving-tabindex.d.ts +118 -0
- package/dist/a11y/roving-tabindex.d.ts.map +1 -0
- package/dist/a11y/roving-tabindex.js +249 -0
- package/dist/a11y/roving-tabindex.js.map +1 -0
- package/dist/a11y/skip-link.d.ts +55 -0
- package/dist/a11y/skip-link.d.ts.map +1 -0
- package/dist/a11y/skip-link.js +164 -0
- package/dist/a11y/skip-link.js.map +1 -0
- package/dist/compile/bindSwitchCases.d.ts +16 -0
- package/dist/compile/bindSwitchCases.d.ts.map +1 -0
- package/dist/compile/bindSwitchCases.js +323 -0
- package/dist/compile/bindSwitchCases.js.map +1 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts +14 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -0
- package/dist/compile/binds/bindBoundAttributes.js +57 -0
- package/dist/compile/binds/bindBoundAttributes.js.map +1 -0
- package/dist/compile/binds/bindClassDirectives.d.ts +20 -0
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindClassDirectives.js +94 -0
- package/dist/compile/binds/bindClassDirectives.js.map +1 -0
- package/dist/compile/binds/bindComponentsTags.d.ts +17 -0
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -0
- package/dist/compile/binds/bindComponentsTags.js +355 -0
- package/dist/compile/binds/bindComponentsTags.js.map +1 -0
- package/dist/compile/binds/bindConditionals.d.ts +16 -0
- package/dist/compile/binds/bindConditionals.d.ts.map +1 -0
- package/dist/compile/binds/bindConditionals.js +102 -0
- package/dist/compile/binds/bindConditionals.js.map +1 -0
- package/dist/compile/binds/bindDefaultTwoWay.d.ts +35 -0
- package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -0
- package/dist/compile/binds/bindDefaultTwoWay.js +128 -0
- package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -0
- package/dist/compile/binds/bindDeferDirectives.d.ts +21 -0
- package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindDeferDirectives.js +465 -0
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -0
- package/dist/compile/binds/bindErrorBoundary.d.ts +71 -0
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -0
- package/dist/compile/binds/bindErrorBoundary.js +389 -0
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -0
- package/dist/compile/binds/bindEventHandlers.d.ts +17 -0
- package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -0
- package/dist/compile/binds/bindEventHandlers.js +174 -0
- package/dist/compile/binds/bindEventHandlers.js.map +1 -0
- package/dist/compile/binds/bindRefDirectives.d.ts +14 -0
- package/dist/compile/binds/bindRefDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindRefDirectives.js +35 -0
- package/dist/compile/binds/bindRefDirectives.js.map +1 -0
- package/dist/compile/binds/bindTextInterpolations.d.ts +16 -0
- package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -0
- package/dist/compile/binds/bindTextInterpolations.js +408 -0
- package/dist/compile/binds/bindTextInterpolations.js.map +1 -0
- package/dist/compile/binds/directiveRegistry.d.ts +46 -0
- package/dist/compile/binds/directiveRegistry.d.ts.map +1 -0
- package/dist/compile/binds/directiveRegistry.js +50 -0
- package/dist/compile/binds/directiveRegistry.js.map +1 -0
- package/dist/compile/compileExpression.d.ts +10 -0
- package/dist/compile/compileExpression.d.ts.map +1 -0
- package/dist/compile/compileExpression.js +26 -0
- package/dist/compile/compileExpression.js.map +1 -0
- package/dist/compile/compileNodes.d.ts +32 -0
- package/dist/compile/compileNodes.d.ts.map +1 -0
- package/dist/compile/compileNodes.js +104 -0
- package/dist/compile/compileNodes.js.map +1 -0
- package/dist/compile/compileTemplate.d.ts +64 -0
- package/dist/compile/compileTemplate.d.ts.map +1 -0
- package/dist/compile/compileTemplate.js +157 -0
- package/dist/compile/compileTemplate.js.map +1 -0
- package/dist/compile/contentProjection.d.ts +29 -0
- package/dist/compile/contentProjection.d.ts.map +1 -0
- package/dist/compile/contentProjection.js +210 -0
- package/dist/compile/contentProjection.js.map +1 -0
- package/dist/compile/forLoops/bindForLoops.d.ts +21 -0
- package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -0
- package/dist/compile/forLoops/bindForLoops.js +151 -0
- package/dist/compile/forLoops/bindForLoops.js.map +1 -0
- package/dist/compile/forLoops/createLoopManager.d.ts +51 -0
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -0
- package/dist/compile/forLoops/createLoopManager.js +429 -0
- package/dist/compile/forLoops/createLoopManager.js.map +1 -0
- package/dist/compile/forLoops/index.d.ts +6 -0
- package/dist/compile/forLoops/index.d.ts.map +1 -0
- package/dist/compile/forLoops/index.js +8 -0
- package/dist/compile/forLoops/index.js.map +1 -0
- package/dist/compile/forLoops/loopHelpers.d.ts +33 -0
- package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -0
- package/dist/compile/forLoops/loopHelpers.js +69 -0
- package/dist/compile/forLoops/loopHelpers.js.map +1 -0
- package/dist/compile/forLoops/loopSignals.d.ts +36 -0
- package/dist/compile/forLoops/loopSignals.d.ts.map +1 -0
- package/dist/compile/forLoops/loopSignals.js +64 -0
- package/dist/compile/forLoops/loopSignals.js.map +1 -0
- package/dist/compile/forLoops/loopTraversal.d.ts +18 -0
- package/dist/compile/forLoops/loopTraversal.d.ts.map +1 -0
- package/dist/compile/forLoops/loopTraversal.js +38 -0
- package/dist/compile/forLoops/loopTraversal.js.map +1 -0
- package/dist/compile/handleConditionalChain.d.ts +15 -0
- package/dist/compile/handleConditionalChain.d.ts.map +1 -0
- package/dist/compile/handleConditionalChain.js +181 -0
- package/dist/compile/handleConditionalChain.js.map +1 -0
- package/dist/compile/index.d.ts +15 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +19 -0
- package/dist/compile/index.js.map +1 -0
- package/dist/compile/injectScopedStyle.d.ts +16 -0
- package/dist/compile/injectScopedStyle.d.ts.map +1 -0
- package/dist/compile/injectScopedStyle.js +50 -0
- package/dist/compile/injectScopedStyle.js.map +1 -0
- package/dist/compile/nodeExpando.d.ts +12 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -0
- package/dist/compile/nodeExpando.js +4 -0
- package/dist/compile/nodeExpando.js.map +1 -0
- package/dist/compile/parseHtml.d.ts +70 -0
- package/dist/compile/parseHtml.d.ts.map +1 -0
- package/dist/compile/parseHtml.js +164 -0
- package/dist/compile/parseHtml.js.map +1 -0
- package/dist/compile/pithyTreeToDom.d.ts +16 -0
- package/dist/compile/pithyTreeToDom.d.ts.map +1 -0
- package/dist/compile/pithyTreeToDom.js +118 -0
- package/dist/compile/pithyTreeToDom.js.map +1 -0
- package/dist/compile/renderChildren.d.ts +50 -0
- package/dist/compile/renderChildren.d.ts.map +1 -0
- package/dist/compile/renderChildren.js +76 -0
- package/dist/compile/renderChildren.js.map +1 -0
- package/dist/compile/ssrMode.d.ts +17 -0
- package/dist/compile/ssrMode.d.ts.map +1 -0
- package/dist/compile/ssrMode.js +20 -0
- package/dist/compile/ssrMode.js.map +1 -0
- package/dist/compile/textValue.d.ts +28 -0
- package/dist/compile/textValue.d.ts.map +1 -0
- package/dist/compile/textValue.js +30 -0
- package/dist/compile/textValue.js.map +1 -0
- package/dist/config/index.d.ts +37 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +16 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/ref-signal.interface.d.ts +6 -0
- package/dist/interfaces/ref-signal.interface.d.ts.map +1 -0
- package/dist/interfaces/ref-signal.interface.js +2 -0
- package/dist/interfaces/ref-signal.interface.js.map +1 -0
- package/dist/interfaces/ref.interface.d.ts +5 -0
- package/dist/interfaces/ref.interface.d.ts.map +1 -0
- package/dist/interfaces/ref.interface.js +2 -0
- package/dist/interfaces/ref.interface.js.map +1 -0
- package/dist/runtime/applyBindings.d.ts +36 -0
- package/dist/runtime/applyBindings.d.ts.map +1 -0
- package/dist/runtime/applyBindings.js +165 -0
- package/dist/runtime/applyBindings.js.map +1 -0
- package/dist/runtime/bindings/applyComponent.d.ts +3 -0
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -0
- package/dist/runtime/bindings/applyComponent.js +190 -0
- package/dist/runtime/bindings/applyComponent.js.map +1 -0
- package/dist/runtime/bindings/applyDefer.d.ts +11 -0
- package/dist/runtime/bindings/applyDefer.d.ts.map +1 -0
- package/dist/runtime/bindings/applyDefer.js +422 -0
- package/dist/runtime/bindings/applyDefer.js.map +1 -0
- package/dist/runtime/bindings/applySimple.d.ts +11 -0
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -0
- package/dist/runtime/bindings/applySimple.js +346 -0
- package/dist/runtime/bindings/applySimple.js.map +1 -0
- package/dist/runtime/bindings/applyStructural.d.ts +5 -0
- package/dist/runtime/bindings/applyStructural.d.ts.map +1 -0
- package/dist/runtime/bindings/applyStructural.js +312 -0
- package/dist/runtime/bindings/applyStructural.js.map +1 -0
- package/dist/runtime/bindings/helpers.d.ts +56 -0
- package/dist/runtime/bindings/helpers.d.ts.map +1 -0
- package/dist/runtime/bindings/helpers.js +121 -0
- package/dist/runtime/bindings/helpers.js.map +1 -0
- package/dist/runtime/bindings/index.d.ts +7 -0
- package/dist/runtime/bindings/index.d.ts.map +1 -0
- package/dist/runtime/bindings/index.js +6 -0
- package/dist/runtime/bindings/index.js.map +1 -0
- package/dist/runtime/bindings/types.d.ts +105 -0
- package/dist/runtime/bindings/types.d.ts.map +1 -0
- package/dist/runtime/bindings/types.js +5 -0
- package/dist/runtime/bindings/types.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +59 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +82 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/createContextProxy.d.ts +10 -0
- package/dist/runtime/createContextProxy.d.ts.map +1 -0
- package/dist/runtime/createContextProxy.js +45 -0
- package/dist/runtime/createContextProxy.js.map +1 -0
- package/dist/runtime/deferHelpers.d.ts +49 -0
- package/dist/runtime/deferHelpers.d.ts.map +1 -0
- package/dist/runtime/deferHelpers.js +65 -0
- package/dist/runtime/deferHelpers.js.map +1 -0
- package/dist/runtime/html.d.ts +23 -0
- package/dist/runtime/html.d.ts.map +1 -0
- package/dist/runtime/html.js +97 -0
- package/dist/runtime/html.js.map +1 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +21 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/lazy.d.ts +144 -0
- package/dist/runtime/lazy.d.ts.map +1 -0
- package/dist/runtime/lazy.js +295 -0
- package/dist/runtime/lazy.js.map +1 -0
- package/dist/runtime/module-cache.d.ts +78 -0
- package/dist/runtime/module-cache.d.ts.map +1 -0
- package/dist/runtime/module-cache.js +109 -0
- package/dist/runtime/module-cache.js.map +1 -0
- package/dist/runtime/onDestroy.d.ts +29 -0
- package/dist/runtime/onDestroy.d.ts.map +1 -0
- package/dist/runtime/onDestroy.js +66 -0
- package/dist/runtime/onDestroy.js.map +1 -0
- package/dist/runtime/parseIdentifiersFromTemplate.d.ts +17 -0
- package/dist/runtime/parseIdentifiersFromTemplate.d.ts.map +1 -0
- package/dist/runtime/parseIdentifiersFromTemplate.js +68 -0
- package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -0
- package/dist/types/globals.d.ts +18 -0
- package/dist/types/globals.d.ts.map +1 -0
- package/dist/types/globals.js +4 -0
- package/dist/types/globals.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +3 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/ref-signal.utility.d.ts +32 -0
- package/dist/utilities/ref-signal.utility.d.ts.map +1 -0
- package/dist/utilities/ref-signal.utility.js +46 -0
- package/dist/utilities/ref-signal.utility.js.map +1 -0
- package/dist/utilities/ref.untility.d.ts +37 -0
- package/dist/utilities/ref.untility.d.ts.map +1 -0
- package/dist/utilities/ref.untility.js +47 -0
- package/dist/utilities/ref.untility.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.directive.loop-manager",
|
|
4
|
+
"title": "Advanced Loop Manager",
|
|
5
|
+
"category": "directive"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { batch } from '@pithyjs/signals';
|
|
9
|
+
import { pithyTreeToDom } from '../pithyTreeToDom';
|
|
10
|
+
import { bindForLoops } from './bindForLoops';
|
|
11
|
+
import { flashUpdate } from '../binds/bindTextInterpolations';
|
|
12
|
+
import { bindTemplateDirectives } from '..';
|
|
13
|
+
import { bindConditionals } from '../binds/bindConditionals';
|
|
14
|
+
import { bindSwitchCases } from '../bindSwitchCases';
|
|
15
|
+
import { createLoopSignals, updateLoopSignals, createLoopContext, } from './loopSignals';
|
|
16
|
+
import { safeInsertBefore, markElementsAsLoopGenerated, createItemRange, wrapInRange, detachRange, } from './loopHelpers';
|
|
17
|
+
import { findAllNestedLoopNodes } from './loopTraversal';
|
|
18
|
+
import { nodeExpando } from '../nodeExpando';
|
|
19
|
+
/** First real element between [start..end] to use as a flash target. */
|
|
20
|
+
function firstElInRange(start, end) {
|
|
21
|
+
let n = start.nextSibling;
|
|
22
|
+
while (n && n !== end) {
|
|
23
|
+
if (n.nodeType === Node.ELEMENT_NODE)
|
|
24
|
+
return n;
|
|
25
|
+
n = n.nextSibling;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/** Extract inclusive [start..end] into a fragment (moving the range intact). */
|
|
30
|
+
function collectRange(start, end) {
|
|
31
|
+
const frag = document.createDocumentFragment();
|
|
32
|
+
let n = start;
|
|
33
|
+
while (n) {
|
|
34
|
+
const next = n.nextSibling;
|
|
35
|
+
frag.appendChild(n);
|
|
36
|
+
if (n === end)
|
|
37
|
+
break;
|
|
38
|
+
n = next;
|
|
39
|
+
}
|
|
40
|
+
return frag;
|
|
41
|
+
}
|
|
42
|
+
/** Compare only shallow, non-object fields to decide if update flash is meaningful. */
|
|
43
|
+
function shallowChangedIgnoringObjects(a, b) {
|
|
44
|
+
if (a === b)
|
|
45
|
+
return false;
|
|
46
|
+
if (typeof a !== 'object' || a == null || typeof b !== 'object' || b == null)
|
|
47
|
+
return true;
|
|
48
|
+
const ar = a;
|
|
49
|
+
const br = b;
|
|
50
|
+
const keys = new Set([...Object.keys(ar), ...Object.keys(br)]);
|
|
51
|
+
for (const k of keys) {
|
|
52
|
+
const va = ar[k];
|
|
53
|
+
const vb = br[k];
|
|
54
|
+
const objA = va && typeof va === 'object';
|
|
55
|
+
const objB = vb && typeof vb === 'object';
|
|
56
|
+
if (objA || objB)
|
|
57
|
+
continue; // ignore nested objects/arrays (child loops will flash)
|
|
58
|
+
if (va !== vb)
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
function shouldFlashUpdate(policy, prevItem, nextItem) {
|
|
64
|
+
switch (policy) {
|
|
65
|
+
case 'none':
|
|
66
|
+
return false;
|
|
67
|
+
case 'identity':
|
|
68
|
+
return prevItem !== nextItem;
|
|
69
|
+
case 'shallow-nested-ignored':
|
|
70
|
+
return shallowChangedIgnoringObjects(prevItem, nextItem);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Clone a cached template fragment and restore JS metadata properties via parallel walk. */
|
|
74
|
+
function cloneFragmentWithContext(template, ctx) {
|
|
75
|
+
const clone = template.cloneNode(true);
|
|
76
|
+
restoreNodeMetadata(template, clone, ctx);
|
|
77
|
+
return clone;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Walk source and target trees in parallel, copying metadata from source to target.
|
|
81
|
+
* `__pithyCtx` is set to the new `ctx` (not copied from source).
|
|
82
|
+
*/
|
|
83
|
+
function restoreNodeMetadata(source, target, ctx) {
|
|
84
|
+
const src = nodeExpando(source);
|
|
85
|
+
const tgt = nodeExpando(target);
|
|
86
|
+
if (src.__pithyCtx !== undefined)
|
|
87
|
+
tgt.__pithyCtx = ctx;
|
|
88
|
+
if (src.__pithyNode !== undefined)
|
|
89
|
+
tgt.__pithyNode = src.__pithyNode;
|
|
90
|
+
if (src.__nodeId !== undefined)
|
|
91
|
+
tgt.__nodeId = src.__nodeId;
|
|
92
|
+
if (src.__slotName !== undefined)
|
|
93
|
+
tgt.__slotName = src.__slotName;
|
|
94
|
+
// Slot fallback factory captures context — recreate with new ctx
|
|
95
|
+
const srcNode = src.__pithyNode;
|
|
96
|
+
if (src.__fallbackFactory !== undefined &&
|
|
97
|
+
srcNode?.fallbackChildren?.length) {
|
|
98
|
+
tgt.__fallbackFactory = () => pithyTreeToDom(srcNode.fallbackChildren, ctx);
|
|
99
|
+
}
|
|
100
|
+
// Walk children in parallel (cloneNode preserves child count/order)
|
|
101
|
+
const srcChildren = source.childNodes;
|
|
102
|
+
const tgtChildren = target.childNodes;
|
|
103
|
+
for (let i = 0; i < srcChildren.length; i++) {
|
|
104
|
+
restoreNodeMetadata(srcChildren[i], tgtChildren[i], ctx);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** @codexApi {"parent":"pithy.directive.loop-manager","name":"createLoopManager","stability":"stable","signature":"<T>(options: LoopManagerOptions<T>) => LoopManager<T>"} */
|
|
108
|
+
export function createLoopManager({ anchor, trackByFn, parentCtx, itemVar, indexVar, countVar, firstVar, lastVar, evenVar, oddVar, templateNodes, }) {
|
|
109
|
+
// Map of key -> LoopItem (stable across updates as long as key is stable)
|
|
110
|
+
const items = new Map();
|
|
111
|
+
let cachedNestedLoopNodes = null;
|
|
112
|
+
let cachedTemplateFrag = null;
|
|
113
|
+
/**
|
|
114
|
+
* Update the loop to reflect the given collection:
|
|
115
|
+
* - Diff keys (remove missing, add new).
|
|
116
|
+
* - If churn is heavy: rebuild in a single batch (fast path).
|
|
117
|
+
* - Else: compute minimal moves (LIS - Longest Increasing Subsequence), update signals, and reorder DOM ranges.
|
|
118
|
+
*/
|
|
119
|
+
function update(collection, node) {
|
|
120
|
+
const liveParent = anchor.parentNode;
|
|
121
|
+
// Flashing Policy
|
|
122
|
+
const FLASH_ON_INSERT = true;
|
|
123
|
+
const FLASH_ON_MOVE = false; // moves typically aren't "re-renders"
|
|
124
|
+
const FLASH_ON_UPDATE = 'shallow-nested-ignored';
|
|
125
|
+
// NOTE: We intentionally do NOT wrap the entire update() in batch().
|
|
126
|
+
// createLoopItem builds DOM via pithyTreeToDom which creates reactive
|
|
127
|
+
// effects. If those effects are deferred by an outer batch, the flush
|
|
128
|
+
// can re-trigger the parent effect (in For.ts) causing infinite recursion.
|
|
129
|
+
// Per-item batch() around signal updates is safe and sufficient.
|
|
130
|
+
// Key Diff
|
|
131
|
+
const newKeys = collection.map((it, idx) => trackByFn(it, idx));
|
|
132
|
+
const newKeySet = new Set(newKeys);
|
|
133
|
+
// Dev-time guard for duplicate keys (can corrupt the map & DOM)
|
|
134
|
+
if (import.meta.env?.DEV) {
|
|
135
|
+
const seen = new Set();
|
|
136
|
+
for (const k of newKeys) {
|
|
137
|
+
if (seen.has(k)) {
|
|
138
|
+
console.warn('[loop] duplicate key detected:', k, {
|
|
139
|
+
node,
|
|
140
|
+
collection,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
seen.add(k);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Remove items that no longer exist
|
|
147
|
+
let removedCount = 0;
|
|
148
|
+
items.forEach((loopItem, key) => {
|
|
149
|
+
if (!newKeySet.has(key)) {
|
|
150
|
+
loopItem.destroy(); // unsubscribes + removes its DOM range
|
|
151
|
+
items.delete(key);
|
|
152
|
+
removedCount++;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
// Count additions
|
|
156
|
+
const addedCount = newKeys.reduce((acc, k) => acc + (items.has(k) ? 0 : 1), 0);
|
|
157
|
+
// Churn heuristic (how much of the list changed)
|
|
158
|
+
const n = newKeys.length;
|
|
159
|
+
const churn = (addedCount + removedCount) / Math.max(1, n);
|
|
160
|
+
// Rebuild Fast-Path
|
|
161
|
+
// For very heavy churn, a single rebuild is often faster than many moves.
|
|
162
|
+
const REBUILD_THRESHOLD = 0.5;
|
|
163
|
+
if (churn > REBUILD_THRESHOLD) {
|
|
164
|
+
const batchFrag = document.createDocumentFragment();
|
|
165
|
+
for (let idx = 0; idx < collection.length; idx++) {
|
|
166
|
+
const key = newKeys[idx];
|
|
167
|
+
const item = collection[idx];
|
|
168
|
+
const existing = items.get(key);
|
|
169
|
+
if (existing) {
|
|
170
|
+
// Update item + positional signals in a single batch to avoid double effect firing
|
|
171
|
+
const prev = existing.signals.itemSig();
|
|
172
|
+
batch(() => {
|
|
173
|
+
if (prev !== item) {
|
|
174
|
+
existing.signals.itemSig.set(item);
|
|
175
|
+
}
|
|
176
|
+
updateLoopSignals(existing.signals, idx, collection.length);
|
|
177
|
+
});
|
|
178
|
+
if (prev !== item && shouldFlashUpdate(FLASH_ON_UPDATE, prev, item)) {
|
|
179
|
+
const el = firstElInRange(existing.start, existing.end);
|
|
180
|
+
if (el)
|
|
181
|
+
flashUpdate(el);
|
|
182
|
+
}
|
|
183
|
+
// Move entire range into the batchFrag fragment
|
|
184
|
+
batchFrag.appendChild(collectRange(existing.start, existing.end));
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// Create new item
|
|
188
|
+
if (!node && !templateNodes)
|
|
189
|
+
continue;
|
|
190
|
+
const created = createLoopItem(node, item, idx, collection.length, key);
|
|
191
|
+
items.set(key, created);
|
|
192
|
+
batchFrag.appendChild(created.fragment);
|
|
193
|
+
if (FLASH_ON_INSERT) {
|
|
194
|
+
const el = firstElInRange(created.start, created.end);
|
|
195
|
+
if (el)
|
|
196
|
+
flashUpdate(el);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Insert everything at once before the anchor
|
|
201
|
+
safeInsertBefore(liveParent, batchFrag, anchor);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// Minimal-Move Path (LIS)
|
|
205
|
+
// Goal: only move items that are out of order (items in LIS keep their place).
|
|
206
|
+
// Current DOM order of existing items (sort by document position)
|
|
207
|
+
const existingItems = Array.from(items.values());
|
|
208
|
+
existingItems.sort((a, b) => {
|
|
209
|
+
const pos = a.start.compareDocumentPosition(b.start);
|
|
210
|
+
// if a follows b, put b first (i.e., a after b => return 1)
|
|
211
|
+
if (pos & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
212
|
+
return -1;
|
|
213
|
+
return 1;
|
|
214
|
+
});
|
|
215
|
+
const oldOrder = existingItems.map(i => i.key);
|
|
216
|
+
// Map key -> new position
|
|
217
|
+
const newPos = new Map();
|
|
218
|
+
newKeys.forEach((k, i) => newPos.set(k, i));
|
|
219
|
+
// Sequence of positions for old items that still exist
|
|
220
|
+
const seq = [];
|
|
221
|
+
const seqKeys = [];
|
|
222
|
+
for (const k of oldOrder) {
|
|
223
|
+
const p = newPos.get(k);
|
|
224
|
+
if (p != null) {
|
|
225
|
+
seq.push(p);
|
|
226
|
+
seqKeys.push(k);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// Compute LIS over positions and mark keys to keep (no move)
|
|
230
|
+
const lisIdxs = lis(seq); // indices into seq[]
|
|
231
|
+
const keep = new Set(lisIdxs.map(i => seqKeys[i]));
|
|
232
|
+
// Reorder by iterating the new order backwards and inserting before a moving cursor
|
|
233
|
+
let cursor = anchor;
|
|
234
|
+
for (let idx = collection.length - 1; idx >= 0; idx--) {
|
|
235
|
+
const item = collection[idx];
|
|
236
|
+
const key = newKeys[idx];
|
|
237
|
+
const existing = items.get(key);
|
|
238
|
+
if (existing) {
|
|
239
|
+
// Update item + positional signals in a single batch to avoid double effect firing
|
|
240
|
+
const prev = existing.signals.itemSig();
|
|
241
|
+
batch(() => {
|
|
242
|
+
if (prev !== item) {
|
|
243
|
+
existing.signals.itemSig.set(item);
|
|
244
|
+
}
|
|
245
|
+
updateLoopSignals(existing.signals, idx, collection.length);
|
|
246
|
+
});
|
|
247
|
+
if (prev !== item && shouldFlashUpdate(FLASH_ON_UPDATE, prev, item)) {
|
|
248
|
+
const el = firstElInRange(existing.start, existing.end);
|
|
249
|
+
if (el)
|
|
250
|
+
flashUpdate(el);
|
|
251
|
+
}
|
|
252
|
+
if (keep.has(key)) {
|
|
253
|
+
// Already in good relative position, don't move; just advance cursor
|
|
254
|
+
cursor = existing.start;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// Move the entire range right before the cursor
|
|
258
|
+
const rangeFrag = collectRange(existing.start, existing.end);
|
|
259
|
+
safeInsertBefore(liveParent, rangeFrag, cursor);
|
|
260
|
+
if (FLASH_ON_MOVE) {
|
|
261
|
+
const el = firstElInRange(existing.start, existing.end);
|
|
262
|
+
if (el)
|
|
263
|
+
flashUpdate(el);
|
|
264
|
+
}
|
|
265
|
+
cursor = existing.start;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// New item: create and insert before cursor
|
|
270
|
+
if (!node && !templateNodes)
|
|
271
|
+
continue;
|
|
272
|
+
const created = createLoopItem(node, item, idx, collection.length, key);
|
|
273
|
+
items.set(key, created);
|
|
274
|
+
safeInsertBefore(liveParent, created.fragment, cursor);
|
|
275
|
+
if (FLASH_ON_INSERT) {
|
|
276
|
+
const el = firstElInRange(created.start, created.end);
|
|
277
|
+
if (el)
|
|
278
|
+
flashUpdate(el);
|
|
279
|
+
}
|
|
280
|
+
cursor = created.start;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Create a new LoopItem:
|
|
286
|
+
* - Build the item's DOM from the AST node and local ctx.
|
|
287
|
+
* - Tag top-level elements with __pithyCtx (so events resolve nearest context).
|
|
288
|
+
* - Cache & tag nested loop hosts to skip parent text-binding.
|
|
289
|
+
* - Bind template directives first; then bind nested loops inside this item.
|
|
290
|
+
* - Wrap the item range with [start..end] markers (for move/remove).
|
|
291
|
+
*/
|
|
292
|
+
function createLoopItem(node, item, idx, total, key) {
|
|
293
|
+
var _a;
|
|
294
|
+
const signals = createLoopSignals(item, idx, total);
|
|
295
|
+
const ctx = createLoopContext(parentCtx, signals, itemVar, indexVar, countVar, firstVar, lastVar, evenVar, oddVar);
|
|
296
|
+
// 1) Build static DOM for this item
|
|
297
|
+
let fragmentFromNode;
|
|
298
|
+
if (!cachedTemplateFrag) {
|
|
299
|
+
// First item: build template from AST once and cache it.
|
|
300
|
+
// Use parentCtx so the cached template does not retain per-item signals.
|
|
301
|
+
// restoreNodeMetadata replaces __pithyCtx with the real per-item ctx on each clone.
|
|
302
|
+
if (templateNodes) {
|
|
303
|
+
cachedTemplateFrag = pithyTreeToDom(templateNodes, parentCtx);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
const nodeForRender = { ...node, directives: { ...node.directives } };
|
|
307
|
+
delete nodeForRender.directives.for;
|
|
308
|
+
cachedTemplateFrag = pithyTreeToDom([nodeForRender], parentCtx);
|
|
309
|
+
markElementsAsLoopGenerated(cachedTemplateFrag, node);
|
|
310
|
+
}
|
|
311
|
+
// Clone for this item (cache stays pristine)
|
|
312
|
+
fragmentFromNode = cloneFragmentWithContext(cachedTemplateFrag, ctx);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
// Subsequent items: clone cached DOM + restore metadata
|
|
316
|
+
fragmentFromNode = cloneFragmentWithContext(cachedTemplateFrag, ctx);
|
|
317
|
+
}
|
|
318
|
+
// 2) Tag local context on top-level elements for nearest-ctx event resolution
|
|
319
|
+
for (const n of Array.from(fragmentFromNode.childNodes)) {
|
|
320
|
+
if (n.nodeType === Node.ELEMENT_NODE)
|
|
321
|
+
nodeExpando(n).__pithyCtx = ctx;
|
|
322
|
+
}
|
|
323
|
+
// 3) Find nested loop nodes ONCE per AST source (cache on the node or in closure)
|
|
324
|
+
const astChildren = templateNodes ?? (node.children || []);
|
|
325
|
+
const allNestedLoopNodes = templateNodes
|
|
326
|
+
? (cachedNestedLoopNodes ?? (cachedNestedLoopNodes = templateNodes.flatMap(tn => {
|
|
327
|
+
// Include root template nodes that themselves carry @for
|
|
328
|
+
// (findAllNestedLoopNodes skips the root, which is correct for
|
|
329
|
+
// the directive path but misses top-level loops in templateNodes)
|
|
330
|
+
const nested = findAllNestedLoopNodes(tn);
|
|
331
|
+
if (tn.directives?.for)
|
|
332
|
+
nested.unshift(tn);
|
|
333
|
+
return nested;
|
|
334
|
+
})))
|
|
335
|
+
: ((_a = node).__nested ?? (_a.__nested = findAllNestedLoopNodes(node)));
|
|
336
|
+
// 4) Build a data-pid => element map for this fragment and tag hosts to skip text-binding
|
|
337
|
+
const pidMap = new Map();
|
|
338
|
+
fragmentFromNode
|
|
339
|
+
.querySelectorAll?.('[data-pid]')
|
|
340
|
+
.forEach(el => pidMap.set(el.getAttribute('data-pid'), el));
|
|
341
|
+
for (const n of allNestedLoopNodes) {
|
|
342
|
+
if (!n.nodeId)
|
|
343
|
+
continue;
|
|
344
|
+
const host = pidMap.get(n.nodeId);
|
|
345
|
+
if (host)
|
|
346
|
+
nodeExpando(host).__pithySkipText = true; // parent text binder must skip this subtree
|
|
347
|
+
}
|
|
348
|
+
// 5) Bind structural directives in the same order as compileTemplate
|
|
349
|
+
const disposers = [];
|
|
350
|
+
// 5a) Bind switch/case statements FIRST
|
|
351
|
+
// IMPORTANT: bindSwitchCases must run BEFORE bindConditionals!
|
|
352
|
+
// Switch cases clone their content from DOM - if bindConditionals runs first,
|
|
353
|
+
// it removes @if/@else elements and replaces them with placeholders, so the
|
|
354
|
+
// cloned switch case content would be missing the conditional elements.
|
|
355
|
+
bindSwitchCases(astChildren, fragmentFromNode, ctx, new Set(), disposers);
|
|
356
|
+
// 5b) Bind conditionals inside this loop item (with loop context)
|
|
357
|
+
// This handles @if/@else inside each loop item
|
|
358
|
+
// Pass disposers so conditional effects are properly cleaned up when item is destroyed
|
|
359
|
+
// Note: Conditionals inside switch cases are already gone from the DOM (removed by switch),
|
|
360
|
+
// so this will only process conditionals outside switch blocks.
|
|
361
|
+
const conditionalProcessedIds = bindConditionals(astChildren, fragmentFromNode, ctx, new Set(), disposers);
|
|
362
|
+
// 5c) Bind nested loops (pass processedNodeIds to skip loops inside conditionals)
|
|
363
|
+
const nestedLoopDisposers = [];
|
|
364
|
+
bindForLoops(allNestedLoopNodes, fragmentFromNode, ctx, nestedLoopDisposers, conditionalProcessedIds);
|
|
365
|
+
disposers.push(...nestedLoopDisposers);
|
|
366
|
+
// 5d) Bind template directives (text interpolations, events, etc.)
|
|
367
|
+
bindTemplateDirectives(fragmentFromNode, ctx, disposers);
|
|
368
|
+
// 5e) Mark top-level elements to prevent parent from re-binding their text content
|
|
369
|
+
for (const n of Array.from(fragmentFromNode.childNodes)) {
|
|
370
|
+
if (n.nodeType === Node.ELEMENT_NODE) {
|
|
371
|
+
nodeExpando(n).__pithySkipText = true;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
// 7) Wrap the whole item in [start..end] comments so we can move/remove it as a unit
|
|
375
|
+
const { start, end } = createItemRange(key);
|
|
376
|
+
const grouped = wrapInRange(start, fragmentFromNode, end);
|
|
377
|
+
// 8) Cleanup function: unsubscribe effects/listeners and detach DOM range
|
|
378
|
+
const destroy = () => {
|
|
379
|
+
for (const d of disposers)
|
|
380
|
+
d();
|
|
381
|
+
detachRange(start, end);
|
|
382
|
+
};
|
|
383
|
+
return { key, fragment: grouped, node, signals, start, end, destroy };
|
|
384
|
+
}
|
|
385
|
+
function destroyAll() {
|
|
386
|
+
items.forEach(item => item.destroy());
|
|
387
|
+
items.clear();
|
|
388
|
+
}
|
|
389
|
+
return { update, destroyAll };
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* O(n log n) Longest Increasing Subsequence.
|
|
393
|
+
* Given an array of numbers `a`, returns the indices into `a` that form
|
|
394
|
+
* a strictly increasing subsequence with maximal length.
|
|
395
|
+
*
|
|
396
|
+
* We use LIS on the sequence of "new positions" for existing items to minimize DOM moves:
|
|
397
|
+
* - Items in the LIS are already in correct relative order and don't need to move.
|
|
398
|
+
* - Only the remaining items are moved to their new positions.
|
|
399
|
+
*/
|
|
400
|
+
function lis(a) {
|
|
401
|
+
const res = []; // res[k] is the index i of the smallest tail of an increasing subsequence of length k+1
|
|
402
|
+
const m = []; // m[i] points to predecessor index for i in the LIS
|
|
403
|
+
for (let i = 0; i < a.length; i++) {
|
|
404
|
+
// binary search in res to find the length of the LIS that a[i] can extend
|
|
405
|
+
let lo = 0, hi = res.length;
|
|
406
|
+
while (lo < hi) {
|
|
407
|
+
const mid = (lo + hi) >> 1;
|
|
408
|
+
if (a[res[mid]] < a[i])
|
|
409
|
+
lo = mid + 1;
|
|
410
|
+
else
|
|
411
|
+
hi = mid;
|
|
412
|
+
}
|
|
413
|
+
// update res and predecessor
|
|
414
|
+
if (lo === res.length)
|
|
415
|
+
res.push(i);
|
|
416
|
+
else
|
|
417
|
+
res[lo] = i;
|
|
418
|
+
m[i] = lo ? res[lo - 1] : -1;
|
|
419
|
+
}
|
|
420
|
+
// reconstruct LIS indices from res/m
|
|
421
|
+
let k = res[res.length - 1];
|
|
422
|
+
const out = [];
|
|
423
|
+
for (let i = res.length - 1; i >= 0; i--) {
|
|
424
|
+
out[i] = k;
|
|
425
|
+
k = m[k];
|
|
426
|
+
}
|
|
427
|
+
return out;
|
|
428
|
+
}
|
|
429
|
+
//# sourceMappingURL=createLoopManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createLoopManager.js","sourceRoot":"","sources":["../../../src/compile/forLoops/createLoopManager.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAiBF,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,2BAA2B,EAC3B,eAAe,EACf,WAAW,EACX,WAAW,GACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAM7C,wEAA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CAAC,EAAE,EAAE,CAAC;QACzC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACX,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/compile/forLoops/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/compile/forLoops/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AAEpC,mBAAmB;AACnB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.directive.loop-helpers",
|
|
4
|
+
"title": "Loop Utility Functions",
|
|
5
|
+
"category": "directive"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* General utility functions for loop operations
|
|
10
|
+
*/
|
|
11
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"safeInsertBefore","stability":"stable","signature":"(parent: Node, newNode: Node, referenceNode: Node | null) => void"} */
|
|
12
|
+
/**
|
|
13
|
+
* Safely inserts a node before a reference node, with fallback to appendChild
|
|
14
|
+
*/
|
|
15
|
+
export declare function safeInsertBefore(parent: Node, newNode: Node, referenceNode: Node | null): void;
|
|
16
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"markElementsAsLoopGenerated","stability":"stable","signature":"(fragment: DocumentFragment, node: { nodeId?: string }) => void"} */
|
|
17
|
+
/**
|
|
18
|
+
* Marks all elements in a fragment as loop-generated for safe cleanup
|
|
19
|
+
* Optimized to use targeted selectors when possible
|
|
20
|
+
*/
|
|
21
|
+
export declare function markElementsAsLoopGenerated(fragment: DocumentFragment, node: {
|
|
22
|
+
nodeId?: string;
|
|
23
|
+
}): void;
|
|
24
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"createItemRange","stability":"stable","signature":"(key: string) => { start: Comment; end: Comment }"} */
|
|
25
|
+
export declare function createItemRange(key: string): {
|
|
26
|
+
start: Comment;
|
|
27
|
+
end: Comment;
|
|
28
|
+
};
|
|
29
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"wrapInRange","stability":"stable","signature":"(start: Comment, content: DocumentFragment | HTMLElement, end: Comment) => DocumentFragment"} */
|
|
30
|
+
export declare function wrapInRange(start: Comment, content: DocumentFragment | HTMLElement, end: Comment): DocumentFragment;
|
|
31
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"detachRange","stability":"stable","signature":"(start: Comment, end: Comment) => void"} */
|
|
32
|
+
export declare function detachRange(start: Comment, end: Comment): void;
|
|
33
|
+
//# sourceMappingURL=loopHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopHelpers.d.ts","sourceRoot":"","sources":["../../../src/compile/forLoops/loopHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;GAEG;AAEH,yLAAyL;AACzL;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,IAAI,EACZ,OAAO,EAAE,IAAI,EACb,aAAa,EAAE,IAAI,GAAG,IAAI,GACzB,IAAI,CASN;AAED,kMAAkM;AAClM;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,gBAAgB,EAC1B,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACxB,IAAI,CAiBN;AAED,wKAAwK;AACxK,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM;;;EAI1C;AAED,8MAA8M;AAC9M,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,gBAAgB,GAAG,WAAW,EACvC,GAAG,EAAE,OAAO,GACX,gBAAgB,CAMlB;AAED,yJAAyJ;AACzJ,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,QASvD"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.directive.loop-helpers",
|
|
4
|
+
"title": "Loop Utility Functions",
|
|
5
|
+
"category": "directive"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* General utility functions for loop operations
|
|
10
|
+
*/
|
|
11
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"safeInsertBefore","stability":"stable","signature":"(parent: Node, newNode: Node, referenceNode: Node | null) => void"} */
|
|
12
|
+
/**
|
|
13
|
+
* Safely inserts a node before a reference node, with fallback to appendChild
|
|
14
|
+
*/
|
|
15
|
+
export function safeInsertBefore(parent, newNode, referenceNode) {
|
|
16
|
+
if (referenceNode && referenceNode.parentNode === parent) {
|
|
17
|
+
parent.insertBefore(newNode, referenceNode);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.warn('[safeInsertBefore] WARNING: referenceNode is NOT in parent; appending at end');
|
|
21
|
+
parent.appendChild(newNode);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"markElementsAsLoopGenerated","stability":"stable","signature":"(fragment: DocumentFragment, node: { nodeId?: string }) => void"} */
|
|
25
|
+
/**
|
|
26
|
+
* Marks all elements in a fragment as loop-generated for safe cleanup
|
|
27
|
+
* Optimized to use targeted selectors when possible
|
|
28
|
+
*/
|
|
29
|
+
export function markElementsAsLoopGenerated(fragment, node) {
|
|
30
|
+
// Optimize: Use more targeted selector if nodeId has hierarchical format
|
|
31
|
+
const selector = node.nodeId && node.nodeId.includes('-')
|
|
32
|
+
? `[data-pid^="${node.nodeId}-"], [data-pid="${node.nodeId}"]`
|
|
33
|
+
: '*';
|
|
34
|
+
fragment.querySelectorAll(selector).forEach(el => {
|
|
35
|
+
el.setAttribute('data-loop-generated', 'true');
|
|
36
|
+
});
|
|
37
|
+
// Also mark any remaining elements that don't have data-pid
|
|
38
|
+
if (selector !== '*') {
|
|
39
|
+
fragment.querySelectorAll('*:not([data-pid])').forEach(el => {
|
|
40
|
+
el.setAttribute('data-loop-generated', 'true');
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"createItemRange","stability":"stable","signature":"(key: string) => { start: Comment; end: Comment }"} */
|
|
45
|
+
export function createItemRange(key) {
|
|
46
|
+
const start = document.createComment(`#for:item:start key="${key}"`);
|
|
47
|
+
const end = document.createComment(`#for:item:end key="${key}"`);
|
|
48
|
+
return { start, end };
|
|
49
|
+
}
|
|
50
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"wrapInRange","stability":"stable","signature":"(start: Comment, content: DocumentFragment | HTMLElement, end: Comment) => DocumentFragment"} */
|
|
51
|
+
export function wrapInRange(start, content, end) {
|
|
52
|
+
const group = document.createDocumentFragment();
|
|
53
|
+
group.appendChild(start);
|
|
54
|
+
group.appendChild(content); // appends all children if it's a fragment
|
|
55
|
+
group.appendChild(end);
|
|
56
|
+
return group;
|
|
57
|
+
}
|
|
58
|
+
/** @codexApi {"parent":"pithy.directive.loop-helpers","name":"detachRange","stability":"stable","signature":"(start: Comment, end: Comment) => void"} */
|
|
59
|
+
export function detachRange(start, end) {
|
|
60
|
+
let n = start.nextSibling;
|
|
61
|
+
while (n && n !== end) {
|
|
62
|
+
const toRemove = n;
|
|
63
|
+
n = n.nextSibling;
|
|
64
|
+
toRemove.parentNode?.removeChild(toRemove);
|
|
65
|
+
}
|
|
66
|
+
start.parentNode?.removeChild(start);
|
|
67
|
+
end.parentNode?.removeChild(end);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=loopHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopHelpers.js","sourceRoot":"","sources":["../../../src/compile/forLoops/loopHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF;;GAEG;AAEH,yLAAyL;AACzL;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAY,EACZ,OAAa,EACb,aAA0B;IAE1B,IAAI,aAAa,IAAI,aAAa,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;QACzD,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9C,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CACV,8EAA8E,CAC/E,CAAC;QACF,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,kMAAkM;AAClM;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAA0B,EAC1B,IAAyB;IAEzB,yEAAyE;IACzE,MAAM,QAAQ,GACZ,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QACtC,CAAC,CAAC,eAAe,IAAI,CAAC,MAAM,mBAAmB,IAAI,CAAC,MAAM,IAAI;QAC9D,CAAC,CAAC,GAAG,CAAC;IAEV,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QAC/C,EAAE,CAAC,YAAY,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,4DAA4D;IAC5D,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QACrB,QAAQ,CAAC,gBA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
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.directive.loop-signals",
|
|
4
|
+
"title": "Loop Reactive Signals",
|
|
5
|
+
"category": "directive"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { Signal } from '@pithyjs/signals';
|
|
9
|
+
export interface LoopSignals {
|
|
10
|
+
itemSig: Signal<unknown>;
|
|
11
|
+
countSig: Signal<number>;
|
|
12
|
+
idxSig: Signal<number>;
|
|
13
|
+
firstSig: Signal<boolean>;
|
|
14
|
+
lastSig: Signal<boolean>;
|
|
15
|
+
evenSig: Signal<boolean>;
|
|
16
|
+
oddSig: Signal<boolean>;
|
|
17
|
+
}
|
|
18
|
+
/** @codexApi {"parent":"pithy.directive.loop-signals","name":"createLoopSignals","stability":"stable","signature":"<T>(item: T, idx: number, total: number) => LoopSignals"} */
|
|
19
|
+
/**
|
|
20
|
+
* Creates all the reactive signals needed for a loop item
|
|
21
|
+
*/
|
|
22
|
+
export declare function createLoopSignals<T>(item: T, idx: number, total: number): LoopSignals;
|
|
23
|
+
/** @codexApi {"parent":"pithy.directive.loop-signals","name":"updateLoopSignals","stability":"stable","signature":"(signals: LoopSignals, idx: number, total: number) => void"} */
|
|
24
|
+
/**
|
|
25
|
+
* Updates all positional signals for a loop item (idx, first, last, even, odd, count)
|
|
26
|
+
* Uses batch() for optimal performance
|
|
27
|
+
*/
|
|
28
|
+
export declare function updateLoopSignals(signals: LoopSignals, idx: number, total: number): void;
|
|
29
|
+
/** @codexApi {"parent":"pithy.directive.loop-signals","name":"createLoopContext","stability":"stable","signature":"(parentCtx: Record<string, unknown>, signals: LoopSignals, itemVar: string, indexVar?: string, countVar?: string, firstVar?: string, lastVar?: string, evenVar?: string, oddVar?: string) => Record<string, unknown>"} */
|
|
30
|
+
/**
|
|
31
|
+
* Creates the context object for a loop item with all necessary signals.
|
|
32
|
+
* Helper signal names (count, first, last, even, odd) can be aliased to
|
|
33
|
+
* avoid shadowing in nested loops.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createLoopContext(parentCtx: Record<string, unknown>, signals: LoopSignals, itemVar: string, indexVar?: string, countVar?: string, firstVar?: string, lastVar?: string, evenVar?: string, oddVar?: string): Record<string, unknown>;
|
|
36
|
+
//# sourceMappingURL=loopSignals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loopSignals.d.ts","sourceRoot":"","sources":["../../../src/compile/forLoops/loopSignals.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAiB,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACzB;AAED,gLAAgL;AAChL;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,IAAI,EAAE,CAAC,EACP,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,WAAW,CAkBb;AAED,mLAAmL;AACnL;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,EACpB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GACZ,IAAI,CASN;AAED,6UAA6U;AAC7U;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,EACjB,QAAQ,SAAU,EAClB,QAAQ,SAAU,EAClB,OAAO,SAAS,EAChB,OAAO,SAAS,EAChB,MAAM,SAAQ,GACb,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWzB"}
|