@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.
- package/LICENSE +661 -0
- package/client.d.ts +4 -0
- package/client.js +30 -0
- package/lib/client/GraphCollectionProvider.d.ts +2 -0
- package/lib/client/GraphCollectionProvider.js +97 -0
- package/lib/client/GraphCollectionShortcut.d.ts +2 -0
- package/lib/client/GraphCollectionShortcut.js +236 -0
- package/lib/client/GraphDrawPage.d.ts +13 -0
- package/lib/client/GraphDrawPage.js +1746 -0
- package/lib/client/action-hooks.d.ts +44 -0
- package/lib/client/action-hooks.js +402 -0
- package/lib/client/components/AddCollectionAction.d.ts +3 -0
- package/lib/client/components/AddCollectionAction.js +73 -0
- package/lib/client/components/AddFieldAction.d.ts +3 -0
- package/lib/client/components/AddFieldAction.js +85 -0
- package/lib/client/components/CollectionNodeProvder.d.ts +10 -0
- package/lib/client/components/CollectionNodeProvder.js +42 -0
- package/lib/client/components/EditCollectionAction.d.ts +3 -0
- package/lib/client/components/EditCollectionAction.js +78 -0
- package/lib/client/components/EditFieldAction.d.ts +3 -0
- package/lib/client/components/EditFieldAction.js +81 -0
- package/lib/client/components/Entity.d.ts +8 -0
- package/lib/client/components/Entity.js +603 -0
- package/lib/client/components/FieldSummary.d.ts +2 -0
- package/lib/client/components/FieldSummary.js +98 -0
- package/lib/client/components/OverrideFieldAction.d.ts +3 -0
- package/lib/client/components/OverrideFieldAction.js +83 -0
- package/lib/client/components/ViewFieldAction.d.ts +3 -0
- package/lib/client/components/ViewFieldAction.js +57 -0
- package/lib/client/components/ViewNode.d.ts +5 -0
- package/lib/client/components/ViewNode.js +40 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +13 -0
- package/lib/client/locale/en-US.d.ts +15 -0
- package/lib/client/locale/en-US.js +21 -0
- package/lib/client/locale/index.d.ts +3 -0
- package/lib/client/locale/index.js +31 -0
- package/lib/client/locale/ja-JP.d.ts +14 -0
- package/lib/client/locale/ja-JP.js +20 -0
- package/lib/client/locale/zh-CN.d.ts +16 -0
- package/lib/client/locale/zh-CN.js +22 -0
- package/lib/client/style.d.ts +9 -0
- package/lib/client/style.js +222 -0
- package/lib/client/utils.d.ts +11 -0
- package/lib/client/utils.js +565 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +15 -0
- package/lib/server/collections/graphPositions.d.ts +2 -0
- package/lib/server/collections/graphPositions.js +33 -0
- package/lib/server/index.d.ts +5 -0
- package/lib/server/index.js +51 -0
- package/package.json +18 -0
- package/server.d.ts +4 -0
- package/server.js +30 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getInheritCollections = exports.getDiffNode = exports.getDiffEdge = exports.getChildrenCollections = exports.formatPortData = exports.formatInheritEdgeData = exports.formatData = void 0;
|
|
7
|
+
|
|
8
|
+
function _lodash() {
|
|
9
|
+
const data = require("lodash");
|
|
10
|
+
|
|
11
|
+
_lodash = function _lodash() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
const shape = {
|
|
25
|
+
ER: 'er-rect',
|
|
26
|
+
EDGE: 'edge'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getInheritCollections = (collections, name) => {
|
|
30
|
+
const parents = [];
|
|
31
|
+
|
|
32
|
+
const getParents = name => {
|
|
33
|
+
const collection = collections === null || collections === void 0 ? void 0 : collections.find(collection => collection.name === name);
|
|
34
|
+
|
|
35
|
+
if (collection) {
|
|
36
|
+
const inherits = collection.inherits;
|
|
37
|
+
|
|
38
|
+
if (inherits) {
|
|
39
|
+
for (let index = 0; index < inherits.length; index++) {
|
|
40
|
+
const collectionKey = inherits[index];
|
|
41
|
+
parents.push(collectionKey);
|
|
42
|
+
getParents(collectionKey);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (0, _lodash().uniq)(parents);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return getParents(name);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.getInheritCollections = getInheritCollections;
|
|
54
|
+
|
|
55
|
+
const getChildrenCollections = (collections, name) => {
|
|
56
|
+
const childrens = [];
|
|
57
|
+
|
|
58
|
+
const getChildrens = name => {
|
|
59
|
+
const inheritCollections = collections.filter(v => {
|
|
60
|
+
var _v$inherits;
|
|
61
|
+
|
|
62
|
+
return (_v$inherits = v.inherits) === null || _v$inherits === void 0 ? void 0 : _v$inherits.includes(name);
|
|
63
|
+
});
|
|
64
|
+
inheritCollections.forEach(v => {
|
|
65
|
+
const collectionKey = v.name;
|
|
66
|
+
childrens.push(v);
|
|
67
|
+
return getChildrens(collectionKey);
|
|
68
|
+
});
|
|
69
|
+
return childrens;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return getChildrens(name);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
exports.getChildrenCollections = getChildrenCollections;
|
|
76
|
+
|
|
77
|
+
const formatData = data => {
|
|
78
|
+
const edgeData = [];
|
|
79
|
+
const targetTablekeys = [];
|
|
80
|
+
const tableData = data.map((item, index) => {
|
|
81
|
+
const ports = [];
|
|
82
|
+
const totalFields = [...item.fields];
|
|
83
|
+
const inheritCollections = getInheritCollections(data, item.name);
|
|
84
|
+
const inheritedFields = (0, _lodash().reduce)(inheritCollections, (result, value) => {
|
|
85
|
+
var _data$find;
|
|
86
|
+
|
|
87
|
+
const arr = result;
|
|
88
|
+
const parentFields = (_data$find = data.find(k => k.name === value)) === null || _data$find === void 0 ? void 0 : _data$find.fields.map(v => {
|
|
89
|
+
return _objectSpread(_objectSpread({}, v), {}, {
|
|
90
|
+
sourceCollectionName: item.name
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return arr.concat(parentFields);
|
|
94
|
+
}, []);
|
|
95
|
+
(0, _lodash().uniqBy)(totalFields.concat(inheritedFields), 'name').forEach(field => {
|
|
96
|
+
field.uiSchema && ports.push(_objectSpread({
|
|
97
|
+
id: field.key,
|
|
98
|
+
group: 'list'
|
|
99
|
+
}, field));
|
|
100
|
+
['obo', 'oho', 'o2o', 'o2m', 'm2o', 'm2m', 'linkTo'].includes(field.interface) && edgeData.push(field);
|
|
101
|
+
});
|
|
102
|
+
targetTablekeys.push(item.name);
|
|
103
|
+
const portsData = formatPortData(ports);
|
|
104
|
+
return {
|
|
105
|
+
id: item.name,
|
|
106
|
+
shape: shape.ER,
|
|
107
|
+
name: item.name,
|
|
108
|
+
title: item.title,
|
|
109
|
+
width: 250,
|
|
110
|
+
// height: 40 * portsData.initPorts?.length||40,
|
|
111
|
+
ports: [...(portsData.initPorts || []), ...(portsData.morePorts || [])],
|
|
112
|
+
item: item
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
const edges = formatEdgeData(edgeData, targetTablekeys, tableData);
|
|
116
|
+
const inheritEdges = formatInheritEdgeData(data);
|
|
117
|
+
return {
|
|
118
|
+
nodesData: tableData,
|
|
119
|
+
edgesData: edges,
|
|
120
|
+
inheritEdges
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
exports.formatData = formatData;
|
|
125
|
+
|
|
126
|
+
const formatPortData = ports => {
|
|
127
|
+
const portsData = (0, _lodash().groupBy)(ports, v => {
|
|
128
|
+
if (v.isForeignKey || v.primaryKey || ['obo', 'oho', 'o2o', 'o2m', 'm2o', 'm2m', 'linkTo', 'id'].includes(v.interface)) {
|
|
129
|
+
return 'initPorts';
|
|
130
|
+
} else {
|
|
131
|
+
return 'morePorts';
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
return portsData;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
exports.formatPortData = formatPortData;
|
|
138
|
+
|
|
139
|
+
const formatInheritEdgeData = collections => {
|
|
140
|
+
const commonAttrs = {
|
|
141
|
+
attrs: {
|
|
142
|
+
line: {
|
|
143
|
+
strokeWidth: 1,
|
|
144
|
+
textAnchor: 'middle',
|
|
145
|
+
textVerticalAnchor: 'middle',
|
|
146
|
+
stroke: '#ddd',
|
|
147
|
+
sourceMarker: null // targetMarker: null,
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
router: {
|
|
152
|
+
name: 'smooth',
|
|
153
|
+
args: {
|
|
154
|
+
direction: 'H'
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
labels: [{
|
|
158
|
+
markup: [{
|
|
159
|
+
tagName: 'ellipse',
|
|
160
|
+
selector: 'labelBody',
|
|
161
|
+
style: {
|
|
162
|
+
cursor: 'pointer'
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
tagName: 'text',
|
|
166
|
+
selector: 'labelText',
|
|
167
|
+
style: {
|
|
168
|
+
cursor: 'pointer'
|
|
169
|
+
}
|
|
170
|
+
}],
|
|
171
|
+
attrs: {
|
|
172
|
+
labelText: {
|
|
173
|
+
text: 'inherits',
|
|
174
|
+
fill: 'rgba(0, 0, 0, 0.3)',
|
|
175
|
+
textAnchor: 'middle',
|
|
176
|
+
textVerticalAnchor: 'middle'
|
|
177
|
+
},
|
|
178
|
+
labelBody: {
|
|
179
|
+
ref: 'labelText',
|
|
180
|
+
refWidth: '100%',
|
|
181
|
+
refHeight: '100%',
|
|
182
|
+
fill: '#f0f2f5'
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
position: {
|
|
186
|
+
distance: 0.5,
|
|
187
|
+
args: {
|
|
188
|
+
keepGradient: true,
|
|
189
|
+
ensureLegibility: true
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}]
|
|
193
|
+
};
|
|
194
|
+
const inheritEdges = [];
|
|
195
|
+
collections.forEach(v => {
|
|
196
|
+
const parentCollectonKeys = v.inherits || [];
|
|
197
|
+
|
|
198
|
+
if (parentCollectonKeys.length) {
|
|
199
|
+
parentCollectonKeys.forEach(k => {
|
|
200
|
+
inheritEdges.push(_objectSpread({
|
|
201
|
+
id: v.name + k,
|
|
202
|
+
source: {
|
|
203
|
+
cell: v.name,
|
|
204
|
+
connectionPoint: 'rect'
|
|
205
|
+
},
|
|
206
|
+
target: {
|
|
207
|
+
cell: k,
|
|
208
|
+
connectionPoint: 'rect'
|
|
209
|
+
},
|
|
210
|
+
connector: 'rounded',
|
|
211
|
+
connectionType: 'inherited'
|
|
212
|
+
}, commonAttrs));
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
return inheritEdges;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
exports.formatInheritEdgeData = formatInheritEdgeData;
|
|
220
|
+
|
|
221
|
+
const formatEdgeData = (data, targetTables, tableData) => {
|
|
222
|
+
const edges = [];
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < data.length; i++) {
|
|
225
|
+
if (targetTables.includes(data[i].target)) {
|
|
226
|
+
const targetTable = tableData.find(v => v.name === data[i].target);
|
|
227
|
+
const sourceTable = tableData.find(v => v.name === (data[i].sourceCollectionName || data[i].collectionName));
|
|
228
|
+
const commonAttrs = {
|
|
229
|
+
attrs: {
|
|
230
|
+
line: {
|
|
231
|
+
strokeWidth: 1,
|
|
232
|
+
textAnchor: 'middle',
|
|
233
|
+
textVerticalAnchor: 'middle',
|
|
234
|
+
stroke: '#ddd',
|
|
235
|
+
sourceMarker: null,
|
|
236
|
+
targetMarker: null
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
router: sourceTable.id === targetTable.id ? {
|
|
240
|
+
name: 'oneSide',
|
|
241
|
+
args: {
|
|
242
|
+
side: 'left'
|
|
243
|
+
}
|
|
244
|
+
} : {
|
|
245
|
+
name: 'er',
|
|
246
|
+
args: {
|
|
247
|
+
direction: 'H'
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
labels: [{
|
|
251
|
+
markup: [{
|
|
252
|
+
tagName: 'ellipse',
|
|
253
|
+
selector: 'labelBody',
|
|
254
|
+
style: {
|
|
255
|
+
cursor: 'pointer'
|
|
256
|
+
}
|
|
257
|
+
}, {
|
|
258
|
+
tagName: 'text',
|
|
259
|
+
selector: 'labelText',
|
|
260
|
+
style: {
|
|
261
|
+
cursor: 'pointer'
|
|
262
|
+
}
|
|
263
|
+
}],
|
|
264
|
+
attrs: {
|
|
265
|
+
labelText: {
|
|
266
|
+
text: getRelationship(data[i].interface)[0],
|
|
267
|
+
fill: 'rgba(0, 0, 0, 0.3)',
|
|
268
|
+
textAnchor: 'middle',
|
|
269
|
+
textVerticalAnchor: 'middle'
|
|
270
|
+
},
|
|
271
|
+
labelBody: {
|
|
272
|
+
ref: 'labelText',
|
|
273
|
+
refWidth: '100%',
|
|
274
|
+
refHeight: '100%',
|
|
275
|
+
stroke: '#ddd',
|
|
276
|
+
fill: '#f0f2f5',
|
|
277
|
+
strokeWidth: 1,
|
|
278
|
+
rx: 10,
|
|
279
|
+
ry: 10
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
position: {
|
|
283
|
+
distance: 0.3,
|
|
284
|
+
args: {
|
|
285
|
+
keepGradient: true,
|
|
286
|
+
ensureLegibility: true
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}, {
|
|
290
|
+
markup: [{
|
|
291
|
+
tagName: 'ellipse',
|
|
292
|
+
selector: 'labelBody',
|
|
293
|
+
style: {
|
|
294
|
+
cursor: 'pointer'
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
tagName: 'text',
|
|
298
|
+
selector: 'labelText',
|
|
299
|
+
style: {
|
|
300
|
+
cursor: 'pointer'
|
|
301
|
+
}
|
|
302
|
+
}],
|
|
303
|
+
attrs: {
|
|
304
|
+
labelText: {
|
|
305
|
+
text: getRelationship(data[i].interface)[1],
|
|
306
|
+
fill: 'rgba(0, 0, 0, 0.3)',
|
|
307
|
+
textAnchor: 'middle',
|
|
308
|
+
textVerticalAnchor: 'middle'
|
|
309
|
+
},
|
|
310
|
+
labelBody: {
|
|
311
|
+
ref: 'labelText',
|
|
312
|
+
refWidth: '100%',
|
|
313
|
+
refHeight: '100%',
|
|
314
|
+
stroke: '#ddd',
|
|
315
|
+
fill: '#f0f2f5',
|
|
316
|
+
rx: 10,
|
|
317
|
+
ry: 10,
|
|
318
|
+
strokeWidth: 1
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
position: {
|
|
322
|
+
distance: 0.7,
|
|
323
|
+
args: {
|
|
324
|
+
keepGradient: true,
|
|
325
|
+
ensureLegibility: true
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}]
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const isuniq = id => {
|
|
332
|
+
const targetEdge = edges.find(v => v.id === id);
|
|
333
|
+
|
|
334
|
+
if (targetEdge) {
|
|
335
|
+
targetEdge.associated.push(data[i].name);
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return true;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
if (['m2m', 'linkTo'].includes(data[i].interface)) {
|
|
343
|
+
const throughTable = tableData.find(v => v.name === data[i].through);
|
|
344
|
+
|
|
345
|
+
if (throughTable) {
|
|
346
|
+
var _sourceTable$ports$fi, _throughTable$ports$f, _targetTable$ports$fi, _throughTable$ports$f2;
|
|
347
|
+
|
|
348
|
+
const sCellId1 = sourceTable.id;
|
|
349
|
+
const tCellId1 = throughTable.id;
|
|
350
|
+
const sPortId1 = (_sourceTable$ports$fi = sourceTable.ports.find(v => v.name === data[i].sourceKey)) === null || _sourceTable$ports$fi === void 0 ? void 0 : _sourceTable$ports$fi.id;
|
|
351
|
+
const tPortId1 = (_throughTable$ports$f = throughTable.ports.find(v => v.name === data[i].foreignKey)) === null || _throughTable$ports$f === void 0 ? void 0 : _throughTable$ports$f.id;
|
|
352
|
+
const sCellId2 = targetTable.id;
|
|
353
|
+
const tCellId2 = throughTable.id;
|
|
354
|
+
const sPortId2 = (_targetTable$ports$fi = targetTable.ports.find(v => v.name === data[i].targetKey)) === null || _targetTable$ports$fi === void 0 ? void 0 : _targetTable$ports$fi.id;
|
|
355
|
+
const tPortId2 = (_throughTable$ports$f2 = throughTable.ports.find(v => v.name === data[i].otherKey)) === null || _throughTable$ports$f2 === void 0 ? void 0 : _throughTable$ports$f2.id;
|
|
356
|
+
const id1 = sCellId1 + sPortId1 + tCellId1 + tPortId1;
|
|
357
|
+
const id2 = sCellId2 + sPortId2 + tCellId2 + tPortId2;
|
|
358
|
+
edges.push(_objectSpread({
|
|
359
|
+
id: id1,
|
|
360
|
+
source: {
|
|
361
|
+
cell: sCellId1,
|
|
362
|
+
port: sPortId1,
|
|
363
|
+
anchor: {
|
|
364
|
+
name: 'right'
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
target: {
|
|
368
|
+
cell: tCellId1,
|
|
369
|
+
port: tPortId1,
|
|
370
|
+
anchor: {
|
|
371
|
+
name: 'left'
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
associated: [data[i].name],
|
|
375
|
+
m2m: [id1, id2]
|
|
376
|
+
}, commonAttrs));
|
|
377
|
+
edges.push(_objectSpread({
|
|
378
|
+
id: id2,
|
|
379
|
+
source: {
|
|
380
|
+
cell: sCellId2,
|
|
381
|
+
port: sPortId2,
|
|
382
|
+
anchor: {
|
|
383
|
+
name: 'right'
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
target: {
|
|
387
|
+
cell: tCellId2,
|
|
388
|
+
port: tPortId2,
|
|
389
|
+
anchor: {
|
|
390
|
+
name: 'left'
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
associated: [data[i].name],
|
|
394
|
+
m2m: [id1, id2]
|
|
395
|
+
}, commonAttrs));
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
var _targetTable$ports$fi2, _sourceTable$ports$fi2, _targetTable$ports$fi3;
|
|
399
|
+
|
|
400
|
+
const isLegalEdge = tableData.find(v => v.name == (data[i].sourceCollectionName || data[i].collectionName)).ports.find(v => v.name === data[i].foreignKey);
|
|
401
|
+
const sCellId1 = sourceTable.id;
|
|
402
|
+
const tCellId1 = targetTable.id;
|
|
403
|
+
const sPortId1 = isLegalEdge === null || isLegalEdge === void 0 ? void 0 : isLegalEdge.id;
|
|
404
|
+
const tPortId1 = (_targetTable$ports$fi2 = targetTable.ports.find(v => v.name === data[i].targetKey)) === null || _targetTable$ports$fi2 === void 0 ? void 0 : _targetTable$ports$fi2.id;
|
|
405
|
+
const sCellId2 = sourceTable.id;
|
|
406
|
+
const tCellId2 = targetTable.id;
|
|
407
|
+
const sPortId2 = (_sourceTable$ports$fi2 = sourceTable.ports.find(v => v.name === data[i].sourceKey)) === null || _sourceTable$ports$fi2 === void 0 ? void 0 : _sourceTable$ports$fi2.id;
|
|
408
|
+
const tPortId2 = (_targetTable$ports$fi3 = targetTable.ports.find(v => v.name === data[i].foreignKey)) === null || _targetTable$ports$fi3 === void 0 ? void 0 : _targetTable$ports$fi3.id;
|
|
409
|
+
const id1 = sCellId1 + sPortId1 + tCellId1 + tPortId1;
|
|
410
|
+
const id2 = sCellId2 + sPortId2 + tCellId2 + tPortId2;
|
|
411
|
+
isuniq(tCellId1 + tPortId1 + sCellId1 + sPortId1) && isLegalEdge && tPortId1 && edges.push(_objectSpread({
|
|
412
|
+
id: id1,
|
|
413
|
+
source: {
|
|
414
|
+
cell: sCellId1,
|
|
415
|
+
port: sPortId1,
|
|
416
|
+
anchor: {
|
|
417
|
+
name: 'right'
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
target: {
|
|
421
|
+
cell: tCellId1,
|
|
422
|
+
port: tPortId1,
|
|
423
|
+
anchor: {
|
|
424
|
+
name: 'left'
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
associated: [data[i].name]
|
|
428
|
+
}, commonAttrs));
|
|
429
|
+
isuniq(tCellId2 + tPortId2 + sCellId2 + sPortId2) && sPortId2 && tPortId2 && edges.push(_objectSpread({
|
|
430
|
+
id: id2,
|
|
431
|
+
source: {
|
|
432
|
+
cell: sCellId2,
|
|
433
|
+
port: sPortId2,
|
|
434
|
+
anchor: {
|
|
435
|
+
name: 'right'
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
target: {
|
|
439
|
+
cell: tCellId2,
|
|
440
|
+
port: tPortId2,
|
|
441
|
+
anchor: {
|
|
442
|
+
name: 'left'
|
|
443
|
+
}
|
|
444
|
+
},
|
|
445
|
+
associated: [data[i].name]
|
|
446
|
+
}, commonAttrs));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return (0, _lodash().uniqBy)(edges, 'id');
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
const getRelationship = relatioship => {
|
|
455
|
+
switch (relatioship) {
|
|
456
|
+
case 'm2m':
|
|
457
|
+
case 'linkTo':
|
|
458
|
+
return ['1', 'N'];
|
|
459
|
+
|
|
460
|
+
case 'o2m':
|
|
461
|
+
return ['1', 'N'];
|
|
462
|
+
|
|
463
|
+
case 'm2o':
|
|
464
|
+
return ['N', '1'];
|
|
465
|
+
|
|
466
|
+
case 'obo':
|
|
467
|
+
case 'oho':
|
|
468
|
+
return ['1', '1'];
|
|
469
|
+
|
|
470
|
+
default:
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
const getDiffNode = (newNodes, oldNodes) => {
|
|
476
|
+
let arr = [];
|
|
477
|
+
const length1 = newNodes.length;
|
|
478
|
+
const length2 = oldNodes.length;
|
|
479
|
+
|
|
480
|
+
for (let i = 0; i < length1; i++) {
|
|
481
|
+
if (!oldNodes.find(v => v.id === newNodes[i].id)) {
|
|
482
|
+
arr.push({
|
|
483
|
+
status: 'add',
|
|
484
|
+
node: newNodes[i]
|
|
485
|
+
});
|
|
486
|
+
} else {
|
|
487
|
+
const oldNode = oldNodes.find(v => v.id === newNodes[i].id);
|
|
488
|
+
const oldPorts = oldNode === null || oldNode === void 0 ? void 0 : oldNode.ports.items;
|
|
489
|
+
const newPorts = newNodes[i].ports;
|
|
490
|
+
|
|
491
|
+
if (oldNode) {
|
|
492
|
+
for (let h = 0; h < newPorts.length; h++) {
|
|
493
|
+
if (!oldPorts.find(v => v.id === newPorts[h].id)) {
|
|
494
|
+
arr.push({
|
|
495
|
+
status: 'insertPort',
|
|
496
|
+
node: newNodes[i],
|
|
497
|
+
port: {
|
|
498
|
+
index: h,
|
|
499
|
+
port: newPorts[h]
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
for (let k = 0; k < oldPorts.length; k++) {
|
|
506
|
+
if (!newPorts.find(v => v.id === oldPorts[k].id)) {
|
|
507
|
+
arr.push({
|
|
508
|
+
status: 'deletePort',
|
|
509
|
+
node: newNodes[i],
|
|
510
|
+
port: oldPorts[k]
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (oldNode.title !== newNodes[i].title) {
|
|
516
|
+
arr.push({
|
|
517
|
+
status: 'updateNode',
|
|
518
|
+
node: newNodes[i]
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
for (let i = 0; i < length2; i++) {
|
|
526
|
+
if (!newNodes.find(v => v.id === oldNodes[i].id)) {
|
|
527
|
+
arr.push({
|
|
528
|
+
status: 'delete',
|
|
529
|
+
node: oldNodes[i]
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return arr;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
exports.getDiffNode = getDiffNode;
|
|
538
|
+
|
|
539
|
+
const getDiffEdge = (newEdges, oldEdges) => {
|
|
540
|
+
const length1 = newEdges.length;
|
|
541
|
+
const length2 = oldEdges === null || oldEdges === void 0 ? void 0 : oldEdges.length;
|
|
542
|
+
const edges = [];
|
|
543
|
+
|
|
544
|
+
for (let i = 0; i < length1; i++) {
|
|
545
|
+
if (!oldEdges.find(v => v.id === newEdges[i].id)) {
|
|
546
|
+
edges.push({
|
|
547
|
+
status: 'add',
|
|
548
|
+
edge: newEdges[i]
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
for (let i = 0; i < length2; i++) {
|
|
554
|
+
if (!newEdges.find(v => v.id === oldEdges[i].id)) {
|
|
555
|
+
edges.push({
|
|
556
|
+
status: 'delete',
|
|
557
|
+
edge: oldEdges[i]
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
return edges;
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
exports.getDiffEdge = getDiffEdge;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './server';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _server.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _server = _interopRequireDefault(require("./server"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var _default = (0, _database().defineCollection)({
|
|
19
|
+
name: 'graphPositions',
|
|
20
|
+
fields: [{
|
|
21
|
+
type: 'string',
|
|
22
|
+
name: 'collectionName',
|
|
23
|
+
unique: true
|
|
24
|
+
}, {
|
|
25
|
+
type: 'double',
|
|
26
|
+
name: 'x'
|
|
27
|
+
}, {
|
|
28
|
+
type: 'double',
|
|
29
|
+
name: 'y'
|
|
30
|
+
}]
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
exports.default = _default;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.GraphCollectionManagerPlugin = void 0;
|
|
7
|
+
|
|
8
|
+
function _server() {
|
|
9
|
+
const data = require("@nocobase/server");
|
|
10
|
+
|
|
11
|
+
_server = function _server() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _path() {
|
|
19
|
+
const data = _interopRequireDefault(require("path"));
|
|
20
|
+
|
|
21
|
+
_path = function _path() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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); } }
|
|
31
|
+
|
|
32
|
+
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); }); }; }
|
|
33
|
+
|
|
34
|
+
class GraphCollectionManagerPlugin extends _server().Plugin {
|
|
35
|
+
load() {
|
|
36
|
+
var _this = this;
|
|
37
|
+
|
|
38
|
+
return _asyncToGenerator(function* () {
|
|
39
|
+
yield _this.db.import({
|
|
40
|
+
directory: _path().default.resolve(__dirname, 'collections')
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
_this.app.acl.allow('graphPositions', '*');
|
|
44
|
+
})();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.GraphCollectionManagerPlugin = GraphCollectionManagerPlugin;
|
|
50
|
+
var _default = GraphCollectionManagerPlugin;
|
|
51
|
+
exports.default = _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nocobase/plugin-graph-collection-manager",
|
|
3
|
+
"version": "0.9.0-alpha.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "AGPL-3.0",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"types": "./lib/index.d.ts",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@antv/x6": "^1.9.0",
|
|
10
|
+
"@antv/x6-react-shape": "^1.6.2",
|
|
11
|
+
"dagre": "^0.8.5"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@nocobase/client": "0.9.0-alpha.1",
|
|
15
|
+
"@nocobase/test": "0.9.0-alpha.1"
|
|
16
|
+
},
|
|
17
|
+
"gitHead": "d84c2a47c42c2ffec4fbf317d53268952fbd58d7"
|
|
18
|
+
}
|
package/server.d.ts
ADDED