From 467ce30f076be8b9027857b9c45f8df1605812ff Mon Sep 17 00:00:00 2001 From: lexmin0412 Date: Mon, 26 May 2025 14:29:04 +0800 Subject: [PATCH] feat: support node copying between `Chatflow` and `Workflow` apps --- web/app/components/workflow/index.tsx | 16 ++++++++++++++++ .../workflow/store/workflow/workflow-slice.ts | 10 ++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/index.tsx b/web/app/components/workflow/index.tsx index 549117faf7..08afad1d7a 100644 --- a/web/app/components/workflow/index.tsx +++ b/web/app/components/workflow/index.tsx @@ -119,6 +119,7 @@ export const Workflow: FC = memo(({ setShowConfirm, setControlPromptEditorRerenderKey, setSyncWorkflowDraftHash, + setClipboardElements, } = workflowStore.getState() const { handleSyncWorkflowDraft, @@ -145,6 +146,21 @@ export const Workflow: FC = memo(({ } }) + const handleVisibilityChange = useCallback(() => { + if (document.visibilityState === 'visible') { + const storedElements = localStorage.getItem('clipboard_elements') + setClipboardElements(storedElements ? JSON.parse(storedElements) : []) + } + }, [setClipboardElements]) + + useEffect(() => { + document.addEventListener('visibilitychange', handleVisibilityChange) + + return () => { + document.removeEventListener('visibilitychange', handleVisibilityChange) + } + }, []) + useEffect(() => { setAutoFreeze(false) diff --git a/web/app/components/workflow/store/workflow/workflow-slice.ts b/web/app/components/workflow/store/workflow/workflow-slice.ts index 6bb69cdfcd..d034080b52 100644 --- a/web/app/components/workflow/store/workflow/workflow-slice.ts +++ b/web/app/components/workflow/store/workflow/workflow-slice.ts @@ -37,8 +37,14 @@ export type WorkflowSliceShape = { export const createWorkflowSlice: StateCreator = set => ({ workflowRunningData: undefined, setWorkflowRunningData: workflowRunningData => set(() => ({ workflowRunningData })), - clipboardElements: [], - setClipboardElements: clipboardElements => set(() => ({ clipboardElements })), + clipboardElements: (() => { + const storedElements = localStorage.getItem('clipboard_elements') + return storedElements ? JSON.parse(storedElements) : [] + })(), + setClipboardElements: (clipboardElements) => { + set(() => ({ clipboardElements })) + localStorage.setItem('clipboard_elements', JSON.stringify(clipboardElements)) + }, selection: null, setSelection: selection => set(() => ({ selection })), bundleNodeSize: null,