/** * Jotai integration for Loro Mirror - Atomic state management with Loro CRDT synchronization * * This package provides atom-based state management following Jotai's bottom-up approach. * Each piece of state is represented as an atom, enabling fine-grained reactivity and composition. */ import type { LoroDoc, EphemeralStore } from "loro-crdt"; import type { SchemaType, InferType, InferInputType, RootInitialValue } from "loro-mirror"; /** * Configuration for creating a Loro Mirror atom */ export interface LoroMirrorAtomConfig { /** * The Loro document to sync with */ doc: LoroDoc; /** * The schema definition for the state */ schema: S; /** * Initial state (optional). Root entries must be container-shaped * (objects, arrays, strings, or `null`/`undefined`); bare numbers and * booleans are rejected, since LoroDoc only stores containers at the * document root. */ initialState?: Partial> & { [key: string]: RootInitialValue; }; /** * Whether to validate state updates against the schema * @default true */ validateUpdates?: boolean; /** * Debug mode - logs operations * @default false */ debug?: boolean; /** * Optional EphemeralStore for syncing temporary state without polluting * LoroDoc history. * * **Setting this changes how writes work:** eligible changes (primitive * values on existing Map keys) are automatically routed to * EphemeralStore instead of LoroDoc. Use `loroMirrorAtoms` to get a * `finalizeAtom` for committing ephemeral values to LoroDoc. */ ephemeralStore?: EphemeralStore; } /** * Creates a primary state atom that syncs with Loro. * * Returns a single read/write atom — drop-in replacement for `useAtom`. * * @example * ```tsx * const todoAtom = loroMirrorAtom({ * doc: new LoroDoc(), * schema: todoSchema, * initialState: { todos: [] }, * }); * * function TodoApp() { * const [state, setState] = useAtom(todoAtom); * } * ``` */ export declare function loroMirrorAtom(config: LoroMirrorAtomConfig): import("jotai").WritableAtom, [update: Partial>], void>; /** * Creates a set of atoms for full Loro Mirror integration including * ephemeral patch support. * * @returns `{ stateAtom, finalizeAtom }` * - `stateAtom` — read/write atom for the synchronized state (same as `loroMirrorAtom`). * When `ephemeralStore` is configured, eligible changes are automatically routed * through EphemeralStore. * - `finalizeAtom` — write-only atom that commits pending ephemeral patches to LoroDoc * * @example * ```tsx * const { stateAtom, finalizeAtom } = loroMirrorAtoms({ * doc, * schema: canvasSchema, * ephemeralStore: new EphemeralStore(), * }); * * function Canvas() { * const [state, setState] = useAtom(stateAtom); * const finalize = useSetAtom(finalizeAtom); * * const onDrag = (x: number, y: number) => { * setState({ x, y }); * }; * * const onDragEnd = () => finalize(); * } * ``` */ export declare function loroMirrorAtoms(config: LoroMirrorAtomConfig): { stateAtom: import("jotai").WritableAtom, [update: Partial>], void>; finalizeAtom: import("jotai").WritableAtom & { init: null; }; }; //# sourceMappingURL=index.d.ts.map