/** * History Store for FlowDrop (Svelte 5 Runes) * * Provides reactive Svelte 5 rune-based bindings for the history service. * Exposes undo/redo state and actions for the workflow editor. * * @module stores/historyStore */ import { type HistoryState, type PushOptions } from '../services/historyService.js'; import type { Workflow } from '../types/index.js'; /** * Clean up the historyService subscription created at module initialisation. * Call this when tearing down the history store (e.g., in tests or on app * unmount) to prevent memory leaks. */ export declare function cleanupHistorySubscription(): void; /** * Get the current history state snapshot. * * Use this for binding to UI elements like undo/redo buttons. * * @example * ```svelte * * * * ``` */ export declare function getHistoryState(): HistoryState; /** * Convenience getter for canUndo state. * * @returns Whether undo is currently available */ export declare function getCanUndo(): boolean; /** * Convenience getter for canRedo state. * * @returns Whether redo is currently available */ export declare function getCanRedo(): boolean; /** * Set the callback for restoring workflow state * * This callback is invoked when undo/redo operations return a workflow. * Use this to update the workflow store or other state management. * * @param callback - Function to call with restored workflow */ export declare function setOnRestoreCallback(callback: ((workflow: Workflow) => void) | null): void; /** * History actions for undo/redo operations * * Use these functions to interact with the history service. * They handle the coordination between history and workflow state. */ export declare const historyActions: { /** * Initialize history with the current workflow * * Call this when loading a new workflow to reset history. * * @param workflow - The initial workflow state */ initialize: (workflow: Workflow) => void; /** * Push the current state to history before making changes * * Call this BEFORE modifying the workflow to capture the "before" state. * * @param workflow - The current workflow state (before changes) * @param options - Options for this history entry */ pushState: (workflow: Workflow, options?: PushOptions) => void; /** * Undo the last change * * Restores the previous workflow state and invokes the restore callback. * * @returns true if undo was successful, false if at beginning of history */ undo: () => boolean; /** * Redo the last undone change * * Restores the next workflow state and invokes the restore callback. * * @returns true if redo was successful, false if at end of history */ redo: () => boolean; /** * Start a transaction for grouping multiple changes * * All changes during a transaction are combined into a single undo entry. * * @param workflow - The current workflow state (before changes) * @param description - Description for the combined change */ startTransaction: (workflow: Workflow, description?: string) => void; /** * Commit the current transaction */ commitTransaction: () => void; /** * Cancel the current transaction without committing */ cancelTransaction: () => void; /** * Clear all history * * @param currentWorkflow - If provided, keeps this as the initial state */ clear: (currentWorkflow?: Workflow) => void; /** * Check if undo is available */ canUndo: () => boolean; /** * Check if redo is available */ canRedo: () => boolean; /** * Get the current history state synchronously * * @returns The current history state */ getState: () => HistoryState; }; export type { HistoryEntry, HistoryState, PushOptions } from '../services/historyService.js'; export { HistoryService, historyService } from '../services/historyService.js';