2021-05-19 09:35:00 +00:00
|
|
|
import Command from "./command"
|
|
|
|
import history from "../history"
|
|
|
|
import { Data, TransformCorner, TransformEdge } from "types"
|
|
|
|
import { getShapeUtils } from "lib/shapes"
|
|
|
|
import { TransformSingleSnapshot } from "state/sessions/transform-single-session"
|
|
|
|
|
|
|
|
export default function transformSingleCommand(
|
|
|
|
data: Data,
|
|
|
|
before: TransformSingleSnapshot,
|
|
|
|
after: TransformSingleSnapshot,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX: number,
|
|
|
|
scaleY: number
|
2021-05-19 09:35:00 +00:00
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-05-19 12:27:01 +00:00
|
|
|
name: "transform_single_shape",
|
2021-05-19 09:35:00 +00:00
|
|
|
category: "canvas",
|
|
|
|
do(data) {
|
2021-05-19 12:27:01 +00:00
|
|
|
const { id, currentPageId, type, initialShape, initialShapeBounds } =
|
|
|
|
after
|
2021-05-19 09:35:00 +00:00
|
|
|
|
2021-05-19 12:27:01 +00:00
|
|
|
const shape = data.document.pages[currentPageId].shapes[id]
|
2021-05-19 09:35:00 +00:00
|
|
|
|
2021-05-19 12:27:01 +00:00
|
|
|
getShapeUtils(shape).transformSingle(shape, initialShapeBounds, {
|
2021-05-19 09:35:00 +00:00
|
|
|
type,
|
|
|
|
initialShape,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX,
|
|
|
|
scaleY,
|
2021-05-19 09:35:00 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
undo(data) {
|
2021-05-19 12:27:01 +00:00
|
|
|
const { id, currentPageId, type, initialShape, initialShapeBounds } =
|
|
|
|
before
|
2021-05-19 09:35:00 +00:00
|
|
|
|
2021-05-19 12:27:01 +00:00
|
|
|
const shape = data.document.pages[currentPageId].shapes[id]
|
2021-05-19 09:35:00 +00:00
|
|
|
|
|
|
|
getShapeUtils(shape).transform(shape, initialShapeBounds, {
|
|
|
|
type,
|
2021-05-19 12:27:01 +00:00
|
|
|
initialShape: after.initialShape,
|
|
|
|
scaleX: 1,
|
|
|
|
scaleY: 1,
|
2021-05-19 09:35:00 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|