@pithyjs/core 0.1.0-beta.14 → 0.1.0-beta.15

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.
Files changed (72) hide show
  1. package/README.md +10 -0
  2. package/dist/compile/bindSwitchCases.d.ts.map +1 -1
  3. package/dist/compile/bindSwitchCases.js +14 -7
  4. package/dist/compile/bindSwitchCases.js.map +1 -1
  5. package/dist/compile/binds/bindAfterComponents.d.ts +4 -0
  6. package/dist/compile/binds/bindAfterComponents.d.ts.map +1 -0
  7. package/dist/compile/binds/bindAfterComponents.js +26 -0
  8. package/dist/compile/binds/bindAfterComponents.js.map +1 -0
  9. package/dist/compile/binds/bindAfterProjection.d.ts.map +1 -1
  10. package/dist/compile/binds/bindAfterProjection.js +2 -21
  11. package/dist/compile/binds/bindAfterProjection.js.map +1 -1
  12. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  13. package/dist/compile/binds/bindComponentsTags.js +32 -10
  14. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  15. package/dist/compile/binds/bindErrorBoundary.d.ts +11 -1
  16. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  17. package/dist/compile/binds/bindErrorBoundary.js +44 -9
  18. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  19. package/dist/compile/compileNodes.d.ts.map +1 -1
  20. package/dist/compile/compileNodes.js +2 -0
  21. package/dist/compile/compileNodes.js.map +1 -1
  22. package/dist/compile/compileTemplate.d.ts.map +1 -1
  23. package/dist/compile/compileTemplate.js +2 -0
  24. package/dist/compile/compileTemplate.js.map +1 -1
  25. package/dist/compile/contentProjection.d.ts +3 -0
  26. package/dist/compile/contentProjection.d.ts.map +1 -1
  27. package/dist/compile/contentProjection.js +8 -0
  28. package/dist/compile/contentProjection.js.map +1 -1
  29. package/dist/compile/disposeOrder.d.ts +35 -0
  30. package/dist/compile/disposeOrder.d.ts.map +1 -0
  31. package/dist/compile/disposeOrder.js +81 -0
  32. package/dist/compile/disposeOrder.js.map +1 -0
  33. package/dist/compile/forLoops/bindForLoops.d.ts +1 -1
  34. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
  35. package/dist/compile/forLoops/bindForLoops.js +10 -3
  36. package/dist/compile/forLoops/bindForLoops.js.map +1 -1
  37. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  38. package/dist/compile/forLoops/createLoopManager.js +19 -2
  39. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  40. package/dist/compile/handleConditionalChain.d.ts.map +1 -1
  41. package/dist/compile/handleConditionalChain.js +2 -3
  42. package/dist/compile/handleConditionalChain.js.map +1 -1
  43. package/dist/compile/renderBranch.d.ts +1 -1
  44. package/dist/compile/renderBranch.d.ts.map +1 -1
  45. package/dist/compile/renderBranch.js +5 -3
  46. package/dist/compile/renderBranch.js.map +1 -1
  47. package/dist/compile/renderChildren.d.ts.map +1 -1
  48. package/dist/compile/renderChildren.js +2 -1
  49. package/dist/compile/renderChildren.js.map +1 -1
  50. package/dist/runtime/applyBindings.d.ts.map +1 -1
  51. package/dist/runtime/applyBindings.js +2 -0
  52. package/dist/runtime/applyBindings.js.map +1 -1
  53. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  54. package/dist/runtime/bindings/applyComponent.js +10 -7
  55. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  56. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  57. package/dist/runtime/bindings/applySimple.js +2 -2
  58. package/dist/runtime/bindings/applySimple.js.map +1 -1
  59. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  60. package/dist/runtime/bindings/applyStructural.js +11 -13
  61. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  62. package/dist/runtime/bindings/helpers.d.ts +7 -0
  63. package/dist/runtime/bindings/helpers.d.ts.map +1 -1
  64. package/dist/runtime/bindings/helpers.js +33 -1
  65. package/dist/runtime/bindings/helpers.js.map +1 -1
  66. package/dist/runtime/html.d.ts.map +1 -1
  67. package/dist/runtime/html.js +2 -3
  68. package/dist/runtime/html.js.map +1 -1
  69. package/dist/types/globals.d.ts +2 -0
  70. package/dist/types/globals.d.ts.map +1 -1
  71. package/dist/types/globals.js.map +1 -1
  72. package/package.json +5 -5
package/README.md CHANGED
@@ -281,6 +281,10 @@ The `@for` directive provides keyed, reactive list rendering with:
281
281
  | compileNodes | compile-nodes | `(nodes: PithyNode[], context: Record<string, unknown>) => { el: DocumentFragment; destroy: () => void }` | stable | - |
282
282
  | compileTemplate | renderer | `(html: string, context: Record<string, any>, css?: string, scopeId?: string, importedIdentifiers?: Set<string>) => { el: HTMLElement | DocumentFragment; destroy: () => void }` | stable | - |
283
283
  | bindTemplateDirectives | renderer | `(fragment: DocumentFragment, context: Record<string, any>, disposers: (() => void)[]) => void` | stable | - |
284
+ | anchorDisposer | dispose-order | `<T extends () => void>(dispose: T, node: Node | null | undefined) => T` | internal | - |
285
+ | orderByDocument | dispose-order | `(disposers: (() => void)[]) => void` | internal | - |
286
+ | blockDisposer | dispose-order | `(stop: () => void, clear: () => void, node: Node | null | undefined) => () => void` | internal | - |
287
+ | componentDisposer | dispose-order | `(destroy: unknown, disposeSetup: (() => void) | undefined, node: Node | null | undefined) => (() => void) | undefined` | internal | - |
284
288
  | clearSSRRenderCrash | ssr-crashes | `(el: Element) => void` | internal | - |
285
289
  | resetSSRRenderCrashes | ssr-crashes | `() => void` | stable | - |
286
290
  | collectUnhandledSSRRenderCrashes | ssr-crashes | `() => SSRRenderCrash[]` | stable | - |
@@ -306,6 +310,7 @@ The `@for` directive provides keyed, reactive list rendering with:
306
310
  | buildPidMap | binding-helpers | `(fragment: DocumentFragment) => Map<string, Element>` | internal | - |
307
311
  | buildCommentMap | binding-helpers | `(fragment: DocumentFragment) => Map<string, Comment>` | internal | - |
308
312
  | nearestCtx | binding-helpers | `(el: Node, rootCtx: BindingContext) => BindingContext` | internal | - |
313
+ | spreadLive | binding-helpers | `(...sources: (BindingContext | undefined)[]) => BindingContext` | internal | - |
309
314
  | mergeContexts | binding-helpers | `(context: BindingContext) => BindingContext` | internal | - |
310
315
  | compileWithEvent | binding-helpers | `(expr: string, ctx: BindingContext) => (ev: Event, el: Element) => unknown` | internal | - |
