| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import Command from "./command"
- import history from "../history"
- import { Data, TransformCorner, TransformEdge } from "types"
- import { TransformSnapshot } from "state/sessions/transform-session"
- import { getShapeUtils } from "lib/shapes"
-
- export default function translateCommand(
- data: Data,
- before: TransformSnapshot,
- after: TransformSnapshot,
- anchor: TransformCorner | TransformEdge
- ) {
- history.execute(
- data,
- new Command({
- name: "translate_shapes",
- category: "canvas",
- do(data) {
- const {
- type,
- shapeBounds,
- initialBounds,
- currentPageId,
- selectedIds,
- } = after
-
- const { shapes } = data.document.pages[currentPageId]
-
- selectedIds.forEach((id) => {
- const { initialShape, initialShapeBounds } = shapeBounds[id]
- const shape = shapes[id]
-
- getShapeUtils(shape).transform(shape, initialShapeBounds, {
- type,
- initialShape,
- initialShapeBounds,
- initialBounds,
- isFlippedX: false,
- isFlippedY: false,
- anchor,
- })
- })
- },
- undo(data) {
- const {
- type,
- shapeBounds,
- initialBounds,
- currentPageId,
- selectedIds,
- } = before
-
- const { shapes } = data.document.pages[currentPageId]
-
- selectedIds.forEach((id) => {
- const { initialShape, initialShapeBounds } = shapeBounds[id]
- const shape = shapes[id]
-
- getShapeUtils(shape).transform(shape, initialShapeBounds, {
- type,
- initialShape,
- initialShapeBounds,
- initialBounds,
- isFlippedX: false,
- isFlippedY: false,
- anchor: type,
- })
- })
- },
- })
- )
- }
|