Edges follow ELK's routes: layoutGraph returns each edge's start, bends, end and chip point, LiveEdge draws them square with rounded corners, moved onto the drawn handles, and keeps the curve for an edge whose node moved since; a feedback edge clears the nodes it passes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WgBfkm4rCmtd1T4vHWjEPx
This commit is contained in:
@@ -57,6 +57,7 @@ import {
|
||||
bindingsKey,
|
||||
boundaryKey,
|
||||
deriveEdges,
|
||||
type FlowEdgeData,
|
||||
flowOf,
|
||||
portOf,
|
||||
qualify,
|
||||
@@ -74,7 +75,12 @@ import { FlowNode, type FlowNodeData } from "./FlowNode"
|
||||
import { FlowPanel } from "./FlowPanel"
|
||||
import { InputInspector, type InspectedInput } from "./InputInspector"
|
||||
import { LiveEdge } from "./LiveEdge"
|
||||
import { type Direction, layoutGraph, type NodeShape } from "./layout"
|
||||
import {
|
||||
type Direction,
|
||||
type Layout,
|
||||
layoutGraph,
|
||||
type NodeShape,
|
||||
} from "./layout"
|
||||
import { NodePanel } from "./NodePanel"
|
||||
import { RunDialog } from "./RunDialog"
|
||||
import "./flow.css"
|
||||
@@ -93,7 +99,7 @@ import { useFlowSocket } from "./useFlowSocket"
|
||||
const nodeTypes = { flow: FlowNode, [ENDPOINT_TYPE]: EndpointNode }
|
||||
|
||||
/**
|
||||
* Where every node sits, once the engine has said so.
|
||||
* Where every node sits and how every edge runs, once the engine has said so.
|
||||
*
|
||||
* The layout is a chunk of its own and answers asynchronously, so a canvas has
|
||||
* a moment before it knows where anything goes. It draws nothing at all until
|
||||
@@ -107,18 +113,15 @@ function useLayout(
|
||||
direction: Direction,
|
||||
shapes: Map<string, NodeShape>,
|
||||
shapeKey: string,
|
||||
): Map<string, { x: number; y: number }> | null {
|
||||
const [placed, setPlaced] = useState<Map<
|
||||
string,
|
||||
{ x: number; y: number }
|
||||
> | null>(null)
|
||||
): Layout | null {
|
||||
const [placed, setPlaced] = useState<Layout | null>(null)
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: the shape key is the dependency; the arrays are rebuilt every render.
|
||||
useEffect(() => {
|
||||
let stale = false
|
||||
layoutGraph(ids, edges, direction, shapes).then((positions) => {
|
||||
layoutGraph(ids, edges, direction, shapes).then((layout) => {
|
||||
// A graph edited while the last one was still being laid out has already
|
||||
// asked for another; that one is the answer, not this.
|
||||
if (!stale) setPlaced(positions)
|
||||
if (!stale) setPlaced(layout)
|
||||
})
|
||||
return () => {
|
||||
stale = true
|
||||
@@ -644,7 +647,8 @@ function FlowEditorInner({
|
||||
] as const
|
||||
}),
|
||||
])
|
||||
const positions = useLayout(ids, edges, direction, shapes, shapeKey)
|
||||
const layout = useLayout(ids, edges, direction, shapes, shapeKey)
|
||||
const positions = layout?.positions ?? null
|
||||
|
||||
/**
|
||||
* The endpoints, placed.
|
||||
@@ -670,17 +674,22 @@ function FlowEditorInner({
|
||||
)
|
||||
|
||||
// Marked after the layout has had the derived array, so selecting an edge
|
||||
// never sends the graph through the layout again.
|
||||
// never sends the graph through the layout again. The route rides along
|
||||
// the same way.
|
||||
const shownEdges = useMemo(
|
||||
() =>
|
||||
edges.map((edge) => ({
|
||||
...edge,
|
||||
data: {
|
||||
...(edge.data as FlowEdgeData),
|
||||
route: layout?.routes.get(edge.id),
|
||||
},
|
||||
selected:
|
||||
selectedEdges.has(edge.id) ||
|
||||
edge.source === landing ||
|
||||
edge.target === landing,
|
||||
})),
|
||||
[edges, selectedEdges, landing],
|
||||
[edges, selectedEdges, landing, layout],
|
||||
)
|
||||
|
||||
const shownNodes = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user