Tldraw/packages/tldraw/src/state/tools/ArrowTool/ArrowTool.ts

38 wiersze
965 B
TypeScript
Czysty Zwykły widok Historia

import Vec from '@tldraw/vec'
import { Utils, TLPointerEventHandler } from '@tldraw/core'
import { Arrow } from '~state/shapes'
import { SessionType, TLDrawShapeType } from '~types'
import { BaseTool, Status } from '../BaseTool'
export class ArrowTool extends BaseTool {
type = TLDrawShapeType.Arrow
/* ----------------- Event Handlers ----------------- */
onPointerDown: TLPointerEventHandler = (info) => {
const pagePoint = Vec.round(this.state.getPagePoint(info.point))
const {
appState: { currentPageId, currentStyle },
} = this.state
const childIndex = this.getNextChildIndex()
const id = Utils.uniqueId()
const newShape = Arrow.create({
id,
parentId: currentPageId,
childIndex,
point: pagePoint,
style: { ...currentStyle },
})
2021-10-22 13:49:29 +00:00
this.state.patchCreate([newShape])
this.state.startSession(SessionType.Arrow, pagePoint, 'end', true)
this.setStatus(Status.Creating)
}
}