{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-approval",
  "title": "RetroApproval",
  "description": "A Mac OS 9 caution alert asking the user to allow or deny an AI tool call, with Option-click to always allow.",
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-ai.json",
    "https://nostalgia-ui.com/r/retro-alert-dialog.json",
    "https://nostalgia-ui.com/r/retro-button.json",
    "https://nostalgia-ui.com/r/retro-collapsible.json",
    "https://nostalgia-ui.com/r/retro-icons.json",
    "https://nostalgia-ui.com/r/retro-motion.json",
    "https://nostalgia-ui.com/r/retro-tool-call.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-approval.tsx",
      "content": "\"use client\"\n\n/*\n * RetroApproval: an OS 9 caution alert that sits in the transcript (not a\n * modal) and asks whether the assistant may run a tool.\n *\n *   ⚠  Allow the assistant to move 12 files?\n *      They'll go from the Desktop into “Old Stuff”.\n *      ▸ Show Details\n *                                   [Don't Allow]  ((Allow))\n *\n * Holding Option turns Allow into Always Allow, as Option did to Finder\n * commands. Return allows and Escape (or ⌘-period) doesn't, while the card\n * has focus; it takes focus when it appears. Once answered, the alert's frame\n * morphs down into a one-line receipt: \"Allowed\" or \"Denied\".\n *\n * Crafted moment: the entrance. Given an `anchorRef` (usually the tool row\n * that asked), zoom rects fly from it to the card, the way an OS 9 alert grew\n * out of whatever raised it; without one the card fades up 4px in 160ms.\n * Classic flair steps the rects and drops the fade; reduced motion shows the\n * card at once.\n *\n * RetroApprovalDialog asks the same question as a blocking modal alert.\n */\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport type { RetroToolPart } from \"@/registry/new-york/lib/retro-ai\"\nimport {\n  EASE_OUT_STRONG,\n  motionOff,\n  playZoomRects,\n  prefersReducedMotion,\n  useMergedRef,\n} from \"@/registry/new-york/lib/retro-motion\"\nimport {\n  RetroAlertDialog,\n  RetroAlertDialogAction,\n  RetroAlertDialogBody,\n  RetroAlertDialogCancel,\n  RetroAlertDialogContent,\n  RetroAlertDialogDescription,\n  RetroAlertDialogFooter,\n  RetroAlertDialogTitle,\n} from \"@/registry/new-york/ui/retro-alert-dialog\"\nimport { RetroButton } from \"@/registry/new-york/ui/retro-button\"\nimport {\n  RetroCollapsible,\n  RetroCollapsibleContent,\n  RetroCollapsibleTrigger,\n} from \"@/registry/new-york/ui/retro-collapsible\"\nimport { RetroIconAlert } from \"@/registry/new-york/ui/retro-icons\"\nimport { RetroToolStatusIcon, toolTitle } from \"@/registry/new-york/ui/retro-tool-call\"\n\n/* ------------------------------------------------------------------ */\n/*  Shared                                                             */\n/* ------------------------------------------------------------------ */\n\ntype RetroApprovalStatus = \"pending\" | \"allowed\" | \"denied\"\n\n/** Reads the answer off a tool part, if the part has one yet. */\nfunction approvalStatusOf(part: RetroToolPart | undefined): RetroApprovalStatus | undefined {\n  if (!part) return undefined\n  if (part.state === \"approval-requested\") return \"pending\"\n  if (part.state === \"output-denied\") return \"denied\"\n  if (part.approval?.approved === true) return \"allowed\"\n  if (part.approval?.approved === false) return \"denied\"\n  return undefined\n}\n\n/** True while Option (Alt) is held anywhere in the window. */\nfunction useOptionKey(active = true) {\n  const [held, setHeld] = React.useState(false)\n  React.useEffect(() => {\n    if (!active) return\n    const onKey = (e: KeyboardEvent) => setHeld(e.altKey)\n    const onBlur = () => setHeld(false)\n    window.addEventListener(\"keydown\", onKey)\n    window.addEventListener(\"keyup\", onKey)\n    window.addEventListener(\"blur\", onBlur)\n    return () => {\n      window.removeEventListener(\"keydown\", onKey)\n      window.removeEventListener(\"keyup\", onKey)\n      window.removeEventListener(\"blur\", onBlur)\n    }\n  }, [active])\n  return active && held\n}\n\n/** \"Allow\" and \"Always Allow\" share one cell, so the button never changes width. */\nfunction AllowLabel({ always }: { always: boolean }) {\n  return (\n    <span className=\"grid justify-items-center\">\n      <span className={cn(\"col-start-1 row-start-1\", always && \"invisible\")}>Allow</span>\n      <span className={cn(\"col-start-1 row-start-1\", !always && \"invisible\")}>Always Allow</span>\n    </span>\n  )\n}\n\n/** \"Show Details\" disclosure over a list (or any node) of what will happen. */\nfunction ApprovalDetails({ details }: { details: React.ReactNode | string[] }) {\n  const [open, setOpen] = React.useState(false)\n  return (\n    <RetroCollapsible open={open} onOpenChange={setOpen} className=\"mt-1\">\n      <RetroCollapsibleTrigger className=\"text-[11px] -ml-px\">\n        {open ? \"Hide Details\" : \"Show Details\"}\n      </RetroCollapsibleTrigger>\n      <RetroCollapsibleContent className=\"pl-0 pt-1.5 text-[11px]\">\n        {Array.isArray(details) ? (\n          <ul className=\"os9-inset m-0 max-h-[132px] list-none overflow-auto px-2 py-1.5 leading-[1.5]\">\n            {details.map((line, i) => (\n              <li key={i} className=\"flex gap-1.5\">\n                <span aria-hidden=\"true\" className=\"text-os9-gray-700\">\n                  •\n                </span>\n                <span className=\"min-w-0 break-words\">{line}</span>\n              </li>\n            ))}\n          </ul>\n        ) : (\n          <div className=\"os9-inset max-h-[132px] overflow-auto px-2 py-1.5 leading-[1.5]\">{details}</div>\n        )}\n      </RetroCollapsibleContent>\n    </RetroCollapsible>\n  )\n}\n\nconst ENTER_CSS = `\n@keyframes os9-approval-rise { from { opacity: 0; transform: translateY(4px); } }\n.os9-approval-enter { animation: os9-approval-rise 160ms cubic-bezier(0.23, 1, 0.32, 1) both; }\n[data-flair=\"classic\"] .os9-approval-enter { animation: none; }\n@media (prefers-reduced-motion: reduce) { .os9-approval-enter { animation: none; } }\n`\n\n/* ------------------------------------------------------------------ */\n/*  RetroApproval (inline)                                             */\n/* ------------------------------------------------------------------ */\n\ninterface RetroApprovalProps\n  extends Omit<React.ComponentProps<\"div\">, \"title\" | \"children\" | \"onKeyDown\" | \"part\"> {\n  /** The tool call asking for permission. Its approval state sets the status when `status` isn't given. */\n  part?: RetroToolPart\n  /** The question. Defaults to “Allow the assistant to use <tool>?” when a part is given. */\n  title?: React.ReactNode\n  description?: React.ReactNode\n  /** What will happen, behind a “Show Details” disclosure. An array renders as a list. */\n  details?: React.ReactNode | string[]\n  /** `always` is true when the person held Option (Always Allow). */\n  onApprove: (always: boolean) => void\n  onDeny: () => void\n  /** Controls the card: pending shows the alert, allowed/denied the receipt. */\n  status?: RetroApprovalStatus\n  /** Zoom rects fly from this element (e.g. the tool row) when the card appears. */\n  anchorRef?: React.RefObject<HTMLElement | null>\n  /** Take focus when the card appears, so Return and Escape answer it. Default true. */\n  autoFocus?: boolean\n}\n\nfunction RetroApproval({\n  part,\n  title,\n  description,\n  details,\n  onApprove,\n  onDeny,\n  status: statusProp,\n  anchorRef,\n  autoFocus = true,\n  className,\n  ref,\n  ...props\n}: RetroApprovalProps) {\n  /* the person's answer shows at once, before the app catches up */\n  const [answer, setAnswer] = React.useState<\"allowed\" | \"always\" | \"denied\" | null>(null)\n  const external = statusProp ?? approvalStatusOf(part) ?? \"pending\"\n  const status: RetroApprovalStatus =\n    external === \"pending\" && answer ? (answer === \"denied\" ? \"denied\" : \"allowed\") : external\n  const pending = status === \"pending\"\n  const always = useOptionKey(pending)\n\n  const frameRef = React.useRef<HTMLDivElement | null>(null)\n  const mergedRef = useMergedRef(ref, frameRef)\n  const question = title ?? (part ? `Allow the assistant to use “${toolTitle(part)}”?` : \"Allow this action?\")\n  const titleId = React.useId()\n  const descId = React.useId()\n\n  /* ── entrance: zoom rects from the anchor, else fade + rise ── */\n  const mountedPending = React.useRef(pending)\n  React.useLayoutEffect(() => {\n    const el = frameRef.current\n    if (!el || !mountedPending.current) return\n    const anchor = anchorRef?.current\n    if (anchor?.isConnected && !prefersReducedMotion()) {\n      el.style.opacity = \"0\"\n      const raf = requestAnimationFrame(() => {\n        void playZoomRects(anchor.getBoundingClientRect(), el.getBoundingClientRect(), anchor).then(() => {\n          el.style.opacity = \"\"\n        })\n      })\n      return () => {\n        cancelAnimationFrame(raf)\n        el.style.opacity = \"\"\n      }\n    }\n    el.classList.add(\"os9-approval-enter\")\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [])\n\n  React.useEffect(() => {\n    if (autoFocus && mountedPending.current) frameRef.current?.focus({ preventScroll: true })\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [])\n\n  /* ── answered: the frame morphs from the alert's height to the receipt's ── */\n  const cardHeight = React.useRef(0)\n  const hadFocus = React.useRef(false)\n  React.useEffect(() => {\n    const el = frameRef.current\n    if (!el || !pending) return\n    const ro = new ResizeObserver(() => {\n      cardHeight.current = el.offsetHeight\n    })\n    ro.observe(el)\n    return () => ro.disconnect()\n  }, [pending])\n\n  React.useLayoutEffect(() => {\n    const el = frameRef.current\n    const from = cardHeight.current\n    if (!el || pending) return\n    /* the buttons are gone: keep focus on the receipt rather than dropping it to <body> */\n    if (hadFocus.current) el.focus({ preventScroll: true })\n    hadFocus.current = false\n    if (!from || motionOff(el)) return\n    const to = el.offsetHeight\n    cardHeight.current = 0\n    const anim = el.animate([{ height: `${from}px` }, { height: `${to}px` }], {\n      duration: 180,\n      easing: EASE_OUT_STRONG,\n    })\n    return () => anim.cancel()\n  }, [pending])\n\n  const decide = (allow: boolean, alwaysAllow = false) => {\n    if (!pending) return\n    const el = frameRef.current\n    if (el) {\n      cardHeight.current = el.offsetHeight\n      hadFocus.current = el.contains(document.activeElement)\n    }\n    if (allow) {\n      setAnswer(alwaysAllow ? \"always\" : \"allowed\")\n      onApprove(alwaysAllow)\n    } else {\n      setAnswer(\"denied\")\n      onDeny()\n    }\n  }\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    if (!pending) return\n    const cancel = e.key === \"Escape\" || (e.key === \".\" && (e.metaKey || e.ctrlKey))\n    if (cancel) {\n      e.preventDefault()\n      e.stopPropagation()\n      decide(false)\n      return\n    }\n    /* Return answers, unless a button inside the card has focus (it answers itself) */\n    const target = e.target as HTMLElement\n    const onAllow = target.closest(\"[data-approval-allow]\")\n    if (e.key === \"Enter\" && !e.shiftKey && (onAllow || !target.closest(\"button, a, input, textarea, select\"))) {\n      e.preventDefault()\n      decide(true, e.altKey)\n    }\n  }\n\n  return (\n    <div\n      ref={mergedRef}\n      tabIndex={-1}\n      role={pending ? \"alertdialog\" : \"status\"}\n      aria-labelledby={pending ? titleId : undefined}\n      aria-describedby={pending && description ? descId : undefined}\n      data-retro-approval=\"\"\n      data-status={status}\n      onKeyDown={onKeyDown}\n      className={cn(\n        \"w-full overflow-hidden border border-os9-black bg-os9-gray-200 text-os9-black outline-none\",\n        \"shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_var(--os9-gray-500)]\",\n        pending && \"focus-visible:os9-focus-ring\",\n        className\n      )}\n      {...props}\n    >\n      <style href=\"os9-approval\" precedence=\"default\">\n        {ENTER_CSS}\n      </style>\n      {pending ? (\n        <div className=\"flex gap-3 p-3 pr-2 pb-1.5\">\n          <RetroIconAlert className=\"mt-px\" />\n          <div className=\"flex min-w-0 flex-1 flex-col\">\n            <p\n              id={titleId}\n              className=\"m-0 font-[family-name:var(--os9-font-heading)] text-[12px] tracking-[0.42px] leading-[1.3]\"\n            >\n              {question}\n            </p>\n            {description && (\n              <p\n                id={descId}\n                className=\"m-0 mt-1 font-[family-name:var(--os9-font-sans)] text-[12px] leading-[1.5]\"\n              >\n                {description}\n              </p>\n            )}\n            {details != null && <ApprovalDetails details={details} />}\n            <div className=\"mt-1.5 flex flex-wrap items-center justify-end gap-x-2\">\n              <RetroButton type=\"button\" onClick={() => decide(false)}>\n                Don&apos;t Allow\n              </RetroButton>\n              <RetroButton\n                type=\"button\"\n                isDefault\n                data-approval-allow=\"\"\n                onClick={(e) => decide(true, e.altKey || always)}\n              >\n                <AllowLabel always={always} />\n              </RetroButton>\n            </div>\n          </div>\n        </div>\n      ) : (\n        <div className=\"flex h-[24px] min-w-0 items-center gap-[6px] px-[6px]\">\n          <RetroToolStatusIcon status={status === \"denied\" ? \"denied\" : \"done\"} />\n          <span className=\"shrink-0 font-[family-name:var(--os9-font-heading)] text-[12px] tracking-[0.42px] leading-none\">\n            {status === \"denied\" ? \"Denied\" : answer === \"always\" ? \"Always Allowed\" : \"Allowed\"}\n          </span>\n          <span className=\"min-w-0 truncate font-[family-name:var(--os9-font-sans)] text-[10px] leading-none text-os9-gray-800\">\n            {question}\n          </span>\n        </div>\n      )}\n    </div>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  RetroApprovalDialog (modal)                                        */\n/* ------------------------------------------------------------------ */\n\ninterface RetroApprovalDialogProps {\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  part?: RetroToolPart\n  title?: React.ReactNode\n  description?: React.ReactNode\n  details?: React.ReactNode | string[]\n  onApprove: (always: boolean) => void\n  onDeny: () => void\n  className?: string\n}\n\n/**\n * The same question as a blocking alert, on RetroAlertDialog. Return allows,\n * Escape doesn't, Option turns Allow into Always Allow.\n */\nfunction RetroApprovalDialog({\n  open,\n  defaultOpen,\n  onOpenChange,\n  part,\n  title,\n  description,\n  details,\n  onApprove,\n  onDeny,\n  className,\n}: RetroApprovalDialogProps) {\n  const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false)\n  const shown = open ?? isOpen\n  const always = useOptionKey(shown)\n  const allowRef = React.useRef<HTMLButtonElement | null>(null)\n  const question = title ?? (part ? `Allow the assistant to use “${toolTitle(part)}”?` : \"Allow this action?\")\n\n  return (\n    <RetroAlertDialog\n      open={shown}\n      onOpenChange={(next, details) => {\n        setIsOpen(next)\n        onOpenChange?.(next)\n        if (next) return\n        const value = details.returnValue\n        if (value === \"always\" || value === \"confirm\") onApprove(value === \"always\")\n        else onDeny()\n      }}\n    >\n      <RetroAlertDialogContent\n        className={className}\n        initialFocus={() => allowRef.current}\n        onKeyDown={(e) => {\n          /* Option-Return doesn't press a focused button natively: answer Always Allow */\n          if (e.key === \"Enter\" && e.altKey && !(e.target as HTMLElement).closest(\"[data-slot=alert-dialog-close]:not([data-approval-allow])\")) {\n            e.preventDefault()\n            allowRef.current?.click()\n          }\n        }}\n      >\n        <RetroAlertDialogBody className=\"pt-4\">\n          <RetroAlertDialogTitle className=\"max-w-none whitespace-normal px-0 leading-[1.3]\">\n            {question}\n          </RetroAlertDialogTitle>\n          {description && (\n            <RetroAlertDialogDescription className=\"mt-1.5 text-[12px] leading-[1.5]\">\n              {description}\n            </RetroAlertDialogDescription>\n          )}\n          {details != null && <ApprovalDetails details={details} />}\n        </RetroAlertDialogBody>\n        <RetroAlertDialogFooter className=\"justify-end\">\n          <RetroAlertDialogCancel>Don&apos;t Allow</RetroAlertDialogCancel>\n          <RetroAlertDialogAction ref={allowRef} data-approval-allow=\"\" value={always ? \"always\" : \"confirm\"}>\n            <AllowLabel always={always} />\n          </RetroAlertDialogAction>\n        </RetroAlertDialogFooter>\n      </RetroAlertDialogContent>\n    </RetroAlertDialog>\n  )\n}\n\nexport { RetroApproval, RetroApprovalDialog, approvalStatusOf }\nexport type { RetroApprovalProps, RetroApprovalDialogProps, RetroApprovalStatus }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}