@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/index.js CHANGED
@@ -818,11 +818,11 @@ var WorkflowLineRenderData = class extends import_core7.EntityData {
818
818
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
819
819
  */
820
820
  updatePosition() {
821
- this.data.position.from = this.entity.from.getData(WorkflowNodePortsData).getOutputPoint(this.entity.info.fromPort);
821
+ this.data.position.from = this.entity.from.ports.getOutputPoint(this.entity.info.fromPort);
822
822
  if (this.entity.info.drawingTo) {
823
823
  this.data.position.to = this.entity.info.drawingTo;
824
824
  } else {
825
- this.data.position.to = this.entity.to?.getData(WorkflowNodePortsData)?.getInputPoint(this.entity.info.toPort) ?? {
825
+ this.data.position.to = this.entity.to?.ports?.getInputPoint(this.entity.info.toPort) ?? {
826
826
  x: this.data.position.from.x,
827
827
  y: this.data.position.from.y,
828
828
  location: this.data.position.from.location === "right" ? "left" : "top"
@@ -1084,13 +1084,13 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends import_core8.Entity
1084
1084
  return this.getData(WorkflowLineRenderData).calcDistance(pos);
1085
1085
  }
1086
1086
  get fromPort() {
1087
- return this.from.getData(WorkflowNodePortsData).getPortEntityByKey("output", this.info.fromPort);
1087
+ return this.from.ports.getPortEntityByKey("output", this.info.fromPort);
1088
1088
  }
1089
1089
  get toPort() {
1090
1090
  if (!this.to) {
1091
1091
  return void 0;
1092
1092
  }
1093
- return this.to.getData(WorkflowNodePortsData).getPortEntityByKey("input", this.info.toPort);
1093
+ return this.to.ports.getPortEntityByKey("input", this.info.toPort);
1094
1094
  }
1095
1095
  /**
1096
1096
  * 获取线条真实的输入输出节点坐标
@@ -1791,7 +1791,7 @@ var WorkflowLinesManager = class {
1791
1791
  */
1792
1792
  getPortFromMousePos(pos) {
1793
1793
  const allNodes = this.getSortedNodes().reverse();
1794
- const allPorts = allNodes.map((node) => node.getData(WorkflowNodePortsData).allPorts).flat();
1794
+ const allPorts = allNodes.map((node) => node.ports.allPorts).flat();
1795
1795
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1796
1796
  if (targetPort) {
1797
1797
  const containNodes = this.getContainNodesFromMousePos(pos);
@@ -2232,6 +2232,8 @@ var WorkflowDocument = class extends import_document8.FlowDocument {
2232
2232
  });
2233
2233
  const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
2234
2234
  node.addInitializeData(datas);
2235
+ node.ports = node.getData(WorkflowNodePortsData);
2236
+ node.lines = node.getData(WorkflowNodeLinesData);
2235
2237
  node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
2236
2238
  this.options.fromNodeJSON?.(node, data, true);
2237
2239
  isNew = true;
@@ -2682,10 +2684,6 @@ var WorkflowDragService = class {
2682
2684
  return Promise.resolve(false);
2683
2685
  }
2684
2686
  this.isDragging = true;
2685
- const sameParent = this.childrenOfContainer(selectedNodes);
2686
- if (sameParent && sameParent.flowNodeType !== import_document10.FlowNodeBaseType.ROOT) {
2687
- selectedNodes = [sameParent];
2688
- }
2689
2687
  let startPosition = this.getNodesPosition(selectedNodes);
2690
2688
  let startPositions = selectedNodes.map((node) => {
2691
2689
  const transform = node.getData(import_core15.TransformData);
@@ -2747,6 +2745,7 @@ var WorkflowDragService = class {
2747
2745
  triggerEvent,
2748
2746
  dragger
2749
2747
  });
2748
+ this.resetContainerInternalPosition(selectedNodes);
2750
2749
  }
2751
2750
  });
2752
2751
  const { clientX, clientY } = import_core15.MouseTouchEvent.getEventCoord(triggerEvent);
@@ -3017,12 +3016,48 @@ var WorkflowDragService = class {
3017
3016
  };
3018
3017
  }
3019
3018
  }
3019
+ /**
3020
+ * 容器内子节点总体位置重置为0
3021
+ */
3022
+ resetContainerInternalPosition(nodes) {
3023
+ const container = this.childrenOfContainer(nodes);
3024
+ if (!container) {
3025
+ return;
3026
+ }
3027
+ const bounds = import_utils16.Rectangle.enlarge(
3028
+ container.blocks.map((node) => {
3029
+ const x = node.transform.position.x - node.transform.bounds.width / 2;
3030
+ const y = node.transform.position.y;
3031
+ const width = node.transform.bounds.width;
3032
+ const height = node.transform.bounds.height;
3033
+ return new import_utils16.Rectangle(x, y, width, height);
3034
+ })
3035
+ );
3036
+ const containerTransform = container.getData(import_core15.TransformData);
3037
+ containerTransform.update({
3038
+ position: {
3039
+ x: containerTransform.position.x + bounds.x,
3040
+ y: containerTransform.position.y + bounds.y
3041
+ }
3042
+ });
3043
+ this.document.layout.updateAffectedTransform(container);
3044
+ container.blocks.forEach((node) => {
3045
+ const transform = node.getData(import_core15.TransformData);
3046
+ transform.update({
3047
+ position: {
3048
+ x: transform.position.x - bounds.x,
3049
+ y: transform.position.y - bounds.y
3050
+ }
3051
+ });
3052
+ this.document.layout.updateAffectedTransform(node);
3053
+ });
3054
+ }
3020
3055
  childrenOfContainer(nodes) {
3021
3056
  if (nodes.length === 0) {
3022
3057
  return;
3023
3058
  }
3024
3059
  const sourceContainer = nodes[0]?.parent;
3025
- if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
3060
+ if (!sourceContainer) {
3026
3061
  return;
3027
3062
  }
3028
3063
  const valid = nodes.every((node) => node?.parent === sourceContainer);
@@ -3223,7 +3258,7 @@ var WorkflowDragService = class {
3223
3258
  }
3224
3259
  /** 获取最近的 port */
3225
3260
  getNearestPort(node, mousePos) {
3226
- const portsData = node.getData(WorkflowNodePortsData);
3261
+ const portsData = node.ports;
3227
3262
  const distanceSortedPorts = portsData.inputPorts.sort((a, b) => {
3228
3263
  const aDistance = Math.abs(mousePos.y - a.point.y);
3229
3264
  const bDistance = Math.abs(mousePos.y - b.point.y);
@@ -3428,7 +3463,7 @@ var isFirefox = navigator?.userAgent?.includes?.("Firefox");
3428
3463
  function useNodeRender(nodeFromProps) {
3429
3464
  const node = nodeFromProps || (0, import_react2.useContext)(import_core21.PlaygroundEntityContext);
3430
3465
  const renderData = node.getData(import_document13.FlowNodeRenderData);
3431
- const portsData = node.getData(WorkflowNodePortsData);
3466
+ const portsData = node.ports;
3432
3467
  const readonly = usePlaygroundReadonlyState();
3433
3468
  const dragService = (0, import_core21.useService)(WorkflowDragService);
3434
3469
  const selectionService = (0, import_core21.useService)(WorkflowSelectService);
@@ -3653,11 +3688,35 @@ WorkflowDocumentContribution = __decorateClass([
3653
3688
 
3654
3689
  // src/utils/get-url-params.ts
3655
3690
  function getUrlParams() {
3656
- return location.search.replace(/^\?/, "").split("&").reduce((res, key) => {
3691
+ const paramsMap = /* @__PURE__ */ new Map();
3692
+ location.search.replace(/^\?/, "").split("&").forEach((key) => {
3693
+ if (!key) return;
3657
3694
  const [k, v] = key.split("=");
3658
- res[k] = v;
3659
- return res;
3660
- }, {});
3695
+ if (k) {
3696
+ const decodedKey = decodeURIComponent(k.trim());
3697
+ const decodedValue = v ? decodeURIComponent(v.trim()) : "";
3698
+ const dangerousProps = [
3699
+ "__proto__",
3700
+ "constructor",
3701
+ "prototype",
3702
+ "__defineGetter__",
3703
+ "__defineSetter__",
3704
+ "__lookupGetter__",
3705
+ "__lookupSetter__",
3706
+ "hasOwnProperty",
3707
+ "isPrototypeOf",
3708
+ "propertyIsEnumerable",
3709
+ "toString",
3710
+ "valueOf",
3711
+ "toLocaleString"
3712
+ ];
3713
+ if (dangerousProps.includes(decodedKey.toLowerCase())) {
3714
+ return;
3715
+ }
3716
+ paramsMap.set(decodedKey, decodedValue);
3717
+ }
3718
+ });
3719
+ return Object.fromEntries(paramsMap);
3661
3720
  }
3662
3721
 
3663
3722
  // src/workflow-document-container-module.ts