@flowgram.ai/free-layout-core 0.1.24 → 0.1.26

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
@@ -1043,8 +1043,8 @@ WorkflowSelectService = __decorateClass([
1043
1043
 
1044
1044
  // src/service/workflow-hover-service.ts
1045
1045
  import { inject as inject2, injectable as injectable2 } from "inversify";
1046
- import { EntityManager } from "@flowgram.ai/core";
1047
1046
  import { Emitter as Emitter2 } from "@flowgram.ai/utils";
1047
+ import { EntityManager } from "@flowgram.ai/core";
1048
1048
  var WorkflowHoverService = class {
1049
1049
  constructor() {
1050
1050
  this.onHoveredChangeEmitter = new Emitter2();
@@ -1543,16 +1543,16 @@ import {
1543
1543
 
1544
1544
  // src/layout/free-layout.ts
1545
1545
  import { inject as inject4, injectable as injectable4 } from "inversify";
1546
- import {
1547
- FlowDocumentProvider,
1548
- FlowNodeTransformData as FlowNodeTransformData4
1549
- } from "@flowgram.ai/document";
1550
- import { PlaygroundConfigEntity as PlaygroundConfigEntity3, TransformData as TransformData7 } from "@flowgram.ai/core";
1551
1546
  import {
1552
1547
  PaddingSchema,
1553
1548
  Rectangle as Rectangle7,
1554
1549
  SizeSchema as SizeSchema2
1555
1550
  } from "@flowgram.ai/utils";
1551
+ import {
1552
+ FlowDocumentProvider,
1553
+ FlowNodeTransformData as FlowNodeTransformData4
1554
+ } from "@flowgram.ai/document";
1555
+ import { PlaygroundConfigEntity as PlaygroundConfigEntity3, TransformData as TransformData7 } from "@flowgram.ai/core";
1556
1556
  var FREE_LAYOUT_KEY = "free-layout";
1557
1557
  var FreeLayout = class {
1558
1558
  constructor() {
@@ -1587,6 +1587,21 @@ var FreeLayout = class {
1587
1587
  const parentTransform = node.parent.getData(FlowNodeTransformData4);
1588
1588
  parentTransform.transform.fireChange();
1589
1589
  }
1590
+ /**
1591
+ * 更新所有受影响的上下游节点
1592
+ */
1593
+ updateAffectedTransform(node) {
1594
+ const transformData = node.transform;
1595
+ if (!transformData.localDirty) {
1596
+ return;
1597
+ }
1598
+ const allParents = this.getAllParents(node);
1599
+ const allBlocks = this.getAllBlocks(node).reverse();
1600
+ const affectedNodes = [...allBlocks, ...allParents];
1601
+ affectedNodes.forEach((node2) => {
1602
+ this.fireChange(node2);
1603
+ });
1604
+ }
1590
1605
  /**
1591
1606
  * 获取节点的 padding 数据
1592
1607
  * @param node
@@ -1632,6 +1647,30 @@ var FreeLayout = class {
1632
1647
  getDefaultNodeOrigin() {
1633
1648
  return { x: 0.5, y: 0 };
1634
1649
  }
1650
+ getAllParents(node) {
1651
+ const parents = [];
1652
+ let current = node.parent;
1653
+ while (current) {
1654
+ parents.push(current);
1655
+ current = current.parent;
1656
+ }
1657
+ return parents;
1658
+ }
1659
+ getAllBlocks(node) {
1660
+ return node.blocks.reduce(
1661
+ (acc, child) => [...acc, ...this.getAllBlocks(child)],
1662
+ [node]
1663
+ );
1664
+ }
1665
+ fireChange(node) {
1666
+ const transformData = node?.transform;
1667
+ if (!node || !transformData?.localDirty) {
1668
+ return;
1669
+ }
1670
+ node.clearMemoGlobal();
1671
+ node.clearMemoLocal();
1672
+ transformData.transform.fireChange();
1673
+ }
1635
1674
  };
1636
1675
  __decorateClass([
1637
1676
  inject4(PlaygroundConfigEntity3)
@@ -1826,6 +1865,13 @@ var WorkflowDocument = class extends FlowDocument {
1826
1865
  });
1827
1866
  return node;
1828
1867
  }
1868
+ get layout() {
1869
+ const layout = this.layouts.find((layout2) => layout2.name == this.currentLayoutKey);
1870
+ if (!layout) {
1871
+ throw new Error(`Unknown flow layout: ${this.currentLayoutKey}`);
1872
+ }
1873
+ return layout;
1874
+ }
1829
1875
  /**
1830
1876
  * 获取默认的 x y 坐标, 默认为当前画布可视区域中心
1831
1877
  * @param type
@@ -2239,15 +2285,10 @@ var WorkflowDragService = class {
2239
2285
  x: nodeStartPosition.x + offset.x,
2240
2286
  y: nodeStartPosition.y + offset.y
2241
2287
  };
2242
- if (node.collapsedChildren?.length > 0) {
2243
- node.collapsedChildren.forEach((childNode) => {
2244
- const childNodeTransformData = childNode.getData(FlowNodeTransformData6);
2245
- childNodeTransformData.fireChange();
2246
- });
2247
- }
2248
2288
  transform.update({
2249
2289
  position: newPosition
2250
2290
  });
2291
+ this.document.layout.updateAffectedTransform(node);
2251
2292
  positions.push(newPosition);
2252
2293
  });
2253
2294
  this._nodesDragEmitter.fire({
@@ -2768,18 +2809,14 @@ var layoutToPositions = async (nodes, nodePositionMap) => {
2768
2809
  const transform = node.getData(TransformData10);
2769
2810
  const deltaX = (nodePositionMap[node.id].x - transform.position.x) * v.d / 100;
2770
2811
  const deltaY = (nodePositionMap[node.id].y - transform.bounds.height / 2 - transform.position.y) * v.d / 100;
2771
- if (node.collapsedChildren?.length > 0) {
2772
- node.collapsedChildren.forEach((childNode) => {
2773
- const childNodeTransformData = childNode.getData(FlowNodeTransformData7);
2774
- childNodeTransformData.fireChange();
2775
- });
2776
- }
2777
2812
  transform.update({
2778
2813
  position: {
2779
2814
  x: transform.position.x + deltaX,
2780
2815
  y: transform.position.y + deltaY
2781
2816
  }
2782
2817
  });
2818
+ const document2 = node.document;
2819
+ document2.layout.updateAffectedTransform(node);
2783
2820
  });
2784
2821
  },
2785
2822
  onComplete: () => {