@flowgram.ai/free-auto-layout-plugin 0.1.0-alpha.31 → 0.1.0-alpha.33

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 CHANGED
@@ -2167,7 +2167,7 @@ var LayoutStore = class {
2167
2167
  const blockIdSet = new Set(blocks.map((b) => b.id));
2168
2168
  const groupFromEdges = edges.filter((edge) => blockIdSet.has(edge.to?.id ?? "")).map((edge) => {
2169
2169
  const { from, to } = edge.info;
2170
- if (!from || !to || edge.vertical) {
2170
+ if (!from || !to) {
2171
2171
  return;
2172
2172
  }
2173
2173
  const id = `virtual_${groupId}_from_${from}_to_${to}`;
@@ -2186,7 +2186,7 @@ var LayoutStore = class {
2186
2186
  }).filter(Boolean);
2187
2187
  const groupToEdges = edges.filter((edge) => blockIdSet.has(edge.from?.id ?? "")).map((edge) => {
2188
2188
  const { from, to } = edge.info;
2189
- if (!from || !to || edge.vertical) {
2189
+ if (!from || !to) {
2190
2190
  return;
2191
2191
  }
2192
2192
  const id = `virtual_${groupId}_from_${from}_to_${to}`;
@@ -2346,7 +2346,7 @@ var LayoutPosition = class {
2346
2346
  updateNodePosition(params) {
2347
2347
  const { layoutNode, step } = params;
2348
2348
  const { transform } = layoutNode.entity.transform;
2349
- const centerToTopEdgeOffset = this.store.options.alignTopEdge ? 0 : (layoutNode.size.height - layoutNode.padding.top - layoutNode.padding.bottom) / 2;
2349
+ const centerToTopEdgeOffset = (layoutNode.size.height - layoutNode.padding.top - layoutNode.padding.bottom) / 2;
2350
2350
  const layoutPosition = {
2351
2351
  x: layoutNode.position.x + layoutNode.offset.x,
2352
2352
  y: layoutNode.position.y + layoutNode.offset.y - centerToTopEdgeOffset
@@ -2375,6 +2375,7 @@ var DagreLayout = class {
2375
2375
  layout() {
2376
2376
  this.graphSetData();
2377
2377
  this.dagreLayout();
2378
+ this.alignTopEdgeIfNeeded();
2378
2379
  this.layoutSetPosition();
2379
2380
  }
2380
2381
  dagreLayout() {
@@ -2459,6 +2460,28 @@ var DagreLayout = class {
2459
2460
  };
2460
2461
  });
2461
2462
  }
2463
+ alignTopEdgeIfNeeded() {
2464
+ const { alignTopEdge } = this.store.options;
2465
+ const { rankdir, marginy = 0 } = this.store.config;
2466
+ if (!alignTopEdge || rankdir !== "LR" && rankdir !== "RL") {
2467
+ return;
2468
+ }
2469
+ const rankGroups = this.rankGroup(this.graph);
2470
+ rankGroups.forEach((indexSet) => {
2471
+ const graphNodes = Array.from(indexSet).map((id) => this.graph.node(id)).filter(Boolean);
2472
+ if (graphNodes.length === 0) {
2473
+ return;
2474
+ }
2475
+ const minTop = Math.min(...graphNodes.map((node) => node.y - node.height / 2));
2476
+ const deltaY = marginy - minTop;
2477
+ if (deltaY === 0) {
2478
+ return;
2479
+ }
2480
+ graphNodes.forEach((node) => {
2481
+ node.y += deltaY;
2482
+ });
2483
+ });
2484
+ }
2462
2485
  normalizeNumber(number) {
2463
2486
  return Number.isNaN(number) ? 0 : number;
2464
2487
  }
@@ -2523,6 +2546,9 @@ var DagreLayout = class {
2523
2546
  const rankGroup = /* @__PURE__ */ new Map();
2524
2547
  g.nodes().forEach((i) => {
2525
2548
  const graphNode = g.node(i);
2549
+ if (!graphNode || typeof graphNode.rank !== "number") {
2550
+ return;
2551
+ }
2526
2552
  const rank2 = graphNode.rank;
2527
2553
  if (!rankGroup.has(rank2)) {
2528
2554
  rankGroup.set(rank2, /* @__PURE__ */ new Set());