@flowgram.ai/free-layout-core 0.4.16 → 0.4.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 CHANGED
@@ -776,11 +776,11 @@ var WorkflowLineRenderData = class extends EntityData3 {
776
776
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
777
777
  */
778
778
  updatePosition() {
779
- this.data.position.from = this.entity.from.getData(WorkflowNodePortsData).getOutputPoint(this.entity.info.fromPort);
779
+ this.data.position.from = this.entity.from.ports.getOutputPoint(this.entity.info.fromPort);
780
780
  if (this.entity.info.drawingTo) {
781
781
  this.data.position.to = this.entity.info.drawingTo;
782
782
  } else {
783
- this.data.position.to = this.entity.to?.getData(WorkflowNodePortsData)?.getInputPoint(this.entity.info.toPort) ?? {
783
+ this.data.position.to = this.entity.to?.ports?.getInputPoint(this.entity.info.toPort) ?? {
784
784
  x: this.data.position.from.x,
785
785
  y: this.data.position.from.y,
786
786
  location: this.data.position.from.location === "right" ? "left" : "top"
@@ -1042,13 +1042,13 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
1042
1042
  return this.getData(WorkflowLineRenderData).calcDistance(pos);
1043
1043
  }
1044
1044
  get fromPort() {
1045
- return this.from.getData(WorkflowNodePortsData).getPortEntityByKey("output", this.info.fromPort);
1045
+ return this.from.ports.getPortEntityByKey("output", this.info.fromPort);
1046
1046
  }
1047
1047
  get toPort() {
1048
1048
  if (!this.to) {
1049
1049
  return void 0;
1050
1050
  }
1051
- return this.to.getData(WorkflowNodePortsData).getPortEntityByKey("input", this.info.toPort);
1051
+ return this.to.ports.getPortEntityByKey("input", this.info.toPort);
1052
1052
  }
1053
1053
  /**
1054
1054
  * 获取线条真实的输入输出节点坐标
@@ -1726,7 +1726,7 @@ var WorkflowLinesManager = class {
1726
1726
  */
1727
1727
  getPortFromMousePos(pos) {
1728
1728
  const allNodes = this.getSortedNodes().reverse();
1729
- const allPorts = allNodes.map((node) => node.getData(WorkflowNodePortsData).allPorts).flat();
1729
+ const allPorts = allNodes.map((node) => node.ports.allPorts).flat();
1730
1730
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1731
1731
  if (targetPort) {
1732
1732
  const containNodes = this.getContainNodesFromMousePos(pos);
@@ -2181,8 +2181,11 @@ var WorkflowDocument = class extends FlowDocument {
2181
2181
  originParent,
2182
2182
  meta
2183
2183
  });
2184
+ this.options.preNodeCreate?.(node);
2184
2185
  const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
2185
2186
  node.addInitializeData(datas);
2187
+ node.ports = node.getData(WorkflowNodePortsData);
2188
+ node.lines = node.getData(WorkflowNodeLinesData);
2186
2189
  node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
2187
2190
  this.options.fromNodeJSON?.(node, data, true);
2188
2191
  isNew = true;
@@ -2633,10 +2636,6 @@ var WorkflowDragService = class {
2633
2636
  return Promise.resolve(false);
2634
2637
  }
2635
2638
  this.isDragging = true;
2636
- const sameParent = this.childrenOfContainer(selectedNodes);
2637
- if (sameParent && sameParent.flowNodeType !== FlowNodeBaseType3.ROOT) {
2638
- selectedNodes = [sameParent];
2639
- }
2640
2639
  let startPosition = this.getNodesPosition(selectedNodes);
2641
2640
  let startPositions = selectedNodes.map((node) => {
2642
2641
  const transform = node.getData(TransformData8);
@@ -2698,6 +2697,7 @@ var WorkflowDragService = class {
2698
2697
  triggerEvent,
2699
2698
  dragger
2700
2699
  });
2700
+ this.resetContainerInternalPosition(selectedNodes);
2701
2701
  }
2702
2702
  });
2703
2703
  const { clientX, clientY } = MouseTouchEvent.getEventCoord(triggerEvent);
@@ -2968,12 +2968,48 @@ var WorkflowDragService = class {
2968
2968
  };
2969
2969
  }
2970
2970
  }
2971
+ /**
2972
+ * 容器内子节点总体位置重置为0
2973
+ */
2974
+ resetContainerInternalPosition(nodes) {
2975
+ const container = this.childrenOfContainer(nodes);
2976
+ if (!container) {
2977
+ return;
2978
+ }
2979
+ const bounds = Rectangle8.enlarge(
2980
+ container.blocks.map((node) => {
2981
+ const x = node.transform.position.x - node.transform.bounds.width / 2;
2982
+ const y = node.transform.position.y;
2983
+ const width = node.transform.bounds.width;
2984
+ const height = node.transform.bounds.height;
2985
+ return new Rectangle8(x, y, width, height);
2986
+ })
2987
+ );
2988
+ const containerTransform = container.getData(TransformData8);
2989
+ containerTransform.update({
2990
+ position: {
2991
+ x: containerTransform.position.x + bounds.x,
2992
+ y: containerTransform.position.y + bounds.y
2993
+ }
2994
+ });
2995
+ this.document.layout.updateAffectedTransform(container);
2996
+ container.blocks.forEach((node) => {
2997
+ const transform = node.getData(TransformData8);
2998
+ transform.update({
2999
+ position: {
3000
+ x: transform.position.x - bounds.x,
3001
+ y: transform.position.y - bounds.y
3002
+ }
3003
+ });
3004
+ this.document.layout.updateAffectedTransform(node);
3005
+ });
3006
+ }
2971
3007
  childrenOfContainer(nodes) {
2972
3008
  if (nodes.length === 0) {
2973
3009
  return;
2974
3010
  }
2975
3011
  const sourceContainer = nodes[0]?.parent;
2976
- if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
3012
+ if (!sourceContainer) {
2977
3013
  return;
2978
3014
  }
2979
3015
  const valid = nodes.every((node) => node?.parent === sourceContainer);
@@ -3174,7 +3210,7 @@ var WorkflowDragService = class {
3174
3210
  }
3175
3211
  /** 获取最近的 port */
3176
3212
  getNearestPort(node, mousePos) {
3177
- const portsData = node.getData(WorkflowNodePortsData);
3213
+ const portsData = node.ports;
3178
3214
  const distanceSortedPorts = portsData.inputPorts.sort((a, b) => {
3179
3215
  const aDistance = Math.abs(mousePos.y - a.point.y);
3180
3216
  const bDistance = Math.abs(mousePos.y - b.point.y);
@@ -3379,7 +3415,7 @@ var isFirefox = navigator?.userAgent?.includes?.("Firefox");
3379
3415
  function useNodeRender(nodeFromProps) {
3380
3416
  const node = nodeFromProps || useContext(PlaygroundEntityContext);
3381
3417
  const renderData = node.getData(FlowNodeRenderData3);
3382
- const portsData = node.getData(WorkflowNodePortsData);
3418
+ const portsData = node.ports;
3383
3419
  const readonly = usePlaygroundReadonlyState();
3384
3420
  const dragService = useService(WorkflowDragService);
3385
3421
  const selectionService = useService(WorkflowSelectService);