From 404ef900b2fdc7bb174fd5451f3815fcb8bf5665 Mon Sep 17 00:00:00 2001 From: jile1997 <1154416769@qq.com> Date: Thu, 2 Jan 2025 14:11:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/CustomNode/index.tsx | 45 ++++++++++------ .../x-flow/src/operator/Control/index.tsx | 53 +++++++++++++------ packages/x-flow/src/types.ts | 15 +++++- 3 files changed, 80 insertions(+), 33 deletions(-) diff --git a/packages/x-flow/src/components/CustomNode/index.tsx b/packages/x-flow/src/components/CustomNode/index.tsx index 15d156a75..2c560478e 100644 --- a/packages/x-flow/src/components/CustomNode/index.tsx +++ b/packages/x-flow/src/components/CustomNode/index.tsx @@ -20,6 +20,9 @@ export default memo((props: any) => { useContext(ConfigContext); const deletable = globalConfig?.edge?.deletable ?? true; + // const isConnectableStart = globalConfig?.handle?.isConnectableStart ?? true; + // const isConnectableEnd = globalConfig?.handle?.isConnectableEnd ?? true; + const NodeWidget = widgets[`${capitalize(type)}Node`] || widgets['CommonNode']; const [isHovered, setIsHovered] = useState(false); @@ -92,6 +95,24 @@ export default memo((props: any) => { deleteNode(id); }, [pasteNode]); + const defaultAction = (e, sourceHandle) => { + if (e.key === 'copy') { + handleCopyNode(); + } else if (e.key === 'paste') { + handlePasteNode(); + } else if (e.key === 'delete') { + handleDeleteNode(); + } else if (e.key.startsWith('paste-')) { + if (sourceHandle) { + handlePasteNode({ + sourceHandle, + }); + } else { + handlePasteNode(); + } + } + }; + const itemClick = e => { if (!e.key) { return; @@ -105,23 +126,11 @@ export default memo((props: any) => { if (type === 'Switch' && e.key.startsWith('paste-') && sourceHandle) { data['sourceHandle'] = sourceHandle; } - onMenuItemClick(data); + onMenuItemClick(data, () => { + defaultAction(e, sourceHandle); + }); } else { - if (e.key === 'copy') { - handleCopyNode(); - } else if (e.key === 'paste') { - handlePasteNode(); - } else if (e.key === 'delete') { - handleDeleteNode(); - } else if (e.key.startsWith('paste-')) { - if (sourceHandle) { - handlePasteNode({ - sourceHandle, - }); - } else { - handlePasteNode(); - } - } + defaultAction(e, sourceHandle); } }; @@ -187,6 +196,8 @@ export default memo((props: any) => { type="target" position={targetPosition} isConnectable={isConnectable} + // isConnectableStart={isConnectableStart} + // isConnectableEnd={isConnectableEnd} /> )} {selected && ( @@ -234,6 +245,8 @@ export default memo((props: any) => { selected={selected} isHovered={isHovered} handleAddNode={handleAddNode} + // isConnectableStart={isConnectableStart} + // isConnectableEnd={isConnectableEnd} /> )} diff --git a/packages/x-flow/src/operator/Control/index.tsx b/packages/x-flow/src/operator/Control/index.tsx index 2496d08d7..cd8f9238c 100644 --- a/packages/x-flow/src/operator/Control/index.tsx +++ b/packages/x-flow/src/operator/Control/index.tsx @@ -1,17 +1,22 @@ import { Button, Tooltip } from 'antd'; import type { MouseEvent } from 'react'; -import React, { memo } from 'react'; +import React, { memo, useContext } from 'react'; import IconView from '../../components/IconView'; import NodeSelectPopover from '../../components/NodesPopover'; import { useStore, useStoreApi } from '../../hooks/useStore'; +import { ConfigContext } from '../../models/context'; import { useEventEmitterContextContext } from '../../models/event-emitter'; -import './index.less'; import { useFullscreen } from 'ahooks'; +import './index.less'; const Control = (props: any) => { const { addNode, xflowRef } = props; - const [isFullscreen, {toggleFullscreen }] = useFullscreen(xflowRef); + const [isFullscreen, { toggleFullscreen }] = useFullscreen(xflowRef); + const { globalConfig } = useContext(ConfigContext); + + const hideAddNode = globalConfig?.controls?.hideAddNode ?? false; + const hideAnnotate = globalConfig?.controls?.hideAnnotate ?? false; const addNote = (e: MouseEvent) => { e.stopPropagation(); @@ -27,22 +32,38 @@ const Control = (props: any) => { return (
- - document.getElementById('xflow-container') as HTMLElement}> + {!hideAddNode && ( + + + document.getElementById('xflow-container') as HTMLElement + } + > +