{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "data-grid-pagination",
  "title": "Data Grid Pagination",
  "author": "gridcn",
  "description": "Pagination add-on for the gridcn data grid: useDataGridPagination (client mode slices data; server mode is fully controlled) plus a composable <DataGridPaginationBar /> footer (range, page-size select, first/prev/pages/next/last parts) — shadcn-Pagination style, renders a default layout with no children or a custom composition of parts. New user-facing strings live under labels.pagination (see data-grid/labels.ts DataGridPaginationLabels). Zero core changes — purely additive.",
  "dependencies": [
    "lucide-react@^1.46.0"
  ],
  "registryDependencies": [
    "@gridcn/data-grid",
    "button",
    "select"
  ],
  "files": [
    {
      "path": "registry/default/blocks/data-grid-pagination/data-grid-pagination.ts",
      "content": "/** Public entry point — the only module consumers/docs should import from. */\n\nexport { useDataGridPagination, type UseDataGridPaginationClientOptions, type UseDataGridPaginationResult, type DataGridPaginationControls } from \"./use-data-grid-pagination\";\nexport { useDataGridServerPager, type UseDataGridServerPagerOptions } from \"./use-data-grid-server-pager\";\nexport { useDataGridPager, type UseDataGridPagerOptions } from \"./use-data-grid-pager\";\nexport {\n  DataGridPaginationBar,\n  type DataGridPaginationBarProps,\n  DataGridPaginationRange,\n  DataGridPaginationPageSize,\n  DataGridPaginationFirst,\n  DataGridPaginationPrev,\n  DataGridPaginationPages,\n  type DataGridPaginationPagesProps,\n  DataGridPaginationNext,\n  DataGridPaginationLast,\n} from \"./pagination-footer\";\n\nexport { useStashedPager } from \"./pager-stash\";\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/data-grid-pagination.ts"
    },
    {
      "path": "registry/default/blocks/data-grid-pagination/use-data-grid-pagination.ts",
      "content": "\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { clampPage, DEFAULT_PAGE_SIZES, pageCount, pageRange } from \"./pagination-math\";\n\n/** What `<DataGridPaginationBar {...pager} />` spreads.  */\nexport type DataGridPaginationControls = {\n  page: number;\n  /** Pages the user can reach. With an unknown `totalRowCount` it is `page`, plus 1 while `hasMore`. */\n  pageCount: number;\n  pageSize: number;\n  pageSizeOptions: readonly number[];\n  /** Row count across all pages; `null` when the server sends no count. */\n  totalRowCount: number | null;\n  /** True when a page after the current one exists. */\n  hasMore: boolean;\n  /** What a page counts: `\"groups\"` while the grid is grouped (a page holds top-level groups, `totalRowCount` counts them), else `\"rows\"`. Default `\"rows\"`. */\n  unit?: \"rows\" | \"groups\";\n  onPageChange: (page: number) => void;\n  onPageSizeChange: (pageSize: number) => void;\n};\n\n/** Options of {@link useDataGridPagination}. */\nexport type UseDataGridPaginationClientOptions<TData> = {\n  data: readonly TData[];\n  /** First page size while `pageSize` is not controlled. Default: the first of `pageSizeOptions`. */\n  defaultPageSize?: number;\n  /** Controls the page size; pair it with `onPageSizeChange`. */\n  pageSize?: number;\n  /** Page sizes the footer offers. Default 10, 25, 50, 100. */\n  pageSizeOptions?: readonly number[];\n  /** First page while `page` is not controlled. Default 1. */\n  defaultPage?: number;\n  /** Controls the current page; pair it with `onPageChange`. A page outside `[1, pageCount]` shows the nearest page. */\n  page?: number;\n  onPageChange?: (page: number) => void;\n  /** Fires after a page-size change with the new size. */\n  onPageSizeChange?: (pageSize: number) => void;\n};\n\n/**\n * Options of {@link useDataGridServerPager} (`UseDataGridServerPagerOptions`): you own `page` and `pageSize` and fetch each page's rows. The hook computes the page window\n * and the pager. `totalRowCount` is `null` when the server does not count rows; `hasMore` then says whether another page exists.\n * A `page` outside `[1, pageCount]` calls `onPageChange` once with the clamped page, never while `totalRowCount` is 0.\n * With a `null` count only a page below 1 is lifted. For a source that fetches, sorts, and filters for you, use `useDataGridServerRows`.\n */\nexport type UseDataGridPaginationServerOptions = {\n  page: number;\n  pageSize: number;\n  totalRowCount: number | null;\n  /** Read only when `totalRowCount` is `null`. Default `false`. */\n  hasMore?: boolean;\n  onPageChange: (page: number) => void;\n  pageSizeOptions?: readonly number[];\n  onPageSizeChange?: (pageSize: number) => void;\n};\n\nexport type UseDataGridPaginationResult<TData> = {\n  /** The current page's slice of `data`. */\n  pageData: readonly TData[];\n  pager: DataGridPaginationControls;\n};\n\n/**\n * Slices a dataset into pages and builds the pager, for a list that lives outside the grid. Page and page size are uncontrolled\n * unless you pass `page` or `pageSize` with their change callbacks.\n *\n * To page the rows of a grid, set `pageSize` on `DataGridProvider` instead and read the pager with `useDataGridPager`: the grid\n * then sorts, filters, and totals all of `data` and shows one page of the result.\n */\nexport function useDataGridPagination<TData>(options: UseDataGridPaginationClientOptions<TData>): UseDataGridPaginationResult<TData> {\n  return useClientPagination<TData>(options);\n}\n\nfunction useClientPagination<TData>(options: UseDataGridPaginationClientOptions<TData>): UseDataGridPaginationResult<TData> {\n  const { data, pageSizeOptions = DEFAULT_PAGE_SIZES, onPageChange: onPageChangeProp, onPageSizeChange: onPageSizeChangeProp } = options;\n  const [internalPageSize, setInternalPageSize] = useState(options.defaultPageSize ?? pageSizeOptions[0] ?? DEFAULT_PAGE_SIZES[0]);\n  const [internalPage, setInternalPage] = useState(options.defaultPage ?? 1);\n\n  const pageSize = options.pageSize ?? internalPageSize;\n  const controlledPage = options.page;\n  const controlled = controlledPage !== undefined;\n  const rawPage = controlled ? controlledPage : internalPage;\n  const page = clampPage(rawPage, data.length, pageSize);\n\n  const setPage = (next: number, sizeForClamp: number = pageSize) => {\n    const clamped = clampPage(next, data.length, sizeForClamp);\n    if (!controlled) setInternalPage(clamped);\n    onPageChangeProp?.(clamped);\n  };\n\n  const pageData = useMemo(() => {\n    const { start, end } = pageRange(page, pageSize, data.length);\n    return data.slice(start, end);\n  }, [data, page, pageSize]);\n\n  const pager: DataGridPaginationControls = {\n    page,\n    pageCount: pageCount(data.length, pageSize),\n    pageSize,\n    pageSizeOptions,\n    totalRowCount: data.length,\n    hasMore: page < pageCount(data.length, pageSize),\n    onPageChange: setPage,\n    onPageSizeChange: (nextSize) => {\n      setInternalPageSize(nextSize);\n      onPageSizeChangeProp?.(nextSize);\n      // keep the same first-visible row across a page-size change\n      const firstRow = (page - 1) * pageSize;\n      setPage(Math.floor(firstRow / nextSize) + 1, nextSize);\n    },\n  };\n\n  return { pageData, pager };\n}\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/use-data-grid-pagination.ts"
    },
    {
      "path": "registry/default/blocks/data-grid-pagination/use-data-grid-server-pager.ts",
      "content": "\"use client\";\n\nimport { useEffect, useMemo, useRef } from \"react\";\nimport type { DataGridPlugin } from \"@/registry/default/components/data-grid/data-grid\";\nimport { usePagerStashPlugin } from \"./pager-stash\";\nimport { clampPage, DEFAULT_PAGE_SIZES, pageCount } from \"./pagination-math\";\nimport type { DataGridPaginationControls, UseDataGridPaginationServerOptions } from \"./use-data-grid-pagination\";\n\nexport type UseDataGridServerPagerOptions = UseDataGridPaginationServerOptions & {\n  /** What a page counts. Default `\"rows\"`. */\n  unit?: \"rows\" | \"groups\";\n};\n\nconst NO_PAGE_SIZE_OPTIONS: readonly number[] = [];\nconst noop = () => {};\n\n/** Result of {@link useDataGridServerPager}. */\nexport type UseDataGridServerPagerResult = {\n  pager: DataGridPaginationControls;\n  /**\n   * Spread onto `DataGridProvider`: `totalRowCount` puts sort and filter in server mode, and `plugins` lets a `DataGridPaginationBar` without props\n   * read this pager. A `plugins` prop after the spread replaces it; add your plugins to `gridProps.plugins` instead.\n   */\n  gridProps: { totalRowCount: number | null; plugins: readonly DataGridPlugin[] };\n};\n\n/** The pager for rows your own data layer fetches page by page. Spread `pager` onto `DataGridPaginationBar`, or `gridProps` onto `DataGridProvider` for a bar without props. Without `onPageSizeChange` the bar hides the page-size select. */\nexport function useDataGridServerPager(options: UseDataGridServerPagerOptions): UseDataGridServerPagerResult {\n  const { page, pageSize, totalRowCount, onPageChange, pageSizeOptions = DEFAULT_PAGE_SIZES, onPageSizeChange, unit } = options;\n  const clampedPage = clampPage(page, totalRowCount, pageSize);\n  const lastPage = totalRowCount === null ? null : pageCount(totalRowCount, pageSize);\n  const hasMore = lastPage === null ? options.hasMore === true : clampedPage < lastPage;\n\n  // The ref keeps the reconcile fire to one per (page, clamped) pair — no re-fire when the consumer\n  // ignores the callback or passes an unstable onPageChange.\n  const firedRef = useRef<{ page: number; clamped: number } | null>(null);\n  useEffect(() => {\n    if (totalRowCount !== null && totalRowCount <= 0) return;\n    const clamped = clampPage(page, totalRowCount, pageSize);\n    if (clamped === page) {\n      firedRef.current = null;\n      return;\n    }\n    const fired = firedRef.current;\n    if (fired && fired.page === page && fired.clamped === clamped) return;\n    firedRef.current = { page, clamped };\n    onPageChange(clamped);\n  }, [page, totalRowCount, pageSize, onPageChange]);\n\n  const pager: DataGridPaginationControls = {\n    page: clampedPage,\n    pageCount: lastPage ?? clampedPage + (hasMore ? 1 : 0),\n    pageSize,\n    pageSizeOptions: onPageSizeChange ? pageSizeOptions : NO_PAGE_SIZE_OPTIONS,\n    totalRowCount,\n    hasMore,\n    ...(unit === \"groups\" ? { unit } : {}),\n    onPageChange,\n    onPageSizeChange: onPageSizeChange ?? noop,\n  };\n  const stash = usePagerStashPlugin(pager);\n  const gridProps = useMemo(() => ({ totalRowCount, plugins: [stash] }), [totalRowCount, stash]);\n  return { pager, gridProps };\n}\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/use-data-grid-server-pager.ts"
    },
    {
      "path": "registry/default/blocks/data-grid-pagination/pager-stash.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useState, useSyncExternalStore } from \"react\";\nimport type { DataGridPlugin } from \"@/registry/default/components/data-grid/data-grid\";\nimport { useDataGridStoreApi } from \"@/registry/default/components/data-grid/data-grid-sdk\";\nimport type { DataGridPaginationControls } from \"./use-data-grid-pagination\";\n\ntype PagerBox = {\n  pager: DataGridPaginationControls;\n  listeners: Set<() => void>;\n  onRead: () => void;\n};\n\n/** A server hook sets a function under this key on the stash plugin to learn that a bar read the pager. */\nconst PAGER_READ = Symbol.for(\"gridcn.pager-read\");\n\nconst boxes = new WeakMap<object, PagerBox>();\nconst registryListeners = new Set<() => void>();\n\nconst notify = (listeners: Set<() => void>) => listeners.forEach((listener) => listener());\n\nconst subscribeRegistry = (listener: () => void) => {\n  registryListeners.add(listener);\n  return () => void registryListeners.delete(listener);\n};\n\nfunction publish(box: PagerBox, pager: DataGridPaginationControls) {\n  if (box.pager === pager) return;\n  box.pager = pager;\n  notify(box.listeners);\n}\n\nfunction StashMount({ box }: { box: PagerBox }): null {\n  const store = useDataGridStoreApi();\n  useEffect(() => {\n    boxes.set(store, box);\n    notify(registryListeners);\n    return () => {\n      if (boxes.get(store) === box) boxes.delete(store);\n      notify(registryListeners);\n    };\n  }, [store, box]);\n  return null;\n}\n\n/** A plugin that hands `pager` to every bare `DataGridPaginationBar` under the grid that mounts it. */\nexport function usePagerStashPlugin(pager: DataGridPaginationControls): DataGridPlugin {\n  const [{ box, plugin }] = useState(() => {\n    const box: PagerBox = { pager, listeners: new Set(), onRead: () => (plugin as Record<symbol, (() => void) | undefined>)[PAGER_READ]?.() };\n    const plugin: DataGridPlugin = { name: \"server-pager\", Mount: () => <StashMount box={box} /> };\n    return { box, plugin };\n  });\n  useEffect(() => publish(box, pager), [box, pager]);\n  return plugin;\n}\n\n/** The pager that a server hook stashed for the enclosing grid, or `null`. */\nexport function useStashedPager(): DataGridPaginationControls | null {\n  const store = useDataGridStoreApi();\n  const box = useSyncExternalStore(\n    subscribeRegistry,\n    () => boxes.get(store) ?? null,\n    () => null,\n  );\n  const pager = useSyncExternalStore(\n    (listener) => {\n      box?.listeners.add(listener);\n      return () => void box?.listeners.delete(listener);\n    },\n    () => box?.pager ?? null,\n    () => null,\n  );\n  useEffect(() => box?.onRead(), [box]);\n  return pager;\n}\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/pager-stash.tsx"
    },
    {
      "path": "registry/default/blocks/data-grid-pagination/use-data-grid-pager.ts",
      "content": "\"use client\";\n\nimport { useEffect, useMemo } from \"react\";\nimport { useDataGridApi } from \"@/registry/default/components/data-grid/data-grid\";\nimport { fullViewOf, effectivePage, pageUnitsOf, useDataGridSelector } from \"@/registry/default/components/data-grid/data-grid-sdk\";\nimport { DEFAULT_PAGE_SIZES, pageCount } from \"./pagination-math\";\nimport type { DataGridPaginationControls } from \"./use-data-grid-pagination\";\n\n/** Options of {@link useDataGridPager}. */\nexport type UseDataGridPagerOptions = {\n  /** Page sizes the footer offers. Default: the provider's `pageSizeOptions`, else 10, 25, 50, 100. */\n  pageSizeOptions?: readonly number[];\n};\n\n/**\n * The pager of a grid that pages its view, as `{ pager }` like `useDataGridServerPager` (`pageSize` on `DataGridProvider`). Call it under the provider and spread the result onto\n * `DataGridPaginationBar`, or build your own controls from it. The total counts every row the sort and filter leave, not one page.\n * A grid without `pageSize` reads as one page that holds every row.\n */\nexport function useDataGridPager(options: UseDataGridPagerOptions = {}): { pager: DataGridPaginationControls } {\n  const providerSizes = useDataGridSelector<unknown, readonly number[] | undefined>((s) => s.pageSizeOptions);\n  const pageSizeOptions = options.pageSizeOptions ?? providerSizes ?? DEFAULT_PAGE_SIZES;\n  const { actions } = useDataGridApi();\n  const requestedPage = useDataGridSelector<unknown, number>((s) => s.page);\n  const configuredSize = useDataGridSelector<unknown, number | null>((s) => s.pageSize);\n  const total = useDataGridSelector<unknown, number>((s) => pageUnitsOf(fullViewOf(s.viewIndex)));\n  const unit = useDataGridSelector<unknown, \"rows\" | \"groups\">((s) => (s.groupLayout ? \"groups\" : \"rows\"));\n  const pageSize = configuredSize ?? Math.max(1, total);\n  const page = effectivePage(requestedPage, total, pageSize);\n\n  useEffect(() => {\n    if (configuredSize !== null && total > 0 && page !== requestedPage) actions.setPage(page);\n  }, [actions, configuredSize, page, requestedPage]);\n\n  const pager = useMemo<DataGridPaginationControls>(() => {\n    const lastPage = pageCount(total, pageSize);\n    return {\n      page,\n      pageCount: lastPage,\n      pageSize,\n      pageSizeOptions,\n      totalRowCount: total,\n      hasMore: page < lastPage,\n      ...(unit === \"groups\" ? { unit } : {}),\n      onPageChange: (next) => actions.setPage(next),\n      onPageSizeChange: (next) => actions.setPageSize(next),\n    };\n  }, [actions, page, pageSize, pageSizeOptions, total, unit]);\n  return { pager };\n}\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/use-data-grid-pager.ts"
    },
    {
      "path": "registry/default/blocks/data-grid-pagination/pagination-footer.tsx",
      "content": "\"use client\";\n\nimport { createContext, use, useEffect, useRef, type ReactNode } from \"react\";\nimport { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport { Button } from \"@/components/ui/button\";\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/components/ui/select\";\nimport { DEFAULT_LABELS, type DataGridPaginationLabels } from \"@/registry/default/components/data-grid/data-grid\";\nimport { GRID_ATTR, isDev, mergeLabelLayers, useDataGridSelector, useOptionalDataGridLabels } from \"@/registry/default/components/data-grid/data-grid-sdk\";\nimport type { DataGridPaginationControls } from \"./use-data-grid-pagination\";\nimport { useDataGridPager } from \"./use-data-grid-pager\";\nimport { useStashedPager } from \"./pager-stash\";\nimport { DEFAULT_PAGE_SIZES, pageWindow } from \"./pagination-math\";\n\n/** Default window size for {@link DataGridPaginationPages} when its `windowSize` prop is omitted. */\nconst DEFAULT_PAGE_WINDOW_SIZE = 5;\n\ntype PaginationBarContextValue = {\n  controls: DataGridPaginationControls;\n  labels: DataGridPaginationLabels;\n};\n\nconst PaginationBarContext = createContext<PaginationBarContextValue | null>(null);\n\n/** Resolves the enclosing bar's context, throwing with a clear message outside {@link DataGridPaginationBar}. */\nfunction usePaginationBarContext(part: string): PaginationBarContextValue {\n  const ctx = use(PaginationBarContext);\n  if (!ctx) {\n    throw new Error(`[data-grid-pagination] <${part} /> must be used inside a <DataGridPaginationBar>.`);\n  }\n  return ctx;\n}\n\n/** Props for {@link DataGridPaginationBar}. */\ntype BarControls = Omit<DataGridPaginationControls, \"pageSizeOptions\">;\n\nexport type DataGridPaginationBarProps = (BarControls | { [K in keyof BarControls]?: never }) & {\n  /** Page sizes the select offers. Default: the controls' own list (10, 25, 50, 100 inside a provider). */\n  pageSizeOptions?: readonly number[];\n  className?: string;\n  /**\n   * i18n override for this footer's strings, merged key by key over the enclosing grid's\n   * `labels.pagination` (the built-in defaults outside a `DataGridProvider`).\n   */\n  labels?: Partial<DataGridPaginationLabels>;\n  /** How many numbered page buttons the default layout shows at once (forwarded to `DataGridPaginationPages`; ignored with `children`). Default 5. */\n  windowSize?: number;\n  /** Custom composition of parts; omit to render the default layout (range, page-size, first/prev/pages/next/last). */\n  children?: ReactNode;\n};\n\n/**\n * Pagination footer bar: provides the shared `DataGridPaginationControls` + merged labels to its\n * children via context, shadcn-`Pagination` style. With no `children` it renders the default\n * layout so the common case stays a one-liner; pass `children` built from the parts below\n * (`DataGridPaginationRange`, `DataGridPaginationPageSize`, `DataGridPaginationFirst`,\n * `DataGridPaginationPrev`, `DataGridPaginationPages`, `DataGridPaginationNext`,\n * `DataGridPaginationLast`) for a custom arrangement.\n *\n * Works identically for every source: spread the `DataGridPaginationControls` of\n * `useDataGridPagination`, `useDataGridServerPager`, `useDataGridPager`, or `useDataGridServerRows`,\n * or pass no controls inside a `DataGridProvider` with `pageSize` to read the grid's own pager.\n * Inside a grid that spreads `useDataGridServerRows` `gridProps` (or `useDataGridServerPager` `gridProps`) a bar without controls reads that hook's pager.\n */\nexport function DataGridPaginationBar(props: DataGridPaginationBarProps): ReactNode {\n  return props.page === undefined ? <ProviderPaginationBar {...props} /> : <PaginationBarView {...props} controls={{ ...(props as BarControls), pageSizeOptions: props.pageSizeOptions ?? DEFAULT_PAGE_SIZES }} />;\n}\n\n/** The bar of a grid without controls on the bar: the pager comes from the server hook of the enclosing `DataGridProvider`, else from the grid's own paging. */\nfunction ProviderPaginationBar(props: DataGridPaginationBarProps): ReactNode {\n  const { pager: viewPager } = useDataGridPager(props.pageSizeOptions ? { pageSizeOptions: props.pageSizeOptions } : {});\n  const stashed = useStashedPager();\n  const controls = stashed ? { ...stashed, pageSizeOptions: stashed.pageSizeOptions.length > 0 ? (props.pageSizeOptions ?? stashed.pageSizeOptions) : stashed.pageSizeOptions } : viewPager;\n  const serverRows = useDataGridSelector<unknown, boolean>((s) => s.totalRowCount !== undefined && s.pageSize === null) && !stashed;\n  const warned = useRef(false);\n  useEffect(() => {\n    if (!serverRows || warned.current || !isDev()) return;\n    // the server pager registers in the commit's effects; warn only if none has arrived by the next task\n    const timer = setTimeout(() => {\n      warned.current = true;\n      warnServerBar();\n    }, 0);\n    return () => clearTimeout(timer);\n  }, [serverRows]);\n  return <PaginationBarView {...props} controls={controls} />;\n}\n\nconst warnServerBar = () =>\n  console.warn(\"[data-grid-pagination] this grid's rows come from a server; spread `pager.gridProps` (from `useDataGridServerPager`) onto DataGridProvider, or spread `pager` onto DataGridPaginationBar\");\n\nfunction PaginationBarView(props: DataGridPaginationBarProps & { controls: DataGridPaginationControls }): ReactNode {\n  const { controls, className, labels: labelsOverride, windowSize, children } = props;\n  const gridLabels = useOptionalDataGridLabels();\n  const labels = mergeLabelLayers<DataGridPaginationLabels>(DEFAULT_LABELS.pagination, gridLabels?.pagination, labelsOverride);\n\n  return (\n    <PaginationBarContext value={{ controls, labels }}>\n      <div {...{ [GRID_ATTR.pagination]: \"\" }} className={cn(\"flex flex-wrap items-center justify-between gap-2 border-t border-border bg-background px-2 py-1.5\", className)}>\n        {children ?? (\n          <>\n            <DataGridPaginationRange />\n            <div className=\"flex flex-wrap items-center gap-3\">\n              <DataGridPaginationPageSize />\n              <div className=\"flex items-center gap-1\">\n                <DataGridPaginationFirst />\n                <DataGridPaginationPrev />\n                <DataGridPaginationPages windowSize={windowSize} />\n                <DataGridPaginationNext />\n                <DataGridPaginationLast />\n              </div>\n            </div>\n          </>\n        )}\n      </div>\n    </PaginationBarContext>\n  );\n}\n\n/** The \"x–y of z\" range label, {@link DataGridPaginationLabels.rangeEmpty} when `totalRowCount` is 0, or {@link DataGridPaginationLabels.rangeUnknown} (\"Page 3\") when `totalRowCount` is `null`. */\nexport function DataGridPaginationRange(): ReactNode {\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationRange\");\n  const { page, pageSize, totalRowCount, unit } = controls;\n  if (totalRowCount === null) return <span className=\"text-xs tabular-nums text-muted-foreground\">{labels.rangeUnknown(page)}</span>;\n  const from = totalRowCount === 0 ? 0 : (page - 1) * pageSize + 1;\n  const to = Math.min(page * pageSize, totalRowCount);\n\n  return <span className=\"text-xs tabular-nums text-muted-foreground\">{totalRowCount === 0 ? labels.rangeEmpty : (unit === \"groups\" ? labels.rangeGroups : labels.range)(from, to, totalRowCount)}</span>;\n}\n\n/** The rows-per-page `Select`. */\nexport function DataGridPaginationPageSize(): ReactNode {\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationPageSize\");\n  const { pageSize, pageSizeOptions, onPageSizeChange, unit } = controls;\n  if (pageSizeOptions.length === 0) return null;\n\n  return (\n    <Select value={String(pageSize)} onValueChange={(value) => onPageSizeChange(Number(value))}>\n      <SelectTrigger className=\"h-8 w-fit\" aria-label={unit === \"groups\" ? labels.pageSizeGroupsAriaLabel : labels.pageSizeAriaLabel}>\n        {/* explicit label lookup: SelectValue only resolves a mounted SelectItem's label, which the popup content isn't until first opened. */}\n        <SelectValue>{(value: string) => labels.pageSizeOption(Number(value))}</SelectValue>\n      </SelectTrigger>\n      <SelectContent>\n        {pageSizeOptions.map((size) => (\n          <SelectItem key={size} value={String(size)}>\n            {labels.pageSizeOption(size)}\n          </SelectItem>\n        ))}\n      </SelectContent>\n    </Select>\n  );\n}\n\n/** Jump to page 1; disabled on page 1. */\nexport function DataGridPaginationFirst(): ReactNode {\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationFirst\");\n  const { page, onPageChange } = controls;\n\n  return (\n    <Button type=\"button\" variant=\"ghost\" size=\"icon-sm\" aria-label={labels.firstPage} disabled={page <= 1} onClick={() => onPageChange(1)}>\n      <ChevronsLeft className=\"rtl:rotate-180\" />\n    </Button>\n  );\n}\n\n/** Page − 1; disabled on page 1. */\nexport function DataGridPaginationPrev(): ReactNode {\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationPrev\");\n  const { page, onPageChange } = controls;\n\n  return (\n    <Button type=\"button\" variant=\"ghost\" size=\"icon-sm\" aria-label={labels.previousPage} disabled={page <= 1} onClick={() => onPageChange(page - 1)}>\n      <ChevronLeft className=\"rtl:rotate-180\" />\n    </Button>\n  );\n}\n\n/** Props for {@link DataGridPaginationPages}. */\nexport type DataGridPaginationPagesProps = {\n  /** How many numbered page buttons to show at once (see {@link pageWindow}). Default 5. */\n  windowSize?: number;\n};\n\n/** The sliding numbered page buttons — the only source of page numbers in the composable layout. */\nexport function DataGridPaginationPages(props: DataGridPaginationPagesProps): ReactNode {\n  const { windowSize = DEFAULT_PAGE_WINDOW_SIZE } = props;\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationPages\");\n  const { page, pageCount, onPageChange } = controls;\n  const pages = pageWindow(page, pageCount, windowSize);\n\n  return (\n    <>\n      {pages.map((p) => (\n        <Button\n          key={p}\n          type=\"button\"\n          variant={p === page ? \"default\" : \"ghost\"}\n          size=\"icon-sm\"\n          aria-label={labels.pageAriaLabel(p)}\n          aria-current={p === page ? \"page\" : undefined}\n          onClick={() => onPageChange(p)}\n        >\n          {p}\n        </Button>\n      ))}\n    </>\n  );\n}\n\n/** Page + 1; disabled when no next page exists. */\nexport function DataGridPaginationNext(): ReactNode {\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationNext\");\n  const { page, hasMore, onPageChange } = controls;\n\n  return (\n    <Button type=\"button\" variant=\"ghost\" size=\"icon-sm\" aria-label={labels.nextPage} disabled={!hasMore} onClick={() => onPageChange(page + 1)}>\n      <ChevronRight className=\"rtl:rotate-180\" />\n    </Button>\n  );\n}\n\n/** Jump to the last page; disabled on the last page and while the count is unknown. */\nexport function DataGridPaginationLast(): ReactNode {\n  const { controls, labels } = usePaginationBarContext(\"DataGridPaginationLast\");\n  const { page, pageCount, onPageChange } = controls;\n\n  return (\n    <Button type=\"button\" variant=\"ghost\" size=\"icon-sm\" aria-label={labels.lastPage} disabled={controls.totalRowCount === null || page >= pageCount} onClick={() => onPageChange(pageCount)}>\n      <ChevronsRight className=\"rtl:rotate-180\" />\n    </Button>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/pagination-footer.tsx"
    },
    {
      "path": "registry/default/blocks/data-grid-pagination/pagination-math.ts",
      "content": "/** Page sizes the footer select offers when `pageSizeOptions` is not given. */\nexport const DEFAULT_PAGE_SIZES = [10, 25, 50, 100] as const;\n\n/** Total pages for `total` rows at `pageSize` per page — at least 1 even when `total` is 0 (an empty grid still shows \"page 1\"). */\nexport function pageCount(total: number, pageSize: number): number {\n  if (pageSize <= 0) return 1;\n  return Math.max(1, Math.ceil(total / pageSize));\n}\n\n/**\n * Clamps `page` (1-based) into `[1, pageCount(total, pageSize)]` — the fallback when data shrinks or pageSize changes out from under the current page.\n * An unknown `total` (`null`) clamps the lower bound only.\n */\nexport function clampPage(page: number, total: number | null, pageSize: number): number {\n  const lowerBounded = Math.max(1, Math.floor(page));\n  return total === null ? lowerBounded : Math.min(lowerBounded, pageCount(total, pageSize));\n}\n\n/** Half-open `[start, end)` row range for `page` (1-based) at `pageSize`, clamped to `total`. */\nexport function pageRange(page: number, pageSize: number, total: number): { start: number; end: number } {\n  const start = Math.min((page - 1) * pageSize, total);\n  const end = Math.min(start + pageSize, total);\n  return { start, end };\n}\n\n/**\n * Sliding page numbers for the footer, e.g. page 7 of 20 with windowSize 5 -> [5,6,7,8,9].\n * The window slides to stay centered on `page` but clamps at both ends so it never runs past\n * `[1, pageCount]` or shows fewer than `windowSize` numbers when there's room for that many.\n */\nexport function pageWindow(page: number, pageCount: number, windowSize: number): number[] {\n  if (pageCount <= 0) return [];\n  const size = Math.max(1, Math.min(windowSize, pageCount));\n  let start = page - Math.floor(size / 2);\n  start = Math.max(1, Math.min(start, pageCount - size + 1));\n  return Array.from({ length: size }, (_, i) => start + i);\n}\n",
      "type": "registry:component",
      "target": "components/data-grid-pagination/pagination-math.ts"
    }
  ],
  "categories": [
    "data"
  ],
  "type": "registry:block"
}
