@flowgram.ai/free-layout-core 0.1.0-alpha.15 → 0.1.0-alpha.16

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
@@ -43,8 +43,7 @@ import {
43
43
  useEntities,
44
44
  useEntityFromContext as useEntityFromContext3,
45
45
  useEntityDataFromContext,
46
- useRefresh as useRefresh2,
47
- usePlaygroundLatest
46
+ useRefresh as useRefresh2
48
47
  } from "@flowgram.ai/core";
49
48
 
50
49
  // src/hooks/use-node-render.tsx
@@ -777,11 +776,11 @@ var WorkflowLineRenderData = class extends EntityData3 {
777
776
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
778
777
  */
779
778
  updatePosition() {
780
- 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);
781
780
  if (this.entity.info.drawingTo) {
782
781
  this.data.position.to = this.entity.info.drawingTo;
783
782
  } else {
784
- 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) ?? {
785
784
  x: this.data.position.from.x,
786
785
  y: this.data.position.from.y,
787
786
  location: this.data.position.from.location === "right" ? "left" : "top"
@@ -1043,13 +1042,13 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
1043
1042
  return this.getData(WorkflowLineRenderData).calcDistance(pos);
1044
1043
  }
1045
1044
  get fromPort() {
1046
- return this.from.getData(WorkflowNodePortsData).getPortEntityByKey("output", this.info.fromPort);
1045
+ return this.from.ports.getPortEntityByKey("output", this.info.fromPort);
1047
1046
  }
1048
1047
  get toPort() {
1049
1048
  if (!this.to) {
1050
1049
  return void 0;
1051
1050
  }
1052
- return this.to.getData(WorkflowNodePortsData).getPortEntityByKey("input", this.info.toPort);
1051
+ return this.to.ports.getPortEntityByKey("input", this.info.toPort);
1053
1052
  }
1054
1053
  /**
1055
1054
  * 获取线条真实的输入输出节点坐标
@@ -1727,7 +1726,7 @@ var WorkflowLinesManager = class {
1727
1726
  */
1728
1727
  getPortFromMousePos(pos) {
1729
1728
  const allNodes = this.getSortedNodes().reverse();
1730
- const allPorts = allNodes.map((node) => node.getData(WorkflowNodePortsData).allPorts).flat();
1729
+ const allPorts = allNodes.map((node) => node.ports.allPorts).flat();
1731
1730
  const targetPort = allPorts.find((port) => port.isHovered(pos.x, pos.y));
1732
1731
  if (targetPort) {
1733
1732
  const containNodes = this.getContainNodesFromMousePos(pos);
@@ -2182,8 +2181,11 @@ var WorkflowDocument = class extends FlowDocument {
2182
2181
  originParent,
2183
2182
  meta
2184
2183
  });
2184
+ this.options.preNodeCreate?.(node);
2185
2185
  const datas = dataRegistries ? this.nodeDataRegistries.concat(...dataRegistries) : this.nodeDataRegistries;
2186
2186
  node.addInitializeData(datas);
2187
+ node.ports = node.getData(WorkflowNodePortsData);
2188
+ node.lines = node.getData(WorkflowNodeLinesData);
2187
2189
  node.onDispose(() => this.onNodeDisposeEmitter.fire({ node }));
2188
2190
  this.options.fromNodeJSON?.(node, data, true);
2189
2191
  isNew = true;
@@ -2634,10 +2636,6 @@ var WorkflowDragService = class {
2634
2636
  return Promise.resolve(false);
2635
2637
  }
2636
2638
  this.isDragging = true;
2637
- const sameParent = this.childrenOfContainer(selectedNodes);
2638
- if (sameParent && sameParent.flowNodeType !== FlowNodeBaseType3.ROOT) {
2639
- selectedNodes = [sameParent];
2640
- }
2641
2639
  let startPosition = this.getNodesPosition(selectedNodes);
2642
2640
  let startPositions = selectedNodes.map((node) => {
2643
2641
  const transform = node.getData(TransformData8);
@@ -2699,6 +2697,7 @@ var WorkflowDragService = class {
2699
2697
  triggerEvent,
2700
2698
  dragger
2701
2699
  });
2700
+ this.resetContainerInternalPosition(selectedNodes);
2702
2701
  }
2703
2702
  });
2704
2703
  const { clientX, clientY } = MouseTouchEvent.getEventCoord(triggerEvent);
