@kne/react-flow-chart 0.1.10 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -19
- package/dist/index.css +285 -166
- package/dist/index.css.map +1 -1
- package/dist/index.js +238 -160
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +206 -107
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en.js +8 -1
- package/dist/locale/en.js.map +1 -1
- package/dist/locale/en.modern.js +8 -1
- package/dist/locale/en.modern.js.map +1 -1
- package/dist/locale/zh-cn.js +8 -1
- package/dist/locale/zh-cn.js.map +1 -1
- package/dist/locale/zh-cn.modern.js +8 -1
- package/dist/locale/zh-cn.modern.js.map +1 -1
- package/package.json +2 -2
- package/dist/arrow~bbpMpvlG.svg +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
var React = require('react');
|
|
2
2
|
var useEvent = require('@kne/use-event');
|
|
3
3
|
var classnames = require('classnames');
|
|
4
|
-
var add_nSLLXReQ_svg = require('./add~nSLLXReQ.svg');
|
|
5
4
|
var reactIntl = require('react-intl');
|
|
6
|
-
var
|
|
5
|
+
var add_nSLLXReQ_svg = require('./add~nSLLXReQ.svg');
|
|
7
6
|
var delete_RuDNzAkQ_svg = require('./delete~RuDNzAkQ.svg');
|
|
8
7
|
var uuid = require('uuid');
|
|
9
8
|
var useControlValue = require('@kne/use-control-value');
|
|
@@ -13,20 +12,9 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
13
12
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
14
13
|
var useEvent__default = /*#__PURE__*/_interopDefaultLegacy(useEvent);
|
|
15
14
|
var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
|
|
16
|
-
var arrow__default = /*#__PURE__*/_interopDefaultLegacy(arrow);
|
|
17
15
|
var useControlValue__default = /*#__PURE__*/_interopDefaultLegacy(useControlValue);
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
if (null == r) return {};
|
|
21
|
-
var t = {};
|
|
22
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
23
|
-
if (e.includes(n)) continue;
|
|
24
|
-
t[n] = r[n];
|
|
25
|
-
}
|
|
26
|
-
return t;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var style = {"container":"_AIhaC","show-scrollbar":"_qp1e9","content":"_XZmmG","is-scale":"_q6z6A","vertical":"_B4OPa","arrow-line":"_W5dM8","show-arrow":"_0Cmjn","add-node":"_sVaw9","add-node-btn":"_Y4-Yv","dot":"_06DKa","normal":"_59XmF","node-type-popover":"_6Grsl","show":"_DGtHa","action-bar":"_vxlwT","action-scale":"_xd3mP","action-scale-btn":"_IVeCE","action-scale-num":"_c9-Rl","condition-node-container":"_QTtQr","condition-add-btn":"_9Gq3x","condition-node-item-list":"_MlJIV","condition-node-item":"_4TP17","condition-node-item-line":"_Q-b5J","condition-node-item-last-line":"_n1DDB","condition-node-item-link-line":"_l-p-G","condition-node-item-node-wrap":"_MnV8A","condition-node-item-link-cross-line":"_ERDNK","delete-node":"_I73Kt","end-node-container":"_WzQqY","node-container":"_HGnYM","normal-node-content":"_Uf6Nh","normal-node-title":"_-7Pvj","normal-node-data":"_leHgE","normal-node-data-text":"_Kqf3r","normal-node-data-icon":"_-RR3K","node-type-content":"_0sM8G","node-type-group":"_wsgr5","node-type-group-name":"_ka6d9","node-type-list":"_lmTJ8","node-type-item":"_4q38j","normal-node-container":"_vS7Kd","normal-node-wrap":"_FhjH6","normal-node-content-wrap":"_EYYsJ","start-node-container":"_pydi2","start-node-content":"_u41XY","condition-content-title":"_MgJlN","condition-content-title-add-btn":"_X7-fq"};
|
|
17
|
+
var style = {"wrapper":"kne-react-flow-chart_Gah47","container":"kne-react-flow-chart_AIhaC","show-scrollbar":"kne-react-flow-chart_qp1e9","content":"kne-react-flow-chart_XZmmG","is-scale":"kne-react-flow-chart_q6z6A","vertical":"kne-react-flow-chart_B4OPa","arrow-line":"kne-react-flow-chart_W5dM8","show-arrow":"kne-react-flow-chart_0Cmjn","add-node":"kne-react-flow-chart_sVaw9","add-node-btn":"kne-react-flow-chart_Y4-Yv","dot":"kne-react-flow-chart_06DKa","normal":"kne-react-flow-chart_59XmF","node-type-popover":"kne-react-flow-chart_6Grsl","show":"kne-react-flow-chart_DGtHa","action-bar":"kne-react-flow-chart_vxlwT","action-scale":"kne-react-flow-chart_xd3mP","action-scale-btn":"kne-react-flow-chart_IVeCE","is-disabled":"kne-react-flow-chart_-cv3B","action-scale-reset":"kne-react-flow-chart_9Mw3U","action-scale-divider":"kne-react-flow-chart_Nu4nf","action-scale-num":"kne-react-flow-chart_c9-Rl","condition-node-container":"kne-react-flow-chart_QTtQr","condition-add-btn":"kne-react-flow-chart_9Gq3x","condition-node-item-list":"kne-react-flow-chart_MlJIV","condition-node-item":"kne-react-flow-chart_4TP17","condition-node-item-line":"kne-react-flow-chart_Q-b5J","condition-node-item-last-line":"kne-react-flow-chart_n1DDB","condition-node-item-link-line":"kne-react-flow-chart_l-p-G","condition-node-item-node-wrap":"kne-react-flow-chart_MnV8A","condition-node-item-link-cross-line":"kne-react-flow-chart_ERDNK","delete-node":"kne-react-flow-chart_I73Kt","end-node-container":"kne-react-flow-chart_WzQqY","node-container":"kne-react-flow-chart_HGnYM","normal-node-content":"kne-react-flow-chart_Uf6Nh","normal-node-title":"kne-react-flow-chart_-7Pvj","normal-node-data":"kne-react-flow-chart_leHgE","normal-node-data-text":"kne-react-flow-chart_Kqf3r","normal-node-data-icon":"kne-react-flow-chart_-RR3K","node-type-content":"kne-react-flow-chart_0sM8G","node-type-group":"kne-react-flow-chart_wsgr5","node-type-group-name":"kne-react-flow-chart_ka6d9","node-type-list":"kne-react-flow-chart_lmTJ8","node-type-item":"kne-react-flow-chart_4q38j","node-type-item-icon":"kne-react-flow-chart_LlqNc","node-type-item-text":"kne-react-flow-chart_FP-Sn","node-type-item-name":"kne-react-flow-chart_BuYmx","node-type-item-desc":"kne-react-flow-chart_yhXFF","normal-node-container":"kne-react-flow-chart_vS7Kd","normal-node-wrap":"kne-react-flow-chart_FhjH6","normal-node-content-wrap":"kne-react-flow-chart_EYYsJ","start-node-container":"kne-react-flow-chart_pydi2","start-node-content":"kne-react-flow-chart_u41XY","condition-content-title":"kne-react-flow-chart_MgJlN","condition-content-title-add-btn":"kne-react-flow-chart_X7-fq"};
|
|
30
18
|
|
|
31
19
|
const getDefaultNodeList = ({
|
|
32
20
|
formatMessage
|
|
@@ -65,6 +53,11 @@ const getDefaultNodeTypeList = ({
|
|
|
65
53
|
name: formatMessage({
|
|
66
54
|
id: 'conditionBranch'
|
|
67
55
|
})
|
|
56
|
+
}, {
|
|
57
|
+
type: 'parallel',
|
|
58
|
+
name: formatMessage({
|
|
59
|
+
id: 'parallelBranch'
|
|
60
|
+
})
|
|
68
61
|
}]
|
|
69
62
|
}];
|
|
70
63
|
};
|
|
@@ -78,19 +71,31 @@ const useContext = () => {
|
|
|
78
71
|
return React.useContext(context);
|
|
79
72
|
};
|
|
80
73
|
|
|
74
|
+
const MIN_SCALE = 10;
|
|
75
|
+
const MAX_SCALE = 300;
|
|
81
76
|
const ActionBar = props => {
|
|
82
77
|
const {
|
|
83
78
|
scale,
|
|
84
79
|
onChange
|
|
85
80
|
} = Object.assign({}, {}, props);
|
|
81
|
+
const {
|
|
82
|
+
formatMessage
|
|
83
|
+
} = reactIntl.useIntl();
|
|
84
|
+
const change = next => onChange(Math.min(MAX_SCALE, Math.max(MIN_SCALE, next)));
|
|
86
85
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
87
|
-
className: style['action-bar']
|
|
86
|
+
className: classnames__default["default"]('flow-chart-action-bar', style['action-bar']),
|
|
87
|
+
onMouseDown: e => e.stopPropagation()
|
|
88
88
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
89
89
|
className: style['action-scale']
|
|
90
90
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
91
|
-
className: style['action-scale-btn'],
|
|
91
|
+
className: classnames__default["default"](style['action-scale-btn'], {
|
|
92
|
+
[style['is-disabled']]: scale >= MAX_SCALE
|
|
93
|
+
}),
|
|
94
|
+
title: formatMessage({
|
|
95
|
+
id: 'zoomIn'
|
|
96
|
+
}),
|
|
92
97
|
onClick: () => {
|
|
93
|
-
|
|
98
|
+
change(scale + 10);
|
|
94
99
|
}
|
|
95
100
|
}, /*#__PURE__*/React__default["default"].createElement("svg", {
|
|
96
101
|
viewBox: "0 0 1024 1024",
|
|
@@ -101,9 +106,14 @@ const ActionBar = props => {
|
|
|
101
106
|
}))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
102
107
|
className: style['action-scale-num']
|
|
103
108
|
}, scale.toFixed(0), "%"), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
104
|
-
className: style['action-scale-btn'],
|
|
109
|
+
className: classnames__default["default"](style['action-scale-btn'], {
|
|
110
|
+
[style['is-disabled']]: scale <= MIN_SCALE
|
|
111
|
+
}),
|
|
112
|
+
title: formatMessage({
|
|
113
|
+
id: 'zoomOut'
|
|
114
|
+
}),
|
|
105
115
|
onClick: () => {
|
|
106
|
-
|
|
116
|
+
change(scale - 10);
|
|
107
117
|
}
|
|
108
118
|
}, /*#__PURE__*/React__default["default"].createElement("svg", {
|
|
109
119
|
viewBox: "0 0 1024 1024",
|
|
@@ -111,7 +121,19 @@ const ActionBar = props => {
|
|
|
111
121
|
xmlns: "http://www.w3.org/2000/svg"
|
|
112
122
|
}, /*#__PURE__*/React__default["default"].createElement("path", {
|
|
113
123
|
d: "M587.229378 437.990403 580.722174 437.990403 76.975139 437.990403 76.975139 581.918419 580.722174 581.918419 587.229378 581.918419 940.542216 581.918419 940.542216 437.990403Z"
|
|
114
|
-
})))
|
|
124
|
+
}))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
125
|
+
className: style['action-scale-divider']
|
|
126
|
+
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
127
|
+
className: classnames__default["default"](style['action-scale-reset'], {
|
|
128
|
+
[style['is-disabled']]: scale === 100
|
|
129
|
+
}),
|
|
130
|
+
title: formatMessage({
|
|
131
|
+
id: 'resetScale'
|
|
132
|
+
}),
|
|
133
|
+
onClick: () => {
|
|
134
|
+
onChange(100);
|
|
135
|
+
}
|
|
136
|
+
}, "1:1")));
|
|
115
137
|
};
|
|
116
138
|
|
|
117
139
|
const ArrowLine = props => {
|
|
@@ -149,18 +171,26 @@ const NodeTypeContent = props => {
|
|
|
149
171
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
150
172
|
className: style['node-type-group'],
|
|
151
173
|
key: groupIndex
|
|
152
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
174
|
+
}, group.name && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
153
175
|
className: style['node-type-group-name']
|
|
154
176
|
}, group.name), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
155
177
|
className: style['node-type-list']
|
|
156
178
|
}, group.list.map((nodeType, typeIndex) => {
|
|
157
179
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
158
|
-
className: style['node-type-item'],
|
|
180
|
+
className: classnames__default["default"](style['node-type-item'], nodeType.className),
|
|
159
181
|
key: typeIndex,
|
|
160
182
|
onClick: e => {
|
|
161
183
|
onClick && onClick(nodeType);
|
|
162
184
|
}
|
|
163
|
-
}, nodeType.
|
|
185
|
+
}, nodeType.icon && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
186
|
+
className: classnames__default["default"](style['node-type-item-icon'], 'flow-chart-node-type-icon')
|
|
187
|
+
}, nodeType.icon), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
188
|
+
className: style['node-type-item-text']
|
|
189
|
+
}, /*#__PURE__*/React__default["default"].createElement("span", {
|
|
190
|
+
className: style['node-type-item-name']
|
|
191
|
+
}, nodeType.name), nodeType.description && /*#__PURE__*/React__default["default"].createElement("span", {
|
|
192
|
+
className: style['node-type-item-desc']
|
|
193
|
+
}, nodeType.description)));
|
|
164
194
|
})));
|
|
165
195
|
}));
|
|
166
196
|
};
|
|
@@ -291,10 +321,24 @@ const NodeContent = props => {
|
|
|
291
321
|
nodeData
|
|
292
322
|
} = Object.assign({}, {}, props);
|
|
293
323
|
const {
|
|
294
|
-
emitter
|
|
324
|
+
emitter,
|
|
325
|
+
renderNodeContent,
|
|
326
|
+
renderNodeTitle,
|
|
327
|
+
getNodeClassName
|
|
295
328
|
} = useContext();
|
|
329
|
+
const defaultTitle = (typeof nodeData.titleRender === 'function' ? nodeData.titleRender(nodeData) : nodeData.title) || '';
|
|
330
|
+
const title = typeof renderNodeTitle === 'function' ? renderNodeTitle({
|
|
331
|
+
nodeData,
|
|
332
|
+
title: defaultTitle
|
|
333
|
+
}) : defaultTitle;
|
|
334
|
+
const content = typeof renderNodeContent === 'function' ? renderNodeContent({
|
|
335
|
+
nodeData,
|
|
336
|
+
content: nodeData.content
|
|
337
|
+
}) : nodeData.content;
|
|
296
338
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
297
|
-
className: style['normal-node-content'],
|
|
339
|
+
className: classnames__default["default"](style['normal-node-content'], 'flow-chart-node-content', typeof getNodeClassName === 'function' && getNodeClassName({
|
|
340
|
+
nodeData
|
|
341
|
+
})),
|
|
298
342
|
onClick: () => {
|
|
299
343
|
emitter.emit('node-content-click', {
|
|
300
344
|
nodeData
|
|
@@ -302,15 +346,18 @@ const NodeContent = props => {
|
|
|
302
346
|
}
|
|
303
347
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
304
348
|
className: style['normal-node-title']
|
|
305
|
-
},
|
|
306
|
-
className: style['normal-node-data']
|
|
349
|
+
}, title), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
350
|
+
className: classnames__default["default"](style['normal-node-data'], 'flow-chart-node-data')
|
|
307
351
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
308
352
|
className: style['normal-node-data-text']
|
|
309
|
-
},
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
353
|
+
}, content || ''), /*#__PURE__*/React__default["default"].createElement("svg", {
|
|
354
|
+
className: classnames__default["default"](style['normal-node-data-icon'], 'flow-chart-node-data-icon'),
|
|
355
|
+
viewBox: "64 64 896 896",
|
|
356
|
+
fill: "currentColor",
|
|
357
|
+
"aria-hidden": "true"
|
|
358
|
+
}, /*#__PURE__*/React__default["default"].createElement("path", {
|
|
359
|
+
d: "M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z"
|
|
360
|
+
}))));
|
|
314
361
|
};
|
|
315
362
|
|
|
316
363
|
const ConditionNode = props => {
|
|
@@ -330,8 +377,11 @@ const ConditionNode = props => {
|
|
|
330
377
|
readonly,
|
|
331
378
|
emitter
|
|
332
379
|
} = useContext();
|
|
380
|
+
const addBranchText = formatMessage({
|
|
381
|
+
id: nodeData.type === 'parallel' ? 'addBranch' : 'addConditions'
|
|
382
|
+
});
|
|
333
383
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
334
|
-
className: classnames__default["default"](style['condition-node-container'], {
|
|
384
|
+
className: classnames__default["default"](style['condition-node-container'], `flow-chart-${nodeData.type}-node`, {
|
|
335
385
|
[style['vertical']]: vertical
|
|
336
386
|
})
|
|
337
387
|
}, !readonly && !nodeData.content && /*#__PURE__*/React__default["default"].createElement("div", {
|
|
@@ -341,9 +391,7 @@ const ConditionNode = props => {
|
|
|
341
391
|
nodeData
|
|
342
392
|
});
|
|
343
393
|
}
|
|
344
|
-
},
|
|
345
|
-
id: 'addConditions'
|
|
346
|
-
})), nodeData.content && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(NodeContent, {
|
|
394
|
+
}, addBranchText), nodeData.content && /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(NodeContent, {
|
|
347
395
|
nodeData: Object.assign({}, nodeData, {
|
|
348
396
|
titleRender: nodeData => /*#__PURE__*/React__default["default"].createElement("div", {
|
|
349
397
|
className: style['condition-content-title']
|
|
@@ -355,9 +403,7 @@ const ConditionNode = props => {
|
|
|
355
403
|
nodeData
|
|
356
404
|
});
|
|
357
405
|
}
|
|
358
|
-
},
|
|
359
|
-
id: 'addConditions'
|
|
360
|
-
}))))
|
|
406
|
+
}, addBranchText)))
|
|
361
407
|
})
|
|
362
408
|
}), /*#__PURE__*/React__default["default"].createElement(ArrowLine, null)), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
363
409
|
className: style['condition-node-item-list']
|
|
@@ -471,7 +517,7 @@ const Node = props => {
|
|
|
471
517
|
nodeData: nodeData
|
|
472
518
|
});
|
|
473
519
|
}
|
|
474
|
-
if (nodeData.type === 'condition') {
|
|
520
|
+
if (nodeData.type === 'condition' || nodeData.type === 'parallel') {
|
|
475
521
|
return /*#__PURE__*/React__default["default"].createElement(ConditionNode, {
|
|
476
522
|
nodeData: nodeData,
|
|
477
523
|
isMouseEnter: isMouseEnter || isCurrentMouseEnter
|
|
@@ -484,7 +530,7 @@ const Node = props => {
|
|
|
484
530
|
});
|
|
485
531
|
};
|
|
486
532
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
487
|
-
className: style['node-container'],
|
|
533
|
+
className: classnames__default["default"](style['node-container'], `flow-chart-node-${nodeData.type}`),
|
|
488
534
|
onMouseEnter: () => {
|
|
489
535
|
setIsCurrentMouseEnter(true);
|
|
490
536
|
},
|
|
@@ -496,6 +542,27 @@ const Node = props => {
|
|
|
496
542
|
}));
|
|
497
543
|
};
|
|
498
544
|
|
|
545
|
+
const BRANCH_CONTAINER_TYPES = ['condition', 'parallel'];
|
|
546
|
+
const isBranchContainer = type => BRANCH_CONTAINER_TYPES.indexOf(type) > -1;
|
|
547
|
+
const findNode = (tree, {
|
|
548
|
+
currentNodeId
|
|
549
|
+
}) => {
|
|
550
|
+
const core = tree => {
|
|
551
|
+
if (Array.isArray(tree)) {
|
|
552
|
+
for (let node of tree) {
|
|
553
|
+
const res = core(node);
|
|
554
|
+
if (res) {
|
|
555
|
+
return res;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (tree.id === currentNodeId) {
|
|
560
|
+
return tree;
|
|
561
|
+
}
|
|
562
|
+
return tree.children ? core(tree.children) : null;
|
|
563
|
+
};
|
|
564
|
+
return core(tree);
|
|
565
|
+
};
|
|
499
566
|
const appendNode = (tree, {
|
|
500
567
|
currentNodeId,
|
|
501
568
|
node,
|
|
@@ -506,7 +573,7 @@ const appendNode = (tree, {
|
|
|
506
573
|
const currentIndex = tree.findIndex(node => node.id === currentNodeId);
|
|
507
574
|
if (currentIndex > -1) {
|
|
508
575
|
const newTree = tree.slice(0);
|
|
509
|
-
if (newTree[currentIndex].type === '
|
|
576
|
+
if (isBranchContainer(newTree[currentIndex].type) && (type === 'branch' || type === newTree[currentIndex].type)) {
|
|
510
577
|
const newNode = Object.assign({}, newTree[currentIndex]);
|
|
511
578
|
const newChildren = (newNode.children || []).slice(0);
|
|
512
579
|
newChildren.push([node]);
|
|
@@ -541,7 +608,7 @@ const removeNode = (tree, {
|
|
|
541
608
|
return newTree;
|
|
542
609
|
} else {
|
|
543
610
|
return tree.map(node => core(node)).filter(node => {
|
|
544
|
-
return !(node.type
|
|
611
|
+
return !(isBranchContainer(node.type) && node.children.length < 2);
|
|
545
612
|
});
|
|
546
613
|
}
|
|
547
614
|
}
|
|
@@ -565,12 +632,19 @@ const replaceNode = (tree, {
|
|
|
565
632
|
type: tree.type
|
|
566
633
|
});
|
|
567
634
|
}
|
|
568
|
-
return tree.children ? Object.assign(tree, {
|
|
635
|
+
return tree.children ? Object.assign({}, tree, {
|
|
569
636
|
children: core(tree.children)
|
|
570
637
|
}) : tree;
|
|
571
638
|
};
|
|
572
639
|
return core(tree);
|
|
573
640
|
};
|
|
641
|
+
const treeUtil = {
|
|
642
|
+
findNode,
|
|
643
|
+
appendNode,
|
|
644
|
+
removeNode,
|
|
645
|
+
replaceNode,
|
|
646
|
+
isBranchContainer
|
|
647
|
+
};
|
|
574
648
|
|
|
575
649
|
const message = {};
|
|
576
650
|
const loader = (locale, localeMessage) => {
|
|
@@ -587,35 +661,41 @@ const locale = {
|
|
|
587
661
|
condition: '条件',
|
|
588
662
|
conditionContent: '条件内容',
|
|
589
663
|
nodeContent: '节点内容',
|
|
590
|
-
addConditions: '添加条件'
|
|
664
|
+
addConditions: '添加条件',
|
|
665
|
+
parallelBranch: '并行分支',
|
|
666
|
+
branch: '分支',
|
|
667
|
+
branchContent: '分支内容',
|
|
668
|
+
addBranch: '添加分支',
|
|
669
|
+
zoomIn: '放大',
|
|
670
|
+
zoomOut: '缩小',
|
|
671
|
+
resetScale: '还原到 100%'
|
|
591
672
|
};
|
|
592
673
|
|
|
593
|
-
const _excluded = ["className"],
|
|
594
|
-
_excluded2 = ["readonly", "showScrollBar", "enableDrag", "initFit", "vertical", "onEditNode", "nodeTemplate"],
|
|
595
|
-
_excluded3 = ["locale"];
|
|
596
674
|
loader('zh-cn', locale);
|
|
597
|
-
const FlowChart =
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
675
|
+
const FlowChart = ({
|
|
676
|
+
className,
|
|
677
|
+
...props
|
|
678
|
+
}) => {
|
|
679
|
+
const {
|
|
680
|
+
readonly,
|
|
681
|
+
showScrollBar,
|
|
682
|
+
enableDrag,
|
|
683
|
+
initFit,
|
|
684
|
+
vertical,
|
|
685
|
+
onEditNode,
|
|
686
|
+
nodeTemplate,
|
|
687
|
+
nodeTypeList,
|
|
688
|
+
renderNodeContent,
|
|
689
|
+
renderNodeTitle,
|
|
690
|
+
getNodeClassName,
|
|
691
|
+
...otherProps
|
|
692
|
+
} = Object.assign({}, {
|
|
693
|
+
showScrollBar: true,
|
|
694
|
+
enableDrag: true,
|
|
695
|
+
initFit: true,
|
|
696
|
+
vertical: false,
|
|
697
|
+
nodeTemplate: {}
|
|
698
|
+
}, props);
|
|
619
699
|
const {
|
|
620
700
|
formatMessage
|
|
621
701
|
} = reactIntl.useIntl();
|
|
@@ -659,97 +739,89 @@ const FlowChart = _ref => {
|
|
|
659
739
|
}
|
|
660
740
|
}, [initFit]);
|
|
661
741
|
React.useEffect(() => {
|
|
662
|
-
|
|
663
|
-
|
|
742
|
+
const getTemplate = (type, parentType) => {
|
|
743
|
+
const template = nodeTemplateRef.current?.[type];
|
|
744
|
+
return typeof template === 'function' ? template({
|
|
664
745
|
type,
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
746
|
+
parentType
|
|
747
|
+
}) : template;
|
|
748
|
+
};
|
|
749
|
+
const createBranch = parentType => {
|
|
750
|
+
const defaultBranch = parentType === 'parallel' ? {
|
|
751
|
+
title: formatMessage({
|
|
752
|
+
id: 'branch'
|
|
753
|
+
}),
|
|
754
|
+
content: formatMessage({
|
|
755
|
+
id: 'branchContent'
|
|
756
|
+
})
|
|
757
|
+
} : {
|
|
758
|
+
title: formatMessage({
|
|
759
|
+
id: 'condition'
|
|
760
|
+
}),
|
|
761
|
+
content: formatMessage({
|
|
762
|
+
id: 'conditionContent'
|
|
763
|
+
})
|
|
764
|
+
};
|
|
765
|
+
return Object.assign({}, defaultBranch, getTemplate('branch', parentType), {
|
|
766
|
+
id: uuid.v4(),
|
|
767
|
+
type: 'branch'
|
|
768
|
+
});
|
|
769
|
+
};
|
|
770
|
+
const defaultTitles = {
|
|
771
|
+
condition: {
|
|
772
|
+
title: formatMessage({
|
|
773
|
+
id: 'conditionBranch'
|
|
774
|
+
})
|
|
775
|
+
},
|
|
776
|
+
parallel: {
|
|
777
|
+
title: formatMessage({
|
|
778
|
+
id: 'parallelBranch'
|
|
779
|
+
})
|
|
780
|
+
},
|
|
781
|
+
normal: {
|
|
782
|
+
title: formatMessage({
|
|
783
|
+
id: 'normalNode'
|
|
784
|
+
}),
|
|
785
|
+
content: formatMessage({
|
|
786
|
+
id: 'nodeContent'
|
|
787
|
+
})
|
|
701
788
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}, (_nodeTemplateRef$curr4 = nodeTemplateRef.current) == null ? void 0 : _nodeTemplateRef$curr4['normal'], {
|
|
714
|
-
id: uuid.v4(),
|
|
715
|
-
type: 'normal'
|
|
716
|
-
})
|
|
717
|
-
}));
|
|
789
|
+
};
|
|
790
|
+
emitter.addListener('add-node-type-click', ({
|
|
791
|
+
type,
|
|
792
|
+
nodeData
|
|
793
|
+
}) => {
|
|
794
|
+
const node = Object.assign({}, defaultTitles[type], getTemplate(type), {
|
|
795
|
+
id: uuid.v4(),
|
|
796
|
+
type
|
|
797
|
+
});
|
|
798
|
+
if (isBranchContainer(type)) {
|
|
799
|
+
node.children = [[createBranch(type)], [createBranch(type)]];
|
|
718
800
|
}
|
|
801
|
+
setNodeList(appendNode(nodeListRef.current, {
|
|
802
|
+
currentNodeId: nodeData.id,
|
|
803
|
+
node
|
|
804
|
+
}));
|
|
719
805
|
});
|
|
720
|
-
emitter.addListener('delete-node-click',
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
} = _ref3;
|
|
806
|
+
emitter.addListener('delete-node-click', ({
|
|
807
|
+
nodeData
|
|
808
|
+
}) => {
|
|
724
809
|
setNodeList(removeNode(nodeListRef.current, {
|
|
725
810
|
currentNodeId: nodeData.id
|
|
726
811
|
}));
|
|
727
812
|
});
|
|
728
|
-
emitter.addListener('add-condition-branch-click',
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
nodeData
|
|
732
|
-
} = _ref4;
|
|
813
|
+
emitter.addListener('add-condition-branch-click', ({
|
|
814
|
+
nodeData
|
|
815
|
+
}) => {
|
|
733
816
|
setNodeList(appendNode(nodeListRef.current, {
|
|
734
817
|
currentNodeId: nodeData.id,
|
|
735
|
-
type: '
|
|
736
|
-
node:
|
|
737
|
-
title: formatMessage({
|
|
738
|
-
id: 'condition'
|
|
739
|
-
}),
|
|
740
|
-
content: formatMessage({
|
|
741
|
-
id: 'conditionContent'
|
|
742
|
-
})
|
|
743
|
-
}, (_nodeTemplateRef$curr5 = nodeTemplateRef.current) == null ? void 0 : _nodeTemplateRef$curr5['branch'], {
|
|
744
|
-
id: uuid.v4(),
|
|
745
|
-
type: 'branch'
|
|
746
|
-
})
|
|
818
|
+
type: 'branch',
|
|
819
|
+
node: createBranch(nodeData.type)
|
|
747
820
|
}));
|
|
748
821
|
});
|
|
749
|
-
emitter.addListener('node-content-click',
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
} = _ref5;
|
|
822
|
+
emitter.addListener('node-content-click', ({
|
|
823
|
+
nodeData
|
|
824
|
+
}) => {
|
|
753
825
|
onEditNodeRef.current && onEditNodeRef.current({
|
|
754
826
|
nodeData,
|
|
755
827
|
replaceNode: node => {
|
|
@@ -782,9 +854,18 @@ const FlowChart = _ref => {
|
|
|
782
854
|
readonly,
|
|
783
855
|
vertical,
|
|
784
856
|
nodeList,
|
|
857
|
+
nodeTypeList,
|
|
858
|
+
renderNodeContent,
|
|
859
|
+
renderNodeTitle,
|
|
860
|
+
getNodeClassName,
|
|
785
861
|
emitter
|
|
786
862
|
}
|
|
787
863
|
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
864
|
+
className: classnames__default["default"]('flow-chart-wrapper', style['wrapper'])
|
|
865
|
+
}, /*#__PURE__*/React__default["default"].createElement(ActionBar, {
|
|
866
|
+
scale: scale,
|
|
867
|
+
onChange: setScale
|
|
868
|
+
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
788
869
|
ref: containerRef,
|
|
789
870
|
className: classnames__default["default"](className, 'flow-chart-container', style['container'], {
|
|
790
871
|
[style['show-scrollbar']]: showScrollBar
|
|
@@ -796,17 +877,14 @@ const FlowChart = _ref => {
|
|
|
796
877
|
mousePosition.current.scrollLeft = containerRef.current.scrollLeft;
|
|
797
878
|
mousePosition.current.scrollTop = containerRef.current.scrollTop;
|
|
798
879
|
}
|
|
799
|
-
}, /*#__PURE__*/React__default["default"].createElement(
|
|
800
|
-
scale: scale,
|
|
801
|
-
onChange: setScale
|
|
802
|
-
}), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
880
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
803
881
|
ref: contentRef,
|
|
804
882
|
className: classnames__default["default"]('flow-chart-content', style['content'], {
|
|
805
883
|
[style['vertical']]: vertical,
|
|
806
884
|
[style['is-scale']]: scale <= 100
|
|
807
885
|
}),
|
|
808
886
|
style: {
|
|
809
|
-
transform:
|
|
887
|
+
transform: `scale(${scale / 100})`
|
|
810
888
|
}
|
|
811
889
|
}, nodeList.map(node => {
|
|
812
890
|
return /*#__PURE__*/React__default["default"].createElement(Node, {
|
|
@@ -814,13 +892,12 @@ const FlowChart = _ref => {
|
|
|
814
892
|
nodeList: nodeList,
|
|
815
893
|
nodeData: node
|
|
816
894
|
});
|
|
817
|
-
}))));
|
|
895
|
+
})))));
|
|
818
896
|
};
|
|
819
|
-
const FlowChartIntl =
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
props = _objectWithoutPropertiesLoose(_ref6, _excluded3);
|
|
897
|
+
const FlowChartIntl = ({
|
|
898
|
+
locale = 'zh-cn',
|
|
899
|
+
...props
|
|
900
|
+
}) => {
|
|
824
901
|
return /*#__PURE__*/React__default["default"].createElement(reactIntl.IntlProvider, {
|
|
825
902
|
messages: message[locale],
|
|
826
903
|
locale: locale
|
|
@@ -829,4 +906,5 @@ const FlowChartIntl = _ref6 => {
|
|
|
829
906
|
|
|
830
907
|
exports["default"] = FlowChartIntl;
|
|
831
908
|
exports.localeLoader = loader;
|
|
909
|
+
exports.treeUtil = treeUtil;
|
|
832
910
|
//# sourceMappingURL=index.js.map
|