@xmachines/json-render-solid 0.20.0-xm.4 → 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 +31 -0
- package/dist/{chunk-ZTWTJIEL.mjs → chunk-4IHHL4OE.mjs} +3 -1
- package/dist/chunk-4IHHL4OE.mjs.map +1 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +130 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -52
- package/dist/index.mjs.map +1 -1
- package/dist/schema.d.mts +10 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -1
- package/dist/schema.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-ZTWTJIEL.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -128,11 +128,42 @@ interface UIElement {
|
|
|
128
128
|
type: string;
|
|
129
129
|
props: Record<string, unknown>;
|
|
130
130
|
children?: string[];
|
|
131
|
+
slots?: Record<string, string[]>; // Named slots mapped to child keys
|
|
131
132
|
visible?: VisibilityCondition;
|
|
132
133
|
watch?: Record<string, ActionBinding | ActionBinding[]>;
|
|
133
134
|
}
|
|
134
135
|
```
|
|
135
136
|
|
|
137
|
+
## Named Slots
|
|
138
|
+
|
|
139
|
+
Use `children` for the default slot. Use the element's top-level `slots` object for the other slot names that the catalog declares:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"type": "Layout",
|
|
144
|
+
"props": {},
|
|
145
|
+
"children": ["main"],
|
|
146
|
+
"slots": {
|
|
147
|
+
"header": ["heading"],
|
|
148
|
+
"footer": ["actions"]
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
A registry component receives `slots`, a record of the rendered content for each named slot:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
Layout: (ctx) => (
|
|
157
|
+
<div>
|
|
158
|
+
<header>{ctx.slots?.header}</header>
|
|
159
|
+
<main>{ctx.children}</main>
|
|
160
|
+
<footer>{ctx.slots?.footer}</footer>
|
|
161
|
+
</div>
|
|
162
|
+
),
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Each key of `slots` is a getter, like `children`, so a slot renders only when the component reads 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.
|
|
166
|
+
|
|
136
167
|
## Providers
|
|
137
168
|
|
|
138
169
|
| Provider | Purpose |
|
|
@@ -15,6 +15,7 @@ var schema = defineSchema(
|
|
|
15
15
|
props: s.propsOf("catalog.components"),
|
|
16
16
|
/** Child element keys (flat reference) */
|
|
17
17
|
children: s.array(s.string()),
|
|
18
|
+
slots: { ...s.record(s.array(s.string())), ...s.optional() },
|
|
18
19
|
/** Visibility condition */
|
|
19
20
|
visible: { ...s.any(), ...s.optional() },
|
|
20
21
|
/** Repeat children from a state array */
|
|
@@ -68,6 +69,7 @@ var schema = defineSchema(
|
|
|
68
69
|
"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.",
|
|
69
70
|
"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.",
|
|
70
71
|
'REQUIRED FIELDS: Every element MUST include a "children" array. Leaf elements (text, badges, inputs, images) use an empty array: "children": []. Omitting "children" fails validation.',
|
|
72
|
+
'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.',
|
|
71
73
|
// Field placement
|
|
72
74
|
'CRITICAL: The "visible" field goes on the ELEMENT object, NOT inside "props". Correct: {"type":"<ComponentName>","props":{},"visible":{"$state":"/tab","eq":"home"},"children":[...]}.',
|
|
73
75
|
'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.',
|
|
@@ -87,4 +89,4 @@ export {
|
|
|
87
89
|
schema,
|
|
88
90
|
elementTreeSchema
|
|
89
91
|
};
|
|
90
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-4IHHL4OE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts"],"sourcesContent":["import { defineSchema } from \"@xmachines/json-render-core\";\n\n/**\n * The schema for @xmachines/json-render-solid\n *\n * Defines:\n * - Spec: A flat tree of elements with keys, types, props, and children references\n * - Catalog: Components with props schemas, and optional actions\n */\nexport const schema = defineSchema(\n (s) => ({\n // What the AI-generated SPEC looks like\n spec: s.object({\n /** Root element key */\n root: s.string(),\n /** Flat map of elements by key */\n elements: s.record(\n s.object({\n /** Component type from catalog */\n type: s.ref(\"catalog.components\"),\n /** Component props */\n props: s.propsOf(\"catalog.components\"),\n /** Child element keys (flat reference) */\n children: s.array(s.string()),\n slots: { ...s.record(s.array(s.string())), ...s.optional() },\n /** Visibility condition */\n visible: { ...s.any(), ...s.optional() },\n /** Repeat children from a state array */\n repeat: { ...s.any(), ...s.optional() },\n }),\n ),\n }),\n\n // What the CATALOG must provide\n catalog: s.object({\n /** Component definitions */\n components: s.map({\n /** Zod schema for component props */\n props: s.zod(),\n /** Slots for this component. Use ['default'] for children, or named slots like ['header', 'footer'] */\n slots: s.array(s.string()),\n /** Description for AI generation hints */\n description: s.string(),\n /** Example prop values used in prompt examples (auto-generated from Zod schema if omitted) */\n example: s.any(),\n }),\n /** Action definitions (optional) */\n actions: s.map({\n /** Zod schema for action params */\n params: s.zod(),\n /** Description for AI generation hints */\n description: s.string(),\n }),\n }),\n }),\n {\n builtInActions: [\n {\n name: \"setState\",\n description:\n \"Update a value in the state model at the given statePath. Params: { statePath: string, value: any }\",\n },\n {\n name: \"pushState\",\n description:\n 'Append an item to an array in state. Params: { statePath: string, value: any, clearStatePath?: string }. Value can contain {\"$state\":\"/path\"} refs and \"$id\" for auto IDs.',\n },\n {\n name: \"removeState\",\n description:\n \"Remove an item from an array in state by index. Params: { statePath: string, index: number }\",\n },\n {\n name: \"validateForm\",\n description:\n \"Validate all registered form fields and write the result to state. Params: { statePath?: string }. Defaults to /formValidation. Result: { valid: boolean, errors: Record<string, string[]> }.\",\n },\n ],\n defaultRules: [\n // Element integrity\n \"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.\",\n \"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.\",\n 'REQUIRED FIELDS: Every element MUST include a \"children\" array. Leaf elements (text, badges, inputs, images) use an empty array: \"children\": []. Omitting \"children\" fails validation.',\n '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.',\n\n // Field placement\n 'CRITICAL: The \"visible\" field goes on the ELEMENT object, NOT inside \"props\". Correct: {\"type\":\"<ComponentName>\",\"props\":{},\"visible\":{\"$state\":\"/tab\",\"eq\":\"home\"},\"children\":[...]}.',\n '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.',\n\n // State and data\n \"When the user asks for a UI that displays data (e.g. blog posts, products, users), ALWAYS include a state field with realistic sample data. The state field is a top-level field on the spec (sibling of root/elements).\",\n 'When building repeating content backed by a state array (e.g. posts, products, items), use the \"repeat\" field on a container element. Example: { \"type\": \"<ContainerComponent>\", \"props\": {}, \"repeat\": { \"statePath\": \"/posts\", \"key\": \"id\" }, \"children\": [\"post-card\"] }. For a nested list stored on the enclosing item, use \"repeat\": { \"statePath\": { \"$item\": \"comments\" }, \"key\": \"id\" }. The $item statePath form is valid only inside another repeat. Replace <ContainerComponent> with an appropriate component from the AVAILABLE COMPONENTS list. Inside repeated children, use { \"$item\": \"field\" } to read a field from the current item, and { \"$index\": true } for the current array index. For two-way binding to an item field use { \"$bindItem\": \"completed\" }. Do NOT hardcode individual elements for each array item.',\n\n // Design quality\n \"Design with visual hierarchy: use container components to group content, heading components for section titles, proper spacing, and status indicators. ONLY use components from the AVAILABLE COMPONENTS list.\",\n \"For data-rich UIs, use multi-column layout components if available. For forms and single-column content, use vertical layout components. ONLY use components from the AVAILABLE COMPONENTS list.\",\n \"Always include realistic, professional-looking sample data. For blogs include 3-4 posts with varied titles, authors, dates, categories. For products include names, prices, images. Never leave data empty.\",\n ],\n },\n);\n\n/**\n * Type for the Solid schema\n */\nexport type SolidSchema = typeof schema;\n\n/**\n * Infer the spec type from a catalog\n */\nexport type SolidSpec<TCatalog> = typeof schema extends {\n createCatalog: (catalog: TCatalog) => { _specType: infer S };\n}\n ? S\n : never;\n\n// Backward compatibility aliases\n/** @deprecated Use `schema` instead */\nexport const elementTreeSchema = schema;\n/** @deprecated Use `SolidSchema` instead */\nexport type ElementTreeSchema = SolidSchema;\n/** @deprecated Use `SolidSpec` instead */\nexport type ElementTreeSpec<T> = SolidSpec<T>;\n"],"mappings":";AAAA,SAAS,oBAAoB;AAStB,IAAM,SAAS;AAAA,EACpB,CAAC,OAAO;AAAA;AAAA,IAEN,MAAM,EAAE,OAAO;AAAA;AAAA,MAEb,MAAM,EAAE,OAAO;AAAA;AAAA,MAEf,UAAU,EAAE;AAAA,QACV,EAAE,OAAO;AAAA;AAAA,UAEP,MAAM,EAAE,IAAI,oBAAoB;AAAA;AAAA,UAEhC,OAAO,EAAE,QAAQ,oBAAoB;AAAA;AAAA,UAErC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,UAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,SAAS,EAAE;AAAA;AAAA,UAE3D,SAAS,EAAE,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,SAAS,EAAE;AAAA;AAAA,UAEvC,QAAQ,EAAE,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,SAAS,EAAE;AAAA,QACxC,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA;AAAA,IAGD,SAAS,EAAE,OAAO;AAAA;AAAA,MAEhB,YAAY,EAAE,IAAI;AAAA;AAAA,QAEhB,OAAO,EAAE,IAAI;AAAA;AAAA,QAEb,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA;AAAA,QAEzB,aAAa,EAAE,OAAO;AAAA;AAAA,QAEtB,SAAS,EAAE,IAAI;AAAA,MACjB,CAAC;AAAA;AAAA,MAED,SAAS,EAAE,IAAI;AAAA;AAAA,QAEb,QAAQ,EAAE,IAAI;AAAA;AAAA,QAEd,aAAa,EAAE,OAAO;AAAA,MACxB,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAAA,EACA;AAAA,IACE,gBAAgB;AAAA,MACd;AAAA,QACE,MAAM;AAAA,QACN,aACE;AAAA,MACJ;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aACE;AAAA,MACJ;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aACE;AAAA,MACJ;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aACE;AAAA,MACJ;AAAA,IACF;AAAA,IACA,cAAc;AAAA;AAAA,MAEZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAGA;AAAA,MACA;AAAA;AAAA,MAGA;AAAA,MACA;AAAA;AAAA,MAGA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAkBO,IAAM,oBAAoB;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -151,6 +151,11 @@ interface EventHandle {
|
|
|
151
151
|
interface BaseComponentProps<P = Record<string, unknown>> {
|
|
152
152
|
props: P;
|
|
153
153
|
children?: JSX.Element;
|
|
154
|
+
/**
|
|
155
|
+
* Rendered content for each named slot of the element (`element.slots`).
|
|
156
|
+
* A slot renders only when the component reads its key, like `children`.
|
|
157
|
+
*/
|
|
158
|
+
slots?: Record<string, JSX.Element>;
|
|
154
159
|
/** Simple event emitter (shorthand). Fires the event and returns void. */
|
|
155
160
|
emit: (event: string) => void;
|
|
156
161
|
/** Get an event handle with metadata. Use when you need shouldPreventDefault or bound checks. */
|
|
@@ -226,6 +231,11 @@ interface ComponentRenderProps<P = Record<string, unknown>> {
|
|
|
226
231
|
element: UIElement<string, P>;
|
|
227
232
|
/** Rendered children */
|
|
228
233
|
children?: JSX.Element;
|
|
234
|
+
/**
|
|
235
|
+
* Rendered content for each named slot of the element (`element.slots`).
|
|
236
|
+
* Each key is a getter, so a slot renders only when the component reads it.
|
|
237
|
+
*/
|
|
238
|
+
slots?: Record<string, JSX.Element>;
|
|
229
239
|
/** Emit a named event. The renderer resolves the event to action binding(s) from the element's `on` field. Always provided by the renderer. */
|
|
230
240
|
emit: (event: string) => void;
|
|
231
241
|
/** Get an event handle with metadata (shouldPreventDefault, bound). Use when you need to inspect event bindings. */
|
|
@@ -355,7 +365,7 @@ type DefineRegistryOptions<C extends Catalog> = {
|
|
|
355
365
|
* });
|
|
356
366
|
* ```
|
|
357
367
|
*/
|
|
358
|
-
declare function defineRegistry<C extends Catalog>(
|
|
368
|
+
declare function defineRegistry<C extends Catalog>(catalog: C, options: DefineRegistryOptions<C>): DefineRegistryResult;
|
|
359
369
|
/**
|
|
360
370
|
* Props for renderers created with createRenderer
|
|
361
371
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -151,6 +151,11 @@ interface EventHandle {
|
|
|
151
151
|
interface BaseComponentProps<P = Record<string, unknown>> {
|
|
152
152
|
props: P;
|
|
153
153
|
children?: JSX.Element;
|
|
154
|
+
/**
|
|
155
|
+
* Rendered content for each named slot of the element (`element.slots`).
|
|
156
|
+
* A slot renders only when the component reads its key, like `children`.
|
|
157
|
+
*/
|
|
158
|
+
slots?: Record<string, JSX.Element>;
|
|
154
159
|
/** Simple event emitter (shorthand). Fires the event and returns void. */
|
|
155
160
|
emit: (event: string) => void;
|
|
156
161
|
/** Get an event handle with metadata. Use when you need shouldPreventDefault or bound checks. */
|
|
@@ -226,6 +231,11 @@ interface ComponentRenderProps<P = Record<string, unknown>> {
|
|
|
226
231
|
element: UIElement<string, P>;
|
|
227
232
|
/** Rendered children */
|
|
228
233
|
children?: JSX.Element;
|
|
234
|
+
/**
|
|
235
|
+
* Rendered content for each named slot of the element (`element.slots`).
|
|
236
|
+
* Each key is a getter, so a slot renders only when the component reads it.
|
|
237
|
+
*/
|
|
238
|
+
slots?: Record<string, JSX.Element>;
|
|
229
239
|
/** Emit a named event. The renderer resolves the event to action binding(s) from the element's `on` field. Always provided by the renderer. */
|
|
230
240
|
emit: (event: string) => void;
|
|
231
241
|
/** Get an event handle with metadata (shouldPreventDefault, bound). Use when you need to inspect event bindings. */
|
|
@@ -355,7 +365,7 @@ type DefineRegistryOptions<C extends Catalog> = {
|
|
|
355
365
|
* });
|
|
356
366
|
* ```
|
|
357
367
|
*/
|
|
358
|
-
declare function defineRegistry<C extends Catalog>(
|
|
368
|
+
declare function defineRegistry<C extends Catalog>(catalog: C, options: DefineRegistryOptions<C>): DefineRegistryResult;
|
|
359
369
|
/**
|
|
360
370
|
* Props for renderers created with createRenderer
|
|
361
371
|
*/
|
package/dist/index.js
CHANGED
|
@@ -760,6 +760,7 @@ var schema = (0, import_core5.defineSchema)(
|
|
|
760
760
|
props: s.propsOf("catalog.components"),
|
|
761
761
|
/** Child element keys (flat reference) */
|
|
762
762
|
children: s.array(s.string()),
|
|
763
|
+
slots: { ...s.record(s.array(s.string())), ...s.optional() },
|
|
763
764
|
/** Visibility condition */
|
|
764
765
|
visible: { ...s.any(), ...s.optional() },
|
|
765
766
|
/** Repeat children from a state array */
|
|
@@ -813,6 +814,7 @@ var schema = (0, import_core5.defineSchema)(
|
|
|
813
814
|
"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.",
|
|
814
815
|
"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.",
|
|
815
816
|
'REQUIRED FIELDS: Every element MUST include a "children" array. Leaf elements (text, badges, inputs, images) use an empty array: "children": []. Omitting "children" fails validation.',
|
|
817
|
+
'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.',
|
|
816
818
|
// Field placement
|
|
817
819
|
'CRITICAL: The "visible" field goes on the ELEMENT object, NOT inside "props". Correct: {"type":"<ComponentName>","props":{},"visible":{"$state":"/tab","eq":"home"},"children":[...]}.',
|
|
818
820
|
'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.',
|
|
@@ -841,6 +843,18 @@ var import_web18 = require("solid-js/web");
|
|
|
841
843
|
var import_solid_js6 = require("solid-js");
|
|
842
844
|
var import_core6 = require("@xmachines/json-render-core");
|
|
843
845
|
var _tmpl$2 = /* @__PURE__ */ (0, import_web13.template)(`<span style=display:contents>`);
|
|
846
|
+
function withRenderErrorHandler(registry, onRenderError) {
|
|
847
|
+
const next = {
|
|
848
|
+
...registry
|
|
849
|
+
};
|
|
850
|
+
Object.defineProperty(next, "onRenderError", {
|
|
851
|
+
value: onRenderError,
|
|
852
|
+
enumerable: false,
|
|
853
|
+
configurable: true
|
|
854
|
+
});
|
|
855
|
+
(0, import_core6.copySlotMetadata)(registry, next);
|
|
856
|
+
return next;
|
|
857
|
+
}
|
|
844
858
|
function reportRenderError(registry, elementType, error) {
|
|
845
859
|
const onRenderError = registry?.onRenderError;
|
|
846
860
|
if (typeof onRenderError === "function") {
|
|
@@ -1049,34 +1063,20 @@ function ElementRendererContent(props) {
|
|
|
1049
1063
|
get when() {
|
|
1050
1064
|
return Comp();
|
|
1051
1065
|
},
|
|
1066
|
+
keyed: true,
|
|
1052
1067
|
get fallback() {
|
|
1053
1068
|
console.warn(`No renderer for component type: ${props.resolvedElement.type}`);
|
|
1054
1069
|
return null;
|
|
1055
1070
|
},
|
|
1056
|
-
children: (
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
return props.spec;
|
|
1064
|
-
},
|
|
1065
|
-
get registry() {
|
|
1066
|
-
return props.registry;
|
|
1067
|
-
},
|
|
1068
|
-
get loading() {
|
|
1069
|
-
return props.loading;
|
|
1070
|
-
},
|
|
1071
|
-
get fallback() {
|
|
1072
|
-
return props.fallback;
|
|
1073
|
-
},
|
|
1074
|
-
get itemFilter() {
|
|
1075
|
-
return props.itemFilter;
|
|
1076
|
-
}
|
|
1077
|
-
}) : (0, import_web18.createComponent)(import_solid_js6.For, {
|
|
1071
|
+
children: (Component) => {
|
|
1072
|
+
const elementSlots = (0, import_solid_js6.createMemo)(() => props.resolvedElement.slots);
|
|
1073
|
+
(0, import_solid_js6.createRenderEffect)(() => {
|
|
1074
|
+
const slotEntries = elementSlots();
|
|
1075
|
+
(0, import_solid_js6.untrack)(() => (0, import_core6.warnElementSlots)(props.registry, props.resolvedElement.type, slotEntries));
|
|
1076
|
+
});
|
|
1077
|
+
const renderChildKeys = (childKeys, slotName) => (0, import_web18.createComponent)(import_solid_js6.For, {
|
|
1078
1078
|
get each() {
|
|
1079
|
-
return
|
|
1079
|
+
return childKeys();
|
|
1080
1080
|
},
|
|
1081
1081
|
children: (childKey) => {
|
|
1082
1082
|
const childElement = () => props.spec.elements[childKey];
|
|
@@ -1086,7 +1086,9 @@ function ElementRendererContent(props) {
|
|
|
1086
1086
|
},
|
|
1087
1087
|
get fallback() {
|
|
1088
1088
|
if (!props.loading) {
|
|
1089
|
-
|
|
1089
|
+
const type = (0, import_solid_js6.untrack)(() => props.resolvedElement.type);
|
|
1090
|
+
const location = slotName ? `in slot "${slotName}" of "${type}"` : `as child of "${type}"`;
|
|
1091
|
+
console.warn(`[json-render] Missing element "${childKey}" referenced ${location}. This element will not render.`);
|
|
1090
1092
|
}
|
|
1091
1093
|
return null;
|
|
1092
1094
|
},
|
|
@@ -1111,6 +1113,99 @@ function ElementRendererContent(props) {
|
|
|
1111
1113
|
});
|
|
1112
1114
|
}
|
|
1113
1115
|
});
|
|
1116
|
+
const owner = (0, import_solid_js6.getOwner)();
|
|
1117
|
+
const once = (make) => {
|
|
1118
|
+
const contents = /* @__PURE__ */ new Map();
|
|
1119
|
+
return () => {
|
|
1120
|
+
const reader = (0, import_solid_js6.getOwner)();
|
|
1121
|
+
let content = contents.get(reader);
|
|
1122
|
+
if (content === void 0) {
|
|
1123
|
+
let dispose = () => {
|
|
1124
|
+
};
|
|
1125
|
+
const value = (0, import_solid_js6.createRoot)((disposeRoot) => {
|
|
1126
|
+
dispose = disposeRoot;
|
|
1127
|
+
return make();
|
|
1128
|
+
}, reader ?? owner);
|
|
1129
|
+
const made = {
|
|
1130
|
+
value,
|
|
1131
|
+
dispose,
|
|
1132
|
+
leaving: false
|
|
1133
|
+
};
|
|
1134
|
+
contents.set(reader, made);
|
|
1135
|
+
(0, import_solid_js6.runWithOwner)(owner, () => (0, import_solid_js6.onCleanup)(() => {
|
|
1136
|
+
contents.delete(reader);
|
|
1137
|
+
made.dispose();
|
|
1138
|
+
}));
|
|
1139
|
+
content = made;
|
|
1140
|
+
}
|
|
1141
|
+
content.leaving = false;
|
|
1142
|
+
if (reader !== null && reader !== owner) {
|
|
1143
|
+
const read = content;
|
|
1144
|
+
(0, import_solid_js6.onCleanup)(() => {
|
|
1145
|
+
read.leaving = true;
|
|
1146
|
+
queueMicrotask(() => {
|
|
1147
|
+
if (!read.leaving || contents.get(reader) !== read) return;
|
|
1148
|
+
contents.delete(reader);
|
|
1149
|
+
read.dispose();
|
|
1150
|
+
});
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
return content.value;
|
|
1154
|
+
};
|
|
1155
|
+
};
|
|
1156
|
+
const children = once(() => (0, import_web18.createComponent)(import_solid_js6.Show, {
|
|
1157
|
+
get when() {
|
|
1158
|
+
return props.resolvedElement.repeat;
|
|
1159
|
+
},
|
|
1160
|
+
get fallback() {
|
|
1161
|
+
return renderChildKeys(() => props.resolvedElement.children ?? []);
|
|
1162
|
+
},
|
|
1163
|
+
get children() {
|
|
1164
|
+
return (0, import_web18.createComponent)(RepeatChildren, {
|
|
1165
|
+
get element() {
|
|
1166
|
+
return props.resolvedElement;
|
|
1167
|
+
},
|
|
1168
|
+
get spec() {
|
|
1169
|
+
return props.spec;
|
|
1170
|
+
},
|
|
1171
|
+
get registry() {
|
|
1172
|
+
return props.registry;
|
|
1173
|
+
},
|
|
1174
|
+
get loading() {
|
|
1175
|
+
return props.loading;
|
|
1176
|
+
},
|
|
1177
|
+
get fallback() {
|
|
1178
|
+
return props.fallback;
|
|
1179
|
+
},
|
|
1180
|
+
get itemFilter() {
|
|
1181
|
+
return props.itemFilter;
|
|
1182
|
+
}
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
}));
|
|
1186
|
+
const slotContent = /* @__PURE__ */ new Map();
|
|
1187
|
+
const slotOf = (slotName) => {
|
|
1188
|
+
let content = slotContent.get(slotName);
|
|
1189
|
+
if (!content) {
|
|
1190
|
+
content = once(() => renderChildKeys(() => props.resolvedElement.slots?.[slotName] ?? [], slotName));
|
|
1191
|
+
slotContent.set(slotName, content);
|
|
1192
|
+
}
|
|
1193
|
+
return content();
|
|
1194
|
+
};
|
|
1195
|
+
const slots = () => {
|
|
1196
|
+
const slotEntries = props.resolvedElement.slots;
|
|
1197
|
+
if (!slotEntries) return void 0;
|
|
1198
|
+
const slotNames = Object.keys(slotEntries).filter((slotName) => slotName !== "default");
|
|
1199
|
+
if (slotNames.length === 0) return void 0;
|
|
1200
|
+
const result = {};
|
|
1201
|
+
for (const slotName of slotNames) {
|
|
1202
|
+
Object.defineProperty(result, slotName, {
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
get: () => slotOf(slotName)
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
return result;
|
|
1208
|
+
};
|
|
1114
1209
|
const rendered = (0, import_web18.createComponent)(Component, {
|
|
1115
1210
|
get element() {
|
|
1116
1211
|
return props.resolvedElement;
|
|
@@ -1127,6 +1222,9 @@ function ElementRendererContent(props) {
|
|
|
1127
1222
|
get loading() {
|
|
1128
1223
|
return props.loading;
|
|
1129
1224
|
},
|
|
1225
|
+
get slots() {
|
|
1226
|
+
return slots();
|
|
1227
|
+
},
|
|
1130
1228
|
get children() {
|
|
1131
1229
|
return children();
|
|
1132
1230
|
}
|
|
@@ -1235,18 +1333,7 @@ function Renderer(props) {
|
|
|
1235
1333
|
if (!spec || !spec.root) return void 0;
|
|
1236
1334
|
return spec.elements[spec.root];
|
|
1237
1335
|
});
|
|
1238
|
-
const rendererRegistry = (0, import_solid_js6.createMemo)(() =>
|
|
1239
|
-
if (!props.onRenderError) return props.registry;
|
|
1240
|
-
const next = {
|
|
1241
|
-
...props.registry
|
|
1242
|
-
};
|
|
1243
|
-
Object.defineProperty(next, "onRenderError", {
|
|
1244
|
-
value: props.onRenderError,
|
|
1245
|
-
enumerable: false,
|
|
1246
|
-
configurable: true
|
|
1247
|
-
});
|
|
1248
|
-
return next;
|
|
1249
|
-
});
|
|
1336
|
+
const rendererRegistry = (0, import_solid_js6.createMemo)(() => props.onRenderError ? withRenderErrorHandler(props.registry, props.onRenderError) : props.registry);
|
|
1250
1337
|
return (0, import_web18.createComponent)(import_solid_js6.Show, {
|
|
1251
1338
|
get when() {
|
|
1252
1339
|
return rootElement();
|
|
@@ -1344,7 +1431,7 @@ function ConfirmationDialogManager() {
|
|
|
1344
1431
|
})
|
|
1345
1432
|
});
|
|
1346
1433
|
}
|
|
1347
|
-
function defineRegistry(
|
|
1434
|
+
function defineRegistry(catalog, options) {
|
|
1348
1435
|
const registry = {};
|
|
1349
1436
|
if (options.components) {
|
|
1350
1437
|
for (const [name, componentFn] of Object.entries(options.components)) {
|
|
@@ -1356,6 +1443,9 @@ function defineRegistry(_catalog, options) {
|
|
|
1356
1443
|
get children() {
|
|
1357
1444
|
return renderProps.children;
|
|
1358
1445
|
},
|
|
1446
|
+
get slots() {
|
|
1447
|
+
return renderProps.slots;
|
|
1448
|
+
},
|
|
1359
1449
|
emit: renderProps.emit,
|
|
1360
1450
|
on: renderProps.on,
|
|
1361
1451
|
get bindings() {
|
|
@@ -1368,6 +1458,7 @@ function defineRegistry(_catalog, options) {
|
|
|
1368
1458
|
};
|
|
1369
1459
|
}
|
|
1370
1460
|
}
|
|
1461
|
+
(0, import_core6.setCatalogSlotMetadata)(registry, catalog);
|
|
1371
1462
|
const actionMap = options.actions ? Object.entries(options.actions) : [];
|
|
1372
1463
|
const handlers = (getSetState, getState) => {
|
|
1373
1464
|
const result = {};
|
|
@@ -1405,20 +1496,10 @@ function defineRegistry(_catalog, options) {
|
|
|
1405
1496
|
}
|
|
1406
1497
|
function createRenderer(catalog, components) {
|
|
1407
1498
|
const registry = components;
|
|
1499
|
+
(0, import_core6.setCatalogSlotMetadata)(registry, catalog);
|
|
1408
1500
|
return function CatalogRenderer(props) {
|
|
1409
1501
|
const directiveRegistry = (0, import_solid_js6.createMemo)(() => props.directives ? (0, import_core6.createDirectiveRegistry)(props.directives) : void 0);
|
|
1410
|
-
const rendererRegistry = (0, import_solid_js6.createMemo)(() =>
|
|
1411
|
-
if (!props.onRenderError) return registry;
|
|
1412
|
-
const next = {
|
|
1413
|
-
...registry
|
|
1414
|
-
};
|
|
1415
|
-
Object.defineProperty(next, "onRenderError", {
|
|
1416
|
-
value: props.onRenderError,
|
|
1417
|
-
enumerable: false,
|
|
1418
|
-
configurable: true
|
|
1419
|
-
});
|
|
1420
|
-
return next;
|
|
1421
|
-
});
|
|
1502
|
+
const rendererRegistry = (0, import_solid_js6.createMemo)(() => props.onRenderError ? withRenderErrorHandler(registry, props.onRenderError) : registry);
|
|
1422
1503
|
const actionHandlers = () => props.onAction ? new Proxy({}, {
|
|
1423
1504
|
get: (_target, prop) => {
|
|
1424
1505
|
return (params) => props.onAction(prop, params);
|