Skip to content

Commit aaa650f

Browse files
author
昔梦
committed
feat:两个节点连线之前的插入按钮配置化
1 parent d14868c commit aaa650f

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

docs/xflow/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ title: API
1616
| nodeSelector | 节点选择器配置,可控制节点的可搜索性 | `TNodeSelector` |
1717
| iconFontUrl | iconfont url,用于配置图标渲染 | `String` | |
1818
| configPanelWidth | 统一设置配置面板宽度 | `number` | 400 |
19+
| hideLineInsertBtn |是否隐藏两个节点之间,连线上的增加节点按钮 | `boolean` | false |
1920

2021

2122
### TNodeGroup

docs/xflow/demo/nodeSetting/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export default () => {
215215
}}
216216
layout="LR"
217217
configPanelWidth={410}
218+
hideLineInsertBtn={true}
218219
/>
219220
</div>
220221
);

packages/x-flow/src/components/CustomEdge/index.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
useReactFlow,
77
} from '@xyflow/react';
88
import produce from 'immer';
9-
import React, { memo, useState } from 'react';
9+
import React, { memo, useContext, useState } from 'react';
1010
import { shallow } from 'zustand/shallow';
1111
import { useStore } from '../../hooks/useStore';
1212
import { uuid } from '../../utils';
1313
import NodeSelectPopover from '../NodesPopover';
1414
import './index.less';
15+
import { ConfigContext } from '../../models/context';
1516

1617
export default memo((edge: any) => {
1718
const { id, selected, sourceX, sourceY, targetX, targetY, source, target } =
@@ -26,6 +27,9 @@ export default memo((edge: any) => {
2627
targetY,
2728
});
2829

30+
const { hideLineInsertBtn } =
31+
useContext(ConfigContext);
32+
2933
const {
3034
nodes,
3135
edges,
@@ -45,7 +49,7 @@ export default memo((edge: any) => {
4549
onEdgesChange: state.onEdgesChange,
4650
}),
4751
shallow
48-
);
52+
);
4953

5054
const handleAddNode = (data: any) => {
5155
const { screenToFlowPosition } = reactflow;
@@ -122,11 +126,13 @@ export default memo((edge: any) => {
122126
>
123127
<CloseOutlined style={{ color: '#fff', fontSize: 10 }} />
124128
</div>
125-
<NodeSelectPopover placement="right" addNode={handleAddNode}>
126-
<div className="line-icon-box">
127-
<PlusOutlined style={{ color: '#fff', fontSize: 10 }} />
128-
</div>
129-
</NodeSelectPopover>
129+
{
130+
!hideLineInsertBtn && <NodeSelectPopover placement="right" addNode={handleAddNode}>
131+
<div className="line-icon-box">
132+
<PlusOutlined style={{ color: '#fff', fontSize: 10 }} />
133+
</div>
134+
</NodeSelectPopover>
135+
}
130136
</div>
131137
</div>
132138
</EdgeLabelRenderer>

packages/x-flow/src/components/CustomNode/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default memo((props: any) => {
2727
shallow
2828
);
2929
const isSwitchNode = type === 'Switch';
30-
3130
// 增加节点并进行联系
3231
const handleAddNode = (data: any) => {
3332
const { screenToFlowPosition } = reactflow;

packages/x-flow/src/withProvider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default function withProvider<T>(
2727
initialValues,
2828
iconFontUrl,
2929
configPanelWidth,
30+
hideLineInsertBtn,
3031
...restProps
3132
} = props;
3233

@@ -51,6 +52,7 @@ export default function withProvider<T>(
5152
settingMap,
5253
iconFontUrl,
5354
configPanelWidth,
55+
hideLineInsertBtn,
5456
widgets: {
5557
...defaultWidgets,
5658
...widgets,

0 commit comments

Comments
 (0)