tldraw/state/commands/draw.ts

30 lines
725 B
TypeScript
Raw Normal View History

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