@platned/ui 0.10.4 → 1.1.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 (63) hide show
  1. package/README.md +66 -99
  2. package/dist/blocks-charts.cjs +460 -0
  3. package/dist/blocks-charts.cjs.map +1 -0
  4. package/dist/blocks-charts.d.cts +64 -0
  5. package/dist/blocks-charts.d.ts +64 -0
  6. package/dist/blocks-charts.js +442 -0
  7. package/dist/blocks-charts.js.map +1 -0
  8. package/dist/blocks.cjs +8099 -0
  9. package/dist/blocks.cjs.map +1 -0
  10. package/dist/blocks.d.cts +3136 -0
  11. package/dist/blocks.d.ts +3136 -0
  12. package/dist/blocks.js +8330 -0
  13. package/dist/blocks.js.map +1 -0
  14. package/dist/chart.cjs +227 -0
  15. package/dist/chart.cjs.map +1 -0
  16. package/dist/chart.d.ts +66 -0
  17. package/dist/chart.js +184 -0
  18. package/dist/chart.js.map +1 -0
  19. package/dist/chunk-6BJ3OMUZ.js +3177 -0
  20. package/dist/chunk-6BJ3OMUZ.js.map +1 -0
  21. package/dist/chunk-7RXFHQL5.js +201 -0
  22. package/dist/chunk-7RXFHQL5.js.map +1 -0
  23. package/dist/chunk-MJC4A7I4.js +13 -0
  24. package/dist/chunk-MJC4A7I4.js.map +1 -0
  25. package/dist/chunk-QYFD7KIK.js +179 -0
  26. package/dist/chunk-QYFD7KIK.js.map +1 -0
  27. package/dist/code-block-BgEiLXpO.d.ts +111 -0
  28. package/dist/code-block-highlight.cjs +490 -0
  29. package/dist/code-block-highlight.cjs.map +1 -0
  30. package/dist/code-block-highlight.d.ts +28 -0
  31. package/dist/code-block-highlight.js +121 -0
  32. package/dist/code-block-highlight.js.map +1 -0
  33. package/dist/data-table-Dec6t8NO.d.ts +729 -0
  34. package/dist/data-table.cjs +3507 -2219
  35. package/dist/data-table.cjs.map +1 -1
  36. package/dist/data-table.d.ts +2 -1
  37. package/dist/data-table.js +1397 -246
  38. package/dist/data-table.js.map +1 -1
  39. package/dist/index.cjs +13232 -12876
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.ts +2748 -5343
  42. package/dist/index.js +8273 -9760
  43. package/dist/index.js.map +1 -1
  44. package/dist/map.cjs +433 -0
  45. package/dist/map.cjs.map +1 -0
  46. package/dist/map.d.cts +294 -0
  47. package/dist/map.d.ts +294 -0
  48. package/dist/map.js +428 -0
  49. package/dist/map.js.map +1 -0
  50. package/dist/theme.css +1897 -0
  51. package/package.json +60 -24
  52. package/dist/chunk-OVIRTNT4.js +0 -2787
  53. package/dist/chunk-OVIRTNT4.js.map +0 -1
  54. package/dist/data-table-JX-vnL0F.d.ts +0 -464
  55. package/dist/sidebar.cjs +0 -108
  56. package/dist/sidebar.cjs.map +0 -1
  57. package/dist/sidebar.d.cts +0 -257
  58. package/dist/sidebar.d.ts +0 -257
  59. package/dist/sidebar.js +0 -70
  60. package/dist/sidebar.js.map +0 -1
  61. package/dist/styles.css +0 -1
  62. package/dist/tokens.css +0 -1
  63. package/tailwind-preset.cjs +0 -446
@@ -1,27 +1,60 @@
1
+ "use client";
1
2
  import {
2
- Button,
3
+ Badge,
3
4
  Checkbox,
5
+ Command,
6
+ CommandEmpty,
7
+ CommandGroup,
8
+ CommandInput,
9
+ CommandItem,
10
+ CommandList,
11
+ CommandSeparator,
12
+ CommandShortcut,
4
13
  DropdownMenu,
5
14
  DropdownMenuCheckboxItem,
6
15
  DropdownMenuContent,
16
+ DropdownMenuItem,
7
17
  DropdownMenuLabel,
18
+ DropdownMenuSeparator,
8
19
  DropdownMenuTrigger,
9
- EmptyState,
10
- FOCUS_RING,
20
+ Empty,
11
21
  FOCUS_RING_INSET,
12
- PaginationBar,
22
+ Input,
23
+ Popover,
24
+ PopoverContent,
25
+ PopoverTrigger,
13
26
  SCROLLBAR_CLASSES,
14
- SearchInput,
27
+ Select,
28
+ Separator,
15
29
  Skeleton,
16
30
  TableCellBadge,
17
31
  TableCellLeadText,
18
32
  TableCellProgress,
19
33
  TableCellText,
20
34
  TableRow,
21
- cn,
35
+ Tabs,
36
+ TabsList,
37
+ TabsTrigger,
38
+ ToggleGroup,
39
+ ToggleGroupItem,
40
+ Value,
22
41
  devWarn,
23
- useElementWidth
24
- } from "./chunk-OVIRTNT4.js";
42
+ fillTemplate,
43
+ formatValue,
44
+ getValueAt,
45
+ humanize,
46
+ isNumericType,
47
+ toDate,
48
+ useElementWidth,
49
+ useFormat,
50
+ valueLabel
51
+ } from "./chunk-6BJ3OMUZ.js";
52
+ import {
53
+ Button
54
+ } from "./chunk-QYFD7KIK.js";
55
+ import {
56
+ cn
57
+ } from "./chunk-MJC4A7I4.js";
25
58
 
26
59
  // src/components/lists/data-table.tsx
27
60
  import {
@@ -31,17 +64,23 @@ import {
31
64
  useLayoutEffect,
32
65
  useMemo,
33
66
  useRef,
34
- useState
67
+ useState,
68
+ Fragment as Fragment4
35
69
  } from "react";
36
70
  import clsx from "clsx";
37
71
  import {
38
72
  flexRender,
39
73
  getCoreRowModel,
74
+ getExpandedRowModel,
75
+ getFacetedRowModel,
76
+ getFacetedUniqueValues,
77
+ getGroupedRowModel,
40
78
  getFilteredRowModel,
41
79
  getPaginationRowModel,
42
80
  getSortedRowModel,
43
81
  useReactTable
44
82
  } from "@tanstack/react-table";
83
+ import { ChevronRightIcon as ChevronRightIcon3, CircleAlertIcon, XIcon as XIcon2 } from "lucide-react";
45
84
 
46
85
  // src/components/lists/data-table-layout.ts
47
86
  var DEFAULT_CARD_BREAKPOINT_PX = 560;
@@ -72,8 +111,21 @@ function cardSlots(columns) {
72
111
  }
73
112
 
74
113
  // src/components/lists/data-table-parts.tsx
75
- import { ChevronDownIcon, ChevronUpIcon, ChevronsUpDownIcon, Columns3Icon } from "lucide-react";
76
- import { jsx, jsxs } from "react/jsx-runtime";
114
+ import {
115
+ ArrowDownIcon,
116
+ ArrowUpIcon,
117
+ ChevronLeftIcon,
118
+ ChevronRightIcon,
119
+ ChevronsLeftIcon,
120
+ ChevronsRightIcon,
121
+ ChevronsUpDownIcon,
122
+ EyeOffIcon,
123
+ PinIcon,
124
+ PinOffIcon,
125
+ Settings2Icon,
126
+ XIcon
127
+ } from "lucide-react";
128
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
77
129
  var SELECT_COLUMN_ID = "select";
78
130
  function columnLabel(column) {
79
131
  const meta = column.columnDef.meta;
@@ -83,42 +135,72 @@ function columnLabel(column) {
83
135
  }
84
136
  function DataTableColumnHeader({
85
137
  column,
138
+ table,
86
139
  title,
87
140
  className
88
141
  }) {
89
142
  const text = title ?? columnLabel(column);
90
143
  const hidden = column.columnDef.meta?.hideHeader;
91
- if (!column.getCanSort()) {
92
- return /* @__PURE__ */ jsx("span", { className: cn(hidden ? "sr-only" : "inline-block w-max whitespace-nowrap", className), children: text });
144
+ const pinning = table?.options.meta?.pinning;
145
+ const multiSort = Boolean(table?.options.meta?.multiSort);
146
+ if (!column.getCanSort() && !pinning) {
147
+ return /* @__PURE__ */ jsx("div", { className: cn(hidden && "sr-only", className), children: text });
93
148
  }
149
+ const sortable = column.getCanSort();
94
150
  const sorted = column.getIsSorted();
95
- const Icon = sorted === "asc" ? ChevronUpIcon : sorted === "desc" ? ChevronDownIcon : ChevronsUpDownIcon;
96
- return /* @__PURE__ */ jsxs(
97
- "button",
98
- {
99
- type: "button",
100
- onClick: column.getToggleSortingHandler(),
101
- "data-sorted": sorted || void 0,
102
- className: cn(
103
- // w-max + nowrap: a header is never truncated; its column widens to fit it instead.
104
- "inline-flex w-max items-center gap-1 whitespace-nowrap rounded-sm transition-colors hover:text-default",
105
- "data-[sorted]:text-default",
106
- FOCUS_RING,
107
- className
108
- ),
109
- children: [
110
- /* @__PURE__ */ jsx("span", { className: cn(hidden && "sr-only"), children: text }),
111
- /* @__PURE__ */ jsx(
112
- Icon,
113
- {
114
- "aria-hidden": true,
115
- "data-sorted": sorted || void 0,
116
- className: "size-3.5 shrink-0 text-icon-default-secondary data-[sorted]:text-icon-brand"
117
- }
118
- )
119
- ]
120
- }
121
- );
151
+ const pinned = pinning?.get(column.id);
152
+ const sorts = (table?.getState().sorting ?? []).filter((sort) => !sort.id.startsWith("__"));
153
+ const position = sorts.findIndex((sort) => sort.id === column.id);
154
+ const sortIndex = sorted && sorts.length > 1 && position >= 0 ? position + 1 : void 0;
155
+ return /* @__PURE__ */ jsx("div", { className: cn("flex items-center gap-2", className), children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
156
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "-ms-3 h-8 data-[state=open]:bg-accent", children: [
157
+ /* @__PURE__ */ jsx("span", { className: cn(hidden && "sr-only"), children: text }),
158
+ pinned && /* @__PURE__ */ jsx(PinIcon, { "aria-hidden": true, className: "size-3 text-muted-foreground" }),
159
+ sorted === "desc" ? /* @__PURE__ */ jsx(ArrowDownIcon, {}) : sorted === "asc" ? /* @__PURE__ */ jsx(ArrowUpIcon, {}) : sortable ? /* @__PURE__ */ jsx(ChevronsUpDownIcon, {}) : null,
160
+ sortIndex && /* @__PURE__ */ jsxs("span", { className: "text-xs text-muted-foreground tabular-nums", children: [
161
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: ", sort " }),
162
+ sortIndex
163
+ ] })
164
+ ] }) }),
165
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", children: [
166
+ sortable && /* @__PURE__ */ jsxs(Fragment, { children: [
167
+ /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: (event) => column.toggleSorting(false, multiSort || event.shiftKey), children: [
168
+ /* @__PURE__ */ jsx(ArrowUpIcon, {}),
169
+ "Asc"
170
+ ] }),
171
+ /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: (event) => column.toggleSorting(true, multiSort || event.shiftKey), children: [
172
+ /* @__PURE__ */ jsx(ArrowDownIcon, {}),
173
+ "Desc"
174
+ ] }),
175
+ multiSort && sorted && /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => column.clearSorting(), children: [
176
+ /* @__PURE__ */ jsx(XIcon, {}),
177
+ "Clear sort"
178
+ ] })
179
+ ] }),
180
+ pinning && /* @__PURE__ */ jsxs(Fragment, { children: [
181
+ sortable && /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
182
+ pinned !== "start" && /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => pinning.set(column.id, "start"), children: [
183
+ /* @__PURE__ */ jsx(PinIcon, {}),
184
+ "Pin to start"
185
+ ] }),
186
+ pinned !== "end" && /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => pinning.set(column.id, "end"), children: [
187
+ /* @__PURE__ */ jsx(PinIcon, {}),
188
+ "Pin to end"
189
+ ] }),
190
+ pinned && /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => pinning.set(column.id, false), children: [
191
+ /* @__PURE__ */ jsx(PinOffIcon, {}),
192
+ "Unpin"
193
+ ] })
194
+ ] }),
195
+ column.getCanHide() && /* @__PURE__ */ jsxs(Fragment, { children: [
196
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
197
+ /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => column.toggleVisibility(false), children: [
198
+ /* @__PURE__ */ jsx(EyeOffIcon, {}),
199
+ "Hide"
200
+ ] })
201
+ ] })
202
+ ] })
203
+ ] }) });
122
204
  }
123
205
  function createSelectColumn(options = {}) {
124
206
  const { getRowLabel, selectAllLabel = "Select all rows on this page" } = options;
@@ -128,8 +210,7 @@ function createSelectColumn(options = {}) {
128
210
  Checkbox,
129
211
  {
130
212
  "aria-label": selectAllLabel,
131
- checked: table.getIsAllPageRowsSelected(),
132
- indeterminate: table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected(),
213
+ checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && "indeterminate",
133
214
  onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked)
134
215
  }
135
216
  ),
@@ -148,18 +229,24 @@ function createSelectColumn(options = {}) {
148
229
  meta: { width: "48px", interactive: true, mobile: "hidden", label: "Select" }
149
230
  };
150
231
  }