311
316
  <!-- @codex:end -->
@@ -409,6 +414,10 @@ pnpm test -- --watch # Watch mode
409
414
  | compileNodes | - | - | - | Missing unit, integration, e2e |
410
415
  | compileTemplate | - | - | - | Missing unit, integration, e2e |
411
416
  | bindTemplateDirectives | - | - | - | Missing unit, integration, e2e |
417
+ | anchorDisposer | - | - | - | Missing unit, integration, e2e |
418
+ | orderByDocument | - | - | - | Missing unit, integration, e2e |
419
+ | blockDisposer | - | - | - | Missing unit, integration, e2e |
420
+ | componentDisposer | - | - | - | Missing unit, integration, e2e |
412
421
  | clearSSRRenderCrash | - | - | - | Missing unit, integration, e2e |
413
422
  | resetSSRRenderCrashes | - | - | - | Missing unit, integration, e2e |
414
423
  | collectUnhandledSSRRenderCrashes | - | - | - | Missing unit, integration, e2e |
@@ -434,6 +443,7 @@ pnpm test -- --watch # Watch mode
434
443
  | buildPidMap | - | - | - | Missing unit, integration, e2e |
435
444
  | buildCommentMap | - | - | - | Missing unit, integration, e2e |
436
445
  | nearestCtx | - | - | - | Missing unit, integration, e2e |
446
+ | spreadLive | - | - | - | Missing unit, integration, e2e |
437
447
  | mergeContexts | - | - | - | Missing unit, integration, e2e |
438
448
  | compileWithEvent | - | - | - | Missing unit, integration, e2e |
439
449
  <!-- @codex:end -->
@@ -1 +1 @@
1
- {"version":3,"file":"bindSwitchCases.d.ts","sourceRoot":"","sources":["../../src/compile/bindSwitchCases.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQlE;;;GAGG;AACH,kRAAkR;AAClR,wBAAgB,eAAe,CAC7B,KAAK,EAAE,SAAS,EAAE,EAClB,MAAM,EAAE,OAAO,GAAG,gBAAgB,EAClC,GAAG,EAA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category": "directive"
6
6
  }
7
7
  */
8
- import { isDefaultCase } from '@pithyjs/compiler';
8
+ import { isDefaultCase, loopConflictMessage, } from '@pithyjs/compiler';
9
9
  import { effect } from '@pithyjs/signals';
10
10
  import { compileExpression } from './compileExpression.js';
11
11
  import { findAllNestedLoopNodes } from './forLoops/loopTraversal.js';
12
+ import { blockDisposer } from './disposeOrder.js';
12
13
  import { nodeExpando } from './nodeExpando.js';
13
14
  import { clearBranch, renderBranch } from './renderBranch.js';
14
15
  import { isSSRMode } from './ssrMode.js';
@@ -44,7 +45,7 @@ disposers = [] // Collect disposers for cleanup
44
45
  elMap.get(node.nodeId)?.remove();
45
46
  if (import.meta.env?.DEV && !warnedOrphans.has(node)) {
46
47
  warnedOrphans.add(node);
47
- console.warn(`[bindSwitchCases] ${node.directives?.case !== undefined ? '@case' : '@default'} has no @switch parent, or its @switch is on a @for element (BUG-070); <${node.originalTagName ?? node.tagName}> is dropped, as in a build`);
48
+ console.warn(`[bindSwitchCases] ${node.directives?.case !== undefined ? '@case' : '@default'} has no @switch parent, or its @switch is on a @for element, which ignores it; <${node.originalTagName ?? node.tagName}> is dropped, as in a build`);
48
49
  }
49
50
  continue;
50
51
  }
