{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thread-layout",
  "title": "ThreadLayout",
  "description": "A conversation beside its thread.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/thread-layout/thread-layout.tsx",
      "content": "\"use client\";\n\nimport { Children, useCallback, useLayoutEffect, useRef, type FocusEvent, type JSX, type ReactNode } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** Props for {@link ThreadLayout}. */\nexport interface ThreadLayoutProps {\n  /**\n   * The main pane: the list and its reply box. It stays mounted while a thread covers it, so its\n   * scroll position and its draft stay.\n   */\n  conversation: ReactNode;\n  /**\n   * The thread, usually a `ThreadRail`. Pass `null` when no thread is open, and the conversation\n   * takes the whole box.\n   */\n  thread?: ReactNode | undefined;\n  /**\n   * The conversation pane's name, which a screen reader hears when focus comes to the pane: when a thread closes that\n   * no control in the conversation opened and the conversation has no heading to take focus. Name it apart from the\n   * MessageList inside it, which is a region too. Translate it with the rest of your interface.\n   * @claim \"The conversation pane's name, which a\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > moves focus to the conversation pane, named, when a thread closes that nothing opened and the conversation has no heading)\n   * @default \"Conversation pane\"\n   */\n  conversationLabel?: string | undefined;\n  /** Layout only: the box's size and margins. Appearance classes warn in development; the colors come from the theme. */\n  className?: string | undefined;\n\n  /** Not a prop. The thread is `thread`: `<ThreadLayout conversation={list} thread={open ? <ThreadRail …/> : null} />`. */\n  rail?: { \"Pass the ThreadRail as thread, or null when closed\": never };\n}\n\n/**\n * A conversation beside its thread. From 32rem up the conversation takes the rest of the width and\n * the thread its own 20rem. Below that, an open thread takes the whole box and the conversation is\n * hidden, not unmounted. The widths follow the layout's own box, not the window.\n *\n * When a thread that holds focus closes, focus goes back to the control in the conversation that\n * opened it. When none did (a thread opened from a link, or its opener gone since), focus comes to\n * the conversation's heading, or else to the conversation pane itself, a region named by\n * `conversationLabel`, so focus never falls to the page.\n *\n * Use `ThreadRail` for the thread itself. Use `Sheet` instead when the thread should cover the page\n * as a modal panel, and `Resizable` instead when the person sizes the panes.\n *\n * @group Layout\n * @example\n * <ThreadLayout\n *   conversation={<MessageList label=\"Messages\">{messages}</MessageList>}\n *   thread={open ? <ThreadRail label=\"Thread\" onClose={closeThread}><MessageList label=\"Replies\">{replies}</MessageList></ThreadRail> : null}\n * />\n * @claim \"From 32rem up the conversation takes the rest of the width and the thread its own 20rem\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > puts the conversation and the rail side by side from 32rem up, the rail at 20rem)\n * @claim \"Below that, an open thread takes the whole box and the conversation is hidden, not unmounted\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > gives the rail the whole box below 32rem, and hides the conversation)\n * @claim \"Below that, an open thread takes the whole box and the conversation is hidden, not unmounted\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > keeps the conversation mounted and its draft while a narrow box hides it)\n * @claim \"When a thread that holds focus closes\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > gives focus back to the conversation's control that opened the thread, once a narrow box shows it again)\n * @claim \"When none did (a thread opened\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > moves focus to the conversation's heading when a thread closes that nothing in the conversation opened (%dpx)) verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > moves focus to the conversation pane, named, when a thread closes that nothing opened and the conversation has no heading)\n * @claim \"The widths follow the layout's own box, not the window\" registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx verify:testExists(registry/ouro/components/ouro/thread-layout/thread-layout.test.tsx::ThreadLayout > keeps the conversation mounted and its draft while a narrow box hides it)\n */\nexport function ThreadLayout(props: ThreadLayoutProps): JSX.Element {\n  const { conversation, thread, conversationLabel = \"Conversation pane\", className, rail } = props;\n  // `Children.toArray` drops null, undefined and booleans, the nodes that render nothing.\n  const open = Children.toArray(thread).length > 0;\n\n  useAppearanceClassNameCheck(\n    \"ThreadLayout\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; the theme sets the colors of the panes ThreadLayout holds`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"ThreadLayout\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          rail !== undefined && [\n            \"rail is not a prop; the thread takes its place\",\n            '<ThreadLayout conversation={list} thread={open ? <ThreadRail label=\"Thread\" onClose={close} /> : null} />',\n          ],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  // A thread that closes gives focus back as it unmounts, which in a narrow box is before the conversation shows again, so\n  // the control it gives focus to is still hidden and focus falls to the page. Once the conversation shows, the last control\n  // focused in it takes focus back, if nothing else has it. When no control there opened the thread (a thread opened from\n  // a link, or one gone since), focus comes to the conversation's heading, or else the conversation pane itself, by name.\n  const lastFocused = useRef<HTMLElement | null>(null);\n  const pane = useRef<HTMLDivElement>(null);\n  // Whether the thread held focus as it closed: read as its box leaves, before the rail gives focus back.\n  const threadHeldFocus = useRef(false);\n  // Stryker disable next-line ArrayDeclaration: the callback reads nothing from render, so any dependency list keeps it.\n  const threadBox = useCallback((box: HTMLDivElement) => () => void (threadHeldFocus.current = box.contains(document.activeElement)), []);\n  useLayoutEffect(() => {\n    if (!open && document.activeElement === document.body) lastFocused.current?.focus();\n    // The thread box's cleanup sets threadHeldFocus as each thread closes, so it is current whenever a close is handled here.\n    if (open || !threadHeldFocus.current || document.activeElement !== document.body) return;\n    // The conversation's own heading: not one inside a message, which would scroll the list away from the newest.\n    const heading = [...pane.current!.querySelectorAll<HTMLElement>(\"h1, h2, h3, h4, h5, h6\")].find((element) => element.closest('[data-ouro=\"message-list\"], [data-ouro=\"message\"]') === null);\n    if (heading !== undefined) {\n      const added = !heading.hasAttribute(\"tabindex\");\n      if (added) heading.tabIndex = -1;\n      heading.focus({ preventScroll: true });\n      // A heading that cannot take focus (hidden) is left as it was.\n      if (added && document.activeElement !== heading) heading.removeAttribute(\"tabindex\");\n    }\n    // No heading, or one that cannot take focus: the pane itself.\n    if (document.activeElement !== heading) pane.current!.focus();\n  }, [open]);\n  const remember = (event: FocusEvent<HTMLElement>) => void (lastFocused.current = event.target);\n\n  // The conversation's display is set only by the container query, and its layout by the element\n  // inside it, so no element has a display utility and a display variant at once.\n  return (\n    <div data-ouro=\"thread-layout\" className={cn(\"@container flex h-full min-h-0 w-full\", className)}>\n      <div\n        ref={pane}\n        role=\"region\"\n        aria-label={conversationLabel}\n        tabIndex={-1}\n        data-ouro-thread-layout-conversation=\"\"\n        className={cn(\"min-w-0 flex-1 outline-ring -outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid\", open && \"@max-lg:hidden\")}\n        onFocus={remember}\n      >\n        <div className=\"flex h-full min-h-0 min-w-0 flex-col\">{conversation}</div>\n      </div>\n      {open && (\n        <div ref={threadBox} className=\"flex h-full min-h-0 w-full min-w-0 flex-col @lg:max-w-80\">\n          {thread}\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/thread-layout/thread-layout.tsx"
    }
  ],
  "docs": "A conversation beside its thread. Import: import { ThreadLayout } from \"@/components/ouro/thread-layout/thread-layout\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports 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/thread-layout.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}