Skip to content

Commit bfb5eb2

Browse files
committed
Merge branch 'xflow' of https://github.com/alibaba/x-render into xflow
2 parents 3d6ca3c + 92fb67c commit bfb5eb2

File tree

12 files changed

+301
-160
lines changed

12 files changed

+301
-160
lines changed

docs/xflow/demo/layout/TB/index.tsx

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,7 @@
11
import XFlow from '@xrenders/xflow';
2-
import settings from './setting';
3-
import React from 'react';
2+
import { edges, nodes, settings } from './setting';
43

54
export default () => {
6-
const nodes = [
7-
{
8-
type: 'Start',
9-
id: '1',
10-
position: { x: 327.5, y: -14.5 },
11-
},
12-
{
13-
type: 'Switch',
14-
id: '2',
15-
position: { x: 328.75, y: 108 },
16-
},
17-
{
18-
type: 'Code',
19-
id: '3',
20-
position: { x: 638.75, y: 247.5 },
21-
},
22-
{
23-
type: 'tool',
24-
id: '4',
25-
position: { x: 75.00000000000003, y: 261.25 },
26-
},
27-
{
28-
type: 'End',
29-
id: '5',
30-
position: { x: 360, y: 501.25 },
31-
},
32-
];
33-
const edges = [
34-
{
35-
source: '1',
36-
target: '2',
37-
id: 'e1-2',
38-
},
39-
{
40-
source: '2',
41-
target: '3',
42-
id: 'e2-3',
43-
},
44-
{
45-
source: '2',
46-
target: '4',
47-
id: 'e2-4',
48-
},
49-
{
50-
source: '3',
51-
target: '5',
52-
id: 'e3-5',
53-
},
54-
{
55-
source: '4',
56-
target: '5',
57-
id: 'e4-5',
58-
},
59-
];
60-
615
return (
626
<div style={{ height: '600px' }}>
637
<XFlow

docs/xflow/demo/layout/TB/setting.tsx

Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default [
1+
export const settings = [
22
{
33
title: '开始',
44
type: 'Start',
@@ -36,34 +36,34 @@ export default [
3636
options: [
3737
{ label: '早', value: 'a' },
3838
{ label: '中', value: 'b' },
39-
{ label: '晚', value: 'c' }
40-
]
41-
}
39+
{ label: '晚', value: 'c' },
40+
],
41+
},
4242
},
4343
textarea1: {
4444
title: '长文本',
4545
type: 'string',
46-
widget: 'textArea'
46+
widget: 'textArea',
4747
},
4848
date1: {
4949
title: '日期选择',
5050
type: 'string',
51-
widget: 'datePicker'
51+
widget: 'datePicker',
5252
},
5353
dateRange1: {
5454
title: '日期范围',
5555
type: 'range',
56-
widget: 'dateRange'
56+
widget: 'dateRange',
5757
},
5858
time1: {
5959
title: '时间选择',
6060
type: 'string',
61-
widget: 'timePicker'
61+
widget: 'timePicker',
6262
},
6363
timeRange1: {
6464
title: '时间范围',
6565
type: 'range',
66-
widget: 'timeRange'
66+
widget: 'timeRange',
6767
},
6868
},
6969
},
@@ -78,7 +78,7 @@ export default [
7878
bgColor: '#F79009',
7979
},
8080
settingSchema: {
81-
type: "object",
81+
type: 'object',
8282
properties: {
8383
input: {
8484
title: '变量一',
@@ -97,8 +97,8 @@ export default [
9797
],
9898
},
9999
},
100-
}
101-
}
100+
},
101+
},
102102
},
103103
{
104104
title: 'LLM',
@@ -197,3 +197,84 @@ export default [
197197
],
198198
},
199199
];
200+
201+
export const nodes = [
202+
{
203+
type: 'Start',
204+
id: '1',
205+
position: {
206+
x: 346.25,
207+
y: -75.54414939880371,
208+
},
209+
},
210+
{
211+
type: 'Switch',
212+
id: 'b6zsd6w5ah2b209t',
213+
position: {
214+
x: 346.25,
215+
y: 41.75,
216+
},
217+
data: {
218+
list: [
219+
{
220+
_conditionId: 'iawoyh5niyi6zjob',
221+
},
222+
],
223+
},
224+
},
225+
{
226+
type: 'Code',
227+
id: '3',
228+
position: {
229+
x: 53,
230+
y: 207.5,
231+
},
232+
},
233+
{
234+
type: 'tool',
235+
id: '4',
236+
position: {
237+
x: 676,
238+
y: 220,
239+
},
240+
},
241+
{
242+
type: 'End',
243+
id: '5',
244+
position: {
245+
x: 388.7499999999998,
246+
y: 497.5,
247+
},
248+
},
249+
];
250+
export const edges = [
251+
{
252+
source: '3',
253+
target: '5',
254+
id: 'e3-5',
255+
},
256+
{
257+
source: '4',
258+
target: '5',
259+
id: 'e4-5',
260+
},
261+
{
262+
id: 'px7fsmha99pju315',
263+
source: '1',
264+
target: 'b6zsd6w5ah2b209t',
265+
},
266+
{
267+
type: 'buttonedge',
268+
source: 'b6zsd6w5ah2b209t',
269+
sourceHandle: 'iawoyh5niyi6zjob',
270+
target: '3',
271+
id: 'xy-edge__b6zsd6w5ah2b209tiawoyh5niyi6zjob-3',
272+
},
273+
{
274+
type: 'buttonedge',
275+
source: 'b6zsd6w5ah2b209t',
276+
sourceHandle: 'condition_else',
277+
target: '4',
278+
id: 'xy-edge__b6zsd6w5ah2b209tcondition_else-4',
279+
},
280+
];