151
- function DataTableViewOptions({ table, label = "Columns" }) {
152
- const columns = table.getAllLeafColumns().filter((column) => column.getCanHide());
232
+ function DataTableViewOptions({ table, label = "View" }) {
233
+ const columns = table.getAllLeafColumns().filter((column) => typeof column.accessorFn !== "undefined" && column.getCanHide());
153
234
  if (columns.length === 0) return null;
154
235
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
155
- /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "neutral", size: "md", leadingIcon: /* @__PURE__ */ jsx(Columns3Icon, { "aria-hidden": true }), children: label }) }),
156
- /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", children: [
157
- /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Show columns" }),
236
+ /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", className: "ms-auto hidden h-8 lg:flex", children: [
237
+ /* @__PURE__ */ jsx(Settings2Icon, {}),
238
+ label
239
+ ] }) }),
240
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-[150px]", children: [
241
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Toggle columns" }),
242
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
158
243
  columns.map((column) => /* @__PURE__ */ jsx(
159
244
  DropdownMenuCheckboxItem,
160
245
  {
246
+ className: "capitalize",
161
247
  checked: column.getIsVisible(),
162
248
  onCheckedChange: (visible) => column.toggleVisibility(visible),
249
+ onSelect: (event) => event.preventDefault(),
163
250
  children: columnLabel(column)
164
251
  },
165
252
  column.id
@@ -169,48 +256,601 @@ function DataTableViewOptions({ table, label = "Columns" }) {
169
256
  }
170
257
  function DataTablePagination({
171
258
  table,
172
- pageSizeOptions = [10, 20, 50],
259
+ pageSizeOptions = [10, 20, 25, 30, 40, 50],
173
260
  summary
174
261
  }) {
175
262
  const { pageIndex, pageSize } = table.getState().pagination;
176
- return /* @__PURE__ */ jsx(
177
- PaginationBar,
263
+ const selectable = Boolean(table.options.enableRowSelection);
264
+ const pageCount = Math.max(table.getPageCount(), 1);
265
+ return /* @__PURE__ */ jsxs("div", { "data-slot": "data-table-pagination", className: "flex items-center justify-between px-2", children: [
266
+ /* @__PURE__ */ jsx("div", { className: "flex-1 text-sm text-muted-foreground", children: summary ?? (selectable ? `${table.getFilteredSelectedRowModel().rows.length} of ${table.getFilteredRowModel().rows.length} row(s) selected.` : null) }),
267
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-6 lg:gap-8", children: [
268
+ pageSizeOptions.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
269
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: "Rows per page" }),
270
+ /* @__PURE__ */ jsx(
271
+ Select,
272
+ {
273
+ "aria-label": "Rows per page",
274
+ value: `${pageSize}`,
275
+ onValueChange: (value) => table.setPageSize(Number(value)),
276
+ options: pageSizeOptions.map((size) => ({ value: `${size}`, label: `${size}` })),
277
+ className: "h-8 w-[70px]"
278
+ }
279
+ )
280
+ ] }),
281
+ /* @__PURE__ */ jsxs("div", { className: "flex w-[100px] items-center justify-center text-sm font-medium", children: [
282
+ "Page ",
283
+ pageIndex + 1,
284
+ " of ",
285
+ pageCount
286
+ ] }),
287
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
288
+ /* @__PURE__ */ jsxs(
289
+ Button,
290
+ {
291
+ variant: "outline",
292
+ size: "icon",
293
+ className: "hidden size-8 lg:flex",
294
+ onClick: () => table.setPageIndex(0),
295
+ disabled: !table.getCanPreviousPage(),
296
+ children: [
297
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Go to first page" }),
298
+ /* @__PURE__ */ jsx(ChevronsLeftIcon, { className: "rtl:rotate-180" })
299
+ ]
300
+ }
301
+ ),
302
+ /* @__PURE__ */ jsxs(
303
+ Button,
304
+ {
305
+ variant: "outline",
306
+ size: "icon",
307
+ className: "size-8",
308
+ onClick: () => table.previousPage(),
309
+ disabled: !table.getCanPreviousPage(),
310
+ children: [
311
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Go to previous page" }),
312
+ /* @__PURE__ */ jsx(ChevronLeftIcon, { className: "rtl:rotate-180" })
313
+ ]
314
+ }
315
+ ),
316
+ /* @__PURE__ */ jsxs(
317
+ Button,
318
+ {
319
+ variant: "outline",
320
+ size: "icon",
321
+ className: "size-8",
322
+ onClick: () => table.nextPage(),
323
+ disabled: !table.getCanNextPage(),
324
+ children: [
325
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Go to next page" }),
326
+ /* @__PURE__ */ jsx(ChevronRightIcon, { className: "rtl:rotate-180" })
327
+ ]
328
+ }
329
+ ),
330
+ /* @__PURE__ */ jsxs(
331
+ Button,
332
+ {
333
+ variant: "outline",
334
+ size: "icon",
335
+ className: "hidden size-8 lg:flex",
336
+ onClick: () => table.setPageIndex(table.getPageCount() - 1),
337
+ disabled: !table.getCanNextPage(),
338
+ children: [
339
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Go to last page" }),
340
+ /* @__PURE__ */ jsx(ChevronsRightIcon, { className: "rtl:rotate-180" })
341
+ ]
342
+ }
343
+ )
344
+ ] })
345
+ ] })
346
+ ] });
347
+ }
348
+
349
+ // src/components/lists/data-table-fields.tsx
350
+ import { CheckIcon, MoreHorizontalIcon, PlusCircleIcon } from "lucide-react";
351
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
352
+ var ROW_ACTIONS_COLUMN_ID = "actions";
353
+ function isFieldColumn(column) {
354
+ return typeof column === "object" && column !== null && "key" in column && typeof column.key === "string";
355
+ }
356
+ function filterValues(value) {
357
+ if (value == null || value === "") return [];
358
+ return Array.isArray(value) ? value.map(String) : [String(value)];
359
+ }
360
+ var includesSome = (row, columnId, selected) => {
361
+ if (!selected?.length) return true;
362
+ return filterValues(row.getValue(columnId)).some((value) => selected.includes(value));
363
+ };
364
+ function sortKey(field, value) {
365
+ if (value == null || value === "") return null;
366
+ switch (field.type) {
367
+ case "number":
368
+ case "currency":
369
+ case "percent": {
370
+ const n = Number(value);
371
+ return Number.isFinite(n) ? n : null;
372
+ }
373
+ case "date":
374
+ case "datetime":
375
+ case "relative":
376
+ return toDate(value)?.getTime() ?? null;
377
+ case "boolean":
378
+ return value ? 1 : 0;
379
+ case "status":
380
+ return valueLabel(value, field.type === "status" ? field.labels : void 0).toLowerCase();
381
+ default:
382
+ return String(value).toLowerCase();
383
+ }
384
+ }
385
+ function sortingFnFor(field) {
386
+ return (a, b, columnId) => {
387
+ const x = sortKey(field, a.getValue(columnId));
388
+ const y = sortKey(field, b.getValue(columnId));
389
+ if (x === null || y === null) return x === y ? 0 : x === null ? 1 : -1;
390
+ if (typeof x === "number" && typeof y === "number") return x - y;
391
+ return String(x).localeCompare(String(y), void 0, { numeric: true });
392
+ };
393
+ }
394
+ function describeFor(field) {
395
+ return (value) => {
396
+ if (field.type === "status")
397
+ return { label: valueLabel(value, field.labels), color: field.colors?.[value] ?? "gray" };
398
+ if (field.type === "boolean")
399
+ return { label: value === "true" ? field.trueLabel ?? "Yes" : field.falseLabel ?? "No" };
400
+ if (field.type === "badge") return { label: field.labels?.[value] ?? value };
401
+ return { label: value };
402
+ };
403
+ }
404
+ function fieldToColumn(field, format = {}) {
405
+ const label = field.label ?? humanize(field.key.split(".").pop() ?? field.key);
406
+ const sortable = field.sortable ?? field.type !== "badge";
407
+ const filter = field.filter ? {
408
+ title: typeof field.filter === "object" && field.filter.title || label,
409
+ options: typeof field.filter === "object" ? field.filter.options : void 0,
410
+ variant: typeof field.filter === "object" && field.filter.variant || "menu",
411
+ allLabel: typeof field.filter === "object" && field.filter.allLabel || "All",
412
+ describe: describeFor(field)
413
+ } : void 0;
414
+ const mobile = field.mobile ?? (field.type === "avatar" ? "title" : field.type === "status" ? "status" : void 0);
415
+ return {
416
+ id: field.id ?? field.key,
417
+ // Empty values read as undefined, so `sortUndefined: 'last'` keeps them last in both directions.
418
+ accessorFn: (row) => {
419
+ const value = getValueAt(row, field.key);
420
+ return value === null || value === "" ? void 0 : value;
421
+ },
422
+ header: ({ column, table }) => /* @__PURE__ */ jsx2(DataTableColumnHeader, { column, table, title: label }),
423
+ cell: ({ row }) => /* @__PURE__ */ jsx2(Value, { row: row.original, field }),
424
+ enableSorting: sortable,
425
+ enableHiding: field.hideable ?? true,
426
+ sortingFn: sortingFnFor(field),
427
+ sortUndefined: "last",
428
+ filterFn: includesSome,
429
+ // A badge column's facets are its single values, not the lists.
430
+ getUniqueValues: (row) => filterValues(getValueAt(row, field.key)),
431
+ meta: {
432
+ label,
433
+ width: field.width,
434
+ grow: field.grow,
435
+ align: field.align ?? (isNumericType(field.type) ? "end" : void 0),
436
+ sticky: field.sticky,
437
+ mobile,
438
+ // A cell with its own link or copy button keeps presses from activating the row.
439
+ interactive: field.type === "email" || field.type === "link" || field.type === "phone" || void 0,
440
+ filter,
441
+ searchText: (value) => formatValue(value, field, format)
442
+ }
443
+ };
444
+ }
445
+ function createGlobalSearch(textById) {
446
+ return (row, columnId, query) => {
447
+ const needle = String(query ?? "").trim().toLowerCase();
448
+ if (!needle) return true;
449
+ const value = row.getValue(columnId);
450
+ const toText = textById.get(columnId);
451
+ const text = toText ? toText(value) : value == null ? "" : Array.isArray(value) ? value.join(" ") : String(value);
452
+ return text.toLowerCase().includes(needle);
453
+ };
454
+ }
455
+ function RowActionsMenu({
456
+ row,
457
+ actions,
458
+ rowLabel,
459
+ renderLink
460
+ }) {
461
+ const visible = actions.filter((action) => !action.hidden?.(row));
462
+ if (visible.length === 0) return null;
463
+ return /* @__PURE__ */ jsxs2(DropdownMenu, { children: [
464
+ /* @__PURE__ */ jsx2(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs2(Button, { variant: "ghost", size: "icon", className: "size-8 data-[state=open]:bg-muted", children: [
465
+ /* @__PURE__ */ jsx2(MoreHorizontalIcon, {}),
466
+ /* @__PURE__ */ jsx2("span", { className: "sr-only", children: rowLabel ? `Actions for ${rowLabel}` : "Open menu" })
467
+ ] }) }),
468
+ /* @__PURE__ */ jsx2(DropdownMenuContent, { align: "end", className: "w-[160px]", children: visible.map((action, index) => /* @__PURE__ */ jsx2(
469
+ RowAction,
470
+ {
471
+ action,
472
+ row,
473
+ renderLink,
474
+ first: index === 0
475
+ },
476
+ `${action.label}-${index}`
477
+ )) })
478
+ ] });
479
+ }
480
+ function RowAction({
481
+ action,
482
+ row,
483
+ renderLink,
484
+ first
485
+ }) {
486
+ const content = /* @__PURE__ */ jsxs2(Fragment2, { children: [
487
+ action.icon,
488
+ action.label
489
+ ] });
490
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
491
+ action.separator && !first && /* @__PURE__ */ jsx2(DropdownMenuSeparator, {}),
492
+ action.href ? /* @__PURE__ */ jsx2(
493
+ DropdownMenuItem,
494
+ {
495
+ asChild: true,
496
+ variant: action.destructive ? "destructive" : "default",
497
+ disabled: action.disabled?.(row),
498
+ onSelect: () => action.onSelect?.(row),
499
+ children: renderLink({ href: fillTemplate(action.href, row), children: content }, row)
500
+ }
501
+ ) : /* @__PURE__ */ jsx2(
502
+ DropdownMenuItem,
503
+ {
504
+ variant: action.destructive ? "destructive" : "default",
505
+ disabled: action.disabled?.(row),
506
+ onSelect: () => action.onSelect?.(row),
507
+ children: content
508
+ }
509
+ )
510
+ ] });
511
+ }
512
+ function rowActionsColumn(actions, options) {
513
+ return {
514
+ id: ROW_ACTIONS_COLUMN_ID,
515
+ header: "Actions",
516
+ enableSorting: false,
517
+ enableHiding: false,
518
+ cell: ({ row }) => /* @__PURE__ */ jsx2(
519
+ RowActionsMenu,
520
+ {
521
+ row: row.original,
522
+ actions,
523
+ rowLabel: options.getRowLabel?.(row.original),
524
+ renderLink: options.renderLink
525
+ }
526
+ ),
527
+ meta: {
528
+ label: "Actions",
529
+ hideHeader: true,
530
+ interactive: true,
531
+ mobile: "actions",
532
+ align: "end",
533
+ width: "56px",
534
+ sticky: "end"
535
+ }
536
+ };
537
+ }
538
+ var DOT = {
539
+ gray: "bg-badge-dot-gray",
540
+ red: "bg-badge-dot-red",
541
+ orange: "bg-badge-dot-orange",
542
+ yellow: "bg-badge-dot-yellow",
543
+ lime: "bg-badge-dot-lime",
544
+ green: "bg-badge-dot-green",
545
+ teal: "bg-badge-dot-teal",
546
+ blue: "bg-badge-dot-blue",
547
+ pink: "bg-badge-dot-pink",
548
+ slate: "bg-badge-dot-slate",
549
+ violet: "bg-badge-dot-violet"
550
+ };
551
+ function facets(column) {
552
+ const meta = column.columnDef.meta?.filter;
553
+ const counts = /* @__PURE__ */ new Map();
554
+ for (const row of column.getFacetedRowModel().rows) {
555
+ if (row.getIsGrouped()) continue;
556
+ for (const value of filterValues(row.getValue(column.id))) counts.set(value, (counts.get(value) ?? 0) + 1);
557
+ }
558
+ const values = meta?.options ?? [...counts.keys()].sort((a, b) => a.localeCompare(b, void 0, { numeric: true }));
559
+ const items = values.map((value) => ({
560
+ value,
561
+ ...meta?.describe(value) ?? { label: value },
562
+ icon: void 0
563
+ }));
564
+ const total = column.getFacetedRowModel().rows.filter((row) => !row.getIsGrouped()).length;
565
+ return { counts, items, total };
566
+ }
567
+ function singleValue(column) {
568
+ const value = column.getFilterValue()?.[0];
569
+ return {
570
+ value: value ?? "",
571
+ set: (next) => column.setFilterValue(next ? [next] : void 0)
572
+ };
573
+ }
574
+ function DataTableButtonFilter({ column, title }) {
575
+ const meta = column.columnDef.meta?.filter;
576
+ const { items } = facets(column);
577
+ const { value, set } = singleValue(column);
578
+ const heading = title ?? meta?.title ?? column.columnDef.meta?.label ?? column.id;
579
+ return /* @__PURE__ */ jsxs2(
580
+ ToggleGroup,
178
581
  {
179
- page: pageIndex + 1,
180
- pageSize,
181
- total: table.getRowCount(),
182
- onPageChange: (page) => table.setPageIndex(page - 1),
183
- onPageSizeChange: (size) => table.setPageSize(size),
184
- pageSizeOptions,
185
- summary,
186
- label: "Table pages"
582
+ type: "single",
583
+ variant: "outline",
584
+ size: "sm",
585
+ spacing: 0,
586
+ "aria-label": heading,
587
+ value: value || "__all",
588
+ onValueChange: (next) => set(next === "__all" || !next ? "" : next),
589
+ children: [
590
+ /* @__PURE__ */ jsx2(ToggleGroupItem, { value: "__all", children: meta?.allLabel ?? "All" }),
591
+ items.map((item) => /* @__PURE__ */ jsxs2(ToggleGroupItem, { value: item.value, children: [
592
+ item.color && /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", className: cn("size-2 rounded-full", DOT[item.color]) }),
593
+ item.label
594
+ ] }, item.value))
595
+ ]
187
596
  }
188
597
  );
189
598
  }
