@flowgram.ai/free-auto-layout-plugin 0.2.2 → 0.2.3
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 +30 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +29 -17
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/esm/index.js
CHANGED
|
@@ -2083,10 +2083,13 @@ import { definePluginCreator } from "@flowgram.ai/core";
|
|
|
2083
2083
|
import { inject, injectable } from "inversify";
|
|
2084
2084
|
import {
|
|
2085
2085
|
WorkflowDocument,
|
|
2086
|
-
WorkflowNodeLinesData
|
|
2086
|
+
WorkflowNodeLinesData as WorkflowNodeLinesData2
|
|
2087
2087
|
} from "@flowgram.ai/free-layout-core";
|
|
2088
2088
|
|
|
2089
2089
|
// src/layout/store.ts
|
|
2090
|
+
import {
|
|
2091
|
+
WorkflowNodeLinesData
|
|
2092
|
+
} from "@flowgram.ai/free-layout-core";
|
|
2090
2093
|
import { FlowNodeBaseType, FlowNodeTransformData } from "@flowgram.ai/document";
|
|
2091
2094
|
var LayoutStore = class {
|
|
2092
2095
|
constructor() {
|
|
@@ -2118,7 +2121,8 @@ var LayoutStore = class {
|
|
|
2118
2121
|
}
|
|
2119
2122
|
/** 创建布局数据 */
|
|
2120
2123
|
createStore(params) {
|
|
2121
|
-
const { nodes, edges } = params;
|
|
2124
|
+
const { nodes, edges, container } = params;
|
|
2125
|
+
this.container = container;
|
|
2122
2126
|
const layoutNodes = this.createLayoutNodes(nodes);
|
|
2123
2127
|
const layoutEdges = this.createEdgesStore(edges);
|
|
2124
2128
|
const virtualEdges = this.createVirtualEdges(params);
|
|
@@ -2258,27 +2262,37 @@ var LayoutStore = class {
|
|
|
2258
2262
|
this.nodes.forEach((node) => {
|
|
2259
2263
|
nodeIdList.push(node.id);
|
|
2260
2264
|
});
|
|
2261
|
-
const sameFromEdges = /* @__PURE__ */ new Map();
|
|
2262
2265
|
this.edges.forEach((edge) => {
|
|
2263
2266
|
nodeIdList.push(edge.to);
|
|
2264
|
-
if (edge.entity.info.fromPort) {
|
|
2265
|
-
const edgesForFrom = sameFromEdges.get(edge.from) || [];
|
|
2266
|
-
sameFromEdges.set(edge.from, [...edgesForFrom, edge]);
|
|
2267
|
-
}
|
|
2268
2267
|
});
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2268
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2269
|
+
const visit = (node) => {
|
|
2270
|
+
if (visited.has(node.id)) {
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2273
|
+
visited.add(node.id);
|
|
2274
|
+
nodeIdList.push(node.id);
|
|
2275
|
+
node.blocks.forEach((child) => {
|
|
2276
|
+
visit(child);
|
|
2277
|
+
});
|
|
2278
|
+
const { outputLines } = node.getData(WorkflowNodeLinesData);
|
|
2279
|
+
const sortedLines = outputLines.sort((a, b) => {
|
|
2280
|
+
const aPort = a.fromPort;
|
|
2281
|
+
const bPort = b.fromPort;
|
|
2273
2282
|
if (aPort && bPort) {
|
|
2274
2283
|
return aPort.point.y - bPort.point.y;
|
|
2275
2284
|
}
|
|
2276
2285
|
return 0;
|
|
2277
2286
|
});
|
|
2278
|
-
|
|
2279
|
-
|
|
2287
|
+
sortedLines.forEach((line) => {
|
|
2288
|
+
const { to } = line;
|
|
2289
|
+
if (!to) {
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
visit(to);
|
|
2280
2293
|
});
|
|
2281
|
-
}
|
|
2294
|
+
};
|
|
2295
|
+
visit(this.container);
|
|
2282
2296
|
const uniqueNodeIds = nodeIdList.reduceRight((acc, nodeId) => {
|
|
2283
2297
|
if (!acc.includes(nodeId)) {
|
|
2284
2298
|
acc.unshift(nodeId);
|
|
@@ -2566,13 +2580,13 @@ var AutoLayoutService = class {
|
|
|
2566
2580
|
const edges = this.getNodesAllLines(nodes);
|
|
2567
2581
|
await Promise.all(nodes.map(async (child) => this.layoutNode(child, options)));
|
|
2568
2582
|
const layout2 = new Layout();
|
|
2569
|
-
layout2.init({ nodes, edges }, options);
|
|
2583
|
+
layout2.init({ nodes, edges, container: node }, options);
|
|
2570
2584
|
layout2.layout();
|
|
2571
2585
|
await layout2.position();
|
|
2572
2586
|
}
|
|
2573
2587
|
getNodesAllLines(nodes) {
|
|
2574
2588
|
const lines = nodes.map((node) => {
|
|
2575
|
-
const linesData = node.getData(
|
|
2589
|
+
const linesData = node.getData(WorkflowNodeLinesData2);
|
|
2576
2590
|
const outputLines = linesData.outputLines.filter(Boolean);
|
|
2577
2591
|
const inputLines = linesData.inputLines.filter(Boolean);
|
|
2578
2592
|
return [...outputLines, ...inputLines];
|