@pithyjs/core 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +513 -0
- package/dist/a11y/focus-trap.d.ts +109 -0
- package/dist/a11y/focus-trap.d.ts.map +1 -0
- package/dist/a11y/focus-trap.js +246 -0
- package/dist/a11y/focus-trap.js.map +1 -0
- package/dist/a11y/index.d.ts +12 -0
- package/dist/a11y/index.d.ts.map +1 -0
- package/dist/a11y/index.js +16 -0
- package/dist/a11y/index.js.map +1 -0
- package/dist/a11y/keyboard-utils.d.ts +165 -0
- package/dist/a11y/keyboard-utils.d.ts.map +1 -0
- package/dist/a11y/keyboard-utils.js +321 -0
- package/dist/a11y/keyboard-utils.js.map +1 -0
- package/dist/a11y/roving-tabindex.d.ts +118 -0
- package/dist/a11y/roving-tabindex.d.ts.map +1 -0
- package/dist/a11y/roving-tabindex.js +249 -0
- package/dist/a11y/roving-tabindex.js.map +1 -0
- package/dist/a11y/skip-link.d.ts +55 -0
- package/dist/a11y/skip-link.d.ts.map +1 -0
- package/dist/a11y/skip-link.js +164 -0
- package/dist/a11y/skip-link.js.map +1 -0
- package/dist/compile/bindSwitchCases.d.ts +16 -0
- package/dist/compile/bindSwitchCases.d.ts.map +1 -0
- package/dist/compile/bindSwitchCases.js +323 -0
- package/dist/compile/bindSwitchCases.js.map +1 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts +14 -0
- package/dist/compile/binds/bindBoundAttributes.d.ts.map +1 -0
- package/dist/compile/binds/bindBoundAttributes.js +57 -0
- package/dist/compile/binds/bindBoundAttributes.js.map +1 -0
- package/dist/compile/binds/bindClassDirectives.d.ts +20 -0
- package/dist/compile/binds/bindClassDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindClassDirectives.js +94 -0
- package/dist/compile/binds/bindClassDirectives.js.map +1 -0
- package/dist/compile/binds/bindComponentsTags.d.ts +17 -0
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -0
- package/dist/compile/binds/bindComponentsTags.js +355 -0
- package/dist/compile/binds/bindComponentsTags.js.map +1 -0
- package/dist/compile/binds/bindConditionals.d.ts +16 -0
- package/dist/compile/binds/bindConditionals.d.ts.map +1 -0
- package/dist/compile/binds/bindConditionals.js +102 -0
- package/dist/compile/binds/bindConditionals.js.map +1 -0
- package/dist/compile/binds/bindDefaultTwoWay.d.ts +35 -0
- package/dist/compile/binds/bindDefaultTwoWay.d.ts.map +1 -0
- package/dist/compile/binds/bindDefaultTwoWay.js +128 -0
- package/dist/compile/binds/bindDefaultTwoWay.js.map +1 -0
- package/dist/compile/binds/bindDeferDirectives.d.ts +21 -0
- package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindDeferDirectives.js +465 -0
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -0
- package/dist/compile/binds/bindErrorBoundary.d.ts +71 -0
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -0
- package/dist/compile/binds/bindErrorBoundary.js +389 -0
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -0
- package/dist/compile/binds/bindEventHandlers.d.ts +17 -0
- package/dist/compile/binds/bindEventHandlers.d.ts.map +1 -0
- package/dist/compile/binds/bindEventHandlers.js +174 -0
- package/dist/compile/binds/bindEventHandlers.js.map +1 -0
- package/dist/compile/binds/bindRefDirectives.d.ts +14 -0
- package/dist/compile/binds/bindRefDirectives.d.ts.map +1 -0
- package/dist/compile/binds/bindRefDirectives.js +35 -0
- package/dist/compile/binds/bindRefDirectives.js.map +1 -0
- package/dist/compile/binds/bindTextInterpolations.d.ts +16 -0
- package/dist/compile/binds/bindTextInterpolations.d.ts.map +1 -0
- package/dist/compile/binds/bindTextInterpolations.js +408 -0
- package/dist/compile/binds/bindTextInterpolations.js.map +1 -0
- package/dist/compile/binds/directiveRegistry.d.ts +46 -0
- package/dist/compile/binds/directiveRegistry.d.ts.map +1 -0
- package/dist/compile/binds/directiveRegistry.js +50 -0
- package/dist/compile/binds/directiveRegistry.js.map +1 -0
- package/dist/compile/compileExpression.d.ts +10 -0
- package/dist/compile/compileExpression.d.ts.map +1 -0
- package/dist/compile/compileExpression.js +26 -0
- package/dist/compile/compileExpression.js.map +1 -0
- package/dist/compile/compileNodes.d.ts +32 -0
- package/dist/compile/compileNodes.d.ts.map +1 -0
- package/dist/compile/compileNodes.js +104 -0
- package/dist/compile/compileNodes.js.map +1 -0
- package/dist/compile/compileTemplate.d.ts +64 -0
- package/dist/compile/compileTemplate.d.ts.map +1 -0
- package/dist/compile/compileTemplate.js +157 -0
- package/dist/compile/compileTemplate.js.map +1 -0
- package/dist/compile/contentProjection.d.ts +29 -0
- package/dist/compile/contentProjection.d.ts.map +1 -0
- package/dist/compile/contentProjection.js +210 -0
- package/dist/compile/contentProjection.js.map +1 -0
- package/dist/compile/forLoops/bindForLoops.d.ts +21 -0
- package/dist/compile/forLoops/bindForLoops.d.ts.map +1 -0
- package/dist/compile/forLoops/bindForLoops.js +151 -0
- package/dist/compile/forLoops/bindForLoops.js.map +1 -0
- package/dist/compile/forLoops/createLoopManager.d.ts +51 -0
- package/dist/compile/forLoops/createLoopManager.d.ts.map +1 -0
- package/dist/compile/forLoops/createLoopManager.js +429 -0
- package/dist/compile/forLoops/createLoopManager.js.map +1 -0
- package/dist/compile/forLoops/index.d.ts +6 -0
- package/dist/compile/forLoops/index.d.ts.map +1 -0
- package/dist/compile/forLoops/index.js +8 -0
- package/dist/compile/forLoops/index.js.map +1 -0
- package/dist/compile/forLoops/loopHelpers.d.ts +33 -0
- package/dist/compile/forLoops/loopHelpers.d.ts.map +1 -0
- package/dist/compile/forLoops/loopHelpers.js +69 -0
- package/dist/compile/forLoops/loopHelpers.js.map +1 -0
- package/dist/compile/forLoops/loopSignals.d.ts +36 -0
- package/dist/compile/forLoops/loopSignals.d.ts.map +1 -0
- package/dist/compile/forLoops/loopSignals.js +64 -0
- package/dist/compile/forLoops/loopSignals.js.map +1 -0
- package/dist/compile/forLoops/loopTraversal.d.ts +18 -0
- package/dist/compile/forLoops/loopTraversal.d.ts.map +1 -0
- package/dist/compile/forLoops/loopTraversal.js +38 -0
- package/dist/compile/forLoops/loopTraversal.js.map +1 -0
- package/dist/compile/handleConditionalChain.d.ts +15 -0
- package/dist/compile/handleConditionalChain.d.ts.map +1 -0
- package/dist/compile/handleConditionalChain.js +181 -0
- package/dist/compile/handleConditionalChain.js.map +1 -0
- package/dist/compile/index.d.ts +15 -0
- package/dist/compile/index.d.ts.map +1 -0
- package/dist/compile/index.js +19 -0
- package/dist/compile/index.js.map +1 -0
- package/dist/compile/injectScopedStyle.d.ts +16 -0
- package/dist/compile/injectScopedStyle.d.ts.map +1 -0
- package/dist/compile/injectScopedStyle.js +50 -0
- package/dist/compile/injectScopedStyle.js.map +1 -0
- package/dist/compile/nodeExpando.d.ts +12 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -0
- package/dist/compile/nodeExpando.js +4 -0
- package/dist/compile/nodeExpando.js.map +1 -0
- package/dist/compile/parseHtml.d.ts +70 -0
- package/dist/compile/parseHtml.d.ts.map +1 -0
- package/dist/compile/parseHtml.js +164 -0
- package/dist/compile/parseHtml.js.map +1 -0
- package/dist/compile/pithyTreeToDom.d.ts +16 -0
- package/dist/compile/pithyTreeToDom.d.ts.map +1 -0
- package/dist/compile/pithyTreeToDom.js +118 -0
- package/dist/compile/pithyTreeToDom.js.map +1 -0
- package/dist/compile/renderChildren.d.ts +50 -0
- package/dist/compile/renderChildren.d.ts.map +1 -0
- package/dist/compile/renderChildren.js +76 -0
- package/dist/compile/renderChildren.js.map +1 -0
- package/dist/compile/ssrMode.d.ts +17 -0
- package/dist/compile/ssrMode.d.ts.map +1 -0
- package/dist/compile/ssrMode.js +20 -0
- package/dist/compile/ssrMode.js.map +1 -0
- package/dist/compile/textValue.d.ts +28 -0
- package/dist/compile/textValue.d.ts.map +1 -0
- package/dist/compile/textValue.js +30 -0
- package/dist/compile/textValue.js.map +1 -0
- package/dist/config/index.d.ts +37 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +16 -0
- package/dist/config/index.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +3 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +3 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/ref-signal.interface.d.ts +6 -0
- package/dist/interfaces/ref-signal.interface.d.ts.map +1 -0
- package/dist/interfaces/ref-signal.interface.js +2 -0
- package/dist/interfaces/ref-signal.interface.js.map +1 -0
- package/dist/interfaces/ref.interface.d.ts +5 -0
- package/dist/interfaces/ref.interface.d.ts.map +1 -0
- package/dist/interfaces/ref.interface.js +2 -0
- package/dist/interfaces/ref.interface.js.map +1 -0
- package/dist/runtime/applyBindings.d.ts +36 -0
- package/dist/runtime/applyBindings.d.ts.map +1 -0
- package/dist/runtime/applyBindings.js +165 -0
- package/dist/runtime/applyBindings.js.map +1 -0
- package/dist/runtime/bindings/applyComponent.d.ts +3 -0
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -0
- package/dist/runtime/bindings/applyComponent.js +190 -0
- package/dist/runtime/bindings/applyComponent.js.map +1 -0
- package/dist/runtime/bindings/applyDefer.d.ts +11 -0
- package/dist/runtime/bindings/applyDefer.d.ts.map +1 -0
- package/dist/runtime/bindings/applyDefer.js +422 -0
- package/dist/runtime/bindings/applyDefer.js.map +1 -0
- package/dist/runtime/bindings/applySimple.d.ts +11 -0
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -0
- package/dist/runtime/bindings/applySimple.js +346 -0
- package/dist/runtime/bindings/applySimple.js.map +1 -0
- package/dist/runtime/bindings/applyStructural.d.ts +5 -0
- package/dist/runtime/bindings/applyStructural.d.ts.map +1 -0
- package/dist/runtime/bindings/applyStructural.js +312 -0
- package/dist/runtime/bindings/applyStructural.js.map +1 -0
- package/dist/runtime/bindings/helpers.d.ts +56 -0
- package/dist/runtime/bindings/helpers.d.ts.map +1 -0
- package/dist/runtime/bindings/helpers.js +121 -0
- package/dist/runtime/bindings/helpers.js.map +1 -0
- package/dist/runtime/bindings/index.d.ts +7 -0
- package/dist/runtime/bindings/index.d.ts.map +1 -0
- package/dist/runtime/bindings/index.js +6 -0
- package/dist/runtime/bindings/index.js.map +1 -0
- package/dist/runtime/bindings/types.d.ts +105 -0
- package/dist/runtime/bindings/types.d.ts.map +1 -0
- package/dist/runtime/bindings/types.js +5 -0
- package/dist/runtime/bindings/types.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +59 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +82 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/createContextProxy.d.ts +10 -0
- package/dist/runtime/createContextProxy.d.ts.map +1 -0
- package/dist/runtime/createContextProxy.js +45 -0
- package/dist/runtime/createContextProxy.js.map +1 -0
- package/dist/runtime/deferHelpers.d.ts +49 -0
- package/dist/runtime/deferHelpers.d.ts.map +1 -0
- package/dist/runtime/deferHelpers.js +65 -0
- package/dist/runtime/deferHelpers.js.map +1 -0
- package/dist/runtime/html.d.ts +23 -0
- package/dist/runtime/html.d.ts.map +1 -0
- package/dist/runtime/html.js +97 -0
- package/dist/runtime/html.js.map +1 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +21 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/lazy.d.ts +144 -0
- package/dist/runtime/lazy.d.ts.map +1 -0
- package/dist/runtime/lazy.js +295 -0
- package/dist/runtime/lazy.js.map +1 -0
- package/dist/runtime/module-cache.d.ts +78 -0
- package/dist/runtime/module-cache.d.ts.map +1 -0
- package/dist/runtime/module-cache.js +109 -0
- package/dist/runtime/module-cache.js.map +1 -0
- package/dist/runtime/onDestroy.d.ts +29 -0
- package/dist/runtime/onDestroy.d.ts.map +1 -0
- package/dist/runtime/onDestroy.js +66 -0
- package/dist/runtime/onDestroy.js.map +1 -0
- package/dist/runtime/parseIdentifiersFromTemplate.d.ts +17 -0
- package/dist/runtime/parseIdentifiersFromTemplate.d.ts.map +1 -0
- package/dist/runtime/parseIdentifiersFromTemplate.js +68 -0
- package/dist/runtime/parseIdentifiersFromTemplate.js.map +1 -0
- package/dist/types/globals.d.ts +18 -0
- package/dist/types/globals.d.ts.map +1 -0
- package/dist/types/globals.js +4 -0
- package/dist/types/globals.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utilities/index.d.ts +3 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +3 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/ref-signal.utility.d.ts +32 -0
- package/dist/utilities/ref-signal.utility.d.ts.map +1 -0
- package/dist/utilities/ref-signal.utility.js +46 -0
- package/dist/utilities/ref-signal.utility.js.map +1 -0
- package/dist/utilities/ref.untility.d.ts +37 -0
- package/dist/utilities/ref.untility.d.ts.map +1 -0
- package/dist/utilities/ref.untility.js +47 -0
- package/dist/utilities/ref.untility.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.directive.switch",
|
|
4
|
+
"title": "@switch directive",
|
|
5
|
+
"category": "directive"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { isDefaultCase } from '@pithyjs/compiler';
|
|
9
|
+
import { effect } from '@pithyjs/signals';
|
|
10
|
+
import { compileExpression } from './compileExpression';
|
|
11
|
+
import { bindConditionals } from './binds/bindConditionals';
|
|
12
|
+
import { flashUpdate } from './binds/bindTextInterpolations';
|
|
13
|
+
import { isSSRMode } from './ssrMode';
|
|
14
|
+
/**
|
|
15
|
+
* Processes switch case directives (@switch, @case, @default) in the template.
|
|
16
|
+
* Identifies switch blocks and delegates their handling to handleSwitchBlock.
|
|
17
|
+
*/
|
|
18
|
+
/** @codexApi {"parent":"pithy.directive.switch","name":"bindSwitchCases","stability":"stable","signature":"(nodes: PithyNode[], rootEl: HTMLElement | DocumentFragment, ctx: Record<string, unknown>, processedNodeIds?: Set<string>, disposers?: (() => void)[]) => void"} */
|
|
19
|
+
export function bindSwitchCases(nodes, rootEl, ctx, processedNodeIds = new Set(), // Track already processed nodes
|
|
20
|
+
disposers = [] // Collect disposers for cleanup
|
|
21
|
+
) {
|
|
22
|
+
// Performance optimization: Create a Map of all elements by data-pid
|
|
23
|
+
// This makes element lookups O(1) instead of O(n) with querySelector
|
|
24
|
+
const elMap = new Map();
|
|
25
|
+
if (rootEl instanceof HTMLElement || rootEl instanceof DocumentFragment) {
|
|
26
|
+
const elements = rootEl.querySelectorAll('[data-pid]');
|
|
27
|
+
elements.forEach(el => {
|
|
28
|
+
const pid = el.getAttribute('data-pid');
|
|
29
|
+
if (pid) {
|
|
30
|
+
elMap.set(pid, el);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// First, identify all switch blocks
|
|
35
|
+
const switchBlocks = [];
|
|
36
|
+
// Iterate through all nodes to identify switch blocks
|
|
37
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
38
|
+
const node = nodes[i];
|
|
39
|
+
// Check if this node has an @switch directive
|
|
40
|
+
if (node.type === 'element' && node.directives?.switch !== undefined) {
|
|
41
|
+
// Found a switch block, collect its children
|
|
42
|
+
if (node.children && node.children.length > 0) {
|
|
43
|
+
// Filter children to only include those with @case or @default directives
|
|
44
|
+
const caseNodes = node.children.filter(child => child.type === 'element' &&
|
|
45
|
+
(child.directives?.case !== undefined || isDefaultCase(child)));
|
|
46
|
+
if (caseNodes.length > 0) {
|
|
47
|
+
switchBlocks.push({ parent: node, children: caseNodes });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Process each switch block
|
|
53
|
+
switchBlocks.forEach(block => {
|
|
54
|
+
// Mark all nodes in this block as processed
|
|
55
|
+
if (block.parent.nodeId) {
|
|
56
|
+
processedNodeIds.add(block.parent.nodeId);
|
|
57
|
+
}
|
|
58
|
+
block.children.forEach(node => {
|
|
59
|
+
if (node.nodeId) {
|
|
60
|
+
processedNodeIds.add(node.nodeId);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
// Find the DOM elements for this switch block
|
|
64
|
+
const parentElement = block.parent.nodeId
|
|
65
|
+
? elMap.get(block.parent.nodeId)
|
|
66
|
+
: null;
|
|
67
|
+
if (!parentElement) {
|
|
68
|
+
console.error('[bindSwitchCases] Could not find parent element for switch block');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const caseElements = block.children
|
|
72
|
+
.map(node => {
|
|
73
|
+
if (!node.nodeId) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
// Use the Map for O(1) lookup
|
|
77
|
+
const element = elMap.get(node.nodeId);
|
|
78
|
+
if (!element) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return element;
|
|
82
|
+
})
|
|
83
|
+
.filter((el) => el !== null);
|
|
84
|
+
// Verify we found all DOM elements
|
|
85
|
+
if (caseElements.length !== block.children.length) {
|
|
86
|
+
console.error('[bindSwitchCases] Could not find all case elements');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
handleSwitchBlock(parentElement, caseElements, block.parent, block.children, ctx, disposers);
|
|
90
|
+
});
|
|
91
|
+
// Recursively process children of all nodes, skipping those already processed in switch blocks
|
|
92
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
93
|
+
const node = nodes[i];
|
|
94
|
+
// Skip nodes that were already processed as part of a switch block
|
|
95
|
+
if (node.nodeId && processedNodeIds.has(node.nodeId)) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (node.type === 'element' && node.children?.length) {
|
|
99
|
+
// Use the Map for O(1) lookup
|
|
100
|
+
const element = node.nodeId ? elMap.get(node.nodeId) : null;
|
|
101
|
+
if (element instanceof HTMLElement) {
|
|
102
|
+
// Pass the processedNodeIds Set and disposers to avoid duplicate processing
|
|
103
|
+
bindSwitchCases(node.children, element, ctx, processedNodeIds, disposers);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Handles rendering and reactivity for an @switch/@case/@default block.
|
|
110
|
+
*/
|
|
111
|
+
function handleSwitchBlock(parentElement, caseElements, switchNode, caseNodes, ctx, disposers) {
|
|
112
|
+
// Generate a unique ID for this switch block for debugging
|
|
113
|
+
const switchId = Math.random().toString(36).substring(2, 8);
|
|
114
|
+
// Create a placeholder comment to mark where our switch content should go
|
|
115
|
+
const placeholder = document.createComment(`switch-block-${switchId}`);
|
|
116
|
+
// Insert the placeholder at the beginning of the parent element
|
|
117
|
+
parentElement.insertBefore(placeholder, parentElement.firstChild);
|
|
118
|
+
// Remove all case elements from the DOM immediately
|
|
119
|
+
for (const el of caseElements) {
|
|
120
|
+
el.remove();
|
|
121
|
+
}
|
|
122
|
+
// Store original elements and create a pool of reusable elements
|
|
123
|
+
const originalElements = caseElements.map(el => el.cloneNode(true));
|
|
124
|
+
// Create a pool of elements for reuse to preserve internal state
|
|
125
|
+
const elementPool = Array(caseElements.length).fill(null);
|
|
126
|
+
// Keep track of the currently displayed element and its index
|
|
127
|
+
let currentElement = null;
|
|
128
|
+
let currentCaseIndex = -1;
|
|
129
|
+
// Track disposers for the current case
|
|
130
|
+
let currentDisposers = [];
|
|
131
|
+
// Cache for compiled expressions to avoid recompiling on each change
|
|
132
|
+
const compiledExpressions = new Map();
|
|
133
|
+
// Helper function to compile and cache expressions
|
|
134
|
+
function getCompiledExpression(expr, kind) {
|
|
135
|
+
if (!expr || expr.trim() === '') {
|
|
136
|
+
return () => undefined;
|
|
137
|
+
}
|
|
138
|
+
// Check if we already compiled this expression
|
|
139
|
+
const cacheKey = `${kind}:${expr}`;
|
|
140
|
+
if (compiledExpressions.has(cacheKey)) {
|
|
141
|
+
return compiledExpressions.get(cacheKey);
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const fn = compileExpression(expr, ctx, undefined);
|
|
145
|
+
compiledExpressions.set(cacheKey, fn);
|
|
146
|
+
return fn;
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.error(`[Switch-${switchId}] Error compiling ${kind}:`, err);
|
|
150
|
+
const fallbackFn = () => undefined;
|
|
151
|
+
compiledExpressions.set(cacheKey, fallbackFn);
|
|
152
|
+
return fallbackFn;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Helper function to safely evaluate expressions
|
|
156
|
+
function safeEvaluate(expr, kind) {
|
|
157
|
+
const fn = getCompiledExpression(expr, kind);
|
|
158
|
+
try {
|
|
159
|
+
return fn();
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
console.error(`[Switch-${switchId}] Error evaluating ${kind}:`, err);
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Create a function to clean up the current element and its bindings
|
|
167
|
+
function cleanupCurrentElement() {
|
|
168
|
+
// Run all disposers to clean up event handlers and other bindings
|
|
169
|
+
currentDisposers.forEach(disposer => disposer());
|
|
170
|
+
currentDisposers = [];
|
|
171
|
+
if (currentElement && currentElement.parentNode) {
|
|
172
|
+
currentElement.remove();
|
|
173
|
+
// Clear the pool slot so we clone a fresh element next time
|
|
174
|
+
// This is necessary because bindConditionals modifies the DOM structure
|
|
175
|
+
// (replaces @if/@else elements with placeholder comments), so reusing
|
|
176
|
+
// the pooled element would cause binding to fail on subsequent renders
|
|
177
|
+
if (currentCaseIndex >= 0) {
|
|
178
|
+
elementPool[currentCaseIndex] = null;
|
|
179
|
+
}
|
|
180
|
+
currentElement = null;
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
// Shared logic for finding the matching case
|
|
186
|
+
function findMatchingCase() {
|
|
187
|
+
// Evaluate the switch expression
|
|
188
|
+
const switchValue = safeEvaluate(switchNode.directives.switch, '@switch');
|
|
189
|
+
// Find the matching case
|
|
190
|
+
let matchIndex = -1;
|
|
191
|
+
let defaultIndex = -1;
|
|
192
|
+
for (let i = 0; i < caseNodes.length; i++) {
|
|
193
|
+
const node = caseNodes[i];
|
|
194
|
+
if (node.directives?.case !== undefined) {
|
|
195
|
+
// This is a @case node
|
|
196
|
+
const caseValue = safeEvaluate(node.directives.case, '@case');
|
|
197
|
+
// Check if the case value matches the switch value
|
|
198
|
+
if (caseValue === switchValue) {
|
|
199
|
+
matchIndex = i;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else if (isDefaultCase(node)) {
|
|
204
|
+
// This is a @default node, remember its index but continue checking other cases
|
|
205
|
+
defaultIndex = i;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// If no case matched but we have a default, use that
|
|
209
|
+
if (matchIndex === -1 && defaultIndex !== -1) {
|
|
210
|
+
matchIndex = defaultIndex;
|
|
211
|
+
}
|
|
212
|
+
return matchIndex;
|
|
213
|
+
}
|
|
214
|
+
// Shared logic for rendering the matched case
|
|
215
|
+
function renderMatchedCase(matchIndex) {
|
|
216
|
+
// If we found a match, insert the corresponding element
|
|
217
|
+
if (matchIndex < 0 || !placeholder.parentNode)
|
|
218
|
+
return;
|
|
219
|
+
let elementToUse;
|
|
220
|
+
// Check if we have a reusable element in the pool
|
|
221
|
+
if (elementPool[matchIndex]) {
|
|
222
|
+
// Reuse the existing element from the pool
|
|
223
|
+
elementToUse = elementPool[matchIndex];
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
// Create a new element and add it to the pool
|
|
227
|
+
elementToUse = originalElements[matchIndex].cloneNode(true);
|
|
228
|
+
elementPool[matchIndex] = elementToUse;
|
|
229
|
+
}
|
|
230
|
+
// Insert the element after the placeholder
|
|
231
|
+
placeholder.parentNode.insertBefore(elementToUse, placeholder.nextSibling);
|
|
232
|
+
// Update our current element reference and index
|
|
233
|
+
currentElement = elementToUse;
|
|
234
|
+
currentCaseIndex = matchIndex;
|
|
235
|
+
// Process children of the matched element and collect disposers
|
|
236
|
+
const matchedAst = caseNodes[matchIndex];
|
|
237
|
+
// Create a new array to collect disposers for this case
|
|
238
|
+
const caseDisposers = [];
|
|
239
|
+
// Bind conditionals and collect their disposers
|
|
240
|
+
bindConditionals(matchedAst.children || [], elementToUse, ctx, new Set(), caseDisposers);
|
|
241
|
+
// Bind event handlers and collect their disposers (skip during SSR - no user interaction)
|
|
242
|
+
if (!isSSRMode()) {
|
|
243
|
+
const eventDisposers = [];
|
|
244
|
+
elementToUse.querySelectorAll('*').forEach((el) => {
|
|
245
|
+
Array.from(el.attributes).forEach((attr) => {
|
|
246
|
+
if (!attr.name.startsWith('data-on-'))
|
|
247
|
+
return;
|
|
248
|
+
const eventName = attr.name.replace('data-on-', '');
|
|
249
|
+
const handlerExpr = attr.value.trim();
|
|
250
|
+
let handler;
|
|
251
|
+
// If expression is a simple identifier, resolve it from context
|
|
252
|
+
const isSimpleFunction = /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(handlerExpr);
|
|
253
|
+
if (isSimpleFunction) {
|
|
254
|
+
const fn = ctx[handlerExpr];
|
|
255
|
+
if (typeof fn === 'function') {
|
|
256
|
+
handler = fn;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
console.warn(`[Switch-${switchId}] Context does not contain a function '${handlerExpr}'`);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// Complex expression: compile it
|
|
265
|
+
try {
|
|
266
|
+
handler = compileExpression(handlerExpr, ctx);
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
console.warn(`[Switch-${switchId}] Failed to compile expression @${eventName}="${handlerExpr}"`, err);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
// Bind event and store unbind disposer
|
|
274
|
+
el.addEventListener(eventName, handler);
|
|
275
|
+
eventDisposers.push(() => el.removeEventListener(eventName, handler));
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
// Add event disposers to our case disposers
|
|
279
|
+
caseDisposers.push(() => {
|
|
280
|
+
eventDisposers.forEach(dispose => dispose());
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
// Store the disposers for this case
|
|
284
|
+
currentDisposers = caseDisposers;
|
|
285
|
+
// Defer flashUpdate via queueMicrotask to prevent blocking
|
|
286
|
+
if (!isSSRMode()) {
|
|
287
|
+
queueMicrotask(() => flashUpdate(elementToUse));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (isSSRMode()) {
|
|
291
|
+
// SSR mode: evaluate once synchronously, no reactive effects
|
|
292
|
+
const matchIndex = findMatchingCase();
|
|
293
|
+
renderMatchedCase(matchIndex);
|
|
294
|
+
// Ensure nested directive disposers created during SSR are added
|
|
295
|
+
// to the parent disposers array for proper cleanup on destroy()
|
|
296
|
+
disposers.push(...currentDisposers);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
// Client mode: reactive effect for dynamic updates
|
|
300
|
+
// Track the previous match index to avoid unnecessary DOM operations
|
|
301
|
+
let previousMatchIndex = -1;
|
|
302
|
+
// Set up the reactive effect and capture the stop function
|
|
303
|
+
const stopEffect = effect(() => {
|
|
304
|
+
const matchIndex = findMatchingCase();
|
|
305
|
+
// Skip re-insertion if match hasn't changed
|
|
306
|
+
if (matchIndex === previousMatchIndex) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
// Clean up the current element before showing a new one
|
|
310
|
+
cleanupCurrentElement();
|
|
311
|
+
// Update the previous match index
|
|
312
|
+
previousMatchIndex = matchIndex;
|
|
313
|
+
renderMatchedCase(matchIndex);
|
|
314
|
+
// Don't return cleanup here - we handle cleanup explicitly:
|
|
315
|
+
// 1. When match changes: cleanupCurrentElement() is called above
|
|
316
|
+
// 2. When effect stops: cleanupCurrentElement is in disposers array
|
|
317
|
+
});
|
|
318
|
+
// Add cleanup and effect stop to disposers for proper cleanup on destroy()
|
|
319
|
+
disposers.push(cleanupCurrentElement);
|
|
320
|
+
disposers.push(stopEffect);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=bindSwitchCases.js.map
|
|
@@ -0,0 +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,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC;;;GAGG;AACH,+QAA+Q;AAC/Q,MAAM,UAAU,eAAe,CAC7B,KAAkB,EAClB,MAAsC,EACtC,GAA4B,EAC5B,mBAAgC,IAAI,GAAG,EAAE,EAAE,gCAAgC;AAC3E,YAA4B,EAAE,CAAC,gCAAgC;;IAE/D,qEAAqE;IACrE,qEAAqE;IACrE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,IAAI,MAAM,YAAY,WAAW,IAAI,MAAM,YAAY,gBAAgB,EAAE,CAAC;QACxE,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;YACpB,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AC;QAChB,6DAA6D;QAC7D,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC;QACtC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAC9B,iEAAiE;QACjE,gEAAgE;QAChE,SAAS,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,mDAAmD;QACnD,qEAAqE;QACrE,IAAI,kBAAkB,GAAG,CAAC,CAAC,CAAC;QAE5B,2DAA2D;QAC3D,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,wDAAwD;YACxD,qBAAqB,EAAE,CAAC;YACxB,kCAAkC;YAClC,kBAAkB,GAAG,UAAU,CAAC;YAChC,iBAAiB,CAAC,UAAU,CAAC,CAAC;YAE9B,4DAA4D;YAC5D,iEAAiE;YACjE,oEAAoE;QACtE,CAAC,CAAC,CAAC;QAEH,2EAA2E;QAC3E,SAAS,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACtC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.attributes",
|
|
4
|
+
"title": "Bound Attribute Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Binds [attr]="expression" bindings like [class]="dynamicClass"
|
|
10
|
+
* using reactive effect evaluation.
|
|
11
|
+
*/
|
|
12
|
+
/** @codexApi {"parent":"pithy.runtime.attributes","name":"bindBoundAttributes","stability":"stable","signature":"(root: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void"} */
|
|
13
|
+
export declare function bindBoundAttributes(root: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]): void;
|
|
14
|
+
//# sourceMappingURL=bindBoundAttributes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindBoundAttributes.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindBoundAttributes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAKF;;;GAGG;AACH,8NAA8N;AAC9N,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAiCN"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.attributes",
|
|
4
|
+
"title": "Bound Attribute Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { effect } from '@pithyjs/signals';
|
|
9
|
+
import { nodeExpando } from '../nodeExpando';
|
|
10
|
+
/**
|
|
11
|
+
* Binds [attr]="expression" bindings like [class]="dynamicClass"
|
|
12
|
+
* using reactive effect evaluation.
|
|
13
|
+
*/
|
|
14
|
+
/** @codexApi {"parent":"pithy.runtime.attributes","name":"bindBoundAttributes","stability":"stable","signature":"(root: Element | DocumentFragment, context: Record<string, unknown>, disposers: (() => void)[]) => void"} */
|
|
15
|
+
export function bindBoundAttributes(root, context, disposers) {
|
|
16
|
+
root.querySelectorAll('*').forEach(el => {
|
|
17
|
+
// Use element's own __pithyCtx when available (projected slot content
|
|
18
|
+
// carries the parent component's context via this property).
|
|
19
|
+
const elCtx = nodeExpando(el).__pithyCtx || context;
|
|
20
|
+
for (const attr of Array.from(el.attributes)) {
|
|
21
|
+
if (!attr.name.startsWith('data-bind-'))
|
|
22
|
+
continue;
|
|
23
|
+
const attrName = attr.name.slice('data-bind-'.length);
|
|
24
|
+
const expr = attr.value;
|
|
25
|
+
// Remove data-bind-* attribute after capturing expression to prevent
|
|
26
|
+
// double-processing when component subtrees are inserted into outer DOM
|
|
27
|
+
el.removeAttribute(attr.name);
|
|
28
|
+
const stop = effect(() => {
|
|
29
|
+
const value = evaluateExpression(expr, elCtx);
|
|
30
|
+
if (typeof value === 'boolean') {
|
|
31
|
+
if (value) {
|
|
32
|
+
el.setAttribute(attrName, '');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
el.removeAttribute(attrName);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
el.setAttribute(attrName, String(value ?? ''));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
disposers.push(stop);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function evaluateExpression(expr, context) {
|
|
47
|
+
try {
|
|
48
|
+
// eslint-disable-next-line no-new-func -- args-style template expression evaluation is a core framework feature
|
|
49
|
+
const compiled = new Function(...Object.keys(context), `return (${expr})`);
|
|
50
|
+
return compiled(...Object.values(context));
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.warn(`[pithy] Failed to evaluate: ${expr}`, err);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=bindBoundAttributes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindBoundAttributes.js","sourceRoot":"","sources":["../../../src/compile/binds/bindBoundAttributes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,8NAA8N;AAC9N,MAAM,UAAU,mBAAmB,CACjC,IAAgC,EAChC,OAAgC,EAChC,SAAyB;IA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;IAEhC,IAAI,CAAC;QACH,gHAAgH;QAChH,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAC3B,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EACvB,WAAW,IAAI,GAAG,CACgB,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAC7C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,+BAA+B,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.classes",
|
|
4
|
+
"title": "Class Directive Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Binds class directives like:
|
|
10
|
+
* • [class.active]="isActive"
|
|
11
|
+
* • [classes]="{ active: isActive() }"
|
|
12
|
+
* • [classes]="['a', 'b']"
|
|
13
|
+
*
|
|
14
|
+
* @param root - The root node to search for class bindings
|
|
15
|
+
* @param ctx - Context object containing reactive variables and functions
|
|
16
|
+
* @param disposers - Cleanup functions to remove subscriptions
|
|
17
|
+
*/
|
|
18
|
+
/** @codexApi {"parent":"pithy.runtime.classes","name":"bindClassDirectives","stability":"stable","signature":"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void"} */
|
|
19
|
+
export declare function bindClassDirectives(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]): void;
|
|
20
|
+
//# sourceMappingURL=bindClassDirectives.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindClassDirectives.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindClassDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAMF;;;;;;;;;GASG;AACH,uNAAuN;AACvN,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,GAAG,gBAAgB,EAChC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,GACxB,IAAI,CAkFN"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.classes",
|
|
4
|
+
"title": "Class Directive Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
import { effect } from '@pithyjs/signals';
|
|
9
|
+
import { compileExpression } from '../compileExpression';
|
|
10
|
+
import { nodeExpando } from '../nodeExpando';
|
|
11
|
+
/**
|
|
12
|
+
* Binds class directives like:
|
|
13
|
+
* • [class.active]="isActive"
|
|
14
|
+
* • [classes]="{ active: isActive() }"
|
|
15
|
+
* • [classes]="['a', 'b']"
|
|
16
|
+
*
|
|
17
|
+
* @param root - The root node to search for class bindings
|
|
18
|
+
* @param ctx - Context object containing reactive variables and functions
|
|
19
|
+
* @param disposers - Cleanup functions to remove subscriptions
|
|
20
|
+
*/
|
|
21
|
+
/** @codexApi {"parent":"pithy.runtime.classes","name":"bindClassDirectives","stability":"stable","signature":"(root: Element | DocumentFragment, ctx: Record<string, unknown>, disposers: (() => void)[]) => void"} */
|
|
22
|
+
export function bindClassDirectives(root, ctx, disposers) {
|
|
23
|
+
root.querySelectorAll('*').forEach(el => {
|
|
24
|
+
// Use element's own __pithyCtx when available (projected slot content
|
|
25
|
+
// carries the parent component's context via this property).
|
|
26
|
+
const elCtx = nodeExpando(el).__pithyCtx || ctx;
|
|
27
|
+
// Handle [class.someName] → data-class-toggle-someName
|
|
28
|
+
for (const attr of Array.from(el.attributes)) {
|
|
29
|
+
if (!attr.name.startsWith('data-class-toggle-'))
|
|
30
|
+
continue;
|
|
31
|
+
const className = attr.name.slice('data-class-toggle-'.length);
|
|
32
|
+
const expression = attr.value;
|
|
33
|
+
// Remove directive attribute after capturing to prevent double-processing
|
|
34
|
+
// when component subtrees are inserted into an outer DOM that re-runs binders
|
|
35
|
+
el.removeAttribute(attr.name);
|
|
36
|
+
let evaluate;
|
|
37
|
+
try {
|
|
38
|
+
evaluate = compileExpression(expression, elCtx);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.warn(`[PithyJS] ⚠️ Failed to compile [class.${className}]="${expression}"`, err);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const stop = effect(() => {
|
|
45
|
+
try {
|
|
46
|
+
const result = evaluate();
|
|
47
|
+
el.classList.toggle(className, !!result);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
/* ignore */
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
disposers.push(stop);
|
|
54
|
+
}
|
|
55
|
+
// Handle [classes]="{ active: isActive() }" or [classes]="['a', 'b']"
|
|
56
|
+
const classGroupExpr = el.getAttribute('data-classes');
|
|
57
|
+
if (classGroupExpr) {
|
|
58
|
+
// Remove directive attribute after capturing to prevent double-processing
|
|
59
|
+
el.removeAttribute('data-classes');
|
|
60
|
+
let evaluate;
|
|
61
|
+
try {
|
|
62
|
+
evaluate = compileExpression(classGroupExpr, elCtx);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.warn(`[PithyJS] ⚠️ Failed to compile [classes]="${classGroupExpr}"`, err);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const stop = effect(() => {
|
|
69
|
+
try {
|
|
70
|
+
const result = evaluate();
|
|
71
|
+
if (Array.isArray(result)) {
|
|
72
|
+
for (const cls of result) {
|
|
73
|
+
if (typeof cls === 'string')
|
|
74
|
+
el.classList.add(cls);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (result && typeof result === 'object') {
|
|
78
|
+
for (const [cls, on] of Object.entries(result)) {
|
|
79
|
+
for (const c of cls.split(/\s+/)) {
|
|
80
|
+
if (c)
|
|
81
|
+
el.classList.toggle(c, !!on);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
console.warn('[PithyJS] ⚠️ Failed to evaluate [classes]:', err);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
disposers.push(stop);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=bindClassDirectives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindClassDirectives.js","sourceRoot":"","sources":["../../../src/compile/binds/bindClassDirectives.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;GASG;AACH,uNAAuN;AACvN,MAAM,UAAU,mBAAmB,CACjC,IAAgC,EAChC,GAA4B,EAC5B,SAAyB;IAEzB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE;QACtC,sEAAsE;QACtE,6DAA6D;QAC7D,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,UAAU,IAAI,GAAG,CAAC;QAEhD,uDAAuD;QACvD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC;gBAAE,SAAS;YAE1D,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;YAC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AM,MAAM,GAAG,QAAQ,EAAE,CAAC;oBAE1B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;wBAC1B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;4BACzB,IAAI,OAAO,GAAG,KAAK,QAAQ;gCAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;wBACrD,CAAC;oBACH,CAAC;yBAAM,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;wBAChD,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;4BAC/C,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gCACjC,IAAI,CAAC;oCAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;4BACtC,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,IAAI,CAAC,4CAA4C,EAAE,GAAG,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.runtime.components",
|
|
4
|
+
"title": "Component Tag Binding System",
|
|
5
|
+
"category": "runtime"
|
|
6
|
+
}
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Replace custom component tags (<Counter/>, <NestedComponent/>) with rendered output.
|
|
10
|
+
* - Skips anything under a pending nested loop host (bind after loop expansion)
|
|
11
|
+
* - Evaluates prop expressions in nearest loop ctx
|
|
12
|
+
* - Case-insensitive prop name normalization
|
|
13
|
+
* - No raw-string fallback (prevents things like calling count() on a string)
|
|
14
|
+
*/
|
|
15
|
+
/** @codexApi {"parent":"pithy.runtime.components","name":"bindComponentTags","stability":"stable","signature":"(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]) => void"} */
|
|
16
|
+
export declare function bindComponentTags(root: Element | DocumentFragment, rootCtx: Record<string, unknown>, disposers: (() => void)[]): void;
|
|
17
|
+
//# sourceMappingURL=bindComponentsTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindComponentsTags.d.ts","sourceRoot":"","sources":["../../../src/compile/binds/bindComponentsTags.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA0JF;;;;;;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,CAmQN"}
|