@xmachines/json-render-solid 0.21.0-xm.4 → 0.21.0-xm.6
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 +114 -17
- package/dist/{chunk-4IHHL4OE.mjs → chunk-ML2S7DVS.mjs} +3 -20
- package/dist/chunk-ML2S7DVS.mjs.map +1 -0
- package/dist/index.d.mts +47 -27
- package/dist/index.d.ts +47 -27
- package/dist/index.js +518 -260
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +475 -186
- package/dist/index.mjs.map +1 -1
- package/dist/schema.js +1 -18
- package/dist/schema.js.map +1 -1
- package/dist/schema.mjs +1 -1
- package/package.json +4 -4
- package/dist/chunk-4IHHL4OE.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ SolidJS renderer for json-render. Turn JSON specs into Solid components with dat
|
|
|
8
8
|
npm install @xmachines/json-render-core @xmachines/json-render-solid zod
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Peer dependencies: `solid-js ^1.9.
|
|
11
|
+
Peer dependencies: `solid-js ^1.9.8` and `zod ^4.0.0`.
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
@@ -37,7 +37,9 @@ export const catalog = defineCatalog(schema, {
|
|
|
37
37
|
},
|
|
38
38
|
Input: {
|
|
39
39
|
props: z.object({
|
|
40
|
-
value: z
|
|
40
|
+
value: z
|
|
41
|
+
.union([z.string(), z.record(z.string(), z.unknown())])
|
|
42
|
+
.nullable(),
|
|
41
43
|
label: z.string(),
|
|
42
44
|
placeholder: z.string().nullable(),
|
|
43
45
|
}),
|
|
@@ -61,28 +63,29 @@ import { catalog } from "./catalog";
|
|
|
61
63
|
|
|
62
64
|
export const { registry } = defineRegistry(catalog, {
|
|
63
65
|
components: {
|
|
64
|
-
Card: (
|
|
66
|
+
Card: (ctx) => (
|
|
65
67
|
<div class="card">
|
|
66
|
-
<h3>{
|
|
67
|
-
{
|
|
68
|
+
<h3>{ctx.props.title}</h3>
|
|
69
|
+
{ctx.children}
|
|
68
70
|
</div>
|
|
69
71
|
),
|
|
70
|
-
Button: (
|
|
71
|
-
<button onClick={() =>
|
|
72
|
-
{renderProps.element.props.label as string}
|
|
73
|
-
</button>
|
|
72
|
+
Button: (ctx) => (
|
|
73
|
+
<button onClick={() => ctx.emit("press")}>{ctx.props.label}</button>
|
|
74
74
|
),
|
|
75
|
-
Input: (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
Input: (ctx) => {
|
|
76
|
+
// A Solid component runs one time, so `useBoundProp` gives the value
|
|
77
|
+
// of the mount. Read `ctx.props.value` in the JSX to show the value of
|
|
78
|
+
// now, and use the setter to write it.
|
|
79
|
+
const [, setValue] = useBoundProp(
|
|
80
|
+
ctx.props.value,
|
|
81
|
+
() => ctx.bindings?.value,
|
|
79
82
|
);
|
|
80
83
|
return (
|
|
81
84
|
<label>
|
|
82
|
-
{
|
|
85
|
+
{ctx.props.label}
|
|
83
86
|
<input
|
|
84
|
-
value={String(value
|
|
85
|
-
placeholder={
|
|
87
|
+
value={String(ctx.props.value ?? "")}
|
|
88
|
+
placeholder={ctx.props.placeholder ?? ""}
|
|
86
89
|
onInput={(e) => setValue(e.currentTarget.value)}
|
|
87
90
|
/>
|
|
88
91
|
</label>
|
|
@@ -203,6 +206,53 @@ const store = createStateStore({ count: 0 });
|
|
|
203
206
|
| `useUIStream(options)` | Stream UI specs from an endpoint |
|
|
204
207
|
| `useChatUI(options)` | Chat-style spec generation hook |
|
|
205
208
|
|
|
209
|
+
`useFieldValidation` also takes an accessor of the config, such as
|
|
210
|
+
`() => ({ checks: [{ type: "required", message: props.message }] })`. A Solid
|
|
211
|
+
component runs one time, so a config that reads props needs the accessor to
|
|
212
|
+
follow the props of now. A config with a new value registers the field again.
|
|
213
|
+
|
|
214
|
+
### Bound paths
|
|
215
|
+
|
|
216
|
+
`useBoundProp`, `useStateValue`, `useStateBinding` and `useFieldValidation`
|
|
217
|
+
take a plain path or an accessor of the path. A Solid component runs one
|
|
218
|
+
time, so a plain path is the path of the mount, as in the upstream hooks.
|
|
219
|
+
The path of a prop can change while the component lives: a keyed row moves,
|
|
220
|
+
or a new spec binds the prop or makes it a literal.
|
|
221
|
+
|
|
222
|
+
- A component in a row of a keyed repeat passes an accessor, such as
|
|
223
|
+
`() => ctx.bindings?.value`, or it uses the bound prop. A plain path in a
|
|
224
|
+
row that moves reads, writes and validates the item at the index of the
|
|
225
|
+
mount.
|
|
226
|
+
- A component that must follow a binding that a later spec adds or removes
|
|
227
|
+
passes an accessor. The accessor reads the binding of now, as react reads
|
|
228
|
+
`bindings.value` on each render. A prop that is no longer bound gives no
|
|
229
|
+
path: `useBoundProp` and `useStateBinding` write nothing, `useStateValue`
|
|
230
|
+
reads nothing, and `useFieldValidation` registers nothing.
|
|
231
|
+
- A literal path, such as `"/name"`, stays as it is.
|
|
232
|
+
|
|
233
|
+
`bindings` is `undefined` while no prop of the element is bound, as in react.
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
Input: (ctx) => {
|
|
237
|
+
const [, setValue] = useBoundProp<string>(
|
|
238
|
+
ctx.props.value,
|
|
239
|
+
() => ctx.bindings?.value,
|
|
240
|
+
);
|
|
241
|
+
const { errors } = useFieldValidation(() => ctx.bindings?.value, {
|
|
242
|
+
checks: [{ type: "required", message: "Required" }],
|
|
243
|
+
});
|
|
244
|
+
return (
|
|
245
|
+
<label>
|
|
246
|
+
<input
|
|
247
|
+
value={String(ctx.props.value ?? "")}
|
|
248
|
+
onInput={(e) => setValue(e.currentTarget.value)}
|
|
249
|
+
/>
|
|
250
|
+
{errors()[0]}
|
|
251
|
+
</label>
|
|
252
|
+
);
|
|
253
|
+
},
|
|
254
|
+
```
|
|
255
|
+
|
|
206
256
|
## Built-in Actions
|
|
207
257
|
|
|
208
258
|
These actions are available in the Solid schema and handled by `ActionProvider`:
|
|
@@ -210,9 +260,11 @@ These actions are available in the Solid schema and handled by `ActionProvider`:
|
|
|
210
260
|
- `setState`
|
|
211
261
|
- `pushState`
|
|
212
262
|
- `removeState`
|
|
263
|
+
- `push`
|
|
264
|
+
- `pop`
|
|
213
265
|
- `validateForm`
|
|
214
266
|
|
|
215
|
-
`setState`/`pushState`/`removeState` mutate the state model. `validateForm` validates registered fields and writes `{ valid, errors }` to state (`/formValidation` by default).
|
|
267
|
+
`setState`/`pushState`/`removeState` mutate the state model. `push` shows a screen (`/currentScreen`) and keeps the last one on `/navStack`, and `pop` goes back to it. `validateForm` validates registered fields and writes `{ valid, errors }` to state (`/formValidation` by default). The catalog prompt names all six.
|
|
216
268
|
|
|
217
269
|
## Events and Action Binding
|
|
218
270
|
|
|
@@ -234,6 +286,32 @@ const stream = useUIStream({ api: "/api/generate" });
|
|
|
234
286
|
await stream.send("Build me a dashboard");
|
|
235
287
|
```
|
|
236
288
|
|
|
289
|
+
## Render Errors
|
|
290
|
+
|
|
291
|
+
`Renderer` and the component of `createRenderer` take an `onRenderError` prop of the type `OnRenderError`. `defineRegistry(catalog, { onRenderError })` puts the handler on the registry, and the prop takes the place of that handler.
|
|
292
|
+
|
|
293
|
+
The handler gets `(error, name, info)`. Each failure in code that the renderer runs reaches the handler one time:
|
|
294
|
+
|
|
295
|
+
| `info.kind` | Failure | `name` | Result |
|
|
296
|
+
| ------------------- | -------------------------------------------------------------------------------------------------------- | ---------------- | ---------------------------------------------------------- |
|
|
297
|
+
| `element` | A component below the root threw while it rendered, in an effect, or in a lifecycle hook | the element type | The element shows nothing |
|
|
298
|
+
| `props` / `visible` | A prop expression or the `visible` condition of a child threw. `info.key` and `info.type` name the child | the parent type | The parent shows nothing |
|
|
299
|
+
| `action` / `watch` | A binding of an `on` event or of a `watch` failed. `info.action` names the action | the action name | The element stays |
|
|
300
|
+
| `root` | The component, the props or the `visible` condition of the root threw | the root type | The renderer shows nothing until a new version of the root |
|
|
301
|
+
|
|
302
|
+
- Without a handler, the renderer writes one `console.error` line, such as `[json-render] element error in <Text> "title":`, and then the error. A failure of the root never goes to the host, such as an `ErrorBoundary` above the renderer, so a root that streams in half done does not fail the application.
|
|
303
|
+
- A handler that throws gives its error to `reportError` one time. No other element fails.
|
|
304
|
+
- An error of code that the renderer does not run stays with the window: a listener of the component, a timer, or a promise that the component drops.
|
|
305
|
+
- An element of an unknown type with no `fallback` gives one `[json-render]` warning when it mounts. A `root` that names no element gives one warning, when the spec is not loading.
|
|
306
|
+
|
|
307
|
+
```tsx
|
|
308
|
+
<Renderer
|
|
309
|
+
spec={spec}
|
|
310
|
+
registry={registry}
|
|
311
|
+
onRenderError={(error, name, info) => report(error, info.kind, info.key)}
|
|
312
|
+
/>
|
|
313
|
+
```
|
|
314
|
+
|
|
237
315
|
## Key Exports
|
|
238
316
|
|
|
239
317
|
| Export | Purpose |
|
|
@@ -254,6 +332,8 @@ await stream.send("Build me a dashboard");
|
|
|
254
332
|
| `EventHandle` | Event metadata (`emit`, `bound`, `shouldPreventDefault`) |
|
|
255
333
|
| `StateStore` | Controlled state backend interface |
|
|
256
334
|
| `StateModel` | Renderer state model type |
|
|
335
|
+
| `OnRenderError` | The `onRenderError` handler: `(error, name, info)` |
|
|
336
|
+
| `RenderErrorInfo` | The `kind`, `key`, `type` and `action` of a failure |
|
|
257
337
|
| `SolidSchema` / `SolidSpec` | Solid schema/spec types |
|
|
258
338
|
|
|
259
339
|
## Differences from `@xmachines/json-render-react`
|
|
@@ -267,6 +347,23 @@ Most APIs are intentionally aligned, but there are runtime behavior differences
|
|
|
267
347
|
- Avoid props destructuring in component signatures when values should remain reactive.
|
|
268
348
|
- Hooks that read changing state return accessors; call them inside JSX or effects.
|
|
269
349
|
|
|
350
|
+
The renderer follows Solid, and not react, in these cases:
|
|
351
|
+
|
|
352
|
+
| Case | react | solid | Note |
|
|
353
|
+
| ------------------------------------------------- | -------------------------------------------- | --------------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
354
|
+
| Focus of a keyed move | react-dom gives the focus back | the focus goes to the body when `<For>` moves the focused node | As a hand-written `<For>` |
|
|
355
|
+
| Native `blur` of the focused row in a keyed move | react moves the rows with a lower old index | `reconcileArrays` of Solid moves other rows | |
|
|
356
|
+
| Config of a path with more fields | the field whose layout effect runs last | the field that registers last in the order of Solid | Solid gives no order of the effects of one update |
|
|
357
|
+
| Order of the `watch` of the elements | the order of the tree of now | the order in which Solid made the effects | |
|
|
358
|
+
| Handlers of a node that the renderer removes | do not run | run for each event that the browser fires, and each `emit` runs its binding | Solid binds a listener of the node |
|
|
359
|
+
| A config that reads the touch of its own field | keeps the touch | the touch changes the config, and the new config starts the field fresh | Do not make a config depend on its own touch |
|
|
360
|
+
| A later effect of a component whose effect throws | does not run | runs, and then the element fails one time | Solid gives the error to the boundary in an effect |
|
|
361
|
+
| Store writes outside a `batch` | one render after the handler | one update for each write: a hide and a show mount the field again | Wrap the writes in `batch()` |
|
|
362
|
+
| A `batch` inside another one | a nested `flushSync` commits when it returns | no flush of its own | "Nested `batch` calls behave like a single larger batch" |
|
|
363
|
+
| Plain path of a hook | read at each render | stays the path of the mount | Pass an accessor in a keyed row |
|
|
364
|
+
|
|
365
|
+
The [table of the renderer differences](https://gitlab.com/xmachin-es/json-render/-/blob/xmachines/main/XMACHINES.md#feature-parity-and-the-renderer-differences-react-vue-solid-svelte-dom) in `XMACHINES.md`, and the page `/docs/renderer-differences` of the docs site, compare all five renderers and name the test that holds each difference.
|
|
366
|
+
|
|
270
367
|
## Documentation
|
|
271
368
|
|
|
272
369
|
Full docs: [json-render.dev/docs/api/solid](https://json-render.dev/docs/api/solid)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/schema.ts
|
|
2
|
-
import { defineSchema } from "@xmachines/json-render-core";
|
|
2
|
+
import { builtInActionDefinitions, defineSchema } from "@xmachines/json-render-core";
|
|
3
3
|
var schema = defineSchema(
|
|
4
4
|
(s) => ({
|
|
5
5
|
// What the AI-generated SPEC looks like
|
|
@@ -46,24 +46,7 @@ var schema = defineSchema(
|
|
|
46
46
|
})
|
|
47
47
|
}),
|
|
48
48
|
{
|
|
49
|
-
builtInActions: [
|
|
50
|
-
{
|
|
51
|
-
name: "setState",
|
|
52
|
-
description: "Update a value in the state model at the given statePath. Params: { statePath: string, value: any }"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "pushState",
|
|
56
|
-
description: '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.'
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "removeState",
|
|
60
|
-
description: "Remove an item from an array in state by index. Params: { statePath: string, index: number }"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: "validateForm",
|
|
64
|
-
description: "Validate all registered form fields and write the result to state. Params: { statePath?: string }. Defaults to /formValidation. Result: { valid: boolean, errors: Record<string, string[]> }."
|
|
65
|
-
}
|
|
66
|
-
],
|
|
49
|
+
builtInActions: [...builtInActionDefinitions],
|
|
67
50
|
defaultRules: [
|
|
68
51
|
// Element integrity
|
|
69
52
|
"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.",
|
|
@@ -89,4 +72,4 @@ export {
|
|
|
89
72
|
schema,
|
|
90
73
|
elementTreeSchema
|
|
91
74
|
};
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
75
|
+
//# sourceMappingURL=chunk-ML2S7DVS.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schema.ts"],"sourcesContent":["import { builtInActionDefinitions, 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: [...builtInActionDefinitions],\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,0BAA0B,oBAAoB;AAShD,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,CAAC,GAAG,wBAAwB;AAAA,IAC5C,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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as solid_js from 'solid-js';
|
|
2
2
|
import { ParentProps, Accessor, JSX, Component } from 'solid-js';
|
|
3
|
-
import { StateStore, StateModel, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, ActionBinding, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams,
|
|
4
|
-
export { RenderErrorHandler, Spec, StateModel, StateStore, createStateStore } from '@xmachines/json-render-core';
|
|
3
|
+
import { StateStore, StateModel, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, ActionBinding, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams, OnRenderError, UIElement, SchemaDefinition, Spec, ComputedFunction, DirectiveDefinition, FlatElement } from '@xmachines/json-render-core';
|
|
4
|
+
export { OnRenderError, RenderErrorHandler, RenderErrorInfo, RenderErrorKind, Spec, StateModel, StateStore, createStateStore } from '@xmachines/json-render-core';
|
|
5
5
|
export { ElementTreeSchema, ElementTreeSpec, SolidSchema, SolidSpec, elementTreeSchema, schema } from './schema.mjs';
|
|
6
6
|
|
|
7
7
|
interface StateContextValue {
|
|
@@ -10,12 +10,6 @@ interface StateContextValue {
|
|
|
10
10
|
set: (path: string, value: unknown) => void;
|
|
11
11
|
update: (updates: Record<string, unknown>) => void;
|
|
12
12
|
getSnapshot: () => StateModel;
|
|
13
|
-
/**
|
|
14
|
-
* Hear the paths that `set` and `update` of this context write. The watch
|
|
15
|
-
* of the renderer reads the reactive state and does not use it, because a
|
|
16
|
-
* write from the store or to a parent path emits no change here. It stays
|
|
17
|
-
* for hosts that use it.
|
|
18
|
-
*/
|
|
19
13
|
subscribeChanges: (listener: (changes: Array<{
|
|
20
14
|
path: string;
|
|
21
15
|
value: unknown;
|
|
@@ -31,8 +25,19 @@ interface StateProviderProps {
|
|
|
31
25
|
}
|
|
32
26
|
declare function StateProvider(props: ParentProps<StateProviderProps>): solid_js.JSX.Element;
|
|
33
27
|
declare function useStateStore(): StateContextValue;
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The value of the state at `path`.
|
|
30
|
+
*
|
|
31
|
+
* @param path - The path, or an accessor of the path, such as
|
|
32
|
+
* `() => props.bindings?.value`, which follows the path of now.
|
|
33
|
+
*/
|
|
34
|
+
declare function useStateValue<T>(path: string | Accessor<string | undefined>): Accessor<T | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* The value of the state at `path`, and a setter of it.
|
|
37
|
+
*
|
|
38
|
+
* @param path - The path, or an accessor of the path (see `useStateValue`).
|
|
39
|
+
*/
|
|
40
|
+
declare function useStateBinding<T>(path: string | Accessor<string | undefined>): [Accessor<T | undefined>, (value: T) => void];
|
|
36
41
|
|
|
37
42
|
interface VisibilityContextValue {
|
|
38
43
|
isVisible: (condition: VisibilityCondition | undefined) => boolean;
|
|
@@ -90,10 +95,9 @@ interface ValidationContextValue {
|
|
|
90
95
|
validateAll: () => boolean;
|
|
91
96
|
registerField: (path: string, config: ValidationConfig) => void;
|
|
92
97
|
/**
|
|
93
|
-
* Release one registration
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* later screen (their bound state no longer exists there).
|
|
98
|
+
* Release one registration of the path. The last release drops the config
|
|
99
|
+
* and the state of the path, so a field of an earlier screen does not fail
|
|
100
|
+
* `validateAll` on a later one.
|
|
97
101
|
*/
|
|
98
102
|
unregisterField: (path: string) => void;
|
|
99
103
|
}
|
|
@@ -103,7 +107,19 @@ interface ValidationProviderProps {
|
|
|
103
107
|
declare function ValidationProvider(props: ParentProps<ValidationProviderProps>): solid_js.JSX.Element;
|
|
104
108
|
declare function useValidation(): ValidationContextValue;
|
|
105
109
|
declare function useOptionalValidation(): ValidationContextValue | null;
|
|
106
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The validation of the field of `path`.
|
|
112
|
+
*
|
|
113
|
+
* @param path - The path, or an accessor of the path, such as
|
|
114
|
+
* `() => props.bindings?.value`. A Solid component runs one time, so a
|
|
115
|
+
* plain path is the path of the mount. An accessor follows the path of
|
|
116
|
+
* now: in a row of a keyed repeat that moves, and for a binding that a
|
|
117
|
+
* later spec adds or removes.
|
|
118
|
+
* @param config - The config, or an accessor of it, such as
|
|
119
|
+
* `() => ({ checks: [...props.checks] })`. A config with a new value
|
|
120
|
+
* registers the field again.
|
|
121
|
+
*/
|
|
122
|
+
declare function useFieldValidation(path: string | Accessor<string | undefined>, config?: ValidationConfig | Accessor<ValidationConfig | undefined>): {
|
|
107
123
|
state: Accessor<FieldValidationState>;
|
|
108
124
|
validate: () => ValidationResult;
|
|
109
125
|
touch: () => void;
|
|
@@ -119,11 +135,9 @@ interface RepeatScopeValue {
|
|
|
119
135
|
}
|
|
120
136
|
declare function RepeatScopeProvider(props: ParentProps<RepeatScopeValue>): solid_js.JSX.Element;
|
|
121
137
|
/**
|
|
122
|
-
* The repeat scope of the row
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* an effect. A row stays mounted across a write to its own item, so a copy
|
|
126
|
-
* that the component makes when it is set up keeps the item of then.
|
|
138
|
+
* The repeat scope of the row, or `null` outside a repeat. Read `item`,
|
|
139
|
+
* `index` and `basePath` in a tracked place, because a row stays mounted
|
|
140
|
+
* when its item changes.
|
|
127
141
|
*/
|
|
128
142
|
declare function useRepeatScope(): RepeatScopeValue | null;
|
|
129
143
|
|
|
@@ -283,8 +297,8 @@ interface RendererProps {
|
|
|
283
297
|
loading?: boolean;
|
|
284
298
|
/** Fallback component for unknown types */
|
|
285
299
|
fallback?: ComponentRenderer;
|
|
286
|
-
/** Callback for
|
|
287
|
-
onRenderError?:
|
|
300
|
+
/** Callback for each failure of the render, an action or a watch */
|
|
301
|
+
onRenderError?: OnRenderError;
|
|
288
302
|
}
|
|
289
303
|
/**
|
|
290
304
|
* Main renderer component
|
|
@@ -350,7 +364,7 @@ interface DefineRegistryResult {
|
|
|
350
364
|
*/
|
|
351
365
|
type DefineRegistryOptions<C extends Catalog> = {
|
|
352
366
|
components?: Components<C>;
|
|
353
|
-
onRenderError?:
|
|
367
|
+
onRenderError?: OnRenderError;
|
|
354
368
|
} & (CatalogHasActions<C> extends true ? {
|
|
355
369
|
actions: Actions<C>;
|
|
356
370
|
} : {
|
|
@@ -408,8 +422,8 @@ interface CreateRendererProps {
|
|
|
408
422
|
loading?: boolean;
|
|
409
423
|
/** Fallback component for unknown types */
|
|
410
424
|
fallback?: ComponentRenderer;
|
|
411
|
-
/** Callback for
|
|
412
|
-
onRenderError?:
|
|
425
|
+
/** Callback for each failure of the render, an action or a watch */
|
|
426
|
+
onRenderError?: OnRenderError;
|
|
413
427
|
}
|
|
414
428
|
/**
|
|
415
429
|
* Component map type - maps component names to Solid components
|
|
@@ -499,17 +513,23 @@ declare function flatToTree(elements: FlatElement[]): Spec;
|
|
|
499
513
|
* Designed to work with the `bindings` map that the renderer provides when
|
|
500
514
|
* a prop uses `{ $bindState: "/path" }` or `{ $bindItem: "field" }`.
|
|
501
515
|
*
|
|
516
|
+
* `bindingPath` can be an accessor, such as `() => ctx.bindings?.value`,
|
|
517
|
+
* which follows the path of now. A plain path is the path of the mount.
|
|
518
|
+
*
|
|
502
519
|
* @example
|
|
503
520
|
* ```tsx
|
|
504
521
|
* import { useBoundProp } from "@xmachines/json-render-solid";
|
|
505
522
|
*
|
|
506
523
|
* const Input: ComponentRenderer = (ctx) => {
|
|
507
|
-
* const [value, setValue] = useBoundProp<string>(
|
|
524
|
+
* const [value, setValue] = useBoundProp<string>(
|
|
525
|
+
* ctx.props.value,
|
|
526
|
+
* () => ctx.bindings?.value,
|
|
527
|
+
* );
|
|
508
528
|
* return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
|
|
509
529
|
* };
|
|
510
530
|
* ```
|
|
511
531
|
*/
|
|
512
|
-
declare function useBoundProp<T>(propValue: T | undefined, bindingPath: string | undefined): [T | undefined, (value: T) => void];
|
|
532
|
+
declare function useBoundProp<T>(propValue: T | undefined, bindingPath: string | undefined | Accessor<string | undefined>): [T | undefined, (value: T) => void];
|
|
513
533
|
/**
|
|
514
534
|
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
515
535
|
* structural type so that library helpers do not depend on the AI SDK.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as solid_js from 'solid-js';
|
|
2
2
|
import { ParentProps, Accessor, JSX, Component } from 'solid-js';
|
|
3
|
-
import { StateStore, StateModel, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, ActionBinding, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams,
|
|
4
|
-
export { RenderErrorHandler, Spec, StateModel, StateStore, createStateStore } from '@xmachines/json-render-core';
|
|
3
|
+
import { StateStore, StateModel, VisibilityCondition, VisibilityContext, ActionHandler, ResolvedAction, ActionBinding, ActionConfirm, ValidationFunction, ValidationResult, ValidationConfig, Catalog, InferCatalogComponents, InferComponentProps, InferCatalogActions, InferActionParams, OnRenderError, UIElement, SchemaDefinition, Spec, ComputedFunction, DirectiveDefinition, FlatElement } from '@xmachines/json-render-core';
|
|
4
|
+
export { OnRenderError, RenderErrorHandler, RenderErrorInfo, RenderErrorKind, Spec, StateModel, StateStore, createStateStore } from '@xmachines/json-render-core';
|
|
5
5
|
export { ElementTreeSchema, ElementTreeSpec, SolidSchema, SolidSpec, elementTreeSchema, schema } from './schema.js';
|
|
6
6
|
|
|
7
7
|
interface StateContextValue {
|
|
@@ -10,12 +10,6 @@ interface StateContextValue {
|
|
|
10
10
|
set: (path: string, value: unknown) => void;
|
|
11
11
|
update: (updates: Record<string, unknown>) => void;
|
|
12
12
|
getSnapshot: () => StateModel;
|
|
13
|
-
/**
|
|
14
|
-
* Hear the paths that `set` and `update` of this context write. The watch
|
|
15
|
-
* of the renderer reads the reactive state and does not use it, because a
|
|
16
|
-
* write from the store or to a parent path emits no change here. It stays
|
|
17
|
-
* for hosts that use it.
|
|
18
|
-
*/
|
|
19
13
|
subscribeChanges: (listener: (changes: Array<{
|
|
20
14
|
path: string;
|
|
21
15
|
value: unknown;
|
|
@@ -31,8 +25,19 @@ interface StateProviderProps {
|
|
|
31
25
|
}
|
|
32
26
|
declare function StateProvider(props: ParentProps<StateProviderProps>): solid_js.JSX.Element;
|
|
33
27
|
declare function useStateStore(): StateContextValue;
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The value of the state at `path`.
|
|
30
|
+
*
|
|
31
|
+
* @param path - The path, or an accessor of the path, such as
|
|
32
|
+
* `() => props.bindings?.value`, which follows the path of now.
|
|
33
|
+
*/
|
|
34
|
+
declare function useStateValue<T>(path: string | Accessor<string | undefined>): Accessor<T | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* The value of the state at `path`, and a setter of it.
|
|
37
|
+
*
|
|
38
|
+
* @param path - The path, or an accessor of the path (see `useStateValue`).
|
|
39
|
+
*/
|
|
40
|
+
declare function useStateBinding<T>(path: string | Accessor<string | undefined>): [Accessor<T | undefined>, (value: T) => void];
|
|
36
41
|
|
|
37
42
|
interface VisibilityContextValue {
|
|
38
43
|
isVisible: (condition: VisibilityCondition | undefined) => boolean;
|
|
@@ -90,10 +95,9 @@ interface ValidationContextValue {
|
|
|
90
95
|
validateAll: () => boolean;
|
|
91
96
|
registerField: (path: string, config: ValidationConfig) => void;
|
|
92
97
|
/**
|
|
93
|
-
* Release one registration
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* later screen (their bound state no longer exists there).
|
|
98
|
+
* Release one registration of the path. The last release drops the config
|
|
99
|
+
* and the state of the path, so a field of an earlier screen does not fail
|
|
100
|
+
* `validateAll` on a later one.
|
|
97
101
|
*/
|
|
98
102
|
unregisterField: (path: string) => void;
|
|
99
103
|
}
|
|
@@ -103,7 +107,19 @@ interface ValidationProviderProps {
|
|
|
103
107
|
declare function ValidationProvider(props: ParentProps<ValidationProviderProps>): solid_js.JSX.Element;
|
|
104
108
|
declare function useValidation(): ValidationContextValue;
|
|
105
109
|
declare function useOptionalValidation(): ValidationContextValue | null;
|
|
106
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The validation of the field of `path`.
|
|
112
|
+
*
|
|
113
|
+
* @param path - The path, or an accessor of the path, such as
|
|
114
|
+
* `() => props.bindings?.value`. A Solid component runs one time, so a
|
|
115
|
+
* plain path is the path of the mount. An accessor follows the path of
|
|
116
|
+
* now: in a row of a keyed repeat that moves, and for a binding that a
|
|
117
|
+
* later spec adds or removes.
|
|
118
|
+
* @param config - The config, or an accessor of it, such as
|
|
119
|
+
* `() => ({ checks: [...props.checks] })`. A config with a new value
|
|
120
|
+
* registers the field again.
|
|
121
|
+
*/
|
|
122
|
+
declare function useFieldValidation(path: string | Accessor<string | undefined>, config?: ValidationConfig | Accessor<ValidationConfig | undefined>): {
|
|
107
123
|
state: Accessor<FieldValidationState>;
|
|
108
124
|
validate: () => ValidationResult;
|
|
109
125
|
touch: () => void;
|
|
@@ -119,11 +135,9 @@ interface RepeatScopeValue {
|
|
|
119
135
|
}
|
|
120
136
|
declare function RepeatScopeProvider(props: ParentProps<RepeatScopeValue>): solid_js.JSX.Element;
|
|
121
137
|
/**
|
|
122
|
-
* The repeat scope of the row
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* an effect. A row stays mounted across a write to its own item, so a copy
|
|
126
|
-
* that the component makes when it is set up keeps the item of then.
|
|
138
|
+
* The repeat scope of the row, or `null` outside a repeat. Read `item`,
|
|
139
|
+
* `index` and `basePath` in a tracked place, because a row stays mounted
|
|
140
|
+
* when its item changes.
|
|
127
141
|
*/
|
|
128
142
|
declare function useRepeatScope(): RepeatScopeValue | null;
|
|
129
143
|
|
|
@@ -283,8 +297,8 @@ interface RendererProps {
|
|
|
283
297
|
loading?: boolean;
|
|
284
298
|
/** Fallback component for unknown types */
|
|
285
299
|
fallback?: ComponentRenderer;
|
|
286
|
-
/** Callback for
|
|
287
|
-
onRenderError?:
|
|
300
|
+
/** Callback for each failure of the render, an action or a watch */
|
|
301
|
+
onRenderError?: OnRenderError;
|
|
288
302
|
}
|
|
289
303
|
/**
|
|
290
304
|
* Main renderer component
|
|
@@ -350,7 +364,7 @@ interface DefineRegistryResult {
|
|
|
350
364
|
*/
|
|
351
365
|
type DefineRegistryOptions<C extends Catalog> = {
|
|
352
366
|
components?: Components<C>;
|
|
353
|
-
onRenderError?:
|
|
367
|
+
onRenderError?: OnRenderError;
|
|
354
368
|
} & (CatalogHasActions<C> extends true ? {
|
|
355
369
|
actions: Actions<C>;
|
|
356
370
|
} : {
|
|
@@ -408,8 +422,8 @@ interface CreateRendererProps {
|
|
|
408
422
|
loading?: boolean;
|
|
409
423
|
/** Fallback component for unknown types */
|
|
410
424
|
fallback?: ComponentRenderer;
|
|
411
|
-
/** Callback for
|
|
412
|
-
onRenderError?:
|
|
425
|
+
/** Callback for each failure of the render, an action or a watch */
|
|
426
|
+
onRenderError?: OnRenderError;
|
|
413
427
|
}
|
|
414
428
|
/**
|
|
415
429
|
* Component map type - maps component names to Solid components
|
|
@@ -499,17 +513,23 @@ declare function flatToTree(elements: FlatElement[]): Spec;
|
|
|
499
513
|
* Designed to work with the `bindings` map that the renderer provides when
|
|
500
514
|
* a prop uses `{ $bindState: "/path" }` or `{ $bindItem: "field" }`.
|
|
501
515
|
*
|
|
516
|
+
* `bindingPath` can be an accessor, such as `() => ctx.bindings?.value`,
|
|
517
|
+
* which follows the path of now. A plain path is the path of the mount.
|
|
518
|
+
*
|
|
502
519
|
* @example
|
|
503
520
|
* ```tsx
|
|
504
521
|
* import { useBoundProp } from "@xmachines/json-render-solid";
|
|
505
522
|
*
|
|
506
523
|
* const Input: ComponentRenderer = (ctx) => {
|
|
507
|
-
* const [value, setValue] = useBoundProp<string>(
|
|
524
|
+
* const [value, setValue] = useBoundProp<string>(
|
|
525
|
+
* ctx.props.value,
|
|
526
|
+
* () => ctx.bindings?.value,
|
|
527
|
+
* );
|
|
508
528
|
* return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
|
|
509
529
|
* };
|
|
510
530
|
* ```
|
|
511
531
|
*/
|
|
512
|
-
declare function useBoundProp<T>(propValue: T | undefined, bindingPath: string | undefined): [T | undefined, (value: T) => void];
|
|
532
|
+
declare function useBoundProp<T>(propValue: T | undefined, bindingPath: string | undefined | Accessor<string | undefined>): [T | undefined, (value: T) => void];
|
|
513
533
|
/**
|
|
514
534
|
* A single part from the AI SDK's `message.parts` array. This is a minimal
|
|
515
535
|
* structural type so that library helpers do not depend on the AI SDK.
|