/** * Workflow Store for FlowDrop (Svelte 5 Runes) * * Provides global state management for workflows with dirty state tracking * and undo/redo history integration. * * **Important: Single-instance only.** This store uses module-level singletons. * Only one FlowDrop editor instance per page is supported. Mounting multiple * FlowDrop editors on the same page will cause them to share workflow state. * * @module stores/workflowStore */ import type { Workflow, WorkflowNode, WorkflowEdge } from '../types'; import type { WorkflowChangeType } from '../types/events.js'; type WorkflowMetadata = NonNullable; /** * Get the current workflow store value reactively * * @returns The current workflow or null */ export declare function getWorkflowStore(): Workflow | null; /** * Get the current dirty state reactively * * Reads both _editVersion and _savedVersion, so Svelte tracks them * as reactive dependencies — any component using this will re-render * when dirty state changes. * * @returns true if there are unsaved changes */ export declare function getIsDirty(): boolean; /** * Get the workflow ID reactively * * @returns The workflow ID or null */ export declare function getWorkflowId(): string | null; /** * Get the workflow name reactively * * @returns The workflow name or 'Untitled Workflow' */ export declare function getWorkflowName(): string; /** * Get the workflow nodes reactively * * @returns Array of workflow nodes */ export declare function getWorkflowNodes(): WorkflowNode[]; /** * Get the workflow edges reactively * * @returns Array of workflow edges */ export declare function getWorkflowEdges(): WorkflowEdge[]; /** * Get the workflow metadata reactively * * @returns The workflow metadata with defaults */ export declare function getWorkflowMetadata(): WorkflowMetadata; /** * Get the current workflow format reactively * * @returns The workflow format string */ export declare function getWorkflowFormat(): string; /** * Get workflow change summary reactively (useful for triggering saves) * * @returns Object with nodes, edges, and name */ export declare function getWorkflowChanged(): { nodes: WorkflowNode[]; edges: WorkflowEdge[]; name: string; }; /** * Get workflow validation state reactively * * @returns Validation info object */ export declare function getWorkflowValidation(): { hasNodes: boolean; hasEdges: boolean; nodeCount: number; edgeCount: number; isValid: boolean; }; /** * Get workflow metadata change summary reactively * * @returns Metadata change info */ export declare function getWorkflowMetadataChanged(): { createdAt: string; updatedAt: string; version: string; }; /** * Get connected handles reactively * * Provides a Set of all handle IDs that are currently connected to edges. * Used by node components to implement hideUnconnectedHandles functionality. * * @example * ```typescript * import { getConnectedHandles } from './workflowStore.svelte.js'; * * // Check if a specific handle is connected * const isConnected = getConnectedHandles().has('node-1-input-data'); * ``` */ export declare function getConnectedHandles(): Set; /** * Set the dirty state change callback * * @param callback - Function to call when dirty state changes */ export declare function setOnDirtyStateChange(callback: ((isDirty: boolean) => void) | null): void; /** * Set the workflow change callback * * @param callback - Function to call when workflow changes */ export declare function setOnWorkflowChange(callback: ((workflow: Workflow, changeType: WorkflowChangeType) => void) | null): void; /** * Mark the current workflow state as saved. * * Captures the current edit version so isDirty becomes false. * Call this after a successful backend save. */ export declare function markAsSaved(): void; /** * Check if there are unsaved changes (non-reactive version for plain TS) * * @returns true if there are unsaved changes */ export declare function isDirty(): boolean; /** * Get the current edit version. * * Use this for the save verification protocol: * 1. Before save: `const v = getEditVersion()` * 2. Include `v` in the save request payload * 3. Backend echoes `v` in the response * 4. If echoed version matches: `markAsSaved()` * 5. If not: the save didn't persist the version you submitted — reset from backend response * * @returns The current monotonic edit version */ export declare function getEditVersion(): number; /** * Enable or disable history recording * * Useful for bulk operations where you don't want individual history entries. * * @param enabled - Whether history should be recorded */ export declare function setHistoryEnabled(enabled: boolean): void; /** * Check if history recording is enabled * * @returns true if history is being recorded */ export declare function isHistoryEnabled(): boolean; /** * Set the restoring from history flag * * Used internally by the history store when performing undo/redo. * * @param restoring - Whether we're currently restoring from history */ export declare function setRestoringFromHistory(restoring: boolean): void; /** * Get the current workflow (non-reactive version for plain TS) * * @returns The current workflow or null */ export declare function getWorkflow(): Workflow | null; /** * Actions for updating the workflow * * All actions that modify the workflow will trigger dirty state updates * and emit change events. */ export declare const workflowActions: { /** * Initialize workflow (from load or new) * * This sets the initial saved snapshot, clears dirty state, and initializes history. */ initialize: (workflow: Workflow) => void; /** * Update the entire workflow * * Note: This is typically called from SvelteFlow sync and should not push to history * for every small change. History is pushed by specific actions or drag handlers. */ updateWorkflow: (workflow: Workflow) => void; /** * Restore workflow from history (undo/redo) * * This bypasses history recording to prevent recursive loops. */ restoreFromHistory: (workflow: Workflow) => void; /** * Update nodes */ updateNodes: (nodes: WorkflowNode[]) => void; /** * Update edges */ updateEdges: (edges: WorkflowEdge[]) => void; /** * Update workflow name */ updateName: (name: string) => void; /** * Add a node */ addNode: (node: WorkflowNode) => void; /** * Remove a node * * This is an atomic operation that also removes connected edges. * A single undo will restore both the node and its edges. */ removeNode: (nodeId: string) => void; /** * Add an edge */ addEdge: (edge: WorkflowEdge) => void; /** * Remove an edge */ removeEdge: (edgeId: string) => void; /** * Update a specific node * * Used for config changes. Pushes to history for undo support. */ updateNode: (nodeId: string, updates: Partial) => void; /** * Clear the workflow * * Resets the workflow and clears history. */ clear: () => void; /** * Update workflow metadata */ updateMetadata: (metadata: Partial) => void; /** * Batch update nodes and edges * * Useful for complex operations that update multiple things at once. * Creates a single history entry for the entire batch. */ batchUpdate: (updates: { nodes?: WorkflowNode[]; edges?: WorkflowEdge[]; name?: string; description?: string; metadata?: Partial; config?: Record; }) => void; /** * Swap a node — atomically replaces nodes and edges with a descriptive history entry. * * Unlike batchUpdate, this uses `"node_swap"` as the change type and * records a meaningful description for the undo history. */ swapNode: (updates: { nodes: WorkflowNode[]; edges: WorkflowEdge[]; description?: string; }) => void; /** * Push current state to history manually * * Use this before operations that modify the workflow through other means * (e.g., drag operations handled by SvelteFlow directly). * * @param description - Description of the upcoming change * @param workflow - Optional workflow to push (uses store state if not provided) */ pushHistory: (description?: string, workflow?: Workflow) => void; }; export {};