@mocanvas/editor · class

StateNode

declare abstract class StateNode

A node in the tool state machine. Tools are trees of StateNodes: the root holds one child per tool, each tool holds its own states.


Methods · 11

constructor(editor: Editor, parent?: StateNode)
enter(info: Record<string, unknown>, from: string): void
exit(info: Record<string, unknown>, to: string): void
getCurrent(): StateNode | undefined
getDescendant<T extends StateNode>(path: string): T | undefined
getIsActive(): boolean
getPath(): string
handleEvent(info: EventInfo): void

Dispatch an event to this node, then to its active child.

static get isLockableTool(): boolean

Tools can declare the interaction they perform when locked.

setCurrentToolIdMask(_mask: string | undefined): void

Change the active tool from anywhere in the tree.

transition(id: string, info?: object): this

Enter a child state.

id may be a dotted path — transition("select.idle") enters select and then walks into its idle child, which is how a tool hands control back to a specific state of another tool rather than to that tool's initial state.


Properties · 28

static children?: () => StateNodeConstructor[]
readonly children?: Record<string, StateNode>
readonly editor: Editor
static id: string
readonly id: string
static initial?: string
readonly initial: string | undefined
static isLockable: boolean
onCancel?(info: CancelEventInfo): void
onComplete?(info: CompleteEventInfo): void
onDoubleClick?(info: ClickEventInfo): void
onEnter?(info: Record<string, unknown>, from: string): void
onExit?(info: Record<string, unknown>, to: string): void
onInterrupt?(info: InterruptEventInfo): void
onKeyDown?(info: KeyboardEventInfo): void
onKeyRepeat?(info: KeyboardEventInfo): void
onKeyUp?(info: KeyboardEventInfo): void
onMiddleClick?(info: PointerEventInfo): void
onPointerDown?(info: PointerEventInfo): void
onPointerMove?(info: PointerEventInfo): void
onPointerUp?(info: PointerEventInfo): void
onRightClick?(info: PointerEventInfo): void
onTick?(info: TickEventInfo): void
onWheel?(info: WheelEventInfo): void
readonly parent: StateNode | undefined
shapeType?: string

Whether the shape kind this tool creates should be kept selected after creation etc.

readonly type: StateNodeType
static useCoalescedEvents: boolean

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.