@nocobase/plugin-graph-collection-manager 0.11.1-alpha.5 → 0.12.0-alpha.2

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