tldraw/state/commands/edit.ts

41 lines
935 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'
import { EditSnapshot } from 'state/sessions/edit-session'
2021-06-21 21:35:28 +00:00
import { getShapeUtils } from 'state/shape-utils'
2021-06-19 17:22:46 +00:00
export default function editCommand(
data: Data,
before: EditSnapshot,
after: EditSnapshot
2021-06-21 21:35:28 +00:00
): void {
history.execute(
data,
new Command({
2021-06-19 17:22:46 +00:00
name: 'edit_shape',
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-29 12:00:59 +00:00
const page = tld.getPage(data)
page.shapes[initialShape.id] = initialShape
const shape = page.shapes[initialShape.id]
2021-06-17 10:43:55 +00:00
if (getShapeUtils(shape).shouldDelete(shape)) {
delete page.shapes[initialShape.id]
}
},
undo(data) {
2021-06-24 12:34:43 +00:00
const { initialShape } = before
2021-06-29 12:00:59 +00:00
const page = tld.getPage(data)
page.shapes[initialShape.id] = initialShape
},
})
)
}