@@ -91,8 +92,10 @@ function isConditionalBranch(node) {
91
92
  export function bindSwitchBlock(switchNode, parentElement, ctx, processedNodeIds, disposers) {
92
93
  const caseNodes = (switchNode.children || []).filter(child => child.type === 'element' &&
93
94
  (child.directives?.case !== undefined || isDefaultCase(child)));
94
- if (caseNodes.length === 0)
95
- return false;
95
+ if (caseNodes.length === 0) {
96
+ removeNonCaseChildren(parentElement, [], switchNode);
97
+ return true;
98
+ }
96
99
  for (const node of caseNodes) {
97
100
  if (node.nodeId)
98
101
  processedNodeIds.add(node.nodeId);
@@ -119,6 +122,7 @@ export function bindSwitchBlock(switchNode, parentElement, ctx, processedNodeIds
119
122
  return true;
120
123
  }
121
124
  const warnedSwitches = new WeakSet();
125
+ const warnedConflicts = new WeakSet();
122
126
  const warnedOrphans = new WeakSet();
123
127
  function removeNonCaseChildren(parentElement, caseElements, switchNode) {
124
128
  const cases = new Set(caseElements);
@@ -131,6 +135,11 @@ function removeNonCaseChildren(parentElement, caseElements, switchNode) {
131
135
  continue;
132
136
  }
133
137
  const node = nodeExpando(child).__pithyNode;
138
+ if (import.meta.env?.DEV && node && !warnedConflicts.has(node)) {
139
+ warnedConflicts.add(node);
140
+ for (const name of node.loopConflicts ?? [])
141
+ console.warn(`[pithy] ${loopConflictMessage(node.originalTagName ?? node.tagName ?? '', name)}`);
142
+ }
134
143
  if (child.nodeType === Node.TEXT_NODE)
135
144
  dropped ?? (dropped = JSON.stringify(child.textContent?.trim()));
136
145
  else if (node?.type === 'slot')
@@ -265,9 +274,7 @@ function handleSwitchBlock(parentElement, caseElements, switchNode, caseNodes, c
265
274
  // 1. When match changes: cleanupCurrentBranch() is called above
266
275
  // 2. When effect stops: cleanupCurrentBranch is in disposers array
267
276
  });
268
- // Add cleanup and effect stop to disposers for proper cleanup on destroy()
269
- disposers.push(cleanupCurrentBranch);
270
- disposers.push(stopEffect);
277
+ disposers.push(blockDisposer(stopEffect, cleanupCurrentBranch, placeholder));
271
278
  }
272
279
  }
273
280
  //# sourceMappingURL=bindSwitchCases.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindSwitchCases.js","sourceRoot":"","sources":["../../src/compile/bindSwitchCases.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,aAAa,EAAkB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,M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,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,EAAE;YAC7B,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC;YAEtC,4CAA4C;YAC5C,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;gBACtC,OAAO;YACT,CAAC;YAED,uDAAuD;YACvD,oBAAoB,EAAE,CAAC;YACvB,kCAAkC;YAClC,kBAAkB,GAAG,UAAU,CAAC;YAChC,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAExC,4DAA4D;YAC5D,gEAAgE;YAChE,mEAAmE;QACrE,CAAC,CAAC,CAAC;QAEH,2EAA2E;QAC3E,SAAS,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACrC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.directive.switch\",\n \"title\": \"@switch directive\",\n \"category\": \"directive\"\n}\n*/\n\nimport { isDefaultCase, type PithyNode } from '@pithyjs/compiler';\nimport { effect } from '@pithyjs/signals';\nimport { compileExpression } from './compileExpression';\nimport { findAllNestedLoopNodes } from './forLoops/loopTraversal';\nimport { nodeExpando } from './nodeExpando';\nimport { clearBranch, renderBranch, type Branch } from './renderBranch';\nimport { isSSRMode } from './ssrMode';\n\n/**\n * Processes switch case directives (@switch, @case, @default) in the template.\n * Identifies switch blocks and delegates their handling to handleSwitchBlock.\n */\n/** @codexApi {\"parent\":\"pithy.directive.switch\",\"name\":\"bindSwitchCases\",\"stability\":\"stable\",\"signature\":\"(nodes: PithyNode[], rootEl: Element | DocumentFragment, ctx: Record<string, unknown>, processedNodeIds?: Set<string>, disposers?: (() => void)[]) => Set<string>\"} */\nexport function bindSwitchCases(\n nodes: PithyNode[],\n rootEl: Element | DocumentFragment,\n ctx: Record<string, unknown>,\n processedNodeIds: Set<string> = new Set(), // Track already processed nodes\n disposers: (() => void)[] = [] // Collect disposers for cleanup\n): Set<string> {\n // Performance optimization: Create a Map of all elements by data-pid\n // This makes element lookups O(1) instead of O(n) with querySelector\n const elMap = new Map<string, Element>();\n if (rootEl instanceof Element || rootEl instanceof DocumentFragment) {\n const elements = rootEl.querySelectorAll('[data-pid]');\n elements.forEach(el => {\n const pid = el.getAttribute('data-pid');\n if (pid) {\n elMap.set(pid, el as Element);\n }\n });\n }\n\n const switchIds = new Set<string>();\n\n for (const node of nodes) {\n if (node.type !== 'element') continue;\n if (\n (node.directives?.case !== undefined || isDefaultCase(node)) &&\n node.nodeId &&\n !processedNodeIds.has(node.nodeId) &&\n !isConditionalBranch(node)\n ) {\n processedNodeIds.add(node.nodeId);\n elMap.get(node.nodeId)?.remove();\n if (import.meta.env?.DEV && !warnedOrphans.has(node)) {\n warnedOrphans.add(node);\n console.warn(\n `[bindSwitchCases] ${node.directives?.case !== undefined ? '@case' : '@default'} has no @switch parent, or its @switch is on a @for element (BUG-070); <${node.originalTagName ?? node.tagName}> is dropped, as in a build`\n );\n }\n continue;\n }\n if (node.directives?.switch === undefined) continue;\n if (isConditionalBranch(node)) continue;\n\n const parentElement = node.nodeId ? elMap.get(node.nodeId) : null;\n if (!parentElement) {\n console.error(\n '[bindSwitchCases] Could not find parent element for switch block'\n );\n continue;\n }\n if (\n bindSwitchBlock(node, parentElement, ctx, processedNodeIds, disposers) &&\n node.nodeId\n )\n switchIds.add(node.nodeId);\n }\n\n for (const node of nodes) {\n if (node.nodeId && switchIds.has(node.nodeId)) continue;\n if (node.nodeId && processedNodeIds.has(node.nodeId)) continue;\n if (isConditionalBranch(node)) continue;\n if (node.isComponent) continue;\n\n if (node.type === 'element' && node.children?.length) {\n const element = node.nodeId ? elMap.get(node.nodeId) : null;\n\n if (element instanceof Element) {\n bindSwitchCases(\n node.children,\n element,\n ctx,\n processedNodeIds,\n disposers\n );\n }\n }\n }\n\n return processedNodeIds;\n}\n\nfunction isConditionalBranch(node: PithyNode): boolean {\n return (\n node.directives?.if !== undefined ||\n node.directives?.elseIf !== undefined ||\n node.directives?.else !== undefined\n );\n}\n\n/**\n * Binds one @switch element whose DOM is already built.\n */\n/** @codexApi {\"parent\":\"pithy.directive.switch\",\"name\":\"bindSwitchBlock\",\"stability\":\"experimental\",\"signature\":\"(switchNode: PithyNode, parentElement: Element, ctx: Record<string, unknown>, processedNodeIds: Set<string>, disposers: (() => void)[]) => boolean\"} */\nexport function bindSwitchBlock(\n switchNode: PithyNode,\n parentElement: Element,\n ctx: Record<string, unknown>,\n processedNodeIds: Set<string>,\n disposers: (() => void)[]\n): boolean {\n const caseNodes = (switchNode.children || []).filter(\n child =>\n child.type === 'element' &&\n (child.directives?.case !== undefined || isDefaultCase(child))\n );\n if (caseNodes.length === 0) return false;\n\n for (const node of caseNodes) {\n if (node.nodeId) processedNodeIds.add(node.nodeId);\n for (const loopNode of findAllNestedLoopNodes(node)) {\n if (loopNode.nodeId) processedNodeIds.add(loopNode.nodeId);\n }\n }\n\n const childByPid = new Map<string, Element>();\n for (const child of Array.from(parentElement.children)) {\n const pid = child.getAttribute('data-pid');\n if (pid) childByPid.set(pid, child as Element);\n }\n const caseElements = caseNodes\n .map(node => (node.nodeId ? childByPid.get(node.nodeId) : undefined))\n .filter((el): el is Element => el !== undefined);\n\n if (caseElements.length !== caseNodes.length) {\n console.error('[bindSwitchCases] Could not find all case elements');\n return true;\n }\n\n removeNonCaseChildren(parentElement, caseElements, switchNode);\n\n handleSwitchBlock(\n parentElement,\n caseElements,\n switchNode,\n caseNodes,\n ctx,\n disposers\n );\n return true;\n}\n\nconst warnedSwitches = new WeakSet<PithyNode>();\nconst warnedOrphans = new WeakSet<PithyNode>();\n\nfunction removeNonCaseChildren(\n parentElement: Element,\n caseElements: Element[],\n switchNode: PithyNode\n): void {\n const cases = new Set<Node>(caseElements);\n let dropped: string | undefined;\n for (const child of Array.from(parentElement.childNodes)) {\n if (cases.has(child)) continue;\n if (child.nodeType === Node.TEXT_NODE && !child.textContent?.trim()) {\n child.remove();\n continue;\n }\n const node = nodeExpando(child).__pithyNode;\n if (child.nodeType === Node.TEXT_NODE)\n dropped ??= JSON.stringify(child.textContent?.trim());\n else if (node?.type === 'slot') dropped ??= '<slot>';\n else if (node) dropped ??= `<${node.originalTagName ?? node.tagName}>`;\n else if (child.nodeType === Node.ELEMENT_NODE)\n dropped ??= `<${(child as Element).localName}>`;\n child.remove();\n }\n if (dropped && import.meta.env?.DEV && !warnedSwitches.has(switchNode)) {\n warnedSwitches.add(switchNode);\n console.warn(\n `[bindSwitchCases] @switch renders only its @case/@default children; ${dropped} is dropped, as in a build`\n );\n }\n}\n\n/**\n * Handles rendering and reactivity for an @switch/@case/@default block.\n */\nfunction handleSwitchBlock(\n parentElement: Element,\n caseElements: Element[],\n switchNode: PithyNode,\n caseNodes: PithyNode[],\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n) {\n // Generate a unique ID for this switch block for debugging\n const switchId = Math.random().toString(36).substring(2, 8);\n\n // Create a placeholder comment to mark where our switch content should go\n const placeholder = document.createComment(`switch-block-${switchId}`);\n\n // Insert the placeholder at the beginning of the parent element\n parentElement.insertBefore(placeholder, parentElement.firstChild);\n\n // Remove all case elements from the DOM immediately\n for (const el of caseElements) {\n el.remove();\n }\n\n let current: Branch | null = null;\n\n // Cache for compiled expressions to avoid recompiling on each change\n const compiledExpressions = new Map<string, () => unknown>();\n\n // Helper function to compile and cache expressions\n function getCompiledExpression(expr: string, kind: string): () => unknown {\n if (!expr || expr.trim() === '') {\n return () => undefined;\n }\n\n // Check if we already compiled this expression\n const cacheKey = `${kind}:${expr}`;\n if (compiledExpressions.has(cacheKey)) {\n return compiledExpressions.get(cacheKey)!;\n }\n\n try {\n const fn = compileExpression(expr, ctx, undefined);\n compiledExpressions.set(cacheKey, fn);\n return fn;\n } catch (err) {\n console.error(`[Switch-${switchId}] Error compiling ${kind}:`, err);\n const fallbackFn = () => undefined;\n compiledExpressions.set(cacheKey, fallbackFn);\n return fallbackFn;\n }\n }\n\n // Helper function to safely evaluate expressions\n function safeEvaluate(expr: string, kind: string): unknown {\n const fn = getCompiledExpression(expr, kind);\n try {\n return fn();\n } catch (err) {\n console.error(`[Switch-${switchId}] Error evaluating ${kind}:`, err);\n return undefined;\n }\n }\n\n function cleanupCurrentBranch() {\n if (current) clearBranch(current);\n current = null;\n }\n\n // Shared logic for finding the matching case\n function findMatchingCase(): number {\n // Evaluate the switch expression\n const switchValue = safeEvaluate(switchNode.directives!.switch!, '@switch');\n\n // Find the matching case\n let matchIndex = -1;\n let defaultIndex = -1;\n\n for (let i = 0; i < caseNodes.length; i++) {\n const node = caseNodes[i];\n\n if (node.directives?.case !== undefined) {\n // This is a @case node\n const caseValue = safeEvaluate(node.directives.case, '@case');\n\n // Check if the case value matches the switch value\n if (caseValue === switchValue) {\n matchIndex = i;\n break;\n }\n } else if (isDefaultCase(node)) {\n // This is a @default node, remember its index but continue checking other cases\n if (defaultIndex === -1) defaultIndex = i;\n }\n }\n\n // If no case matched but we have a default, use that\n if (matchIndex === -1 && defaultIndex !== -1) {\n matchIndex = defaultIndex;\n }\n\n return matchIndex;\n }\n\n function renderMatchedCase(matchIndex: number): Branch | null {\n if (matchIndex < 0 || !placeholder.parentNode) return null;\n return renderBranch(caseNodes[matchIndex], ctx, placeholder);\n }\n\n if (isSSRMode()) {\n // SSR mode: evaluate once synchronously, no reactive effects\n const matchIndex = findMatchingCase();\n const branch = renderMatchedCase(matchIndex);\n // Ensure nested directive disposers created during SSR are added\n // to the parent disposers array for proper cleanup on destroy()\n if (branch) disposers.push(...branch.disposers);\n } else {\n // Client mode: reactive effect for dynamic updates\n // Track the previous match index to avoid unnecessary DOM operations\n let previousMatchIndex = -1;\n\n // Set up the reactive effect and capture the stop function\n const stopEffect = effect(() => {\n const matchIndex = findMatchingCase();\n\n // Skip re-insertion if match hasn't changed\n if (matchIndex === previousMatchIndex) {\n return;\n }\n\n // Clean up the current branch before showing a new one\n cleanupCurrentBranch();\n // Update the previous match index\n previousMatchIndex = matchIndex;\n current = renderMatchedCase(matchIndex);\n\n // Don't return cleanup here - we handle cleanup explicitly:\n // 1. When match changes: cleanupCurrentBranch() is called above\n // 2. When effect stops: cleanupCurrentBranch is in disposers array\n });\n\n // Add cleanup and effect stop to disposers for proper cleanup on destroy()\n disposers.push(cleanupCurrentBranch);\n disposers.push(stopEffect);\n }\n}\n"]}
1
+ {"version":3,"file":"bindSwitchCases.js","sourceRoot":"","sources":["../../src/compile/bindSwitchCases.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EACL,aAAa,EACb,mBAAmB,GAEpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAe,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;;GAGG;AACH,kRAAkR;AAClR,MAAM,UAAU,eAAe,CAC7B,KAAkB,EAClB,MAAkC,EAClC,GAA4B,EAC5B,mBAAgC,IAAI,GAAG,EAAE,EAAE,gCAAgC;AAC3E,YAA4B,EAAE,CAAC,gCAAgC;;IAE/D,qEAAqE;IACrE,qEAAqE;IACrE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;IACzC,IAAI,MAAM,YAAY,OAAO,IAAI,MAAM,YAAY,gBAAgB,EAAE,CAAC;QACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YACpB,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC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AAU,GAAG,MAAM,CAAC,GAAG,EAAE;YAC7B,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC;YAEtC,4CAA4C;YAC5C,IAAI,UAAU,KAAK,kBAAkB,EAAE,CAAC;gBACtC,OAAO;YACT,CAAC;YAED,uDAAuD;YACvD,oBAAoB,EAAE,CAAC;YACvB,kCAAkC;YAClC,kBAAkB,GAAG,UAAU,CAAC;YAChC,OAAO,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAExC,4DAA4D;YAC5D,gEAAgE;YAChE,mEAAmE;QACrE,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,IAAI,CACZ,aAAa,CAAC,UAAU,EAAE,oBAAoB,EAAE,WAAW,CAAC,CAC7D,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.directive.switch\",\n \"title\": \"@switch directive\",\n \"category\": \"directive\"\n}\n*/\n\nimport {\n isDefaultCase,\n loopConflictMessage,\n type PithyNode,\n} from '@pithyjs/compiler';\nimport { effect } from '@pithyjs/signals';\nimport { compileExpression } from './compileExpression';\nimport { findAllNestedLoopNodes } from './forLoops/loopTraversal';\nimport { blockDisposer } from './disposeOrder';\nimport { nodeExpando } from './nodeExpando';\nimport { clearBranch, renderBranch, type Branch } from './renderBranch';\nimport { isSSRMode } from './ssrMode';\n\n/**\n * Processes switch case directives (@switch, @case, @default) in the template.\n * Identifies switch blocks and delegates their handling to handleSwitchBlock.\n */\n/** @codexApi {\"parent\":\"pithy.directive.switch\",\"name\":\"bindSwitchCases\",\"stability\":\"stable\",\"signature\":\"(nodes: PithyNode[], rootEl: Element | DocumentFragment, ctx: Record<string, unknown>, processedNodeIds?: Set<string>, disposers?: (() => void)[]) => Set<string>\"} */\nexport function bindSwitchCases(\n nodes: PithyNode[],\n rootEl: Element | DocumentFragment,\n ctx: Record<string, unknown>,\n processedNodeIds: Set<string> = new Set(), // Track already processed nodes\n disposers: (() => void)[] = [] // Collect disposers for cleanup\n): Set<string> {\n // Performance optimization: Create a Map of all elements by data-pid\n // This makes element lookups O(1) instead of O(n) with querySelector\n const elMap = new Map<string, Element>();\n if (rootEl instanceof Element || rootEl instanceof DocumentFragment) {\n const elements = rootEl.querySelectorAll('[data-pid]');\n elements.forEach(el => {\n const pid = el.getAttribute('data-pid');\n if (pid) {\n elMap.set(pid, el as Element);\n }\n });\n }\n\n const switchIds = new Set<string>();\n\n for (const node of nodes) {\n if (node.type !== 'element') continue;\n if (\n (node.directives?.case !== undefined || isDefaultCase(node)) &&\n node.nodeId &&\n !processedNodeIds.has(node.nodeId) &&\n !isConditionalBranch(node)\n ) {\n processedNodeIds.add(node.nodeId);\n elMap.get(node.nodeId)?.remove();\n if (import.meta.env?.DEV && !warnedOrphans.has(node)) {\n warnedOrphans.add(node);\n console.warn(\n `[bindSwitchCases] ${node.directives?.case !== undefined ? '@case' : '@default'} has no @switch parent, or its @switch is on a @for element, which ignores it; <${node.originalTagName ?? node.tagName}> is dropped, as in a build`\n );\n }\n continue;\n }\n if (node.directives?.switch === undefined) continue;\n if (isConditionalBranch(node)) continue;\n\n const parentElement = node.nodeId ? elMap.get(node.nodeId) : null;\n if (!parentElement) {\n console.error(\n '[bindSwitchCases] Could not find parent element for switch block'\n );\n continue;\n }\n if (\n bindSwitchBlock(node, parentElement, ctx, processedNodeIds, disposers) &&\n node.nodeId\n )\n switchIds.add(node.nodeId);\n }\n\n for (const node of nodes) {\n if (node.nodeId && switchIds.has(node.nodeId)) continue;\n if (node.nodeId && processedNodeIds.has(node.nodeId)) continue;\n if (isConditionalBranch(node)) continue;\n if (node.isComponent) continue;\n\n if (node.type === 'element' && node.children?.length) {\n const element = node.nodeId ? elMap.get(node.nodeId) : null;\n\n if (element instanceof Element) {\n bindSwitchCases(\n node.children,\n element,\n ctx,\n processedNodeIds,\n disposers\n );\n }\n }\n }\n\n return processedNodeIds;\n}\n\nfunction isConditionalBranch(node: PithyNode): boolean {\n return (\n node.directives?.if !== undefined ||\n node.directives?.elseIf !== undefined ||\n node.directives?.else !== undefined\n );\n}\n\n/**\n * Binds one @switch element whose DOM is already built.\n */\n/** @codexApi {\"parent\":\"pithy.directive.switch\",\"name\":\"bindSwitchBlock\",\"stability\":\"experimental\",\"signature\":\"(switchNode: PithyNode, parentElement: Element, ctx: Record<string, unknown>, processedNodeIds: Set<string>, disposers: (() => void)[]) => boolean\"} */\nexport function bindSwitchBlock(\n switchNode: PithyNode,\n parentElement: Element,\n ctx: Record<string, unknown>,\n processedNodeIds: Set<string>,\n disposers: (() => void)[]\n): boolean {\n const caseNodes = (switchNode.children || []).filter(\n child =>\n child.type === 'element' &&\n (child.directives?.case !== undefined || isDefaultCase(child))\n );\n if (caseNodes.length === 0) {\n removeNonCaseChildren(parentElement, [], switchNode);\n return true;\n }\n\n for (const node of caseNodes) {\n if (node.nodeId) processedNodeIds.add(node.nodeId);\n for (const loopNode of findAllNestedLoopNodes(node)) {\n if (loopNode.nodeId) processedNodeIds.add(loopNode.nodeId);\n }\n }\n\n const childByPid = new Map<string, Element>();\n for (const child of Array.from(parentElement.children)) {\n const pid = child.getAttribute('data-pid');\n if (pid) childByPid.set(pid, child as Element);\n }\n const caseElements = caseNodes\n .map(node => (node.nodeId ? childByPid.get(node.nodeId) : undefined))\n .filter((el): el is Element => el !== undefined);\n\n if (caseElements.length !== caseNodes.length) {\n console.error('[bindSwitchCases] Could not find all case elements');\n return true;\n }\n\n removeNonCaseChildren(parentElement, caseElements, switchNode);\n\n handleSwitchBlock(\n parentElement,\n caseElements,\n switchNode,\n caseNodes,\n ctx,\n disposers\n );\n return true;\n}\n\nconst warnedSwitches = new WeakSet<PithyNode>();\nconst warnedConflicts = new WeakSet<PithyNode>();\nconst warnedOrphans = new WeakSet<PithyNode>();\n\nfunction removeNonCaseChildren(\n parentElement: Element,\n caseElements: Element[],\n switchNode: PithyNode\n): void {\n const cases = new Set<Node>(caseElements);\n let dropped: string | undefined;\n for (const child of Array.from(parentElement.childNodes)) {\n if (cases.has(child)) continue;\n if (child.nodeType === Node.TEXT_NODE && !child.textContent?.trim()) {\n child.remove();\n continue;\n }\n const node = nodeExpando(child).__pithyNode;\n if (import.meta.env?.DEV && node && !warnedConflicts.has(node)) {\n warnedConflicts.add(node);\n for (const name of node.loopConflicts ?? [])\n console.warn(\n `[pithy] ${loopConflictMessage(node.originalTagName ?? node.tagName ?? '', name)}`\n );\n }\n if (child.nodeType === Node.TEXT_NODE)\n dropped ??= JSON.stringify(child.textContent?.trim());\n else if (node?.type === 'slot') dropped ??= '<slot>';\n else if (node) dropped ??= `<${node.originalTagName ?? node.tagName}>`;\n else if (child.nodeType === Node.ELEMENT_NODE)\n dropped ??= `<${(child as Element).localName}>`;\n child.remove();\n }\n if (dropped && import.meta.env?.DEV && !warnedSwitches.has(switchNode)) {\n warnedSwitches.add(switchNode);\n console.warn(\n `[bindSwitchCases] @switch renders only its @case/@default children; ${dropped} is dropped, as in a build`\n );\n }\n}\n\n/**\n * Handles rendering and reactivity for an @switch/@case/@default block.\n */\nfunction handleSwitchBlock(\n parentElement: Element,\n caseElements: Element[],\n switchNode: PithyNode,\n caseNodes: PithyNode[],\n ctx: Record<string, unknown>,\n disposers: (() => void)[]\n) {\n // Generate a unique ID for this switch block for debugging\n const switchId = Math.random().toString(36).substring(2, 8);\n\n // Create a placeholder comment to mark where our switch content should go\n const placeholder = document.createComment(`switch-block-${switchId}`);\n\n // Insert the placeholder at the beginning of the parent element\n parentElement.insertBefore(placeholder, parentElement.firstChild);\n\n // Remove all case elements from the DOM immediately\n for (const el of caseElements) {\n el.remove();\n }\n\n let current: Branch | null = null;\n\n // Cache for compiled expressions to avoid recompiling on each change\n const compiledExpressions = new Map<string, () => unknown>();\n\n // Helper function to compile and cache expressions\n function getCompiledExpression(expr: string, kind: string): () => unknown {\n if (!expr || expr.trim() === '') {\n return () => undefined;\n }\n\n // Check if we already compiled this expression\n const cacheKey = `${kind}:${expr}`;\n if (compiledExpressions.has(cacheKey)) {\n return compiledExpressions.get(cacheKey)!;\n }\n\n try {\n const fn = compileExpression(expr, ctx, undefined);\n compiledExpressions.set(cacheKey, fn);\n return fn;\n } catch (err) {\n console.error(`[Switch-${switchId}] Error compiling ${kind}:`, err);\n const fallbackFn = () => undefined;\n compiledExpressions.set(cacheKey, fallbackFn);\n return fallbackFn;\n }\n }\n\n // Helper function to safely evaluate expressions\n function safeEvaluate(expr: string, kind: string): unknown {\n const fn = getCompiledExpression(expr, kind);\n try {\n return fn();\n } catch (err) {\n console.error(`[Switch-${switchId}] Error evaluating ${kind}:`, err);\n return undefined;\n }\n }\n\n function cleanupCurrentBranch() {\n if (current) clearBranch(current);\n current = null;\n }\n\n // Shared logic for finding the matching case\n function findMatchingCase(): number {\n // Evaluate the switch expression\n const switchValue = safeEvaluate(switchNode.directives!.switch!, '@switch');\n\n // Find the matching case\n let matchIndex = -1;\n let defaultIndex = -1;\n\n for (let i = 0; i < caseNodes.length; i++) {\n const node = caseNodes[i];\n\n if (node.directives?.case !== undefined) {\n // This is a @case node\n const caseValue = safeEvaluate(node.directives.case, '@case');\n\n // Check if the case value matches the switch value\n if (caseValue === switchValue) {\n matchIndex = i;\n break;\n }\n } else if (isDefaultCase(node)) {\n // This is a @default node, remember its index but continue checking other cases\n if (defaultIndex === -1) defaultIndex = i;\n }\n }\n\n // If no case matched but we have a default, use that\n if (matchIndex === -1 && defaultIndex !== -1) {\n matchIndex = defaultIndex;\n }\n\n return matchIndex;\n }\n\n function renderMatchedCase(matchIndex: number): Branch | null {\n if (matchIndex < 0 || !placeholder.parentNode) return null;\n return renderBranch(caseNodes[matchIndex], ctx, placeholder);\n }\n\n if (isSSRMode()) {\n // SSR mode: evaluate once synchronously, no reactive effects\n const matchIndex = findMatchingCase();\n const branch = renderMatchedCase(matchIndex);\n // Ensure nested directive disposers created during SSR are added\n // to the parent disposers array for proper cleanup on destroy()\n if (branch) disposers.push(...branch.disposers);\n } else {\n // Client mode: reactive effect for dynamic updates\n // Track the previous match index to avoid unnecessary DOM operations\n let previousMatchIndex = -1;\n\n // Set up the reactive effect and capture the stop function\n const stopEffect = effect(() => {\n const matchIndex = findMatchingCase();\n\n // Skip re-insertion if match hasn't changed\n if (matchIndex === previousMatchIndex) {\n return;\n }\n\n // Clean up the current branch before showing a new one\n cleanupCurrentBranch();\n // Update the previous match index\n previousMatchIndex = matchIndex;\n current = renderMatchedCase(matchIndex);\n\n // Don't return cleanup here - we handle cleanup explicitly:\n // 1. When match changes: cleanupCurrentBranch() is called above\n // 2. When effect stops: cleanupCurrentBranch is in disposers array\n });\n\n disposers.push(\n blockDisposer(stopEffect, cleanupCurrentBranch, placeholder)\n );\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ /** The passes after components: what a component's forwarded directives need. */
2
+ /** @codexApi {"parent":"pithy.runtime.renderer","name":"bindAfterComponents","stability":"internal","signature":"(fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void"} */
3
+ export declare function bindAfterComponents(fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]): void;
4
+ //# sourceMappingURL=bindAfterComponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindAfterComponents.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindAfterComponents.ts"],"names":[],"mappings":"AAQA,iFAAiF;AACjF,wNAAwN;AACxN,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAqBN"}
@@ -0,0 +1,26 @@
1
+ import { bindDefaultTwoWay } from './bindDefaultTwoWay.js';
2
+ import { bindTextInterpolations } from './bindTextInterpolations.js';
3
+ import { bindEventHandlers } from './bindEventHandlers.js';
4
+ import { bindClassDirectives } from './bindClassDirectives.js';
5
+ import { bindBoundAttributes } from './bindBoundAttributes.js';
6
+ import { executeCustomDirectiveBinders } from './directiveRegistry.js';
7
+ import { bindDeferDirectives } from './bindDeferDirectives.js';
8
+ /** The passes after components: what a component's forwarded directives need. */
9
+ /** @codexApi {"parent":"pithy.runtime.renderer","name":"bindAfterComponents","stability":"internal","signature":"(fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void"} */
10
+ export function bindAfterComponents(fragment, context, disposers) {
11
+ // two-way model bindings for native controls at this level
12
+ bindDefaultTwoWay(fragment, context, disposers);
13
+ // text interpolations — our binder already skips nested loops & component roots
14
+ bindTextInterpolations(fragment, context, disposers);
15
+ // events (idempotent; supports modifiers; nearest ctx; $event/$el)
16
+ bindEventHandlers(fragment, context, disposers);
17
+ // classes and style properties
18
+ bindClassDirectives(fragment, context, disposers);
19
+ // bound attributes
20
+ bindBoundAttributes(fragment, context, disposers);
21
+ // custom directives — allows external packages (router, etc.) to register binders
22
+ executeCustomDirectiveBinders(fragment, context, disposers);
23
+ // defer directives — lazy loading with @defer, @load, @placeholder
24
+ bindDeferDirectives(fragment, context, disposers);
25
+ }
26
+ //# sourceMappingURL=bindAfterComponents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindAfterComponents.js","sourceRoot":"","sources":["../../../src/compile/binds/bindAfterComponents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,iFAAiF;AACjF,wNAAwN;AACxN,MAAM,UAAU,mBAAmB,CACjC,QAA0B,EAC1B,OAAgC,EAChC,SAAyB;IAEzB,2DAA2D;IAC3D,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,gFAAgF;IAChF,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAErD,mEAAmE;IACnE,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,+BAA+B;IAC/B,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAElD,mBAAmB;IACnB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAElD,kFAAkF;IAClF,6BAA6B,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE5D,mEAAmE;IACnE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { bindDefaultTwoWay } from './bindDefaultTwoWay';\nimport { bindTextInterpolations } from './bindTextInterpolations';\nimport { bindEventHandlers } from './bindEventHandlers';\nimport { bindClassDirectives } from './bindClassDirectives';\nimport { bindBoundAttributes } from './bindBoundAttributes';\nimport { executeCustomDirectiveBinders } from './directiveRegistry';\nimport { bindDeferDirectives } from './bindDeferDirectives';\n\n/** The passes after components: what a component's forwarded directives need. */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"bindAfterComponents\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindAfterComponents(\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // two-way model bindings for native controls at this level\n bindDefaultTwoWay(fragment, context, disposers);\n\n // text interpolations — our binder already skips nested loops & component roots\n bindTextInterpolations(fragment, context, disposers);\n\n // events (idempotent; supports modifiers; nearest ctx; $event/$el)\n bindEventHandlers(fragment, context, disposers);\n\n // classes and style properties\n bindClassDirectives(fragment, context, disposers);\n\n // bound attributes\n bindBoundAttributes(fragment, context, disposers);\n\n // custom directives — allows external packages (router, etc.) to register binders\n executeCustomDirectiveBinders(fragment, context, disposers);\n\n // defer directives — lazy loading with @defer, @load, @placeholder\n bindDeferDirectives(fragment, context, disposers);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bindAfterProjection.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindAfterProjection.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,wNAAwN;AACxN,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAwBN"}
1
+ {"version":3,"file":"bindAfterProjection.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindAfterProjection.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wNAAwN;AACxN,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAIN"}
@@ -1,11 +1,5 @@
1
1
  import { bindComponentTags } from './bindComponentsTags.js';
2
- import { bindDefaultTwoWay } from './bindDefaultTwoWay.js';
3
- import { bindTextInterpolations } from './bindTextInterpolations.js';
4
- import { bindEventHandlers } from './bindEventHandlers.js';
5
- import { bindClassDirectives } from './bindClassDirectives.js';
6
- import { bindBoundAttributes } from './bindBoundAttributes.js';
7
- import { executeCustomDirectiveBinders } from './directiveRegistry.js';
8
- import { bindDeferDirectives } from './bindDeferDirectives.js';
2
+ import { bindAfterComponents } from './bindAfterComponents.js';
9
3
  /**
10
4
  * The non-structural passes that follow content projection, in order. Each
11
5
  * consumes what it binds, so a second run over the same nodes binds nothing.
@@ -14,19 +8,6 @@ import { bindDeferDirectives } from './bindDeferDirectives.js';
14
8
  export function bindAfterProjection(fragment, context, disposers) {
15
9
  // components — materialize custom tags, including those in projected content
16
10
  bindComponentTags(fragment, context, disposers);
17
- // two-way model bindings for native controls at this level
18
- bindDefaultTwoWay(fragment, context, disposers);
19
- // text interpolations — our binder already skips nested loops & component roots
20
- bindTextInterpolations(fragment, context, disposers);
21
- // events (idempotent; supports modifiers; nearest ctx; $event/$el)
22
- bindEventHandlers(fragment, context, disposers);
23
- // classes and style properties
24
- bindClassDirectives(fragment, context, disposers);
25
- // bound attributes
26
- bindBoundAttributes(fragment, context, disposers);
27
- // custom directives — allows external packages (router, etc.) to register binders
28
- executeCustomDirectiveBinders(fragment, context, disposers);
29
- // defer directives — lazy loading with @defer, @load, @placeholder
30
- bindDeferDirectives(fragment, context, disposers);
11
+ bindAfterComponents(fragment, context, disposers);
31
12
  }
32
13
  //# sourceMappingURL=bindAfterProjection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bindAfterProjection.js","sourceRoot":"","sources":["../../../src/compile/binds/bindAfterProjection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;GAGG;AACH,wNAAwN;AACxN,MAAM,UAAU,mBAAmB,CACjC,QAA0B,EAC1B,OAAgC,EAChC,SAAyB;IAEzB,6EAA6E;IAC7E,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,2DAA2D;IAC3D,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,gFAAgF;IAChF,sBAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAErD,mEAAmE;IACnE,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAEhD,+BAA+B;IAC/B,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAElD,mBAAmB;IACnB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAElD,kFAAkF;IAClF,6BAA6B,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAE5D,mEAAmE;IACnE,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { bindComponentTags } from './bindComponentsTags';\nimport { bindDefaultTwoWay } from './bindDefaultTwoWay';\nimport { bindTextInterpolations } from './bindTextInterpolations';\nimport { bindEventHandlers } from './bindEventHandlers';\nimport { bindClassDirectives } from './bindClassDirectives';\nimport { bindBoundAttributes } from './bindBoundAttributes';\nimport { executeCustomDirectiveBinders } from './directiveRegistry';\nimport { bindDeferDirectives } from './bindDeferDirectives';\n\n/**\n * The non-structural passes that follow content projection, in order. Each\n * consumes what it binds, so a second run over the same nodes binds nothing.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"bindAfterProjection\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindAfterProjection(\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // components — materialize custom tags, including those in projected content\n bindComponentTags(fragment, context, disposers);\n\n // two-way model bindings for native controls at this level\n bindDefaultTwoWay(fragment, context, disposers);\n\n // text interpolations — our binder already skips nested loops & component roots\n bindTextInterpolations(fragment, context, disposers);\n\n // events (idempotent; supports modifiers; nearest ctx; $event/$el)\n bindEventHandlers(fragment, context, disposers);\n\n // classes and style properties\n bindClassDirectives(fragment, context, disposers);\n\n // bound attributes\n bindBoundAttributes(fragment, context, disposers);\n\n // custom directives — allows external packages (router, etc.) to register binders\n executeCustomDirectiveBinders(fragment, context, disposers);\n\n // defer directives — lazy loading with @defer, @load, @placeholder\n bindDeferDirectives(fragment, context, disposers);\n}\n"]}
1
+ {"version":3,"file":"bindAfterProjection.js","sourceRoot":"","sources":["../../../src/compile/binds/bindAfterProjection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;GAGG;AACH,wNAAwN;AACxN,MAAM,UAAU,mBAAmB,CACjC,QAA0B,EAC1B,OAAgC,EAChC,SAAyB;IAEzB,6EAA6E;IAC7E,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IAChD,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { bindComponentTags } from './bindComponentsTags';\nimport { bindAfterComponents } from './bindAfterComponents';\n\n/**\n * The non-structural passes that follow content projection, in order. Each\n * consumes what it binds, so a second run over the same nodes binds nothing.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.renderer\",\"name\":\"bindAfterProjection\",\"stability\":\"internal\",\"signature\":\"(fragment: DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindAfterProjection(\n fragment: DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // components — materialize custom tags, including those in projected content\n bindComponentTags(fragment, context, disposers);\n bindAfterComponents(fragment, context, disposers);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bindComponentsTags.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAqCF,qGAAqG;AACrG,wBAAgB,2BAA2B,IAAI,IAAI,CAElD;AA6JD;;;;;;GAMG;AACH,4NAA4N;AAC5N,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAoXN"}
1
+ {"version":3,"file":"bindComponentsTags.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA8CF,qGAAqG;AACrG,wBAAgB,2BAA2B,IAAI,IAAI,CAElD;AA6JD;;;;;;GAMG;AACH,4NAA4N;AAC5N,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CA2YN"}
@@ -6,12 +6,14 @@
6
6
  }
7
7
  */
8
8
  import { compileExpression } from '../compileExpression.js';
9
- import { boundaryForElement, runWithBoundary } from './bindErrorBoundary.js';
10
- import { collectSlotMap } from '../contentProjection.js';
9
+ import { boundaryForElement, currentBoundary, replaceHidden, runWithBoundary, slotContentHidden, withSlotBoundary, } from './bindErrorBoundary.js';
10
+ import { bindAfterComponents } from './bindAfterComponents.js';
11
+ import { collectSlotMap, inProjectedContent } from '../contentProjection.js';
11
12
  import { componentChildDirectiveMessage, componentChildDirectives, nativeTags, } from '@pithyjs/compiler';
12
13
  import { collectForwardedAttrs, applyForwardedAttrs } from './forwardedAttrs.js';
13
14
  import { createRoot, untrack } from '@pithyjs/signals';
14
15
  import { nodeExpando } from '../nodeExpando.js';
16
+ import { componentDisposer } from '../disposeOrder.js';
15
17
  import { pithyGlobals } from '../../types/globals.js';
16
18
  import { isSSRMode } from '../ssrMode.js';
17
19
  import { clearSSRRenderCrash, reportComponentFailure } from '../ssrCrashes.js';
@@ -257,6 +259,14 @@ export function bindComponentTags(root, rootCtx, disposers) {
257
259
  }
258
260
  if (typeof candidate !== 'function')
259
261
  continue;
262
+ // Content a runtime-compiled receiver projected: bound detached, inside the
263
+ // output of the component being rendered.
264
+ const projectedHost = !el.closest('[data-error]') && inProjectedContent(el)
265
+ ? pithyGlobals().__pithyComponentContext?.__slotHost
266
+ : undefined;
267
+ // Hidden like a sibling an activated boundary detached: never rendered.
268
+ if (withSlotBoundary(undefined, projectedHost, () => slotContentHidden(el)))
269
+ continue;
260
270
  const componentFn = candidate;
261
271
  const localCtx = nearestCtx(el, rootCtx); // crucial for item(), gIdx(), etc.
262
272
  // Extract expected props for validation (DEV) and prop name normalization (always)
@@ -307,10 +317,13 @@ export function bindComponentTags(root, rootCtx, disposers) {
307
317
  __slotMap: slotMap,
308
318
  __childAstNodes: pithyChildren,
309
319
  __childFactory: undefined,
320
+ __slotHost: el,
310
321
  };
311
322
  // Find nearest error boundary for this component
312
323
  const boundaryEl = el.closest('[data-error]');
313
- const boundary = boundaryForElement(boundaryEl);
324
+ // Projected content is bound detached, during its receiver's render.
325
+ const boundary = boundaryForElement(boundaryEl) ??
326
+ (!boundaryEl && inProjectedContent(el) ? currentBoundary() : null);
314
327
  // Invoke component under boundary context; expect { el, destroy }
315
328
  let out;
316
329
  let disposeSetup;
@@ -427,8 +440,12 @@ export function bindComponentTags(root, rootCtx, disposers) {
427
440
  for (const node of renderedNodes)
428
441
  nodeExpando(node).__pithyComponentDom = true;
429
442
  let replaced = true;
443
+ let hidden = false;
430
444
  try {
431
- el.replaceWith(...renderedNodes);
445
+ // A boundary that caught a crash in this render may have hidden `el`.
446
+ hidden = replaceHidden(el, renderedNodes);
447
+ if (!hidden)
448
+ el.replaceWith(...renderedNodes);
432
449
  }
433
450
  catch (err) {
434
451
  // A failed replacement leaves the raw <${tag}> exactly where a crash
@@ -451,6 +468,10 @@ export function bindComponentTags(root, rootCtx, disposers) {
451
468
  forwardTarget.classList.add(cls);
452
469
  }
453
470
  }
471
+ // Before any binding pass below, which can throw.
472
+ const teardown = componentDisposer(destroy, disposeSetup, renderedNodes[0] ?? (replaced ? null : el));
473
+ if (teardown)
474
+ disposers.push(teardown);
454
475
  // Forward captured attributes so subsequent binders can attach the bindings
455
476
  if (forwardedAttrs.length > 0 && forwardTarget) {
456
477
  applyForwardedAttrs(forwardTarget, forwardedAttrs, tag);
@@ -460,12 +481,13 @@ export function bindComponentTags(root, rootCtx, disposers) {
460
481
  const classToggles = Object.keys(pithyNode?.directives?.classMap ?? {});
461
482
  if (classToggles.length)
462
483
  nodeExpando(forwardTarget).__classToggles = classToggles;
463
- }
464
- if (disposeSetup) {
465
- disposers.push(disposeSetup);
466
- }
467
- if (typeof destroy === 'function') {
468
- disposers.push(destroy);
484
+ // Hidden, it is out of reach of this fragment's later passes. An active
485
+ // nested boundary `hideContent` kept in place is still within reach.
486
+ if (hidden && !forwardTarget.parentNode) {
487
+ const detached = document.createDocumentFragment();
488
+ detached.append(forwardTarget);
489
+ bindAfterComponents(detached, localCtx, disposers);
490
+ }
469
491
  }
470
492
  }
471
493
  }