tldraw/state/commands/handle.ts

37 lines
962 B
TypeScript
Raw Normal View History

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'
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-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-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
},
})
)
}