tldraw/state/commands/draw.ts

29 lines
712 B
TypeScript
Raw Normal View History

import Command from './command'
import history from '../history'
import { Data, DrawShape } from 'types'
2021-06-24 12:34:43 +00:00
import { deepClone, getPage, getShape, setSelectedIds } from 'utils'
2021-06-21 21:35:28 +00:00
export default function drawCommand(data: Data, id: string): void {
2021-06-24 12:34:43 +00:00
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]
},
})
)
}