2021-06-15 11:58:51 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
|
|
|
import { getPage, getShape } from 'utils/utils'
|
|
|
|
import { EditSnapshot } from 'state/sessions/edit-session'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
|
|
|
|
|
|
|
export default function handleCommand(
|
|
|
|
data: Data,
|
|
|
|
before: EditSnapshot,
|
|
|
|
after: EditSnapshot
|
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'edited_shape',
|
|
|
|
category: 'canvas',
|
2021-06-18 15:31:46 +00:00
|
|
|
do(data) {
|
2021-06-15 11:58:51 +00:00
|
|
|
const { initialShape, currentPageId } = after
|
|
|
|
|
|
|
|
const page = getPage(data, currentPageId)
|
|
|
|
|
|
|
|
page.shapes[initialShape.id] = initialShape
|
|
|
|
|
|
|
|
const shape = page.shapes[initialShape.id]
|
|
|
|
|
2021-06-17 10:43:55 +00:00
|
|
|
if (getShapeUtils(shape).shouldDelete(shape)) {
|
2021-06-15 11:58:51 +00:00
|
|
|
delete page.shapes[initialShape.id]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
const { initialShape, currentPageId } = before
|
|
|
|
|
|
|
|
const page = getPage(data, currentPageId)
|
|
|
|
|
|
|
|
page.shapes[initialShape.id] = initialShape
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|