@nocobase/plugin-graph-collection-manager 0.9.0-alpha.1

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.
Files changed (54) hide show
  1. package/LICENSE +661 -0
  2. package/client.d.ts +4 -0
  3. package/client.js +30 -0
  4. package/lib/client/GraphCollectionProvider.d.ts +2 -0
  5. package/lib/client/GraphCollectionProvider.js +97 -0
  6. package/lib/client/GraphCollectionShortcut.d.ts +2 -0
  7. package/lib/client/GraphCollectionShortcut.js +236 -0
  8. package/lib/client/GraphDrawPage.d.ts +13 -0
  9. package/lib/client/GraphDrawPage.js +1746 -0
  10. package/lib/client/action-hooks.d.ts +44 -0
  11. package/lib/client/action-hooks.js +402 -0
  12. package/lib/client/components/AddCollectionAction.d.ts +3 -0
  13. package/lib/client/components/AddCollectionAction.js +73 -0
  14. package/lib/client/components/AddFieldAction.d.ts +3 -0
  15. package/lib/client/components/AddFieldAction.js +85 -0
  16. package/lib/client/components/CollectionNodeProvder.d.ts +10 -0
  17. package/lib/client/components/CollectionNodeProvder.js +42 -0
  18. package/lib/client/components/EditCollectionAction.d.ts +3 -0
  19. package/lib/client/components/EditCollectionAction.js +78 -0
  20. package/lib/client/components/EditFieldAction.d.ts +3 -0
  21. package/lib/client/components/EditFieldAction.js +81 -0
  22. package/lib/client/components/Entity.d.ts +8 -0
  23. package/lib/client/components/Entity.js +603 -0
  24. package/lib/client/components/FieldSummary.d.ts +2 -0
  25. package/lib/client/components/FieldSummary.js +98 -0
  26. package/lib/client/components/OverrideFieldAction.d.ts +3 -0
  27. package/lib/client/components/OverrideFieldAction.js +83 -0
  28. package/lib/client/components/ViewFieldAction.d.ts +3 -0
  29. package/lib/client/components/ViewFieldAction.js +57 -0
  30. package/lib/client/components/ViewNode.d.ts +5 -0
  31. package/lib/client/components/ViewNode.js +40 -0
  32. package/lib/client/index.d.ts +1 -0
  33. package/lib/client/index.js +13 -0
  34. package/lib/client/locale/en-US.d.ts +15 -0
  35. package/lib/client/locale/en-US.js +21 -0
  36. package/lib/client/locale/index.d.ts +3 -0
  37. package/lib/client/locale/index.js +31 -0
  38. package/lib/client/locale/ja-JP.d.ts +14 -0
  39. package/lib/client/locale/ja-JP.js +20 -0
  40. package/lib/client/locale/zh-CN.d.ts +16 -0
  41. package/lib/client/locale/zh-CN.js +22 -0
  42. package/lib/client/style.d.ts +9 -0
  43. package/lib/client/style.js +222 -0
  44. package/lib/client/utils.d.ts +11 -0
  45. package/lib/client/utils.js +565 -0
  46. package/lib/index.d.ts +1 -0
  47. package/lib/index.js +15 -0
  48. package/lib/server/collections/graphPositions.d.ts +2 -0
  49. package/lib/server/collections/graphPositions.js +33 -0
  50. package/lib/server/index.d.ts +5 -0
  51. package/lib/server/index.js +51 -0
  52. package/package.json +18 -0
  53. package/server.d.ts +4 -0
  54. package/server.js +30 -0
