tldraw/state/commands/double-point-handle.ts

35 lines
879 B
TypeScript
Raw Normal View History

import Command from './command'
import history from '../history'
import { Data, PointerInfo } from 'types'
import { getShapeUtils } from 'state/shape-utils'
2021-06-29 12:00:59 +00:00
import { deepClone } from 'utils'
import tld from 'utils/tld'
export default function doublePointHandleCommand(
data: Data,
id: string,
payload: PointerInfo
): void {
2021-06-29 12:00:59 +00:00
const initialShape = deepClone(tld.getShape(data, id))
history.execute(
data,
new Command({
name: 'double_point_handle',
category: 'canvas',
do(data) {
2021-06-29 12:00:59 +00:00
const { shapes } = tld.getPage(data)
const shape = shapes[id]
getShapeUtils(shape).onDoublePointHandle(shape, payload.target, payload)
2021-06-29 12:00:59 +00:00
tld.updateParents(data, [id])
},
undo(data) {
2021-06-29 12:00:59 +00:00
const { shapes } = tld.getPage(data)
shapes[id] = initialShape
2021-06-29 12:00:59 +00:00
tld.updateParents(data, [id])
},
})
)
}