/** * Auto-save Service for FlowDrop * * Handles automatic saving of workflows based on user settings. * Uses behaviorSettings for auto-save configuration. * * @module services/autoSaveService */ /** * Auto-save configuration options */ interface AutoSaveOptions { /** * Callback function to save the workflow * Should return a promise that resolves when save is complete */ onSave: () => Promise; /** * Optional callback for save errors */ onError?: (error: Error) => void; /** * Optional callback for successful saves */ onSuccess?: () => void; } /** * Initialize auto-save functionality based on user settings * * Creates an interval-based auto-save mechanism that: * - Listens to behaviorSettings changes for auto-save configuration * - Monitors the isDirty state to check for unsaved changes * - Calls the provided save callback when dirty and auto-save is enabled * * @param options - Auto-save configuration options * @returns Cleanup function to stop auto-save and unsubscribe from stores * * @example * ```typescript * // In App.svelte onMount * const cleanupAutoSave = initAutoSave({ * onSave: async () => { * await saveWorkflow(); * }, * onError: (error) => { * console.error("Auto-save failed:", error); * }, * onSuccess: () => { * console.log("Auto-saved workflow"); * } * }); * * // In onDestroy * cleanupAutoSave(); * ``` */ export declare function initAutoSave(options: AutoSaveOptions): () => void; /** * Create an auto-save manager with more control * * This is a class-based alternative to initAutoSave for cases where * you need more fine-grained control over the auto-save behavior. */ export declare class AutoSaveManager { private intervalId; private isSaving; private settingsUnsubscriber; private onSave; private onError?; private onSuccess?; /** * Create a new AutoSaveManager * * @param options - Auto-save configuration options */ constructor(options: AutoSaveOptions); /** * Start the auto-save manager * * Listens for settings changes and starts the auto-save interval. */ start(): void; /** * Stop the auto-save manager * * Clears the interval and unsubscribes from settings. */ stop(): void; /** * Force an immediate save (if dirty) * * @returns Promise that resolves when save is complete */ saveNow(): Promise; /** * Check if auto-save is currently enabled */ isEnabled(): boolean; /** * Check if auto-save is currently running */ isRunning(): boolean; /** * Update the interval based on current settings */ private updateInterval; /** * Perform the save operation */ private performSave; } export {};