@tradalab/lyra 3.14.0 → 3.16.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.
- package/dist/blocks/index.d.ts +127 -4
- package/dist/blocks/index.js +474 -170
- package/dist/blocks/index.js.map +1 -1
- package/dist/chunk-5XFDQRXV.js +9 -0
- package/dist/chunk-5XFDQRXV.js.map +1 -0
- package/dist/{chunk-4ILJ3M7K.js → chunk-ASSRDIKG.js} +138 -5
- package/dist/chunk-ASSRDIKG.js.map +1 -0
- package/dist/chunk-DRBRT57F.js +3 -0
- package/dist/{chunk-PL37KFRJ.js.map → chunk-DRBRT57F.js.map} +1 -1
- package/dist/{chunk-U4HIZXI6.js → chunk-KSF233MC.js} +3 -3
- package/dist/chunk-KSF233MC.js.map +1 -0
- package/dist/{chunk-VEWKPOMS.js → chunk-OH3OMK7A.js} +13 -3
- package/dist/{chunk-VEWKPOMS.js.map → chunk-OH3OMK7A.js.map} +1 -1
- package/dist/{chunk-SQELPQZU.js → chunk-UNRT3B6P.js} +6 -16
- package/dist/chunk-UNRT3B6P.js.map +1 -0
- package/dist/data-table/index.d.ts +182 -5
- package/dist/data-table/index.js +657 -78
- package/dist/data-table/index.js.map +1 -1
- package/dist/people/index.js +25 -10
- package/dist/people/index.js.map +1 -1
- package/dist/shell/index.d.ts +3 -1
- package/dist/shell/index.js +11 -5
- package/dist/shell/index.js.map +1 -1
- package/dist/ui/index.d.ts +17 -1
- package/dist/ui/index.js +4 -4
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.js +2 -1
- package/package.json +3 -1
- package/dist/chunk-4ILJ3M7K.js.map +0 -1
- package/dist/chunk-PL37KFRJ.js +0 -3
- package/dist/chunk-SQELPQZU.js.map +0 -1
- package/dist/chunk-U4HIZXI6.js.map +0 -1
package/dist/data-table/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { TableHead, Table, TableRow, TableHeader, TableCell, TableBody,
|
|
3
|
-
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '../chunk-
|
|
2
|
+
import { TableHead, Table, TableRow, TableHeader, TableCell, TableBody, NativeSelect, NativeSelectOption, Checkbox, TableFooter } from '../chunk-KSF233MC.js';
|
|
3
|
+
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuCheckboxItem, Skeleton } from '../chunk-OH3OMK7A.js';
|
|
4
|
+
import { foldText } from '../chunk-5XFDQRXV.js';
|
|
4
5
|
import { Input, Button } from '../chunk-VGOGWZCF.js';
|
|
5
6
|
import { cn } from '../chunk-XH55BHUU.js';
|
|
6
|
-
import { flexRender, useReactTable, getSortedRowModel, getCoreRowModel, getPaginationRowModel, getFilteredRowModel } from '@tanstack/react-table';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { flexRender, useReactTable, getSortedRowModel, getCoreRowModel, getPaginationRowModel, getFilteredRowModel, getExpandedRowModel, getGroupedRowModel } from '@tanstack/react-table';
|
|
8
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
9
|
+
import { SearchIcon, RefreshCwIcon, XIcon, ArrowDownIcon, ArrowUpIcon, ChevronsUpDownIcon, DownloadIcon, Columns3Icon, Loader2Icon, ChevronRightIcon } from 'lucide-react';
|
|
10
|
+
import { createContext, memo, useState, useRef, useEffect, useCallback, useMemo, useContext, Fragment } from 'react';
|
|
11
|
+
import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
|
|
10
12
|
|
|
11
13
|
// src/data-table/filter-rows.ts
|
|
12
14
|
function filterRows(rows, q, fields) {
|
|
@@ -14,6 +16,62 @@ function filterRows(rows, q, fields) {
|
|
|
14
16
|
if (!needle) return rows;
|
|
15
17
|
return rows.filter((r) => fields(r).some((v) => v?.toLowerCase().includes(needle)));
|
|
16
18
|
}
|
|
19
|
+
var prefix = "lyra.table.";
|
|
20
|
+
function useTableState(key, defaults = {}) {
|
|
21
|
+
const [state, setState] = useState(defaults);
|
|
22
|
+
const initial = useRef(defaults);
|
|
23
|
+
initial.current = defaults;
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
let stored = null;
|
|
26
|
+
try {
|
|
27
|
+
const raw = localStorage.getItem(prefix + key);
|
|
28
|
+
stored = raw ? JSON.parse(raw) : null;
|
|
29
|
+
} catch {
|
|
30
|
+
stored = null;
|
|
31
|
+
}
|
|
32
|
+
const { sort: legacySort, ...kept } = stored ?? {};
|
|
33
|
+
setState({ ...initial.current, ...kept, ...legacySort && !kept.sorts ? { sorts: [legacySort] } : {} });
|
|
34
|
+
}, [key]);
|
|
35
|
+
const update = useCallback(
|
|
36
|
+
(patch) => setState((prev) => {
|
|
37
|
+
const next = { ...prev, ...patch };
|
|
38
|
+
try {
|
|
39
|
+
localStorage.setItem(prefix + key, JSON.stringify(next));
|
|
40
|
+
} catch {
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
return next;
|
|
44
|
+
}),
|
|
45
|
+
[key]
|
|
46
|
+
);
|
|
47
|
+
const reset = useCallback(() => {
|
|
48
|
+
try {
|
|
49
|
+
localStorage.removeItem(prefix + key);
|
|
50
|
+
} catch {
|
|
51
|
+
setState(initial.current);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setState(initial.current);
|
|
55
|
+
}, [key]);
|
|
56
|
+
const props = useMemo(
|
|
57
|
+
() => ({
|
|
58
|
+
sorts: state.sorts ?? [],
|
|
59
|
+
onSortsChange: (sorts) => update({ sorts }),
|
|
60
|
+
columnOrder: state.columnOrder ?? [],
|
|
61
|
+
onColumnOrderChange: (columnOrder) => update({ columnOrder }),
|
|
62
|
+
groupBy: state.groupBy ?? null,
|
|
63
|
+
onGroupByChange: (groupBy) => update({ groupBy }),
|
|
64
|
+
columnVisibility: state.columnVisibility ?? {},
|
|
65
|
+
onColumnVisibilityChange: (columnVisibility) => update({ columnVisibility }),
|
|
66
|
+
columnSizing: state.columnSizing ?? {},
|
|
67
|
+
onColumnSizingChange: (columnSizing) => update({ columnSizing }),
|
|
68
|
+
columnFilters: state.columnFilters ?? {},
|
|
69
|
+
onColumnFiltersChange: (columnFilters) => update({ columnFilters })
|
|
70
|
+
}),
|
|
71
|
+
[state, update]
|
|
72
|
+
);
|
|
73
|
+
return { props, state, reset };
|
|
74
|
+
}
|
|
17
75
|
function TableFilterBar({
|
|
18
76
|
children,
|
|
19
77
|
actions,
|
|
@@ -188,6 +246,67 @@ function usePager(options = {}) {
|
|
|
188
246
|
}
|
|
189
247
|
};
|
|
190
248
|
}
|
|
249
|
+
function nextSorts(current, id) {
|
|
250
|
+
const i = current.findIndex((s) => s.id === id);
|
|
251
|
+
if (i < 0) return [...current, { id, desc: false }];
|
|
252
|
+
if (!current[i].desc) return current.map((s, j) => j === i ? { id, desc: true } : s);
|
|
253
|
+
return current.filter((_, j) => j !== i);
|
|
254
|
+
}
|
|
255
|
+
function moveColumn(order, id, target) {
|
|
256
|
+
const from = order.indexOf(id);
|
|
257
|
+
const to = order.indexOf(target);
|
|
258
|
+
if (from < 0 || to < 0 || from === to) return [...order];
|
|
259
|
+
const next = order.filter((c) => c !== id);
|
|
260
|
+
next.splice(to, 0, id);
|
|
261
|
+
return next;
|
|
262
|
+
}
|
|
263
|
+
function nextSort(current, id) {
|
|
264
|
+
if (!current || current.id !== id) return { id, desc: false };
|
|
265
|
+
if (!current.desc) return { id, desc: true };
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
var ALIGN = { left: "", center: "text-center", right: "text-right tabular-nums" };
|
|
269
|
+
function columnClass(meta) {
|
|
270
|
+
return cn(meta?.align ? ALIGN[meta.align] : void 0, meta?.className);
|
|
271
|
+
}
|
|
272
|
+
var CSV_FORMULA = /^[=+\-@\t\r]/;
|
|
273
|
+
function cellText(cell) {
|
|
274
|
+
if (typeof cell === "string") return cell;
|
|
275
|
+
if (typeof cell === "number" || typeof cell === "bigint" || typeof cell === "boolean") return String(cell);
|
|
276
|
+
try {
|
|
277
|
+
return JSON.stringify(cell) ?? "";
|
|
278
|
+
} catch {
|
|
279
|
+
return "";
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function leafColumns(defs) {
|
|
283
|
+
return defs.flatMap((def) => {
|
|
284
|
+
const group = def.columns;
|
|
285
|
+
if (group?.length) return leafColumns(group);
|
|
286
|
+
const key = def.accessorKey;
|
|
287
|
+
const id = def.id ?? (typeof key === "string" ? key.replaceAll(".", "_") : typeof def.header === "string" ? def.header : void 0);
|
|
288
|
+
return typeof id === "string" ? [{ id, def }] : [];
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
function toCsv(header, rows) {
|
|
292
|
+
const field = (v) => {
|
|
293
|
+
if (v === null || v === void 0) return "";
|
|
294
|
+
if (typeof v === "number" || typeof v === "bigint" || typeof v === "boolean") return String(v);
|
|
295
|
+
let t = v instanceof Date ? v.toISOString() : typeof v === "string" ? v : JSON.stringify(v) ?? "";
|
|
296
|
+
if (CSV_FORMULA.test(t)) t = `'${t}`;
|
|
297
|
+
return /[",\r\n]/.test(t) || t !== t.trim() ? `"${t.replace(/"/g, '""')}"` : t;
|
|
298
|
+
};
|
|
299
|
+
return [header, ...rows].map((r) => r.map(field).join(",")).join("\r\n");
|
|
300
|
+
}
|
|
301
|
+
var ROW_TINT = "group-hover/row:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))] group-has-aria-expanded/row:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))] group-data-[state=selected]/row:bg-muted";
|
|
302
|
+
var UTILITY = 32;
|
|
303
|
+
var ROW_HEIGHT = 37;
|
|
304
|
+
var RESIZE_STEP = 16;
|
|
305
|
+
var MIN_COLUMN = 48;
|
|
306
|
+
function columnLabel(column) {
|
|
307
|
+
const header = column.columnDef.header;
|
|
308
|
+
return column.columnDef.meta?.label ?? (typeof header === "string" ? header : column.id);
|
|
309
|
+
}
|
|
191
310
|
var TableContext = createContext({
|
|
192
311
|
data: [],
|
|
193
312
|
columns: [],
|
|
@@ -319,30 +438,230 @@ function DataTable({
|
|
|
319
438
|
getRowId,
|
|
320
439
|
selected = [],
|
|
321
440
|
onSelectedChange,
|
|
322
|
-
selectLabels
|
|
441
|
+
selectLabels,
|
|
442
|
+
selectionActions,
|
|
443
|
+
sortable,
|
|
444
|
+
sort,
|
|
445
|
+
onSortChange,
|
|
446
|
+
columnToggle,
|
|
447
|
+
columnsLabel = "Columns",
|
|
448
|
+
columnVisibility,
|
|
449
|
+
onColumnVisibilityChange,
|
|
450
|
+
stickyHeader,
|
|
451
|
+
loadingRows,
|
|
452
|
+
resizableColumns,
|
|
453
|
+
columnSizing,
|
|
454
|
+
onColumnSizingChange,
|
|
455
|
+
resizeLabel = "Resize",
|
|
456
|
+
renderDetail,
|
|
457
|
+
rowHasDetail,
|
|
458
|
+
detailLabels,
|
|
459
|
+
exportCsv,
|
|
460
|
+
columnFilters,
|
|
461
|
+
onColumnFiltersChange,
|
|
462
|
+
filterLabels,
|
|
463
|
+
multiSort,
|
|
464
|
+
sorts,
|
|
465
|
+
onSortsChange,
|
|
466
|
+
groupBy,
|
|
467
|
+
onGroupByChange,
|
|
468
|
+
groupLabels,
|
|
469
|
+
reorderableColumns,
|
|
470
|
+
columnOrder,
|
|
471
|
+
onColumnOrderChange,
|
|
472
|
+
virtualize
|
|
323
473
|
}) {
|
|
324
474
|
const [globalFilter, setGlobalFilter] = useState("");
|
|
475
|
+
const [ownSorts, setOwnSorts] = useState([]);
|
|
476
|
+
const [ownVisibility, setOwnVisibility] = useState({});
|
|
477
|
+
const currentSorts = sorts ?? (sort !== void 0 ? sort ? [sort] : [] : ownSorts);
|
|
478
|
+
const visibility = columnVisibility ?? ownVisibility;
|
|
479
|
+
const setSorts = (next) => {
|
|
480
|
+
setOwnSorts(next);
|
|
481
|
+
onSortsChange?.(next);
|
|
482
|
+
onSortChange?.(next[0] ?? null);
|
|
483
|
+
};
|
|
484
|
+
const clickSort = (id, add) => {
|
|
485
|
+
if (multiSort && add) return setSorts(nextSorts(currentSorts, id));
|
|
486
|
+
const one = nextSort(currentSorts[0] ?? null, id);
|
|
487
|
+
setSorts(one ? [one] : []);
|
|
488
|
+
};
|
|
489
|
+
const [ownGroup, setOwnGroup] = useState(null);
|
|
490
|
+
const group = groupBy !== void 0 ? groupBy : ownGroup;
|
|
491
|
+
const [groupOpen, setGroupOpen] = useState(true);
|
|
492
|
+
const setGroup = (next) => {
|
|
493
|
+
setOwnGroup(next);
|
|
494
|
+
setGroupOpen(true);
|
|
495
|
+
onGroupByChange?.(next);
|
|
496
|
+
};
|
|
497
|
+
const [ownOrder, setOwnOrder] = useState([]);
|
|
498
|
+
const order = columnOrder ?? ownOrder;
|
|
499
|
+
const setOrder = (next) => {
|
|
500
|
+
setOwnOrder(next);
|
|
501
|
+
onColumnOrderChange?.(next);
|
|
502
|
+
};
|
|
503
|
+
const [dragging, setDragging] = useState(null);
|
|
504
|
+
const setVisibility = (next) => {
|
|
505
|
+
setOwnVisibility(next);
|
|
506
|
+
onColumnVisibilityChange?.(next);
|
|
507
|
+
};
|
|
508
|
+
const [ownSizing, setOwnSizing] = useState({});
|
|
509
|
+
const sizing = columnSizing ?? ownSizing;
|
|
510
|
+
const setSizing = (next) => {
|
|
511
|
+
setOwnSizing(next);
|
|
512
|
+
onColumnSizingChange?.(next);
|
|
513
|
+
};
|
|
514
|
+
const [ownFilters, setOwnFilters] = useState({});
|
|
515
|
+
const filters = columnFilters ?? ownFilters;
|
|
516
|
+
const setFilter = (id, value) => {
|
|
517
|
+
const next = { ...filters, [id]: value };
|
|
518
|
+
if (!value) delete next[id];
|
|
519
|
+
setOwnFilters(next);
|
|
520
|
+
onColumnFiltersChange?.(next);
|
|
521
|
+
};
|
|
522
|
+
const [expanded, setExpanded] = useState(/* @__PURE__ */ new Set());
|
|
523
|
+
const [expandedFor, setExpandedFor] = useState(data);
|
|
524
|
+
if (expandedFor !== data) {
|
|
525
|
+
setExpandedFor(data);
|
|
526
|
+
if (!getRowId && expanded.size > 0) setExpanded(/* @__PURE__ */ new Set());
|
|
527
|
+
}
|
|
528
|
+
const toggleDetail = (id) => setExpanded((prev) => {
|
|
529
|
+
const next = new Set(prev);
|
|
530
|
+
if (!next.delete(id)) next.add(id);
|
|
531
|
+
return next;
|
|
532
|
+
});
|
|
533
|
+
const { pinning, selectKinds } = useMemo(() => {
|
|
534
|
+
const pinning2 = { left: [], right: [] };
|
|
535
|
+
const selectKinds2 = /* @__PURE__ */ new Set();
|
|
536
|
+
for (const { id, def } of leafColumns(columns)) {
|
|
537
|
+
if (def.meta?.pin === "left") pinning2.left.push(id);
|
|
538
|
+
if (def.meta?.pin === "right") pinning2.right.push(id);
|
|
539
|
+
if (def.meta?.filter && def.meta.filter !== "text") selectKinds2.add(id);
|
|
540
|
+
}
|
|
541
|
+
return { pinning: pinning2, selectKinds: selectKinds2 };
|
|
542
|
+
}, [columns]);
|
|
325
543
|
const selecting = Boolean(onSelectedChange && getRowId);
|
|
326
544
|
const picked = new Set(selected);
|
|
327
545
|
const infinite = Boolean(onLoadMore);
|
|
328
546
|
const served = !infinite && Boolean(onPageChange);
|
|
329
547
|
const sliced = !infinite && !served && !unpaged;
|
|
548
|
+
const holdsAll = !infinite && !served;
|
|
549
|
+
const sorting = Boolean(sortable) && (holdsAll || Boolean(onSortChange) || Boolean(onSortsChange));
|
|
550
|
+
const sortKey = JSON.stringify(currentSorts.map((s) => ({ id: s.id, desc: Boolean(s.desc) })));
|
|
551
|
+
const sortingState = useMemo(() => JSON.parse(sortKey), [sortKey]);
|
|
552
|
+
const grouping = useMemo(() => holdsAll && group ? [group] : [], [holdsAll, group]);
|
|
553
|
+
const filterState = useMemo(
|
|
554
|
+
() => holdsAll ? Object.entries(filters).filter(([, v]) => v).map(([id, value]) => ({ id, value })) : [],
|
|
555
|
+
[holdsAll, filters]
|
|
556
|
+
);
|
|
330
557
|
const table = useReactTable({
|
|
331
558
|
data,
|
|
332
559
|
columns,
|
|
333
560
|
getRowId: getRowId ? (row) => getRowId(row) : void 0,
|
|
334
|
-
state: {
|
|
561
|
+
state: {
|
|
562
|
+
globalFilter,
|
|
563
|
+
sorting: sortingState,
|
|
564
|
+
columnVisibility: visibility,
|
|
565
|
+
columnSizing: sizing,
|
|
566
|
+
columnPinning: pinning,
|
|
567
|
+
columnFilters: filterState,
|
|
568
|
+
grouping,
|
|
569
|
+
expanded: groupOpen,
|
|
570
|
+
columnOrder: order
|
|
571
|
+
},
|
|
572
|
+
onExpandedChange: setGroupOpen,
|
|
573
|
+
autoResetExpanded: false,
|
|
574
|
+
onColumnOrderChange: (updater) => setOrder(typeof updater === "function" ? updater(order) : updater),
|
|
575
|
+
getGroupedRowModel: getGroupedRowModel(),
|
|
576
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
577
|
+
defaultColumn: {
|
|
578
|
+
aggregationFn: void 0,
|
|
579
|
+
filterFn: (row, id, value) => {
|
|
580
|
+
const text = cellText(row.getValue(id));
|
|
581
|
+
return selectKinds.has(id) ? text === value : foldText(text).includes(foldText(value));
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
globalFilterFn: (row, id, value) => foldText(cellText(row.getValue(id))).includes(foldText(value)),
|
|
585
|
+
onColumnSizingChange: (updater) => setSizing(typeof updater === "function" ? updater(sizing) : updater),
|
|
586
|
+
enableColumnResizing: Boolean(resizableColumns),
|
|
587
|
+
columnResizeMode: "onChange",
|
|
335
588
|
onGlobalFilterChange: setGlobalFilter,
|
|
589
|
+
onColumnVisibilityChange: (updater) => setVisibility(typeof updater === "function" ? updater(visibility) : updater),
|
|
590
|
+
enableSorting: sorting,
|
|
591
|
+
enableMultiSort: Boolean(multiSort),
|
|
336
592
|
getCoreRowModel: getCoreRowModel(),
|
|
337
593
|
getFilteredRowModel: getFilteredRowModel(),
|
|
594
|
+
...sorting && holdsAll ? { getSortedRowModel: getSortedRowModel() } : {},
|
|
338
595
|
// Only the default finite table slices rows itself. The other three modes each hand the
|
|
339
596
|
// table exactly what to render: infinite every accumulated row, served the one page the
|
|
340
597
|
// server answered with, unpaged the whole list.
|
|
341
598
|
...sliced ? { getPaginationRowModel: getPaginationRowModel(), initialState: { pagination: { pageSize } } } : {}
|
|
342
599
|
});
|
|
343
600
|
const rows = table.getRowModel().rows;
|
|
344
|
-
const
|
|
345
|
-
const
|
|
601
|
+
const leafRows = rows.filter((r) => !r.getIsGrouped());
|
|
602
|
+
const groupables = holdsAll ? table.getAllLeafColumns().filter((c) => c.columnDef.meta?.groupable) : [];
|
|
603
|
+
const frameRef = useRef(null);
|
|
604
|
+
const virtualOn = Boolean(virtualize) && !sliced && !served;
|
|
605
|
+
const vopts = typeof virtualize === "object" ? virtualize : {};
|
|
606
|
+
const virtualizer = useVirtualizer({
|
|
607
|
+
count: virtualOn ? rows.length : 0,
|
|
608
|
+
getScrollElement: () => frameRef.current,
|
|
609
|
+
estimateSize: () => vopts.estimateRowHeight ?? ROW_HEIGHT,
|
|
610
|
+
overscan: vopts.overscan ?? 8,
|
|
611
|
+
getItemKey: (i) => rows[i]?.id ?? i
|
|
612
|
+
});
|
|
613
|
+
const expandable = Boolean(renderDetail);
|
|
614
|
+
const span = table.getVisibleLeafColumns().length + (selecting ? 1 : 0) + (expandable ? 1 : 0);
|
|
615
|
+
const resizing = Boolean(resizableColumns);
|
|
616
|
+
const fixedLayout = resizing;
|
|
617
|
+
const lead = (selecting ? UTILITY : 0) + (expandable ? UTILITY : 0);
|
|
618
|
+
const pinsLeft = table.getLeftVisibleLeafColumns().length > 0;
|
|
619
|
+
const stuck = (head) => cn("bg-background sticky", head ? "z-20" : cn("z-10", ROW_TINT));
|
|
620
|
+
const leadClass = (head) => pinsLeft ? stuck(head) : void 0;
|
|
621
|
+
const leadStyle = (left) => pinsLeft ? { left } : void 0;
|
|
622
|
+
const pinClass = (column, head) => column.getIsPinned() ? stuck(head) : void 0;
|
|
623
|
+
const cellStyle = (column) => {
|
|
624
|
+
const pin = column.getIsPinned();
|
|
625
|
+
const w = column.getSize();
|
|
626
|
+
if (pin === "left") return { width: w, minWidth: w, maxWidth: w, left: lead + column.getStart("left") };
|
|
627
|
+
if (pin === "right") return { width: w, minWidth: w, maxWidth: w, right: column.getAfter("right") };
|
|
628
|
+
return fixedLayout ? { width: w } : void 0;
|
|
629
|
+
};
|
|
630
|
+
const hasFooter = table.getVisibleLeafColumns().some((c) => c.columnDef.footer !== void 0);
|
|
631
|
+
const filterable = table.getVisibleLeafColumns().some((c) => c.columnDef.meta?.filter);
|
|
632
|
+
const optionsOf = (column) => {
|
|
633
|
+
const f = column.columnDef.meta?.filter;
|
|
634
|
+
if (!f || f === "text") return null;
|
|
635
|
+
if (f !== "select") return f.options;
|
|
636
|
+
if (!holdsAll) return null;
|
|
637
|
+
const seen = /* @__PURE__ */ new Set();
|
|
638
|
+
for (const r of table.getCoreRowModel().rows) {
|
|
639
|
+
const v = cellText(r.getValue(column.id));
|
|
640
|
+
if (v !== "") seen.add(v);
|
|
641
|
+
}
|
|
642
|
+
return [...seen].sort((a, b) => foldText(a).localeCompare(foldText(b))).map((value) => ({ value }));
|
|
643
|
+
};
|
|
644
|
+
const canExport = Boolean(exportCsv) && holdsAll;
|
|
645
|
+
const download = () => {
|
|
646
|
+
if (!exportCsv) return;
|
|
647
|
+
const cols = table.getVisibleLeafColumns().filter((c) => c.accessorFn || c.columnDef.meta?.exportValue);
|
|
648
|
+
const leaves = (list) => list.flatMap((r) => r.getIsGrouped() ? leaves(r.subRows) : [r]);
|
|
649
|
+
const body = leaves(table.getSortedRowModel().rows).map(
|
|
650
|
+
(r) => cols.map((c) => c.columnDef.meta?.exportValue ? c.columnDef.meta.exportValue(r.original) : r.getValue(c.id))
|
|
651
|
+
);
|
|
652
|
+
const blob = new Blob(["\uFEFF" + toCsv(cols.map((c) => columnLabel(c)), body)], { type: "text/csv;charset=utf-8" });
|
|
653
|
+
const url = URL.createObjectURL(blob);
|
|
654
|
+
const a = document.createElement("a");
|
|
655
|
+
a.href = url;
|
|
656
|
+
a.download = exportCsv.filename;
|
|
657
|
+
document.body.appendChild(a);
|
|
658
|
+
a.click();
|
|
659
|
+
a.remove();
|
|
660
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
661
|
+
};
|
|
662
|
+
const hideable = table.getAllLeafColumns().filter((c) => c.getCanHide());
|
|
663
|
+
const visibleCount = table.getVisibleLeafColumns().length;
|
|
664
|
+
const shown = leafRows.map((r) => r.id);
|
|
346
665
|
const shownPicked = shown.filter((id) => picked.has(id)).length;
|
|
347
666
|
const toggle = (ids, on) => {
|
|
348
667
|
const next = new Set(picked);
|
|
@@ -352,7 +671,88 @@ function DataTable({
|
|
|
352
671
|
}
|
|
353
672
|
onSelectedChange?.([...next]);
|
|
354
673
|
};
|
|
355
|
-
const
|
|
674
|
+
const renderRow = (row) => {
|
|
675
|
+
if (row.getIsGrouped()) {
|
|
676
|
+
const open2 = row.getIsExpanded();
|
|
677
|
+
return /* @__PURE__ */ jsxs(TableRow, { "data-slot": "data-table-group", className: "group/row bg-muted/40 hover:bg-muted/40 font-medium", children: [
|
|
678
|
+
selecting ? /* @__PURE__ */ jsx(TableCell, { className: leadClass(false), style: leadStyle(0) }) : null,
|
|
679
|
+
expandable ? /* @__PURE__ */ jsx(TableCell, { className: leadClass(false), style: leadStyle(selecting ? UTILITY : 0) }) : null,
|
|
680
|
+
row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(
|
|
681
|
+
TableCell,
|
|
682
|
+
{
|
|
683
|
+
className: cn(columnClass(cell.column.columnDef.meta), pinClass(cell.column, false)),
|
|
684
|
+
style: cellStyle(cell.column),
|
|
685
|
+
children: cell.getIsGrouped() ? /* @__PURE__ */ jsxs("button", { type: "button", "aria-expanded": open2, onClick: row.getToggleExpandedHandler(), className: "inline-flex items-center gap-1", children: [
|
|
686
|
+
/* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-3.5 transition-transform", open2 && "rotate-90") }),
|
|
687
|
+
flexRender(cell.column.columnDef.cell, cell.getContext()),
|
|
688
|
+
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground font-normal", children: groupLabels?.count ? groupLabels.count(row.subRows.length) : `(${row.subRows.length})` })
|
|
689
|
+
] }) : cell.getIsAggregated() ? flexRender(cell.column.columnDef.aggregatedCell, cell.getContext()) : null
|
|
690
|
+
},
|
|
691
|
+
cell.id
|
|
692
|
+
))
|
|
693
|
+
] });
|
|
694
|
+
}
|
|
695
|
+
const hasDetail = expandable && (rowHasDetail ? rowHasDetail(row.original) : true);
|
|
696
|
+
const open = hasDetail && expanded.has(row.id);
|
|
697
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
698
|
+
/* @__PURE__ */ jsxs(
|
|
699
|
+
TableRow,
|
|
700
|
+
{
|
|
701
|
+
"data-state": picked.has(row.id) ? "selected" : void 0,
|
|
702
|
+
"aria-expanded": hasDetail ? open : void 0,
|
|
703
|
+
className: cn(
|
|
704
|
+
"group/row",
|
|
705
|
+
onRowClick && "focus-visible:outline-ring cursor-pointer focus-visible:outline-2 focus-visible:-outline-offset-2"
|
|
706
|
+
),
|
|
707
|
+
tabIndex: onRowClick ? 0 : void 0,
|
|
708
|
+
onClick: onRowClick ? (e) => opensRow(e) && onRowClick(row.original) : void 0,
|
|
709
|
+
onKeyDown: onRowClick ? (e) => {
|
|
710
|
+
if ((e.key === "Enter" || e.key === " ") && opensRow(e)) {
|
|
711
|
+
e.preventDefault();
|
|
712
|
+
onRowClick(row.original);
|
|
713
|
+
}
|
|
714
|
+
} : void 0,
|
|
715
|
+
children: [
|
|
716
|
+
selecting ? (
|
|
717
|
+
// The cell is a wide target around a small box; a near miss must not open the row.
|
|
718
|
+
/* @__PURE__ */ jsx(TableCell, { className: cn("w-8", leadClass(false)), style: leadStyle(0), onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsx(
|
|
719
|
+
Checkbox,
|
|
720
|
+
{
|
|
721
|
+
"aria-label": selectLabels?.row ?? "Select row",
|
|
722
|
+
checked: picked.has(row.id),
|
|
723
|
+
onCheckedChange: (v) => toggle([row.id], v === true)
|
|
724
|
+
}
|
|
725
|
+
) })
|
|
726
|
+
) : null,
|
|
727
|
+
expandable ? /* @__PURE__ */ jsx(TableCell, { className: cn("w-8", leadClass(false)), style: leadStyle(selecting ? UTILITY : 0), children: hasDetail ? /* @__PURE__ */ jsx(
|
|
728
|
+
Button,
|
|
729
|
+
{
|
|
730
|
+
type: "button",
|
|
731
|
+
variant: "ghost",
|
|
732
|
+
size: "icon-xs",
|
|
733
|
+
"aria-expanded": open,
|
|
734
|
+
"aria-label": open ? detailLabels?.collapse ?? "Hide details" : detailLabels?.expand ?? "Show details",
|
|
735
|
+
onClick: () => toggleDetail(row.id),
|
|
736
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-3.5 transition-transform", open && "rotate-90") })
|
|
737
|
+
}
|
|
738
|
+
) : null }) : null,
|
|
739
|
+
row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(
|
|
740
|
+
TableCell,
|
|
741
|
+
{
|
|
742
|
+
className: cn(columnClass(cell.column.columnDef.meta), pinClass(cell.column, false)),
|
|
743
|
+
style: cellStyle(cell.column),
|
|
744
|
+
children: cell.getIsPlaceholder() ? null : flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
745
|
+
},
|
|
746
|
+
cell.id
|
|
747
|
+
))
|
|
748
|
+
]
|
|
749
|
+
}
|
|
750
|
+
),
|
|
751
|
+
open && renderDetail ? /* @__PURE__ */ jsx(TableRow, { "data-slot": "data-table-detail", className: "bg-muted/30 hover:bg-muted/30", children: /* @__PURE__ */ jsx(TableCell, { colSpan: span, className: "whitespace-normal", children: renderDetail(row.original) }) }) : null
|
|
752
|
+
] });
|
|
753
|
+
};
|
|
754
|
+
const showBar = Boolean(searchable || onReload || toolbar || columnToggle || canExport || groupables.length > 0);
|
|
755
|
+
const leafOrder = () => table.getAllLeafColumns().map((c) => c.id);
|
|
356
756
|
const sentinelRef = useRef(null);
|
|
357
757
|
const onLoadMoreRef = useRef(onLoadMore);
|
|
358
758
|
onLoadMoreRef.current = onLoadMore;
|
|
@@ -397,8 +797,42 @@ function DataTable({
|
|
|
397
797
|
}
|
|
398
798
|
)
|
|
399
799
|
] }) : null,
|
|
400
|
-
onReload || toolbar ? /* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-2", children: [
|
|
800
|
+
onReload || toolbar || columnToggle || canExport || groupables.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-2", children: [
|
|
401
801
|
toolbar,
|
|
802
|
+
groupables.length > 0 ? /* @__PURE__ */ jsxs(
|
|
803
|
+
NativeSelect,
|
|
804
|
+
{
|
|
805
|
+
"aria-label": groupLabels?.groupBy ?? "Group by",
|
|
806
|
+
className: "h-8 w-auto",
|
|
807
|
+
value: group ?? "",
|
|
808
|
+
onChange: (e) => setGroup(e.target.value || null),
|
|
809
|
+
children: [
|
|
810
|
+
/* @__PURE__ */ jsx(NativeSelectOption, { value: "", children: groupLabels?.none ?? "No grouping" }),
|
|
811
|
+
groupables.map((c) => /* @__PURE__ */ jsx(NativeSelectOption, { value: c.id, children: columnLabel(c) }, c.id))
|
|
812
|
+
]
|
|
813
|
+
}
|
|
814
|
+
) : null,
|
|
815
|
+
canExport ? /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: download, children: [
|
|
816
|
+
/* @__PURE__ */ jsx(DownloadIcon, { className: "size-4" }),
|
|
817
|
+
exportCsv?.label ?? "CSV"
|
|
818
|
+
] }) : null,
|
|
819
|
+
columnToggle && hideable.length > 0 ? /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
820
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { type: "button", variant: "outline", size: "sm", children: [
|
|
821
|
+
/* @__PURE__ */ jsx(Columns3Icon, { className: "size-4" }),
|
|
822
|
+
columnsLabel
|
|
823
|
+
] }) }),
|
|
824
|
+
/* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", children: hideable.map((c) => /* @__PURE__ */ jsx(
|
|
825
|
+
DropdownMenuCheckboxItem,
|
|
826
|
+
{
|
|
827
|
+
checked: c.getIsVisible(),
|
|
828
|
+
disabled: c.getIsVisible() && visibleCount <= 1,
|
|
829
|
+
onSelect: (e) => e.preventDefault(),
|
|
830
|
+
onCheckedChange: (v) => c.toggleVisibility(v === true),
|
|
831
|
+
children: columnLabel(c)
|
|
832
|
+
},
|
|
833
|
+
c.id
|
|
834
|
+
)) })
|
|
835
|
+
] }) : null,
|
|
402
836
|
onReload ? /* @__PURE__ */ jsx(
|
|
403
837
|
Button,
|
|
404
838
|
{
|
|
@@ -414,73 +848,218 @@ function DataTable({
|
|
|
414
848
|
) : null
|
|
415
849
|
] }) : null
|
|
416
850
|
] }) : null,
|
|
417
|
-
/* @__PURE__ */ jsxs("div", { className:
|
|
418
|
-
/* @__PURE__ */
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
/* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { className: "h-24 text-center", colSpan: span, children: loadingText }) })
|
|
435
|
-
) : rows.length ? rows.map((row) => /* @__PURE__ */ jsxs(
|
|
436
|
-
TableRow,
|
|
437
|
-
{
|
|
438
|
-
"data-state": picked.has(row.id) ? "selected" : void 0,
|
|
439
|
-
className: onRowClick ? "focus-visible:outline-ring cursor-pointer focus-visible:outline-2 focus-visible:-outline-offset-2" : void 0,
|
|
440
|
-
tabIndex: onRowClick ? 0 : void 0,
|
|
441
|
-
onClick: onRowClick ? (e) => opensRow(e) && onRowClick(row.original) : void 0,
|
|
442
|
-
onKeyDown: onRowClick ? (e) => {
|
|
443
|
-
if ((e.key === "Enter" || e.key === " ") && opensRow(e)) {
|
|
444
|
-
e.preventDefault();
|
|
445
|
-
onRowClick(row.original);
|
|
446
|
-
}
|
|
447
|
-
} : void 0,
|
|
448
|
-
children: [
|
|
449
|
-
selecting ? (
|
|
450
|
-
// The cell is a wide target around a small box; a near miss must not open the row.
|
|
451
|
-
/* @__PURE__ */ jsx(TableCell, { className: "w-8", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsx(
|
|
452
|
-
Checkbox,
|
|
453
|
-
{
|
|
454
|
-
"aria-label": selectLabels?.row ?? "Select row",
|
|
455
|
-
checked: picked.has(row.id),
|
|
456
|
-
onCheckedChange: (v) => toggle([row.id], v === true)
|
|
457
|
-
}
|
|
458
|
-
) })
|
|
459
|
-
) : null,
|
|
460
|
-
row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(TableCell, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
461
|
-
]
|
|
462
|
-
},
|
|
463
|
-
row.id
|
|
464
|
-
)) : (
|
|
465
|
-
// An empty state is not a record, so the row drops the `hover:bg-muted/50` every
|
|
466
|
-
// other row carries: lighting up under the pointer offers an interaction that is not
|
|
467
|
-
// there, and it gets louder the taller the cell grows.
|
|
468
|
-
/* @__PURE__ */ jsx(TableRow, { className: "hover:bg-transparent", children: /* @__PURE__ */ jsx(
|
|
469
|
-
TableCell,
|
|
851
|
+
selecting && selectionActions && picked.size > 0 ? /* @__PURE__ */ jsxs("div", { "data-slot": "data-table-selection", className: "bg-muted/50 mb-2 flex flex-wrap items-center gap-2 border px-3 py-2 text-sm", children: [
|
|
852
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: selectLabels?.count ? selectLabels.count(picked.size) : `${picked.size} selected` }),
|
|
853
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center gap-2", children: selectionActions([...picked]) }),
|
|
854
|
+
/* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "ml-auto", onClick: () => onSelectedChange?.([]), children: selectLabels?.clear ?? "Clear" })
|
|
855
|
+
] }) : null,
|
|
856
|
+
/* @__PURE__ */ jsxs(
|
|
857
|
+
"div",
|
|
858
|
+
{
|
|
859
|
+
ref: frameRef,
|
|
860
|
+
className: cn(
|
|
861
|
+
"border",
|
|
862
|
+
stickyHeader || virtualOn ? "overflow-auto [&_[data-slot=table-container]]:overflow-visible" : "overflow-hidden",
|
|
863
|
+
className
|
|
864
|
+
),
|
|
865
|
+
children: [
|
|
866
|
+
/* @__PURE__ */ jsxs(
|
|
867
|
+
Table,
|
|
470
868
|
{
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
869
|
+
"aria-busy": loading || void 0,
|
|
870
|
+
className: fixedLayout ? "table-fixed" : void 0,
|
|
871
|
+
style: fixedLayout ? { width: table.getTotalSize() + lead } : void 0,
|
|
872
|
+
children: [
|
|
873
|
+
/* @__PURE__ */ jsxs(TableHeader, { className: stickyHeader ? "bg-background sticky top-0 z-10" : void 0, children: [
|
|
874
|
+
table.getHeaderGroups().map((hg) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
875
|
+
selecting ? /* @__PURE__ */ jsx(TableHead, { className: cn("w-8", leadClass(true)), style: leadStyle(0), children: /* @__PURE__ */ jsx(
|
|
876
|
+
Checkbox,
|
|
877
|
+
{
|
|
878
|
+
"aria-label": selectLabels?.rows ?? "Select rows on this page",
|
|
879
|
+
checked: shown.length > 0 && shownPicked === shown.length ? true : shownPicked > 0 ? "indeterminate" : false,
|
|
880
|
+
disabled: shown.length === 0,
|
|
881
|
+
onCheckedChange: (v) => toggle(shown, v === true)
|
|
882
|
+
}
|
|
883
|
+
) }) : null,
|
|
884
|
+
expandable ? /* @__PURE__ */ jsx(TableHead, { className: cn("w-8", leadClass(true)), style: leadStyle(selecting ? UTILITY : 0) }) : null,
|
|
885
|
+
hg.headers.map((header) => {
|
|
886
|
+
const meta = header.column.columnDef.meta;
|
|
887
|
+
const content = header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext());
|
|
888
|
+
const canSort = sorting && !header.isPlaceholder && header.column.getCanSort();
|
|
889
|
+
const dir = header.column.getIsSorted();
|
|
890
|
+
const rank = currentSorts.length > 1 ? currentSorts.findIndex((s) => s.id === header.column.id) : -1;
|
|
891
|
+
const id = header.column.id;
|
|
892
|
+
const movable = Boolean(reorderableColumns) && !header.isPlaceholder && !header.column.getIsPinned();
|
|
893
|
+
return /* @__PURE__ */ jsxs(
|
|
894
|
+
TableHead,
|
|
895
|
+
{
|
|
896
|
+
className: cn(
|
|
897
|
+
columnClass(meta),
|
|
898
|
+
pinClass(header.column, true) ?? (resizing && "relative"),
|
|
899
|
+
movable && "cursor-grab data-[dragging]:opacity-50"
|
|
900
|
+
),
|
|
901
|
+
style: cellStyle(header.column),
|
|
902
|
+
"aria-sort": canSort ? dir === "asc" ? "ascending" : dir === "desc" ? "descending" : "none" : void 0,
|
|
903
|
+
draggable: movable || void 0,
|
|
904
|
+
tabIndex: movable && !canSort ? 0 : void 0,
|
|
905
|
+
"data-dragging": dragging === id || void 0,
|
|
906
|
+
onDragStart: movable ? (e) => {
|
|
907
|
+
e.dataTransfer.effectAllowed = "move";
|
|
908
|
+
e.dataTransfer.setData("text/plain", id);
|
|
909
|
+
setDragging(id);
|
|
910
|
+
} : void 0,
|
|
911
|
+
onDragEnd: movable ? () => setDragging(null) : void 0,
|
|
912
|
+
onDragOver: movable && dragging && dragging !== id ? (e) => e.preventDefault() : void 0,
|
|
913
|
+
onDrop: movable ? (e) => {
|
|
914
|
+
e.preventDefault();
|
|
915
|
+
const from = dragging ?? e.dataTransfer.getData("text/plain");
|
|
916
|
+
if (from && from !== id) setOrder(moveColumn(leafOrder(), from, id));
|
|
917
|
+
setDragging(null);
|
|
918
|
+
} : void 0,
|
|
919
|
+
onKeyDown: movable ? (e) => {
|
|
920
|
+
const step = e.altKey ? e.key === "ArrowLeft" ? -1 : e.key === "ArrowRight" ? 1 : 0 : 0;
|
|
921
|
+
if (!step) return;
|
|
922
|
+
e.preventDefault();
|
|
923
|
+
const center = table.getCenterVisibleLeafColumns().map((c) => c.id);
|
|
924
|
+
const target = center[center.indexOf(id) + step];
|
|
925
|
+
if (target) setOrder(moveColumn(leafOrder(), id, target));
|
|
926
|
+
} : void 0,
|
|
927
|
+
children: [
|
|
928
|
+
canSort ? /* @__PURE__ */ jsxs(
|
|
929
|
+
"button",
|
|
930
|
+
{
|
|
931
|
+
type: "button",
|
|
932
|
+
onClick: (e) => clickSort(id, e.shiftKey),
|
|
933
|
+
className: cn(
|
|
934
|
+
"hover:text-foreground focus-visible:outline-ring -mx-1 inline-flex items-center gap-1 px-1 font-medium focus-visible:outline-2",
|
|
935
|
+
meta?.align === "right" && "flex-row-reverse"
|
|
936
|
+
),
|
|
937
|
+
children: [
|
|
938
|
+
content,
|
|
939
|
+
dir === "asc" ? /* @__PURE__ */ jsx(ArrowUpIcon, { className: "size-3.5" }) : dir === "desc" ? /* @__PURE__ */ jsx(ArrowDownIcon, { className: "size-3.5" }) : /* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: "size-3.5 opacity-40" }),
|
|
940
|
+
rank >= 0 ? /* @__PURE__ */ jsx("sup", { className: "text-[10px] tabular-nums", children: rank + 1 }) : null
|
|
941
|
+
]
|
|
942
|
+
}
|
|
943
|
+
) : content,
|
|
944
|
+
resizing && !header.isPlaceholder && header.column.getCanResize() ? /* @__PURE__ */ jsx(
|
|
945
|
+
"div",
|
|
946
|
+
{
|
|
947
|
+
role: "separator",
|
|
948
|
+
"aria-orientation": "vertical",
|
|
949
|
+
"aria-label": `${resizeLabel} ${columnLabel(header.column)}`,
|
|
950
|
+
"aria-valuenow": header.column.getSize(),
|
|
951
|
+
tabIndex: 0,
|
|
952
|
+
"data-slot": "data-table-resizer",
|
|
953
|
+
"data-resizing": header.column.getIsResizing() || void 0,
|
|
954
|
+
onMouseDown: (e) => {
|
|
955
|
+
if (movable) e.preventDefault();
|
|
956
|
+
header.getResizeHandler()(e);
|
|
957
|
+
},
|
|
958
|
+
onTouchStart: header.getResizeHandler(),
|
|
959
|
+
onDoubleClick: () => header.column.resetSize(),
|
|
960
|
+
onKeyDown: (e) => {
|
|
961
|
+
const step = e.key === "ArrowRight" ? RESIZE_STEP : e.key === "ArrowLeft" ? -RESIZE_STEP : 0;
|
|
962
|
+
if (!step) return;
|
|
963
|
+
e.preventDefault();
|
|
964
|
+
const c = header.column;
|
|
965
|
+
const min = c.columnDef.minSize ?? MIN_COLUMN;
|
|
966
|
+
table.setColumnSizing((old) => ({ ...old, [c.id]: Math.max(min, c.getSize() + step) }));
|
|
967
|
+
},
|
|
968
|
+
className: "hover:bg-border focus-visible:bg-ring data-[resizing]:bg-primary absolute top-0 right-0 h-full w-1 cursor-col-resize touch-none select-none outline-none"
|
|
969
|
+
}
|
|
970
|
+
) : null
|
|
971
|
+
]
|
|
972
|
+
},
|
|
973
|
+
header.id
|
|
974
|
+
);
|
|
975
|
+
})
|
|
976
|
+
] }, hg.id)),
|
|
977
|
+
filterable ? /* @__PURE__ */ jsxs(TableRow, { "data-slot": "data-table-filters", className: "hover:bg-transparent", children: [
|
|
978
|
+
selecting ? /* @__PURE__ */ jsx(TableHead, { className: leadClass(true), style: leadStyle(0) }) : null,
|
|
979
|
+
expandable ? /* @__PURE__ */ jsx(TableHead, { className: leadClass(true), style: leadStyle(selecting ? UTILITY : 0) }) : null,
|
|
980
|
+
table.getVisibleLeafColumns().map((c) => {
|
|
981
|
+
const kind = c.columnDef.meta?.filter;
|
|
982
|
+
const options = optionsOf(c);
|
|
983
|
+
const label = columnLabel(c);
|
|
984
|
+
return /* @__PURE__ */ jsx(TableHead, { className: cn("py-1", pinClass(c, true)), style: cellStyle(c), children: !kind || kind !== "text" && !options ? null : options ? /* @__PURE__ */ jsxs(
|
|
985
|
+
NativeSelect,
|
|
986
|
+
{
|
|
987
|
+
"aria-label": label,
|
|
988
|
+
className: "h-7",
|
|
989
|
+
value: filters[c.id] ?? "",
|
|
990
|
+
onChange: (e) => setFilter(c.id, e.target.value),
|
|
991
|
+
children: [
|
|
992
|
+
/* @__PURE__ */ jsx(NativeSelectOption, { value: "", children: filterLabels?.all ?? "All" }),
|
|
993
|
+
options.map((o) => /* @__PURE__ */ jsx(NativeSelectOption, { value: o.value, children: o.label ?? o.value }, o.value))
|
|
994
|
+
]
|
|
995
|
+
}
|
|
996
|
+
) : /* @__PURE__ */ jsx(
|
|
997
|
+
Input,
|
|
998
|
+
{
|
|
999
|
+
"aria-label": label,
|
|
1000
|
+
className: "h-7",
|
|
1001
|
+
placeholder: filterLabels?.placeholder ?? "Filter\u2026",
|
|
1002
|
+
value: filters[c.id] ?? "",
|
|
1003
|
+
onChange: (e) => setFilter(c.id, e.target.value)
|
|
1004
|
+
}
|
|
1005
|
+
) }, c.id);
|
|
1006
|
+
})
|
|
1007
|
+
] }) : null
|
|
1008
|
+
] }),
|
|
1009
|
+
/* @__PURE__ */ jsx(TableBody, { children: loading && rows.length === 0 && loadingRows ? Array.from({ length: loadingRows }, (_, i) => /* @__PURE__ */ jsx(TableRow, { className: "hover:bg-transparent", children: Array.from({ length: span }, (_2, j) => /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Skeleton, { "data-slot": "data-table-skeleton", className: "h-4 w-full" }) }, j)) }, `loading${i}`)) : loading && rows.length === 0 ? (
|
|
1010
|
+
// Only replace the body with a loading row on the FIRST load; on a
|
|
1011
|
+
// refetch keep the (stale) rows visible while the reload icon spins.
|
|
1012
|
+
/* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, { className: "h-24 text-center", colSpan: span, children: loadingText }) })
|
|
1013
|
+
) : rows.length ? virtualOn ? null : rows.map((row) => /* @__PURE__ */ jsx(Fragment, { children: renderRow(row) }, row.id)) : (
|
|
1014
|
+
// An empty state is not a record, so the row drops the `hover:bg-muted/50` every
|
|
1015
|
+
// other row carries: lighting up under the pointer offers an interaction that is not
|
|
1016
|
+
// there, and it gets louder the taller the cell grows.
|
|
1017
|
+
/* @__PURE__ */ jsx(TableRow, { className: "hover:bg-transparent", children: /* @__PURE__ */ jsx(
|
|
1018
|
+
TableCell,
|
|
1019
|
+
{
|
|
1020
|
+
className: empty ? "p-0" : "text-muted-foreground h-24 text-center",
|
|
1021
|
+
colSpan: span,
|
|
1022
|
+
children: empty ?? emptyText
|
|
1023
|
+
}
|
|
1024
|
+
) })
|
|
1025
|
+
) }),
|
|
1026
|
+
virtualOn && rows.length > 0 ? (() => {
|
|
1027
|
+
const items = virtualizer.getVirtualItems();
|
|
1028
|
+
const top = items[0]?.start ?? 0;
|
|
1029
|
+
const bottom = virtualizer.getTotalSize() - (items[items.length - 1]?.end ?? 0);
|
|
1030
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1031
|
+
top > 0 ? /* @__PURE__ */ jsx("tbody", { "aria-hidden": true, "data-slot": "data-table-spacer", children: /* @__PURE__ */ jsx("tr", { style: { height: top } }) }) : null,
|
|
1032
|
+
items.map((v) => {
|
|
1033
|
+
const row = rows[v.index];
|
|
1034
|
+
return /* @__PURE__ */ jsx("tbody", { "data-index": v.index, ref: virtualizer.measureElement, "data-slot": "data-table-virtual", children: renderRow(row) }, row.id);
|
|
1035
|
+
}),
|
|
1036
|
+
bottom > 0 ? /* @__PURE__ */ jsx("tbody", { "aria-hidden": true, "data-slot": "data-table-spacer", children: /* @__PURE__ */ jsx("tr", { style: { height: bottom } }) }) : null
|
|
1037
|
+
] });
|
|
1038
|
+
})() : null,
|
|
1039
|
+
hasFooter && rows.length > 0 ? /* @__PURE__ */ jsx(TableFooter, { children: table.getFooterGroups().slice(0, 1).map((fg) => /* @__PURE__ */ jsxs(TableRow, { children: [
|
|
1040
|
+
selecting ? /* @__PURE__ */ jsx(TableCell, { className: leadClass(false), style: leadStyle(0) }) : null,
|
|
1041
|
+
expandable ? /* @__PURE__ */ jsx(TableCell, { className: leadClass(false), style: leadStyle(selecting ? UTILITY : 0) }) : null,
|
|
1042
|
+
fg.headers.map((f) => /* @__PURE__ */ jsx(
|
|
1043
|
+
TableCell,
|
|
1044
|
+
{
|
|
1045
|
+
className: cn("font-medium", columnClass(f.column.columnDef.meta), pinClass(f.column, false)),
|
|
1046
|
+
style: cellStyle(f.column),
|
|
1047
|
+
children: f.isPlaceholder ? null : flexRender(f.column.columnDef.footer, f.getContext())
|
|
1048
|
+
},
|
|
1049
|
+
f.id
|
|
1050
|
+
))
|
|
1051
|
+
] }, fg.id)) }) : null
|
|
1052
|
+
]
|
|
474
1053
|
}
|
|
475
|
-
)
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
1054
|
+
),
|
|
1055
|
+
infinite && loadingMore ? /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground flex items-center justify-center gap-2 py-3 text-sm", children: [
|
|
1056
|
+
/* @__PURE__ */ jsx(Loader2Icon, { className: "size-4 animate-spin" }),
|
|
1057
|
+
loadingMoreText
|
|
1058
|
+
] }) : null,
|
|
1059
|
+
infinite ? /* @__PURE__ */ jsx("div", { ref: sentinelRef, "aria-hidden": true, className: "h-px w-full" }) : null
|
|
1060
|
+
]
|
|
1061
|
+
}
|
|
1062
|
+
),
|
|
484
1063
|
served ? /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 py-4", children: [
|
|
485
1064
|
/* @__PURE__ */ jsxs("div", { className: "text-muted-foreground flex items-center gap-3 text-sm", children: [
|
|
486
1065
|
rangeLabel,
|
|
@@ -562,6 +1141,6 @@ function DataTable({
|
|
|
562
1141
|
] });
|
|
563
1142
|
}
|
|
564
1143
|
|
|
565
|
-
export { DEFAULT_PAGE_SIZE, DataTable, PAGE_SIZE_OPTIONS, TableBody2 as TableBody, TableCell2 as TableCell, TableColumnHeader, TableContext, TableFilterBar, TableFilterChips, TableHead2 as TableHead, TableHeader2 as TableHeader, TableHeaderGroup, TableProvider, TableReload, TableRow2 as TableRow, TableSearch, filterRows, pageWindow, usePager };
|
|
1144
|
+
export { DEFAULT_PAGE_SIZE, DataTable, PAGE_SIZE_OPTIONS, TableBody2 as TableBody, TableCell2 as TableCell, TableColumnHeader, TableContext, TableFilterBar, TableFilterChips, TableHead2 as TableHead, TableHeader2 as TableHeader, TableHeaderGroup, TableProvider, TableReload, TableRow2 as TableRow, TableSearch, columnLabel, filterRows, moveColumn, nextSort, nextSorts, pageWindow, toCsv, usePager, useTableState };
|
|
566
1145
|
//# sourceMappingURL=index.js.map
|
|
567
1146
|
//# sourceMappingURL=index.js.map
|