/** * Editor State Machine for WorkflowEditor (Svelte 5 Runes) * * Centralizes all reactive guard logic into explicit states and transitions. * Replaces scattered boolean flags (isDraggingNode, isRestoringFromHistory, * lastEditorStoreValue identity checks) with a single source of truth. * * @module stores/editorStateMachine */ export type EditorState = 'uninitialized' | 'loading' | 'idle' | 'dragging' | 'connecting' | 'dropping' | 'restoring' | 'deleting' | 'updating_node'; export type EditorEvent = 'WORKFLOW_LOADED' | 'LOAD_COMPLETE' | 'START_DRAG' | 'STOP_DRAG' | 'START_CONNECT' | 'CONNECTION_MADE' | 'CONNECTION_CANCELLED' | 'START_DROP' | 'DROP_COMPLETE' | 'DROP_CANCELLED' | 'START_RESTORE' | 'RESTORE_COMPLETE' | 'EXTERNAL_STORE_CHANGE' | 'SYNC_COMPLETE' | 'START_DELETE' | 'DELETE_COMPLETE' | 'START_NODE_UPDATE' | 'UPDATE_COMPLETE' | 'WORKFLOW_SWITCHED' | 'WORKFLOW_CLEARED' | 'RESET'; /** What operations are permitted in the current state */ export interface StatePermissions { /** Whether the editor can write to the global workflow store */ canWriteToStore: boolean; /** Whether the editor can push to undo/redo history */ canPushHistory: boolean; /** Suppress the store → flowNodes/flowEdges sync effect */ suppressEffect: boolean; } export interface EditorStateMachine { /** Current state (reactive via $state) */ readonly current: EditorState; /** Current permissions (reactive, derived from current state) */ readonly permissions: StatePermissions; /** Attempt a transition. Returns true if the transition was valid. */ send(event: EditorEvent): boolean; /** Check if an event is valid from the current state */ canSend(event: EditorEvent): boolean; /** Subscribe to state changes (for debugging/logging). Returns unsubscribe function. */ onTransition(callback: (from: EditorState, event: EditorEvent, to: EditorState) => void): () => void; } /** * Create an editor state machine instance. * * Uses Svelte 5 `$state` rune for reactivity so that components can * read `machine.current` and `machine.permissions` inside `$derived` * or `$effect` blocks and react to state changes. * * Each WorkflowEditor component instance should create its own machine. */ export declare function createEditorStateMachine(initialState?: EditorState): EditorStateMachine;