Let one effect own the flow canvas viewport
Three things moved the viewport independently — the shape-fit effect, focusNode, and React Flow's own fitView prop — so a fourth for "centre the node I just selected" would have been a fourth party to the argument. There is one effect now, and which branch it takes is decided by what changed rather than by what is true: selecting a node brings that node into the lane the panel leaves, and every other change — new wiring, a new endpoint, a panel opening — re-fits the whole flow into the same lane. A selection centres once, so the port edits that follow re-fit around it, which is what makes a new edge's far end visible. The refit triggers on the edge count, not the bindings key: that key changes on every keystroke in a message-name field, and refitting per character is not what "an edge was created" means. renderedNodes overwrote xyflow's own `selected` flag, so a box-selection of several nodes was invisible even though delete and copy acted on all of them. The logs panel was a popover anchored on its own button, which is why it sat off centre, hugged the button and closed on any outside click. It is a plain surface above the dock now, and the button is stateful. Escape still closes it. Expanding a node's editor gives the panel the whole inset and puts the code on the left with the settings beside it, while the toolbar and the flow name translate off screen. Narrowing the window past `md` gives the room back — the sheet it becomes has no second column to hold. The zoom buttons are gone: there is a mouse, or there is a pinch.
This commit is contained in:
@@ -12,8 +12,6 @@ import {
|
||||
StepForward,
|
||||
WifiOff,
|
||||
X,
|
||||
ZoomIn,
|
||||
ZoomOut,
|
||||
} from "lucide-react"
|
||||
import { motion } from "motion/react"
|
||||
|
||||
@@ -43,6 +41,20 @@ import { useLiveConnection } from "./liveStore"
|
||||
*/
|
||||
export const FIT_VIEW = { padding: 0.25, maxZoom: 1.2 }
|
||||
|
||||
/**
|
||||
* The same fit with the settings panel's lane held clear, so an opening panel
|
||||
* never lands on the node you are looking at. 432px is the lane the chrome is
|
||||
* pushed out of by `md:right-[27rem]`; xyflow's padding parser takes px and %,
|
||||
* so it cannot be spelled in rem. 10% per side is what `padding: 0.25` above
|
||||
* resolves to, so the two fits are equally generous.
|
||||
*/
|
||||
export const FIT_VIEW_PANEL = {
|
||||
maxZoom: FIT_VIEW.maxZoom,
|
||||
// `as const` because xyflow types each side as `${number}px | ${number}%`,
|
||||
// which a widened `string` does not satisfy.
|
||||
padding: { top: "10%", bottom: "10%", left: "10%", right: "432px" } as const,
|
||||
}
|
||||
|
||||
/**
|
||||
* The action bar, floating bottom-centre. Run is the one brand-secondary
|
||||
* affordance on this view; everything else stays quiet.
|
||||
@@ -51,7 +63,7 @@ export const FIT_VIEW = { padding: 0.25, maxZoom: 1.2 }
|
||||
* saved, the flow's own settings, and putting it live or throwing it away —
|
||||
* so the top of the canvas is left to say which flow this is.
|
||||
*
|
||||
* It wraps rather than overflows, and drops the zoom controls on a phone; see
|
||||
* It wraps rather than overflows, and drops the fit control on a phone; see
|
||||
* DESIGN-GUIDELINES.md → Responsive.
|
||||
*/
|
||||
export function FlowDock({
|
||||
@@ -73,6 +85,7 @@ export function FlowDock({
|
||||
onEditFlow,
|
||||
onPublish,
|
||||
onDiscard,
|
||||
className,
|
||||
}: {
|
||||
flow: string
|
||||
issues: ValidationIssue[]
|
||||
@@ -93,8 +106,9 @@ export function FlowDock({
|
||||
onEditFlow: () => void
|
||||
onPublish: () => void
|
||||
onDiscard: () => void
|
||||
className?: string
|
||||
}) {
|
||||
const { zoomIn, zoomOut, fitView } = useReactFlow()
|
||||
const { fitView } = useReactFlow()
|
||||
const connected = useLiveConnection()
|
||||
|
||||
return (
|
||||
@@ -107,7 +121,10 @@ export function FlowDock({
|
||||
// Capped and wrapping: the canvas shell clips, so an uncapped row would
|
||||
// put the buttons at its ends out of reach on a phone rather than merely
|
||||
// look wrong. See DESIGN-GUIDELINES.md → Responsive.
|
||||
className="pointer-events-auto absolute bottom-4 left-1/2 z-10 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 flex-wrap items-center justify-center gap-1 rounded-full border border-border bg-card/80 px-1.5 py-1 shadow-e2 backdrop-blur-md pb-[max(0.25rem,env(safe-area-inset-bottom))]"
|
||||
className={cn(
|
||||
"pointer-events-auto absolute bottom-4 left-1/2 z-10 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 flex-wrap items-center justify-center gap-1 rounded-full border border-border bg-card/80 px-1.5 py-1 shadow-e2 backdrop-blur-md pb-[max(0.25rem,env(safe-area-inset-bottom))]",
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
@@ -130,17 +147,8 @@ export function FlowDock({
|
||||
className="mx-0.5 !h-5 hidden md:block"
|
||||
/>
|
||||
|
||||
{/* A phone pinches to zoom and the graph fits itself, so these three
|
||||
would only be taking room the rest of the bar needs. */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="hidden text-muted-foreground md:inline-flex md:size-8"
|
||||
onClick={() => zoomOut()}
|
||||
aria-label="Zoom out"
|
||||
>
|
||||
<ZoomOut />
|
||||
</Button>
|
||||
{/* A phone pinches to zoom and the graph fits itself, so this would only
|
||||
be taking room the rest of the bar needs. */}
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
@@ -155,15 +163,6 @@ export function FlowDock({
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Fit to screen</TooltipContent>
|
||||
</Tooltip>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="hidden text-muted-foreground md:inline-flex md:size-8"
|
||||
onClick={() => zoomIn()}
|
||||
aria-label="Zoom in"
|
||||
>
|
||||
<ZoomIn />
|
||||
</Button>
|
||||
|
||||
{issues.length > 0 ? (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user