{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "composer",
  "title": "Composer",
  "description": "A chat message box: text that grows from one line as the person writes, a send button, and room for the rest of a composer, in one frame with one focus outline.",
  "registryDependencies": [
    "@ouro/button",
    "@ouro/emoji",
    "@ouro/kbd",
    "@ouro/lib-announce",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-insert-text",
    "@ouro/lib-key-shortcuts",
    "@ouro/lib-refs",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-platform",
    "@ouro/text-area",
    "@ouro/tooltip"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/composer/composer-styles.ts",
      "content": "import type { ComposerFormat } from \"@/registry/ouro/components/ouro/composer/composer\";\n\nexport { composerShortcuts, formatEdit, isApple, markFormats, pressed };\nexport type { ComposerEdit };\n\n// The text edits and keys Composer's formatting uses, apart from the component so its file\n// exports only components and types (React Fast Refresh).\n\n/**\n * Teams' keys for Composer's formats and its expand button, as `Kbd` and Toolbar's `shortcut`\n * take them: `mod` is ⌘ on Apple platforms and Ctrl elsewhere. Give them to your toolbar's\n * entries so their tooltips show them: `shortcut: composerShortcuts.bold`.\n *\n * @example\n * { label: \"Bold\", icon: BoldIcon, hideLabel: true, shortcut: composerShortcuts.bold, onClick: () => editor.current?.format(\"bold\") }\n */\nconst composerShortcuts = {\n  bold: [\"mod\", \"b\"],\n  italic: [\"mod\", \"i\"],\n  underline: [\"mod\", \"u\"],\n  strike: [\"mod\", \"alt\", \"x\"],\n  code: [\"mod\", \"shift\", \"c\"],\n  expand: [\"mod\", \"shift\", \"x\"],\n} as const satisfies Record<string, readonly string[]>;\n\n/** The formats that wrap the selection in a mark, which the keys apply. */\nconst markFormats = [\"bold\", \"italic\", \"underline\", \"strike\", \"code\"] as const;\n\n/**\n * The marks Composer writes for each, light Markdown that the app renders.\n * @claim \"The marks Composer writes for each\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > applies Teams' formatting keys, and takes each back with Undo and gives it again with Redo)\n */\nconst marks: Readonly<Record<(typeof markFormats)[number], string>> = { bold: \"**\", italic: \"_\", underline: \"++\", strike: \"~~\", code: \"`\" };\n\n/**\n * One change to the text: `text` replaces the text from `from` to `to`, then `start` to `end`\n * (in the new text) is selected. A format is one change, so one Undo takes it back.\n *\n * @internal\n */\ninterface ComposerEdit {\n  from: number;\n  to: number;\n  text: string;\n  start: number;\n  end: number;\n}\n\n/**\n * The change a format makes to `value` with `start` to `end` selected: a mark around the\n * selection, or taken away when it is there already; list or quote markers on the selected lines,\n * or taken away; or a code block around them.\n *\n * @internal\n */\nfunction formatEdit(value: string, start: number, end: number, format: ComposerFormat): ComposerEdit {\n  if (format === \"codeBlock\") return codeBlockEdit(value, start, end);\n  if (format === \"bullets\" || format === \"numbers\" || format === \"quote\") return linesEdit(value, start, end, format);\n  return markEdit(value, start, end, marks[format]);\n}\n\n/** Wraps the selection in `mark`, or unwraps it; spaces at its ends stay outside the marks, or they would not read as formatting. */\nfunction markEdit(value: string, start: number, end: number, mark: string): ComposerEdit {\n  const n = mark.length;\n  const selected = value.slice(start, end);\n  if (value.slice(Math.max(0, start - n), start) === mark && value.slice(end, end + n) === mark) {\n    return { from: start - n, to: end + n, text: selected, start: start - n, end: end - n };\n  }\n  if (selected.length > 2 * n && selected.startsWith(mark) && selected.endsWith(mark)) {\n    return { from: start, to: end, text: selected.slice(n, -n), start, end: end - 2 * n };\n  }\n  const core = selected.trim();\n  if (core === \"\") return { from: end, to: end, text: mark + mark, start: end + n, end: end + n };\n  const from = start + selected.indexOf(core);\n  return { from, to: from + core.length, text: mark + core + mark, start: from + n, end: from + n + core.length };\n}\n\nconst lineMarkers = { bullets: /^- /, numbers: /^\\d+\\. /, quote: /^> / } as const;\n\n/**\n * Puts list or quote markers on the selected lines, numbering a numbered list, or takes them away when every line has one.\n * @claim \"Puts list or quote markers on\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > marks the selected lines as a list or quote, numbering them, and takes the markers away when every line has one)\n */\nfunction linesEdit(value: string, start: number, end: number, kind: keyof typeof lineMarkers): ComposerEdit {\n  const from = value.slice(0, start).lastIndexOf(\"\\n\") + 1;\n  // A selection that ends just after a line break ends on the line before it; one that ends inside a line finds the same break from a step back.\n  const last = end > start ? end - 1 : end;\n  const next = value.indexOf(\"\\n\", last);\n  const to = next < 0 ? value.length : next;\n  const lines = value.slice(from, to).split(\"\\n\");\n  const written = lines.filter((line) => line.trim() !== \"\");\n  const off = written.length > 0 && written.every((line) => lineMarkers[kind].test(line));\n  let count = 0;\n  const text = lines\n    .map((line) => {\n      if (off) return line.replace(lineMarkers[kind], \"\");\n      if (line.trim() === \"\" && lines.length > 1) return line;\n      count += 1;\n      const marker = kind === \"bullets\" ? \"- \" : kind === \"numbers\" ? `${count}. ` : \"> \";\n      return marker + line.replace(/^(?:- |\\d+\\. |> )/, \"\");\n    })\n    .join(\"\\n\");\n  return { from, to, text, start: from, end: from + text.length };\n}\n\n/** Fences the selection as a code block, on lines of its own. */\nfunction codeBlockEdit(value: string, start: number, end: number): ComposerEdit {\n  const open = `${start > 0 && value[start - 1] !== \"\\n\" ? \"\\n\" : \"\"}\\`\\`\\`\\n`;\n  const close = `\\n\\`\\`\\`${end < value.length && value[end] !== \"\\n\" ? \"\\n\" : \"\"}`;\n  const selected = value.slice(start, end);\n  return { from: start, to: end, text: open + selected + close, start: start + open.length, end: start + open.length + selected.length };\n}\n\n/** Whether the platform's command key is ⌘ (macOS, iOS, iPadOS) rather than Ctrl. */\nfunction isApple(): boolean {\n  const nav = navigator as Navigator & { userAgentData?: { platform?: string } };\n  return /mac|iphone|ipad|ipod|ios/i.test(nav.userAgentData?.platform ?? nav.platform);\n}\n\n/**\n * Whether a key press is exactly the shortcut: its modifiers and no others, and its letter by\n * the physical key, so Option on a Mac, which changes the character, still matches.\n * @claim \"Whether a key press is exactly\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > lists the keys for a toolbar's tooltips, and reads a press only with exactly its modifiers)\n */\nfunction pressed(event: Pick<KeyboardEvent, \"code\" | \"metaKey\" | \"ctrlKey\" | \"altKey\" | \"shiftKey\">, keys: readonly string[], apple: boolean): boolean {\n  const mod = keys.includes(\"mod\");\n  return (\n    event.metaKey === (mod && apple) &&\n    event.ctrlKey === (mod && !apple) &&\n    event.altKey === keys.includes(\"alt\") &&\n    event.shiftKey === keys.includes(\"shift\") &&\n    event.code === `Key${keys.at(-1)!.toUpperCase()}`\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/composer/composer-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/composer/composer.tsx",
      "content": "\"use client\";\n\nimport { Children, useEffect, useId, useImperativeHandle, useLayoutEffect, useRef, useState } from \"react\";\nimport type { ClipboardEvent, JSX, KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref, TextareaHTMLAttributes } from \"react\";\nimport { Button } from \"@/registry/ouro/components/ouro/button/button\";\nimport { composerShortcuts, formatEdit, isApple, markFormats, pressed } from \"@/registry/ouro/components/ouro/composer/composer-styles\";\nimport type { EmojiCatalogue } from \"@/registry/ouro/components/ouro/emoji/emoji\";\nimport { emojiTextToTokens } from \"@/registry/ouro/components/ouro/emoji/emoji-styles\";\nimport { Kbd } from \"@/registry/ouro/components/ouro/kbd/kbd\";\nimport { TextArea, type TextAreaHighlight } from \"@/registry/ouro/components/ouro/text-field/text-area\";\nimport { Tooltip } from \"@/registry/ouro/components/ouro/tooltip/tooltip\";\nimport { announce } from \"@/registry/ouro/lib/ouro/announce\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { insertText } from \"@/registry/ouro/lib/ouro/insert-text\";\nimport { ariaKeyShortcuts } from \"@/registry/ouro/lib/ouro/key-shortcuts\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { usePlatform } from \"@/registry/ouro/lib/ouro/use-platform\";\n\n/** What sent the message: the Enter key in the box, or a press of the send button. */\nexport type ComposerSendEvent = KeyboardEvent<HTMLTextAreaElement> | MouseEvent<HTMLButtonElement>;\n\n/** The message a reply quotes, for Composer's `quote`: who wrote it and a line of what they wrote. */\nexport interface ComposerQuote {\n  /** Who wrote the quoted message: \"Ana Lind\", or \"You\". */\n  author: string;\n  /**\n   * What they wrote, or its start. One line shows, cut with an ellipsis.\n   * @claim \"One line shows, cut with\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > shows the quote inside the frame above the text: a bar, the author in semibold and the excerpt on one line, cut with an ellipsis)\n   */\n  excerpt: string;\n  /**\n   * What the quote shows in place of `author`, when plain text cannot draw it: a name with its\n   * emoji as pictures (`<EmojiText text={name} catalogue={catalogue} />`). `author` stays the\n   * name in the remove button's and screen readers' words.\n   *\n   * @claim \"What the quote shows in place of `author`\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > shows authorContent and excerptContent in place of the author and the excerpt, while screen readers hear the text)\n   */\n  authorContent?: ReactNode;\n  /**\n   * What the quote shows in place of `excerpt`, when plain text cannot draw it: the line with its\n   * emoji as pictures (`<EmojiText text={line} catalogue={catalogue} />`), on one line, cut with an\n   * ellipsis. `excerpt` stays what screen readers hear.\n   *\n   * @claim \"What the quote shows in place of `excerpt`\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > shows authorContent and excerptContent in place of the author and the excerpt, while screen readers hear the text)\n   */\n  excerptContent?: ReactNode;\n  /** The author's picture, before the name: an `Avatar` element, `<Avatar name=\"Ana\" src={url} alt=\"\" size=\"xs\" />`. */\n  avatar?: ReactElement | undefined;\n  /** Removes the quote: called by the remove button, and by Escape while the box is empty. Set `quote` to `undefined` in it. */\n  onRemove: () => void;\n  /** Makes the quote a button that shows the quoted message, as by scrolling to it. */\n  onActivate?: (() => void) | undefined;\n  /** What screen readers hear in place of the author's name, before the excerpt. @default `Quoting ${author}` */\n  label?: string | undefined;\n  /** The remove button's name, which its tooltip shows too. @default `Remove quote from ${author}` */\n  removeLabel?: string | undefined;\n}\n\n/**\n * A format Composer applies to the selected text, as light Markdown: `bold` (`**`), `italic`\n * (`_`), `underline` (`++`), `strike` (`~~`) and `code` (a backtick) wrap it in marks, `bullets`,\n * `numbers` and `quote` mark its lines, and `codeBlock` fences them.\n */\nexport type ComposerFormat = \"bold\" | \"italic\" | \"underline\" | \"strike\" | \"code\" | \"bullets\" | \"numbers\" | \"quote\" | \"codeBlock\";\n\n/** What an app's formatting bar, emoji button or link dialog changes the text with: `editorRef`. */\nexport interface ComposerEditor {\n  /** Applies a format to the selection, or takes it away when the selection has it already. */\n  format: (format: ComposerFormat) => void;\n  /** Puts text in place of the selection, or at the caret: an emoji, a link. */\n  insert: (text: string) => void;\n}\n\n/** The props Composer adds to the `<textarea>` attributes it passes through. */\nexport interface ComposerOwnProps {\n  /**\n   * What the message box is for, read as its name: \"Message Mia\", \"Reply in thread\". Required:\n   * the box shows `placeholder`, which is not a label.\n   */\n  label: string;\n  /**\n   * Called with the text when the person sends: Enter in the box (see `sendOn`) or the send\n   * button. The event says which, and `event.isTrusted` that a person did it. It is not called\n   * while the text is blank (unless there are `attachments`), while `sending`, or with\n   * `sendDisabledReason` set. Without `value`, the box clears after it.\n   */\n  onSend: (text: string, event: ComposerSendEvent) => void;\n  /** The text, for a controlled composer; pair it with `onValueChange`, and clear it yourself once the message is sent. */\n  value?: string | undefined;\n  /** The starting text, for an uncontrolled composer, which clears itself after a send. */\n  defaultValue?: string | undefined;\n  /** Called with the new text when it changes. */\n  onValueChange?: ((value: string) => void) | undefined;\n  /** An example of what to write, shown on the first line while the box is empty. */\n  placeholder?: string | undefined;\n  /**\n   * Which key sends. `enter`: Enter sends and Shift+Enter starts a new line, as chat apps do.\n   * `mod-enter`: Ctrl+Enter (Command+Enter on a Mac) sends and Enter starts a new line, for\n   * long messages. Enter never sends while an input method is composing a word or while a\n   * suggestion list (`Autocomplete`) is open, and an `expanded` composer sends on Ctrl+Enter.\n   * @default \"enter\"\n   * @claim \"Enter never sends while an input\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer > never sends on the Enter that ends a word an input method is composing)\n   * @claim \"Enter never sends while an input\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > never sends while a suggestion list is open, Ctrl+Enter included)\n   * @claim \"and an `expanded` composer sends on\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > starts a new line on Enter and sends on Ctrl+Enter or Command+Enter, whatever sendOn says)\n   */\n  sendOn?: \"enter\" | \"mod-enter\" | (string & { 'Use \"enter\" (Shift+Enter is a new line) or \"mod-enter\"': never }) | undefined;\n  /** The send button's name, which its tooltip shows too. @default \"Send\" */\n  sendLabel?: string | undefined;\n  /** The message is on its way: the send button shows a spinner, and nothing more sends until it is done. */\n  sending?: boolean | undefined;\n  /** What screen readers hear when `sending` turns on. @default \"Sending\" */\n  sendingLabel?: string | undefined;\n  /**\n   * Sending is off, and why: \"Sending is off while you review the draft\". The person can still\n   * write; the send button is disabled, the reason shows under the box and is read with it,\n   * and pressing Enter says it again. `hideSendDisabledReason` leaves the line out.\n   */\n  sendDisabledReason?: string | undefined;\n  /**\n   * Keeps the `sendDisabledReason` line from being drawn under the box. Sending stays off, the\n   * reason is still the box's description for screen readers, and Enter still says it. For two\n   * composers side by side, so the reason shows under the one being written in only.\n   * @claim \"For two composers side by side\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer states > with hideSendDisabledReason, keeps the reason as the box's description and says it on Enter, but draws no line for it)\n   */\n  hideSendDisabledReason?: boolean | undefined;\n  /** Disables the whole composer: the box and the send button. */\n  disabled?: boolean | undefined;\n  /**\n   * Files waiting to go with the message, shown in a row inside the box under the text:\n   * `Attachment` items with `onRemove`. Pass it only when there are some; with it, the\n   * message can be sent without text.\n   */\n  attachments?: ReactNode;\n  /** A name for the attachments row, for screen readers. @default \"Attachments\" */\n  attachmentsLabel?: string | undefined;\n  /**\n   * The message this one replies to, shown inside the box above the text until it is sent or\n   * removed: a bar, the author, a line of what they wrote and a remove button. Screen readers\n   * hear it as part of the text's description. Escape in the empty box removes it, as the\n   * remove button does, and that Escape goes no further, so a dialog around the composer stays\n   * open. The quote fades in (opacity only, and not at all with reduced motion) and takes no\n   * focus: focus stays in the box. It stays after a send, so clear it in `onSend`.\n   *\n   * @claim \"Screen readers hear it as part\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > describes the text with the quote, so screen readers hear what the reply quotes)\n   * @claim \"Escape in the empty box removes\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > removes the quote on Escape while the box is empty, and that Escape goes no further)\n   * @claim \"Escape in the empty box removes\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > leaves Escape alone while the box has text, while an input method composes, or after the app's onKeyDown prevents it)\n   * @claim \"The quote fades in (opacity\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > fades in with opacity only, and not at all with reduced motion)\n   * @claim \"takes no focus: focus stays in\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > leaves focus in the box when a quote appears)\n   * @claim \"It stays after a send, so\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer quote > stays after a send until the app clears it)\n   */\n  quote?: ComposerQuote | undefined;\n  /** Buttons before the send button: emoji, attach a file, show formatting. Ouro `Button`s with `variant=\"plain\"` and an `aria-label`. */\n  actions?: ReactNode;\n  /**\n   * Tools shown above the text, inside the box: a formatting bar. In a composer that expands, it\n   * shows only while expanded; otherwise pass it only while it should show.\n   */\n  toolbar?: ReactNode;\n  /** A quiet line under the box, read as the text's description: what the marks mean, a character count. */\n  description?: ReactNode;\n  /**\n   * An image emoji catalogue. With it, an emoji typed into the box (from the system's emoji\n   * panel, say) or pasted goes in as its `:shortcode:` token, the token `Autocomplete` and\n   * `EmojiPicker` insert, so the text holds the catalogue's emoji only as tokens, which\n   * `EmojiText` draws as its images. That includes an emoji joined from others and one with a\n   * skin tone, which become the catalogue's emoji or tone for it; an emoji the catalogue does\n   * not list stays as it is. The caret lands after what went in, and one undo takes it out.\n   *\n   * @claim \"goes in as its `:shortcode:` token\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer with a catalogue > puts a typed emoji in as its token, with the caret after it, in one step undo takes out)\n   * @claim \"or pasted goes in as its\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer with a catalogue > puts pasted emoji in as their tokens, including joined and toned ones, and leaves those it does not list)\n   */\n  catalogue?: EmojiCatalogue | undefined;\n  /** Ranges of the text to mark in place, as TextArea's `highlights`: words an assistant suggested, spelling notes. */\n  highlights?: readonly TextAreaHighlight[] | undefined;\n  /** Called with the highlights moved to fit the text after the person edits it, as TextArea's. */\n  onHighlightsChange?: ((highlights: TextAreaHighlight[]) => void) | undefined;\n  /**\n   * The bigger box for a long message, as a chat app's format button opens: taller (`expandedRows`,\n   * growing to `expandedMaxRows`), with the `toolbar`, and Enter starts a new line while Ctrl+Enter\n   * (Command+Enter on a Mac) or the send button sends, whatever `sendOn` says. It is the same text\n   * either way, and the caret stays where it was. ⌘⇧X (Ctrl+Shift+X off Apple platforms) expands and\n   * collapses it, as in Teams, and the expand button's tooltip shows the key. Escape collapses it,\n   * and that Escape goes no further. The box grows and shrinks in height over a moment, and at once with reduced motion.\n   * Controlled; pair it with `onExpandedChange`, or use `defaultExpanded`.\n   *\n   * @claim \"Enter starts a new line while\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > starts a new line on Enter and sends on Ctrl+Enter or Command+Enter, whatever sendOn says)\n   * @claim \"It is the same text either\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > keeps the text, focus and the caret when it expands and collapses)\n   * @claim \"expands and collapses it, as in Teams\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > expands and collapses on Command+Shift+X, and shows the key in the expand button's tooltip)\n   * @claim \"Escape collapses it, and that Escape\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > collapses on Escape, and that Escape goes no further)\n   * @claim \"The box grows and shrinks in\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > grows and shrinks in height over a moment, and at once with reduced motion)\n   */\n  expanded?: boolean | undefined;\n  /** Whether it starts expanded, for an uncontrolled composer that the expand button opens; `false` to start small. */\n  defaultExpanded?: boolean | undefined;\n  /**\n   * Called when the person expands or collapses it: the expand button, or Escape. With it, or with\n   * `defaultExpanded`, the expand button shows first among the actions.\n   * @claim \"With it, or with `defaultExpanded`, the\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer expanded > shows the expand button first among the actions, pressed while expanded, with the toolbar only while expanded)\n   */\n  onExpandedChange?: ((expanded: boolean) => void) | undefined;\n  /** The expand button's name, which its tooltip shows too. @default \"Expand\" */\n  expandLabel?: string | undefined;\n  /** Lines the expanded box starts with. @default 6 */\n  expandedRows?: number | undefined;\n  /** Lines the expanded box grows to before it scrolls. @default 20 */\n  expandedMaxRows?: number | undefined;\n  /** Lines the box starts with; it grows as the person writes. @default 1 */\n  rows?: number | undefined;\n  /** Lines it grows to before it scrolls. @default 10 */\n  maxRows?: number | undefined;\n  /** The form field name the text submits under. */\n  name?: string | undefined;\n  /** Layout only: margins, width, grid placement (`mt-2`). Appearance classes warn in development. */\n  className?: string | undefined;\n  /** The `<textarea>`. */\n  ref?: Ref<HTMLTextAreaElement> | undefined;\n  /**\n   * Teams' formatting keys in the box: ⌘B bold, ⌘I italic, ⌘U underline, ⌘⌥X strikethrough and\n   * ⌘⇧C code (Ctrl for ⌘, Alt for ⌥, off Apple platforms), each as a `ComposerFormat`.\n   * `composerShortcuts` (from `composer-styles`) has the keys, for your toolbar's tooltips.\n   *\n   * @claim \"Teams' formatting keys in the box\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > applies Teams' formatting keys, and takes each back with Undo and gives it again with Redo)\n   */\n  formatting?: boolean | undefined;\n  /**\n   * A handle that formats the text and inserts into it, for a formatting bar, an emoji button or\n   * a link dialog. Every change it makes, a key's format and a `pasteText` paste go through the\n   * browser's own editing, as typing does, so Undo (⌘Z) and Redo (⌘⇧Z) step through them. WebKit\n   * (Safari) can join changes made in a row into one step, as it joins typing.\n   *\n   * @claim \"so Undo (⌘Z) and Redo\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > formats and inserts from editorRef, each a step that Undo takes back)\n   * @claim \"can join changes made in a row\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > applies Teams' formatting keys, and takes each back with Undo and gives it again with Redo)\n   * @claim \"so Undo (⌘Z) and Redo\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer formatting > puts a paste through pasteText, as one step that Undo takes back)\n   */\n  editorRef?: Ref<ComposerEditor> | undefined;\n  /**\n   * Turns a paste into the box's text, such as formatted text into Markdown: return the text, or\n   * `undefined` for the browser's own paste.\n   */\n  pasteText?: ((data: DataTransfer) => string | undefined) | undefined;\n\n  /** Not a prop. Sending calls `onSend`: `<Composer onSend={(text) => send(text)}>`. */\n  onSubmit?: { 'Use <Composer onSend={(text) => send(text)}>': never };\n  /** Not a prop. Ouro UI uses `sendOn`: `<Composer sendOn=\"mod-enter\">`. */\n  submitOnEnter?: { 'Use <Composer sendOn=\"enter\"> or sendOn=\"mod-enter\"': never };\n  /** Not a prop. Ouro UI uses `sendOn`: `<Composer sendOn=\"mod-enter\">`. */\n  enterToSend?: { 'Use <Composer sendOn=\"enter\"> or sendOn=\"mod-enter\"': never };\n  /** Not a prop. Ouro UI uses `sending`: `<Composer sending>`. */\n  loading?: { 'Use <Composer sending>': never };\n  /** Not a prop. Ouro UI uses `sendDisabledReason`: `<Composer sendDisabledReason=\"Sending is off\">`. */\n  sendDisabled?: { 'Use <Composer sendDisabledReason=\"Sending is off\">': never };\n  /** Not a prop. The message a reply quotes is `quote`: `<Composer quote={{ author: \"Ana\", excerpt: \"Lunch?\", onRemove }}>`. */\n  replyTo?: { 'Use <Composer quote={{ author: \"Ana\", excerpt: \"Lunch?\", onRemove }}>': never };\n  /** Not a prop. A composer that expands takes `defaultExpanded` or `onExpandedChange`: `<Composer defaultExpanded={false}>`. */\n  expandable?: { 'Use <Composer defaultExpanded={false}> or expanded with onExpandedChange': never };\n}\n\n/** Props for {@link Composer}: its own props and the `<textarea>` attributes it passes through (`onKeyDown`, `onPaste`, `readOnly`). */\nexport type ComposerProps = Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, keyof ComposerOwnProps | \"children\"> & ComposerOwnProps;\n\nconst sendKeys = [\"enter\", \"mod-enter\"] as const;\n\n// One frame for the whole composer, with the field's border and one focus outline while the\n// text has focus; the textarea inside draws neither.\nconst frameClass =\n  \"relative box-border flex min-w-0 flex-col rounded-ouro-lg border border-solid border-input bg-card text-card-foreground \" +\n  \"outline-ring outline-offset-2 has-[textarea:focus-visible]:outline-2 has-[textarea:focus-visible]:outline-solid \" +\n  \"[&_textarea:focus-visible]:outline-0\";\n\n// The quote: a box on the muted surface with a hairline, which fades in when it appears (not\n// with reduced motion). Message's quote looks the same (message.tsx).\nconst quoteBoxClass =\n  \"flex min-w-0 items-center gap-1 rounded-ouro-md bg-muted pe-1 ring-1 ring-border/60 forced-colors:border forced-colors:border-solid \" +\n  \"transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) starting:opacity-0 motion-reduce:transition-none\";\nconst quoteBodyClass = \"flex min-w-0 flex-1 items-center gap-2 p-1.5\";\n// The quote as a button: it highlights while hovered rather than scaling, as a wide row does, and\n// with two lines of text it is taller than a touch target already.\nconst quoteButtonClass =\n  `${quoteBodyClass} m-0 cursor-pointer rounded-ouro-md border-0 bg-transparent text-start font-[inherit] text-inherit pointer-fine:hover:bg-accent ` +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\";\n\n/**\n * What the quote shows: the bar, the avatar, the author and the excerpt. Screen readers hear the\n * label (\"Quoting Ana\") in place of the author's name, then the excerpt.\n */\nfunction QuoteBody({ quote, id }: { quote: ComposerQuote; id: string }): JSX.Element {\n  return (\n    <>\n      <span aria-hidden=\"true\" data-ouro-composer-quote-bar=\"\" className=\"w-1 shrink-0 self-stretch rounded-full bg-primary forced-colors:bg-[Highlight]\" />\n      {quote.avatar}\n      <span className=\"flex min-w-0 flex-1 flex-col\">\n        <span id={`${id}-quote`} className=\"sr-only\">\n          {quote.label ?? `Quoting ${quote.author}`}:{\" \"}\n        </span>\n        <span aria-hidden=\"true\" data-ouro-composer-quote-author=\"\" className=\"truncate text-xs font-semibold text-foreground\">\n          {quote.authorContent ?? quote.author}\n        </span>\n        <span id={`${id}-excerpt`} data-ouro-composer-quote-excerpt=\"\" className=\"truncate text-sm text-[color-mix(in_oklab,var(--muted-foreground)_80%,var(--foreground))]\">\n          {quote.excerptContent === undefined ? (\n            quote.excerpt\n          ) : (\n            <>\n              <span aria-hidden=\"true\">{quote.excerptContent}</span>\n              <span className=\"sr-only\">{quote.excerpt}</span>\n            </>\n          )}\n        </span>\n      </span>\n    </>\n  );\n}\n\n/** A cross: remove. */\nfunction RemoveIcon(): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" className=\"size-4 shrink-0\">\n      <path d=\"M4 4l8 8M12 4l-8 8\" />\n    </svg>\n  );\n}\n\n// The row's height transition while the box expands or collapses, clipped: the classes are added\n// for that moment only.\nconst growClasses = [\"overflow-hidden\", \"transition-[height]\", \"duration-(--ouro-duration-base)\", \"ease-(--ouro-ease-out)\"];\n\n/** Arrows: out to expand, in to collapse. */\nfunction ExpandIcon({ expanded }: { expanded: boolean }): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" className=\"size-5 shrink-0\">\n      <path d={expanded ? \"M4 11h5v5M11 4v5h5M9 11l-5 5M11 9l5-5\" : \"M11 4h5v5M9 16H4v-5M16 4l-5 5M4 16l5-5\"} />\n    </svg>\n  );\n}\n\n/** A paper plane. */\nfunction SendIcon(): JSX.Element {\n  return (\n    <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinejoin=\"round\" className=\"size-5 shrink-0 rtl:-scale-x-100\">\n      <path d=\"M3.5 3.2 17 10 3.5 16.8 5.6 10z\" />\n      <path d=\"M5.6 10h5.4\" strokeLinecap=\"round\" />\n    </svg>\n  );\n}\n\n/**\n * Puts text in at the caret, in place of the browser's own insertion, with the catalogue's\n * tokens for the emoji it lists, when it has any; otherwise the browser inserts it as usual.\n * One edit, so one undo takes it out.\n */\nfunction insertTokens(control: HTMLTextAreaElement, event: { preventDefault(): void }, text: string, catalogue: EmojiCatalogue): void {\n  const tokens = emojiTextToTokens(text, catalogue);\n  if (tokens === text) return;\n  event.preventDefault();\n  insertText(control, control.selectionStart, control.selectionEnd, tokens);\n}\n\n/**\n * A chat message box: text that grows from one line as the person writes, a send button, and\n * room for the rest of a composer, in one frame with one focus outline. Enter sends and\n * Shift+Enter starts a new line, or `sendOn=\"mod-enter\"` for Ctrl+Enter, and Enter never\n * sends mid-word in an input method. A press anywhere around the text, out to the frame's\n * edge, puts the caret where it lands, as in a text field. `actions` holds the buttons before Send (emoji, attach,\n * formatting), `toolbar` a formatting bar above the text while it is on, `attachments`\n * the files waiting to go, and `quote` the message a reply quotes, which Escape in the empty\n * box removes. `sendDisabledReason` turns sending off and says why, while the\n * person can still write, and `highlights` marks words in the text, as TextArea's do.\n *\n * The text is plain text, so emoji from an image catalogue go in as `:shortcode:` tokens: an\n * `Autocomplete` trigger with `catalogue` inserts them as the person types `:` and a few\n * letters, and an `EmojiPicker` with `catalogue` in `actions` gives its `selection.token` to\n * put at the caret. `EmojiText` draws the tokens as the catalogue's images once the message\n * is sent. Given the `catalogue` too, Composer puts an emoji typed from the system's emoji\n * panel or pasted in as its token as well.\n *\n * Use `TextArea` instead for a long text that is saved rather than sent, and `Message` for\n * a message once it is sent.\n *\n * @group Chat\n * @see https://ui.ouroboros.bot/docs/composer\n *\n * @example\n * <Composer label=\"Message Mia\" placeholder=\"Write a message\" onSend={(text) => send(text)} />\n *\n * @example\n * <Composer\n *   label=\"Reply\"\n *   value={text}\n *   onValueChange={setText}\n *   onSend={(text) => { send(text); setText(\"\"); }}\n *   highlights={[{ start: 0, end: 22, label: \"Suggested by your assistant\" }]}\n *   description=\"Your assistant's suggestions are underlined.\"\n *   actions={<Button variant=\"plain\" aria-label=\"Attach a file\" onClick={attach}><PaperclipIcon /></Button>}\n *   attachments={files.length > 0 && files.map((file) => <Attachment key={file.name} name={file.name} onRemove={() => remove(file)} />)}\n *   sendDisabledReason={offline ? \"You're offline. Sending resumes when you reconnect.\" : undefined}\n * />\n *\n * @example\n * <Composer\n *   label=\"Reply to Ana\"\n *   quote={quoted && { author: quoted.author, excerpt: quoted.text, onRemove: () => setQuoted(undefined), onActivate: () => scrollTo(quoted.id) }}\n *   onSend={(text) => { send(text, quoted?.id); setQuoted(undefined); }}\n * />\n *\n * @example\n * <Composer label=\"Reply\" defaultExpanded={false} toolbar={<Toolbar label=\"Formatting\" items={formatting} />} onSend={(text) => send(text)} />\n * @claim \"Enter sends and Shift+Enter starts\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer > starts a new line on Shift+Enter, and sends on Ctrl+Enter or Command+Enter too)\n * @claim \"Enter sends and Shift+Enter starts\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer > never sends on the Enter that ends a word an input method is composing)\n * @claim \"an `Autocomplete` trigger with `catalogue` inserts them\" registry/ouro/components/ouro/autocomplete/autocomplete.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/autocomplete/autocomplete.catalogue.test.tsx::Autocomplete with a catalogue > inserts the picked emoji's token and a space in a Composer, which EmojiText draws as its image)\n * @claim \"gives its `selection.token` to put at the caret\" registry/ouro/components/ouro/emoji-picker/emoji-picker.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/emoji-picker/emoji-picker.catalogue.test.tsx::EmojiPicker with a catalogue > chooses an emoji: onSelect gets its id, name, token, tone and catalogue item, and the token draws as its image)\n * @claim \"A press anywhere around the\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer presses around the text > puts the caret at the start of the text on a press in the box's top left corner)\n * @claim \"A press anywhere around the\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer presses around the text > puts the caret at the end of a line on a press between the line and the send button)\n * @claim \"room for the rest of a composer\" registry/ouro/components/ouro/composer/composer.test.tsx verify:testExists(registry/ouro/components/ouro/composer/composer.test.tsx::Composer > draws one focus outline, on the frame, while the text has focus, and none on the text itself)\n */\nexport function Composer(props: ComposerProps): JSX.Element {\n  const platform = usePlatform();\n  const {\n    label,\n    onSend,\n    value,\n    defaultValue,\n    onValueChange,\n    placeholder,\n    sendOn: sendOnProp = \"enter\",\n    sendLabel = \"Send\",\n    sending = false,\n    sendingLabel = \"Sending\",\n    sendDisabledReason,\n    hideSendDisabledReason = false,\n    disabled = false,\n    attachments,\n    attachmentsLabel = \"Attachments\",\n    quote,\n    actions,\n    toolbar: toolbarProp,\n    description,\n    highlights,\n    onHighlightsChange,\n    catalogue,\n    expanded: expandedProp,\n    defaultExpanded,\n    onExpandedChange,\n    expandLabel = \"Expand\",\n    expandedRows = 6,\n    expandedMaxRows = 20,\n    rows: rowsProp = 1,\n    maxRows: maxRowsProp = 10,\n    name,\n    className,\n    ref,\n    formatting = false,\n    editorRef,\n    pasteText,\n    onKeyDown,\n    onPaste,\n    \"aria-describedby\": describedByProp,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    onSubmit,\n    submitOnEnter,\n    enterToSend,\n    loading,\n    sendDisabled,\n    replyTo,\n    expandable: expandableHint,\n    ...rest\n  } = props;\n  const [ownExpanded, setOwnExpanded] = useState(defaultExpanded ?? false);\n  const expandable = expandedProp !== undefined || defaultExpanded !== undefined || onExpandedChange !== undefined;\n  // The person can expand and collapse it: the composer holds the state, or the app listens.\n  const canExpand = expandedProp === undefined ? expandable : onExpandedChange !== undefined;\n  const expanded = expandedProp ?? ownExpanded;\n  const rows = expanded ? expandedRows : rowsProp;\n  const maxRows = expanded ? expandedMaxRows : maxRowsProp;\n  const toolbar = expandable && !expanded ? undefined : toolbarProp;\n  // Any other value is enter, as the default; expanded, Enter is a new line.\n  const modEnter = expanded || sendOnProp === \"mod-enter\";\n  const [own, setOwn] = useState(defaultValue ?? \"\");\n  const text = value ?? own;\n  const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n  // The row around the text, and its height after the last render, from which it grows or shrinks when the box expands or collapses.\n  const rowRef = useRef<HTMLDivElement | null>(null);\n  const height = useRef<{ expanded: boolean; px: number } | null>(null);\n  const setRef = useMergedRef(ref, textareaRef);\n  const id = useId();\n  const hasAttachments = Children.toArray(attachments).length > 0;\n  const blocked = disabled || sending || sendDisabledReason !== undefined;\n  const ready = !blocked && (text.trim() !== \"\" || hasAttachments);\n\n  useAppearanceClassNameCheck(\n    \"Composer\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; Composer takes its colors from the theme`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Composer\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !(sendKeys as readonly string[]).includes(sendOnProp) && [`sendOn=\"${String(sendOnProp)}\" is not a key; use \"enter\" or \"mod-enter\"`, '<Composer sendOn=\"enter\">'],\n          onSubmit !== undefined && [\"onSubmit is not a prop; sending calls onSend\", \"<Composer onSend={(text) => send(text)}>\"],\n          submitOnEnter !== undefined && [\"submitOnEnter is not a prop\", '<Composer sendOn=\"enter\">'],\n          enterToSend !== undefined && [\"enterToSend is not a prop\", '<Composer sendOn=\"enter\">'],\n          loading !== undefined && [\"loading is not a prop\", \"<Composer sending>\"],\n          sendDisabled !== undefined && [\"sendDisabled is not a prop; say why sending is off\", '<Composer sendDisabledReason=\"Sending is off\">'],\n          replyTo !== undefined && [\"replyTo is not a prop; the message a reply quotes is quote\", '<Composer quote={{ author: \"Ana\", excerpt: \"Lunch?\", onRemove }}>'],\n          expandableHint !== undefined && [\"expandable is not a prop; defaultExpanded or onExpandedChange shows the expand button\", \"<Composer defaultExpanded={false}>\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // A controlled composer reads its text from value, so its own copy is never read.\n  const change = (next: string) => {\n    setOwn(next);\n    onValueChange?.(next);\n  };\n  const send = (event: ComposerSendEvent) => {\n    if (sendDisabledReason !== undefined && !disabled) announce(sendDisabledReason);\n    if (!ready) return;\n    onSend(text, event);\n    setOwn(\"\");\n    // After a press of Send, the person goes on writing; after Enter, focus is there already. No\n    // box around the composer scrolls for it.\n    textareaRef.current!.focus({ preventScroll: true });\n  };\n  const setExpanded = (next: boolean) => {\n    setOwnExpanded(next);\n    onExpandedChange?.(next);\n  };\n  const toggleExpanded = () => {\n    setExpanded(!expanded);\n    // The person goes on writing where they were: the textarea keeps its caret while it has no focus.\n    textareaRef.current!.focus({ preventScroll: true });\n  };\n  const removeQuote = () => {\n    quote!.onRemove();\n    // The remove button goes with the quote, so focus goes back to the text, scrolling no box around it.\n    textareaRef.current!.focus({ preventScroll: true });\n  };\n\n  // After every render, once TextArea has fitted the box: a render that expands or collapses it\n  // grows or shrinks the row around the text from the height it had, clipped, while the text takes\n  // its new height at once (so autoGrow measures it as ever). Any other render ends that at once.\n  useLayoutEffect(() => {\n    const row = rowRef.current!;\n    const animating = row.style.height !== \"\";\n    // What shows now: a running change's height, or the row's own.\n    const shown = row.offsetHeight;\n    row.style.height = \"\";\n    const px = row.offsetHeight;\n    const before = height.current;\n    height.current = { expanded, px };\n    const from = animating ? shown : before?.px;\n    // A change still running stops at once here: its classes go once its transition is cancelled, below.\n    if (before === null || before.expanded === expanded || matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    row.style.height = `${from}px`;\n    void row.offsetHeight;\n    row.classList.add(...growClasses);\n    row.style.height = `${px}px`;\n    // Once it ends, or is cancelled with nothing after it, the row takes its own height again.\n    void Promise.allSettled(row.getAnimations().map((animation) => animation.finished)).then(() => {\n      if (row.getAnimations().length > 0) return;\n      row.classList.remove(...growClasses);\n      row.style.height = \"\";\n    });\n  });\n  // Changes the text as the browser's own editing does, so Undo and Redo step through them; never in a read-only box.\n  const edit = (change: (textarea: HTMLTextAreaElement) => void) => {\n    const textarea = textareaRef.current!;\n    if (!textarea.readOnly) change(textarea);\n  };\n  const format = (kind: ComposerFormat) =>\n    edit((textarea) => {\n      const change = formatEdit(textarea.value, textarea.selectionStart, textarea.selectionEnd, kind);\n      insertText(textarea, change.from, change.to, change.text);\n      textarea.setSelectionRange(change.start, change.end);\n    });\n  const insert = (text: string) => edit((textarea) => insertText(textarea, textarea.selectionStart, textarea.selectionEnd, text));\n  useImperativeHandle(editorRef, () => ({ format, insert }));\n  const keyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {\n    onKeyDown?.(event);\n    // A word an input method is still composing ends with Enter, and Escape cancels it; those keys are the input method's.\n    if (event.defaultPrevented || event.nativeEvent.isComposing || event.keyCode === 229) return;\n    const apple = isApple();\n    if (canExpand && pressed(event, composerShortcuts.expand, apple)) {\n      event.preventDefault();\n      setExpanded(!expanded);\n      return;\n    }\n    const key = formatting ? markFormats.find((kind) => pressed(event, composerShortcuts[kind], apple)) : undefined;\n    if (key) {\n      event.preventDefault();\n      format(key);\n      return;\n    }\n    if (event.key === \"Escape\" && quote && text === \"\") {\n      // This Escape is the quote's: a dialog around the composer stays open.\n      event.preventDefault();\n      event.stopPropagation();\n      quote.onRemove();\n      return;\n    }\n    if (event.key === \"Escape\" && expanded && canExpand) {\n      // This Escape is the expanded box's: a dialog around the composer stays open.\n      event.preventDefault();\n      event.stopPropagation();\n      setExpanded(false);\n      return;\n    }\n    // An open suggestion list (Autocomplete) owns Enter, Ctrl+Enter too.\n    if (event.key !== \"Enter\" || event.currentTarget.hasAttribute(\"aria-activedescendant\")) return;\n    const sends = modEnter ? event.metaKey || event.ctrlKey : !event.shiftKey;\n    if (!sends) return;\n    event.preventDefault();\n    send(event);\n  };\n\n  // With a catalogue, an emoji typed (from the system's emoji panel, which inserts it whole) goes in as its token.\n  useEffect(() => {\n    if (!catalogue) return;\n    const control = textareaRef.current!;\n    const typed = (event: InputEvent) => {\n      // A word an input method is composing is the input method's until it ends; a replacement without text inserts none.\n      if (event.isComposing || event.data === null || (event.inputType !== \"insertText\" && event.inputType !== \"insertReplacementText\")) return;\n      insertTokens(control, event, event.data, catalogue);\n    };\n    control.addEventListener(\"beforeinput\", typed);\n    return () => control.removeEventListener(\"beforeinput\", typed);\n  }, [catalogue]);\n  const paste = (event: ClipboardEvent<HTMLTextAreaElement>) => {\n    onPaste?.(event);\n    if (event.defaultPrevented) return;\n    // An app's pasteText turns the paste into the box's text; with a catalogue, its emoji go in as tokens either way.\n    const custom = pasteText?.(event.clipboardData);\n    if (custom === undefined) {\n      if (catalogue) insertTokens(event.currentTarget, event, event.clipboardData.getData(\"text/plain\"), catalogue);\n      return;\n    }\n    event.preventDefault();\n    insert(catalogue ? emojiTextToTokens(custom, catalogue) : custom);\n  };\n\n  const notes = [sendDisabledReason !== undefined && !disabled ? `${id}-reason` : undefined, description ? `${id}-description` : undefined];\n  const quoteIds = quote ? [`${id}-quote`, `${id}-excerpt`] : [];\n  const removeLabel = quote && (quote.removeLabel ?? `Remove quote from ${quote.author}`);\n  const describedBy = [describedByProp, ...quoteIds, ...notes].filter(Boolean).join(\" \") || undefined;\n  const reasonDrawn = notes[0] !== undefined && !hideSendDisabledReason;\n  const reasonHidden = notes[0] !== undefined && hideSendDisabledReason;\n\n  return (\n    <div data-ouro=\"composer\" data-expanded={expanded ? \"\" : undefined} data-sending={sending ? \"\" : undefined} data-send-disabled={sendDisabledReason !== undefined ? \"\" : undefined} className={cn(\"box-border flex min-w-0 flex-col gap-1.5\", className)}>\n      <div data-ouro-composer-frame=\"\" className={frameClass}>\n        {toolbar && (\n          <div data-ouro-composer-toolbar=\"\" className=\"flex min-w-0 flex-wrap items-center gap-0.5 border-0 border-b border-solid border-border px-1 py-1\">\n            {toolbar}\n          </div>\n        )}\n        {quote && (\n          <div className=\"px-1 pt-1\">\n            <div data-ouro-composer-quote=\"\" className={quoteBoxClass}>\n              {quote.onActivate ? (\n                <button type=\"button\" data-ouro-control=\"composer\" data-ouro-part=\"quote\" onClick={quote.onActivate} className={quoteButtonClass}>\n                  <QuoteBody quote={quote} id={id} />\n                </button>\n              ) : (\n                <div className={quoteBodyClass}>\n                  <QuoteBody quote={quote} id={id} />\n                </div>\n              )}\n              <Tooltip content={removeLabel}>\n                <Button data-ouro-control=\"composer\" data-ouro-part=\"remove\" variant=\"plain\" tone=\"secondary\" size=\"sm\" disabled={disabled} onClick={removeQuote} className=\"px-1.5\">\n                  <RemoveIcon />\n                  <span className=\"sr-only\">{removeLabel}</span>\n                </Button>\n              </Tooltip>\n            </div>\n          </div>\n        )}\n        {/* The text's padding is the textarea's own, out to the frame's edge, so a press anywhere around the text takes the caret where it lands. */}\n        <div ref={rowRef} data-ouro-composer-body=\"\" className=\"flex min-w-0 flex-wrap items-end\">\n          <TextArea\n            {...rest}\n            ref={setRef}\n            label={label}\n            hideLabel\n            name={name}\n            variant=\"plain\"\n            autoGrow\n            rows={rows}\n            maxRows={maxRows}\n            value={text}\n            onValueChange={change}\n            placeholder={placeholder}\n            disabled={disabled}\n            highlights={highlights}\n            onHighlightsChange={onHighlightsChange}\n            onKeyDown={keyDown}\n            onPaste={paste}\n            aria-describedby={describedBy}\n            // Expanded, the text takes the whole width, and the buttons go on a row under it.\n            className={cn(\"min-w-[min(12rem,100%)] flex-1 basis-48 [&_textarea]:py-3 [&_textarea]:ps-3 [&_textarea]:pe-2\", expanded && \"w-full flex-auto\")}\n          />\n          <div className=\"ms-auto flex shrink-0 items-center gap-0.5 p-1\">\n            {canExpand && (\n              <Tooltip\n                content={\n                  <span className=\"inline-flex items-center gap-2\">\n                    {expandLabel}\n                    <Kbd keys={composerShortcuts.expand} />\n                  </span>\n                }\n              >\n                <Button\n                  data-ouro-control=\"composer\"\n                  data-ouro-part=\"expand\"\n                  variant={expanded ? \"outline\" : \"plain\"}\n                  tone={expanded ? \"primary\" : \"secondary\"}\n                  aria-label={expandLabel}\n                  aria-pressed={expanded}\n                  aria-keyshortcuts={ariaKeyShortcuts(composerShortcuts.expand, platform)}\n                  disabled={disabled}\n                  // A press keeps focus, and the caret, in the text.\n                  onMouseDown={(event) => event.preventDefault()}\n                  onClick={toggleExpanded}\n                  className=\"px-2\"\n                >\n                  <ExpandIcon expanded={expanded} />\n                </Button>\n              </Tooltip>\n            )}\n            {actions}\n            <Tooltip content={sendLabel}>\n              <Button\n                data-ouro-control=\"composer\"\n                data-ouro-part=\"send\"\n                variant=\"plain\"\n                aria-label={sendLabel}\n                disabled={!ready && !sending}\n                loading={sending}\n                loadingLabel={sendingLabel}\n                onClick={send}\n                className=\"px-2\"\n              >\n                <SendIcon />\n              </Button>\n            </Tooltip>\n          </div>\n        </div>\n        {hasAttachments && (\n          <div role=\"group\" aria-label={attachmentsLabel} data-ouro-composer-attachments=\"\" className=\"flex min-w-0 flex-wrap gap-2 px-2 pb-2\">\n            {attachments}\n          </div>\n        )}\n      </div>\n      {(reasonDrawn || description) && (\n        <div className=\"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 px-1 text-xs text-muted-foreground\">\n          {reasonDrawn && (\n            <span id={notes[0]} data-ouro-composer-reason=\"\" className=\"font-medium text-[color-mix(in_oklab,var(--muted-foreground)_70%,var(--foreground))]\">\n              {sendDisabledReason}\n            </span>\n          )}\n          {description && (\n            <span id={notes[1]} data-ouro-composer-description=\"\">\n              {description}\n            </span>\n          )}\n        </div>\n      )}\n      {reasonHidden && (\n        <span id={notes[0]} data-ouro-composer-reason=\"\" className=\"sr-only\">\n          {sendDisabledReason}\n        </span>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/composer/composer.tsx"
    }
  ],
  "docs": "A chat message box: text that grows from one line as the person writes, a send button, and room for the rest of a composer, in one frame with one focus outline. Import: import { Composer } from \"@/components/ouro/composer/composer\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: button, emoji, field, kbd, text-area, text-field, tooltip, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/composer.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}