2021-05-31 19:13:43 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
2021-06-24 08:18:14 +00:00
|
|
|
import { getPage } from 'utils'
|
2021-05-31 19:13:43 +00:00
|
|
|
import { HandleSnapshot } from 'state/sessions/handle-session'
|
2021-06-21 21:35:28 +00:00
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
2021-05-31 19:13:43 +00:00
|
|
|
|
|
|
|
export default function handleCommand(
|
|
|
|
data: Data,
|
|
|
|
before: HandleSnapshot,
|
|
|
|
after: HandleSnapshot
|
2021-06-21 21:35:28 +00:00
|
|
|
): void {
|
2021-05-31 19:13:43 +00:00
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'moved_handle',
|
|
|
|
category: 'canvas',
|
2021-06-21 21:35:28 +00:00
|
|
|
do(data) {
|
2021-06-24 12:34:43 +00:00
|
|
|
const { initialShape } = after
|
2021-05-31 19:13:43 +00:00
|
|
|
|
2021-06-24 12:34:43 +00:00
|
|
|
const page = getPage(data)
|
2021-06-05 06:36:39 +00:00
|
|
|
const shape = page.shapes[initialShape.id]
|
2021-05-31 19:13:43 +00:00
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
getShapeUtils(shape)
|
|
|
|
.onHandleChange(shape, initialShape.handles)
|
|
|
|
.onSessionComplete(shape)
|
2021-05-31 19:13:43 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
2021-06-24 12:34:43 +00:00
|
|
|
const { initialShape } = before
|
2021-05-31 19:13:43 +00:00
|
|
|
|
2021-06-24 12:34:43 +00:00
|
|
|
const page = getPage(data)
|
2021-06-05 14:29:49 +00:00
|
|
|
page.shapes[initialShape.id] = initialShape
|
2021-05-31 19:13:43 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|