@flowgram.ai/free-auto-layout-plugin 0.2.16 → 0.2.18
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 +57 -33
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +39 -4
- package/dist/index.d.ts +39 -4
- package/dist/index.js +57 -33
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/esm/index.js
CHANGED
|
@@ -2086,6 +2086,23 @@ import {
|
|
|
2086
2086
|
WorkflowNodeLinesData as WorkflowNodeLinesData2
|
|
2087
2087
|
} from "@flowgram.ai/free-layout-core";
|
|
2088
2088
|
|
|
2089
|
+
// src/layout/constant.ts
|
|
2090
|
+
var DefaultLayoutConfig = {
|
|
2091
|
+
rankdir: "LR",
|
|
2092
|
+
align: void 0,
|
|
2093
|
+
nodesep: 100,
|
|
2094
|
+
edgesep: 10,
|
|
2095
|
+
ranksep: 100,
|
|
2096
|
+
marginx: 0,
|
|
2097
|
+
marginy: 0,
|
|
2098
|
+
acyclicer: void 0,
|
|
2099
|
+
ranker: "network-simplex"
|
|
2100
|
+
};
|
|
2101
|
+
var DefaultLayoutOptions = {
|
|
2102
|
+
getFollowNode: void 0,
|
|
2103
|
+
enableAnimation: false
|
|
2104
|
+
};
|
|
2105
|
+
|
|
2089
2106
|
// src/layout/store.ts
|
|
2090
2107
|
import {
|
|
2091
2108
|
WorkflowNodeLinesData
|
|
@@ -2118,9 +2135,10 @@ var LayoutStore = class {
|
|
|
2118
2135
|
get edges() {
|
|
2119
2136
|
return Array.from(this.store.edges.values());
|
|
2120
2137
|
}
|
|
2121
|
-
create(params) {
|
|
2138
|
+
create(params, options) {
|
|
2122
2139
|
this.store = this.createStore(params);
|
|
2123
2140
|
this.indexMap = this.createIndexMap();
|
|
2141
|
+
this.setOptions(options);
|
|
2124
2142
|
this.init = true;
|
|
2125
2143
|
}
|
|
2126
2144
|
/** 创建布局数据 */
|
|
@@ -2310,6 +2328,27 @@ var LayoutStore = class {
|
|
|
2310
2328
|
}, []);
|
|
2311
2329
|
return uniqueNodeIds;
|
|
2312
2330
|
}
|
|
2331
|
+
/** 记录运行选项 */
|
|
2332
|
+
setOptions(options) {
|
|
2333
|
+
this.options = options;
|
|
2334
|
+
this.setFollowNode(options.getFollowNode);
|
|
2335
|
+
}
|
|
2336
|
+
/** 设置跟随节点配置 */
|
|
2337
|
+
setFollowNode(getFollowNode) {
|
|
2338
|
+
if (!getFollowNode) return;
|
|
2339
|
+
const context = { store: this };
|
|
2340
|
+
this.nodes.forEach((node) => {
|
|
2341
|
+
const followTo = getFollowNode(node, context)?.followTo;
|
|
2342
|
+
if (!followTo) return;
|
|
2343
|
+
const followToNode = this.getNode(followTo);
|
|
2344
|
+
if (!followToNode) return;
|
|
2345
|
+
if (!followToNode.followedBy) {
|
|
2346
|
+
followToNode.followedBy = [];
|
|
2347
|
+
}
|
|
2348
|
+
followToNode.followedBy.push(node.id);
|
|
2349
|
+
node.followTo = followTo;
|
|
2350
|
+
});
|
|
2351
|
+
}
|
|
2313
2352
|
};
|
|
2314
2353
|
|
|
2315
2354
|
// src/layout/position.ts
|
|
@@ -2319,6 +2358,17 @@ var LayoutPosition = class {
|
|
|
2319
2358
|
this.store = store;
|
|
2320
2359
|
}
|
|
2321
2360
|
async position() {
|
|
2361
|
+
if (this.store.options.enableAnimation) {
|
|
2362
|
+
return this.positionWithAnimation();
|
|
2363
|
+
}
|
|
2364
|
+
return this.positionDirectly();
|
|
2365
|
+
}
|
|
2366
|
+
positionDirectly() {
|
|
2367
|
+
this.store.nodes.forEach((layoutNode) => {
|
|
2368
|
+
this.updateNodePosition({ layoutNode, step: 100 });
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
2371
|
+
async positionWithAnimation() {
|
|
2322
2372
|
return new Promise((resolve) => {
|
|
2323
2373
|
startTween({
|
|
2324
2374
|
from: { d: 0 },
|
|
@@ -2533,9 +2583,8 @@ var Layout = class {
|
|
|
2533
2583
|
this._layout = new DagreLayout(this._store);
|
|
2534
2584
|
this._position = new LayoutPosition(this._store);
|
|
2535
2585
|
}
|
|
2536
|
-
init(params, options
|
|
2537
|
-
this._store.create(params);
|
|
2538
|
-
this.setFollowNode(options.getFollowNode);
|
|
2586
|
+
init(params, options) {
|
|
2587
|
+
this._store.create(params, options);
|
|
2539
2588
|
}
|
|
2540
2589
|
layout() {
|
|
2541
2590
|
if (!this._store.initialized) {
|
|
@@ -2549,34 +2598,6 @@ var Layout = class {
|
|
|
2549
2598
|
}
|
|
2550
2599
|
return await this._position.position();
|
|
2551
2600
|
}
|
|
2552
|
-
setFollowNode(getFollowNode) {
|
|
2553
|
-
if (!getFollowNode) return;
|
|
2554
|
-
const context = { store: this._store };
|
|
2555
|
-
this._store.nodes.forEach((node) => {
|
|
2556
|
-
const followTo = getFollowNode(node, context)?.followTo;
|
|
2557
|
-
if (!followTo) return;
|
|
2558
|
-
const followToNode = this._store.getNode(followTo);
|
|
2559
|
-
if (!followToNode) return;
|
|
2560
|
-
if (!followToNode.followedBy) {
|
|
2561
|
-
followToNode.followedBy = [];
|
|
2562
|
-
}
|
|
2563
|
-
followToNode.followedBy.push(node.id);
|
|
2564
|
-
node.followTo = followTo;
|
|
2565
|
-
});
|
|
2566
|
-
}
|
|
2567
|
-
};
|
|
2568
|
-
|
|
2569
|
-
// src/layout/constant.ts
|
|
2570
|
-
var DefaultLayoutConfig = {
|
|
2571
|
-
rankdir: "LR",
|
|
2572
|
-
align: void 0,
|
|
2573
|
-
nodesep: 100,
|
|
2574
|
-
edgesep: 10,
|
|
2575
|
-
ranksep: 100,
|
|
2576
|
-
marginx: 0,
|
|
2577
|
-
marginy: 0,
|
|
2578
|
-
acyclicer: void 0,
|
|
2579
|
-
ranker: "network-simplex"
|
|
2580
2601
|
};
|
|
2581
2602
|
|
|
2582
2603
|
// src/services.ts
|
|
@@ -2591,7 +2612,10 @@ var AutoLayoutService = class {
|
|
|
2591
2612
|
};
|
|
2592
2613
|
}
|
|
2593
2614
|
async layout(options = {}) {
|
|
2594
|
-
await this.layoutNode(this.document.root,
|
|
2615
|
+
await this.layoutNode(this.document.root, {
|
|
2616
|
+
...DefaultLayoutOptions,
|
|
2617
|
+
...options
|
|
2618
|
+
});
|
|
2595
2619
|
}
|
|
2596
2620
|
async layoutNode(node, options) {
|
|
2597
2621
|
const nodes = node.blocks;
|