packages/x-flow/src/XFlow.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const XFlow: FC<FlowProps> = memo(props => {
7676
);
7777
const { record } = useTemporalStore();
7878
const [activeNode, setActiveNode] = useState<any>(null);
79-
const { settingMap } = useContext(ConfigContext);
79+
const { settingMap,globalConfig } = useContext(ConfigContext);
8080
const [openPanel, setOpenPanel] = useState<boolean>(true);
8181
const [openLogPanel, setOpenLogPanel] = useState<boolean>(true);
8282
const { onNodeClick } = props;
@@ -254,6 +254,8 @@ const XFlow: FC<FlowProps> = memo(props => {
254254
);
255255
}, [activeNode?.id]);
256256

257+
const deletable = globalConfig?.edge?.deletable ?? true;
258+
257259
return (
258260
<div id="xflow-container" ref={workflowContainerRef}>
259261
<ReactFlow
@@ -271,6 +273,7 @@ const XFlow: FC<FlowProps> = memo(props => {
271273
markerEnd: {
272274
type: MarkerType.ArrowClosed, // 箭头
273275
},
276+
deletable:deletable //默认连线属性受此项控制
274277
}}
275278
onConnect={onConnect}
276279
onNodesChange={changes => {

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default memo((edge: any) => {
3838

3939
const { globalConfig, settingMap } = useContext(ConfigContext);
4040
const hideEdgeAddBtn = globalConfig?.edge?.hideEdgeAddBtn ?? false;
41+
const hideEdgeDelBtn = globalConfig?.edge?.hideEdgeDelBtn ?? false;
42+
const deletable = globalConfig?.edge?.deletable ?? true;
4143

4244
const {
4345
nodes,
@@ -89,11 +91,13 @@ export default memo((edge: any) => {
8991
id: uuid(),
9092
source,
9193
target: targetId,
94+
deletable:deletable,
9295
...(sourceHandleId && { sourceHandle: sourceHandleId }),
9396
},
9497
{
9598
id: uuid(),
9699
source: targetId,
100+
deletable:deletable,
97101
target,
98102
},
99103
]
@@ -135,12 +139,14 @@ export default memo((edge: any) => {
135139
}}
136140
>
137141
<div className="line-content">
138-
<div
139-
className="line-icon-box"
140-
onClick={() => onEdgesChange([{ id, type: 'remove' }])}
141-
>
142-
<CloseOutlined style={{ color: '#fff', fontSize: 10 }} />
143-
</div>
142+
{!hideEdgeDelBtn && (
143+
<div
144+
className="line-icon-box"
145+
onClick={() => onEdgesChange([{ id, type: 'remove' }])}
146+
>
147+
<CloseOutlined style={{ color: '#fff', fontSize: 10 }} />
148+
</div>
149+
)}
144150
{!hideEdgeAddBtn && (
145151
<NodeSelectPopover
146152
placement="right"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default memo((props: any) => {
1515
const { id, type, data, layout, isConnectable, selected, onClick, status } =
1616
props;
1717
const { widgets, settingMap, globalConfig } = useContext(ConfigContext);
18+
const deletable = globalConfig?.edge?.deletable ?? true;
1819
const NodeWidget =
1920
widgets[`${capitalize(type)}Node`] || widgets['CommonNode'];
2021
const [isHovered, setIsHovered] = useState(false);
@@ -57,6 +58,7 @@ export default memo((props: any) => {
5758
id: uuid(),
5859
source: id,
5960
target: targetId,
61+
deletable,
6062
...(sourceHandle && { sourceHandle }),
6163
};
6264
addNodes(newNodes);

packages/x-flow/src/components/NodeContainer/index.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
font-size: 12px;
2222
padding-top: 4px;
2323
margin-top: 10px;
24+
max-width: 100%;
2425
}
2526

2627
.icon-box {
@@ -69,3 +70,9 @@
6970
justify-content: center;
7071
}
7172
}
73+
74+
75+
.switch-node-code-bottom{
76+
min-width: 240px;
77+
width:min-content;
78+
}

0 commit comments

Comments
 (0)