2021-05-29 10:12:28 +00:00
|
|
|
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-05-27 20:11:48 +00:00
|
|
|
|
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
|
2021-05-27 20:11:48 +00:00
|
|
|
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-06-11 10:11:42 +00:00
|
|
|
name: 'create_draw_shape',
|
2021-05-29 10:12:28 +00:00
|
|
|
category: 'canvas',
|
2021-05-27 20:11:48 +00:00
|
|
|
manualSelection: true,
|
|
|
|
do(data, initial) {
|
|
|
|
if (!initial) {
|
|
|
|
getPage(data).shapes[id] = restoreShape
|
|
|
|
}
|
|
|
|
|
2021-06-07 11:18:50 +00:00
|
|
|
setSelectedIds(data, [])
|
2021-05-27 20:11:48 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-07 11:18:50 +00:00
|
|
|
setSelectedIds(data, [])
|
2021-05-27 20:11:48 +00:00
|
|
|
delete getPage(data).shapes[id]
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|