tldraw/state/commands/draw.ts
2021-06-24 13:34:43 +01:00

28 lines
712 B
TypeScript

import Command from './command'
import history from '../history'
import { Data, DrawShape } from 'types'
import { deepClone, getPage, getShape, setSelectedIds } from 'utils'
export default function drawCommand(data: Data, id: string): void {
const restoreShape = deepClone(getShape(data, id)) as DrawShape
history.execute(
data,
new Command({
name: 'create_draw_shape',
category: 'canvas',
manualSelection: true,
do(data, initial) {
if (!initial) {
getPage(data).shapes[id] = restoreShape
}
setSelectedIds(data, [])
},
undo(data) {
setSelectedIds(data, [])
delete getPage(data).shapes[id]
},
})
)
}