@flowgram.ai/free-auto-layout-plugin 0.2.9 → 0.2.11
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 +42 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +35 -5
- package/dist/index.d.ts +35 -5
- package/dist/index.js +43 -16
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/esm/index.js
CHANGED
|
@@ -2092,13 +2092,17 @@ import {
|
|
|
2092
2092
|
} from "@flowgram.ai/free-layout-core";
|
|
2093
2093
|
import { FlowNodeBaseType, FlowNodeTransformData } from "@flowgram.ai/document";
|
|
2094
2094
|
var LayoutStore = class {
|
|
2095
|
-
constructor() {
|
|
2095
|
+
constructor(config) {
|
|
2096
|
+
this.config = config;
|
|
2096
2097
|
this.init = false;
|
|
2097
2098
|
}
|
|
2098
2099
|
get initialized() {
|
|
2099
2100
|
return this.init;
|
|
2100
2101
|
}
|
|
2101
2102
|
getNode(id) {
|
|
2103
|
+
if (!id) {
|
|
2104
|
+
return void 0;
|
|
2105
|
+
}
|
|
2102
2106
|
return this.store.nodes.get(id);
|
|
2103
2107
|
}
|
|
2104
2108
|
getNodeByIndex(index) {
|
|
@@ -2277,8 +2281,13 @@ var LayoutStore = class {
|
|
|
2277
2281
|
});
|
|
2278
2282
|
const { outputLines } = node.getData(WorkflowNodeLinesData);
|
|
2279
2283
|
const sortedLines = outputLines.sort((a, b) => {
|
|
2284
|
+
const aNode = this.getNode(a.to?.id);
|
|
2285
|
+
const bNode = this.getNode(b.to?.id);
|
|
2280
2286
|
const aPort = a.fromPort;
|
|
2281
2287
|
const bPort = b.fromPort;
|
|
2288
|
+
if (aPort === bPort && aNode && bNode) {
|
|
2289
|
+
return aNode.position.y - bNode.position.y;
|
|
2290
|
+
}
|
|
2282
2291
|
if (aPort && bPort) {
|
|
2283
2292
|
return aPort.point.y - bPort.point.y;
|
|
2284
2293
|
}
|
|
@@ -2349,16 +2358,6 @@ var LayoutPosition = class {
|
|
|
2349
2358
|
// src/layout/dagre.ts
|
|
2350
2359
|
import { FlowNodeTransformData as FlowNodeTransformData2 } from "@flowgram.ai/document";
|
|
2351
2360
|
import { Graph as DagreGraph } from "@dagrejs/graphlib";
|
|
2352
|
-
|
|
2353
|
-
// src/layout/constant.ts
|
|
2354
|
-
var DagreLayoutOptions = {
|
|
2355
|
-
rankdir: "LR",
|
|
2356
|
-
nodesep: 100,
|
|
2357
|
-
ranksep: 100,
|
|
2358
|
-
ranker: "network-simplex"
|
|
2359
|
-
};
|
|
2360
|
-
|
|
2361
|
-
// src/layout/dagre.ts
|
|
2362
2361
|
var DagreLayout = class {
|
|
2363
2362
|
constructor(store) {
|
|
2364
2363
|
this.store = store;
|
|
@@ -2407,7 +2406,7 @@ var DagreLayout = class {
|
|
|
2407
2406
|
createGraph() {
|
|
2408
2407
|
const graph = new DagreGraph({ multigraph: true });
|
|
2409
2408
|
graph.setDefaultEdgeLabel(() => ({}));
|
|
2410
|
-
graph.setGraph(
|
|
2409
|
+
graph.setGraph(this.store.config);
|
|
2411
2410
|
return graph;
|
|
2412
2411
|
}
|
|
2413
2412
|
graphSetData() {
|
|
@@ -2529,8 +2528,8 @@ var DagreLayout = class {
|
|
|
2529
2528
|
|
|
2530
2529
|
// src/layout/layout.ts
|
|
2531
2530
|
var Layout = class {
|
|
2532
|
-
constructor() {
|
|
2533
|
-
this._store = new LayoutStore();
|
|
2531
|
+
constructor(config) {
|
|
2532
|
+
this._store = new LayoutStore(config);
|
|
2534
2533
|
this._layout = new DagreLayout(this._store);
|
|
2535
2534
|
this._position = new LayoutPosition(this._store);
|
|
2536
2535
|
}
|
|
@@ -2567,8 +2566,30 @@ var Layout = class {
|
|
|
2567
2566
|
}
|
|
2568
2567
|
};
|
|
2569
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
|
+
};
|
|
2581
|
+
|
|
2570
2582
|
// src/services.ts
|
|
2571
2583
|
var AutoLayoutService = class {
|
|
2584
|
+
constructor() {
|
|
2585
|
+
this.layoutConfig = DefaultLayoutConfig;
|
|
2586
|
+
}
|
|
2587
|
+
init(options) {
|
|
2588
|
+
this.layoutConfig = {
|
|
2589
|
+
...this.layoutConfig,
|
|
2590
|
+
...options.layoutConfig
|
|
2591
|
+
};
|
|
2592
|
+
}
|
|
2572
2593
|
async layout(options = {}) {
|
|
2573
2594
|
await this.layoutNode(this.document.root, options);
|
|
2574
2595
|
}
|
|
@@ -2579,7 +2600,7 @@ var AutoLayoutService = class {
|
|
|
2579
2600
|
}
|
|
2580
2601
|
const edges = this.getNodesAllLines(nodes);
|
|
2581
2602
|
await Promise.all(nodes.map(async (child) => this.layoutNode(child, options)));
|
|
2582
|
-
const layout2 = new Layout();
|
|
2603
|
+
const layout2 = new Layout(this.layoutConfig);
|
|
2583
2604
|
layout2.init({ nodes, edges, container: node }, options);
|
|
2584
2605
|
layout2.layout();
|
|
2585
2606
|
await layout2.position();
|
|
@@ -2605,7 +2626,11 @@ AutoLayoutService = __decorateClass([
|
|
|
2605
2626
|
var createFreeAutoLayoutPlugin = definePluginCreator({
|
|
2606
2627
|
onBind: ({ bind }) => {
|
|
2607
2628
|
bind(AutoLayoutService).toSelf().inSingletonScope();
|
|
2608
|
-
}
|
|
2629
|
+
},
|
|
2630
|
+
onInit: (ctx, opts) => {
|
|
2631
|
+
ctx.get(AutoLayoutService).init(opts);
|
|
2632
|
+
},
|
|
2633
|
+
singleton: true
|
|
2609
2634
|
});
|
|
2610
2635
|
|
|
2611
2636
|
// src/index.ts
|
|
@@ -2613,6 +2638,7 @@ import { Graph as Graph8 } from "@dagrejs/graphlib";
|
|
|
2613
2638
|
export {
|
|
2614
2639
|
AutoLayoutService,
|
|
2615
2640
|
Graph8 as DagreGraph,
|
|
2641
|
+
DefaultLayoutConfig,
|
|
2616
2642
|
Layout,
|
|
2617
2643
|
createFreeAutoLayoutPlugin,
|
|
2618
2644
|
dagreLib
|