@json-render/solid 0.21.1 → 0.21.3
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 +21 -15
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -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
|
}),
|
|
@@ -55,6 +57,8 @@ export const catalog = defineCatalog(schema, {
|
|
|
55
57
|
|
|
56
58
|
`defineRegistry` conditionally requires the `actions` field only when the catalog declares actions.
|
|
57
59
|
|
|
60
|
+
Registry callbacks receive resolved values through `renderProps.props`. Read changing values inside JSX to preserve Solid's reactivity; `useBoundProp` returns a scalar value and a write-back setter, not an accessor.
|
|
61
|
+
|
|
58
62
|
```tsx
|
|
59
63
|
import { defineRegistry, useBoundProp } from "@json-render/solid";
|
|
60
64
|
import { catalog } from "./catalog";
|
|
@@ -63,26 +67,26 @@ export const { registry } = defineRegistry(catalog, {
|
|
|
63
67
|
components: {
|
|
64
68
|
Card: (renderProps) => (
|
|
65
69
|
<div class="card">
|
|
66
|
-
<h3>{renderProps.
|
|
70
|
+
<h3>{renderProps.props.title}</h3>
|
|
67
71
|
{renderProps.children}
|
|
68
72
|
</div>
|
|
69
73
|
),
|
|
70
74
|
Button: (renderProps) => (
|
|
71
75
|
<button onClick={() => renderProps.emit("press")}>
|
|
72
|
-
{renderProps.
|
|
76
|
+
{renderProps.props.label}
|
|
73
77
|
</button>
|
|
74
78
|
),
|
|
75
79
|
Input: (renderProps) => {
|
|
76
|
-
const [
|
|
77
|
-
renderProps.
|
|
80
|
+
const [, setValue] = useBoundProp(
|
|
81
|
+
renderProps.props.value,
|
|
78
82
|
renderProps.bindings?.value,
|
|
79
83
|
);
|
|
80
84
|
return (
|
|
81
85
|
<label>
|
|
82
|
-
{renderProps.
|
|
86
|
+
{renderProps.props.label}
|
|
83
87
|
<input
|
|
84
|
-
value={String(value
|
|
85
|
-
placeholder={String(renderProps.
|
|
88
|
+
value={String(renderProps.props.value ?? "")}
|
|
89
|
+
placeholder={String(renderProps.props.placeholder ?? "")}
|
|
86
90
|
onInput={(e) => setValue(e.currentTarget.value)}
|
|
87
91
|
/>
|
|
88
92
|
</label>
|
|
@@ -99,16 +103,18 @@ export const { registry } = defineRegistry(catalog, {
|
|
|
99
103
|
### 3. Render Specs
|
|
100
104
|
|
|
101
105
|
```tsx
|
|
102
|
-
import { Renderer,
|
|
106
|
+
import { Renderer, JSONUIProvider } from "@json-render/solid";
|
|
103
107
|
import { registry } from "./registry";
|
|
104
108
|
|
|
105
109
|
export function App(props: { spec: any }) {
|
|
106
110
|
return (
|
|
107
|
-
<
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
<JSONUIProvider
|
|
112
|
+
registry={registry}
|
|
113
|
+
initialState={{ form: { name: "" } }}
|
|
114
|
+
handlers={{ submit: () => console.log("submit") }}
|
|
115
|
+
>
|
|
116
|
+
<Renderer spec={props.spec} registry={registry} />
|
|
117
|
+
</JSONUIProvider>
|
|
112
118
|
);
|
|
113
119
|
}
|
|
114
120
|
```
|
|
@@ -168,7 +174,7 @@ const store = createStateStore({ count: 0 });
|
|
|
168
174
|
| `useActions()` / `useAction()` | Action context and single-action helper |
|
|
169
175
|
| `useValidation()` / `useOptionalValidation()` | Validation context (throwing/non-throwing) |
|
|
170
176
|
| `useFieldValidation(path, config)` | Field state accessors plus validate/touch/clear |
|
|
171
|
-
| `useBoundProp(value, binding)` |
|
|
177
|
+
| `useBoundProp(value, binding)` | Resolved prop value plus a write-back setter |
|
|
172
178
|
| `useUIStream(options)` | Stream UI specs from an endpoint |
|
|
173
179
|
| `useChatUI(options)` | Chat-style spec generation hook |
|
|
174
180
|
|
package/dist/index.d.mts
CHANGED
|
@@ -468,8 +468,8 @@ declare function flatToTree(elements: FlatElement[]): Spec;
|
|
|
468
468
|
* import { useBoundProp } from "@json-render/solid";
|
|
469
469
|
*
|
|
470
470
|
* const Input: ComponentRenderer = (ctx) => {
|
|
471
|
-
* const [
|
|
472
|
-
* return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
|
|
471
|
+
* const [, setValue] = useBoundProp<string>(ctx.props.value, ctx.bindings?.value);
|
|
472
|
+
* return <input value={ctx.props.value ?? ""} onInput={(e) => setValue(e.target.value)} />;
|
|
473
473
|
* };
|
|
474
474
|
* ```
|
|
475
475
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -468,8 +468,8 @@ declare function flatToTree(elements: FlatElement[]): Spec;
|
|
|
468
468
|
* import { useBoundProp } from "@json-render/solid";
|
|
469
469
|
*
|
|
470
470
|
* const Input: ComponentRenderer = (ctx) => {
|
|
471
|
-
* const [
|
|
472
|
-
* return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
|
|
471
|
+
* const [, setValue] = useBoundProp<string>(ctx.props.value, ctx.bindings?.value);
|
|
472
|
+
* return <input value={ctx.props.value ?? ""} onInput={(e) => setValue(e.target.value)} />;
|
|
473
473
|
* };
|
|
474
474
|
* ```
|
|
475
475
|
*/
|