2021-05-29 10:12:28 +00:00
|
|
|
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-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-29 12:00:59 +00:00
|
|
|
const restoreShape = deepClone(tld.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) {
|
2021-06-29 12:00:59 +00:00
|
|
|
tld.getPage(data).shapes[id] = restoreShape
|
2021-05-27 20:11:48 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 12:00:59 +00:00
|
|
|
tld.setSelectedIds(data, [])
|
2021-05-27 20:11:48 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-29 12:00:59 +00:00
|
|
|
tld.setSelectedIds(data, [])
|
|
|
|
delete tld.getPage(data).shapes[id]
|
2021-05-27 20:11:48 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|