@@ -2739,7 +2738,7 @@ var WorkflowDragService = class {
2739
2738
  const targetNode = event.currentTarget;
2740
2739
  domNode = cloneNode ? cloneNode(e) : targetNode.cloneNode(true);
2741
2740
  const bounds = targetNode.getBoundingClientRect();
2742
- startPos = { x: bounds.left, y: bounds.top };
2741
+ startPos = { x: bounds.left + window.scrollX, y: bounds.top + window.scrollY };
2743
2742
  domUtils2.setStyle(domNode, {
2744
2743
  zIndex: 1e3,
2745
2744
  position: "absolute",
@@ -2969,12 +2968,48 @@ var WorkflowDragService = class {
2969
2968
  };
2970
2969
  }
2971
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
+ }
2972
3007
  childrenOfContainer(nodes) {
2973
3008
  if (nodes.length === 0) {
2974
3009
  return;
2975
3010
  }
2976
3011
  const sourceContainer = nodes[0]?.parent;
2977
- if (!sourceContainer || sourceContainer.collapsedChildren.length !== nodes.length) {
3012
+ if (!sourceContainer) {
2978
3013
  return;
2979
3014
  }
2980
3015
  const valid = nodes.every((node) => node?.parent === sourceContainer);
@@ -3175,7 +3210,7 @@ var WorkflowDragService = class {
3175
3210
  }
3176
3211
  /** 获取最近的 port */
3177
3212
  getNearestPort(node, mousePos) {
3178
- const portsData = node.getData(WorkflowNodePortsData);
3213
+ const portsData = node.ports;
3179
3214
  const distanceSortedPorts = portsData.inputPorts.sort((a, b) => {
3180
3215
  const aDistance = Math.abs(mousePos.y - a.point.y);
3181
3216
  const bDistance = Math.abs(mousePos.y - b.point.y);
@@ -3380,7 +3415,7 @@ var isFirefox = navigator?.userAgent?.includes?.("Firefox");
3380
3415
  function useNodeRender(nodeFromProps) {
3381
3416
  const node = nodeFromProps || useContext(PlaygroundEntityContext);
3382
3417
  const renderData = node.getData(FlowNodeRenderData3);
3383
- const portsData = node.getData(WorkflowNodePortsData);
3418
+ const portsData = node.ports;
3384
3419
  const readonly = usePlaygroundReadonlyState();
3385
3420
  const dragService = useService(WorkflowDragService);
3386
3421
  const selectionService = useService(WorkflowSelectService);
@@ -3608,11 +3643,35 @@ WorkflowDocumentContribution = __decorateClass([
3608
3643
 
3609
3644
  // src/utils/get-url-params.ts
3610
3645
  function getUrlParams() {
3611
- return location.search.replace(/^\?/, "").split("&").reduce((res, key) => {
3646
+ const paramsMap = /* @__PURE__ */ new Map();
3647
+ location.search.replace(/^\?/, "").split("&").forEach((key) => {
3648
+ if (!key) return;
3612
3649
  const [k, v] = key.split("=");
3613
- res[k] = v;
3614
- return res;
3615
- }, {});
3650
+ if (k) {
3651
+ const decodedKey = decodeURIComponent(k.trim());
3652
+ const decodedValue = v ? decodeURIComponent(v.trim()) : "";
3653
+ const dangerousProps = [
3654
+ "__proto__",
3655
+ "constructor",
3656
+ "prototype",
3657
+ "__defineGetter__",
3658
+ "__defineSetter__",
3659
+ "__lookupGetter__",
3660
+ "__lookupSetter__",
3661
+ "hasOwnProperty",
3662
+ "isPrototypeOf",
3663
+ "propertyIsEnumerable",
3664
+ "toString",
3665
+ "valueOf",
3666
+ "toLocaleString"
3667
+ ];
3668
+ if (dangerousProps.includes(decodedKey.toLowerCase())) {
3669
+ return;
3670
+ }
3671
+ paramsMap.set(decodedKey, decodedValue);
3672
+ }
3673
+ });
3674
+ return Object.fromEntries(paramsMap);
3616
3675
  }
3617
3676
 
3618
3677
  // src/workflow-document-container-module.ts
@@ -3687,7 +3746,6 @@ export {
3687
3746
  usePlayground2 as usePlayground,
3688
3747
  usePlaygroundContainer,
3689
3748
  usePlaygroundContext,
3690
- usePlaygroundLatest,
3691
3749
  usePlaygroundReadonlyState,
3692
3750
  useRefresh2 as useRefresh,
3693
3751
  useService3 as useService,