@flowgram.ai/free-layout-core 0.4.15 → 0.4.17

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);
@@ -2183,6 +2183,8 @@ var WorkflowDocument = class extends FlowDocument {
2183
2183
  });
2184
2184
  const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
2185
2185
  node.addInitializeData(datas);
2186
+ node.ports = node.getData(WorkflowNodePortsData);
2187
+ node.lines = node.getData(WorkflowNodeLinesData);
2186
2188
  node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
2187
2189
  this.options.fromNodeJSON?.(node, data, true);
2188
2190
  isNew = true;
@@ -2633,10 +2635,6 @@ var WorkflowDragService = class {
2633
2635
  return Promise.resolve(false);
2634
2636
  }
2635
2637
  this.isDragging = true;
2636
- const sameParent = this.childrenOfContainer(selectedNodes);
2637
- if (sameParent && sameParent.flowNodeType !== FlowNodeBaseType3.ROOT) {
2638
- selectedNodes = [sameParent];
2639
- }
2640
2638
  let startPosition = this.getNodesPosition(selectedNodes);
2641
2639
  let startPositions = selectedNodes.map((node) => {
2642
2640
  const transform = node.getData(TransformData8);
@@ -2698,6 +2696,7 @@ var WorkflowDragService = class {
2698
2696
  triggerEvent,
2699
2697
  dragger
2700
2698
  });
2699
+ this.resetContainerInternalPosition(selectedNodes);
2701
2700
  }
2702
2701
  });
2703
2702
  const { clientX, clientY } = MouseTouchEvent.getEventCoord(triggerEvent);
@@ -2968,12 +2967,48 @@ var WorkflowDragService = class {
2968
2967
  };
2969
2968
  }
2970
2969
  }
2970
+ /**
2971
+ * 容器内子节点总体位置重置为0
2972
+ */
2973
+ resetContainerInternalPosition(nodes) {
2974
+ const container = this.childrenOfContainer(nodes);
2975
+ if (!container) {
2976
+ return;
2977
+ }
2978
+ const bounds = Rectangle8.enlarge(
2979
+ container.blocks.map((node) => {
2980
+ const x = node.transform.position.x - node.transform.bounds.width / 2;
2981
+ const y = node.transform.position.y;
2982
+ const width = node.transform.bounds.width;
2983
+ const height = node.transform.bounds.height;
2984
+ return new Rectangle8(x, y, width, height);
2985
+ })
2986
+ );
2987
+ const containerTransform = container.getData(TransformData8);
2988
+ containerTransform.update({
2989
+ position: {
2990
+ x: containerTransform.position.x + bounds.x,
2991
+ y: containerTransform.position.y + bounds.y
2992
+ }
2993
+ });
2994
+ this.document.layout.updateAffectedTransform(container);
2995
+ container.blocks.forEach((node) => {
2996
+ const transform = node.getData(TransformData8);
2997
+ transform.update({
2998
+ position: {
2999
+ x: transform.position.x - bounds.x,
3000
+ y: transform.position.y - bounds.y
3001
+ }
3002
+ });
3003
+ this.document.layout.updateAffectedTransform(node);
3004
+ });
3005
+ }
2971
3006
  childrenOfContainer(nodes) {
2972
3007
  if (nodes.length === 0) {
2973
3008
  return;
2974
3009
  }
2975
3010
  const sourceContainer = nodes[0]?.parent;
2976
- if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
3011
+ if (!sourceContainer) {
2977
3012
  return;
2978
3013
  }
2979
3014
  const valid = nodes.every((node) => node?.parent === sourceContainer);
@@ -3174,7 +3209,7 @@ var WorkflowDragService = class {
3174
3209
  }
3175
3210
  /** 获取最近的 port */
3176
3211
  getNearestPort(node, mousePos) {
3177
- const portsData = node.getData(WorkflowNodePortsData);
3212
+ const portsData = node.ports;
3178
3213
  const distanceSortedPorts = portsData.inputPorts.sort((a, b) => {
3179
3214
  const aDistance = Math.abs(mousePos.y - a.point.y);
3180
3215
  const bDistance = Math.abs(mousePos.y - b.point.y);
@@ -3379,7 +3414,7 @@ var isFirefox = navigator?.userAgent?.includes?.("Firefox");
3379
3414
  function useNodeRender(nodeFromProps) {
3380
3415
  const node = nodeFromProps || useContext(PlaygroundEntityContext);
3381
3416
  const renderData = node.getData(FlowNodeRenderData3);
3382
- const portsData = node.getData(WorkflowNodePortsData);
3417
+ const portsData = node.ports;
3383
3418
  const readonly = usePlaygroundReadonlyState();
3384
3419
  const dragService = useService(WorkflowDragService);
3385
3420
  const selectionService = useService(WorkflowSelectService);
@@ -3607,11 +3642,35 @@ WorkflowDocumentContribution = __decorateClass([
3607
3642
 
3608
3643
  // src/utils/get-url-params.ts
3609
3644
  function getUrlParams() {
3610
- return location.search.replace(/^\?/, "").split("&").reduce((res, key) => {
3645
+ const paramsMap = /* @__PURE__ */ new Map();
3646
+ location.search.replace(/^\?/, "").split("&").forEach((key) => {
3647
+ if (!key) return;
3611
3648
  const [k, v] = key.split("=");
3612
- res[k] = v;
3613
- return res;
3614
- }, {});
3649
+ if (k) {
3650
+ const decodedKey = decodeURIComponent(k.trim());
3651
+ const decodedValue = v ? decodeURIComponent(v.trim()) : "";
3652
+ const dangerousProps = [
3653
+ "__proto__",
3654
+ "constructor",
3655
+ "prototype",
3656
+ "__defineGetter__",
3657
+ "__defineSetter__",
3658
+ "__lookupGetter__",
3659
+ "__lookupSetter__",
3660
+ "hasOwnProperty",
3661
+ "isPrototypeOf",
3662
+ "propertyIsEnumerable",
3663
+ "toString",
3664
+ "valueOf",
3665
+ "toLocaleString"
3666
+ ];
3667
+ if (dangerousProps.includes(decodedKey.toLowerCase())) {
3668
+ return;
3669
+ }
3670
+ paramsMap.set(decodedKey, decodedValue);
3671
+ }
3672
+ });
3673
+ return Object.fromEntries(paramsMap);
3615
3674
  }
3616
3675
 
3617
3676
  // src/workflow-document-container-module.ts