| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   memo, | 
					
						
							|  |  |  |   useCallback, | 
					
						
							|  |  |  |   useEffect, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useRef, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } from 'react' | 
					
						
							|  |  |  | import { setAutoFreeze } from 'immer' | 
					
						
							|  |  |  | import { | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useEventListener, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } from 'ahooks' | 
					
						
							|  |  |  | import ReactFlow, { | 
					
						
							|  |  |  |   Background, | 
					
						
							|  |  |  |   ReactFlowProvider, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   SelectionMode, | 
					
						
							| 
									
										
										
										
											2024-04-23 17:02:23 +08:00
										 |  |  |   useEdgesState, | 
					
						
							|  |  |  |   useNodesState, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   useOnViewportChange, | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |   useReactFlow, | 
					
						
							| 
									
										
										
										
											2024-07-10 18:20:13 +08:00
										 |  |  |   useStoreApi, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } from 'reactflow' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import type { | 
					
						
							|  |  |  |   Viewport, | 
					
						
							|  |  |  | } from 'reactflow' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import 'reactflow/dist/style.css' | 
					
						
							|  |  |  | import './style.css' | 
					
						
							|  |  |  | import type { | 
					
						
							|  |  |  |   Edge, | 
					
						
							|  |  |  |   Node, | 
					
						
							|  |  |  | } from './types' | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   ControlMode, | 
					
						
							|  |  |  | } from './types' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   useEdgesInteractions, | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |   useFetchToolsData, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   useNodesInteractions, | 
					
						
							|  |  |  |   useNodesReadOnly, | 
					
						
							|  |  |  |   useNodesSyncDraft, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   usePanelInteractions, | 
					
						
							|  |  |  |   useSelectionInteractions, | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |   useShortcuts, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   useWorkflow, | 
					
						
							|  |  |  |   useWorkflowReadOnly, | 
					
						
							| 
									
										
										
										
											2025-05-06 18:24:10 +08:00
										 |  |  |   useWorkflowRefreshDraft, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } from './hooks' | 
					
						
							|  |  |  | import CustomNode from './nodes' | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  | import CustomNoteNode from './note-node' | 
					
						
							|  |  |  | import { CUSTOM_NOTE_NODE } from './note-node/constants' | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  | import CustomIterationStartNode from './nodes/iteration-start' | 
					
						
							|  |  |  | import { CUSTOM_ITERATION_START_NODE } from './nodes/iteration-start/constants' | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  | import CustomLoopStartNode from './nodes/loop-start' | 
					
						
							|  |  |  | import { CUSTOM_LOOP_START_NODE } from './nodes/loop-start/constants' | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  | import CustomSimpleNode from './simple-node' | 
					
						
							|  |  |  | import { CUSTOM_SIMPLE_NODE } from './simple-node/constants' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | import Operator from './operator' | 
					
						
							|  |  |  | import CustomEdge from './custom-edge' | 
					
						
							|  |  |  | import CustomConnectionLine from './custom-connection-line' | 
					
						
							|  |  |  | import HelpLine from './help-line' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import CandidateNode from './candidate-node' | 
					
						
							|  |  |  | import PanelContextmenu from './panel-contextmenu' | 
					
						
							|  |  |  | import NodeContextmenu from './node-contextmenu' | 
					
						
							| 
									
										
										
										
											2024-06-12 16:35:19 +08:00
										 |  |  | import SyncingDataModal from './syncing-data-modal' | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  | import LimitTips from './limit-tips' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   useStore, | 
					
						
							|  |  |  |   useWorkflowStore, | 
					
						
							|  |  |  | } from './store' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import { | 
					
						
							| 
									
										
										
										
											2025-02-19 17:27:26 +08:00
										 |  |  |   CUSTOM_EDGE, | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |   CUSTOM_NODE, | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   ITERATION_CHILDREN_Z_INDEX, | 
					
						
							|  |  |  |   WORKFLOW_DATA_UPDATE, | 
					
						
							|  |  |  | } from './constants' | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  | import { WorkflowHistoryProvider } from './workflow-history-store' | 
					
						
							| 
									
										
										
										
											2024-04-23 17:02:23 +08:00
										 |  |  | import { useEventEmitterContextContext } from '@/context/event-emitter' | 
					
						
							| 
									
										
										
										
											2024-08-06 14:31:13 +08:00
										 |  |  | import Confirm from '@/app/components/base/confirm' | 
					
						
							| 
									
										
										
										
											2025-03-24 14:30:26 +08:00
										 |  |  | import DatasetsDetailProvider from './datasets-detail-store/provider' | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | import { HooksStoreContextProvider } from './hooks-store' | 
					
						
							|  |  |  | import type { Shape as HooksStoreShape } from './hooks-store' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const nodeTypes = { | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |   [CUSTOM_NODE]: CustomNode, | 
					
						
							|  |  |  |   [CUSTOM_NOTE_NODE]: CustomNoteNode, | 
					
						
							| 
									
										
										
										
											2025-04-01 16:52:07 +08:00
										 |  |  |   [CUSTOM_SIMPLE_NODE]: CustomSimpleNode, | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  |   [CUSTOM_ITERATION_START_NODE]: CustomIterationStartNode, | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |   [CUSTOM_LOOP_START_NODE]: CustomLoopStartNode, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | const edgeTypes = { | 
					
						
							| 
									
										
										
										
											2025-02-19 17:27:26 +08:00
										 |  |  |   [CUSTOM_EDGE]: CustomEdge, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | export type WorkflowProps = { | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   nodes: Node[] | 
					
						
							|  |  |  |   edges: Edge[] | 
					
						
							|  |  |  |   viewport?: Viewport | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |   children?: React.ReactNode | 
					
						
							|  |  |  |   onWorkflowDataUpdate?: (v: any) => void | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | export const Workflow: FC<WorkflowProps> = memo(({ | 
					
						
							| 
									
										
										
										
											2024-04-23 17:02:23 +08:00
										 |  |  |   nodes: originalNodes, | 
					
						
							|  |  |  |   edges: originalEdges, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   viewport, | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |   children, | 
					
						
							|  |  |  |   onWorkflowDataUpdate, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | }) => { | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const workflowContainerRef = useRef<HTMLDivElement>(null) | 
					
						
							|  |  |  |   const workflowStore = useWorkflowStore() | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |   const reactflow = useReactFlow() | 
					
						
							| 
									
										
										
										
											2024-04-23 17:02:23 +08:00
										 |  |  |   const [nodes, setNodes] = useNodesState(originalNodes) | 
					
						
							|  |  |  |   const [edges, setEdges] = useEdgesState(originalEdges) | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const controlMode = useStore(s => s.controlMode) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   const nodeAnimation = useStore(s => s.nodeAnimation) | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   const showConfirm = useStore(s => s.showConfirm) | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-12 16:35:19 +08:00
										 |  |  |   const { | 
					
						
							|  |  |  |     setShowConfirm, | 
					
						
							|  |  |  |     setControlPromptEditorRerenderKey, | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |     setSyncWorkflowDraftHash, | 
					
						
							| 
									
										
										
										
											2024-06-12 16:35:19 +08:00
										 |  |  |   } = workflowStore.getState() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   const { | 
					
						
							|  |  |  |     handleSyncWorkflowDraft, | 
					
						
							|  |  |  |     syncWorkflowDraftWhenPageClose, | 
					
						
							|  |  |  |   } = useNodesSyncDraft() | 
					
						
							|  |  |  |   const { workflowReadOnly } = useWorkflowReadOnly() | 
					
						
							|  |  |  |   const { nodesReadOnly } = useNodesReadOnly() | 
					
						
							| 
									
										
										
										
											2024-04-23 17:02:23 +08:00
										 |  |  |   const { eventEmitter } = useEventEmitterContextContext() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   eventEmitter?.useSubscription((v: any) => { | 
					
						
							|  |  |  |     if (v.type === WORKFLOW_DATA_UPDATE) { | 
					
						
							|  |  |  |       setNodes(v.payload.nodes) | 
					
						
							|  |  |  |       setEdges(v.payload.edges) | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (v.payload.viewport) | 
					
						
							|  |  |  |         reactflow.setViewport(v.payload.viewport) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (v.payload.hash) | 
					
						
							|  |  |  |         setSyncWorkflowDraftHash(v.payload.hash) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |       onWorkflowDataUpdate?.(v.payload) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-12 16:35:19 +08:00
										 |  |  |       setTimeout(() => setControlPromptEditorRerenderKey(Date.now())) | 
					
						
							| 
									
										
										
										
											2024-04-23 17:02:23 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     setAutoFreeze(false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return () => { | 
					
						
							|  |  |  |       setAutoFreeze(true) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, []) | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     return () => { | 
					
						
							| 
									
										
										
										
											2024-05-10 14:48:20 +08:00
										 |  |  |       handleSyncWorkflowDraft(true, true) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |     // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   }, []) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-06 18:24:10 +08:00
										 |  |  |   const { handleRefreshWorkflowDraft } = useWorkflowRefreshDraft() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   const handleSyncWorkflowDraftWhenPageClose = useCallback(() => { | 
					
						
							|  |  |  |     if (document.visibilityState === 'hidden') | 
					
						
							|  |  |  |       syncWorkflowDraftWhenPageClose() | 
					
						
							| 
									
										
										
										
											2024-05-10 14:48:20 +08:00
										 |  |  |     else if (document.visibilityState === 'visible') | 
					
						
							| 
									
										
										
										
											2024-06-12 16:35:19 +08:00
										 |  |  |       setTimeout(() => handleRefreshWorkflowDraft(), 500) | 
					
						
							| 
									
										
										
										
											2024-05-10 14:48:20 +08:00
										 |  |  |   }, [syncWorkflowDraftWhenPageClose, handleRefreshWorkflowDraft]) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     document.addEventListener('visibilitychange', handleSyncWorkflowDraftWhenPageClose) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return () => { | 
					
						
							|  |  |  |       document.removeEventListener('visibilitychange', handleSyncWorkflowDraftWhenPageClose) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, [handleSyncWorkflowDraftWhenPageClose]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useEventListener('keydown', (e) => { | 
					
						
							|  |  |  |     if ((e.key === 'd' || e.key === 'D') && (e.ctrlKey || e.metaKey)) | 
					
						
							|  |  |  |       e.preventDefault() | 
					
						
							| 
									
										
										
										
											2024-06-26 08:37:12 +02:00
										 |  |  |     if ((e.key === 'z' || e.key === 'Z') && (e.ctrlKey || e.metaKey)) | 
					
						
							|  |  |  |       e.preventDefault() | 
					
						
							| 
									
										
										
										
											2024-08-01 12:57:30 +08:00
										 |  |  |     if ((e.key === 'y' || e.key === 'Y') && (e.ctrlKey || e.metaKey)) | 
					
						
							|  |  |  |       e.preventDefault() | 
					
						
							|  |  |  |     if ((e.key === 's' || e.key === 'S') && (e.ctrlKey || e.metaKey)) | 
					
						
							|  |  |  |       e.preventDefault() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   }) | 
					
						
							|  |  |  |   useEventListener('mousemove', (e) => { | 
					
						
							|  |  |  |     const containerClientRect = workflowContainerRef.current?.getBoundingClientRect() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (containerClientRect) { | 
					
						
							|  |  |  |       workflowStore.setState({ | 
					
						
							|  |  |  |         mousePosition: { | 
					
						
							|  |  |  |           pageX: e.clientX, | 
					
						
							|  |  |  |           pageY: e.clientY, | 
					
						
							|  |  |  |           elementX: e.clientX - containerClientRect.left, | 
					
						
							|  |  |  |           elementY: e.clientY - containerClientRect.top, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |   const { handleFetchAllTools } = useFetchToolsData() | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     handleFetchAllTools('builtin') | 
					
						
							|  |  |  |     handleFetchAllTools('custom') | 
					
						
							|  |  |  |     handleFetchAllTools('workflow') | 
					
						
							|  |  |  |   }, [handleFetchAllTools]) | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   const { | 
					
						
							|  |  |  |     handleNodeDragStart, | 
					
						
							|  |  |  |     handleNodeDrag, | 
					
						
							|  |  |  |     handleNodeDragStop, | 
					
						
							|  |  |  |     handleNodeEnter, | 
					
						
							|  |  |  |     handleNodeLeave, | 
					
						
							|  |  |  |     handleNodeClick, | 
					
						
							|  |  |  |     handleNodeConnect, | 
					
						
							|  |  |  |     handleNodeConnectStart, | 
					
						
							|  |  |  |     handleNodeConnectEnd, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |     handleNodeContextMenu, | 
					
						
							| 
									
										
										
										
											2024-06-26 08:37:12 +02:00
										 |  |  |     handleHistoryBack, | 
					
						
							|  |  |  |     handleHistoryForward, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   } = useNodesInteractions() | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     handleEdgeEnter, | 
					
						
							|  |  |  |     handleEdgeLeave, | 
					
						
							|  |  |  |     handleEdgesChange, | 
					
						
							|  |  |  |   } = useEdgesInteractions() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const { | 
					
						
							|  |  |  |     handleSelectionStart, | 
					
						
							|  |  |  |     handleSelectionChange, | 
					
						
							|  |  |  |     handleSelectionDrag, | 
					
						
							|  |  |  |   } = useSelectionInteractions() | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     handlePaneContextMenu, | 
					
						
							|  |  |  |   } = usePanelInteractions() | 
					
						
							| 
									
										
										
										
											2024-04-13 03:48:39 +02:00
										 |  |  |   const { | 
					
						
							|  |  |  |     isValidConnection, | 
					
						
							|  |  |  |   } = useWorkflow() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   useOnViewportChange({ | 
					
						
							|  |  |  |     onEnd: () => { | 
					
						
							|  |  |  |       handleSyncWorkflowDraft() | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |   useShortcuts() | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-10 18:20:13 +08:00
										 |  |  |   const store = useStoreApi() | 
					
						
							|  |  |  |   if (process.env.NODE_ENV === 'development') { | 
					
						
							|  |  |  |     store.getState().onError = (code, message) => { | 
					
						
							|  |  |  |       if (code === '002') | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       console.warn(message) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <div | 
					
						
							|  |  |  |       id='workflow-container' | 
					
						
							|  |  |  |       className={`
 | 
					
						
							| 
									
										
										
										
											2025-04-29 18:04:33 +08:00
										 |  |  |         relative h-full w-full min-w-[960px] | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         ${workflowReadOnly && 'workflow-panel-animation'} | 
					
						
							|  |  |  |         ${nodeAnimation && 'workflow-node-animation'} | 
					
						
							|  |  |  |       `}
 | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       ref={workflowContainerRef} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     > | 
					
						
							| 
									
										
										
										
											2024-06-12 16:35:19 +08:00
										 |  |  |       <SyncingDataModal /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       <CandidateNode /> | 
					
						
							| 
									
										
										
										
											2024-06-26 08:37:12 +02:00
										 |  |  |       <Operator handleRedo={handleHistoryForward} handleUndo={handleHistoryBack} /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       <PanelContextmenu /> | 
					
						
							|  |  |  |       <NodeContextmenu /> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       <HelpLine /> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |       { | 
					
						
							|  |  |  |         !!showConfirm && ( | 
					
						
							|  |  |  |           <Confirm | 
					
						
							|  |  |  |             isShow | 
					
						
							|  |  |  |             onCancel={() => setShowConfirm(undefined)} | 
					
						
							|  |  |  |             onConfirm={showConfirm.onConfirm} | 
					
						
							|  |  |  |             title={showConfirm.title} | 
					
						
							| 
									
										
										
										
											2024-08-06 14:31:13 +08:00
										 |  |  |             content={showConfirm.desc} | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |           /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-09-10 15:23:16 +08:00
										 |  |  |       <LimitTips /> | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |       {children} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       <ReactFlow | 
					
						
							|  |  |  |         nodeTypes={nodeTypes} | 
					
						
							|  |  |  |         edgeTypes={edgeTypes} | 
					
						
							|  |  |  |         nodes={nodes} | 
					
						
							|  |  |  |         edges={edges} | 
					
						
							|  |  |  |         onNodeDragStart={handleNodeDragStart} | 
					
						
							|  |  |  |         onNodeDrag={handleNodeDrag} | 
					
						
							|  |  |  |         onNodeDragStop={handleNodeDragStop} | 
					
						
							|  |  |  |         onNodeMouseEnter={handleNodeEnter} | 
					
						
							|  |  |  |         onNodeMouseLeave={handleNodeLeave} | 
					
						
							|  |  |  |         onNodeClick={handleNodeClick} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         onNodeContextMenu={handleNodeContextMenu} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         onConnect={handleNodeConnect} | 
					
						
							|  |  |  |         onConnectStart={handleNodeConnectStart} | 
					
						
							|  |  |  |         onConnectEnd={handleNodeConnectEnd} | 
					
						
							|  |  |  |         onEdgeMouseEnter={handleEdgeEnter} | 
					
						
							|  |  |  |         onEdgeMouseLeave={handleEdgeLeave} | 
					
						
							|  |  |  |         onEdgesChange={handleEdgesChange} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         onSelectionStart={handleSelectionStart} | 
					
						
							|  |  |  |         onSelectionChange={handleSelectionChange} | 
					
						
							|  |  |  |         onSelectionDrag={handleSelectionDrag} | 
					
						
							|  |  |  |         onPaneContextMenu={handlePaneContextMenu} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         connectionLineComponent={CustomConnectionLine} | 
					
						
							| 
									
										
										
										
											2025-03-05 17:41:15 +08:00
										 |  |  |         // TODO: For LOOP node, how to distinguish between ITERATION and LOOP here? Maybe both are the same?
 | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |         connectionLineContainerStyle={{ zIndex: ITERATION_CHILDREN_Z_INDEX }} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         defaultViewport={viewport} | 
					
						
							|  |  |  |         multiSelectionKeyCode={null} | 
					
						
							|  |  |  |         deleteKeyCode={null} | 
					
						
							|  |  |  |         nodesDraggable={!nodesReadOnly} | 
					
						
							|  |  |  |         nodesConnectable={!nodesReadOnly} | 
					
						
							|  |  |  |         nodesFocusable={!nodesReadOnly} | 
					
						
							|  |  |  |         edgesFocusable={!nodesReadOnly} | 
					
						
							| 
									
										
										
										
											2025-04-30 16:57:48 +08:00
										 |  |  |         panOnScroll={false} | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |         panOnDrag={controlMode === ControlMode.Hand && !workflowReadOnly} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         zoomOnPinch={!workflowReadOnly} | 
					
						
							|  |  |  |         zoomOnScroll={!workflowReadOnly} | 
					
						
							|  |  |  |         zoomOnDoubleClick={!workflowReadOnly} | 
					
						
							|  |  |  |         isValidConnection={isValidConnection} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         selectionKeyCode={null} | 
					
						
							|  |  |  |         selectionMode={SelectionMode.Partial} | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |         selectionOnDrag={controlMode === ControlMode.Pointer && !workflowReadOnly} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         minZoom={0.25} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |       > | 
					
						
							|  |  |  |         <Background | 
					
						
							|  |  |  |           gap={[14, 14]} | 
					
						
							|  |  |  |           size={2} | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |           className="bg-workflow-canvas-workflow-bg" | 
					
						
							|  |  |  |           color='var(--color-workflow-canvas-workflow-dot-color)' | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         /> | 
					
						
							|  |  |  |       </ReactFlow> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | type WorkflowWithInnerContextProps = WorkflowProps & { | 
					
						
							|  |  |  |   hooksStore?: Partial<HooksStoreShape> | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export const WorkflowWithInnerContext = memo(({ | 
					
						
							|  |  |  |   hooksStore, | 
					
						
							|  |  |  |   ...restProps | 
					
						
							|  |  |  | }: WorkflowWithInnerContextProps) => { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <HooksStoreContextProvider {...hooksStore}> | 
					
						
							|  |  |  |       <Workflow {...restProps} /> | 
					
						
							|  |  |  |     </HooksStoreContextProvider> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | type WorkflowWithDefaultContextProps = | 
					
						
							|  |  |  |   Pick<WorkflowProps, 'edges' | 'nodes'> | 
					
						
							|  |  |  |   & { | 
					
						
							|  |  |  |     children: React.ReactNode | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | const WorkflowWithDefaultContext = ({ | 
					
						
							|  |  |  |   nodes, | 
					
						
							|  |  |  |   edges, | 
					
						
							|  |  |  |   children, | 
					
						
							|  |  |  | }: WorkflowWithDefaultContextProps) => { | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <ReactFlowProvider> | 
					
						
							| 
									
										
										
										
											2024-06-26 08:37:12 +02:00
										 |  |  |       <WorkflowHistoryProvider | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  |         nodes={nodes} | 
					
						
							|  |  |  |         edges={edges} > | 
					
						
							|  |  |  |         <DatasetsDetailProvider nodes={nodes}> | 
					
						
							|  |  |  |           {children} | 
					
						
							|  |  |  |         </DatasetsDetailProvider> | 
					
						
							| 
									
										
										
										
											2024-06-26 08:37:12 +02:00
										 |  |  |       </WorkflowHistoryProvider> | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |     </ReactFlowProvider> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-18 13:59:12 +08:00
										 |  |  | export default memo(WorkflowWithDefaultContext) |