import { EventObject, EventPayloadMap, ExtractEvents, StoreConfig, StoreContext, StoreExtension, StoreLogic, StoreSnapshot } from "./types.js"; interface UndoRedoEventOptions { /** A function that returns the transaction ID of an event. */ getTransactionId?: (event: TEvent, snapshot: StoreSnapshot) => string | null | undefined; /** * A function that returns whether an event should be skipped during * undo/redo. Skipped events are not stored in history and are not replayed * during undo/redo. */ skipEvent?: (event: TEvent, snapshot: StoreSnapshot) => boolean; } interface UndoRedoSnapshotOptions { /** A function that returns the transaction ID of an event. */ getTransactionId?: (event: TEvent, snapshot: StoreSnapshot) => string | null | undefined; /** * A function that returns whether a snapshot should be skipped during * undo/redo. Skipped events don't save snapshots to history. */ skipEvent?: (event: TEvent, snapshot: StoreSnapshot) => boolean; /** Maximum number of snapshots to keep in history. Defaults to Infinity. */ historyLimit?: number; /** * A function to compare snapshots for equality. When true, the new snapshot * will not be added to history. Useful for avoiding duplicate snapshots. */ compare?: (pastSnapshot: StoreSnapshot, currentSnapshot: StoreSnapshot) => boolean; } type UndoRedoStrategyOptions = ({ strategy?: 'event'; } & UndoRedoEventOptions) | ({ strategy: 'snapshot'; } & UndoRedoSnapshotOptions); /** * Creates store logic with undo/redo functionality. * * Supports two strategies: * * - 'event' (default): Maintains event history and replays events * - 'snapshot': Maintains snapshot history for faster undo/redo * * @example * * ```ts * // Using with .with() (recommended) * const store = createStore({ * context: { count: 0 }, * on: { * inc: (ctx) => ({ count: ctx.count + 1 }) * } * }).with(undoRedo()); * * store.trigger.inc(); * store.trigger.undo(); // count = 0 * ``` * * @example * * ```ts * // Legacy: wrapping config directly * const store = createStore( * undoRedo({ * context: { count: 0 }, * on: { * inc: (ctx) => ({ count: ctx.count + 1 }) * } * }) * ); * ``` * * @example * * ```ts * // Snapshot strategy with .with() * const store = createStore({ * context: { count: 0 }, * on: { inc: (ctx) => ({ count: ctx.count + 1 }) } * }).with(undoRedo({ strategy: 'snapshot', historyLimit: 10 })); * ``` * * @returns Store extension or store logic with additional `undo` and `redo` * event handlers */ export declare function undoRedo(options?: UndoRedoStrategyOptions>): StoreExtension; /** * @deprecated Use the .with() pattern instead. * @example * * ```ts * const store = createStore({ * context: { count: 0 }, * on: { inc: (ctx) => ({ count: ctx.count + 1 }) } * }).with(undoRedo({ strategy: 'snapshot', historyLimit: 10 })); * ``` */ export declare function undoRedo(storeConfig: StoreConfig, options?: UndoRedoStrategyOptions>): StoreLogic, ExtractEvents | { type: 'undo'; } | { type: 'redo'; }, ExtractEvents>; export {};