tldraw/state/commands/edit.ts

41 lines
931 B
TypeScript
Raw Normal View History

import Command from './command'
import history from '../history'
import { Data } from 'types'
2021-06-24 08:18:14 +00:00
import { getPage } from 'utils'
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-24 12:34:43 +00:00
const page = 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-24 12:34:43 +00:00
const page = getPage(data)
page.shapes[initialShape.id] = initialShape
},
})
)
}