tldraw/state/commands/transform.ts
2021-06-24 09:18:14 +01:00

40 lines
981 B
TypeScript

import Command from './command'
import history from '../history'
import { Data } from 'types'
import { TransformSnapshot } from 'state/sessions/transform-session'
import { getPage, updateParents } from 'utils'
export default function transformCommand(
data: Data,
before: TransformSnapshot,
after: TransformSnapshot
): void {
history.execute(
data,
new Command({
name: 'transform_shapes',
category: 'canvas',
do(data) {
const { shapeBounds } = after
const { shapes } = getPage(data)
for (const id in shapeBounds) {
shapes[id] = shapeBounds[id].initialShape
}
updateParents(data, Object.keys(shapeBounds))
},
undo(data) {
const { shapeBounds } = before
const { shapes } = getPage(data)
for (const id in shapeBounds) {
shapes[id] = shapeBounds[id].initialShape
}
updateParents(data, Object.keys(shapeBounds))
},
})
)
}