import { forwardRef, useRef, useImperativeHandle, useState } from 'react'; import clsx from 'clsx'; import NodeLibrary from './components/NodeLibrary' import Properties from './components/Properties'; import CanvasToolbar from './components/CanvasToolbar'; import PortClickHandler from './components/PortClickHandler'; import { useWorkflowGraph } from './hooks/useWorkflowGraph'; import type { WorkflowRef, FeaturesConfigForm, FeaturesConfigModalRef } from '@/views/ApplicationConfig/types' import Chat from './components/Chat/Chat'; import type { ChatRef, AddChatVariableRef } from './types' import AddChatVariable from './components/AddChatVariable'; import FeaturesConfigModal from '@/views/ApplicationConfig/components/FeaturesConfig/FeaturesConfigModal' const Workflow = forwardRef void }>(({ onFeaturesLoad }, ref) => { const containerRef = useRef(null); const miniMapRef = useRef(null); const addChatVariableRef = useRef(null) const chatRef = useRef(null) const [collapsed, setCollapsed] = useState(false) // 使用自定义Hook初始化工作流图 const { config, graphRef, selectedNode, zoomLevel, isHandMode, setIsHandMode, onDrop, blankClick, nodeClick, deleteEvent, copyEvent, parseEvent, handleSave, chatVariables, setChatVariables, handleAddNotes, handleSaveFeaturesConfig, features, getStartNodeVariables, canUndo, canRedo, undo, redo, } = useWorkflowGraph({ containerRef, miniMapRef, onFeaturesLoad }); const onDragOver = (event: React.DragEvent) => { event.preventDefault(); }; const handleRun = () => { chatRef.current?.handleOpen() } const handleToggle = () => { setCollapsed(prev => !prev) } const addVariable = () => { addChatVariableRef.current?.handleOpen() } // Ref used to imperatively open the config modal const funConfigModalRef = useRef(null) /** Open the feature config modal pre-populated with the current values */ const handleFeaturesConfig = () => { blankClick() funConfigModalRef.current?.handleOpen(features as FeaturesConfigForm) } useImperativeHandle(ref, () => ({ handleSave, handleRun, graphRef, addVariable, chatVariables, config, features: features, handleFeaturesConfig, handleSaveFeaturesConfig, nodeClick })) return (
{/* 左侧节点面板 */} {/* 右侧画布区域 */}
{/* 地图工具栏 */}
{/* 右侧属性面板 */} {selectedNode && } {/* Modal for editing feature settings; calls refresh on save */} ({ name: v.name, key: `start_${v.name}`, label: v.name, type: 'variable', dataType: v.type, value:`{{${v.name}}}` })) as any} />
); }); export default Workflow;