ronds-metadata 1.2.10 → 1.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. package/es/api/index.js +249 -0
  2. package/es/comps/DynamicPorts/comps/ContextMenu.js +44 -0
  3. package/es/comps/DynamicPorts/comps/DragNode.js +55 -0
  4. package/es/comps/DynamicPorts/comps/GraphHandler/index.js +51 -0
  5. package/es/comps/DynamicPorts/comps/NodeElement.js +30 -0
  6. package/es/comps/DynamicPorts/comps/contextMenu/EdgeContextMenu/index.js +42 -0
  7. package/es/comps/DynamicPorts/comps/contextMenu/GraphContextMenu/index.js +40 -0
  8. package/es/comps/DynamicPorts/comps/contextMenu/NodeContextMenu/index.js +55 -0
  9. package/es/comps/DynamicPorts/comps/shape/connector.js +19 -0
  10. package/es/comps/DynamicPorts/comps/shape/edge.js +91 -0
  11. package/es/comps/DynamicPorts/comps/shape/node.js +190 -0
  12. package/es/comps/DynamicPorts/constant/index.js +19 -0
  13. package/es/comps/DynamicPorts/graph.js +697 -0
  14. package/es/comps/DynamicPorts/index.js +143 -0
  15. package/es/comps/DynamicPorts/interface.js +6 -0
  16. package/es/comps/DynamicPorts/utils.js +127 -0
  17. package/es/comps/Editable/DataCell/ButtonCell.js +45 -0
  18. package/es/comps/Editable/DataCell/ColorPicker.js +33 -0
  19. package/es/comps/Editable/DataCell/Input.js +54 -0
  20. package/es/comps/Editable/DataCell/Number.js +44 -0
  21. package/es/comps/Editable/DataCell/Select.js +48 -0
  22. package/es/comps/Editable/DataCell/Switch.js +33 -0
  23. package/es/comps/Editable/comps/EditableAction.js +110 -0
  24. package/es/comps/Editable/comps/EditableCell.js +108 -0
  25. package/es/comps/Editable/comps/EditableHeardCell.js +172 -0
  26. package/es/comps/Editable/comps/EditableRow.js +118 -0
  27. package/es/comps/Editable/comps/Texty.js +277 -0
  28. package/es/comps/Editable/index.js +386 -0
  29. package/es/comps/Editable/interface.js +8 -0
  30. package/es/comps/Editable/utils.js +46 -0
  31. package/es/comps/FileView/index.js +198 -0
  32. package/es/comps/FormGenerator/Provider.js +8 -0
  33. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Checkbox.js +69 -0
  34. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Color.js +17 -0
  35. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Date.js +16 -0
  36. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Input.js +17 -0
  37. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/List.js +50 -0
  38. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/MutiSelect.js +55 -0
  39. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Number.js +14 -0
  40. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Obj.js +50 -0
  41. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Password.js +17 -0
  42. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Radio.js +69 -0
  43. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Select.js +55 -0
  44. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Switch.js +13 -0
  45. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Table.js +50 -0
  46. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/TextArea.js +14 -0
  47. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/Cell/Upload.js +27 -0
  48. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/HOC/index.js +261 -0
  49. package/es/comps/FormGenerator/comps/Canvas/core/RenderField/index.js +62 -0
  50. package/es/comps/FormGenerator/comps/Canvas/core/index.js +315 -0
  51. package/es/comps/FormGenerator/comps/Canvas/index.js +120 -0
  52. package/es/comps/FormGenerator/comps/Settings/index.js +150 -0
  53. package/es/comps/FormGenerator/comps/Sidebar/Elements.js +48 -0
  54. package/es/comps/FormGenerator/comps/Sidebar/index.js +37 -0
  55. package/es/comps/FormGenerator/index.js +68 -0
  56. package/es/comps/FormGenerator/settings/index.js +367 -0
  57. package/es/comps/FormGenerator/settings/ruleConfig.js +557 -0
  58. package/es/comps/FormGenerator/transformer.js +300 -0
  59. package/es/comps/Icons/index.js +23 -0
  60. package/es/comps/JsonEdit/constant/index.js +87 -0
  61. package/es/comps/JsonEdit/index.js +221 -0
  62. package/es/comps/JsonView/index.js +109 -0
  63. package/es/comps/MdEdit/index.js +41 -0
  64. package/es/comps/MdNavbar/index.js +180 -0
  65. package/es/comps/MdNavbar/utils.js +34 -0
  66. package/es/comps/MdView/index.js +70 -0
  67. package/es/comps/MetadataEdit/components/MetaFieldsEdit.js +419 -0
  68. package/es/comps/MetadataEdit/components/MetaPropsEdit.js +368 -0
  69. package/es/comps/MetadataEdit/constant/index.js +69 -0
  70. package/es/comps/MetadataEdit/hooks/index.js +43 -0
  71. package/es/comps/MetadataEdit/index.js +255 -0
  72. package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +237 -0
  73. package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +367 -0
  74. package/es/comps/MetadataEditV2/constant/index.js +69 -0
  75. package/es/comps/MetadataEditV2/hooks/index.js +43 -0
  76. package/es/comps/MetadataEditV2/index.js +298 -0
  77. package/es/comps/MetadataForm/DataCell/Array.js +148 -0
  78. package/es/comps/MetadataForm/DataCell/Input.js +199 -0
  79. package/es/comps/MetadataForm/DataCell/Number.js +131 -0
  80. package/es/comps/MetadataForm/DataCell/Ref.js +326 -0
  81. package/es/comps/MetadataForm/DataCell/Select.js +558 -0
  82. package/es/comps/MetadataForm/DataCell/Switch.js +116 -0
  83. package/es/comps/MetadataForm/DataCell/layout/TableArray.js +359 -0
  84. package/es/comps/MetadataForm/HOC/index.js +126 -0
  85. package/es/comps/MetadataForm/constants.js +11 -0
  86. package/es/comps/MetadataForm/hooks/index.js +139 -0
  87. package/es/comps/MetadataForm/index.js +268 -0
  88. package/es/comps/MetadataForm/interface.d.ts +2 -1
  89. package/es/comps/MetadataForm/interface.js +8 -0
  90. package/es/comps/MetadataForm/utils.js +112 -0
  91. package/es/comps/locales/en-US.js +24 -0
  92. package/es/comps/locales/index.js +8 -0
  93. package/es/comps/locales/zh-CN.js +24 -0
  94. package/es/config.js +50 -0
  95. package/es/framework/graph/index.js +515 -0
  96. package/es/framework/hooks/use-async-memo.js +32 -0
  97. package/es/framework/hooks/use-sync-scroll.js +106 -0
  98. package/es/framework/http/cache.js +137 -0
  99. package/es/framework/http/cancel.js +44 -0
  100. package/es/framework/http/index.js +392 -0
  101. package/es/framework/http/msgpack.js +34 -0
  102. package/es/framework/http/msgpack5/index.js +84 -0
  103. package/es/framework/http/msgpack5/lib/codecs/DateCodec.js +71 -0
  104. package/es/framework/http/msgpack5/lib/decoder.js +287 -0
  105. package/es/framework/http/msgpack5/lib/encoder.js +252 -0
  106. package/es/framework/http/msgpack5/lib/helpers.js +23 -0
  107. package/es/framework/http/msgpack5/lib/streams.js +93 -0
  108. package/es/framework/http/types.js +1 -0
  109. package/es/framework/libs/jquery.min.js +4022 -0
  110. package/es/framework/locale/dil8/di18n.js +132 -0
  111. package/es/framework/locale/dil8/index.js +3 -0
  112. package/es/framework/locale/dil8/translate.js +76 -0
  113. package/es/framework/locale/dil8/util.js +17 -0
  114. package/es/framework/locale/index.js +26 -0
  115. package/es/framework/metadata/MetadataService.js +169 -0
  116. package/es/framework/metadata/index.js +384 -0
  117. package/es/framework/rxjs-hooks/useMemoSubject.js +16 -0
  118. package/es/framework/rxjs-hooks/useObservable.js +22 -0
  119. package/es/framework/rxjs-hooks/useObservableState.js +45 -0
  120. package/es/index.js +27 -0
  121. package/es/utils.js +138 -0
  122. package/package.json +1 -1
