@elabs-ai/components-data 4.1.0 → 5.0.0

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 (139) hide show
  1. package/README.md +1 -1
  2. package/dist/chunk-3OVN7MMO.js +2 -0
  3. package/dist/chunk-3OVN7MMO.js.map +1 -0
  4. package/dist/chunk-3UFWYVDS.js +2 -0
  5. package/dist/chunk-3UFWYVDS.js.map +1 -0
  6. package/dist/chunk-47ZBQZYS.js +47 -0
  7. package/dist/chunk-47ZBQZYS.js.map +1 -0
  8. package/dist/chunk-5K2IFOV2.js +2 -0
  9. package/dist/chunk-5K2IFOV2.js.map +1 -0
  10. package/dist/chunk-677ORWI6.js +17 -0
  11. package/dist/chunk-677ORWI6.js.map +1 -0
  12. package/dist/chunk-7ZYUY3UL.js +2 -0
  13. package/dist/chunk-7ZYUY3UL.js.map +1 -0
  14. package/dist/chunk-BEYHV3ZX.js +37 -0
  15. package/dist/chunk-BEYHV3ZX.js.map +1 -0
  16. package/dist/chunk-DBPJ7LVM.js +57 -0
  17. package/dist/chunk-DBPJ7LVM.js.map +1 -0
  18. package/dist/chunk-E3V3SYY7.js +87 -0
  19. package/dist/chunk-E3V3SYY7.js.map +1 -0
  20. package/dist/chunk-GBO56756.js +81 -0
  21. package/dist/chunk-GBO56756.js.map +1 -0
  22. package/dist/chunk-HG2YMSRM.js +95 -0
  23. package/dist/chunk-HG2YMSRM.js.map +1 -0
  24. package/dist/chunk-K2GHSRCP.js +1823 -0
  25. package/dist/chunk-K2GHSRCP.js.map +1 -0
  26. package/dist/chunk-KCB33PD3.js +43 -0
  27. package/dist/chunk-KCB33PD3.js.map +1 -0
  28. package/dist/chunk-MV2YVXEZ.js +67 -0
  29. package/dist/chunk-MV2YVXEZ.js.map +1 -0
  30. package/dist/chunk-NKVJUQYW.js +82 -0
  31. package/dist/chunk-NKVJUQYW.js.map +1 -0
  32. package/dist/chunk-OASM53LL.js +29 -0
  33. package/dist/chunk-OASM53LL.js.map +1 -0
  34. package/dist/chunk-RZ5MYZOA.js +2 -0
  35. package/dist/chunk-RZ5MYZOA.js.map +1 -0
  36. package/dist/chunk-SK6347WB.js +100 -0
  37. package/dist/chunk-SK6347WB.js.map +1 -0
  38. package/dist/chunk-TBB33PHQ.js +58 -0
  39. package/dist/chunk-TBB33PHQ.js.map +1 -0
  40. package/dist/chunk-VCLA45IC.js +150 -0
  41. package/dist/chunk-VCLA45IC.js.map +1 -0
  42. package/dist/chunk-XN6O6Z2N.js +58 -0
  43. package/dist/chunk-XN6O6Z2N.js.map +1 -0
  44. package/dist/chunk-ZFEW36RG.js +77 -0
  45. package/dist/chunk-ZFEW36RG.js.map +1 -0
  46. package/dist/chunk-ZQXJ34VJ.js +34 -0
  47. package/dist/chunk-ZQXJ34VJ.js.map +1 -0
  48. package/dist/chunk-ZUCGV2XD.js +42 -0
  49. package/dist/chunk-ZUCGV2XD.js.map +1 -0
  50. package/dist/column-picker/column-picker.js +8 -0
  51. package/dist/column-picker/column-picker.js.map +1 -0
  52. package/dist/column-picker/index.js +9 -0
  53. package/dist/column-picker/index.js.map +1 -0
  54. package/dist/data-table/card-layout.js +11 -0
  55. package/dist/data-table/card-layout.js.map +1 -0
  56. package/dist/data-table/cell-scales.js +26 -0
  57. package/dist/data-table/cell-scales.js.map +1 -0
  58. package/dist/data-table/cells/bar-cell.js +14 -0
  59. package/dist/data-table/cells/bar-cell.js.map +1 -0
  60. package/dist/data-table/cells/category-legend.js +9 -0
  61. package/dist/data-table/cells/category-legend.js.map +1 -0
  62. package/dist/data-table/cells/columns-cell.js +13 -0
  63. package/dist/data-table/cells/columns-cell.js.map +1 -0
  64. package/dist/data-table/cells/heatmap-cell.js +13 -0
  65. package/dist/data-table/cells/heatmap-cell.js.map +1 -0
  66. package/dist/data-table/cells/markdown-cell.js +13 -0
  67. package/dist/data-table/cells/markdown-cell.js.map +1 -0
  68. package/dist/data-table/cells/sparkline-cell.js +13 -0
  69. package/dist/data-table/cells/sparkline-cell.js.map +1 -0
  70. package/dist/data-table/column-meta.js +12 -0
  71. package/dist/data-table/column-meta.js.map +1 -0
  72. package/dist/data-table/data-table.js +23 -0
  73. package/dist/data-table/data-table.js.map +1 -0
  74. package/dist/data-table/index.js +23 -0
  75. package/dist/data-table/index.js.map +1 -0
  76. package/dist/data-table/ranks-column.js +13 -0
  77. package/dist/data-table/ranks-column.js.map +1 -0
  78. package/dist/data-table/sticky-rows.js +10 -0
  79. package/dist/data-table/sticky-rows.js.map +1 -0
  80. package/dist/data-table/use-table-breakpoint.js +13 -0
  81. package/dist/data-table/use-table-breakpoint.js.map +1 -0
  82. package/dist/facet-filter/facet-filter.js +8 -0
  83. package/dist/facet-filter/facet-filter.js.map +1 -0
  84. package/dist/facet-filter/index.js +9 -0
  85. package/dist/facet-filter/index.js.map +1 -0
  86. package/dist/filter-bar/filter-bar.js +8 -0
  87. package/dist/filter-bar/filter-bar.js.map +1 -0
  88. package/dist/filter-bar/filter-chip.js +9 -0
  89. package/dist/filter-bar/filter-chip.js.map +1 -0
  90. package/dist/filter-bar/index.js +13 -0
  91. package/dist/filter-bar/index.js.map +1 -0
  92. package/dist/index.d.ts +554 -10
  93. package/dist/index.js +102 -1494
  94. package/dist/index.js.map +1 -1
  95. package/dist/search-input/index.js +9 -0
  96. package/dist/search-input/index.js.map +1 -0
  97. package/dist/search-input/search-input.js +9 -0
  98. package/dist/search-input/search-input.js.map +1 -0
  99. package/dist/to-csv.js +10 -0
  100. package/dist/to-csv.js.map +1 -0
  101. package/package.json +7 -7
  102. package/src/__contract__/filter-chip.contract.test.tsx +49 -0
  103. package/src/column-picker/column-picker.tsx +3 -2
  104. package/src/data-table/card-layout.test.tsx +26 -0
  105. package/src/data-table/card-layout.tsx +74 -0
  106. package/src/data-table/cell-scales.test.ts +118 -0
  107. package/src/data-table/cell-scales.ts +246 -0
  108. package/src/data-table/cells/bar-cell.test.tsx +158 -0
  109. package/src/data-table/cells/bar-cell.tsx +135 -0
  110. package/src/data-table/cells/category-legend.test.tsx +37 -0
  111. package/src/data-table/cells/category-legend.tsx +58 -0
  112. package/src/data-table/cells/columns-cell.test.tsx +27 -0
  113. package/src/data-table/cells/columns-cell.tsx +79 -0
  114. package/src/data-table/cells/heatmap-cell.test.tsx +31 -0
  115. package/src/data-table/cells/heatmap-cell.tsx +116 -0
  116. package/src/data-table/cells/markdown-cell.test.tsx +36 -0
  117. package/src/data-table/cells/markdown-cell.tsx +91 -0
  118. package/src/data-table/cells/sparkline-cell.test.tsx +43 -0
  119. package/src/data-table/cells/sparkline-cell.tsx +113 -0
  120. package/src/data-table/column-meta.test.ts +42 -0
  121. package/src/data-table/column-meta.ts +282 -0
  122. package/src/data-table/data-table.stories.tsx +748 -1
  123. package/src/data-table/data-table.test.tsx +547 -11
  124. package/src/data-table/data-table.tsx +1014 -175
  125. package/src/data-table/ranks-column.test.tsx +65 -0
  126. package/src/data-table/ranks-column.tsx +91 -0
  127. package/src/data-table/sticky-rows.test.ts +16 -0
  128. package/src/data-table/sticky-rows.ts +77 -0
  129. package/src/data-table/use-table-breakpoint.test.ts +14 -0
  130. package/src/data-table/use-table-breakpoint.ts +67 -0
  131. package/src/facet-filter/facet-filter.stories.tsx +4 -1
  132. package/src/facet-filter/facet-filter.test.tsx +3 -3
  133. package/src/filter-bar/filter-chip.stories.tsx +1 -0
  134. package/src/index.ts +64 -0
  135. package/src/search-input/search-input.test.tsx +35 -0
  136. package/src/search-input/search-input.tsx +44 -19
  137. package/src/templates-data-app.stories.tsx +7 -2
  138. package/src/to-csv.test.ts +13 -0
  139. package/src/to-csv.ts +7 -30
package/dist/index.js CHANGED
@@ -1,1513 +1,121 @@
1
1
  "use client";
