@xmachines/json-render-solid 0.21.0-xm.7 → 0.23.1-xm.1

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 CHANGED
@@ -57,6 +57,8 @@ export const catalog = defineCatalog(schema, {
57
57
 
58
58
  `defineRegistry` conditionally requires the `actions` field only when the catalog declares actions.
59
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
+
60
62
  ```tsx
61
63
  import { defineRegistry, useBoundProp } from "@xmachines/json-render-solid";
62
64
  import { catalog } from "./catalog";
@@ -85,7 +87,7 @@ export const { registry } = defineRegistry(catalog, {
85
87
  {ctx.props.label}
86
88
  <input
87
89
  value={String(ctx.props.value ?? "")}
88
- placeholder={ctx.props.placeholder ?? ""}
90
+ placeholder={String(ctx.props.placeholder ?? "")}
89
91
  onInput={(e) => setValue(e.currentTarget.value)}
90
92
  />
91
93
  </label>
@@ -102,16 +104,18 @@ export const { registry } = defineRegistry(catalog, {
102
104
  ### 3. Render Specs
103
105
 
104
106
  ```tsx
105
- import { Renderer, StateProvider, ActionProvider } from "@xmachines/json-render-solid";
107
+ import { Renderer, JSONUIProvider } from "@xmachines/json-render-solid";
106
108
  import { registry } from "./registry";
107
109
 
108
110
  export function App(props: { spec: any }) {
109
111
  return (
110
- <StateProvider initialState={{ form: { name: "" } }}>
111
- <ActionProvider handlers={{ submit: () => console.log("submit") }}>
112
- <Renderer spec={props.spec} registry={registry} />
113
- </ActionProvider>
114
- </StateProvider>
112
+ <JSONUIProvider
113
+ registry={registry}
114
+ initialState={{ form: { name: "" } }}
115
+ handlers={{ submit: () => console.log("submit") }}
116
+ >
117
+ <Renderer spec={props.spec} registry={registry} />
118
+ </JSONUIProvider>
115
119
  );
116
120
  }
117
121
  ```
@@ -202,7 +206,7 @@ const store = createStateStore({ count: 0 });
202
206
  | `useActions()` / `useAction()` | Action context and single-action helper |
203
207
  | `useValidation()` / `useOptionalValidation()` | Validation context (throwing/non-throwing) |
204
208
  | `useFieldValidation(path, config)` | Field state accessors plus validate/touch/clear |
205
- | `useBoundProp(value, binding)` | Fine-grained two-way binding helper |
209
+ | `useBoundProp(value, binding)` | Resolved prop value plus a write-back setter |
206
210
  | `useUIStream(options)` | Stream UI specs from an endpoint |
207
211
  | `useChatUI(options)` | Chat-style spec generation hook |
208
212
 
package/dist/index.d.mts CHANGED
@@ -347,7 +347,8 @@ interface DefineRegistryResult {
347
347
  /**
348
348
  * Create ActionProvider-compatible handlers.
349
349
  * Accepts getter functions so handlers always read the latest state/setState
350
- * (e.g. from refs or closures).
350
+ * (e.g. from refs or closures). When `getSetState` returns `undefined`, actions
351
+ * still run and receive a no-op setter, so state updates are discarded.
351
352
  */
352
353
  handlers: (getSetState: () => SetState | undefined, getState: () => StateModel) => Record<string, (params: Record<string, unknown>) => Promise<void>>;
353
354
  /**
@@ -521,11 +522,11 @@ declare function flatToTree(elements: FlatElement[]): Spec;
521
522
  * import { useBoundProp } from "@xmachines/json-render-solid";
522
523
  *
523
524
  * const Input: ComponentRenderer = (ctx) => {
524
- * const [value, setValue] = useBoundProp<string>(
525
+ * const [, setValue] = useBoundProp<string>(
525
526
  * ctx.props.value,
526
527
  * () => ctx.bindings?.value,
527
528
  * );
528
- * return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
529
+ * return <input value={ctx.props.value ?? ""} onInput={(e) => setValue(e.target.value)} />;
529
530
  * };
530
531
  * ```
531
532
  */
package/dist/index.d.ts CHANGED
@@ -347,7 +347,8 @@ interface DefineRegistryResult {
347
347
  /**
348
348
  * Create ActionProvider-compatible handlers.
349
349
  * Accepts getter functions so handlers always read the latest state/setState
350
- * (e.g. from refs or closures).
350
+ * (e.g. from refs or closures). When `getSetState` returns `undefined`, actions
351
+ * still run and receive a no-op setter, so state updates are discarded.
351
352
  */
352
353
  handlers: (getSetState: () => SetState | undefined, getState: () => StateModel) => Record<string, (params: Record<string, unknown>) => Promise<void>>;
353
354
  /**
@@ -521,11 +522,11 @@ declare function flatToTree(elements: FlatElement[]): Spec;
521
522
  * import { useBoundProp } from "@xmachines/json-render-solid";
522
523
  *
523
524
  * const Input: ComponentRenderer = (ctx) => {
524
- * const [value, setValue] = useBoundProp<string>(
525
+ * const [, setValue] = useBoundProp<string>(
525
526
  * ctx.props.value,
526
527
  * () => ctx.bindings?.value,
527
528
  * );
528
- * return <input value={value ?? ""} onInput={(e) => setValue(e.target.value)} />;
529
+ * return <input value={ctx.props.value ?? ""} onInput={(e) => setValue(e.target.value)} />;
529
530
  * };
530
531
  * ```
531
532
  */
package/dist/index.js CHANGED
@@ -1738,11 +1738,9 @@ function defineRegistry(catalog, options) {
1738
1738
  const result = {};
1739
1739
  for (const [name, actionFn] of actionMap) {
1740
1740
  result[name] = async (params) => {
1741
- const setState = getSetState();
1741
+ const setState = getSetState() ?? (() => void 0);
1742
1742
  const state = getState();
1743
- if (setState) {
1744
- await actionFn(params, setState, state);
1745
- }
1743
+ await actionFn(params, setState, state);
1746
1744
  };
1747
1745
  }
1748
1746
  return result;
@@ -2138,6 +2136,9 @@ function isSpecDataPart(data) {
2138
2136
  return false;
2139
2137
  }
2140
2138
  }
2139
+ function cloneJson(value) {
2140
+ return JSON.parse(JSON.stringify(value));
2141
+ }
2141
2142
  function buildSpecFromParts(parts) {
2142
2143
  const spec = { root: "", elements: {} };
2143
2144
  let hasSpec = false;
@@ -2147,13 +2148,13 @@ function buildSpecFromParts(parts) {
2147
2148
  const payload = part.data;
2148
2149
  if (payload.type === "patch") {
2149
2150
  hasSpec = true;
2150
- (0, import_core8.applySpecPatch)(spec, payload.patch);
2151
+ (0, import_core8.applySpecPatch)(spec, cloneJson(payload.patch));
2151
2152
  } else if (payload.type === "flat") {
2152
2153
  hasSpec = true;
2153
- Object.assign(spec, payload.spec);
2154
+ Object.assign(spec, cloneJson(payload.spec));
2154
2155
  } else if (payload.type === "nested") {
2155
2156
  hasSpec = true;
2156
- const flat = (0, import_core8.nestedToFlat)(payload.spec);
2157
+ const flat = (0, import_core8.nestedToFlat)(cloneJson(payload.spec));
2157
2158
  Object.assign(spec, flat);
2158
2159
  }
2159
2160
  }