@flowgram.ai/free-auto-layout-plugin 0.1.26 → 0.1.28
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/dist/esm/index.js +79 -20
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +78 -19
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/esm/index.js
CHANGED
|
@@ -2085,10 +2085,9 @@ import {
|
|
|
2085
2085
|
WorkflowDocument,
|
|
2086
2086
|
WorkflowNodeLinesData
|
|
2087
2087
|
} from "@flowgram.ai/free-layout-core";
|
|
2088
|
-
import { FlowNodeBaseType } from "@flowgram.ai/document";
|
|
2089
2088
|
|
|
2090
2089
|
// src/layout/store.ts
|
|
2091
|
-
import { FlowNodeTransformData } from "@flowgram.ai/document";
|
|
2090
|
+
import { FlowNodeBaseType, FlowNodeTransformData } from "@flowgram.ai/document";
|
|
2092
2091
|
var LayoutStore = class {
|
|
2093
2092
|
constructor() {
|
|
2094
2093
|
this.init = false;
|
|
@@ -2120,11 +2119,20 @@ var LayoutStore = class {
|
|
|
2120
2119
|
/** 创建布局数据 */
|
|
2121
2120
|
createStore(params) {
|
|
2122
2121
|
const { nodes, edges } = params;
|
|
2122
|
+
const layoutNodes = this.createLayoutNodes(nodes);
|
|
2123
|
+
const layoutEdges = this.createEdgesStore(edges);
|
|
2124
|
+
const virtualEdges = this.createVirtualEdges(params);
|
|
2123
2125
|
const store = {
|
|
2124
2126
|
nodes: /* @__PURE__ */ new Map(),
|
|
2125
2127
|
edges: /* @__PURE__ */ new Map()
|
|
2126
2128
|
};
|
|
2127
|
-
|
|
2129
|
+
layoutNodes.forEach((node) => store.nodes.set(node.id, node));
|
|
2130
|
+
layoutEdges.concat(virtualEdges).forEach((edge) => store.edges.set(edge.id, edge));
|
|
2131
|
+
return store;
|
|
2132
|
+
}
|
|
2133
|
+
/** 创建节点布局数据 */
|
|
2134
|
+
createLayoutNodes(nodes) {
|
|
2135
|
+
const layoutNodes = nodes.map((node, index) => {
|
|
2128
2136
|
const { bounds } = node.getData(FlowNodeTransformData);
|
|
2129
2137
|
const layoutNode = {
|
|
2130
2138
|
id: node.id,
|
|
@@ -2140,9 +2148,13 @@ var LayoutStore = class {
|
|
|
2140
2148
|
size: { width: bounds.width, height: bounds.height },
|
|
2141
2149
|
hasChildren: node.collapsedChildren?.length > 0
|
|
2142
2150
|
};
|
|
2143
|
-
|
|
2151
|
+
return layoutNode;
|
|
2144
2152
|
});
|
|
2145
|
-
|
|
2153
|
+
return layoutNodes;
|
|
2154
|
+
}
|
|
2155
|
+
/** 创建线条布局数据 */
|
|
2156
|
+
createEdgesStore(edges) {
|
|
2157
|
+
const layoutEdges = edges.map((edge) => {
|
|
2146
2158
|
const { from, to } = edge.info;
|
|
2147
2159
|
if (!from || !to || edge.vertical) {
|
|
2148
2160
|
return;
|
|
@@ -2158,9 +2170,58 @@ var LayoutStore = class {
|
|
|
2158
2170
|
// 初始化时,index 未计算
|
|
2159
2171
|
name: edge.id
|
|
2160
2172
|
};
|
|
2161
|
-
|
|
2162
|
-
});
|
|
2163
|
-
return
|
|
2173
|
+
return layoutEdge;
|
|
2174
|
+
}).filter(Boolean);
|
|
2175
|
+
return layoutEdges;
|
|
2176
|
+
}
|
|
2177
|
+
/** 创建虚拟线条数据 */
|
|
2178
|
+
createVirtualEdges(params) {
|
|
2179
|
+
const { nodes, edges } = params;
|
|
2180
|
+
const groupNodes = nodes.filter((n) => n.flowNodeType === FlowNodeBaseType.GROUP);
|
|
2181
|
+
const virtualEdges = groupNodes.map((group) => {
|
|
2182
|
+
const { id: groupId, blocks = [] } = group;
|
|
2183
|
+
const blockIdSet = new Set(blocks.map((b) => b.id));
|
|
2184
|
+
const groupFromEdges = edges.filter((edge) => blockIdSet.has(edge.to?.id ?? "")).map((edge) => {
|
|
2185
|
+
const { from, to } = edge.info;
|
|
2186
|
+
if (!from || !to || edge.vertical) {
|
|
2187
|
+
return;
|
|
2188
|
+
}
|
|
2189
|
+
const id = `virtual_${groupId}_${to}`;
|
|
2190
|
+
const layoutEdge = {
|
|
2191
|
+
id,
|
|
2192
|
+
entity: edge,
|
|
2193
|
+
from,
|
|
2194
|
+
to: groupId,
|
|
2195
|
+
fromIndex: "",
|
|
2196
|
+
// 初始化时,index 未计算
|
|
2197
|
+
toIndex: "",
|
|
2198
|
+
// 初始化时,index 未计算
|
|
2199
|
+
name: id
|
|
2200
|
+
};
|
|
2201
|
+
return layoutEdge;
|
|
2202
|
+
}).filter(Boolean);
|
|
2203
|
+
const groupToEdges = edges.filter((edge) => blockIdSet.has(edge.from.id ?? "")).map((edge) => {
|
|
2204
|
+
const { from, to } = edge.info;
|
|
2205
|
+
if (!from || !to || edge.vertical) {
|
|
2206
|
+
return;
|
|
2207
|
+
}
|
|
2208
|
+
const id = `virtual_${groupId}_${from}`;
|
|
2209
|
+
const layoutEdge = {
|
|
2210
|
+
id,
|
|
2211
|
+
entity: edge,
|
|
2212
|
+
from: groupId,
|
|
2213
|
+
to,
|
|
2214
|
+
fromIndex: "",
|
|
2215
|
+
// 初始化时,index 未计算
|
|
2216
|
+
toIndex: "",
|
|
2217
|
+
// 初始化时,index 未计算
|
|
2218
|
+
name: id
|
|
2219
|
+
};
|
|
2220
|
+
return layoutEdge;
|
|
2221
|
+
}).filter(Boolean);
|
|
2222
|
+
return [...groupFromEdges, ...groupToEdges];
|
|
2223
|
+
}).flat();
|
|
2224
|
+
return virtualEdges;
|
|
2164
2225
|
}
|
|
2165
2226
|
/** 创建节点索引映射 */
|
|
2166
2227
|
createIndexMap() {
|
|
@@ -2498,27 +2559,25 @@ var AutoLayoutService = class {
|
|
|
2498
2559
|
await this.layoutNode(this.document.root, options);
|
|
2499
2560
|
}
|
|
2500
2561
|
async layoutNode(node, options) {
|
|
2501
|
-
const nodes =
|
|
2562
|
+
const nodes = node.blocks;
|
|
2502
2563
|
if (!nodes || !Array.isArray(nodes) || !nodes.length) {
|
|
2503
2564
|
return;
|
|
2504
2565
|
}
|
|
2505
|
-
const edges =
|
|
2506
|
-
const childLinesData = child.getData(WorkflowNodeLinesData);
|
|
2507
|
-
return childLinesData.outputLines.filter(Boolean);
|
|
2508
|
-
}).flat();
|
|
2566
|
+
const edges = this.getNodesAllLines(nodes);
|
|
2509
2567
|
await Promise.all(nodes.map(async (child) => this.layoutNode(child, options)));
|
|
2510
2568
|
const layout2 = new Layout();
|
|
2511
2569
|
layout2.init({ nodes, edges }, options);
|
|
2512
2570
|
layout2.layout();
|
|
2513
2571
|
await layout2.position();
|
|
2514
2572
|
}
|
|
2515
|
-
|
|
2516
|
-
const
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2573
|
+
getNodesAllLines(nodes) {
|
|
2574
|
+
const lines = nodes.map((node) => {
|
|
2575
|
+
const linesData = node.getData(WorkflowNodeLinesData);
|
|
2576
|
+
const outputLines = linesData.outputLines.filter(Boolean);
|
|
2577
|
+
const inputLines = linesData.inputLines.filter(Boolean);
|
|
2578
|
+
return [...outputLines, ...inputLines];
|
|
2579
|
+
}).flat();
|
|
2580
|
+
return lines;
|
|
2522
2581
|
}
|
|
2523
2582
|
};
|
|
2524
2583
|
__decorateClass([
|