2
-
3
- // src/data-table/data-table.tsx
4
2
  import {
5
- forwardRef,
6
- useCallback,
7
- useEffect,
8
- useMemo,
9
- useRef,
10
- useState
11
- } from "react";
3
+ downloadCsv,
4
+ toCsv
5
+ } from "./chunk-ZQXJ34VJ.js";
6
+ import "./chunk-3UFWYVDS.js";
7
+ import {
8
+ FacetFilter
9
+ } from "./chunk-ZFEW36RG.js";
10
+ import "./chunk-3OVN7MMO.js";
11
+ import {
12
+ FilterBar
13
+ } from "./chunk-677ORWI6.js";
14
+ import {
15
+ FilterChip
16
+ } from "./chunk-OASM53LL.js";
17
+ import "./chunk-7ZYUY3UL.js";
18
+ import {
19
+ SearchInput
20
+ } from "./chunk-E3V3SYY7.js";
21
+ import "./chunk-RZ5MYZOA.js";
22
+ import {
23
+ DataTableWithRef,
24
+ createSelectionColumn
25
+ } from "./chunk-K2GHSRCP.js";
26
+ import {
27
+ DATA_TABLE_BREAKPOINT_THRESHOLDS,
28
+ tableBreakpointForWidth,
29
+ useTableBreakpoint
30
+ } from "./chunk-BEYHV3ZX.js";
12
31
  import {
13
- flexRender,
14
- getCoreRowModel,
15
- getFilteredRowModel,
16
- getPaginationRowModel,
17
- getSortedRowModel,
18
- useReactTable
19
- } from "@tanstack/react-table";
20
- import { useVirtualizer } from "@tanstack/react-virtual";
32
+ HeatmapCell,
33
+ HeatmapLegend,
34
+ heatmapCellStyle
35
+ } from "./chunk-NKVJUQYW.js";
21
36
  import {
22
- DndContext,
23
- KeyboardSensor,
24
- PointerSensor,
25
- closestCenter,
26
- useSensor,
27
- useSensors
28
- } from "@dnd-kit/core";
37
+ MarkdownCell,
38
+ isSafeCellUrl,
39
+ parseCellMarkdown
40
+ } from "./chunk-MV2YVXEZ.js";
29
41
  import {
30
- SortableContext,
31
- sortableKeyboardCoordinates,
32
- useSortable,
33
- verticalListSortingStrategy
34
- } from "@dnd-kit/sortable";
35
- import { CSS } from "@dnd-kit/utilities";
36
- import { ArrowDown, ArrowUp, ArrowUpDown, GripVertical } from "lucide-react";
37
- import { Button, Checkbox, Skeleton, Spinner, useLocale } from "@elabs-ai/components-ui";
38
- import { cn } from "@elabs-ai/components-ui/lib/cn";
39
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
40
- function numericColumnClasses(meta) {
41
- if (!meta?.numeric && !meta?.align) return void 0;
42
- const alignClass = meta?.align === "start" ? "text-start" : meta?.align === "center" ? "text-center" : meta?.align === "end" ? "text-end" : meta?.numeric ? "text-end" : void 0;
43
- return cn(alignClass, meta?.numeric && "tabular-nums");
44
- }
45
- var ROW_CLICK_GUARD_SELECTOR = 'button, a[href], input, select, textarea, label, summary, [role="button"], [role="link"], [role="menuitem"], [role="checkbox"], [role="radio"], [role="switch"], [role="tab"], [contenteditable="true"]';
46
- function isInteractiveEventTarget(target) {
47
- return target instanceof Element && target.closest(ROW_CLICK_GUARD_SELECTOR) !== null;
48
- }
49
- function isActiveTextSelection() {
50
- if (typeof window === "undefined" || typeof window.getSelection !== "function") return false;
51
- return window.getSelection()?.type === "Range";
52
- }
53
- var PINNED_SEAM_CLASS = "after:pointer-events-none after:absolute after:inset-y-0 after:w-px after:bg-border-strong after:content-['']";
54
- function unsizedColumnIds(defs) {
55
- const out = /* @__PURE__ */ new Set();
56
- const walk = (list) => {
57
- for (const def of list) {
58
- const group = def;
59
- if (group.columns) {
60
- walk(group.columns);
61
- continue;
62
- }
63
- if (def.size !== void 0) continue;
64
- const accessorKey = def.accessorKey;
65
- const id = def.id ?? (accessorKey !== void 0 ? String(accessorKey).replace(/\./gu, "_") : typeof def.header === "string" ? def.header : void 0);
66
- if (id) out.add(id);
67
- }
68
- };
69
- walk(defs);
70
- return out;
71
- }
72
- function resizeWidthStyle(size) {
73
- return { width: size, minWidth: size, maxWidth: size };
74
- }
75
- function firstDataCellValue(row) {
76
- for (const cell of row.getVisibleCells()) {
77
- if (!cell.column.accessorFn) continue;
78
- const value = cell.getValue();
79
- if (typeof value === "string" && value.trim() !== "") return value;
80
- if (typeof value === "number") return String(value);
81
- }
82
- return void 0;
83
- }
84
- function SelectAllHeaderCell({ table }) {
85
- const { t } = useLocale();
86
- const allSelected = table.getIsAllPageRowsSelected();
87
- const someSelected = table.getIsSomePageRowsSelected();
88
- return /* @__PURE__ */ jsx(
89
- Checkbox,
90
- {
91
- "data-slot": "data-table-select-all",
92
- checked: allSelected ? true : someSelected ? "indeterminate" : false,
93
- onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked === true),
94
- "aria-label": t("data.table.selectAllRows")
95
- }
96
- );
97
- }
98
- function SelectRowCell({ row }) {
99
- const { t } = useLocale();
100
- const name = firstDataCellValue(row);
101
- return /* @__PURE__ */ jsx(
102
- Checkbox,
103
- {
104
- "data-slot": "data-table-select-cell",
105
- checked: row.getIsSelected(),
106
- disabled: !row.getCanSelect(),
107
- onCheckedChange: (checked) => row.toggleSelected(checked === true),
108
- "aria-label": name ? t("data.table.selectRowNamed", { name }) : t("data.table.selectRow")
109
- }
110
- );
111
- }
112
- function createSelectionColumn() {
113
- return {
114
- id: "select",
115
- size: 40,
116
- enableSorting: false,
117
- enableHiding: false,
118
- header: ({ table }) => (
119
- // #11 C1: `toggleAllPageRowsSelected` wipes-then-sets on every row when
120
- // `enableMultiRowSelection` is off (TanStack's `mutateRowIsSelected`), so
121
- // a select-all header under single-select leaves only the LAST row
122
- // selected and pins the header at indeterminate forever. Suppress it.
123
- table.options.enableMultiRowSelection === false ? null : /* @__PURE__ */ jsx(SelectAllHeaderCell, { table })
124
- ),
125
- cell: ({ row }) => /* @__PURE__ */ jsx(SelectRowCell, { row })
126
- };
127
- }
128
- function SortableDataRow({
129
- id,
130
- disabled,
131
- attributesOverride,
132
- children
133
- }) {
134
- const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, isDragging } = useSortable({ id, disabled, transition: null, attributes: attributesOverride });
135
- return /* @__PURE__ */ jsx(Fragment, { children: children({
136
- setNodeRef,
137
- setActivatorNodeRef,
138
- attributes,
139
- listeners,
140
- isDragging,
141
- style: { transform: CSS.Transform.toString(transform) }
142
- }) });
143
- }
144
- function DataTableInner({
145
- columns,
146
- data,
147
- toolbar,
148
- enablePagination = false,
149
- pageSize = 10,
150
- hidePaginationWhenSingle = true,
151
- // Global filter
152
- globalFilter: globalFilterProp,
153
- onGlobalFilterChange,
154
- // Controlled slices
155
- sorting: sortingProp,
156
- onSortingChange: onSortingChangeProp,
157
- columnVisibility: columnVisibilityProp,
158
- onColumnVisibilityChange: onColumnVisibilityChangeProp,
159
- columnFilters: columnFiltersProp,
160
- onColumnFiltersChange: onColumnFiltersChangeProp,
161
- pagination: paginationProp,
162
- onPaginationChange: onPaginationChangeProp,
163
- columnPinning: columnPinningProp,
164
- onColumnPinningChange: onColumnPinningChangeProp,
165
- enableColumnResizing = false,
166
- columnResizeMode = "onChange",
167
- columnSizing: columnSizingProp,
168
- onColumnSizingChange: onColumnSizingChangeProp,
169
- rowSelection: rowSelectionProp,
170
- onRowSelectionChange: onRowSelectionChangeProp,
171
- enableRowSelection,
172
- enableMultiRowSelection,
173
- getRowId,
174
- // Saved views rehydration
175
- initialView,
176
- // Server-side model
177
- manualSorting = false,
178
- manualFiltering = false,
179
- manualPagination = false,
180
- rowCount,
181
- pageCount,
182
- onServerChange,
183
- // Loading
184
- loading = false,
185
- loadingRows,
186
- // Virtualization
187
- enableRowVirtualization = false,
188
- estimateRowHeight = 40,
189
- overscan = 8,
190
- maxBodyHeight = "32rem",
191
- zebra = true,
192
- // Row drag-reorder (#13)
193
- enableRowReorder = false,
194
- onRowReorder,
195
- rowReorderHandle = "cell",
196
- onRowClick,
197
- rowActionLabel,
198
- rowClassName,
199
- caption,
200
- emptyMessage = "No results.",
201
- className,
202
- ...rest
203
- }, ref) {
204
- const { t, dir, formatNumber } = useLocale();
205
- const isSortingControlled = sortingProp !== void 0;
206
- const isColumnVisibilityControlled = columnVisibilityProp !== void 0;
207
- const isColumnFiltersControlled = columnFiltersProp !== void 0;
208
- const isPaginationControlled = paginationProp !== void 0;
209
- const isFilterControlled = globalFilterProp !== void 0;
210
- const isColumnPinningControlled = columnPinningProp !== void 0;
211
- const isColumnSizingControlled = columnSizingProp !== void 0;
212
- const isRowSelectionControlled = rowSelectionProp !== void 0;
213
- const [internalSorting, setInternalSorting] = useState(
214
- () => initialView?.sorting ?? []
215
- );
216
- const [internalColumnVisibility, setInternalColumnVisibility] = useState(
217
- () => initialView?.columnVisibility ?? {}
218
- );
219
- const [internalColumnFilters, setInternalColumnFilters] = useState(
220
- () => initialView?.columnFilters ?? []
221
- );
222
- const [internalPagination, setInternalPagination] = useState(
223
- () => initialView?.pagination ?? {
224
- pageIndex: 0,
225
- pageSize
226
- }
227
- );
228
- const [internalGlobalFilter, setInternalGlobalFilter] = useState(
229
- () => initialView?.globalFilter ?? ""
230
- );
231
- const [internalColumnPinning, setInternalColumnPinning] = useState(
232
- () => initialView?.columnPinning ?? { left: [], right: [] }
233
- );
234
- const [internalColumnSizing, setInternalColumnSizing] = useState(
235
- () => initialView?.columnSizing ?? {}
236
- );
237
- const [internalRowSelection, setInternalRowSelection] = useState(
238
- () => initialView?.rowSelection ?? {}
239
- );
240
- const sorting = isSortingControlled ? sortingProp : internalSorting;
241
- const columnVisibility = isColumnVisibilityControlled ? columnVisibilityProp : internalColumnVisibility;
242
- const columnFilters = isColumnFiltersControlled ? columnFiltersProp : internalColumnFilters;
243
- const pagination = isPaginationControlled ? paginationProp : internalPagination;
244
- const globalFilter = isFilterControlled ? globalFilterProp : internalGlobalFilter;
245
- const columnPinning = isColumnPinningControlled ? columnPinningProp : internalColumnPinning;
246
- const columnSizing = isColumnSizingControlled ? columnSizingProp : internalColumnSizing;
247
- const rowSelection = isRowSelectionControlled ? rowSelectionProp : internalRowSelection;
248
- const sortingRef = useRef(sorting);
249
- sortingRef.current = sorting;
250
- const columnFiltersRef = useRef(columnFilters);
251
- columnFiltersRef.current = columnFilters;
252
- const paginationRef = useRef(pagination);
253
- paginationRef.current = pagination;
254
- const globalFilterRef = useRef(globalFilter);
255
- globalFilterRef.current = globalFilter;
256
- const columnVisibilityRef = useRef(columnVisibility);
257
- columnVisibilityRef.current = columnVisibility;
258
- const columnPinningRef = useRef(columnPinning);
259
- columnPinningRef.current = columnPinning;
260
- const columnSizingRef = useRef(columnSizing);
261
- columnSizingRef.current = columnSizing;
262
- const rowSelectionRef = useRef(rowSelection);
263
- rowSelectionRef.current = rowSelection;
264
- const warnedMissingRowCountRef = useRef(false);
265
- useEffect(() => {
266
- if (process.env.NODE_ENV !== "production" && manualPagination && rowCount === void 0 && pageCount === void 0 && !warnedMissingRowCountRef.current) {
267
- warnedMissingRowCountRef.current = true;
268
- console.warn(
269
- '[DataTable] `manualPagination` is true but neither `rowCount` nor `pageCount` was provided \u2014 the pager will appear stuck ("Page 1 of 1", Next disabled). Pass `rowCount` (or `pageCount`) so the pager can compute the total.'
270
- );
271
- }
272
- }, [manualPagination, rowCount, pageCount]);
273
- const warnedManualSelectionRef = useRef(false);
274
- useEffect(() => {
275
- if (process.env.NODE_ENV !== "production" && manualPagination && getRowId === void 0 && (isRowSelectionControlled || onRowSelectionChangeProp !== void 0) && !warnedManualSelectionRef.current) {
276
- warnedManualSelectionRef.current = true;
277
- console.warn(
278
- '[DataTable] `rowSelection` is wired up under `manualPagination` with no `getRowId` \u2014 each page is a fresh `data` array, so the default index-based id restarts at "0" per page and a selection made on one page can silently apply to a different record on the next. Pass `getRowId` so selection is keyed to a stable identity instead of position.'
279
- );
280
- }
281
- }, [manualPagination, getRowId, isRowSelectionControlled, onRowSelectionChangeProp]);
282
- const warnedReorderSortingRef = useRef(false);
283
- useEffect(() => {
284
- if (process.env.NODE_ENV !== "production" && enableRowReorder && sorting.length > 0 && !warnedReorderSortingRef.current) {
285
- warnedReorderSortingRef.current = true;
286
- console.warn(
287
- "[DataTable] `enableRowReorder` is set while a column is sorted \u2014 the sort will keep re-ordering rows out from under a manual drag. Clear `sorting` (or avoid enabling both at once) so a drag's new order stays stable."
288
- );
289
- }
290
- }, [enableRowReorder, sorting.length]);
291
- const warnedReorderVirtualizedRef = useRef(false);
292
- useEffect(() => {
293
- if (process.env.NODE_ENV !== "production" && enableRowReorder && enableRowVirtualization && !warnedReorderVirtualizedRef.current) {
294
- warnedReorderVirtualizedRef.current = true;
295
- console.warn(
296
- "[DataTable] `enableRowReorder` has no effect while `enableRowVirtualization` is set \u2014 the two are mutually exclusive. Virtualization wins; row reorder is disabled."
297
- );
298
- }
299
- }, [enableRowReorder, enableRowVirtualization]);
300
- const rowReorderActive = enableRowReorder && !enableRowVirtualization;
301
- const hasGripColumn = rowReorderActive && rowReorderHandle === "cell";
302
- const reorderSensors = useSensors(
303
- useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),
304
- useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
305
- );
306
- const reorderIdentityMapRef = useRef(/* @__PURE__ */ new WeakMap());
307
- const reorderIdentityCounterRef = useRef(0);
308
- const reorderRepeatedPositions = useMemo(() => {
309
- const repeats = /* @__PURE__ */ new Set();
310
- if (!rowReorderActive) return repeats;
311
- const seen = /* @__PURE__ */ new Set();
312
- data.forEach((record, index) => {
313
- if (record === null || typeof record !== "object") return;
314
- if (seen.has(record)) repeats.add(index);
315
- else seen.add(record);
316
- });
317
- return repeats;
318
- }, [data, rowReorderActive]);
319
- const [reorderLiveMessage, setReorderLiveMessage] = useState("");
320
- const reorderLastAnnouncedPositionRef = useRef(null);
321
- function fireServerChange(overrides = {}) {
322
- if (!onServerChange) return;
323
- onServerChange({
324
- pagination: paginationRef.current,
325
- sorting: sortingRef.current,
326
- columnFilters: columnFiltersRef.current,
327
- globalFilter: globalFilterRef.current,
328
- ...overrides
329
- });
330
- }
331
- function resolveSorting(updater) {
332
- return typeof updater === "function" ? updater(sortingRef.current) : updater;
333
- }
334
- function resolveColumnVisibility(updater) {
335
- return typeof updater === "function" ? updater(columnVisibilityRef.current) : updater;
336
- }
337
- function resolveColumnFilters(updater) {
338
- return typeof updater === "function" ? updater(columnFiltersRef.current) : updater;
339
- }
340
- function resolvePagination(updater) {
341
- return typeof updater === "function" ? updater(paginationRef.current) : updater;
342
- }
343
- function resolveGlobalFilter(updater) {
344
- return typeof updater === "function" ? updater(globalFilterRef.current) : updater;
345
- }
346
- function resolveColumnPinning(updater) {
347
- return typeof updater === "function" ? updater(columnPinningRef.current) : updater;
348
- }
349
- function resolveColumnSizing(updater) {
350
- return typeof updater === "function" ? updater(columnSizingRef.current) : updater;
351
- }
352
- function resolveRowSelection(updater) {
353
- return typeof updater === "function" ? updater(rowSelectionRef.current) : updater;
354
- }
355
- const sortedRowModel = manualSorting ? {} : { getSortedRowModel: getSortedRowModel() };
356
- const filteredRowModel = manualFiltering ? {} : { getFilteredRowModel: getFilteredRowModel() };
357
- const paginationRowModel = enablePagination && !manualPagination ? { getPaginationRowModel: getPaginationRowModel() } : {};
358
- const table = useReactTable({
359
- data,
360
- columns,
361
- state: {
362
- sorting,
363
- columnVisibility,
364
- columnFilters,
365
- globalFilter,
366
- pagination,
367
- columnPinning,
368
- columnSizing,
369
- rowSelection
370
- },
371
- // Sorting
372
- onSortingChange: (updater) => {
373
- const next = resolveSorting(updater);
374
- if (!isSortingControlled) setInternalSorting(next);
375
- onSortingChangeProp?.(updater);
376
- if (manualSorting) {
377
- sortingRef.current = next;
378
- fireServerChange({ sorting: next });
379
- }
380
- },
381
- // Column visibility
382
- onColumnVisibilityChange: (updater) => {
383
- const next = resolveColumnVisibility(updater);
384
- if (!isColumnVisibilityControlled) setInternalColumnVisibility(next);
385
- onColumnVisibilityChangeProp?.(updater);
386
- },
387
- // Column filters
388
- onColumnFiltersChange: (updater) => {
389
- const next = resolveColumnFilters(updater);
390
- if (!isColumnFiltersControlled) setInternalColumnFilters(next);
391
- onColumnFiltersChangeProp?.(updater);
392
- if (manualFiltering) {
393
- columnFiltersRef.current = next;
394
- fireServerChange({ columnFilters: next });
395
- }
396
- },
397
- // Global filter
398
- onGlobalFilterChange: (updater) => {
399
- const next = resolveGlobalFilter(updater);
400
- if (!isFilterControlled) setInternalGlobalFilter(next);
401
- onGlobalFilterChange?.(next);
402
- if (manualFiltering) {
403
- globalFilterRef.current = next;
404
- fireServerChange({ globalFilter: next });
405
- }
406
- },
407
- // Pagination
408
- onPaginationChange: (updater) => {
409
- const next = resolvePagination(updater);
410
- if (!isPaginationControlled) setInternalPagination(next);
411
- onPaginationChangeProp?.(updater);
412
- if (manualPagination) {
413
- paginationRef.current = next;
414
- fireServerChange({ pagination: next });
415
- }
416
- },
417
- // Column pinning — a LAYOUT slice, so unlike sorting/filtering/pagination it
418
- // never fires `onServerChange`: freezing a column changes nothing the server
419
- // would need to re-query.
420
- onColumnPinningChange: (updater) => {
421
- const next = resolveColumnPinning(updater);
422
- if (!isColumnPinningControlled) setInternalColumnPinning(next);
423
- onColumnPinningChangeProp?.(updater);
424
- },
425
- // Column resizing (#12) — a LAYOUT slice, like column pinning: a column's
426
- // width changes nothing the server would need to re-query, so this never
427
- // fires onServerChange either. Routed through by BOTH the pointer path
428
- // (TanStack's own `header.getResizeHandler()`, wired below) and the
429
- // keyboard path (`handleResizeKeyDown`, via `table.setColumnSizing`) so
430
- // the two input modes can never diverge in controlled/uncontrolled
431
- // behaviour.
432
- columnResizeMode,
433
- // RTL fix (#12 review, P1): TanStack's pointer-drag math hardcodes LTR
434
- // unless told otherwise — `deltaDirection = columnResizeDirection ===
435
- // 'rtl' ? -1 : 1` internally — so under `dir="rtl"` (the resize handle's
436
- // own edge already flips via `end-0`, see the `useLocale()` call above)
437
- // dragging would otherwise move the column's width opposite the visible
438
- // boundary. `handleResizeKeyDown` below mirrors this for the keyboard path.
439
- columnResizeDirection: dir,
440
- enableColumnResizing,
441
- onColumnSizingChange: (updater) => {
442
- const next = resolveColumnSizing(updater);
443
- if (!isColumnSizingControlled) setInternalColumnSizing(next);
444
- onColumnSizingChangeProp?.(updater);
445
- },
446
- // Row selection (#11) — also a LAYOUT/UI slice, so it never fires
447
- // onServerChange: which rows are checked changes nothing the server
448
- // would need to re-query.
449
- onRowSelectionChange: (updater) => {
450
- const next = resolveRowSelection(updater);
451
- if (!isRowSelectionControlled) setInternalRowSelection(next);
452
- onRowSelectionChangeProp?.(updater);
453
- },
454
- enableRowSelection,
455
- enableMultiRowSelection,
456
- getRowId,
457
- getCoreRowModel: getCoreRowModel(),
458
- ...sortedRowModel,
459
- ...filteredRowModel,
460
- ...paginationRowModel,
461
- // Server-side options
462
- manualSorting,
463
- manualFiltering,
464
- manualPagination,
465
- ...rowCount !== void 0 ? { rowCount } : {},
466
- ...pageCount !== void 0 ? { pageCount } : {}
467
- // No `initialState`: every slice is driven explicitly via `state` above
468
- // (internal slices are seeded from `initialView` at useState init), so a
469
- // TanStack `initialState` would be dead/misleading.
470
- });
471
- const rows = table.getRowModel().rows;
472
- const colCount = table.getVisibleLeafColumns().length;
473
- const headerRowCount = table.getHeaderGroups().length;
474
- const ariaRowCount = (rowCount ?? rows.length) + headerRowCount;
475
- function reorderRowName(id) {
476
- const row = rows.find((r) => getReorderRowId(r) === id);
477
- return row ? rowActionName(row) : id;
478
- }
479
- function reorderPosition(id) {
480
- return rows.findIndex((r) => getReorderRowId(r) === id) + 1;
481
- }
482
- function getReorderRowId(row) {
483
- if (getRowId) return row.id;
484
- const original = row.original;
485
- if (original !== null && typeof original === "object") {
486
- const map = reorderIdentityMapRef.current;
487
- let id = map.get(original);
488
- if (id === void 0) {
489
- id = `__reorder-${reorderIdentityCounterRef.current++}`;
490
- map.set(original, id);
491
- }
492
- return reorderRepeatedPositions.has(row.index) ? `${id}__${row.index}` : id;
493
- }
494
- return row.id;
495
- }
496
- const silentDragAnnouncements = {
497
- onDragStart: () => void 0,
498
- onDragOver: () => void 0,
499
- onDragEnd: () => void 0,
500
- onDragCancel: () => void 0
501
- };
502
- function handleRowDragStart(event) {
503
- const activeRowId = String(event.active.id);
504
- reorderLastAnnouncedPositionRef.current = reorderPosition(activeRowId);
505
- setReorderLiveMessage(t("data.table.reorderPickedUp", { name: reorderRowName(activeRowId) }));
506
- }
507
- function handleRowDragOver(event) {
508
- const { active, over } = event;
509
- if (!over) return;
510
- const position = reorderPosition(String(over.id));
511
- if (position === reorderLastAnnouncedPositionRef.current) return;
512
- reorderLastAnnouncedPositionRef.current = position;
513
- setReorderLiveMessage(
514
- t("data.table.reorderMoved", {
515
- name: reorderRowName(String(active.id)),
516
- position,
517
- total: rows.length
518
- })
519
- );
520
- }
521
- function handleRowDragCancel(event) {
522
- const activeRowId = String(event.active.id);
523
- setReorderLiveMessage(
524
- t("data.table.reorderCancelled", {
525
- name: reorderRowName(activeRowId),
526
- position: reorderPosition(activeRowId),
527
- total: rows.length
528
- })
529
- );
530
- reorderLastAnnouncedPositionRef.current = null;
531
- }
532
- function handleRowDragEnd(event) {
533
- const { active, over } = event;
534
- const activeRowId = String(active.id);
535
- setReorderLiveMessage(
536
- t("data.table.reorderDropped", {
537
- name: reorderRowName(activeRowId),
538
- position: reorderPosition(String(over ? over.id : active.id)),
539
- total: rows.length
540
- })
541
- );
542
- reorderLastAnnouncedPositionRef.current = null;
543
- if (!over || active.id === over.id) return;
544
- const movedRow = rows.find((r) => getReorderRowId(r) === activeRowId);
545
- const targetRow = rows.find((r) => getReorderRowId(r) === String(over.id));
546
- if (!movedRow || !targetRow) return;
547
- const from = movedRow.index;
548
- const to = targetRow.index;
549
- if (from < 0 || from >= data.length || to < 0 || to >= data.length) return;
550
- onRowReorder?.(from, to, movedRow.original);
551
- }
552
- const hasLeftPinned = (columnPinning.left?.length ?? 0) > 0;
553
- const hasRightPinned = (columnPinning.right?.length ?? 0) > 0;
554
- const pinnedScrollPadding = {
555
- ...hasLeftPinned ? { scrollPaddingInlineStart: table.getLeftTotalSize() } : {},
556
- ...hasRightPinned ? { scrollPaddingInlineEnd: table.getRightTotalSize() } : {}
557
- };
558
- const warnedUnsizedPinnedRef = useRef(false);
559
- const pinnedIds = [...columnPinning.left ?? [], ...columnPinning.right ?? []];
560
- const unsizedIds = process.env.NODE_ENV === "production" || pinnedIds.length === 0 ? null : unsizedColumnIds(columns);
561
- const pinnedWithoutSizeKey = unsizedIds ? pinnedIds.filter((id) => unsizedIds.has(id)).join(",") : "";
562
- useEffect(() => {
563
- if (process.env.NODE_ENV !== "production" && pinnedWithoutSizeKey !== "" && !warnedUnsizedPinnedRef.current) {
564
- warnedUnsizedPinnedRef.current = true;
565
- console.warn(
566
- `[DataTable] Pinned column(s) without an explicit \`size\` in their \`ColumnDef\`: ${pinnedWithoutSizeKey}. Sticky offsets are computed from the declared sizes, so an auto-width pinned column will render at a width that doesn't match its own offset. Give every pinned column a \`size\`.`
567
- );
568
- }
569
- }, [pinnedWithoutSizeKey]);
570
- function pinnedCellGeometry(column) {
571
- const pinned = column.getIsPinned();
572
- if (pinned === false) return null;
573
- const size = column.getSize();
574
- const style = {
575
- width: size,
576
- minWidth: size,
577
- maxWidth: size,
578
- ...pinned === "left" ? { left: column.getStart("left") } : { right: column.getAfter("right") }
579
- };
580
- return {
581
- pinned,
582
- style,
583
- // The seam between the frozen block and the scrolling block is the SOLE
584
- // structural cue between two regions that share one row fill and one
585
- // zebra stripe — delete it and a sighted user cannot tell them apart — so
586
- // it takes the strong rung (ADR 0010 decision test). No shadow: ADR 0020's
587
- // `--shadow-strength: 0` (`data-decoration="8|9|10"`) would
588
- // erase a shadow-only cue entirely.
589
- //
590
- // It is drawn as a 1px `::after` INSIDE the cell, NOT as `border-e` /
591
- // `border-s`. A real border cannot work here: Tailwind's Preflight puts
592
- // the table in the COLLAPSED border model, and a collapsed border is
593
- // painted by the <table> at the cell's STATIC position — it does not
594
- // travel with a `position: sticky` cell, and the cell's own opaque fill
595
- // (which it needs, see `pinnedCellFillClass`) then paints over it. Measured
596
- // in Chromium on `Data/DataTable → PinnedColumns`: with `border-e` the
597
- // seam pixel read `143,143,143` (light `--border-strong`) at
598
- // scrollLeft 0 and `245,245,245` (the plain cell fill — i.e. GONE) once
599
- // scrolled, in every theme and on both edges. So the one cue vanished
600
- // exactly when the freeze was doing something. The `::after` lives in the
601
- // sticky cell's own stacking context, so it moves with it.
602
- edgeClass: pinned === "left" ? column.getIsLastColumn("left") ? PINNED_SEAM_CLASS + " after:end-0" : "" : column.getIsFirstColumn("right") ? PINNED_SEAM_CLASS + " after:start-0" : ""
603
- };
604
- }
605
- const RESIZE_STEP = 10;
606
- const RESIZE_UNBOUNDED_ARIA_MAX = 2e3;
607
- function handleResizeKeyDown(event, column) {
608
- let delta = 0;
609
- if (event.key === "ArrowRight") delta = RESIZE_STEP;
610
- else if (event.key === "ArrowLeft") delta = -RESIZE_STEP;
611
- else return;
612
- event.preventDefault();
613
- if (dir === "rtl") delta = -delta;
614
- const minSize = column.columnDef.minSize ?? 20;
615
- const maxSize = column.columnDef.maxSize ?? Number.MAX_SAFE_INTEGER;
616
- const nextSize = Math.min(maxSize, Math.max(minSize, column.getSize() + delta));
617
- table.setColumnSizing((old) => ({ ...old, [column.id]: nextSize }));
618
- }
619
- function handleResizeDoubleClick(column) {
620
- table.setColumnSizing((old) => {
621
- if (!(column.id in old)) return old;
622
- const { [column.id]: _removed, ...rest2 } = old;
623
- return rest2;
624
- });
625
- }
626
- const scrollRef = useRef(null);
627
- const virtualizer = useVirtualizer({
628
- count: enableRowVirtualization ? rows.length : 0,
629
- getScrollElement: () => enableRowVirtualization ? scrollRef.current : null,
630
- estimateSize: () => estimateRowHeight,
631
- overscan,
632
- enabled: enableRowVirtualization
633
- });
634
- const virtualItems = enableRowVirtualization ? virtualizer.getVirtualItems() : [];
635
- const totalSize = enableRowVirtualization ? virtualizer.getTotalSize() : 0;
636
- const paddingTop = virtualItems.length > 0 ? virtualItems[0]?.start ?? 0 : 0;
637
- const paddingBottom = totalSize > 0 ? totalSize - (virtualItems[virtualItems.length - 1]?.end ?? 0) : 0;
638
- const plainScrollRef = useRef(null);
639
- const [scrollOverflows, setScrollOverflows] = useState(false);
640
- const [canScrollLeft, setCanScrollLeft] = useState(false);
641
- const [canScrollRight, setCanScrollRight] = useState(false);
642
- const updateScrollAffordance = useCallback(() => {
643
- const el = plainScrollRef.current;
644
- if (!el) return;
645
- setScrollOverflows(
646
- el.scrollWidth > el.clientWidth + 1 || el.scrollHeight > el.clientHeight + 1
647
- );
648
- setCanScrollLeft(el.scrollLeft > 0);
649
- setCanScrollRight(el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
650
- }, []);
651
- useEffect(() => {
652
- const el = plainScrollRef.current;
653
- if (!el) return;
654
- updateScrollAffordance();
655
- if (typeof ResizeObserver === "undefined") return;
656
- const observer = new ResizeObserver(updateScrollAffordance);
657
- observer.observe(el);
658
- if (el.firstElementChild) observer.observe(el.firstElementChild);
659
- return () => observer.disconnect();
660
- }, [updateScrollAffordance, colCount, rows.length]);
661
- const showEmpty = !loading && rows.length === 0;
662
- const showSkeletons = loading && rows.length === 0;
663
- const skeletonRowCount = loadingRows ?? pageSize;
664
- function renderThead(sticky, withRowIndex = false) {
665
- return /* @__PURE__ */ jsx(
666
- "thead",
667
- {
668
- className: cn(
669
- // #173: header bottom is the only cue between header and first data row → border-strong
670
- "border-b border-border-strong",
671
- // A sticky header scrolls OVER the body, so its fill must be opaque or data
672
- // rows bleed through the labels; the non-sticky header keeps the /60 wash.
673
- // z-20 (raised from z-10 for #333) puts the header row above the pinned
674
- // body cells (z-10) and below the pinned header corner (z-30). No visual
675
- // delta: nothing else in the table sits between those rungs.
676
- sticky ? "sticky top-0 z-20 bg-surface-muted" : "bg-surface-muted/60"
677
- ),
678
- children: table.getHeaderGroups().map((headerGroup, groupIndex) => /* @__PURE__ */ jsxs("tr", { "aria-rowindex": withRowIndex ? groupIndex + 1 : void 0, children: [
679
- hasGripColumn && /* @__PURE__ */ jsx("th", { scope: "col", className: "h-10 w-10 px-3 align-middle", children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("data.table.reorderColumnHeader") }) }, "__reorder"),
680
- headerGroup.headers.map((header) => {
681
- const geometry = pinnedCellGeometry(header.column);
682
- const canSort = header.column.getCanSort();
683
- const sorted = header.column.getIsSorted();
684
- const headerLabel = typeof header.column.columnDef.header === "string" ? header.column.columnDef.header : header.column.id;
685
- const sortStateLabel = sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : "not sorted";
686
- const SortIcon = sorted === "asc" ? ArrowUp : sorted === "desc" ? ArrowDown : ArrowUpDown;
687
- const resizeStyle = enableColumnResizing ? resizeWidthStyle(header.getSize()) : void 0;
688
- const canResize = enableColumnResizing && !header.isPlaceholder && header.column.getCanResize();
689
- const resizeMax = header.column.columnDef.maxSize;
690
- return /* @__PURE__ */ jsxs(
691
- "th",
692
- {
693
- scope: "col",
694
- "aria-sort": canSort ? sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : "none" : void 0,
695
- "data-pinned": geometry?.pinned ?? void 0,
696
- style: geometry?.style ?? resizeStyle,
697
- className: cn(
698
- // Same `px-3` the body `<td>` uses (below) — deliberately
699
- // NOT split into `ps-3`/`pe-3` for a resize-handle
700
- // override (round-1 briefly did this, see the round-2
701
- // note on `numericColumnClasses`): the header's padding
702
- // must stay byte-identical to the body's so an
703
- // end-aligned numeric column's header lines up with its
704
- // own values.
705
- "h-10 px-3 text-start align-middle font-medium text-muted-foreground",
706
- // #69: a numeric column's `meta` overrides the default
707
- // `text-start` — placed right after the base string so
708
- // tailwind-merge lets it win over that default.
709
- numericColumnClasses(header.column.columnDef.meta),
710
- // `sticky`/pinned already establishes a positioning context
711
- // for the resize handle's `absolute`; an unpinned resizable
712
- // header needs its own.
713
- !geometry && canResize && "relative",
714
- // A pinned HEADER cell is the corner where both freezes meet,
715
- // so it stacks above the sticky header row (z-20) which is
716
- // above the pinned body cells (z-10). It needs an OPAQUE
717
- // fill (scrolled header cells pass underneath it), and that
718
- // fill has to composite to exactly what its unpinned
719
- // neighbours show — same problem, same two-layer answer as
720
- // `pinnedCellFillClass`:
721
- // sticky branch → the row is already opaque `surface-muted`, so match it.
722
- // plain branch → the row is `surface-muted/60` over the
723
- // container's `card`, so paint `card` and
724
- // re-apply the /60 wash on `::before`.
725
- // Painting the plain branch's corner solid `surface-muted`
726
- // read 4-5/255 darker than the header beside it in every
727
- // theme (measured: 242 vs 247 light, 43 vs 40
728
- // dark) — the same "floating pill"
729
- // artefact #333 was filed about, moved into the header.
730
- geometry && "sticky z-30",
731
- geometry && (sticky ? "bg-surface-muted" : "bg-card before:pointer-events-none before:absolute before:inset-0 before:-z-10 before:bg-surface-muted/60 before:content-['']"),
732
- // Separate cn() argument on purpose: the seam is the sole
733
- // structural cue between the frozen and scrolling blocks, so
734
- // it must not read as a "boundary + fill in one class string"
735
- // redundancy (separation:check).
736
- geometry?.edgeClass
737
- ),
738
- children: [
739
- header.isPlaceholder ? null : canSort ? /* @__PURE__ */ jsxs(
740
- "button",
741
- {
742
- type: "button",
743
- onClick: header.column.getToggleSortingHandler(),
744
- "aria-label": `Sort by ${headerLabel}, ${sortStateLabel}`,
745
- className: "relative z-10 inline-flex items-center gap-1 rounded-sm transition-colors duration-fast ease-standard hover:text-foreground focus-ring",
746
- children: [
747
- flexRender(header.column.columnDef.header, header.getContext()),
748
- /* @__PURE__ */ jsx(
749
- SortIcon,
750
- {
751
- "aria-hidden": "true",
752
- className: "size-3 shrink-0 transition-colors duration-fast ease-standard"
753
- }
754
- )
755
- ]
756
- }
757
- ) : flexRender(header.column.columnDef.header, header.getContext()),
758
- canResize && /* @__PURE__ */ jsx(
759
- "div",
760
- {
761
- role: "separator",
762
- "aria-orientation": "vertical",
763
- "aria-valuenow": Math.round(header.getSize()),
764
- "aria-valuemin": header.column.columnDef.minSize,
765
- "aria-valuemax": resizeMax !== void 0 && resizeMax < Number.MAX_SAFE_INTEGER ? resizeMax : Math.max(header.getSize(), RESIZE_UNBOUNDED_ARIA_MAX),
766
- "aria-valuetext": t("data.table.resizeColumnValue", {
767
- count: Math.round(header.getSize()),
768
- size: formatNumber(Math.round(header.getSize()))
769
- }),
770
- "aria-label": t("data.table.resizeColumn", { name: headerLabel }),
771
- tabIndex: 0,
772
- "data-slot": "data-table-resize-handle",
773
- onMouseDown: header.getResizeHandler(),
774
- onTouchStart: header.getResizeHandler(),
775
- onKeyDown: (event) => handleResizeKeyDown(event, header.column),
776
- onDoubleClick: () => handleResizeDoubleClick(header.column),
777
- className: cn(
778
- // #51: the hit box is a literal 24px (clamped to half
779
- // the header cell so it can never overlap a neighbour,
780
- // even at `minSize=20`) rather than the `w-2` Tailwind
781
- // spacing-scale utility. `w-2` compiles to
782
- // `calc(var(--spacing) * 2)`, and `--spacing` is what
783
- // `data-density="compact"` rescales — so the old 8px
784
- // hit box shrank further under compact density
785
- // (~7.1px). A literal px value is density-independent
786
- // by construction, which is the actual defect the
787
- // maintainer's review corrected (NOT `--type-factor`,
788
- // which this handle never used). Do not widen via
789
- // overhang into the neighbouring cell instead — on the
790
- // last column that lands inside the `overflow-auto`
791
- // box (#330 false positive) and a pinned neighbour
792
- // paints over/hit-tests away the extra area.
793
- "absolute inset-y-0 end-0 w-[min(24px,50%)] cursor-col-resize touch-none select-none",
794
- // #51: the focus ring moves to the `after:` pseudo-
795
- // element (the drawn seam) rather than the box itself
796
- // — the box is now a 24px hit target, and a 24px focus
797
- // rectangle would replace the deliberately slim ring
798
- // already reviewed/approved as the #12 a11y fix
799
- // (da9b29e). `focus-visible:after:*` targets the
800
- // pseudo-element the same way `hover:after:w-2` /
801
- // `focus-visible:after:w-2` below already do.
802
- "focus-visible:outline-none",
803
- // a11y fix (#12 review, blocking): this handle is the
804
- // SOLE boundary between two adjacent header cells once
805
- // resizing is on — no fill/elevation change separates
806
- // them otherwise — so per the border/border-strong
807
- // decision test (styling-and-tokens.md) it needs a
808
- // rung that clears WCAG 1.4.11's 3:1 on its OWN, in
809
- // EVERY state, including rest (a control with no
810
- // affordance until hover is unusable without a
811
- // pointer). `border-strong` measures only 2.86-2.96:1
812
- // against this `bg-surface-muted` header — that rung
813
- // is guaranteed only vs `--card`/`--background`, not a
814
- // same-tone surface, which is the exact trap the rule
815
- // warns about. `muted-foreground` is guaranteed AA
816
- // text contrast against `--surface-muted`
817
- // (TEXT_SURFACES), so it clears the 3:1 non-text
818
- // minimum with wide margin (measured ~5.3-6.4:1 in
819
- // both themes, unaffected by density) and is already
820
- // the header's own label color. A slim persistent
821
- // `after:` seam (not just a hover reveal) gives the
822
- // real resting boundary; hover/focus widen the drawn
823
- // seam to 8px (`after:w-2`) using the same compliant
824
- // color — a separate width from the 24px pointer hit
825
- // box below (#51), which the seam does not fill.
826
- // Dragging keeps the pre-existing full-fill
827
- // `bg-primary` treatment — that is a drag AFFORDANCE,
828
- // not a focus indicator, and it is redundant with the
829
- // pointer capture, so it is out of scope here. The
830
- // keyboard focus indicator on both branches is the
831
- // shared compound one (#67), applied to the drawn seam
832
- // via `focus-visible:after:focus-ring-static`: the
833
- // element itself is a 24px transparent hit box, so
834
- // ringing IT would ring nothing a user can see.
835
- header.column.getIsResizing() ? "after:absolute after:inset-y-0 after:end-0 after:w-2 after:bg-primary after:content-[''] focus-visible:after:focus-ring-static" : "after:absolute after:inset-y-0 after:end-0 after:w-px after:bg-muted-foreground after:content-[''] hover:after:w-2 focus-visible:after:w-2 focus-visible:after:focus-ring-static"
836
- )
837
- }
838
- )
839
- ]
840
- },
841
- header.id
842
- );
843
- })
844
- ] }, headerGroup.id))
845
- }
846
- );
847
- }
848
- function rowSeparationClass(rowIndex) {
849
- if (!zebra) return "border-b border-border-strong last:border-b-0";
850
- return rowIndex % 2 === 1 ? "bg-foreground/5" : "";
851
- }
852
- function pinnedCellFillClass(rowIndex) {
853
- return cn(
854
- "bg-card",
855
- "before:pointer-events-none before:absolute before:inset-0 before:-z-10 before:content-['']",
856
- zebra && rowIndex % 2 === 1 && "before:bg-foreground/5",
857
- "group-hover/row:before:bg-foreground/10",
858
- "group-data-[state=selected]/row:before:bg-accent"
859
- );
860
- }
861
- function rowActionName(row) {
862
- const explicit = rowActionLabel?.(row);
863
- if (explicit) return explicit;
864
- const name = firstDataCellValue(row);
865
- if (name !== void 0) return name;
866
- return t("data.table.rowAction");
867
- }
868
- function renderRow(row, rowIndex, extras, dragHandle) {
869
- const clickable = Boolean(onRowClick);
870
- function handleRowClick(event) {
871
- if (isInteractiveEventTarget(event.target)) return;
872
- if (isActiveTextSelection()) return;
873
- onRowClick?.(row, event);
874
- }
875
- return /* @__PURE__ */ jsxs(
876
- "tr",
877
- {
878
- "data-state": row.getIsSelected() ? "selected" : void 0,
879
- onClick: clickable ? handleRowClick : void 0,
880
- className: cn(
881
- // Color-only feedback (no transform/movement) → per
882
- // docs/MOTION_GUIDELINES.md item 3 this stays under OS reduced-motion
883
- // (only movement is neutralized); the gated duration-fast/ease-standard
884
- // pair already collapses toward ~0ms via --motion-factor when the user
885
- // or OS asks for reduced motion, matching the header sort button.
886
- "transition-colors duration-fast ease-standard hover:bg-foreground/10 data-[state=selected]:bg-accent",
887
- // #13: the dragged row's live `transform` (set inline via `extras.style`,
888
- // see `SortableDataRow`) is what actually MOVES it — this class only
889
- // makes that movement glide instead of snapping, through the gated
890
- // duration/ease utilities (never a raw ms/ease value —
891
- // quality-gates.md "Motion-tokened") with a reduced-motion
892
- // neutralizer. Raising the dragged row's stacking + opacity is a
893
- // colour/composite-only cue, so it isn't gated by the same rule.
894
- dragHandle && "relative transition-transform duration-base ease-standard motion-reduce:transition-none",
895
- dragHandle?.isDragging && "z-20 opacity-90 shadow-md",
896
- // Named group (#333) so a PINNED cell can re-apply the row's hover /
897
- // selected wash on top of its own opaque fill — only CSS knows the
898
- // pointer is over a sibling cell. Purely a selector hook: `group/row`
899
- // emits no style of its own.
900
- "group/row",
901
- rowSeparationClass(rowIndex),
902
- // `<tr>` isn't in the global auto-cursor-pointer role list (button/
903
- // menuitem/tab/…), so a clickable row needs its own cursor. The focus
904
- // ring is driven off the hidden button's `:focus-visible` (same
905
- // `has-[[data-slot=…]:focus-visible]` pattern as InputGroup) so the
906
- // ring paints on the ROW the user is about to activate, even though
907
- // focus lives on the sr-only control inside it.
908
- clickable && "cursor-pointer has-[[data-slot=data-table-row-action]:focus-visible]:focus-ring-static-inset",
909
- rowClassName?.(row)
910
- ),
911
- ...extras,
912
- children: [
913
- dragHandle?.activator && /* @__PURE__ */ jsx("td", { className: "w-10 px-3 py-2 align-middle", children: /* @__PURE__ */ jsx(
914
- "button",
915
- {
916
- type: "button",
917
- ref: dragHandle.activator.setActivatorNodeRef,
918
- "data-slot": "data-table-row-drag-handle",
919
- "aria-label": t("data.table.reorderHandle", { name: rowActionName(row) }),
920
- className: cn(
921
- "inline-flex size-7 cursor-grab items-center justify-center rounded-sm text-muted-foreground transition-colors duration-fast ease-standard hover:bg-foreground/10 hover:text-foreground focus-ring active:cursor-grabbing",
922
- dragHandle.isDragging && "text-foreground"
923
- ),
924
- ...dragHandle.activator.attributes,
925
- ...dragHandle.activator.listeners,
926
- children: /* @__PURE__ */ jsx(GripVertical, { "aria-hidden": "true", className: "size-4" })
927
- }
928
- ) }),
929
- row.getVisibleCells().map((cell, cellIndex) => {
930
- const geometry = pinnedCellGeometry(cell.column);
931
- const resizeStyle = enableColumnResizing ? resizeWidthStyle(cell.column.getSize()) : void 0;
932
- return /* @__PURE__ */ jsxs(
933
- "td",
934
- {
935
- "data-pinned": geometry?.pinned ?? void 0,
936
- style: geometry?.style ?? resizeStyle,
937
- className: cn(
938
- "px-3 py-2 align-middle",
939
- // #69: same numeric-column seam as the header — see
940
- // `numericColumnClasses`.
941
- numericColumnClasses(cell.column.columnDef.meta),
942
- // z-10: above the normal (unpositioned) cells it scrolls over,
943
- // below the sticky header row (z-20) and the pinned corner (z-30).
944
- geometry && "sticky z-10",
945
- geometry && pinnedCellFillClass(rowIndex),
946
- // Separate cn() argument — see pinnedCellGeometry's edgeClass.
947
- geometry?.edgeClass
948
- ),
949
- children: [
950
- clickable && cellIndex === 0 && /* @__PURE__ */ jsx(
951
- "button",
952
- {
953
- type: "button",
954
- "data-slot": "data-table-row-action",
955
- className: "sr-only focus-visible:outline-none",
956
- onClick: (event) => onRowClick?.(row, event),
957
- children: rowActionName(row)
958
- }
959
- ),
960
- flexRender(cell.column.columnDef.cell, cell.getContext())
961
- ]
962
- },
963
- cell.id
964
- );
965
- })
966
- ]
967
- },
968
- row.id
969
- );
970
- }
971
- function renderSkeletonBody(count) {
972
- const visibleColumns = table.getVisibleLeafColumns();
973
- return Array.from({ length: count }).map((_, i) => /* @__PURE__ */ jsxs("tr", { "aria-hidden": "true", className: rowSeparationClass(i), children: [
974
- hasGripColumn && /* @__PURE__ */ jsx("td", { className: "w-10 px-3 py-2 align-middle", children: /* @__PURE__ */ jsx(Skeleton, { className: "size-4" }) }),
975
- visibleColumns.map((column) => /* @__PURE__ */ jsx(
976
- "td",
977
- {
978
- className: cn("px-3 py-2 align-middle", numericColumnClasses(column.columnDef.meta)),
979
- children: /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full" })
980
- },
981
- column.id
982
- ))
983
- ] }, `skeleton-${i}`));
984
- }
985
- function renderEmptyBody() {
986
- return /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx(
987
- "td",
988
- {
989
- colSpan: colCount + (hasGripColumn ? 1 : 0),
990
- className: "h-24 px-3 text-center text-muted-foreground",
991
- children: emptyMessage
992
- }
993
- ) });
994
- }
995
- function renderTbodyNormal() {
996
- if (showSkeletons) {
997
- return /* @__PURE__ */ jsx("tbody", { children: renderSkeletonBody(skeletonRowCount) });
998
- }
999
- if (showEmpty) {
1000
- return /* @__PURE__ */ jsx("tbody", { children: renderEmptyBody() });
1001
- }
1002
- if (!rowReorderActive) {
1003
- return /* @__PURE__ */ jsx("tbody", { children: rows.map((row, i) => renderRow(row, i)) });
1004
- }
1005
- return /* @__PURE__ */ jsx(
1006
- SortableContext,
1007
- {
1008
- items: rows.map((r) => getReorderRowId(r)),
1009
- strategy: verticalListSortingStrategy,
1010
- children: /* @__PURE__ */ jsx("tbody", { children: rows.map((row, i) => /* @__PURE__ */ jsx(
1011
- SortableDataRow,
1012
- {
1013
- id: getReorderRowId(row),
1014
- attributesOverride: {
1015
- // #98: dnd-kit's own `roleDescription: 'sortable'` default is
1016
- // hardcoded English; override it with the localized value in
1017
- // BOTH handle modes — `role` stays row-mode-only (see the
1018
- // `attributesOverride` prop doc above).
1019
- roleDescription: t("data.table.reorderRoleDescription"),
1020
- ...rowReorderHandle === "row" ? { role: "row" } : null
1021
- },
1022
- children: ({ setNodeRef, setActivatorNodeRef, attributes, listeners, isDragging, style }) => renderRow(
1023
- row,
1024
- i,
1025
- {
1026
- ref: setNodeRef,
1027
- style,
1028
- // `aria-pressed` is a `DraggableAttributes` field meant for a
1029
- // real `<button>` activator; spread onto a `<tr role="row">`
1030
- // (row-handle mode) it fails axe's `aria-allowed-attr` (that
1031
- // ARIA state is not permitted on the `row` role), so strip it
1032
- // here rather than exempt it downstream.
1033
- ...rowReorderHandle === "row" ? (() => {
1034
- const { "aria-pressed": _ariaPressed, ...rowAttributes } = attributes;
1035
- return { ...rowAttributes, ...listeners };
1036
- })() : {}
1037
- },
1038
- {
1039
- isDragging,
1040
- activator: rowReorderHandle === "cell" ? { setActivatorNodeRef, attributes, listeners } : void 0
1041
- }
1042
- )
1043
- },
1044
- getReorderRowId(row)
1045
- )) })
1046
- }
1047
- );
1048
- }
1049
- function renderTbodyVirtualized() {
1050
- if (showSkeletons) {
1051
- const virtualSkeletonCount = loadingRows ?? Math.min(10, pageSize);
1052
- return /* @__PURE__ */ jsx("tbody", { children: renderSkeletonBody(virtualSkeletonCount) });
1053
- }
1054
- return /* @__PURE__ */ jsx("tbody", { children: showEmpty ? renderEmptyBody() : /* @__PURE__ */ jsxs(Fragment, { children: [
1055
- paddingTop > 0 && /* @__PURE__ */ jsx("tr", { "aria-hidden": "true", children: /* @__PURE__ */ jsx("td", { style: { height: paddingTop }, colSpan: colCount }) }),
1056
- virtualItems.map((virtualRow) => {
1057
- const row = rows[virtualRow.index];
1058
- if (!row) return null;
1059
- return renderRow(row, virtualRow.index, {
1060
- ref: virtualizer.measureElement,
1061
- "data-index": virtualRow.index,
1062
- // Absolute 1-based row position; header row(s) occupy 1..headerRowCount.
1063
- "aria-rowindex": headerRowCount + virtualRow.index + 1
1064
- });
1065
- }),
1066
- paddingBottom > 0 && /* @__PURE__ */ jsx("tr", { "aria-hidden": "true", children: /* @__PURE__ */ jsx("td", { style: { height: paddingBottom }, colSpan: colCount }) })
1067
- ] }) });
1068
- }
1069
- function renderPagination() {
1070
- if (enableRowVirtualization) return null;
1071
- if (!enablePagination && !manualPagination) return null;
1072
- const pageCountUnknown = manualPagination && rowCount === void 0 && pageCount === void 0;
1073
- if (hidePaginationWhenSingle && !pageCountUnknown && table.getPageCount() <= 1) return null;
1074
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
1075
- /* @__PURE__ */ jsxs("p", { className: "text-body text-muted-foreground", children: [
1076
- "Page ",
1077
- table.getState().pagination.pageIndex + 1,
1078
- " of ",
1079
- table.getPageCount() || 1
1080
- ] }),
1081
- /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
1082
- /* @__PURE__ */ jsx(
1083
- Button,
1084
- {
1085
- variant: "outline",
1086
- size: "sm",
1087
- onClick: () => table.previousPage(),
1088
- disabled: !table.getCanPreviousPage(),
1089
- children: "Previous"
1090
- }
1091
- ),
1092
- /* @__PURE__ */ jsx(
1093
- Button,
1094
- {
1095
- variant: "outline",
1096
- size: "sm",
1097
- onClick: () => table.nextPage(),
1098
- disabled: !table.getCanNextPage(),
1099
- children: "Next"
1100
- }
1101
- )
1102
- ] })
1103
- ] });
1104
- }
1105
- const captionElement = caption != null ? /* @__PURE__ */ jsx("caption", { className: "sr-only", children: caption }) : null;
1106
- if (enableRowVirtualization) {
1107
- return /* @__PURE__ */ jsxs("div", { ref, className: cn("space-y-3", className), ...rest, children: [
1108
- toolbar ? toolbar(table) : null,
1109
- /* @__PURE__ */ jsxs(
1110
- "div",
1111
- {
1112
- ref: scrollRef,
1113
- tabIndex: 0,
1114
- "aria-label": t("data.table.scrollRegion"),
1115
- "aria-busy": loading || void 0,
1116
- className: "relative overflow-auto rounded-lg border bg-card focus-ring",
1117
- style: { maxHeight: maxBodyHeight, ...pinnedScrollPadding },
1118
- children: [
1119
- loading && rows.length > 0 && /* @__PURE__ */ jsxs(
1120
- "div",
1121
- {
1122
- role: "status",
1123
- "aria-live": "polite",
1124
- className: "absolute inset-0 z-40 flex items-center justify-center rounded-lg bg-card/80",
1125
- children: [
1126
- /* @__PURE__ */ jsx(Spinner, { "aria-hidden": "true", className: "text-foreground" }),
1127
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading table data\u2026" })
1128
- ]
1129
- }
1130
- ),
1131
- /* @__PURE__ */ jsxs(
1132
- "table",
1133
- {
1134
- "aria-busy": loading || void 0,
1135
- "aria-rowcount": ariaRowCount,
1136
- className: "w-full caption-bottom text-body",
1137
- children: [
1138
- captionElement,
1139
- renderThead(true, true),
1140
- renderTbodyVirtualized()
1141
- ]
1142
- }
1143
- )
1144
- ]
1145
- }
1146
- )
1147
- ] });
1148
- }
1149
- const nonVirtualizedContent = /* @__PURE__ */ jsxs("div", { ref, className: cn("space-y-3", className), ...rest, children: [
1150
- toolbar ? toolbar(table) : null,
1151
- /* @__PURE__ */ jsxs(
1152
- "div",
1153
- {
1154
- "aria-busy": loading || void 0,
1155
- className: "relative overflow-hidden rounded-lg border bg-card",
1156
- children: [
1157
- loading && rows.length > 0 && /* @__PURE__ */ jsxs(
1158
- "div",
1159
- {
1160
- role: "status",
1161
- "aria-live": "polite",
1162
- className: "absolute inset-0 z-40 flex items-center justify-center rounded-lg bg-card/80",
1163
- children: [
1164
- /* @__PURE__ */ jsx(Spinner, { "aria-hidden": "true", className: "text-foreground" }),
1165
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading table data\u2026" })
1166
- ]
1167
- }
1168
- ),
1169
- /* @__PURE__ */ jsx(
1170
- "div",
1171
- {
1172
- ref: plainScrollRef,
1173
- "data-slot": "data-table-scroll-region",
1174
- tabIndex: scrollOverflows ? 0 : void 0,
1175
- "aria-label": scrollOverflows ? t("data.table.scrollRegion") : void 0,
1176
- onScroll: updateScrollAffordance,
1177
- className: "overflow-auto rounded-lg focus-ring-inset",
1178
- style: hasLeftPinned || hasRightPinned ? pinnedScrollPadding : void 0,
1179
- children: /* @__PURE__ */ jsxs("table", { "aria-busy": loading || void 0, className: "w-full caption-bottom text-body", children: [
1180
- captionElement,
1181
- renderThead(false),
1182
- renderTbodyNormal()
1183
- ] })
1184
- }
1185
- ),
1186
- canScrollLeft && !hasLeftPinned && /* @__PURE__ */ jsx(
1187
- "div",
1188
- {
1189
- "aria-hidden": "true",
1190
- "data-slot": "data-table-scroll-fade-left",
1191
- className: "pointer-events-none absolute inset-y-0 left-0 z-10 w-8 rounded-lg bg-gradient-to-r from-card to-transparent"
1192
- }
1193
- ),
1194
- canScrollRight && !hasRightPinned && /* @__PURE__ */ jsx(
1195
- "div",
1196
- {
1197
- "aria-hidden": "true",
1198
- "data-slot": "data-table-scroll-fade-right",
1199
- className: "pointer-events-none absolute inset-y-0 right-0 z-10 w-8 rounded-lg bg-gradient-to-l from-card to-transparent"
1200
- }
1201
- )
1202
- ]
1203
- }
1204
- ),
1205
- renderPagination()
1206
- ] });
1207
- if (!rowReorderActive) return nonVirtualizedContent;
1208
- return /* @__PURE__ */ jsxs(
1209
- DndContext,
1210
- {
1211
- sensors: reorderSensors,
1212
- collisionDetection: closestCenter,
1213
- onDragStart: handleRowDragStart,
1214
- onDragOver: handleRowDragOver,
1215
- onDragEnd: handleRowDragEnd,
1216
- onDragCancel: handleRowDragCancel,
1217
- accessibility: {
1218
- announcements: silentDragAnnouncements,
1219
- // #98: dnd-kit's own hidden keyboard-instructions node is hardcoded
1220
- // English (`defaultScreenReaderInstructions`) unless overridden here.
1221
- screenReaderInstructions: { draggable: t("data.table.reorderInstructions") }
1222
- },
1223
- children: [
1224
- nonVirtualizedContent,
1225
- /* @__PURE__ */ jsx(
1226
- "div",
1227
- {
1228
- role: "status",
1229
- "aria-live": "polite",
1230
- "aria-atomic": "true",
1231
- "data-slot": "data-table-reorder-live-region",
1232
- className: "sr-only",
1233
- children: reorderLiveMessage
1234
- }
1235
- )
1236
- ]
1237
- }
1238
- );
1239
- }
1240
- var DataTableWithRef = forwardRef(DataTableInner);
1241
-
1242
- // src/search-input/search-input.tsx
1243
- import { useId } from "react";
1244
- import { Input } from "@elabs-ai/components-ui";
1245
- import { cn as cn2 } from "@elabs-ai/components-ui/lib/cn";
1246
- import { SearchIcon } from "@elabs-ai/components-icons";
1247
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1248
- function SearchInput({
1249
- value,
1250
- onValueChange,
1251
- label = "Search",
1252
- placeholder = "Search\u2026",
1253
- className,
1254
- containerClassName,
1255
- disabled,
1256
- ...props
1257
- }) {
1258
- const id = useId();
1259
- return /* @__PURE__ */ jsxs2("div", { className: cn2("relative w-full max-w-xs", containerClassName), children: [
1260
- /* @__PURE__ */ jsx2("label", { htmlFor: id, className: "sr-only", children: label }),
1261
- /* @__PURE__ */ jsx2(
1262
- SearchIcon,
1263
- {
1264
- size: 16,
1265
- className: "pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"
1266
- }
1267
- ),
1268
- /* @__PURE__ */ jsx2(
1269
- Input,
1270
- {
1271
- id,
1272
- value,
1273
- onChange: (e) => onValueChange(e.target.value),
1274
- placeholder,
1275
- disabled,
1276
- className: cn2("ps-8", value && "pe-8", className),
1277
- ...props
1278
- }
1279
- ),
1280
- value && !disabled ? /* @__PURE__ */ jsx2(
1281
- "button",
1282
- {
1283
- type: "button",
1284
- onClick: () => onValueChange(""),
1285
- "aria-label": "Clear search",
1286
- className: "absolute end-2 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground transition-colors duration-fast ease-standard hover:text-foreground focus-ring animate-in fade-in zoom-in-95 duration-fast ease-entrance",
1287
- children: /* @__PURE__ */ jsx2(
1288
- "svg",
1289
- {
1290
- width: "14",
1291
- height: "14",
1292
- viewBox: "0 0 24 24",
1293
- fill: "none",
1294
- stroke: "currentColor",
1295
- strokeWidth: "2",
1296
- strokeLinecap: "round",
1297
- strokeLinejoin: "round",
1298
- "aria-hidden": "true",
1299
- children: /* @__PURE__ */ jsx2("path", { d: "M18 6 6 18M6 6l12 12" })
1300
- }
1301
- )
1302
- }
1303
- ) : null
1304
- ] });
1305
- }
1306
-
1307
- // src/filter-bar/filter-bar.tsx
1308
- import "react";
1309
- import { cn as cn3 } from "@elabs-ai/components-ui/lib/cn";
1310
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1311
- function FilterBar({ children, actions, className }) {
1312
- return /* @__PURE__ */ jsxs3("div", { className: cn3("flex flex-wrap items-center justify-between gap-2", className), children: [
1313
- /* @__PURE__ */ jsx3("div", { className: "flex flex-wrap items-center gap-2", children }),
1314
- actions ? /* @__PURE__ */ jsx3("div", { className: "flex items-center gap-2", children: actions }) : null
1315
- ] });
1316
- }
1317
-
1318
- // src/filter-bar/filter-chip.tsx
1319
- import { forwardRef as forwardRef2 } from "react";
42
+ SparklineCell
43
+ } from "./chunk-HG2YMSRM.js";
1320
44
  import {
1321
- FilterChip as BaseFilterChip,
1322
- useLocale as useLocale2
1323
- } from "@elabs-ai/components-ui";
1324
- import { jsx as jsx4 } from "react/jsx-runtime";
1325
- var FilterChip = forwardRef2(function FilterChip2({ label, count, countLabel, ...props }, ref) {
1326
- const { formatNumber } = useLocale2();
1327
- const countText = count === void 0 ? void 0 : countLabel ? `${countLabel} ${formatNumber(count)}` : formatNumber(count);
1328
- const { trailing: _ignoredTrailing, ...restProps } = props;
1329
- return /* @__PURE__ */ jsx4(
1330
- BaseFilterChip,
1331
- {
1332
- ref,
1333
- "data-slot": "filter-chip",
1334
- label,
1335
- ...restProps,
1336
- trailing: countText
1337
- }
1338
- );
1339
- });
1340
-
1341
- // src/facet-filter/facet-filter.tsx
1342
- import { forwardRef as forwardRef3 } from "react";
45
+ columnSizeStyle,
46
+ formatCellValue,
47
+ resolveShowAt
48
+ } from "./chunk-TBB33PHQ.js";
1343
49
  import {
1344
- Badge,
1345
- Button as Button2,
1346
- DropdownMenu,
1347
- DropdownMenuContent,
1348
- DropdownMenuItem,
1349
- DropdownMenuLabel,
1350
- DropdownMenuSeparator,
1351
- DropdownMenuTrigger,
1352
- useLocale as useLocale3
1353
- } from "@elabs-ai/components-ui";
1354
- import { cn as cn4 } from "@elabs-ai/components-ui/lib/cn";
1355
- import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1356
- var FacetFilter = forwardRef3(function FacetFilter2({ title, options, selected, onSelectedChange, className, ...props }, ref) {
1357
- const { t } = useLocale3();
1358
- const selectedSet = new Set(selected);
1359
- const toggle = (value) => {
1360
- const next = new Set(selectedSet);
1361
- if (next.has(value)) next.delete(value);
1362
- else next.add(value);
1363
- onSelectedChange([...next]);
1364
- };
1365
- return /* @__PURE__ */ jsxs4(DropdownMenu, { children: [
1366
- /* @__PURE__ */ jsx5(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs4(Button2, { ref, variant: "outline", className: cn4("border-dashed", className), ...props, children: [
1367
- title,
1368
- selected.length > 0 ? /* @__PURE__ */ jsx5(
1369
- Badge,
1370
- {
1371
- variant: "secondary",
1372
- className: "ms-1 rounded px-1.5 animate-in fade-in zoom-in-95 duration-fast ease-entrance",
1373
- children: selected.length
1374
- }
1375
- ) : null
1376
- ] }) }),
1377
- /* @__PURE__ */ jsxs4(DropdownMenuContent, { className: "min-w-[12rem]", children: [
1378
- /* @__PURE__ */ jsx5(DropdownMenuLabel, { children: title }),
1379
- options.map((opt) => {
1380
- const checked = selectedSet.has(opt.value);
1381
- return /* @__PURE__ */ jsxs4(
1382
- DropdownMenuItem,
1383
- {
1384
- onSelect: (e) => {
1385
- e.preventDefault();
1386
- toggle(opt.value);
1387
- },
1388
- children: [
1389
- /* @__PURE__ */ jsx5(
1390
- "span",
1391
- {
1392
- "aria-hidden": "true",
1393
- className: "flex size-4 items-center justify-center rounded border transition-colors duration-fast ease-standard " + (checked ? "border-primary bg-primary text-primary-foreground" : "border-input"),
1394
- children: checked ? "\u2713" : ""
1395
- }
1396
- ),
1397
- opt.label
1398
- ]
1399
- },
1400
- opt.value
1401
- );
1402
- }),
1403
- selected.length > 0 ? /* @__PURE__ */ jsxs4(Fragment2, { children: [
1404
- /* @__PURE__ */ jsx5(DropdownMenuSeparator, {}),
1405
- /* @__PURE__ */ jsx5(DropdownMenuItem, { onSelect: () => onSelectedChange([]), children: t("data.facetFilter.clearFilters") })
1406
- ] }) : null
1407
- ] })
1408
- ] });
1409
- });
1410
- FacetFilter.displayName = "FacetFilter";
1411
-
1412
- // src/column-picker/column-picker.tsx
1413
- import "@tanstack/react-table";
1414
- import { forwardRef as forwardRef4 } from "react";
50
+ DataTableRankCell,
51
+ DataTableRankHeader,
52
+ computeRowRanks
53
+ } from "./chunk-XN6O6Z2N.js";
1415
54
  import {
1416
- Button as Button3,
1417
- DropdownMenu as DropdownMenu2,
1418
- DropdownMenuContent as DropdownMenuContent2,
1419
- DropdownMenuItem as DropdownMenuItem2,
1420
- DropdownMenuLabel as DropdownMenuLabel2,
1421
- DropdownMenuSeparator as DropdownMenuSeparator2,
1422
- DropdownMenuTrigger as DropdownMenuTrigger2,
1423
- useLocale as useLocale4
1424
- } from "@elabs-ai/components-ui";
1425
- import { cn as cn5 } from "@elabs-ai/components-ui/lib/cn";
1426
- import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1427
- function ColumnPickerInner({ table, label = "Columns", className, ...props }, ref) {
1428
- const { t } = useLocale4();
1429
- const columns = table.getAllColumns().filter((c) => c.getCanHide());
1430
- return /* @__PURE__ */ jsxs5(DropdownMenu2, { children: [
1431
- /* @__PURE__ */ jsx6(DropdownMenuTrigger2, { asChild: true, children: /* @__PURE__ */ jsx6(Button3, { ref, variant: "outline", size: "sm", className: cn5(className), ...props, children: label }) }),
1432
- /* @__PURE__ */ jsxs5(DropdownMenuContent2, { align: "end", className: "min-w-[12rem]", children: [
1433
- /* @__PURE__ */ jsx6(DropdownMenuLabel2, { children: t("data.columnPicker.toggleColumns") }),
1434
- /* @__PURE__ */ jsx6(DropdownMenuSeparator2, {}),
1435
- columns.map((column) => /* @__PURE__ */ jsxs5(
1436
- DropdownMenuItem2,
1437
- {
1438
- onSelect: (e) => {
1439
- e.preventDefault();
1440
- column.toggleVisibility(!column.getIsVisible());
1441
- },
1442
- children: [
1443
- /* @__PURE__ */ jsx6(
1444
- "span",
1445
- {
1446
- "aria-hidden": "true",
1447
- className: "flex size-4 items-center justify-center rounded border transition-colors duration-fast ease-standard " + (column.getIsVisible() ? "border-primary bg-primary text-primary-foreground" : "border-input"),
1448
- children: column.getIsVisible() ? "\u2713" : ""
1449
- }
1450
- ),
1451
- /* @__PURE__ */ jsx6("span", { className: "capitalize", children: column.id })
1452
- ]
1453
- },
1454
- column.id
1455
- ))
1456
- ] })
1457
- ] });
1458
- }
1459
- ColumnPickerInner.displayName = "ColumnPicker";
1460
- var ColumnPicker = forwardRef4(ColumnPickerInner);
1461
-
1462
- // src/to-csv.ts
1463
- import { downloadBlob } from "@elabs-ai/components-ui";
1464
- var INJECTION_PREFIXES = ["=", "+", "-", "@"];
1465
- function stringifyValue(value) {
1466
- if (value === null || value === void 0) return "";
1467
- if (value instanceof Date) return value.toISOString();
1468
- if (typeof value === "object") return JSON.stringify(value);
1469
- return String(value);
1470
- }
1471
- function quoteField(field, delimiter) {
1472
- if (INJECTION_PREFIXES.some((p) => field.startsWith(p))) {
1473
- field = "'" + field;
1474
- }
1475
- if (field.includes(delimiter) || field.includes('"') || field.includes("\n") || field.includes("\r")) {
1476
- return '"' + field.replaceAll('"', '""') + '"';
1477
- }
1478
- return field;
1479
- }
1480
- function toCsv(rows, opts) {
1481
- const delimiter = opts?.delimiter ?? ",";
1482
- const includeHeader = opts?.header !== false;
1483
- const firstRow = rows[0];
1484
- const cols = opts?.columns ?? (firstRow !== void 0 ? Object.keys(firstRow).map((k) => ({ key: k })) : []);
1485
- const lines = [];
1486
- if (includeHeader && cols.length > 0) {
1487
- const headerRow = cols.map((c) => quoteField(c.header ?? c.key, delimiter)).join(delimiter);
1488
- lines.push(headerRow);
1489
- }
1490
- for (const row of rows) {
1491
- const line = cols.map((c) => quoteField(stringifyValue(row[c.key]), delimiter)).join(delimiter);
1492
- lines.push(line);
1493
- }
1494
- return lines.join("\r\n") + (lines.length > 0 ? "\r\n" : "");
1495
- }
1496
- function downloadCsv(rows, opts) {
1497
- if (typeof document === "undefined") return;
1498
- const csv = toCsv(rows, opts);
1499
- const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
1500
- downloadBlob(blob, (opts?.filename ?? "download") + ".csv");
1501
- }
55
+ stickyRowPinning
56
+ } from "./chunk-47ZBQZYS.js";
57
+ import "./chunk-5K2IFOV2.js";
58
+ import {
59
+ ColumnPicker
60
+ } from "./chunk-DBPJ7LVM.js";
61
+ import {
62
+ DataTableCard,
63
+ DataTableCardList
64
+ } from "./chunk-KCB33PD3.js";
65
+ import {
66
+ CategoryLegend
67
+ } from "./chunk-ZUCGV2XD.js";
68
+ import {
69
+ ColumnsCell
70
+ } from "./chunk-GBO56756.js";
71
+ import {
72
+ BarCell
73
+ } from "./chunk-SK6347WB.js";
74
+ import {
75
+ barDomain,
76
+ barGeometry,
77
+ computeColumnScales,
78
+ extentOf,
79
+ heatmapColorScaleSpec,
80
+ seriesValues
81
+ } from "./chunk-VCLA45IC.js";
1502
82
  export {
83
+ BarCell,
84
+ CategoryLegend,
1503
85
  ColumnPicker,
86
+ ColumnsCell,
87
+ DATA_TABLE_BREAKPOINT_THRESHOLDS,
1504
88
  DataTableWithRef as DataTable,
89
+ DataTableCard,
90
+ DataTableCardList,
91
+ DataTableRankCell,
92
+ DataTableRankHeader,
1505
93
  FacetFilter,
1506
94
  FilterBar,
1507
95
  FilterChip,
96
+ HeatmapCell,
97
+ HeatmapLegend,
98
+ MarkdownCell,
1508
99
  SearchInput,
100
+ SparklineCell,
101
+ barDomain,
102
+ barGeometry,
103
+ columnSizeStyle,
104
+ computeColumnScales,
105
+ computeRowRanks,
1509
106
  createSelectionColumn,
1510
107
  downloadCsv,
1511
- toCsv
108
+ extentOf,
109
+ formatCellValue,
110
+ heatmapCellStyle,
111
+ heatmapColorScaleSpec,
112
+ isSafeCellUrl,
113
+ parseCellMarkdown,
114
+ resolveShowAt,
115
+ seriesValues,
116
+ stickyRowPinning,
117
+ tableBreakpointForWidth,
118
+ toCsv,
119
+ useTableBreakpoint
1512
120
  };
1513
121
  //# sourceMappingURL=index.js.map