$flow Magic

$flow is an Alpine.js magic property available inside any flowCanvas() scope. It provides programmatic access to the nearest flow canvas instance, returning the full Alpine data object with all reactive state and methods.

<div x-data="flowCanvas({ nodes: [...], edges: [...] })">
  <button @click="$flow.addNodes({ id: 'new', position: { x: 100, y: 100 }, data: { label: 'New' } })">
    Add Node
  </button>
</div>

$flow works from any descendant element -- it walks up the DOM to find the nearest [data-flow-canvas] container. If used outside a flowCanvas() scope, it logs a warning and returns an empty object.


Sections

Section Description
State Reactive properties
Nodes Node CRUD and queries
Edges Edge CRUD
Selection Selection and filtering
Viewport Pan, zoom, coordinates
Hierarchy Parent/child, collapse, condense, transform
Update & Animation update(), animate(), timeline, particles, follow
Layout Auto-layout algorithms
State Management Serialization, clipboard, history, config

Quick Reference

All $flow methods and properties at a glance:

Reactive State

Property Type Description
nodes FlowNode[] All nodes
edges FlowEdge[] All edges
viewport Viewport Current { x, y, zoom }
selectedNodes Set<string> Selected node IDs
selectedEdges Set<string> Selected edge IDs
selectedRows Set<string> Selected row IDs
ready boolean Canvas initialized
isLoading boolean Loading state
isInteractive boolean Pan/zoom/drag enabled
canUndo boolean Undo available
canRedo boolean Redo available
colorMode string Resolved color mode
contextMenu object Context menu state
pendingConnection object? Active connection drag

Methods

Method Signature Page
addNodes (nodes, options?) → void Nodes
removeNodes (ids) → void Nodes
getNode (id) → FlowNode? Nodes
getNodesBounds (ids?) → Rect Nodes
getOutgoers (nodeId) → FlowNode[] Nodes
getIncomers (nodeId) → FlowNode[] Nodes
getConnectedEdges (nodeId) → FlowEdge[] Nodes
areNodesConnected (a, b, directed?) → boolean Nodes
getIntersectingNodes (node, partially?) → FlowNode[] Nodes
isNodeIntersecting (node, target, partially?) → boolean Nodes
addEdges (edges) → void Edges
removeEdges (ids) → void Edges
getEdge (id) → FlowEdge? Edges
getEdgePathElement (id) → SVGPathElement? Edges
getEdgeElement (id) → SVGElement? Edges
deselectAll () → void Selection
selectRow (rowId) → void Selection
deselectRow (rowId) → void Selection
toggleRowSelect (rowId) → void Selection
setRowFilter (nodeId, filter) → void Selection
clearNodeFilter () → void Selection
setNodeFilter (predicate) → void Selection
setViewport (viewport, options?) → void Viewport
zoomIn (options?) → void Viewport
zoomOut (options?) → void Viewport
setCenter (x, y, zoom?, options?) → void Viewport
panBy (dx, dy, options?) → void Viewport
fitView (options?) → void Viewport
fitBounds (rect, options?) → void Viewport
getViewportForBounds (bounds, padding?) → Viewport Viewport
toggleInteractive () → void Viewport
screenToFlowPosition (x, y) → XYPosition Viewport
flowToScreenPosition (x, y) → XYPosition Viewport
getAbsolutePosition (nodeId) → XYPosition Viewport
layoutChildren (parentId, options?) → void Hierarchy
propagateLayoutUp (parentId, opts?) → void Hierarchy
reorderChild (nodeId, newOrder) → void Hierarchy
reparentNode (nodeId, newParentId) → boolean Hierarchy
collapseNode (id, options?) → void Hierarchy
expandNode (id, options?) → void Hierarchy
toggleNode (id, options?) → void Hierarchy
isCollapsed (id) → boolean Hierarchy
condenseNode (id) → void Hierarchy
uncondenseNode (id) → void Hierarchy
toggleCondense (id) → void Hierarchy
rotateNode (id, angle) → void Hierarchy
registerCompute (nodeType, definition) → void Hierarchy
compute (startNodeId?) → Map Hierarchy
validateParent (nodeId) → { valid, errors } Hierarchy
validateAll () → Map Hierarchy
update (targets, options?) → FlowAnimationHandle Animation
animate (targets, options?) → FlowAnimationHandle Animation
timeline () → FlowTimeline Animation
registerAnimation (name, steps) → void Animation
playAnimation (name) → Promise<void> Animation
follow (target, options?) → FlowAnimationHandle Animation
sendParticle (edgeId, options?) → ParticleHandle? Animation
layout (options?) → void Layout
forceLayout (options?) → void Layout
treeLayout (options?) → void Layout
elkLayout (options?) → Promise<void> Layout
copy () → void State
paste () → void State
cut () → Promise<void> State
undo () → void State
redo () → void State
toObject () → { nodes, edges, viewport } State
fromObject (obj) → void State
$reset () → void State
$clear () → void State
toImage (options?) → Promise<string> State
setLoading (value) → void State
patchConfig (changes) → void State
closeContextMenu () → void State
resetPanels () → void State