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

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 (126) hide show
  1. package/README.md +14 -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/bindBoundAttributes.d.ts +4 -0
  13. package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -1
  14. package/dist/compile/binds/bindBoundAttributes.js +63 -3
  15. package/dist/compile/binds/bindBoundAttributes.js.map +1 -1
  16. package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -1
  17. package/dist/compile/binds/bindClassDirectives.js +3 -2
  18. package/dist/compile/binds/bindClassDirectives.js.map +1 -1
  19. package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
  20. package/dist/compile/binds/bindComponentsTags.js +47 -11
  21. package/dist/compile/binds/bindComponentsTags.js.map +1 -1
  22. package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -1
  23. package/dist/compile/binds/bindDefaultTwoWay.js +2 -1
  24. package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -1
  25. package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
  26. package/dist/compile/binds/bindDeferDirectives.js +17 -15
  27. package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
  28. package/dist/compile/binds/bindErrorBoundary.d.ts +11 -1
  29. package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
  30. package/dist/compile/binds/bindErrorBoundary.js +50 -13
  31. package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
  32. package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -1
  33. package/dist/compile/binds/bindEventHandlers.js +2 -1
  34. package/dist/compile/binds/bindEventHandlers.js.map +1 -1
  35. package/dist/compile/binds/bindRefDirectives.d.ts.map +1 -1
  36. package/dist/compile/binds/bindRefDirectives.js +2 -1
  37. package/dist/compile/binds/bindRefDirectives.js.map +1 -1
  38. package/dist/compile/binds/bindStyleDirectives.d.ts.map +1 -1
  39. package/dist/compile/binds/bindStyleDirectives.js +2 -1
  40. package/dist/compile/binds/bindStyleDirectives.js.map +1 -1
  41. package/dist/compile/binds/bindTextInterpolations.d.ts +2 -1
  42. package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -1
  43. package/dist/compile/binds/bindTextInterpolations.js +25 -14
  44. package/dist/compile/binds/bindTextInterpolations.js.map +1 -1
  45. package/dist/compile/binds/declaredDirective.d.ts +12 -0
  46. package/dist/compile/binds/declaredDirective.d.ts.map +1 -0
  47. package/dist/compile/binds/declaredDirective.js +42 -0
  48. package/dist/compile/binds/declaredDirective.js.map +1 -0
  49. package/dist/compile/binds/forwardedAttrs.d.ts +4 -2
  50. package/dist/compile/binds/forwardedAttrs.d.ts.map +1 -1
  51. package/dist/compile/binds/forwardedAttrs.js +10 -2
  52. package/dist/compile/binds/forwardedAttrs.js.map +1 -1
  53. package/dist/compile/binds/staleRowProps.d.ts +9 -0
  54. package/dist/compile/binds/staleRowProps.d.ts.map +1 -0
  55. package/dist/compile/binds/staleRowProps.js +86 -0
  56. package/dist/compile/binds/staleRowProps.js.map +1 -0
  57. package/dist/compile/compileNodes.d.ts.map +1 -1
  58. package/dist/compile/compileNodes.js +2 -0
  59. package/dist/compile/compileNodes.js.map +1 -1
  60. package/dist/compile/compileTemplate.d.ts.map +1 -1
  61. package/dist/compile/compileTemplate.js +2 -0
  62. package/dist/compile/compileTemplate.js.map +1 -1
  63. package/dist/compile/contentProjection.d.ts +3 -0
  64. package/dist/compile/contentProjection.d.ts.map +1 -1
  65. package/dist/compile/contentProjection.js +8 -0
  66. package/dist/compile/contentProjection.js.map +1 -1
  67. package/dist/compile/disposeOrder.d.ts +35 -0
  68. package/dist/compile/disposeOrder.d.ts.map +1 -0
  69. package/dist/compile/disposeOrder.js +81 -0
  70. package/dist/compile/disposeOrder.js.map +1 -0
  71. package/dist/compile/forLoops/bindForLoops.d.ts +1 -1
  72. package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -1
  73. package/dist/compile/forLoops/bindForLoops.js +10 -3
  74. package/dist/compile/forLoops/bindForLoops.js.map +1 -1
  75. package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -1
  76. package/dist/compile/forLoops/createLoopManager.js +19 -2
  77. package/dist/compile/forLoops/createLoopManager.js.map +1 -1
  78. package/dist/compile/forLoops/loopSignals.d.ts.map +1 -1
  79. package/dist/compile/forLoops/loopSignals.js +15 -1
  80. package/dist/compile/forLoops/loopSignals.js.map +1 -1
  81. package/dist/compile/handleConditionalChain.d.ts.map +1 -1
  82. package/dist/compile/handleConditionalChain.js +2 -3
  83. package/dist/compile/handleConditionalChain.js.map +1 -1
  84. package/dist/compile/nodeExpando.d.ts +6 -0
  85. package/dist/compile/nodeExpando.d.ts.map +1 -1
  86. package/dist/compile/nodeExpando.js.map +1 -1
  87. package/dist/compile/pithyTreeToDom.js +1 -0
  88. package/dist/compile/pithyTreeToDom.js.map +1 -1
  89. package/dist/compile/renderBranch.d.ts +1 -1
  90. package/dist/compile/renderBranch.d.ts.map +1 -1
  91. package/dist/compile/renderBranch.js +5 -3
  92. package/dist/compile/renderBranch.js.map +1 -1
  93. package/dist/compile/renderChildren.d.ts.map +1 -1
  94. package/dist/compile/renderChildren.js +3 -2
  95. package/dist/compile/renderChildren.js.map +1 -1
  96. package/dist/runtime/applyBindings.d.ts.map +1 -1
  97. package/dist/runtime/applyBindings.js +5 -1
  98. package/dist/runtime/applyBindings.js.map +1 -1
  99. package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
  100. package/dist/runtime/bindings/applyComponent.js +19 -7
  101. package/dist/runtime/bindings/applyComponent.js.map +1 -1
  102. package/dist/runtime/bindings/applyDefer.d.ts.map +1 -1
  103. package/dist/runtime/bindings/applyDefer.js +10 -9
  104. package/dist/runtime/bindings/applyDefer.js.map +1 -1
  105. package/dist/runtime/bindings/applySimple.d.ts +2 -0
  106. package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
  107. package/dist/runtime/bindings/applySimple.js +50 -10
  108. package/dist/runtime/bindings/applySimple.js.map +1 -1
  109. package/dist/runtime/bindings/applyStructural.d.ts.map +1 -1
  110. package/dist/runtime/bindings/applyStructural.js +11 -13
  111. package/dist/runtime/bindings/applyStructural.js.map +1 -1
  112. package/dist/runtime/bindings/helpers.d.ts +7 -0
  113. package/dist/runtime/bindings/helpers.d.ts.map +1 -1
  114. package/dist/runtime/bindings/helpers.js +35 -1
  115. package/dist/runtime/bindings/helpers.js.map +1 -1
  116. package/dist/runtime/bindings/index.d.ts +1 -1
  117. package/dist/runtime/bindings/index.d.ts.map +1 -1
  118. package/dist/runtime/bindings/index.js +1 -1
  119. package/dist/runtime/bindings/index.js.map +1 -1
  120. package/dist/runtime/html.d.ts.map +1 -1
  121. package/dist/runtime/html.js +2 -3
  122. package/dist/runtime/html.js.map +1 -1
  123. package/dist/types/globals.d.ts +2 -0
  124. package/dist/types/globals.d.ts.map +1 -1
  125. package/dist/types/globals.js.map +1 -1
  126. package/package.json +5 -5
@@ -6,12 +6,16 @@
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 { isTemplateAttr } from './declaredDirective.js';
10
+ import { boundaryForElement, currentBoundary, replaceHidden, runWithBoundary, slotContentHidden, withSlotBoundary, } from './bindErrorBoundary.js';
11
+ import { bindAfterComponents } from './bindAfterComponents.js';
12
+ import { collectSlotMap, inProjectedContent } from '../contentProjection.js';
11
13
  import { componentChildDirectiveMessage, componentChildDirectives, nativeTags, } from '@pithyjs/compiler';
12
14
  import { collectForwardedAttrs, applyForwardedAttrs } from './forwardedAttrs.js';
13
15
  import { createRoot, untrack } from '@pithyjs/signals';
16
+ import { watchStaleRowProp } from './staleRowProps.js';
14
17
  import { nodeExpando } from '../nodeExpando.js';
18
+ import { componentDisposer } from '../disposeOrder.js';
15
19
  import { pithyGlobals } from '../../types/globals.js';
16
20
  import { isSSRMode } from '../ssrMode.js';
17
21
  import { clearSSRRenderCrash, reportComponentFailure } from '../ssrCrashes.js';