@@ -0,0 +1,515 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
5
+ var _excluded = ["wrapper", "container", "nodes", "edges"];
6
+
7
+ /*
8
+ * @Author: wangxian
9
+ * @Date: 2022-05-24 13:55:44
10
+ * @LastEditTime: 2022-05-31 10:43:04
11
+ */
12
+ import { Graph } from '@antv/x6';
13
+ import { debounceTime, fromEventPattern, map, merge, scan, tap } from 'rxjs';
14
+ import './index.less';
15
+ export var GraphCore = /*#__PURE__*/function () {
16
+ // 传入的 nodes 原始信息
17
+ // 传入的 edges 原始信息
18
+ function GraphCore(options) {
19
+ var _this = this;
20
+
21
+ _classCallCheck(this, GraphCore);
22
+
23
+ this.wrapper = void 0;
24
+ this.container = void 0;
25
+ this.nodeMetas = [];
26
+ this.edgeMetas = [];
27
+ this.options = void 0;
28
+ this.graph = void 0;
29
+ this.factorySub = {};
30
+
31
+ this.resizeGraph = function () {
32
+ var graph = _this.graph,
33
+ wrapper = _this.wrapper;
34
+
35
+ if (graph && wrapper) {
36
+ requestAnimationFrame(function () {
37
+ var width = wrapper.clientWidth;
38
+ var height = wrapper.clientHeight;
39
+ graph.resize(width, height);
40
+ });
41
+ }
42
+ };
43
+
44
+ this.zoom = function (factor) {
45
+ if (typeof factor === 'number') {
46
+ var _this$graph;
47
+
48
+ (_this$graph = _this.graph) === null || _this$graph === void 0 ? void 0 : _this$graph.zoom(factor);
49
+ } else if (factor === 'fit') {
50
+ var _this$graph2;
51
+
52
+ (_this$graph2 = _this.graph) === null || _this$graph2 === void 0 ? void 0 : _this$graph2.zoomToFit({
53
+ padding: 12
54
+ });
55
+ } else if (factor === 'real') {
56
+ var _this$graph3, _this$graph4;
57
+
58
+ (_this$graph3 = _this.graph) === null || _this$graph3 === void 0 ? void 0 : _this$graph3.scale(1);
59
+ (_this$graph4 = _this.graph) === null || _this$graph4 === void 0 ? void 0 : _this$graph4.centerContent();
60
+ }
61
+ };
62
+
63
+ this.addNode = function (nodeMeta) {
64
+ var _this$nodeMetas;
65
+
66
+ (_this$nodeMetas = _this.nodeMetas) === null || _this$nodeMetas === void 0 ? void 0 : _this$nodeMetas.push(nodeMeta);
67
+ return _this.renderNode(nodeMeta);
68
+ };
69
+
70
+ this.getNodes = function () {
71
+ var _this$graph5;
72
+
73
+ return ((_this$graph5 = _this.graph) === null || _this$graph5 === void 0 ? void 0 : _this$graph5.getNodes()) || [];
74
+ };
75
+
76
+ this.addEdge = function (edgeMeta) {
77
+ var _this$edgeMetas;
78
+
79
+ (_this$edgeMetas = _this.edgeMetas) === null || _this$edgeMetas === void 0 ? void 0 : _this$edgeMetas.push(edgeMeta);
80
+ return _this.renderEdge(edgeMeta);
81
+ };
82
+
83
+ this.deleteNodes = function (nodes) {
84
+ var _this$graph6;
85
+
86
+ var target = [].concat(nodes); // @ts-ignore
87
+
88
+ _this.nodeMetas = _this.nodeMetas.filter(function (nodeMeta) {
89
+ return !target.includes(nodeMeta.id);
90
+ });
91
+ (_this$graph6 = _this.graph) === null || _this$graph6 === void 0 ? void 0 : _this$graph6.removeCells(target);
92
+ };
93
+
94
+ this.deleteEdges = function (edges) {
95
+ var _this$graph7;
96
+
97
+ var target = [].concat(edges);
98
+ var targetIds = target.map(function (i) {
99
+ return typeof i === 'string' ? i : i.id;
100
+ }); // @ts-ignore
101
+
102
+ _this.edgeMetas = _this.edgeMetas.filter(function (edgeMeta) {
103
+ return !targetIds.includes(edgeMeta.id);
104
+ });
105
+ (_this$graph7 = _this.graph) === null || _this$graph7 === void 0 ? void 0 : _this$graph7.removeCells(target);
106
+ };
107
+
108
+ this.getNodeById = function (nodeId) {
109
+ var _this$graph8;
110
+
111
+ var node = (_this$graph8 = _this.graph) === null || _this$graph8 === void 0 ? void 0 : _this$graph8.getCellById(nodeId);
112
+
113
+ if (node === null || node === void 0 ? void 0 : node.isNode()) {
114
+ return node;
115
+ }
116
+
117
+ return undefined;
118
+ };
119
+
120
+ this.updateNodeById = function (nodeId, handler) {
121
+ handler(_this.getNodeById(nodeId));
122
+ };
123
+
124
+ this.updateNodes = function (handler) {
125
+ handler(_this.getNodes());
126
+ };
127
+
128
+ this.updateEdgeById = function (edgeId, handler) {
129
+ var _this$graph9;
130
+
131
+ var edge = (_this$graph9 = _this.graph) === null || _this$graph9 === void 0 ? void 0 : _this$graph9.getCellById(edgeId);
132
+
133
+ if (edge === null || edge === void 0 ? void 0 : edge.isEdge()) {
134
+ handler(edge);
135
+ } else {
136
+ handler(undefined);
137
+ }
138
+ };
139
+
140
+ this.updateEdges = function (handler) {
141
+ var _this$graph10;
142
+
143
+ var edges = ((_this$graph10 = _this.graph) === null || _this$graph10 === void 0 ? void 0 : _this$graph10.getEdges()) || [];
144
+ handler(edges);
145
+ };
146
+
147
+ this.throwRenderError = function () {
148
+ if (!_this.wrapper) {
149
+ console.warn('Wrapper element is needed.');
150
+ }
151
+
152
+ if (!_this.container) {
153
+ console.warn('Container element is needed.');
154
+ }
155
+
156
+ if (!_this.nodeMetas) {
157
+ console.warn('NodeMetas could not be empty');
158
+ }
159
+
160
+ if (!_this.edgeMetas) {
161
+ console.warn('EdgeMetas could not be empty');
162
+ }
163
+ };
164
+
165
+ var _wrapper = options.wrapper,
166
+ container = options.container,
167
+ _nodes = options.nodes,
168
+ _edges = options.edges,
169
+ others = _objectWithoutProperties(options, _excluded);
170
+
171
+ this.setMeta(options);
172
+ this.options = others;
173
+ }
174
+
175
+ _createClass(GraphCore, [{
176
+ key: "setMeta",
177
+ value: function setMeta(params) {
178
+ var wrapper = params.wrapper,
179
+ container = params.container,
180
+ nodes = params.nodes,
181
+ edges = params.edges;
182
+
183
+ if (wrapper) {
184
+ this.setWrapper(wrapper);
185
+ }
186
+
187
+ if (container) {
188
+ this.setContainer(container);
189
+ }
190
+
191
+ if (nodes) {
192
+ this.setNodes(nodes);
193
+ }
194
+
195
+ if (edges) {
196
+ this.setEdges(edges);
197
+ }
198
+ }
199
+ }, {
200
+ key: "isMetaValid",
201
+ get: function get() {
202
+ var wrapper = this.wrapper,
203
+ container = this.container;
204
+ return !!wrapper && !!container;
205
+ }
206
+ }, {
207
+ key: "setWrapper",
208
+ value: function setWrapper(wrapper) {
209
+ this.wrapper = wrapper;
210
+ }
211
+ }, {
212
+ key: "setContainer",
213
+ value: function setContainer(container) {
214
+ this.container = container;
215
+ this.options.container = container;
216
+ }
217
+ }, {
218
+ key: "setNodes",
219
+ value: function setNodes(nodes) {
220
+ this.nodeMetas = nodes;
221
+ }
222
+ }, {
223
+ key: "setEdges",
224
+ value: function setEdges(edges) {
225
+ this.edgeMetas = edges;
226
+ } // 处理一些订阅事件
227
+
228
+ }, {
229
+ key: "initFactorySub",
230
+ value: function initFactorySub() {
231
+ var _this2 = this;
232
+
233
+ // 处理产生连线事件
234
+ this.factorySub.connectNode = fromEventPattern(function (handler) {
235
+ _this2.graph.on('edge:connected', handler);
236
+ }, function (handler) {
237
+ _this2.graph.off('edge:connected', handler);
238
+ }).subscribe(function (args) {
239
+ _this2.onConnectNode(args);
240
+ }); // 处理节点选中事件
241
+
242
+ this.factorySub.selectNode = fromEventPattern(function (handler) {
243
+ _this2.graph.on('selection:changed', handler);
244
+ }, function (handler) {
245
+ _this2.graph.off('selection:changed', handler);
246
+ }).subscribe(function (args) {
247
+ var removed = args.removed,
248
+ selected = args.selected;
249
+ setCellsSelectedStatus(removed, false);
250
+ setCellsSelectedStatus(selected, true);
251
+
252
+ _this2.onSelectNodes(selected);
253
+ }); // 处理窗口缩放
254
+
255
+ this.factorySub.windowResize = fromEventPattern(function (handler) {
256
+ window.addEventListener('resize', handler);
257
+ }, function (handler) {
258
+ window.removeEventListener('resize', handler);
259
+ }).subscribe(this.resizeGraph); // 处理连线删除
260
+
261
+ this.factorySub.connectionRemoved = fromEventPattern(function (handler) {
262
+ _this2.graph.on('edge:removed', handler);
263
+ }, function (handler) {
264
+ _this2.graph.off('edge:removed', handler);
265
+ }).subscribe(function (args) {
266
+ _this2.onConnectionRemoved(args);
267
+ }); // 处理删除节点或连线事件
268
+
269
+ this.factorySub.deleteNodeOrEdge = fromEventPattern(function (handler) {
270
+ _this2.graph.bindKey(['delete', 'backspace'], handler);
271
+ }, function () {
272
+ _this2.graph.unbindKey(['delete', 'backspace']);
273
+ }).subscribe(function () {
274
+ var selectedCells = _this2.graph.getSelectedCells();
275
+
276
+ var selectedNodes = selectedCells.filter(function (cell) {
277
+ return cell.isNode();
278
+ });
279
+ var selectedEdges = selectedCells.filter(function (cell) {
280
+ return cell.isEdge();
281
+ });
282
+
283
+ _this2.onDeleteNodeOrEdge({
284
+ nodes: selectedNodes,
285
+ edges: selectedEdges
286
+ });
287
+ }); // 处理右键菜单
288
+
289
+ var nodeContextMenuObs = fromEventPattern(function (handler) {
290
+ _this2.graph.on('node:contextmenu', function (data) {
291
+ handler({
292
+ type: 'node',
293
+ data: data
294
+ });
295
+ });
296
+ }, function (handler) {
297
+ _this2.graph.off('node:contextmenu', handler);
298
+ });
299
+ var edgeContextMenuObs = fromEventPattern(function (handler) {
300
+ _this2.graph.on('edge:contextmenu', function (data) {
301
+ handler({
302
+ type: 'edge',
303
+ data: data
304
+ });
305
+ });
306
+ }, function (handler) {
307
+ _this2.graph.off('edge:contextmenu', handler);
308
+ });
309
+ var graphContextMenuObs = fromEventPattern(function (handler) {
310
+ _this2.graph.on('blank:contextmenu', function (data) {
311
+ handler({
312
+ type: 'graph',
313
+ data: data
314
+ });
315
+ });
316
+ }, function (handler) {
317
+ _this2.graph.off('edge:contextmenu', handler);
318
+ });
319
+ this.factorySub.contextMenu = merge(nodeContextMenuObs, edgeContextMenuObs, graphContextMenuObs).subscribe(function (data) {
320
+ if (_this2.validateContextMenu(data)) {
321
+ _this2.onContextMenu(data);
322
+ }
323
+ }); // 处理节点移动事件
324
+
325
+ var moveStarted = false; // 因为需要对移动事件做分片,区分两次移动事件,所以引入一个记录移动开始的变量
326
+
327
+ this.factorySub.moveNodes = fromEventPattern(function (handler) {
328
+ _this2.graph.on('node:change:position', handler);
329
+ }, function (handler) {
330
+ _this2.graph.off('node:change:position', handler);
331
+ }).pipe(tap(function (args) {
332
+ _this2.onMoveNodeStart(args);
333
+ }), scan(function (accum, args) {
334
+ var currentAccum = !moveStarted ? [] : accum;
335
+ var node = args.node;
336
+ var id = node.id;
337
+ var matchItemIndex = currentAccum.findIndex(function (item) {
338
+ return item.id === id;
339
+ });
340
+
341
+ if (matchItemIndex > -1) {
342
+ currentAccum.splice(matchItemIndex, 1, {
343
+ id: id,
344
+ data: args
345
+ });
346
+ } else {
347
+ currentAccum.push({
348
+ id: id,
349
+ data: args
350
+ });
351
+ }
352
+
353
+ return currentAccum;
354
+ }, []), tap(function () {
355
+ if (!moveStarted) {
356
+ moveStarted = true;
357
+ }
358
+ }), debounceTime(300), tap(function () {
359
+ if (moveStarted) {
360
+ moveStarted = false;
361
+ }
362
+ }), map(function (items) {
363
+ return items.map(function (item) {
364
+ return item.data;
365
+ });
366
+ })).subscribe(function (movedNodes) {
367
+ _this2.onMoveNodes(movedNodes);
368
+ });
369
+ } // 渲染
370
+
371
+ }, {
372
+ key: "render",
373
+ value: function render(params) {
374
+ var _this3 = this;
375
+
376
+ this.setMeta(params);
377
+
378
+ if (this.isMetaValid) {
379
+ var wrapper = this.wrapper,
380
+ options = this.options,
381
+ nodeMetas = this.nodeMetas,
382
+ edgeMetas = this.edgeMetas;
383
+ var width = wrapper.clientWidth;
384
+ var height = wrapper.clientHeight;
385
+ var graph = new Graph(_objectSpread(_objectSpread({}, options), {}, {
386
+ width: width,
387
+ height: height
388
+ }));
389
+ this.graph = graph;
390
+ nodeMetas.forEach(function (nodeMeta) {
391
+ return _this3.renderNode(nodeMeta);
392
+ });
393
+ edgeMetas.forEach(function (edgeMeta) {
394
+ return _this3.renderEdge(edgeMeta);
395
+ });
396
+ this.afterLayout();
397
+
398
+ if (graph.isFrozen()) {
399
+ graph.unfreeze();
400
+ }
401
+
402
+ requestAnimationFrame(function () {
403
+ graph.centerContent();
404
+ });
405
+ this.initFactorySub();
406
+ } else {
407
+ this.throwRenderError();
408
+ }
409
+ }
410
+ }, {
411
+ key: "renderNode",
412
+ value: function renderNode(nodeMeta) {
413
+ return this.graph.addNode(nodeMeta);
414
+ }
415
+ }, {
416
+ key: "renderEdge",
417
+ value: function renderEdge(edgeMeta) {
418
+ return this.graph.addEdge(edgeMeta);
419
+ }
420
+ }, {
421
+ key: "afterLayout",
422
+ value: function afterLayout() {
423
+ if (process.env.NODE_ENV === 'development') {}
424
+ } // 连线的触发事件
425
+
426
+ }, {
427
+ key: "onConnectNode",
428
+ value: function onConnectNode(args) {
429
+ if (process.env.NODE_ENV === 'development') {}
430
+ } // 节点选中的触发事件
431
+
432
+ }, {
433
+ key: "onSelectNodes",
434
+ value: function onSelectNodes(nodes) {
435
+ if (process.env.NODE_ENV === 'development') {}
436
+ } // 窗口大小resize触发事件
437
+
438
+ }, {
439
+ key: "onConnectionRemoved",
440
+ value: // 处理连线删除的触发事件
441
+ function onConnectionRemoved(args) {
442
+ if (process.env.NODE_ENV === 'development') {}
443
+ } // 按下删除键的回调,默认参数为当前选中的节点和边
444
+
445
+ }, {
446
+ key: "onDeleteNodeOrEdge",
447
+ value: function onDeleteNodeOrEdge(args) {
448
+ if (process.env.NODE_ENV === 'development') {}
449
+ }
450
+ }, {
451
+ key: "validateContextMenu",
452
+ value: function validateContextMenu(data) {
453
+ return !!data;
454
+ }
455
+ }, {
456
+ key: "onContextMenu",
457
+ value: function onContextMenu(data) {
458
+ if (process.env.NODE_ENV === 'development') {}
459
+ } // 缩放画布
460
+
461
+ }, {
462
+ key: "onMoveNodeStart",
463
+ value: function onMoveNodeStart(args) {
464
+ if (process.env.NODE_ENV === 'development') {}
465
+ }
466
+ }, {
467
+ key: "onMoveNodes",
468
+ value: function onMoveNodes(args) {
469
+ if (process.env.NODE_ENV === 'development') {}
470
+ }
471
+ /* 以下为主动触发的方法 */
472
+
473
+ }, {
474
+ key: "dispose",
475
+ value: // 注销
476
+ function dispose() {
477
+ var _this$factorySub$conn, _this$factorySub$move, _this$factorySub$sele;
478
+
479
+ (_this$factorySub$conn = this.factorySub.connectNode) === null || _this$factorySub$conn === void 0 ? void 0 : _this$factorySub$conn.unsubscribe();
480
+ (_this$factorySub$move = this.factorySub.moveNodes) === null || _this$factorySub$move === void 0 ? void 0 : _this$factorySub$move.unsubscribe();
481
+ (_this$factorySub$sele = this.factorySub.selectNode) === null || _this$factorySub$sele === void 0 ? void 0 : _this$factorySub$sele.unsubscribe(); // ! 这一步要注意放在图的事件订阅都取消了之后
482
+
483
+ if (this.wrapper) {
484
+ var _this$graph11;
485
+
486
+ var graphScroller = this.wrapper.querySelector('.x6-graph-scroller');
487
+
488
+ if (graphScroller) {
489
+ graphScroller.innerHTML = '';
490
+ graphScroller.setAttribute('style', '');
491
+ graphScroller.setAttribute('class', '');
492
+
493
+ if (this.container) {
494
+ this.container.innerHTML = '';
495
+ this.container.setAttribute('style', '');
496
+ this.container.setAttribute('class', '');
497
+ }
498
+ }
499
+
500
+ (_this$graph11 = this.graph) === null || _this$graph11 === void 0 ? void 0 : _this$graph11.dispose();
501
+ }
502
+ }
503
+ }]);
504
+
505
+ return GraphCore;
506
+ }();
507
+
508
+ function setCellsSelectedStatus(cells, selected) {
509
+ cells.forEach(function (cell) {
510
+ var data = cell.getData() || {};
511
+ cell.setData(_objectSpread(_objectSpread({}, data), {}, {
512
+ selected: selected
513
+ }));
514
+ });
515
+ }
@@ -0,0 +1,32 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+
3
+ /*
4
+ * @Author: wangxian
5
+ * @Date: 2022-05-21 11:04:53
6
+ * @LastEditTime: 2022-05-21 11:07:34
7
+ */
8
+ import { useEffect, useState } from 'react';
9
+ export function useAsyncMemo(factory, deps, initial) {
10
+ var _useState = useState(initial),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ val = _useState2[0],
13
+ setVal = _useState2[1];
14
+
15
+ useEffect(function () {
16
+ var cancel = false;
17
+ var promise = factory();
18
+
19
+ if (promise) {
20
+ promise.then(function (val) {
21
+ if (!cancel) {
22
+ setVal(val);
23
+ }
24
+ });
25
+ }
26
+
27
+ return function () {
28
+ cancel = true;
29
+ };
30
+ }, deps);
31
+ return val;
32
+ }
@@ -0,0 +1,106 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+
3
+ /*
4
+ * @Author: wangxian
5
+ * @Date: 2022-06-24 08:44:41
6
+ * @LastEditTime: 2022-06-24 16:25:38
7
+ */
8
+ import React from 'react';
9
+
10
+ function syncScroll(target, others, TopLeft, WidthHeight) {
11
+ var percentage = target["scroll".concat(TopLeft)] / (target["scroll".concat(WidthHeight)] - target["offset".concat(WidthHeight)]);
12
+ window.requestAnimationFrame(function () {
13
+ others.forEach(function (el) {
14
+ el["scroll".concat(TopLeft)] = Math.round(percentage * (el["scroll".concat(WidthHeight)] - el["offset".concat(WidthHeight)]));
15
+ });
16
+ });
17
+ }
18
+
19
+ function syncVerticalScroll(target, others) {
20
+ syncScroll(target, others, 'Top', 'Height');
21
+ }
22
+
23
+ function syncHorizontalScroll(target, others) {
24
+ syncScroll(target, others, 'Left', 'Width');
25
+ }
26
+
27
+ export default function useSyncScroll(_ref) {
28
+ var vertical = _ref.vertical,
29
+ horizontal = _ref.horizontal;
30
+ var deps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
31
+ var refsRef = React.useRef([]);
32
+ var locksRef = React.useRef(0);
33
+ React.useEffect(function () {
34
+ if (refsRef.current.length < 2) return function () {};
35
+
36
+ function handleScroll(_ref2) {
37
+ var target = _ref2.target;
38
+
39
+ if (locksRef.current > 0) {
40
+ locksRef.current -= 1;
41
+ return;
42
+ }
43
+
44
+ locksRef.current = refsRef.current.length - 1;
45
+ var others = refsRef.current.filter(function (ref) {
46
+ return ref !== target;
47
+ });
48
+ if (vertical) syncVerticalScroll(target, others);
49
+ if (horizontal) syncHorizontalScroll(target, others);
50
+ }
51
+
52
+ var elements = refsRef.current;
53
+ elements.forEach(function (el) {
54
+ return el.addEventListener('scroll', handleScroll);
55
+ });
56
+ return function () {
57
+ elements.forEach(function (el) {
58
+ return el.removeEventListener('scroll', handleScroll);
59
+ });
60
+ };
61
+ }, [refsRef, vertical, horizontal, locksRef].concat(_toConsumableArray(deps)));
62
+ return function (ref) {
63
+ return refsRef.current.push(ref);
64
+ };
65
+ }
66
+ export function useSyncScrollByRefs(refsRef, _ref3) {
67
+ var vertical = _ref3.vertical,
68
+ horizontal = _ref3.horizontal;
69
+ var deps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
70
+ var refsRefOk = refsRef && refsRef.current && refsRef.current.length > 1;
71
+ var locksRef = React.useRef(0);
72
+ React.useEffect(function () {
73
+ if (!refsRefOk) return function () {};
74
+
75
+ function handleScroll(_ref4) {
76
+ var target = _ref4.target;
77
+
78
+ if (locksRef.current > 0) {
79
+ locksRef.current -= 1;
80
+ return;
81
+ }
82
+
83
+ locksRef.current = refsRef.current.length - 1;
84
+ var others = refsRef.current.reduce(function (result, ref) {
85
+ if (ref.current && ref.current !== target) result.push(ref.current);
86
+ return result;
87
+ }, []);
88
+ if (vertical) syncVerticalScroll(target, others);
89
+ if (horizontal) syncHorizontalScroll(target, others);
90
+ }
91
+
92
+ var elements = refsRef.current.reduce(function (result, ref) {
93
+ if (ref.current) result.push(ref.current);
94
+ return result;
95
+ }, []);
96
+ elements.forEach(function (el) {
97
+ return el.addEventListener('scroll', handleScroll);
98
+ });
99
+ return function () {
100
+ elements.forEach(function (el) {
101
+ return el.removeEventListener('scroll', handleScroll);
102
+ });
103
+ };
104
+ }, [refsRef, refsRefOk, vertical, horizontal, locksRef].concat(_toConsumableArray(deps)));
105
+ return refsRefOk;
106
+ }