@@ -0,0 +1,1746 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.GraphDrawPage = exports.DirectionType = exports.ConnectionType = void 0;
7
+
8
+ function _icons() {
9
+ const data = require("@ant-design/icons");
10
+
11
+ _icons = function _icons() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _x4() {
19
+ const data = require("@antv/x6");
20
+
21
+ _x4 = function _x4() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ require("@antv/x6-react-shape");
29
+
30
+ function _css() {
31
+ const data = require("@emotion/css");
32
+
33
+ _css = function _css() {
34
+ return data;
35
+ };
36
+
37
+ return data;
38
+ }
39
+
40
+ function _react() {
41
+ const data = require("@formily/react");
42
+
43
+ _react = function _react() {
44
+ return data;
45
+ };
46
+
47
+ return data;
48
+ }
49
+
50
+ function _client() {
51
+ const data = require("@nocobase/client");
52
+
53
+ _client = function _client() {
54
+ return data;
55
+ };
56
+
57
+ return data;
58
+ }
59
+
60
+ function _ahooks() {
61
+ const data = require("ahooks");
62
+
63
+ _ahooks = function _ahooks() {
64
+ return data;
65
+ };
66
+
67
+ return data;
68
+ }
69
+
70
+ function _antd() {
71
+ const data = require("antd");
72
+
73
+ _antd = function _antd() {
74
+ return data;
75
+ };
76
+
77
+ return data;
78
+ }
79
+
80
+ function _dagre() {
81
+ const data = _interopRequireDefault(require("dagre"));
82
+
83
+ _dagre = function _dagre() {
84
+ return data;
85
+ };
86
+
87
+ return data;
88
+ }
89
+
90
+ function _lodash() {
91
+ const data = require("lodash");
92
+
93
+ _lodash = function _lodash() {
94
+ return data;
95
+ };
96
+
97
+ return data;
98
+ }
99
+
100
+ function _react2() {
101
+ const data = _interopRequireWildcard(require("react"));
102
+
103
+ _react2 = function _react2() {
104
+ return data;
105
+ };
106
+
107
+ return data;
108
+ }
109
+
110
+ function _reactI18next() {
111
+ const data = require("react-i18next");
112
+
113
+ _reactI18next = function _reactI18next() {
114
+ return data;
115
+ };
116
+
117
+ return data;
118
+ }
119
+
120
+ var _actionHooks = require("./action-hooks");
121
+
122
+ var _AddCollectionAction = require("./components/AddCollectionAction");
123
+
124
+ var _Entity = _interopRequireDefault(require("./components/Entity"));
125
+
126
+ var _style = require("./style");
127
+
128
+ var _utils = require("./utils");
129
+
130
+ var _ViewNode = require("./components/ViewNode");
131
+
132
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
133
+
134
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
135
+
136
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
137
+
138
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
139
+
140
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
141
+
142
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
143
+
144
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
145
+
146
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
147
+
148
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
149
+
150
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
151
+
152
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
153
+
154
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
155
+
156
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
157
+
158
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
159
+
160
+ const LINE_HEIGHT = 40;
161
+ const NODE_WIDTH = 250;
162
+ let targetGraph;
163
+ let targetNode;
164
+ let dir = 'TB'; // LR RL TB BT 横排
165
+
166
+ var DirectionType;
167
+ exports.DirectionType = DirectionType;
168
+
169
+ (function (DirectionType) {
170
+ DirectionType["Both"] = "both";
171
+ DirectionType["Target"] = "target";
172
+ DirectionType["Source"] = "source";
173
+ })(DirectionType || (exports.DirectionType = DirectionType = {}));
174
+
175
+ var ConnectionType;
176
+ exports.ConnectionType = ConnectionType;
177
+
178
+ (function (ConnectionType) {
179
+ ConnectionType["Both"] = "both";
180
+ ConnectionType["Inherit"] = "inherited";
181
+ ConnectionType["Entity"] = "entity";
182
+ })(ConnectionType || (exports.ConnectionType = ConnectionType = {}));
183
+
184
+ const getGridData = (num, arr) => {
185
+ const newArr = [];
186
+
187
+ while (arr.length > 0 && num) {
188
+ newArr.push(arr.splice(0, num));
189
+ }
190
+
191
+ return newArr;
192
+ }; //初始布局
193
+
194
+
195
+ function layout(_x) {
196
+ return _layout.apply(this, arguments);
197
+ }
198
+
199
+ function _layout() {
200
+ _layout = _asyncToGenerator(function* (createPositions) {
201
+ const _targetGraph10 = targetGraph,
202
+ positions = _targetGraph10.positions;
203
+ let graphPositions = [];
204
+ const nodes = targetGraph.getNodes();
205
+ const edges = targetGraph.getEdges();
206
+ const g = new (_dagre().default.graphlib.Graph)();
207
+ g.setGraph({
208
+ rankdir: dir,
209
+ nodesep: 50,
210
+ edgesep: 50,
211
+ rankSep: 50,
212
+ align: 'DL',
213
+ controlPoints: true
214
+ });
215
+ g.setDefaultEdgeLabel(() => ({}));
216
+ nodes.forEach((node, i) => {
217
+ const width = NODE_WIDTH;
218
+ const height = node.getPorts().length * 32 + 30;
219
+ g.setNode(node.id, {
220
+ width,
221
+ height
222
+ });
223
+ });
224
+
225
+ _dagre().default.layout(g);
226
+
227
+ targetGraph.freeze();
228
+ const dNodes = getGridData(15, g.nodes());
229
+ dNodes.forEach((arr, row) => {
230
+ arr.forEach((id, index) => {
231
+ const node = targetGraph.getCell(id);
232
+ const col = index % 15;
233
+
234
+ if (node) {
235
+ const targetPosition = positions && positions.find(v => {
236
+ return v.collectionName === node.store.data.name;
237
+ }) || {};
238
+ const calculatedPosition = {
239
+ x: col * 325 + 50,
240
+ y: row * 400 + 60
241
+ };
242
+ node.position(targetPosition.x || calculatedPosition.x, targetPosition.y || calculatedPosition.y);
243
+
244
+ if (positions && !positions.find(v => v.collectionName === node.store.data.name)) {
245
+ // 位置表中没有的表都自动保存
246
+ graphPositions.push({
247
+ collectionName: node.store.data.name,
248
+ x: calculatedPosition.x,
249
+ y: calculatedPosition.y
250
+ });
251
+ }
252
+ }
253
+ });
254
+ });
255
+ edges.forEach(edge => {
256
+ optimizeEdge(edge);
257
+ });
258
+ targetGraph.unfreeze();
259
+
260
+ if (targetNode) {
261
+ typeof targetNode === 'string' ? targetGraph.positionCell((0, _lodash().last)(nodes), 'top', {
262
+ padding: 100
263
+ }) : targetGraph.positionCell(targetNode, 'top', {
264
+ padding: 100
265
+ });
266
+ } else {
267
+ targetGraph.positionCell(nodes[0], 'top-left', {
268
+ padding: 100
269
+ });
270
+ }
271
+
272
+ if (graphPositions.length > 0) {
273
+ yield createPositions(graphPositions);
274
+ graphPositions = [];
275
+ }
276
+ });
277
+ return _layout.apply(this, arguments);
278
+ }
279
+
280
+ function optimizeEdge(edge) {
281
+ const connectionType = edge.store.data.connectionType;
282
+ const source = edge.getSource();
283
+ const target = edge.getTarget();
284
+ const sorceNodeX = targetGraph.getCell(source.cell).position().x;
285
+ const targeNodeX = targetGraph.getCell(target.cell).position().x;
286
+ const leftAnchor = connectionType ? {
287
+ name: 'topLeft',
288
+ args: {
289
+ dy: -20
290
+ }
291
+ } : {
292
+ name: 'left'
293
+ };
294
+ const rightAnchor = connectionType ? {
295
+ name: 'topRight',
296
+ args: {
297
+ dy: -20
298
+ }
299
+ } : 'right';
300
+ const router = connectionType ? 'normal' : 'er';
301
+ const vertices = edge.getVertices();
302
+ vertices.forEach(() => {
303
+ return edge.removeVertexAt(0);
304
+ });
305
+
306
+ if (sorceNodeX - 100 > targeNodeX) {
307
+ edge.setSource({
308
+ cell: source.cell,
309
+ port: source.port,
310
+ anchor: leftAnchor
311
+ });
312
+ edge.setTarget({
313
+ cell: target.cell,
314
+ port: target.port,
315
+ anchor: rightAnchor
316
+ });
317
+ edge.setRouter(router, {
318
+ direction: 'H'
319
+ });
320
+ } else if (Math.abs(sorceNodeX - targeNodeX) < 100) {
321
+ const sourceCell = targetGraph.getCell(source.cell);
322
+ const targetCell = targetGraph.getCell(target.cell);
323
+ edge.setSource({
324
+ cell: source.cell,
325
+ port: source.port,
326
+ anchor: leftAnchor
327
+ });
328
+ edge.setTarget({
329
+ cell: target.cell,
330
+ port: target.port,
331
+ anchor: leftAnchor
332
+ });
333
+
334
+ if (connectionType) {
335
+ edge.setVertices([{
336
+ x: sourceCell.position().x - 30,
337
+ y: sourceCell.position().y + 20
338
+ }, {
339
+ x: targetCell.position().x - 30,
340
+ y: targetCell.position().y + 20
341
+ }]);
342
+ edge.setRouter('normal');
343
+ } else {
344
+ edge.setRouter('oneSide', {
345
+ side: 'left'
346
+ });
347
+ }
348
+ } else {
349
+ edge.setSource({
350
+ cell: source.cell,
351
+ port: source.port,
352
+ anchor: rightAnchor
353
+ });
354
+ edge.setTarget({
355
+ cell: target.cell,
356
+ port: target.port,
357
+ anchor: leftAnchor
358
+ });
359
+ edge.setRouter(router, {
360
+ direction: 'H'
361
+ });
362
+ }
363
+ }
364
+
365
+ function getNodes(nodes) {
366
+ targetGraph.addNodes(nodes);
367
+ }
368
+
369
+ function getEdges(edges) {
370
+ edges.forEach(item => {
371
+ if (item.source && item.target) {
372
+ targetGraph.addEdge(_objectSpread(_objectSpread({}, item), {}, {
373
+ connector: {
374
+ name: 'normal',
375
+ zIndex: 1000
376
+ }
377
+ }));
378
+ }
379
+ });
380
+ }
381
+
382
+ const getPopupContainer = () => {
383
+ return document.getElementById('graph_container');
384
+ };
385
+
386
+ const CollapsedContext = (0, _react2().createContext)({});
387
+
388
+ const formatNodeData = () => {
389
+ const layoutNodes = [];
390
+ const edges = targetGraph.getEdges();
391
+ const nodes = targetGraph.getNodes();
392
+ edges.forEach(edge => {
393
+ layoutNodes.push(edge.getSourceCellId());
394
+ layoutNodes.push(edge.getTargetCellId());
395
+ });
396
+ const nodeGroup = (0, _lodash().groupBy)(nodes, v => {
397
+ if (layoutNodes.includes(v.id)) {
398
+ return 'linkNodes';
399
+ } else {
400
+ return 'rawNodes';
401
+ }
402
+ });
403
+ return nodeGroup;
404
+ }; //自动布局
405
+
406
+
407
+ const handelResetLayout = () => {
408
+ const _formatNodeData = formatNodeData(),
409
+ _formatNodeData$linkN = _formatNodeData.linkNodes,
410
+ linkNodes = _formatNodeData$linkN === void 0 ? [] : _formatNodeData$linkN,
411
+ rawNodes = _formatNodeData.rawNodes;
412
+
413
+ const _targetGraph = targetGraph,
414
+ positions = _targetGraph.positions;
415
+ const nodes = linkNodes.concat(rawNodes);
416
+ const edges = targetGraph.getEdges();
417
+ const g = new (_dagre().default.graphlib.Graph)();
418
+ let alternateNum;
419
+ let rawEntity;
420
+ let num;
421
+ let minX;
422
+ let maxY;
423
+ const updatePositionData = [];
424
+ g.setGraph({
425
+ rankdir: 'TB',
426
+ nodesep: 50,
427
+ edgesep: 50,
428
+ rankSep: 50,
429
+ align: 'DL',
430
+ controlPoints: true
431
+ });
432
+ const width = 250;
433
+ const height = 400;
434
+ nodes.forEach(node => {
435
+ g.setNode(node.id, {
436
+ width,
437
+ height
438
+ });
439
+ });
440
+ edges.forEach(edge => {
441
+ const source = edge.getSource();
442
+ const target = edge.getTarget();
443
+ g.setEdge(source.cell, target.cell, {});
444
+ });
445
+
446
+ _dagre().default.layout(g);
447
+
448
+ targetGraph.freeze();
449
+ const gNodes = g.nodes();
450
+ const nodeWithEdges = (0, _lodash().take)(gNodes, linkNodes.length);
451
+ const nodeWithoutEdges = (0, _lodash().drop)(gNodes, linkNodes.length);
452
+ nodeWithEdges.forEach(id => {
453
+ var _positions$find;
454
+
455
+ const node = targetGraph.getCell(id);
456
+ const positionId = (_positions$find = positions.find(v => v.collectionName === node.id)) === null || _positions$find === void 0 ? void 0 : _positions$find.id;
457
+
458
+ if (node) {
459
+ const pos = g.node(id);
460
+ updatePositionData.push({
461
+ id: positionId,
462
+ x: pos.x,
463
+ y: pos.y
464
+ });
465
+ node.position(pos === null || pos === void 0 ? void 0 : pos.x, pos === null || pos === void 0 ? void 0 : pos.y);
466
+ }
467
+ });
468
+
469
+ if (nodeWithEdges.length) {
470
+ var _targetGraph$getCell;
471
+
472
+ maxY = targetGraph.getCellById((0, _lodash().maxBy)(nodeWithEdges, k => {
473
+ return targetGraph.getCellById(k).position().y;
474
+ })).position().y;
475
+ minX = targetGraph.getCellById((0, _lodash().minBy)(nodeWithEdges, k => {
476
+ return targetGraph.getCellById(k).position().x;
477
+ })).position().x;
478
+ const maxX = targetGraph.getCellById((0, _lodash().maxBy)(nodeWithEdges, k => {
479
+ return targetGraph.getCellById(k).position().x;
480
+ })).position().x;
481
+ const yNodes = nodeWithEdges.filter(v => {
482
+ return Math.abs(targetGraph.getCellById(v).position().y - maxY) < 50;
483
+ });
484
+ let referenceNode = (_targetGraph$getCell = targetGraph.getCell((0, _lodash().maxBy)(yNodes, k => targetGraph.getCellById(k).position().x))) === null || _targetGraph$getCell === void 0 ? void 0 : _targetGraph$getCell.position();
485
+ num = Math.round(maxX / 320) || 1;
486
+ alternateNum = Math.floor((4500 - (maxX + 100 - referenceNode.x)) / 280);
487
+ rawEntity = getGridData(num, rawNodes);
488
+
489
+ if (alternateNum >= 1) {
490
+ const alternateNodes = (0, _lodash().take)(nodeWithoutEdges, alternateNum);
491
+ rawEntity = getGridData(num, (0, _lodash().drop)(nodeWithoutEdges, alternateNum));
492
+ alternateNodes.forEach((id, index) => {
493
+ const node = targetGraph.getCell(id);
494
+
495
+ if (node) {
496
+ var _positions$find2;
497
+
498
+ const calculatedPosition = {
499
+ x: referenceNode.x + 320 * index + 280,
500
+ y: referenceNode.y
501
+ };
502
+ node.position(calculatedPosition.x, calculatedPosition.y);
503
+ const positionId = (_positions$find2 = positions.find(v => v.collectionName === node.id)) === null || _positions$find2 === void 0 ? void 0 : _positions$find2.id;
504
+ updatePositionData.push({
505
+ id: positionId,
506
+ x: calculatedPosition.x,
507
+ y: calculatedPosition.y
508
+ });
509
+ }
510
+ });
511
+ }
512
+ } else {
513
+ num = 15;
514
+ alternateNum = 0;
515
+ rawEntity = getGridData(15, rawNodes);
516
+ minX = 50;
517
+ maxY = 50;
518
+ }
519
+
520
+ rawEntity.forEach((arr, row) => {
521
+ arr.forEach((id, index) => {
522
+ const node = targetGraph.getCell(id);
523
+ const col = index % num;
524
+
525
+ if (node) {
526
+ var _positions$find3;
527
+
528
+ const calculatedPosition = {
529
+ x: col * 325 + minX,
530
+ y: row * 300 + maxY + 300
531
+ };
532
+ node.position(calculatedPosition.x, calculatedPosition.y);
533
+ const positionId = (_positions$find3 = positions.find(v => v.collectionName === node.id)) === null || _positions$find3 === void 0 ? void 0 : _positions$find3.id;
534
+ updatePositionData.push({
535
+ id: positionId,
536
+ x: calculatedPosition.x,
537
+ y: calculatedPosition.y
538
+ });
539
+ }
540
+ });
541
+ });
542
+ edges.forEach(edge => {
543
+ optimizeEdge(edge);
544
+ });
545
+ targetGraph.unfreeze();
546
+ targetGraph.positionCell(nodes[0], 'top-left', {
547
+ padding: 100
548
+ });
549
+ targetGraph.updatePositionAction(updatePositionData, true);
550
+ };
551
+
552
+ const GraphDrawPage = _react2().default.memo(() => {
553
+ var _targetGraph7;
554
+
555
+ let options = (0, _react2().useContext)(_react().SchemaOptionsContext);
556
+ const ctx = (0, _react2().useContext)(_client().CollectionManagerContext);
557
+ const api = (0, _client().useAPIClient)();
558
+ const compile = (0, _client().useCompile)();
559
+
560
+ const _useTranslation = (0, _reactI18next().useTranslation)('graphPositions'),
561
+ t = _useTranslation.t;
562
+
563
+ const _useState = (0, _react2().useState)([]),
564
+ _useState2 = _slicedToArray(_useState, 2),
565
+ collectionData = _useState2[0],
566
+ setCollectionData = _useState2[1];
567
+
568
+ const _useState3 = (0, _react2().useState)([]),
569
+ _useState4 = _slicedToArray(_useState3, 2),
570
+ collectionList = _useState4[0],
571
+ setCollectionList = _useState4[1];
572
+
573
+ const _useCollectionManager = (0, _client().useCollectionManager)(),
574
+ refreshCM = _useCollectionManager.refreshCM;
575
+
576
+ const _useCurrentAppInfo = (0, _client().useCurrentAppInfo)(),
577
+ database = _useCurrentAppInfo.data.database;
578
+
579
+ const scope = _objectSpread({}, options === null || options === void 0 ? void 0 : options.scope);
580
+
581
+ const components = _objectSpread({}, options === null || options === void 0 ? void 0 : options.components);
582
+
583
+ const useSaveGraphPositionAction = /*#__PURE__*/function () {
584
+ var _ref = _asyncToGenerator(function* (data) {
585
+ yield api.resource('graphPositions').create({
586
+ values: data
587
+ });
588
+ yield refreshPositions();
589
+ });
590
+
591
+ return function useSaveGraphPositionAction(_x2) {
592
+ return _ref.apply(this, arguments);
593
+ };
594
+ }();
595
+
596
+ const useUpdatePositionAction = /*#__PURE__*/function () {
597
+ var _ref2 = _asyncToGenerator(function* (data, isbatch = false) {
598
+ if (isbatch) {
599
+ yield api.resource('graphPositions').update({
600
+ values: data
601
+ });
602
+ } else {
603
+ yield api.resource('graphPositions').update({
604
+ filter: {
605
+ collectionName: data.collectionName
606
+ },
607
+ values: _objectSpread({}, data)
608
+ });
609
+ }
610
+
611
+ yield refreshPositions();
612
+ });
613
+
614
+ return function useUpdatePositionAction(_x3) {
615
+ return _ref2.apply(this, arguments);
616
+ };
617
+ }();
618
+
619
+ const refreshPositions = /*#__PURE__*/function () {
620
+ var _ref3 = _asyncToGenerator(function* () {
621
+ const _yield$api$resource$l = yield api.resource('graphPositions').list({
622
+ paginate: false
623
+ }),
624
+ data = _yield$api$resource$l.data;
625
+
626
+ targetGraph.positions = data.data;
627
+ return Promise.resolve();
628
+ });
629
+
630
+ return function refreshPositions() {
631
+ return _ref3.apply(this, arguments);
632
+ };
633
+ }();
634
+
635
+ const setTargetNode = node => {
636
+ targetNode = node;
637
+
638
+ if (node === 'destory') {
639
+ refreshPositions();
640
+ }
641
+ };
642
+
643
+ const refreshGM = /*#__PURE__*/function () {
644
+ var _ref4 = _asyncToGenerator(function* () {
645
+ const data = yield refreshCM();
646
+ console.log(data);
647
+ targetGraph.collections = data;
648
+ targetGraph.updatePositionAction = useUpdatePositionAction;
649
+ const currentNodes = targetGraph.getNodes();
650
+ setCollectionData(data);
651
+ setCollectionList(data);
652
+
653
+ if (!currentNodes.length) {
654
+ renderInitGraphCollection(data);
655
+ } else {
656
+ renderDiffGraphCollection(data);
657
+ }
658
+ });
659
+
660
+ return function refreshGM() {
661
+ return _ref4.apply(this, arguments);
662
+ };
663
+ }();
664
+
665
+ const initGraphCollections = () => {
666
+ targetGraph = new (_x4().Graph)({
667
+ container: document.getElementById('container'),
668
+ moveThreshold: 0,
669
+ scroller: {
670
+ enabled: true,
671
+ pannable: true,
672
+ padding: {
673
+ top: 0,
674
+ left: 500,
675
+ right: 300,
676
+ bottom: 400
677
+ }
678
+ },
679
+ selecting: {
680
+ enabled: false,
681
+ multiple: true,
682
+ rubberband: true,
683
+ movable: true,
684
+ className: 'node-selecting',
685
+ modifiers: 'shift'
686
+ },
687
+ minimap: {
688
+ enabled: true,
689
+ container: document.getElementById('graph-minimap'),
690
+ width: 300,
691
+ height: 250,
692
+ padding: 10,
693
+ graphOptions: {
694
+ async: true,
695
+
696
+ getCellView(cell) {
697
+ if (cell.isNode()) {
698
+ return _ViewNode.SimpleNodeView;
699
+ }
700
+ },
701
+
702
+ createCellView(cell) {
703
+ if (cell.isEdge()) {
704
+ return null;
705
+ }
706
+ }
707
+
708
+ }
709
+ },
710
+ connecting: {
711
+ anchor: {
712
+ name: 'midSide'
713
+ }
714
+ },
715
+ mousewheel: {
716
+ enabled: true,
717
+ modifiers: ['ctrl', 'meta']
718
+ },
719
+ snapline: {
720
+ enabled: !0
721
+ },
722
+ keyboard: {
723
+ enabled: false
724
+ },
725
+ clipboard: {
726
+ enabled: false
727
+ },
728
+ interacting: {
729
+ magnetConnectable: false
730
+ },
731
+ async: true,
732
+ preventDefaultBlankAction: true
733
+ });
734
+ targetGraph.connectionType = ConnectionType.Both;
735
+ targetGraph.direction = DirectionType.Target;
736
+ targetGraph.cacheCollection = {};
737
+
738
+ _x4().Graph.registerPortLayout('erPortPosition', portsPositionArgs => {
739
+ return portsPositionArgs.map((_, index) => {
740
+ return {
741
+ position: {
742
+ x: 0,
743
+ y: (index + 1) * LINE_HEIGHT
744
+ },
745
+ angle: 0
746
+ };
747
+ });
748
+ }, true);
749
+
750
+ _x4().Graph.registerNode('er-rect', {
751
+ inherit: 'react-shape',
752
+ component: node => {
753
+ var _targetGraph2;
754
+
755
+ return _react2().default.createElement(_client().CurrentAppInfoContext.Provider, {
756
+ value: database
757
+ }, _react2().default.createElement(_client().APIClientProvider, {
758
+ apiClient: api
759
+ }, _react2().default.createElement(_client().SchemaComponentOptions, {
760
+ inherit: true,
761
+ scope: scope,
762
+ components: components
763
+ }, _react2().default.createElement(_client().CollectionManagerProvider, {
764
+ collections: (_targetGraph2 = targetGraph) === null || _targetGraph2 === void 0 ? void 0 : _targetGraph2.collections,
765
+ refreshCM: refreshGM,
766
+ interfaces: ctx.interfaces
767
+ }, _react2().default.createElement("div", {
768
+ style: {
769
+ height: 'auto'
770
+ }
771
+ }, _react2().default.createElement(_Entity.default, {
772
+ node: node,
773
+ setTargetNode: setTargetNode,
774
+ targetGraph: targetGraph
775
+ }))))));
776
+ },
777
+ ports: {
778
+ groups: {
779
+ list: {
780
+ markup: [{
781
+ tagName: 'rect',
782
+ selector: 'portBody'
783
+ }],
784
+ attrs: {
785
+ portBody: {
786
+ width: NODE_WIDTH,
787
+ height: LINE_HEIGHT,
788
+ strokeWidth: 1,
789
+ // magnet: true,
790
+ visibility: 'hidden'
791
+ }
792
+ },
793
+ position: 'erPortPosition'
794
+ }
795
+ }
796
+ },
797
+ body: {
798
+ refWidth: 100,
799
+ refHeight: 100
800
+ }
801
+ }, true);
802
+
803
+ targetGraph.on('edge:mouseleave', ({
804
+ e,
805
+ edge: targetEdge
806
+ }) => {
807
+ e.stopPropagation();
808
+ handleEdgeUnActive(targetEdge);
809
+ });
810
+ targetGraph.on('node:moved', ({
811
+ e,
812
+ node
813
+ }) => {
814
+ e.stopPropagation();
815
+ const connectEdges = targetGraph.getConnectedEdges(node);
816
+ const currentPosition = node.position();
817
+ const oldPosition = targetGraph.positions.find(v => v.collectionName === node.store.data.name);
818
+
819
+ if (oldPosition) {
820
+ (oldPosition.x !== currentPosition.x || oldPosition.y !== currentPosition.y) && useUpdatePositionAction(_objectSpread({
821
+ collectionName: node.store.data.name
822
+ }, currentPosition));
823
+ } else {
824
+ useSaveGraphPositionAction(_objectSpread({
825
+ collectionName: node.store.data.name
826
+ }, currentPosition));
827
+ }
828
+
829
+ connectEdges.forEach(edge => {
830
+ optimizeEdge(edge);
831
+ });
832
+ });
833
+ targetGraph.on('cell:mouseenter', ({
834
+ e,
835
+ cell,
836
+ edge
837
+ }) => {
838
+ e.stopPropagation();
839
+ cell.toFront();
840
+
841
+ if (edge) {
842
+ handleEdgeActive(edge);
843
+ }
844
+ });
845
+ targetGraph.on('blank:click', e => {
846
+ var _targetGraph3, _targetGraph$collapse;
847
+
848
+ if ((_targetGraph3 = targetGraph) === null || _targetGraph3 === void 0 ? void 0 : _targetGraph3.activeEdge) {
849
+ var _targetGraph4;
850
+
851
+ handleEdgeUnActive((_targetGraph4 = targetGraph) === null || _targetGraph4 === void 0 ? void 0 : _targetGraph4.activeEdge);
852
+ }
853
+
854
+ (_targetGraph$collapse = targetGraph.collapseNodes) === null || _targetGraph$collapse === void 0 ? void 0 : _targetGraph$collapse.map(v => {
855
+ const node = targetGraph.getCell(Object.keys(v)[0]);
856
+ Object.values(v)[0] && node.setData({
857
+ collapse: false
858
+ });
859
+ });
860
+ targetGraph.cleanSelection();
861
+ });
862
+ targetGraph.on('node:selected', ({
863
+ e,
864
+ node
865
+ }) => {
866
+ node.setProp({
867
+ select: true
868
+ });
869
+ });
870
+ targetGraph.on('node:unselected', ({
871
+ e,
872
+ node
873
+ }) => {
874
+ node.setProp({
875
+ select: false
876
+ });
877
+ });
878
+ };
879
+
880
+ const handleEdgeUnActive = targetEdge => {
881
+ var _targetEdge$store;
882
+
883
+ targetGraph.activeEdge = null;
884
+
885
+ const _targetEdge$store$dat = (_targetEdge$store = targetEdge.store) === null || _targetEdge$store === void 0 ? void 0 : _targetEdge$store.data,
886
+ m2m = _targetEdge$store$dat.m2m,
887
+ connectionType = _targetEdge$store$dat.connectionType;
888
+
889
+ const m2mLineId = m2m === null || m2m === void 0 ? void 0 : m2m.find(v => v !== targetEdge.id);
890
+ const m2mEdge = targetGraph.getCellById(m2mLineId);
891
+
892
+ const lightsOut = edge => {
893
+ const targeNode = targetGraph.getCellById(edge.store.data.target.cell);
894
+ const sourceNode = targetGraph.getCellById(edge.store.data.source.cell);
895
+ targeNode.setProp({
896
+ targetPort: false,
897
+ associated: null
898
+ });
899
+ sourceNode.setProp({
900
+ sourcePort: false,
901
+ associated: null
902
+ });
903
+ edge.setAttrs({
904
+ line: {
905
+ stroke: '#ddd',
906
+ targetMarker: connectionType === ConnectionType.Inherit ? {
907
+ name: 'classic',
908
+ fill: '#ddd'
909
+ } : null
910
+ }
911
+ });
912
+ edge.setLabels(edge.getLabels().map(v => {
913
+ return _objectSpread(_objectSpread({}, v), {}, {
914
+ attrs: {
915
+ labelText: _objectSpread(_objectSpread({}, v.attrs.labelText), {}, {
916
+ fill: 'rgba(0, 0, 0, 0.3)'
917
+ }),
918
+ labelBody: _objectSpread(_objectSpread({}, v.attrs.labelBody), {}, {
919
+ stroke: '#ddd'
920
+ })
921
+ }
922
+ });
923
+ }));
924
+ };
925
+
926
+ lightsOut(targetEdge);
927
+ m2mEdge && lightsOut(m2mEdge);
928
+ };
929
+
930
+ const handleEdgeActive = targetEdge => {
931
+ var _targetEdge$store2;
932
+
933
+ targetGraph.activeEdge = targetEdge;
934
+
935
+ const _targetEdge$store$dat2 = (_targetEdge$store2 = targetEdge.store) === null || _targetEdge$store2 === void 0 ? void 0 : _targetEdge$store2.data,
936
+ associated = _targetEdge$store$dat2.associated,
937
+ m2m = _targetEdge$store$dat2.m2m,
938
+ connectionType = _targetEdge$store$dat2.connectionType;
939
+
940
+ const m2mLineId = m2m === null || m2m === void 0 ? void 0 : m2m.find(v => v !== targetEdge.id);
941
+ const m2mEdge = targetGraph.getCellById(m2mLineId);
942
+
943
+ const lightUp = edge => {
944
+ edge.toFront();
945
+ edge.setAttrs({
946
+ line: {
947
+ stroke: '#1890ff',
948
+ strokeWidth: 1,
949
+ textAnchor: 'middle',
950
+ textVerticalAnchor: 'middle',
951
+ sourceMarker: null,
952
+ targetMarker: connectionType === ConnectionType.Inherit ? {
953
+ name: 'classic',
954
+ fill: '#1890ff'
955
+ } : null
956
+ }
957
+ });
958
+ edge.setLabels(edge.getLabels().map(v => {
959
+ return _objectSpread(_objectSpread({}, v), {}, {
960
+ attrs: {
961
+ labelText: _objectSpread(_objectSpread({}, v.attrs.labelText), {}, {
962
+ fill: '#1890ff'
963
+ }),
964
+ labelBody: _objectSpread(_objectSpread({}, v.attrs.labelBody), {}, {
965
+ stroke: '#1890ff'
966
+ })
967
+ }
968
+ });
969
+ }));
970
+ const targeNode = targetGraph.getCellById(edge.store.data.target.cell);
971
+ const sourceNode = targetGraph.getCellById(edge.store.data.source.cell);
972
+ targeNode.toFront();
973
+ sourceNode.toFront();
974
+ targeNode.setProp({
975
+ targetPort: edge.store.data.target.port,
976
+ associated
977
+ });
978
+ sourceNode.setProp({
979
+ sourcePort: edge.store.data.source.port,
980
+ associated
981
+ });
982
+ };
983
+
984
+ lightUp(targetEdge);
985
+ m2mEdge && lightUp(m2mEdge);
986
+ }; // 首次渲染
987
+
988
+
989
+ const renderInitGraphCollection = rawData => {
990
+ const _formatData = (0, _utils.formatData)(rawData),
991
+ nodesData = _formatData.nodesData,
992
+ edgesData = _formatData.edgesData,
993
+ inheritEdges = _formatData.inheritEdges;
994
+
995
+ targetGraph.data = {
996
+ nodes: nodesData,
997
+ edges: edgesData
998
+ };
999
+ getNodes(nodesData);
1000
+ getEdges(edgesData);
1001
+ getEdges(inheritEdges);
1002
+ layout(useSaveGraphPositionAction);
1003
+ }; // 增量渲染
1004
+
1005
+
1006
+ const renderDiffGraphCollection = rawData => {
1007
+ const _targetGraph5 = targetGraph,
1008
+ positions = _targetGraph5.positions;
1009
+
1010
+ const _formatData2 = (0, _utils.formatData)(rawData),
1011
+ nodesData = _formatData2.nodesData,
1012
+ edgesData = _formatData2.edgesData,
1013
+ inheritEdges = _formatData2.inheritEdges;
1014
+
1015
+ const currentNodes = targetGraph.getNodes().map(v => v.store.data);
1016
+ const totalEdges = targetGraph.getEdges().map(v => v.store.data);
1017
+ const currentEdgesGroup = (0, _lodash().groupBy)(totalEdges, v => {
1018
+ if (v.connectionType) {
1019
+ return 'currentInheritEdges';
1020
+ } else {
1021
+ return 'currentRelateEdges';
1022
+ }
1023
+ });
1024
+ const diffNodes = (0, _utils.getDiffNode)(nodesData, currentNodes);
1025
+ const diffEdges = (0, _utils.getDiffEdge)(edgesData, currentEdgesGroup.currentRelateEdges || []);
1026
+ const diffInheritEdge = (0, _utils.getDiffEdge)(inheritEdges, currentEdgesGroup.currentInheritEdges || []);
1027
+ diffNodes.forEach(({
1028
+ status,
1029
+ node,
1030
+ port
1031
+ }) => {
1032
+ const updateNode = targetGraph.getCellById(node.id);
1033
+
1034
+ switch (status) {
1035
+ case 'add':
1036
+ const maxY = (0, _lodash().maxBy)(positions, 'y').y;
1037
+ const yNodes = positions.filter(v => {
1038
+ return Math.abs(v.y - maxY) < 100;
1039
+ });
1040
+ let referenceNode = (0, _lodash().maxBy)(yNodes, 'x');
1041
+ let position;
1042
+
1043
+ if (referenceNode.x > 4500) {
1044
+ const minX = (0, _lodash().minBy)(positions, 'x').x;
1045
+ referenceNode = (0, _lodash().minBy)(yNodes, 'x');
1046
+ position = {
1047
+ x: minX,
1048
+ y: referenceNode.y + 400
1049
+ };
1050
+ } else {
1051
+ position = {
1052
+ x: referenceNode.x + 350,
1053
+ y: referenceNode.y
1054
+ };
1055
+ }
1056
+
1057
+ targetNode = targetGraph.addNode(_objectSpread(_objectSpread({}, node), {}, {
1058
+ position
1059
+ }));
1060
+ useSaveGraphPositionAction(_objectSpread({
1061
+ collectionName: node.name
1062
+ }, position));
1063
+ targetGraph && targetGraph.positionCell(targetNode, 'top', {
1064
+ padding: 200
1065
+ });
1066
+ break;
1067
+
1068
+ case 'insertPort':
1069
+ updateNode.insertPort(port.index, port.port);
1070
+ break;
1071
+
1072
+ case 'deletePort':
1073
+ updateNode.removePort(port.id);
1074
+ break;
1075
+
1076
+ case 'updateNode':
1077
+ updateNode.setProp({
1078
+ title: node.title
1079
+ });
1080
+ break;
1081
+
1082
+ case 'delete':
1083
+ targetGraph.removeCell(node.id);
1084
+
1085
+ default:
1086
+ return null;
1087
+ }
1088
+ });
1089
+
1090
+ const renderDiffEdges = data => {
1091
+ data.forEach(({
1092
+ status,
1093
+ edge
1094
+ }) => {
1095
+ switch (status) {
1096
+ case 'add':
1097
+ const newEdge = targetGraph.addEdge(_objectSpread({}, edge));
1098
+ optimizeEdge(newEdge);
1099
+ break;
1100
+
1101
+ case 'delete':
1102
+ targetGraph.removeCell(edge.id);
1103
+ break;
1104
+
1105
+ default:
1106
+ return null;
1107
+ }
1108
+ });
1109
+ };
1110
+
1111
+ setTimeout(() => {
1112
+ renderDiffEdges(diffEdges.concat(diffInheritEdge));
1113
+ });
1114
+ };
1115
+
1116
+ const handleSearchCollection = e => {
1117
+ const value = e.target.value.toLowerCase();
1118
+
1119
+ if (value) {
1120
+ const targetCollections = collectionData.filter(v => {
1121
+ const collectionTitle = compile(v.title).toLowerCase();
1122
+ return collectionTitle.includes(value);
1123
+ });
1124
+ setCollectionList(targetCollections);
1125
+ } else {
1126
+ setCollectionList(collectionData);
1127
+ }
1128
+ }; // 处理不同方向的继承关系表
1129
+
1130
+
1131
+ const hanleHighlightInheritedNode = (key, direction) => {
1132
+ if (direction === DirectionType.Target) {
1133
+ const INodes = (0, _utils.getInheritCollections)(targetGraph.collections, key);
1134
+ INodes.forEach(v => {
1135
+ var _targetGraph$getCellB;
1136
+
1137
+ (_targetGraph$getCellB = targetGraph.getCellById(v)) === null || _targetGraph$getCellB === void 0 ? void 0 : _targetGraph$getCellB.setAttrs({
1138
+ hightLight: true,
1139
+ direction,
1140
+ connectionType: ConnectionType.Inherit
1141
+ });
1142
+ });
1143
+ } else {
1144
+ const INodes = (0, _utils.getChildrenCollections)(targetGraph.collections, key);
1145
+ INodes.forEach(v => {
1146
+ var _targetGraph$getCellB2;
1147
+
1148
+ (_targetGraph$getCellB2 = targetGraph.getCellById(v.name)) === null || _targetGraph$getCellB2 === void 0 ? void 0 : _targetGraph$getCellB2.setAttrs({
1149
+ hightLight: true,
1150
+ direction,
1151
+ connectionType: ConnectionType.Inherit
1152
+ });
1153
+ });
1154
+ }
1155
+ }; // target index entity relation
1156
+
1157
+
1158
+ const handelTargetIndexEntity = key => {
1159
+ const node = targetGraph.getCellById(key);
1160
+ targetGraph.cacheCollection[key] = true;
1161
+ const connectedEdges = targetGraph.getConnectedEdges(node);
1162
+ let visibleEdges = connectedEdges.filter(v => {
1163
+ var _v$store$data;
1164
+
1165
+ return !((_v$store$data = v.store.data) === null || _v$store$data === void 0 ? void 0 : _v$store$data.connectionType) && v.getTargetCellId() === key;
1166
+ });
1167
+ visibleEdges.forEach(v => {
1168
+ var _node$store$data$attr2;
1169
+
1170
+ if (v.store.data.m2m) {
1171
+ v.store.data.m2m.forEach(i => {
1172
+ const m2mEdge = targetGraph.getCellById(i);
1173
+
1174
+ if (m2mEdge.getTargetCellId() === key) {
1175
+ var _node$store$data$attr;
1176
+
1177
+ const sourceId = m2mEdge.getSourceCellId();
1178
+ const node = targetGraph.getCellById(sourceId);
1179
+
1180
+ if (!((_node$store$data$attr = node.store.data.attrs) === null || _node$store$data$attr === void 0 ? void 0 : _node$store$data$attr.hightLight)) {
1181
+ node.setAttrs({
1182
+ hightLight: true,
1183
+ direction: DirectionType.Target,
1184
+ connectionType: ConnectionType.Entity
1185
+ });
1186
+ handelTargetIndexEntity(sourceId);
1187
+ }
1188
+ }
1189
+ });
1190
+ }
1191
+
1192
+ const sourceId = v.getSourceCellId();
1193
+ const node = targetGraph.getCellById(sourceId);
1194
+
1195
+ if (!((_node$store$data$attr2 = node.store.data.attrs) === null || _node$store$data$attr2 === void 0 ? void 0 : _node$store$data$attr2.hightLight)) {
1196
+ node.setAttrs({
1197
+ hightLight: true,
1198
+ direction: DirectionType.Target,
1199
+ connectionType: ConnectionType.Entity
1200
+ });
1201
+ handelTargetIndexEntity(sourceId);
1202
+ }
1203
+ });
1204
+ }; // source index entity relation
1205
+
1206
+
1207
+ const handelSourceIndexEntity = key => {
1208
+ const node = targetGraph.getCellById(key);
1209
+ const connectedEdges = targetGraph.getConnectedEdges(node);
1210
+ const visibleEdges = connectedEdges.filter(v => {
1211
+ var _v$store$data2;
1212
+
1213
+ return !((_v$store$data2 = v.store.data) === null || _v$store$data2 === void 0 ? void 0 : _v$store$data2.connectionType) && v.getSourceCellId() === key;
1214
+ });
1215
+ visibleEdges.forEach(v => {
1216
+ var _node$store$data$attr4;
1217
+
1218
+ if (v.store.data.m2m) {
1219
+ v.store.data.m2m.forEach(i => {
1220
+ const m2mEdge = targetGraph.getCellById(i);
1221
+
1222
+ if (m2mEdge.getSourceCellId() === key) {
1223
+ var _node$store$data$attr3;
1224
+
1225
+ const targetId = m2mEdge.getTargetCellId();
1226
+ const node = targetGraph.getCellById(targetId);
1227
+
1228
+ if (!((_node$store$data$attr3 = node.store.data.attrs) === null || _node$store$data$attr3 === void 0 ? void 0 : _node$store$data$attr3.hightLight)) {
1229
+ node.setAttrs({
1230
+ hightLight: true,
1231
+ direction: DirectionType.Source,
1232
+ connectionType: ConnectionType.Entity
1233
+ });
1234
+ handelSourceIndexEntity(targetId);
1235
+ }
1236
+ }
1237
+ });
1238
+ }
1239
+
1240
+ const targetId = v.getTargetCellId();
1241
+ const node = targetGraph.getCellById(targetId);
1242
+
1243
+ if (!((_node$store$data$attr4 = node.store.data.attrs) === null || _node$store$data$attr4 === void 0 ? void 0 : _node$store$data$attr4.hightLight)) {
1244
+ node.setAttrs({
1245
+ hightLight: true,
1246
+ direction: DirectionType.Source,
1247
+ connectionType: ConnectionType.Entity
1248
+ });
1249
+ handelSourceIndexEntity(targetId);
1250
+ }
1251
+ });
1252
+ }; // 处理不同方向的实体关系表
1253
+
1254
+
1255
+ const handleHighlightRelationNodes = (nodekey, direction) => {
1256
+ if (direction === DirectionType.Target) {
1257
+ handelTargetIndexEntity(nodekey);
1258
+ } else {
1259
+ handelSourceIndexEntity(nodekey);
1260
+ }
1261
+ };
1262
+
1263
+ const handleCleanHighlight = (key, currentDirection, currentConnectionType) => {
1264
+ const nodes = targetGraph.getNodes().filter(v => {
1265
+ var _v$store$data$attrs;
1266
+
1267
+ return (_v$store$data$attrs = v.store.data.attrs) === null || _v$store$data$attrs === void 0 ? void 0 : _v$store$data$attrs.hightLight;
1268
+ });
1269
+ const length = nodes.length;
1270
+
1271
+ for (let i = 0; i < length; i++) {
1272
+ var _targetGraph$filterCo, _targetGraph$filterCo2;
1273
+
1274
+ const _nodes$i$getAttrs = nodes[i].getAttrs(),
1275
+ direction = _nodes$i$getAttrs.direction,
1276
+ connectionType = _nodes$i$getAttrs.connectionType;
1277
+
1278
+ const filterFlag = nodes[i].id !== key;
1279
+ const directionFlag = key && ((_targetGraph$filterCo = targetGraph.filterConfig) === null || _targetGraph$filterCo === void 0 ? void 0 : _targetGraph$filterCo.key) === key ? direction !== currentDirection : true;
1280
+ const renltionshipFlag = key && ((_targetGraph$filterCo2 = targetGraph.filterConfig) === null || _targetGraph$filterCo2 === void 0 ? void 0 : _targetGraph$filterCo2.key) === key ? connectionType !== currentConnectionType : true;
1281
+
1282
+ if (nodes[i].id !== key) {
1283
+ setTimeout(() => {
1284
+ filterFlag && (directionFlag || renltionshipFlag) && nodes[i].setAttrs({
1285
+ hightLight: false
1286
+ });
1287
+ }, 0);
1288
+ }
1289
+ }
1290
+ };
1291
+
1292
+ const handleFiterCollections = value => {
1293
+ const _targetGraph6 = targetGraph,
1294
+ connectionType = _targetGraph6.connectionType,
1295
+ direction = _targetGraph6.direction,
1296
+ filterConfig = _targetGraph6.filterConfig;
1297
+ const directionBothFlag1 = value === (filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.key) && direction === DirectionType.Both;
1298
+ const relationshipBothFlag = value === (filterConfig === null || filterConfig === void 0 ? void 0 : filterConfig.key) && (connectionType === ConnectionType.Both || connectionType === filterConfig.connectionType);
1299
+
1300
+ if (value) {
1301
+ (!directionBothFlag1 || !relationshipBothFlag) && handleCleanHighlight(value, direction, connectionType);
1302
+ targetNode = targetGraph.getCellById(value);
1303
+ targetGraph.positionCell(targetNode, 'center', {
1304
+ padding: 0
1305
+ });
1306
+ targetNode.setAttrs({
1307
+ hightLight: true,
1308
+ connectionType: connectionType
1309
+ });
1310
+ setTimeout(() => {
1311
+ if ([ConnectionType.Entity, ConnectionType.Both].includes(connectionType)) {
1312
+ if (direction === DirectionType.Both) {
1313
+ handleHighlightRelationNodes(value, DirectionType.Target);
1314
+ handleHighlightRelationNodes(value, DirectionType.Source);
1315
+ } else {
1316
+ direction === DirectionType.Target && handleHighlightRelationNodes(value, direction);
1317
+ direction === DirectionType.Source && handleHighlightRelationNodes(value, direction);
1318
+ }
1319
+ }
1320
+
1321
+ if ([ConnectionType.Inherit, ConnectionType.Both].includes(connectionType)) {
1322
+ if (direction === DirectionType.Both) {
1323
+ hanleHighlightInheritedNode(value, DirectionType.Target);
1324
+ hanleHighlightInheritedNode(value, DirectionType.Source);
1325
+ } else {
1326
+ hanleHighlightInheritedNode(value, direction);
1327
+ }
1328
+ }
1329
+
1330
+ targetGraph.filterConfig = {
1331
+ key: value,
1332
+ direction: direction,
1333
+ connectionType
1334
+ };
1335
+ }, 0);
1336
+ } else {
1337
+ handleCleanHighlight();
1338
+ }
1339
+ };
1340
+
1341
+ const handleSetRelationshipType = type => {
1342
+ handleSetEdgeVisible(type);
1343
+ };
1344
+
1345
+ const handleSetEdgeVisible = type => {
1346
+ targetNode = null;
1347
+ const edges = targetGraph.getEdges();
1348
+ edges.forEach(v => {
1349
+ const connectionType = v.store.data.connectionType;
1350
+
1351
+ if (type === ConnectionType.Entity) {
1352
+ if (connectionType) {
1353
+ v.setVisible(false);
1354
+ } else {
1355
+ v.setVisible(true);
1356
+ }
1357
+ } else if (type === ConnectionType.Inherit) {
1358
+ if (!connectionType) {
1359
+ v.setVisible(false);
1360
+ } else {
1361
+ v.setVisible(true);
1362
+ }
1363
+ } else {
1364
+ v.setVisible(true);
1365
+ }
1366
+ });
1367
+ };
1368
+
1369
+ (0, _react2().useLayoutEffect)(() => {
1370
+ initGraphCollections();
1371
+ return () => {
1372
+ targetGraph.off('cell:mouseenter');
1373
+ targetGraph.off('edge:mouseleave');
1374
+ targetGraph.off('node:moved');
1375
+ targetGraph.off('blank:click');
1376
+ targetGraph = null;
1377
+ targetNode = null;
1378
+ };
1379
+ }, []);
1380
+ (0, _react2().useEffect)(() => {
1381
+ refreshPositions().then(() => {
1382
+ refreshGM();
1383
+ });
1384
+ }, []);
1385
+
1386
+ const loadCollections = /*#__PURE__*/function () {
1387
+ var _ref5 = _asyncToGenerator(function* () {
1388
+ var _targetGraph$collecti;
1389
+
1390
+ return (_targetGraph$collecti = targetGraph.collections) === null || _targetGraph$collecti === void 0 ? void 0 : _targetGraph$collecti.map(collection => ({
1391
+ label: compile(collection.title),
1392
+ value: collection.name
1393
+ }));
1394
+ });
1395
+
1396
+ return function loadCollections() {
1397
+ return _ref5.apply(this, arguments);
1398
+ };
1399
+ }();
1400
+
1401
+ return _react2().default.createElement(_antd().Layout, null, _react2().default.createElement("div", {
1402
+ className: (0, _css().cx)(_style.graphCollectionContainerClass)
1403
+ }, _react2().default.createElement(_client().CollectionManagerProvider, {
1404
+ collections: (_targetGraph7 = targetGraph) === null || _targetGraph7 === void 0 ? void 0 : _targetGraph7.collections,
1405
+ refreshCM: refreshGM
1406
+ }, _react2().default.createElement(CollapsedContext.Provider, {
1407
+ value: {
1408
+ collectionList,
1409
+ handleSearchCollection
1410
+ }
1411
+ }, _react2().default.createElement("div", {
1412
+ className: (0, _css().cx)(_style.collectionListClass)
1413
+ }, _react2().default.createElement(_client().SchemaComponent, {
1414
+ components: {
1415
+ Select: props => _react2().default.createElement(_client().Select, _objectSpread(_objectSpread({}, props), {}, {
1416
+ getPopupContainer: () => {
1417
+ return document.getElementById('graph_container');
1418
+ }
1419
+ })),
1420
+ AddCollectionAction: _AddCollectionAction.AddCollectionAction
1421
+ },
1422
+ schema: {
1423
+ type: 'void',
1424
+ properties: {
1425
+ block1: {
1426
+ type: 'void',
1427
+ 'x-collection': 'collections',
1428
+ 'x-decorator': 'ResourceActionProvider',
1429
+ 'x-decorator-props': {
1430
+ collection: _client().collection,
1431
+ request: {
1432
+ resource: 'collections',
1433
+ action: 'list',
1434
+ params: {
1435
+ pageSize: 50,
1436
+ filter: {
1437
+ inherit: false
1438
+ },
1439
+ sort: ['sort'],
1440
+ appends: []
1441
+ }
1442
+ }
1443
+ },
1444
+ properties: {
1445
+ actions: {
1446
+ type: 'void',
1447
+ 'x-component': 'ActionBar',
1448
+ 'x-component-props': {
1449
+ style: {
1450
+ fontSize: 16
1451
+ }
1452
+ },
1453
+ properties: {
1454
+ create: {
1455
+ type: 'void',
1456
+ title: '{{ t("Create collection") }}',
1457
+ 'x-component': 'AddCollectionAction',
1458
+ 'x-component-props': {
1459
+ type: 'primary'
1460
+ }
1461
+ },
1462
+ fullScreen: {
1463
+ type: 'void',
1464
+ 'x-component': 'Action',
1465
+ 'x-component-props': {
1466
+ component: (0, _react2().forwardRef)(() => {
1467
+ const _useFullscreen = (0, _ahooks().useFullscreen)(document.getElementById('graph_container')),
1468
+ _useFullscreen2 = _slicedToArray(_useFullscreen, 2),
1469
+ isFullscreen = _useFullscreen2[0],
1470
+ toggleFullscreen = _useFullscreen2[1].toggleFullscreen;
1471
+
1472
+ return _react2().default.createElement(_antd().Tooltip, {
1473
+ title: t('Full Screen'),
1474
+ getPopupContainer: getPopupContainer
1475
+ }, _react2().default.createElement(_antd().Button, {
1476
+ onClick: () => {
1477
+ toggleFullscreen();
1478
+ }
1479
+ }, isFullscreen ? _react2().default.createElement(_icons().FullscreenExitOutlined, null) : _react2().default.createElement(_icons().FullscreenOutlined, null)));
1480
+ }),
1481
+ useAction: () => {
1482
+ return {
1483
+ run() {}
1484
+
1485
+ };
1486
+ }
1487
+ }
1488
+ },
1489
+ collectionList: {
1490
+ type: 'void',
1491
+ 'x-component': () => {
1492
+ const _useContext = (0, _react2().useContext)(CollapsedContext),
1493
+ handleSearchCollection = _useContext.handleSearchCollection,
1494
+ collectionList = _useContext.collectionList;
1495
+
1496
+ const _useState5 = (0, _react2().useState)([]),
1497
+ _useState6 = _slicedToArray(_useState5, 2),
1498
+ selectedKeys = _useState6[0],
1499
+ setSelectKey = _useState6[1];
1500
+
1501
+ const content = _react2().default.createElement("div", null, _react2().default.createElement(_antd().Input, {
1502
+ style: {
1503
+ margin: '4px 0'
1504
+ },
1505
+ bordered: false,
1506
+ placeholder: t('Collection Search'),
1507
+ onChange: handleSearchCollection
1508
+ }), _react2().default.createElement(_antd().Menu, {
1509
+ selectedKeys: selectedKeys,
1510
+ selectable: true,
1511
+ className: (0, _css().css)`
1512
+ .ant-menu-item {
1513
+ height: 32px;
1514
+ line-height: 32px;
1515
+ }
1516
+ `,
1517
+ style: {
1518
+ maxHeight: '70vh',
1519
+ overflowY: 'auto',
1520
+ border: 'none'
1521
+ }
1522
+ }, _react2().default.createElement(_antd().Menu.Divider, null), collectionList.map(v => {
1523
+ return _react2().default.createElement(_antd().Menu.Item, {
1524
+ key: v.name,
1525
+ onClick: e => {
1526
+ if (e.key !== selectedKeys[0]) {
1527
+ setSelectKey([e.key]);
1528
+ handleFiterCollections(e.key);
1529
+ } else {
1530
+ targetGraph.filterConfig = null;
1531
+ handleFiterCollections(false);
1532
+ setSelectKey([]);
1533
+ }
1534
+ }
1535
+ }, _react2().default.createElement("span", null, compile(v.title)));
1536
+ })));
1537
+
1538
+ return _react2().default.createElement(_antd().Popover, {
1539
+ content: content,
1540
+ autoAdjustOverflow: true,
1541
+ placement: "bottomRight",
1542
+ trigger: ['click'],
1543
+ getPopupContainer: getPopupContainer,
1544
+ overlayClassName: (0, _css().css)`
1545
+ .ant-popover-inner-content {
1546
+ padding: 0;
1547
+ }
1548
+ `
1549
+ }, _react2().default.createElement(_antd().Button, null, _react2().default.createElement(_icons().MenuOutlined, null)));
1550
+ },
1551
+ 'x-component-props': {
1552
+ icon: 'MenuOutlined',
1553
+ useAction: () => {
1554
+ return {
1555
+ run() {}
1556
+
1557
+ };
1558
+ }
1559
+ }
1560
+ },
1561
+ autoLayout: {
1562
+ type: 'void',
1563
+ 'x-component': 'Action',
1564
+ 'x-component-props': {
1565
+ component: (0, _react2().forwardRef)(() => {
1566
+ return _react2().default.createElement(_antd().Tooltip, {
1567
+ title: t('Auto layout'),
1568
+ getPopupContainer: getPopupContainer
1569
+ }, _react2().default.createElement(_antd().Button, {
1570
+ onClick: () => {
1571
+ handelResetLayout();
1572
+ }
1573
+ }, _react2().default.createElement(_icons().ApartmentOutlined, null)));
1574
+ }),
1575
+ useAction: () => {
1576
+ return {
1577
+ run() {}
1578
+
1579
+ };
1580
+ }
1581
+ }
1582
+ },
1583
+ connectionType: {
1584
+ type: 'void',
1585
+ 'x-component': () => {
1586
+ const menuItems = [{
1587
+ key: ConnectionType.Both,
1588
+ label: 'All relationships'
1589
+ }, {
1590
+ key: ConnectionType.Entity,
1591
+ label: 'Entity relationship only'
1592
+ }, {
1593
+ key: ConnectionType.Inherit,
1594
+ label: 'Inheritance relationship only'
1595
+ }];
1596
+
1597
+ const content = _react2().default.createElement("div", null, _react2().default.createElement(_antd().Menu, {
1598
+ defaultSelectedKeys: [ConnectionType.Both],
1599
+ selectable: true,
1600
+ className: (0, _css().css)`
1601
+ .ant-menu-item {
1602
+ height: 32px;
1603
+ line-height: 32px;
1604
+ }
1605
+ `,
1606
+ style: {
1607
+ maxHeight: '70vh',
1608
+ overflowY: 'auto',
1609
+ border: 'none'
1610
+ }
1611
+ }, _react2().default.createElement(_antd().Menu.Divider, null), menuItems.map(v => {
1612
+ return _react2().default.createElement(_antd().Menu.Item, {
1613
+ key: v.key,
1614
+ onClick: e => {
1615
+ targetGraph.connectionType = v.key;
1616
+ const _targetGraph8 = targetGraph,
1617
+ filterConfig = _targetGraph8.filterConfig;
1618
+ filterConfig && handleFiterCollections(filterConfig.key);
1619
+ handleSetRelationshipType(v.key);
1620
+ }
1621
+ }, _react2().default.createElement("span", null, t(v.label)));
1622
+ })));
1623
+
1624
+ return _react2().default.createElement(_antd().Popover, {
1625
+ content: content,
1626
+ autoAdjustOverflow: true,
1627
+ placement: "bottomRight",
1628
+ trigger: ['click'],
1629
+ getPopupContainer: getPopupContainer,
1630
+ overlayClassName: (0, _css().css)`
1631
+ .ant-popover-inner-content {
1632
+ padding: 0;
1633
+ }
1634
+ `
1635
+ }, _react2().default.createElement(_antd().Button, null, _react2().default.createElement(_icons().ShareAltOutlined, null)));
1636
+ },
1637
+ 'x-component-props': {
1638
+ icon: 'MenuOutlined',
1639
+ useAction: () => {
1640
+ return {
1641
+ run() {}
1642
+
1643
+ };
1644
+ }
1645
+ }
1646
+ },
1647
+ direction: {
1648
+ type: 'void',
1649
+ 'x-component': () => {
1650
+ const menuItems = [{
1651
+ key: DirectionType.Both,
1652
+ label: 'All directions'
1653
+ }, {
1654
+ key: DirectionType.Target,
1655
+ label: 'Target index'
1656
+ }, {
1657
+ key: DirectionType.Source,
1658
+ label: 'Source index'
1659
+ }];
1660
+
1661
+ const content = _react2().default.createElement("div", null, _react2().default.createElement(_antd().Menu, {
1662
+ defaultSelectedKeys: [DirectionType.Target],
1663
+ selectable: true,
1664
+ className: (0, _css().css)`
1665
+ .ant-menu-item {
1666
+ height: 32px;
1667
+ line-height: 32px;
1668
+ }
1669
+ `,
1670
+ style: {
1671
+ maxHeight: '70vh',
1672
+ overflowY: 'auto',
1673
+ border: 'none'
1674
+ }
1675
+ }, _react2().default.createElement(_antd().Menu.Divider, null), menuItems.map(v => {
1676
+ return _react2().default.createElement(_antd().Menu.Item, {
1677
+ key: v.key,
1678
+ onClick: e => {
1679
+ targetGraph.direction = v.key;
1680
+ const _targetGraph9 = targetGraph,
1681
+ filterConfig = _targetGraph9.filterConfig;
1682
+
1683
+ if (filterConfig) {
1684
+ handleFiterCollections(filterConfig.key);
1685
+ }
1686
+ }
1687
+ }, _react2().default.createElement("span", null, t(v.label)));
1688
+ })));
1689
+
1690
+ return _react2().default.createElement(_antd().Popover, {
1691
+ content: content,
1692
+ autoAdjustOverflow: true,
1693
+ placement: "bottomRight",
1694
+ trigger: ['click'],
1695
+ getPopupContainer: getPopupContainer,
1696
+ overlayClassName: (0, _css().css)`
1697
+ .ant-popover-inner-content {
1698
+ padding: 0;
1699
+ }
1700
+ `
1701
+ }, _react2().default.createElement(_antd().Button, null, _react2().default.createElement(_icons().LineHeightOutlined, null)));
1702
+ }
1703
+ },
1704
+ selectMode: {
1705
+ type: 'void',
1706
+ 'x-component': () => {
1707
+ return _react2().default.createElement(_antd().Tooltip, {
1708
+ title: t('Selection')
1709
+ }, _react2().default.createElement(_antd().Switch, {
1710
+ onChange: value => {
1711
+ targetGraph.toggleSelection();
1712
+ }
1713
+ }));
1714
+ }
1715
+ }
1716
+ }
1717
+ }
1718
+ }
1719
+ }
1720
+ }
1721
+ },
1722
+ scope: {
1723
+ useAsyncDataSource: _actionHooks.useAsyncDataSource,
1724
+ loadCollections,
1725
+ useCreateActionAndRefreshCM: () => (0, _actionHooks.useCreateActionAndRefreshCM)(setTargetNode),
1726
+ enableInherits: (database === null || database === void 0 ? void 0 : database.dialect) === 'postgres'
1727
+ }
1728
+ })))), _react2().default.createElement("div", {
1729
+ id: "container",
1730
+ style: {
1731
+ width: '100vw',
1732
+ height: '100vh'
1733
+ }
1734
+ }), _react2().default.createElement("div", {
1735
+ id: "graph-minimap",
1736
+ style: {
1737
+ width: '300px',
1738
+ height: '250px',
1739
+ right: '10px',
1740
+ bottom: '20px',
1741
+ position: 'fixed'
1742
+ }
1743
+ })));
1744
+ });
1745
+
1746
+ exports.GraphDrawPage = GraphDrawPage;