import { useEffect, useRef, type KeyboardEvent } from "react"; import { presentationNodes } from "./workflow-graph-data.js"; type NodeSpotlightProps = { readonly nodeId: string; readonly close: () => void; }; const kindLabel = (node: (typeof presentationNodes)[number]): string => { if (node.type === "interrupt") return "Human boundary"; if (node.type === "end") return "Outcome"; return "Action"; }; export const NodeSpotlight = ({ nodeId, close }: NodeSpotlightProps) => { const dialogRef = useRef(null); const closeButtonRef = useRef(null); const node = presentationNodes.find((candidate) => candidate.id === nodeId); const label = node && "label" in node ? node.label : nodeId === "review_issues" ? "Review issues" : nodeId; useEffect(() => { const previouslyFocused = document.activeElement instanceof HTMLElement ? document.activeElement : null; closeButtonRef.current?.focus(); return () => previouslyFocused?.focus(); }, []); const handleKeyDown = (event: KeyboardEvent) => { if (event.key !== "Tab") return; const focusable = [...(dialogRef.current?.querySelectorAll( "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])", ) ?? [])].filter((element) => !element.hasAttribute("disabled")); if (focusable.length === 0) return; const first = focusable[0]!; const last = focusable[focusable.length - 1]!; if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); } else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } }; if (!node) return null; const schemaSummary = "schemaSummary" in node ? node.schemaSummary : null; return ( ); };