import { EnqueueObject, EventObject, EventPayloadMap, ExtractEvents, StoreContext, StoreExtension, 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; /** Customizes the context restored by snapshot-based undo/redo. */ restore?: (args: { current: TContext; next: TContext; direction: 'undo' | 'redo'; }, enqueue: EnqueueObject) => TContext; } 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 * 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 * // Snapshot strategy * const store = createStore({ * context: { count: 0 }, * on: { inc: (ctx) => ({ count: ctx.count + 1 }) } * }).with(undoRedo({ strategy: 'snapshot', historyLimit: 10 })); * ``` * * @returns Store extension with additional `undo` and `redo` event handlers */ export declare function undoRedo(options?: UndoRedoStrategyOptions, TEmitted, TEventPayloadMap>): StoreExtension; export {};