@stackframe/dashboard-ui-components 2.8.86 → 2.8.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/components/analytics-chart/analytics-chart-pie.js +3 -3
  2. package/dist/components/analytics-chart/analytics-chart-pie.js.map +1 -1
  3. package/dist/components/data-grid/data-grid-sizing.d.ts +2 -1
  4. package/dist/components/data-grid/data-grid-sizing.d.ts.map +1 -1
  5. package/dist/components/data-grid/data-grid-sizing.js +33 -4
  6. package/dist/components/data-grid/data-grid-sizing.js.map +1 -1
  7. package/dist/components/data-grid/data-grid-toolbar.js +18 -15
  8. package/dist/components/data-grid/data-grid-toolbar.js.map +1 -1
  9. package/dist/components/data-grid/data-grid.d.ts +35 -1
  10. package/dist/components/data-grid/data-grid.d.ts.map +1 -1
  11. package/dist/components/data-grid/data-grid.js +329 -127
  12. package/dist/components/data-grid/data-grid.js.map +1 -1
  13. package/dist/components/data-grid/data-grid.test.d.ts +1 -0
  14. package/dist/components/data-grid/data-grid.test.js +215 -0
  15. package/dist/components/data-grid/data-grid.test.js.map +1 -0
  16. package/dist/components/data-grid/index.d.ts +3 -2
  17. package/dist/components/data-grid/index.js +13 -0
  18. package/dist/components/data-grid/state.d.ts.map +1 -1
  19. package/dist/components/data-grid/state.js +24 -7
  20. package/dist/components/data-grid/state.js.map +1 -1
  21. package/dist/components/data-grid/types.d.ts +34 -3
  22. package/dist/components/data-grid/types.d.ts.map +1 -1
  23. package/dist/components/data-grid/use-data-source.d.ts +6 -0
  24. package/dist/components/data-grid/use-data-source.d.ts.map +1 -1
  25. package/dist/components/data-grid/use-data-source.js +10 -2
  26. package/dist/components/data-grid/use-data-source.js.map +1 -1
  27. package/dist/components/tabs.d.ts +5 -1
  28. package/dist/components/tabs.d.ts.map +1 -1
  29. package/dist/components/tabs.js +40 -27
  30. package/dist/components/tabs.js.map +1 -1
  31. package/dist/dashboard-ui-components.global.js +672 -368
  32. package/dist/dashboard-ui-components.global.js.map +4 -4
  33. package/dist/esm/components/analytics-chart/analytics-chart-pie.js +3 -3
  34. package/dist/esm/components/analytics-chart/analytics-chart-pie.js.map +1 -1
  35. package/dist/esm/components/data-grid/data-grid-sizing.d.ts +2 -1
  36. package/dist/esm/components/data-grid/data-grid-sizing.d.ts.map +1 -1
  37. package/dist/esm/components/data-grid/data-grid-sizing.js +33 -5
  38. package/dist/esm/components/data-grid/data-grid-sizing.js.map +1 -1
  39. package/dist/esm/components/data-grid/data-grid-toolbar.js +18 -15
  40. package/dist/esm/components/data-grid/data-grid-toolbar.js.map +1 -1
  41. package/dist/esm/components/data-grid/data-grid.d.ts +35 -1
  42. package/dist/esm/components/data-grid/data-grid.d.ts.map +1 -1
  43. package/dist/esm/components/data-grid/data-grid.js +329 -128
  44. package/dist/esm/components/data-grid/data-grid.js.map +1 -1
  45. package/dist/esm/components/data-grid/data-grid.test.d.ts +1 -0
  46. package/dist/esm/components/data-grid/data-grid.test.js +215 -0
  47. package/dist/esm/components/data-grid/data-grid.test.js.map +1 -0
  48. package/dist/esm/components/data-grid/index.d.ts +3 -2
  49. package/dist/esm/components/data-grid/index.js +3 -2
  50. package/dist/esm/components/data-grid/state.d.ts.map +1 -1
  51. package/dist/esm/components/data-grid/state.js +24 -7
  52. package/dist/esm/components/data-grid/state.js.map +1 -1
  53. package/dist/esm/components/data-grid/types.d.ts +34 -3
  54. package/dist/esm/components/data-grid/types.d.ts.map +1 -1
  55. package/dist/esm/components/data-grid/use-data-source.d.ts +6 -0
  56. package/dist/esm/components/data-grid/use-data-source.d.ts.map +1 -1
  57. package/dist/esm/components/data-grid/use-data-source.js +10 -2
  58. package/dist/esm/components/data-grid/use-data-source.js.map +1 -1
  59. package/dist/esm/components/tabs.d.ts +5 -1
  60. package/dist/esm/components/tabs.d.ts.map +1 -1
  61. package/dist/esm/components/tabs.js +40 -27
  62. package/dist/esm/components/tabs.js.map +1 -1
  63. package/dist/index.d.ts +3 -2
  64. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"data-grid.js","names":["ArrowUp","ArrowDown","CaretUp","CaretDown","DesignSkeleton","MinusSquare","CheckSquare","Square","DataGridToolbar"],"sources":["../../../src/components/data-grid/data-grid.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ArrowDown,\n ArrowUp,\n CaretDown,\n CaretUp,\n CheckSquare,\n MinusSquare,\n Square,\n} from \"@phosphor-icons/react\";\nimport { cn } from \"@stackframe/stack-ui\";\nimport { useVirtualizer, type VirtualItem } from \"@tanstack/react-virtual\";\nimport React, {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from \"react\";\n\nimport { DesignSkeleton } from \"../skeleton\";\nimport { DataGridToolbar } from \"./data-grid-toolbar\";\nimport {\n applyDraggedColumnWidth,\n clampColumnWidth,\n createGridSizingStyle,\n getColumnSizingStyle,\n} from \"./data-grid-sizing\";\nimport {\n clearSelection,\n exportToCsv,\n formatGridDate,\n getSortDirection,\n getSortIndex,\n isColumnVisible,\n resolveColumnValue,\n resolveColumnWidth,\n selectAll,\n toggleRowSelection,\n toggleSort,\n} from \"./state\";\nimport { resolveDataGridStrings } from \"./strings\";\nimport type {\n DataGridCellContext,\n DataGridColumnDef,\n DataGridDateDisplay,\n DataGridFooterContext,\n DataGridHeaderContext,\n DataGridPaginationMode,\n DataGridProps,\n DataGridState,\n DataGridStrings,\n DataGridToolbarContext,\n RowId\n} from \"./types\";\n// ─── Resize handle ───────────────────────────────────────────────────\n\nfunction ResizeHandle({\n onResize,\n onResizeEnd,\n}: {\n onResize: (delta: number) => void;\n onResizeEnd: () => void;\n}) {\n const startXRef = useRef(0);\n const rafRef = useRef(0);\n const latestDeltaRef = useRef(0);\n const callbacksRef = useRef({ onResize, onResizeEnd });\n\n callbacksRef.current = { onResize, onResizeEnd };\n\n const onPointerDown = useCallback(\n (e: React.PointerEvent) => {\n e.preventDefault();\n e.stopPropagation();\n startXRef.current = e.clientX;\n latestDeltaRef.current = 0;\n const el = e.currentTarget as HTMLElement;\n el.setPointerCapture(e.pointerId);\n let finished = false;\n\n const onMove = (ev: PointerEvent) => {\n latestDeltaRef.current = ev.clientX - startXRef.current;\n if (rafRef.current !== 0) {\n return;\n }\n\n rafRef.current = requestAnimationFrame(() => {\n rafRef.current = 0;\n callbacksRef.current.onResize(latestDeltaRef.current);\n });\n };\n const finish = () => {\n if (finished) return;\n finished = true;\n if (rafRef.current !== 0) {\n cancelAnimationFrame(rafRef.current);\n rafRef.current = 0;\n callbacksRef.current.onResize(latestDeltaRef.current);\n }\n el.removeEventListener(\"pointermove\", onMove);\n el.removeEventListener(\"pointerup\", finish);\n el.removeEventListener(\"pointercancel\", finish);\n el.removeEventListener(\"lostpointercapture\", finish);\n if (el.hasPointerCapture(e.pointerId)) {\n el.releasePointerCapture(e.pointerId);\n }\n callbacksRef.current.onResizeEnd();\n };\n\n el.addEventListener(\"pointermove\", onMove);\n el.addEventListener(\"pointerup\", finish);\n el.addEventListener(\"pointercancel\", finish);\n el.addEventListener(\"lostpointercapture\", finish);\n },\n [],\n );\n\n return (\n <div\n className={cn(\n \"absolute right-0 top-0 bottom-0 z-10 w-[5px] cursor-col-resize touch-none\",\n \"group-hover/header:bg-foreground/[0.06] hover:!bg-blue-500/30\",\n \"transition-colors duration-100\",\n )}\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onPointerDown={onPointerDown}\n />\n );\n}\n\n// ─── Header cell ─────────────────────────────────────────────────────\n\nfunction HeaderCell<TRow>({\n col,\n isSorted,\n sortIndex,\n resizable,\n onSort,\n onResize,\n onResizeEnd,\n}: {\n col: DataGridColumnDef<TRow>;\n isSorted: false | \"asc\" | \"desc\";\n sortIndex: number | null;\n resizable: boolean;\n onSort: (columnId: string, multi: boolean) => void;\n onResize: (columnId: string, delta: number) => void;\n onResizeEnd: () => void;\n}) {\n const ctx: DataGridHeaderContext<TRow> = {\n columnId: col.id,\n columnDef: col,\n isSorted,\n sortIndex,\n };\n const label =\n typeof col.header === \"function\" ? col.header(ctx) : col.header;\n\n const sortable = col.sortable !== false;\n\n return (\n <div\n className={cn(\n \"group/header relative flex items-center gap-1.5 px-3 select-none bg-transparent\",\n \"border-r border-black/[0.04] dark:border-white/[0.04] last:border-r-0\",\n sortable && \"cursor-pointer\",\n )}\n style={getColumnSizingStyle(col)}\n data-col-id={col.id}\n onClick={(e) => sortable && onSort(col.id, e.metaKey || e.ctrlKey)}\n role=\"columnheader\"\n aria-sort={isSorted === \"asc\" ? \"ascending\" : isSorted === \"desc\" ? \"descending\" : \"none\"}\n >\n <span\n className={cn(\n \"flex-1 truncate text-xs font-semibold uppercase tracking-wider text-muted-foreground\",\n col.align === \"center\" && \"text-center\",\n col.align === \"right\" && \"text-right\",\n )}\n >\n {label}\n </span>\n\n {/* Sort indicator */}\n {isSorted && (\n <span className=\"flex items-center gap-0.5 text-foreground/60\">\n {isSorted === \"asc\" ? (\n <ArrowUp className=\"h-3 w-3\" weight=\"bold\" />\n ) : (\n <ArrowDown className=\"h-3 w-3\" weight=\"bold\" />\n )}\n {sortIndex != null && (\n <span className=\"text-[10px] font-medium tabular-nums\">{sortIndex}</span>\n )}\n </span>\n )}\n\n {/* Unsorted hint on hover */}\n {!isSorted && sortable && (\n <span className=\"hidden group-hover/header:flex items-center text-foreground/20\">\n <CaretUp className=\"h-2.5 w-2.5 -mb-[1px]\" weight=\"bold\" />\n <CaretDown className=\"h-2.5 w-2.5 -mt-[1px]\" weight=\"bold\" />\n </span>\n )}\n\n {/* Resize handle */}\n {resizable && col.resizable !== false && (\n <ResizeHandle\n onResize={(delta) => onResize(col.id, delta)}\n onResizeEnd={onResizeEnd}\n />\n )}\n </div>\n );\n}\n\n// ─── Data cell ───────────────────────────────────────────────────────\n\nfunction DataCell<TRow>({\n col,\n row,\n rowId,\n rowIndex,\n isSelected,\n dateDisplay,\n}: {\n col: DataGridColumnDef<TRow>;\n row: TRow;\n rowId: RowId;\n rowIndex: number;\n isSelected: boolean;\n dateDisplay: DataGridDateDisplay;\n}) {\n const value = resolveColumnValue(col, row);\n const ctx: DataGridCellContext<TRow> = {\n row,\n rowId,\n rowIndex,\n value,\n columnId: col.id,\n isSelected,\n dateDisplay,\n };\n\n const isDateCol = col.type === \"date\" || col.type === \"dateTime\";\n let content: React.ReactNode;\n if (col.renderCell) {\n content = col.renderCell(ctx);\n } else if (isDateCol) {\n content = renderDateCell(value, dateDisplay, col);\n } else {\n content = formatCellValue(value);\n }\n const hasCellClick = col.onCellClick || col.onCellDoubleClick;\n\n return (\n <div\n className={cn(\n \"flex items-center px-3 truncate bg-transparent\",\n \"border-r border-black/[0.04] dark:border-white/[0.04] last:border-r-0\",\n \"text-sm text-foreground\",\n col.align === \"center\" && \"justify-center\",\n col.align === \"right\" && \"justify-end\",\n hasCellClick && \"cursor-pointer\",\n )}\n style={getColumnSizingStyle(col)}\n data-col-id={col.id}\n role=\"gridcell\"\n onClick={col.onCellClick ? (e) => {\n e.stopPropagation();\n col.onCellClick!(ctx, e);\n } : undefined}\n onDoubleClick={col.onCellDoubleClick ? (e) => {\n e.stopPropagation();\n col.onCellDoubleClick!(ctx, e);\n } : undefined}\n >\n {content}\n </div>\n );\n}\n\nfunction formatCellValue(value: unknown): React.ReactNode {\n if (value == null) return <span className=\"text-muted-foreground/40\">-</span>;\n if (typeof value === \"boolean\") {\n return (\n <span\n className={cn(\n \"inline-flex items-center px-1.5 py-0.5 rounded-md text-xs font-medium\",\n value\n ? \"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400\"\n : \"bg-foreground/[0.04] text-muted-foreground\",\n )}\n >\n {value ? \"Yes\" : \"No\"}\n </span>\n );\n }\n if (value instanceof Date) {\n return (\n <span className=\"tabular-nums text-muted-foreground\">\n {value.toLocaleDateString()}\n </span>\n );\n }\n return <span className=\"truncate\">{String(value)}</span>;\n}\n\n/** Built-in date cell — mirrors what `formatGridDate` returns but wraps\n * the display in a `<span>` with a `title` tooltip showing the absolute\n * datetime. Only used when the column has `type: \"date\" | \"dateTime\"`\n * and no custom `renderCell`. */\nfunction renderDateCell<TRow>(\n value: unknown,\n dateDisplay: DataGridDateDisplay,\n col: DataGridColumnDef<TRow>,\n): React.ReactNode {\n const { display, tooltip } = formatGridDate(value, dateDisplay, {\n parseValue: col.parseValue,\n dateFormat: col.dateFormat,\n });\n if (display == null) return <span className=\"text-muted-foreground/40\">-</span>;\n return (\n <span\n className=\"tabular-nums text-muted-foreground truncate cursor-help\"\n title={tooltip ?? undefined}\n >\n {display}\n </span>\n );\n}\n\n// ─── Skeleton row ────────────────────────────────────────────────────\n\nfunction SkeletonRow({\n columns,\n height,\n showCheckbox,\n}: {\n columns: readonly DataGridColumnDef<any>[];\n height: number;\n showCheckbox?: boolean;\n}) {\n return (\n <div className=\"flex\" style={{ height }} role=\"row\">\n {showCheckbox && (\n <div\n className=\"flex items-center justify-center border-r border-black/[0.04] dark:border-white/[0.04]\"\n style={{ width: 44 }}\n >\n <DesignSkeleton className=\"h-4 w-4 rounded\" />\n </div>\n )}\n {columns.map((col) => (\n <div\n key={col.id}\n className=\"flex items-center px-3 border-r border-black/[0.04] dark:border-white/[0.04] last:border-r-0\"\n style={getColumnSizingStyle(col)}\n >\n <DesignSkeleton\n className=\"h-3.5 rounded-md\"\n style={{ width: `${40 + Math.random() * 40}%` }}\n />\n </div>\n ))}\n </div>\n );\n}\n\n// ─── Checkbox cell ───────────────────────────────────────────────────\n\nfunction SelectionCheckbox({\n checked,\n indeterminate,\n onChange,\n ariaLabel,\n}: {\n checked: boolean;\n indeterminate?: boolean;\n onChange: (event: React.MouseEvent<HTMLButtonElement>) => void;\n ariaLabel: string;\n}) {\n const Icon = indeterminate ? MinusSquare : checked ? CheckSquare : Square;\n return (\n <button\n className={cn(\n \"flex items-center justify-center w-full h-full\",\n \"hover:bg-foreground/[0.04] transition-colors duration-75\",\n checked || indeterminate\n ? \"text-blue-600 dark:text-blue-400\"\n : \"text-muted-foreground/40 hover:text-muted-foreground/60\",\n )}\n onClick={(e) => {\n e.stopPropagation();\n onChange(e);\n }}\n aria-label={ariaLabel}\n role=\"checkbox\"\n aria-checked={indeterminate ? \"mixed\" : checked}\n >\n <Icon className=\"h-4 w-4\" weight={checked || indeterminate ? \"fill\" : \"regular\"} />\n </button>\n );\n}\n\n// ─── Infinite scroll sentinel ────────────────────────────────────────\n\nfunction InfiniteScrollSentinel({\n onIntersect,\n isLoading,\n strings,\n}: {\n onIntersect: () => void;\n isLoading: boolean;\n strings: DataGridStrings;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const observer = new IntersectionObserver(\n (entries) => {\n if (entries[0]?.isIntersecting) {\n onIntersect();\n }\n },\n { rootMargin: \"200px\" },\n );\n observer.observe(el);\n return () => observer.disconnect();\n }, [onIntersect]);\n\n return (\n <div ref={ref} className=\"flex items-center justify-center py-4\">\n {isLoading && (\n <div className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n <div className=\"h-3 w-3 rounded-full border-2 border-current border-t-transparent animate-spin\" />\n {strings.loadingMore}\n </div>\n )}\n </div>\n );\n}\n\n// ─── Footer ──────────────────────────────────────────────────────────\n\nfunction DefaultFooter<TRow>({\n ctx,\n pagination,\n onChange,\n}: {\n ctx: DataGridFooterContext<TRow>;\n pagination: DataGridPaginationMode;\n onChange: React.Dispatch<React.SetStateAction<DataGridState>>;\n}) {\n const { state, totalRowCount, visibleRowCount, selectedRowCount, strings } = ctx;\n const totalPages = totalRowCount != null\n ? Math.max(1, Math.ceil(totalRowCount / state.pagination.pageSize))\n : undefined;\n\n const setPage = (pageIndex: number) =>\n onChange((s) => ({\n ...s,\n pagination: { ...s.pagination, pageIndex },\n }));\n\n const setPageSize = (pageSize: number) =>\n onChange((s) => ({\n ...s,\n pagination: { ...s.pagination, pageSize, pageIndex: 0 },\n }));\n\n return (\n <div className=\"flex items-center justify-between px-4 py-2.5 border-t border-foreground/[0.06] text-xs text-muted-foreground\">\n <div className=\"flex items-center gap-3\">\n {selectedRowCount > 0 && (\n <span className=\"font-medium text-foreground\">\n {strings.rowsSelected(selectedRowCount)}\n </span>\n )}\n {totalRowCount != null && (\n <span>\n {visibleRowCount} of {totalRowCount} rows\n </span>\n )}\n </div>\n\n {pagination !== \"infinite\" && totalPages != null && (\n <div className=\"flex items-center gap-3\">\n {/* Page size selector */}\n <div className=\"flex items-center gap-1.5\">\n <span>{strings.rowsPerPage}</span>\n <select\n className={cn(\n \"h-7 rounded-lg border border-black/[0.08] dark:border-white/[0.08] bg-background px-1.5\",\n \"text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-foreground/[0.1]\",\n \"cursor-pointer\",\n )}\n value={state.pagination.pageSize}\n onChange={(e) => setPageSize(Number(e.target.value))}\n >\n {[10, 25, 50, 100].map((size) => (\n <option key={size} value={size}>\n {size}\n </option>\n ))}\n </select>\n </div>\n\n {/* Page navigation */}\n <div className=\"flex items-center gap-1\">\n <button\n className={cn(\n \"h-7 w-7 flex items-center justify-center rounded-lg\",\n \"hover:bg-foreground/[0.04] disabled:opacity-30 disabled:cursor-not-allowed\",\n \"transition-colors duration-75\",\n )}\n onClick={() => setPage(state.pagination.pageIndex - 1)}\n disabled={state.pagination.pageIndex === 0}\n aria-label=\"Previous page\"\n >\n <CaretUp className=\"h-3.5 w-3.5 -rotate-90\" weight=\"bold\" />\n </button>\n <span className=\"px-2 tabular-nums font-medium\">\n {strings.pageOf(state.pagination.pageIndex + 1, totalPages)}\n </span>\n <button\n className={cn(\n \"h-7 w-7 flex items-center justify-center rounded-lg\",\n \"hover:bg-foreground/[0.04] disabled:opacity-30 disabled:cursor-not-allowed\",\n \"transition-colors duration-75\",\n )}\n onClick={() => setPage(state.pagination.pageIndex + 1)}\n disabled={state.pagination.pageIndex >= totalPages - 1}\n aria-label=\"Next page\"\n >\n <CaretDown className=\"h-3.5 w-3.5 -rotate-90\" weight=\"bold\" />\n </button>\n </div>\n </div>\n )}\n </div>\n );\n}\n\n// ─── Main DataGrid ───────────────────────────────────────────────────\n\n/**\n * Interactive table with sorting, quick search, pagination, selection,\n * and virtualization. Handles 10k+ rows smoothly. Pair with\n * `useDataSource` for client-side data; use an async `dataSource`\n * generator for server or infinite-scroll modes.\n *\n * ## Mental model (read this first — everything else depends on it)\n *\n * DataGrid is a **display** component. It does NOT sort, search, or\n * paginate your data directly — you own that, but `useDataSource` does\n * it for you. The `rows` prop is always the already-processed slice to\n * show. The grid tracks user intent in `state` (sort model, quick\n * search text, page index). You feed that state into `useDataSource`,\n * and its output goes back in as `rows`.\n *\n * `useDataSource` IS the processor. Given your full dataset and the\n * grid's state, it returns the searched + sorted + paginated rows\n * ready to pass to DataGrid. This is the ONLY correct pattern for\n * client-side data — do NOT pass a raw array to `rows`.\n *\n * ## Search (client vs async)\n *\n * - **Client mode** (`useDataSource` with `data`): a case-insensitive\n * substring match across every column is applied automatically.\n * Override the matcher with `matchRow` for fuzzy / weighted search,\n * or disable by passing `matchRow: () => true`.\n * - **Async mode** (`useDataSource` with `dataSource`): `state.quickSearch`\n * is forwarded to the generator as `params.quickSearch`. Same\n * mechanism as `params.sorting` — a change triggers a refetch, and\n * the generator is the \"matching logic\" (typically a WHERE / ILIKE\n * clause in the backend query). The grid does NO client-side\n * filtering in async mode.\n *\n * ## The canonical pattern\n *\n * ```tsx\n * // 1. Columns — define OUTSIDE the component or inside a useMemo. Must be stable.\n * const columns = React.useMemo(() => [\n * { id: \"name\", header: \"Name\", accessor: \"name\", width: 180, type: \"string\" },\n * { id: \"email\", header: \"Email\", accessor: \"email\", width: 240, type: \"string\" },\n * { id: \"role\", header: \"Role\", accessor: \"role\", width: 120, type: \"singleSelect\",\n * valueOptions: [{ value: \"admin\", label: \"Admin\" }, { value: \"member\", label: \"Member\" }] },\n * { id: \"signUps\", header: \"Sign-ups\", accessor: \"signUps\", width: 120, type: \"number\", align: \"right\",\n * renderCell: ({ value }) => <span className=\"tabular-nums\">{Number(value).toLocaleString()}</span> },\n * ], []);\n *\n * // 2. Grid state — one hook, initialized from the columns. NEVER build the state object by hand.\n * const [gridState, setGridState] = React.useState(() => createDefaultDataGridState(columns));\n *\n * // 3. Data source — wires your raw array through the grid state. ALWAYS call this\n * // hook unconditionally at the top level (no if/return before it).\n * const gridData = useDataSource({\n * data: users, // your raw array (can be [] while loading)\n * columns,\n * getRowId: (row) => row.id,\n * sorting: gridState.sorting,\n * quickSearch: gridState.quickSearch,\n * pagination: gridState.pagination,\n * paginationMode: \"client\", // \"client\" | \"server\" | \"infinite\"\n * });\n *\n * // 4. Render — `rows` comes from gridData.rows, NOT from your raw array.\n * <DataGrid\n * columns={columns}\n * rows={gridData.rows}\n * getRowId={(row) => row.id}\n * totalRowCount={gridData.totalRowCount}\n * isLoading={gridData.isLoading}\n * state={gridState}\n * onChange={setGridState}\n * selectionMode=\"none\" // \"none\" | \"single\" | \"multiple\"\n * maxHeight={480}\n * />\n * ```\n *\n * ## Iron rules (violating any of these breaks the grid)\n *\n * 1. The prop is `rows`, NOT `data`. There is no `data` prop on DataGrid.\n * `data` belongs on `useDataSource`.\n * 2. `rows` is ALWAYS `gridData.rows`. Never pass your raw array to\n * `rows` — the grid won't search, sort, or paginate it.\n * 3. Columns must be stable across renders. Define them outside the\n * component or wrap in `React.useMemo`. A fresh columns array every\n * render will reset sorting state.\n * 4. Initialize grid state with `createDefaultDataGridState(columns)`.\n * Do NOT spell out the state object manually — you will miss fields\n * and crash.\n * 5. `onChange` takes a `SetStateAction` (the setter you got from\n * `useState`). Pass `setGridState` directly. Do NOT wrap it unless\n * you know exactly what you're doing.\n * 6. Call `useDataSource` ONCE per grid, at the top level, before any\n * early return. It contains hooks.\n * 7. `renderCell` is a PURE function of its context. NEVER call React\n * hooks inside it (no `useState`, `useMemo`, `useEffect`, nothing).\n * If you need derived data per row, compute it BEFORE the render —\n * e.g. build a `Map<rowId, sparklineData>` in a `useMemo` and look\n * it up in `renderCell`.\n * 8. `toolbar` accepts `false` (hide it) or a render function\n * `(ctx) => ReactNode`. Anything else — `true`, `undefined`, a state\n * variable — will either show the default toolbar or crash. If you\n * just want the default toolbar, omit the prop entirely.\n * 9. The toolbar's search input writes to `state.quickSearch`. That\n * value is consumed by `useDataSource` — client mode filters\n * client-side, async mode forwards to the generator. Do NOT wire\n * a separate \"controlled\" search prop, everything flows through\n * grid state.\n *\n * ## renderCell — what you can and cannot do inside it\n *\n * ```tsx\n * // OK — pure rendering from ctx:\n * renderCell: ({ value }) => <span className=\"tabular-nums\">{Number(value).toLocaleString()}</span>\n * renderCell: ({ row }) => <Badge variant={row.active ? \"default\" : \"outline\"}>{row.status}</Badge>\n *\n * // OK — looking up pre-computed data by row id:\n * // BEFORE the return, in the component body:\n * const sparklinesById = React.useMemo(() => {\n * const m = new Map();\n * for (const u of users) {\n * m.set(u.id, u.recentActivity.map((n, i) => ({ ts: i, values: { primary: n } })));\n * }\n * return m;\n * }, [users]);\n * // Then inside the column def:\n * renderCell: ({ rowId }) => <MiniSparkline data={sparklinesById.get(rowId) ?? []} />\n *\n * // NOT OK — hooks inside renderCell:\n * renderCell: ({ row }) => {\n * const [hovered, setHovered] = React.useState(false); // ← crashes the grid\n * const data = React.useMemo(() => ..., []); // ← crashes the grid\n * return ...;\n * }\n *\n * // NOT OK — embedding AnalyticsChart (or any other controlled, stateful chart) per row:\n * // AnalyticsChart owns its own state, tooltips, zoom, and virtualized data\n * // pipeline. Instantiating one per row is expensive and fights the grid's\n * // virtualizer. Don't do it.\n * ```\n *\n * ## Sparklines and mini-charts in cells — use raw Recharts\n *\n * If you want a tiny chart (sparkline, micro bar chart, trend line) inside\n * a cell, drop down to raw `Recharts.*` components — they are lightweight\n * and stateless, so they render cleanly per row without owning any state.\n * Read pre-computed points off the row (or off a `Map<rowId, points>` you\n * built in a `useMemo` above) and pass them directly to the Recharts\n * primitive. Do NOT wrap them in `DesignChartContainer` or\n * `DesignChartCard` inside a cell — those add chrome meant for full-size\n * charts.\n *\n * ```tsx\n * // OK — raw Recharts sparkline per row:\n * renderCell: ({ rowId }) => {\n * const points = sparklinesById.get(rowId) ?? [];\n * return (\n * <Recharts.ResponsiveContainer width=\"100%\" height={28}>\n * <Recharts.LineChart data={points} margin={{ top: 2, right: 2, bottom: 2, left: 2 }}>\n * <Recharts.Line type=\"monotone\" dataKey=\"v\" stroke=\"currentColor\" strokeWidth={1.5} dot={false} isAnimationActive={false} />\n * </Recharts.LineChart>\n * </Recharts.ResponsiveContainer>\n * );\n * }\n * ```\n *\n * Keep in-cell Recharts configs minimal: no axes, no tooltips, no animation\n * (`isAnimationActive={false}`), tight margins, fixed height. The goal is a\n * visual summary, not an interactive chart.\n *\n * ## State shape (from `createDefaultDataGridState`)\n *\n * ```ts\n * {\n * sorting: [], // { columnId, direction: \"asc\" | \"desc\" }[]\n * quickSearch: \"\", // search input text\n * dateDisplay: \"relative\", // \"relative\" | \"absolute\"\n * columnVisibility: {}, columnWidths: {...},\n * columnPinning: { left: [], right: [] }, columnOrder: [...],\n * pagination: { pageIndex: 0, pageSize: 50 },\n * selection: { selectedIds: new Set(), anchorId: null },\n * }\n * ```\n *\n * Everything is updated through `setGridState` — the toolbar, header,\n * and footer all call it for you. You do not need to wire any of this\n * manually.\n *\n * ## Height and scrolling\n *\n * DataGrid is NOT a card. It has no border, rounded corners, or shadow of\n * its own. Wrap it in whatever chrome you want — a `DesignCard`, a section,\n * or just raw layout. The grid itself fills its parent's height via\n * `h-full`.\n *\n * How the grid gets its height (pick ONE):\n * 1. Bounded parent — put the grid inside a flex/grid container with a\n * definite height (e.g. `flex-1 min-h-0` inside a page-filling flex\n * column). The grid stretches to that height and scrolls its body.\n * 2. `maxHeight` prop — pass a number (pixels) or CSS string\n * (`\"480px\"`, `\"60vh\"`, `\"100%\"`). The grid caps at that size and\n * scrolls its body.\n * 3. Unbounded — omit `maxHeight` and let the parent grow freely. The\n * grid renders at its full content height and the page scrolls. Fine\n * for small lists; bad UX for thousands of rows.\n *\n * The toolbar, header, and footer are always `shrink-0`; only the body\n * scrolls. You do NOT need to subtract toolbar/footer heights from\n * `maxHeight` — the grid's internal flex layout handles that.\n *\n * ## When to use what\n *\n * - Simple static list, < 20 rows, no interaction → use a plain table component instead.\n * - Interactive table, sortable + searchable, any size → `DataGrid` +\n * `useDataSource` with `paginationMode: \"client\"`.\n * - Infinite scroll over a huge dataset you fetch in pages → `dataSource` async\n * generator + `paginationMode: \"infinite\"`. Only reach for this if you actually\n * need pagination over a remote source. For anything that fits in memory,\n * `\"client\"` is simpler and faster.\n *\n * ## Features you get for free\n *\n * Quick search, sortable columns (shift-click for multi-sort), column\n * visibility toggle, column resize, CSV export, virtualized rendering\n * for 10k+ rows, keyboard navigation, and a relative/absolute date\n * toggle for `date` / `dateTime` columns.\n */\nexport function DataGrid<TRow>(props: DataGridProps<TRow>) {\n const {\n columns: allColumns,\n rows,\n getRowId,\n totalRowCount,\n isLoading = false,\n isRefetching = false,\n hasMore = false,\n isLoadingMore = false,\n onLoadMore,\n state,\n onChange,\n paginationMode = \"paginated\",\n selectionMode = \"none\",\n resizable = true,\n rowHeight = 44,\n headerHeight = 44,\n overscan = 5,\n maxHeight,\n toolbar,\n toolbarExtra,\n emptyState,\n loadingState,\n footer,\n footerExtra,\n exportFilename = \"export\",\n strings: stringsOverride,\n className,\n // Callbacks\n onRowClick,\n onRowDoubleClick,\n onSelectionChange,\n onSortChange,\n } = props;\n\n const strings = useMemo(\n () => resolveDataGridStrings(stringsOverride),\n [stringsOverride],\n );\n\n // ── Visible columns ──────────────────────────────────────────\n const visibleColumns = useMemo(\n () =>\n (state.columnOrder.length > 0\n ? state.columnOrder\n .map((id) => allColumns.find((c) => c.id === id))\n .filter(Boolean) as DataGridColumnDef<TRow>[]\n : allColumns\n ).filter((col) => isColumnVisible(col.id, state.columnVisibility)),\n [allColumns, state.columnOrder, state.columnVisibility],\n );\n\n // ── Row IDs (stable) ─────────────────────────────────────────\n const rowIds = useMemo(() => rows.map(getRowId), [rows, getRowId]);\n\n // ── Column widths ────────────────────────────────────────────\n const visibleColumnMetrics = useMemo(() => {\n const widths = new Map<string, number>();\n let totalWidth = selectionMode !== \"none\" ? 44 : 0;\n\n for (const col of visibleColumns) {\n const width = resolveColumnWidth(col, state.columnWidths[col.id]);\n widths.set(col.id, width);\n totalWidth += width;\n }\n\n return { widths, totalWidth };\n }, [selectionMode, state.columnWidths, visibleColumns]);\n\n const gridSizingStyle = useMemo(\n () => createGridSizingStyle(visibleColumnMetrics.widths, visibleColumnMetrics.totalWidth),\n [visibleColumnMetrics],\n );\n\n // Resize drag tracked via ref — zero React re-renders during drag.\n // CSS variables on gridRef are mutated directly; committed on pointer up.\n const resizeRef = useRef<{ columnId: string; baseWidth: number; baseTotalWidth: number; latestWidth: number } | null>(null);\n const gridRef = useRef<HTMLDivElement>(null);\n\n // ── Handlers ─────────────────────────────────────────────────\n const handleSort = useCallback(\n (columnId: string, multi: boolean) => {\n onChange((s) => {\n const next = toggleSort(s.sorting, columnId, multi);\n onSortChange?.(next);\n return { ...s, sorting: next };\n });\n },\n [onChange, onSortChange],\n );\n\n const handleResize = useCallback(\n (columnId: string, delta: number) => {\n const col = allColumns.find((c) => c.id === columnId);\n if (!col) return;\n if (!resizeRef.current || resizeRef.current.columnId !== columnId) {\n const baseWidth = visibleColumnMetrics.widths.get(columnId) ?? resolveColumnWidth(col, state.columnWidths[columnId]);\n resizeRef.current = { columnId, baseWidth, baseTotalWidth: visibleColumnMetrics.totalWidth, latestWidth: baseWidth };\n }\n const newWidth = clampColumnWidth(col, resizeRef.current.baseWidth + delta);\n resizeRef.current.latestWidth = newWidth;\n if (gridRef.current) {\n applyDraggedColumnWidth(gridRef.current, columnId, newWidth, resizeRef.current.baseTotalWidth + (newWidth - resizeRef.current.baseWidth));\n }\n },\n [allColumns, state.columnWidths, visibleColumnMetrics],\n );\n\n // Re-apply CSS vars after React re-renders (e.g. sort during drag)\n useLayoutEffect(() => {\n const r = resizeRef.current;\n if (r && gridRef.current) {\n applyDraggedColumnWidth(gridRef.current, r.columnId, r.latestWidth, r.baseTotalWidth + (r.latestWidth - r.baseWidth));\n }\n }, [gridSizingStyle]);\n\n const handleResizeEnd = useCallback(() => {\n const r = resizeRef.current;\n resizeRef.current = null;\n if (!r || r.latestWidth === r.baseWidth) return;\n onChange((s) => ({ ...s, columnWidths: { ...s.columnWidths, [r.columnId]: r.latestWidth } }));\n }, [onChange]);\n\n const handleRowClick = useCallback(\n (row: TRow, rowId: RowId, event: React.MouseEvent) => {\n // Selection\n if (selectionMode !== \"none\") {\n onChange((s) => {\n const next = toggleRowSelection(\n s.selection,\n rowId,\n selectionMode,\n event.shiftKey,\n event.metaKey || event.ctrlKey,\n rowIds,\n );\n // Fire callback after state update\n if (onSelectionChange) {\n const selectedRows = rows.filter((r) =>\n next.selectedIds.has(getRowId(r)),\n );\n setTimeout(() => onSelectionChange(next.selectedIds, selectedRows), 0);\n }\n return { ...s, selection: next };\n });\n }\n\n onRowClick?.(row, rowId, event);\n },\n [selectionMode, onChange, onRowClick, onSelectionChange, rowIds, rows, getRowId],\n );\n\n const handleRowSelectionCheckboxClick = useCallback(\n (\n row: TRow,\n rowId: RowId,\n event: React.MouseEvent<HTMLButtonElement>,\n ) => {\n handleRowClick(row, rowId, event);\n },\n [handleRowClick],\n );\n\n const handleSelectAll = useCallback(() => {\n onChange((s) => {\n const allSelected = rowIds.every((id) => s.selection.selectedIds.has(id));\n const next = allSelected ? clearSelection() : selectAll(rowIds);\n if (onSelectionChange) {\n const selectedRows = allSelected\n ? []\n : rows;\n setTimeout(() => onSelectionChange(next.selectedIds, [...selectedRows]), 0);\n }\n return { ...s, selection: next };\n });\n }, [onChange, rowIds, rows, onSelectionChange]);\n\n const handleExportCsv = useCallback(() => {\n exportToCsv(rows, visibleColumns, exportFilename);\n }, [rows, visibleColumns, exportFilename]);\n\n // ── Virtualizer ──────────────────────────────────────────────\n const scrollContainerRef = useRef<HTMLDivElement>(null);\n const headerScrollRef = useRef<HTMLDivElement>(null);\n const rowVirtualizer = useVirtualizer({\n count: rows.length,\n getScrollElement: () => scrollContainerRef.current,\n estimateSize: () => rowHeight,\n overscan,\n });\n\n // Sync horizontal scroll from body to header\n const handleBodyScroll = useCallback(() => {\n const body = scrollContainerRef.current;\n const header = headerScrollRef.current;\n if (body && header) {\n header.scrollLeft = body.scrollLeft;\n }\n }, []);\n\n // ── Toolbar context ──────────────────────────────────────────\n const toolbarCtx: DataGridToolbarContext<TRow> = useMemo(\n () => ({\n state,\n onChange,\n columns: allColumns,\n visibleColumns,\n totalRowCount,\n selectedRowCount: state.selection.selectedIds.size,\n strings,\n exportCsv: handleExportCsv,\n }),\n [state, onChange, allColumns, visibleColumns, totalRowCount, strings, handleExportCsv],\n );\n\n // ── Footer context ───────────────────────────────────────────\n const footerCtx: DataGridFooterContext<TRow> = useMemo(\n () => ({\n state,\n totalRowCount,\n visibleRowCount: rows.length,\n selectedRowCount: state.selection.selectedIds.size,\n paginationMode,\n strings,\n }),\n [state, totalRowCount, rows.length, paginationMode, strings],\n );\n\n // ── Selection state for header checkbox ──────────────────────\n const allSelected = rowIds.length > 0 && rowIds.every((id) => state.selection.selectedIds.has(id));\n const someSelected = !allSelected && rowIds.some((id) => state.selection.selectedIds.has(id));\n\n // ── Render ───────────────────────────────────────────────────\n //\n // Height model:\n // - Root is `flex flex-col h-full min-h-0 bg-transparent`. `h-full`\n // makes the grid fill a bounded parent; in an unbounded parent it\n // resolves to `auto` and the grid takes the content's intrinsic size.\n // - Toolbar/header/footer are `shrink-0`; the scroll body is\n // `flex-1 min-h-0 overflow-auto`, so the scroll area naturally takes\n // whatever space remains after the fixed-size chrome — regardless of\n // toolbar/footer size.\n // - `maxHeight` is applied directly to the root; the scroll body never\n // subtracts chrome sizes manually (that math breaks when the toolbar\n // wraps, the footer grows, etc.).\n return (\n <div\n ref={gridRef}\n className={cn(\n \"flex flex-col h-full min-h-0 bg-transparent\",\n className,\n )}\n style={maxHeight != null ? { ...gridSizingStyle, maxHeight } : gridSizingStyle}\n role=\"grid\"\n aria-rowcount={totalRowCount ?? rows.length}\n aria-colcount={visibleColumns.length}\n >\n {/* Toolbar. When a custom `toolbar` render function is supplied,\n it owns the whole row — `toolbarExtra` is ignored because the\n custom render can consume `ctx` and include whatever it wants.\n When the default toolbar is used, `toolbarExtra` is injected\n into its row to the left of the columns / export actions. */}\n {toolbar !== false && (\n <div className=\"relative shrink-0 bg-transparent\">\n {toolbar ? (\n toolbar(toolbarCtx)\n ) : (\n <DataGridToolbar\n ctx={toolbarCtx}\n extra={\n typeof toolbarExtra === \"function\"\n ? toolbarExtra(toolbarCtx)\n : toolbarExtra\n }\n />\n )}\n </div>\n )}\n\n {/* Grid content */}\n <div className=\"relative flex min-h-0 flex-1 flex-col\">\n {/* Refetch indicator — thin progress bar, no layout shift */}\n {isRefetching && (\n <div className=\"absolute top-0 left-0 right-0 h-0.5 z-30 bg-foreground/[0.04] overflow-hidden\">\n <div className=\"h-full w-1/3 bg-blue-500/60 rounded-full animate-pulse\" />\n </div>\n )}\n\n {/* Header row — separate from scroll body, syncs horizontal scroll */}\n <div\n ref={headerScrollRef}\n className=\"overflow-hidden shrink-0 border-b border-foreground/[0.06]\"\n >\n <div\n className=\"flex\"\n style={{ height: headerHeight, minWidth: visibleColumnMetrics.totalWidth }}\n role=\"row\"\n >\n {selectionMode !== \"none\" && (\n <div\n className=\"flex items-center justify-center border-r border-foreground/[0.04]\"\n style={{ width: 44 }}\n >\n {selectionMode === \"multiple\" && (\n <SelectionCheckbox\n checked={allSelected}\n indeterminate={someSelected}\n onChange={handleSelectAll}\n ariaLabel=\"Select all rows\"\n />\n )}\n </div>\n )}\n {visibleColumns.map((col) => (\n <HeaderCell\n key={col.id}\n col={col}\n isSorted={getSortDirection(state.sorting, col.id)}\n sortIndex={getSortIndex(state.sorting, col.id)}\n resizable={resizable}\n onSort={handleSort}\n onResize={handleResize}\n onResizeEnd={handleResizeEnd}\n />\n ))}\n </div>\n </div>\n\n {/* Scrollable body — flex-1 + min-h-0 makes it take the remaining\n space inside the `flex flex-col` grid wrapper, no manual math. */}\n <div\n ref={scrollContainerRef}\n className={cn(\n \"min-h-0 overflow-auto flex-1 bg-transparent\",\n // Custom scrollbar\n \"[&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar]:h-1.5\",\n \"[&::-webkit-scrollbar-track]:bg-transparent\",\n \"[&::-webkit-scrollbar-thumb]:bg-foreground/[0.08] [&::-webkit-scrollbar-thumb]:rounded-full\",\n \"[&::-webkit-scrollbar-thumb]:hover:bg-foreground/[0.15]\",\n )}\n onScroll={handleBodyScroll}\n >\n {/* Loading initial */}\n {isLoading && (\n <div style={{ minWidth: visibleColumnMetrics.totalWidth }}>\n {loadingState ??\n Array.from({ length: 8 }).map((_, i) => (\n <SkeletonRow\n key={i}\n columns={visibleColumns}\n height={rowHeight}\n showCheckbox={selectionMode !== \"none\"}\n />\n ))}\n </div>\n )}\n\n {/* Empty state */}\n {!isLoading && rows.length === 0 && (\n <div\n className=\"flex items-center justify-center py-16 text-sm text-muted-foreground\"\n style={{ minWidth: visibleColumnMetrics.totalWidth }}\n >\n {emptyState ?? strings.noData}\n </div>\n )}\n\n {/* Virtualized rows */}\n {!isLoading && rows.length > 0 && (\n <div\n style={{\n height: rowVirtualizer.getTotalSize(),\n width: \"100%\",\n minWidth: visibleColumnMetrics.totalWidth,\n position: \"relative\",\n }}\n >\n {rowVirtualizer.getVirtualItems().map((virtualRow: VirtualItem) => {\n const row = rows[virtualRow.index]!;\n const rowId = getRowId(row);\n const isSelected = state.selection.selectedIds.has(rowId);\n\n const isOddRow = virtualRow.index % 2 === 1;\n return (\n <div\n key={rowId}\n className={cn(\n \"absolute left-0 w-full flex\",\n \"border-b border-black/[0.03] dark:border-white/[0.03]\",\n \"transition-colors duration-75\",\n isSelected\n ? \"bg-blue-500/[0.06] dark:bg-blue-400/[0.08] hover:bg-blue-500/[0.08] dark:hover:bg-blue-400/[0.1]\"\n : isOddRow\n ? \"bg-foreground/[0.02] dark:bg-foreground/[0.03] hover:bg-foreground/[0.04] dark:hover:bg-foreground/[0.06]\"\n : \"hover:bg-foreground/[0.025] dark:hover:bg-foreground/[0.04]\",\n selectionMode !== \"none\" && \"cursor-pointer\",\n )}\n style={{\n height: rowHeight,\n transform: `translateY(${virtualRow.start}px)`,\n }}\n onClick={(e) => handleRowClick(row, rowId, e)}\n onDoubleClick={(e) => onRowDoubleClick?.(row, rowId, e)}\n role=\"row\"\n aria-rowindex={virtualRow.index + 2}\n aria-selected={isSelected}\n data-row-id={rowId}\n data-state={isSelected ? \"selected\" : undefined}\n >\n {/* Selection checkbox */}\n {selectionMode !== \"none\" && (\n <div\n className=\"flex items-center justify-center border-r border-black/[0.04] dark:border-white/[0.04]\"\n style={{ width: 44 }}\n >\n <SelectionCheckbox\n checked={isSelected}\n onChange={(event) => handleRowSelectionCheckboxClick(row, rowId, event)}\n ariaLabel={`Select row ${rowId}`}\n />\n </div>\n )}\n\n {/* Data cells */}\n {visibleColumns.map((col) => (\n <DataCell\n key={col.id}\n col={col}\n row={row}\n rowId={rowId}\n rowIndex={virtualRow.index}\n isSelected={isSelected}\n dateDisplay={state.dateDisplay}\n />\n ))}\n </div>\n );\n })}\n </div>\n )}\n\n {/* Infinite scroll sentinel */}\n {paginationMode === \"infinite\" && hasMore && !isLoading && (\n <InfiniteScrollSentinel\n onIntersect={onLoadMore ?? (() => {})}\n isLoading={isLoadingMore}\n strings={strings}\n />\n )}\n </div>\n </div>\n\n {/* Footer */}\n {footer !== false && (\n <div className=\"relative z-10 shrink-0 bg-transparent\">\n {footer ? (\n footer(footerCtx)\n ) : (\n <DefaultFooter\n ctx={footerCtx}\n pagination={paginationMode}\n onChange={onChange}\n />\n )}\n {footerExtra && (\n typeof footerExtra === \"function\" ? footerExtra(footerCtx) : footerExtra\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0DA,SAAS,aAAa,EACpB,UACA,eAIC;CACD,MAAM,8BAAmB,EAAE;CAC3B,MAAM,2BAAgB,EAAE;CACxB,MAAM,mCAAwB,EAAE;CAChC,MAAM,iCAAsB;EAAE;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AAO,MAAM;YACvE,WAAW,cAAc;aACzB;YACE,EAIP,eAAe,KAAK,QACnB,2CAAC;WAEM;WACA;WACE;WACP,UAAU,WAAW;WACT;WACZ,aAAa,MAAM;aANd,IAAI,GAOT,CACF;YAjDG,MAkDD;UAER;SACE;OAIP,mBAAmB,cAAc,WAAW,CAAC,aAC5C,2CAAC;QACC,aAAa,qBAAqB;QAClC,WAAW;QACF;SACT;;OAEA;;KACF;GAGL,WAAW,SACV,4CAAC;IAAI,WAAU;eACZ,SACC,OAAO,UAAU,GAEjB,2CAAC;KACC,KAAK;KACL,YAAY;KACF;MACV,EAEH,gBACC,OAAO,gBAAgB,aAAa,YAAY,UAAU,GAAG;KAE3D;;GAEJ"}