599
+ function DataTableTabsFilter({ column, title }) {
600
+ const meta = column.columnDef.meta?.filter;
601
+ const { counts, items, total } = facets(column);
602
+ const { value, set } = singleValue(column);
603
+ const heading = title ?? meta?.title ?? column.columnDef.meta?.label ?? column.id;
604
+ const count = (n) => /* @__PURE__ */ jsx2(Badge, { variant: "secondary", className: "ms-1 h-5 min-w-5 rounded-full px-1.5 font-normal tabular-nums", children: n ?? 0 });
605
+ return /* @__PURE__ */ jsx2(Tabs, { value: value || "__all", onValueChange: (next) => set(next === "__all" ? "" : next), children: /* @__PURE__ */ jsxs2(TabsList, { "aria-label": heading, children: [
606
+ /* @__PURE__ */ jsxs2(TabsTrigger, { value: "__all", children: [
607
+ meta?.allLabel ?? "All",
608
+ count(total)
609
+ ] }),
610
+ items.map((item) => /* @__PURE__ */ jsxs2(TabsTrigger, { value: item.value, children: [
611
+ item.label,
612
+ count(counts.get(item.value))
613
+ ] }, item.value))
614
+ ] }) });
615
+ }
616
+ function DataTableFacetedFilter({ column, title, options }) {
617
+ const meta = column.columnDef.meta?.filter;
618
+ const { counts, items: facetItems } = facets(column);
619
+ const items = options ?? facetItems;
620
+ const selected = new Set(column.getFilterValue() ?? []);
621
+ const heading = title ?? meta?.title ?? column.columnDef.meta?.label ?? column.id;
622
+ const toggle = (value) => {
623
+ const next = new Set(selected);
624
+ if (next.has(value)) next.delete(value);
625
+ else next.add(value);
626
+ column.setFilterValue(next.size ? [...next] : void 0);
627
+ };
628
+ return /* @__PURE__ */ jsxs2(Popover, { children: [
629
+ /* @__PURE__ */ jsx2(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs2(Button, { variant: "outline", size: "sm", className: "h-8 border-dashed", children: [
630
+ /* @__PURE__ */ jsx2(PlusCircleIcon, {}),
631
+ heading,
632
+ selected.size > 0 && /* @__PURE__ */ jsxs2(Fragment2, { children: [
633
+ /* @__PURE__ */ jsx2(Separator, { orientation: "vertical", className: "mx-2 h-4" }),
634
+ /* @__PURE__ */ jsx2(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal lg:hidden", children: selected.size }),
635
+ /* @__PURE__ */ jsx2("div", { className: "hidden gap-1 lg:flex", children: selected.size > 2 ? /* @__PURE__ */ jsxs2(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal", children: [
636
+ selected.size,
637
+ " selected"
638
+ ] }) : items.filter((item) => selected.has(item.value)).map((item) => /* @__PURE__ */ jsx2(Badge, { variant: "secondary", className: "rounded-sm px-1 font-normal", children: item.label }, item.value)) })
639
+ ] })
640
+ ] }) }),
641
+ /* @__PURE__ */ jsx2(PopoverContent, { className: "w-[200px] p-0", align: "start", children: /* @__PURE__ */ jsxs2(Command, { children: [
642
+ /* @__PURE__ */ jsx2(CommandInput, { placeholder: heading, "aria-label": heading }),
643
+ /* @__PURE__ */ jsxs2(CommandList, { children: [
644
+ /* @__PURE__ */ jsx2(CommandEmpty, { children: "No results found." }),
645
+ /* @__PURE__ */ jsx2(CommandGroup, { children: items.map((item) => {
646
+ const isSelected = selected.has(item.value);
647
+ return /* @__PURE__ */ jsxs2(
648
+ CommandItem,
649
+ {
650
+ value: item.label,
651
+ keywords: [item.value],
652
+ "aria-checked": isSelected,
653
+ onSelect: () => toggle(item.value),
654
+ children: [
655
+ /* @__PURE__ */ jsx2(
656
+ "div",
657
+ {
658
+ className: cn(
659
+ "flex size-4 items-center justify-center rounded-[4px] border",
660
+ isSelected ? "border-primary bg-primary text-primary-foreground" : "border-input [&_svg]:invisible"
661
+ ),
662
+ children: /* @__PURE__ */ jsx2(CheckIcon, { className: "size-3.5 text-primary-foreground" })
663
+ }
664
+ ),
665
+ item.color && /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", className: cn("size-2 rounded-full", DOT[item.color]) }),
666
+ item.icon,
667
+ /* @__PURE__ */ jsx2("span", { children: item.label }),
668
+ counts.get(item.value) ? (
669
+ // A shortcut slot, so it takes the item's end (and the item's own check hides).
670
+ /* @__PURE__ */ jsx2(CommandShortcut, { className: "font-mono tracking-normal", children: counts.get(item.value) })
671
+ ) : null
672
+ ]
673
+ },
674
+ item.value
675
+ );
676
+ }) }),
677
+ selected.size > 0 && /* @__PURE__ */ jsxs2(Fragment2, { children: [
678
+ /* @__PURE__ */ jsx2(CommandSeparator, {}),
679
+ /* @__PURE__ */ jsx2(CommandGroup, { children: /* @__PURE__ */ jsx2(CommandItem, { onSelect: () => column.setFilterValue(void 0), className: "justify-center text-center", children: "Clear filters" }) })
680
+ ] })
681
+ ] })
682
+ ] }) })
683
+ ] });
684
+ }
685
+
686
+ // src/components/lists/data-table-features.tsx
687
+ import { createContext, useContext } from "react";
688
+ import { ChevronRightIcon as ChevronRightIcon2, GripVerticalIcon } from "lucide-react";
689
+ import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
690
+ var EXPAND_COLUMN_ID = "expand";
691
+ var DRAG_COLUMN_ID = "drag";
692
+ var GROUP_COLUMN_ID = "__group";
693
+ function DetailFields({ row, fields }) {
694
+ return /* @__PURE__ */ jsx3("dl", { className: "grid gap-x-6 gap-y-3 sm:grid-cols-2 lg:grid-cols-3", children: fields.map((field) => /* @__PURE__ */ jsxs3("div", { className: "flex min-w-0 flex-col gap-1", children: [
695
+ /* @__PURE__ */ jsx3("dt", { className: "text-xs text-muted-foreground", children: field.label ?? humanize(field.key.split(".").pop() ?? field.key) }),
696
+ /* @__PURE__ */ jsx3("dd", { className: "min-w-0 text-sm", children: /* @__PURE__ */ jsx3(Value, { row, field }) })
697
+ ] }, field.key)) });
698
+ }
699
+ function expandColumn() {
700
+ return {
701
+ id: EXPAND_COLUMN_ID,
702
+ header: "Details",
703
+ enableSorting: false,
704
+ enableHiding: false,
705
+ enableGlobalFilter: false,
706
+ cell: ({ row, table }) => {
707
+ const expansion = table.options.meta?.expansion;
708
+ if (!expansion) return null;
709
+ const open = expansion.isOpen(row.id);
710
+ return /* @__PURE__ */ jsx3(
711
+ Button,
712
+ {
713
+ variant: "ghost",
714
+ size: "icon-sm",
715
+ "aria-expanded": open,
716
+ "aria-controls": open ? detailId(row.id) : void 0,
717
+ "aria-label": `Details for ${expansion.label(row.original)}`,
718
+ onClick: () => expansion.toggle(row.id),
719
+ children: /* @__PURE__ */ jsx3(ChevronRightIcon2, { className: cn("transition-transform", open && "rotate-90") })
720
+ }
721
+ );
722
+ },
723
+ meta: { width: "44px", interactive: true, hideHeader: true, mobile: "hidden", label: "Details" }
724
+ };
725
+ }
726
+ var detailId = (rowId) => `data-table-detail-${rowId.replace(/[^\w-]/g, "_")}`;
727
+ var RowDragContext = createContext(null);
728
+ function DragHandle() {
729
+ const drag = useContext(RowDragContext);
730
+ if (!drag) return null;
731
+ return /* @__PURE__ */ jsx3(
732
+ Button,
733
+ {
734
+ ref: drag.setActivatorNodeRef,
735
+ variant: "ghost",
736
+ size: "icon-sm",
737
+ disabled: drag.disabled,
738
+ "aria-label": drag.label,
739
+ title: drag.disabled ? "Clear the sort, filters and grouping to reorder" : void 0,
740
+ className: "cursor-grab touch-none active:cursor-grabbing",
741
+ onClick: (event) => event.stopPropagation(),
742
+ ...drag.attributes,
743
+ ...drag.listeners,
744
+ children: /* @__PURE__ */ jsx3(GripVerticalIcon, {})
745
+ }
746
+ );
747
+ }
748
+ function dragColumn() {
749
+ return {
750
+ id: DRAG_COLUMN_ID,
751
+ header: "Reorder",
752
+ enableSorting: false,
753
+ enableHiding: false,
754
+ enableGlobalFilter: false,
755
+ cell: () => /* @__PURE__ */ jsx3(DragHandle, {}),
756
+ // Not `interactive`: that guard stops key events, which would also stop the drag sensor's
757
+ // window listener. The handle stops its own clicks instead.
758
+ meta: { width: "44px", hideHeader: true, mobile: "hidden", label: "Reorder" }
759
+ };
760
+ }
761
+ function groupKey(value, by = "value", timeZone) {
762
+ if (by === "value") return value == null ? "" : Array.isArray(value) ? value.join(", ") : String(value);
763
+ const date = toDate(value);
764
+ if (!date) return "";
765
+ const iso = new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" }).format(
766
+ date
767
+ );
768
+ return by === "day" ? iso : by === "month" ? iso.slice(0, 7) : iso.slice(0, 4);
769
+ }
770
+ function GroupLabel({
771
+ groupingValue,
772
+ by = "value",
773
+ format,
774
+ options
775
+ }) {
776
+ if (groupingValue === "") return /* @__PURE__ */ jsx3("span", { className: "text-muted-foreground", children: "None" });
777
+ if (by === "value") return /* @__PURE__ */ jsx3(Value, { value: groupingValue, ...format ?? {} });
778
+ const [y, m = "01", d = "01"] = groupingValue.split("-");
779
+ const date = new Date(Date.UTC(Number(y), Number(m) - 1, Number(d), 12));
780
+ if (by === "year") return /* @__PURE__ */ jsx3(Fragment3, { children: y });
781
+ if (by === "month")
782
+ return /* @__PURE__ */ jsx3(Fragment3, { children: new Intl.DateTimeFormat(options.locale, { month: "long", year: "numeric", timeZone: "UTC" }).format(date) });
783
+ const today = groupKey(options.now === void 0 ? /* @__PURE__ */ new Date() : new Date(options.now), "day", options.timeZone);
784
+ const yesterday = groupKey(
785
+ (options.now === void 0 ? Date.now() : new Date(options.now).getTime()) - 24 * 3600 * 1e3,
786
+ "day",
787
+ options.timeZone
788
+ );
789
+ const words = new Intl.DateTimeFormat(options.locale, {
790
+ weekday: "long",
791
+ day: "numeric",
792
+ month: "long",
793
+ year: "numeric",
794
+ timeZone: "UTC"
795
+ }).format(date);
796
+ if (groupingValue === today) return /* @__PURE__ */ jsxs3(Fragment3, { children: [
797
+ "Today \xB7 ",
798
+ words
799
+ ] });
800
+ if (groupingValue === yesterday) return /* @__PURE__ */ jsxs3(Fragment3, { children: [
801
+ "Yesterday \xB7 ",
802
+ words
803
+ ] });
804
+ return /* @__PURE__ */ jsx3(Fragment3, { children: words });
805
+ }
806
+ function groupSummary(row, summary, formatOf, options) {
807
+ const leaves = row.getLeafRows().filter((leaf) => !leaf.getIsGrouped());
808
+ return summary.map(({ key, fn = "sum", label }) => {
809
+ if (fn === "count") return { key, text: String(leaves.length), label };
810
+ const numbers = leaves.map((leaf) => Number(getValueAt(leaf.original, key))).filter(Number.isFinite);
811
+ const total = fn === "min" ? Math.min(...numbers) : fn === "max" ? Math.max(...numbers) : numbers.reduce((sum, n) => sum + n, 0) / (fn === "avg" ? numbers.length || 1 : 1);
812
+ const format = formatOf(key) ?? { type: "number" };
813
+ return { key, text: numbers.length ? formatValue(total, format, options) : "\u2014", label };
814
+ });
815
+ }
190
816
 
