@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/index.d.mts CHANGED
@@ -146,6 +146,7 @@ declare class LayoutStore {
146
146
  private indexMap;
147
147
  private init;
148
148
  private store;
149
+ private container;
149
150
  get initialized(): boolean;
150
151
  getNode(id: string): LayoutNode | undefined;
151
152
  getNodeByIndex(index: string): LayoutNode | undefined;
@@ -217,6 +218,7 @@ interface LayoutEdge {
217
218
  interface LayoutParams {
218
219
  nodes: WorkflowNodeEntity[];
219
220
  edges: WorkflowLineEntity[];
221
+ container: WorkflowNodeEntity;
220
222
  }
221
223
  interface LayoutOptions {
222
224
  getFollowNode?: GetFollowNode;
package/dist/index.d.ts CHANGED
@@ -146,6 +146,7 @@ declare class LayoutStore {
146
146
  private indexMap;
147
147
  private init;
148
148
  private store;
149
+ private container;
149
150
  get initialized(): boolean;
150
151
  getNode(id: string): LayoutNode | undefined;
151
152
  getNodeByIndex(index: string): LayoutNode | undefined;
@@ -217,6 +218,7 @@ interface LayoutEdge {
217
218
  interface LayoutParams {
218
219
  nodes: WorkflowNodeEntity[];
219
220
  edges: WorkflowLineEntity[];
221
+ container: WorkflowNodeEntity;
220
222
  }
221
223
  interface LayoutOptions {
222
224
  getFollowNode?: GetFollowNode;
package/dist/index.js CHANGED
@@ -2108,9 +2108,10 @@ var import_core2 = require("@flowgram.ai/core");
2108
2108
 
2109
2109
  // src/services.ts
2110
2110
  var import_inversify = require("inversify");
2111
- var import_free_layout_core = require("@flowgram.ai/free-layout-core");
2111
+ var import_free_layout_core2 = require("@flowgram.ai/free-layout-core");
2112
2112
 
2113
2113
  // src/layout/store.ts
2114
+ var import_free_layout_core = require("@flowgram.ai/free-layout-core");
2114
2115
  var import_document = require("@flowgram.ai/document");
2115
2116
  var LayoutStore = class {
2116
2117
  constructor() {
@@ -2142,7 +2143,8 @@ var LayoutStore = class {
2142
2143
  }
2143
2144
  /** 创建布局数据 */
2144
2145
  createStore(params) {
2145
- const { nodes, edges } = params;
2146
+ const { nodes, edges, container } = params;
2147
+ this.container = container;
2146
2148
  const layoutNodes = this.createLayoutNodes(nodes);
2147
2149
  const layoutEdges = this.createEdgesStore(edges);
2148
2150
  const virtualEdges = this.createVirtualEdges(params);
@@ -2282,27 +2284,37 @@ var LayoutStore = class {
2282
2284
  this.nodes.forEach((node) => {
2283
2285
  nodeIdList.push(node.id);
2284
2286
  });
2285
- const sameFromEdges = /* @__PURE__ */ new Map();
2286
2287
  this.edges.forEach((edge) => {
2287
2288
  nodeIdList.push(edge.to);
2288
- if (edge.entity.info.fromPort) {
2289
- const edgesForFrom = sameFromEdges.get(edge.from) || [];
2290
- sameFromEdges.set(edge.from, [...edgesForFrom, edge]);
2291
- }
2292
2289
  });
2293
- sameFromEdges.forEach((edges, from) => {
2294
- const sortedEdges = edges.sort((a, b) => {
2295
- const aPort = a.entity.fromPort;
2296
- const bPort = b.entity.fromPort;
2290
+ const visited = /* @__PURE__ */ new Set();
2291
+ const visit = (node) => {
2292
+ if (visited.has(node.id)) {
2293
+ return;
2294
+ }
2295
+ visited.add(node.id);
2296
+ nodeIdList.push(node.id);
2297
+ node.blocks.forEach((child) => {
2298
+ visit(child);
2299
+ });
2300
+ const { outputLines } = node.getData(import_free_layout_core.WorkflowNodeLinesData);
2301
+ const sortedLines = outputLines.sort((a, b) => {
2302
+ const aPort = a.fromPort;
2303
+ const bPort = b.fromPort;
2297
2304
  if (aPort && bPort) {
2298
2305
  return aPort.point.y - bPort.point.y;
2299
2306
  }
2300
2307
  return 0;
2301
2308
  });
2302
- sortedEdges.forEach((edge) => {
2303
- nodeIdList.push(edge.to);
2309
+ sortedLines.forEach((line) => {
2310
+ const { to } = line;
2311
+ if (!to) {
2312
+ return;
2313
+ }
2314
+ visit(to);
2304
2315
  });
2305
- });
2316
+ };
2317
+ visit(this.container);
2306
2318
  const uniqueNodeIds = nodeIdList.reduceRight((acc, nodeId) => {
2307
2319
  if (!acc.includes(nodeId)) {
2308
2320
  acc.unshift(nodeId);
@@ -2590,13 +2602,13 @@ var AutoLayoutService = class {
2590
2602
  const edges = this.getNodesAllLines(nodes);
2591
2603
  await Promise.all(nodes.map(async (child) => this.layoutNode(child, options)));
2592
2604
  const layout2 = new Layout();
2593
- layout2.init({ nodes, edges }, options);
2605
+ layout2.init({ nodes, edges, container: node }, options);
2594
2606
  layout2.layout();
2595
2607
  await layout2.position();
2596
2608
  }
2597
2609
  getNodesAllLines(nodes) {
2598
2610
  const lines = nodes.map((node) => {
2599
- const linesData = node.getData(import_free_layout_core.WorkflowNodeLinesData);
2611
+ const linesData = node.getData(import_free_layout_core2.WorkflowNodeLinesData);
2600
2612
  const outputLines = linesData.outputLines.filter(Boolean);
2601
2613
  const inputLines = linesData.inputLines.filter(Boolean);
2602
2614
  return [...outputLines, ...inputLines];
@@ -2605,7 +2617,7 @@ var AutoLayoutService = class {
2605
2617
  }
2606
2618
  };
2607
2619
  __decorateClass([
2608
- (0, import_inversify.inject)(import_free_layout_core.WorkflowDocument)
2620
+ (0, import_inversify.inject)(import_free_layout_core2.WorkflowDocument)
2609
2621
  ], AutoLayoutService.prototype, "document", 2);
2610
2622
  AutoLayoutService = __decorateClass([
2611
2623
  (0, import_inversify.injectable)()