2021-05-29 10:12:28 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data, DrawShape } from 'types'
|
|
|
|
import { getPage } from 'utils/utils'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
|
|
|
import { current } from 'immer'
|
2021-05-27 20:11:48 +00:00
|
|
|
|
2021-05-29 12:54:33 +00:00
|
|
|
export default function drawCommand(
|
|
|
|
data: Data,
|
|
|
|
id: string,
|
|
|
|
points: number[][]
|
|
|
|
) {
|
2021-05-29 10:12:28 +00:00
|
|
|
const restoreShape = current(getPage(data)).shapes[id] as DrawShape
|
2021-05-29 12:54:33 +00:00
|
|
|
getShapeUtils(restoreShape).setProperty(restoreShape, 'points', points)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
data.selectedIds.clear()
|
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
delete getPage(data).shapes[id]
|
|
|
|
data.selectedIds.clear()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|