tldraw/state/commands/edit.ts

41 lines
997 B
TypeScript
Raw Normal View History

import Command from './command'
import history from '../history'
import { Data } from 'types'
2021-06-19 17:22:46 +00:00
import { getPage } from 'utils/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) {
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)) {
delete page.shapes[initialShape.id]
}
},
undo(data) {
const { initialShape, currentPageId } = before
const page = getPage(data, currentPageId)
page.shapes[initialShape.id] = initialShape
},
})
)
}