{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "table",
  "title": "Table",
  "description": "A data table: a caption, column headers, and rows, from `columns` and `rows` or from parts.",
  "registryDependencies": [
    "@ouro/lib-announce",
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-refs",
    "@ouro/lib-router-link",
    "@ouro/lib-stretched-link",
    "@ouro/lib-use-dev-messages",
    "@ouro/scroll-area"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/table/table-parts.tsx",
      "content": "\"use client\";\n\nimport {\n  createContext,\n  useContext,\n  useEffect,\n  useId,\n  useRef,\n  type CSSProperties,\n  type HTMLAttributes,\n  type JSX,\n  type ReactNode,\n  type Ref,\n  type TdHTMLAttributes,\n  type ThHTMLAttributes,\n} from \"react\";\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 { devThrow, devWarn } from \"@/registry/ouro/lib/ouro/dev\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { RouterLink, safeRel } from \"@/registry/ouro/lib/ouro/router-link\";\nimport { raiseControlsClass, stretchedLinkClass } from \"@/registry/ouro/lib/ouro/stretched-link\";\nimport { ScrollArea } from \"@/registry/ouro/components/ouro/scroll-area/scroll-area\";\nimport {\n  alignClasses,\n  cellBase,\n  cellPad,\n  directionOf,\n  directionWarning,\n  headCell,\n  rowLinkClass,\n  sectionCell,\n  sortButtonClass,\n  sortedLabelDefault,\n  sortIconPaths,\n  stickyHead,\n  wrapClass,\n  type TableAlign,\n  type TableSortDirection,\n} from \"@/registry/ouro/components/ouro/table/table-styles\";\n\nexport type { TableAlign, TableSortDirection } from \"@/registry/ouro/components/ouro/table/table-styles\";\n\ninterface TableState {\n  dense: boolean;\n  striped: boolean;\n  stickyHeader: boolean;\n  sortedLabel: (header: string, direction: TableSortDirection) => string;\n}\ntype Section = \"head\" | \"body\" | \"foot\";\ninterface RowState {\n  section: Section;\n  href: string | undefined;\n  external: boolean;\n  externalLabel: string;\n  /** The first row header cell to render claims the row link, so a row has one link and one tab stop. */\n  claim: { owner?: string };\n}\n\nconst TableContext = createContext<TableState | null>(null);\nconst SectionContext = createContext<Section | null>(null);\nconst RowContext = createContext<RowState | null>(null);\n\nconst shapes = {\n  TableHeader: '<Table caption=\"…\"><TableHeader>…</TableHeader></Table>',\n  TableBody: '<Table caption=\"…\"><TableBody>…</TableBody></Table>',\n  TableFooter: '<Table caption=\"…\"><TableFooter>…</TableFooter></Table>',\n  TableRow: '<Table caption=\"…\"><TableBody><TableRow>…</TableRow></TableBody></Table>',\n  TableHead: '<Table caption=\"…\"><TableHeader><TableRow><TableHead>…</TableHead></TableRow></TableHeader></Table>',\n  TableCell: '<Table caption=\"…\"><TableBody><TableRow><TableCell>…</TableCell></TableRow></TableBody></Table>',\n} as const;\n\n/** Throws in development, with the JSX the part belongs in, unless its parent is there. */\nfunction misplaced(part: keyof typeof shapes, parent: string): never {\n  return devThrow(\n    part,\n    `must be rendered inside <${parent}>`,\n    process.env.NODE_ENV !== \"production\" ? shapes[part] : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n}\n\nfunction useTable(part: keyof typeof shapes): TableState {\n  const table = useContext(TableContext);\n  return table ?? misplaced(part, \"Table\");\n}\n\n/** What a row link can't contain: anything that takes its own clicks or focus. */\nconst interactive = \"a,button,input,select,textarea,summary,[tabindex]:not([tabindex='-1']),[role=button]\";\n\nconst alignHint = (part: string) =>\n  process.env.NODE_ENV !== \"production\" ? `<${part} align=\"end\">` : /* istanbul ignore next @preserve -- production only */ undefined;\nconst cellHint = () =>\n  process.env.NODE_ENV !== \"production\" ? \"<Table striped> or <Table dense>; Table sets the look of its cells\" : /* istanbul ignore next @preserve -- production only */ \"\";\n\n/** Props for {@link TableFrame}. */\nexport interface TableFrameProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n  caption: string;\n  hideCaption?: boolean | undefined;\n  striped?: boolean | undefined;\n  dense?: boolean | undefined;\n  stickyHeader?: boolean | undefined;\n  sortedLabel?: ((header: string, direction: TableSortDirection) => string) | undefined;\n  children?: ReactNode;\n  className?: string | undefined;\n  style?: CSSProperties | undefined;\n  tableRef?: Ref<HTMLTableElement> | undefined;\n}\n\n/**\n * The frame Table and TableRoot render: the caption, a ScrollArea that scrolls the table\n * sideways (and down, inside a height), and the `<table>`.\n *\n * @internal Table and TableRoot render it.\n * @example\n * <TableFrame caption=\"Recipes\"><TableBody>…</TableBody></TableFrame>\n */\nexport function TableFrame(props: TableFrameProps): JSX.Element {\n  const { caption, hideCaption, striped, dense, stickyHeader, sortedLabel = sortedLabelDefault, children, className, tableRef, ...rest } = props;\n  return (\n    <TableContext.Provider value={{ dense: Boolean(dense), striped: Boolean(striped), stickyHeader: Boolean(stickyHeader), sortedLabel }}>\n      <div {...rest} data-ouro=\"table\" className={cn(\"flex min-w-0 flex-col gap-3\", className)}>\n        {!hideCaption && (\n          <div aria-hidden data-table-caption=\"\" className=\"text-sm font-medium text-muted-foreground\">\n            {caption}\n          </div>\n        )}\n        <ScrollArea orientation=\"both\" label={caption} className=\"min-h-0 flex-1\">\n          <table ref={tableRef} className=\"w-full border-separate border-spacing-0 text-base text-foreground pointer-fine:text-sm\">\n            <caption className=\"sr-only\">{caption}</caption>\n            {children}\n          </table>\n        </ScrollArea>\n      </div>\n    </TableContext.Provider>\n  );\n}\n\n/** Props for {@link TableRoot}. */\nexport interface TableRootProps extends Omit<HTMLAttributes<HTMLDivElement>, \"children\" | \"title\"> {\n  /** What the table shows. It names the table and its scrolling region, and shows above it unless `hideCaption`. */\n  caption: string;\n  /** Hides the caption visually and keeps it as the table's name. */\n  hideCaption?: boolean | undefined;\n  /**\n   * Shades every other body row.\n   *\n   * @claim \"Shades every other body row\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > shades every other body row with striped)\n   */\n  striped?: boolean | undefined;\n  /** Tighter cells, for many rows. */\n  dense?: boolean | undefined;\n  /** Keeps the header row at the top while the rows scroll, inside the height you give it (`className=\"max-h-96\"`). */\n  stickyHeader?: boolean | undefined;\n  /**\n   * What screen readers hear after a header with `onSort` is pressed, from the header's text\n   * and the new direction. Pass it to translate the message.\n   * @default (header, direction) => `Sorted by ${header}, ${direction}`\n   */\n  sortedLabel?: ((header: string, direction: TableSortDirection) => string) | undefined;\n  /** `TableHeader`, `TableBody` and `TableFooter`. */\n  children: ReactNode;\n  /** Layout: margins, width and the height the table scrolls inside. Appearance classes warn in development. */\n  className?: string | undefined;\n  /** A ref to the `<table>` element. */\n  ref?: Ref<HTMLTableElement> | undefined;\n}\n\n/**\n * Part: the root of a table built from parts, with its caption and its scrolling region.\n * `Table` takes the same parts as children (`<Table caption=\"Pantry\">…</Table>`), so use\n * it instead unless you are composing parts of your own; `Table` also builds the whole\n * table from `columns` and `rows`.\n *\n * @group Data\n * @example\n * <TableRoot caption=\"Pantry\">\n *   <TableHeader>\n *     <TableRow>\n *       <TableHead>Item</TableHead>\n *       <TableHead align=\"end\">Qty</TableHead>\n *     </TableRow>\n *   </TableHeader>\n *   <TableBody>\n *     <TableRow href=\"/pantry/flour\">\n *       <TableCell rowHeader>Flour</TableCell>\n *       <TableCell align=\"end\">2 kg</TableCell>\n *     </TableRow>\n *   </TableBody>\n * </TableRoot>\n */\nexport function TableRoot(props: TableRootProps): JSX.Element {\n  const { ref, className, ...rest } = props;\n  useAppearanceClassNameCheck(\n    \"TableRoot\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? \"put the table inside a <Card> for a frame\" : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"TableRoot\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [!props.caption && [\"caption is required; it names the table\", '<TableRoot caption=\"Pantry\">, with hideCaption when a heading already shows it']]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  return <TableFrame {...rest} className={className} tableRef={ref} />;\n}\n\n/** Props for {@link TableHeader}, {@link TableBody} and {@link TableFooter}. */\nexport interface TableSectionProps extends HTMLAttributes<HTMLTableSectionElement> {\n  /** Layout only. Appearance classes warn in development. */\n  className?: string | undefined;\n  ref?: Ref<HTMLTableSectionElement> | undefined;\n}\n\nfunction TableSection(props: TableSectionProps & { part: \"TableHeader\" | \"TableBody\" | \"TableFooter\"; kind: Section }): JSX.Element {\n  const { part, kind, className, ...rest } = props;\n  useTable(part);\n  useAppearanceClassNameCheck(part, className, cellHint());\n  const Element = kind === \"head\" ? \"thead\" : kind === \"body\" ? \"tbody\" : \"tfoot\";\n  return (\n    <SectionContext.Provider value={kind}>\n      <Element {...rest} className={cn(className)} />\n    </SectionContext.Provider>\n  );\n}\n\n/**\n * Part: the table's header rows (`<thead>`), holding a `TableRow` of `TableHead` cells.\n * With `stickyHeader` on the Table, they stay at the top while the rows scroll.\n *\n * @group Data\n * @example\n * <TableHeader>\n *   <TableRow>\n *     <TableHead>Recipe</TableHead>\n *     <TableHead align=\"end\">Serves</TableHead>\n *   </TableRow>\n * </TableHeader>\n */\nexport function TableHeader(props: TableSectionProps): JSX.Element {\n  return <TableSection {...props} part=\"TableHeader\" kind=\"head\" />;\n}\n\n/**\n * Part: the table's body rows (`<tbody>`).\n *\n * @group Data\n * @example\n * <TableBody>\n *   <TableRow href=\"/recipes/ribs\">\n *     <TableCell rowHeader>Braised short ribs</TableCell>\n *     <TableCell align=\"end\">6</TableCell>\n *   </TableRow>\n * </TableBody>\n */\nexport function TableBody(props: TableSectionProps): JSX.Element {\n  return <TableSection {...props} part=\"TableBody\" kind=\"body\" />;\n}\n\n/**\n * Part: summary rows under the body (`<tfoot>`), such as a total, with a line above them.\n *\n * @group Data\n * @example\n * <TableFooter>\n *   <TableRow>\n *     <TableCell rowHeader>Total</TableCell>\n *     <TableCell align=\"end\">3 kg</TableCell>\n *   </TableRow>\n * </TableFooter>\n */\nexport function TableFooter(props: TableSectionProps): JSX.Element {\n  return <TableSection {...props} part=\"TableFooter\" kind=\"foot\" />;\n}\n\n/** Props for {@link TableRow}. */\nexport interface TableRowProps extends HTMLAttributes<HTMLTableRowElement> {\n  /**\n   * Makes the whole body row one link, with one tab stop, named by its row header cell\n   * (`<TableCell rowHeader>`), which holds the link. Internal paths go through\n   * `OuroProvider`'s `linkComponent`. Buttons, links and inputs in other cells stay their\n   * own tab stops and take their own clicks and taps. On a touch screen the row is at least\n   * 44px tall.\n   * @claim \"On a touch screen the row\" registry/ouro/components/ouro/table/table.touch.test.tsx verify:fileLine(registry/ouro/components/ouro/table/table.touch.test.tsx, /makes\\sa\\slinked\\srow\\sat\\sleast\\s44px\\stall\\sin\\s%s/)\n   * @claim \"On a touch screen the row\" registry/ouro/components/ouro/table/table-parts.tsx verify:fileLine(registry/ouro/components/ouro/table/table-parts.tsx, /pointer-coarse:h-11/)\n   */\n  href?: string | undefined;\n  /** With `href`: opens the link in a new tab, safely, and tells screen readers so with `externalLabel`. */\n  external?: boolean | undefined;\n  /**\n   * What screen readers hear after the link's name when `external` opens it in a new tab.\n   * @default \"(opens in a new tab)\"\n   */\n  externalLabel?: string | undefined;\n  /** Layout only. Appearance classes warn in development; use the Table's `striped`. */\n  className?: string | undefined;\n  ref?: Ref<HTMLTableRowElement> | undefined;\n}\n\n/**\n * Part: one row (`<tr>`). With `href` a body row is one link, held by its row header cell.\n *\n * @group Data\n * @example\n * <TableRow href=\"/recipes/ribs\">\n *   <TableCell rowHeader>Braised short ribs</TableCell>\n *   <TableCell>4 h</TableCell>\n * </TableRow>\n */\nexport function TableRow(props: TableRowProps): JSX.Element {\n  const { href, external, externalLabel = \"(opens in a new tab)\", className, ref, children, ...rest } = props;\n  const table = useTable(\"TableRow\");\n  const kind = useContext(SectionContext) ?? misplaced(\"TableRow\", \"TableBody\");\n  const own = useRef<HTMLTableRowElement>(null);\n  const merged = useMergedRef(ref, own);\n  useAppearanceClassNameCheck(\n    \"TableRow\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? \"<Table striped>\" : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  const linked = href !== undefined && kind === \"body\";\n  useEffect(() => {\n    /* istanbul ignore else @preserve -- the else path exists only in production bundles; scripts/dev-strip.test.mjs covers it */\n    if (process.env.NODE_ENV !== \"production\") {\n      const row = own.current;\n      /* istanbul ignore if @preserve -- the ref is set before effects run */\n      if (!row) return;\n      if (href !== undefined && !linked) {\n        devWarn(\"TableRow\", \"href works on body rows only\", '<TableBody><TableRow href=\"…\">…</TableRow></TableBody>', own);\n        return;\n      }\n      if (!linked) return;\n      const link = row.querySelector(\"[data-stretched-link]\");\n      if (!link) {\n        const text = row.cells[0]?.textContent || \"…\";\n        devWarn(\n          \"TableRow\",\n          \"href needs a row header cell, which holds the link and names it\",\n          `<TableRow href=\"${href}\"><TableCell rowHeader>${text}</TableCell>…</TableRow>`,\n          own,\n        );\n        return;\n      }\n      const nameFix = '{ key: \"name\", header: \"Recipe\", rowHeader: true }, or <TableCell rowHeader>Name</TableCell>';\n      const name = [...link.childNodes]\n        .filter((node) => !(node instanceof Element && node.hasAttribute(\"data-external-label\")))\n        .map((node) => node.textContent)\n        .join(\"\")\n        .trim();\n      if (link.querySelector(interactive)) devWarn(\"TableRow\", \"the row link holds a control, and a link can't contain one\", nameFix, own);\n      else if (!name && !link.querySelector(\"img[alt]:not([alt=''])\")) devWarn(\"TableRow\", \"the row link has no text to name it\", nameFix, own);\n      if (row.querySelectorAll(\"th[scope=row]\").length > 1) {\n        devWarn(\"TableRow\", \"two cells are row headers, and only the first holds the row link\", \"<TableCell rowHeader> on the name cell only\", own);\n      }\n    }\n  });\n  return (\n    <RowContext.Provider value={{ section: kind, href: linked ? href : undefined, external: Boolean(external), externalLabel, claim: {} }}>\n      <tr\n        {...rest}\n        ref={merged}\n        data-linked={linked ? \"\" : undefined}\n        className={cn(\n          table.striped && kind === \"body\" && \"even:bg-muted/50\",\n          linked && \"relative isolate cursor-pointer pointer-coarse:h-11\",\n          linked && raiseControlsClass,\n          className,\n        )}\n      >\n        {children}\n      </tr>\n    </RowContext.Provider>\n  );\n}\n\n/** The props TableHead and TableCell share. */\ninterface CellOwnProps {\n  /**\n   * How the content lines up: `end` for numbers and amounts, `center` for a status mark.\n   * @default \"start\"\n   */\n  align?: TableAlign | (string & { 'Use \"start\", \"center\" or \"end\": right is \"end\"': never }) | undefined;\n  /**\n   * Lets long text wrap onto more lines, at least 192px wide, instead of widening the table.\n   *\n   * @claim \"Lets long text wrap onto more\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > lets a column with wrap break its text onto more lines, at least 192px wide)\n   * @claim \"Lets long text wrap onto more\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > breaks a long URL in a wrap column instead of widening it)\n   */\n  wrap?: boolean | undefined;\n  /** Layout only: a width (`w-32`). Appearance classes warn in development; alignment is `align`. */\n  className?: string | undefined;\n}\n\nfunction alignOf(align: string | undefined): TableAlign {\n  return align === \"center\" || align === \"end\" ? align : \"start\";\n}\n\n/** Warns in development when `align` is not one of ours; the cell aligns to the start. */\nfunction useAlignCheck(part: string, align: string | undefined): void {\n  useDevWarnings(\n    part,\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          align !== undefined &&\n            alignOf(align) !== align && [\n              `align=\"${align}\" is not an alignment; use \"start\", \"center\", \"end\"`,\n              `<${part} align=\"${align === \"left\" ? \"start\" : \"end\"}\">`,\n            ],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n}\n\n/** Props for {@link TableHead}. */\nexport interface TableHeadProps extends Omit<ThHTMLAttributes<HTMLTableCellElement>, \"align\">, CellOwnProps {\n  /** The column's name. Keep it even for a column of buttons, and hide it with `hideHeader`. */\n  children: ReactNode;\n  /** Hides the header visually and keeps it for screen readers, for a column of actions. */\n  hideHeader?: boolean | undefined;\n  /**\n   * Which way the rows are sorted by this column. It sets `aria-sort` and shows an arrow; leave\n   * it out on the columns the rows are not sorted by.\n   */\n  sorted?: TableSortDirection | (string & { 'Use \"ascending\" or \"descending\": asc is \"ascending\"': never }) | undefined;\n  /**\n   * Makes the header a button that sorts the rows by this column, with an arrow that shows the\n   * direction. A press calls it with the direction to sort to (`\"descending\"` when this column\n   * is sorted ascending, or else `\"ascending\"`) and tells screen readers. Sort the rows yourself\n   * and pass `sorted` back. On a touch screen the header is at least 44px tall.\n   *\n   * @claim \"A press calls it with the direction\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table parts > sorts from a TableHead with onSort, which the app sorts and marks with sorted)\n   * @claim \"On a touch screen the header\" registry/ouro/components/ouro/table/table.touch.test.tsx verify:fileLine(registry/ouro/components/ouro/table/table.touch.test.tsx, /makes\\sa\\ssortable\\sheader\\sat\\sleast\\s44px\\stall/)\n   */\n  onSort?: ((direction: TableSortDirection) => void) | undefined;\n  ref?: Ref<HTMLTableCellElement> | undefined;\n}\n\n/**\n * Part: a column header (`<th scope=\"col\">`) in a `TableHeader` row. With `onSort` it is a\n * button that sorts the rows by its column, and `sorted` marks the column they are sorted by.\n *\n * @group Data\n * @example\n * <TableHead align=\"end\">Serves</TableHead>\n * <TableHead hideHeader>Actions</TableHead>\n * <TableHead sorted={sort.key === \"name\" ? sort.direction : undefined} onSort={(direction) => setSort({ key: \"name\", direction })}>\n *   Recipe\n * </TableHead>\n */\nexport function TableHead(props: TableHeadProps): JSX.Element {\n  const { align, hideHeader, wrap, sorted, onSort, className, children, ...rest } = props;\n  const table = useTable(\"TableHead\");\n  const row = useContext(RowContext) ?? misplaced(\"TableHead\", \"TableRow\");\n  useAppearanceClassNameCheck(\"TableHead\", className, cellHint(), alignHint(\"TableHead\"));\n  useAlignCheck(\"TableHead\", align);\n  useDevWarnings(\n    \"TableHead\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [directionWarning(sorted, (direction) => `<TableHead sorted=\"${direction}\">`)]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const direction = directionOf(sorted);\n  const label = hideHeader ? <span className=\"sr-only\">{children}</span> : children;\n  const icon = (onSort || direction) && (\n    <svg\n      aria-hidden=\"true\"\n      data-sort-icon={direction ?? \"none\"}\n      viewBox=\"0 0 16 16\"\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth=\"1.5\"\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      className=\"size-3.5 shrink-0\"\n    >\n      <path d={sortIconPaths[direction ?? \"none\"]} />\n    </svg>\n  );\n  return (\n    <th\n      scope=\"col\"\n      aria-sort={direction}\n      {...rest}\n      className={cn(\n        cellBase,\n        headCell,\n        cellPad[table.dense ? \"dense\" : \"md\"],\n        alignClasses[alignOf(align)],\n        sectionCell[row.section],\n        wrap && wrapClass,\n        direction && \"text-foreground\",\n        onSort && \"relative pointer-coarse:h-11\",\n        table.stickyHeader && row.section === \"head\" && stickyHead,\n        className,\n      )}\n    >\n      {onSort ? (\n        <button\n          type=\"button\"\n          data-ouro-control=\"table\"\n          data-ouro-part=\"sort\"\n          // An end-aligned column keeps its name over its numbers, with the arrow before it.\n          className={cn(sortButtonClass, alignOf(align) === \"end\" && \"flex-row-reverse\")}\n          onClick={(event) => {\n            const next = direction === \"ascending\" ? \"descending\" : \"ascending\";\n            announce(table.sortedLabel(event.currentTarget.textContent!, next));\n            onSort(next);\n          }}\n        >\n          <span className=\"min-w-0\">{label}</span>\n          {icon}\n        </button>\n      ) : (\n        <>\n          {label}\n          {icon && <span className=\"ms-1.5 inline-flex align-middle\">{icon}</span>}\n        </>\n      )}\n    </th>\n  );\n}\n\n/** Props for {@link TableCell}. */\nexport interface TableCellProps extends Omit<TdHTMLAttributes<HTMLTableCellElement>, \"align\">, CellOwnProps {\n  /**\n   * Makes this cell the row's header (`<th scope=\"row\">`): what the row is, such as a\n   * recipe's name. In a row with `href` it holds the link, so its text names the link.\n   */\n  rowHeader?: boolean | undefined;\n  ref?: Ref<HTMLTableCellElement> | undefined;\n}\n\n/**\n * Part: a cell (`<td>`), or the row's header with `rowHeader` (`<th scope=\"row\">`).\n *\n * @group Data\n * @example\n * <TableCell rowHeader>Braised short ribs</TableCell>\n * <TableCell align=\"end\">6</TableCell>\n */\nexport function TableCell(props: TableCellProps): JSX.Element {\n  const { rowHeader, align, wrap, className, children, ...rest } = props;\n  const table = useTable(\"TableCell\");\n  const row = useContext(RowContext) ?? misplaced(\"TableCell\", \"TableRow\");\n  const id = useId();\n  useAppearanceClassNameCheck(\"TableCell\", className, cellHint(), alignHint(\"TableCell\"));\n  useAlignCheck(\"TableCell\", align);\n  // The first row header cell holds the row link; a second one stays plain (TableRow warns).\n  if (rowHeader && row.href !== undefined) row.claim.owner ??= id;\n  const holdsLink = rowHeader && row.href !== undefined && row.claim.owner === id;\n  const Element = rowHeader ? \"th\" : \"td\";\n  return (\n    <Element\n      scope={rowHeader ? \"row\" : undefined}\n      {...rest}\n      className={cn(\n        cellBase,\n        cellPad[table.dense ? \"dense\" : \"md\"],\n        alignClasses[alignOf(align)],\n        sectionCell[row.section],\n        rowHeader && \"font-medium\",\n        wrap && wrapClass,\n        className,\n      )}\n    >\n      {holdsLink ? (\n        <RouterLink\n          href={row.href!}\n          target={row.external ? \"_blank\" : undefined}\n          rel={row.external ? safeRel(undefined) : undefined}\n          data-table-row-link=\"\"\n          data-stretched-link=\"\"\n          data-ouro-control=\"table\"\n          data-ouro-part=\"row-link\"\n          className={cn(stretchedLinkClass, rowLinkClass)}\n        >\n          {children}\n          {row.external && (\n            <span data-external-label=\"\" className=\"sr-only\">\n              {\" \"}\n              {row.externalLabel}\n            </span>\n          )}\n        </RouterLink>\n      ) : (\n        children\n      )}\n    </Element>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/table/table-parts.tsx"
    },
    {
      "path": "registry/ouro/components/ouro/table/table-styles.ts",
      "content": "export { alignClasses, cellBase, cellPad, directionOf, directionWarning, headCell, rowLinkClass, sectionCell, sortButtonClass, sortIconPaths, sortedLabelDefault, stickyHead, tableAligns, wrapClass };\nexport type { TableAlign, TableSortDirection };\n\n/** How a column's content lines up: `end` for numbers, `center` for a status mark. */\ntype TableAlign = \"start\" | \"center\" | \"end\";\n\n/** The alignments a column or cell takes, for the dev message on an unknown one. */\nconst tableAligns: readonly TableAlign[] = [\"start\", \"center\", \"end\"];\n\nconst alignClasses = { start: \"text-start\", center: \"text-center\", end: \"text-end\" } as const;\n\n// Cells stay on one line, so a wide table scrolls sideways instead of squeezing its columns.\nconst cellBase = \"m-0 align-middle whitespace-nowrap border-b border-border font-normal\";\n// `anywhere` (not `break-word`) also lowers the cell's minimum width, so a long URL wraps\n// instead of widening the column.\nconst wrapClass = \"whitespace-normal wrap-anywhere min-w-48\";\nconst cellPad = { md: \"px-4 py-3\", dense: \"px-3 py-1.5\" } as const;\n\nconst headCell = \"font-medium text-muted-foreground\";\n// Inside the ScrollArea's viewport, which scrolls both ways, the header sticks to its top and\n// moves sideways with its column. z-20 keeps it over the rows' links (z-1) and raised controls (z-10).\nconst stickyHead = \"sticky top-0 z-20 bg-background\";\n\n// The last body row has no line under it; a footer has a line above it and none under it.\nconst sectionCell = {\n  head: \"\",\n  body: \"[tbody>tr:last-child>&]:border-b-0\",\n  foot: \"border-t border-b-0 font-medium\",\n} as const;\n\n// The row link's focus ring is drawn by the layer that covers the row, so it outlines the\n// whole row in every browser (WebKit paints no outline on a <tr>).\nconst rowLinkClass = \"after:outline-ring after:-outline-offset-2 focus-visible:after:outline-2 focus-visible:after:outline-solid\";\n\n/** Which way a sorted column runs, in the words `aria-sort` uses. */\ntype TableSortDirection = \"ascending\" | \"descending\";\n\n/** What screen readers hear after a header sorts the rows, unless the table says otherwise. */\nconst sortedLabelDefault = (header: string, direction: TableSortDirection): string => `Sorted by ${header}, ${direction}`;\n\n// The sort button's layer covers its header cell, so a press anywhere on the cell sorts, and its\n// focus ring outlines the cell. It highlights while pressed instead of scaling, as a linked row\n// does, because a whole cell that shrinks reads as a jump. Under forced colours the layer keeps an\n// edge, since its highlight is a background.\nconst sortButtonClass =\n  \"m-0 inline-flex max-w-full cursor-pointer items-center gap-1.5 border-0 bg-transparent p-0 text-start [font:inherit] text-inherit outline-none \" +\n  \"pointer-fine:hover:text-foreground after:absolute after:inset-0 after:z-1 after:content-[''] \" +\n  \"after:transition-colors after:duration-(--ouro-duration-fast) pointer-fine:hover:after:bg-foreground/[0.03] active:after:bg-foreground/[0.06] \" +\n  \"after:outline-ring after:-outline-offset-2 focus-visible:after:outline-2 focus-visible:after:outline-solid \" +\n  \"forced-colors:after:border forced-colors:after:border-solid\";\n\n// An arrow up or down for the sorted column, and both chevrons for one that can sort: a shape, not a colour.\nconst sortIconPaths = {\n  ascending: \"M8 13V3M4 7l4-4 4 4\",\n  descending: \"M8 3v10M4 9l4 4 4-4\",\n  none: \"M5 6l3-3 3 3M5 10l3 3 3-3\",\n} as const;\n\n/** A sort direction that is not one of ours reads as ascending. */\nfunction directionOf(direction: string | undefined): TableSortDirection | undefined {\n  return direction === undefined ? undefined : direction === \"descending\" ? \"descending\" : \"ascending\";\n}\n\n/** The development message for a sort direction that is not one of ours, with `fix` given the likely one. */\nfunction directionWarning(direction: string | undefined, fix: (direction: TableSortDirection) => string): readonly [string, string] | false {\n  return (\n    directionOf(direction) !== direction && [\n      `\"${direction}\" is not a sort direction; use \"ascending\" or \"descending\"`,\n      fix(String(direction).startsWith(\"d\") ? \"descending\" : \"ascending\"),\n    ]\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/table/table-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/table/table.tsx",
      "content": "\"use client\";\n\nimport { useMemo, useState, useSyncExternalStore, type CSSProperties, type HTMLAttributes, type JSX, type Key, type ReactNode, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { useDevWarnings, type DevWarning } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { TableBody, TableCell, TableHead, TableFrame, TableHeader, TableRow, type TableAlign } from \"@/registry/ouro/components/ouro/table/table-parts\";\nimport { directionOf, directionWarning, type TableSortDirection } from \"@/registry/ouro/components/ouro/table/table-styles\";\n\nexport type { TableSortDirection } from \"@/registry/ouro/components/ouro/table/table-styles\";\n\n/** The keys of `Row` whose values are assignable to `Value`. */\nexport type TableKeysOf<Row, Value> = { [K in keyof Row]-?: Row[K] extends Value ? K : never }[keyof Row] & string;\n\n/** What a column sorts by: text, a number, a date or a boolean. An empty value sorts last. */\nexport type TableSortValue = string | number | Date | boolean | null | undefined;\n\n/**\n * Which column the rows are sorted by, and which way: what `sort`, `defaultSort` and\n * `onSortChange` take.\n *\n * @example\n * const [sort, setSort] = useState<TableSort>({ key: \"name\", direction: \"ascending\" });\n */\nexport interface TableSort {\n  /** The sorted column's `key`. */\n  key: string;\n  /** `\"ascending\"`: A to Z, low to high, old to new. `\"descending\"`: the other way. */\n  direction: TableSortDirection | (string & { 'Use \"ascending\" or \"descending\": asc is \"ascending\"': never });\n}\n\n/**\n * What every column takes, whichever way its cells are filled.\n *\n * @claim \"What every column takes, whichever way\" registry/ouro/components/ouro/table/table.test-d.ts verify:fileLine(registry/ouro/components/ouro/table/table.test-d.ts, /expectTypeOf<\\{\\skey:\\s\"name\"\\s\\}>\\(\\)\\.not\\.toExtend<TableColumn<Recipe>>/)\n */\nexport interface TableColumnBase {\n  /**\n   * The column's name, in its header cell. Keep it even for a column of buttons, and hide\n   * it with `hideHeader`: screen readers read it with every cell.\n   */\n  header: string;\n  /** Hides the header visually and keeps it for screen readers, for a column of actions. */\n  hideHeader?: boolean | undefined;\n  /**\n   * How the column lines up: `end` for numbers and amounts, `center` for a status mark.\n   * @default \"start\"\n   */\n  align?: TableAlign | (string & { 'Use \"start\", \"center\" or \"end\": right is \"end\"': never }) | undefined;\n  /**\n   * Makes this column the rows' headers (`<th scope=\"row\">`), what each row is. With\n   * `rowHref` its cell holds the row's link and names it. Without one, the first column with\n   * no `cell` renderer is, or else the first column.\n   * @claim \"Makes this column the rows' headers\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > makes the column marked rowHeader the row header, and keeps a hidden header's name)\n   * @claim \"Makes this column the rows' headers\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > renders a semantic table named by its caption, with column and row headers)\n   * @claim \"Without one, the first column with\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table with rowHref > puts the row link in the first column without a cell renderer, past a leading checkbox)\n   */\n  rowHeader?: boolean | undefined;\n  /**\n   * Lets long text wrap onto more lines, at least 192px wide, instead of widening the table.\n   *\n   * @claim \"Lets long text wrap onto more\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > lets a column with wrap break its text onto more lines, at least 192px wide)\n   * @claim \"Lets long text wrap onto more\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > breaks a long URL in a wrap column instead of widening it)\n   */\n  wrap?: boolean | undefined;\n  /** Layout only, on the header cell: a width (`w-32`). */\n  className?: string | undefined;\n  /**\n   * Makes the column's header a button that sorts the rows by it; pressing it again reverses\n   * them. Table sorts by the row's `key` field, or by `sortValue`: numbers and dates as\n   * numbers and dates, text in the reader's language with the numbers in it in order (\"Step 2\"\n   * before \"Step 10\"), and rows with an empty value last. Rows with equal values keep their order.\n   *\n   * @claim \"Makes the column's header a button\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > sorts by a sortable column from its header, and reverses on the next press, with aria-sort and an arrow)\n   * @claim \"Table sorts by the row's `key`\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > sorts numbers, dates and text with numbers in order, and puts empty values last both ways)\n   * @claim \"Rows with equal values keep their\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > keeps rows with equal values in their order, both ways)\n   */\n  sortable?: boolean | undefined;\n\n  /** Not a prop. Ouro UI uses `sortable`: `{ key: \"name\", header: \"Recipe\", sortable: true }`. */\n  enableSorting?: { \"Use sortable: true\": never };\n  /** Not a prop. Ouro UI uses `key`: `{ key: \"name\", header: \"Recipe\" }`. */\n  accessorKey?: { 'Use key: \"name\"': never };\n  /** Not a prop. Ouro UI uses `header`: `{ key: \"name\", header: \"Recipe\" }`. */\n  title?: { 'Use header: \"Recipe\"': never };\n  /** Not a prop. Ouro UI uses `header`: `{ key: \"name\", header: \"Recipe\" }`. */\n  label?: { 'Use header: \"Recipe\"': never };\n  /** Not a prop. Ouro UI uses `cell`: `{ key: \"save\", header: \"Save\", cell: (row) => <Button>Save</Button> }`. */\n  render?: { \"Use cell: (row) => ...\": never };\n}\n\n/**\n * One column of a {@link Table}: its `header`, and where its cells come from. `key` names a\n * field of the row whose value is shown as it is (text, a number, an element), or, with\n * `cell`, any name, and `cell` renders each row's cell.\n * @claim \"`key` names a field of the\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > renders a semantic table named by its caption, with column and row headers)\n */\nexport type TableColumn<Row> = TableColumnBase & {\n  /**\n   * What the column sorts by, when its cells show something else (a `cell` renderer, a\n   * formatted date): `sortValue: (row) => row.added`. It makes the column `sortable`.\n   *\n   * @claim \"It makes the column `sortable`\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > sorts a cell column by its sortValue, which makes it sortable)\n   */\n  sortValue?: ((row: Row) => TableSortValue) | undefined;\n} & (\n    | {\n        /**\n         * The field of each row to show, and the column's React key.\n         *\n         * @claim \"The field of each row to\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > keys rows by id, by a rowKey field or function, and by index without an id)\n         */\n        key: TableKeysOf<Row, ReactNode>;\n        /** Renders the row's cell instead of the field's value. */\n        cell?: ((row: Row, index: number) => ReactNode) | undefined;\n      }\n    | {\n        /** The column's name for React; with `cell`, it need not be a field of the row. */\n        key: string;\n        /**\n         * Renders the row's cell: a badge, a formatted date, a button. From a Server\n         * Component, put the element in the row's field instead, because a function can't\n         * cross to the client.\n         */\n        cell: (row: Row, index: number) => ReactNode;\n      }\n  );\n\n/**\n * The props every Table takes, with columns and rows or with parts.\n *\n * @claim \"The props every Table takes, with\" registry/ouro/components/ouro/table/table.test-d.ts verify:fileLine(registry/ouro/components/ouro/table/table.test-d.ts, /expectTypeOf<\\{\\scaption:\\s\"Recipes\";\\scolumns:\\sTableColumn<Recipe>\\[\\];\\srows:\\sRecipe\\[\\];\\srowHref:\\s\"href\";\\srowKey:\\s\"id\"\\s\\}>\\(\\)\\.toExtend<TableProps<Recipe>>/)\n * @claim \"The props every Table takes, with\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > renders a semantic table named by its caption, with column and row headers)\n */\nexport interface TableOwnProps {\n  /**\n   * What the table shows: \"Recipes\", \"Order history\". It names the table and its scrolling\n   * region for screen readers, and shows above it unless `hideCaption`.\n   */\n  caption: string;\n  /** Hides the caption visually and keeps it as the table's name, when a heading already shows it. */\n  hideCaption?: boolean | undefined;\n  /**\n   * Shades every other body row, for long rows that are hard to follow across.\n   *\n   * @claim \"Shades every other body row, for\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > shades every other body row with striped)\n   */\n  striped?: boolean | undefined;\n  /**\n   * Tighter cells, for many rows. A row is still 44px tall on a touch screen when it is a link.\n   *\n   * @claim \"A row is still 44px tall\" registry/ouro/components/ouro/table/table.touch.test.tsx verify:fileLine(registry/ouro/components/ouro/table/table.touch.test.tsx, /makes\\sa\\slinked\\srow\\sat\\sleast\\s44px\\stall\\sin\\s%s/)\n   */\n  dense?: boolean | undefined;\n  /**\n   * Keeps the header row at the top while the rows scroll under it. The table scrolls inside\n   * its own height, so give it one: `className=\"max-h-96\"`. It keeps working while the table\n   * also scrolls sideways.\n   */\n  stickyHeader?: boolean | undefined;\n  /**\n   * Layout: margins, width, and the height the table scrolls inside (`max-h-96`). Appearance\n   * classes warn in development; put the Table inside a `Card` for a frame.\n   */\n  className?: string | undefined;\n  style?: CSSProperties | undefined;\n  /** A ref to the `<table>` element. */\n  ref?: Ref<HTMLTableElement> | undefined;\n  /**\n   * What screen readers hear after a header sorts the rows, from the column's header and the\n   * new direction. Pass it to translate the message.\n   * @default (header, direction) => `Sorted by ${header}, ${direction}`\n   * @claim \"What screen readers hear after a\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > tells screen readers how the rows are sorted, once per press, in the words sortedLabel gives)\n   */\n  sortedLabel?: ((header: string, direction: TableSortDirection) => string) | undefined;\n\n  /** Not a prop. Ouro UI uses `rows`: `<Table rows={recipes} columns={…}>`. */\n  data?: { \"Use rows={recipes}\": never };\n  /** Not a prop. A row opens a link with `rowHref`: `` <Table rowHref={(row) => `/recipes/${row.id}`}> ``. */\n  onRowClick?: { \"Use rowHref={(row) => `/recipes/${row.id}`}\": never };\n  /** Not a prop. Ouro UI uses `caption`: `<Table caption=\"Recipes\">`. */\n  title?: { 'Use <Table caption=\"Recipes\">': never };\n  /** Not a prop. A column sorts with `sortable`: `{ key: \"name\", header: \"Recipe\", sortable: true }`. */\n  sortable?: { \"Put sortable on a column: { key, header, sortable: true }\": never };\n}\n\n/** With columns and rows: the props that describe the whole table. */\nexport interface TableDataProps<Row> {\n  /**\n   * The columns, in order: each one's `header`, `key` and optional `cell`.\n   *\n   * @claim \"The columns, in order: each one's\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > renders a semantic table named by its caption, with column and row headers)\n   */\n  columns: readonly TableColumn<NoInfer<Row>>[];\n  /** The rows, in the order to show them until a `sortable` column sorts them. Table does not page them. */\n  rows: readonly Row[];\n  /**\n   * The sorted column, controlled: Table marks its header and shows the rows in the order you\n   * pass them, so you sort them (on a server, say), and `onSortChange` tells you which sort to\n   * show next. Pass `null` while nothing is sorted. To let Table sort the rows itself, use\n   * `defaultSort` instead.\n   *\n   * @claim \"Table marks its header and shows\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > with sort, marks the header and keeps the rows in the order passed, and asks for the next sort)\n   */\n  sort?: TableSort | null | undefined;\n  /**\n   * The column the rows are sorted by at first. Table then sorts the rows itself as the\n   * headers are pressed.\n   *\n   * @claim \"The column the rows are sorted\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > starts sorted by defaultSort, and renders it on the server)\n   */\n  defaultSort?: TableSort | undefined;\n  /** Called with the new sort when a header is pressed, with `sort` or without it. */\n  onSortChange?: ((sort: { key: string; direction: TableSortDirection }) => void) | undefined;\n  /**\n   * Each row's React key: the name of a field (`rowKey=\"slug\"`) or a function. Without it,\n   * a row's `id` field, or else its position.\n   * @claim \"Each row's React key: the name\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > keys rows by id, by a rowKey field or function, and by index without an id)\n   */\n  rowKey?: TableKeysOf<Row, string | number> | ((row: Row, index: number) => Key) | undefined;\n  /**\n   * Makes each row one link, with one tab stop, named by its row header cell: a function\n   * that returns the row's path (or `undefined` for a row that is not a link), or the name\n   * of a field that holds it (`rowHref=\"href\"`), which a Server Component can pass. Buttons,\n   * links and inputs in the cells stay their own tab stops and take their own taps. On a\n   * touch screen a linked row is at least 44px tall.\n   * @claim \"On a touch screen a linked\" registry/ouro/components/ouro/table/table.touch.test.tsx verify:fileLine(registry/ouro/components/ouro/table/table.touch.test.tsx, /makes\\sa\\slinked\\srow\\sat\\sleast\\s44px\\stall\\sin\\s%s/)\n   * @claim \"Makes each row one link, with\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table with rowHref > makes each linked row one link named by its row header, with one tab stop, covering the row)\n   * @claim \"Makes each row one link, with\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table parts > warns when a linked row has no row header cell to hold its link)\n   */\n  rowHref?: TableKeysOf<Row, string | undefined> | ((row: Row) => string | undefined) | undefined;\n  /**\n   * Opens every row link in a new tab, safely, and tells screen readers so with `externalLabel`.\n   *\n   * @claim \"Opens every row link in a\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table with rowHref > opens external row links in a new tab, safely, and says so with a translatable label)\n   * @claim \"Opens every row link in a\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table with rowHref > keeps internal row links in the same tab)\n   */\n  rowExternal?: boolean | undefined;\n  /**\n   * What screen readers hear after a row link's name with `rowExternal`.\n   * @default \"(opens in a new tab)\"\n   */\n  externalLabel?: string | undefined;\n  /**\n   * What the body shows when there are no rows, in one cell across every column.\n   * @default \"Nothing here yet.\"\n   * @claim \"What the body shows when there\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table > shows the empty message in one cell across every column)\n   */\n  empty?: ReactNode;\n  /** Only with parts. Pass columns and rows, or parts as children. */\n  children?: never;\n}\n\n/** With parts: `TableHeader`, `TableBody` and `TableFooter` as children. */\nexport interface TablePartsProps {\n  /** The parts: `TableHeader`, `TableBody` and `TableFooter`, with `TableRow`, `TableHead` and `TableCell` in them. */\n  children: ReactNode;\n  /** Only without parts. */\n  columns?: never;\n  /** Only without parts. */\n  rows?: never;\n  /** Only without parts. */\n  rowKey?: never;\n  /** Only without parts. Give a linked row `<TableRow href=\"…\">`. */\n  rowHref?: never;\n  /** Only without parts. */\n  empty?: never;\n  /** Only without parts. Give a row `<TableRow href=\"…\" external>`. */\n  rowExternal?: never;\n  /** Only without parts. Give a row `<TableRow externalLabel=\"…\">`. */\n  externalLabel?: never;\n  /** Only without parts. Give the sorted column's header `<TableHead sorted=\"ascending\">`. */\n  sort?: never;\n  /** Only without parts. Give the sorted column's header `<TableHead sorted=\"ascending\">`. */\n  defaultSort?: never;\n  /** Only without parts. Give each header `<TableHead onSort={…}>`. */\n  onSortChange?: never;\n}\n\n/**\n * Props for {@link Table}: columns and rows, or parts as children. The HTML attributes go to\n * the root `<div>`, and sit outside the union, which keeps the editor's hover docs.\n */\nexport type TableProps<Row extends object = Record<string, unknown>> = Omit<HTMLAttributes<HTMLDivElement>, keyof TableOwnProps | \"children\"> &\n  TableOwnProps &\n  (TableDataProps<Row> | TablePartsProps);\n\nconst aligns: readonly string[] = [\"start\", \"center\", \"end\"];\n\n/** Whether the className or style gives the table a height to scroll inside. */\nfunction hasHeight(className: string | undefined, style: CSSProperties | undefined): boolean {\n  if (style?.height !== undefined || style?.maxHeight !== undefined) return true;\n  return (className ?? \"\").split(/\\s+/).some((token) => /^(max-)?h-/.test(token.slice(token.lastIndexOf(\":\") + 1)));\n}\n\n/** What a value sorts as: a number (for numbers, dates and booleans), text, or `null` for an empty value or one that can't sort. */\nfunction sortKey(value: unknown): number | string | null {\n  const plain = value instanceof Date ? value.getTime() : typeof value === \"boolean\" ? Number(value) : value;\n  if (typeof plain === \"number\") return Number.isNaN(plain) ? null : plain;\n  return typeof plain === \"string\" && plain !== \"\" ? plain : null;\n}\n\ntype SortColumn<Row> = TableColumnBase & { key: string; sortValue?: ((row: Row) => TableSortValue) | undefined };\n\nconst isSortable = (column: { sortable?: boolean | undefined; sortValue?: unknown }) => column.sortable ?? column.sortValue !== undefined;\n\n/** The value a column sorts a row by: its `sortValue`, or else the row's field. */\nconst sortValueOf = <Row,>(column: SortColumn<Row>, row: Row): unknown => (column.sortValue ? column.sortValue(row) : (row as Record<string, unknown>)[column.key]);\n\n/**\n * The rows in the sort's order: stable, with empty values last both ways, numbers before text\n * when a column mixes them, and text compared in `locale` with the numbers in it in order.\n */\nfunction sortRows<Row>(rows: readonly Row[], column: SortColumn<Row>, direction: TableSortDirection, locale: string | undefined): readonly Row[] {\n  const collator = new Intl.Collator(locale, { numeric: true });\n  const sign = direction === \"descending\" ? -1 : 1;\n  const compare = (a: number | string, b: number | string) =>\n    typeof a !== typeof b ? (typeof a === \"number\" ? -1 : 1) : typeof a === \"number\" ? a - (b as number) : collator.compare(a as string, b as string);\n  const keyed = rows.map((row) => ({ row, key: sortKey(sortValueOf(column, row)) }));\n  // Array sort is stable, so rows with equal values keep their order, and so do the empty ones after them.\n  const valued = keyed.filter((entry): entry is { row: Row; key: number | string } => entry.key !== null).sort((x, y) => sign * compare(x.key, y.key));\n  return [...valued, ...keyed.filter((entry) => entry.key === null)].map((entry) => entry.row);\n}\n\n// Text sorts in the reader's language, which the server can't know: it sorts in English, and\n// the browser sorts again in its own language once the page has hydrated.\n// Stryker disable next-line ArrowFunction: the store never changes, so there is nothing to unsubscribe\nconst noSubscribe = () => () => {};\n// Stryker disable next-line ArrowFunction: undefined is the browser's own locale, so the mutant is the same function\nconst browserLocale = () => undefined;\n// Stryker disable next-line ArrowFunction: the test browsers' own locale is English, so they sort as the mutant does; pinning it keeps every server alike\nconst serverLocale = () => \"en\";\n\nconst none: readonly never[] = [];\n\nfunction sortWarnings<Row>(columns: readonly SortColumn<Row>[], rows: readonly Row[], sort: TableSort | undefined): DevWarning[] {\n  const named = sort && columns.find((column) => column.key === sort.key);\n  return [\n    sort !== undefined && directionWarning(sort.direction, (direction) => `{ key: \"${sort.key}\", direction: \"${direction}\" }`),\n    sort !== undefined &&\n      !(named && isSortable(named)) && [`the sort names \"${sort.key}\", which is not a sortable column`, `{ key: \"${sort.key}\", header: \"…\", sortable: true }`],\n    ...columns.map((column): DevWarning => {\n      if (!isSortable(column) || column.sortValue || rows.length === 0) return false;\n      const fields = rows as readonly Record<string, unknown>[];\n      // A `cell` column whose key is no field, or a field that holds an element.\n      const missing = fields.every((row) => !(column.key in row));\n      const element = fields.some((row) => typeof row[column.key] === \"object\" && row[column.key] !== null && !(row[column.key] instanceof Date));\n      return (\n        (missing || element) && [\n          `column \"${column.key}\" has no text, number or date to sort by`,\n          `{ key: \"${column.key}\", header: \"…\", sortable: true, sortValue: (row) => row.name }`,\n        ]\n      );\n    }),\n  ];\n}\n\nfunction columnWarnings(columns: readonly (TableColumnBase & { key: string })[]): DevWarning[] {\n  const seen = new Set<string>();\n  return columns.flatMap((column): DevWarning[] => {\n    const { key } = column;\n    const duplicate = seen.has(key);\n    seen.add(key);\n    return [\n      !column.header && [\"every column needs a header; it names the column for screen readers\", '{ key: \"…\", header: \"Actions\", hideHeader: true }'],\n      duplicate && [`two columns have key \"${key}\"; keys name columns, so each is unique`, '{ key: \"name\", … }, { key: \"time\", … }'],\n      column.align !== undefined &&\n        !aligns.includes(column.align) && [\n          `align=\"${String(column.align)}\" is not an alignment; use \"start\", \"center\", \"end\"`,\n          `{ align: \"${String(column.align) === \"left\" ? \"start\" : \"end\"}\" }`,\n        ],\n      column.accessorKey !== undefined && [\"a column's accessorKey is not a prop\", `{ key: \"${String(column.accessorKey)}\", header: \"…\" }`],\n      column.title !== undefined && [\"a column's title is not a prop\", `{ key: \"…\", header: \"${String(column.title)}\" }`],\n      column.label !== undefined && [\"a column's label is not a prop\", `{ key: \"…\", header: \"${String(column.label)}\" }`],\n      column.render !== undefined && [\"a column's render is not a prop\", '{ key: \"…\", header: \"…\", cell: (row) => … }'],\n      column.enableSorting !== undefined && [\"a column's enableSorting is not a prop\", `{ key: \"${key}\", header: \"…\", sortable: true }`],\n    ];\n  });\n}\n\n/**\n * A data table: a caption, column headers, and rows, from `columns` and `rows` or from\n * parts. It scrolls sideways inside its own region on a phone, so the page never does.\n * With `rowHref` each row is one link with one tab stop, named by its row header, and the\n * buttons, links and inputs in its cells keep their own taps. A `sortable` column sorts the\n * rows when its header is pressed, and reverses them on the next press. `striped`, `dense` and\n * `stickyHeader` (inside a height you set) change how it reads. It does not page or filter.\n *\n * Use `DescriptionList` instead for one thing's details as label and value pairs, and\n * `ItemGroup` for a list of rows that need no columns, which reads better on a phone. To sort\n * on a server or by more than one column, control `sort` and pass the rows in that order.\n *\n * @group Data\n * @see https://ui.ouroboros.bot/docs/table\n *\n * @example\n * <Table\n *   caption=\"Recipes\"\n *   columns={[\n *     { key: \"name\", header: \"Recipe\" },\n *     { key: \"time\", header: \"Time\" },\n *     { key: \"serves\", header: \"Serves\", align: \"end\" },\n *   ]}\n *   rows={recipes}\n *   rowHref={(recipe) => `/recipes/${recipe.id}`}\n * />\n * <Table\n *   caption=\"Orders\"\n *   columns={[\n *     { key: \"customer\", header: \"Customer\", sortable: true },\n *     { key: \"placed\", header: \"Placed\", cell: (order) => formatDate(order.placed), sortValue: (order) => order.placed },\n *     { key: \"total\", header: \"Total\", align: \"end\", sortable: true },\n *   ]}\n *   rows={orders}\n *   defaultSort={{ key: \"placed\", direction: \"descending\" }}\n * />\n * <Table caption=\"Pantry\" hideCaption>\n *   <TableHeader>\n *     <TableRow><TableHead>Item</TableHead><TableHead align=\"end\">Qty</TableHead></TableRow>\n *   </TableHeader>\n *   <TableBody>\n *     <TableRow><TableCell rowHeader>Flour</TableCell><TableCell align=\"end\">2 kg</TableCell></TableRow>\n *   </TableBody>\n * </Table>\n * @claim \"A `sortable` column sorts the rows\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table sorting > sorts by a sortable column from its header, and reverses on the next press, with aria-sort and an arrow)\n * @claim \"It scrolls sideways inside its own\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table scrolling > scrolls sideways inside its own region on a phone, named by the caption, without widening the page)\n * @claim \"With `rowHref` each row is one\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table with rowHref > opens the row from a real tap on any cell, and buttons, links and inputs in cells keep their own taps on a phone)\n * @claim \"With `rowHref` each row is one\" registry/ouro/components/ouro/table/table.test.tsx verify:testExists(registry/ouro/components/ouro/table/table.test.tsx::Table with rowHref > makes each linked row one link named by its row header, with one tab stop, covering the row)\n */\nexport function Table<Row extends object = Record<string, unknown>>(props: TableProps<Row>): JSX.Element {\n  const {\n    caption,\n    hideCaption,\n    striped,\n    dense,\n    stickyHeader,\n    className,\n    style,\n    ref,\n    columns,\n    rows,\n    rowKey,\n    rowHref,\n    rowExternal,\n    externalLabel,\n    empty = \"Nothing here yet.\",\n    sort,\n    defaultSort,\n    onSortChange,\n    sortedLabel,\n    children,\n    data,\n    onRowClick,\n    title,\n    sortable,\n    ...rest\n  } = props as TableProps<Row> & Partial<TableDataProps<Row>> & { children?: ReactNode };\n  useAppearanceClassNameCheck(\n    \"Table\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? \"put the Table inside a <Card> for a frame\" : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Table\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !caption && [\"caption is required; it names the table\", '<Table caption=\"Recipes\">, with hideCaption when a heading already shows it'],\n          data !== undefined && [\"data is not a prop\", \"<Table rows={recipes} columns={…}>\"],\n          onRowClick !== undefined && [\"onRowClick is not a prop; a row opens a link\", \"<Table rowHref={(row) => `/recipes/${row.id}`}>\"],\n          title !== undefined && [\"title is not a prop\", `<Table caption=\"${String(title)}\">`],\n          sortable !== undefined && [\"sortable is not a Table prop; it goes on a column\", '{ key: \"name\", header: \"Recipe\", sortable: true }'],\n          children !== undefined &&\n            columns !== undefined && [\"pass columns and rows, or parts as children, not both\", '<Table caption=\"…\" columns={…} rows={…} />'],\n          columns !== undefined && rows === undefined && [\"columns need rows\", \"<Table columns={…} rows={recipes}>\"],\n          stickyHeader && !hasHeight(className, style) && [\"stickyHeader needs a height to scroll inside\", '<Table stickyHeader className=\"max-h-96\">'],\n          ...columnWarnings(columns ?? []),\n          ...sortWarnings(columns ?? none, rows ?? none, sort ?? defaultSort),\n          sort !== undefined &&\n            !onSortChange && [\"sort needs onSortChange, or its headers can't change it\", \"<Table sort={sort} onSortChange={setSort}>, or defaultSort={…} for Table to sort the rows\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const list = rows ?? none;\n  const [ownSort, setOwnSort] = useState<TableSort | null>(defaultSort ?? null);\n  const controlled = sort !== undefined;\n  const current = controlled ? sort : ownSort;\n  const sortColumn = (columns ?? none).find((column) => column.key === current?.key && isSortable(column));\n  const direction = directionOf(current?.direction);\n  const locale = useSyncExternalStore(noSubscribe, browserLocale, serverLocale);\n  const changeSort = (next: { key: string; direction: TableSortDirection }) => {\n    // Controlled, the state goes unread, so setting it is harmless.\n    setOwnSort(next);\n    onSortChange?.(next);\n  };\n  const shown = useMemo(\n    () => (controlled || !sortColumn ? list : sortRows(list, sortColumn as SortColumn<Row>, direction!, locale)),\n    [controlled, list, sortColumn, direction, locale],\n  );\n  // The row header holds the row link and names it: the column marked rowHeader, or else the\n  // first that shows a field's value (a `cell` renderer is often a checkbox or a badge).\n  const marked = columns?.findIndex((column) => column.rowHeader) ?? -1;\n  const headerIndex = marked >= 0 ? marked : Math.max(0, columns?.findIndex((column) => !column.cell) ?? 0);\n  const alignOf = (align: string | undefined) => (align !== undefined && aligns.includes(align) ? (align as TableAlign) : undefined);\n  const body =\n    columns === undefined ? (\n      children\n    ) : (\n      <>\n        <TableHeader>\n          <TableRow>\n            {columns.map((column) => (\n              <TableHead\n                key={column.key}\n                align={alignOf(column.align)}\n                hideHeader={column.hideHeader}\n                wrap={column.wrap}\n                className={column.className}\n                sorted={column === sortColumn ? direction : undefined}\n                onSort={isSortable(column) ? (next) => changeSort({ key: column.key, direction: next }) : undefined}\n              >\n                {column.header}\n              </TableHead>\n            ))}\n          </TableRow>\n        </TableHeader>\n        <TableBody>\n          {shown.length === 0 ? (\n            <TableRow>\n              <TableCell colSpan={columns.length}>\n                <span className=\"text-muted-foreground\">{empty}</span>\n              </TableCell>\n            </TableRow>\n          ) : (\n            shown.map((row, index) => {\n              const fields = row as Record<string, unknown>;\n              const key =\n                typeof rowKey === \"function\"\n                  ? rowKey(row, index)\n                  : rowKey !== undefined\n                    ? (fields[rowKey] as Key)\n                    : typeof fields[\"id\"] === \"string\" || typeof fields[\"id\"] === \"number\"\n                      ? fields[\"id\"]\n                      : index;\n              const href = typeof rowHref === \"function\" ? rowHref(row) : rowHref !== undefined ? (fields[rowHref] as string | undefined) : undefined;\n              return (\n                <TableRow key={key} href={href} external={rowExternal} externalLabel={externalLabel}>\n                  {columns.map((column, columnIndex) => (\n                    <TableCell key={column.key} rowHeader={columnIndex === headerIndex} align={alignOf(column.align)} wrap={column.wrap}>\n                      {column.cell ? column.cell(row, index) : (fields[column.key] as ReactNode)}\n                    </TableCell>\n                  ))}\n                </TableRow>\n              );\n            })\n          )}\n        </TableBody>\n      </>\n    );\n  return (\n    <TableFrame\n      {...rest}\n      caption={caption}\n      hideCaption={hideCaption}\n      striped={striped}\n      dense={dense}\n      stickyHeader={stickyHeader}\n      sortedLabel={sortedLabel}\n      className={className}\n      style={style}\n      tableRef={ref}\n    >\n      {body}\n    </TableFrame>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/table/table.tsx"
    }
  ],
  "docs": "A data table: a caption, column headers, and rows, from `columns` and `rows` or from parts. Import: import { Table } from \"@/components/ouro/table/table\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: scroll-area, 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/table.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}