1
+ {"version":3,"file":"data-grid.js","names":["ArrowUp","ArrowDown","CaretUp","CaretDown","DesignSkeleton","MinusSquare","CheckSquare","Square","DataGridToolbar"],"sources":["../../../src/components/data-grid/data-grid.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ArrowDown,\n ArrowUp,\n CaretDown,\n CaretUp,\n CheckSquare,\n MinusSquare,\n Square,\n} from \"@phosphor-icons/react\";\nimport { throwErr } from \"@stackframe/stack-shared/dist/utils/errors\";\nimport { cn } from \"@stackframe/stack-ui\";\nimport { useVirtualizer, type VirtualItem } from \"@tanstack/react-virtual\";\nimport React, {\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n} from \"react\";\n\nimport { DesignSkeleton } from \"../skeleton\";\nimport {\n applyDraggedColumnWidth,\n clampColumnWidth,\n createGridSizingStyle,\n getColumnSizingStyle,\n} from \"./data-grid-sizing\";\nimport { DataGridToolbar } from \"./data-grid-toolbar\";\nimport {\n clearSelection,\n exportToCsv,\n formatGridDate,\n getSortDirection,\n getSortIndex,\n isColumnVisible,\n resolveColumnValue,\n resolveColumnWidth,\n selectAll,\n toggleRowSelection,\n toggleSort,\n} from \"./state\";\nimport { resolveDataGridStrings } from \"./strings\";\nimport type {\n DataGridCellContext,\n DataGridColumnDef,\n DataGridDateDisplay,\n DataGridFooterContext,\n DataGridHeaderContext,\n DataGridPaginationMode,\n DataGridProps,\n DataGridState,\n DataGridStrings,\n DataGridToolbarContext,\n RowId\n} from \"./types\";\n// ─── Resize handle ───────────────────────────────────────────────────\n\nfunction ResizeHandle({\n onResize,\n onResizeEnd,\n}: {\n onResize: (delta: number) => void;\n onResizeEnd: () => void;\n}) {\n const startXRef = useRef(0);\n const rafRef = useRef(0);\n const latestDeltaRef = useRef(0);\n const callbacksRef = useRef({ onResize, onResizeEnd });\n\n callbacksRef.current = { onResize, onResizeEnd };\n\n const onPointerDown = useCallback(\n (e: React.PointerEvent) => {\n e.preventDefault();\n e.stopPropagation();\n startXRef.current = e.clientX;\n latestDeltaRef.current = 0;\n const el = e.currentTarget as HTMLElement;\n el.setPointerCapture(e.pointerId);\n let finished = false;\n\n const onMove = (ev: PointerEvent) => {\n latestDeltaRef.current = ev.clientX - startXRef.current;\n if (rafRef.current !== 0) {\n return;\n }\n\n rafRef.current = requestAnimationFrame(() => {\n rafRef.current = 0;\n callbacksRef.current.onResize(latestDeltaRef.current);\n });\n };\n const finish = () => {\n if (finished) return;\n finished = true;\n if (rafRef.current !== 0) {\n cancelAnimationFrame(rafRef.current);\n rafRef.current = 0;\n callbacksRef.current.onResize(latestDeltaRef.current);\n }\n el.removeEventListener(\"pointermove\", onMove);\n el.removeEventListener(\"pointerup\", finish);\n el.removeEventListener(\"pointercancel\", finish);\n el.removeEventListener(\"lostpointercapture\", finish);\n if (el.hasPointerCapture(e.pointerId)) {\n el.releasePointerCapture(e.pointerId);\n }\n callbacksRef.current.onResizeEnd();\n };\n\n el.addEventListener(\"pointermove\", onMove);\n el.addEventListener(\"pointerup\", finish);\n el.addEventListener(\"pointercancel\", finish);\n el.addEventListener(\"lostpointercapture\", finish);\n },\n [],\n );\n\n return (\n <div\n className={cn(\n \"absolute right-0 top-0 bottom-0 z-10 w-[5px] cursor-col-resize touch-none\",\n \"group-hover/header:bg-foreground/[0.06] hover:!bg-blue-500/30\",\n \"transition-colors duration-100\",\n )}\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n onPointerDown={onPointerDown}\n />\n );\n}\n\nfunction getNearestVerticalScrollElement(element: HTMLElement | null): HTMLElement | Window {\n let current = element?.parentElement ?? null;\n\n while (current) {\n const style = window.getComputedStyle(current);\n const overflowY = style.overflowY === \"visible\" ? style.overflow : style.overflowY;\n const canScrollVertically =\n (overflowY === \"auto\" || overflowY === \"scroll\" || overflowY === \"overlay\") &&\n current.scrollHeight > current.clientHeight + 1;\n\n if (canScrollVertically) {\n return current;\n }\n\n current = current.parentElement;\n }\n\n return window;\n}\n\nfunction getEventTargetElement(target: EventTarget | null): Element | null {\n if (target instanceof Element) {\n return target;\n }\n if (target instanceof Node) {\n return target.parentElement;\n }\n return null;\n}\n\nexport function isDataGridInteractiveRowClickTarget(target: EventTarget | null): boolean {\n const targetElement = getEventTargetElement(target);\n return targetElement?.closest([\n \"a\",\n \"button\",\n \"input\",\n \"select\",\n \"textarea\",\n \"[role=\\\"button\\\"]\",\n \"[role=\\\"menuitem\\\"]\",\n \"[contenteditable]:not([contenteditable=\\\"false\\\"])\",\n \"[data-no-row-click]\",\n ].join(\",\")) != null;\n}\n\nfunction shouldIgnoreRowClick(event: React.MouseEvent): boolean {\n return event.defaultPrevented || isDataGridInteractiveRowClickTarget(event.target);\n}\n\n// ─── Header cell ─────────────────────────────────────────────────────\n\nfunction HeaderCell<TRow>({\n col,\n isSorted,\n sortIndex,\n resizable,\n onSort,\n onResize,\n onResizeEnd,\n}: {\n col: DataGridColumnDef<TRow>;\n isSorted: false | \"asc\" | \"desc\";\n sortIndex: number | null;\n resizable: boolean;\n onSort: (columnId: string, multi: boolean) => void;\n onResize: (columnId: string, delta: number) => void;\n onResizeEnd: () => void;\n}) {\n const ctx: DataGridHeaderContext<TRow> = {\n columnId: col.id,\n columnDef: col,\n isSorted,\n sortIndex,\n };\n const label =\n typeof col.header === \"function\" ? col.header(ctx) : col.header;\n\n const sortable = col.sortable !== false;\n\n return (\n <div\n className={cn(\n \"group/header relative flex items-center gap-1.5 px-3 select-none bg-transparent overflow-hidden\",\n \"border-r border-black/[0.04] dark:border-white/[0.04] last:border-r-0\",\n sortable && \"cursor-pointer\",\n )}\n style={getColumnSizingStyle(col)}\n data-col-id={col.id}\n onClick={(e) => sortable && onSort(col.id, e.metaKey || e.ctrlKey)}\n role=\"columnheader\"\n aria-sort={isSorted === \"asc\" ? \"ascending\" : isSorted === \"desc\" ? \"descending\" : \"none\"}\n >\n <span\n className={cn(\n \"flex-1 min-w-0 truncate text-xs font-semibold uppercase tracking-wider text-muted-foreground\",\n col.align === \"center\" && \"text-center\",\n col.align === \"right\" && \"text-right\",\n )}\n >\n {label}\n </span>\n\n {/* Sort indicator */}\n {isSorted && (\n <span className=\"flex items-center gap-0.5 text-foreground/60\">\n {isSorted === \"asc\" ? (\n <ArrowUp className=\"h-3 w-3\" weight=\"bold\" />\n ) : (\n <ArrowDown className=\"h-3 w-3\" weight=\"bold\" />\n )}\n {sortIndex != null && (\n <span className=\"text-[10px] font-medium tabular-nums\">{sortIndex}</span>\n )}\n </span>\n )}\n\n {/* Unsorted hint on hover */}\n {!isSorted && sortable && (\n <span className=\"hidden group-hover/header:flex items-center text-foreground/20\">\n <CaretUp className=\"h-2.5 w-2.5 -mb-[1px]\" weight=\"bold\" />\n <CaretDown className=\"h-2.5 w-2.5 -mt-[1px]\" weight=\"bold\" />\n </span>\n )}\n\n {/* Resize handle */}\n {resizable && col.resizable !== false && (\n <ResizeHandle\n onResize={(delta) => onResize(col.id, delta)}\n onResizeEnd={onResizeEnd}\n />\n )}\n </div>\n );\n}\n\n// ─── Data cell ───────────────────────────────────────────────────────\n\nfunction DataCell<TRow>({\n col,\n row,\n rowId,\n rowIndex,\n isSelected,\n dateDisplay,\n}: {\n col: DataGridColumnDef<TRow>;\n row: TRow;\n rowId: RowId;\n rowIndex: number;\n isSelected: boolean;\n dateDisplay: DataGridDateDisplay;\n}) {\n const value = resolveColumnValue(col, row);\n const ctx: DataGridCellContext<TRow> = {\n row,\n rowId,\n rowIndex,\n value,\n columnId: col.id,\n isSelected,\n dateDisplay,\n };\n\n const isDateCol = col.type === \"date\" || col.type === \"dateTime\";\n let content: React.ReactNode;\n if (col.renderCell) {\n content = col.renderCell(ctx);\n } else if (isDateCol) {\n content = renderDateCell(value, dateDisplay, col);\n } else {\n content = formatCellValue(value);\n }\n const hasCellClick = col.onCellClick || col.onCellDoubleClick;\n\n const isWrap = col.cellOverflow === \"wrap\";\n\n return (\n <div\n className={cn(\n \"flex px-3 bg-transparent overflow-hidden\",\n \"border-r border-black/[0.04] dark:border-white/[0.04] last:border-r-0\",\n \"text-sm text-foreground\",\n isWrap ? \"items-start py-2\" : \"items-center\",\n col.align === \"center\" && \"justify-center\",\n col.align === \"right\" && \"justify-end\",\n hasCellClick && \"cursor-pointer\",\n )}\n style={getColumnSizingStyle(col)}\n data-col-id={col.id}\n role=\"gridcell\"\n onClick={col.onCellClick ? (e) => {\n e.stopPropagation();\n col.onCellClick!(ctx, e);\n } : undefined}\n onDoubleClick={col.onCellDoubleClick ? (e) => {\n e.stopPropagation();\n col.onCellDoubleClick!(ctx, e);\n } : undefined}\n >\n <div className={cn(\"min-w-0\", isWrap ? \"flex-1\" : \"truncate\")}>\n {content}\n </div>\n </div>\n );\n}\n\nfunction formatCellValue(value: unknown): React.ReactNode {\n if (value == null) return <span className=\"text-muted-foreground/40\">-</span>;\n if (typeof value === \"boolean\") {\n return (\n <span\n className={cn(\n \"inline-flex items-center px-1.5 py-0.5 rounded-md text-xs font-medium\",\n value\n ? \"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400\"\n : \"bg-foreground/[0.04] text-muted-foreground\",\n )}\n >\n {value ? \"Yes\" : \"No\"}\n </span>\n );\n }\n if (value instanceof Date) {\n return (\n <span className=\"tabular-nums text-muted-foreground\">\n {value.toLocaleDateString()}\n </span>\n );\n }\n return <span className=\"truncate\">{String(value)}</span>;\n}\n\n/** Built-in date cell — mirrors what `formatGridDate` returns but wraps\n * the display in a `<span>` with a `title` tooltip showing the absolute\n * datetime. Only used when the column has `type: \"date\" | \"dateTime\"`\n * and no custom `renderCell`. */\nfunction renderDateCell<TRow>(\n value: unknown,\n dateDisplay: DataGridDateDisplay,\n col: DataGridColumnDef<TRow>,\n): React.ReactNode {\n const { display, tooltip } = formatGridDate(value, dateDisplay, {\n parseValue: col.parseValue,\n dateFormat: col.dateFormat,\n });\n if (display == null) return <span className=\"text-muted-foreground/40\">-</span>;\n return (\n <span\n className=\"tabular-nums text-muted-foreground truncate cursor-help\"\n title={tooltip ?? undefined}\n >\n {display}\n </span>\n );\n}\n\n// ─── Skeleton row ────────────────────────────────────────────────────\n\nfunction hashStringToInt(value: string): number {\n let hash = 0;\n for (let i = 0; i < value.length; i++) {\n hash = ((hash << 5) - hash + value.charCodeAt(i)) | 0;\n }\n return Math.abs(hash);\n}\n\nfunction SkeletonRow({\n columns,\n height,\n showCheckbox,\n}: {\n columns: readonly DataGridColumnDef<any>[];\n height: number;\n showCheckbox?: boolean;\n}) {\n return (\n <div className=\"flex\" style={{ height }} role=\"row\">\n {showCheckbox && (\n <div\n className=\"flex items-center justify-center border-r border-black/[0.04] dark:border-white/[0.04]\"\n style={{ width: 44 }}\n >\n <DesignSkeleton className=\"h-4 w-4 rounded\" />\n </div>\n )}\n {columns.map((col) => (\n <div\n key={col.id}\n className=\"flex items-center px-3 border-r border-black/[0.04] dark:border-white/[0.04] last:border-r-0\"\n style={getColumnSizingStyle(col)}\n >\n <DesignSkeleton\n className=\"h-3.5 rounded-md\"\n style={{ width: `${40 + (hashStringToInt(col.id) % 40)}%` }}\n />\n </div>\n ))}\n </div>\n );\n}\n\n// ─── Checkbox cell ───────────────────────────────────────────────────\n\nfunction SelectionCheckbox({\n checked,\n indeterminate,\n onChange,\n ariaLabel,\n}: {\n checked: boolean;\n indeterminate?: boolean;\n onChange: (event: React.MouseEvent<HTMLButtonElement>) => void;\n ariaLabel: string;\n}) {\n const Icon = indeterminate ? MinusSquare : checked ? CheckSquare : Square;\n return (\n <button\n className={cn(\n \"flex items-center justify-center w-full h-full\",\n \"hover:bg-foreground/[0.04] transition-colors duration-75\",\n checked || indeterminate\n ? \"text-blue-600 dark:text-blue-400\"\n : \"text-muted-foreground/40 hover:text-muted-foreground/60\",\n )}\n onClick={(e) => {\n e.stopPropagation();\n onChange(e);\n }}\n aria-label={ariaLabel}\n role=\"checkbox\"\n aria-checked={indeterminate ? \"mixed\" : checked}\n >\n <Icon className=\"h-4 w-4\" weight={checked || indeterminate ? \"fill\" : \"regular\"} />\n </button>\n );\n}\n\n// ─── Infinite scroll sentinel ────────────────────────────────────────\n\n// Stable module-level no-op so passing `onLoadMore ?? NOOP` to\n// InfiniteScrollSentinel doesn't allocate a fresh function every render\n// (which would re-trigger the sentinel's IntersectionObserver effect).\nconst NOOP = () => {};\n\nfunction InfiniteScrollSentinel({\n onIntersect,\n isLoading,\n rootRef,\n strings,\n}: {\n onIntersect: () => void;\n isLoading: boolean;\n rootRef?: React.RefObject<Element | null>;\n strings: DataGridStrings;\n}) {\n const ref = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const el = ref.current;\n if (!el) return;\n\n const observer = new IntersectionObserver(\n (entries) => {\n if (entries[0]?.isIntersecting) {\n onIntersect();\n }\n },\n {\n root: rootRef?.current ?? null,\n rootMargin: \"200px\",\n },\n );\n observer.observe(el);\n return () => observer.disconnect();\n }, [onIntersect, rootRef]);\n\n return (\n <div ref={ref} className=\"flex items-center justify-center py-4\">\n {isLoading && (\n <div className=\"flex items-center gap-2 text-xs text-muted-foreground\">\n <div className=\"h-3 w-3 rounded-full border-2 border-current border-t-transparent animate-spin\" />\n {strings.loadingMore}\n </div>\n )}\n </div>\n );\n}\n\n// ─── Footer ──────────────────────────────────────────────────────────\n\nfunction DefaultFooter<TRow>({\n ctx,\n pagination,\n onChange,\n}: {\n ctx: DataGridFooterContext<TRow>;\n pagination: DataGridPaginationMode;\n onChange: React.Dispatch<React.SetStateAction<DataGridState>>;\n}) {\n const { state, totalRowCount, visibleRowCount, selectedRowCount, strings } = ctx;\n const totalPages = totalRowCount != null\n ? Math.max(1, Math.ceil(totalRowCount / state.pagination.pageSize))\n : undefined;\n\n const setPage = (pageIndex: number) =>\n onChange((s) => ({\n ...s,\n pagination: { ...s.pagination, pageIndex },\n }));\n\n const setPageSize = (pageSize: number) =>\n onChange((s) => ({\n ...s,\n pagination: { ...s.pagination, pageSize, pageIndex: 0 },\n }));\n\n return (\n <div className=\"flex items-center justify-between px-4 py-2.5 border-t border-foreground/[0.06] text-xs text-muted-foreground\">\n <div className=\"flex items-center gap-3\">\n {selectedRowCount > 0 && (\n <span className=\"font-medium text-foreground\">\n {strings.rowsSelected(selectedRowCount)}\n </span>\n )}\n {totalRowCount != null && (\n <span>\n {visibleRowCount} of {totalRowCount} rows\n </span>\n )}\n </div>\n\n {pagination !== \"infinite\" && totalPages != null && (\n <div className=\"flex items-center gap-3\">\n {/* Page size selector */}\n <div className=\"flex items-center gap-1.5\">\n <span>{strings.rowsPerPage}</span>\n <select\n className={cn(\n \"h-7 rounded-lg border border-black/[0.08] dark:border-white/[0.08] bg-background px-1.5\",\n \"text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-foreground/[0.1]\",\n \"cursor-pointer\",\n )}\n value={state.pagination.pageSize}\n onChange={(e) => setPageSize(Number(e.target.value))}\n >\n {[10, 25, 50, 100].map((size) => (\n <option key={size} value={size}>\n {size}\n </option>\n ))}\n </select>\n </div>\n\n {/* Page navigation */}\n <div className=\"flex items-center gap-1\">\n <button\n className={cn(\n \"h-7 w-7 flex items-center justify-center rounded-lg\",\n \"hover:bg-foreground/[0.04] disabled:opacity-30 disabled:cursor-not-allowed\",\n \"transition-colors duration-75\",\n )}\n onClick={() => setPage(state.pagination.pageIndex - 1)}\n disabled={state.pagination.pageIndex === 0}\n aria-label=\"Previous page\"\n >\n <CaretUp className=\"h-3.5 w-3.5 -rotate-90\" weight=\"bold\" />\n </button>\n <span className=\"px-2 tabular-nums font-medium\">\n {strings.pageOf(state.pagination.pageIndex + 1, totalPages)}\n </span>\n <button\n className={cn(\n \"h-7 w-7 flex items-center justify-center rounded-lg\",\n \"hover:bg-foreground/[0.04] disabled:opacity-30 disabled:cursor-not-allowed\",\n \"transition-colors duration-75\",\n )}\n onClick={() => setPage(state.pagination.pageIndex + 1)}\n disabled={state.pagination.pageIndex >= totalPages - 1}\n aria-label=\"Next page\"\n >\n <CaretDown className=\"h-3.5 w-3.5 -rotate-90\" weight=\"bold\" />\n </button>\n </div>\n </div>\n )}\n </div>\n );\n}\n\n// ─── Main DataGrid ───────────────────────────────────────────────────\n\n/**\n * Interactive table with sorting, quick search, pagination, selection,\n * and virtualization. Handles 10k+ rows smoothly. Pair with\n * `useDataSource` for client-side data; use an async `dataSource`\n * generator for server or infinite-scroll modes.\n *\n * ## Mental model (read this first — everything else depends on it)\n *\n * DataGrid is a **display** component. It does NOT sort, search, or\n * paginate your data directly — you own that, but `useDataSource` does\n * it for you. The `rows` prop is always the already-processed slice to\n * show. The grid tracks user intent in `state` (sort model, quick\n * search text, page index). You feed that state into `useDataSource`,\n * and its output goes back in as `rows`.\n *\n * `useDataSource` IS the processor. Given your full dataset and the\n * grid's state, it returns the searched + sorted + paginated rows\n * ready to pass to DataGrid. This is the ONLY correct pattern for\n * client-side data — do NOT pass a raw array to `rows`.\n *\n * ## Search (client vs async)\n *\n * - **Client mode** (`useDataSource` with `data`): a case-insensitive\n * substring match across every column is applied automatically.\n * Override the matcher with `matchRow` for fuzzy / weighted search,\n * or disable by passing `matchRow: () => true`.\n * - **Async mode** (`useDataSource` with `dataSource`): `state.quickSearch`\n * is forwarded to the generator as `params.quickSearch`. Same\n * mechanism as `params.sorting` — a change triggers a refetch, and\n * the generator is the \"matching logic\" (typically a WHERE / ILIKE\n * clause in the backend query). The grid does NO client-side\n * filtering in async mode.\n *\n * ## The canonical pattern\n *\n * ```tsx\n * // 1. Columns — define OUTSIDE the component or inside a useMemo. Must be stable.\n * const columns = React.useMemo(() => [\n * { id: \"name\", header: \"Name\", accessor: \"name\", width: 180, type: \"string\" },\n * { id: \"email\", header: \"Email\", accessor: \"email\", width: 240, type: \"string\" },\n * { id: \"role\", header: \"Role\", accessor: \"role\", width: 120, type: \"singleSelect\",\n * valueOptions: [{ value: \"admin\", label: \"Admin\" }, { value: \"member\", label: \"Member\" }] },\n * { id: \"signUps\", header: \"Sign-ups\", accessor: \"signUps\", width: 120, type: \"number\", align: \"right\",\n * renderCell: ({ value }) => <span className=\"tabular-nums\">{Number(value).toLocaleString()}</span> },\n * ], []);\n *\n * // 2. Grid state — one hook, initialized from the columns. NEVER build the state object by hand.\n * const [gridState, setGridState] = React.useState(() => createDefaultDataGridState(columns));\n *\n * // 3. Data source — wires your raw array through the grid state. ALWAYS call this\n * // hook unconditionally at the top level (no if/return before it).\n * const gridData = useDataSource({\n * data: users, // your raw array (can be [] while loading)\n * columns,\n * getRowId: (row) => row.id,\n * sorting: gridState.sorting,\n * quickSearch: gridState.quickSearch,\n * pagination: gridState.pagination,\n * paginationMode: \"client\", // \"client\" | \"server\" | \"infinite\"\n * });\n *\n * // 4. Render — `rows` comes from gridData.rows, NOT from your raw array.\n * <DataGrid\n * columns={columns}\n * rows={gridData.rows}\n * getRowId={(row) => row.id}\n * totalRowCount={gridData.totalRowCount}\n * isLoading={gridData.isLoading}\n * state={gridState}\n * onChange={setGridState}\n * selectionMode=\"none\" // \"none\" | \"single\" | \"multiple\"\n * maxHeight={480}\n * />\n * ```\n *\n * ## Iron rules (violating any of these breaks the grid)\n *\n * 1. The prop is `rows`, NOT `data`. There is no `data` prop on DataGrid.\n * `data` belongs on `useDataSource`.\n * 2. `rows` is ALWAYS `gridData.rows`. Never pass your raw array to\n * `rows` — the grid won't search, sort, or paginate it.\n * 3. Columns must be stable across renders. Define them outside the\n * component or wrap in `React.useMemo`. A fresh columns array every\n * render will reset sorting state.\n * 4. Initialize grid state with `createDefaultDataGridState(columns)`.\n * Do NOT spell out the state object manually — you will miss fields\n * and crash.\n * 5. `onChange` takes a `SetStateAction` (the setter you got from\n * `useState`). Pass `setGridState` directly. Do NOT wrap it unless\n * you know exactly what you're doing.\n * 6. Call `useDataSource` ONCE per grid, at the top level, before any\n * early return. It contains hooks.\n * 7. `renderCell` is a PURE function of its context. NEVER call React\n * hooks inside it (no `useState`, `useMemo`, `useEffect`, nothing).\n * If you need derived data per row, compute it BEFORE the render —\n * e.g. build a `Map<rowId, sparklineData>` in a `useMemo` and look\n * it up in `renderCell`.\n * 8. `toolbar` accepts `false` (hide it) or a render function\n * `(ctx) => ReactNode`. Anything else — `true`, `undefined`, a state\n * variable — will either show the default toolbar or crash. If you\n * just want the default toolbar, omit the prop entirely.\n * 9. The toolbar's search input writes to `state.quickSearch`. That\n * value is consumed by `useDataSource` — client mode filters\n * client-side, async mode forwards to the generator. Do NOT wire\n * a separate \"controlled\" search prop, everything flows through\n * grid state.\n *\n * ## renderCell — what you can and cannot do inside it\n *\n * ```tsx\n * // OK — pure rendering from ctx:\n * renderCell: ({ value }) => <span className=\"tabular-nums\">{Number(value).toLocaleString()}</span>\n * renderCell: ({ row }) => <Badge variant={row.active ? \"default\" : \"outline\"}>{row.status}</Badge>\n *\n * // OK — looking up pre-computed data by row id:\n * // BEFORE the return, in the component body:\n * const sparklinesById = React.useMemo(() => {\n * const m = new Map();\n * for (const u of users) {\n * m.set(u.id, u.recentActivity.map((n, i) => ({ ts: i, values: { primary: n } })));\n * }\n * return m;\n * }, [users]);\n * // Then inside the column def:\n * renderCell: ({ rowId }) => <MiniSparkline data={sparklinesById.get(rowId) ?? []} />\n *\n * // NOT OK — hooks inside renderCell:\n * renderCell: ({ row }) => {\n * const [hovered, setHovered] = React.useState(false); // ← crashes the grid\n * const data = React.useMemo(() => ..., []); // ← crashes the grid\n * return ...;\n * }\n *\n * // NOT OK — embedding AnalyticsChart (or any other controlled, stateful chart) per row:\n * // AnalyticsChart owns its own state, tooltips, zoom, and virtualized data\n * // pipeline. Instantiating one per row is expensive and fights the grid's\n * // virtualizer. Don't do it.\n * ```\n *\n * ## Sparklines and mini-charts in cells — use raw Recharts\n *\n * If you want a tiny chart (sparkline, micro bar chart, trend line) inside\n * a cell, drop down to raw `Recharts.*` components — they are lightweight\n * and stateless, so they render cleanly per row without owning any state.\n * Read pre-computed points off the row (or off a `Map<rowId, points>` you\n * built in a `useMemo` above) and pass them directly to the Recharts\n * primitive. Do NOT wrap them in `DesignChartContainer` or\n * `DesignChartCard` inside a cell — those add chrome meant for full-size\n * charts.\n *\n * ```tsx\n * // OK — raw Recharts sparkline per row:\n * renderCell: ({ rowId }) => {\n * const points = sparklinesById.get(rowId) ?? [];\n * return (\n * <Recharts.ResponsiveContainer width=\"100%\" height={28}>\n * <Recharts.LineChart data={points} margin={{ top: 2, right: 2, bottom: 2, left: 2 }}>\n * <Recharts.Line type=\"monotone\" dataKey=\"v\" stroke=\"currentColor\" strokeWidth={1.5} dot={false} isAnimationActive={false} />\n * </Recharts.LineChart>\n * </Recharts.ResponsiveContainer>\n * );\n * }\n * ```\n *\n * Keep in-cell Recharts configs minimal: no axes, no tooltips, no animation\n * (`isAnimationActive={false}`), tight margins, fixed height. The goal is a\n * visual summary, not an interactive chart.\n *\n * ## State shape (from `createDefaultDataGridState`)\n *\n * ```ts\n * {\n * sorting: [], // { columnId, direction: \"asc\" | \"desc\" }[]\n * quickSearch: \"\", // search input text\n * dateDisplay: \"relative\", // \"relative\" | \"absolute\"\n * columnVisibility: {}, columnWidths: {...},\n * columnPinning: { left: [], right: [] }, columnOrder: [...],\n * pagination: { pageIndex: 0, pageSize: 50 },\n * selection: { selectedIds: new Set(), anchorId: null },\n * }\n * ```\n *\n * Everything is updated through `setGridState` — the toolbar, header,\n * and footer all call it for you. You do not need to wire any of this\n * manually.\n *\n * ## Cell overflow and dynamic row heights\n *\n * By default every cell truncates its content with an ellipsis\n * (`cellOverflow: \"truncate\"`). For columns whose content should wrap\n * — badge lists, multi-line text, permission chips — set\n * `cellOverflow: \"wrap\"` on the column definition.\n *\n * To let rows grow to fit their tallest cell, set `rowHeight=\"auto\"`\n * on the grid. The virtualizer will measure each row after render and\n * adjust scroll positions accordingly. Pair with `estimatedRowHeight`\n * (default 44) for better scroll-position estimates before measurement.\n *\n * ```tsx\n * // Columns: UUIDs truncate, auth-method badges wrap\n * const columns = [\n * { id: \"userId\", header: \"User ID\", width: 130 }, // default truncate\n * { id: \"auth\", header: \"Auth methods\", width: 150, cellOverflow: \"wrap\",\n * renderCell: ({ row }) => (\n * <div className=\"flex flex-wrap gap-1\">\n * {row.authTypes.map((t) => <Badge key={t}>{t}</Badge>)}\n * </div>\n * ),\n * },\n * ];\n *\n * <DataGrid columns={columns} rowHeight=\"auto\" estimatedRowHeight={48} ... />\n * ```\n *\n * With a fixed numeric `rowHeight` (the default), `cellOverflow: \"wrap\"`\n * still lets content wrap within the row, but anything exceeding the\n * fixed height is clipped. This is useful when you want controlled\n * wrapping without variable row heights.\n *\n * ## Height and scrolling\n *\n * DataGrid is NOT a card. It has no border, rounded corners, or shadow of\n * its own. Wrap it in whatever chrome you want — a `DesignCard`, a section,\n * or just raw layout. The grid itself fills its parent's height via\n * `h-full`.\n *\n * How the grid gets its height (pick ONE):\n * 1. Bounded parent — put the grid inside a flex/grid container with a\n * definite height (e.g. `flex-1 min-h-0` inside a page-filling flex\n * column). The grid stretches to that height and scrolls its body.\n * 2. `maxHeight` prop — pass a number (pixels) or CSS string\n * (`\"480px\"`, `\"60vh\"`, `\"100%\"`). The grid caps at that size and\n * scrolls its body.\n * 3. Unbounded — omit `maxHeight` and let the parent grow freely. The\n * grid renders at its full content height and the page scrolls. Fine\n * for small lists; bad UX for thousands of rows.\n *\n * The toolbar, header, and footer are always `shrink-0`; only the body\n * scrolls. You do NOT need to subtract toolbar/footer heights from\n * `maxHeight` — the grid's internal flex layout handles that.\n *\n * ## When to use what\n *\n * - Simple static list, < 20 rows, no interaction → use a plain table component instead.\n * - Interactive table, sortable + searchable, any size → `DataGrid` +\n * `useDataSource` with `paginationMode: \"client\"`.\n * - Infinite scroll over a huge dataset you fetch in pages → `dataSource` async\n * generator + `paginationMode: \"infinite\"`. Only reach for this if you actually\n * need pagination over a remote source. For anything that fits in memory,\n * `\"client\"` is simpler and faster.\n *\n * ## Features you get for free\n *\n * Quick search, sortable columns (shift-click for multi-sort), column\n * visibility toggle, column resize, CSV export, virtualized rendering\n * for 10k+ rows, keyboard navigation, and a relative/absolute date\n * toggle for `date` / `dateTime` columns.\n */\nexport function DataGrid<TRow>(props: DataGridProps<TRow>) {\n const {\n columns: allColumns,\n rows,\n getRowId,\n totalRowCount,\n isLoading = false,\n isRefetching = false,\n hasMore = false,\n isLoadingMore = false,\n onLoadMore,\n state,\n onChange,\n paginationMode = \"paginated\",\n selectionMode = \"none\",\n resizable = true,\n rowHeight: rowHeightProp = 44,\n estimatedRowHeight: estimatedRowHeightProp,\n headerHeight = 44,\n overscan = 5,\n maxHeight,\n fillHeight = true,\n stickyTop,\n toolbar,\n toolbarExtra,\n emptyState,\n loadingState,\n footer,\n footerExtra,\n exportFilename = \"export\",\n strings: stringsOverride,\n className,\n // Callbacks\n onRowClick,\n onRowDoubleClick,\n onSelectionChange,\n onSortChange,\n } = props;\n\n const isDynamicRowHeight = rowHeightProp === \"auto\";\n const fixedRowHeight = isDynamicRowHeight ? undefined : rowHeightProp;\n const estimatedRowHeight = estimatedRowHeightProp ?? (fixedRowHeight ?? 44);\n\n const strings = useMemo(\n () => resolveDataGridStrings(stringsOverride),\n [stringsOverride],\n );\n\n // ── Visible columns ──────────────────────────────────────────\n const visibleColumns = useMemo(\n () =>\n (state.columnOrder.length > 0\n ? state.columnOrder\n .map((id) => allColumns.find((c) => c.id === id))\n .filter(Boolean) as DataGridColumnDef<TRow>[]\n : allColumns\n ).filter((col) => isColumnVisible(col.id, state.columnVisibility)),\n [allColumns, state.columnOrder, state.columnVisibility],\n );\n\n // ── Row IDs (stable) ─────────────────────────────────────────\n const rowIds = useMemo(() => rows.map(getRowId), [rows, getRowId]);\n\n // ── Column widths ────────────────────────────────────────────\n const visibleColumnMetrics = useMemo(() => {\n const widths = new Map<string, number>();\n let totalWidth = selectionMode !== \"none\" ? 44 : 0;\n\n for (const col of visibleColumns) {\n const width = resolveColumnWidth(col, state.columnWidths[col.id]);\n widths.set(col.id, width);\n totalWidth += width;\n }\n\n return { widths, totalWidth };\n }, [selectionMode, state.columnWidths, visibleColumns]);\n\n const gridSizingStyle = useMemo(\n () => createGridSizingStyle(visibleColumnMetrics.widths, visibleColumnMetrics.totalWidth),\n [visibleColumnMetrics],\n );\n\n // Resize drag tracked via ref — zero React re-renders during drag.\n // CSS variables on gridRef are mutated directly; committed on pointer up.\n const resizeRef = useRef<{ columnId: string; baseWidth: number; baseTotalWidth: number; latestWidth: number } | null>(null);\n const gridRef = useRef<HTMLDivElement>(null);\n\n // ── Handlers ─────────────────────────────────────────────────\n const handleSort = useCallback(\n (columnId: string, multi: boolean) => {\n const next = toggleSort(state.sorting, columnId, multi);\n onChange((s) => ({ ...s, sorting: next }));\n onSortChange?.(next);\n },\n [onChange, onSortChange, state.sorting],\n );\n\n const handleResize = useCallback(\n (columnId: string, delta: number) => {\n const col = allColumns.find((c) => c.id === columnId);\n if (!col) return;\n if (!resizeRef.current || resizeRef.current.columnId !== columnId) {\n const baseWidth = visibleColumnMetrics.widths.get(columnId) ?? resolveColumnWidth(col, state.columnWidths[columnId]);\n resizeRef.current = { columnId, baseWidth, baseTotalWidth: visibleColumnMetrics.totalWidth, latestWidth: baseWidth };\n }\n const newWidth = clampColumnWidth(col, resizeRef.current.baseWidth + delta);\n resizeRef.current.latestWidth = newWidth;\n if (gridRef.current) {\n applyDraggedColumnWidth(gridRef.current, columnId, newWidth, resizeRef.current.baseTotalWidth + (newWidth - resizeRef.current.baseWidth));\n }\n },\n [allColumns, state.columnWidths, visibleColumnMetrics],\n );\n\n // Re-apply CSS vars after React re-renders (e.g. sort during drag)\n useLayoutEffect(() => {\n const r = resizeRef.current;\n if (r && gridRef.current) {\n applyDraggedColumnWidth(gridRef.current, r.columnId, r.latestWidth, r.baseTotalWidth + (r.latestWidth - r.baseWidth));\n }\n }, [gridSizingStyle]);\n\n const handleResizeEnd = useCallback(() => {\n const r = resizeRef.current;\n resizeRef.current = null;\n if (!r || r.latestWidth === r.baseWidth) return;\n onChange((s) => ({ ...s, columnWidths: { ...s.columnWidths, [r.columnId]: r.latestWidth } }));\n }, [onChange]);\n\n const handleRowClick = useCallback(\n (row: TRow, rowId: RowId, event: React.MouseEvent) => {\n // Selection callbacks fire outside the updater (fixes strict-mode\n // double-invoke from the old `setTimeout` inside the reducer). Compute\n // from the current controlled prop instead of from inside the updater,\n // because React does not guarantee updater functions run synchronously.\n if (selectionMode !== \"none\") {\n const next = toggleRowSelection(\n state.selection,\n rowId,\n selectionMode,\n event.shiftKey,\n event.metaKey || event.ctrlKey,\n rowIds,\n );\n onChange((s) => ({ ...s, selection: next }));\n if (onSelectionChange) {\n const selectedRows = rows.filter((r) => next.selectedIds.has(getRowId(r)));\n onSelectionChange(next.selectedIds, selectedRows);\n }\n }\n\n onRowClick?.(row, rowId, event);\n },\n [selectionMode, onChange, onRowClick, onSelectionChange, rowIds, rows, getRowId, state.selection],\n );\n\n const handleRowSelectionCheckboxClick = useCallback(\n (\n row: TRow,\n rowId: RowId,\n event: React.MouseEvent<HTMLButtonElement>,\n ) => {\n handleRowClick(row, rowId, event);\n },\n [handleRowClick],\n );\n\n const handleSelectAll = useCallback(() => {\n const allSelectedNow = rowIds.every((id) => state.selection.selectedIds.has(id));\n const next = allSelectedNow ? clearSelection() : selectAll(rowIds);\n const selectedRows = allSelectedNow ? [] : rows;\n onChange((s) => ({ ...s, selection: next }));\n if (onSelectionChange) {\n onSelectionChange(next.selectedIds, [...selectedRows]);\n }\n }, [onChange, rowIds, rows, onSelectionChange, state.selection]);\n\n const handleExportCsv = useCallback(() => {\n exportToCsv(rows, visibleColumns, exportFilename);\n }, [rows, visibleColumns, exportFilename]);\n\n // ── Virtualizer ──────────────────────────────────────────────\n const scrollContainerRef = useRef<HTMLDivElement>(null);\n const headerScrollRef = useRef<HTMLDivElement>(null);\n const stickyChromeRef = useRef<HTMLDivElement>(null);\n const rowsClipRef = useRef<HTMLDivElement>(null);\n const measureElementFn = useCallback(\n (el: Element) => el.getBoundingClientRect().height,\n [],\n );\n // Key each virtual item by its row id (not index) so that when rows are\n // sorted / filtered, the virtualizer's measurement cache follows the row\n // rather than the slot. Matters specifically in dynamic-height mode —\n // otherwise a heavy row scrolling into slot-5 inherits slot-5's old\n // measurement until the browser re-measures.\n const rowVirtualizer = useVirtualizer({\n count: rows.length,\n getScrollElement: () => scrollContainerRef.current,\n estimateSize: () => estimatedRowHeight,\n overscan,\n getItemKey: (index) => {\n const row = rows[index];\n return row != null ? String(getRowId(row)) : index;\n },\n ...(isDynamicRowHeight ? { measureElement: measureElementFn } : {}),\n });\n\n // Composite ancestor backgrounds into a single opaque color so the\n // sticky header fully covers rows scrolling underneath. Handles\n // semi-transparent layers like `bg-white/80` by alpha-blending the\n // full ancestor chain. Re-runs on theme changes (class on <html>).\n useLayoutEffect(() => {\n const grid = gridRef.current;\n const stickyEl = stickyChromeRef.current;\n if (!grid || !stickyEl) return;\n\n const parseRgba = (raw: string): [number, number, number, number] | null => {\n const rgbaMatch = raw.match(/rgba?\\(\\s*([\\d.]+),\\s*([\\d.]+),\\s*([\\d.]+)(?:,\\s*([\\d.]+))?\\s*\\)/);\n if (!rgbaMatch) return null;\n // Alpha is an optional capture group so at runtime this may be\n // undefined, even though TS's types for `RegExp.match` say otherwise.\n const alphaRaw = rgbaMatch[4] as string | undefined;\n return [\n Number(rgbaMatch[1]),\n Number(rgbaMatch[2]),\n Number(rgbaMatch[3]),\n alphaRaw === undefined ? 1 : Number(alphaRaw),\n ];\n };\n\n const blendOver = (\n base: [number, number, number, number],\n top: [number, number, number, number],\n ): [number, number, number, number] => {\n const [tr, tg, tb, ta] = top;\n const [br, bg, bb, ba] = base;\n const outA = ta + ba * (1 - ta);\n if (outA === 0) return [0, 0, 0, 0];\n return [\n (tr * ta + br * ba * (1 - ta)) / outA,\n (tg * ta + bg * ba * (1 - ta)) / outA,\n (tb * ta + bb * ba * (1 - ta)) / outA,\n outA,\n ];\n };\n\n const detect = () => {\n const layers: [number, number, number, number][] = [];\n let ancestor: HTMLElement | null = grid.parentElement;\n while (ancestor) {\n const parsed = parseRgba(getComputedStyle(ancestor).backgroundColor);\n if (parsed && parsed[3] > 0) {\n layers.push(parsed);\n if (parsed[3] >= 1) break;\n }\n ancestor = ancestor.parentElement;\n }\n\n if (layers.length === 0) {\n stickyEl.style.backgroundColor = \"\";\n return;\n }\n\n // Blend bottom-up (deepest ancestor is the base)\n let result: [number, number, number, number] = layers[layers.length - 1]!;\n for (let i = layers.length - 2; i >= 0; i--) {\n result = blendOver(result, layers[i]!);\n }\n\n const [r, g, b] = result;\n stickyEl.style.backgroundColor = `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`;\n };\n\n detect();\n\n const observer = new MutationObserver(detect);\n observer.observe(document.documentElement, { attributes: true, attributeFilter: [\"class\"] });\n return () => observer.disconnect();\n }, []);\n\n // Hide row content scrolling behind the sticky chrome by clipping the\n // rows wrapper. Computes overlap = max(0, stickyBottom - wrapperTop)\n // in viewport coords and writes `clip-path: inset(<overlap>px 0 0 0)`\n // directly to the wrapper on every scroll/resize. Direct DOM writes\n // (no React state, no rAF) keep clip in lockstep with scroll so no\n // row content flashes through the sticky band for a frame.\n useLayoutEffect(() => {\n const gridEl = gridRef.current;\n const stickyEl = stickyChromeRef.current;\n const bodyEl = scrollContainerRef.current;\n const clipEl = rowsClipRef.current;\n if (!gridEl || !stickyEl || !bodyEl || !clipEl) return;\n\n const verticalScrollEl = fillHeight\n ? bodyEl\n : getNearestVerticalScrollElement(gridEl);\n let extraObservedScrollEl: HTMLElement | null = null;\n if (verticalScrollEl instanceof HTMLElement && verticalScrollEl !== bodyEl) {\n extraObservedScrollEl = verticalScrollEl;\n }\n\n const updateClip = () => {\n const stickyRect = stickyEl.getBoundingClientRect();\n const clipRect = clipEl.getBoundingClientRect();\n const overlap = Math.max(0, stickyRect.bottom - clipRect.top);\n const clipValue = overlap > 0 ? `inset(${overlap}px 0 0 0)` : \"\";\n const maskValue = overlap > 0\n ? `linear-gradient(to bottom, transparent 0px, transparent ${overlap}px, black ${overlap}px, black 100%)`\n : \"\";\n clipEl.style.clipPath = clipValue;\n clipEl.style.setProperty(\"-webkit-clip-path\", clipValue);\n clipEl.style.maskImage = maskValue;\n clipEl.style.setProperty(\"-webkit-mask-image\", maskValue);\n };\n\n updateClip();\n\n bodyEl.addEventListener(\"scroll\", updateClip);\n if (verticalScrollEl === window) {\n window.addEventListener(\"scroll\", updateClip, true);\n } else if (extraObservedScrollEl) {\n extraObservedScrollEl.addEventListener(\"scroll\", updateClip);\n }\n window.addEventListener(\"resize\", updateClip);\n const ro = new ResizeObserver(updateClip);\n ro.observe(gridEl);\n ro.observe(stickyEl);\n ro.observe(bodyEl);\n // NOTE: deliberately not observing `clipEl`. The effect writes\n // `clip-path`/`mask-image` to `clipEl`, so observing it creates a\n // feedback loop that thrashes height inside a bounded parent. `gridEl` /\n // `bodyEl` changing size already covers clip-relevant layout changes.\n if (extraObservedScrollEl) {\n ro.observe(extraObservedScrollEl);\n }\n\n return () => {\n bodyEl.removeEventListener(\"scroll\", updateClip);\n if (verticalScrollEl === window) {\n window.removeEventListener(\"scroll\", updateClip, true);\n } else if (extraObservedScrollEl) {\n extraObservedScrollEl.removeEventListener(\"scroll\", updateClip);\n }\n window.removeEventListener(\"resize\", updateClip);\n ro.disconnect();\n };\n }, [fillHeight]);\n\n // Sync horizontal scroll from body to header\n const handleBodyScroll = useCallback(() => {\n const body = scrollContainerRef.current;\n const header = headerScrollRef.current;\n if (body && header) {\n header.scrollLeft = body.scrollLeft;\n }\n }, []);\n\n // ── Toolbar context ──────────────────────────────────────────\n const toolbarCtx: DataGridToolbarContext<TRow> = useMemo(\n () => ({\n state,\n onChange,\n columns: allColumns,\n visibleColumns,\n totalRowCount,\n selectedRowCount: state.selection.selectedIds.size,\n strings,\n exportCsv: handleExportCsv,\n }),\n [state, onChange, allColumns, visibleColumns, totalRowCount, strings, handleExportCsv],\n );\n\n // ── Footer context ───────────────────────────────────────────\n const footerCtx: DataGridFooterContext<TRow> = useMemo(\n () => ({\n state,\n totalRowCount,\n visibleRowCount: rows.length,\n selectedRowCount: state.selection.selectedIds.size,\n paginationMode,\n strings,\n }),\n [state, totalRowCount, rows.length, paginationMode, strings],\n );\n\n // ── Selection state for header checkbox ──────────────────────\n const allSelected = rowIds.length > 0 && rowIds.every((id) => state.selection.selectedIds.has(id));\n const someSelected = !allSelected && rowIds.some((id) => state.selection.selectedIds.has(id));\n const infiniteScrollRootRef =\n paginationMode === \"infinite\" && (fillHeight || maxHeight != null)\n ? scrollContainerRef\n : undefined;\n\n // ── Render ───────────────────────────────────────────────────\n //\n // Height model:\n // - Root is `flex flex-col h-full min-h-0 bg-transparent`. `h-full`\n // makes the grid fill a bounded parent; in an unbounded parent it\n // resolves to `auto` and the grid takes the content's intrinsic size.\n // - Toolbar + header are wrapped in a single `sticky top-0` container\n // so they pin to the top of the nearest scroll ancestor. Footer is\n // `shrink-0`; the scroll body is `flex-1 min-h-0 overflow-auto`.\n // - `maxHeight` is applied directly to the root; the scroll body never\n // subtracts chrome sizes manually (that math breaks when the toolbar\n // wraps, the footer grows, etc.).\n // - `fillHeight={false}` uses `h-auto` and a non-growing scroll body so the grid\n // only occupies the height of its rows (no flex gap above sibling sections).\n return (\n <div\n ref={gridRef}\n className={cn(\n \"flex w-full min-w-0 max-w-full flex-col bg-transparent rounded-[calc(var(--radius)*2)]\",\n fillHeight ? \"min-h-0 h-full\" : \"min-h-0 h-auto\",\n className,\n )}\n style={maxHeight != null ? { ...gridSizingStyle, maxHeight } : gridSizingStyle}\n role=\"grid\"\n aria-rowcount={totalRowCount ?? rows.length}\n aria-colcount={visibleColumns.length}\n >\n {/* Sticky chrome: toolbar + header pin to the top of the nearest\n scroll ancestor so they remain visible while the body scrolls. */}\n <div\n ref={stickyChromeRef}\n className=\"sticky z-20 w-full min-w-0 shrink-0 rounded-t-[calc(var(--radius)*2)] bg-background\"\n style={{ top: stickyTop ?? \"var(--data-grid-sticky-top, 0px)\" }}\n >\n {/* Toolbar */}\n {toolbar !== false && (\n <div className=\"relative bg-transparent\">\n {toolbar ? (\n toolbar(toolbarCtx)\n ) : (\n <DataGridToolbar\n ctx={toolbarCtx}\n extra={\n typeof toolbarExtra === \"function\"\n ? toolbarExtra(toolbarCtx)\n : toolbarExtra\n }\n />\n )}\n </div>\n )}\n\n {/* Header row — syncs horizontal scroll with the body */}\n <div className=\"relative\">\n {isRefetching && (\n <div className=\"absolute top-0 left-0 right-0 h-0.5 z-30 bg-foreground/[0.04] overflow-hidden\">\n <div className=\"h-full w-1/3 bg-blue-500/60 rounded-full animate-pulse\" />\n </div>\n )}\n <div\n ref={headerScrollRef}\n className=\"w-full min-w-0 shrink-0 overflow-hidden border-b border-foreground/[0.06]\"\n >\n <div\n className=\"flex\"\n style={{ height: headerHeight, minWidth: visibleColumnMetrics.totalWidth }}\n role=\"row\"\n >\n {selectionMode !== \"none\" && (\n <div\n className=\"flex items-center justify-center border-r border-foreground/[0.04]\"\n style={{ width: 44 }}\n >\n {selectionMode === \"multiple\" && (\n <SelectionCheckbox\n checked={allSelected}\n indeterminate={someSelected}\n onChange={handleSelectAll}\n ariaLabel=\"Select all rows\"\n />\n )}\n </div>\n )}\n {visibleColumns.map((col) => (\n <HeaderCell\n key={col.id}\n col={col}\n isSorted={getSortDirection(state.sorting, col.id)}\n sortIndex={getSortIndex(state.sorting, col.id)}\n resizable={resizable}\n onSort={handleSort}\n onResize={handleResize}\n onResizeEnd={handleResizeEnd}\n />\n ))}\n </div>\n </div>\n </div>\n </div>\n\n {/* Scrollable body — flex-1 + min-h-0 when filling parent; flex-none when\n `fillHeight` is false so row stack height drives the grid (page scroll). */}\n <div\n ref={scrollContainerRef}\n className={cn(\n \"w-full min-w-0 overflow-auto bg-transparent\",\n fillHeight ? \"min-h-0 flex-1\" : \"flex-none\",\n \"[&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar]:h-1.5\",\n \"[&::-webkit-scrollbar-track]:bg-transparent\",\n \"[&::-webkit-scrollbar-thumb]:bg-foreground/[0.08] [&::-webkit-scrollbar-thumb]:rounded-full\",\n \"[&::-webkit-scrollbar-thumb]:hover:bg-foreground/[0.15]\",\n )}\n onScroll={handleBodyScroll}\n >\n {/* Clip wrapper — `clip-path` updated on scroll/resize so row\n content scrolling behind the sticky chrome is physically cut\n out instead of bleeding through. */}\n <div ref={rowsClipRef}>\n {/* Loading initial */}\n {isLoading && (\n <div style={{ minWidth: visibleColumnMetrics.totalWidth }}>\n {loadingState ??\n Array.from({ length: 8 }).map((_, i) => (\n <SkeletonRow\n key={i}\n columns={visibleColumns}\n height={estimatedRowHeight}\n showCheckbox={selectionMode !== \"none\"}\n />\n ))}\n </div>\n )}\n\n {/* Empty state */}\n {!isLoading && rows.length === 0 && (\n <div\n className=\"flex items-center justify-center py-16 text-sm text-muted-foreground\"\n style={{ minWidth: visibleColumnMetrics.totalWidth }}\n >\n {emptyState ?? strings.noData}\n </div>\n )}\n\n {/* Virtualized rows */}\n {!isLoading && rows.length > 0 && (\n <div\n style={{\n height: rowVirtualizer.getTotalSize(),\n width: \"100%\",\n minWidth: visibleColumnMetrics.totalWidth,\n position: \"relative\",\n }}\n >\n {rowVirtualizer.getVirtualItems().map((virtualRow: VirtualItem) => {\n const row = rows[virtualRow.index] ?? throwErr(\n `DataGrid: virtualized row index ${virtualRow.index} out of range (rows.length=${rows.length})`,\n );\n const rowId = getRowId(row);\n const isSelected = state.selection.selectedIds.has(rowId);\n\n const isOddRow = virtualRow.index % 2 === 1;\n return (\n <div\n key={rowId}\n ref={isDynamicRowHeight ? rowVirtualizer.measureElement : undefined}\n data-index={virtualRow.index}\n className={cn(\n \"absolute left-0 w-full flex\",\n \"border-b border-black/[0.03] dark:border-white/[0.03]\",\n \"transition-colors duration-75\",\n isSelected\n ? \"bg-blue-500/[0.06] dark:bg-blue-400/[0.08] hover:bg-blue-500/[0.08] dark:hover:bg-blue-400/[0.1]\"\n : isOddRow\n ? \"bg-foreground/[0.02] dark:bg-foreground/[0.03] hover:bg-foreground/[0.04] dark:hover:bg-foreground/[0.06]\"\n : \"hover:bg-foreground/[0.025] dark:hover:bg-foreground/[0.04]\",\n (selectionMode !== \"none\" || onRowClick) && \"cursor-pointer\",\n )}\n style={{\n ...(isDynamicRowHeight\n ? { minHeight: estimatedRowHeight }\n : { height: fixedRowHeight }),\n transform: `translateY(${virtualRow.start}px)`,\n }}\n onClick={(e) => {\n if (shouldIgnoreRowClick(e)) {\n return;\n }\n handleRowClick(row, rowId, e);\n }}\n onDoubleClick={(e) => {\n if (shouldIgnoreRowClick(e)) {\n return;\n }\n onRowDoubleClick?.(row, rowId, e);\n }}\n role=\"row\"\n aria-rowindex={virtualRow.index + 2}\n aria-selected={isSelected}\n data-row-id={rowId}\n data-state={isSelected ? \"selected\" : undefined}\n >\n {/* Selection checkbox */}\n {selectionMode !== \"none\" && (\n <div\n className=\"flex items-center justify-center border-r border-black/[0.04] dark:border-white/[0.04]\"\n style={{ width: 44 }}\n >\n <SelectionCheckbox\n checked={isSelected}\n onChange={(event) => handleRowSelectionCheckboxClick(row, rowId, event)}\n ariaLabel={`Select row ${rowId}`}\n />\n </div>\n )}\n\n {/* Data cells */}\n {visibleColumns.map((col) => (\n <DataCell\n key={col.id}\n col={col}\n row={row}\n rowId={rowId}\n rowIndex={virtualRow.index}\n isSelected={isSelected}\n dateDisplay={state.dateDisplay}\n />\n ))}\n </div>\n );\n })}\n </div>\n )}\n\n {/* Infinite scroll sentinel */}\n {paginationMode === \"infinite\" && hasMore && !isLoading && (\n <InfiniteScrollSentinel\n onIntersect={onLoadMore ?? NOOP}\n isLoading={isLoadingMore}\n rootRef={infiniteScrollRootRef}\n strings={strings}\n />\n )}\n </div>\n </div>\n\n {/* Footer */}\n {footer !== false && (\n <div className=\"relative z-10 shrink-0 bg-transparent\">\n {footer ? (\n footer(footerCtx)\n ) : (\n <DefaultFooter\n ctx={footerCtx}\n pagination={paginationMode}\n onChange={onChange}\n />\n )}\n {footerExtra && (\n typeof footerExtra === \"function\" ? footerExtra(footerCtx) : footerExtra\n )}\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA2DA,SAAS,aAAa,EACpB,UACA,eAIC;CACD,MAAM,8BAAmB,EAAE;CAC3B,MAAM,2BAAgB,EAAE;CACxB,MAAM,mCAAwB,EAAE;CAChC,MAAM,iCAAsB;EAAE;EAAU;EAAa,CAAC;AAEtD,cAAa,UAAU;EAAE;EAAU;EAAa;CAEhD,MAAM,wCACH,MAA0B;AACzB,IAAE,gBAAgB;AAClB,IAAE,iBAAiB;AACnB,YAAU,UAAU,EAAE;AACtB,iBAAe,UAAU;EACzB,MAAM,KAAK,EAAE;AACb,KAAG,kBAAkB,EAAE,UAAU;EACjC,IAAI,WAAW;EAEf,MAAM,UAAU,OAAqB;AACnC,kBAAe,UAAU,GAAG,UAAU,UAAU;AAChD,OAAI,OAAO,YAAY,EACrB;AAGF,UAAO,UAAU,4BAA4B;AAC3C,WAAO,UAAU;AACjB,iBAAa,QAAQ,SAAS,eAAe,QAAQ;KACrD;;EAEJ,MAAM,eAAe;AACnB,OAAI,SAAU;AACd,cAAW;AACX,OAAI,OAAO,YAAY,GAAG;AACxB,yBAAqB,OAAO,QAAQ;AACpC,WAAO,UAAU;AACjB,iBAAa,QAAQ,SAAS,eAAe,QAAQ;;AAEvD,MAAG,oBAAoB,eAAe,OAAO;AAC7C,MAAG,oBAAoB,aAAa,OAAO;AAC3C,MAAG,oBAAoB,iBAAiB,OAAO;AAC/C,MAAG,oBAAoB,sBAAsB,OAAO;AACpD,OAAI,GAAG,kBAAkB,EAAE,UAAU,CACnC,IAAG,sBAAsB,EAAE,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Y,aAAa,aAAa;oBAGrC,kBAAkB,UACjB,2CAAC;UACC,WAAU;UACV,OAAO,EAAE,OAAO,IAAI;oBAEpB,2CAAC;WACC,SAAS;WACT,WAAW,UAAU,gCAAgC,KAAK,OAAO,MAAM;WACvE,WAAW,cAAc;YACzB;WACE,EAIP,eAAe,KAAK,QACnB,2CAAC;UAEM;UACA;UACE;UACP,UAAU,WAAW;UACT;UACZ,aAAa,MAAM;YANd,IAAI,GAOT,CACF;WA/DG,MAgED;SAER;QACE;MAIP,mBAAmB,cAAc,WAAW,CAAC,aAC5C,2CAAC;OACC,aAAa,cAAc;OAC3B,WAAW;OACX,SAAS;OACA;QACT;;MAEA;KACF;GAGL,WAAW,SACV,4CAAC;IAAI,WAAU;eACZ,SACC,OAAO,UAAU,GAEjB,2CAAC;KACC,KAAK;KACL,YAAY;KACF;MACV,EAEH,gBACC,OAAO,gBAAgB,aAAa,YAAY,UAAU,GAAG;KAE3D;;GAEJ"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,215 @@
1
+ const require_chunk = require('../../chunk-BE-pF4vm.js');
2
+ let react_jsx_runtime = require("react/jsx-runtime");
3
+ let react = require("react");
4
+ let _testing_library_react = require("@testing-library/react");
5
+ let vitest = require("vitest");
6
+ let __index_js = require("./index.js");
7
+
8
+ //#region src/components/data-grid/data-grid.test.tsx
9
+ // @vitest-environment jsdom
10
+ const columns = [{
11
+ id: "name",
12
+ header: "Name",
13
+ accessor: (row) => row.name,
14
+ width: 160,
15
+ minWidth: 80,
16
+ sortable: true,
17
+ type: "string"
18
+ }];
19
+ let intersectionObserverRecords = [];
20
+ var MockIntersectionObserver = class {
21
+ constructor(callback, options) {
22
+ this.callback = callback;
23
+ this.root = options?.root ?? null;
24
+ this.rootMargin = options?.rootMargin ?? "";
25
+ this.thresholds = Array.isArray(options?.threshold) ? options.threshold : [options?.threshold ?? 0];
26
+ this.record = { options };
27
+ intersectionObserverRecords.push(this.record);
28
+ }
29
+ disconnect() {}
30
+ observe() {}
31
+ takeRecords() {
32
+ return [];
33
+ }
34
+ unobserve() {}
35
+ trigger(entry = {}) {
36
+ this.callback([{
37
+ boundingClientRect: {},
38
+ intersectionRatio: 1,
39
+ intersectionRect: {},
40
+ isIntersecting: true,
41
+ rootBounds: null,
42
+ target: document.createElement("div"),
43
+ time: 0,
44
+ ...entry
45
+ }], this);
46
+ }
47
+ };
48
+ var MockResizeObserver = class {
49
+ disconnect() {}
50
+ observe() {}
51
+ unobserve() {}
52
+ };
53
+ function DataGridHarness(props) {
54
+ const [state, setState] = (0, react.useState)(() => (0, __index_js.createDefaultDataGridState)(columns));
55
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
56
+ style: { height: 400 },
57
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__index_js.DataGrid, {
58
+ columns,
59
+ rows: [{
60
+ id: "row-1",
61
+ name: "Row 1"
62
+ }],
63
+ getRowId: (row) => row.id,
64
+ state,
65
+ onChange: setState,
66
+ paginationMode: "infinite",
67
+ hasMore: true,
68
+ fillHeight: props.fillHeight
69
+ })
70
+ });
71
+ }
72
+ function InteractiveDataGridHarness(props) {
73
+ const [state, setState] = (0, react.useState)(() => (0, __index_js.createDefaultDataGridState)(columns));
74
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__index_js.DataGrid, {
75
+ columns,
76
+ rows: [{
77
+ id: "row-1",
78
+ name: "Row 1"
79
+ }],
80
+ getRowId: (row) => row.id,
81
+ state,
82
+ onChange: setState,
83
+ selectionMode: "multiple",
84
+ onSortChange: props.onSortChange,
85
+ onSelectionChange: props.onSelectionChange
86
+ });
87
+ }
88
+ (0, vitest.describe)("DataGrid infinite scroll observer", () => {
89
+ (0, vitest.beforeEach)(() => {
90
+ intersectionObserverRecords = [];
91
+ vitest.vi.stubGlobal("IntersectionObserver", MockIntersectionObserver);
92
+ vitest.vi.stubGlobal("ResizeObserver", MockResizeObserver);
93
+ vitest.vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function getBoundingClientRect() {
94
+ return {
95
+ x: 0,
96
+ y: 0,
97
+ width: 320,
98
+ height: 44,
99
+ top: 0,
100
+ left: 0,
101
+ right: 320,
102
+ bottom: 44,
103
+ toJSON() {
104
+ return this;
105
+ }
106
+ };
107
+ });
108
+ Object.defineProperty(HTMLElement.prototype, "clientHeight", {
109
+ configurable: true,
110
+ get() {
111
+ return 400;
112
+ }
113
+ });
114
+ Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
115
+ configurable: true,
116
+ get() {
117
+ return 400;
118
+ }
119
+ });
120
+ });
121
+ (0, vitest.afterEach)(() => {
122
+ (0, _testing_library_react.cleanup)();
123
+ vitest.vi.restoreAllMocks();
124
+ vitest.vi.unstubAllGlobals();
125
+ });
126
+ (0, vitest.it)("observes against the grid body when the grid owns vertical scrolling", async () => {
127
+ const { container } = (0, _testing_library_react.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataGridHarness, { fillHeight: true }));
128
+ await (0, _testing_library_react.waitFor)(() => {
129
+ (0, vitest.expect)(intersectionObserverRecords.length).toBeGreaterThan(0);
130
+ });
131
+ const grid = container.querySelector("[role=\"grid\"]");
132
+ (0, vitest.expect)(grid).not.toBeNull();
133
+ const scrollContainer = grid?.children.item(1);
134
+ (0, vitest.expect)(intersectionObserverRecords.at(-1)?.options?.root).toBe(scrollContainer);
135
+ });
136
+ (0, vitest.it)("falls back to the viewport when the page owns vertical scrolling", async () => {
137
+ (0, _testing_library_react.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataGridHarness, { fillHeight: false }));
138
+ await (0, _testing_library_react.waitFor)(() => {
139
+ (0, vitest.expect)(intersectionObserverRecords.length).toBeGreaterThan(0);
140
+ });
141
+ (0, vitest.expect)(intersectionObserverRecords.at(-1)?.options?.root ?? null).toBeNull();
142
+ });
143
+ });
144
+ (0, vitest.describe)("DataGrid controlled callbacks", () => {
145
+ (0, vitest.beforeEach)(() => {
146
+ vitest.vi.stubGlobal("ResizeObserver", MockResizeObserver);
147
+ vitest.vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function getBoundingClientRect() {
148
+ return {
149
+ x: 0,
150
+ y: 0,
151
+ width: 320,
152
+ height: 44,
153
+ top: 0,
154
+ left: 0,
155
+ right: 320,
156
+ bottom: 44,
157
+ toJSON() {
158
+ return this;
159
+ }
160
+ };
161
+ });
162
+ Object.defineProperty(HTMLElement.prototype, "clientHeight", {
163
+ configurable: true,
164
+ get() {
165
+ return 400;
166
+ }
167
+ });
168
+ Object.defineProperty(HTMLElement.prototype, "scrollHeight", {
169
+ configurable: true,
170
+ get() {
171
+ return 400;
172
+ }
173
+ });
174
+ });
175
+ (0, vitest.afterEach)(() => {
176
+ (0, _testing_library_react.cleanup)();
177
+ vitest.vi.restoreAllMocks();
178
+ vitest.vi.unstubAllGlobals();
179
+ });
180
+ (0, vitest.it)("fires onSortChange from the current controlled sort state", () => {
181
+ const onSortChange = vitest.vi.fn();
182
+ const { getByRole } = (0, _testing_library_react.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(InteractiveDataGridHarness, { onSortChange }));
183
+ _testing_library_react.fireEvent.click(getByRole("columnheader", { name: /name/i }));
184
+ (0, vitest.expect)(onSortChange).toHaveBeenCalledTimes(1);
185
+ (0, vitest.expect)(onSortChange).toHaveBeenCalledWith([{
186
+ columnId: "name",
187
+ direction: "asc"
188
+ }]);
189
+ });
190
+ (0, vitest.it)("fires onSelectionChange when selecting all rows", () => {
191
+ const onSelectionChange = vitest.vi.fn();
192
+ const { getByRole } = (0, _testing_library_react.render)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(InteractiveDataGridHarness, { onSelectionChange }));
193
+ _testing_library_react.fireEvent.click(getByRole("checkbox", { name: /select all rows/i }));
194
+ (0, vitest.expect)(onSelectionChange).toHaveBeenCalledTimes(1);
195
+ const [selectedIds, selectedRows] = onSelectionChange.mock.calls[0];
196
+ (0, vitest.expect)([...selectedIds]).toEqual(["row-1"]);
197
+ (0, vitest.expect)(selectedRows).toEqual([{
198
+ id: "row-1",
199
+ name: "Row 1"
200
+ }]);
201
+ });
202
+ (0, vitest.it)("identifies nested interactive controls as row-click blockers", () => {
203
+ const cell = document.createElement("div");
204
+ const button = document.createElement("button");
205
+ const label = document.createElement("span");
206
+ label.textContent = "Open menu";
207
+ button.append(label);
208
+ cell.append(button);
209
+ (0, vitest.expect)((0, __index_js.isDataGridInteractiveRowClickTarget)(label.firstChild)).toBe(true);
210
+ (0, vitest.expect)((0, __index_js.isDataGridInteractiveRowClickTarget)(cell)).toBe(false);
211
+ });
212
+ });
213
+
214
+ //#endregion
215
+ //# sourceMappingURL=data-grid.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-grid.test.js","names":["DataGrid","vi"],"sources":["../../../src/components/data-grid/data-grid.test.tsx"],"sourcesContent":["// @vitest-environment jsdom\n\nimport { cleanup, fireEvent, render, waitFor } from \"@testing-library/react\";\nimport { useState } from \"react\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport {\n createDefaultDataGridState,\n DataGrid,\n isDataGridInteractiveRowClickTarget,\n type DataGridColumnDef,\n type DataGridProps,\n} from \"./index\";\n\ntype Row = {\n id: string,\n name: string,\n};\n\nconst columns: DataGridColumnDef<Row>[] = [\n {\n id: \"name\",\n header: \"Name\",\n accessor: (row) => row.name,\n width: 160,\n minWidth: 80,\n sortable: true,\n type: \"string\",\n },\n];\n\ntype ObserverRecord = {\n options?: IntersectionObserverInit,\n};\n\nlet intersectionObserverRecords: ObserverRecord[] = [];\n\nclass MockIntersectionObserver implements IntersectionObserver {\n readonly root: Element | Document | null;\n readonly rootMargin: string;\n readonly thresholds: ReadonlyArray<number>;\n private readonly callback: IntersectionObserverCallback;\n private readonly record: ObserverRecord;\n\n constructor(\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n ) {\n this.callback = callback;\n this.root = options?.root ?? null;\n this.rootMargin = options?.rootMargin ?? \"\";\n this.thresholds = Array.isArray(options?.threshold)\n ? options.threshold\n : [options?.threshold ?? 0];\n this.record = { options };\n intersectionObserverRecords.push(this.record);\n }\n\n disconnect() {}\n observe() {}\n takeRecords(): IntersectionObserverEntry[] {\n return [];\n }\n unobserve() {}\n\n trigger(entry: Partial<IntersectionObserverEntry> = {}) {\n this.callback(\n [\n {\n boundingClientRect: {} as DOMRectReadOnly,\n intersectionRatio: 1,\n intersectionRect: {} as DOMRectReadOnly,\n isIntersecting: true,\n rootBounds: null,\n target: document.createElement(\"div\"),\n time: 0,\n ...entry,\n },\n ],\n this,\n );\n }\n}\n\nclass MockResizeObserver implements ResizeObserver {\n disconnect() {}\n observe() {}\n unobserve() {}\n}\n\nfunction DataGridHarness(props: { fillHeight?: boolean }) {\n const [state, setState] = useState(() => createDefaultDataGridState(columns));\n\n return (\n <div style={{ height: 400 }}>\n <DataGrid<Row>\n columns={columns}\n rows={[{ id: \"row-1\", name: \"Row 1\" }]}\n getRowId={(row) => row.id}\n state={state}\n onChange={setState}\n paginationMode=\"infinite\"\n hasMore\n fillHeight={props.fillHeight}\n />\n </div>\n );\n}\n\nfunction InteractiveDataGridHarness(props: {\n onSortChange?: DataGridProps<Row>[\"onSortChange\"],\n onSelectionChange?: DataGridProps<Row>[\"onSelectionChange\"],\n}) {\n const [state, setState] = useState(() => createDefaultDataGridState(columns));\n\n return (\n <DataGrid<Row>\n columns={columns}\n rows={[{ id: \"row-1\", name: \"Row 1\" }]}\n getRowId={(row) => row.id}\n state={state}\n onChange={setState}\n selectionMode=\"multiple\"\n onSortChange={props.onSortChange}\n onSelectionChange={props.onSelectionChange}\n />\n );\n}\n\ndescribe(\"DataGrid infinite scroll observer\", () => {\n beforeEach(() => {\n intersectionObserverRecords = [];\n\n vi.stubGlobal(\"IntersectionObserver\", MockIntersectionObserver);\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.spyOn(HTMLElement.prototype, \"getBoundingClientRect\").mockImplementation(\n function getBoundingClientRect() {\n return {\n x: 0,\n y: 0,\n width: 320,\n height: 44,\n top: 0,\n left: 0,\n right: 320,\n bottom: 44,\n toJSON() {\n return this;\n },\n } as DOMRect;\n },\n );\n Object.defineProperty(HTMLElement.prototype, \"clientHeight\", {\n configurable: true,\n get() {\n return 400;\n },\n });\n Object.defineProperty(HTMLElement.prototype, \"scrollHeight\", {\n configurable: true,\n get() {\n return 400;\n },\n });\n });\n\n afterEach(() => {\n cleanup();\n vi.restoreAllMocks();\n vi.unstubAllGlobals();\n });\n\n it(\"observes against the grid body when the grid owns vertical scrolling\", async () => {\n const { container } = render(<DataGridHarness fillHeight />);\n\n await waitFor(() => {\n expect(intersectionObserverRecords.length).toBeGreaterThan(0);\n });\n\n const grid = container.querySelector('[role=\"grid\"]');\n expect(grid).not.toBeNull();\n const scrollContainer = grid?.children.item(1);\n\n expect(intersectionObserverRecords.at(-1)?.options?.root).toBe(scrollContainer);\n });\n\n it(\"falls back to the viewport when the page owns vertical scrolling\", async () => {\n render(<DataGridHarness fillHeight={false} />);\n\n await waitFor(() => {\n expect(intersectionObserverRecords.length).toBeGreaterThan(0);\n });\n\n expect(intersectionObserverRecords.at(-1)?.options?.root ?? null).toBeNull();\n });\n});\n\ndescribe(\"DataGrid controlled callbacks\", () => {\n beforeEach(() => {\n vi.stubGlobal(\"ResizeObserver\", MockResizeObserver);\n vi.spyOn(HTMLElement.prototype, \"getBoundingClientRect\").mockImplementation(\n function getBoundingClientRect() {\n return {\n x: 0,\n y: 0,\n width: 320,\n height: 44,\n top: 0,\n left: 0,\n right: 320,\n bottom: 44,\n toJSON() {\n return this;\n },\n } as DOMRect;\n },\n );\n Object.defineProperty(HTMLElement.prototype, \"clientHeight\", {\n configurable: true,\n get() {\n return 400;\n },\n });\n Object.defineProperty(HTMLElement.prototype, \"scrollHeight\", {\n configurable: true,\n get() {\n return 400;\n },\n });\n });\n\n afterEach(() => {\n cleanup();\n vi.restoreAllMocks();\n vi.unstubAllGlobals();\n });\n\n it(\"fires onSortChange from the current controlled sort state\", () => {\n const onSortChange = vi.fn();\n const { getByRole } = render(<InteractiveDataGridHarness onSortChange={onSortChange} />);\n\n fireEvent.click(getByRole(\"columnheader\", { name: /name/i }));\n\n expect(onSortChange).toHaveBeenCalledTimes(1);\n expect(onSortChange).toHaveBeenCalledWith([{ columnId: \"name\", direction: \"asc\" }]);\n });\n\n it(\"fires onSelectionChange when selecting all rows\", () => {\n const onSelectionChange = vi.fn();\n const { getByRole } = render(<InteractiveDataGridHarness onSelectionChange={onSelectionChange} />);\n\n fireEvent.click(getByRole(\"checkbox\", { name: /select all rows/i }));\n\n expect(onSelectionChange).toHaveBeenCalledTimes(1);\n const [selectedIds, selectedRows] = onSelectionChange.mock.calls[0];\n expect([...selectedIds]).toEqual([\"row-1\"]);\n expect(selectedRows).toEqual([{ id: \"row-1\", name: \"Row 1\" }]);\n });\n\n it(\"identifies nested interactive controls as row-click blockers\", () => {\n const cell = document.createElement(\"div\");\n const button = document.createElement(\"button\");\n const label = document.createElement(\"span\");\n label.textContent = \"Open menu\";\n button.append(label);\n cell.append(button);\n\n expect(isDataGridInteractiveRowClickTarget(label.firstChild)).toBe(true);\n expect(isDataGridInteractiveRowClickTarget(cell)).toBe(false);\n });\n});\n"],"mappings":";;;;;;;;;AAkBA,MAAM,UAAoC,CACxC;CACE,IAAI;CACJ,QAAQ;CACR,WAAW,QAAQ,IAAI;CACvB,OAAO;CACP,UAAU;CACV,UAAU;CACV,MAAM;CACP,CACF;AAMD,IAAI,8BAAgD,EAAE;AAEtD,IAAM,2BAAN,MAA+D;CAO7D,YACE,UACA,SACA;AACA,OAAK,WAAW;AAChB,OAAK,OAAO,SAAS,QAAQ;AAC7B,OAAK,aAAa,SAAS,cAAc;AACzC,OAAK,aAAa,MAAM,QAAQ,SAAS,UAAU,GAC/C,QAAQ,YACR,CAAC,SAAS,aAAa,EAAE;AAC7B,OAAK,SAAS,EAAE,SAAS;AACzB,8BAA4B,KAAK,KAAK,OAAO;;CAG/C,aAAa;CACb,U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ridColumnVisibility, DataGridDataPaginationMode, DataGridDataSource, DataGridDateDisplay, DataGridDateFormat, DataGridFetchParams, DataGridFetchResult, DataGridFooterContext, DataGridHeaderContext, DataGridPaginationMode, DataGridPaginationModel, DataGridProps, DataGridSelectOption, DataGridSelectionMode, DataGridSelectionModel, DataGridSortItem, DataGridSortModel, DataGridState, DataGridStrings, DataGridToolbarContext, RowId } from "./types.js";
2
+ import { getEffectiveMinWidth } from "./data-grid-sizing.js";
2
3
  import { DataGridToolbar } from "./data-grid-toolbar.js";
