@pithyjs/core 0.1.0-beta.23 → 0.1.0-beta.25
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/README.md +2 -0
- package/dist/compile/binds/bindComponentsTags.d.ts.map +1 -1
- package/dist/compile/binds/bindComponentsTags.js +24 -11
- package/dist/compile/binds/bindComponentsTags.js.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.d.ts +3 -3
- package/dist/compile/binds/bindDeferDirectives.d.ts.map +1 -1
- package/dist/compile/binds/bindDeferDirectives.js +7 -5
- package/dist/compile/binds/bindDeferDirectives.js.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.d.ts +6 -2
- package/dist/compile/binds/bindErrorBoundary.d.ts.map +1 -1
- package/dist/compile/binds/bindErrorBoundary.js +86 -20
- package/dist/compile/binds/bindErrorBoundary.js.map +1 -1
- package/dist/compile/compileTemplate.d.ts.map +1 -1
- package/dist/compile/compileTemplate.js +5 -1
- package/dist/compile/compileTemplate.js.map +1 -1
- package/dist/compile/contentProjection.d.ts +53 -2
- package/dist/compile/contentProjection.d.ts.map +1 -1
- package/dist/compile/contentProjection.js +118 -5
- package/dist/compile/contentProjection.js.map +1 -1
- package/dist/compile/index.d.ts +1 -0
- package/dist/compile/index.d.ts.map +1 -1
- package/dist/compile/index.js +1 -0
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/nodeExpando.d.ts +5 -0
- package/dist/compile/nodeExpando.d.ts.map +1 -1
- package/dist/compile/nodeExpando.js.map +1 -1
- package/dist/compile/renderChildren.d.ts +2 -0
- package/dist/compile/renderChildren.d.ts.map +1 -1
- package/dist/compile/renderChildren.js +6 -2
- package/dist/compile/renderChildren.js.map +1 -1
- package/dist/compile/ssrCrashes.d.ts.map +1 -1
- package/dist/compile/ssrCrashes.js +76 -20
- package/dist/compile/ssrCrashes.js.map +1 -1
- package/dist/runtime/applyBindings.d.ts +6 -0
- package/dist/runtime/applyBindings.d.ts.map +1 -1
- package/dist/runtime/applyBindings.js +15 -0
- package/dist/runtime/applyBindings.js.map +1 -1
- package/dist/runtime/bindings/applyComponent.d.ts.map +1 -1
- package/dist/runtime/bindings/applyComponent.js +5 -1
- package/dist/runtime/bindings/applyComponent.js.map +1 -1
- package/dist/runtime/bindings/applyDefer.js +2 -2
- package/dist/runtime/bindings/applyDefer.js.map +1 -1
- package/dist/runtime/bindings/applySimple.d.ts.map +1 -1
- package/dist/runtime/bindings/applySimple.js +10 -4
- package/dist/runtime/bindings/applySimple.js.map +1 -1
- package/dist/runtime/bindings/helpers.d.ts.map +1 -1
- package/dist/runtime/bindings/helpers.js +2 -1
- package/dist/runtime/bindings/helpers.js.map +1 -1
- package/dist/runtime/bindings/types.d.ts +2 -0
- package/dist/runtime/bindings/types.d.ts.map +1 -1
- package/dist/runtime/bindings/types.js.map +1 -1
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/globals.d.ts.map +1 -1
- package/dist/types/globals.js.map +1 -1
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"category": "feature"
|
|
6
6
|
}
|
|
7
7
|
*/
|
|
8
|
-
import { sharedSlotMessage, sharedSlots } from '@pithyjs/compiler';
|
|
8
|
+
import { duplicateSlotMessage, sharedSlotMessage, sharedSlots, undeclaredSlotMessage, } from '@pithyjs/compiler';
|
|
9
9
|
import { pithyTreeToDom } from './pithyTreeToDom.js';
|
|
10
10
|
import { bindStructuralDirectives } from './compileTemplate.js';
|
|
11
11
|
import { nodeExpando } from './nodeExpando.js';
|
|
@@ -17,7 +17,112 @@ function expando(node) {
|
|
|
17
17
|
return node;
|
|
18
18
|
}
|
|
19
19
|
const outerSlotMaps = new WeakMap();
|
|
20
|
-
|
|
20
|
+
const slotMapTags = new WeakMap();
|
|
21
|
+
const slotMapOwners = new WeakMap();
|
|
22
|
+
let warnedDuplicates = new WeakMap();
|
|
23
|
+
/** Records the component tag `slotMap` fills, and the component, for DEV warnings. */
|
|
24
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"nameSlotMap","stability":"internal","signature":"(slotMap: SlotMap, tag: string, owner?: object) => void"} */
|
|
25
|
+
export function nameSlotMap(slotMap, tag, owner) {
|
|
26
|
+
slotMapTags.set(slotMap, tag);
|
|
27
|
+
if (owner)
|
|
28
|
+
slotMapOwners.set(slotMap, owner);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* DEV: warns once per component and slot name that a later `<slot>` gets no
|
|
32
|
+
* content. Without a known component, once per `instance` (one render).
|
|
33
|
+
*/
|
|
34
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"warnDuplicateSlot","stability":"internal","signature":"(slotMap: SlotMap | undefined, name: string, instance: object) => void"} */
|
|
35
|
+
export function warnDuplicateSlot(slotMap, name, instance) {
|
|
36
|
+
const key = (slotMap && slotMapOwners.get(slotMap)) ?? instance;
|
|
37
|
+
let names = warnedDuplicates.get(key);
|
|
38
|
+
if (!names)
|
|
39
|
+
warnedDuplicates.set(key, (names = new Set()));
|
|
40
|
+
if (names.has(name))
|
|
41
|
+
return;
|
|
42
|
+
names.add(name);
|
|
43
|
+
const tag = (slotMap && slotMapTags.get(slotMap)) ?? 'component';
|
|
44
|
+
console.warn(`[PithyJS] ${duplicateSlotMessage(tag, name)}`);
|
|
45
|
+
}
|
|
46
|
+
/** Test hook: lets each test see its first duplicate-slot warning. */
|
|
47
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"resetDuplicateSlotWarnings","stability":"internal","signature":"() => void"} */
|
|
48
|
+
export function resetDuplicateSlotWarnings() {
|
|
49
|
+
warnedDuplicates = new WeakMap();
|
|
50
|
+
}
|
|
51
|
+
const declaredSlots = new WeakMap();
|
|
52
|
+
const seenSlotMaps = new WeakSet();
|
|
53
|
+
const unknownSlotMaps = new WeakSet();
|
|
54
|
+
let warnedUndeclared = new WeakMap();
|
|
55
|
+
/**
|
|
56
|
+
* DEV: records `names` as slots the component that `slotMap` fills renders,
|
|
57
|
+
* and that its template or children were looked at, which is what lets
|
|
58
|
+
* `warnUndeclaredSlots` check the rest.
|
|
59
|
+
*/
|
|
60
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"declareSlotNames","stability":"internal","signature":"(slotMap: SlotMap | undefined, names: Iterable<string>) => void"} */
|
|
61
|
+
export function declareSlotNames(slotMap, names) {
|
|
62
|
+
if (!slotMap)
|
|
63
|
+
return;
|
|
64
|
+
let declared = declaredSlots.get(slotMap);
|
|
65
|
+
if (!declared)
|
|
66
|
+
declaredSlots.set(slotMap, (declared = new Set()));
|
|
67
|
+
for (const name of names)
|
|
68
|
+
declared.add(name);
|
|
69
|
+
seenSlotMaps.add(slotMap);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* DEV: a template rendered for `slotMap` without its `<slot>` list, as an
|
|
73
|
+
* older plugin's build or a precompiled library does. `warnUndeclaredSlots`
|
|
74
|
+
* then stays silent for the map, whatever else declared names for it.
|
|
75
|
+
*/
|
|
76
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"markSlotsUnknown","stability":"internal","signature":"(slotMap: SlotMap | undefined) => void"} */
|
|
77
|
+
export function markSlotsUnknown(slotMap) {
|
|
78
|
+
if (slotMap)
|
|
79
|
+
unknownSlotMaps.add(slotMap);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Declares slot names a component reads from its children by hand, such as
|
|
83
|
+
* `slot="fallback"`, so DEV does not report content addressed to them as
|
|
84
|
+
* having nowhere to go, and marks its children as read, so DEV reports the
|
|
85
|
+
* rest. With no names, it only marks them read. Call it during render, before
|
|
86
|
+
* `captureChildren()`, which clears the context it reads. A no-op outside DEV
|
|
87
|
+
* or a render.
|
|
88
|
+
*
|
|
89
|
+
* @param names - The `slot="…"` values the component handles itself
|
|
90
|
+
*/
|
|
91
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"declareSlots","stability":"experimental","signature":"(...names: string[]) => void"} */
|
|
92
|
+
export function declareSlots(...names) {
|
|
93
|
+
if (import.meta.env?.DEV)
|
|
94
|
+
declareSlotNames(pithyGlobals().__pithyComponentContext?.__slotMap, names);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* DEV: warns once per component and slot name for content in `slotMap`
|
|
98
|
+
* addressed to a named slot its component never declared. Silent for a
|
|
99
|
+
* component whose template and children were never looked at, or whose
|
|
100
|
+
* template rendered without its `<slot>` list.
|
|
101
|
+
*/
|
|
102
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"warnUndeclaredSlots","stability":"internal","signature":"(slotMap: SlotMap) => void"} */
|
|
103
|
+
export function warnUndeclaredSlots(slotMap) {
|
|
104
|
+
if (!seenSlotMaps.has(slotMap) || unknownSlotMaps.has(slotMap))
|
|
105
|
+
return;
|
|
106
|
+
const declared = declaredSlots.get(slotMap);
|
|
107
|
+
const tag = slotMapTags.get(slotMap) ?? 'component';
|
|
108
|
+
const key = slotMapOwners.get(slotMap) ?? slotMap;
|
|
109
|
+
let warned = warnedUndeclared.get(key);
|
|
110
|
+
if (!warned)
|
|
111
|
+
warnedUndeclared.set(key, (warned = new Set()));
|
|
112
|
+
for (const name of slotMap.keys()) {
|
|
113
|
+
if (name === '' || declared?.has(name) || warned.has(name))
|
|
114
|
+
continue;
|
|
115
|
+
warned.add(name);
|
|
116
|
+
console.warn(`[PithyJS] ${undeclaredSlotMessage(tag, name)}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** Test hook: lets each test see its first undeclared-slot warning. */
|
|
120
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"resetUndeclaredSlotWarnings","stability":"internal","signature":"() => void"} */
|
|
121
|
+
export function resetUndeclaredSlotWarnings() {
|
|
122
|
+
warnedUndeclared = new WeakMap();
|
|
123
|
+
}
|
|
124
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"slotMapOf","stability":"internal","signature":"(ctx: Record<string, unknown>) => SlotMap | undefined"} */
|
|
125
|
+
export function slotMapOf(ctx) {
|
|
21
126
|
return ('__slotMap' in ctx ? ctx.__slotMap : undefined);
|
|
22
127
|
}
|
|
23
128
|
/**
|
|
@@ -35,8 +140,8 @@ export function linkOuterSlotMap(slotMap, ctx) {
|
|
|
35
140
|
if (outer)
|
|
36
141
|
outerSlotMaps.set(slotMap, outer);
|
|
37
142
|
}
|
|
38
|
-
/** @codexApi {"parent":"pithy.feature.content-projection","name":"collectSlotMap","stability":"stable","signature":"(children: PithyNode[], parentContext: Record<string, any>, host?: Element) => SlotMap"} */
|
|
39
|
-
export function collectSlotMap(children, parentContext, host) {
|
|
143
|
+
/** @codexApi {"parent":"pithy.feature.content-projection","name":"collectSlotMap","stability":"stable","signature":"(children: PithyNode[], parentContext: Record<string, any>, host?: Element, owner?: object) => SlotMap"} */
|
|
144
|
+
export function collectSlotMap(children, parentContext, host, owner) {
|
|
40
145
|
const slotMap = new Map();
|
|
41
146
|
const slotGroups = new Map();
|
|
42
147
|
linkOuterSlotMap(slotMap, parentContext);
|
|
@@ -61,6 +166,7 @@ export function collectSlotMap(children, parentContext, host) {
|
|
|
61
166
|
const tag = (host && nodeExpando(host).__pithyNode?.originalTagName) ??
|
|
62
167
|
host?.localName ??
|
|
63
168
|
'component';
|
|
169
|
+
nameSlotMap(slotMap, tag, owner);
|
|
64
170
|
for (const name of sharedSlots(children))
|
|
65
171
|
console.warn(`[PithyJS] ${sharedSlotMessage(tag, name)}`);
|
|
66
172
|
}
|
|
@@ -154,15 +260,21 @@ export function mountProjection(slotDefs, slotMap, disposers) {
|
|
|
154
260
|
withinRender(() => mountSlots(slotDefs, slotMap, disposers));
|
|
155
261
|
}
|
|
156
262
|
function mountSlots(slotDefs, slotMap, disposers) {
|
|
263
|
+
// As in the HTML spec, only the first slot of a name receives content.
|
|
264
|
+
const filled = new Set();
|
|
157
265
|
for (const slotDef of slotDefs) {
|
|
158
266
|
const { name, anchor, fallbackFactory } = slotDef;
|
|
159
|
-
const renderer = slotMap.get(name);
|
|
160
267
|
// Skip if this slot has already been processed
|
|
161
268
|
if (expando(anchor).__projectionProcessed) {
|
|
162
269
|
continue;
|
|
163
270
|
}
|
|
164
271
|
// Mark this slot as processed to prevent multiple passes
|
|
165
272
|
expando(anchor).__projectionProcessed = true;
|
|
273
|
+
const later = filled.has(name);
|
|
274
|
+
filled.add(name);
|
|
275
|
+
if (later && import.meta.env?.DEV)
|
|
276
|
+
warnDuplicateSlot(slotMap, name, slotMap);
|
|
277
|
+
const renderer = later ? undefined : slotMap.get(name);
|
|
166
278
|
const parent = anchor.parentNode;
|
|
167
279
|
// A crash in an earlier slot can have hidden this anchor behind a fallback.
|
|
168
280
|
if (!parent && !isHiddenByBoundary(anchor)) {
|
|
@@ -281,5 +393,6 @@ function mountSlots(slotDefs, slotMap, disposers) {
|
|
|
281
393
|
// projected "fallback" content is legitimate — it will be mounted when
|
|
282
394
|
// the @else branch activates. Warnings here would be false positives
|
|
283
395
|
// and fire repeatedly on every reactive toggle.
|
|
396
|
+
// warnUndeclaredSlots checks against the whole template after the component returns.
|
|
284
397
|
}
|
|
285
398
|
//# sourceMappingURL=contentProjection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentProjection.js","sourceRoot":"","sources":["../../src/compile/contentProjection.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAa,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAA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UAAU,EAAE,CAAC;oBACpB,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,YAAY,EAAE,CAAC,sBAAsB,EAAE,CAAC;gBAClE,OAAO,CAAC,GAAG,CAAC,yCAAyC,IAAI,GAAG,CAAC,CAAC;YAChE,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,YAAY,EAAE,CAAC,sBAAsB,EAAE,CAAC;YAClE,OAAO,CAAC,GAAG,CACT,6CAA6C,aAAa,CAAC,MAAM,oBAAoB,IAAI,GAAG,CAC7F,CAAC;QACJ,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,2EAA2E;IAC3E,yEAAyE;IACzE,6EAA6E;IAC7E,sEAAsE;IACtE,uEAAuE;IACvE,qEAAqE;IACrE,gDAAgD;AAClD,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.feature.content-projection\",\n \"title\": \"Content Projection System\",\n \"category\": \"feature\"\n}\n*/\n\nimport { PithyNode, sharedSlotMessage, sharedSlots } from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { bindStructuralDirectives } from './compileTemplate';\nimport { nodeExpando } from './nodeExpando';\nimport {\n bindErrorBoundary,\n insertBesideHidden,\n withSlotBoundary,\n isHiddenByBoundary,\n} from './binds/bindErrorBoundary';\nimport { pithyGlobals } from '../types/globals';\nimport { trimBlankEdges } from './trimBlankEdges';\nimport { withinRender } from './ssrCrashes';\n\n/**\n * SlotMap contains renderer functions for each slot name.\n * Each entry is a factory that returns a DocumentFragment of the slot's content.\n */\nexport type SlotMap = Map<\n string,\n (disposers?: (() => void)[], anchor?: Node) => DocumentFragment\n>;\n\n/**\n * SlotDef describes a slot anchor and its fallback content\n */\nexport type FallbackFactory = () => HTMLElement | DocumentFragment | undefined;\n\nexport interface SlotDef {\n name: string;\n anchor: Comment;\n fallbackFactory?: FallbackFactory;\n}\n\ninterface ProjectionExpando {\n __slotName?: string;\n __fallbackFactory?: FallbackFactory;\n __projectionProcessed?: boolean;\n __projectedContent?: boolean;\n}\n\nfunction expando(node: Node): ProjectionExpando {\n return node as Node & ProjectionExpando;\n}\n\nconst outerSlotMaps = new WeakMap<SlotMap, SlotMap>();\n\nfunction slotMapOf(ctx: Record<string, unknown>): SlotMap | undefined {\n return ('__slotMap' in ctx ? ctx.__slotMap : undefined) as\n | SlotMap\n | undefined;\n}\n\n/**\n * The slot map of the template the children behind `slotMap` were written in:\n * what a `<slot>` among those children receives.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"outerSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined) => SlotMap | undefined\"} */\nexport function outerSlotMap(\n slotMap: SlotMap | undefined\n): SlotMap | undefined {\n return slotMap && outerSlotMaps.get(slotMap);\n}\n\n/** Records `ctx`'s slot map as what a `<slot>` among `slotMap`'s children receives. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"linkOuterSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap, ctx: Record<string, unknown>) => void\"} */\nexport function linkOuterSlotMap(\n slotMap: SlotMap,\n ctx: Record<string, unknown>\n): void {\n const outer = slotMapOf(ctx);\n if (outer) outerSlotMaps.set(slotMap, outer);\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"collectSlotMap\",\"stability\":\"stable\",\"signature\":\"(children: PithyNode[], parentContext: Record<string, any>, host?: Element) => SlotMap\"} */\nexport function collectSlotMap(\n children: PithyNode[],\n parentContext: Record<string, unknown>,\n host?: Element\n): SlotMap {\n const slotMap: SlotMap = new Map();\n const slotGroups = new Map<string, PithyNode[]>();\n linkOuterSlotMap(slotMap, parentContext);\n const outer = slotMapOf(parentContext);\n\n // Group children by slot attribute\n for (const child of children) {\n const slotName = child.directives?.slot || ''; // default slot if no slot attribute\n\n if (!slotGroups.has(slotName)) {\n slotGroups.set(slotName, []);\n }\n slotGroups.get(slotName)!.push(child);\n }\n const defaultSlot = slotGroups.get('');\n if (defaultSlot) {\n const content = trimBlankEdges(defaultSlot, node =>\n node.type === 'text' ? (node.textContent ?? '') : null\n );\n if (content.length) slotGroups.set('', content);\n else slotGroups.delete('');\n }\n\n if (import.meta.env?.DEV) {\n const tag =\n (host && nodeExpando(host).__pithyNode?.originalTagName) ??\n host?.localName ??\n 'component';\n for (const name of sharedSlots(children))\n console.warn(`[PithyJS] ${sharedSlotMessage(tag, name)}`);\n }\n\n // Create renderer functions for each slot group.\n // NOTE: We intentionally do NOT cache or clone DocumentFragments here.\n // Using fragment caching + cloneNode(true) would strip custom JS properties\n // like __pithyCtx that binders rely on to resolve projected content\n // expressions (including interpolation, [class], and [attr] bindings)\n // against the *parent* component's context.\n //\n // This behavior is relied upon by regression tests that exercise projected\n // nodes containing such bindings; changing this to reuse or clone\n // fragments will cause those tests to fail and break content projection.\n // pithyTreeToDom is cheap (just creates DOM nodes), so recreating is fine.\n\n for (const [slotName, nodes] of slotGroups) {\n // Capture nodes and context in closure for stable reference\n const capturedNodes = nodes;\n const capturedContext = parentContext;\n\n const render = (\n disposers: (() => void)[] = [],\n at?: Node\n ): DocumentFragment => {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Rendering slot \"${slotName}\" with ${capturedNodes.length} nodes`\n );\n }\n\n const fragment = pithyTreeToDom(capturedNodes, capturedContext);\n // As the AOT renderer does: a branch in the content then finds a boundary\n // the receiver wraps its `<slot>` in.\n withSlotBoundary(at, host, () =>\n withinRender(() => {\n bindStructuralDirectives(\n capturedNodes,\n fragment,\n capturedContext,\n disposers\n );\n bindErrorBoundary(fragment, capturedContext, disposers);\n return fragment;\n })\n );\n // A `<slot>` passed through: the receiving component has already looked for its slots.\n const passed = extractSlotDefs(fragment);\n if (passed.length) mountProjection(passed, outer ?? new Map(), disposers);\n nodeExpando(fragment).__pithyCtx = capturedContext;\n return fragment;\n };\n\n slotMap.set(slotName, render);\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Collected SlotMap with slots:`,\n Array.from(slotMap.keys())\n );\n }\n return slotMap;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"extractSlotDefs\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment) => SlotDef[]\"} */\nexport function extractSlotDefs(fragment: DocumentFragment): SlotDef[] {\n const slotDefs: SlotDef[] = [];\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_COMMENT, {\n acceptNode: node => {\n const comment = node as Comment;\n return comment.textContent?.startsWith('slot:')\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT;\n },\n });\n\n let node: Comment | null;\n while ((node = walker.nextNode() as Comment | null)) {\n // Inside a component tag, the slot is that component's content to place.\n if (inComponentTag(node)) continue;\n const slotName = expando(node).__slotName || '';\n const fallbackFactory = expando(node).__fallbackFactory;\n\n slotDefs.push({\n name: slotName,\n anchor: node,\n fallbackFactory,\n });\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Extracted ${slotDefs.length} slot definitions`\n );\n }\n return slotDefs;\n}\n\n/** Whether `node` is inside content a `<slot>` projected. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"inProjectedContent\",\"stability\":\"internal\",\"signature\":\"(node: Node) => boolean\"} */\nexport function inProjectedContent(node: Node): boolean {\n for (let n: Node | null = node; n; n = n.parentNode)\n if (expando(n).__projectedContent) return true;\n return false;\n}\n\nfunction inComponentTag(node: Node): boolean {\n for (let el = node.parentElement; el; el = el.parentElement)\n if (nodeExpando(el).__pithyNode?.isComponent) return true;\n return false;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"mountProjection\",\"stability\":\"stable\",\"signature\":\"(slotDefs: SlotDef[], slotMap: SlotMap, disposers: (() => void)[]) => void\"} */\nexport function mountProjection(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n // A slot's content is rendered and then inserted: one render transaction.\n withinRender(() => mountSlots(slotDefs, slotMap, disposers));\n}\n\nfunction mountSlots(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n for (const slotDef of slotDefs) {\n const { name, anchor, fallbackFactory } = slotDef;\n const renderer = slotMap.get(name);\n\n // Skip if this slot has already been processed\n if (expando(anchor).__projectionProcessed) {\n continue;\n }\n\n // Mark this slot as processed to prevent multiple passes\n expando(anchor).__projectionProcessed = true;\n\n const parent = anchor.parentNode;\n // A crash in an earlier slot can have hidden this anchor behind a fallback.\n if (!parent && !isHiddenByBoundary(anchor)) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[ContentProjection] Slot anchor \"${name}\" has no parent node - skipping`\n );\n }\n continue;\n }\n\n // Determine which content to render\n let contentFragment: HTMLElement | DocumentFragment | null = null;\n let isProjectedContent = false;\n\n if (renderer) {\n // Use projected content\n contentFragment = renderer(disposers, anchor);\n isProjectedContent = true;\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting projected content for slot \"${name}\"`\n );\n }\n } else if (fallbackFactory) {\n // Use fallback content\n contentFragment = fallbackFactory() ?? null;\n const slotNode = nodeExpando(anchor).__pithyNode;\n if (\n contentFragment instanceof DocumentFragment &&\n slotNode?.fallbackChildren\n ) {\n const fallbackCtx = nodeExpando(anchor).__pithyCtx ?? {};\n const fallbackFragment = contentFragment;\n const fallbackNodes = slotNode.fallbackChildren;\n withinRender(() => {\n bindStructuralDirectives(\n fallbackNodes,\n fallbackFragment,\n fallbackCtx,\n disposers\n );\n bindErrorBoundary(fallbackFragment, fallbackCtx, disposers);\n });\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting fallback content for slot \"${name}\"`\n );\n }\n } else {\n // No content to mount\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] No content for slot \"${name}\"`);\n }\n continue;\n }\n\n // Validate content\n if (!contentFragment || contentFragment.childNodes.length === 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Empty content for slot \"${name}\" - skipping`\n );\n }\n continue;\n }\n\n // CRITICAL: Collect nodes BEFORE inserting into DOM (for cleanup tracking)\n // Once inserted, the fragment's childNodes will be empty\n const nodesToInsert: Node[] = Array.from(contentFragment.childNodes);\n\n // Mark nodes for tracking\n for (const node of nodesToInsert) {\n expando(node).__projectedContent = isProjectedContent;\n expando(node).__slotName = name;\n }\n\n // Find and remove any existing content for this slot\n const existingNodes: Node[] = [];\n let current = anchor.nextSibling;\n\n while (current) {\n // Stop if we hit another slot anchor\n if (\n current.nodeType === Node.COMMENT_NODE &&\n (current as Comment).textContent?.startsWith('slot:')\n ) {\n break;\n }\n\n // A sibling no projection marked is the component's own markup.\n const meta = expando(current);\n if (meta.__projectedContent === undefined || meta.__slotName !== name) {\n break;\n }\n existingNodes.push(current);\n\n current = current.nextSibling;\n }\n\n // Simple diffing: only replace if content appears different\n // Compare node count and types as a basic heuristic\n const shouldReplace =\n existingNodes.length !== nodesToInsert.length ||\n existingNodes.some(\n (node, i) => node.nodeType !== nodesToInsert[i]?.nodeType\n );\n\n if (!shouldReplace && existingNodes.length > 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Content for slot \"${name}\" unchanged - skipping replacement`\n );\n }\n continue;\n }\n\n // Remove existing content\n for (const node of existingNodes) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n\n // Insert new content after the anchor comment\n if (!insertBesideHidden(anchor, contentFragment))\n parent?.insertBefore(contentFragment, anchor.nextSibling);\n\n // Track cleanup - remove projected nodes when component unmounts\n disposers.push(() => {\n for (const node of nodesToInsert) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] Cleaned up slot \"${name}\"`);\n }\n });\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Successfully mounted ${nodesToInsert.length} nodes for slot \"${name}\"`\n );\n }\n }\n\n // DEV: Validate slot usage\n // NOTE: We intentionally do NOT warn about unmatched projected slots here.\n // When a component uses @if/@else with different <slot> elements in each\n // branch (e.g., Show has <slot> in @if and <slot name=\"fallback\"> in @else),\n // the currently-rendered branch may not include all slot targets. The\n // projected \"fallback\" content is legitimate — it will be mounted when\n // the @else branch activates. Warnings here would be false positives\n // and fire repeatedly on every reactive toggle.\n}\n"]}
|
|
1
|
+
{"version":3,"file":"contentProjection.js","sourceRoot":"","sources":["../../src/compile/contentProjection.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAEL,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBA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AAC,IAAI,CAAC,GAAG,EAAE;YAClB,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;gBACjC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;oBACpB,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC;YACD,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,YAAY,EAAE,CAAC,sBAAsB,EAAE,CAAC;gBAClE,OAAO,CAAC,GAAG,CAAC,yCAAyC,IAAI,GAAG,CAAC,CAAC;YAChE,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,YAAY,EAAE,CAAC,sBAAsB,EAAE,CAAC;YAClE,OAAO,CAAC,GAAG,CACT,6CAA6C,aAAa,CAAC,MAAM,oBAAoB,IAAI,GAAG,CAC7F,CAAC;QACJ,CAAC;IACH,CAAC;IAED,2BAA2B;IAC3B,2EAA2E;IAC3E,yEAAyE;IACzE,6EAA6E;IAC7E,sEAAsE;IACtE,uEAAuE;IACvE,qEAAqE;IACrE,gDAAgD;IAChD,qFAAqF;AACvF,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.feature.content-projection\",\n \"title\": \"Content Projection System\",\n \"category\": \"feature\"\n}\n*/\n\nimport {\n PithyNode,\n duplicateSlotMessage,\n sharedSlotMessage,\n sharedSlots,\n undeclaredSlotMessage,\n} from '@pithyjs/compiler';\nimport { pithyTreeToDom } from './pithyTreeToDom';\nimport { bindStructuralDirectives } from './compileTemplate';\nimport { nodeExpando } from './nodeExpando';\nimport {\n bindErrorBoundary,\n insertBesideHidden,\n withSlotBoundary,\n isHiddenByBoundary,\n} from './binds/bindErrorBoundary';\nimport { pithyGlobals } from '../types/globals';\nimport { trimBlankEdges } from './trimBlankEdges';\nimport { withinRender } from './ssrCrashes';\n\n/**\n * SlotMap contains renderer functions for each slot name.\n * Each entry is a factory that returns a DocumentFragment of the slot's content.\n */\nexport type SlotMap = Map<\n string,\n (disposers?: (() => void)[], anchor?: Node) => DocumentFragment\n>;\n\n/**\n * SlotDef describes a slot anchor and its fallback content\n */\nexport type FallbackFactory = () => HTMLElement | DocumentFragment | undefined;\n\nexport interface SlotDef {\n name: string;\n anchor: Comment;\n fallbackFactory?: FallbackFactory;\n}\n\ninterface ProjectionExpando {\n __slotName?: string;\n __fallbackFactory?: FallbackFactory;\n __projectionProcessed?: boolean;\n __projectedContent?: boolean;\n}\n\nfunction expando(node: Node): ProjectionExpando {\n return node as Node & ProjectionExpando;\n}\n\nconst outerSlotMaps = new WeakMap<SlotMap, SlotMap>();\nconst slotMapTags = new WeakMap<SlotMap, string>();\nconst slotMapOwners = new WeakMap<SlotMap, object>();\nlet warnedDuplicates = new WeakMap<object, Set<string>>();\n\n/** Records the component tag `slotMap` fills, and the component, for DEV warnings. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"nameSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap, tag: string, owner?: object) => void\"} */\nexport function nameSlotMap(\n slotMap: SlotMap,\n tag: string,\n owner?: object\n): void {\n slotMapTags.set(slotMap, tag);\n if (owner) slotMapOwners.set(slotMap, owner);\n}\n\n/**\n * DEV: warns once per component and slot name that a later `<slot>` gets no\n * content. Without a known component, once per `instance` (one render).\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"warnDuplicateSlot\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined, name: string, instance: object) => void\"} */\nexport function warnDuplicateSlot(\n slotMap: SlotMap | undefined,\n name: string,\n instance: object\n): void {\n const key = (slotMap && slotMapOwners.get(slotMap)) ?? instance;\n let names = warnedDuplicates.get(key);\n if (!names) warnedDuplicates.set(key, (names = new Set()));\n if (names.has(name)) return;\n names.add(name);\n const tag = (slotMap && slotMapTags.get(slotMap)) ?? 'component';\n console.warn(`[PithyJS] ${duplicateSlotMessage(tag, name)}`);\n}\n\n/** Test hook: lets each test see its first duplicate-slot warning. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"resetDuplicateSlotWarnings\",\"stability\":\"internal\",\"signature\":\"() => void\"} */\nexport function resetDuplicateSlotWarnings(): void {\n warnedDuplicates = new WeakMap();\n}\n\nconst declaredSlots = new WeakMap<SlotMap, Set<string>>();\nconst seenSlotMaps = new WeakSet<SlotMap>();\nconst unknownSlotMaps = new WeakSet<SlotMap>();\nlet warnedUndeclared = new WeakMap<object, Set<string>>();\n\n/**\n * DEV: records `names` as slots the component that `slotMap` fills renders,\n * and that its template or children were looked at, which is what lets\n * `warnUndeclaredSlots` check the rest.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"declareSlotNames\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined, names: Iterable<string>) => void\"} */\nexport function declareSlotNames(\n slotMap: SlotMap | undefined,\n names: Iterable<string>\n): void {\n if (!slotMap) return;\n let declared = declaredSlots.get(slotMap);\n if (!declared) declaredSlots.set(slotMap, (declared = new Set()));\n for (const name of names) declared.add(name);\n seenSlotMaps.add(slotMap);\n}\n\n/**\n * DEV: a template rendered for `slotMap` without its `<slot>` list, as an\n * older plugin's build or a precompiled library does. `warnUndeclaredSlots`\n * then stays silent for the map, whatever else declared names for it.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"markSlotsUnknown\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined) => void\"} */\nexport function markSlotsUnknown(slotMap: SlotMap | undefined): void {\n if (slotMap) unknownSlotMaps.add(slotMap);\n}\n\n/**\n * Declares slot names a component reads from its children by hand, such as\n * `slot=\"fallback\"`, so DEV does not report content addressed to them as\n * having nowhere to go, and marks its children as read, so DEV reports the\n * rest. With no names, it only marks them read. Call it during render, before\n * `captureChildren()`, which clears the context it reads. A no-op outside DEV\n * or a render.\n *\n * @param names - The `slot=\"…\"` values the component handles itself\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"declareSlots\",\"stability\":\"experimental\",\"signature\":\"(...names: string[]) => void\"} */\nexport function declareSlots(...names: string[]): void {\n if (import.meta.env?.DEV)\n declareSlotNames(pithyGlobals().__pithyComponentContext?.__slotMap, names);\n}\n\n/**\n * DEV: warns once per component and slot name for content in `slotMap`\n * addressed to a named slot its component never declared. Silent for a\n * component whose template and children were never looked at, or whose\n * template rendered without its `<slot>` list.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"warnUndeclaredSlots\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap) => void\"} */\nexport function warnUndeclaredSlots(slotMap: SlotMap): void {\n if (!seenSlotMaps.has(slotMap) || unknownSlotMaps.has(slotMap)) return;\n const declared = declaredSlots.get(slotMap);\n const tag = slotMapTags.get(slotMap) ?? 'component';\n const key = slotMapOwners.get(slotMap) ?? slotMap;\n let warned = warnedUndeclared.get(key);\n if (!warned) warnedUndeclared.set(key, (warned = new Set()));\n for (const name of slotMap.keys()) {\n if (name === '' || declared?.has(name) || warned.has(name)) continue;\n warned.add(name);\n console.warn(`[PithyJS] ${undeclaredSlotMessage(tag, name)}`);\n }\n}\n\n/** Test hook: lets each test see its first undeclared-slot warning. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"resetUndeclaredSlotWarnings\",\"stability\":\"internal\",\"signature\":\"() => void\"} */\nexport function resetUndeclaredSlotWarnings(): void {\n warnedUndeclared = new WeakMap();\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"slotMapOf\",\"stability\":\"internal\",\"signature\":\"(ctx: Record<string, unknown>) => SlotMap | undefined\"} */\nexport function slotMapOf(ctx: Record<string, unknown>): SlotMap | undefined {\n return ('__slotMap' in ctx ? ctx.__slotMap : undefined) as\n | SlotMap\n | undefined;\n}\n\n/**\n * The slot map of the template the children behind `slotMap` were written in:\n * what a `<slot>` among those children receives.\n */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"outerSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap | undefined) => SlotMap | undefined\"} */\nexport function outerSlotMap(\n slotMap: SlotMap | undefined\n): SlotMap | undefined {\n return slotMap && outerSlotMaps.get(slotMap);\n}\n\n/** Records `ctx`'s slot map as what a `<slot>` among `slotMap`'s children receives. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"linkOuterSlotMap\",\"stability\":\"internal\",\"signature\":\"(slotMap: SlotMap, ctx: Record<string, unknown>) => void\"} */\nexport function linkOuterSlotMap(\n slotMap: SlotMap,\n ctx: Record<string, unknown>\n): void {\n const outer = slotMapOf(ctx);\n if (outer) outerSlotMaps.set(slotMap, outer);\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"collectSlotMap\",\"stability\":\"stable\",\"signature\":\"(children: PithyNode[], parentContext: Record<string, any>, host?: Element, owner?: object) => SlotMap\"} */\nexport function collectSlotMap(\n children: PithyNode[],\n parentContext: Record<string, unknown>,\n host?: Element,\n owner?: object\n): SlotMap {\n const slotMap: SlotMap = new Map();\n const slotGroups = new Map<string, PithyNode[]>();\n linkOuterSlotMap(slotMap, parentContext);\n const outer = slotMapOf(parentContext);\n\n // Group children by slot attribute\n for (const child of children) {\n const slotName = child.directives?.slot || ''; // default slot if no slot attribute\n\n if (!slotGroups.has(slotName)) {\n slotGroups.set(slotName, []);\n }\n slotGroups.get(slotName)!.push(child);\n }\n const defaultSlot = slotGroups.get('');\n if (defaultSlot) {\n const content = trimBlankEdges(defaultSlot, node =>\n node.type === 'text' ? (node.textContent ?? '') : null\n );\n if (content.length) slotGroups.set('', content);\n else slotGroups.delete('');\n }\n\n if (import.meta.env?.DEV) {\n const tag =\n (host && nodeExpando(host).__pithyNode?.originalTagName) ??\n host?.localName ??\n 'component';\n nameSlotMap(slotMap, tag, owner);\n for (const name of sharedSlots(children))\n console.warn(`[PithyJS] ${sharedSlotMessage(tag, name)}`);\n }\n\n // Create renderer functions for each slot group.\n // NOTE: We intentionally do NOT cache or clone DocumentFragments here.\n // Using fragment caching + cloneNode(true) would strip custom JS properties\n // like __pithyCtx that binders rely on to resolve projected content\n // expressions (including interpolation, [class], and [attr] bindings)\n // against the *parent* component's context.\n //\n // This behavior is relied upon by regression tests that exercise projected\n // nodes containing such bindings; changing this to reuse or clone\n // fragments will cause those tests to fail and break content projection.\n // pithyTreeToDom is cheap (just creates DOM nodes), so recreating is fine.\n\n for (const [slotName, nodes] of slotGroups) {\n // Capture nodes and context in closure for stable reference\n const capturedNodes = nodes;\n const capturedContext = parentContext;\n\n const render = (\n disposers: (() => void)[] = [],\n at?: Node\n ): DocumentFragment => {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Rendering slot \"${slotName}\" with ${capturedNodes.length} nodes`\n );\n }\n\n const fragment = pithyTreeToDom(capturedNodes, capturedContext);\n // As the AOT renderer does: a branch in the content then finds a boundary\n // the receiver wraps its `<slot>` in.\n withSlotBoundary(at, host, () =>\n withinRender(() => {\n bindStructuralDirectives(\n capturedNodes,\n fragment,\n capturedContext,\n disposers\n );\n bindErrorBoundary(fragment, capturedContext, disposers);\n return fragment;\n })\n );\n // A `<slot>` passed through: the receiving component has already looked for its slots.\n const passed = extractSlotDefs(fragment);\n if (passed.length) mountProjection(passed, outer ?? new Map(), disposers);\n nodeExpando(fragment).__pithyCtx = capturedContext;\n return fragment;\n };\n\n slotMap.set(slotName, render);\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Collected SlotMap with slots:`,\n Array.from(slotMap.keys())\n );\n }\n return slotMap;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"extractSlotDefs\",\"stability\":\"stable\",\"signature\":\"(fragment: DocumentFragment) => SlotDef[]\"} */\nexport function extractSlotDefs(fragment: DocumentFragment): SlotDef[] {\n const slotDefs: SlotDef[] = [];\n const walker = document.createTreeWalker(fragment, NodeFilter.SHOW_COMMENT, {\n acceptNode: node => {\n const comment = node as Comment;\n return comment.textContent?.startsWith('slot:')\n ? NodeFilter.FILTER_ACCEPT\n : NodeFilter.FILTER_REJECT;\n },\n });\n\n let node: Comment | null;\n while ((node = walker.nextNode() as Comment | null)) {\n // Inside a component tag, the slot is that component's content to place.\n if (inComponentTag(node)) continue;\n const slotName = expando(node).__slotName || '';\n const fallbackFactory = expando(node).__fallbackFactory;\n\n slotDefs.push({\n name: slotName,\n anchor: node,\n fallbackFactory,\n });\n }\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Extracted ${slotDefs.length} slot definitions`\n );\n }\n return slotDefs;\n}\n\n/** Whether `node` is inside content a `<slot>` projected. */\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"inProjectedContent\",\"stability\":\"internal\",\"signature\":\"(node: Node) => boolean\"} */\nexport function inProjectedContent(node: Node): boolean {\n for (let n: Node | null = node; n; n = n.parentNode)\n if (expando(n).__projectedContent) return true;\n return false;\n}\n\nfunction inComponentTag(node: Node): boolean {\n for (let el = node.parentElement; el; el = el.parentElement)\n if (nodeExpando(el).__pithyNode?.isComponent) return true;\n return false;\n}\n\n/** @codexApi {\"parent\":\"pithy.feature.content-projection\",\"name\":\"mountProjection\",\"stability\":\"stable\",\"signature\":\"(slotDefs: SlotDef[], slotMap: SlotMap, disposers: (() => void)[]) => void\"} */\nexport function mountProjection(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n // A slot's content is rendered and then inserted: one render transaction.\n withinRender(() => mountSlots(slotDefs, slotMap, disposers));\n}\n\nfunction mountSlots(\n slotDefs: SlotDef[],\n slotMap: SlotMap,\n disposers: (() => void)[]\n): void {\n // As in the HTML spec, only the first slot of a name receives content.\n const filled = new Set<string>();\n for (const slotDef of slotDefs) {\n const { name, anchor, fallbackFactory } = slotDef;\n\n // Skip if this slot has already been processed\n if (expando(anchor).__projectionProcessed) {\n continue;\n }\n\n // Mark this slot as processed to prevent multiple passes\n expando(anchor).__projectionProcessed = true;\n\n const later = filled.has(name);\n filled.add(name);\n if (later && import.meta.env?.DEV)\n warnDuplicateSlot(slotMap, name, slotMap);\n const renderer = later ? undefined : slotMap.get(name);\n\n const parent = anchor.parentNode;\n // A crash in an earlier slot can have hidden this anchor behind a fallback.\n if (!parent && !isHiddenByBoundary(anchor)) {\n if (import.meta.env?.DEV) {\n console.warn(\n `[ContentProjection] Slot anchor \"${name}\" has no parent node - skipping`\n );\n }\n continue;\n }\n\n // Determine which content to render\n let contentFragment: HTMLElement | DocumentFragment | null = null;\n let isProjectedContent = false;\n\n if (renderer) {\n // Use projected content\n contentFragment = renderer(disposers, anchor);\n isProjectedContent = true;\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting projected content for slot \"${name}\"`\n );\n }\n } else if (fallbackFactory) {\n // Use fallback content\n contentFragment = fallbackFactory() ?? null;\n const slotNode = nodeExpando(anchor).__pithyNode;\n if (\n contentFragment instanceof DocumentFragment &&\n slotNode?.fallbackChildren\n ) {\n const fallbackCtx = nodeExpando(anchor).__pithyCtx ?? {};\n const fallbackFragment = contentFragment;\n const fallbackNodes = slotNode.fallbackChildren;\n withinRender(() => {\n bindStructuralDirectives(\n fallbackNodes,\n fallbackFragment,\n fallbackCtx,\n disposers\n );\n bindErrorBoundary(fallbackFragment, fallbackCtx, disposers);\n });\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Mounting fallback content for slot \"${name}\"`\n );\n }\n } else {\n // No content to mount\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] No content for slot \"${name}\"`);\n }\n continue;\n }\n\n // Validate content\n if (!contentFragment || contentFragment.childNodes.length === 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Empty content for slot \"${name}\" - skipping`\n );\n }\n continue;\n }\n\n // CRITICAL: Collect nodes BEFORE inserting into DOM (for cleanup tracking)\n // Once inserted, the fragment's childNodes will be empty\n const nodesToInsert: Node[] = Array.from(contentFragment.childNodes);\n\n // Mark nodes for tracking\n for (const node of nodesToInsert) {\n expando(node).__projectedContent = isProjectedContent;\n expando(node).__slotName = name;\n }\n\n // Find and remove any existing content for this slot\n const existingNodes: Node[] = [];\n let current = anchor.nextSibling;\n\n while (current) {\n // Stop if we hit another slot anchor\n if (\n current.nodeType === Node.COMMENT_NODE &&\n (current as Comment).textContent?.startsWith('slot:')\n ) {\n break;\n }\n\n // A sibling no projection marked is the component's own markup.\n const meta = expando(current);\n if (meta.__projectedContent === undefined || meta.__slotName !== name) {\n break;\n }\n existingNodes.push(current);\n\n current = current.nextSibling;\n }\n\n // Simple diffing: only replace if content appears different\n // Compare node count and types as a basic heuristic\n const shouldReplace =\n existingNodes.length !== nodesToInsert.length ||\n existingNodes.some(\n (node, i) => node.nodeType !== nodesToInsert[i]?.nodeType\n );\n\n if (!shouldReplace && existingNodes.length > 0) {\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Content for slot \"${name}\" unchanged - skipping replacement`\n );\n }\n continue;\n }\n\n // Remove existing content\n for (const node of existingNodes) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n\n // Insert new content after the anchor comment\n if (!insertBesideHidden(anchor, contentFragment))\n parent?.insertBefore(contentFragment, anchor.nextSibling);\n\n // Track cleanup - remove projected nodes when component unmounts\n disposers.push(() => {\n for (const node of nodesToInsert) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n }\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(`[PithyJS:Projection] Cleaned up slot \"${name}\"`);\n }\n });\n\n if (import.meta.env?.DEV && pithyGlobals().PITHY_DEBUG_PROJECTION) {\n console.log(\n `[PithyJS:Projection] Successfully mounted ${nodesToInsert.length} nodes for slot \"${name}\"`\n );\n }\n }\n\n // DEV: Validate slot usage\n // NOTE: We intentionally do NOT warn about unmatched projected slots here.\n // When a component uses @if/@else with different <slot> elements in each\n // branch (e.g., Show has <slot> in @if and <slot name=\"fallback\"> in @else),\n // the currently-rendered branch may not include all slot targets. The\n // projected \"fallback\" content is legitimate — it will be mounted when\n // the @else branch activates. Warnings here would be false positives\n // and fire repeatedly on every reactive toggle.\n // warnUndeclaredSlots checks against the whole template after the component returns.\n}\n"]}
|
package/dist/compile/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { bindComponentTags } from './binds/bindComponentsTags.js';
|
|
|
9
9
|
export { bindForLoops, createLoopManager, type ChildFactory, type LoopManager, } from './forLoops/index.js';
|
|
10
10
|
export { bindTemplateDirectives } from './compileTemplate.js';
|
|
11
11
|
export type { SlotMap } from './contentProjection.js';
|
|
12
|
+
export { declareSlots } from './contentProjection.js';
|
|
12
13
|
export { isSSRMode } from './ssrMode.js';
|
|
13
14
|
export { registerDirectiveBinder, unregisterDirectiveBinder, executeCustomDirectiveBinders, type DirectiveBinder, } from './binds/directiveRegistry.js';
|
|
14
15
|
export { boundaryForElement, setBoundaryError, clearBoundaryError, registerBoundary, } from './binds/bindErrorBoundary.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,kBAAkB,C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,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,YAAY,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,6BAA6B,EAC7B,KAAK,eAAe,GACrB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAU9D,OAAO,EACL,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/compile/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export { bindClassDirectives } from './binds/bindClassDirectives.js';
|
|
|
12
12
|
export { bindComponentTags } from './binds/bindComponentsTags.js';
|
|
13
13
|
export { bindForLoops, createLoopManager, } from './forLoops/index.js';
|
|
14
14
|
export { bindTemplateDirectives } from './compileTemplate.js';
|
|
15
|
+
export { declareSlots } from './contentProjection.js';
|
|
15
16
|
// The explicit static-render signal. `@pithyjs/ssr`'s setupEnvironment() copies
|
|
16
17
|
// a happy-dom window onto globalThis — IntersectionObserver, requestAnimationFrame
|
|
17
18
|
// and matchMedia included — so no `typeof` feature check can distinguish a server
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAC1B,uEAAuE;AACvE,0EAA0E;AAC1E,sEAAsE;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,wDAAwD;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,GAEjB,MAAM,kBAAkB,CAAC;AAC1B,uEAAuE;AACvE,0EAA0E;AAC1E,sEAAsE;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,wDAAwD;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAI3D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,gFAAgF;AAChF,mFAAmF;AACnF,kFAAkF;AAClF,iFAAiF;AACjF,iFAAiF;AACjF,2DAA2D;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,0FAA0F;AAC1F,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,6BAA6B,GAE9B,MAAM,2BAA2B,CAAC;AAEnC,mDAAmD;AACnD,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,2EAA2E;AAC3E,sEAAsE;AACtE,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,8DAA8D;AAC9D,OAAO,EACL,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,cAAc,CAAC","sourcesContent":["export { compileTemplate } from './compileTemplate';\nexport { compileNodes } from './compileNodes';\nexport {\n renderChildren,\n captureChildren,\n readChildPayload,\n type ChildPayload,\n} from './renderChildren';\n// parseHtml is NOT re-exported from this barrel to prevent parse5 from\n// being pulled into production bundles. Use the dedicated subpath export:\n// import { loadJITCompiler } from '@pithyjs/core/compile/parseHtml'\nexport { injectScopedStyle } from './injectScopedStyle';\n\n// Only export these if useful for advanced users / SSR:\nexport { bindTextInterpolations } from './binds/bindTextInterpolations';\nexport { bindEventHandlers } from './binds/bindEventHandlers';\nexport { bindClassDirectives } from './binds/bindClassDirectives';\nexport { bindComponentTags } from './binds/bindComponentsTags';\nexport {\n bindForLoops,\n createLoopManager,\n type ChildFactory,\n type LoopManager,\n} from './forLoops';\nexport { bindTemplateDirectives } from './compileTemplate';\n\n// Content projection types (stable — part of the component authoring API)\nexport type { SlotMap } from './contentProjection';\nexport { declareSlots } from './contentProjection';\n\n// The explicit static-render signal. `@pithyjs/ssr`'s setupEnvironment() copies\n// a happy-dom window onto globalThis — IntersectionObserver, requestAnimationFrame\n// and matchMedia included — so no `typeof` feature check can distinguish a server\n// render from a browser. Packages that must branch on it (e.g. @pithyjs/ui-kit's\n// section entrance animations, BUG-010) read this rather than hand-rolling their\n// own derivation of the underlying `__PITHY_SSR__` global.\nexport { isSSRMode } from './ssrMode';\n\n// Custom directive registry - allows external packages (router, etc.) to register binders\nexport {\n registerDirectiveBinder,\n unregisterDirectiveBinder,\n executeCustomDirectiveBinders,\n type DirectiveBinder,\n} from './binds/directiveRegistry';\n\n// Error boundary functions for router integration:\nexport {\n boundaryForElement,\n setBoundaryError,\n clearBoundaryError,\n registerBoundary,\n} from './binds/bindErrorBoundary';\nexport type { BoundaryInfo } from './binds/bindErrorBoundary';\n\n// Unhandled component crashes recorded during a server render. Consumed by\n// @pithyjs/ssr's renderToString so a crash fails its route (BUG-018).\n//\n// Only the two read/lifecycle APIs are public. `recordSSRRenderCrash` and\n// `clearSSRRenderCrash` mutate the registry and are called exclusively by the\n// binders inside this package, so they are annotated `internal` rather than\n// exported here — advertising them as stable in the generated API table while\n// leaving them unimportable is worse than either alternative.\nexport {\n collectUnhandledSSRRenderCrashes,\n resetSSRRenderCrashes,\n} from './ssrCrashes';\nexport type { SSRRenderCrash } from './ssrCrashes';\n"]}
|
|
@@ -29,8 +29,13 @@ export interface NodeExpando {
|
|
|
29
29
|
__pithyForwardAttrs?: Set<string>;
|
|
30
30
|
/** Identifies that forwarding, so two tags in one scope stay two bindings. */
|
|
31
31
|
__pithyForwardId?: number;
|
|
32
|
+
/** A build's root fragment: its template's `<slot>` names, in DEV. */
|
|
33
|
+
__pithySlots?: string[];
|
|
34
|
+
/** A build's template-component child fragment, in DEV: not a root without a slot list. */
|
|
35
|
+
__pithyChildFactory?: boolean;
|
|
32
36
|
/** The boundary element a slot rendered this node for, wherever a portal moves it. */
|
|
33
37
|
__pithySlotOwner?: Element;
|
|
38
|
+
__pithySlotInFallback?: boolean;
|
|
34
39
|
}
|
|
35
40
|
/** Records that `ctx`'s tag forwarded `names` onto `root`. */
|
|
36
41
|
export declare function markForwardTarget(root: Element, ctx: Record<string, unknown>, names: Set<string>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodeExpando.d.ts","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,gBAAgB,CAAC;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,0EAA0E;IAC1E,yEAAyE;IACzE,eAAe,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;IACxD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,aAAa,CAAC,EAAE;Q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Expando.js","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nodeExpando.js","sourceRoot":"","sources":["../../src/compile/nodeExpando.ts"],"names":[],"mappings":"AAuCA,IAAI,aAAa,GAAG,CAAC,CAAC;AAEtB,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,IAAa,EACb,GAA4B,EAC5B,KAAkB;IAElB,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC,iBAAiB,GAAG,GAAG,CAAC;IAC1B,CAAC,CAAC,mBAAmB,GAAG,KAAK,CAAC;IAC9B,CAAC,CAAC,gBAAgB,GAAG,EAAE,aAAa,CAAC;AACvC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,eAAe,CAAC,EAAW,EAAE,GAAW;IACtD,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,gBAAgB,IAAI,GAAG,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,WAAW,CAAiB,IAAO;IACjD,OAAO,IAAuB,CAAC;AACjC,CAAC","sourcesContent":["import type { PithyNode } from '@pithyjs/compiler';\n\nexport interface StyleOwners {\n strings: string[];\n props: Map<string, [value: string, priority: string]>;\n}\n\nexport interface NodeExpando {\n __pithyCtx?: Record<string, unknown>;\n __pithyNode?: PithyNode;\n __nodeId?: string;\n __slotName?: string;\n __fallbackFactory?: () => DocumentFragment;\n __nested?: boolean;\n __pithySkipText?: boolean;\n __pithyComponentDom?: boolean;\n /** A build's component placeholder: renders it through the AOT binder. */\n /** Renders a build's placeholder; returns the nodes that replaced it. */\n __pithyAotMount?: (disposers: (() => void)[]) => Node[];\n __styleProps?: string[];\n __styleOwners?: StyleOwners;\n __selectValue?: { text: string; picks: Set<string> | null };\n __classToggles?: string[];\n __forwardedDirectives?: Map<string, string>;\n /** A component root's forwarded bindings evaluate in the tag's template. */\n __pithyForwardCtx?: Record<string, unknown>;\n /** The attributes the tag that set `__pithyForwardCtx` forwarded. */\n __pithyForwardAttrs?: Set<string>;\n /** Identifies that forwarding, so two tags in one scope stay two bindings. */\n __pithyForwardId?: number;\n /** A build's root fragment: its template's `<slot>` names, in DEV. */\n __pithySlots?: string[];\n /** A build's template-component child fragment, in DEV: not a root without a slot list. */\n __pithyChildFactory?: boolean;\n /** The boundary element a slot rendered this node for, wherever a portal moves it. */\n __pithySlotOwner?: Element;\n __pithySlotInFallback?: boolean;\n}\n\nlet nextForwardId = 0;\n\n/** Records that `ctx`'s tag forwarded `names` onto `root`. */\nexport function markForwardTarget(\n root: Element,\n ctx: Record<string, unknown>,\n names: Set<string>\n): void {\n const x = nodeExpando(root);\n x.__pithyForwardCtx = ctx;\n x.__pithyForwardAttrs = names;\n x.__pithyForwardId = ++nextForwardId;\n}\n\n/** Keys a forwarded event by the forwarding that put it on `el`. */\nexport function forwardEventKey(el: Element, key: string): string {\n return `${nodeExpando(el).__pithyForwardId}|${key}`;\n}\n\nexport function nodeExpando<T extends Node>(node: T): T & NodeExpando {\n return node as T & NodeExpando;\n}\n"]}
|
|
@@ -64,6 +64,8 @@ export interface ChildPayload {
|
|
|
64
64
|
slot?: SlotRenderer;
|
|
65
65
|
/** What a `<slot>` among `astNodes` receives. */
|
|
66
66
|
outer?: SlotMap;
|
|
67
|
+
/** A build passed content for a named slot, which `slot` does not carry. */
|
|
68
|
+
named: boolean;
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
69
71
|
* Reads the children addressed to the component being rendered, without
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderChildren.d.ts","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAgB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"renderChildren.d.ts","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAgB,KAAK,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAGL,KAAK,OAAO,EACb,MAAM,qBAAqB,CAAC;AAG7B,KAAK,YAAY,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE5D;;;;;;;;;;;;;;;;GAgBG;AACH,wKAAwK;AACxK,wBAAgB,cAAc,IAAI;IAChC,EAAE,EAAE,gBAAgB,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAiDA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,yKAAyK;AACzK,wBAAgB,eAAe,IAAI;IACjC,EAAE,EAAE,gBAAgB,CAAC;IACrB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CASA;AASD,+IAA+I;AAC/I,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC3C,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,2EAA2E;IAC3E,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,iDAAiD;IACjD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4EAA4E;IAC5E,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;GAKG;AACH,+IAA+I;AAC/I,wBAAgB,gBAAgB,IAAI,YAAY,CAc/C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compileNodes } from './compileNodes.js';
|
|
2
2
|
import { pithyGlobals } from '../types/globals.js';
|
|
3
|
-
import { outerSlotMap } from './contentProjection.js';
|
|
3
|
+
import { declareSlotNames, outerSlotMap, } from './contentProjection.js';
|
|
4
4
|
import { withSlotBoundary } from './binds/bindErrorBoundary.js';
|
|
5
5
|
/**
|
|
6
6
|
* If the registry renderer has set `globalThis.__pithyProjectedChildren` (a
|
|
@@ -22,12 +22,15 @@ import { withSlotBoundary } from './binds/bindErrorBoundary.js';
|
|
|
22
22
|
/** @codexApi {"parent":"pithy.runtime.compile-nodes","name":"renderChildren","stability":"stable","signature":"() => { el: DocumentFragment; destroy: () => void }"} */
|
|
23
23
|
export function renderChildren() {
|
|
24
24
|
const globalScope = pithyGlobals();
|
|
25
|
+
const componentCtx = globalScope.__pithyComponentContext;
|
|
26
|
+
// Children rendered here fill no named slot.
|
|
27
|
+
if (import.meta.env?.DEV)
|
|
28
|
+
declareSlotNames(componentCtx?.__slotMap, []);
|
|
25
29
|
const injected = globalScope.__pithyProjectedChildren;
|
|
26
30
|
if (injected) {
|
|
27
31
|
globalScope.__pithyProjectedChildren = undefined;
|
|
28
32
|
return { el: injected, destroy: () => { } };
|
|
29
33
|
}
|
|
30
|
-
const componentCtx = pithyGlobals().__pithyComponentContext;
|
|
31
34
|
const slot = buildDefaultSlot(componentCtx);
|
|
32
35
|
if (slot) {
|
|
33
36
|
const disposers = [];
|
|
@@ -119,6 +122,7 @@ export function readChildPayload() {
|
|
|
119
122
|
projected: g.__pithyProjectedChildren,
|
|
120
123
|
slot: buildDefaultSlot(context),
|
|
121
124
|
outer: outerSlotMap(context?.__slotMap),
|
|
125
|
+
named: [...(context?.__slotMap?.keys() ?? [])].some(name => name !== ''),
|
|
122
126
|
};
|
|
123
127
|
}
|
|
124
128
|
//# sourceMappingURL=renderChildren.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderChildren.js","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,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AC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;QACxB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAcD;;;;;GAKG;AACH,+IAA+I;AAC/I,MAAM,UAAU,gBAAgB;IAC9B,MAAM,CAAC,GAAG,YAAY,EAAE,CAAC;IACzB,MAAM,OAAO,GAAG,CAAC,CAAC,uBAAuB,CAAC;IAC1C,MAAM,OAAO,GAAG,OAAO,EAAE,cAAc,CAAC;IACxC,MAAM,GAAG,GAAG,OAAO,EAAE,eAAe,CAAC;IACrC,OAAO;QACL,OAAO;QACP,OAAO;QACP,QAAQ,EAAE,CAAC,OAAO,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;QAC7D,SAAS,EAAE,CAAC,CAAC,wBAAwB;QACrC,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC;QAC/B,KAAK,EAAE,YAAY,CAAC,OAAO,EAAE,SAAS,CAAC;KACxC,CAAC;AACJ,CAAC","sourcesContent":["import { compileNodes } from './compileNodes';\nimport type { PithyNode } from '@pithyjs/compiler';\nimport { pithyGlobals, type PithyComponentContext } from '../types/globals';\nimport type { ChildFactory } from '../runtime/bindings/types';\nimport { outerSlotMap, type SlotMap } from './contentProjection';\nimport { withSlotBoundary } from './binds/bindErrorBoundary';\n\ntype SlotRenderer = NonNullable<ReturnType<SlotMap['get']>>;\n\n/**\n * If the registry renderer has set `globalThis.__pithyProjectedChildren` (a\n * `DocumentFragment` of already-rendered slot children), returns and clears it —\n * single-consume, so the first caller wins. This delivers construction-time\n * children on the registry path. The registry path has no AST fallback, so a\n * second `renderChildren()`/`captureChildren()` call returns an empty fragment.\n *\n * A build-compiled parent's default slot is rendered afresh on every call.\n *\n * Otherwise compiles child AST nodes from the current component context through\n * the full pipeline (structural + non-structural directives). This enables\n * nested components inside projected content — unlike `<slot>`, which inserts\n * DOM after `bindComponentTags` has already run.\n *\n * Use inside component functions (Stack, Grid, etc.) that need to compile\n * their children without named slots or fallback content.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"renderChildren\",\"stability\":\"stable\",\"signature\":\"() => { el: DocumentFragment; destroy: () => void }\"} */\nexport function renderChildren(): {\n el: DocumentFragment;\n destroy: () => void;\n} {\n const globalScope = pithyGlobals();\n const injected = globalScope.__pithyProjectedChildren;\n if (injected) {\n globalScope.__pithyProjectedChildren = undefined;\n return { el: injected, destroy: () => {} };\n }\n\n const componentCtx = pithyGlobals().__pithyComponentContext;\n const slot = buildDefaultSlot(componentCtx);\n if (slot) {\n const disposers: (() => void)[] = [];\n const el = slot(disposers);\n return {\n el,\n destroy: () => {\n for (let i = disposers.length - 1; i >= 0; i--) disposers[i]();\n disposers.length = 0;\n },\n };\n }\n\n // A parent composing atoms by direct call after captureChildren() cleared its\n // context is still mid-render (`rendering` truthy) — not the misuse this guards\n // against, so a consumed context alone must not trigger the warning.\n const rendering = pithyGlobals().__pithyRenderingComponent;\n if (import.meta.env?.DEV && !componentCtx && !rendering) {\n console.warn('[renderChildren] Called outside component render context');\n }\n\n const childAstNodes: PithyNode[] = componentCtx?.__childAstNodes ?? [];\n\n // Strip internal __ properties, keep parent scope (includes components, signals, etc.)\n const parentCtx: Record<string, unknown> = componentCtx\n ? Object.fromEntries(\n Object.entries(componentCtx).filter(\n ([k]) => !k.startsWith('__') || k === '__pithyRowLocals'\n )\n )\n : {};\n // What a `<slot>` among the children receives.\n const outer = outerSlotMap(componentCtx?.__slotMap);\n if (outer) parentCtx.__slotMap = outer;\n\n return withSlotBoundary(undefined, componentCtx?.__slotHost, () =>\n compileNodes(childAstNodes, parentCtx)\n );\n}\n\n/**\n * Captures projected children and clears the component context so\n * inner component calls (e.g. `Heading()`, `Text()`) don't consume\n * the outer component's children.\n *\n * After capture, the current component's context on `globalThis` is\n * reset to the value of `__parentComponentContext` if present, or\n * otherwise to `undefined`. In the current core implementation,\n * `__parentComponentContext` is not set by the runtime, so this\n * effectively clears the active component context to prevent child\n * leakage into inner component calls.\n *\n * **Important invariant:** This function must be called exactly once per\n * component, before any inner component function calls. It consumes the\n * current context's children — a second call would return an empty fragment.\n * After this call, the caller must not rely on reading its own context\n * properties from `globalThis.__pithyComponentContext`.\n *\n * For 3+ levels of nesting (e.g., section A → section B → atoms), each\n * level should call `captureChildren()` independently. Any multi-level\n * parent restoration depends on `__parentComponentContext` being managed\n * by external tooling; the core library only performs a best-effort reset\n * from that property when present.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"captureChildren\",\"stability\":\"stable\",\"signature\":\"() => { el: DocumentFragment; destroy: () => void }\"} */\nexport function captureChildren(): {\n el: DocumentFragment;\n destroy: () => void;\n} {\n const g = pithyGlobals();\n const prevCtx = g.__pithyComponentContext;\n const result = renderChildren();\n // Clear context so inner component calls start fresh.\n // If there was a parent context, it will be restored by the parent's\n // own render cycle — we only need to prevent child leakage here.\n g.__pithyComponentContext = prevCtx?.__parentComponentContext ?? undefined;\n return result;\n}\n\n/** Default-slot renderer of a build-compiled parent; it has no AST. */\nfunction buildDefaultSlot(ctx: PithyComponentContext | undefined) {\n return ctx && !ctx.__childAstNodes && !ctx.__childFactory\n ? ctx.__slotMap?.get('')\n : undefined;\n}\n\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"ChildPayload\",\"stability\":\"experimental\",\"signature\":\"interface ChildPayload\"} */\nexport interface ChildPayload {\n context: PithyComponentContext | undefined;\n factory?: ChildFactory;\n astNodes?: PithyNode[];\n projected?: DocumentFragment;\n /** A build's default slot, rendered by `renderChildren()` on each call. */\n slot?: SlotRenderer;\n /** What a `<slot>` among `astNodes` receives. */\n outer?: SlotMap;\n}\n\n/**\n * Reads the children addressed to the component being rendered, without\n * consuming them. `factory` and `astNodes` are mutually exclusive: an AOT child\n * factory wins, because a JIT parent's AST can reach an AOT component's context\n * through `mergeContexts`, never the reverse.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"readChildPayload\",\"stability\":\"experimental\",\"signature\":\"() => ChildPayload\"} */\nexport function readChildPayload(): ChildPayload {\n const g = pithyGlobals();\n const context = g.__pithyComponentContext;\n const factory = context?.__childFactory;\n const ast = context?.__childAstNodes;\n return {\n context,\n factory,\n astNodes: !factory && ast && ast.length > 0 ? ast : undefined,\n projected: g.__pithyProjectedChildren,\n slot: buildDefaultSlot(context),\n outer: outerSlotMap(context?.__slotMap),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"renderChildren.js","sourceRoot":"","sources":["../../src/compile/renderChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAA8B,MAAM,kBAAkB,CAAC;AAE5E,OAAO,EACL,gBAAgB,EAChB,YAAY,GAEb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAI7D;;;;;;;;;;;;;;;;GAgBG;AACH,wKAAwK;AACxK,MAAM,UAAU,cAAc;IAI5B,MAAM,WAAW,GAAG,YAAY,EAAE,CAAC;IACnC,MAAM,YAAY,GAAG,WAAW,CAAC,uBAAuB,CAAC;IACzD,6CAA6C;IAC7C,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG;QAAE,gBAAgB,CAAC,YAAY,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;IACxE,MAAM,QAAQ,GAAG,WAAW,CAAC,wBAAwB,CAAC;IACtD,IAAI,QAAQ,EAAE,CAAC;QACb,WAAW,CAAC,wBAAwB,GAAG,SAAS,CAAC;QACjD,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAC7C,CAAC;IAED,MAAM,IAAI,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,IAAI,EAAE,CAAC;QAC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AE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["import { compileNodes } from './compileNodes';\nimport type { PithyNode } from '@pithyjs/compiler';\nimport { pithyGlobals, type PithyComponentContext } from '../types/globals';\nimport type { ChildFactory } from '../runtime/bindings/types';\nimport {\n declareSlotNames,\n outerSlotMap,\n type SlotMap,\n} from './contentProjection';\nimport { withSlotBoundary } from './binds/bindErrorBoundary';\n\ntype SlotRenderer = NonNullable<ReturnType<SlotMap['get']>>;\n\n/**\n * If the registry renderer has set `globalThis.__pithyProjectedChildren` (a\n * `DocumentFragment` of already-rendered slot children), returns and clears it —\n * single-consume, so the first caller wins. This delivers construction-time\n * children on the registry path. The registry path has no AST fallback, so a\n * second `renderChildren()`/`captureChildren()` call returns an empty fragment.\n *\n * A build-compiled parent's default slot is rendered afresh on every call.\n *\n * Otherwise compiles child AST nodes from the current component context through\n * the full pipeline (structural + non-structural directives). This enables\n * nested components inside projected content — unlike `<slot>`, which inserts\n * DOM after `bindComponentTags` has already run.\n *\n * Use inside component functions (Stack, Grid, etc.) that need to compile\n * their children without named slots or fallback content.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"renderChildren\",\"stability\":\"stable\",\"signature\":\"() => { el: DocumentFragment; destroy: () => void }\"} */\nexport function renderChildren(): {\n el: DocumentFragment;\n destroy: () => void;\n} {\n const globalScope = pithyGlobals();\n const componentCtx = globalScope.__pithyComponentContext;\n // Children rendered here fill no named slot.\n if (import.meta.env?.DEV) declareSlotNames(componentCtx?.__slotMap, []);\n const injected = globalScope.__pithyProjectedChildren;\n if (injected) {\n globalScope.__pithyProjectedChildren = undefined;\n return { el: injected, destroy: () => {} };\n }\n\n const slot = buildDefaultSlot(componentCtx);\n if (slot) {\n const disposers: (() => void)[] = [];\n const el = slot(disposers);\n return {\n el,\n destroy: () => {\n for (let i = disposers.length - 1; i >= 0; i--) disposers[i]();\n disposers.length = 0;\n },\n };\n }\n\n // A parent composing atoms by direct call after captureChildren() cleared its\n // context is still mid-render (`rendering` truthy) — not the misuse this guards\n // against, so a consumed context alone must not trigger the warning.\n const rendering = pithyGlobals().__pithyRenderingComponent;\n if (import.meta.env?.DEV && !componentCtx && !rendering) {\n console.warn('[renderChildren] Called outside component render context');\n }\n\n const childAstNodes: PithyNode[] = componentCtx?.__childAstNodes ?? [];\n\n // Strip internal __ properties, keep parent scope (includes components, signals, etc.)\n const parentCtx: Record<string, unknown> = componentCtx\n ? Object.fromEntries(\n Object.entries(componentCtx).filter(\n ([k]) => !k.startsWith('__') || k === '__pithyRowLocals'\n )\n )\n : {};\n // What a `<slot>` among the children receives.\n const outer = outerSlotMap(componentCtx?.__slotMap);\n if (outer) parentCtx.__slotMap = outer;\n\n return withSlotBoundary(undefined, componentCtx?.__slotHost, () =>\n compileNodes(childAstNodes, parentCtx)\n );\n}\n\n/**\n * Captures projected children and clears the component context so\n * inner component calls (e.g. `Heading()`, `Text()`) don't consume\n * the outer component's children.\n *\n * After capture, the current component's context on `globalThis` is\n * reset to the value of `__parentComponentContext` if present, or\n * otherwise to `undefined`. In the current core implementation,\n * `__parentComponentContext` is not set by the runtime, so this\n * effectively clears the active component context to prevent child\n * leakage into inner component calls.\n *\n * **Important invariant:** This function must be called exactly once per\n * component, before any inner component function calls. It consumes the\n * current context's children — a second call would return an empty fragment.\n * After this call, the caller must not rely on reading its own context\n * properties from `globalThis.__pithyComponentContext`.\n *\n * For 3+ levels of nesting (e.g., section A → section B → atoms), each\n * level should call `captureChildren()` independently. Any multi-level\n * parent restoration depends on `__parentComponentContext` being managed\n * by external tooling; the core library only performs a best-effort reset\n * from that property when present.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"captureChildren\",\"stability\":\"stable\",\"signature\":\"() => { el: DocumentFragment; destroy: () => void }\"} */\nexport function captureChildren(): {\n el: DocumentFragment;\n destroy: () => void;\n} {\n const g = pithyGlobals();\n const prevCtx = g.__pithyComponentContext;\n const result = renderChildren();\n // Clear context so inner component calls start fresh.\n // If there was a parent context, it will be restored by the parent's\n // own render cycle — we only need to prevent child leakage here.\n g.__pithyComponentContext = prevCtx?.__parentComponentContext ?? undefined;\n return result;\n}\n\n/** Default-slot renderer of a build-compiled parent; it has no AST. */\nfunction buildDefaultSlot(ctx: PithyComponentContext | undefined) {\n return ctx && !ctx.__childAstNodes && !ctx.__childFactory\n ? ctx.__slotMap?.get('')\n : undefined;\n}\n\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"ChildPayload\",\"stability\":\"experimental\",\"signature\":\"interface ChildPayload\"} */\nexport interface ChildPayload {\n context: PithyComponentContext | undefined;\n factory?: ChildFactory;\n astNodes?: PithyNode[];\n projected?: DocumentFragment;\n /** A build's default slot, rendered by `renderChildren()` on each call. */\n slot?: SlotRenderer;\n /** What a `<slot>` among `astNodes` receives. */\n outer?: SlotMap;\n /** A build passed content for a named slot, which `slot` does not carry. */\n named: boolean;\n}\n\n/**\n * Reads the children addressed to the component being rendered, without\n * consuming them. `factory` and `astNodes` are mutually exclusive: an AOT child\n * factory wins, because a JIT parent's AST can reach an AOT component's context\n * through `mergeContexts`, never the reverse.\n */\n/** @codexApi {\"parent\":\"pithy.runtime.compile-nodes\",\"name\":\"readChildPayload\",\"stability\":\"experimental\",\"signature\":\"() => ChildPayload\"} */\nexport function readChildPayload(): ChildPayload {\n const g = pithyGlobals();\n const context = g.__pithyComponentContext;\n const factory = context?.__childFactory;\n const ast = context?.__childAstNodes;\n return {\n context,\n factory,\n astNodes: !factory && ast && ast.length > 0 ? ast : undefined,\n projected: g.__pithyProjectedChildren,\n slot: buildDefaultSlot(context),\n outer: outerSlotMap(context?.__slotMap),\n named: [...(context?.__slotMap?.keys() ?? [])].some(name => name !== ''),\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrCrashes.d.ts","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAKF,OAAO,
|
|
1
|
+
{"version":3,"file":"ssrCrashes.d.ts","sourceRoot":"","sources":["../../src/compile/ssrCrashes.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAKF,OAAO,EASL,KAAK,YAAY,EAClB,MAAM,2BAA2B,CAAC;AAEnC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,EAAE,EAAE,OAAO,CAAC;IACZ,kDAAkD;IAClD,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,KAAK,EAAE,KAAK,CAAC;CACd;AAwBD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,+IAA+I;AAC/I,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAErD;AA4BD;;;GAGG;AACH,oIAAoI;AACpI,wBAAgB,qBAAqB,IAAI,IAAI,CAK5C;AAED;;;GAGG;AACH,uIAAuI;AACvI,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,IAAI,CAI7C;AAQD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,2JAA2J;AAC3J,wBAAgB,gCAAgC,IAAI,cAAc,EAAE,CAMnE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,0OAA0O;AAC1O,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,OAAO,EACX,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,GAAG,IAAI,EAC7B,WAAW,GAAE,WAAgB,GAC5B,OAAO,CAGT;AAED,sGAAsG;AACtG,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;AAkGD,4GAA4G;AAC5G,yIAAyI;AACzI,wBAAg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