Import these from @grafloria/engine.
Classes
ConnectionStateManager
Manages connection creation state during drag operations
tsclass ConnectionStateManager
Methods
constructor(eventBus: EventBus, diagram: DiagramModel | null = null)setDiagram(diagram: DiagramModel | null): void— Point the manager at the live diagram (DiagramEngine calls this on load).startConnection(sourcePort: PortModel, startPoint: Point): void— Start connection drag from a portupdateConnection(currentPoint: Point, hoveredPort?: PortModel): void— Update connection drag positioncompleteConnection(targetPort: PortModel): { success: boolean; link?: LinkModel }— Complete connection to target portcancelConnection(): void— Cancel connectionsetValidTargets(nodeIds: Set<string>, portIds: Set<string>): void— Set valid target ports (called by a host that wants to narrow the set further than the rules do — e.g. a wizard that only permits one legal move).addValidator(validator: ConnectionValidator): void— Add a custom connection validatorremoveValidator(validator: ConnectionValidator): void— Remove a custom connection validatorclearValidators(): void— Clear all custom validatorsgetState(): Readonly<ConnectionDragState>— Get current state (read-only)isConnecting(): boolean— Check if currently connectinggetSourcePort(): PortModel | null— Get source port (if connecting)getTargetPort(): PortModel | null— Get target port (if hovering over one)getCurrentMousePosition(): Point | null— Get current mouse positionisOverValidTarget(): boolean— Check if hovering over valid target
DiagramStore
tsclass DiagramStore
Methods
constructor(initialState?: Partial<DiagramState>)getState(): Readonly<DiagramState>— Get current state (immutable)setState(updater: (state: DiagramState) => void): void— Set state with change trackingselect<T>(path: string): T— Get state value by pathget(path: string): any— Get state value by pathset(path: string, value: any): void— Set state value by pathsubscribe(listener: StateListener): () => void— Subscribe to all state changeswatch(path: string, listener: PathListener): () => void— Subscribe to path changescomputed<T>(key: string, compute: (state: DiagramState) => T, deps?: string[]): T— Computed value with memoizationbatch(fn: () => void): void— Batch multiple state updatesreset(initialState?: Partial<DiagramState>): void— Reset to initial statetimeTravel(index: number): void— Time travel to history indexgetHistory(): ReadonlyArray<StateSnapshot>— Get historycreateSnapshot(): StateSnapshot— Create snapshotrestoreSnapshot(snapshot: StateSnapshot): void— Restore snapshot
Interfaces
ConnectionDragState
Connection drag state Tracks the state of an in-progress connection being dragged
tsinterface ConnectionDragState
Properties
| Name | Type | Default | Description |
|---|---|---|---|
isConnecting | boolean | Whether a connection is currently being dragged | |
sourcePort | PortModel | null | Source port where connection started | |
targetPort | PortModel | null | Target port currently hovered (if any) | |
currentMousePosition | Point | null | Current mouse position in world coordinates | |
previewPath | Point[] | null | Preview path points (for rendering connection line) | |
validTargetNodes | Set<string> | Set of node IDs that can accept this connection | |
validTargetPorts | Set<string> | Set of port IDs that can accept this connection | |
isOverValidTarget | boolean | Whether current hover position is over a valid target | |
invalidTargetPorts | Map<string, ConnectionRejectionReason> | Every port the drag has REJECTED, and why. The renderer draws an explicit "no" cue on a rejected target and dims ports whose data type is incompatible — it can only do that if the rejection is data, not a silently-swallowed false. Populated alongside validTargetPorts at drag start. | |
rejectionReason? | ConnectionRejectionReason | Why the CURRENT hover was rejected (undefined when it is valid). | |
rejectionMessage? | string | Human-readable form of {@link rejectionReason}. |
DiagramState
tsinterface DiagramState
Properties
| Name | Type | Default | Description |
|---|---|---|---|
diagram | DiagramModel | null | ||
selectedNodes | Set<string> | ||
selectedLinks | Set<string> | ||
hoveredElement | string | null | ||
focusedElement | string | null | ||
viewport | Viewport | ||
zoom | number | ||
gridEnabled | boolean | ||
snapEnabled | boolean | ||
activeTool | string | ||
toolOptions | Record<string, any> | ||
mode | 'design' | 'runtime' | 'readonly' | ||
locked | boolean | ||
theme | 'light' | 'dark' | ||
showMinimap | boolean | ||
showToolbar | boolean | ||
showProperties | boolean | ||
renderStats | RenderStats | ||
errors | Error[] | ||
warnings | string[] |
RenderStats
tsinterface RenderStats
Properties
| Name | Type | Default | Description |
|---|---|---|---|
fps | number | ||
renderTime | number | ||
nodeCount | number | ||
linkCount | number | ||
visibleNodes | number | ||
visibleLinks | number |
StateSnapshot
tsinterface StateSnapshot
Properties
| Name | Type | Default | Description |
|---|---|---|---|
timestamp | number | ||
state | DiagramState | ||
version | string |
Types
ConnectionValidator
Connection validation function Returns true if connection is allowed
tstype ConnectionValidator = (
sourcePort: PortModel,
targetPort: PortModel
) => boolean;
PathListener
tstype PathListener = (value: any, oldValue: any) => void;
StateListener
tstype StateListener = (state: DiagramState, changes: string[]) => void;
Was this page helpful?