@rxflow/bloodline 0.0.1-alpha.0
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/README.md +41 -0
- package/cjs/BaseNodeWrapper/index.d.ts +18 -0
- package/cjs/BaseNodeWrapper/index.d.ts.map +1 -0
- package/cjs/BaseNodeWrapper/index.js +51 -0
- package/cjs/GroupNodeWrapper/index.d.ts +15 -0
- package/cjs/GroupNodeWrapper/index.d.ts.map +1 -0
- package/cjs/GroupNodeWrapper/index.js +64 -0
- package/cjs/components/Connector.d.ts +8 -0
- package/cjs/components/Connector.d.ts.map +1 -0
- package/cjs/components/Connector.js +147 -0
- package/cjs/constants.d.ts +26 -0
- package/cjs/constants.d.ts.map +1 -0
- package/cjs/constants.js +35 -0
- package/cjs/index.d.ts +7 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +82 -0
- package/cjs/style/index.less +1 -0
- package/cjs/style/theme.less +16 -0
- package/cjs/types.d.ts +49 -0
- package/cjs/types.d.ts.map +1 -0
- package/cjs/types.js +3 -0
- package/cjs/utils/_layoutCells.d.ts +14 -0
- package/cjs/utils/_layoutCells.d.ts.map +1 -0
- package/cjs/utils/_layoutCells.js +483 -0
- package/cjs/utils/keys.d.ts +3 -0
- package/cjs/utils/keys.d.ts.map +1 -0
- package/cjs/utils/keys.js +18 -0
- package/cjs/utils/layoutCells.d.ts +14 -0
- package/cjs/utils/layoutCells.d.ts.map +1 -0
- package/cjs/utils/layoutCells.js +308 -0
- package/esm/BaseNodeWrapper/index.d.ts +18 -0
- package/esm/BaseNodeWrapper/index.d.ts.map +1 -0
- package/esm/BaseNodeWrapper/index.js +44 -0
- package/esm/GroupNodeWrapper/index.d.ts +15 -0
- package/esm/GroupNodeWrapper/index.d.ts.map +1 -0
- package/esm/GroupNodeWrapper/index.js +56 -0
- package/esm/components/Connector.d.ts +8 -0
- package/esm/components/Connector.d.ts.map +1 -0
- package/esm/components/Connector.js +162 -0
- package/esm/constants.d.ts +26 -0
- package/esm/constants.d.ts.map +1 -0
- package/esm/constants.js +30 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +55 -0
- package/esm/style/index.less +1 -0
- package/esm/style/theme.less +16 -0
- package/esm/types.d.ts +49 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +13 -0
- package/esm/utils/_layoutCells.d.ts +14 -0
- package/esm/utils/_layoutCells.d.ts.map +1 -0
- package/esm/utils/_layoutCells.js +477 -0
- package/esm/utils/keys.d.ts +3 -0
- package/esm/utils/keys.d.ts.map +1 -0
- package/esm/utils/keys.js +11 -0
- package/esm/utils/layoutCells.d.ts +14 -0
- package/esm/utils/layoutCells.d.ts.map +1 -0
- package/esm/utils/layoutCells.js +305 -0
- package/package.json +47 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.layoutCells = void 0;
|
|
7
|
+
var _hierarchy = _interopRequireDefault(require("@antv/hierarchy"));
|
|
8
|
+
var _base = require("@rxflow/base");
|
|
9
|
+
var _last = _interopRequireDefault(require("lodash/last"));
|
|
10
|
+
var _constants = require("../constants");
|
|
11
|
+
var _keys = require("./keys");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
/**
|
|
14
|
+
* @author: yanxianliang
|
|
15
|
+
* @date: 2025-07-03 13:20
|
|
16
|
+
* @desc: 血缘布局
|
|
17
|
+
*
|
|
18
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// 支持 innerNodes 配置
|
|
22
|
+
function getChildren(direction, origin) {
|
|
23
|
+
let children = [];
|
|
24
|
+
if (origin.innerNodes) {
|
|
25
|
+
origin.innerNodes.forEach(innerNode => {
|
|
26
|
+
const connectorState = direction === _constants.BloodlineDirection.downstream ? innerNode.downstream : innerNode.upstream;
|
|
27
|
+
if (connectorState?.state === 'expanded') {
|
|
28
|
+
const list = connectorState.list || [];
|
|
29
|
+
children.push(...list.map(child => {
|
|
30
|
+
return {
|
|
31
|
+
...child,
|
|
32
|
+
[_constants.sideSymbol]: direction === _constants.BloodlineDirection.upstream ? _constants.SplitSide.left : _constants.SplitSide.right,
|
|
33
|
+
[_constants.parentIdSymbol]: innerNode.id
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
const connectorState = direction === _constants.BloodlineDirection.downstream ? origin.downstream : origin.upstream;
|
|
40
|
+
if (connectorState?.state === 'expanded') {
|
|
41
|
+
const list = connectorState.list || [];
|
|
42
|
+
children.push(...list.map(child => {
|
|
43
|
+
return {
|
|
44
|
+
...child,
|
|
45
|
+
[_constants.sideSymbol]: direction === _constants.BloodlineDirection.upstream ? _constants.SplitSide.left : _constants.SplitSide.right
|
|
46
|
+
};
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return children;
|
|
51
|
+
}
|
|
52
|
+
function getSiblings(node) {
|
|
53
|
+
const {
|
|
54
|
+
depth,
|
|
55
|
+
side,
|
|
56
|
+
parent
|
|
57
|
+
} = node;
|
|
58
|
+
if (!parent || !parent.children) {
|
|
59
|
+
return {
|
|
60
|
+
firstNode: null
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
let firstNode = null;
|
|
64
|
+
for (const child of parent.children) {
|
|
65
|
+
if (depth === 1 && child.side === side) {
|
|
66
|
+
!firstNode && (firstNode = child);
|
|
67
|
+
}
|
|
68
|
+
if (depth !== 1) {
|
|
69
|
+
!firstNode && (firstNode = child);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
firstNode
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getChildrenNodes(node, cycleCheckNodeSet) {
|
|
77
|
+
const side = node.side;
|
|
78
|
+
let children = [];
|
|
79
|
+
switch (side) {
|
|
80
|
+
case 'left':
|
|
81
|
+
children = getChildren(_constants.BloodlineDirection.upstream, node);
|
|
82
|
+
break;
|
|
83
|
+
case 'right':
|
|
84
|
+
children = getChildren(_constants.BloodlineDirection.downstream, node);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
{
|
|
88
|
+
const leftChildren = getChildren(_constants.BloodlineDirection.upstream, node);
|
|
89
|
+
const rightChildren = getChildren(_constants.BloodlineDirection.downstream, node);
|
|
90
|
+
children = [...(leftChildren || []), ...(rightChildren || [])];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 支持 nodeList 处理
|
|
95
|
+
|
|
96
|
+
if (cycleCheckNodeSet) {
|
|
97
|
+
// 剔除循环引用的列表
|
|
98
|
+
return children.filter(child => {
|
|
99
|
+
if (cycleCheckNodeSet.has(child.id)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
cycleCheckNodeSet.add(child.id);
|
|
103
|
+
return true;
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
return children;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const layoutCells = config => {
|
|
110
|
+
const {
|
|
111
|
+
nodeTypes,
|
|
112
|
+
originNodes,
|
|
113
|
+
theme,
|
|
114
|
+
store,
|
|
115
|
+
flowProps
|
|
116
|
+
} = config;
|
|
117
|
+
|
|
118
|
+
// const {autoHideIntermediateNode} = flowProps as IBloodlineFlowProps;
|
|
119
|
+
|
|
120
|
+
const {
|
|
121
|
+
nodeLookup
|
|
122
|
+
} = store;
|
|
123
|
+
const innerNodeLookup = new Map();
|
|
124
|
+
if (originNodes.length === 0) {
|
|
125
|
+
return {
|
|
126
|
+
nodes: [],
|
|
127
|
+
edges: []
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 需不需要进行 clone ??? 需要设置 side 等属性,要回显回去吗??不需要的吧
|
|
132
|
+
const root = originNodes[0]; // 根节点
|
|
133
|
+
|
|
134
|
+
const align = theme.align || _constants.Align.top;
|
|
135
|
+
const layoutType = theme.layout || 'compactBox';
|
|
136
|
+
const layoutUtil = layoutType === 'mindmap' ? _hierarchy.default.mindmap : _hierarchy.default.compactBox;
|
|
137
|
+
|
|
138
|
+
// let edges: Edge[] = [];
|
|
139
|
+
|
|
140
|
+
// split side
|
|
141
|
+
root?.upstream?.list?.forEach(item => {
|
|
142
|
+
item[_constants.sideSymbol] = _constants.SplitSide.left;
|
|
143
|
+
});
|
|
144
|
+
root?.downstream?.list?.forEach(item => {
|
|
145
|
+
item[_constants.sideSymbol] = _constants.SplitSide.right;
|
|
146
|
+
});
|
|
147
|
+
const cycleCheckNodeSet = new Set([root.id]); // 循环依赖节点检测
|
|
148
|
+
|
|
149
|
+
const layoutResult = layoutUtil(root, {
|
|
150
|
+
direction: 'H',
|
|
151
|
+
getHGap: () => {
|
|
152
|
+
return 40;
|
|
153
|
+
},
|
|
154
|
+
getVGap: () => {
|
|
155
|
+
return 20;
|
|
156
|
+
},
|
|
157
|
+
getWidth(node) {
|
|
158
|
+
const width = (0, _base.getNodeWidth)(node, nodeTypes, theme, nodeLookup);
|
|
159
|
+
node.measured ?? (node.measured = {});
|
|
160
|
+
node.measured.width = width;
|
|
161
|
+
return width;
|
|
162
|
+
},
|
|
163
|
+
getHeight(node) {
|
|
164
|
+
const height = (0, _base.getNodeHeight)(node, nodeTypes, theme, nodeLookup);
|
|
165
|
+
node.measured ?? (node.measured = {});
|
|
166
|
+
node.measured.height = height;
|
|
167
|
+
return height;
|
|
168
|
+
},
|
|
169
|
+
getSide: node => {
|
|
170
|
+
// side 计算,上下游需要区分左和右
|
|
171
|
+
return node.data[_constants.sideSymbol] || 'right';
|
|
172
|
+
},
|
|
173
|
+
getChildren: node => {
|
|
174
|
+
return getChildrenNodes(node, cycleCheckNodeSet);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
let layoutNodes = [];
|
|
178
|
+
const {
|
|
179
|
+
x: rootX,
|
|
180
|
+
y: rootY
|
|
181
|
+
} = layoutResult;
|
|
182
|
+
// 开始节点x,y 以(0,0)进行修正,根节点需要能够被检测显示在画布区域
|
|
183
|
+
|
|
184
|
+
const loopCycleCheckNodeSet = new Set();
|
|
185
|
+
const edgesCount = {};
|
|
186
|
+
const edgesIndex = {};
|
|
187
|
+
const nodeHandles = {};
|
|
188
|
+
let edges = [];
|
|
189
|
+
|
|
190
|
+
// source 表示上游节点,target 表示下游节点
|
|
191
|
+
layoutResult.BFTraverse(node => {
|
|
192
|
+
const {
|
|
193
|
+
x,
|
|
194
|
+
y,
|
|
195
|
+
data,
|
|
196
|
+
side,
|
|
197
|
+
parent,
|
|
198
|
+
depth
|
|
199
|
+
} = node;
|
|
200
|
+
const {
|
|
201
|
+
id,
|
|
202
|
+
type,
|
|
203
|
+
measured
|
|
204
|
+
} = data;
|
|
205
|
+
if (loopCycleCheckNodeSet.has(id)) {
|
|
206
|
+
// 循环节点进行剔除
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
loopCycleCheckNodeSet.add(id);
|
|
210
|
+
const {
|
|
211
|
+
firstNode
|
|
212
|
+
} = getSiblings(node); // 同级节点
|
|
213
|
+
|
|
214
|
+
const offsetY = firstNode ? firstNode.y - parent.position.y : 0;
|
|
215
|
+
const direction = side === 'left' ? _constants.BloodlineDirection.upstream : _constants.BloodlineDirection.downstream;
|
|
216
|
+
const adjustX = x - rootX;
|
|
217
|
+
// 是否居中, 可居中,可顶部对齐
|
|
218
|
+
const adjustY = align === _constants.Align.top ? y - (parent ? offsetY : rootY) : y - rootY;
|
|
219
|
+
const position = {
|
|
220
|
+
x: adjustX,
|
|
221
|
+
y: adjustY
|
|
222
|
+
};
|
|
223
|
+
node.position = position;
|
|
224
|
+
if (!innerNodeLookup.has(id)) {
|
|
225
|
+
// 已经存在相同的节点了,直接关联到之前的节点上
|
|
226
|
+
// 实例每次都是新的,使用 data 实例缓存,但是所有节点外面都需要包一层????
|
|
227
|
+
const definition = nodeTypes?.[type];
|
|
228
|
+
const instance = {
|
|
229
|
+
id,
|
|
230
|
+
type,
|
|
231
|
+
measured: measured,
|
|
232
|
+
width: measured.width,
|
|
233
|
+
// 宽度固定,高度自动计算
|
|
234
|
+
height: measured.height,
|
|
235
|
+
// 血缘节点高度标准化模式为固定
|
|
236
|
+
data: {
|
|
237
|
+
isRoot: node.isRoot(),
|
|
238
|
+
depth,
|
|
239
|
+
id,
|
|
240
|
+
direction,
|
|
241
|
+
origin: data
|
|
242
|
+
// leaf 节点属性,当展开和折叠时需要处理对应的 leaf。
|
|
243
|
+
},
|
|
244
|
+
position: position,
|
|
245
|
+
zIndex: 10 // 节点默认 zIndex
|
|
246
|
+
};
|
|
247
|
+
const handles = definition?.measureHandles?.(instance);
|
|
248
|
+
instance.handles = (0, _base.parseHandles)(handles);
|
|
249
|
+
|
|
250
|
+
// 重复检测,如果已经存在相同节点,节点id相同,自动复用之前的节点。
|
|
251
|
+
layoutNodes.push(instance);
|
|
252
|
+
innerNodeLookup.set(id, instance);
|
|
253
|
+
}
|
|
254
|
+
const childrenNodes = getChildrenNodes(data);
|
|
255
|
+
childrenNodes.forEach(child => {
|
|
256
|
+
const side = child[_constants.sideSymbol] || 'right';
|
|
257
|
+
const {
|
|
258
|
+
innerNodes
|
|
259
|
+
} = child; // 如果有父级的子节点标记
|
|
260
|
+
// 连线是从 __parentId__ 到 child
|
|
261
|
+
const parentNodeId = child[_constants.parentIdSymbol] || id;
|
|
262
|
+
const childId = child.id;
|
|
263
|
+
if (!innerNodes) {
|
|
264
|
+
const sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
265
|
+
const targetNode = side === 'left' ? id : childId; // 下游节点
|
|
266
|
+
|
|
267
|
+
const sourceHandleNode = side === 'left' ? childId : parentNodeId;
|
|
268
|
+
const targetHandleNode = side === 'left' ? parentNodeId : childId; // targetHandleNode 是
|
|
269
|
+
|
|
270
|
+
const sourceHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.downstream, sourceHandleNode);
|
|
271
|
+
const targetHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.upstream, targetHandleNode);
|
|
272
|
+
const _edge = {
|
|
273
|
+
id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
274
|
+
type: 'smart',
|
|
275
|
+
// 'smart',
|
|
276
|
+
source: sourceNode,
|
|
277
|
+
target: targetNode,
|
|
278
|
+
sourceHandle: sourceHandle,
|
|
279
|
+
// 可能链接其中某个版本
|
|
280
|
+
targetHandle: targetHandle
|
|
281
|
+
};
|
|
282
|
+
edges.push(_edge);
|
|
283
|
+
const {
|
|
284
|
+
source,
|
|
285
|
+
target
|
|
286
|
+
} = _edge;
|
|
287
|
+
if (!edgesCount[sourceHandle]) {
|
|
288
|
+
edgesCount[sourceHandle] = 1;
|
|
289
|
+
} else {
|
|
290
|
+
edgesCount[sourceHandle] += 1;
|
|
291
|
+
}
|
|
292
|
+
if (!edgesCount[targetHandle]) {
|
|
293
|
+
edgesCount[targetHandle] = 1;
|
|
294
|
+
} else {
|
|
295
|
+
edgesCount[targetHandle] += 1;
|
|
296
|
+
}
|
|
297
|
+
if (!edgesCount[`source-${source}`]) {
|
|
298
|
+
edgesCount[`source-${source}`] = 1;
|
|
299
|
+
} else {
|
|
300
|
+
edgesCount[`source-${source}`] += 1;
|
|
301
|
+
}
|
|
302
|
+
if (!edgesCount[`target-${target}`]) {
|
|
303
|
+
edgesCount[`target-${target}`] = 1;
|
|
304
|
+
} else {
|
|
305
|
+
edgesCount[`target-${target}`] += 1;
|
|
306
|
+
}
|
|
307
|
+
edgesIndex[_edge.id] = {
|
|
308
|
+
source: edgesCount[sourceHandle] - 1,
|
|
309
|
+
target: edgesCount[targetHandle] - 1
|
|
310
|
+
};
|
|
311
|
+
if (!nodeHandles[source]) {
|
|
312
|
+
nodeHandles[source] = {
|
|
313
|
+
sourceHandles: {},
|
|
314
|
+
targetHandles: {}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
if (!nodeHandles[target]) {
|
|
318
|
+
nodeHandles[target] = {
|
|
319
|
+
sourceHandles: {},
|
|
320
|
+
targetHandles: {}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
if (!nodeHandles[source].sourceHandles[sourceHandle]) {
|
|
324
|
+
nodeHandles[source].sourceHandles[sourceHandle] = 1;
|
|
325
|
+
} else {
|
|
326
|
+
nodeHandles[source].sourceHandles[sourceHandle] += 1;
|
|
327
|
+
}
|
|
328
|
+
if (!nodeHandles[target].targetHandles[targetHandle]) {
|
|
329
|
+
nodeHandles[target].targetHandles[targetHandle] = 1;
|
|
330
|
+
} else {
|
|
331
|
+
nodeHandles[target].targetHandles[targetHandle] += 1;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
//
|
|
335
|
+
// edges.push({
|
|
336
|
+
// id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
337
|
+
// type: 'smart', // 'smart',
|
|
338
|
+
// source: sourceNode,
|
|
339
|
+
// target: targetNode,
|
|
340
|
+
// sourceHandle: sourceHandle, // 可能链接其中某个版本
|
|
341
|
+
// targetHandle: targetHandle,
|
|
342
|
+
// data: {
|
|
343
|
+
// sourcePort: {
|
|
344
|
+
// edges: edgesCount[`source-${edge.source}`],
|
|
345
|
+
// portIndex: parseInt(lastOf(edge.sourceHandle.split('#'))!, 10),
|
|
346
|
+
// portCount: Object.keys(nodeHandles[edge.source].sourceHandles).length,
|
|
347
|
+
// edgeIndex: edgesIndex[edge.id].source,
|
|
348
|
+
// edgeCount: edgesCount[edge.sourceHandle],
|
|
349
|
+
// },
|
|
350
|
+
// targetPort: {
|
|
351
|
+
// edges: edgesCount[`target-${edge.target}`],
|
|
352
|
+
// portIndex: parseInt(lastOf(edge.targetHandle.split('#'))!, 10),
|
|
353
|
+
// portCount: Object.keys(nodeHandles[edge.target].targetHandles).length,
|
|
354
|
+
// edgeIndex: edgesIndex[edge.id].target,
|
|
355
|
+
// edgeCount: edgesCount[edge.targetHandle],
|
|
356
|
+
// },
|
|
357
|
+
// },
|
|
358
|
+
// })
|
|
359
|
+
} else {
|
|
360
|
+
innerNodes.forEach(innerNode => {
|
|
361
|
+
const sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
362
|
+
const targetNode = side === 'left' ? id : childId; // 下游节点
|
|
363
|
+
|
|
364
|
+
const sourceHandleNode = side === 'left' ? innerNode.id : parentNodeId;
|
|
365
|
+
const targetHandleNode = side === 'left' ? parentNodeId : innerNode.id; // targetHandleNode 是
|
|
366
|
+
|
|
367
|
+
const sourceHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.downstream, sourceHandleNode);
|
|
368
|
+
const targetHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.upstream, targetHandleNode);
|
|
369
|
+
const _edge = {
|
|
370
|
+
id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
371
|
+
type: 'smart',
|
|
372
|
+
// 'smart',
|
|
373
|
+
source: sourceNode,
|
|
374
|
+
target: targetNode,
|
|
375
|
+
sourceHandle: sourceHandle,
|
|
376
|
+
// 可能链接其中某个版本
|
|
377
|
+
targetHandle: targetHandle
|
|
378
|
+
};
|
|
379
|
+
edges.push(_edge);
|
|
380
|
+
const {
|
|
381
|
+
source,
|
|
382
|
+
target
|
|
383
|
+
} = _edge;
|
|
384
|
+
if (!edgesCount[sourceHandle]) {
|
|
385
|
+
edgesCount[sourceHandle] = 1;
|
|
386
|
+
} else {
|
|
387
|
+
edgesCount[sourceHandle] += 1;
|
|
388
|
+
}
|
|
389
|
+
if (!edgesCount[targetHandle]) {
|
|
390
|
+
edgesCount[targetHandle] = 1;
|
|
391
|
+
} else {
|
|
392
|
+
edgesCount[targetHandle] += 1;
|
|
393
|
+
}
|
|
394
|
+
if (!edgesCount[`source-${source}`]) {
|
|
395
|
+
edgesCount[`source-${source}`] = 1;
|
|
396
|
+
} else {
|
|
397
|
+
edgesCount[`source-${source}`] += 1;
|
|
398
|
+
}
|
|
399
|
+
if (!edgesCount[`target-${target}`]) {
|
|
400
|
+
edgesCount[`target-${target}`] = 1;
|
|
401
|
+
} else {
|
|
402
|
+
edgesCount[`target-${target}`] += 1;
|
|
403
|
+
}
|
|
404
|
+
edgesIndex[_edge.id] = {
|
|
405
|
+
source: edgesCount[sourceHandle] - 1,
|
|
406
|
+
target: edgesCount[targetHandle] - 1
|
|
407
|
+
};
|
|
408
|
+
if (!nodeHandles[source]) {
|
|
409
|
+
nodeHandles[source] = {
|
|
410
|
+
sourceHandles: {},
|
|
411
|
+
targetHandles: {}
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
if (!nodeHandles[target]) {
|
|
415
|
+
nodeHandles[target] = {
|
|
416
|
+
sourceHandles: {},
|
|
417
|
+
targetHandles: {}
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (!nodeHandles[source].sourceHandles[sourceHandle]) {
|
|
421
|
+
nodeHandles[source].sourceHandles[sourceHandle] = 1;
|
|
422
|
+
} else {
|
|
423
|
+
nodeHandles[source].sourceHandles[sourceHandle] += 1;
|
|
424
|
+
}
|
|
425
|
+
if (!nodeHandles[target].targetHandles[targetHandle]) {
|
|
426
|
+
nodeHandles[target].targetHandles[targetHandle] = 1;
|
|
427
|
+
} else {
|
|
428
|
+
nodeHandles[target].targetHandles[targetHandle] += 1;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// edges.push({
|
|
432
|
+
// id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
433
|
+
// type: 'smart', // 'smart',
|
|
434
|
+
// source: sourceNode,
|
|
435
|
+
// target: targetNode,
|
|
436
|
+
// sourceHandle: sourceHandle, // 可能链接其中某个版本
|
|
437
|
+
// targetHandle: targetHandle,
|
|
438
|
+
// data: {
|
|
439
|
+
// sourcePort: {
|
|
440
|
+
// edges: edgesCount[`source-${edge.source}`],
|
|
441
|
+
// portIndex: 1,
|
|
442
|
+
// portCount: 1,
|
|
443
|
+
// edgeIndex: edgesIndex[edge.id].source,
|
|
444
|
+
// edgeCount: edgesCount[edge.sourceHandle],
|
|
445
|
+
// },
|
|
446
|
+
// targetPort: {
|
|
447
|
+
// edges: edgesCount[`target-${edge.target}`],
|
|
448
|
+
// portIndex: 1,
|
|
449
|
+
// portCount: 1,
|
|
450
|
+
// edgeIndex: edgesIndex[edge.id].target,
|
|
451
|
+
// edgeCount: edgesCount[edge.targetHandle],
|
|
452
|
+
// },
|
|
453
|
+
// },
|
|
454
|
+
// })
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
edges = edges.map(edge => ({
|
|
460
|
+
...edge,
|
|
461
|
+
data: {
|
|
462
|
+
sourcePort: {
|
|
463
|
+
edges: edgesCount[`source-${edge.source}`],
|
|
464
|
+
portIndex: parseInt((0, _last.default)(edge.sourceHandle.split('#')), 10),
|
|
465
|
+
portCount: Object.keys(nodeHandles[edge.source].sourceHandles).length,
|
|
466
|
+
edgeIndex: edgesIndex[edge.id].source,
|
|
467
|
+
edgeCount: edgesCount[edge.sourceHandle]
|
|
468
|
+
},
|
|
469
|
+
targetPort: {
|
|
470
|
+
edges: edgesCount[`target-${edge.target}`],
|
|
471
|
+
portIndex: parseInt((0, _last.default)(edge.targetHandle.split('#')), 10),
|
|
472
|
+
portCount: Object.keys(nodeHandles[edge.target].targetHandles).length,
|
|
473
|
+
edgeIndex: edgesIndex[edge.id].target,
|
|
474
|
+
edgeCount: edgesCount[edge.targetHandle]
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}));
|
|
478
|
+
return {
|
|
479
|
+
nodes: layoutNodes,
|
|
480
|
+
edges: edges
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
exports.layoutCells = layoutCells;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["keys.ts"],"names":[],"mappings":"AAQA,OAAO,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAGhD,eAAO,MAAM,cAAc,cAAe,kBAAkB,MAAM,MAAM,WAEvE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getConnectorId = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* @author: yanxianliang
|
|
9
|
+
* @date: 2025-06-02 16:57
|
|
10
|
+
* @desc: keys 生成
|
|
11
|
+
*
|
|
12
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const getConnectorId = (direction, id) => {
|
|
16
|
+
return `${id}.${direction}`;
|
|
17
|
+
};
|
|
18
|
+
exports.getConnectorId = getConnectorId;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author: yanxianliang
|
|
3
|
+
* @date: 2025-07-03 13:20
|
|
4
|
+
* @desc: 血缘布局
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
|
+
*/
|
|
8
|
+
import { Edge, Node } from "@xyflow/react";
|
|
9
|
+
import { LayoutConfig } from "@rxflow/base";
|
|
10
|
+
export declare const layoutCells: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(config: LayoutConfig<NodeType, EdgeType>) => {
|
|
11
|
+
nodes: NodeType[];
|
|
12
|
+
edges: EdgeType[];
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=layoutCells.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layoutCells.d.ts","sourceRoot":"","sources":["layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAA8B,YAAY,EAAgB,MAAM,cAAc,CAAC;AAqGtF,eAAO,MAAM,WAAW,uEACd,aAAa,QAAQ,EAAE,QAAQ,CAAC;;;CA+LzC,CAAA"}
|