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-05-29 10:12:28 +00:00
|
|
|
name: 'set_points',
|
|
|
|
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]
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|