191
817
  // src/components/lists/data-table.tsx
192
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
193
- var DENSITY = {
194
- default: {
195
- headerCell: "px-4 py-3",
196
- headerText: "text-body-xs font-medium text-default-secondary",
197
- bodyCell: "px-4 py-[14px]"
198
- },
199
- compact: {
200
- headerCell: "px-3 py-2",
201
- headerText: "text-body-tiny font-semibold uppercase tracking-[0.4px] text-default-secondary",
202
- bodyCell: "px-3 py-2 text-body-xs text-default"
203
- }
818
+ import {
819
+ DndContext,
820
+ KeyboardSensor,
821
+ PointerSensor,
822
+ closestCenter,
823
+ useSensor,
824
+ useSensors
825
+ } from "@dnd-kit/core";
826
+ import {
827
+ SortableContext,
828
+ arrayMove,
829
+ sortableKeyboardCoordinates,
830
+ useSortable,
831
+ verticalListSortingStrategy
832
+ } from "@dnd-kit/sortable";
833
+ import { CSS } from "@dnd-kit/utilities";
834
+ import { Fragment as Fragment5, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
835
+ var ROW_TONE = "data-[tone=muted]:bg-muted data-[tone=brand]:bg-accent data-[tone=positive]:bg-success/10 data-[tone=warning]:bg-warning/10 data-[tone=danger]:bg-destructive/10 data-[dimmed]:opacity-60 data-[state=selected]:bg-muted";
836
+ var D = {
837
+ headerCell: "h-10 px-2 align-middle",
838
+ headerText: "text-foreground font-medium whitespace-nowrap",
839
+ bodyCell: "p-2 whitespace-nowrap"
204
840
  };
205
841
  var VERTICAL = {
206
842
  center: "align-middle",
207
843
  top: "align-top"
208
844
  };
209
845
  var TEXT_ALIGN = {
210
- start: "text-left",
846
+ start: "text-start",
211
847
  center: "text-center",
212
- end: "text-right"
848
+ end: "text-end"
213
849
  };
850
+ var GROUPING_ON = ["__group"];
851
+ var GROUPING_OFF = [];
852
+ var NO_ROWS = [];
853
+ var UTILITY_COLUMNS = ["drag", "select", "expand"];
214
854
  var ROW_LINK_ATTR = "data-row-link";
215
855
  function resolve(updater, previous) {
216
856
  return typeof updater === "function" ? updater(previous) : updater;
@@ -236,7 +876,7 @@ function useTableState(controlled, initial, onChange) {
236
876
  function CellInteractionGuard({ children }) {
237
877
  return (
238
878
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
239
- /* @__PURE__ */ jsx2(
879
+ /* @__PURE__ */ jsx4(
240
880
  "div",
241
881
  {
242
882
  className: "contents",
@@ -248,7 +888,7 @@ function CellInteractionGuard({ children }) {
248
888
  )
249
889
  );
250
890
  }
251
- var HEADER_PADDING_PX = { default: 32, compact: 24 };
891
+ var HEADER_PADDING_PX = 16;
252
892
  function useHeaderWidths(padding, deps) {
253
893
  const nodes = useRef(/* @__PURE__ */ new Map());
254
894
  const [widths, setWidths] = useState({});
@@ -310,7 +950,7 @@ function useScrollEdges() {
310
950
  }
311
951
  var serverSortedValue = () => void 0;
312
952
  function defaultRowLink({ children, ...props }) {
313
- return /* @__PURE__ */ jsx2("a", { ...props, children });
953
+ return /* @__PURE__ */ jsx4("a", { ...props, children });
314
954
  }
315
955
  function DataTable({
316
956
  columns,
@@ -327,7 +967,17 @@ function DataTable({
327
967
  onSelectionChange,
328
968
  getRowLabel,
329
969
  onRowClick,
330
- getRowHref,
970
+ getRowHref: getRowHrefProp,
971
+ rowHref,
972
+ rowActions,
973
+ defaultSort,
974
+ multiSort = false,
975
+ expand,
976
+ groupBy,
977
+ columnPinning = false,
978
+ resizable = false,
979
+ reorderable = false,
980
+ onDataChange,
331
981
  renderRowLink = defaultRowLink,
332
982
  getRowTone,
333
983
  getRowDimmed,
@@ -335,10 +985,9 @@ function DataTable({
335
985
  loadingRows = 5,
336
986
  error,
337
987
  onRetry,
338
- empty = "No results found.",
988
+ empty = "No results.",
339
989
  toolbar,
340
990
  footer,
341
- density = "default",
342
991
  align = "center",
343
992
  responsive = true,
344
993
  maxHeight,
@@ -360,7 +1009,29 @@ function DataTable({
360
1009
  if (manual.pagination && manual.rowCount === void 0) {
361
1010
  devWarn("DataTable `manual.pagination` needs `manual.rowCount` to know how many pages there are.");
362
1011
  }
363
- const [sorting, setSorting] = useTableState(state.sorting, [], onSortingChange);
1012
+ const [sorting, setSorting] = useTableState(
1013
+ state.sorting,
1014
+ (Array.isArray(defaultSort) ? defaultSort : defaultSort ? [defaultSort] : []).map((sort) => ({
1015
+ id: sort.key,
1016
+ desc: Boolean(sort.desc)
1017
+ })),
1018
+ onSortingChange
1019
+ );
1020
+ const [ownOrder, setOwnOrder] = useState(null);
1021
+ useEffect(() => setOwnOrder(null), [data]);
1022
+ const tableData = ownOrder ?? data;
1023
+ const moveRow = (from, to) => {
1024
+ const next = arrayMove(tableData, from, to);
1025
+ if (onDataChange) onDataChange(next);
1026
+ else setOwnOrder(next);
1027
+ };
1028
+ const group = typeof groupBy === "string" ? { key: groupBy } : groupBy;
1029
+ const [groupsExpanded, setGroupsExpanded] = useState(group?.defaultCollapsed ? {} : true);
1030
+ const [openRows, setOpenRows] = useState(() => new Set(expand?.defaultExpanded ?? []));
1031
+ const [pinOverrides, setPinOverrides] = useState({});
1032
+ const [widthOverrides, setWidthOverrides] = useState({});
1033
+ const getRowHref = getRowHrefProp ?? (rowHref ? (row) => fillTemplate(rowHref, row) : void 0);
1034
+ const format = useFormat();
364
1035
  const [globalFilter, setGlobalFilter] = useTableState(state.globalFilter, "", onGlobalFilterChange);
365
1036
  const [columnFilters, setColumnFilters] = useTableState(state.columnFilters, [], onColumnFiltersChange);
366
1037
  const [pagination, setPagination] = useTableState(
@@ -374,21 +1045,152 @@ function DataTable({
374
1045
  onColumnVisibilityChange
375
1046
  );
376
1047
  const [rowSelection, setRowSelection] = useTableState(state.rowSelection, {}, onRowSelectionChange);
1048
+ const hasExpand = Boolean(expand);
377
1049
  const allColumns = useMemo(() => {
378
- let cols = columns;
1050
+ let cols = columns.map(
1051
+ (column) => isFieldColumn(column) ? fieldToColumn(column, format) : column
1052
+ );
1053
+ if (expand) cols = [expandColumn(), ...cols];
1054
+ if (group) {
1055
+ cols = [
1056
+ ...cols,
1057
+ {
1058
+ id: GROUP_COLUMN_ID,
1059
+ accessorFn: (row) => groupKey(getValueAt(row, group.key), group.by, format.timeZone),
1060
+ header: "Group",
1061
+ cell: () => null,
1062
+ enableHiding: false,
1063
+ enableGlobalFilter: false,
1064
+ meta: { mobile: "hidden", label: "Group" }
1065
+ }
1066
+ ];
1067
+ }
1068
+ if (rowActions?.length) {
1069
+ cols = [
1070
+ ...cols,
1071
+ rowActionsColumn(rowActions, {
1072
+ getRowLabel,
1073
+ renderLink: ({ href, children }, row) => renderRowLink({ href, className: "", children, [ROW_LINK_ATTR]: "" }, row)
1074
+ })
1075
+ ];
1076
+ }
379
1077
  if (manual.sorting) {
380
1078
  cols = cols.map(
381
1079
  (column) => column.enableSorting === true && !("accessorFn" in column) && !("accessorKey" in column) ? { ...column, accessorFn: serverSortedValue } : column
382
1080
  );
383
1081
  }
384
- if (!enableRowSelection || cols.some((column) => column.id === SELECT_COLUMN_ID)) return cols;
385
- return [createSelectColumn({ getRowLabel: getRowLabel && ((row) => `Select ${getRowLabel(row)}`) }), ...cols];
386
- }, [columns, enableRowSelection, getRowLabel, manual.sorting]);
1082
+ if (enableRowSelection && !cols.some((column) => column.id === SELECT_COLUMN_ID)) {
1083
+ cols = [createSelectColumn({ getRowLabel: getRowLabel && ((row) => `Select ${getRowLabel(row)}`) }), ...cols];
1084
+ }
1085
+ if (reorderable) cols = [dragColumn(), ...cols];
1086
+ return cols;
1087
+ }, [
1088
+ columns,
1089
+ enableRowSelection,
1090
+ getRowLabel,
1091
+ manual.sorting,
1092
+ format,
1093
+ rowActions,
1094
+ renderRowLink,
1095
+ hasExpand,
1096
+ group?.key,
1097
+ group?.by,
1098
+ reorderable
1099
+ ]);
1100
+ const fieldsByKey = useMemo(() => {
1101
+ const map = /* @__PURE__ */ new Map();
1102
+ for (const column of columns) if (isFieldColumn(column)) map.set(column.key, column);
1103
+ return map;
1104
+ }, [columns]);
1105
+ const formatOf = (key) => {
1106
+ const field = fieldsByKey.get(key);
1107
+ if (!field) return void 0;
1108
+ const { key: _key, label: _label, ...rest } = field;
1109
+ return rest;
1110
+ };
1111
+ const metaPin = (id) => allColumns.find((column) => column.id === id)?.meta?.sticky;
1112
+ const pinOf = (id) => {
1113
+ const override = pinOverrides[id];
1114
+ return override === "none" ? void 0 : override ?? metaPin(id);
1115
+ };
1116
+ const columnIds = allColumns.map((column) => column.id ?? "");
1117
+ const isUtility = (id) => UTILITY_COLUMNS.includes(id);
1118
+ const orderKey = [
1119
+ ...UTILITY_COLUMNS.filter((id) => columnIds.includes(id)),
1120
+ ...columnIds.filter((id) => !isUtility(id) && pinOf(id) === "start"),
1121
+ ...columnIds.filter((id) => !isUtility(id) && !pinOf(id)),
1122
+ ...columnIds.filter((id) => !isUtility(id) && pinOf(id) === "end")
1123
+ ].join("\0");
1124
+ const columnOrder = useMemo(() => orderKey.split("\0"), [orderKey]);
1125
+ const anyStartPin = columnIds.some((id) => !isUtility(id) && pinOf(id) === "start");
1126
+ const effectivePin = (id) => isUtility(id) ? anyStartPin ? "start" : void 0 : pinOf(id);
1127
+ const grouped = Boolean(group);
1128
+ const groupDesc = group?.order === "desc";
1129
+ const effectiveSorting = useMemo(
1130
+ () => grouped ? [{ id: GROUP_COLUMN_ID, desc: groupDesc }, ...sorting.filter((sort) => sort.id !== GROUP_COLUMN_ID)] : sorting,
1131
+ [grouped, groupDesc, sorting]
1132
+ );
1133
+ const effectiveVisibility = useMemo(
1134
+ () => grouped ? { ...columnVisibility, [GROUP_COLUMN_ID]: false } : columnVisibility,
1135
+ [grouped, columnVisibility]
1136
+ );
1137
+ const expansion = expand ? {
1138
+ isOpen: (id) => openRows.has(id),
1139
+ toggle: (id) => setOpenRows((current) => {
1140
+ const next = new Set(expand.single ? [] : current);
1141
+ if (current.has(id)) next.delete(id);
1142
+ else next.add(id);
1143
+ return next;
1144
+ }),
1145
+ label: (row) => getRowLabel?.(row) ?? "row",
1146
+ render: (row) => expand.render ? expand.render(row) : expand.table ? /* @__PURE__ */ jsx4(
1147
+ DataTable,
1148
+ {
1149
+ label: expand.table.label ?? "Details",
1150
+ data: getValueAt(row, expand.table.key) ?? NO_ROWS,
1151
+ columns: expand.table.columns,
1152
+ pagination: false,
1153
+ className: "bg-background"
1154
+ }
1155
+ ) : expand.fields ? /* @__PURE__ */ jsx4(DetailFields, { row, fields: expand.fields }) : null
1156
+ } : void 0;
1157
+ const searchTextById = useMemo(() => {
1158
+ const map = /* @__PURE__ */ new Map();
1159
+ for (const column of allColumns) {
1160
+ const text = column.meta?.searchText;
1161
+ if (text && column.id) map.set(column.id, text);
1162
+ }
1163
+ return map;
1164
+ }, [allColumns]);
1165
+ const hasFilters = allColumns.some((column) => column.meta?.filter);
387
1166
  const table = useReactTable({
388
- data,
1167
+ data: tableData,
389
1168
  columns: allColumns,
390
1169
  getRowId,
391
- state: { sorting, globalFilter, columnFilters, pagination, columnVisibility, rowSelection },
1170
+ state: {
1171
+ sorting: effectiveSorting,
1172
+ globalFilter,
1173
+ columnFilters,
1174
+ pagination,
1175
+ columnVisibility: effectiveVisibility,
1176
+ rowSelection,
1177
+ columnOrder,
1178
+ grouping: grouped ? GROUPING_ON : GROUPING_OFF,
1179
+ expanded: groupsExpanded
1180
+ },
1181
+ onExpandedChange: setGroupsExpanded,
1182
+ getGroupedRowModel: group ? getGroupedRowModel() : void 0,
1183
+ getExpandedRowModel: group ? getExpandedRowModel() : void 0,
1184
+ groupedColumnMode: false,
1185
+ autoResetExpanded: false,
1186
+ meta: {
1187
+ pinning: columnPinning ? {
1188
+ get: pinOf,
1189
+ set: (id, side) => setPinOverrides((current) => ({ ...current, [id]: side || "none" }))
1190
+ } : void 0,
1191
+ multiSort,
1192
+ expansion
1193
+ },
392
1194
  onSortingChange: setSorting,
393
1195
  onGlobalFilterChange: setGlobalFilter,
394
1196
  onColumnFiltersChange: setColumnFilters,
@@ -400,6 +1202,16 @@ function DataTable({
400
1202
  getSortedRowModel: manual.sorting ? void 0 : getSortedRowModel(),
401
1203
  getFilteredRowModel: manual.filtering ? void 0 : getFilteredRowModel(),
402
1204
  getPaginationRowModel: paginated && !manual.pagination ? getPaginationRowModel() : void 0,
1205
+ getFacetedRowModel: hasFilters ? getFacetedRowModel() : void 0,
1206
+ getFacetedUniqueValues: hasFilters ? getFacetedUniqueValues() : void 0,
1207
+ globalFilterFn: searchTextById.size ? createGlobalSearch(searchTextById) : "auto",
1208
+ // TanStack searches only columns whose first value is a string or number. JSON columns are
1209
+ // searched by their shown text, so lists (tags), dates and nested values are searchable too.
1210
+ getColumnCanGlobalFilter: (column) => {
1211
+ if (column.columnDef.meta?.searchText) return true;
1212
+ const value = tableData.length ? column.accessorFn?.(tableData[0], 0) : void 0;
1213
+ return typeof value === "string" || typeof value === "number";
1214
+ },
403
1215
  manualSorting: manual.sorting,
404
1216
  manualFiltering: manual.filtering,
405
1217
  manualPagination: !paginated || manual.pagination,
@@ -435,25 +1247,28 @@ function DataTable({
435
1247
  const filtering = Boolean(globalFilter) || columnFilters.length > 0;
436
1248
  const rows = table.getRowModel().rows;
437
1249
  const isEmpty = !loading && !error && rows.length === 0;
438
- const placeholder = error ? /* @__PURE__ */ jsx2(
439
- EmptyState,
1250
+ const placeholder = error ? /* @__PURE__ */ jsx4(
1251
+ Empty,
440
1252
  {
441
- message: typeof error === "string" ? error : "Something went wrong loading this data.",
442
- variant: "error",
443
- size: "md",
444
- action: onRetry ? /* @__PURE__ */ jsx2(Button, { variant: "neutral", size: "sm", onClick: onRetry, children: "Retry" }) : void 0,
445
- className: "mx-auto max-w-[520px]"
1253
+ role: "alert",
1254
+ icon: /* @__PURE__ */ jsx4(CircleAlertIcon, {}),
1255
+ title: typeof error === "string" ? error : "Something went wrong loading this data.",
1256
+ className: "mx-auto max-w-[520px]",
1257
+ children: onRetry ? /* @__PURE__ */ jsx4(Button, { variant: "outline", size: "xs", onClick: onRetry, children: "Retry" }) : void 0
446
1258
  }
447
- ) : isEmpty ? typeof empty === "string" ? /* @__PURE__ */ jsx2(EmptyState, { message: empty, size: "md", className: "mx-auto max-w-[520px]" }) : empty : null;
1259
+ ) : isEmpty ? empty : null;
448
1260
  const resultCount = manual.filtering ? table.getRowCount() : table.getFilteredRowModel().rows.length;
449
- const showToolbar = Boolean(search || toolbar || showColumnMenu);
1261
+ const filterColumns = table.getAllLeafColumns().filter((column) => column.columnDef.meta?.filter);
1262
+ const tabsFilters = filterColumns.filter((column) => column.columnDef.meta?.filter?.variant === "tabs");
1263
+ const isToolbarFilter = (id) => filterColumns.some((c) => c.id === id && c.columnDef.meta?.filter?.variant !== "tabs");
1264
+ const showToolbar = Boolean(search || toolbar || showColumnMenu || filterColumns.length > tabsFilters.length);
1265
+ const reorderActive = reorderable && sorting.length === 0 && !filtering && !group;
450
1266
  const showPager = paginated && !error && table.getRowCount() > 0;
451
1267
  const view = {
452
1268
  table,
453
1269
  label,
454
1270
  caption,
455
1271
  captionId,
456
- density,
457
1272
  align,
458
1273
  loading,
459
1274
  loadingRows,
@@ -464,34 +1279,75 @@ function DataTable({
464
1279
  getRowTone,
465
1280
  getRowDimmed,
466
1281
  getRowLabel,
467
- maxHeight
468
- };
469
- return /* @__PURE__ */ jsxs2("div", { "data-slot": "data-table", className: cn("relative flex flex-col gap-3", className), children: [
470
- showToolbar && /* @__PURE__ */ jsxs2("div", { className: cn("flex flex-wrap items-center gap-2", !bordered && "px-4 pt-3"), children: [
471
- search && /* @__PURE__ */ jsx2(
472
- SearchInput,
1282
+ maxHeight,
1283
+ expansion,
1284
+ pinOf: effectivePin,
1285
+ resizable,
1286
+ widthOverrides,
1287
+ setWidth: (id, width) => setWidthOverrides((current) => {
1288
+ const next = { ...current };
1289
+ if (width === void 0) delete next[id];
1290
+ else next[id] = width;
1291
+ return next;
1292
+ }),
1293
+ reorder: reorderable ? { active: reorderActive, move: moveRow } : void 0,
1294
+ group: group ? {
1295
+ label: (row) => /* @__PURE__ */ jsx4(
1296
+ GroupLabel,
473
1297
  {
474
- size: "md",
475
- label: search.label ?? "Search",
476
- placeholder: search.placeholder ?? "Search\u2026",
477
- value: searchValue,
478
- onChange: (event) => setSearchValue(event.target.value),
479
- onClear: () => setSearchValue(""),
480
- className: "w-full max-w-[280px]"
1298
+ groupingValue: String(row.groupingValue ?? ""),
1299
+ by: group.by,
1300
+ format: group.by && group.by !== "value" ? void 0 : formatOf(group.key),
1301
+ options: format
481
1302
  }
482
1303
  ),
483
- toolbar,
484
- showColumnMenu && /* @__PURE__ */ jsx2("div", { className: "ml-auto", children: /* @__PURE__ */ jsx2(DataTableViewOptions, { table }) })
1304
+ summary: (row) => groupSummary(row, group.summary ?? [], formatOf, format)
1305
+ } : void 0
1306
+ };
1307
+ return /* @__PURE__ */ jsxs4("div", { "data-slot": "data-table", className: cn("relative flex flex-col gap-4", className), children: [
1308
+ tabsFilters.length > 0 && /* @__PURE__ */ jsx4("div", { className: cn("flex flex-wrap items-center gap-2", !bordered && "px-4 pt-3"), children: tabsFilters.map((column) => /* @__PURE__ */ jsx4(DataTableTabsFilter, { column }, column.id)) }),
1309
+ showToolbar && /* @__PURE__ */ jsxs4("div", { className: cn("flex items-center justify-between gap-2", !bordered && "px-4 pt-3"), children: [
1310
+ /* @__PURE__ */ jsxs4("div", { className: "flex flex-1 flex-wrap items-center gap-2", children: [
1311
+ search && /* @__PURE__ */ jsx4(
1312
+ Input,
1313
+ {
1314
+ type: "search",
1315
+ "aria-label": search.label ?? "Filter",
1316
+ placeholder: search.placeholder ?? "Filter...",
1317
+ value: searchValue,
1318
+ onChange: (event) => setSearchValue(event.target.value),
1319
+ className: "h-8 w-[150px] lg:w-[250px]"
1320
+ }
1321
+ ),
1322
+ filterColumns.map(
1323
+ (column) => column.columnDef.meta?.filter?.variant === "buttons" ? /* @__PURE__ */ jsx4(DataTableButtonFilter, { column }, column.id) : column.columnDef.meta?.filter?.variant === "tabs" ? null : /* @__PURE__ */ jsx4(DataTableFacetedFilter, { column }, column.id)
1324
+ ),
1325
+ columnFilters.some((f) => isToolbarFilter(f.id)) && /* @__PURE__ */ jsxs4(
1326
+ Button,
1327
+ {
1328
+ variant: "ghost",
1329
+ size: "sm",
1330
+ onClick: () => table.setColumnFilters((current) => current.filter((f) => !isToolbarFilter(f.id))),
1331
+ children: [
1332
+ "Reset",
1333
+ /* @__PURE__ */ jsx4(XIcon2, {})
1334
+ ]
1335
+ }
1336
+ ),
1337
+ toolbar
1338
+ ] }),
1339
+ showColumnMenu && /* @__PURE__ */ jsx4("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx4(DataTableViewOptions, { table }) })
485
1340
  ] }),
486
- /* @__PURE__ */ jsx2("p", { role: "status", "aria-live": "polite", className: "sr-only", children: filtering && !loading ? `${resultCount} ${resultCount === 1 ? "result" : "results"}` : "" }),
487
- /* @__PURE__ */ jsxs2("div", { ref: wrapRef, className: cn("overflow-hidden bg-default", bordered && "rounded-xl border border-default"), children: [
488
- mode === "cards" && caption && /* @__PURE__ */ jsx2("div", { id: captionId, className: "px-4 pt-3 text-left text-body-sm text-default-secondary", children: caption }),
489
- mode === "cards" ? maxHeight ? /* @__PURE__ */ jsx2(CardScroll, { label, maxHeight, children: /* @__PURE__ */ jsx2(CardList, { ...view }) }) : /* @__PURE__ */ jsx2(CardList, { ...view }) : /* @__PURE__ */ jsx2(TableView, { ...view }),
490
- showPager && /* @__PURE__ */ jsx2("div", { className: "border-t border-default px-4 py-3", children: /* @__PURE__ */ jsx2(DataTablePagination, { table, pageSizeOptions }) }),
491
- footer && /* @__PURE__ */ jsx2("div", { className: "border-t border-default px-4 py-3", children: footer })
492
- ] })
1341
+ /* @__PURE__ */ jsx4("p", { role: "status", "aria-live": "polite", className: "sr-only", children: filtering && !loading ? `${resultCount} ${resultCount === 1 ? "result" : "results"}` : "" }),
1342
+ /* @__PURE__ */ jsxs4("div", { ref: wrapRef, className: cn("overflow-hidden bg-background", bordered && "rounded-md border"), children: [
1343
+ mode === "cards" && caption && /* @__PURE__ */ jsx4("div", { id: captionId, className: "px-4 pt-3 text-left text-sm text-muted-foreground", children: caption }),
1344
+ mode === "cards" ? maxHeight ? /* @__PURE__ */ jsx4(CardScroll, { label, maxHeight, children: /* @__PURE__ */ jsx4(CardList, { ...view }) }) : /* @__PURE__ */ jsx4(CardList, { ...view }) : /* @__PURE__ */ jsx4(TableView, { ...view }),
1345
+ footer && /* @__PURE__ */ jsx4("div", { className: "border-t p-2", children: footer })
1346
+ ] }),
1347
+ showPager && /* @__PURE__ */ jsx4("div", { className: cn(!bordered && "px-2 pb-3"), children: /* @__PURE__ */ jsx4(DataTablePagination, { table, pageSizeOptions }) })
493
1348
  ] });
494
1349
  }
1350
+ var verticalOnly = ({ transform }) => ({ ...transform, x: 0 });
495
1351
  function titleColumnId(columns) {
496
1352
  const content = columns.filter((column) => column.id !== SELECT_COLUMN_ID);
497
1353
  return (content.find((column) => column.columnDef.meta?.mobile === "title") ?? content[0])?.id;
@@ -500,7 +1356,6 @@ function TableView({
500
1356
  table,
501
1357
  label,
502
1358
  caption,
503
- density,
504
1359
  align,
505
1360
  loading,
506
1361
  loadingRows,
@@ -510,40 +1365,63 @@ function TableView({
510
1365
  renderRowLink,
511
1366
  getRowTone,
512
1367
  getRowDimmed,
513
- maxHeight
1368
+ getRowLabel,
1369
+ maxHeight,
1370
+ expansion,
1371
+ pinOf,
1372
+ resizable,
1373
+ widthOverrides,
1374
+ setWidth,
1375
+ reorder,
1376
+ group
514
1377
  }) {
515
- const d = DENSITY[density];
1378
+ const d = D;
516
1379
  const columns = table.getVisibleLeafColumns();
1380
+ const sensors = useSensors(
1381
+ useSensor(PointerSensor, { activationConstraint: { distance: 4 } }),
1382
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
1383
+ );
517
1384
  const scroll = useScrollEdges();
518
- const headers = useHeaderWidths(HEADER_PADDING_PX[density], columns.map((column) => column.id).join());
519
- const columnPx = (column) => Math.max(widthToPx(column.columnDef.meta?.width), headers.widths[column.id] ?? 0);
1385
+ const headers = useHeaderWidths(HEADER_PADDING_PX, columns.map((column) => column.id).join());
1386
+ const columnPx = (column) => widthOverrides[column.id] ?? Math.max(widthToPx(column.columnDef.meta?.width), headers.widths[column.id] ?? 0);
520
1387
  const minWidth = columns.reduce((sum, column) => sum + columnPx(column), 0);
521
1388
  const showPlaceholder = loading || placeholder !== null;
522
- const first = columns[0];
523
- const last = columns[columns.length - 1];
524
- const stickyStart = scroll.overflowing && first?.columnDef.meta?.sticky === "start" ? first.id : void 0;
525
- const stickyEnd = scroll.overflowing && last?.columnDef.meta?.sticky === "end" && last !== first ? last.id : void 0;
526
- const hasSticky = Boolean(stickyStart || stickyEnd);
1389
+ const offsets = usePinOffsets(
1390
+ [
1391
+ columns.map((column) => `${column.id}:${pinOf(column.id) ?? ""}`).join(),
1392
+ JSON.stringify(widthOverrides),
1393
+ Object.values(headers.widths).join(),
1394
+ scroll.overflowing
1395
+ ].join("|")
1396
+ );
1397
+ const pinned = (id) => scroll.overflowing ? pinOf(id) : void 0;
1398
+ const startIds = columns.filter((column) => pinned(column.id) === "start").map((column) => column.id);
1399
+ const endIds = columns.filter((column) => pinned(column.id) === "end").map((column) => column.id);
1400
+ const hasSticky = startIds.length + endIds.length > 0;
527
1401
  const titleId = titleColumnId(columns);
528
1402
  const rowAction = getRowHref ? "link" : onRowClick ? "click" : null;
529
- const stickyClass = (id, header) => clsx(
530
- id === stickyStart && [
531
- "sticky left-0 z-raised",
532
- // A hairline where content slides under the pinned column, once it has scrolled.
533
- !scroll.atStart && "shadow-[inset_-1px_0_0_var(--color-border-default-default)]"
534
- ],
535
- id === stickyEnd && [
536
- "sticky right-0 z-raised",
537
- !scroll.atEnd && "shadow-[inset_1px_0_0_var(--color-border-default-default)]"
538
- ],
539
- (id === stickyStart || id === stickyEnd) && (header ? "bg-default-secondary" : ["bg-default", rowAction && "group-hover:bg-default-secondary"])
540
- );
1403
+ const stickyProps = (id, header) => {
1404
+ const side = pinned(id);
1405
+ if (!side) return { className: "" };
1406
+ return {
1407
+ className: clsx(
1408
+ "sticky z-raised",
1409
+ // A hairline where content slides under the pinned columns, once it has scrolled.
1410
+ side === "start" && id === startIds[startIds.length - 1] && !scroll.atStart && "shadow-[inset_-1px_0_0_var(--border)]",
1411
+ side === "end" && id === endIds[0] && !scroll.atEnd && "shadow-[inset_1px_0_0_var(--border)]",
1412
+ header ? "bg-background" : ["bg-background", rowAction && "group-hover:bg-muted"]
1413
+ ),
1414
+ style: side === "start" ? { insetInlineStart: offsets.start[id] ?? 0 } : { insetInlineEnd: offsets.end[id] ?? 0 }
1415
+ };
1416
+ };
1417
+ const stickyStart = startIds[0];
1418
+ const stickyEnd = endIds[0];
541
1419
  const scrolls = scroll.overflowing || Boolean(maxHeight) && scroll.overflowingY;
542
1420
  const direction = scroll.overflowing && maxHeight && scroll.overflowingY ? "scrolls" : scroll.overflowing ? "scrolls horizontally" : "scrolls vertically";
543
1421
  const regionLabel = `${label ?? "Table"} (${direction})`;
544
- const pinnedHeader = maxHeight ? clsx("sticky top-0 z-sticky bg-default-secondary", !scroll.atTop && "shadow-[inset_0_-1px_0_var(--color-border-default-default)]") : void 0;
545
- return /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
546
- /* @__PURE__ */ jsx2(
1422
+ const pinnedHeader = maxHeight ? clsx("sticky top-0 z-sticky bg-background", !scroll.atTop && "shadow-[inset_0_-1px_0_var(--border)]") : void 0;
1423
+ return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
1424
+ /* @__PURE__ */ jsx4(
547
1425
  "div",
548
1426
  {
549
1427
  ref: scroll.ref,
@@ -555,105 +1433,164 @@ function TableView({
555
1433
  ),
556
1434
  style: maxHeight ? { maxHeight } : void 0,
557
1435
  ...scrolls ? { role: "region", tabIndex: 0, "aria-label": regionLabel } : {},
558
- children: /* @__PURE__ */ jsxs2(
559
- "table",
1436
+ children: /* @__PURE__ */ jsx4(
1437
+ DndWrapper,
560
1438
  {
561
- className: "w-full table-fixed border-collapse text-left",
562
- style: showPlaceholder ? void 0 : { minWidth },
563
- "aria-busy": loading || void 0,
564
- children: [
565
- caption ? /* @__PURE__ */ jsx2("caption", { className: "px-4 pt-3 text-left text-body-sm text-default-secondary", children: caption }) : label && /* @__PURE__ */ jsx2("caption", { className: "sr-only", children: label }),
566
- /* @__PURE__ */ jsx2("colgroup", { children: columns.map((column) => {
567
- const meta = column.columnDef.meta;
568
- const floor = headers.widths[column.id] ?? 0;
569
- return /* @__PURE__ */ jsx2(
570
- "col",
571
- {
572
- style: meta?.grow || !meta?.width ? void 0 : { width: floor > widthToPx(meta.width) ? floor : meta.width }
573
- },
574
- column.id
575
- );
576
- }) }),
577
- /* @__PURE__ */ jsx2("thead", { children: table.getHeaderGroups().map((group) => /* @__PURE__ */ jsx2("tr", { className: "bg-default-secondary", children: group.headers.map((header) => {
578
- const meta = header.column.columnDef.meta;
579
- const sortable = header.column.getCanSort();
580
- const sorted = header.column.getIsSorted();
581
- const definition = header.column.columnDef.header;
582
- return /* @__PURE__ */ jsx2(
583
- "th",
584
- {
585
- scope: "col",
586
- colSpan: header.colSpan,
587
- "aria-sort": sortable ? sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : "none" : void 0,
588
- className: cn(
589
- d.headerCell,
590
- d.headerText,
591
- TEXT_ALIGN[meta?.align ?? "start"],
592
- !meta?.interactive && "overflow-hidden",
593
- stickyClass(header.column.id, true),
594
- pinnedHeader,
595
- meta?.headerClassName
596
- ),
597
- children: header.isPlaceholder ? null : typeof definition === "string" || definition === void 0 ? /* @__PURE__ */ jsx2("span", { ref: meta?.hideHeader ? void 0 : headers.register(header.column.id), className: "inline-block", children: /* @__PURE__ */ jsx2(DataTableColumnHeader, { column: header.column }) }) : flexRender(definition, header.getContext())
598
- },
599
- header.id
600
- );
601
- }) }, group.id)) }),
602
- /* @__PURE__ */ jsx2("tbody", { children: loading && !placeholder ? Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ jsx2("tr", { className: clsx(index > 0 && "border-t border-default"), children: columns.map((column) => /* @__PURE__ */ jsx2("td", { className: clsx(d.bodyCell, "align-middle"), children: /* @__PURE__ */ jsx2(Skeleton, { className: column.columnDef.meta?.grow ? "w-[70%]" : "w-[55%]" }) }, column.id)) }, `skeleton-${index}`)) : placeholder ? /* @__PURE__ */ jsx2("tr", { children: /* @__PURE__ */ jsx2("td", { colSpan: columns.length, className: "px-4", children: placeholder }) }) : table.getRowModel().rows.map((row) => /* @__PURE__ */ jsx2(
603
- BodyRow,
604
- {
605
- row,
606
- density,
607
- align,
608
- titleId,
609
- rowAction,
610
- hasSticky,
611
- stickyClass,
612
- onRowClick,
613
- getRowHref,
614
- renderRowLink,
615
- getRowTone,
616
- getRowDimmed
617
- },
618
- row.id
619
- )) })
620
- ]
1439
+ enabled: Boolean(reorder),
1440
+ sensors,
1441
+ ids: table.getRowModel().rows.map((row) => row.id),
1442
+ onDragEnd: (event) => {
1443
+ const rows = table.getRowModel().rows;
1444
+ const from = rows.find((row) => row.id === event.active.id)?.index;
1445
+ const to = rows.find((row) => row.id === event.over?.id)?.index;
1446
+ if (from !== void 0 && to !== void 0 && from !== to) reorder?.move(from, to);
1447
+ },
1448
+ children: /* @__PURE__ */ jsxs4(
1449
+ "table",
1450
+ {
1451
+ className: "w-full table-fixed border-collapse caption-bottom text-sm text-start",
1452
+ style: showPlaceholder ? void 0 : { minWidth },
1453
+ "aria-busy": loading || void 0,
1454
+ children: [
1455
+ caption ? /* @__PURE__ */ jsx4("caption", { className: "text-muted-foreground py-4 text-sm", children: caption }) : label && /* @__PURE__ */ jsx4("caption", { className: "sr-only", children: label }),
1456
+ /* @__PURE__ */ jsx4("colgroup", { children: columns.map((column) => {
1457
+ const meta = column.columnDef.meta;
1458
+ const floor = headers.widths[column.id] ?? 0;
1459
+ return /* @__PURE__ */ jsx4(
1460
+ "col",
1461
+ {
1462
+ style: widthOverrides[column.id] !== void 0 ? { width: widthOverrides[column.id] } : meta?.grow || !meta?.width ? void 0 : { width: floor > widthToPx(meta.width) ? floor : meta.width }
1463
+ },
1464
+ column.id
1465
+ );
1466
+ }) }),
1467
+ /* @__PURE__ */ jsx4("thead", { children: table.getHeaderGroups().map((group2) => /* @__PURE__ */ jsx4("tr", { className: "border-b", children: group2.headers.map((header) => {
1468
+ const meta = header.column.columnDef.meta;
1469
+ const sortable = header.column.getCanSort();
1470
+ const sorted = header.column.getIsSorted();
1471
+ const definition = header.column.columnDef.header;
1472
+ const sticky = stickyProps(header.column.id, true);
1473
+ const canResize = resizable && !UTILITY_COLUMNS.includes(header.column.id) && !meta?.hideHeader;
1474
+ return /* @__PURE__ */ jsxs4(
1475
+ "th",
1476
+ {
1477
+ ref: offsets.register(header.column.id),
1478
+ scope: "col",
1479
+ colSpan: header.colSpan,
1480
+ style: sticky.style,
1481
+ "aria-sort": sortable ? sorted === "asc" ? "ascending" : sorted === "desc" ? "descending" : "none" : void 0,
1482
+ className: cn(
1483
+ d.headerCell,
1484
+ d.headerText,
1485
+ TEXT_ALIGN[meta?.align ?? "start"],
1486
+ !meta?.interactive && "overflow-hidden",
1487
+ canResize && "relative",
1488
+ sticky.className,
1489
+ pinnedHeader,
1490
+ meta?.headerClassName
1491
+ ),
1492
+ children: [
1493
+ header.isPlaceholder ? null : typeof definition === "string" || definition === void 0 ? /* @__PURE__ */ jsx4("span", { ref: meta?.hideHeader ? void 0 : headers.register(header.column.id), className: "inline-block", children: /* @__PURE__ */ jsx4(DataTableColumnHeader, { column: header.column, table }) }) : flexRender(definition, header.getContext()),
1494
+ canResize && /* @__PURE__ */ jsx4(
1495
+ ResizeHandle,
1496
+ {
1497
+ label: columnLabel(header.column),
1498
+ floor: headers.widths[header.column.id] ?? 48,
1499
+ width: () => offsets.width(header.column.id),
1500
+ onResize: (width) => setWidth(header.column.id, width)
1501
+ }
1502
+ )
1503
+ ]
1504
+ },
1505
+ header.id
1506
+ );
1507
+ }) }, group2.id)) }),
1508
+ /* @__PURE__ */ jsx4("tbody", { className: "[&_tr:last-child]:border-0", children: loading && !placeholder ? Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ jsx4("tr", { className: "border-b", children: columns.map((column) => /* @__PURE__ */ jsx4("td", { className: clsx(d.bodyCell, "align-middle"), children: /* @__PURE__ */ jsx4(Skeleton, { className: column.columnDef.meta?.grow ? "h-4 w-[70%]" : "h-4 w-[55%]" }) }, column.id)) }, `skeleton-${index}`)) : placeholder ? /* @__PURE__ */ jsx4("tr", { children: /* @__PURE__ */ jsx4("td", { colSpan: columns.length, className: "h-24 px-2 text-center", children: placeholder }) }) : table.getRowModel().rows.map((row) => {
1509
+ if (row.getIsGrouped() && group) {
1510
+ return /* @__PURE__ */ jsx4(GroupRow, { row, span: columns.length, group }, row.id);
1511
+ }
1512
+ const props = {
1513
+ row,
1514
+ align,
1515
+ titleId,
1516
+ rowAction,
1517
+ hasSticky,
1518
+ stickyProps,
1519
+ onRowClick,
1520
+ getRowHref,
1521
+ renderRowLink,
1522
+ getRowTone,
1523
+ getRowDimmed
1524
+ };
1525
+ return /* @__PURE__ */ jsxs4(Fragment4, { children: [
1526
+ reorder ? /* @__PURE__ */ jsx4(
1527
+ SortableBodyRow,
1528
+ {
1529
+ ...props,
1530
+ disabled: !reorder.active,
1531
+ label: `Reorder ${getRowLabel?.(row.original) ?? "row"}`
1532
+ }
1533
+ ) : /* @__PURE__ */ jsx4(BodyRow, { ...props }),
1534
+ expansion?.isOpen(row.id) && /* @__PURE__ */ jsx4("tr", { "data-slot": "data-table-detail", className: "border-b bg-muted/30", children: /* @__PURE__ */ jsx4("td", { colSpan: columns.length, className: "p-0", children: /* @__PURE__ */ jsx4(
1535
+ "div",
1536
+ {
1537
+ id: detailId(row.id),
1538
+ role: "region",
1539
+ "aria-label": `Details for ${expansion.label(row.original)}`,
1540
+ className: "p-4",
1541
+ children: expansion.render(row.original)
1542
+ }
1543
+ ) }) })
1544
+ ] }, row.id);
1545
+ }) })
1546
+ ]
1547
+ }
1548
+ )
621
1549
  }
622
1550
  )
623
1551
  }
624
1552
  ),
625
- scroll.overflowing && !scroll.atStart && !stickyStart && /* @__PURE__ */ jsx2("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 left-0 w-6 bg-gradient-to-r from-default-secondary to-transparent" }),
626
- scroll.overflowing && !scroll.atEnd && !stickyEnd && /* @__PURE__ */ jsx2("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 right-0 w-6 bg-gradient-to-l from-default-secondary to-transparent" })
1553
+ scroll.overflowing && !scroll.atStart && !stickyStart && /* @__PURE__ */ jsx4("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 left-0 w-6 bg-gradient-to-r from-muted to-transparent" }),
1554
+ scroll.overflowing && !scroll.atEnd && !stickyEnd && /* @__PURE__ */ jsx4("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-y-0 right-0 w-6 bg-gradient-to-l from-muted to-transparent" })
627
1555
  ] });
628
1556
  }
629
1557
  function BodyRow({
630
1558
  row,
631
- density,
632
1559
  align,
633
1560
  titleId,
634
1561
  rowAction,
635
1562
  hasSticky,
636
- stickyClass,
1563
+ stickyProps,
637
1564
  onRowClick,
638
1565
  getRowHref,
639
1566
  renderRowLink,
640
1567
  getRowTone,
641
- getRowDimmed
1568
+ getRowDimmed,
1569
+ sortable
642
1570
  }) {
643
- const d = DENSITY[density];
1571
+ const d = D;
644
1572
  const href = getRowHref?.(row.original);
645
- return /* @__PURE__ */ jsx2(
1573
+ return /* @__PURE__ */ jsx4(
646
1574
  TableRow,
647
1575
  {
648
- selected: row.getIsSelected() || void 0,
649
- tone: getRowTone?.(row.original),
650
- dimmed: getRowDimmed?.(row.original),
1576
+ ref: sortable?.ref,
1577
+ style: sortable?.style,
1578
+ "data-dragging": sortable?.dragging || void 0,
1579
+ "aria-selected": row.getIsSelected() || void 0,
1580
+ "data-state": row.getIsSelected() ? "selected" : void 0,
1581
+ "data-tone": (() => {
1582
+ const tone = getRowTone?.(row.original);
1583
+ return tone && tone !== "default" ? tone : void 0;
1584
+ })(),
1585
+ "data-dimmed": getRowDimmed?.(row.original) || void 0,
651
1586
  className: cn(
652
1587
  "group",
653
- rowAction && ["cursor-pointer", hasSticky && "hover:bg-default-secondary"],
1588
+ ROW_TONE,
1589
+ "data-[dragging]:relative data-[dragging]:z-overlay data-[dragging]:bg-background data-[dragging]:shadow-lg",
1590
+ rowAction && ["cursor-pointer", hasSticky && "hover:bg-muted"],
654
1591
  // outline, not ring: `ring-*` is box-shadow, which browsers do not paint on a <tr>
655
1592
  // under border-collapse.
656
- rowAction === "click" && "outline-none focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-brand"
1593
+ rowAction === "click" && "outline-none focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
657
1594
  ),
658
1595
  tabIndex: rowAction === "click" ? 0 : void 0,
659
1596
  onClick: rowAction === "link" ? (event) => {
@@ -667,11 +1604,12 @@ function BodyRow({
667
1604
  onRowClick(row.original);
668
1605
  }
669
1606
  } : void 0,
670
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx2(
1607
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx4(
671
1608
  BodyCell,
672
1609
  {
673
1610
  cell,
674
- className: cn(d.bodyCell, VERTICAL[align], stickyClass(cell.column.id, false)),
1611
+ className: cn(d.bodyCell, VERTICAL[align], stickyProps(cell.column.id, false).className),
1612
+ style: stickyProps(cell.column.id, false).style,
675
1613
  link: href && cell.column.id === titleId ? href : void 0,
676
1614
  renderRowLink
677
1615
  },
@@ -683,6 +1621,7 @@ function BodyRow({
683
1621
  function BodyCell({
684
1622
  cell,
685
1623
  className,
1624
+ style,
686
1625
  link,
687
1626
  renderRowLink
688
1627
  }) {
@@ -696,9 +1635,10 @@ function BodyCell({
696
1635
  children: content
697
1636
  }, cell.row.original);
698
1637
  }
699
- return /* @__PURE__ */ jsx2(
1638
+ return /* @__PURE__ */ jsx4(
700
1639
  "td",
701
1640
  {
1641
+ style,
702
1642
  className: cn(
703
1643
  className,
704
1644
  TEXT_ALIGN[meta?.align ?? "start"],
@@ -707,13 +1647,180 @@ function BodyCell({
707
1647
  !meta?.interactive && "overflow-hidden",
708
1648
  meta?.cellClassName
709
1649
  ),
710
- children: meta?.interactive ? /* @__PURE__ */ jsx2(CellInteractionGuard, { children: content }) : content
1650
+ children: meta?.interactive ? /* @__PURE__ */ jsx4(CellInteractionGuard, { children: content }) : content
1651
+ }
1652
+ );
1653
+ }
1654
+ function SortableBodyRow(props) {
1655
+ const { disabled, label, ...rowProps } = props;
1656
+ const sortable = useSortable({ id: props.row.id, disabled });
1657
+ return /* @__PURE__ */ jsx4(
1658
+ RowDragContext.Provider,
1659
+ {
1660
+ value: {
1661
+ attributes: sortable.attributes,
1662
+ listeners: sortable.listeners,
1663
+ setActivatorNodeRef: sortable.setActivatorNodeRef,
1664
+ disabled,
1665
+ label
1666
+ },
1667
+ children: /* @__PURE__ */ jsx4(
1668
+ BodyRow,
1669
+ {
1670
+ ...rowProps,
1671
+ sortable: {
1672
+ ref: sortable.setNodeRef,
1673
+ style: { transform: CSS.Translate.toString(sortable.transform), transition: sortable.transition },
1674
+ dragging: sortable.isDragging
1675
+ }
1676
+ }
1677
+ )
1678
+ }
1679
+ );
1680
+ }
1681
+ function DndWrapper({
1682
+ enabled,
1683
+ sensors,
1684
+ ids,
1685
+ onDragEnd,
1686
+ children
1687
+ }) {
1688
+ if (!enabled) return /* @__PURE__ */ jsx4(Fragment5, { children });
1689
+ return /* @__PURE__ */ jsx4(DndContext, { sensors, collisionDetection: closestCenter, modifiers: [verticalOnly], onDragEnd, children: /* @__PURE__ */ jsx4(SortableContext, { items: ids, strategy: verticalListSortingStrategy, children }) });
1690
+ }
1691
+ function GroupRow({
1692
+ row,
1693
+ span,
1694
+ group
1695
+ }) {
1696
+ const open = row.getIsExpanded();
1697
+ const count = row.getLeafRows().filter((leaf) => !leaf.getIsGrouped()).length;
1698
+ const summary = group.summary(row);
1699
+ return /* @__PURE__ */ jsx4("tr", { "data-slot": "data-table-group", className: "border-b bg-muted/50", children: /* @__PURE__ */ jsx4("td", { colSpan: span, className: "p-0", children: /* @__PURE__ */ jsxs4(
1700
+ "button",
1701
+ {
1702
+ type: "button",
1703
+ "aria-expanded": open,
1704
+ onClick: row.getToggleExpandedHandler(),
1705
+ className: cn("flex h-10 w-full items-center gap-2 px-2 text-start text-sm font-medium", FOCUS_RING_INSET),
1706
+ children: [
1707
+ /* @__PURE__ */ jsx4(ChevronRightIcon3, { "aria-hidden": true, className: cn("size-4 shrink-0 transition-transform", open && "rotate-90") }),
1708
+ /* @__PURE__ */ jsx4("span", { className: "min-w-0 truncate", children: group.label(row) }),
1709
+ /* @__PURE__ */ jsxs4(Badge, { variant: "secondary", className: "h-5 rounded-full px-1.5 font-normal tabular-nums", children: [
1710
+ count,
1711
+ /* @__PURE__ */ jsxs4("span", { className: "sr-only", children: [
1712
+ " ",
1713
+ count === 1 ? "row" : "rows"
1714
+ ] })
1715
+ ] }),
1716
+ summary.length > 0 && /* @__PURE__ */ jsx4("span", { className: "ms-auto flex items-center gap-3 text-xs font-normal text-muted-foreground tabular-nums", children: summary.map((item) => /* @__PURE__ */ jsxs4("span", { children: [
1717
+ item.label && /* @__PURE__ */ jsxs4("span", { children: [
1718
+ item.label,
1719
+ " "
1720
+ ] }),
1721
+ /* @__PURE__ */ jsx4("span", { className: "font-medium text-foreground", children: item.text })
1722
+ ] }, item.key)) })
1723
+ ]
1724
+ }
1725
+ ) }) });
1726
+ }
1727
+ function usePinOffsets(key) {
1728
+ const nodes = useRef(/* @__PURE__ */ new Map());
1729
+ const [offsets, setOffsets] = useState({
1730
+ start: {},
1731
+ end: {}
1732
+ });
1733
+ useLayoutEffect(() => {
1734
+ const cells = [...nodes.current.entries()].filter(([, node]) => node.isConnected);
1735
+ cells.sort(([, a], [, b]) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
1736
+ const start = {};
1737
+ const end = {};
1738
+ let acc = 0;
1739
+ for (const [id, node] of cells) {
1740
+ start[id] = acc;
1741
+ acc += node.offsetWidth;
1742
+ }
1743
+ acc = 0;
1744
+ for (const [id, node] of [...cells].reverse()) {
1745
+ end[id] = acc;
1746
+ acc += node.offsetWidth;
711
1747
  }
1748
+ setOffsets(
1749
+ (current) => JSON.stringify(current) === JSON.stringify({ start, end }) ? current : { start, end }
1750
+ );
1751
+ }, [key]);
1752
+ const register = useCallback(
1753
+ (id) => (node) => {
1754
+ if (node) nodes.current.set(id, node);
1755
+ else nodes.current.delete(id);
1756
+ },
1757
+ []
1758
+ );
1759
+ const width = (id) => nodes.current.get(id)?.offsetWidth ?? 0;
1760
+ return { ...offsets, register, width };
1761
+ }
1762
+ function ResizeHandle({
1763
+ label,
1764
+ floor,
1765
+ width,
1766
+ onResize
1767
+ }) {
1768
+ const [now, setNow] = useState();
1769
+ const set = (next) => {
1770
+ const clamped = next === void 0 ? void 0 : Math.max(floor, Math.round(next));
1771
+ setNow(clamped);
1772
+ onResize(clamped);
1773
+ };
1774
+ return (
1775
+ // A focusable separator is a widget (ARIA "window splitter"): keyboard and pointer resize it.
1776
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
1777
+ /* @__PURE__ */ jsx4(
1778
+ "div",
1779
+ {
1780
+ role: "separator",
1781
+ "aria-orientation": "vertical",
1782
+ "aria-label": `Resize ${label}`,
1783
+ "aria-valuenow": now ?? width(),
1784
+ "aria-valuemin": floor,
1785
+ tabIndex: 0,
1786
+ onPointerDown: (event) => {
1787
+ event.preventDefault();
1788
+ const startX = event.clientX;
1789
+ const startWidth = width();
1790
+ const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
1791
+ const target = event.currentTarget;
1792
+ target.setPointerCapture?.(event.pointerId);
1793
+ const move = (e) => set(startWidth + (rtl ? startX - e.clientX : e.clientX - startX));
1794
+ const up = () => {
1795
+ target.removeEventListener("pointermove", move);
1796
+ target.removeEventListener("pointerup", up);
1797
+ };
1798
+ target.addEventListener("pointermove", move);
1799
+ target.addEventListener("pointerup", up);
1800
+ },
1801
+ onDoubleClick: () => set(void 0),
1802
+ onKeyDown: (event) => {
1803
+ if (event.key === "ArrowRight" || event.key === "ArrowLeft") {
1804
+ event.preventDefault();
1805
+ const rtl = getComputedStyle(event.currentTarget).direction === "rtl";
1806
+ const grow = event.key === "ArrowRight" !== rtl;
1807
+ set(width() + (grow ? 16 : -16));
1808
+ } else if (event.key === "Home") {
1809
+ event.preventDefault();
1810
+ set(void 0);
1811
+ }
1812
+ },
1813
+ className: cn(
1814
+ "absolute inset-y-0 end-0 z-raised w-2 translate-x-1/2 cursor-col-resize touch-none select-none rtl:-translate-x-1/2",
1815
+ "after:absolute after:inset-y-2 after:start-1/2 after:w-px after:bg-border hover:after:bg-ring focus-visible:outline-none focus-visible:after:w-0.5 focus-visible:after:bg-ring"
1816
+ )
1817
+ }
1818
+ )
712
1819
  );
713
1820
  }
714
1821
  function CardScroll({ label, maxHeight, children }) {
715
1822
  const scroll = useScrollEdges();
716
- return /* @__PURE__ */ jsx2(
1823
+ return /* @__PURE__ */ jsx4(
717
1824
  "div",
718
1825
  {
719
1826
  ref: scroll.ref,
@@ -738,14 +1845,16 @@ function CardList({
738
1845
  renderRowLink,
739
1846
  getRowTone,
740
1847
  getRowDimmed,
741
- getRowLabel
1848
+ getRowLabel,
1849
+ expansion,
1850
+ group
742
1851
  }) {
743
- if (placeholder) return /* @__PURE__ */ jsx2("div", { className: "px-4", children: placeholder });
1852
+ if (placeholder) return /* @__PURE__ */ jsx4("div", { className: "px-4", children: placeholder });
744
1853
  if (loading) {
745
- return /* @__PURE__ */ jsx2("ul", { "aria-label": label, "aria-labelledby": !label && caption ? captionId : void 0, "aria-busy": "true", className: "divide-y divide-default", children: Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ jsxs2("li", { className: "flex flex-col gap-3 p-4", children: [
746
- /* @__PURE__ */ jsx2(Skeleton, { className: "w-2/3" }),
747
- /* @__PURE__ */ jsx2(Skeleton, { className: "w-1/2" }),
748
- /* @__PURE__ */ jsx2(Skeleton, { className: "w-5/6" })
1854
+ return /* @__PURE__ */ jsx4("ul", { "aria-label": label, "aria-labelledby": !label && caption ? captionId : void 0, "aria-busy": "true", className: "divide-y divide-border", children: Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ jsxs4("li", { className: "flex flex-col gap-3 p-4", children: [
1855
+ /* @__PURE__ */ jsx4(Skeleton, { className: "h-4 w-2/3" }),
1856
+ /* @__PURE__ */ jsx4(Skeleton, { className: "h-4 w-1/2" }),
1857
+ /* @__PURE__ */ jsx4(Skeleton, { className: "h-4 w-5/6" })
749
1858
  ] }, index)) });
750
1859
  }
751
1860
  const columns = table.getVisibleLeafColumns();
@@ -756,18 +1865,36 @@ function CardList({
756
1865
  const trigger = clsx(
757
1866
  "block w-full min-w-0 text-left focus-visible:outline-none",
758
1867
  "after:absolute after:inset-0 after:content-['']",
759
- "focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-brand"
1868
+ "focus-visible:after:ring-[3px] focus-visible:after:ring-inset focus-visible:after:ring-ring/50"
760
1869
  );
761
1870
  return (
762
1871
  // Card mode un-truncates: on touch there is no hover tooltip, so a clipped value would be
763
1872
  // unreadable. `.truncate` cell renderers wrap here instead.
764
- /* @__PURE__ */ jsx2(
1873
+ /* @__PURE__ */ jsx4(
765
1874
  "ul",
766
1875
  {
767
1876
  "aria-label": label,
768
1877
  "aria-labelledby": !label && caption ? captionId : void 0,
769
- className: "divide-y divide-default [&_.truncate]:whitespace-normal [&_.truncate]:[overflow-wrap:anywhere]",
1878
+ className: "divide-y divide-border [&_.truncate]:whitespace-normal [&_.truncate]:[overflow-wrap:anywhere]",
770
1879
  children: table.getRowModel().rows.map((row) => {
1880
+ if (row.getIsGrouped() && group) {
1881
+ const open = row.getIsExpanded();
1882
+ const count = row.getLeafRows().filter((leaf) => !leaf.getIsGrouped()).length;
1883
+ return /* @__PURE__ */ jsx4("li", { "data-slot": "data-table-group", className: "bg-muted/50", children: /* @__PURE__ */ jsxs4(
1884
+ "button",
1885
+ {
1886
+ type: "button",
1887
+ "aria-expanded": open,
1888
+ onClick: row.getToggleExpandedHandler(),
1889
+ className: cn("flex w-full items-center gap-2 px-4 py-2.5 text-start text-sm font-medium", FOCUS_RING_INSET),
1890
+ children: [
1891
+ /* @__PURE__ */ jsx4(ChevronRightIcon3, { "aria-hidden": true, className: cn("size-4 shrink-0 transition-transform", open && "rotate-90") }),
1892
+ /* @__PURE__ */ jsx4("span", { className: "min-w-0 flex-1", children: group.label(row) }),
1893
+ /* @__PURE__ */ jsx4(Badge, { variant: "secondary", className: "h-5 rounded-full px-1.5 font-normal tabular-nums", children: count })
1894
+ ]
1895
+ }
1896
+ ) }, row.id);
1897
+ }
771
1898
  const cells = new Map(row.getVisibleCells().map((cell) => [cell.column.id, cell]));
772
1899
  const render = (id) => {
773
1900
  const cell = id ? cells.get(id) : void 0;
@@ -776,7 +1903,7 @@ function CardList({
776
1903
  const href = getRowHref?.(row.original);
777
1904
  const titleContent = render(slots.title?.id);
778
1905
  const tone = getRowTone?.(row.original);
779
- return /* @__PURE__ */ jsxs2(
1906
+ return /* @__PURE__ */ jsxs4(
780
1907
  "li",
781
1908
  {
782
1909
  "data-state": row.getIsSelected() ? "selected" : void 0,
@@ -784,16 +1911,16 @@ function CardList({
784
1911
  "data-dimmed": getRowDimmed?.(row.original) || void 0,
785
1912
  className: cn(
786
1913
  "relative flex flex-col gap-3 p-4 transition-colors",
787
- (href || onRowClick) && "hover:bg-default-secondary/50",
788
- "data-[tone=muted]:bg-default-secondary data-[tone=brand]:bg-brand-tertiary",
789
- "data-[tone=positive]:bg-positive-tertiary data-[tone=warning]:bg-warning-tertiary",
790
- "data-[tone=danger]:bg-danger-tertiary data-[dimmed]:opacity-60",
791
- "data-[state=selected]:bg-brand-tertiary"
1914
+ (href || onRowClick) && "hover:bg-muted/50",
1915
+ "data-[tone=muted]:bg-muted data-[tone=brand]:bg-accent",
1916
+ "data-[tone=positive]:bg-success/10 data-[tone=warning]:bg-warning/10",
1917
+ "data-[tone=danger]:bg-destructive/10 data-[dimmed]:opacity-60",
1918
+ "data-[state=selected]:bg-accent"
792
1919
  ),
793
1920
  children: [
794
- /* @__PURE__ */ jsxs2("div", { className: "flex items-start gap-3", children: [
795
- selectable && /* @__PURE__ */ jsx2("div", { className: "relative z-raised shrink-0 pt-0.5", children: render(SELECT_COLUMN_ID) }),
796
- /* @__PURE__ */ jsx2("div", { className: "min-w-0 flex-1", children: href ? renderRowLink({ href, [ROW_LINK_ATTR]: "", className: trigger, children: titleContent }, row.original) : onRowClick ? /* @__PURE__ */ jsx2(
1921
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-start gap-3", children: [
1922
+ selectable && /* @__PURE__ */ jsx4("div", { className: "relative z-raised shrink-0 pt-0.5", children: render(SELECT_COLUMN_ID) }),
1923
+ /* @__PURE__ */ jsx4("div", { className: "min-w-0 flex-1", children: href ? renderRowLink({ href, [ROW_LINK_ATTR]: "", className: trigger, children: titleContent }, row.original) : onRowClick ? /* @__PURE__ */ jsx4(
797
1924
  "button",
798
1925
  {
799
1926
  type: "button",
@@ -805,13 +1932,31 @@ function CardList({
805
1932
  ) : titleContent }),
806
1933
  slots.status && // A status pill is `nowrap`, so a long label would spill off the card. Let it
807
1934
  // wrap inside the cap instead.
808
- /* @__PURE__ */ jsx2("div", { className: "flex max-w-[45%] shrink-0 justify-end [&_.whitespace-nowrap]:whitespace-normal", children: render(slots.status.id) }),
809
- slots.actions && /* @__PURE__ */ jsx2("div", { className: "relative z-raised shrink-0", children: /* @__PURE__ */ jsx2(CellInteractionGuard, { children: render(slots.actions.id) }) })
1935
+ /* @__PURE__ */ jsx4("div", { className: "flex max-w-[45%] shrink-0 justify-end [&_.whitespace-nowrap]:whitespace-normal", children: render(slots.status.id) }),
1936
+ slots.actions && /* @__PURE__ */ jsx4("div", { className: "relative z-raised shrink-0", children: /* @__PURE__ */ jsx4(CellInteractionGuard, { children: render(slots.actions.id) }) })
810
1937
  ] }),
811
- slots.fields.length > 0 && /* @__PURE__ */ jsx2("dl", { className: "grid grid-cols-[repeat(auto-fit,minmax(min(100%,8.5rem),1fr))] gap-x-4 gap-y-2.5", children: slots.fields.map(({ id, column }) => /* @__PURE__ */ jsxs2("div", { className: clsx("min-w-0", column.columnDef.meta?.interactive && "relative z-raised"), children: [
812
- /* @__PURE__ */ jsx2("dt", { className: "text-body-tiny text-default-secondary", children: columnLabel(column) }),
813
- /* @__PURE__ */ jsx2("dd", { className: "mt-0.5 min-w-0 text-body-xs text-default", children: column.columnDef.meta?.interactive ? /* @__PURE__ */ jsx2(CellInteractionGuard, { children: render(id) }) : render(id) })
814
- ] }, id)) })
1938
+ slots.fields.length > 0 && /* @__PURE__ */ jsx4("dl", { className: "grid grid-cols-[repeat(auto-fit,minmax(min(100%,8.5rem),1fr))] gap-x-4 gap-y-2.5", children: slots.fields.map(({ id, column }) => /* @__PURE__ */ jsxs4("div", { className: clsx("min-w-0", column.columnDef.meta?.interactive && "relative z-raised"), children: [
1939
+ /* @__PURE__ */ jsx4("dt", { className: "text-xs text-muted-foreground", children: columnLabel(column) }),
1940
+ /* @__PURE__ */ jsx4("dd", { className: "mt-0.5 min-w-0 text-xs text-foreground", children: column.columnDef.meta?.interactive ? /* @__PURE__ */ jsx4(CellInteractionGuard, { children: render(id) }) : render(id) })
1941
+ ] }, id)) }),
1942
+ expansion && /* @__PURE__ */ jsxs4("div", { className: "relative z-raised flex flex-col gap-3", children: [
1943
+ /* @__PURE__ */ jsxs4(
1944
+ Button,
1945
+ {
1946
+ variant: "ghost",
1947
+ size: "xs",
1948
+ className: "-ms-2 self-start",
1949
+ "aria-expanded": expansion.isOpen(row.id),
1950
+ "aria-controls": expansion.isOpen(row.id) ? detailId(row.id) : void 0,
1951
+ onClick: () => expansion.toggle(row.id),
1952
+ children: [
1953
+ /* @__PURE__ */ jsx4(ChevronRightIcon3, { className: cn("transition-transform", expansion.isOpen(row.id) && "rotate-90") }),
1954
+ "Details"
1955
+ ]
1956
+ }
1957
+ ),
1958
+ expansion.isOpen(row.id) && /* @__PURE__ */ jsx4("div", { id: detailId(row.id), role: "region", "aria-label": `Details for ${expansion.label(row.original)}`, children: expansion.render(row.original) })
1959
+ ] })
815
1960
  ]
816
1961
  },
817
1962
  row.id
@@ -826,15 +1971,21 @@ function CardList({
826
1971
  import { createColumnHelper } from "@tanstack/react-table";
827
1972
  export {
828
1973
  DataTable,
1974
+ DataTableButtonFilter,
829
1975
  DataTableColumnHeader,
1976
+ DataTableFacetedFilter,
830
1977
  DataTablePagination,
1978
+ DataTableTabsFilter,
831
1979
  DataTableViewOptions,
1980
+ ROW_ACTIONS_COLUMN_ID,
832
1981
  SELECT_COLUMN_ID,
833
1982
  TableCellBadge,
834
1983
  TableCellLeadText,
835
1984
  TableCellProgress,
836
1985
  TableCellText,
837
1986
  createColumnHelper,
838
- createSelectColumn
1987
+ createSelectColumn,
1988
+ fieldToColumn,
1989
+ isFieldColumn
839
1990
  };
840
1991
  //# sourceMappingURL=data-table.js.map