@json-render/core 0.7.0 → 0.9.0
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 +83 -0
- package/dist/chunk-4ZGEEX7K.mjs +718 -0
- package/dist/chunk-4ZGEEX7K.mjs.map +1 -0
- package/dist/index.d.mts +3 -734
- package/dist/index.d.ts +3 -734
- package/dist/index.js +79 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -615
- package/dist/index.mjs.map +1 -1
- package/dist/store-utils-DHnkfKAT.d.mts +817 -0
- package/dist/store-utils-DHnkfKAT.d.ts +817 -0
- package/dist/store-utils.d.mts +2 -0
- package/dist/store-utils.d.ts +2 -0
- package/dist/store-utils.js +176 -0
- package/dist/store-utils.js.map +1 -0
- package/dist/store-utils.mjs +11 -0
- package/dist/store-utils.mjs.map +1 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -157,6 +157,14 @@ const spec = compileSpecStream<MySpec>(jsonlString);
|
|
|
157
157
|
| `defineSchema(builder, options?)` | Create a schema with spec/catalog structure |
|
|
158
158
|
| `SchemaBuilder` | Builder with `s.object()`, `s.array()`, `s.map()`, etc. |
|
|
159
159
|
|
|
160
|
+
Schema options:
|
|
161
|
+
|
|
162
|
+
| Option | Purpose |
|
|
163
|
+
|--------|---------|
|
|
164
|
+
| `promptTemplate` | Custom AI prompt generator |
|
|
165
|
+
| `defaultRules` | Default rules injected before custom rules in prompts |
|
|
166
|
+
| `builtInActions` | Actions always available at runtime, auto-injected into prompts (e.g. `setState`) |
|
|
167
|
+
|
|
160
168
|
### Catalog
|
|
161
169
|
|
|
162
170
|
| Export | Purpose |
|
|
@@ -196,12 +204,87 @@ const spec = compileSpecStream<MySpec>(jsonlString);
|
|
|
196
204
|
| `autoFixSpec(spec)` | Auto-fix common spec issues (returns corrected copy) |
|
|
197
205
|
| `formatSpecIssues(issues)` | Format validation issues as readable strings |
|
|
198
206
|
|
|
207
|
+
### Actions
|
|
208
|
+
|
|
209
|
+
| Export | Purpose |
|
|
210
|
+
|--------|---------|
|
|
211
|
+
| `ActionBinding` | Action binding with `action`, `params`, `confirm`, `preventDefault`, etc. |
|
|
212
|
+
| `BuiltInAction` | Built-in action definition with `name` and `description` |
|
|
213
|
+
|
|
214
|
+
### Chat Mode (Mixed Streams)
|
|
215
|
+
|
|
216
|
+
| Export | Purpose |
|
|
217
|
+
|--------|---------|
|
|
218
|
+
| `createJsonRenderTransform()` | TransformStream that separates text from JSONL patches in a mixed stream |
|
|
219
|
+
| `pipeJsonRender()` | Server-side helper to pipe a mixed stream through the transform |
|
|
220
|
+
| `SPEC_DATA_PART` / `SPEC_DATA_PART_TYPE` | Constants for filtering spec data parts |
|
|
221
|
+
|
|
222
|
+
The transform splits text blocks around spec data by emitting `text-end`/`text-start` pairs, ensuring the AI SDK creates separate text parts and preserving correct interleaving of prose and UI in `message.parts`.
|
|
223
|
+
|
|
224
|
+
### State Store
|
|
225
|
+
|
|
226
|
+
| Export | Purpose |
|
|
227
|
+
|--------|---------|
|
|
228
|
+
| `createStateStore(initialState?)` | Create a framework-agnostic in-memory `StateStore` |
|
|
229
|
+
| `StateStore` | Interface for plugging in external state management (Redux, Zustand, XState, etc.) |
|
|
230
|
+
| `StateModel` | State model type (`Record<string, unknown>`) |
|
|
231
|
+
|
|
232
|
+
The `StateStore` interface allows renderers to use external state management instead of the built-in internal store:
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { createStateStore, type StateStore } from "@json-render/core";
|
|
236
|
+
|
|
237
|
+
// Simple in-memory store
|
|
238
|
+
const store = createStateStore({ count: 0 });
|
|
239
|
+
|
|
240
|
+
store.get("/count"); // 0
|
|
241
|
+
store.set("/count", 1); // updates and notifies subscribers
|
|
242
|
+
store.getSnapshot(); // { count: 1 }
|
|
243
|
+
|
|
244
|
+
// Subscribe to changes (compatible with React's useSyncExternalStore)
|
|
245
|
+
const unsubscribe = store.subscribe(() => {
|
|
246
|
+
console.log("state changed:", store.getSnapshot());
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Pass the store to `StateProvider` in any renderer package (`@json-render/react`, `@json-render/react-native`, `@json-render/react-pdf`) for controlled mode.
|
|
251
|
+
|
|
252
|
+
### Store Utilities (for adapter authors)
|
|
253
|
+
|
|
254
|
+
Available via `@json-render/core/store-utils`:
|
|
255
|
+
|
|
256
|
+
| Export | Purpose |
|
|
257
|
+
|--------|---------|
|
|
258
|
+
| `createStoreAdapter(config)` | Build a full `StateStore` from a minimal `{ getSnapshot, setSnapshot, subscribe }` config |
|
|
259
|
+
| `immutableSetByPath(root, path, value)` | Immutably set a value at a JSON Pointer path with structural sharing |
|
|
260
|
+
| `flattenToPointers(obj)` | Flatten a nested object into JSON Pointer keyed entries |
|
|
261
|
+
| `StoreAdapterConfig` | Config type for `createStoreAdapter` |
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import { createStoreAdapter, immutableSetByPath, flattenToPointers } from "@json-render/core/store-utils";
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
`createStoreAdapter` handles `get`, `set` (with no-op detection), batched `update`, `getSnapshot`, `getServerSnapshot`, and `subscribe` -- adapter authors only need to supply the snapshot source, write API, and subscribe mechanism:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { createStoreAdapter } from "@json-render/core/store-utils";
|
|
271
|
+
|
|
272
|
+
const store = createStoreAdapter({
|
|
273
|
+
getSnapshot: () => myLib.getState(),
|
|
274
|
+
setSnapshot: (next) => myLib.setState(next),
|
|
275
|
+
subscribe: (listener) => myLib.subscribe(listener),
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The official adapter packages (`@json-render/redux`, `@json-render/zustand`, `@json-render/jotai`) are all built on top of `createStoreAdapter`.
|
|
280
|
+
|
|
199
281
|
### Types
|
|
200
282
|
|
|
201
283
|
| Export | Purpose |
|
|
202
284
|
|--------|---------|
|
|
203
285
|
| `Spec` | Base spec type |
|
|
204
286
|
| `Catalog` | Catalog type |
|
|
287
|
+
| `BuiltInAction` | Built-in action type (`name` + `description`) |
|
|
205
288
|
| `VisibilityCondition` | Visibility condition type (used by `$cond`) |
|
|
206
289
|
| `VisibilityContext` | Context for evaluating visibility and prop expressions |
|
|
207
290
|
| `SpecStreamLine` | Single patch operation |
|