UNPKG

jotai-history-global

Version:

Lightweight global undo/redo extension for Jotai. / 为 Jotai 提供全局撤销、重做功能的轻量扩展。

50 lines (49 loc) 2.23 kB
/** * History Manager * * Manages a global history stack for tracking state changes across atoms */ import type { AtomWithHistory, HistoryEntry, HistoryStack } from './types'; export declare const historyStore: { get: <Value>(atom: import("jotai").Atom<Value>) => Value; set: <Value, Args extends unknown[], Result>(atom: import("jotai").WritableAtom<Value, Args, Result>, ...args: Args) => Result; sub: (atom: import("jotai").Atom<unknown>, listener: () => void) => () => void; } | ({ get: <Value>(atom: import("jotai").Atom<Value>) => Value; set: <Value, Args extends unknown[], Result>(atom: import("jotai").WritableAtom<Value, Args, Result>, ...args: Args) => Result; sub: (atom: import("jotai").Atom<unknown>, listener: () => void) => () => void; } & import("jotai/vanilla/store").INTERNAL_DevStoreRev4); export declare const historyStackAtom: import("jotai").PrimitiveAtom<HistoryStack> & { init: HistoryStack; }; export declare const isHistoryOperationInProgressAtom: import("jotai").PrimitiveAtom<boolean> & { init: boolean; }; export declare const currentGroupOperationAtom: import("jotai").PrimitiveAtom<HistoryEntry[] | null> & { init: HistoryEntry[] | null; }; export declare const isGroupOperationInProgressAtom: import("jotai").PrimitiveAtom<boolean> & { init: boolean; }; /** * Register an atom with the history system * @param atom - The atom to register */ export declare function registerHistoryAtom<Value>(atom: AtomWithHistory<Value>): void; /** * Unregister an atom from the history system * @param atom - The atom to unregister */ export declare function unregisterHistoryAtom<Value>(atom: AtomWithHistory<Value>): void; /** * Find an atom by ID in the registry - O(1) lookup with Map */ export declare function getAtomById(id: string): AtomWithHistory<any> | undefined; export declare const generateId: () => string; export declare const pushToHistory: (id: string, prevValue: unknown, nextValue: unknown, options?: { historyLimit?: number; useFullValueInstead?: boolean; customDiff?: (prev: unknown, next: unknown) => unknown; }) => void; export declare const startGroupOperation: () => void; export declare const endGroupOperation: () => void;