@@ -115,6 +119,10 @@ function warnBoundProps(componentFn, el, componentName) {
115
119
  if (!attr.name.startsWith('data-bind-'))
116
120
  continue;
117
121
  const bound = attr.name.slice('data-bind-'.length);
122
+ if (bound === 'slot' && !warnedBoundProps.has(`${componentName} slot`)) {
123
+ warnedBoundProps.add(`${componentName} slot`);
124
+ console.warn(`[PithyJS] <${componentName}> [slot] cannot choose a slot: the key is read as a literal, so this lands in the default slot. Write slot="name".`);
125
+ }
118
126
  if (GLOBAL_ATTRS.has(bound))
119
127
  continue;
120
128
  const prop = expected.find(p => p.toLowerCase() === bound);
@@ -257,6 +265,14 @@ export function bindComponentTags(root, rootCtx, disposers) {
257
265
  }
258
266
  if (typeof candidate !== 'function')
259
267
  continue;
268
+ // Content a runtime-compiled receiver projected: bound detached, inside the
269
+ // output of the component being rendered.
270
+ const projectedHost = !el.closest('[data-error]') && inProjectedContent(el)
271
+ ? pithyGlobals().__pithyComponentContext?.__slotHost
272
+ : undefined;
273
+ // Hidden like a sibling an activated boundary detached: never rendered.
274
+ if (withSlotBoundary(undefined, projectedHost, () => slotContentHidden(el)))
275
+ continue;
260
276
  const componentFn = candidate;
261
277
  const localCtx = nearestCtx(el, rootCtx); // crucial for item(), gIdx(), etc.
262
278
  // Extract expected props for validation (DEV) and prop name normalization (always)
@@ -267,6 +283,7 @@ export function bindComponentTags(root, rootCtx, disposers) {
267
283
  // (pithyNode already extracted above for isComponent check)
268
284
  const originalAttrs = pithyNode?.originalAttrs;
269
285
  const props = {};
286
+ const staleWatchers = [];
270
287
  // Evaluate attributes as expressions in localCtx
271
288
  for (const attr of Array.from(el.attributes)) {
272
289
  const name = attr.name;
@@ -274,7 +291,9 @@ export function bindComponentTags(root, rootCtx, disposers) {
274
291
  // Skip internal/behavioral attributes
275
292
  if (name.startsWith('data-'))
276
293
  continue;
277
- if (name === 'class' || name === 'style')
294
+ if (name === 'class' || name === 'style' || name === 'slot')
295
+ continue;
296
+ if (!isTemplateAttr(attr))
278
297
  continue;
279
298
  // Prefer originally-authored name (preserve casing), else DOM name
280
299
  const authored = originalAttrs?.[name] ?? name;
@@ -282,6 +301,9 @@ export function bindComponentTags(root, rootCtx, disposers) {
282
301
  try {
283
302
  const value = untrack(() => evalInCtx(raw, localCtx));
284
303
  props[propName] = value; // only set when evaluation succeeds
304
+ if (import.meta.env?.DEV) {
305
+ staleWatchers.push(() => watchStaleRowProp(localCtx, pithyNode ?? el, pithyNode?.originalTagName || tag, propName, raw, value, () => evalInCtx(raw, localCtx), disposers));
306
+ }
285
307
  }
286
308
  catch (err) {
287
309
  if (import.meta.env?.DEV) {
@@ -307,10 +329,13 @@ export function bindComponentTags(root, rootCtx, disposers) {
307
329
  __slotMap: slotMap,
308
330
  __childAstNodes: pithyChildren,
309
331
  __childFactory: undefined,
332
+ __slotHost: el,
310
333
  };
311
334
  // Find nearest error boundary for this component
312
335
  const boundaryEl = el.closest('[data-error]');
313
- const boundary = boundaryForElement(boundaryEl);
336
+ // Projected content is bound detached, during its receiver's render.
337
+ const boundary = boundaryForElement(boundaryEl) ??
338
+ (!boundaryEl && inProjectedContent(el) ? currentBoundary() : null);
314
339
  // Invoke component under boundary context; expect { el, destroy }
315
340
  let out;
316
341
  let disposeSetup;
@@ -427,8 +452,12 @@ export function bindComponentTags(root, rootCtx, disposers) {
427
452
  for (const node of renderedNodes)
428
453
  nodeExpando(node).__pithyComponentDom = true;
429
454
  let replaced = true;
455
+ let hidden = false;
430
456
  try {
431
- el.replaceWith(...renderedNodes);
457
+ // A boundary that caught a crash in this render may have hidden `el`.
458
+ hidden = replaceHidden(el, renderedNodes);
459
+ if (!hidden)
460
+ el.replaceWith(...renderedNodes);
432
461
  }
433
462
  catch (err) {
434
463
  // A failed replacement leaves the raw <${tag}> exactly where a crash
@@ -444,6 +473,8 @@ export function bindComponentTags(root, rootCtx, disposers) {
444
473
  // an earlier detached attempt's crash is genuinely no longer the outcome.
445
474
  if (isSSRMode() && replaced)
446
475
  clearSSRRenderCrash(el);
476
+ for (const watch of staleWatchers)
477
+ watch();
447
478
  // Forward class from component tag onto the rendered root element
448
479
  if (forwardedClass && forwardTarget) {
449
480
  for (const cls of forwardedClass.split(/\s+/)) {
@@ -451,6 +482,10 @@ export function bindComponentTags(root, rootCtx, disposers) {
451
482
  forwardTarget.classList.add(cls);
452
483
  }
453
484
  }
485
+ // Before any binding pass below, which can throw.
486
+ const teardown = componentDisposer(destroy, disposeSetup, renderedNodes[0] ?? (replaced ? null : el));
487
+ if (teardown)
488
+ disposers.push(teardown);
454
489
  // Forward captured attributes so subsequent binders can attach the bindings
455
490
  if (forwardedAttrs.length > 0 && forwardTarget) {
456
491
  applyForwardedAttrs(forwardTarget, forwardedAttrs, tag);
@@ -460,12 +495,13 @@ export function bindComponentTags(root, rootCtx, disposers) {
460
495
  const classToggles = Object.keys(pithyNode?.directives?.classMap ?? {});
461
496
  if (classToggles.length)
462
497
  nodeExpando(forwardTarget).__classToggles = classToggles;
463
- }
464
- if (disposeSetup) {
465
- disposers.push(disposeSetup);
466
- }
467
- if (typeof destroy === 'function') {
468
- disposers.push(destroy);
498
+ // Hidden, it is out of reach of this fragment's later passes. An active
499
+ // nested boundary `hideContent` kept in place is still within reach.
500
+ if (hidden && !forwardTarget.parentNode) {
501
+ const detached = document.createDocumentFragment();
502
+ detached.append(forwardTarget);
503
+ bindAfterComponents(detached, localCtx, disposers);
504
+ }
469
505
  }
470
506
  }
471
507
  }
@@ -1 +1 @@
1
- {"version":3,"file":"bindComponentsTags.js","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,8BAA8B,EAC9B,wBAAwB,EACxB,UAAU,GAEX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAS7D;;;GAGG;AACH,0EAA0E;AAC1E,qEAAqE;AACrE,8CAA8C;AAC9C,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC9C,MAAM,qBAAqB,GAAG,IAAI,OAAO,EAAa,CAAC;AAEvD,qGAAqG;AACrG,MAAM,UAAU,2BAA2B;IACzC,mBAAmB,CAAC,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,UAAU,CACjB,EAAW,EACX,OAAgC;IAEhC,IAAI,CAAC,GAAmB,EA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CAAC,CAAC;YACxD,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;YACtE,IAAI,UAAU,CAAC,MAAM;gBACnB,WAAW,CAAC,aAAa,CAAC,CAAC,YAAY,GAAG,UAAU,CAAC;YACvD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC;YACxE,IAAI,YAAY,CAAC,MAAM;gBACrB,WAAW,CAAC,aAAa,CAAC,CAAC,cAAc,GAAG,YAAY,CAAC;QAC7D,CAAC;QAED,IAAI,YAAY,EAAE,CAAC;YACjB,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.components\",\n \"title\": \"Component Tag Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { compileExpression } from '../compileExpression';\nimport { boundaryForElement, runWithBoundary } from './bindErrorBoundary';\nimport { collectSlotMap } from '../contentProjection';\nimport {\n componentChildDirectiveMessage,\n componentChildDirectives,\n nativeTags,\n type PithyNode,\n} from '@pithyjs/compiler';\nimport { collectForwardedAttrs, applyForwardedAttrs } from './forwardedAttrs';\nimport { createRoot, untrack } from '@pithyjs/signals';\nimport { nodeExpando } from '../nodeExpando';\nimport { pithyGlobals } from '../../types/globals';\nimport { isSSRMode } from '../ssrMode';\nimport { clearSSRRenderCrash, reportComponentFailure } from '../ssrCrashes';\nimport { isRenderableComponentEl } from '../componentResult';\nimport { parsePropNames, type PropNames } from './propNames';\n\ninterface ComponentResult {\n /** Any DOM node — see the `Component` type for why this is not narrower. */\n el: Node;\n destroy?: () => void;\n}\ntype ComponentFn = (props: Record<string, unknown>) => ComponentResult;\n\n/**\n * Find the closest element-scoped context we attach in createLoopItem().\n * This is what exposes item(), gIdx(), count(), etc.\n */\n// Warn once per component/tag pair — the same idiom re-renders constantly\n// (e.g. a panel importing Button while using a native <button>), and\n// repeating the warning drowns out real ones.\nconst warnedComponentTags = new Set<string>();\nconst warnedChildDirectives = new WeakSet<PithyNode>();\n\n/** Test-only: forget which tags were warned about, so each render warns as a fresh process would. */\nexport function __resetComponentTagWarnings(): void {\n warnedComponentTags.clear();\n}\n\nfunction nearestCtx(\n el: Element,\n rootCtx: Record<string, unknown>\n): Record<string, unknown> {\n let n: Element | null = el;\n while (n) {\n const local = nodeExpando(n).__pithyCtx;\n if (local) return local;\n n = n.parentElement;\n }\n return rootCtx;\n}\n\n/**\n * Detect whether a node is inside a subtree that represents a NOT-YET-EXPANDED nested loop.\n * Those hosts are tagged in createLoopManager.createLoopItem() via `__pithySkipText`,\n * and real templates may also still carry @for / data-for before expansion.\n * We must *defer* binding for anything under such a host, otherwise expressions like item()\n * will throw ReferenceError (because inner loop ctx isn’t created yet).\n */\nfunction isInsidePendingLoopZone(node: Element): boolean {\n let p: Element | null = node;\n while (p) {\n if (nodeExpando(p).__pithySkipText) return true;\n if (\n p.hasAttribute &&\n (p.hasAttribute('@for') || p.hasAttribute('data-for'))\n ) {\n return true;\n }\n p = p.parentElement;\n }\n return false;\n}\n\n/** Evaluate `expr` in `ctx`. Try engine compiler first, then args-style fallback. */\nfunction evalInCtx(expr: string, ctx: Record<string, unknown>): unknown {\n // 1) Preferred: compileExpression uses `with(ctx) { return (...) }`\n try {\n const f = compileExpression(expr, ctx);\n try {\n return f();\n } catch {\n /* fall through to fallback */\n }\n } catch {\n /* fall through to fallback */\n }\n\n // 2) Fallback: args-style evaluator (robust even if compileExpression throws)\n const keys = Object.keys(ctx);\n const vals = keys.map(k => ctx[k]);\n // eslint-disable-next-line no-new-func -- args-style template expression evaluation is a core framework feature\n const fn = new Function(...keys, `return (${expr});`) as (\n ...args: unknown[]\n ) => unknown;\n return fn(...vals);\n}\n\nconst propNameCache = new WeakMap<ComponentFn, PropNames>();\n\nfunction readPropNames(componentFn: ComponentFn): PropNames {\n let cached = propNameCache.get(componentFn);\n if (!cached) {\n try {\n cached = parsePropNames(componentFn.toString());\n } catch {\n cached = { names: [], fromParam: false, exhaustive: false };\n }\n propNameCache.set(componentFn, cached);\n }\n return cached;\n}\n\nfunction extractExpectedPropNames(componentFn: ComponentFn): string[] {\n return readPropNames(componentFn).names;\n}\n\nconst warnedBoundProps = new Set<string>();\nconst GLOBAL_ATTRS = new Set([\n 'id',\n 'class',\n 'style',\n 'title',\n 'role',\n 'tabindex',\n 'hidden',\n]);\n\nfunction warnBoundProps(\n componentFn: ComponentFn,\n el: Element,\n componentName: string\n): void {\n const expected = extractExpectedPropNames(componentFn);\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith('data-bind-')) continue;\n const bound = attr.name.slice('data-bind-'.length);\n if (GLOBAL_ATTRS.has(bound)) continue;\n const prop = expected.find(p => p.toLowerCase() === bound);\n const key = `${componentName} ${bound}`;\n if (!prop || warnedBoundProps.has(key)) continue;\n warnedBoundProps.add(key);\n console.warn(\n `[PithyJS] <${componentName}> [${bound}] sets an attribute on the rendered root, not the \\`${prop}\\` prop. Write ${prop}=\"…\" without brackets to set the prop; for a live value pass a signal or () => … if the prop accepts one.`\n );\n }\n}\n\n/** Dev warnings for unexpected props (only if destructuring is present). */\nfunction validateComponentProps(\n componentFn: ComponentFn,\n props: Record<string, unknown>,\n componentName: string\n): void {\n const { names: allNames, exhaustive } = readPropNames(componentFn);\n if (!exhaustive || allNames.length === 0) return;\n\n const passed = Object.keys(props);\n const expectedSet = new Set(allNames);\n\n const unexpected = passed.filter(p => !expectedSet.has(p));\n if (unexpected.length) {\n console.warn(\n `[PithyJS] 🔍 Component <${componentName}> received unexpected props: ${unexpected.join(\n ', '\n )}\\nExpected props: ${allNames.join(', ')}\\nPassed props: ${passed.join(', ')}`\n );\n }\n\n // NOTE: We intentionally do NOT warn about \"missing\" props here.\n // In template-driven usage, props are assembled at runtime by\n // bindComponentTags(), so TypeScript cannot catch missing required\n // props in this path. Components should self-validate critical\n // props where appropriate (e.g. Toggle warns on empty label).\n}\n\n/** DOM a component already rendered: its native tags may share a component's name. */\nfunction inComponentDom(el: Element): boolean {\n for (let n: Element | null = el; n; n = n.parentElement)\n if (nodeExpando(n).__pithyComponentDom) return true;\n return false;\n}\n\n/** Map lowercased DOM attr name to expected prop name (case-insensitive). */\nfunction normalizePropName(\n authoredName: string,\n expectedProps: string[]\n): string {\n if (expectedProps.includes(authoredName)) return authoredName;\n const lower = authoredName.toLowerCase();\n const matches = expectedProps.filter(p => p.toLowerCase() === lower);\n return matches.length === 1 ? matches[0] : authoredName;\n}\n\n/**\n * Replace custom component tags (<Counter/>, <NestedComponent/>) with rendered output.\n * - Skips anything under a pending nested loop host (bind after loop expansion)\n * - Evaluates prop expressions in nearest loop ctx\n * - Case-insensitive prop name normalization\n * - No raw-string fallback (prevents things like calling count() on a string)\n */\n/** @codexApi {\"parent\":\"pithy.runtime.components\",\"name\":\"bindComponentTags\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindComponentTags(\n root: Element | DocumentFragment,\n rootCtx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // case-insensitive tag lookup from context\n const tagMap = new Map<string, unknown>(\n Object.keys(rootCtx).map(k => [k.toLowerCase(), rootCtx[k]])\n );\n\n const scope =\n root instanceof Element ? (root as Element) : (root as DocumentFragment);\n const elements = Array.from(scope.querySelectorAll('*'));\n\n for (const el of elements) {\n // Skip elements removed from the tree by a parent component's render, or\n // hidden by an `@error-boundary` that has since activated.\n if (!scope.contains(el)) {\n // An element that has left the tree contributes nothing to the output, so\n // a crash recorded for it on an earlier DETACHED pass is stale. Leaving it\n // fails a route that rendered correctly: with two crashing components\n // under one boundary inside an `@if`, the detached pass records both, the\n // retry lets the boundary accept the first, and accepting synchronously\n // hides the second — which then never gets a retry to retract it.\n if (isSSRMode()) clearSSRRenderCrash(el);\n continue;\n }\n\n // Defer components inside not-yet-expanded loops\n if (isInsidePendingLoopZone(el)) continue;\n\n // A build's placeholder carries no AST: its children are DOM, which only\n // the AOT binder reads.\n const aotMount = nodeExpando(el).__pithyAotMount;\n if (aotMount) {\n // Marked as below, so the text pass skips what the component rendered.\n for (const node of aotMount(disposers))\n nodeExpando(node).__pithyComponentDom = true;\n continue;\n }\n\n const tag = el.tagName.toLowerCase();\n\n // Check if the parser marked this element as a component\n // This is the authoritative source - it checks originalTagName starts with uppercase\n // AND the tag name exists in importedIdentifiers\n const pithyNode = nodeExpando(el).__pithyNode;\n if (pithyNode) {\n // Parser processed this element - use its isComponent flag\n if (!pithyNode.isComponent) {\n // DEV: Warn if there's a component that matches case-insensitively\n // This helps developers catch typos like <button> when they meant <Button>\n // Skip warning if we're inside a component's render (the component might\n // legitimately use native elements like <button> in its implementation)\n const isInsideComponentRender =\n !!pithyGlobals().__pithyRenderingComponent;\n if (\n import.meta.env?.DEV &&\n !isInsideComponentRender &&\n !inComponentDom(el)\n ) {\n const matchingComponent = tagMap.get(tag);\n if (matchingComponent && typeof matchingComponent === 'function') {\n // Find the actual component name from context\n const componentName = Object.keys(rootCtx).find(\n k => k.toLowerCase() === tag && rootCtx[k] === matchingComponent\n );\n const warnKey = `${componentName}:${pithyNode.originalTagName}`;\n if (\n componentName &&\n componentName !== pithyNode.originalTagName &&\n !warnedComponentTags.has(warnKey)\n ) {\n warnedComponentTags.add(warnKey);\n console.warn(\n `[PithyJS] ⚠️ Component '${componentName}' is imported but used as '<${pithyNode.originalTagName}>'. ` +\n `Components must use PascalCase. Use '<${componentName}>' instead.`\n );\n }\n }\n }\n continue;\n }\n } else {\n // Fallback for elements not processed by our parser:\n // Skip native HTML elements to prevent <button> matching Button component\n if (nativeTags.has(tag)) continue;\n // Rendered already, e.g. a build's slot content.\n if (inComponentDom(el)) continue;\n }\n\n if (\n import.meta.env?.DEV &&\n pithyNode &&\n !warnedChildDirectives.has(pithyNode)\n ) {\n warnedChildDirectives.add(pithyNode);\n for (const name of componentChildDirectives(pithyNode))\n console.warn(\n `[pithy] ${componentChildDirectiveMessage(pithyNode.originalTagName ?? tag, name)}`\n );\n }\n\n let candidate = tagMap.get(tag);\n\n if (!candidate) continue;\n\n // Support default exports\n if (\n candidate &&\n typeof candidate === 'object' &&\n 'default' in candidate &&\n typeof candidate.default === 'function'\n ) {\n candidate = candidate.default;\n }\n if (typeof candidate !== 'function') continue;\n\n const componentFn = candidate as ComponentFn;\n const localCtx = nearestCtx(el, rootCtx); // crucial for item(), gIdx(), etc.\n\n // Extract expected props for validation (DEV) and prop name normalization (always)\n // This ensures case-insensitive matching works even when originalAttrs is unavailable\n const { names, fromParam } = readPropNames(componentFn);\n const expectedProps = fromParam ? names : [];\n\n // Preserve originally-authored attribute names/casing from the parsed template\n // (pithyNode already extracted above for isComponent check)\n const originalAttrs: Record<string, string> | undefined =\n pithyNode?.originalAttrs;\n\n const props: Record<string, unknown> = {};\n\n // Evaluate attributes as expressions in localCtx\n for (const attr of Array.from(el.attributes)) {\n const name = attr.name;\n const raw = attr.value;\n\n // Skip internal/behavioral attributes\n if (name.startsWith('data-')) continue;\n if (name === 'class' || name === 'style') continue;\n\n // Prefer originally-authored name (preserve casing), else DOM name\n const authored = originalAttrs?.[name] ?? name;\n const propName = normalizePropName(authored, expectedProps);\n\n try {\n const value = untrack(() => evalInCtx(raw, localCtx));\n props[propName] = value; // only set when evaluation succeeds\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[PithyJS] ⚠️ Failed to evaluate prop \"${propName}\" = \"${raw}\"`,\n err\n );\n }\n // IMPORTANT: do NOT set a raw string fallback here.\n // Leaving it undefined lets the child use defaults and avoids count()-on-string.\n }\n }\n\n // Validate props for all components in DEV mode.\n // Native elements are already filtered out earlier (line 197 for fallback, line 171 for parser).\n if (import.meta.env?.DEV) {\n const displayTag = pithyNode?.originalTagName || tag;\n validateComponentProps(componentFn, props, displayTag);\n warnBoundProps(componentFn, el, displayTag);\n }\n\n // Collect content projection SlotMap from component children\n const pithyChildren: PithyNode[] = pithyNode?.children || [];\n const slotMap = collectSlotMap(pithyChildren, localCtx);\n\n // Create enhanced context with SlotMap for content projection\n const componentContext = {\n ...localCtx,\n __slotMap: slotMap,\n __childAstNodes: pithyChildren,\n __childFactory: undefined,\n };\n\n // Find nearest error boundary for this component\n const boundaryEl = el.closest('[data-error]') as Element | null;\n const boundary = boundaryForElement(boundaryEl);\n\n // Invoke component under boundary context; expect { el, destroy }\n let out: ComponentResult | undefined;\n let disposeSetup: (() => void) | undefined;\n try {\n out = runWithBoundary(boundary, () => {\n // Store the enhanced context globally for the component's html() calls to access.\n // This per-component context contains __slotMap for content projection.\n //\n // In SSR, there are TWO context sources that html() merges:\n // 1. AsyncLocalStorage context (__getComponentContext) - request-level isolation\n // 2. This global context (__pithyComponentContext) - per-component __slotMap\n //\n // Both are needed: AsyncLocalStorage provides request isolation, while this\n // global provides the __slotMap that changes for each component render.\n const g = pithyGlobals();\n const originalContext = g.__pithyComponentContext;\n const wasRendering = g.__pithyRenderingComponent;\n g.__pithyComponentContext = componentContext;\n // Mark that we're rendering a component to suppress casing warnings for\n // native elements used in component implementations (e.g., <button> in Button)\n g.__pithyRenderingComponent = true;\n\n try {\n const result = createRoot(disposeRoot => {\n disposeSetup = disposeRoot;\n return componentFn(props);\n });\n return result;\n } finally {\n // Restore original context\n g.__pithyComponentContext = originalContext;\n g.__pithyRenderingComponent = wasRendering;\n }\n });\n } catch (err) {\n // Route sync render errors to the nearest boundary with escalation\n if (boundary) {\n const error = err instanceof Error ? err : new Error(String(err));\n // A boundary being in scope does not mean it accepted the error: an\n // already-active boundary with no free ancestor drops it (React's\n // first-error-wins). A component inside that boundary's `@fallback` is\n // the everyday case, and the fallback is what the user actually sees.\n const accepted = reportComponentFailure(el, tag, error, boundary);\n if (import.meta.env?.DEV) {\n // Say which of the two actually happened. \"Captured\" on a rejected\n // error reports the opposite of the truth, and this branch exists\n // precisely because the two are not the same.\n console.log(\n accepted\n ? `[ErrorBoundary] Captured sync render error in <${tag}>:`\n : `[ErrorBoundary] Boundary already active — error from <${tag}> was NOT captured:`,\n error.message\n );\n }\n continue;\n }\n\n // No boundary in scope *yet*. Degrading is still the right call here in\n // both modes: throwing would pre-empt the retry pass that gives an\n // `@error-boundary` its only chance to claim a crash raised while the\n // subtree was detached.\n //\n // A static/server render additionally records the crash. Nobody reads a\n // console during `pithy-ssg`, so this used to leave the raw <${tag}> in\n // the emitted HTML while the route still counted as rendered and the CLI\n // exited 0 (BUG-018). Anything still recorded when the render finishes\n // makes the SSR renderer throw, and the per-route catch in `vite-ssg.ts`\n // fails that route.\n reportComponentFailure(\n el,\n tag,\n err instanceof Error ? err : new Error(String(err)),\n null\n );\n\n console.error(`❌ Component <${tag}> crashed during render:`, err);\n continue;\n }\n\n if (\n !out ||\n typeof out !== 'object' ||\n !('el' in out) ||\n !isRenderableComponentEl(out.el, el)\n ) {\n console.warn(\n `❌ Invalid render result from <${tag}>. Expected { el, destroy }`\n );\n // Not a throw, but the same outcome as one: the raw <${tag}> is left in\n // the document and the subtree never renders. Under SSR that is content\n // silently missing from the emitted HTML, so it is recorded exactly like\n // a crash (BUG-018). Recorded rather than merely left in place, because\n // this attempt may also be retracting an earlier attempt's record.\n // Same funnel as a throw: a boundary above this component gets the\n // chance to claim it and render its fallback, and only an unclaimed\n // failure is recorded. Bypassing this meant a component under\n // `@error-boundary` that returned garbage failed the route with the\n // boundary signal still null.\n reportComponentFailure(\n el,\n tag,\n new Error(\n `Invalid render result from <${tag}>; expected { el, destroy }`\n ),\n boundary\n );\n disposeSetup?.();\n continue;\n }\n\n const { el: renderedEl, destroy } = out;\n\n // Capture class and data-* attributes for forwarding to rendered root:\n // directive bindings (data-on-*, data-bind-*, data-class-toggle-*,\n // data-classes, data-style-*) plus any author-written data-* attribute.\n const forwardedClass = el.getAttribute('class');\n const forwardedAttrs = collectForwardedAttrs(el);\n\n const isFragment = renderedEl.nodeType === Node.DOCUMENT_FRAGMENT_NODE;\n let forwardTarget: HTMLElement | null = null;\n const hasForwardables = !!(forwardedClass || forwardedAttrs.length > 0);\n if (hasForwardables) {\n if (isFragment) {\n forwardTarget = (renderedEl as DocumentFragment)\n .firstElementChild as HTMLElement | null;\n if (import.meta.env?.DEV && !forwardTarget) {\n const displayTag = pithyNode?.originalTagName || tag;\n console.warn(\n `[PithyJS] <${displayTag}> has class or data-* attributes but returns a fragment with no element children — forwarding skipped.`\n );\n }\n } else if (renderedEl.nodeType === Node.ELEMENT_NODE) {\n forwardTarget = renderedEl as HTMLElement;\n }\n }\n\n const renderedNodes = isFragment\n ? Array.from(renderedEl.childNodes)\n : [renderedEl];\n for (const node of renderedNodes)\n nodeExpando(node).__pithyComponentDom = true;\n\n let replaced = true;\n try {\n el.replaceWith(...renderedNodes);\n } catch (err) {\n // A failed replacement leaves the raw <${tag}> exactly where a crash\n // would have, so it is the same content loss and is recorded the same way.\n replaced = false;\n reportComponentFailure(\n el,\n tag,\n err instanceof Error ? err : new Error(String(err)),\n boundary\n );\n console.error(`❌ Failed to replace <${tag}> with rendered DOM:`, err);\n }\n\n // Retracted only here, and in the boundary catch above — never eagerly at\n // the top of an attempt, where any early `continue` added later would\n // silently drop a real record. This is the point at which the component is\n // known to have produced a usable node AND to have reached the document, so\n // an earlier detached attempt's crash is genuinely no longer the outcome.\n if (isSSRMode() && replaced) clearSSRRenderCrash(el);\n\n // Forward class from component tag onto the rendered root element\n if (forwardedClass && forwardTarget) {\n for (const cls of forwardedClass.split(/\\s+/)) {\n if (cls) forwardTarget.classList.add(cls);\n }\n }\n\n // Forward captured attributes so subsequent binders can attach the bindings\n if (forwardedAttrs.length > 0 && forwardTarget) {\n applyForwardedAttrs(forwardTarget, forwardedAttrs, tag);\n const styleProps = Object.keys(pithyNode?.directives?.styleMap ?? {});\n if (styleProps.length)\n nodeExpando(forwardTarget).__styleProps = styleProps;\n const classToggles = Object.keys(pithyNode?.directives?.classMap ?? {});\n if (classToggles.length)\n nodeExpando(forwardTarget).__classToggles = classToggles;\n }\n\n if (disposeSetup) {\n disposers.push(disposeSetup);\n }\n\n if (typeof destroy === 'function') {\n disposers.push(destroy);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"bindComponentsTags.js","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EACL,8BAA8B,EAC9B,wBAAwB,EACxB,UAAU,GAEX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAA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,qEAAqE;YACrE,IAAI,MAAM,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC;gBACxC,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;gBACnD,QAAQ,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;gBAC/B,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.components\",\n \"title\": \"Component Tag Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { compileExpression } from '../compileExpression';\nimport { isTemplateAttr } from './declaredDirective';\nimport {\n boundaryForElement,\n currentBoundary,\n replaceHidden,\n runWithBoundary,\n slotContentHidden,\n withSlotBoundary,\n} from './bindErrorBoundary';\nimport { bindAfterComponents } from './bindAfterComponents';\nimport { collectSlotMap, inProjectedContent } from '../contentProjection';\nimport {\n componentChildDirectiveMessage,\n componentChildDirectives,\n nativeTags,\n type PithyNode,\n} from '@pithyjs/compiler';\nimport { collectForwardedAttrs, applyForwardedAttrs } from './forwardedAttrs';\nimport { createRoot, untrack } from '@pithyjs/signals';\nimport { watchStaleRowProp } from './staleRowProps';\nimport { nodeExpando } from '../nodeExpando';\nimport { componentDisposer } from '../disposeOrder';\nimport { pithyGlobals } from '../../types/globals';\nimport { isSSRMode } from '../ssrMode';\nimport { clearSSRRenderCrash, reportComponentFailure } from '../ssrCrashes';\nimport { isRenderableComponentEl } from '../componentResult';\nimport { parsePropNames, type PropNames } from './propNames';\n\ninterface ComponentResult {\n /** Any DOM node — see the `Component` type for why this is not narrower. */\n el: Node;\n destroy?: () => void;\n}\ntype ComponentFn = (props: Record<string, unknown>) => ComponentResult;\n\n/**\n * Find the closest element-scoped context we attach in createLoopItem().\n * This is what exposes item(), gIdx(), count(), etc.\n */\n// Warn once per component/tag pair — the same idiom re-renders constantly\n// (e.g. a panel importing Button while using a native <button>), and\n// repeating the warning drowns out real ones.\nconst warnedComponentTags = new Set<string>();\nconst warnedChildDirectives = new WeakSet<PithyNode>();\n\n/** Test-only: forget which tags were warned about, so each render warns as a fresh process would. */\nexport function __resetComponentTagWarnings(): void {\n warnedComponentTags.clear();\n}\n\nfunction nearestCtx(\n el: Element,\n rootCtx: Record<string, unknown>\n): Record<string, unknown> {\n let n: Element | null = el;\n while (n) {\n const local = nodeExpando(n).__pithyCtx;\n if (local) return local;\n n = n.parentElement;\n }\n return rootCtx;\n}\n\n/**\n * Detect whether a node is inside a subtree that represents a NOT-YET-EXPANDED nested loop.\n * Those hosts are tagged in createLoopManager.createLoopItem() via `__pithySkipText`,\n * and real templates may also still carry @for / data-for before expansion.\n * We must *defer* binding for anything under such a host, otherwise expressions like item()\n * will throw ReferenceError (because inner loop ctx isn’t created yet).\n */\nfunction isInsidePendingLoopZone(node: Element): boolean {\n let p: Element | null = node;\n while (p) {\n if (nodeExpando(p).__pithySkipText) return true;\n if (\n p.hasAttribute &&\n (p.hasAttribute('@for') || p.hasAttribute('data-for'))\n ) {\n return true;\n }\n p = p.parentElement;\n }\n return false;\n}\n\n/** Evaluate `expr` in `ctx`. Try engine compiler first, then args-style fallback. */\nfunction evalInCtx(expr: string, ctx: Record<string, unknown>): unknown {\n // 1) Preferred: compileExpression uses `with(ctx) { return (...) }`\n try {\n const f = compileExpression(expr, ctx);\n try {\n return f();\n } catch {\n /* fall through to fallback */\n }\n } catch {\n /* fall through to fallback */\n }\n\n // 2) Fallback: args-style evaluator (robust even if compileExpression throws)\n const keys = Object.keys(ctx);\n const vals = keys.map(k => ctx[k]);\n // eslint-disable-next-line no-new-func -- args-style template expression evaluation is a core framework feature\n const fn = new Function(...keys, `return (${expr});`) as (\n ...args: unknown[]\n ) => unknown;\n return fn(...vals);\n}\n\nconst propNameCache = new WeakMap<ComponentFn, PropNames>();\n\nfunction readPropNames(componentFn: ComponentFn): PropNames {\n let cached = propNameCache.get(componentFn);\n if (!cached) {\n try {\n cached = parsePropNames(componentFn.toString());\n } catch {\n cached = { names: [], fromParam: false, exhaustive: false };\n }\n propNameCache.set(componentFn, cached);\n }\n return cached;\n}\n\nfunction extractExpectedPropNames(componentFn: ComponentFn): string[] {\n return readPropNames(componentFn).names;\n}\n\nconst warnedBoundProps = new Set<string>();\nconst GLOBAL_ATTRS = new Set([\n 'id',\n 'class',\n 'style',\n 'title',\n 'role',\n 'tabindex',\n 'hidden',\n]);\n\nfunction warnBoundProps(\n componentFn: ComponentFn,\n el: Element,\n componentName: string\n): void {\n const expected = extractExpectedPropNames(componentFn);\n for (const attr of Array.from(el.attributes)) {\n if (!attr.name.startsWith('data-bind-')) continue;\n const bound = attr.name.slice('data-bind-'.length);\n if (bound === 'slot' && !warnedBoundProps.has(`${componentName} slot`)) {\n warnedBoundProps.add(`${componentName} slot`);\n console.warn(\n `[PithyJS] <${componentName}> [slot] cannot choose a slot: the key is read as a literal, so this lands in the default slot. Write slot=\"name\".`\n );\n }\n if (GLOBAL_ATTRS.has(bound)) continue;\n const prop = expected.find(p => p.toLowerCase() === bound);\n const key = `${componentName} ${bound}`;\n if (!prop || warnedBoundProps.has(key)) continue;\n warnedBoundProps.add(key);\n console.warn(\n `[PithyJS] <${componentName}> [${bound}] sets an attribute on the rendered root, not the \\`${prop}\\` prop. Write ${prop}=\"…\" without brackets to set the prop; for a live value pass a signal or () => … if the prop accepts one.`\n );\n }\n}\n\n/** Dev warnings for unexpected props (only if destructuring is present). */\nfunction validateComponentProps(\n componentFn: ComponentFn,\n props: Record<string, unknown>,\n componentName: string\n): void {\n const { names: allNames, exhaustive } = readPropNames(componentFn);\n if (!exhaustive || allNames.length === 0) return;\n\n const passed = Object.keys(props);\n const expectedSet = new Set(allNames);\n\n const unexpected = passed.filter(p => !expectedSet.has(p));\n if (unexpected.length) {\n console.warn(\n `[PithyJS] 🔍 Component <${componentName}> received unexpected props: ${unexpected.join(\n ', '\n )}\\nExpected props: ${allNames.join(', ')}\\nPassed props: ${passed.join(', ')}`\n );\n }\n\n // NOTE: We intentionally do NOT warn about \"missing\" props here.\n // In template-driven usage, props are assembled at runtime by\n // bindComponentTags(), so TypeScript cannot catch missing required\n // props in this path. Components should self-validate critical\n // props where appropriate (e.g. Toggle warns on empty label).\n}\n\n/** DOM a component already rendered: its native tags may share a component's name. */\nfunction inComponentDom(el: Element): boolean {\n for (let n: Element | null = el; n; n = n.parentElement)\n if (nodeExpando(n).__pithyComponentDom) return true;\n return false;\n}\n\n/** Map lowercased DOM attr name to expected prop name (case-insensitive). */\nfunction normalizePropName(\n authoredName: string,\n expectedProps: string[]\n): string {\n if (expectedProps.includes(authoredName)) return authoredName;\n const lower = authoredName.toLowerCase();\n const matches = expectedProps.filter(p => p.toLowerCase() === lower);\n return matches.length === 1 ? matches[0] : authoredName;\n}\n\n/**\n * Replace custom component tags (<Counter/>, <NestedComponent/>) with rendered output.\n * - Skips anything under a pending nested loop host (bind after loop expansion)\n * - Evaluates prop expressions in nearest loop ctx\n * - Case-insensitive prop name normalization\n * - No raw-string fallback (prevents things like calling count() on a string)\n */\n/** @codexApi {\"parent\":\"pithy.runtime.components\",\"name\":\"bindComponentTags\",\"stability\":\"stable\",\"signature\":\"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindComponentTags(\n root: Element | DocumentFragment,\n rootCtx: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n // case-insensitive tag lookup from context\n const tagMap = new Map<string, unknown>(\n Object.keys(rootCtx).map(k => [k.toLowerCase(), rootCtx[k]])\n );\n\n const scope =\n root instanceof Element ? (root as Element) : (root as DocumentFragment);\n const elements = Array.from(scope.querySelectorAll('*'));\n\n for (const el of elements) {\n // Skip elements removed from the tree by a parent component's render, or\n // hidden by an `@error-boundary` that has since activated.\n if (!scope.contains(el)) {\n // An element that has left the tree contributes nothing to the output, so\n // a crash recorded for it on an earlier DETACHED pass is stale. Leaving it\n // fails a route that rendered correctly: with two crashing components\n // under one boundary inside an `@if`, the detached pass records both, the\n // retry lets the boundary accept the first, and accepting synchronously\n // hides the second — which then never gets a retry to retract it.\n if (isSSRMode()) clearSSRRenderCrash(el);\n continue;\n }\n\n // Defer components inside not-yet-expanded loops\n if (isInsidePendingLoopZone(el)) continue;\n\n // A build's placeholder carries no AST: its children are DOM, which only\n // the AOT binder reads.\n const aotMount = nodeExpando(el).__pithyAotMount;\n if (aotMount) {\n // Marked as below, so the text pass skips what the component rendered.\n for (const node of aotMount(disposers))\n nodeExpando(node).__pithyComponentDom = true;\n continue;\n }\n\n const tag = el.tagName.toLowerCase();\n\n // Check if the parser marked this element as a component\n // This is the authoritative source - it checks originalTagName starts with uppercase\n // AND the tag name exists in importedIdentifiers\n const pithyNode = nodeExpando(el).__pithyNode;\n if (pithyNode) {\n // Parser processed this element - use its isComponent flag\n if (!pithyNode.isComponent) {\n // DEV: Warn if there's a component that matches case-insensitively\n // This helps developers catch typos like <button> when they meant <Button>\n // Skip warning if we're inside a component's render (the component might\n // legitimately use native elements like <button> in its implementation)\n const isInsideComponentRender =\n !!pithyGlobals().__pithyRenderingComponent;\n if (\n import.meta.env?.DEV &&\n !isInsideComponentRender &&\n !inComponentDom(el)\n ) {\n const matchingComponent = tagMap.get(tag);\n if (matchingComponent && typeof matchingComponent === 'function') {\n // Find the actual component name from context\n const componentName = Object.keys(rootCtx).find(\n k => k.toLowerCase() === tag && rootCtx[k] === matchingComponent\n );\n const warnKey = `${componentName}:${pithyNode.originalTagName}`;\n if (\n componentName &&\n componentName !== pithyNode.originalTagName &&\n !warnedComponentTags.has(warnKey)\n ) {\n warnedComponentTags.add(warnKey);\n console.warn(\n `[PithyJS] ⚠️ Component '${componentName}' is imported but used as '<${pithyNode.originalTagName}>'. ` +\n `Components must use PascalCase. Use '<${componentName}>' instead.`\n );\n }\n }\n }\n continue;\n }\n } else {\n // Fallback for elements not processed by our parser:\n // Skip native HTML elements to prevent <button> matching Button component\n if (nativeTags.has(tag)) continue;\n // Rendered already, e.g. a build's slot content.\n if (inComponentDom(el)) continue;\n }\n\n if (\n import.meta.env?.DEV &&\n pithyNode &&\n !warnedChildDirectives.has(pithyNode)\n ) {\n warnedChildDirectives.add(pithyNode);\n for (const name of componentChildDirectives(pithyNode))\n console.warn(\n `[pithy] ${componentChildDirectiveMessage(pithyNode.originalTagName ?? tag, name)}`\n );\n }\n\n let candidate = tagMap.get(tag);\n\n if (!candidate) continue;\n\n // Support default exports\n if (\n candidate &&\n typeof candidate === 'object' &&\n 'default' in candidate &&\n typeof candidate.default === 'function'\n ) {\n candidate = candidate.default;\n }\n if (typeof candidate !== 'function') continue;\n // Content a runtime-compiled receiver projected: bound detached, inside the\n // output of the component being rendered.\n const projectedHost =\n !el.closest('[data-error]') && inProjectedContent(el)\n ? pithyGlobals().__pithyComponentContext?.__slotHost\n : undefined;\n // Hidden like a sibling an activated boundary detached: never rendered.\n if (withSlotBoundary(undefined, projectedHost, () => slotContentHidden(el)))\n continue;\n\n const componentFn = candidate as ComponentFn;\n const localCtx = nearestCtx(el, rootCtx); // crucial for item(), gIdx(), etc.\n\n // Extract expected props for validation (DEV) and prop name normalization (always)\n // This ensures case-insensitive matching works even when originalAttrs is unavailable\n const { names, fromParam } = readPropNames(componentFn);\n const expectedProps = fromParam ? names : [];\n\n // Preserve originally-authored attribute names/casing from the parsed template\n // (pithyNode already extracted above for isComponent check)\n const originalAttrs: Record<string, string> | undefined =\n pithyNode?.originalAttrs;\n\n const props: Record<string, unknown> = {};\n\n const staleWatchers: (() => void)[] = [];\n\n // Evaluate attributes as expressions in localCtx\n for (const attr of Array.from(el.attributes)) {\n const name = attr.name;\n const raw = attr.value;\n\n // Skip internal/behavioral attributes\n if (name.startsWith('data-')) continue;\n if (name === 'class' || name === 'style' || name === 'slot') continue;\n if (!isTemplateAttr(attr)) continue;\n\n // Prefer originally-authored name (preserve casing), else DOM name\n const authored = originalAttrs?.[name] ?? name;\n const propName = normalizePropName(authored, expectedProps);\n\n try {\n const value = untrack(() => evalInCtx(raw, localCtx));\n props[propName] = value; // only set when evaluation succeeds\n if (import.meta.env?.DEV) {\n staleWatchers.push(() =>\n watchStaleRowProp(\n localCtx,\n pithyNode ?? el,\n pithyNode?.originalTagName || tag,\n propName,\n raw,\n value,\n () => evalInCtx(raw, localCtx),\n disposers\n )\n );\n }\n } catch (err) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[PithyJS] ⚠️ Failed to evaluate prop \"${propName}\" = \"${raw}\"`,\n err\n );\n }\n // IMPORTANT: do NOT set a raw string fallback here.\n // Leaving it undefined lets the child use defaults and avoids count()-on-string.\n }\n }\n\n // Validate props for all components in DEV mode.\n // Native elements are already filtered out earlier (line 197 for fallback, line 171 for parser).\n if (import.meta.env?.DEV) {\n const displayTag = pithyNode?.originalTagName || tag;\n validateComponentProps(componentFn, props, displayTag);\n warnBoundProps(componentFn, el, displayTag);\n }\n\n // Collect content projection SlotMap from component children\n const pithyChildren: PithyNode[] = pithyNode?.children || [];\n const slotMap = collectSlotMap(pithyChildren, localCtx);\n\n // Create enhanced context with SlotMap for content projection\n const componentContext = {\n ...localCtx,\n __slotMap: slotMap,\n __childAstNodes: pithyChildren,\n __childFactory: undefined,\n __slotHost: el,\n };\n\n // Find nearest error boundary for this component\n const boundaryEl = el.closest('[data-error]') as Element | null;\n // Projected content is bound detached, during its receiver's render.\n const boundary =\n boundaryForElement(boundaryEl) ??\n (!boundaryEl && inProjectedContent(el) ? currentBoundary() : null);\n\n // Invoke component under boundary context; expect { el, destroy }\n let out: ComponentResult | undefined;\n let disposeSetup: (() => void) | undefined;\n try {\n out = runWithBoundary(boundary, () => {\n // Store the enhanced context globally for the component's html() calls to access.\n // This per-component context contains __slotMap for content projection.\n //\n // In SSR, there are TWO context sources that html() merges:\n // 1. AsyncLocalStorage context (__getComponentContext) - request-level isolation\n // 2. This global context (__pithyComponentContext) - per-component __slotMap\n //\n // Both are needed: AsyncLocalStorage provides request isolation, while this\n // global provides the __slotMap that changes for each component render.\n const g = pithyGlobals();\n const originalContext = g.__pithyComponentContext;\n const wasRendering = g.__pithyRenderingComponent;\n g.__pithyComponentContext = componentContext;\n // Mark that we're rendering a component to suppress casing warnings for\n // native elements used in component implementations (e.g., <button> in Button)\n g.__pithyRenderingComponent = true;\n\n try {\n const result = createRoot(disposeRoot => {\n disposeSetup = disposeRoot;\n return componentFn(props);\n });\n return result;\n } finally {\n // Restore original context\n g.__pithyComponentContext = originalContext;\n g.__pithyRenderingComponent = wasRendering;\n }\n });\n } catch (err) {\n // Route sync render errors to the nearest boundary with escalation\n if (boundary) {\n const error = err instanceof Error ? err : new Error(String(err));\n // A boundary being in scope does not mean it accepted the error: an\n // already-active boundary with no free ancestor drops it (React's\n // first-error-wins). A component inside that boundary's `@fallback` is\n // the everyday case, and the fallback is what the user actually sees.\n const accepted = reportComponentFailure(el, tag, error, boundary);\n if (import.meta.env?.DEV) {\n // Say which of the two actually happened. \"Captured\" on a rejected\n // error reports the opposite of the truth, and this branch exists\n // precisely because the two are not the same.\n console.log(\n accepted\n ? `[ErrorBoundary] Captured sync render error in <${tag}>:`\n : `[ErrorBoundary] Boundary already active — error from <${tag}> was NOT captured:`,\n error.message\n );\n }\n continue;\n }\n\n // No boundary in scope *yet*. Degrading is still the right call here in\n // both modes: throwing would pre-empt the retry pass that gives an\n // `@error-boundary` its only chance to claim a crash raised while the\n // subtree was detached.\n //\n // A static/server render additionally records the crash. Nobody reads a\n // console during `pithy-ssg`, so this used to leave the raw <${tag}> in\n // the emitted HTML while the route still counted as rendered and the CLI\n // exited 0 (BUG-018). Anything still recorded when the render finishes\n // makes the SSR renderer throw, and the per-route catch in `vite-ssg.ts`\n // fails that route.\n reportComponentFailure(\n el,\n tag,\n err instanceof Error ? err : new Error(String(err)),\n null\n );\n\n console.error(`❌ Component <${tag}> crashed during render:`, err);\n continue;\n }\n\n if (\n !out ||\n typeof out !== 'object' ||\n !('el' in out) ||\n !isRenderableComponentEl(out.el, el)\n ) {\n console.warn(\n `❌ Invalid render result from <${tag}>. Expected { el, destroy }`\n );\n // Not a throw, but the same outcome as one: the raw <${tag}> is left in\n // the document and the subtree never renders. Under SSR that is content\n // silently missing from the emitted HTML, so it is recorded exactly like\n // a crash (BUG-018). Recorded rather than merely left in place, because\n // this attempt may also be retracting an earlier attempt's record.\n // Same funnel as a throw: a boundary above this component gets the\n // chance to claim it and render its fallback, and only an unclaimed\n // failure is recorded. Bypassing this meant a component under\n // `@error-boundary` that returned garbage failed the route with the\n // boundary signal still null.\n reportComponentFailure(\n el,\n tag,\n new Error(\n `Invalid render result from <${tag}>; expected { el, destroy }`\n ),\n boundary\n );\n disposeSetup?.();\n continue;\n }\n\n const { el: renderedEl, destroy } = out;\n\n // Capture class and data-* attributes for forwarding to rendered root:\n // directive bindings (data-on-*, data-bind-*, data-class-toggle-*,\n // data-classes, data-style-*) plus any author-written data-* attribute.\n const forwardedClass = el.getAttribute('class');\n const forwardedAttrs = collectForwardedAttrs(el);\n\n const isFragment = renderedEl.nodeType === Node.DOCUMENT_FRAGMENT_NODE;\n let forwardTarget: HTMLElement | null = null;\n const hasForwardables = !!(forwardedClass || forwardedAttrs.length > 0);\n if (hasForwardables) {\n if (isFragment) {\n forwardTarget = (renderedEl as DocumentFragment)\n .firstElementChild as HTMLElement | null;\n if (import.meta.env?.DEV && !forwardTarget) {\n const displayTag = pithyNode?.originalTagName || tag;\n console.warn(\n `[PithyJS] <${displayTag}> has class or data-* attributes but returns a fragment with no element children — forwarding skipped.`\n );\n }\n } else if (renderedEl.nodeType === Node.ELEMENT_NODE) {\n forwardTarget = renderedEl as HTMLElement;\n }\n }\n\n const renderedNodes = isFragment\n ? Array.from(renderedEl.childNodes)\n : [renderedEl];\n for (const node of renderedNodes)\n nodeExpando(node).__pithyComponentDom = true;\n\n let replaced = true;\n let hidden = false;\n try {\n // A boundary that caught a crash in this render may have hidden `el`.\n hidden = replaceHidden(el, renderedNodes);\n if (!hidden) el.replaceWith(...renderedNodes);\n } catch (err) {\n // A failed replacement leaves the raw <${tag}> exactly where a crash\n // would have, so it is the same content loss and is recorded the same way.\n replaced = false;\n reportComponentFailure(\n el,\n tag,\n err instanceof Error ? err : new Error(String(err)),\n boundary\n );\n console.error(`❌ Failed to replace <${tag}> with rendered DOM:`, err);\n }\n\n // Retracted only here, and in the boundary catch above — never eagerly at\n // the top of an attempt, where any early `continue` added later would\n // silently drop a real record. This is the point at which the component is\n // known to have produced a usable node AND to have reached the document, so\n // an earlier detached attempt's crash is genuinely no longer the outcome.\n if (isSSRMode() && replaced) clearSSRRenderCrash(el);\n\n for (const watch of staleWatchers) watch();\n\n // Forward class from component tag onto the rendered root element\n if (forwardedClass && forwardTarget) {\n for (const cls of forwardedClass.split(/\\s+/)) {\n if (cls) forwardTarget.classList.add(cls);\n }\n }\n\n // Before any binding pass below, which can throw.\n const teardown = componentDisposer(\n destroy,\n disposeSetup,\n renderedNodes[0] ?? (replaced ? null : el)\n );\n if (teardown) disposers.push(teardown);\n\n // Forward captured attributes so subsequent binders can attach the bindings\n if (forwardedAttrs.length > 0 && forwardTarget) {\n applyForwardedAttrs(forwardTarget, forwardedAttrs, tag);\n const styleProps = Object.keys(pithyNode?.directives?.styleMap ?? {});\n if (styleProps.length)\n nodeExpando(forwardTarget).__styleProps = styleProps;\n const classToggles = Object.keys(pithyNode?.directives?.classMap ?? {});\n if (classToggles.length)\n nodeExpando(forwardTarget).__classToggles = classToggles;\n // Hidden, it is out of reach of this fragment's later passes. An active\n // nested boundary `hideContent` kept in place is still within reach.\n if (hidden && !forwardTarget.parentNode) {\n const detached = document.createDocumentFragment();\n detached.append(forwardTarget);\n bindAfterComponents(detached, localCtx, disposers);\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bindDefaultTwoWay.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindDefaultTwoWay.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAqBF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,qOAAqO;AACrO,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,GAAG,gBAAgB,EACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAwDN"}
1
+ {"version":3,"file":"bindDefaultTwoWay.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindDefaultTwoWay.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAsBF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,qOAAqO;AACrO,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,OAAO,GAAG,gBAAgB,EACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAwDN"}
@@ -5,6 +5,7 @@
5
5
  "category": "runtime"
6
6
  }
7
7
  */
8
+ import { isDeclaredDirective } from './declaredDirective.js';
8
9
  import { effect, isSignal } from '@pithyjs/signals';
9
10
  // Type guard to check if an element is an HTMLElement
10
11
  function isHTMLElement(element) {
@@ -49,7 +50,7 @@ export function bindDefaultTwoWay(fragment, context, disposers) {
49
50
  }
50
51
  const el = element; // Now TypeScript knows this is HTMLElement
51
52
  Array.from(el.attributes).forEach(attr => {
52
- if (attr.name !== 'data-bind')
53
+ if (attr.name !== 'data-bind' || !isDeclaredDirective(attr))
53
54
  return;
54
55
  const signal = context[attr.value];
55
56
  if (!isWritableSignal(signal)) {
@@ -1 +1 @@
1
- {"version":3,"file":"bindDefaultTwoWay.js","sourceRoot":"","sources":["../../../src/compile/binds/bindDefaultTwoWay.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAQpD,sDAAsD;AACtD,SAAS,aAAa,CAAC,OAAgB;IACrC,OAAO,OAAO,YAAY,WAAW,CAAC;AACxC,CAAC;AAED,8CAA8C;AA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AC;AAED,SAAS,kBAAkB,CAAC,EAAe,EAAE,IAAY;IACvD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACxC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,oBAAoB,CAAC,EAAe,EAAE,IAAY;IACzD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAQ,EAAuB,CAAC,OAAO,CAAC;IAC1C,CAAC;IAED,MAAM,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,IAAI,GAAG,KAAK,OAAO,EAAE,CAAC;QACpB,MAAM,OAAO,GAAG,EAAsB,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;QACpD,CAAC;QACD,OAAO,OAAO,CAAC,KAAK,CAAC;IACvB,CAAC;IAED,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;QACvB,OAAQ,EAA0B,CAAC,KAAK,CAAC;IAC3C,CAAC;IAED,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;QACrB,OAAQ,EAAwB,CAAC,KAAK,CAAC;IACzC,CAAC;IAED,OAAQ,EAA4C,CAAC,IAAI,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.two-way-binding\",\n \"title\": \"Two-Way Data Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { effect, isSignal } from '@pithyjs/signals';\n\n// Define a type for writable signals\ninterface WritableSignal<T = unknown> {\n (): T;\n set(value: T): void;\n}\n\n// Type guard to check if an element is an HTMLElement\nfunction isHTMLElement(element: Element): element is HTMLElement {\n return element instanceof HTMLElement;\n}\n\n// Type guard to check if a signal is writable\nfunction isWritableSignal(signal: unknown): signal is WritableSignal {\n return (\n isSignal(signal) && typeof (signal as WritableSignal).set === 'function'\n );\n}\n/**\n * Establishes two-way data binding between HTML elements with `data-bind` attributes and writable signals.\n *\n * This function scans the provided fragment for elements with `data-bind` attributes and creates\n * bidirectional synchronization between the DOM elements and their corresponding signals in the context.\n *\n * **How it works:**\n * 1. Finds all elements with `data-bind` attributes within the fragment\n * 2. For each element, retrieves the corresponding signal from the context using the attribute value\n * 3. Sets up reactive updates: when the signal changes, the DOM element is updated\n * 4. Sets up event listeners: when the user interacts with the element, the signal is updated\n * 5. Automatically infers the appropriate property and event based on the element type\n *\n * **Supported elements:**\n * - `<input>` elements: binds to `value` property (or `checked` for checkboxes/radio buttons)\n * - `<textarea>` elements: binds to `value` property\n * - `<select>` elements: binds to `value` property\n * - Other elements: falls back to `value` property\n *\n * @param fragment - The DOM fragment or element to search for bindable elements\n * @param context - Object containing the signals referenced by `data-bind` attributes\n * @param disposers - Array to collect cleanup functions for proper resource disposal\n *\n * @throws Will log warnings for elements that are not HTMLElements or signals that are not writable\n */\n\n/** @codexApi {\"parent\":\"pithy.runtime.two-way-binding\",\"name\":\"bindDefaultTwoWay\",\"stability\":\"stable\",\"signature\":\"(fragment: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindDefaultTwoWay(\n fragment: Element | DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n fragment.querySelectorAll('[data-bind]').forEach(element => {\n // Type guard to ensure we have an HTMLElement\n if (!isHTMLElement(element)) {\n console.warn(\n `[PithyJS] Element with data-bind is not an HTMLElement:`,\n element\n );\n return;\n }\n\n const el = element; // Now TypeScript knows this is HTMLElement\n\n Array.from(el.attributes).forEach(attr => {\n if (attr.name !== 'data-bind') return;\n\n const signal = context[attr.value];\n\n if (!isWritableSignal(signal)) {\n console.warn(\n `[PithyJS] @bind=\"${attr.value}\" must refer to a writable signal`\n );\n return;\n }\n\n const prop = inferBindableProperty(el);\n const target = el as HTMLElement & Record<string, unknown>;\n\n // Reactive update: signal → DOM\n const effectDisposer = effect(() => {\n const value = signal();\n const currentValue = target[prop];\n if (currentValue !== value) {\n target[prop] = value;\n }\n });\n\n // Event listener: DOM → signal\n const event = inferBindableEvent(el, prop);\n const eventHandler = () => {\n const newVal = extractBindableValue(el, prop);\n signal.set(newVal);\n };\n\n el.addEventListener(event, eventHandler);\n el.removeAttribute('data-bind');\n\n // Add proper cleanup\n disposers.push(() => {\n el.removeEventListener(event, eventHandler);\n if (typeof effectDisposer === 'function') {\n effectDisposer();\n }\n });\n });\n });\n}\n\nfunction inferBindableProperty(el: HTMLElement): string {\n const tag = el.tagName.toLowerCase();\n\n if (tag === 'input') {\n const inputEl = el as HTMLInputElement;\n const type = inputEl.type;\n if (type === 'checkbox' || type === 'radio') return 'checked';\n return 'value';\n }\n\n if (tag === 'textarea') return 'value';\n if (tag === 'select') return 'value';\n\n return 'value'; // fallback\n}\n\nfunction inferBindableEvent(el: HTMLElement, prop: string): string {\n if (prop === 'checked') return 'change';\n return 'input';\n}\n\nfunction extractBindableValue(el: HTMLElement, prop: string): unknown {\n if (prop === 'checked') {\n return (el as HTMLInputElement).checked;\n }\n\n const tag = el.tagName.toLowerCase();\n if (tag === 'input') {\n const inputEl = el as HTMLInputElement;\n const type = inputEl.type;\n if (type === 'number') {\n const numValue = Number(inputEl.value);\n return isNaN(numValue) ? inputEl.value : numValue;\n }\n return inputEl.value;\n }\n\n if (tag === 'textarea') {\n return (el as HTMLTextAreaElement).value;\n }\n\n if (tag === 'select') {\n return (el as HTMLSelectElement).value;\n }\n\n return (el as HTMLElement & Record<string, unknown>)[prop];\n}\n"]}
1
+ {"version":3,"file":"bindDefaultTwoWay.js","sourceRoot":"","sources":["../../../src/compile/binds/bindDefaultTwoWay.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE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AC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.runtime.two-way-binding\",\n \"title\": \"Two-Way Data Binding System\",\n \"category\": \"runtime\"\n}\n*/\n\nimport { isDeclaredDirective } from './declaredDirective';\nimport { effect, isSignal } from '@pithyjs/signals';\n\n// Define a type for writable signals\ninterface WritableSignal<T = unknown> {\n (): T;\n set(value: T): void;\n}\n\n// Type guard to check if an element is an HTMLElement\nfunction isHTMLElement(element: Element): element is HTMLElement {\n return element instanceof HTMLElement;\n}\n\n// Type guard to check if a signal is writable\nfunction isWritableSignal(signal: unknown): signal is WritableSignal {\n return (\n isSignal(signal) && typeof (signal as WritableSignal).set === 'function'\n );\n}\n/**\n * Establishes two-way data binding between HTML elements with `data-bind` attributes and writable signals.\n *\n * This function scans the provided fragment for elements with `data-bind` attributes and creates\n * bidirectional synchronization between the DOM elements and their corresponding signals in the context.\n *\n * **How it works:**\n * 1. Finds all elements with `data-bind` attributes within the fragment\n * 2. For each element, retrieves the corresponding signal from the context using the attribute value\n * 3. Sets up reactive updates: when the signal changes, the DOM element is updated\n * 4. Sets up event listeners: when the user interacts with the element, the signal is updated\n * 5. Automatically infers the appropriate property and event based on the element type\n *\n * **Supported elements:**\n * - `<input>` elements: binds to `value` property (or `checked` for checkboxes/radio buttons)\n * - `<textarea>` elements: binds to `value` property\n * - `<select>` elements: binds to `value` property\n * - Other elements: falls back to `value` property\n *\n * @param fragment - The DOM fragment or element to search for bindable elements\n * @param context - Object containing the signals referenced by `data-bind` attributes\n * @param disposers - Array to collect cleanup functions for proper resource disposal\n *\n * @throws Will log warnings for elements that are not HTMLElements or signals that are not writable\n */\n\n/** @codexApi {\"parent\":\"pithy.runtime.two-way-binding\",\"name\":\"bindDefaultTwoWay\",\"stability\":\"stable\",\"signature\":\"(fragment: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void\"} */\nexport function bindDefaultTwoWay(\n fragment: Element | DocumentFragment,\n context: Record<string, unknown>,\n disposers: (() => void)[]\n): void {\n fragment.querySelectorAll('[data-bind]').forEach(element => {\n // Type guard to ensure we have an HTMLElement\n if (!isHTMLElement(element)) {\n console.warn(\n `[PithyJS] Element with data-bind is not an HTMLElement:`,\n element\n );\n return;\n }\n\n const el = element; // Now TypeScript knows this is HTMLElement\n\n Array.from(el.attributes).forEach(attr => {\n if (attr.name !== 'data-bind' || !isDeclaredDirective(attr)) return;\n\n const signal = context[attr.value];\n\n if (!isWritableSignal(signal)) {\n console.warn(\n `[PithyJS] @bind=\"${attr.value}\" must refer to a writable signal`\n );\n return;\n }\n\n const prop = inferBindableProperty(el);\n const target = el as HTMLElement & Record<string, unknown>;\n\n // Reactive update: signal → DOM\n const effectDisposer = effect(() => {\n const value = signal();\n const currentValue = target[prop];\n if (currentValue !== value) {\n target[prop] = value;\n }\n });\n\n // Event listener: DOM → signal\n const event = inferBindableEvent(el, prop);\n const eventHandler = () => {\n const newVal = extractBindableValue(el, prop);\n signal.set(newVal);\n };\n\n el.addEventListener(event, eventHandler);\n el.removeAttribute('data-bind');\n\n // Add proper cleanup\n disposers.push(() => {\n el.removeEventListener(event, eventHandler);\n if (typeof effectDisposer === 'function') {\n effectDisposer();\n }\n });\n });\n });\n}\n\nfunction inferBindableProperty(el: HTMLElement): string {\n const tag = el.tagName.toLowerCase();\n\n if (tag === 'input') {\n const inputEl = el as HTMLInputElement;\n const type = inputEl.type;\n if (type === 'checkbox' || type === 'radio') return 'checked';\n return 'value';\n }\n\n if (tag === 'textarea') return 'value';\n if (tag === 'select') return 'value';\n\n return 'value'; // fallback\n}\n\nfunction inferBindableEvent(el: HTMLElement, prop: string): string {\n if (prop === 'checked') return 'change';\n return 'input';\n}\n\nfunction extractBindableValue(el: HTMLElement, prop: string): unknown {\n if (prop === 'checked') {\n return (el as HTMLInputElement).checked;\n }\n\n const tag = el.tagName.toLowerCase();\n if (tag === 'input') {\n const inputEl = el as HTMLInputElement;\n const type = inputEl.type;\n if (type === 'number') {\n const numValue = Number(inputEl.value);\n return isNaN(numValue) ? inputEl.value : numValue;\n }\n return inputEl.value;\n }\n\n if (tag === 'textarea') {\n return (el as HTMLTextAreaElement).value;\n }\n\n if (tag === 'select') {\n return (el as HTMLSelectElement).value;\n }\n\n return (el as HTMLElement & Record<string, unknown>)[prop];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bindDeferDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindDeferDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAmCF;;;;;;;;;;GAUG;AACH,mOAAmO;AACnO,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,GAC3B,IAAI,CAkiBN"}
1
+ {"version":3,"file":"bindDeferDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindDeferDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAqCF;;;;;;;;;;GAUG;AACH,mOAAmO;AACnO,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,GAC3B,IAAI,CAoiBN"}
@@ -16,9 +16,11 @@
16
16
  import { createRoot, effect } from '@pithyjs/signals';
17
17
  import { DEFAULT_LAZY_TIMEOUT, } from '@pithyjs/compiler';
18
18
  import { compileExpression } from '../compileExpression.js';
19
+ import { declaredValue } from './declaredDirective.js';
19
20
  import { DEFAULT_VISIBILITY_MARGIN, isLazyHandle, observeVisibilityOnce, } from '../../runtime/index.js';
20
21
  import { boundaryForElement, setBoundaryError } from './bindErrorBoundary.js';
21
22
  import { loadWithTimeout, scheduleByPriority, } from '../../runtime/deferHelpers.js';
23
+ import { setStyleProp } from './bindBoundAttributes.js';
22
24
  /** Unique ID counter for defer anchors */
23
25
  let deferIdCounter = 0;
24
26
  /**
@@ -43,12 +45,12 @@ export function bindDeferDirectives(fragment, context, disposers) {
43
45
  if (element.hasAttribute('data-defer-state'))
44
46
  continue;
45
47
  // Read directive values from data attributes
46
- const trigger = element.dataset.defer;
47
- const loadExpr = element.dataset.load;
48
- const placeholderExpr = element.dataset.placeholder;
49
- const whenExpr = element.dataset.when;
50
- const priority = element.dataset.deferPriority;
51
- const timeoutStr = element.dataset.deferTimeout;
48
+ const trigger = declaredValue(element, 'data-defer');
49
+ const loadExpr = declaredValue(element, 'data-load');
50
+ const placeholderExpr = declaredValue(element, 'data-placeholder');
51
+ const whenExpr = declaredValue(element, 'data-when');
52
+ const priority = declaredValue(element, 'data-defer-priority');
53
+ const timeoutStr = declaredValue(element, 'data-defer-timeout');
52
54
  const timeout = timeoutStr ? parseInt(timeoutStr, 10) : undefined;
53
55
  // Validate required attributes
54
56
  if (!trigger) {
@@ -131,7 +133,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
131
133
  // Add data attribute for test accessibility
132
134
  errorEl.setAttribute('data-defer-error', deferId);
133
135
  // Keep error slot hidden until needed
134
- errorEl.style.display = 'none';
136
+ setStyleProp(errorEl, 'display', 'none');
135
137
  }
136
138
  // Insert anchor and placeholder
137
139
  const parent = element.parentNode;
@@ -142,7 +144,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
142
144
  // For @defer="when", placeholder starts hidden (only shows during loading)
143
145
  // For @defer="visible", placeholder shows immediately (triggers on visibility)
144
146
  if (trigger === 'when' && placeholderEl instanceof HTMLElement) {
145
- placeholderEl.style.display = 'none';
147
+ setStyleProp(placeholderEl, 'display', 'none');
146
148
  }
147
149
  parent.insertBefore(placeholderEl, element);
148
150
  }
@@ -151,7 +153,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
151
153
  parent.insertBefore(errorEl, element);
152
154
  }
153
155
  // Hide the original element (it becomes the container after load)
154
- element.style.display = 'none';
156
+ setStyleProp(element, 'display', 'none');
155
157
  // Track mounted component for cleanup
156
158
  let mountedDestroy = null;
157
159
  let disposeMountedSetup = null;
@@ -208,7 +210,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
208
210
  isMounted = false;
209
211
  // Hide placeholder if it was shown during a cancelled in-flight mount
210
212
  if (placeholderEl && placeholderEl instanceof HTMLElement) {
211
- placeholderEl.style.display = 'none';
213
+ setStyleProp(placeholderEl, 'display', 'none');
212
214
  }
213
215
  // Reset state to pending (ready for re-mount on next trigger)
214
216
  element.setAttribute('data-defer-state', 'pending');
@@ -226,7 +228,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
226
228
  element.setAttribute('data-defer-state', 'loading');
227
229
  // Show placeholder during loading (for @defer="when" it starts hidden)
228
230
  if (placeholderEl && placeholderEl instanceof HTMLElement) {
229
- placeholderEl.style.display = '';
231
+ setStyleProp(placeholderEl, 'display', null);
230
232
  }
231
233
  try {
232
234
  // Load the module with timeout (chunk is cached after first load)
@@ -321,7 +323,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
321
323
  }
322
324
  else if (errorEl) {
323
325
  // No error boundary - fall back to local error slot
324
- errorEl.style.display = '';
326
+ setStyleProp(errorEl, 'display', null);
325
327
  }
326
328
  // Dispatch error event (for programmatic handling)
327
329
  element.dispatchEvent(new CustomEvent('error', {
@@ -330,7 +332,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
330
332
  retry: () => {
331
333
  // Hide error, re-show placeholder if we had one
332
334
  if (errorEl) {
333
- errorEl.style.display = 'none';
335
+ setStyleProp(errorEl, 'display', 'none');
334
336
  }
335
337
  lazyHandle.retry().then(mountComponent);
336
338
  },
@@ -417,7 +419,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
417
419
  elementState === 'error') {
418
420
  // Hide error slot
419
421
  if (errorEl) {
420
- errorEl.style.display = 'none';
422
+ setStyleProp(errorEl, 'display', 'none');
421
423
  }
422
424
  // Mount the component - it will handle state transitions
423
425
  mountComponent();
@@ -476,7 +478,7 @@ export function bindDeferDirectives(fragment, context, disposers) {
476
478
  }
477
479
  // Hide error slot when condition becomes false (after a failed load)
478
480
  if (errorEl) {
479
- errorEl.style.display = 'none';
481
+ setStyleProp(errorEl, 'display', 'none');
480
482
  }
481
483
  }
482
484
  });