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"
|
2021-05-20 09:49:40 +00:00
|
|
|
import { getShapeUtils } from "lib/shape-utils"
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-05-19 09:35:00 +00:00
|
|
|
export default function transformCommand(
|
2021-05-14 21:05:21 +00:00
|
|
|
data: Data,
|
|
|
|
before: TransformSnapshot,
|
2021-05-15 13:02:13 +00:00
|
|
|
after: TransformSnapshot,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX: number,
|
|
|
|
scaleY: number
|
2021-05-14 21:05:21 +00:00
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: "translate_shapes",
|
|
|
|
category: "canvas",
|
|
|
|
do(data) {
|
2021-05-19 12:27:01 +00:00
|
|
|
const { type, currentPageId, selectedIds } = after
|
2021-05-14 21:05:21 +00:00
|
|
|
|
|
|
|
selectedIds.forEach((id) => {
|
2021-05-19 12:27:01 +00:00
|
|
|
const { initialShape, initialShapeBounds } = after.shapeBounds[id]
|
|
|
|
const shape = data.document.pages[currentPageId].shapes[id]
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-05-15 13:02:13 +00:00
|
|
|
getShapeUtils(shape).transform(shape, initialShapeBounds, {
|
|
|
|
type,
|
2021-05-14 21:05:21 +00:00
|
|
|
initialShape,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX: 1,
|
|
|
|
scaleY: 1,
|
2021-05-15 13:02:13 +00:00
|
|
|
})
|
2021-05-14 21:05:21 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
undo(data) {
|
2021-05-19 12:27:01 +00:00
|
|
|
const { type, currentPageId, selectedIds } = before
|
2021-05-14 21:05:21 +00:00
|
|
|
|
|
|
|
selectedIds.forEach((id) => {
|
2021-05-19 12:27:01 +00:00
|
|
|
const { initialShape, initialShapeBounds } = before.shapeBounds[id]
|
|
|
|
const shape = data.document.pages[currentPageId].shapes[id]
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-05-15 13:02:13 +00:00
|
|
|
getShapeUtils(shape).transform(shape, initialShapeBounds, {
|
|
|
|
type,
|
2021-05-14 21:05:21 +00:00
|
|
|
initialShape,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX: 1,
|
|
|
|
scaleY: 1,
|
2021-05-15 13:02:13 +00:00
|
|
|
})
|
2021-05-14 21:05:21 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|