UNPKG

tldraw

Version:

A tiny little drawing editor.

38 lines (32 loc) 1.01 kB
import { StateNode, TLKeyboardEventInfo, TLPointerEventInfo } from '@tldraw/editor' export class Idle extends StateNode { static override id = 'idle' override onPointerDown(info: TLPointerEventInfo) { this.parent.transition('pointing', info) } override onEnter() { this.editor.setCursor({ type: 'cross', rotation: 0 }) } override onCancel() { this.editor.setCurrentTool('select') } override onKeyUp(info: TLKeyboardEventInfo) { if (info.key === 'Enter') { if (this.editor.getIsReadonly()) return null const onlySelectedShape = this.editor.getOnlySelectedShape() // If the only selected shape is editable, start editing it if ( onlySelectedShape && this.editor.getShapeUtil(onlySelectedShape).canEdit(onlySelectedShape) ) { this.editor.setCurrentTool('select') this.editor.setEditingShape(onlySelectedShape.id) this.editor.root.getCurrent()?.transition('editing_shape', { ...info, target: 'shape', shape: onlySelectedShape, }) } } } }