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'
|
2021-06-29 12:00:59 +00:00
|
|
|
import tld from 'utils/tld'
|
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-06-21 21:35:28 +00:00
|
|
|
after: TransformSnapshot
|
|
|
|
): void {
|
2021-05-14 21:05:21 +00:00
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-06-17 10:43:55 +00:00
|
|
|
name: 'transform_shapes',
|
2021-05-29 12:40:41 +00:00
|
|
|
category: 'canvas',
|
2021-06-17 10:43:55 +00:00
|
|
|
do(data) {
|
2021-06-21 13:13:16 +00:00
|
|
|
const { shapeBounds } = after
|
2021-05-22 15:45:24 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
const { shapes } = tld.getPage(data)
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
for (const id in shapeBounds) {
|
2021-06-21 13:13:16 +00:00
|
|
|
shapes[id] = shapeBounds[id].initialShape
|
2021-05-29 12:40:41 +00:00
|
|
|
}
|
2021-06-04 16:08:43 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
tld.updateParents(data, Object.keys(shapeBounds))
|
2021-05-14 21:05:21 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-17 10:43:55 +00:00
|
|
|
const { shapeBounds } = before
|
2021-06-29 12:00:59 +00:00
|
|
|
const { shapes } = tld.getPage(data)
|
2021-05-14 21:05:21 +00:00
|
|
|
|
2021-06-21 21:35:28 +00:00
|
|
|
for (const id in shapeBounds) {
|
2021-06-17 10:43:55 +00:00
|
|
|
shapes[id] = shapeBounds[id].initialShape
|
2021-05-29 12:40:41 +00:00
|
|
|
}
|
2021-06-04 16:08:43 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
tld.updateParents(data, Object.keys(shapeBounds))
|
2021-05-14 21:05:21 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|