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