tldraw/state/commands/reset-bounds.ts

31 lines
719 B
TypeScript
Raw Normal View History

import Command from './command'
import history from '../history'
import { Data } from 'types'
2021-06-29 12:00:59 +00:00
import tld from 'utils/tld'
2021-06-21 21:35:28 +00:00
export default function resetBoundsCommand(data: Data): void {
2021-06-29 12:00:59 +00:00
const initialShapes = tld.getSelectedShapeSnapshot(data)
history.execute(
data,
new Command({
name: 'reset_bounds',
category: 'canvas',
do(data) {
2021-06-29 12:00:59 +00:00
tld.mutateShapes(
data,
initialShapes.map((shape) => shape.id),
(shape, utils) => void utils.onBoundsReset(shape)
)
},
undo(data) {
2021-06-29 12:00:59 +00:00
tld.mutateShapes(
data,
initialShapes.map((shape) => shape.id),
(_, __, i) => initialShapes[i]
)
},
})
)
}