2021-05-17 21:27:18 +00:00
|
|
|
import Command from "./command"
|
|
|
|
import history from "../history"
|
|
|
|
import { Data } from "types"
|
|
|
|
import { RotateSnapshot } from "state/sessions/rotate-session"
|
2021-05-22 15:45:24 +00:00
|
|
|
import { getPage } from "utils/utils"
|
2021-05-25 09:00:59 +00:00
|
|
|
import { getShapeUtils } from "lib/shape-utils"
|
2021-05-17 21:27:18 +00:00
|
|
|
|
2021-05-19 09:35:00 +00:00
|
|
|
export default function rotateCommand(
|
2021-05-17 21:27:18 +00:00
|
|
|
data: Data,
|
|
|
|
before: RotateSnapshot,
|
|
|
|
after: RotateSnapshot
|
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: "translate_shapes",
|
|
|
|
category: "canvas",
|
|
|
|
do(data) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { shapes } = getPage(data)
|
2021-05-17 21:27:18 +00:00
|
|
|
|
2021-05-18 08:32:20 +00:00
|
|
|
for (let { id, point, rotation } of after.shapes) {
|
|
|
|
const shape = shapes[id]
|
2021-05-25 09:00:59 +00:00
|
|
|
const utils = getShapeUtils(shape)
|
2021-05-25 11:38:21 +00:00
|
|
|
utils.rotateTo(shape, rotation).translateTo(shape, point)
|
2021-05-17 21:27:18 +00:00
|
|
|
}
|
2021-05-18 08:32:20 +00:00
|
|
|
|
|
|
|
data.boundsRotation = after.boundsRotation
|
2021-05-17 21:27:18 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { shapes } = getPage(data, before.currentPageId)
|
2021-05-17 21:27:18 +00:00
|
|
|
|
2021-05-18 08:32:20 +00:00
|
|
|
for (let { id, point, rotation } of before.shapes) {
|
|
|
|
const shape = shapes[id]
|
2021-05-25 09:00:59 +00:00
|
|
|
const utils = getShapeUtils(shape)
|
2021-05-25 11:38:21 +00:00
|
|
|
utils.rotateTo(shape, rotation).translateTo(shape, point)
|
2021-05-17 21:27:18 +00:00
|
|
|
}
|
2021-05-18 08:32:20 +00:00
|
|
|
|
|
|
|
data.boundsRotation = before.boundsRotation
|
2021-05-17 21:27:18 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|