@bian-womp/spark-workbench 0.3.21 → 0.3.23

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/lib/cjs/index.cjs CHANGED
@@ -5796,9 +5796,31 @@ function useKeyboardShortcutToast() {
5796
5796
  }
5797
5797
 
5798
5798
  const SelectionBoundOverlay = ({ selection, rfInstance, viewportTick }) => {
5799
+ const overlayRef = React.useRef(null);
5800
+ const [parentRect, setParentRect] = React.useState(null);
5801
+ React.useEffect(() => {
5802
+ if (!overlayRef.current)
5803
+ return;
5804
+ const parent = overlayRef.current.parentElement;
5805
+ if (!parent)
5806
+ return;
5807
+ const updateRect = () => {
5808
+ setParentRect(parent.getBoundingClientRect());
5809
+ };
5810
+ updateRect();
5811
+ const resizeObserver = new ResizeObserver(updateRect);
5812
+ resizeObserver.observe(parent);
5813
+ const scrollHandler = () => updateRect();
5814
+ window.addEventListener("scroll", scrollHandler, true);
5815
+ return () => {
5816
+ resizeObserver.disconnect();
5817
+ window.removeEventListener("scroll", scrollHandler, true);
5818
+ };
5819
+ }, [viewportTick]);
5799
5820
  const selectionBounds = React.useMemo(() => {
5800
5821
  if (typeof document === "undefined" ||
5801
5822
  !rfInstance ||
5823
+ !parentRect ||
5802
5824
  selection.nodes.length < 2) {
5803
5825
  return null;
5804
5826
  }
@@ -5808,31 +5830,35 @@ const SelectionBoundOverlay = ({ selection, rfInstance, viewportTick }) => {
5808
5830
  if (!el)
5809
5831
  continue;
5810
5832
  const rect = el.getBoundingClientRect();
5833
+ const relativeLeft = rect.left - parentRect.left;
5834
+ const relativeTop = rect.top - parentRect.top;
5835
+ const relativeRight = rect.right - parentRect.left;
5836
+ const relativeBottom = rect.bottom - parentRect.top;
5811
5837
  if (!bounds) {
5812
5838
  bounds = {
5813
- left: rect.left,
5814
- top: rect.top,
5815
- right: rect.right,
5816
- bottom: rect.bottom,
5839
+ left: relativeLeft,
5840
+ top: relativeTop,
5841
+ right: relativeRight,
5842
+ bottom: relativeBottom,
5817
5843
  };
5818
5844
  }
5819
5845
  else {
5820
- bounds.left = Math.min(bounds.left, rect.left);
5821
- bounds.top = Math.min(bounds.top, rect.top);
5822
- bounds.right = Math.max(bounds.right, rect.right);
5823
- bounds.bottom = Math.max(bounds.bottom, rect.bottom);
5846
+ bounds.left = Math.min(bounds.left, relativeLeft);
5847
+ bounds.top = Math.min(bounds.top, relativeTop);
5848
+ bounds.right = Math.max(bounds.right, relativeRight);
5849
+ bounds.bottom = Math.max(bounds.bottom, relativeBottom);
5824
5850
  }
5825
5851
  }
5826
5852
  return bounds;
5827
- }, [selection.nodes, rfInstance, viewportTick]);
5853
+ }, [selection.nodes, rfInstance, viewportTick, parentRect]);
5828
5854
  if (!selectionBounds || selection.nodes.length < 2) {
5829
- return null;
5855
+ return jsxRuntime.jsx("div", { ref: overlayRef, style: { display: "none" } });
5830
5856
  }
5831
5857
  const { left, top, right, bottom } = selectionBounds;
5832
5858
  const width = right - left;
5833
5859
  const height = bottom - top;
5834
- return (jsxRuntime.jsx("div", { style: {
5835
- position: "fixed",
5860
+ return (jsxRuntime.jsx("div", { ref: overlayRef, style: {
5861
+ position: "absolute",
5836
5862
  left: `${left}px`,
5837
5863
  top: `${top}px`,
5838
5864
  width: `${width}px`,
@@ -6495,7 +6521,7 @@ const WorkbenchCanvasComponent = React.forwardRef((props, ref) => {
6495
6521
  return () => off();
6496
6522
  }, [wb]);
6497
6523
  const { onInit: userOnInit, ...restReactFlowProps } = reactFlowProps || {};
6498
- return (jsxRuntime.jsxs("div", { className: "w-full h-full", onContextMenu: onContextMenu, children: [jsxRuntime.jsxs(react.ReactFlowProvider, { children: [jsxRuntime.jsxs(react.ReactFlow, { ...restReactFlowProps, nodes: throttled.nodes, edges: throttled.edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, connectionLineComponent: connectionLineRenderer, selectionOnDrag: true, onInit: (inst) => {
6524
+ return (jsxRuntime.jsxs("div", { className: "w-full h-full relative overflow-hidden", onContextMenu: onContextMenu, children: [jsxRuntime.jsxs(react.ReactFlowProvider, { children: [jsxRuntime.jsxs(react.ReactFlow, { ...restReactFlowProps, nodes: throttled.nodes, edges: throttled.edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, connectionLineComponent: connectionLineRenderer, selectionOnDrag: true, onInit: (inst) => {
6499
6525
  rfInstanceRef.current = inst;
6500
6526
  const savedViewport = wb.getViewport();
6501
6527
  if (savedViewport) {