2021-05-29 12:40:41 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
|
|
|
import { TransformSnapshot } from 'state/sessions/transform-session'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
|
|
|
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-29 12:40:41 +00:00
|
|
|
after: TransformSnapshot
|
2021-05-14 21:05:21 +00:00
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-05-29 12:40:41 +00:00
|
|
|
name: 'translate_shapes',
|
|
|
|
category: 'canvas',
|
2021-05-14 21:05:21 +00:00
|
|
|
do(data) {
|
2021-05-29 12:40:41 +00:00
|
|
|
const { type, shapeBounds } = after
|
2021-05-22 15:45:24 +00:00
|
|
|
|
|
|
|
const { shapes } = getPage(data)
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-05-29 12:40:41 +00:00
|
|
|
for (let id in shapeBounds) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { initialShape, initialShapeBounds, transformOrigin } =
|
2021-05-29 12:40:41 +00:00
|
|
|
shapeBounds[id]
|
2021-05-22 15:45:24 +00:00
|
|
|
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-29 12:40:41 +00:00
|
|
|
transformOrigin,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX: 1,
|
|
|
|
scaleY: 1,
|
2021-05-15 13:02:13 +00:00
|
|
|
})
|
2021-05-29 12:40:41 +00:00
|
|
|
}
|
2021-05-14 21:05:21 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-05-29 12:40:41 +00:00
|
|
|
const { type, shapeBounds } = before
|
2021-05-22 15:45:24 +00:00
|
|
|
|
|
|
|
const { shapes } = getPage(data)
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-05-29 12:40:41 +00:00
|
|
|
for (let id in shapeBounds) {
|
2021-05-22 15:45:24 +00:00
|
|
|
const { initialShape, initialShapeBounds, transformOrigin } =
|
2021-05-29 12:40:41 +00:00
|
|
|
shapeBounds[id]
|
2021-05-22 15:45:24 +00:00
|
|
|
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-29 12:40:41 +00:00
|
|
|
transformOrigin,
|
2021-05-19 12:27:01 +00:00
|
|
|
scaleX: 1,
|
|
|
|
scaleY: 1,
|
2021-05-15 13:02:13 +00:00
|
|
|
})
|
2021-05-29 12:40:41 +00:00
|
|
|
}
|
2021-05-14 21:05:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|