Add the flow editor: canvas, node panel and live values

The browser half of M3. Flows open on a full-bleed canvas with their chrome
floating over it: flow tabs top, dock bottom, node settings in a panel on the
right that leaves the graph visible and running behind it.

- Connections are derived, not stored. A node declares the messages it reads
  and publishes; every matching pair draws an edge, so two producers of one
  message converge on their consumer. Dragging output to input is shorthand
  for pointing that input at the producer's message, and asks before it
  replaces an existing one.
- Values land on the edges as they flow, over a websocket that feeds a store
  outside React, so a value arriving re-renders its own chip and nothing else.
  Clicking an edge shows the last payload and when it arrived.
- Node source is edited in Monaco, loaded only when a panel opens and themed
  from the design tokens.
- Edits autosave; identical documents are skipped server-side, so a quiet
  canvas writes nothing.
- Validation from the API shows on the node it belongs to and is summarised in
  the dock, where each entry pans to its node.
- Works on a phone: touch-connect, 44px dock targets, and the node panel
  becomes a full-screen sheet.

Two new tokens (--status-success, --font-mono) are mirrored in the website repo
and recorded in DESIGN-GUIDELINES.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WzrvW7rjQbynnhF6pxh6i
This commit is contained in:
Melvin Strobl
2026-08-15 18:10:50 +02:00
co-authored by Claude Fable 5
parent 06a4506767
commit 8c82549cf6
40 changed files with 5027 additions and 66 deletions
@@ -0,0 +1,91 @@
import type { Edge } from "@xyflow/react"
import type { MessageSpec, NodeDef_Input } from "@/client"
/** Resolve a message name against its flow: bare names belong to this flow. */
export function qualify(flow: string, name: string): string {
if (!name) return ""
return name.includes(".") ? name : `${flow}.${name}`
}
/** The flow a qualified message belongs to. */
export function flowOf(message: string): string {
return message.split(".", 1)[0]
}
/** How a message reads inside its own flow. */
export function displayName(flow: string, message: string): string {
return message.startsWith(`${flow}.`)
? message.slice(flow.length + 1)
: message
}
export function portOf(spec: MessageSpec): string {
return spec.port || spec.name?.split(".").pop() || ""
}
export type FlowEdgeData = {
message: string
flow: string
[key: string]: unknown
}
/**
* Turn name bindings into canvas edges.
*
* Nodes never point at each other: a node declares the messages it consumes,
* and every node providing that message is upstream of it. Two producers of one
* message therefore draw two edges converging on the same input.
*/
export function deriveEdges(nodes: NodeDef_Input[], flow: string): Edge[] {
const producers = new Map<string, { node: string; port: string }[]>()
for (const node of nodes) {
for (const spec of node.provides ?? []) {
const message = qualify(flow, spec.name ?? "")
if (!message) continue
const list = producers.get(message) ?? []
list.push({ node: node.id, port: portOf(spec) })
producers.set(message, list)
}
}
const edges: Edge[] = []
for (const node of nodes) {
for (const spec of node.requires ?? []) {
const message = qualify(flow, spec.name ?? "")
if (!message) continue
const targetPort = portOf(spec)
for (const producer of producers.get(message) ?? []) {
if (producer.node === node.id) continue
edges.push({
id: `${producer.node}:${producer.port}->${node.id}:${targetPort}`,
source: producer.node,
sourceHandle: producer.port,
target: node.id,
targetHandle: targetPort,
type: "live",
data: { message, flow } satisfies FlowEdgeData,
})
}
}
}
return edges
}
/**
* A cheap fingerprint of everything edges depend on, so dragging a node (which
* replaces the array every frame) does not re-derive them.
*/
export function bindingsKey(nodes: NodeDef_Input[]): string {
return nodes
.map(
(node) =>
`${node.id}|${(node.requires ?? [])
.map((s) => `${portOf(s)}=${s.name ?? ""}`)
.join(",")}|${(node.provides ?? [])
.map((s) => `${portOf(s)}=${s.name ?? ""}`)
.join(",")}`,
)
.join(";")
}