Fix node dragging while zooming on a flow that does not occupy whole browser window.

This commit is contained in:
peterkogo
2024-11-07 12:42:17 +01:00
parent c8ccca3434
commit ae7a3478aa
2 changed files with 10 additions and 6 deletions
+6 -2
View File
@@ -5,14 +5,18 @@ export type GetPointerPositionParams = {
transform: Transform;
snapGrid?: SnapGrid;
snapToGrid?: boolean;
containerBounds: DOMRect | null;
};
export function getPointerPosition(
event: MouseEvent | TouchEvent,
{ snapGrid = [0, 0], snapToGrid = false, transform }: GetPointerPositionParams
{ snapGrid = [0, 0], snapToGrid = false, transform, containerBounds }: GetPointerPositionParams
): XYPosition & { xSnapped: number; ySnapped: number } {
const { x, y } = getEventPosition(event);
const pointerPos = pointToRendererPoint({ x, y }, transform);
const pointerPos = pointToRendererPoint(
{ x: x - (containerBounds?.left ?? 0), y: y - (containerBounds?.top ?? 0) },
transform
);
const { x: xSnapped, y: ySnapped } = snapToGrid ? snapPosition(pointerPos, snapGrid) : pointerPos;
// we need the snapped position in order to be able to skip unnecessary drag events