defuss-shadcn / Workflows / workflows
Workflows
One component for node-based editors: the Workflow turns a JSON document of nodes, typed ports and connections into an editor you pan, zoom, connect, group and run. A Web Worker draws the connections and every node far from the view into one canvas; only the cards near the view become HTML - built from the system's own Input, Select, Slider and Switch - so 10,000 nodes and 100,000 connections stay a page of a few hundred elements. The palette, the outline, the inspector and the toolbar are outlets the page places around it.
On this page (3)
§Headline studio
Drag a node by its title, drag from a port to another to connect (compatible ports grow), click a connection to inspect it. Add nodes from Nodes by click or drag. Run executes the steps in the page - each step waits a moment so you can watch the states. ⌘Z undoes, F fits.
§How it works
The graph lives in a store on the main thread: every edit is a transaction of new values that is checked whole - port types, how many connections a port takes, cycles - and rolled back whole when it fails, so the graph is never half changed. The worker keeps a derived scene of node boxes and connection curves in a spatial hash; each frame it draws what is in view into an OffscreenCanvas and hands the bitmap back. The page meanwhile moves at most 150 HTML cards with the camera, so panning never waits on the worker.
flowchart LR
Edit["edit:<br/>drag, connect, type"] -->|"patches"| Store["store:<br/>checks, history"]
Store -->|"changed geometry"| Worker["worker:<br/>scene, spatial hash"]
Worker -->|"ImageBitmap"| Canvas["canvas:<br/>connections, far nodes"]
Store --> Cards["HTML cards:<br/>at most 150 near the view"]
Canvas --> Frame["one animation frame"]
Cards --> Frame§Topics
Large Workflows - 10,000 nodes and 100,000 connections, the render budget and what it samples. Node Types & Fields - declaring node types, the card controls and custom card bodies. Editing & Structure - connecting, moving, groups, subworkflows and the keys. Running Workflows - run handlers in the page, an execution adapter for a server, the node states. Formats & Import - the JSON document, ComfyUI and Gradio, import and export.
Comments, ideas or improvements? Edit this page's source on GitHub