From 14b10f40e8b79e7862e0cf236132b42e152f4c38 Mon Sep 17 00:00:00 2001 From: Johnpaul Date: Thu, 25 Sep 2025 23:02:47 +0100 Subject: [PATCH] [feat] Add Vue widget serialization store for custom widgets --- src/stores/vueWidgetSerializationStore.ts | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/stores/vueWidgetSerializationStore.ts diff --git a/src/stores/vueWidgetSerializationStore.ts b/src/stores/vueWidgetSerializationStore.ts new file mode 100644 index 000000000..8532ab9e8 --- /dev/null +++ b/src/stores/vueWidgetSerializationStore.ts @@ -0,0 +1,63 @@ +/** + * Store for managing Vue widget serialization functions. + * This allows Vue components to register serialization handlers that can be + * accessed by LiteGraph widgets for workflow saving/loading. + */ + +type SerializationFunction = () => Promise + +class VueWidgetSerializationStore { + private registry = new Map() + + /** + * Register a serialization function for a widget + * @param key Unique identifier for the widget (e.g., "{nodeId}-{widgetName}") + * @param serializeFn Function that serializes the widget value + */ + register(key: string, serializeFn: SerializationFunction): void { + this.registry.set(key, serializeFn) + } + + /** + * Unregister a serialization function + * @param key The key used during registration + */ + unregister(key: string): void { + this.registry.delete(key) + } + + /** + * Get a serialization function for a widget + * @param key The key to look up + * @returns The serialization function if found, undefined otherwise + */ + get(key: string): SerializationFunction | undefined { + return this.registry.get(key) + } + + /** + * Check if a serialization function is registered + * @param key The key to check + * @returns True if registered, false otherwise + */ + has(key: string): boolean { + return this.registry.has(key) + } + + /** + * Clear all registered serialization functions + */ + clear(): void { + this.registry.clear() + } + + /** + * Get all registered keys (useful for debugging) + */ + getKeys(): string[] { + return Array.from(this.registry.keys()) + } +} + +// Create singleton instance +export const vueWidgetSerializationStore = new VueWidgetSerializationStore()