3
- import { DataGrid } from "./data-grid.js";
4
+ import { DataGrid, isDataGridInteractiveRowClickTarget } from "./data-grid.js";
4
5
  import { UseDataSourceResult, useDataSource } from "./use-data-source.js";
5
6
  import { DEFAULT_PAGINATION, EMPTY_SELECTION, EMPTY_SORT_MODEL, applyQuickSearch, buildRowComparator, clearSelection, createDefaultDataGridState, defaultFormatAbsolute, defaultFormatRelative, defaultMatchRow, defaultParseDate, exportToCsv, formatGridDate, getSortDirection, getSortIndex, getTotalPages, isColumnVisible, paginateRows, resolveColumnValue, resolveColumnWidth, selectAll, toggleRowSelection, toggleSort } from "./state.js";
6
7
  import { DATA_GRID_DEFAULT_STRINGS, resolveDataGridStrings } from "./strings.js";
7
- export { DATA_GRID_DEFAULT_STRINGS, DEFAULT_PAGINATION, DataGrid, type DataGridCallbacks, type DataGridCellContext, type DataGridColumnAlign, type DataGridColumnDef, type DataGridColumnPin, type DataGridColumnPinning, type DataGridColumnType, type DataGridColumnVisibility, type DataGridDataPaginationMode, type DataGridDataSource, type DataGridDateDisplay, type DataGridDateFormat, type DataGridFetchParams, type DataGridFetchResult, type DataGridFooterContext, type DataGridHeaderContext, type DataGridPaginationMode, type DataGridPaginationModel, type DataGridProps, type DataGridSelectOption, type DataGridSelectionMode, type DataGridSelectionModel, type DataGridSortItem, type DataGridSortModel, type DataGridState, type DataGridStrings, DataGridToolbar, type DataGridToolbarContext, EMPTY_SELECTION, EMPTY_SORT_MODEL, type RowId, type UseDataSourceResult, applyQuickSearch, buildRowComparator, clearSelection, createDefaultDataGridState, defaultFormatAbsolute, defaultFormatRelative, defaultMatchRow, defaultParseDate, exportToCsv, formatGridDate, getSortDirection, getSortIndex, getTotalPages, isColumnVisible, paginateRows, resolveColumnValue, resolveColumnWidth, resolveDataGridStrings, selectAll, toggleRowSelection, toggleSort, useDataSource };
8
+ export { DATA_GRID_DEFAULT_STRINGS, DEFAULT_PAGINATION, DataGrid, type DataGridCallbacks, type DataGridCellContext, type DataGridColumnAlign, type DataGridColumnDef, type DataGridColumnPin, type DataGridColumnPinning, type DataGridColumnType, type DataGridColumnVisibility, type DataGridDataPaginationMode, type DataGridDataSource, type DataGridDateDisplay, type DataGridDateFormat, type DataGridFetchParams, type DataGridFetchResult, type DataGridFooterContext, type DataGridHeaderContext, type DataGridPaginationMode, type DataGridPaginationModel, type DataGridProps, type DataGridSelectOption, type DataGridSelectionMode, type DataGridSelectionModel, type DataGridSortItem, type DataGridSortModel, type DataGridState, type DataGridStrings, DataGridToolbar, type DataGridToolbarContext, EMPTY_SELECTION, EMPTY_SORT_MODEL, type RowId, type UseDataSourceResult, applyQuickSearch, buildRowComparator, clearSelection, createDefaultDataGridState, defaultFormatAbsolute, defaultFormatRelative, defaultMatchRow, defaultParseDate, exportToCsv, formatGridDate, getEffectiveMinWidth, getSortDirection, getSortIndex, getTotalPages, isColumnVisible, isDataGridInteractiveRowClickTarget, paginateRows, resolveColumnValue, resolveColumnWidth, resolveDataGridStrings, selectAll, toggleRowSelection, toggleSort, useDataSource };