{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-table",
  "title": "Data Table",
  "description": "TanStack Table driving the Keyline table parts: useDataTable (sorting, multi-sort, filters, a search, paging, row selection, column visibility; each slice controlled or not) and DataTable, DataTableBulkBar, DataTablePagination and DataTableSearch. Selecting a row re-renders that row alone.",
  "dependencies": [
    "@tanstack/react-table@9.3.1"
  ],
  "registryDependencies": [
    "@keyline-ui/keyline",
    "@keyline-ui/table",
    "@keyline-ui/data-table-model",
    "@keyline-ui/keyline-render"
  ],
  "files": [
    {
      "path": "src/registry/keyline/ui/data-table.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport {\n  FlexRender,\n  Subscribe,\n  columnFilteringFeature,\n  columnVisibilityFeature,\n  constructFilterFn,\n  createFilteredRowModel,\n  createPaginatedRowModel,\n  createSortedRowModel,\n  functionalUpdate,\n  globalFilteringFeature,\n  rowExpandingFeature,\n  rowPaginationFeature,\n  rowSelectionFeature,\n  rowSortingFeature,\n  sortFn_alphanumeric,\n  sortFn_basic,\n  sortFn_datetime,\n  sortFn_text,\n  tableFeatures,\n  useTable,\n  type ColumnDef,\n  type ColumnFiltersState,\n  type ColumnVisibilityState,\n  type ExpandedState,\n  type Header,\n  type PaginationState,\n  type ReactTable,\n  type Row,\n  type RowData,\n  type RowSelectionState,\n  type SortingState,\n  type TableState,\n  type Updater,\n} from \"@tanstack/react-table\";\n\nimport {\n  Table,\n  TableBody,\n  TableBulkBar,\n  TableCaption,\n  TableCell,\n  TableDetail,\n  TableExpandCell,\n  TableHead,\n  TableHeader,\n  TableIndexCell,\n  TableLoadingRows,\n  TablePagination,\n  TableRow,\n  TableSearch,\n  TableSortHeader,\n  TableState as TableStateRow,\n  useDetailPresence,\n  type TableBulkBarProps,\n  type TableRowProps,\n} from \"./table\";\nimport type { PartProps } from \"../lib/keyline-render\";\nimport {\n  columnAlign,\n  columnCellClassName,\n  isFilterActive,\n  matchesFilter,\n  matchesSearch,\n  nextSorting,\n  rowCode,\n  sortLevelOf,\n  type DataTableFilter,\n} from \"../lib/data-table\";\n\n/* ------------------------------------------------------------------ *\n * DATA TABLE: TanStack Table (v9) driving Keyline's table parts.\n *\n *   const table = useDataTable({ data, columns, getRowId: (r) => r.id })\n *   <TableFrame>\n *     <DataTableBulkBar table={table}>…actions…</DataTableBulkBar>\n *     <TableScroll><DataTable table={table} rowLabel={(r) => `Select ${r.original.id}`} /></TableScroll>\n *     <DataTablePagination table={table} noun=\"shipments\" />\n *   </TableFrame>\n *\n * TanStack owns the models (sorted, filtered, paged rows) and the state; the Keyline parts own the markup,\n * keyboard and accessibility. State is controlled or not, slice by slice: a slice given in `state` is the\n * caller's (keep it in sync from `onStateChange`), any other slice is the table's, seeded from `defaultState`.\n * `onStateChange(next, eventDetails)` reports every change either way, so a URL adapter can follow the table.\n *\n * Rendering is narrow. Each row subscribes to its own entries in the selection and the expansion, so selecting or\n * expanding a row re-renders that row alone; the header's select-all and the bulk bar subscribe to the selection themselves. The owner of\n * useDataTable re-renders for sorting, filters, paging and column visibility, not for selection.\n * ------------------------------------------------------------------ */\n\n/** Filter functions, by name: `filterFn: \"keyline\"` on a column takes a DataTableFilter (lib/data-table). */\nconst keylineFilter = constructFilterFn({\n  filter: (value: unknown, filter: DataTableFilter) => matchesFilter(value, filter),\n  autoRemove: (filter: DataTableFilter | undefined) => !isFilterActive(filter),\n});\nconst keylineSearch = constructFilterFn({\n  filter: (value: unknown, search: string) => matchesSearch([value], search),\n  autoRemove: (search: unknown) => typeof search !== \"string\" || search.trim() === \"\",\n});\n\n/** The features every Data Table registers. Each row model comes after the feature it needs. */\nconst features = tableFeatures({\n  rowSortingFeature,\n  sortedRowModel: createSortedRowModel(),\n  sortFns: { alphanumeric: sortFn_alphanumeric, basic: sortFn_basic, datetime: sortFn_datetime, text: sortFn_text },\n  columnFilteringFeature,\n  globalFilteringFeature,\n  filteredRowModel: createFilteredRowModel(),\n  filterFns: { keyline: keylineFilter, search: keylineSearch },\n  rowPaginationFeature,\n  paginatedRowModel: createPaginatedRowModel(),\n  rowSelectionFeature,\n  rowExpandingFeature,\n  columnVisibilityFeature,\n});\n\ntype Features = typeof features;\n\n/** A column of a Data Table. `meta: { align: \"end\" }` aligns a column of figures; `sortDescFirst` makes it sort\n *  high-to-low first; `filterFn: \"keyline\"` filters it by a DataTableFilter. */\nexport type DataTableColumnDef<TData extends RowData> = ColumnDef<Features, TData, any>;\nexport type DataTableInstance<TData extends RowData> = ReactTable<Features, TData, any>;\n\n/** The state a Data Table keeps: TanStack's slices, by TanStack's names. */\nexport type DataTableState = {\n  sorting: SortingState;\n  columnFilters: ColumnFiltersState;\n  globalFilter: string;\n  pagination: PaginationState;\n  rowSelection: RowSelectionState;\n  columnVisibility: ColumnVisibilityState;\n  /** the rows whose detail is open (DataTable's `renderDetail`), by row id */\n  expanded: ExpandedState;\n};\nexport type DataTableSlice = keyof DataTableState;\nexport type DataTableChangeDetails = { slice: DataTableSlice };\n\nconst SLICES = [\n  \"sorting\",\n  \"columnFilters\",\n  \"globalFilter\",\n  \"pagination\",\n  \"rowSelection\",\n  \"columnVisibility\",\n  \"expanded\",\n] as const satisfies readonly DataTableSlice[];\n// every slice of DataTableState is wired: a slice missing from SLICES fails to compile here\ntype Unwired = Exclude<DataTableSlice, (typeof SLICES)[number]>;\nconst allWired: Unwired extends never ? true : false = true;\nvoid allWired;\n\nconst DEFAULT_STATE: DataTableState = {\n  sorting: [],\n  columnFilters: [],\n  globalFilter: \"\",\n  pagination: { pageIndex: 0, pageSize: 10 },\n  rowSelection: {},\n  columnVisibility: {},\n  expanded: {},\n};\n\nconst HANDLER = {\n  sorting: \"onSortingChange\",\n  columnFilters: \"onColumnFiltersChange\",\n  globalFilter: \"onGlobalFilterChange\",\n  pagination: \"onPaginationChange\",\n  rowSelection: \"onRowSelectionChange\",\n  columnVisibility: \"onColumnVisibilityChange\",\n  expanded: \"onExpandedChange\",\n} as const satisfies Record<DataTableSlice, `on${string}Change`>;\n\nexport type UseDataTableOptions<TData extends RowData> = {\n  data: readonly TData[];\n  /** Keep the columns stable (module scope or a memo): a new array rebuilds every column. */\n  columns: readonly DataTableColumnDef<TData>[];\n  /** The slices the caller controls. Write `onStateChange`'s value back for each one. */\n  state?: Partial<DataTableState>;\n  /** Called with the table's next state and `{ slice }`, the slice that changed, for controlled and uncontrolled\n   *  slices alike. */\n  onStateChange?: (state: DataTableState, eventDetails: DataTableChangeDetails) => void;\n  /** Seeds for the slices the table controls (the page size, an initial sort). */\n  defaultState?: Partial<DataTableState>;\n  /** The row's id: selection is kept by id, so make it stable across sorting and paging. Default: `row.id`, else\n   *  the row's index. */\n  getRowId?: (row: TData, index: number) => string;\n  /** Which rows can be selected; false turns selection off (no index column). Default: every row. */\n  enableRowSelection?: boolean | ((row: Row<Features, TData>) => boolean);\n  /** The rows are one page from a server: pass `rowCount`, the total. */\n  manualPagination?: boolean;\n  /** The rows are sorted and filtered by a server. */\n  manualSorting?: boolean;\n  manualFiltering?: boolean;\n  rowCount?: number;\n  /** Return to the first page when data, filters or sorting change. Default true. */\n  autoResetPageIndex?: boolean;\n  /** Which rows have a detail to expand (DataTable's `renderDetail`). Default: every row. */\n  getRowCanExpand?: (row: Row<Features, TData>) => boolean;\n  /** Close every open detail when data changes. Default true. */\n  autoResetExpanded?: boolean;\n};\n\nconst expandAny = () => true;\n\nconst defaultRowId = (row: unknown, index: number) => {\n  const id = (row as { id?: unknown } | null)?.id;\n  return typeof id === \"string\" || typeof id === \"number\" ? String(id) : String(index);\n};\n\n/** What the owner of useDataTable re-renders for: everything but the selection, which the rows, the header's\n *  select-all and the bulk bar read for themselves. */\nconst ownerSlices = (state: TableState<Features>) => ({\n  sorting: state.sorting,\n  columnFilters: state.columnFilters,\n  globalFilter: state.globalFilter as string,\n  pagination: state.pagination,\n  columnVisibility: state.columnVisibility,\n});\n\n/**\n * A TanStack table with Keyline's features registered (sorting, filtering, a search, paging, selection, column\n * visibility). Pass it to DataTable, DataTableBulkBar, DataTablePagination and DataTableSearch.\n */\nfunction useDataTable<TData extends RowData>({\n  data,\n  columns,\n  state,\n  onStateChange,\n  defaultState,\n  getRowId = defaultRowId,\n  enableRowSelection = true,\n  manualPagination,\n  manualSorting,\n  manualFiltering,\n  rowCount,\n  autoResetPageIndex,\n  getRowCanExpand = expandAny,\n  autoResetExpanded,\n}: UseDataTableOptions<TData>): DataTableInstance<TData> {\n  const latest = React.useRef({ state, onStateChange });\n  React.useLayoutEffect(() => {\n    latest.current = { state, onStateChange };\n  });\n  const tableRef = React.useRef<DataTableInstance<TData> | null>(null);\n  // one stable handler per slice: a controlled slice goes to the caller; the table's own slice is written to its\n  // atom (as TanStack's default handler does) and reported\n  const [handlers] = React.useState(() => {\n    const out: Record<string, (updater: Updater<unknown>) => void> = {};\n    for (const slice of SLICES) {\n      out[HANDLER[slice]] = (updater) => {\n        const table = tableRef.current;\n        if (!table) return;\n        const { state: controlled, onStateChange: report } = latest.current;\n        const own = controlled?.[slice] === undefined;\n        const atoms = table.atoms as unknown as Record<DataTableSlice, { get(): unknown }>;\n        const prev = own ? atoms[slice].get() : controlled[slice];\n        const next = functionalUpdate(updater, prev);\n        if (Object.is(next, prev)) return;\n        if (own) (table.baseAtoms as unknown as Record<DataTableSlice, { set(v: unknown): void }>)[slice].set(next);\n        if (report) {\n          const current = {} as Record<DataTableSlice, unknown>;\n          for (const s of SLICES) current[s] = controlled?.[s] !== undefined ? controlled[s] : atoms[s].get();\n          current[slice] = next;\n          report(current as DataTableState, { slice });\n        }\n      };\n    }\n    return out;\n  });\n  const controlledState: Partial<DataTableState> = {};\n  if (state)\n    for (const s of SLICES) if (state[s] !== undefined) (controlledState as Record<string, unknown>)[s] = state[s];\n  const table = useTable(\n    {\n      features,\n      data: data as TData[],\n      columns: columns as DataTableColumnDef<TData>[],\n      getRowId,\n      initialState: { ...DEFAULT_STATE, ...defaultState },\n      state: controlledState,\n      ...handlers,\n      enableRowSelection,\n      enableMultiSort: true,\n      isRowRangeSelectionEvent: (e: unknown) => !!(e as { shiftKey?: boolean } | null)?.shiftKey,\n      manualPagination,\n      manualSorting,\n      manualFiltering,\n      rowCount,\n      autoResetPageIndex,\n      getRowCanExpand,\n      autoResetExpanded,\n      globalFilterFn: \"search\",\n    },\n    ownerSlices,\n  ) as unknown as DataTableInstance<TData>;\n  tableRef.current = table;\n  return table;\n}\n\n/* ------------------------------------------------------------------ *\n * PARTS\n * ------------------------------------------------------------------ */\n\ntype DataTableRowInstance<TData extends RowData> = Row<Features, TData>;\n\ntype DataTableProps<TData extends RowData> = Omit<PartProps<\"table\", Record<string, never>>, \"children\"> & {\n  table: DataTableInstance<TData>;\n  /** The selection checkbox's name for a row (\"Select SH-20481\"). Default: \"Select row\" and its code. */\n  rowLabel?: (row: DataTableRowInstance<TData>) => string;\n  /** The select-all checkbox's name. */\n  selectAllLabel?: string;\n  /** The index column's code for a row: its place across pages (\"01\") by default; null prints none. */\n  rowCode?: ((row: DataTableRowInstance<TData>, index: number) => React.ReactNode) | null;\n  /** Props for a row's TableRow (an onClick, a data attribute). Keep the function stable: a new one re-renders\n   *  every row. */\n  rowProps?: (row: DataTableRowInstance<TData>) => Omit<TableRowProps, \"selected\" | \"expanded\">;\n  /** A row's detail, shown under it while it is expanded (the `expanded` slice). Adds an expand column; the row's\n   *  index cell spans its detail. Keep the function stable: a new one re-renders every row. */\n  renderDetail?: (row: DataTableRowInstance<TData>) => React.ReactNode;\n  /** The expand toggle's name for a row. Default: \"Show details\" / \"Hide details\". */\n  expandLabel?: (row: DataTableRowInstance<TData>, expanded: boolean) => string;\n  /** Props for the body (a `ref` for useRowMotion). */\n  bodyProps?: PartProps<\"tbody\", Record<string, never>>;\n  /** The table's name, read before its rows (a TableCaption). */\n  caption?: React.ReactNode;\n  /** While data loads: a page of loading rows in place of the rows (mark the frame `aria-busy`). */\n  loading?: boolean;\n  /** Data failed to load: an error row (announced) in place of the rows. */\n  error?: { title: React.ReactNode; body?: React.ReactNode; action?: React.ReactNode; count?: React.ReactNode };\n  /** What shows when no row passes the filters (an Empty spanning the grid). */\n  empty?: { title: React.ReactNode; body?: React.ReactNode; action?: React.ReactNode; count?: React.ReactNode };\n};\n\nconst detailLabel = (_row: unknown, expanded: boolean) => (expanded ? \"Hide details\" : \"Show details\");\n\n/** The rows of a TanStack table as Keyline table parts: sort headers with aria-sort and the sort order, an index\n *  column of selection checkboxes (Shift extends a range), rows that expand into a detail, and the loading, error\n *  and empty rows. Put it in a TableScroll. */\nfunction DataTable<TData extends RowData>({\n  table,\n  rowLabel,\n  selectAllLabel = \"Select this page\",\n  rowCode: code,\n  rowProps,\n  renderDetail,\n  expandLabel = detailLabel,\n  bodyProps,\n  caption,\n  loading,\n  error,\n  empty,\n  ...props\n}: DataTableProps<TData>): React.ReactElement {\n  const { sorting, pagination } = table.state as ReturnType<typeof ownerSlices>;\n  const selectable = table.options.enableRowSelection !== false;\n  const rows = table.getRowModel().rows;\n  const columns = table.getVisibleLeafColumns();\n  // a row re-renders when the columns it shows change; its cells are read through the row, which stays the same\n  const shown = columns.map((c) => c.id).join(\"\\u0000\");\n  const span = columns.length + (selectable ? 1 : 0) + (renderDetail ? 1 : 0);\n  const groups = table.getHeaderGroups();\n  return (\n    <Table {...props}>\n      {caption ? <TableCaption>{caption}</TableCaption> : null}\n      <TableHeader>\n        {groups.map((group, g) => (\n          // a plain row: the header takes no row hover or selection\n          <tr key={group.id}>\n            {selectable && g === groups.length - 1 ? (\n              <DataTableSelectAll table={table} label={selectAllLabel} />\n            ) : selectable ? (\n              <TableHead aria-hidden />\n            ) : null}\n            {renderDetail ? g === groups.length - 1 ? <TableExpandCell header /> : <TableHead aria-hidden /> : null}\n            {group.headers.map((header) => (\n              <DataTableColumnHeader key={header.id} header={header} sorting={sorting} />\n            ))}\n          </tr>\n        ))}\n      </TableHeader>\n      <TableBody {...bodyProps}>\n        {loading ? (\n          <TableLoadingRows cols={span} rows={pagination.pageSize} />\n        ) : error ? (\n          <TableStateRow\n            kind=\"error\"\n            colSpan={span}\n            count={error.count ?? \"!\"}\n            title={error.title}\n            body={error.body}\n            action={error.action}\n          />\n        ) : rows.length === 0 && empty ? (\n          <TableStateRow\n            kind=\"empty\"\n            colSpan={span}\n            count={empty.count ?? 0}\n            title={empty.title}\n            body={empty.body}\n            action={empty.action}\n          />\n        ) : (\n          rows.map((row, i) => (\n            <DataTableRow\n              key={row.id}\n              row={row as DataTableRowProps[\"row\"]}\n              shown={shown}\n              selectable={selectable}\n              code={\n                code === null\n                  ? undefined\n                  : code\n                    ? code(row, i)\n                    : rowCode(table.options.manualPagination ? 0 : pagination.pageIndex, pagination.pageSize, i)\n              }\n              label={rowLabel ? rowLabel(row) : `Select row ${rowCode(pagination.pageIndex, pagination.pageSize, i)}`}\n              rowProps={rowProps as DataTableRowProps[\"rowProps\"]}\n              detail={renderDetail as DataTableRowProps[\"detail\"]}\n              expandLabel={expandLabel as DataTableRowProps[\"expandLabel\"]}\n              detailSpan={columns.length + 1}\n            />\n          ))\n        )}\n      </TableBody>\n    </Table>\n  );\n}\n\nfunction DataTableColumnHeader<TData extends RowData>({\n  header,\n  sorting,\n}: {\n  header: Header<Features, TData, unknown>;\n  sorting: SortingState;\n}): React.ReactElement {\n  if (header.isPlaceholder) return <TableHead colSpan={header.colSpan} />;\n  const column = header.column;\n  const align = columnAlign(column.columnDef.meta);\n  const label = <FlexRender header={header} />;\n  if (!column.getCanSort())\n    return (\n      <TableHead align={align} colSpan={header.colSpan > 1 ? header.colSpan : undefined}>\n        {label}\n      </TableHead>\n    );\n  const level = sortLevelOf(sorting, column.id);\n  return (\n    <TableSortHeader\n      align={align}\n      colSpan={header.colSpan > 1 ? header.colSpan : undefined}\n      sort={level?.direction ?? null}\n      priority={level?.priority}\n      levels={sorting.length}\n      onSort={({ additive }) =>\n        column.table.setSorting((old) =>\n          nextSorting(old, column.id, {\n            first: column.columnDef.sortDescFirst ? \"descending\" : \"ascending\",\n            additive: additive && column.getCanMultiSort(),\n          }),\n        )\n      }\n    >\n      {label}\n    </TableSortHeader>\n  );\n}\n\n/** The header's select-all checkbox: checked when every row on the page is, mixed when some are. */\nfunction DataTableSelectAll<TData extends RowData>({\n  table,\n  label,\n}: {\n  table: DataTableInstance<TData>;\n  label: string;\n}): React.ReactElement {\n  return (\n    <Subscribe\n      source={table.atoms.rowSelection}\n      selector={() => (table.getIsAllPageRowsSelected() ? \"all\" : table.getIsSomePageRowsSelected() ? \"some\" : \"none\")}\n    >\n      {(page) => (\n        <TableIndexCell\n          header\n          checked={page === \"all\"}\n          indeterminate={page === \"some\"}\n          onCheckedChange={(checked) => table.toggleAllPageRowsSelected(checked)}\n          label={label}\n        />\n      )}\n    </Subscribe>\n  );\n}\n\ntype DataTableRowProps = {\n  row: Row<Features, any>;\n  /** the visible columns' ids, so the row re-renders when they change */\n  shown: string;\n  selectable: boolean;\n  code: React.ReactNode;\n  label: string;\n  rowProps: ((row: Row<Features, any>) => Omit<TableRowProps, \"selected\" | \"expanded\">) | undefined;\n  detail: ((row: Row<Features, any>) => React.ReactNode) | undefined;\n  expandLabel: (row: Row<Features, any>, expanded: boolean) => string;\n  /** the detail's colSpan: every column after the index cell, which spans the detail */\n  detailSpan: number;\n};\n\n/** One row. Memoised, and subscribed to its own selection entry (and its expansion, when rows have a detail):\n *  toggling a row re-renders that row alone. */\nconst DataTableRow = React.memo(function DataTableRow(props: DataTableRowProps): React.ReactElement {\n  const { row, detail } = props;\n  return (\n    <Subscribe source={row.table.atoms.rowSelection} selector={(selection) => !!selection?.[row.id]}>\n      {(selected) =>\n        detail ? (\n          <Subscribe\n            source={row.table.atoms.expanded}\n            selector={(expanded) => expanded === true || !!expanded?.[row.id]}\n          >\n            {(expanded) => (\n              <DataTableRowWithDetail {...props} detail={detail} selected={selected} expanded={expanded} />\n            )}\n          </Subscribe>\n        ) : (\n          <DataTableRowCells {...props} selected={selected} />\n        )\n      }\n    </Subscribe>\n  );\n});\n\n/** A row and its detail. The row's index cell spans the detail for as long as the detail is mounted (through its\n *  fold), so the row never moves. */\nfunction DataTableRowWithDetail(\n  props: DataTableRowProps & {\n    detail: NonNullable<DataTableRowProps[\"detail\"]>;\n    selected: boolean;\n    expanded: boolean;\n  },\n): React.ReactElement {\n  const { row, detail, expanded, detailSpan } = props;\n  const presence = useDetailPresence(expanded);\n  return (\n    <>\n      <DataTableRowCells {...props} span={presence.mounted ? 2 : undefined} />\n      {presence.mounted ? (\n        <TableDetail presence={presence} colSpan={detailSpan}>\n          {detail(row)}\n        </TableDetail>\n      ) : null}\n    </>\n  );\n}\n\nfunction DataTableRowCells({\n  row,\n  selectable,\n  code,\n  label,\n  rowProps,\n  detail,\n  expandLabel,\n  selected,\n  expanded,\n  span,\n}: DataTableRowProps & { selected: boolean; expanded?: boolean; span?: number | undefined }): React.ReactElement {\n  return (\n    <TableRow\n      {...rowProps?.(row)}\n      selected={selected}\n      expanded={!!expanded}\n      aria-selected={selectable ? selected : undefined}\n    >\n      {selectable ? (\n        <TableIndexCell\n          rowSpan={span}\n          checked={selected}\n          onCheckedChange={(checked, eventDetails) =>\n            // TanStack's handler reads the checkbox's new value, and Shift for a range from the last row toggled\n            row.getToggleSelectedHandler()({\n              target: { checked },\n              shiftKey: (eventDetails.event as { shiftKey?: boolean } | undefined)?.shiftKey ?? false,\n            })\n          }\n          code={code}\n          label={label}\n        />\n      ) : null}\n      {detail ? (\n        row.getCanExpand() ? (\n          <TableExpandCell\n            expanded={!!expanded}\n            onToggle={() => row.toggleExpanded()}\n            label={expandLabel(row, !!expanded)}\n          />\n        ) : (\n          <TableExpandCell />\n        )\n      ) : null}\n      {row.getVisibleCells().map((cell) => (\n        <TableCell\n          key={cell.id}\n          align={columnAlign(cell.column.columnDef.meta)}\n          className={columnCellClassName(cell.column.columnDef.meta)}\n        >\n          <FlexRender cell={cell} />\n        </TableCell>\n      ))}\n    </TableRow>\n  );\n}\n\ntype DataTableBulkBarProps<TData extends RowData> = Omit<TableBulkBarProps, \"count\" | \"scope\" | \"children\"> & {\n  table: DataTableInstance<TData>;\n  /** what the selection covers; a function of the selected count */\n  scope?: React.ReactNode | ((count: number) => React.ReactNode);\n  /** the actions; a function of the selected count (to disable them at 0) */\n  children?: React.ReactNode | ((count: number) => React.ReactNode);\n};\n\n/** The bulk bar over a Data Table's selection: the count (announced politely), the scope, the actions. It\n *  re-renders on its own when the selection changes. */\nfunction DataTableBulkBar<TData extends RowData>({\n  table,\n  scope,\n  children,\n  ...props\n}: DataTableBulkBarProps<TData>): React.ReactElement {\n  return (\n    <Subscribe\n      source={table.atoms.rowSelection}\n      selector={(selection) => Object.values(selection ?? {}).filter(Boolean).length}\n    >\n      {(count) => (\n        <TableBulkBar {...props} count={count} scope={typeof scope === \"function\" ? scope(count) : scope}>\n          {typeof children === \"function\" ? children(count) : children}\n        </TableBulkBar>\n      )}\n    </Subscribe>\n  );\n}\n\n/** The pager over a Data Table: the range of rows shown, the page, previous and next. */\nfunction DataTablePagination<TData extends RowData>({\n  table,\n  noun,\n  loading,\n  children,\n  className,\n}: {\n  table: DataTableInstance<TData>;\n  /** what the rows are (\"shipments\") */\n  noun?: string;\n  /** while data loads the range shows \"–\" and the buttons are off */\n  loading?: boolean;\n  /** fills the cell between the range and the buttons (a ToastDock) */\n  children?: React.ReactNode;\n  className?: string;\n}): React.ReactElement {\n  const { pagination } = table.state as ReturnType<typeof ownerSlices>;\n  return (\n    <TablePagination\n      page={pagination.pageIndex}\n      pageSize={pagination.pageSize}\n      total={loading ? null : table.getRowCount()}\n      onPageChange={(page) => table.setPageIndex(page)}\n      noun={noun}\n      className={className}\n    >\n      {children}\n    </TablePagination>\n  );\n}\n\n/** The toolbar's search box, bound to the table's global filter (every column's text). */\nfunction DataTableSearch<TData extends RowData>({\n  table,\n  ...props\n}: Omit<React.ComponentProps<typeof TableSearch>, \"value\" | \"onChange\"> & {\n  table: DataTableInstance<TData>;\n}): React.ReactElement {\n  const { globalFilter } = table.state as ReturnType<typeof ownerSlices>;\n  return <TableSearch {...props} value={globalFilter ?? \"\"} onChange={(e) => table.setGlobalFilter(e.target.value)} />;\n}\n\nexport {\n  useDataTable,\n  DataTable,\n  DataTableBulkBar,\n  DataTablePagination,\n  DataTableSearch,\n  type DataTableProps,\n  type DataTableBulkBarProps,\n  type DataTableFilter,\n};\n",
      "type": "registry:ui",
      "target": "components/keyline/ui/data-table.tsx"
    }
  ],
  "type": "registry:ui"
}