2021-05-31 19:13:43 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data } from 'types'
|
|
|
|
import { getPage } from 'utils/utils'
|
|
|
|
import { HandleSnapshot } from 'state/sessions/handle-session'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
2021-06-05 06:36:39 +00:00
|
|
|
import * as vec from 'utils/vec'
|
2021-05-31 19:13:43 +00:00
|
|
|
|
|
|
|
export default function handleCommand(
|
|
|
|
data: Data,
|
|
|
|
before: HandleSnapshot,
|
|
|
|
after: HandleSnapshot
|
|
|
|
) {
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
|
|
|
name: 'moved_handle',
|
|
|
|
category: 'canvas',
|
|
|
|
do(data, isInitial) {
|
2021-06-05 06:36:39 +00:00
|
|
|
// if (isInitial) return
|
2021-05-31 19:13:43 +00:00
|
|
|
|
|
|
|
const { initialShape, currentPageId } = after
|
|
|
|
|
2021-06-05 06:36:39 +00:00
|
|
|
const page = getPage(data, currentPageId)
|
|
|
|
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-06-05 06:36:39 +00:00
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
// const bounds = getShapeUtils(shape).getBounds(shape)
|
2021-06-05 06:36:39 +00:00
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
// const offset = vec.sub([bounds.minX, bounds.minY], shape.point)
|
2021-06-05 06:36:39 +00:00
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
// getShapeUtils(shape).translateTo(shape, vec.add(shape.point, offset))
|
2021-06-05 06:36:39 +00:00
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
// const { start, end, bend } = page.shapes[initialShape.id].handles
|
2021-06-05 06:36:39 +00:00
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
// start.point = vec.sub(start.point, offset)
|
|
|
|
// end.point = vec.sub(end.point, offset)
|
|
|
|
// bend.point = vec.sub(bend.point, offset)
|
2021-05-31 19:13:43 +00:00
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
const { initialShape, currentPageId } = before
|
|
|
|
|
2021-06-05 14:29:49 +00:00
|
|
|
const page = getPage(data, currentPageId)
|
|
|
|
page.shapes[initialShape.id] = initialShape
|
2021-05-31 19:13:43 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|