2021-06-15 11:58:51 +00:00
|
|
|
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-15 11:58:51 +00:00
|
|
|
import { EditSnapshot } from 'state/sessions/edit-session'
|
2021-06-21 21:35:28 +00:00
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
2021-06-15 11:58:51 +00:00
|
|
|
|
2021-06-19 17:22:46 +00:00
|
|
|
export default function editCommand(
|
2021-06-15 11:58:51 +00:00
|
|
|
data: Data,
|
|
|
|
before: EditSnapshot,
|
|
|
|
after: EditSnapshot
|
2021-06-21 21:35:28 +00:00
|
|
|
): void {
|
2021-06-15 11:58:51 +00:00
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-06-19 17:22:46 +00:00
|
|
|
name: 'edit_shape',
|
2021-06-15 11:58:51 +00:00
|
|
|
category: 'canvas',
|
2021-06-18 15:31:46 +00:00
|
|
|
do(data) {
|
2021-06-24 12:34:43 +00:00
|
|
|
const { initialShape } = after
|
2021-06-15 11:58:51 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
const page = tld.getPage(data)
|
2021-06-15 11:58:51 +00:00
|
|
|
|
|
|
|
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) {
|
2021-06-24 12:34:43 +00:00
|
|
|
const { initialShape } = before
|
2021-06-15 11:58:51 +00:00
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
const page = tld.getPage(data)
|
2021-06-15 11:58:51 +00:00
|
|
|
|
|
|
|
page.shapes[initialShape.id] = initialShape
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|