From 57ed161ac54e9bebd1c28920829a63ed158d2d3f Mon Sep 17 00:00:00 2001 From: jile1997 <1154416769@qq.com> Date: Wed, 8 Jan 2025 11:19:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=83=A8=E5=88=86api=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/x-flow/src/XFlow.tsx | 11 +++++++---- packages/x-flow/src/components/CustomEdge/index.tsx | 2 +- packages/x-flow/src/components/CustomNode/index.tsx | 2 +- packages/x-flow/src/types.ts | 7 +------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/x-flow/src/XFlow.tsx b/packages/x-flow/src/XFlow.tsx index 96c452cf9..33bd19917 100644 --- a/packages/x-flow/src/XFlow.tsx +++ b/packages/x-flow/src/XFlow.tsx @@ -8,7 +8,7 @@ import { import '@xyflow/react/dist/style.css'; import { useEventListener, useMemoizedFn } from 'ahooks'; import produce, { setAutoFreeze } from 'immer'; -import { debounce } from 'lodash'; +import { debounce, isFunction } from 'lodash'; import type { FC } from 'react'; import React, { memo, @@ -86,7 +86,7 @@ const XFlow: FC = memo(props => { const { settingMap, globalConfig,readOnly } = useContext(ConfigContext); const [openPanel, setOpenPanel] = useState(true); const [openLogPanel, setOpenLogPanel] = useState(true); - const { onNodeClick,panel = {} as any } = props; + const { onNodeClick } = props; useEffect(() => { zoomTo(0.8); @@ -147,8 +147,8 @@ const XFlow: FC = memo(props => { id: uuid(), type: 'custom', data: { - ...data, title: `${title}_${uuid4()}`, + ...data, }, position: { x: 0, @@ -268,6 +268,7 @@ const XFlow: FC = memo(props => { }, [activeNode?.id]); const deletable = globalConfig?.edge?.deletable ?? true; + const panelonClose = globalConfig?.nodePanel?.onClose return (
@@ -341,7 +342,9 @@ const XFlow: FC = memo(props => { if (!activeNode?._status || !openLogPanel) { setActiveNode(null); } - panel.onClose && panel.onClose(activeNode?.id) + if(isFunction(panelonClose)){ + panelonClose(activeNode?.id) + } }} node={activeNode} data={activeNode?.values} diff --git a/packages/x-flow/src/components/CustomEdge/index.tsx b/packages/x-flow/src/components/CustomEdge/index.tsx index 5c8d96822..fdef87762 100644 --- a/packages/x-flow/src/components/CustomEdge/index.tsx +++ b/packages/x-flow/src/components/CustomEdge/index.tsx @@ -77,8 +77,8 @@ export default memo((edge: any) => { id: targetId, type: 'custom', data: { - ...data, title: `${title}_${uuid4()}`, + ...data, }, position: { x, y }, }); diff --git a/packages/x-flow/src/components/CustomNode/index.tsx b/packages/x-flow/src/components/CustomNode/index.tsx index fe9fa73d4..4d5f24e91 100644 --- a/packages/x-flow/src/components/CustomNode/index.tsx +++ b/packages/x-flow/src/components/CustomNode/index.tsx @@ -57,8 +57,8 @@ export default memo((props: any) => { id: targetId, type: 'custom', data: { - ...data, title: `${title}_${uuid4()}`, + ...data, }, position: { x, y }, }; diff --git a/packages/x-flow/src/types.ts b/packages/x-flow/src/types.ts index 1f86bdc5c..7ba0d44c8 100644 --- a/packages/x-flow/src/types.ts +++ b/packages/x-flow/src/types.ts @@ -49,6 +49,7 @@ export interface TNodePanel { // 配置面板属性设置 width?: string | number; // 配置面板宽度 hideDesc?: boolean; // 配置面板描述 + onClose?:(activeNodeId:string)=>void } export interface TNodeSelector { @@ -99,11 +100,6 @@ export interface THandle{ // isConnectableEnd?:boolean isValidConnection?:HandleProps['isValidConnection'] } - -export interface TPanel{ - onClose:(activeNodeId:string)=>void -} - export interface FlowProps { initialValues?: { nodes: any[]; @@ -130,7 +126,6 @@ export interface FlowProps { }; logPanel?: TLogPanel; // 日志面板配置 readOnly?:boolean//只读模式 - panel?:TPanel //表单配置面板 onNodeClick?: NodeMouseHandler; onMenuItemClick?: (itemInfo: ItemInfo, defaultAction: () => void) => void; clickAddNode?:(type:string,nodeItem:TNodeItem,addNode:(initData?:Record)=>void)=>void