@json-render/core 0.8.0 → 0.9.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 +57 -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
|
@@ -221,6 +221,63 @@ Schema options:
|
|
|
221
221
|
|
|
222
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
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
|
+
|
|
224
281
|
### Types
|
|
225
282
|
|
|
226
283
|
| Export | Purpose |
|