ronds-metadata 1.2.10 → 1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- package/es/api/index.js +249 -0
- package/es/comps/DynamicPorts/comps/ContextMenu.js +44 -0
- package/es/comps/DynamicPorts/comps/DragNode.js +55 -0
- package/es/comps/DynamicPorts/comps/GraphHandler/index.js +51 -0
- package/es/comps/DynamicPorts/comps/NodeElement.js +30 -0
- package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +42 -0
- package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +40 -0
- package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +55 -0
- package/es/comps/DynamicPorts/comps/shape/connector.js +19 -0
- package/es/comps/DynamicPorts/comps/shape/edge.js +91 -0
- package/es/comps/DynamicPorts/comps/shape/node.js +190 -0
- package/es/comps/DynamicPorts/constant/index.js +19 -0
- package/es/comps/DynamicPorts/graph.js +697 -0
- package/es/comps/DynamicPorts/index.js +143 -0
- package/es/comps/DynamicPorts/interface.js +6 -0
- package/es/comps/DynamicPorts/utils.js +127 -0
- package/es/comps/Editable/DataCell/ButtonCell.js +45 -0
- package/es/comps/Editable/DataCell/ColorPicker.js +33 -0
- package/es/comps/Editable/DataCell/Input.js +54 -0
- package/es/comps/Editable/DataCell/Number.js +44 -0
- package/es/comps/Editable/DataCell/Select.js +48 -0
- package/es/comps/Editable/DataCell/Switch.js +33 -0
- package/es/comps/Editable/comps/EditableAction.js +110 -0
- package/es/comps/Editable/comps/EditableCell.js +108 -0
- package/es/comps/Editable/comps/EditableHeardCell.js +172 -0
- package/es/comps/Editable/comps/EditableRow.js +118 -0
- package/es/comps/Editable/comps/Texty.js +277 -0
- package/es/comps/Editable/index.js +386 -0
- package/es/comps/Editable/interface.js +8 -0
- package/es/comps/Editable/utils.js +46 -0
- package/es/comps/FileView/index.js +198 -0
- package/es/comps/FormGenerator/Provider.js +8 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Checkbox.js +69 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Color.js +17 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +16 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Input.js +17 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +50 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +55 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +14 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +50 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Password.js +17 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Radio.js +69 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +55 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +13 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Table.js +50 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +14 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Upload.js +27 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +261 -0
- package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +62 -0
- package/es/comps/FormGenerator/comps/Canvas/core/index.js +315 -0
- package/es/comps/FormGenerator/comps/Canvas/index.js +120 -0
- package/es/comps/FormGenerator/comps/Settings/index.js +150 -0
- package/es/comps/FormGenerator/comps/Sidebar/Elements.js +48 -0
- package/es/comps/FormGenerator/comps/Sidebar/index.js +37 -0
- package/es/comps/FormGenerator/index.js +68 -0
- package/es/comps/FormGenerator/settings/index.js +367 -0
- package/es/comps/FormGenerator/settings/ruleConfig.js +557 -0
- package/es/comps/FormGenerator/transformer.js +300 -0
- package/es/comps/Icons/index.js +23 -0
- package/es/comps/JsonEdit/constant/index.js +87 -0
- package/es/comps/JsonEdit/index.js +221 -0
- package/es/comps/JsonView/index.js +109 -0
- package/es/comps/MdEdit/index.js +41 -0
- package/es/comps/MdNavbar/index.js +180 -0
- package/es/comps/MdNavbar/utils.js +34 -0
- package/es/comps/MdView/index.js +70 -0
- package/es/comps/MetadataEdit/components/MetaFieldsEdit.js +419 -0
- package/es/comps/MetadataEdit/components/MetaPropsEdit.js +368 -0
- package/es/comps/MetadataEdit/constant/index.js +69 -0
- package/es/comps/MetadataEdit/hooks/index.js +43 -0
- package/es/comps/MetadataEdit/index.js +255 -0
- package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +237 -0
- package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +367 -0
- package/es/comps/MetadataEditV2/constant/index.js +69 -0
- package/es/comps/MetadataEditV2/hooks/index.js +43 -0
- package/es/comps/MetadataEditV2/index.js +298 -0
- package/es/comps/MetadataForm/DataCell/Array.js +148 -0
- package/es/comps/MetadataForm/DataCell/Input.js +198 -0
- package/es/comps/MetadataForm/DataCell/Number.js +130 -0
- package/es/comps/MetadataForm/DataCell/Ref.js +326 -0
- package/es/comps/MetadataForm/DataCell/Select.js +557 -0
- package/es/comps/MetadataForm/DataCell/Switch.js +115 -0
- package/es/comps/MetadataForm/DataCell/layout/TableArray.js +359 -0
- package/es/comps/MetadataForm/HOC/index.js +125 -0
- package/es/comps/MetadataForm/constants.js +11 -0
- package/es/comps/MetadataForm/hooks/index.js +128 -0
- package/es/comps/MetadataForm/index.js +268 -0
- package/es/comps/MetadataForm/interface.js +8 -0
- package/es/comps/MetadataForm/utils.js +112 -0
- package/es/comps/locales/en-US.js +24 -0
- package/es/comps/locales/index.js +8 -0
- package/es/comps/locales/zh-CN.js +24 -0
- package/es/config.js +50 -0
- package/es/framework/graph/index.js +515 -0
- package/es/framework/hooks/use-async-memo.js +32 -0
- package/es/framework/hooks/use-sync-scroll.js +106 -0
- package/es/framework/http/cache.js +137 -0
- package/es/framework/http/cancel.js +44 -0
- package/es/framework/http/index.js +392 -0
- package/es/framework/http/msgpack.js +34 -0
- package/es/framework/http/msgpack5/index.js +84 -0
- package/es/framework/http/msgpack5/lib/codecs/DateCodec.js +71 -0
- package/es/framework/http/msgpack5/lib/decoder.js +287 -0
- package/es/framework/http/msgpack5/lib/encoder.js +252 -0
- package/es/framework/http/msgpack5/lib/helpers.js +23 -0
- package/es/framework/http/msgpack5/lib/streams.js +93 -0
- package/es/framework/http/types.js +1 -0
- package/es/framework/libs/jquery.min.js +4022 -0
- package/es/framework/locale/dil8/di18n.js +132 -0
- package/es/framework/locale/dil8/index.js +3 -0
- package/es/framework/locale/dil8/translate.js +76 -0
- package/es/framework/locale/dil8/util.js +17 -0
- package/es/framework/locale/index.js +26 -0
- package/es/framework/metadata/MetadataService.js +169 -0
- package/es/framework/metadata/index.js +384 -0
- package/es/framework/rxjs-hooks/useMemoSubject.js +16 -0
- package/es/framework/rxjs-hooks/useObservable.js +22 -0
- package/es/framework/rxjs-hooks/useObservableState.js +45 -0
- package/es/index.js +27 -0
- package/es/utils.js +138 -0
- package/package.json +1 -1
@@ -0,0 +1,697 @@
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
5
|
+
import "antd/es/tooltip/style";
|
6
|
+
import _Tooltip from "antd/es/tooltip";
|
7
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
8
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
9
|
+
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
10
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
11
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
12
|
+
import _get from "@babel/runtime/helpers/esm/get";
|
13
|
+
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
14
|
+
import produce from 'immer';
|
15
|
+
import React from 'react';
|
16
|
+
import ReactDOM from 'react-dom';
|
17
|
+
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
18
|
+
import { filter, take } from 'rxjs/operators';
|
19
|
+
import { round } from 'lodash-es';
|
20
|
+
import { GraphCore } from '../../framework/graph';
|
21
|
+
import NodeElement from './comps/NodeElement';
|
22
|
+
import { DPEdge } from './comps/shape/edge';
|
23
|
+
import { DPNode } from './comps/shape/node';
|
24
|
+
import { formatGraphData, formatNodeInfoToNodeMeta } from './utils';
|
25
|
+
|
26
|
+
var DPGraph = /*#__PURE__*/function (_GraphCore) {
|
27
|
+
_inherits(DPGraph, _GraphCore);
|
28
|
+
|
29
|
+
var _super = _createSuper(DPGraph);
|
30
|
+
|
31
|
+
// 图数据的订阅
|
32
|
+
function DPGraph(_graphData) {
|
33
|
+
var _thisSuper, _this;
|
34
|
+
|
35
|
+
_classCallCheck(this, DPGraph);
|
36
|
+
|
37
|
+
_this = _super.call(this, {
|
38
|
+
history: true,
|
39
|
+
frozen: true,
|
40
|
+
grid: true,
|
41
|
+
selecting: {
|
42
|
+
enabled: true,
|
43
|
+
rubberband: false,
|
44
|
+
multiple: true,
|
45
|
+
strict: true,
|
46
|
+
showNodeSelectionBox: false,
|
47
|
+
selectNodeOnMoved: false
|
48
|
+
},
|
49
|
+
keyboard: {
|
50
|
+
enabled: true
|
51
|
+
},
|
52
|
+
connecting: {
|
53
|
+
snap: {
|
54
|
+
radius: 10
|
55
|
+
},
|
56
|
+
allowBlank: false,
|
57
|
+
highlight: true,
|
58
|
+
connector: 'pai',
|
59
|
+
sourceAnchor: 'bottom',
|
60
|
+
targetAnchor: 'center',
|
61
|
+
connectionPoint: 'anchor',
|
62
|
+
createEdge: function createEdge() {
|
63
|
+
return new DPEdge({
|
64
|
+
attrs: {
|
65
|
+
line: {
|
66
|
+
strokeDasharray: '5 5',
|
67
|
+
stroke: '#808080',
|
68
|
+
strokeWidth: 1,
|
69
|
+
targetMarker: {
|
70
|
+
name: 'block',
|
71
|
+
args: {
|
72
|
+
size: '6'
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
});
|
78
|
+
},
|
79
|
+
validateEdge: function validateEdge(args) {
|
80
|
+
var _edge$target;
|
81
|
+
|
82
|
+
var edge = args.edge;
|
83
|
+
return !!(edge === null || edge === void 0 ? void 0 : (_edge$target = edge.target) === null || _edge$target === void 0 ? void 0 : _edge$target.port);
|
84
|
+
},
|
85
|
+
// 是否触发交互事件
|
86
|
+
validateMagnet: function validateMagnet(_ref) {
|
87
|
+
var magnet = _ref.magnet;
|
88
|
+
return magnet.getAttribute('port-group') !== 'in';
|
89
|
+
},
|
90
|
+
// 显示可用的链接桩
|
91
|
+
validateConnection: function validateConnection(_ref2) {
|
92
|
+
var sourceView = _ref2.sourceView,
|
93
|
+
targetView = _ref2.targetView,
|
94
|
+
sourceMagnet = _ref2.sourceMagnet,
|
95
|
+
targetMagnet = _ref2.targetMagnet;
|
96
|
+
|
97
|
+
// 不允许连接到自己
|
98
|
+
if (sourceView === targetView) {
|
99
|
+
return false;
|
100
|
+
} // 只能从输出链接桩创建连接
|
101
|
+
|
102
|
+
|
103
|
+
if (!sourceMagnet || sourceMagnet.getAttribute('port-group') === 'in') {
|
104
|
+
return false;
|
105
|
+
} // 只能连接到输入链接桩
|
106
|
+
|
107
|
+
|
108
|
+
if (!targetMagnet || targetMagnet.getAttribute('port-group') !== 'in') {
|
109
|
+
return false;
|
110
|
+
} // 判断目标链接桩是否可连接
|
111
|
+
|
112
|
+
|
113
|
+
var portId = targetMagnet.getAttribute('port');
|
114
|
+
var node = targetView.cell;
|
115
|
+
var port = node.getPort(portId);
|
116
|
+
return !(port && port.connected);
|
117
|
+
}
|
118
|
+
},
|
119
|
+
scroller: {
|
120
|
+
enabled: true,
|
121
|
+
pageVisible: false,
|
122
|
+
pageBreak: false,
|
123
|
+
pannable: true
|
124
|
+
},
|
125
|
+
highlighting: {
|
126
|
+
nodeAvailable: {
|
127
|
+
name: 'className',
|
128
|
+
args: {
|
129
|
+
className: 'available'
|
130
|
+
}
|
131
|
+
},
|
132
|
+
magnetAvailable: {
|
133
|
+
name: 'className',
|
134
|
+
args: {
|
135
|
+
className: 'available'
|
136
|
+
}
|
137
|
+
},
|
138
|
+
magnetAdsorbed: {
|
139
|
+
name: 'className',
|
140
|
+
args: {
|
141
|
+
className: 'adsorbed'
|
142
|
+
}
|
143
|
+
}
|
144
|
+
},
|
145
|
+
onPortRendered: function onPortRendered(args) {
|
146
|
+
var port = args.port;
|
147
|
+
var contentSelectors = args.contentSelectors;
|
148
|
+
var container = contentSelectors && contentSelectors.content;
|
149
|
+
var placement = port.group === 'in' ? 'top' : 'bottom';
|
150
|
+
|
151
|
+
if (container) {
|
152
|
+
ReactDOM.render( /*#__PURE__*/React.createElement(_Tooltip, {
|
153
|
+
title: port.name,
|
154
|
+
placement: placement
|
155
|
+
}, /*#__PURE__*/React.createElement("span", {
|
156
|
+
className: "dp-port ".concat(port.connected ? 'connected' : '')
|
157
|
+
})), container);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
});
|
161
|
+
_this.factory$ = {
|
162
|
+
loading: new BehaviorSubject(false),
|
163
|
+
dpGraph: new BehaviorSubject(null),
|
164
|
+
selectedNodes: new BehaviorSubject([]),
|
165
|
+
contextMenuInfo: new BehaviorSubject(null)
|
166
|
+
};
|
167
|
+
_this.dpGraphSub = void 0;
|
168
|
+
|
169
|
+
_this.renderGraph = function (wrapper, container) {
|
170
|
+
_this.dpGraphSub = _this.factory$.dpGraph.pipe(filter(function (x) {
|
171
|
+
return !!x;
|
172
|
+
}), // 过滤出有效数据
|
173
|
+
take(1)).subscribe(function (graphData) {
|
174
|
+
if (!_this.graph) {
|
175
|
+
var _formatGraphData = formatGraphData(graphData),
|
176
|
+
nodes = _formatGraphData.nodes,
|
177
|
+
edges = _formatGraphData.edges;
|
178
|
+
|
179
|
+
_get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(DPGraph.prototype)), "render", _thisSuper).call(_thisSuper, {
|
180
|
+
wrapper: wrapper,
|
181
|
+
container: container,
|
182
|
+
nodes: nodes,
|
183
|
+
edges: edges
|
184
|
+
});
|
185
|
+
}
|
186
|
+
});
|
187
|
+
};
|
188
|
+
|
189
|
+
_this.renderGraphData = /*#__PURE__*/function () {
|
190
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(graphData) {
|
191
|
+
var oldGraph, _formatGraphData2, nodes, edges;
|
192
|
+
|
193
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
194
|
+
while (1) {
|
195
|
+
switch (_context.prev = _context.next) {
|
196
|
+
case 0:
|
197
|
+
// 清除已有的图谱
|
198
|
+
oldGraph = _this.factory$.dpGraph.getValue();
|
199
|
+
|
200
|
+
_this.deleteNodes(oldGraph.nodes.map(function (it) {
|
201
|
+
return it.id;
|
202
|
+
}));
|
203
|
+
|
204
|
+
_formatGraphData2 = formatGraphData(graphData), nodes = _formatGraphData2.nodes, edges = _formatGraphData2.edges;
|
205
|
+
nodes.forEach(function (nodeMeta) {
|
206
|
+
return _this.renderNode(nodeMeta);
|
207
|
+
});
|
208
|
+
edges.forEach(function (edgeMeta) {
|
209
|
+
return _this.renderEdge(edgeMeta);
|
210
|
+
});
|
211
|
+
|
212
|
+
_this.loadDPGraph(graphData);
|
213
|
+
|
214
|
+
case 6:
|
215
|
+
case "end":
|
216
|
+
return _context.stop();
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}, _callee);
|
220
|
+
}));
|
221
|
+
|
222
|
+
return function (_x) {
|
223
|
+
return _ref3.apply(this, arguments);
|
224
|
+
};
|
225
|
+
}();
|
226
|
+
|
227
|
+
_this.zoomGraph = function (factor) {
|
228
|
+
_this.zoom(factor);
|
229
|
+
};
|
230
|
+
|
231
|
+
_this.zoomGraphToFit = function () {
|
232
|
+
_this.zoom('fit');
|
233
|
+
};
|
234
|
+
|
235
|
+
_this.zoomGraphRealSize = function () {
|
236
|
+
_this.zoom('real');
|
237
|
+
};
|
238
|
+
|
239
|
+
_this.onDeleteNodes = function (ids) {
|
240
|
+
var nodeInstanceIds = [].concat(ids);
|
241
|
+
|
242
|
+
if (_this.graph && nodeInstanceIds.length) {
|
243
|
+
_this.deleteNodes(nodeInstanceIds);
|
244
|
+
|
245
|
+
_this.delDPGraphElement(nodeInstanceIds, []);
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
_this.onDeleteEdges = function (edges) {
|
250
|
+
var targetEdges = [].concat(edges);
|
251
|
+
|
252
|
+
_this.deleteEdges(targetEdges);
|
253
|
+
|
254
|
+
_this.delDPGraphElement([], targetEdges.map(function (cell) {
|
255
|
+
return cell.getData();
|
256
|
+
}));
|
257
|
+
};
|
258
|
+
|
259
|
+
_this.clearContextMenuInfo = function () {
|
260
|
+
_this.factory$.contextMenuInfo.next(null);
|
261
|
+
};
|
262
|
+
|
263
|
+
_this.initialize(_graphData);
|
264
|
+
|
265
|
+
return _this;
|
266
|
+
} // 获取实验和图及执行状态信息
|
267
|
+
|
268
|
+
|
269
|
+
_createClass(DPGraph, [{
|
270
|
+
key: "initialize",
|
271
|
+
value: function () {
|
272
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(graphData) {
|
273
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
274
|
+
while (1) {
|
275
|
+
switch (_context2.prev = _context2.next) {
|
276
|
+
case 0:
|
277
|
+
this.factory$.loading.next(true);
|
278
|
+
_context2.prev = 1;
|
279
|
+
_context2.next = 4;
|
280
|
+
return this.loadDPGraph(graphData || {
|
281
|
+
nodes: [],
|
282
|
+
edges: []
|
283
|
+
});
|
284
|
+
|
285
|
+
case 4:
|
286
|
+
this.factory$.loading.next(false);
|
287
|
+
_context2.next = 11;
|
288
|
+
break;
|
289
|
+
|
290
|
+
case 7:
|
291
|
+
_context2.prev = 7;
|
292
|
+
_context2.t0 = _context2["catch"](1);
|
293
|
+
this.factory$.loading.next(false);
|
294
|
+
console.error('加载实验错误', _context2.t0);
|
295
|
+
|
296
|
+
case 11:
|
297
|
+
case "end":
|
298
|
+
return _context2.stop();
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}, _callee2, this, [[1, 7]]);
|
302
|
+
}));
|
303
|
+
|
304
|
+
function initialize(_x2) {
|
305
|
+
return _initialize.apply(this, arguments);
|
306
|
+
}
|
307
|
+
|
308
|
+
return initialize;
|
309
|
+
}() // 获取图
|
310
|
+
|
311
|
+
}, {
|
312
|
+
key: "loadDPGraph",
|
313
|
+
value: function () {
|
314
|
+
var _loadDPGraph = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(graphData) {
|
315
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
316
|
+
while (1) {
|
317
|
+
switch (_context3.prev = _context3.next) {
|
318
|
+
case 0:
|
319
|
+
this.factory$.dpGraph.next(graphData);
|
320
|
+
|
321
|
+
case 1:
|
322
|
+
case "end":
|
323
|
+
return _context3.stop();
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}, _callee3, this);
|
327
|
+
}));
|
328
|
+
|
329
|
+
function loadDPGraph(_x3) {
|
330
|
+
return _loadDPGraph.apply(this, arguments);
|
331
|
+
}
|
332
|
+
|
333
|
+
return loadDPGraph;
|
334
|
+
}() // 判断画布是否准备完成
|
335
|
+
|
336
|
+
}, {
|
337
|
+
key: "isGraphReady",
|
338
|
+
value: function isGraphReady() {
|
339
|
+
return !!this.graph;
|
340
|
+
} // 渲染画布
|
341
|
+
|
342
|
+
}, {
|
343
|
+
key: "renderNode",
|
344
|
+
value: // 渲染节点
|
345
|
+
function renderNode(nodeMeta) {
|
346
|
+
var data = nodeMeta.data;
|
347
|
+
var type = data.type;
|
348
|
+
|
349
|
+
if (type === 'node') {
|
350
|
+
var node = this.graph.addNode(new DPNode(_objectSpread(_objectSpread({}, nodeMeta), {}, {
|
351
|
+
shape: 'dp-rect-port',
|
352
|
+
component: /*#__PURE__*/React.createElement(NodeElement, null)
|
353
|
+
})));
|
354
|
+
return node;
|
355
|
+
}
|
356
|
+
|
357
|
+
return undefined;
|
358
|
+
} // 渲染连线
|
359
|
+
|
360
|
+
}, {
|
361
|
+
key: "renderEdge",
|
362
|
+
value: function renderEdge(edgeMeta) {
|
363
|
+
return this.graph.addEdge(new DPEdge(edgeMeta));
|
364
|
+
} // 外部添加拖拽节点
|
365
|
+
|
366
|
+
}, {
|
367
|
+
key: "addDragNode",
|
368
|
+
value: function addDragNode(data) {
|
369
|
+
var graph = this.graph;
|
370
|
+
|
371
|
+
if (graph) {
|
372
|
+
var pos = this.graph.clientToLocal(data.x, data.y);
|
373
|
+
|
374
|
+
var _node = _objectSpread(_objectSpread({}, data), pos);
|
375
|
+
|
376
|
+
this.updateDPGraph([_node]);
|
377
|
+
var newNode = formatNodeInfoToNodeMeta(_node);
|
378
|
+
this.addNode(newNode);
|
379
|
+
}
|
380
|
+
} // 更新图信息
|
381
|
+
|
382
|
+
}, {
|
383
|
+
key: "updateDPGraph",
|
384
|
+
value: function () {
|
385
|
+
var _updateDPGraph = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
386
|
+
var nodes,
|
387
|
+
edges,
|
388
|
+
oldGraph,
|
389
|
+
newGraph,
|
390
|
+
_args4 = arguments;
|
391
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
392
|
+
while (1) {
|
393
|
+
switch (_context4.prev = _context4.next) {
|
394
|
+
case 0:
|
395
|
+
nodes = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : [];
|
396
|
+
edges = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : [];
|
397
|
+
oldGraph = this.factory$.dpGraph.getValue();
|
398
|
+
newGraph = produce(oldGraph, function (nextGraph) {
|
399
|
+
if (nodes.length) {
|
400
|
+
var _nextGraph$nodes;
|
401
|
+
|
402
|
+
(_nextGraph$nodes = nextGraph.nodes).push.apply(_nextGraph$nodes, _toConsumableArray(nodes));
|
403
|
+
}
|
404
|
+
|
405
|
+
if (edges.length) {
|
406
|
+
var _nextGraph$edges;
|
407
|
+
|
408
|
+
(_nextGraph$edges = nextGraph.edges).push.apply(_nextGraph$edges, _toConsumableArray(edges));
|
409
|
+
}
|
410
|
+
});
|
411
|
+
this.factory$.dpGraph.next(newGraph);
|
412
|
+
|
413
|
+
case 5:
|
414
|
+
case "end":
|
415
|
+
return _context4.stop();
|
416
|
+
}
|
417
|
+
}
|
418
|
+
}, _callee4, this);
|
419
|
+
}));
|
420
|
+
|
421
|
+
function updateDPGraph() {
|
422
|
+
return _updateDPGraph.apply(this, arguments);
|
423
|
+
}
|
424
|
+
|
425
|
+
return updateDPGraph;
|
426
|
+
}() // 删除图信息
|
427
|
+
|
428
|
+
}, {
|
429
|
+
key: "delDPGraphElement",
|
430
|
+
value: function () {
|
431
|
+
var _delDPGraphElement = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
432
|
+
var nodes,
|
433
|
+
edges,
|
434
|
+
oldGraph,
|
435
|
+
newGraph,
|
436
|
+
_args5 = arguments;
|
437
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
438
|
+
while (1) {
|
439
|
+
switch (_context5.prev = _context5.next) {
|
440
|
+
case 0:
|
441
|
+
nodes = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : [];
|
442
|
+
edges = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : [];
|
443
|
+
oldGraph = this.factory$.dpGraph.getValue();
|
444
|
+
newGraph = produce(oldGraph, function (nextGraph) {
|
445
|
+
if (nodes.length) {
|
446
|
+
nextGraph.nodes = oldGraph.nodes.filter(function (node) {
|
447
|
+
return !nodes.includes(node.id.toString());
|
448
|
+
});
|
449
|
+
nextGraph.edges = oldGraph.edges.filter(function (edge) {
|
450
|
+
return !nodes.find(function (node) {
|
451
|
+
return [edge.source.toString(), edge.target.toString()].includes(node);
|
452
|
+
});
|
453
|
+
});
|
454
|
+
} else {
|
455
|
+
nextGraph.edges = oldGraph.edges.filter(function (edge) {
|
456
|
+
return !edges.find(function (delEdge) {
|
457
|
+
return delEdge.inPortId.toString() === edge.inPortId.toString() && delEdge.outPortId.toString() === edge.outPortId.toString();
|
458
|
+
});
|
459
|
+
});
|
460
|
+
}
|
461
|
+
});
|
462
|
+
this.factory$.dpGraph.next(newGraph);
|
463
|
+
|
464
|
+
case 5:
|
465
|
+
case "end":
|
466
|
+
return _context5.stop();
|
467
|
+
}
|
468
|
+
}
|
469
|
+
}, _callee5, this);
|
470
|
+
}));
|
471
|
+
|
472
|
+
function delDPGraphElement() {
|
473
|
+
return _delDPGraphElement.apply(this, arguments);
|
474
|
+
}
|
475
|
+
|
476
|
+
return delDPGraphElement;
|
477
|
+
}() // 缩放特定比例
|
478
|
+
|
479
|
+
}, {
|
480
|
+
key: "onConnectNode",
|
481
|
+
value: // 处理连线事件
|
482
|
+
function () {
|
483
|
+
var _onConnectNode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(args) {
|
484
|
+
var _args$edge, edge, isNew, source, target, node, portId, data;
|
485
|
+
|
486
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
487
|
+
while (1) {
|
488
|
+
switch (_context6.prev = _context6.next) {
|
489
|
+
case 0:
|
490
|
+
_args$edge = args.edge, edge = _args$edge === void 0 ? {} : _args$edge, isNew = args.isNew;
|
491
|
+
source = edge.source, target = edge.target;
|
492
|
+
|
493
|
+
if (isNew) {
|
494
|
+
// 处理边虚线样式更新的问题。
|
495
|
+
node = args.currentCell;
|
496
|
+
portId = edge.getTargetPortId();
|
497
|
+
|
498
|
+
if (node && portId) {
|
499
|
+
// 触发 port 重新渲染
|
500
|
+
node.setPortProp(portId, 'connected', true); // 更新连线样式
|
501
|
+
|
502
|
+
edge.attr({
|
503
|
+
line: {
|
504
|
+
strokeDasharray: '',
|
505
|
+
targetMarker: '',
|
506
|
+
stroke: '#808080'
|
507
|
+
}
|
508
|
+
});
|
509
|
+
data = {
|
510
|
+
source: source.cell,
|
511
|
+
target: target.cell,
|
512
|
+
outPortId: source.port,
|
513
|
+
inPortId: target.port
|
514
|
+
};
|
515
|
+
edge.setData(data);
|
516
|
+
this.updateDPGraph([], [data]);
|
517
|
+
}
|
518
|
+
}
|
519
|
+
|
520
|
+
return _context6.abrupt("return", {
|
521
|
+
success: true
|
522
|
+
});
|
523
|
+
|
524
|
+
case 4:
|
525
|
+
case "end":
|
526
|
+
return _context6.stop();
|
527
|
+
}
|
528
|
+
}
|
529
|
+
}, _callee6, this);
|
530
|
+
}));
|
531
|
+
|
532
|
+
function onConnectNode(_x4) {
|
533
|
+
return _onConnectNode.apply(this, arguments);
|
534
|
+
}
|
535
|
+
|
536
|
+
return onConnectNode;
|
537
|
+
}() // 处理选择事件
|
538
|
+
|
539
|
+
}, {
|
540
|
+
key: "onSelectNodes",
|
541
|
+
value: function onSelectNodes(nodes) {
|
542
|
+
var selectedNodes = nodes.filter(function (cell) {
|
543
|
+
return cell.isNode() && !cell.isGroup();
|
544
|
+
});
|
545
|
+
|
546
|
+
if (selectedNodes.length === 1) {
|
547
|
+
// 当只选中了一个节点时,激活当前选中项
|
548
|
+
var cell = selectedNodes[0];
|
549
|
+
var nodeData = cell.getData();
|
550
|
+
this.factory$.selectedNodes.next([nodeData]);
|
551
|
+
} else {// todo
|
552
|
+
}
|
553
|
+
} // 处理连线删除事件
|
554
|
+
|
555
|
+
}, {
|
556
|
+
key: "onConnectionRemoved",
|
557
|
+
value: function onConnectionRemoved(args) {
|
558
|
+
try {
|
559
|
+
var edge = args.edge;
|
560
|
+
var target = edge.target;
|
561
|
+
var nodeId = target.cell,
|
562
|
+
portId = target.port;
|
563
|
+
|
564
|
+
if (nodeId) {
|
565
|
+
var targetCell = this.getNodeById(nodeId);
|
566
|
+
|
567
|
+
if (targetCell) {
|
568
|
+
// 触发 port 重新渲染
|
569
|
+
targetCell.setPortProp(portId, 'connected', false);
|
570
|
+
}
|
571
|
+
}
|
572
|
+
} catch (error) {
|
573
|
+
console.warn(error);
|
574
|
+
}
|
575
|
+
} //删除节点
|
576
|
+
|
577
|
+
}, {
|
578
|
+
key: "onDeleteNodeOrEdge",
|
579
|
+
value: // 按下删除键的回调,默认参数为当前选中的节点和边
|
580
|
+
function onDeleteNodeOrEdge(args) {
|
581
|
+
var nodes = args.nodes,
|
582
|
+
edges = args.edges;
|
583
|
+
var normalNodes = nodes.filter(function (node) {
|
584
|
+
return !node.isGroup();
|
585
|
+
});
|
586
|
+
|
587
|
+
if (normalNodes === null || normalNodes === void 0 ? void 0 : normalNodes.length) {
|
588
|
+
this.onDeleteNodes(normalNodes.map(function (node) {
|
589
|
+
return node.id;
|
590
|
+
}));
|
591
|
+
}
|
592
|
+
|
593
|
+
if (edges === null || edges === void 0 ? void 0 : edges.length) {
|
594
|
+
this.onDeleteEdges(edges);
|
595
|
+
}
|
596
|
+
} // 右击菜单
|
597
|
+
|
598
|
+
}, {
|
599
|
+
key: "onContextMenu",
|
600
|
+
value: function onContextMenu(data) {
|
601
|
+
this.factory$.contextMenuInfo.next(data);
|
602
|
+
} // 清空右键菜单信息
|
603
|
+
|
604
|
+
}, {
|
605
|
+
key: "onMoveNodes",
|
606
|
+
value: function () {
|
607
|
+
var _onMoveNodes = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(movedNodes) {
|
608
|
+
var _this2 = this;
|
609
|
+
|
610
|
+
var targetNodes, newPos, oldGraph, newGraph;
|
611
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
612
|
+
while (1) {
|
613
|
+
switch (_context7.prev = _context7.next) {
|
614
|
+
case 0:
|
615
|
+
targetNodes = movedNodes.filter(function (arg) {
|
616
|
+
var node = arg.node;
|
617
|
+
return !node.isGroup();
|
618
|
+
});
|
619
|
+
|
620
|
+
if (targetNodes === null || targetNodes === void 0 ? void 0 : targetNodes.length) {
|
621
|
+
newPos = targetNodes.map(function (moveNode) {
|
622
|
+
var current = moveNode.current,
|
623
|
+
node = moveNode.node;
|
624
|
+
var x = current.x,
|
625
|
+
y = current.y;
|
626
|
+
var id = node.id;
|
627
|
+
|
628
|
+
_this2.updateNodeById(id, function (node) {
|
629
|
+
node.setData({
|
630
|
+
x: x,
|
631
|
+
y: y
|
632
|
+
});
|
633
|
+
});
|
634
|
+
|
635
|
+
return {
|
636
|
+
nodeInstanceId: id,
|
637
|
+
posX: round(x),
|
638
|
+
posY: round(y)
|
639
|
+
};
|
640
|
+
});
|
641
|
+
oldGraph = this.factory$.dpGraph.getValue();
|
642
|
+
newGraph = produce(oldGraph, function (nextGraph) {
|
643
|
+
newPos.forEach(function (position) {
|
644
|
+
var nodeInstanceId = position.nodeInstanceId,
|
645
|
+
posX = position.posX,
|
646
|
+
posY = position.posY;
|
647
|
+
var matchNode = nextGraph.nodes.find(function (item) {
|
648
|
+
return item.id.toString() === nodeInstanceId.toString();
|
649
|
+
});
|
650
|
+
|
651
|
+
if (matchNode) {
|
652
|
+
matchNode.x = posX;
|
653
|
+
matchNode.y = posY;
|
654
|
+
}
|
655
|
+
});
|
656
|
+
});
|
657
|
+
this.factory$.dpGraph.next(newGraph);
|
658
|
+
}
|
659
|
+
|
660
|
+
case 2:
|
661
|
+
case "end":
|
662
|
+
return _context7.stop();
|
663
|
+
}
|
664
|
+
}
|
665
|
+
}, _callee7, this);
|
666
|
+
}));
|
667
|
+
|
668
|
+
function onMoveNodes(_x5) {
|
669
|
+
return _onMoveNodes.apply(this, arguments);
|
670
|
+
}
|
671
|
+
|
672
|
+
return onMoveNodes;
|
673
|
+
}()
|
674
|
+
}, {
|
675
|
+
key: "dispose",
|
676
|
+
value: function dispose() {
|
677
|
+
_get(_getPrototypeOf(DPGraph.prototype), "dispose", this).call(this);
|
678
|
+
}
|
679
|
+
}]);
|
680
|
+
|
681
|
+
return DPGraph;
|
682
|
+
}(GraphCore);
|
683
|
+
|
684
|
+
export var gDPGraph;
|
685
|
+
export default DPGraph; // 获取图的实例
|
686
|
+
|
687
|
+
export var useDPGraph = function useDPGraph(graphData) {
|
688
|
+
gDPGraph = new DPGraph(graphData);
|
689
|
+
return gDPGraph;
|
690
|
+
};
|
691
|
+
export var useUnmountDPGraph = function useUnmountDPGraph() {
|
692
|
+
React.useEffect(function () {
|
693
|
+
return function () {
|
694
|
+
gDPGraph.dispose();
|
695
|
+
};
|
696
|
+
}, []);
|
697
|
+
};
|