2021-05-29 10:12:28 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data, DrawShape } from 'types'
|
2021-06-07 11:18:50 +00:00
|
|
|
import { getPage, setSelectedIds } from 'utils/utils'
|
2021-05-29 10:12:28 +00:00
|
|
|
import { current } from 'immer'
|
2021-05-27 20:11:48 +00:00
|
|
|
|
2021-06-07 11:18:50 +00:00
|
|
|
export default function drawCommand(data: Data, id: string) {
|
|
|
|
const restoreShape = getPage(current(data)).shapes[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]
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|