@xmachines/json-render-svelte 0.21.0-xm.1 → 0.21.0-xm.2
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 +34 -0
- package/dist/ElementRenderer.svelte +48 -5
- package/dist/ElementRenderer.svelte.d.ts.map +1 -1
- package/dist/RendererWithProvider.test.svelte +4 -2
- package/dist/RendererWithProvider.test.svelte.d.ts +2 -1
- package/dist/RendererWithProvider.test.svelte.d.ts.map +1 -1
- package/dist/TestCountingFooter.svelte +10 -0
- package/dist/TestCountingFooter.svelte.d.ts +23 -0
- package/dist/TestCountingFooter.svelte.d.ts.map +1 -0
- package/dist/TestLayout.svelte +14 -0
- package/dist/TestLayout.svelte.d.ts +7 -0
- package/dist/TestLayout.svelte.d.ts.map +1 -0
- package/dist/TestLazyLayout.svelte +11 -0
- package/dist/TestLazyLayout.svelte.d.ts +5 -0
- package/dist/TestLazyLayout.svelte.d.ts.map +1 -0
- package/dist/TestRawText.svelte +7 -0
- package/dist/TestRawText.svelte.d.ts +7 -0
- package/dist/TestRawText.svelte.d.ts.map +1 -0
- package/dist/catalog-types.d.ts +8 -0
- package/dist/catalog-types.d.ts.map +1 -1
- package/dist/named-slots.test.js +196 -0
- package/dist/renderer.d.ts +10 -2
- package/dist/renderer.d.ts.map +1 -1
- package/dist/renderer.js +12 -2
- package/dist/schema.d.ts +5 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -76,6 +76,40 @@ export const { registry } = defineRegistry(catalog, {
|
|
|
76
76
|
</StateProvider>
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
## Named Slots
|
|
80
|
+
|
|
81
|
+
Use `children` for the default slot. Use the element's top-level `slots` object for the other slot names that the catalog declares:
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"type": "Layout",
|
|
86
|
+
"props": {},
|
|
87
|
+
"children": ["main"],
|
|
88
|
+
"slots": {
|
|
89
|
+
"header": ["heading"],
|
|
90
|
+
"footer": ["actions"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Svelte 5 cannot bind a slot name to a snippet at run time. A component therefore receives one `renderSlot` snippet that takes the slot name, and `slotNames`, which lists the named slots that the element fills:
|
|
96
|
+
|
|
97
|
+
```svelte
|
|
98
|
+
<script lang="ts">
|
|
99
|
+
import type { BaseComponentProps } from "@xmachines/json-render-svelte";
|
|
100
|
+
|
|
101
|
+
let { children, renderSlot, slotNames }: BaseComponentProps = $props();
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<header>{@render renderSlot?.("header")}</header>
|
|
105
|
+
<main>{@render children?.()}</main>
|
|
106
|
+
{#if slotNames?.includes("footer")}
|
|
107
|
+
<footer>{@render renderSlot?.("footer")}</footer>
|
|
108
|
+
{/if}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
A slot renders only when the component calls `renderSlot` for it. Keep default content in `children`: the renderer warns about a `default` entry in `slots` and ignores it. It also warns about a slot name that the catalog does not declare, and it still renders that slot.
|
|
112
|
+
|
|
79
113
|
## Providers
|
|
80
114
|
|
|
81
115
|
| Provider | Purpose |
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
evaluateVisibility,
|
|
8
8
|
isDevtoolsActive,
|
|
9
9
|
subscribeDevtoolsActive,
|
|
10
|
+
warnElementSlots,
|
|
10
11
|
type PropResolutionContext,
|
|
11
12
|
splitRepeatVisibility,
|
|
12
13
|
} from "@xmachines/json-render-core";
|
|
13
|
-
import { onDestroy } from "svelte";
|
|
14
|
+
import { onDestroy, untrack } from "svelte";
|
|
14
15
|
import type { ComponentRegistry, ComponentRenderer } from "./renderer.js";
|
|
15
16
|
import type { EventHandle } from "./catalog-types.js";
|
|
16
17
|
import { getStateContext } from "./contexts/StateProvider.svelte";
|
|
@@ -98,6 +99,26 @@
|
|
|
98
99
|
// Get the component renderer
|
|
99
100
|
let Component = $derived(registry[resolvedElement.type] ?? fallback);
|
|
100
101
|
|
|
102
|
+
// Named slots. `slots.default` is left out: the warning below names
|
|
103
|
+
// `children` as its spelling. The slot children render at the scope of the
|
|
104
|
+
// owner, one time, and not once for each item of the owner's own repeat.
|
|
105
|
+
// Read the element, not the resolved element: a state change resolves a new
|
|
106
|
+
// element object, and the names must keep their reference. The "Missing
|
|
107
|
+
// element" warnings below read the element type untracked: a new element
|
|
108
|
+
// object with the same contents, as a new spec gives, must not repeat them.
|
|
109
|
+
let slotNames = $derived.by(() => {
|
|
110
|
+
const names = Object.keys(element.slots ?? {}).filter(
|
|
111
|
+
(slotName) => slotName !== "default",
|
|
112
|
+
);
|
|
113
|
+
return names.length > 0 ? names : undefined;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Read the element, not the resolved element: a state change that resolves
|
|
117
|
+
// new props gives a new resolved element, and the warnings must not repeat.
|
|
118
|
+
$effect.pre(() => {
|
|
119
|
+
warnElementSlots(registry, element.type, element.slots);
|
|
120
|
+
});
|
|
121
|
+
|
|
101
122
|
// Create emit function
|
|
102
123
|
function emit(eventName: string): void {
|
|
103
124
|
const binding = element.on?.[eventName];
|
|
@@ -134,6 +155,24 @@
|
|
|
134
155
|
}
|
|
135
156
|
</script>
|
|
136
157
|
|
|
158
|
+
{#snippet renderSlot(slotName: string)}
|
|
159
|
+
{#each resolvedElement.slots?.[slotName] ?? [] as childKey (childKey)}
|
|
160
|
+
{#if spec.elements[childKey]}
|
|
161
|
+
<Self
|
|
162
|
+
element={spec.elements[childKey]}
|
|
163
|
+
elementKey={childKey}
|
|
164
|
+
{spec}
|
|
165
|
+
{registry}
|
|
166
|
+
{loading}
|
|
167
|
+
{fallback} />
|
|
168
|
+
{:else if !loading}
|
|
169
|
+
{console.warn(
|
|
170
|
+
`[json-render] Missing element "${childKey}" referenced in slot "${slotName}" of "${untrack(() => element.type)}". This element will not render.`,
|
|
171
|
+
)}
|
|
172
|
+
{/if}
|
|
173
|
+
{/each}
|
|
174
|
+
{/snippet}
|
|
175
|
+
|
|
137
176
|
{#if isVisible && Component}
|
|
138
177
|
<svelte:boundary
|
|
139
178
|
onerror={(error) => {
|
|
@@ -158,7 +197,9 @@
|
|
|
158
197
|
bindings={elementBindings}
|
|
159
198
|
{loading}
|
|
160
199
|
{on}
|
|
161
|
-
{emit}
|
|
200
|
+
{emit}
|
|
201
|
+
renderSlot={slotNames ? renderSlot : undefined}
|
|
202
|
+
{slotNames}>
|
|
162
203
|
{#if resolvedElement.repeat}
|
|
163
204
|
<RepeatChildren
|
|
164
205
|
element={resolvedElement}
|
|
@@ -179,7 +220,7 @@
|
|
|
179
220
|
{fallback} />
|
|
180
221
|
{:else if !loading}
|
|
181
222
|
{console.warn(
|
|
182
|
-
`[json-render] Missing element "${childKey}" referenced as child of "${
|
|
223
|
+
`[json-render] Missing element "${childKey}" referenced as child of "${untrack(() => element.type)}". This element will not render.`,
|
|
183
224
|
)}
|
|
184
225
|
{/if}
|
|
185
226
|
{/each}
|
|
@@ -192,7 +233,9 @@
|
|
|
192
233
|
bindings={elementBindings}
|
|
193
234
|
{loading}
|
|
194
235
|
{on}
|
|
195
|
-
{emit}
|
|
236
|
+
{emit}
|
|
237
|
+
renderSlot={slotNames ? renderSlot : undefined}
|
|
238
|
+
{slotNames}>
|
|
196
239
|
{#if resolvedElement.repeat}
|
|
197
240
|
<RepeatChildren
|
|
198
241
|
element={resolvedElement}
|
|
@@ -213,7 +256,7 @@
|
|
|
213
256
|
{fallback} />
|
|
214
257
|
{:else if !loading}
|
|
215
258
|
{console.warn(
|
|
216
|
-
`[json-render] Missing element "${childKey}" referenced as child of "${
|
|
259
|
+
`[json-render] Missing element "${childKey}" referenced as child of "${untrack(() => element.type)}". This element will not render.`,
|
|
217
260
|
)}
|
|
218
261
|
{/if}
|
|
219
262
|
{/each}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElementRenderer.svelte.d.ts","sourceRoot":"","sources":["../src/ElementRenderer.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAsB,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ElementRenderer.svelte.d.ts","sourceRoot":"","sources":["../src/ElementRenderer.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAsB,IAAI,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAa7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAWxE,UAAU,KAAK;IACb,OAAO,EAAE,SAAS,CAAC;IACnB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAiNH,QAAA,MAAM,eAAe,2CAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Spec, ActionHandler } from "@xmachines/json-render-core";
|
|
2
|
+
import type { Spec, ActionHandler, StateStore } from "@xmachines/json-render-core";
|
|
3
3
|
import type { ComponentRegistry, ComponentRenderer } from "./renderer.js";
|
|
4
4
|
import StateProvider from "./contexts/StateProvider.svelte";
|
|
5
5
|
import VisibilityProvider from "./contexts/VisibilityProvider.svelte";
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
fallback?: ComponentRenderer;
|
|
15
15
|
initialState?: Record<string, unknown>;
|
|
16
16
|
handlers?: Record<string, ActionHandler>;
|
|
17
|
+
store?: StateStore;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
let {
|
|
@@ -23,10 +24,11 @@
|
|
|
23
24
|
fallback,
|
|
24
25
|
initialState = {},
|
|
25
26
|
handlers = {},
|
|
27
|
+
store,
|
|
26
28
|
}: Props = $props();
|
|
27
29
|
</script>
|
|
28
30
|
|
|
29
|
-
<StateProvider {initialState}>
|
|
31
|
+
<StateProvider {store} {initialState}>
|
|
30
32
|
<VisibilityProvider>
|
|
31
33
|
<ValidationProvider>
|
|
32
34
|
<ActionProvider {handlers}>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Spec, ActionHandler } from "@xmachines/json-render-core";
|
|
1
|
+
import type { Spec, ActionHandler, StateStore } from "@xmachines/json-render-core";
|
|
2
2
|
import type { ComponentRegistry, ComponentRenderer } from "./renderer.js";
|
|
3
3
|
interface Props {
|
|
4
4
|
spec: Spec | null;
|
|
@@ -7,6 +7,7 @@ interface Props {
|
|
|
7
7
|
fallback?: ComponentRenderer;
|
|
8
8
|
initialState?: Record<string, unknown>;
|
|
9
9
|
handlers?: Record<string, ActionHandler>;
|
|
10
|
+
store?: StateStore;
|
|
10
11
|
}
|
|
11
12
|
declare const RendererWithProvider: import("svelte").Component<Props, {}, "">;
|
|
12
13
|
type RendererWithProvider = ReturnType<typeof RendererWithProvider>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendererWithProvider.test.svelte.d.ts","sourceRoot":"","sources":["../src/RendererWithProvider.test.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"RendererWithProvider.test.svelte.d.ts","sourceRoot":"","sources":["../src/RendererWithProvider.test.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAQxE,UAAU,KAAK;IACb,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAkCH,QAAA,MAAM,oBAAoB,2CAAwC,CAAC;AACnE,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACpE,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** How many times the renderer created this component. */
|
|
2
|
+
export declare const footerMounts: {
|
|
3
|
+
count: number;
|
|
4
|
+
};
|
|
5
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
6
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
7
|
+
$$bindings?: Bindings;
|
|
8
|
+
} & Exports;
|
|
9
|
+
(internal: unknown, props: {
|
|
10
|
+
$$events?: Events;
|
|
11
|
+
$$slots?: Slots;
|
|
12
|
+
}): Exports & {
|
|
13
|
+
$set?: any;
|
|
14
|
+
$on?: any;
|
|
15
|
+
};
|
|
16
|
+
z_$$bindings?: Bindings;
|
|
17
|
+
}
|
|
18
|
+
declare const TestCountingFooter: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
}, {}, {}, string>;
|
|
21
|
+
type TestCountingFooter = InstanceType<typeof TestCountingFooter>;
|
|
22
|
+
export default TestCountingFooter;
|
|
23
|
+
//# sourceMappingURL=TestCountingFooter.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestCountingFooter.svelte.d.ts","sourceRoot":"","sources":["../src/TestCountingFooter.svelte.ts"],"names":[],"mappings":"AAGE,0DAA0D;AAC1D,eAAO,MAAM,YAAY;;CAAe,CAAC;AAY3C,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IACtG,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,kBAAkB;;kBAA+E,CAAC;AACtF,KAAK,kBAAkB,GAAG,YAAY,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { BaseComponentProps } from "./catalog-types.js";
|
|
3
|
+
|
|
4
|
+
interface Props extends BaseComponentProps<Record<string, never>> {}
|
|
5
|
+
|
|
6
|
+
let { children, renderSlot, slotNames }: Props = $props();
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<section class="test-layout" data-slot-names={slotNames?.join(",") ?? ""}>
|
|
10
|
+
<header data-testid="header-slot">{@render renderSlot?.("header")}</header>
|
|
11
|
+
<main data-testid="default-slot">{@render children?.()}</main>
|
|
12
|
+
<footer data-testid="footer-slot">{@render renderSlot?.("footer")}</footer>
|
|
13
|
+
<aside data-testid="sidebar-slot">{@render renderSlot?.("sidebar")}</aside>
|
|
14
|
+
</section>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseComponentProps } from "./catalog-types.js";
|
|
2
|
+
interface Props extends BaseComponentProps<Record<string, never>> {
|
|
3
|
+
}
|
|
4
|
+
declare const TestLayout: import("svelte").Component<Props, {}, "">;
|
|
5
|
+
type TestLayout = ReturnType<typeof TestLayout>;
|
|
6
|
+
export default TestLayout;
|
|
7
|
+
//# sourceMappingURL=TestLayout.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestLayout.svelte.d.ts","sourceRoot":"","sources":["../src/TestLayout.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAG3D,UAAU,KAAM,SAAQ,kBAAkB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;CAAG;AAiBtE,QAAA,MAAM,UAAU,2CAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ComponentRenderProps } from "./renderer.js";
|
|
3
|
+
|
|
4
|
+
let { children, renderSlot, slotNames }: ComponentRenderProps = $props();
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<section>
|
|
8
|
+
<header>{@render renderSlot?.("header")}</header>
|
|
9
|
+
<main>{@render children?.()}</main>
|
|
10
|
+
{#if slotNames?.includes("footer")}<i>has-footer</i>{/if}
|
|
11
|
+
</section>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ComponentRenderProps } from "./renderer.js";
|
|
2
|
+
declare const TestLazyLayout: import("svelte").Component<ComponentRenderProps<Record<string, unknown>>, {}, "">;
|
|
3
|
+
type TestLazyLayout = ReturnType<typeof TestLazyLayout>;
|
|
4
|
+
export default TestLazyLayout;
|
|
5
|
+
//# sourceMappingURL=TestLazyLayout.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestLazyLayout.svelte.d.ts","sourceRoot":"","sources":["../src/TestLazyLayout.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAgB1D,QAAA,MAAM,cAAc,mFAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComponentRenderProps } from "./renderer.js";
|
|
2
|
+
declare const TestRawText: import("svelte").Component<ComponentRenderProps<{
|
|
3
|
+
text?: string;
|
|
4
|
+
}>, {}, "">;
|
|
5
|
+
type TestRawText = ReturnType<typeof TestRawText>;
|
|
6
|
+
export default TestRawText;
|
|
7
|
+
//# sourceMappingURL=TestRawText.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestRawText.svelte.d.ts","sourceRoot":"","sources":["../src/TestRawText.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAY1D,QAAA,MAAM,WAAW;WAD0C,MAAM;WACR,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
package/dist/catalog-types.d.ts
CHANGED
|
@@ -24,6 +24,14 @@ export interface EventHandle {
|
|
|
24
24
|
export interface BaseComponentProps<P = Record<string, unknown>> {
|
|
25
25
|
props: P;
|
|
26
26
|
children?: Snippet;
|
|
27
|
+
/**
|
|
28
|
+
* Renders the children of one named slot of the element (`element.slots`):
|
|
29
|
+
* `{@render renderSlot?.("header")}`. Present only when the element fills
|
|
30
|
+
* at least one named slot. A slot renders only when the component calls it.
|
|
31
|
+
*/
|
|
32
|
+
renderSlot?: Snippet<[slotName: string]>;
|
|
33
|
+
/** The names of the named slots that the element fills, in spec order. */
|
|
34
|
+
slotNames?: string[];
|
|
27
35
|
/** Simple event emitter (shorthand). Fires the event and returns void. */
|
|
28
36
|
emit: (event: string) => void;
|
|
29
37
|
/** Get an event handle with metadata. Use when you need shouldPreventDefault or bound checks. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog-types.d.ts","sourceRoot":"","sources":["../src/catalog-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EACV,OAAO,EACP,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,UAAU,EAAE,CAAC;AAM3B;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CACrB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAChE,IAAI,CAAC;AAMV;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mDAAmD;IACnD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,iDAAiD;IACjD,KAAK,EAAE,OAAO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CAAC,EAAE,CAAC,CAAC;CACpD,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named slots — parity with the react renderer (upstream #320) and the vue
|
|
3
|
+
* renderer (upstream #323).
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the named-slot cases of packages/vue/src/renderer.test.ts. Svelte 5
|
|
6
|
+
* cannot bind a slot name to a snippet at run time, so a component receives
|
|
7
|
+
* one `renderSlot` snippet that takes the slot name, and `slotNames`.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, describe, it, expect, vi } from "vitest";
|
|
10
|
+
import { flushSync } from "svelte";
|
|
11
|
+
import { render, cleanup } from "@testing-library/svelte";
|
|
12
|
+
import { createStateStore, defineCatalog } from "@xmachines/json-render-core";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import RendererWithProvider from "./RendererWithProvider.test.svelte";
|
|
15
|
+
import TestLayout from "./TestLayout.svelte";
|
|
16
|
+
import TestLazyLayout from "./TestLazyLayout.svelte";
|
|
17
|
+
import TestCountingFooter, { footerMounts } from "./TestCountingFooter.svelte";
|
|
18
|
+
import TestRawText from "./TestRawText.svelte";
|
|
19
|
+
import TestText from "./TestText.svelte";
|
|
20
|
+
import { createRenderer, defineRegistry } from "./renderer.js";
|
|
21
|
+
import { schema } from "./schema.js";
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
cleanup();
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
const catalog = defineCatalog(schema, {
|
|
27
|
+
components: {
|
|
28
|
+
Layout: {
|
|
29
|
+
props: z.object({}),
|
|
30
|
+
slots: ["default", "header", "footer"],
|
|
31
|
+
},
|
|
32
|
+
Text: { props: z.object({ text: z.string() }), slots: [] },
|
|
33
|
+
},
|
|
34
|
+
actions: {},
|
|
35
|
+
});
|
|
36
|
+
const { registry } = defineRegistry(catalog, {
|
|
37
|
+
components: { Layout: TestLayout, Text: TestText },
|
|
38
|
+
});
|
|
39
|
+
function layoutSpec(slots) {
|
|
40
|
+
return {
|
|
41
|
+
root: "layout",
|
|
42
|
+
elements: {
|
|
43
|
+
layout: { type: "Layout", props: {}, children: ["main"], slots },
|
|
44
|
+
main: { type: "Text", props: { text: "Main" } },
|
|
45
|
+
header: { type: "Text", props: { text: "Header" } },
|
|
46
|
+
footer: { type: "Text", props: { text: "Footer" } },
|
|
47
|
+
other: { type: "Text", props: { text: "Other" } },
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function mount(spec, reg = registry, loading = false) {
|
|
52
|
+
return render(RendererWithProvider, {
|
|
53
|
+
props: { spec, registry: reg, loading, initialState: spec.state ?? {} },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
// Svelte keeps the whitespace between the elements of a template.
|
|
57
|
+
const text = (node) => (node?.textContent ?? "").replace(/\s+/g, "");
|
|
58
|
+
const slotText = (container, slot) => text(container.querySelector(`[data-testid="${slot}-slot"]`));
|
|
59
|
+
describe("named slots", () => {
|
|
60
|
+
it("renders named slots through defineRegistry", () => {
|
|
61
|
+
const { container } = mount(layoutSpec({ header: ["header"], footer: ["footer"] }));
|
|
62
|
+
expect(slotText(container, "header")).toBe("Header");
|
|
63
|
+
expect(slotText(container, "default")).toBe("Main");
|
|
64
|
+
expect(slotText(container, "footer")).toBe("Footer");
|
|
65
|
+
expect(container.querySelector(".test-layout")?.getAttribute("data-slot-names")).toBe("header,footer");
|
|
66
|
+
});
|
|
67
|
+
it("advertises named slots in the Svelte catalog prompt without default", () => {
|
|
68
|
+
const prompt = catalog.prompt();
|
|
69
|
+
expect(prompt).toContain("slots: header, footer");
|
|
70
|
+
expect(prompt).not.toContain("slots: default");
|
|
71
|
+
});
|
|
72
|
+
it("warns and ignores slots.default while preserving children", () => {
|
|
73
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
74
|
+
const { container } = mount(layoutSpec({ default: ["other"] }));
|
|
75
|
+
expect(text(container)).toBe("Main");
|
|
76
|
+
expect(container.querySelector(".test-layout")?.getAttribute("data-slot-names")).toBe("");
|
|
77
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining("slots.default"));
|
|
78
|
+
});
|
|
79
|
+
it("warns but renders an undeclared named slot", () => {
|
|
80
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
81
|
+
const { container } = mount(layoutSpec({ sidebar: ["other"] }));
|
|
82
|
+
expect(slotText(container, "sidebar")).toBe("Other");
|
|
83
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('Unknown slot "sidebar"'));
|
|
84
|
+
});
|
|
85
|
+
it("delivers raw registry named slots lazily", () => {
|
|
86
|
+
footerMounts.count = 0;
|
|
87
|
+
const spec = layoutSpec({ header: ["header"], footer: ["footer"] });
|
|
88
|
+
spec.elements.footer = { type: "Footer", props: {} };
|
|
89
|
+
const { container } = mount(spec, {
|
|
90
|
+
Layout: TestLazyLayout,
|
|
91
|
+
Text: TestRawText,
|
|
92
|
+
Footer: TestCountingFooter,
|
|
93
|
+
});
|
|
94
|
+
expect(text(container)).toBe("HeaderMainhas-footer");
|
|
95
|
+
expect(footerMounts.count).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
it("suppresses missing named slot warnings while loading", () => {
|
|
98
|
+
const spec = layoutSpec({ header: ["missing"] });
|
|
99
|
+
const reg = { Layout: TestLazyLayout, Text: TestRawText };
|
|
100
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
101
|
+
const loading = mount(spec, reg, true);
|
|
102
|
+
expect(warn).not.toHaveBeenCalled();
|
|
103
|
+
loading.unmount();
|
|
104
|
+
mount(spec, reg, false);
|
|
105
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('in slot "header"'));
|
|
106
|
+
});
|
|
107
|
+
it("warns about a missing slot child one time across state changes", () => {
|
|
108
|
+
const spec = {
|
|
109
|
+
root: "layout",
|
|
110
|
+
elements: {
|
|
111
|
+
layout: {
|
|
112
|
+
type: "Layout",
|
|
113
|
+
props: { title: { $state: "/title" } },
|
|
114
|
+
children: [],
|
|
115
|
+
slots: { header: ["missing"] },
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
const store = createStateStore({ title: "One" });
|
|
120
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
121
|
+
render(RendererWithProvider, {
|
|
122
|
+
props: { spec, registry: { Layout: TestLayout }, store },
|
|
123
|
+
});
|
|
124
|
+
store.set("/title", "Two");
|
|
125
|
+
flushSync();
|
|
126
|
+
store.set("/title", "Three");
|
|
127
|
+
flushSync();
|
|
128
|
+
expect(warn.mock.calls.filter(([message]) => String(message).includes('in slot "header"'))).toHaveLength(1);
|
|
129
|
+
});
|
|
130
|
+
it("warns about a missing slot child one time across new spec objects", async () => {
|
|
131
|
+
// A composed view gives a new spec object with the same contents.
|
|
132
|
+
const make = () => ({
|
|
133
|
+
root: "layout",
|
|
134
|
+
elements: {
|
|
135
|
+
layout: {
|
|
136
|
+
type: "Layout",
|
|
137
|
+
props: {},
|
|
138
|
+
children: [],
|
|
139
|
+
slots: { header: ["missing"] },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
144
|
+
const view = render(RendererWithProvider, {
|
|
145
|
+
props: { spec: make(), registry: { Layout: TestLayout } },
|
|
146
|
+
});
|
|
147
|
+
await view.rerender({ spec: make(), registry: { Layout: TestLayout } });
|
|
148
|
+
flushSync();
|
|
149
|
+
await view.rerender({ spec: make(), registry: { Layout: TestLayout } });
|
|
150
|
+
flushSync();
|
|
151
|
+
expect(warn.mock.calls.filter(([message]) => String(message).includes('in slot "header"'))).toHaveLength(1);
|
|
152
|
+
});
|
|
153
|
+
it("renders owner named slots once outside the owner repeat scope", () => {
|
|
154
|
+
const spec = {
|
|
155
|
+
root: "layout",
|
|
156
|
+
state: { items: [{ name: "A" }, { name: "B" }] },
|
|
157
|
+
elements: {
|
|
158
|
+
layout: {
|
|
159
|
+
type: "Layout",
|
|
160
|
+
props: {},
|
|
161
|
+
repeat: { statePath: "/items" },
|
|
162
|
+
children: ["row"],
|
|
163
|
+
slots: { header: ["header"] },
|
|
164
|
+
},
|
|
165
|
+
row: { type: "Text", props: { text: { $item: "name" } } },
|
|
166
|
+
header: { type: "Text", props: { text: "Header" } },
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
const { container } = mount(spec, {
|
|
170
|
+
Layout: TestLazyLayout,
|
|
171
|
+
Text: TestRawText,
|
|
172
|
+
});
|
|
173
|
+
expect(text(container)).toBe("HeaderAB");
|
|
174
|
+
});
|
|
175
|
+
it("follows a change of the slot keys in the spec", async () => {
|
|
176
|
+
const { container, rerender } = mount(layoutSpec({ header: ["header"] }));
|
|
177
|
+
expect(slotText(container, "header")).toBe("Header");
|
|
178
|
+
await rerender({ spec: layoutSpec({ header: ["other"] }) });
|
|
179
|
+
expect(slotText(container, "header")).toBe("Other");
|
|
180
|
+
});
|
|
181
|
+
it("renders and validates named slots through createRenderer", () => {
|
|
182
|
+
const CatalogRenderer = createRenderer(catalog, {
|
|
183
|
+
Layout: TestLazyLayout,
|
|
184
|
+
Text: TestRawText,
|
|
185
|
+
});
|
|
186
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
187
|
+
const { container } = render(CatalogRenderer, {
|
|
188
|
+
props: {
|
|
189
|
+
spec: layoutSpec({ header: ["header"], sidebar: ["other"] }),
|
|
190
|
+
onRenderError: () => { },
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
expect(text(container)).toBe("HeaderMain");
|
|
194
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('Unknown slot "sidebar"'));
|
|
195
|
+
});
|
|
196
|
+
});
|
package/dist/renderer.d.ts
CHANGED
|
@@ -10,6 +10,14 @@ export interface ComponentRenderProps<P = Record<string, unknown>> {
|
|
|
10
10
|
element: UIElement<string, P>;
|
|
11
11
|
/** Rendered children snippet */
|
|
12
12
|
children?: Snippet;
|
|
13
|
+
/**
|
|
14
|
+
* Renders the children of one named slot of the element (`element.slots`):
|
|
15
|
+
* `{@render renderSlot?.("header")}`. Present only when the element fills
|
|
16
|
+
* at least one named slot. A slot renders only when the component calls it.
|
|
17
|
+
*/
|
|
18
|
+
renderSlot?: Snippet<[slotName: string]>;
|
|
19
|
+
/** The names of the named slots that the element fills, in spec order. */
|
|
20
|
+
slotNames?: string[];
|
|
13
21
|
/** Emit a named event. The renderer resolves the event to action binding(s) from the element's `on` field. */
|
|
14
22
|
emit: (event: string) => void;
|
|
15
23
|
/** Get an event handle with metadata */
|
|
@@ -75,7 +83,7 @@ export interface DefineRegistryResult {
|
|
|
75
83
|
* });
|
|
76
84
|
* ```
|
|
77
85
|
*/
|
|
78
|
-
export declare function defineRegistry<C extends Catalog, TComponents extends Record<string, Component<BaseComponentProps<any>>>>(
|
|
86
|
+
export declare function defineRegistry<C extends Catalog, TComponents extends Record<string, Component<BaseComponentProps<any>>>>(catalog: C, options: {
|
|
79
87
|
/** Svelte components that accept BaseComponentProps */
|
|
80
88
|
components?: TComponents;
|
|
81
89
|
/** Action handlers */
|
|
@@ -130,5 +138,5 @@ export declare function createRenderer<TDef extends SchemaDefinition, TCatalog e
|
|
|
130
138
|
components: Record<string, {
|
|
131
139
|
props: unknown;
|
|
132
140
|
}>;
|
|
133
|
-
}>(
|
|
141
|
+
}>(catalog: Catalog<TDef, TCatalog>, components: ComponentMap<TCatalog["components"]>): Component<CreateRendererProps>;
|
|
134
142
|
//# sourceMappingURL=renderer.d.ts.map
|
package/dist/renderer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,IAAI,EACJ,UAAU,EACV,SAAS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,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,EAChC,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAC/C,SAAS,CAAC,mBAAmB,CAAC,CA+ChC"}
|
package/dist/renderer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { copySlotMetadata, setCatalogSlotMetadata } from "@xmachines/json-render-core";
|
|
1
2
|
import CatalogRenderer from "./CatalogRenderer.svelte";
|
|
2
3
|
/**
|
|
3
4
|
* Create a registry from a catalog with Svelte components and/or actions.
|
|
@@ -24,7 +25,7 @@ import CatalogRenderer from "./CatalogRenderer.svelte";
|
|
|
24
25
|
* });
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
|
-
export function defineRegistry(
|
|
28
|
+
export function defineRegistry(catalog, options) {
|
|
28
29
|
const registry = {};
|
|
29
30
|
if (options.components) {
|
|
30
31
|
for (const [name, componentFn] of Object.entries(options.components)) {
|
|
@@ -35,6 +36,12 @@ export function defineRegistry(_catalog, options) {
|
|
|
35
36
|
get children() {
|
|
36
37
|
return props.children;
|
|
37
38
|
},
|
|
39
|
+
get renderSlot() {
|
|
40
|
+
return props.renderSlot;
|
|
41
|
+
},
|
|
42
|
+
get slotNames() {
|
|
43
|
+
return props.slotNames;
|
|
44
|
+
},
|
|
38
45
|
get emit() {
|
|
39
46
|
return props.emit;
|
|
40
47
|
},
|
|
@@ -50,6 +57,7 @@ export function defineRegistry(_catalog, options) {
|
|
|
50
57
|
});
|
|
51
58
|
}
|
|
52
59
|
}
|
|
60
|
+
setCatalogSlotMetadata(registry, catalog);
|
|
53
61
|
// Build action helpers
|
|
54
62
|
const actionMap = options.actions
|
|
55
63
|
? Object.entries(options.actions)
|
|
@@ -99,8 +107,9 @@ export function defineRegistry(_catalog, options) {
|
|
|
99
107
|
* <DashboardRenderer spec={aiGeneratedSpec} {state} />
|
|
100
108
|
* ```
|
|
101
109
|
*/
|
|
102
|
-
export function createRenderer(
|
|
110
|
+
export function createRenderer(catalog, components) {
|
|
103
111
|
const registry = components;
|
|
112
|
+
setCatalogSlotMetadata(registry, catalog);
|
|
104
113
|
return (_, props) => {
|
|
105
114
|
let rendererRegistry = registry;
|
|
106
115
|
if (props.onRenderError) {
|
|
@@ -110,6 +119,7 @@ export function createRenderer(_catalog, components) {
|
|
|
110
119
|
enumerable: false,
|
|
111
120
|
configurable: true,
|
|
112
121
|
});
|
|
122
|
+
copySlotMetadata(registry, rendererRegistry);
|
|
113
123
|
}
|
|
114
124
|
return CatalogRenderer(_, {
|
|
115
125
|
registry: rendererRegistry,
|
package/dist/schema.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export declare const schema: import("@xmachines/json-render-core").Schema<{
|
|
|
17
17
|
props: import("@xmachines/json-render-core").SchemaType<"propsOf", string>;
|
|
18
18
|
/** Child element keys (flat reference) */
|
|
19
19
|
children: import("@xmachines/json-render-core").SchemaType<"array", import("@xmachines/json-render-core").SchemaType<"string", unknown>>;
|
|
20
|
+
slots: {
|
|
21
|
+
optional: true;
|
|
22
|
+
kind: "record";
|
|
23
|
+
inner?: import("@xmachines/json-render-core").SchemaType<"array", import("@xmachines/json-render-core").SchemaType<"string", unknown>> | undefined;
|
|
24
|
+
};
|
|
20
25
|
/** Visibility condition */
|
|
21
26
|
visible: {
|
|
22
27
|
optional: true;
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;;QAIb,uBAAuB;;QAEvB,kCAAkC;;YAG9B,kCAAkC;;YAElC,sBAAsB;;YAEtB,0CAA0C
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;;QAIb,uBAAuB;;QAEvB,kCAAkC;;YAG9B,kCAAkC;;YAElC,sBAAsB;;YAEtB,0CAA0C;;;;;;;YAG1C,2BAA2B;;;;;;YAE3B,yCAAyC;;;;;;;;;QAQ7C,4BAA4B;;YAE1B,qCAAqC;;YAErC,uGAAuG;;YAEvG,0CAA0C;;YAE1C,8FAA8F;;;QAGhG,oCAAoC;;YAElC,mCAAmC;;YAEnC,0CAA0C;;;;EAiDjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,MAAM,CAAC;AAEzC;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,IAAI,OAAO,MAAM,SAAS;IACvD,aAAa,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK;QAAE,SAAS,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC;CAC9D,GACG,CAAC,GACD,KAAK,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -19,6 +19,7 @@ export const schema = defineSchema((s) => ({
|
|
|
19
19
|
props: s.propsOf("catalog.components"),
|
|
20
20
|
/** Child element keys (flat reference) */
|
|
21
21
|
children: s.array(s.string()),
|
|
22
|
+
slots: { ...s.record(s.array(s.string())), ...s.optional() },
|
|
22
23
|
/** Visibility condition */
|
|
23
24
|
visible: { ...s.any(), ...s.optional() },
|
|
24
25
|
/** Repeat children from a state array */
|
|
@@ -70,6 +71,7 @@ export const schema = defineSchema((s) => ({
|
|
|
70
71
|
"CRITICAL INTEGRITY CHECK: Before outputting ANY element that references children, you MUST have already output (or will output) each child as its own element. If an element has children: ['a', 'b'], then elements 'a' and 'b' MUST exist. A missing child element causes that entire branch of the UI to be invisible.",
|
|
71
72
|
"SELF-CHECK: After generating all elements, mentally walk the tree from root. Every key in every children array must resolve to a defined element. If you find a gap, output the missing element immediately.",
|
|
72
73
|
'REQUIRED FIELDS: Every element MUST include a "children" array. Leaf elements (text, badges, inputs, images) use an empty array: "children": []. Omitting "children" fails validation.',
|
|
74
|
+
'NAMED SLOTS: Use "children" for the default slot. For other slots declared by the component, use a top-level "slots" object that maps each slot name to child element keys, for example {"slots":{"header":["heading"],"footer":["actions"]}}. Never use "slots.default". Every referenced key must exist.',
|
|
73
75
|
// Field placement
|
|
74
76
|
'CRITICAL: The "visible" field goes on the ELEMENT object, NOT inside "props". Correct: {"type":"<ComponentName>","props":{},"visible":{"$state":"/tab","eq":"home"},"children":[...]}.',
|
|
75
77
|
'CRITICAL: The "on" field goes on the ELEMENT object, NOT inside "props". Use on.press, on.change, on.submit etc. NEVER put action/actionParams inside props.',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmachines/json-render-svelte",
|
|
3
|
-
"version": "0.21.0-xm.
|
|
3
|
+
"version": "0.21.0-xm.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Svelte 5 renderer for @xmachines/json-render-core. JSON becomes Svelte components.",
|
|
6
6
|
"keywords": [
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"dist"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@xmachines/json-render-core": "0.21.0-xm.
|
|
52
|
+
"@xmachines/json-render-core": "0.21.0-xm.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@sveltejs/package": "^2.3.0",
|