Computed flow layout, and mobile written into the design
The canvas lays itself out: a layered graph, left to right on a desktop and top to bottom on a phone, with room reserved for the value each edge carries. Nodes cannot be dragged and `NodeDef.position` is gone from the document — a graph nobody can arrange is one worth keeping small, which is what keeps flows atomic. Endpoints join the same layout, so their lanes and the localStorage that remembered where they were dragged go too. Mobile, per the new Responsive section of DESIGN-GUIDELINES.md: the dock caps its width and wraps instead of running off the screen, the dashboard stacks into one column rather than shrinking a wall panel to a fifth of its size, and Home stops widening its grid track past the viewport. A Playwright project at a phone's width fails the build when a screen no longer fits. Along the way: publish is the checkmark that was already there rather than a button that appears and disappears, with discard beside it on both the flow and the dashboard; the brain reveals a neuron's name on the first tap; and the port sparklines get room to breathe. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VDSXaRhvqHYNevgDGmNAto
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip"
|
||||
import { useIsMobile } from "@/hooks/useMobile"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { portOf } from "./deriveEdges"
|
||||
import { useNodeEmits, useNodeStatus } from "./liveStore"
|
||||
@@ -69,7 +70,7 @@ export type FlowNodeData = {
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
/** Vertically distribute handles so several ports stay reachable. */
|
||||
/** Spread handles along the node's edge so several ports stay reachable. */
|
||||
function handleOffset(index: number, total: number): string {
|
||||
if (total <= 1) return "50%"
|
||||
const span = 60
|
||||
@@ -85,10 +86,13 @@ function PortHandles({
|
||||
type: "source" | "target"
|
||||
position: Position
|
||||
}) {
|
||||
// The ports run across whichever edge they sit on.
|
||||
const along = position === Position.Top || position === Position.Bottom
|
||||
return (
|
||||
<>
|
||||
{specs.map((spec, index) => {
|
||||
const port = portOf(spec)
|
||||
const offset = handleOffset(index, specs.length)
|
||||
return (
|
||||
<Handle
|
||||
key={`${type}-${port}`}
|
||||
@@ -99,7 +103,7 @@ function PortHandles({
|
||||
"!bg-card !border-muted-foreground/60",
|
||||
!spec.name && "unbound",
|
||||
)}
|
||||
style={{ top: handleOffset(index, specs.length) }}
|
||||
style={along ? { left: offset } : { top: offset }}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
@@ -112,6 +116,9 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
|
||||
data as FlowNodeData
|
||||
const live = useNodeStatus(`${flow}.${definition.id}`)
|
||||
const emits = useNodeEmits(`${flow}.${definition.id}`)
|
||||
// The graph runs top to bottom on a phone, so the ports have to face that
|
||||
// way too — see DESIGN-GUIDELINES.md → Responsive.
|
||||
const vertical = useIsMobile()
|
||||
const Icon =
|
||||
NODE_ICONS[definition.type as keyof typeof NODE_ICONS] ??
|
||||
// A connector's own type cannot be in the map above, and a device is
|
||||
@@ -143,7 +150,7 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
|
||||
<PortHandles
|
||||
specs={definition.requires ?? []}
|
||||
type="target"
|
||||
position={Position.Left}
|
||||
position={vertical ? Position.Top : Position.Left}
|
||||
/>
|
||||
|
||||
<div className="flex items-center gap-2.5">
|
||||
@@ -226,7 +233,7 @@ function FlowNodeComponent({ data, selected }: NodeProps) {
|
||||
<PortHandles
|
||||
specs={definition.provides ?? []}
|
||||
type="source"
|
||||
position={Position.Right}
|
||||
position={vertical ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user