{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-prompt-input",
  "title": "RetroPromptInput",
  "description": "A Mac OS 9 chat composer: an inset edit field that grows with its text, a default Send button that becomes Stop while a reply streams (⌘-period), and slots for attachments and a model picker.",
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-ai.json",
    "https://nostalgia-ui.com/r/retro-button.json",
    "https://nostalgia-ui.com/r/retro-motion.json",
    "https://nostalgia-ui.com/r/retro-textarea.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-prompt-input.tsx",
      "content": "\"use client\"\n\n/*\n * RetroPromptInput: the chat composer. An inset edit field that grows with\n * the draft (one line up to `maxRows`, then it scrolls), a leading toolbar\n * slot for a model picker or an attach button, an attachments row above the\n * field, and the default Send button, which becomes Stop while a reply is on\n * its way.\n *\n *   Return          send            Shift-Return   new line\n *   ⌘-period, Esc   stop a reply    (IME composition is never interrupted)\n *\n * Crafted moment: the key presses the button. When Return sends, the Send\n * button shows its pressed face for a beat before the message goes and the\n * field clears, the way the Mac flashed a dialog's default button when you\n * hit Return; ⌘-period and Escape do the same to Stop. It is OS 9's own\n * feedback, so it plays in both flairs.\n */\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport type { RetroChatStatus, RetroFilePart } from \"@/registry/new-york/lib/retro-ai\"\nimport { useMergedRef } from \"@/registry/new-york/lib/retro-motion\"\nimport { RetroButton } from \"@/registry/new-york/ui/retro-button\"\nimport { RetroTextarea } from \"@/registry/new-york/ui/retro-textarea\"\n\n/* ------------------------------------------------------------------ */\n/*  Shared CSS                                                         */\n/* ------------------------------------------------------------------ */\n\n/* Entering items fade and rise 4px (modern flair only). Shared by the AI\n * components; React hoists it and dedupes it by href. */\nconst RISE_CSS = `\n@keyframes os9-ai-rise { from { opacity: 0; transform: translateY(4px); } }\n.os9-ai-rise { animation: os9-ai-rise 160ms cubic-bezier(0.23, 1, 0.32, 1) both; }\n[data-flair=\"classic\"] .os9-ai-rise { animation: none; }\n@media (prefers-reduced-motion: reduce) { .os9-ai-rise { animation: none; } }\n`\n\n/* ------------------------------------------------------------------ */\n/*  Geometry                                                           */\n/* ------------------------------------------------------------------ */\n\nconst LINE_PX = 18\nconst PAD_Y_PX = 4\nconst BORDER_PX = 1\n/* how long the button holds its pressed face before the command runs\n * (the Mac held it for 8 ticks, ~133ms) */\nconst FLASH_MS = 120\n\n/* the button's pressed face, held by data-flash while a key presses it */\nconst SEND_FLASH =\n  \"data-flash:bg-os9-gray-800 data-flash:text-os9-white data-flash:shadow-[inset_1px_1px_0_var(--os9-gray-700),inset_-1px_-1px_0_var(--os9-white),0_0_0_2px_var(--os9-gray-300),0_0_0_5px_var(--os9-black)]\"\nconst STOP_FLASH =\n  \"data-flash:bg-os9-gray-800 data-flash:text-os9-white data-flash:shadow-[inset_1px_1px_0_var(--os9-gray-700),inset_-1px_-1px_0_var(--os9-white)]\"\n\n/* ------------------------------------------------------------------ */\n/*  RetroPromptInput                                                   */\n/* ------------------------------------------------------------------ */\n\ntype RetroPromptInputProps = Omit<\n  React.ComponentProps<\"form\">,\n  \"onSubmit\" | \"children\" | \"defaultValue\"\n> & {\n  /** The draft (controlled). Pair with `onValueChange`. */\n  value?: string\n  /** The initial draft when uncontrolled. */\n  defaultValue?: string\n  /** Fires on every edit, and with `\"\"` when a sent draft clears. */\n  onValueChange?: (value: string) => void\n  /** Fires with the trimmed draft when Send is pressed (button or Return). */\n  onSubmit?: (text: string) => void\n  /** Fires when Stop is pressed (button, ⌘-period or Escape). */\n  onStop?: () => void\n  /** `useChat` status. `\"submitted\"` and `\"streaming\"` turn Send into Stop. */\n  status?: RetroChatStatus\n  disabled?: boolean\n  placeholder?: string\n  /** Leading controls on the button row: a model picker, an attach button. */\n  toolbar?: React.ReactNode\n  /** Files shown as chips above the field. They let an empty draft send. */\n  attachments?: RetroFilePart[]\n  /** Shows a remove box on each chip. */\n  onAttachmentRemove?: (attachment: RetroFilePart, index: number) => void\n  /** Lines the field grows to before it scrolls. */\n  maxRows?: number\n  autoFocus?: boolean\n  /** Ref to the edit field, e.g. to focus it after filling a suggestion. */\n  inputRef?: React.Ref<HTMLTextAreaElement>\n  /** Accessible name of the edit field. */\n  inputLabel?: string\n  sendLabel?: string\n  stopLabel?: string\n}\n\nfunction RetroPromptInput({\n  value: valueProp,\n  defaultValue = \"\",\n  onValueChange,\n  onSubmit,\n  onStop,\n  status = \"ready\",\n  disabled = false,\n  placeholder = \"Send a message…\",\n  toolbar,\n  attachments,\n  onAttachmentRemove,\n  maxRows = 8,\n  autoFocus,\n  inputRef,\n  inputLabel = \"Message\",\n  sendLabel = \"Send\",\n  stopLabel = \"Stop\",\n  className,\n  ...props\n}: RetroPromptInputProps) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const draft = valueProp ?? inner\n  const busy = status === \"submitted\" || status === \"streaming\"\n  const hasFiles = (attachments?.length ?? 0) > 0\n  const canSend = !disabled && !busy && (draft.trim().length > 0 || hasFiles)\n\n  const fieldRef = React.useRef<HTMLTextAreaElement>(null)\n  const mergedFieldRef = useMergedRef(fieldRef, inputRef)\n\n  /* which button a key is pressing right now */\n  const [flash, setFlash] = React.useState<\"send\" | \"stop\" | null>(null)\n  const flashTimer = React.useRef(0)\n  React.useEffect(() => () => window.clearTimeout(flashTimer.current), [])\n\n  const setDraft = (next: string) => {\n    if (valueProp === undefined) setInner(next)\n    onValueChange?.(next)\n  }\n\n  /* ── grow with the draft, then scroll ── */\n  const fit = React.useCallback(() => {\n    const el = fieldRef.current\n    if (!el) return\n    const max = maxRows * LINE_PX + PAD_Y_PX * 2 + BORDER_PX * 2\n    el.style.height = \"auto\"\n    const needed = el.scrollHeight + BORDER_PX * 2\n    el.style.height = `${Math.min(needed, max)}px`\n    el.style.overflowY = needed > max ? \"auto\" : \"hidden\"\n  }, [maxRows])\n\n  React.useLayoutEffect(fit, [fit, draft])\n\n  React.useEffect(() => {\n    const el = fieldRef.current\n    if (!el || typeof ResizeObserver === \"undefined\") return\n    let width = el.offsetWidth\n    const observer = new ResizeObserver(() => {\n      if (el.offsetWidth === width) return\n      width = el.offsetWidth\n      fit()\n    })\n    observer.observe(el)\n    return () => observer.disconnect()\n  }, [fit])\n\n  /* ── send & stop ── */\n  const press = (which: \"send\" | \"stop\", run: () => void) => {\n    setFlash(which)\n    flashTimer.current = window.setTimeout(() => {\n      setFlash(null)\n      run()\n    }, FLASH_MS)\n  }\n\n  const commit = (text: string) => {\n    onSubmit?.(text)\n    setDraft(\"\")\n    /* Send is about to become Stop; keep focus in the field, not on body */\n    fieldRef.current?.focus()\n  }\n\n  const send = (byKey: boolean) => {\n    if (!canSend || flash) return\n    const text = draft.trim()\n    if (byKey) press(\"send\", () => commit(text))\n    else commit(text)\n  }\n\n  const stop = (byKey: boolean) => {\n    if (!busy || disabled || flash) return\n    if (byKey) press(\"stop\", () => onStop?.())\n    else onStop?.()\n  }\n\n  /* ⌘-period cancels from anywhere on the page while a reply is coming,\n   * like it did in every OS 9 app; Escape only from the composer itself */\n  const stopRef = React.useRef(stop)\n  React.useEffect(() => {\n    stopRef.current = stop\n  })\n  React.useEffect(() => {\n    if (!busy || disabled) return\n    const onKey = (event: KeyboardEvent) => {\n      if ((event.metaKey || event.ctrlKey) && event.key === \".\" && !event.isComposing) {\n        event.preventDefault()\n        stopRef.current(true)\n      }\n    }\n    window.addEventListener(\"keydown\", onKey)\n    return () => window.removeEventListener(\"keydown\", onKey)\n  }, [busy, disabled])\n\n  const onFieldKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n    /* 229: Safari reports the key that ends an IME composition with this */\n    if (event.nativeEvent.isComposing || event.keyCode === 229) return\n    if (event.key === \"Enter\" && !event.shiftKey && !event.altKey) {\n      event.preventDefault()\n      send(true)\n    } else if (event.key === \"Escape\" && busy) {\n      event.preventDefault()\n      stop(true)\n    }\n  }\n\n  const removeAttachment = (attachment: RetroFilePart, index: number) => {\n    onAttachmentRemove?.(attachment, index)\n    fieldRef.current?.focus()\n  }\n\n  return (\n    <form\n      data-slot=\"prompt-input\"\n      data-status={status}\n      data-disabled={disabled || undefined}\n      onSubmit={(event) => {\n        event.preventDefault()\n        send(false)\n      }}\n      className={cn(\n        \"flex flex-col gap-[6px] p-[8px]\",\n        \"border border-os9-black bg-os9-gray-200\",\n        \"shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_var(--os9-gray-500)]\",\n        className\n      )}\n      {...props}\n    >\n      <style href=\"os9-ai-rise\" precedence=\"default\">\n        {RISE_CSS}\n      </style>\n\n      {hasFiles && (\n        <ul aria-label=\"Attachments\" className=\"flex flex-wrap gap-[4px]\">\n          {attachments!.map((file, index) => (\n            <li key={`${file.url}-${index}`} className=\"os9-ai-rise flex min-w-0\">\n              <RetroPromptInputAttachment\n                attachment={file}\n                disabled={disabled}\n                onRemove={\n                  onAttachmentRemove ? () => removeAttachment(file, index) : undefined\n                }\n              />\n            </li>\n          ))}\n        </ul>\n      )}\n\n      <RetroTextarea\n        ref={mergedFieldRef}\n        data-slot=\"prompt-input-field\"\n        rows={1}\n        value={draft}\n        placeholder={placeholder}\n        disabled={disabled}\n        readOnly={flash !== null}\n        autoFocus={autoFocus}\n        aria-label={inputLabel}\n        aria-keyshortcuts={busy ? \"Meta+Period Escape\" : undefined}\n        onChange={(event) => setDraft(event.target.value)}\n        onKeyDown={onFieldKeyDown}\n        className={cn(\n          \"block min-h-0 resize-none overflow-hidden\",\n          \"font-[family-name:var(--os9-font-sans)] text-[12px] leading-[18px] tracking-normal\",\n          \"px-[6px] py-[4px] [overflow-wrap:anywhere]\"\n        )}\n      />\n\n      <div className=\"flex items-center gap-[6px]\">\n        <div\n          data-slot=\"prompt-input-toolbar\"\n          className=\"flex min-w-0 flex-1 items-center gap-[4px]\"\n        >\n          {toolbar}\n        </div>\n        {busy ? (\n          <RetroButton\n            type=\"button\"\n            data-slot=\"prompt-input-stop\"\n            data-flash={flash === \"stop\" ? \"\" : undefined}\n            aria-keyshortcuts=\"Meta+Period Escape\"\n            disabled={disabled}\n            onClick={() => stop(false)}\n            /* the margin keeps Send's ring footprint, so nothing moves */\n            className={cn(\"m-[5px] min-w-[64px] shrink-0\", STOP_FLASH)}\n          >\n            {stopLabel}\n          </RetroButton>\n        ) : (\n          <RetroButton\n            type=\"submit\"\n            isDefault\n            data-slot=\"prompt-input-send\"\n            data-flash={flash === \"send\" ? \"\" : undefined}\n            disabled={!canSend}\n            className={cn(\"min-w-[64px] shrink-0\", SEND_FLASH)}\n          >\n            {sendLabel}\n          </RetroButton>\n        )}\n      </div>\n    </form>\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/*  Attachment chip                                                    */\n/* ------------------------------------------------------------------ */\n\nfunction DocumentGlyph({ image }: { image: boolean }) {\n  return (\n    <svg\n      width=\"12\"\n      height=\"12\"\n      viewBox=\"0 0 12 12\"\n      aria-hidden=\"true\"\n      shapeRendering=\"crispEdges\"\n      className=\"shrink-0\"\n    >\n      <path d=\"M1.5 0.5H7.5L10.5 3.5V11.5H1.5Z\" fill=\"var(--os9-white)\" stroke=\"currentColor\" />\n      <path d=\"M7.5 0.5V3.5H10.5\" fill=\"none\" stroke=\"currentColor\" />\n      {image ? (\n        <>\n          <path d=\"M3 10L5 7L6.5 8.5L7.5 7.5L9 10Z\" fill=\"currentColor\" />\n          <rect x=\"3\" y=\"4\" width=\"2\" height=\"2\" fill=\"currentColor\" />\n        </>\n      ) : (\n        <path d=\"M3 5.5H8M3 7.5H9M3 9.5H7\" stroke=\"currentColor\" />\n      )}\n    </svg>\n  )\n}\n\ntype RetroPromptInputAttachmentProps = Omit<React.ComponentProps<\"span\">, \"children\"> & {\n  attachment: RetroFilePart\n  /** Shows the remove box. */\n  onRemove?: () => void\n  disabled?: boolean\n}\n\n/* A small file chip: a document glyph, the name, and a close-box style\n * remove button. Rendered by RetroPromptInput for `attachments`, exported\n * for custom rows. */\nfunction RetroPromptInputAttachment({\n  attachment,\n  onRemove,\n  disabled,\n  className,\n  ...props\n}: RetroPromptInputAttachmentProps) {\n  const name = attachment.filename ?? \"Untitled\"\n  return (\n    <span\n      data-slot=\"prompt-input-attachment\"\n      title={name}\n      className={cn(\n        \"inline-flex h-[20px] max-w-[200px] min-w-0 items-center gap-[4px] pl-[4px]\",\n        onRemove ? \"pr-[3px]\" : \"pr-[6px]\",\n        \"border border-os9-black bg-os9-white text-os9-black\",\n        \"font-[family-name:var(--os9-font-sans)] text-[10px] leading-none\",\n        className\n      )}\n      {...props}\n    >\n      <DocumentGlyph image={attachment.mediaType.startsWith(\"image/\")} />\n      <span className=\"min-w-0 truncate\">{name}</span>\n      {onRemove && (\n        <button\n          type=\"button\"\n          aria-label={`Remove ${name}`}\n          disabled={disabled}\n          onClick={onRemove}\n          className={cn(\n            \"ml-[2px] flex size-[12px] shrink-0 items-center justify-center\",\n            \"border border-os9-black bg-os9-gray-300 text-os9-black\",\n            \"shadow-[inset_1px_1px_0_var(--os9-white),inset_-1px_-1px_0_var(--os9-gray-600)]\",\n            \"cursor-pointer outline-none focus-visible:os9-focus-ring\",\n            \"active:bg-os9-gray-800 active:text-os9-white active:shadow-none\",\n            \"disabled:pointer-events-none disabled:opacity-50\"\n          )}\n        >\n          <svg width=\"6\" height=\"6\" viewBox=\"0 0 6 6\" aria-hidden=\"true\" shapeRendering=\"crispEdges\">\n            <path\n              d=\"M0 0h1v1H0zM5 0h1v1H5zM1 1h1v1H1zM4 1h1v1H4zM2 2h2v2H2zM1 4h1v1H1zM4 4h1v1H4zM0 5h1v1H0zM5 5h1v1H5z\"\n              fill=\"currentColor\"\n            />\n          </svg>\n        </button>\n      )}\n    </span>\n  )\n}\n\nexport { RetroPromptInput, RetroPromptInputAttachment }\nexport type { RetroPromptInputProps, RetroPromptInputAttachmentProps }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}