/** * The Tamagui node body. * * Knobs reach it through the REAL `useResolvedKnobs` — the resolver with its * Preset / Surface / Intent context stack, not the pure functions — which is * what MPO-191 AC-3 asks for. Every style comes from a whole `knobProps.*` * fragment spread (AGENTS.md); nothing here cherry-picks a resolved token. * * Two things this component must NOT do, both from design §7.1: * - clip. The frame is never `overflow: hidden`, because handles sit at the * node edge under `translate(±50%)` and a clipping frame eats half the dot * and most of the 44pt hit region. * - re-measure the world on a knob flip. `useUpdateNodeInternals` fires for * ONE node when its own `ports` identity changes — a port added or removed * changes `handleBounds` with no size change for React Flow's per-node * ResizeObserver to see. A knob flip DOES change height, the observer does * catch that (measured, design §5), and firing 200 updates on top of it * would stack a second forced-layout storm on the observer's. */ import { composeKnobs, panelPaddingPx, pickStates, transitionProps, } from "@multiplatform.one/theme"; import { type ReactNode, useEffect, useRef } from "react"; import { useGraphNodeKnobs } from "../knobs/graphKnobs"; import { SizableText, View, XStack, YStack } from "tamagui"; import { useUpdateNodeInternals } from "../react-flow/xy"; import { detailOpacity, isOverview } from "./lod"; import type { GraphRenderMode } from "./lod"; import { containerRadiusPx, type GraphNodeMeasure, type GraphNodePort, graphNodeMinHeight, graphNodeWidth, portSpacing, graphNodeSize, } from "./nodeMeasure"; export interface GraphNodeProps { /** Node id. React Flow addresses `updateNodeInternals` by it. */ readonly id: string; readonly title: string; readonly subtitle?: string; readonly ports?: readonly GraphNodePort[]; /** Semantic intent — reaches the resolver, never a colour prop. */ readonly intent?: string; readonly selected?: boolean; readonly dragging?: boolean; /** `NodeKindSpec.measure`; falls back to the per-kind default table. */ readonly measure?: Partial; /** * "overview" below `overviewZoom` (design §5). Children FADE, they never * unmount, so the box keeps the same height in both modes and React Flow's * ResizeObserver has nothing to chase. */ readonly renderMode?: GraphRenderMode; /** true on a touch surface — widens the port pitch to the press floor. */ readonly coarsePointer?: boolean; /** Rendered inside each port row. Task 1.9 puts the painted disc here. */ readonly renderPort?: (port: GraphNodePort) => ReactNode; readonly children?: ReactNode; } function sidePortOverhang(side: GraphNodePort["side"], framePaddingPx: number) { return side === "right" ? { right: -framePaddingPx } : { left: -framePaddingPx }; } /** * Fire `updateNodeInternals` for this node when, and only when, its `ports` * array identity changes. Never on mount: React Flow measures a fresh node * itself, so a mount-time call is a redundant forced layout. */ function usePortInternals(id: string, ports: readonly GraphNodePort[] | undefined) { const updateNodeInternals = useUpdateNodeInternals(); const first = useRef(true); useEffect(() => { if (first.current) { first.current = false; return; } updateNodeInternals(id); }, [id, ports, updateNodeInternals]); } export function GraphNode({ id, title, subtitle, ports, intent, selected = false, dragging = false, measure, renderMode = "detail", coarsePointer = false, renderPort, children, }: GraphNodeProps) { // `useGraphNodeKnobs`, not `useResolvedKnobs` directly: it is task 1.6's ONE // node knob call site, so a §11 law gets added in one place rather than per // node kind. It resolves through the same real Preset / Surface / Intent // stack, which is what `KnobEnvelopeProvider` rebuilds inside the WebView — // so this component needs no native branch (design §6.1). const { knobProps, control } = useGraphNodeKnobs({ intent, selected, dragging }); usePortInternals(id, ports); const size = graphNodeSize(knobProps.sizeToken); const portSpacingPx = portSpacing({ coarsePointer }); // §7.1 H6: the disc sits ON the frame edge. Each port mounts in a // zero-width anchor offset back out through the frame's padding, so React // Flow's `left: 0` / `right: 0` lands on the edge while the label keeps its // place. Inset by the padding, every arrowhead ended on the node body and // the body painted over it (FZ-9012). const framePaddingPx = panelPaddingPx(); const width = graphNodeWidth({ size, measure }); const minHeight = graphNodeMinHeight({ size, ports: ports ?? [], portSpacingPx, measure }); // The px the frame paints, read off the SAME fragment it is styled from. const radiusPx = containerRadiusPx(knobProps.containerRadius.borderRadius); const overview = isOverview(renderMode); // ZERO, never `display: none` and never an unmount. Children at opacity 0 // are still laid out and still hold the box open, so the node's height is // the same number in both modes and React Flow's per-node ResizeObserver has // nothing to chase across a zoom tick. Design §5, and it is the invariant // `lod.spec.tsx` exists for. const fade = detailOpacity(renderMode); return ( {/* `label` ALONE, and deliberately not `{...knobProps.heading}` before it. Measured in the MPO-191 knob fuzz: `label` carries `fontFamily: bodyFontValue` (resolveKnobs.ts:648-652) and `heading` carries the heading family, so spreading heading first and label second made the title paint the BODY face while the source read as if it painted the heading one. The rendered result was right — design §11 declares this ink honours `bodyFont` — but only by spread order, and a reorder would have flipped a documented law silently. One fragment, one law. `GraphNode.spec.tsx` pins that `headingFont` does not move it. */} {title} {selected ? : null} {subtitle ? ( {subtitle} ) : null} {ports?.length ? ( {ports.map((port) => ( {renderPort && (port.side === "top" || port.side === "bottom") ? renderPort(port) : null} {renderPort && (port.side === "left" || port.side === "right") ? ( {renderPort(port)} ) : null} {port.label ?? port.id} ))} ) : null} {/* Wrapped, and the wrapper is present in BOTH modes. Rendering `{children}` bare and switching it off in overview is what the previous version did, and an unmount collapses the box — which is the one thing design §5 forbids, because React Flow's observer then reports a new height and every edge attached to this node moves. */} {children ? ( {children} ) : null} ); }