2021-05-14 21:05:21 +00:00
|
|
|
import Command from "./command"
|
|
|
|
import history from "../history"
|
2021-05-22 15:45:24 +00:00
|
|
|
import { Data, Corner, Edge } 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-22 15:45:24 +00:00
|
|
|
import { getPage } from "utils/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-22 15:45:24 +00:00
|
|
|
const { type, selectedIds } = after
|
|
|
|
|
|
|
|
const { shapes } = getPage(data)
|
2021-05-14 21:05:21 +00:00
|
|
|
|
|
|
|
selectedIds.forEach((id) => {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { initialShape, initialShapeBounds, transformOrigin } =
|
|
|
|
after.shapeBounds[id]
|
|
|
|
const shape = 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-22 15:45:24 +00:00
|
|
|
transformOrigin,
|
2021-05-15 13:02:13 +00:00
|
|
|
})
|
2021-05-14 21:05:21 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
undo(data) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { type, selectedIds } = before
|
|
|
|
|
|
|
|
const { shapes } = getPage(data)
|
2021-05-14 21:05:21 +00:00
|
|
|
|
|
|
|
selectedIds.forEach((id) => {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { initialShape, initialShapeBounds, transformOrigin } =
|
|
|
|
before.shapeBounds[id]
|
|
|
|
const shape = 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-22 15:45:24 +00:00
|
|
|
transformOrigin,
|
2021-05-15 13:02:13 +00:00
|
|
|
})
|
2021-05-14 21:05:21 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|