2021-06-15 11:58:51 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
2021-06-18 09:32:07 +00:00
|
|
|
import { getPage, getSelectedShapes, updateParents } from 'utils/utils'
|
2021-06-15 11:58:51 +00:00
|
|
|
import { current } from 'immer'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
|
|
|
|
|
|
|
export default function resetBoundsCommand(data: Data) {
|
|
|
|
const initialShapes = Object.fromEntries(
|
|
|
|
getSelectedShapes(current(data)).map((shape) => [shape.id, shape])
|
|
|
|
)
|
|
|
|
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'reset_bounds',
|
|
|
|
category: 'canvas',
|
|
|
|
do(data) {
|
|
|
|
getSelectedShapes(data).forEach((shape) => {
|
2021-06-18 15:31:46 +00:00
|
|
|
if (shape.isLocked) return
|
2021-06-15 11:58:51 +00:00
|
|
|
getShapeUtils(shape).onBoundsReset(shape)
|
|
|
|
})
|
2021-06-18 09:32:07 +00:00
|
|
|
|
|
|
|
updateParents(data, Object.keys(initialShapes))
|
2021-06-15 11:58:51 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
const page = getPage(data)
|
|
|
|
getSelectedShapes(data).forEach((shape) => {
|
2021-06-18 15:31:46 +00:00
|
|
|
if (shape.isLocked) return
|
2021-06-15 11:58:51 +00:00
|
|
|
page.shapes[shape.id] = initialShapes[shape.id]
|
|
|
|
})
|
2021-06-18 09:32:07 +00:00
|
|
|
|
|
|
|
updateParents(data, Object.keys(initialShapes))
|
2021-06-15 11:58:51 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|