import { StateModel, StateStore } from '@json-render/core'; export { StateStore } from '@json-render/core'; import { StoreApi } from 'zustand'; /** * Options for {@link zustandStateStore}. */ interface ZustandStateStoreOptions { /** A Zustand vanilla store (created with `createStore` from `zustand/vanilla`). */ store: StoreApi; /** * Select the json-render state slice from the Zustand store state. * Defaults to `(state) => state` (the entire store is the state model). */ selector?: (state: S) => StateModel; /** * Apply a state change back to the Zustand store. * Defaults to a shallow merge (`store.setState(next)`) so that keys * outside the json-render model are preserved. Override this if you use * a selector and only want to update a nested slice, or pass * `(next, s) => s.setState(next as S, true)` for full replacement. */ updater?: (nextState: StateModel, store: StoreApi) => void; } /** * Create a {@link StateStore} backed by a Zustand store. * * @example * ```ts * import { createStore } from "zustand/vanilla"; * import { zustandStateStore } from "@json-render/zustand"; * * const bearStore = createStore(() => ({ count: 0, name: "Bear" })); * * const store = zustandStateStore({ store: bearStore }); * * ... * ``` * * @example Using a selector for a nested slice: * ```ts * const appStore = createStore(() => ({ * ui: { count: 0 }, * auth: { token: null }, * })); * * const store = zustandStateStore({ * store: appStore, * selector: (s) => s.ui, * updater: (next, s) => s.setState({ ui: next }), * }); * ``` */ declare function zustandStateStore(options: ZustandStateStoreOptions): StateStore; export { type ZustandStateStoreOptions, zustandStateStore };