|
|
@ -1,8 +1,10 @@
|
|
|
|
import type { ElementsMap, ExcalidrawElement } from "./element/types";
|
|
|
|
import type { ElementsMap, ExcalidrawElement } from "./element/types";
|
|
|
|
import { newElementWith } from "./element/mutateElement";
|
|
|
|
import { mutateElement } from "./element/mutateElement";
|
|
|
|
import type { BoundingBox } from "./element/bounds";
|
|
|
|
import type { BoundingBox } from "./element/bounds";
|
|
|
|
import { getCommonBoundingBox } from "./element/bounds";
|
|
|
|
import { getCommonBoundingBox } from "./element/bounds";
|
|
|
|
import { getMaximumGroups } from "./groups";
|
|
|
|
import { getMaximumGroups } from "./groups";
|
|
|
|
|
|
|
|
import { updateBoundElements } from "./element/binding";
|
|
|
|
|
|
|
|
import type Scene from "./scene/Scene";
|
|
|
|
|
|
|
|
|
|
|
|
export interface Alignment {
|
|
|
|
export interface Alignment {
|
|
|
|
position: "start" | "center" | "end";
|
|
|
|
position: "start" | "center" | "end";
|
|
|
@ -13,6 +15,7 @@ export const alignElements = (
|
|
|
|
selectedElements: ExcalidrawElement[],
|
|
|
|
selectedElements: ExcalidrawElement[],
|
|
|
|
elementsMap: ElementsMap,
|
|
|
|
elementsMap: ElementsMap,
|
|
|
|
alignment: Alignment,
|
|
|
|
alignment: Alignment,
|
|
|
|
|
|
|
|
scene: Scene,
|
|
|
|
): ExcalidrawElement[] => {
|
|
|
|
): ExcalidrawElement[] => {
|
|
|
|
const groups: ExcalidrawElement[][] = getMaximumGroups(
|
|
|
|
const groups: ExcalidrawElement[][] = getMaximumGroups(
|
|
|
|
selectedElements,
|
|
|
|
selectedElements,
|
|
|
@ -26,12 +29,18 @@ export const alignElements = (
|
|
|
|
selectionBoundingBox,
|
|
|
|
selectionBoundingBox,
|
|
|
|
alignment,
|
|
|
|
alignment,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return group.map((element) =>
|
|
|
|
return group.map((element) => {
|
|
|
|
newElementWith(element, {
|
|
|
|
// update element
|
|
|
|
|
|
|
|
const updatedEle = mutateElement(element, {
|
|
|
|
x: element.x + translation.x,
|
|
|
|
x: element.x + translation.x,
|
|
|
|
y: element.y + translation.y,
|
|
|
|
y: element.y + translation.y,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
);
|
|
|
|
// update bound elements
|
|
|
|
|
|
|
|
updateBoundElements(element, scene.getNonDeletedElementsMap(), {
|
|
|
|
|
|
|
|
simultaneouslyUpdated: group,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return updatedEle;
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|