Merge branch 'master' into mrazator/separate-element-into-standalone-package

This commit is contained in:
Marcel Mraz 2025-03-21 11:58:33 +01:00
commit ffa8da2aa7
6 changed files with 149 additions and 117 deletions

View file

@ -13,6 +13,8 @@ import type {
import type Scene from "@excalidraw/excalidraw/scene/Scene";
import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types";
import { updateBoundElements } from "./binding";
import { getCommonBounds } from "./bounds";
import { mutateElement } from "./mutateElement";
@ -28,7 +30,7 @@ import {
} from "./typeChecks";
import type { Bounds } from "./bounds";
import type { NonDeletedExcalidrawElement } from "./types";
import type { ExcalidrawElement } from "./types";
export const dragSelectedElements = (
pointerDownState: PointerDownState,
@ -82,13 +84,20 @@ export const dragSelectedElements = (
}
}
const commonBounds = getCommonBounds(
Array.from(elementsToUpdate).map(
(el) => pointerDownState.originalElements.get(el.id) ?? el,
),
);
const origElements: ExcalidrawElement[] = [];
for (const element of elementsToUpdate) {
const origElement = pointerDownState.originalElements.get(element.id);
// if original element is not set (e.g. when you duplicate during a drag
// operation), exit to avoid undefined behavior
if (!origElement) {
return;
}
origElements.push(origElement);
}
const adjustedOffset = calculateOffset(
commonBounds,
getCommonBounds(origElements),
offset,
snapOffset,
gridSize,