Skip to content

Commit c026c3e

Browse files
author
昔梦
committed
fix:修复文档关于条件节点的错误展示以及layout失效的bug
1 parent eff366b commit c026c3e

File tree

5 files changed

+103
-61
lines changed

5 files changed

+103
-61
lines changed

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

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,8 @@
11
import XFlow from '@xrenders/xflow';
2-
import settings from './setting';
2+
import { settings,nodes,edges } from './setting';
33
import React from 'react';
44

55
export default () => {
6-
const nodes = [
7-
{
8-
type: 'Start',
9-
id: '1',
10-
position: { x: -35, y: 268 },
11-
},
12-
{
13-
type: 'Switch',
14-
id: '2',
15-
position: { x: 277.5, y: 268 },
16-
},
17-
{
18-
type: 'Code',
19-
id: '3',
20-
position: { x: 675, y: 123.75 },
21-
},
22-
{
23-
type: 'tool',
24-
id: '4',
25-
position: { x: 686.25, y: 495 },
26-
},
27-
{
28-
type: 'End',
29-
id: '5',
30-
position: { x: 1176.2499999999998, y: 281.25 },
31-
},
32-
];
33-
const edges = [
34-
{ source: '1', target: '2', id: 'e1-2' },
35-
{
36-
source: '2',
37-
target: '3',
38-
id: 'e2-3',
39-
},
40-
{ source: '2', target: '4', id: 'e2-4' },
41-
{
42-
source: '3',
43-
target: '5',
44-
id: 'e3-5',
45-
},
46-
{
47-
source: '4',
48-
target: '5',
49-
id: 'e4-5',
50-
},
51-
];
526

537
return (
548
<div style={{ height: '600px' }}>

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

Lines changed: 68 additions & 1 deletion
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',
@@ -197,3 +197,70 @@ export default [
197197
],
198198
},
199199
];
200+
201+
202+
export const nodes = [
203+
{
204+
type: 'Start',
205+
id: '1',
206+
position: { x: -35, y: 268 },
207+
},
208+
{
209+
type: 'Switch',
210+
id: 'b6zsd6w5ah2b209t',
211+
position: { x: 277.5, y: 268 },
212+
data: {
213+
list: [
214+
{
215+
_conditionId: 'iawoyh5niyi6zjob',
216+
},
217+
],
218+
},
219+
},
220+
{
221+
type: 'Code',
222+
id: '3',
223+
position: { x: 675, y: 123.75 },
224+
},
225+
{
226+
type: 'tool',
227+
id: '4',
228+
position: { x: 686.25, y: 495 },
229+
},
230+
{
231+
type: 'End',
232+
id: '5',
233+
position: { x: 1176.2499999999998, y: 281.25 },
234+
},
235+
];
236+
export const edges = [
237+
{
238+
source: '3',
239+
target: '5',
240+
id: 'e3-5',
241+
},
242+
{
243+
source: '4',
244+
target: '5',
245+
id: 'e4-5',
246+
},
247+
{
248+
id: 'px7fsmha99pju315',
249+
source: '1',
250+
target: 'b6zsd6w5ah2b209t',
251+
},
252+
{
253+
type: 'buttonedge',
254+
source: 'b6zsd6w5ah2b209t',
255+
sourceHandle: 'iawoyh5niyi6zjob',
256+
target: '3',
257+
id: 'xy-edge__b6zsd6w5ah2b209tiawoyh5niyi6zjob-3',
258+
},
259+
{
260+
type: 'buttonedge',
261+
source: 'b6zsd6w5ah2b209t',
262+
sourceHandle: 'condition_else',
263+
target: '4',
264+
id: 'xy-edge__b6zsd6w5ah2b209tcondition_else-4',
265+
},
266+
];

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default () => {
6666
nodeSelector={{
6767
showSearch: true,
6868
}}
69-
layout="LR"
69+
layout="TB"
7070
/>
7171
</div>
7272
);

docs/xflow/demo/nodeSetting/data.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const settings = [
1111
},
1212
nodePanel: {
1313
width: 600,
14-
hideDesc:false,
14+
hideDesc: false,
1515
},
1616
settingSchema: {
1717
// 自定义节点配置
@@ -172,8 +172,15 @@ export const nodes = [
172172
},
173173
{
174174
type: 'Switch',
175-
id: '2',
175+
id: 'b6zsd6w5ah2b209t',
176176
position: { x: 277.5, y: 268 },
177+
data: {
178+
list: [
179+
{
180+
_conditionId: 'iawoyh5niyi6zjob',
181+
},
182+
],
183+
},
177184
},
178185
{
179186
type: 'Code',
@@ -192,13 +199,6 @@ export const nodes = [
192199
},
193200
];
194201
export const edges = [
195-
{ source: '1', target: '2', id: 'e1-2' },
196-
{
197-
source: '2',
198-
target: '3',
199-
id: 'e2-3',
200-
},
201-
{ source: '2', target: '4', id: 'e2-4' },
202202
{
203203
source: '3',
204204
target: '5',
@@ -209,4 +209,23 @@ export const edges = [
209209
target: '5',
210210
id: 'e4-5',
211211
},
212+
{
213+
id: 'px7fsmha99pju315',
214+
source: '1',
215+
target: 'b6zsd6w5ah2b209t',
216+
},
217+
{
218+
type: 'buttonedge',
219+
source: 'b6zsd6w5ah2b209t',
220+
sourceHandle: 'iawoyh5niyi6zjob',
221+
target: '3',
222+
id: 'xy-edge__b6zsd6w5ah2b209tiawoyh5niyi6zjob-3',
223+
},
224+
{
225+
type: 'buttonedge',
226+
source: 'b6zsd6w5ah2b209t',
227+
sourceHandle: 'condition_else',
228+
target: '4',
229+
id: 'xy-edge__b6zsd6w5ah2b209tcondition_else-4',
230+
},
212231
];

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ export const FlowProvider = memo<{
1010
initialNodes?: any[];
1111
initialEdges?: any[];
1212
children: ReactNode;
13-
}>(({ initialNodes: nodes = [], initialEdges: edges = [], children }) => {
13+
layout?: 'LR' | 'TB';
14+
}>(({ initialNodes: nodes = [], initialEdges: edges = [], children, layout = 'LR' }) => {
1415
const [store] = useState(() =>
1516
createStore({
1617
nodes,
1718
edges,
19+
layout
1820
})
1921
);
2022

@@ -52,7 +54,7 @@ export const FlowProviderWrapper = ({
5254
nodes: any[];
5355
edges: any[];
5456
layout?: 'LR' | 'TB';
55-
}) => {
57+
}) => {
5658
const isWrapped = useContext(StoreContext);
5759

5860
if (isWrapped) {
@@ -64,7 +66,7 @@ export const FlowProviderWrapper = ({
6466
}
6567

6668
return (
67-
<FlowProvider initialNodes={transformNodes(nodes)} initialEdges={edges}>
69+
<FlowProvider initialNodes={transformNodes(nodes)} initialEdges={edges} layout={layout}>
6870
{children}
6971
</FlowProvider>
7072
);

0 commit comments

Comments
 (0)