jenosize-ui 0.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.
- package/LICENSE +28 -0
- package/README.md +100 -0
- package/THIRD-PARTY-NOTICES.md +163 -0
- package/dist/Button-Bt7pzM4R.d.ts +82 -0
- package/dist/PaymentInput-CKPIPNWH.d.ts +141 -0
- package/dist/Select-CVbEQ2Ep.d.ts +118 -0
- package/dist/TagInput-CTJYOB4J.d.ts +90 -0
- package/dist/avatar.d.ts +161 -0
- package/dist/avatar.js +11 -0
- package/dist/badge.d.ts +109 -0
- package/dist/badge.js +10 -0
- package/dist/breadcrumb.d.ts +58 -0
- package/dist/breadcrumb.js +7 -0
- package/dist/button.d.ts +54 -0
- package/dist/button.js +14 -0
- package/dist/calendar.d.ts +368 -0
- package/dist/calendar.js +21 -0
- package/dist/callout.d.ts +70 -0
- package/dist/callout.js +16 -0
- package/dist/card-nWicloNi.d.ts +80 -0
- package/dist/card.d.ts +2 -0
- package/dist/card.js +7 -0
- package/dist/checkbox.d.ts +133 -0
- package/dist/checkbox.js +11 -0
- package/dist/chunk-24TO7E32.js +42 -0
- package/dist/chunk-3Y5X7B5C.js +146 -0
- package/dist/chunk-4OLULPQG.js +202 -0
- package/dist/chunk-4P2NBLBW.js +103 -0
- package/dist/chunk-52IFGFTL.js +11 -0
- package/dist/chunk-5FATN5YD.js +115 -0
- package/dist/chunk-5NOBSXJN.js +297 -0
- package/dist/chunk-5RAPA22E.js +106 -0
- package/dist/chunk-7EUAMHMU.js +16 -0
- package/dist/chunk-7EWQKTNQ.js +1336 -0
- package/dist/chunk-7HOIZ3UO.js +110 -0
- package/dist/chunk-7IU5TMFL.js +452 -0
- package/dist/chunk-7JBNLEJ7.js +29 -0
- package/dist/chunk-7S2TBALK.js +23 -0
- package/dist/chunk-BJUZVYQC.js +188 -0
- package/dist/chunk-BVJWBYIG.js +66 -0
- package/dist/chunk-CME4DIML.js +65 -0
- package/dist/chunk-CYPPEUX5.js +73 -0
- package/dist/chunk-D5BTFSL7.js +71 -0
- package/dist/chunk-D6TPWNRK.js +387 -0
- package/dist/chunk-DJSXIAFH.js +66 -0
- package/dist/chunk-DRZCJCBO.js +46 -0
- package/dist/chunk-DWKILXHE.js +17 -0
- package/dist/chunk-E7ZSWBAK.js +70 -0
- package/dist/chunk-EDSK6FEH.js +8 -0
- package/dist/chunk-F2K7VJUV.js +114 -0
- package/dist/chunk-F6NLE6XJ.js +40 -0
- package/dist/chunk-FHHAPGCR.js +32 -0
- package/dist/chunk-FXIBGTS5.js +14 -0
- package/dist/chunk-GCVA3OIV.js +72 -0
- package/dist/chunk-GFOAJVW5.js +336 -0
- package/dist/chunk-GRLSUQQE.js +136 -0
- package/dist/chunk-GTHJWR3Q.js +77 -0
- package/dist/chunk-HMUZE6EK.js +67 -0
- package/dist/chunk-I7WU4GTY.js +503 -0
- package/dist/chunk-J2BCKBHC.js +151 -0
- package/dist/chunk-J36M3KRX.js +1315 -0
- package/dist/chunk-J7ZQQFPT.js +113 -0
- package/dist/chunk-JP26LPCY.js +234 -0
- package/dist/chunk-JTNFJLIY.js +1046 -0
- package/dist/chunk-JVJRHBTD.js +50 -0
- package/dist/chunk-JYGR44ZC.js +133 -0
- package/dist/chunk-KDLPXXD2.js +173 -0
- package/dist/chunk-KMSYEE23.js +224 -0
- package/dist/chunk-KNYKWUYX.js +52 -0
- package/dist/chunk-LME57Z6J.js +138 -0
- package/dist/chunk-MFJP5FA7.js +20 -0
- package/dist/chunk-MKC5HNA7.js +1692 -0
- package/dist/chunk-MQGD2OUF.js +39 -0
- package/dist/chunk-MUFHLP4S.js +566 -0
- package/dist/chunk-O2LG3PNI.js +74 -0
- package/dist/chunk-O4GRKO3I.js +66 -0
- package/dist/chunk-OHUFNYGN.js +791 -0
- package/dist/chunk-PWKWNDBS.js +243 -0
- package/dist/chunk-QA74ITR4.js +103 -0
- package/dist/chunk-R6RGJF4L.js +170 -0
- package/dist/chunk-S7NNXWIN.js +7 -0
- package/dist/chunk-SV56BSUQ.js +162 -0
- package/dist/chunk-T7FCG7XV.js +435 -0
- package/dist/chunk-THC2ISYP.js +57 -0
- package/dist/chunk-VWC72TR3.js +115 -0
- package/dist/chunk-W46K56XU.js +216 -0
- package/dist/chunk-W5GGOUUI.js +75 -0
- package/dist/chunk-WEUJYDCV.js +269 -0
- package/dist/chunk-WFY7DKQD.js +279 -0
- package/dist/chunk-WZQFC7ZN.js +448 -0
- package/dist/chunk-Z3ETJN5G.js +136 -0
- package/dist/chunk-ZOOX3TUB.js +192 -0
- package/dist/chunk-ZSNJ6UA3.js +42 -0
- package/dist/chunk-ZZA2LUTL.js +130 -0
- package/dist/chunk-ZZT2E5VT.js +24 -0
- package/dist/color-CtSxc1Rh.d.ts +6 -0
- package/dist/combobox.d.ts +184 -0
- package/dist/combobox.js +21 -0
- package/dist/date-input.d.ts +83 -0
- package/dist/date-input.js +16 -0
- package/dist/date-picker.d.ts +249 -0
- package/dist/date-picker.js +29 -0
- package/dist/date-utils-7hTFTXNK.d.ts +34 -0
- package/dist/date-vMJBKAFK.d.ts +22 -0
- package/dist/dialog.d.ts +86 -0
- package/dist/dialog.js +15 -0
- package/dist/drawer.d.ts +77 -0
- package/dist/drawer.js +14 -0
- package/dist/dropdown-menu.d.ts +218 -0
- package/dist/dropdown-menu.js +10 -0
- package/dist/file-trigger.d.ts +42 -0
- package/dist/file-trigger.js +3 -0
- package/dist/form.d.ts +487 -0
- package/dist/form.js +1179 -0
- package/dist/header-navigation.d.ts +74 -0
- package/dist/header-navigation.js +23 -0
- package/dist/icons/app.d.ts +48 -0
- package/dist/icons/app.js +282 -0
- package/dist/icons/flag.d.ts +817 -0
- package/dist/icons/flag.js +58336 -0
- package/dist/icons/integration.d.ts +36 -0
- package/dist/icons/integration.js +531 -0
- package/dist/icons/payment.d.ts +116 -0
- package/dist/icons/payment.js +2418 -0
- package/dist/icons.d.ts +2013 -0
- package/dist/icons.js +2012 -0
- package/dist/illustration.d.ts +48 -0
- package/dist/illustration.js +4 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +73 -0
- package/dist/indicator.d.ts +51 -0
- package/dist/indicator.js +7 -0
- package/dist/input.d.ts +66 -0
- package/dist/input.js +15 -0
- package/dist/multi-value-CJb_tnvi.d.ts +8 -0
- package/dist/nav-Bla0o_-1.d.ts +98 -0
- package/dist/number-input.d.ts +80 -0
- package/dist/number-input.js +15 -0
- package/dist/options-CPEIgjtd.d.ts +68 -0
- package/dist/overflow-Df0h42Oi.d.ts +29 -0
- package/dist/pagination.d.ts +77 -0
- package/dist/pagination.js +17 -0
- package/dist/payment-input.d.ts +7 -0
- package/dist/payment-input.js +15 -0
- package/dist/popover.d.ts +60 -0
- package/dist/popover.js +14 -0
- package/dist/progress.d.ts +87 -0
- package/dist/progress.js +5 -0
- package/dist/radio.d.ts +77 -0
- package/dist/radio.js +12 -0
- package/dist/select.d.ts +68 -0
- package/dist/select.js +24 -0
- package/dist/shared-BNXAdgh2.d.ts +9 -0
- package/dist/shared-BYXJPnsN.d.ts +11 -0
- package/dist/shared-Dc-GgA16.d.ts +42 -0
- package/dist/sidebar-navigation.d.ts +129 -0
- package/dist/sidebar-navigation.js +15 -0
- package/dist/styles.css +2 -0
- package/dist/switch.d.ts +23 -0
- package/dist/switch.js +7 -0
- package/dist/table.d.ts +692 -0
- package/dist/table.js +44 -0
- package/dist/tabs.d.ts +111 -0
- package/dist/tabs.js +8 -0
- package/dist/tag-input.d.ts +12 -0
- package/dist/tag-input.js +19 -0
- package/dist/tag.d.ts +98 -0
- package/dist/tag.js +9 -0
- package/dist/textarea.d.ts +40 -0
- package/dist/textarea.js +12 -0
- package/dist/theme-script.d.ts +29 -0
- package/dist/theme-script.js +15 -0
- package/dist/theme.css +929 -0
- package/dist/theme.d.ts +71 -0
- package/dist/theme.js +15 -0
- package/dist/toast.d.ts +242 -0
- package/dist/toast.js +15 -0
- package/dist/tooltip.d.ts +70 -0
- package/dist/tooltip.js +6 -0
- package/dist/tree.d.ts +308 -0
- package/dist/tree.js +11 -0
- package/package.json +352 -0
|
@@ -0,0 +1,1692 @@
|
|
|
1
|
+
import { Pagination } from './chunk-WFY7DKQD.js';
|
|
2
|
+
import { Callout } from './chunk-BVJWBYIG.js';
|
|
3
|
+
import { Badge } from './chunk-PWKWNDBS.js';
|
|
4
|
+
import { AlertDialog } from './chunk-THC2ISYP.js';
|
|
5
|
+
import { SkeletonBar, skeletonWidth } from './chunk-FXIBGTS5.js';
|
|
6
|
+
import { DropdownMenu } from './chunk-JP26LPCY.js';
|
|
7
|
+
import { useDebounced } from './chunk-F6NLE6XJ.js';
|
|
8
|
+
import { Checkbox } from './chunk-ZOOX3TUB.js';
|
|
9
|
+
import { SURFACE_BASE, SURFACE_VARIANT, SURFACE_EDGE_OVERLAY } from './chunk-MFJP5FA7.js';
|
|
10
|
+
import { Button } from './chunk-W46K56XU.js';
|
|
11
|
+
import { ButtonUtility } from './chunk-JVJRHBTD.js';
|
|
12
|
+
import { Input } from './chunk-7HOIZ3UO.js';
|
|
13
|
+
import { Select } from './chunk-T7FCG7XV.js';
|
|
14
|
+
import { Tag } from './chunk-R6RGJF4L.js';
|
|
15
|
+
import { overflowClasses } from './chunk-DWKILXHE.js';
|
|
16
|
+
import { ChevronRightIcon, ArrowDownIcon, ChevronsUpDownIcon, CircleAlertIcon, InboxIcon, EllipsisVerticalIcon, SearchIcon, Columns3Icon } from './chunk-24TO7E32.js';
|
|
17
|
+
import { TooltipExport } from './chunk-ZZA2LUTL.js';
|
|
18
|
+
import { warnPositiveInt, warnNonNegativeInt, devWarn } from './chunk-GCVA3OIV.js';
|
|
19
|
+
import { cn } from './chunk-ZSNJ6UA3.js';
|
|
20
|
+
import { useReactTable, getPaginationRowModel, getExpandedRowModel, getFacetedUniqueValues, getFacetedRowModel, getFilteredRowModel, getSortedRowModel, getCoreRowModel } from '@tanstack/react-table';
|
|
21
|
+
import * as React from 'react';
|
|
22
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
23
|
+
|
|
24
|
+
// src/components/table/columns.ts
|
|
25
|
+
function isColumnGroup(entry) {
|
|
26
|
+
return "columns" in entry && Array.isArray(entry.columns);
|
|
27
|
+
}
|
|
28
|
+
function flattenColumns(columns) {
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const entry of columns) {
|
|
31
|
+
if (isColumnGroup(entry)) out.push(...entry.columns);
|
|
32
|
+
else out.push(entry);
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
function hasColumnGroups(columns) {
|
|
37
|
+
return columns.some((entry) => isColumnGroup(entry));
|
|
38
|
+
}
|
|
39
|
+
function expansionChildren(result) {
|
|
40
|
+
if (!result || !("children" in result)) return null;
|
|
41
|
+
const children = result.children;
|
|
42
|
+
return children && children.length > 0 ? children : null;
|
|
43
|
+
}
|
|
44
|
+
function expansionDetail(result) {
|
|
45
|
+
if (!result || !("detail" in result)) return null;
|
|
46
|
+
return result.detail ?? null;
|
|
47
|
+
}
|
|
48
|
+
var toSet = (v) => v === void 0 ? void 0 : v instanceof Set ? v : new Set(v);
|
|
49
|
+
var EMPTY_SET = /* @__PURE__ */ new Set();
|
|
50
|
+
var EMPTY_FILTERS = Object.freeze({});
|
|
51
|
+
var EMPTY_PAGINATE = Object.freeze({});
|
|
52
|
+
function readValue(column, row) {
|
|
53
|
+
if (column.value) return column.value(row);
|
|
54
|
+
return row[column.key];
|
|
55
|
+
}
|
|
56
|
+
function asText(value) {
|
|
57
|
+
if (value === null || value === void 0) return "";
|
|
58
|
+
if (value instanceof Date) return value.toISOString();
|
|
59
|
+
return String(value);
|
|
60
|
+
}
|
|
61
|
+
var facetMatches = (raw, filterValue) => {
|
|
62
|
+
const wanted = filterValue;
|
|
63
|
+
if (!wanted || wanted.length === 0) return true;
|
|
64
|
+
if (Array.isArray(raw)) return raw.some((v) => wanted.includes(asText(v)));
|
|
65
|
+
return wanted.includes(asText(raw));
|
|
66
|
+
};
|
|
67
|
+
var textFilterFn = (row, columnId, filterValue) => {
|
|
68
|
+
const needle = String(filterValue ?? "").toLowerCase();
|
|
69
|
+
if (!needle) return true;
|
|
70
|
+
return asText(row.getValue(columnId)).toLowerCase().includes(needle);
|
|
71
|
+
};
|
|
72
|
+
var numberFilterFn = (row, columnId, filterValue) => {
|
|
73
|
+
const { min, max } = filterValue ?? {};
|
|
74
|
+
const n = Number(row.getValue(columnId));
|
|
75
|
+
if (Number.isNaN(n)) return false;
|
|
76
|
+
if (min !== void 0 && n < min) return false;
|
|
77
|
+
return !(max !== void 0 && n > max);
|
|
78
|
+
};
|
|
79
|
+
var dateRangeFilterFn = (row, columnId, filterValue) => {
|
|
80
|
+
const { from, to } = filterValue ?? {};
|
|
81
|
+
const day = asText(row.getValue(columnId)).slice(0, 10);
|
|
82
|
+
if (!day) return false;
|
|
83
|
+
if (from && day < from.slice(0, 10)) return false;
|
|
84
|
+
return !(to && day > to.slice(0, 10));
|
|
85
|
+
};
|
|
86
|
+
function filterPayload(value) {
|
|
87
|
+
switch (value.kind) {
|
|
88
|
+
case "facet": {
|
|
89
|
+
return value.values;
|
|
90
|
+
}
|
|
91
|
+
case "text": {
|
|
92
|
+
return value.value;
|
|
93
|
+
}
|
|
94
|
+
case "number": {
|
|
95
|
+
return { min: value.min, max: value.max };
|
|
96
|
+
}
|
|
97
|
+
case "dateRange": {
|
|
98
|
+
return { from: value.from, to: value.to };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function isNarrowing(value) {
|
|
103
|
+
switch (value.kind) {
|
|
104
|
+
case "facet": {
|
|
105
|
+
return value.values.length > 0;
|
|
106
|
+
}
|
|
107
|
+
case "text": {
|
|
108
|
+
return value.value.trim().length > 0;
|
|
109
|
+
}
|
|
110
|
+
case "number": {
|
|
111
|
+
return value.min !== void 0 || value.max !== void 0;
|
|
112
|
+
}
|
|
113
|
+
case "dateRange": {
|
|
114
|
+
return Boolean(value.from || value.to);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function describeFilter(value) {
|
|
119
|
+
switch (value.kind) {
|
|
120
|
+
case "facet": {
|
|
121
|
+
return value.values.join(", ");
|
|
122
|
+
}
|
|
123
|
+
case "text": {
|
|
124
|
+
return value.value;
|
|
125
|
+
}
|
|
126
|
+
case "number": {
|
|
127
|
+
if (value.min !== void 0 && value.max !== void 0) return `${value.min}\u2013${value.max}`;
|
|
128
|
+
if (value.min !== void 0) return `\u2265 ${value.min}`;
|
|
129
|
+
return `\u2264 ${value.max}`;
|
|
130
|
+
}
|
|
131
|
+
case "dateRange": {
|
|
132
|
+
if (value.from && value.to) return `${value.from} \u2013 ${value.to}`;
|
|
133
|
+
return value.from ? `from ${value.from}` : `until ${value.to}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function useTable(options) {
|
|
138
|
+
const {
|
|
139
|
+
rows,
|
|
140
|
+
columns,
|
|
141
|
+
getRowId,
|
|
142
|
+
manual = false,
|
|
143
|
+
paginate,
|
|
144
|
+
selection: selectionMode = "none",
|
|
145
|
+
expansion,
|
|
146
|
+
onSortChange,
|
|
147
|
+
onQueryChange,
|
|
148
|
+
onFiltersChange,
|
|
149
|
+
onSelectionChange,
|
|
150
|
+
onExpandedChange
|
|
151
|
+
} = options;
|
|
152
|
+
const pg = paginate === false ? null : paginate ?? EMPTY_PAGINATE;
|
|
153
|
+
const paginateOn = pg !== null;
|
|
154
|
+
const { rowCount, onPageChange, onPageSizeChange } = pg ?? EMPTY_PAGINATE;
|
|
155
|
+
const leafColumns = React.useMemo(() => flattenColumns(columns), [columns]);
|
|
156
|
+
const leafByKey = React.useMemo(
|
|
157
|
+
// Keyed by plain `string`: TanStack hands the filter an untyped `columnId`, and every id we
|
|
158
|
+
// register above IS one of these keys.
|
|
159
|
+
() => new Map(leafColumns.map((c) => [c.key, c])),
|
|
160
|
+
[leafColumns]
|
|
161
|
+
);
|
|
162
|
+
const [sortState, setSortState] = React.useState(options.defaultSort ?? null);
|
|
163
|
+
const sort = options.sort !== void 0 ? options.sort : sortState;
|
|
164
|
+
const [queryState, setQueryState] = React.useState(options.defaultQuery ?? "");
|
|
165
|
+
const query = options.query !== void 0 ? options.query : queryState;
|
|
166
|
+
const searchDebounce = options.searchDebounce ?? 0;
|
|
167
|
+
const debouncedQuery = useDebounced(query, searchDebounce);
|
|
168
|
+
const appliedQuery = query === "" ? "" : debouncedQuery;
|
|
169
|
+
const [pageState, setPageState] = React.useState(pg?.defaultPage ?? 1);
|
|
170
|
+
const page = pg?.page !== void 0 ? pg.page : pageState;
|
|
171
|
+
const [pageSizeState, setPageSizeState] = React.useState(pg?.defaultPageSize ?? 10);
|
|
172
|
+
const pageSize = pg?.pageSize !== void 0 ? pg.pageSize : pageSizeState;
|
|
173
|
+
const [selectionState, setSelectionState] = React.useState(() => toSet(options.defaultSelectedRows) ?? EMPTY_SET);
|
|
174
|
+
const selection = toSet(options.selectedRows) ?? selectionState;
|
|
175
|
+
const [expandedState, setExpandedState] = React.useState(() => toSet(options.defaultExpanded) ?? EMPTY_SET);
|
|
176
|
+
const expanded = toSet(options.expanded) ?? expandedState;
|
|
177
|
+
const [filtersState, setFiltersState] = React.useState(options.defaultFilters ?? EMPTY_FILTERS);
|
|
178
|
+
const filters = options.filters !== void 0 ? options.filters : filtersState;
|
|
179
|
+
const [columnVisibility, setColumnVisibilityState] = React.useState(() => {
|
|
180
|
+
const initial = {};
|
|
181
|
+
for (const c of leafColumns) if (c.defaultHidden) initial[c.key] = false;
|
|
182
|
+
return initial;
|
|
183
|
+
});
|
|
184
|
+
React.useEffect(() => {
|
|
185
|
+
if (pg?.pageSize !== void 0) warnPositiveInt("Table", "pageSize", pg.pageSize);
|
|
186
|
+
if (pg?.page !== void 0) warnPositiveInt("Table", "page", pg.page);
|
|
187
|
+
if (rowCount !== void 0) warnPositiveInt("Table", "rowCount", rowCount);
|
|
188
|
+
warnPositiveInt("Table", "defaultPageSize", pg?.defaultPageSize);
|
|
189
|
+
warnPositiveInt("Table", "defaultPage", pg?.defaultPage);
|
|
190
|
+
warnNonNegativeInt("Table", "searchDebounce", options.searchDebounce);
|
|
191
|
+
if (manual && paginateOn && rowCount === void 0) {
|
|
192
|
+
devWarn("Table: `manual` pagination needs `rowCount` \u2014 without it the page count is unknowable and the footer will read `of 1`.");
|
|
193
|
+
}
|
|
194
|
+
}, [pg?.pageSize, pg?.page, pg?.defaultPageSize, pg?.defaultPage, rowCount, manual, paginateOn, options.searchDebounce]);
|
|
195
|
+
const columnDefs = React.useMemo(
|
|
196
|
+
() => leafColumns.map((column) => {
|
|
197
|
+
const filter = column.filter;
|
|
198
|
+
const facetAccessor = filter?.kind === "facet" ? filter.getValue : void 0;
|
|
199
|
+
const accessorFn = (row) => readValue(column, row);
|
|
200
|
+
const filterFn = filter?.kind === "facet" ? (
|
|
201
|
+
// Per-column, because the facet values are no longer what `row.getValue` returns:
|
|
202
|
+
// matching has to read the same members faceting counted, or a picked chip would
|
|
203
|
+
// filter nothing.
|
|
204
|
+
(row, _columnId, filterValue) => facetMatches(facetAccessor ? facetAccessor(row.original) : readValue(column, row.original), filterValue)
|
|
205
|
+
) : filter?.kind === "number" ? numberFilterFn : filter?.kind === "dateRange" ? dateRangeFilterFn : textFilterFn;
|
|
206
|
+
return {
|
|
207
|
+
id: column.key,
|
|
208
|
+
accessorFn,
|
|
209
|
+
// Always an array, per TanStack's contract for this option.
|
|
210
|
+
...facetAccessor && {
|
|
211
|
+
getUniqueValues: (row) => {
|
|
212
|
+
const v = facetAccessor(row);
|
|
213
|
+
return Array.isArray(v) ? v : [v];
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
enableSorting: column.sortable ?? false,
|
|
217
|
+
enableColumnFilter: Boolean(filter),
|
|
218
|
+
enableHiding: column.hideable ?? true,
|
|
219
|
+
filterFn
|
|
220
|
+
};
|
|
221
|
+
}),
|
|
222
|
+
[leafColumns]
|
|
223
|
+
);
|
|
224
|
+
const sorting = React.useMemo(() => sort ? [{ id: sort.key, desc: sort.dir === "desc" }] : [], [sort]);
|
|
225
|
+
const columnFilters = React.useMemo(() => {
|
|
226
|
+
const out = [];
|
|
227
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
228
|
+
if (value && isNarrowing(value)) out.push({ id: key, value: filterPayload(value) });
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
}, [filters]);
|
|
232
|
+
const tanstackExpanded = React.useMemo(() => {
|
|
233
|
+
const out = {};
|
|
234
|
+
for (const id of expanded) out[id] = true;
|
|
235
|
+
return out;
|
|
236
|
+
}, [expanded]);
|
|
237
|
+
const getSubRows = React.useMemo(() => {
|
|
238
|
+
if (!expansion) return;
|
|
239
|
+
return (row) => {
|
|
240
|
+
const result = expansion(row);
|
|
241
|
+
return result && "children" in result ? result.children : void 0;
|
|
242
|
+
};
|
|
243
|
+
}, [expansion]);
|
|
244
|
+
const table = useReactTable({
|
|
245
|
+
data: rows,
|
|
246
|
+
columns: columnDefs,
|
|
247
|
+
getRowId: (row) => getRowId(row),
|
|
248
|
+
getSubRows,
|
|
249
|
+
state: {
|
|
250
|
+
sorting,
|
|
251
|
+
columnFilters,
|
|
252
|
+
globalFilter: appliedQuery,
|
|
253
|
+
expanded: tanstackExpanded,
|
|
254
|
+
columnVisibility,
|
|
255
|
+
pagination: { pageIndex: Math.max(0, page - 1), pageSize }
|
|
256
|
+
},
|
|
257
|
+
manualSorting: manual,
|
|
258
|
+
manualFiltering: manual,
|
|
259
|
+
manualPagination: manual || !paginateOn,
|
|
260
|
+
...manual && rowCount !== void 0 && { rowCount },
|
|
261
|
+
// We own every reset (see the invariants at the top) — TanStack's automatic page reset would
|
|
262
|
+
// fire on unrelated data identity changes and fight the clamp below.
|
|
263
|
+
autoResetPageIndex: false,
|
|
264
|
+
autoResetExpanded: false,
|
|
265
|
+
// Reads ONLY the column it was handed. TanStack invokes the global filter once per
|
|
266
|
+
// (row, globally-filterable column) and passes a row if any call returns true — so scanning
|
|
267
|
+
// every column inside each call did the whole sweep once per column: N² text reads per
|
|
268
|
+
// non-matching row. Measured at 100 rows × 10 columns with a query that matches nothing,
|
|
269
|
+
// this went from 10,010 accessor calls to 1,010 — a flat 10×, and it grows with the column
|
|
270
|
+
// count, undebounced, on every keystroke.
|
|
271
|
+
//
|
|
272
|
+
// The searched SET is unchanged: every leaf column gets an `accessorFn` above and none
|
|
273
|
+
// disables global filtering, so TanStack calls this for each of them and the union is the
|
|
274
|
+
// same set the old sweep walked. `readValue` (not the facet accessor) keeps the searched TEXT
|
|
275
|
+
// identical too.
|
|
276
|
+
globalFilterFn: (row, columnId, filterValue) => {
|
|
277
|
+
const needle = String(filterValue ?? "").toLowerCase();
|
|
278
|
+
if (!needle) return true;
|
|
279
|
+
const column = leafByKey.get(columnId);
|
|
280
|
+
return column ? asText(readValue(column, row.original)).toLowerCase().includes(needle) : false;
|
|
281
|
+
},
|
|
282
|
+
getCoreRowModel: getCoreRowModel(),
|
|
283
|
+
getSortedRowModel: getSortedRowModel(),
|
|
284
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
285
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
286
|
+
getFacetedUniqueValues: getFacetedUniqueValues(),
|
|
287
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
288
|
+
// `paginateExpandedRows: false` means expanded children ride with their parent instead of
|
|
289
|
+
// consuming page slots — otherwise expanding a row reflows the page and can push its own
|
|
290
|
+
// parent off it. It may ONLY be set alongside the pagination row model: with it on, the
|
|
291
|
+
// EXPANDED model deliberately stops flattening (pagination re-expands after slicing), so
|
|
292
|
+
// setting it without a pagination model silently hides every child row.
|
|
293
|
+
...paginateOn && !manual && { getPaginationRowModel: getPaginationRowModel(), paginateExpandedRows: false }
|
|
294
|
+
});
|
|
295
|
+
const filteredRows = React.useMemo(
|
|
296
|
+
() => manual ? rows : table.getFilteredRowModel().rows.map((r) => r.original),
|
|
297
|
+
// `table` is stable; the row model changes with the state above.
|
|
298
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
299
|
+
[manual, rows, table, sorting, columnFilters, appliedQuery]
|
|
300
|
+
);
|
|
301
|
+
const modelRows = manual ? null : table.getRowModel().rows;
|
|
302
|
+
const visibleRows = React.useMemo(() => modelRows ? modelRows.map((r) => r.original) : rows, [modelRows, rows]);
|
|
303
|
+
const rowDepth = React.useMemo(() => {
|
|
304
|
+
const map = /* @__PURE__ */ new Map();
|
|
305
|
+
if (modelRows) for (const r of modelRows) map.set(r.id, r.depth);
|
|
306
|
+
return map;
|
|
307
|
+
}, [modelRows]);
|
|
308
|
+
const totalRows = manual ? rowCount ?? rows.length : filteredRows.length;
|
|
309
|
+
const pageCount = paginateOn ? Math.max(1, Math.ceil(totalRows / Math.max(1, pageSize))) : 1;
|
|
310
|
+
const commitPage = React.useCallback(
|
|
311
|
+
(next) => {
|
|
312
|
+
const clamped = Math.min(Math.max(1, next), pageCount);
|
|
313
|
+
if (pg?.page === void 0) setPageState(clamped);
|
|
314
|
+
onPageChange?.(clamped);
|
|
315
|
+
},
|
|
316
|
+
[onPageChange, pg?.page, pageCount]
|
|
317
|
+
);
|
|
318
|
+
React.useEffect(() => {
|
|
319
|
+
if (!paginateOn) return;
|
|
320
|
+
if (page > pageCount) commitPage(pageCount);
|
|
321
|
+
else if (page < 1) commitPage(1);
|
|
322
|
+
}, [page, pageCount, paginateOn, commitPage]);
|
|
323
|
+
const commitSelection = React.useCallback(
|
|
324
|
+
(next) => {
|
|
325
|
+
if (options.selectedRows === void 0) setSelectionState(next);
|
|
326
|
+
onSelectionChange?.(next);
|
|
327
|
+
},
|
|
328
|
+
[onSelectionChange, options.selectedRows]
|
|
329
|
+
);
|
|
330
|
+
const resetSelection = React.useCallback(() => {
|
|
331
|
+
if (selection.size > 0) commitSelection(EMPTY_SET);
|
|
332
|
+
}, [commitSelection, selection]);
|
|
333
|
+
const resetPage = React.useCallback(() => {
|
|
334
|
+
if (page === 1) return;
|
|
335
|
+
if (pg?.page === void 0) setPageState(1);
|
|
336
|
+
onPageChange?.(1);
|
|
337
|
+
}, [onPageChange, page, pg?.page]);
|
|
338
|
+
const resetScope = React.useCallback(() => {
|
|
339
|
+
resetPage();
|
|
340
|
+
resetSelection();
|
|
341
|
+
}, [resetPage, resetSelection]);
|
|
342
|
+
const setQuery = React.useCallback(
|
|
343
|
+
(next) => {
|
|
344
|
+
if (options.query === void 0) setQueryState(next);
|
|
345
|
+
onQueryChange?.(next);
|
|
346
|
+
if (searchDebounce <= 0) resetScope();
|
|
347
|
+
},
|
|
348
|
+
[onQueryChange, options.query, resetScope, searchDebounce]
|
|
349
|
+
);
|
|
350
|
+
const appliedQueryRef = React.useRef(appliedQuery);
|
|
351
|
+
React.useEffect(() => {
|
|
352
|
+
if (appliedQueryRef.current === appliedQuery) return;
|
|
353
|
+
appliedQueryRef.current = appliedQuery;
|
|
354
|
+
if (searchDebounce > 0) resetScope();
|
|
355
|
+
}, [appliedQuery, searchDebounce]);
|
|
356
|
+
const commitFilters = React.useCallback(
|
|
357
|
+
(next) => {
|
|
358
|
+
if (options.filters === void 0) setFiltersState(next);
|
|
359
|
+
onFiltersChange?.(next);
|
|
360
|
+
},
|
|
361
|
+
[onFiltersChange, options.filters]
|
|
362
|
+
);
|
|
363
|
+
const setFilter = React.useCallback(
|
|
364
|
+
(key, value) => {
|
|
365
|
+
const next = { ...filters };
|
|
366
|
+
if (value === null) delete next[key];
|
|
367
|
+
else next[key] = value;
|
|
368
|
+
commitFilters(next);
|
|
369
|
+
resetScope();
|
|
370
|
+
},
|
|
371
|
+
[commitFilters, filters, resetScope]
|
|
372
|
+
);
|
|
373
|
+
const clearFilters = React.useCallback(() => {
|
|
374
|
+
if (Object.keys(filters).length > 0) commitFilters(EMPTY_FILTERS);
|
|
375
|
+
if (options.query === void 0) setQueryState("");
|
|
376
|
+
onQueryChange?.("");
|
|
377
|
+
resetScope();
|
|
378
|
+
}, [commitFilters, filters, onQueryChange, options.query, resetScope]);
|
|
379
|
+
const setSort = React.useCallback(
|
|
380
|
+
(next) => {
|
|
381
|
+
if (options.sort === void 0) setSortState(next);
|
|
382
|
+
onSortChange?.(next);
|
|
383
|
+
},
|
|
384
|
+
[onSortChange, options.sort]
|
|
385
|
+
);
|
|
386
|
+
const toggleSort = React.useCallback(
|
|
387
|
+
(key) => {
|
|
388
|
+
if (!sort || sort.key !== key) setSort({ key, dir: "asc" });
|
|
389
|
+
else if (sort.dir === "asc") setSort({ key, dir: "desc" });
|
|
390
|
+
else setSort(null);
|
|
391
|
+
},
|
|
392
|
+
[setSort, sort]
|
|
393
|
+
);
|
|
394
|
+
const setPageSize = React.useCallback(
|
|
395
|
+
(size) => {
|
|
396
|
+
warnPositiveInt("Table", "pageSize", size);
|
|
397
|
+
if (pg?.pageSize === void 0) setPageSizeState(size);
|
|
398
|
+
onPageSizeChange?.(size);
|
|
399
|
+
resetPage();
|
|
400
|
+
},
|
|
401
|
+
[onPageSizeChange, pg?.pageSize, resetPage]
|
|
402
|
+
);
|
|
403
|
+
const setPage = commitPage;
|
|
404
|
+
const isSelectable = React.useCallback(
|
|
405
|
+
(row) => (rowDepth.get(getRowId(row)) ?? 0) === 0 && !options.disabledRows?.(row),
|
|
406
|
+
[rowDepth, getRowId, options.disabledRows]
|
|
407
|
+
);
|
|
408
|
+
const pageIds = React.useMemo(() => visibleRows.filter(isSelectable).map(getRowId), [visibleRows, isSelectable, getRowId]);
|
|
409
|
+
const allIds = React.useMemo(() => filteredRows.filter((row) => !options.disabledRows?.(row)).map(getRowId), [filteredRows, getRowId, options.disabledRows]);
|
|
410
|
+
const selectionOnPage = React.useMemo(() => pageIds.filter((id) => selection.has(id)).length, [pageIds, selection]);
|
|
411
|
+
const selState = React.useMemo(() => {
|
|
412
|
+
if (selection.size === 0) return "none";
|
|
413
|
+
if (allIds.length > 0 && selection.size >= totalRows && allIds.every((id) => selection.has(id))) return "all";
|
|
414
|
+
if (pageIds.length > 0 && pageIds.every((id) => selection.has(id))) return "page";
|
|
415
|
+
return "some";
|
|
416
|
+
}, [allIds, pageIds, selection, totalRows]);
|
|
417
|
+
const toggleRow = React.useCallback(
|
|
418
|
+
(id) => {
|
|
419
|
+
if (selectionMode === "none") return;
|
|
420
|
+
if (selectionMode === "single") {
|
|
421
|
+
commitSelection(selection.has(id) ? EMPTY_SET : /* @__PURE__ */ new Set([id]));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const next = new Set(selection);
|
|
425
|
+
if (next.has(id)) next.delete(id);
|
|
426
|
+
else next.add(id);
|
|
427
|
+
commitSelection(next);
|
|
428
|
+
},
|
|
429
|
+
[commitSelection, selection, selectionMode]
|
|
430
|
+
);
|
|
431
|
+
const selectOnly = React.useCallback(
|
|
432
|
+
(id) => {
|
|
433
|
+
if (selectionMode === "none") return;
|
|
434
|
+
commitSelection(/* @__PURE__ */ new Set([id]));
|
|
435
|
+
},
|
|
436
|
+
[commitSelection, selectionMode]
|
|
437
|
+
);
|
|
438
|
+
const togglePage = React.useCallback(() => {
|
|
439
|
+
if (selectionMode !== "multiple") return;
|
|
440
|
+
const everySelected = pageIds.length > 0 && pageIds.every((id) => selection.has(id));
|
|
441
|
+
const next = new Set(selection);
|
|
442
|
+
for (const id of pageIds) {
|
|
443
|
+
if (everySelected) next.delete(id);
|
|
444
|
+
else next.add(id);
|
|
445
|
+
}
|
|
446
|
+
commitSelection(next);
|
|
447
|
+
}, [commitSelection, pageIds, selection, selectionMode]);
|
|
448
|
+
const selectAll = React.useCallback(() => {
|
|
449
|
+
if (selectionMode !== "multiple") return;
|
|
450
|
+
commitSelection(new Set(allIds));
|
|
451
|
+
}, [allIds, commitSelection, selectionMode]);
|
|
452
|
+
const clearSelection = React.useCallback(() => commitSelection(EMPTY_SET), [commitSelection]);
|
|
453
|
+
const commitExpanded = React.useCallback(
|
|
454
|
+
(next) => {
|
|
455
|
+
if (options.expanded === void 0) setExpandedState(next);
|
|
456
|
+
onExpandedChange?.(next);
|
|
457
|
+
},
|
|
458
|
+
[onExpandedChange, options.expanded]
|
|
459
|
+
);
|
|
460
|
+
const toggleExpanded = React.useCallback(
|
|
461
|
+
(id) => {
|
|
462
|
+
const next = new Set(expanded);
|
|
463
|
+
if (next.has(id)) next.delete(id);
|
|
464
|
+
else next.add(id);
|
|
465
|
+
commitExpanded(next);
|
|
466
|
+
},
|
|
467
|
+
[commitExpanded, expanded]
|
|
468
|
+
);
|
|
469
|
+
const expandAll = React.useCallback(() => {
|
|
470
|
+
if (!expansion) return;
|
|
471
|
+
const ids = /* @__PURE__ */ new Set();
|
|
472
|
+
const walk = (list) => {
|
|
473
|
+
for (const row of list) {
|
|
474
|
+
const result = expansion(row);
|
|
475
|
+
if (!result) continue;
|
|
476
|
+
ids.add(getRowId(row));
|
|
477
|
+
if ("children" in result && result.children) walk(result.children);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
walk(rows);
|
|
481
|
+
commitExpanded(ids);
|
|
482
|
+
}, [commitExpanded, expansion, getRowId, rows]);
|
|
483
|
+
const collapseAll = React.useCallback(() => commitExpanded(EMPTY_SET), [commitExpanded]);
|
|
484
|
+
const facetCounts = React.useCallback(
|
|
485
|
+
(key) => {
|
|
486
|
+
const column = table.getColumn(key);
|
|
487
|
+
const raw = column?.getFacetedUniqueValues() ?? /* @__PURE__ */ new Map();
|
|
488
|
+
const out = /* @__PURE__ */ new Map();
|
|
489
|
+
for (const [value, count] of raw) {
|
|
490
|
+
if (Array.isArray(value)) {
|
|
491
|
+
for (const member of value) out.set(asText(member), (out.get(asText(member)) ?? 0) + count);
|
|
492
|
+
} else if (value !== null && value !== void 0) {
|
|
493
|
+
out.set(asText(value), (out.get(asText(value)) ?? 0) + count);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return out;
|
|
497
|
+
},
|
|
498
|
+
[table]
|
|
499
|
+
);
|
|
500
|
+
const activeFilters = React.useMemo(() => {
|
|
501
|
+
const out = [];
|
|
502
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
503
|
+
if (!value || !isNarrowing(value)) continue;
|
|
504
|
+
const column = leafColumns.find((c) => c.key === key);
|
|
505
|
+
const declared = column?.filter;
|
|
506
|
+
const label2 = declared && "label" in declared && declared.label || (typeof column?.header === "string" ? column.header : key);
|
|
507
|
+
out.push({ key, label: label2, display: describeFilter(value), clear: () => setFilter(key, null) });
|
|
508
|
+
}
|
|
509
|
+
return out;
|
|
510
|
+
}, [filters, leafColumns, setFilter]);
|
|
511
|
+
const isFiltered = activeFilters.length > 0 || appliedQuery.trim().length > 0;
|
|
512
|
+
const setColumnVisible = React.useCallback((key, visible) => {
|
|
513
|
+
setColumnVisibilityState((prev) => ({ ...prev, [key]: visible }));
|
|
514
|
+
}, []);
|
|
515
|
+
const toggleColumn = React.useCallback((key) => {
|
|
516
|
+
setColumnVisibilityState((prev) => ({ ...prev, [key]: prev[key] === false }));
|
|
517
|
+
}, []);
|
|
518
|
+
const isTree = React.useMemo(() => expansion ? rows.some((row) => expansionChildren(expansion(row)) !== null) : false, [expansion, rows]);
|
|
519
|
+
return {
|
|
520
|
+
rows: visibleRows,
|
|
521
|
+
filteredRows,
|
|
522
|
+
totalRows,
|
|
523
|
+
query,
|
|
524
|
+
setQuery,
|
|
525
|
+
appliedQuery,
|
|
526
|
+
filters,
|
|
527
|
+
setFilter,
|
|
528
|
+
clearFilters,
|
|
529
|
+
activeFilters,
|
|
530
|
+
isFiltered,
|
|
531
|
+
facetCounts,
|
|
532
|
+
sort,
|
|
533
|
+
setSort,
|
|
534
|
+
toggleSort,
|
|
535
|
+
page,
|
|
536
|
+
pageCount,
|
|
537
|
+
pageSize,
|
|
538
|
+
setPage,
|
|
539
|
+
setPageSize,
|
|
540
|
+
selectionMode,
|
|
541
|
+
selection,
|
|
542
|
+
selectionState: selState,
|
|
543
|
+
selectionOnPage,
|
|
544
|
+
toggleRow,
|
|
545
|
+
selectOnly,
|
|
546
|
+
togglePage,
|
|
547
|
+
selectAll,
|
|
548
|
+
clearSelection,
|
|
549
|
+
expanded,
|
|
550
|
+
toggleExpanded,
|
|
551
|
+
expandAll,
|
|
552
|
+
collapseAll,
|
|
553
|
+
columnVisibility,
|
|
554
|
+
toggleColumn,
|
|
555
|
+
setColumnVisible,
|
|
556
|
+
manual,
|
|
557
|
+
columns,
|
|
558
|
+
expansion,
|
|
559
|
+
disabledRows: options.disabledRows,
|
|
560
|
+
getRowId,
|
|
561
|
+
isTree,
|
|
562
|
+
rowDepth
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
function cellContent(column, row) {
|
|
566
|
+
if (column.cell) return column.cell(row);
|
|
567
|
+
const raw = row[column.key];
|
|
568
|
+
if (raw === null || raw === void 0) return null;
|
|
569
|
+
if (raw instanceof Date) return raw.toISOString().slice(0, 10);
|
|
570
|
+
if (React.isValidElement(raw)) return raw;
|
|
571
|
+
return String(raw);
|
|
572
|
+
}
|
|
573
|
+
function toMenuItems(items, run) {
|
|
574
|
+
return items.map((item) => {
|
|
575
|
+
if ("separator" in item) return item;
|
|
576
|
+
if ("type" in item) return item;
|
|
577
|
+
if ("group" in item) return { group: item.group, items: toMenuItems(item.items, run) };
|
|
578
|
+
if ("items" in item) {
|
|
579
|
+
const { icon, items: children, ...rest } = item;
|
|
580
|
+
return { ...rest, leading: icon, items: toMenuItems(children, run) };
|
|
581
|
+
}
|
|
582
|
+
return {
|
|
583
|
+
label: item.label,
|
|
584
|
+
leading: item.icon,
|
|
585
|
+
disabled: item.disabled,
|
|
586
|
+
// The one lossy part of the map, and deliberately so: a menu row has `default | destructive`,
|
|
587
|
+
// not the library's six-tone colour axis, because a menu is a stack of text rows and five
|
|
588
|
+
// tints of text in one popup is noise. `error` is the tone that MEANS something here.
|
|
589
|
+
//
|
|
590
|
+
// It was previously dropped entirely, so the same `tone: "error"` Delete rendered red under
|
|
591
|
+
// `icons`/`links` and plain under `menu` — the destructive action was the one action the
|
|
592
|
+
// variants disagreed about.
|
|
593
|
+
variant: item.tone === "error" ? "destructive" : void 0,
|
|
594
|
+
// A disabled action is never a link — `<a>` has no disabled state, and dropping the href is
|
|
595
|
+
// what actually makes it inert (`DropdownMenu` still marks it `aria-disabled`).
|
|
596
|
+
href: item.disabled ? void 0 : item.href,
|
|
597
|
+
onClick: () => run(item)
|
|
598
|
+
};
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
function linkRender(action) {
|
|
602
|
+
return action.href && !action.disabled ? /* @__PURE__ */ jsx("a", { href: action.href }) : void 0;
|
|
603
|
+
}
|
|
604
|
+
function RowActionsCell({ row, config, size, onConfirm }) {
|
|
605
|
+
const run = (action) => {
|
|
606
|
+
if (action.disabled) return;
|
|
607
|
+
const fire = () => action.onClick?.();
|
|
608
|
+
if (action.confirm) onConfirm({ label: action.label, tone: action.tone, confirm: action.confirm, run: fire });
|
|
609
|
+
else fire();
|
|
610
|
+
};
|
|
611
|
+
if (config.variant === "menu") {
|
|
612
|
+
const items = config.items(row);
|
|
613
|
+
if (items.length === 0) return null;
|
|
614
|
+
return /* @__PURE__ */ jsx(
|
|
615
|
+
DropdownMenu,
|
|
616
|
+
{
|
|
617
|
+
trigger: /* @__PURE__ */ jsx(ButtonUtility, { size: "sm", variant: "tertiary", icon: /* @__PURE__ */ jsx(EllipsisVerticalIcon, {}), "aria-label": "Row actions" }),
|
|
618
|
+
items: toMenuItems(items, run),
|
|
619
|
+
align: "end"
|
|
620
|
+
}
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
const { variant = "icons", max = 3 } = config;
|
|
624
|
+
const actions = config.items(row);
|
|
625
|
+
if (actions.length === 0) return null;
|
|
626
|
+
const inline = actions.length > max ? actions.slice(0, max - 1) : actions;
|
|
627
|
+
const overflow = actions.length > max ? actions.slice(max - 1) : [];
|
|
628
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("flex items-center", variant === "links" ? "gap-3" : "gap-0.5"), children: [
|
|
629
|
+
inline.map(
|
|
630
|
+
(action) => variant === "links" ? /* @__PURE__ */ jsx(
|
|
631
|
+
Button,
|
|
632
|
+
{
|
|
633
|
+
render: linkRender(action),
|
|
634
|
+
variant: "link",
|
|
635
|
+
color: action.tone ?? "neutral",
|
|
636
|
+
size: size === "sm" ? "sm" : "md",
|
|
637
|
+
disabled: action.disabled,
|
|
638
|
+
onClick: () => run(action),
|
|
639
|
+
children: action.label
|
|
640
|
+
},
|
|
641
|
+
action.label
|
|
642
|
+
) : /* @__PURE__ */ jsx(
|
|
643
|
+
ButtonUtility,
|
|
644
|
+
{
|
|
645
|
+
render: linkRender(action),
|
|
646
|
+
size: "sm",
|
|
647
|
+
variant: "tertiary",
|
|
648
|
+
icon: action.icon,
|
|
649
|
+
"aria-label": action.label,
|
|
650
|
+
tooltip: action.label,
|
|
651
|
+
disabled: action.disabled,
|
|
652
|
+
onClick: () => run(action)
|
|
653
|
+
},
|
|
654
|
+
action.label
|
|
655
|
+
)
|
|
656
|
+
),
|
|
657
|
+
overflow.length > 0 ? /* @__PURE__ */ jsx(
|
|
658
|
+
DropdownMenu,
|
|
659
|
+
{
|
|
660
|
+
trigger: /* @__PURE__ */ jsx(ButtonUtility, { size: "sm", variant: "tertiary", icon: /* @__PURE__ */ jsx(EllipsisVerticalIcon, {}), "aria-label": "More actions" }),
|
|
661
|
+
items: toMenuItems(overflow, run),
|
|
662
|
+
align: "end"
|
|
663
|
+
}
|
|
664
|
+
) : null
|
|
665
|
+
] });
|
|
666
|
+
}
|
|
667
|
+
function ConfirmAction({ action, onClose }) {
|
|
668
|
+
return /* @__PURE__ */ jsx(
|
|
669
|
+
AlertDialog,
|
|
670
|
+
{
|
|
671
|
+
open: true,
|
|
672
|
+
onOpenChange: (next) => {
|
|
673
|
+
if (!next) onClose();
|
|
674
|
+
},
|
|
675
|
+
title: action.confirm?.title ?? action.label,
|
|
676
|
+
description: action.confirm?.description,
|
|
677
|
+
footer: (close) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
678
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: close, children: "Cancel" }),
|
|
679
|
+
/* @__PURE__ */ jsx(
|
|
680
|
+
Button,
|
|
681
|
+
{
|
|
682
|
+
variant: "primary",
|
|
683
|
+
color: action.tone ?? "brand",
|
|
684
|
+
onClick: () => {
|
|
685
|
+
action.run();
|
|
686
|
+
close();
|
|
687
|
+
},
|
|
688
|
+
children: action.confirm?.confirmLabel ?? action.label
|
|
689
|
+
}
|
|
690
|
+
)
|
|
691
|
+
] })
|
|
692
|
+
}
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
function TableErrorState({ error, onRetry }) {
|
|
696
|
+
if (typeof error !== "string") return /* @__PURE__ */ jsx(Fragment, { children: error });
|
|
697
|
+
return /* @__PURE__ */ jsx(
|
|
698
|
+
Callout,
|
|
699
|
+
{
|
|
700
|
+
tone: "error",
|
|
701
|
+
icon: /* @__PURE__ */ jsx(CircleAlertIcon, {}),
|
|
702
|
+
title: error,
|
|
703
|
+
description: "The data could not be loaded.",
|
|
704
|
+
actions: onRetry ? [{ label: "Try again", onClick: onRetry, variant: "primary" }] : void 0
|
|
705
|
+
}
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
function TableEmptyState({ isFiltered, query, onClearFilters }) {
|
|
709
|
+
const typed = query.trim();
|
|
710
|
+
return /* @__PURE__ */ jsx(
|
|
711
|
+
Callout,
|
|
712
|
+
{
|
|
713
|
+
icon: /* @__PURE__ */ jsx(InboxIcon, {}),
|
|
714
|
+
title: isFiltered ? "No matching results" : "Nothing here yet",
|
|
715
|
+
description: !isFiltered ? "Rows will appear here once there is data." : typed ? `Your search \u201C${typed}\u201D did not match any rows. Try a different search, or clear the filters.` : "Try a different search, or clear the filters to see everything.",
|
|
716
|
+
actions: isFiltered ? [{ label: "Clear filters", onClick: onClearFilters }] : void 0
|
|
717
|
+
}
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
function label(column) {
|
|
721
|
+
return column.header ?? column.key;
|
|
722
|
+
}
|
|
723
|
+
function TableCardStack(props) {
|
|
724
|
+
const {
|
|
725
|
+
table,
|
|
726
|
+
columns,
|
|
727
|
+
getRowId,
|
|
728
|
+
size,
|
|
729
|
+
selection,
|
|
730
|
+
rowActions,
|
|
731
|
+
expansion,
|
|
732
|
+
rowClick,
|
|
733
|
+
disabledRows,
|
|
734
|
+
loading,
|
|
735
|
+
loadingRows = 5,
|
|
736
|
+
error,
|
|
737
|
+
onRetry,
|
|
738
|
+
empty,
|
|
739
|
+
onConfirm
|
|
740
|
+
} = props;
|
|
741
|
+
const primary = columns.find((column) => column.cardPriority === "primary") ?? columns[0];
|
|
742
|
+
const body = columns.filter((column) => column !== primary && column.cardPriority !== "hidden");
|
|
743
|
+
const sortable = columns.filter((column) => column.sortable);
|
|
744
|
+
const pad = size === "sm" ? "p-4" : "p-5";
|
|
745
|
+
if (!loading && error != null) {
|
|
746
|
+
return /* @__PURE__ */ jsx("div", { className: pad, children: /* @__PURE__ */ jsx(TableErrorState, { error, onRetry }) });
|
|
747
|
+
}
|
|
748
|
+
if (!loading && table.rows.length === 0) {
|
|
749
|
+
return /* @__PURE__ */ jsx("div", { className: pad, children: empty ?? /* @__PURE__ */ jsx(TableEmptyState, { isFiltered: table.isFiltered, query: table.query, onClearFilters: table.clearFilters }) });
|
|
750
|
+
}
|
|
751
|
+
if (loading) {
|
|
752
|
+
return /* @__PURE__ */ jsx("ul", { "aria-busy": "true", className: "divide-y divide-border-secondary", children: Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ jsxs("li", { className: cn("flex flex-col gap-3", pad), children: [
|
|
753
|
+
/* @__PURE__ */ jsx(SkeletonBar, { className: "h-5 w-1/2" }),
|
|
754
|
+
/* @__PURE__ */ jsx(SkeletonBar, { className: cn("h-4", skeletonWidth(index)) }),
|
|
755
|
+
/* @__PURE__ */ jsx(SkeletonBar, { className: cn("h-4", skeletonWidth(index + 2)) })
|
|
756
|
+
] }, index)) });
|
|
757
|
+
}
|
|
758
|
+
const rowClickSelects = rowClick === "select";
|
|
759
|
+
const rowClickExpands = rowClick === "expand";
|
|
760
|
+
const onRowClick = typeof rowClick === "function" ? rowClick : null;
|
|
761
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
762
|
+
sortable.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 border-b border-secondary px-4 py-3", children: [
|
|
763
|
+
/* @__PURE__ */ jsxs("label", { className: "flex items-center gap-2 text-sm text-tertiary", children: [
|
|
764
|
+
/* @__PURE__ */ jsx("span", { className: "whitespace-nowrap", children: "Sort by" }),
|
|
765
|
+
/* @__PURE__ */ jsxs(
|
|
766
|
+
"select",
|
|
767
|
+
{
|
|
768
|
+
value: table.sort?.key ?? "",
|
|
769
|
+
onChange: (event) => table.setSort(event.target.value ? { key: event.target.value, dir: table.sort?.dir ?? "asc" } : null),
|
|
770
|
+
className: "h-9 rounded-lg bg-primary px-3 text-sm text-primary ring-1 ring-secondary outline-focus-ring ring-inset focus-visible:outline-2",
|
|
771
|
+
children: [
|
|
772
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "None" }),
|
|
773
|
+
sortable.map((column) => /* @__PURE__ */ jsx("option", { value: column.key, children: typeof column.header === "string" ? column.header : column.key }, column.key))
|
|
774
|
+
]
|
|
775
|
+
}
|
|
776
|
+
)
|
|
777
|
+
] }),
|
|
778
|
+
table.sort ? /* @__PURE__ */ jsx(
|
|
779
|
+
"button",
|
|
780
|
+
{
|
|
781
|
+
type: "button",
|
|
782
|
+
onClick: () => table.setSort({ key: table.sort.key, dir: table.sort.dir === "asc" ? "desc" : "asc" }),
|
|
783
|
+
className: "rounded-lg px-2 py-1 text-sm text-tertiary outline-focus-ring hover:bg-ghost-hover focus-visible:outline-2",
|
|
784
|
+
children: table.sort.dir === "asc" ? "Ascending" : "Descending"
|
|
785
|
+
}
|
|
786
|
+
) : null
|
|
787
|
+
] }) : null,
|
|
788
|
+
/* @__PURE__ */ jsx("ul", { className: "divide-y divide-border-secondary", children: table.rows.map((row) => {
|
|
789
|
+
const id = getRowId(row);
|
|
790
|
+
const depth = table.rowDepth.get(id) ?? 0;
|
|
791
|
+
const selected = table.selection.has(id);
|
|
792
|
+
const disabled = disabledRows?.(row) ?? false;
|
|
793
|
+
const resolved = expansion?.(row);
|
|
794
|
+
const isBranch = expansionChildren(resolved) !== null;
|
|
795
|
+
const detail = expansionDetail(resolved);
|
|
796
|
+
const isOpen = table.expanded.has(id);
|
|
797
|
+
const rowExpandable = Boolean(isBranch || detail);
|
|
798
|
+
const clickable = !disabled && (onRowClick !== null || rowClickSelects && selection !== "none" || rowClickExpands && rowExpandable);
|
|
799
|
+
const activateRow = () => {
|
|
800
|
+
if (onRowClick) onRowClick(row);
|
|
801
|
+
else if (rowClickSelects) (selection === "single" ? table.selectOnly : table.toggleRow)(id);
|
|
802
|
+
else if (rowClickExpands) table.toggleExpanded(id);
|
|
803
|
+
};
|
|
804
|
+
return /* @__PURE__ */ jsxs(
|
|
805
|
+
"li",
|
|
806
|
+
{
|
|
807
|
+
style: depth > 0 ? { paddingLeft: `calc(1rem + ${depth * 16}px)` } : void 0,
|
|
808
|
+
className: cn("flex flex-col gap-3", pad, selected && "bg-brand-primary", disabled && "opacity-50"),
|
|
809
|
+
children: [
|
|
810
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start gap-3", children: [
|
|
811
|
+
selection !== "none" ? selection === "multiple" ? /* @__PURE__ */ jsx(Checkbox, { "aria-label": "Select row", checked: selected, disabled, onCheckedChange: () => table.toggleRow(id) }) : /* @__PURE__ */ jsx(
|
|
812
|
+
"input",
|
|
813
|
+
{
|
|
814
|
+
type: "radio",
|
|
815
|
+
"aria-label": "Select row",
|
|
816
|
+
checked: selected,
|
|
817
|
+
disabled,
|
|
818
|
+
onChange: () => table.selectOnly(id),
|
|
819
|
+
className: "mt-0.5 size-4 cursor-pointer accent-bg-brand-solid"
|
|
820
|
+
}
|
|
821
|
+
) : null,
|
|
822
|
+
/* @__PURE__ */ jsx(
|
|
823
|
+
"div",
|
|
824
|
+
{
|
|
825
|
+
className: cn(
|
|
826
|
+
"min-w-0 flex-1 text-sm font-medium text-primary",
|
|
827
|
+
clickable && "cursor-pointer rounded-sm outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2"
|
|
828
|
+
),
|
|
829
|
+
onClick: clickable ? activateRow : void 0,
|
|
830
|
+
role: clickable && onRowClick ? "button" : void 0,
|
|
831
|
+
tabIndex: clickable && onRowClick ? 0 : void 0,
|
|
832
|
+
onKeyDown: clickable && onRowClick ? (event) => {
|
|
833
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
834
|
+
event.preventDefault();
|
|
835
|
+
activateRow();
|
|
836
|
+
} : void 0,
|
|
837
|
+
children: primary ? cellContent(primary, row) : null
|
|
838
|
+
}
|
|
839
|
+
),
|
|
840
|
+
rowExpandable ? /* @__PURE__ */ jsx(
|
|
841
|
+
"button",
|
|
842
|
+
{
|
|
843
|
+
type: "button",
|
|
844
|
+
"aria-label": isOpen ? "Collapse row" : "Expand row",
|
|
845
|
+
"aria-expanded": isOpen,
|
|
846
|
+
onClick: () => table.toggleExpanded(id),
|
|
847
|
+
className: "flex size-6 shrink-0 items-center justify-center rounded-sm text-fg-quaternary outline-focus-ring hover:text-primary focus-visible:outline-2",
|
|
848
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-4 transition-transform", isOpen && "rotate-90") })
|
|
849
|
+
}
|
|
850
|
+
) : null
|
|
851
|
+
] }),
|
|
852
|
+
/* @__PURE__ */ jsx("dl", { className: "flex flex-col gap-1.5", children: body.map((column) => /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 text-sm", children: [
|
|
853
|
+
/* @__PURE__ */ jsx("dt", { className: "shrink-0 text-fg-quaternary", children: label(column) }),
|
|
854
|
+
/* @__PURE__ */ jsx("dd", { className: cn("min-w-0 text-right text-tertiary", column.align === "end" && "tabular-nums"), children: cellContent(column, row) })
|
|
855
|
+
] }, column.key)) }),
|
|
856
|
+
detail && isOpen ? /* @__PURE__ */ jsx("div", { className: "rounded-lg bg-secondary p-3", children: detail }) : null,
|
|
857
|
+
rowActions ? /* @__PURE__ */ jsx("div", { className: "flex justify-end border-t border-secondary pt-3", children: /* @__PURE__ */ jsx(RowActionsCell, { row, config: rowActions, size, onConfirm }) }) : null
|
|
858
|
+
]
|
|
859
|
+
},
|
|
860
|
+
id
|
|
861
|
+
);
|
|
862
|
+
}) })
|
|
863
|
+
] });
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// src/components/table/shared.ts
|
|
867
|
+
var SIZE = {
|
|
868
|
+
sm: {
|
|
869
|
+
head: "h-9",
|
|
870
|
+
row: "min-h-14",
|
|
871
|
+
px: "px-5",
|
|
872
|
+
pxValue: "1.25rem",
|
|
873
|
+
cellPy: "py-3",
|
|
874
|
+
headPy: "py-2",
|
|
875
|
+
selectionWidth: "w-9",
|
|
876
|
+
gutterPx: "pl-5 pr-0",
|
|
877
|
+
actionsPx: "px-3",
|
|
878
|
+
cardPy: "py-4"
|
|
879
|
+
},
|
|
880
|
+
md: {
|
|
881
|
+
head: "h-11",
|
|
882
|
+
row: "min-h-18",
|
|
883
|
+
px: "px-6",
|
|
884
|
+
pxValue: "1.5rem",
|
|
885
|
+
cellPy: "py-4",
|
|
886
|
+
headPy: "py-2",
|
|
887
|
+
selectionWidth: "w-11",
|
|
888
|
+
gutterPx: "pl-6 pr-0",
|
|
889
|
+
actionsPx: "px-4",
|
|
890
|
+
cardPy: "py-5"
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
var SHELL = cn(SURFACE_BASE, SURFACE_VARIANT.outlined, SURFACE_EDGE_OVERLAY, "overflow-hidden");
|
|
894
|
+
var HEAD_LABEL = "text-xs font-semibold whitespace-nowrap text-fg-quaternary";
|
|
895
|
+
var CELL_TEXT = "text-sm text-tertiary";
|
|
896
|
+
var ROW_DIVIDER = "[&>td]:after:pointer-events-none [&>td]:after:absolute [&>td]:after:inset-x-0 [&>td]:after:bottom-0 [&>td]:after:h-px [&>td]:after:bg-border-secondary last:[&>td]:after:hidden [&:has(+tr:focus-visible)>td]:after:hidden focus-visible:[&>td]:after:hidden";
|
|
897
|
+
var HEAD_DIVIDER = "[&>th]:after:pointer-events-none [&>th]:after:absolute [&>th]:after:inset-x-0 [&>th]:after:bottom-0 [&>th]:after:h-px [&>th]:after:bg-border-secondary";
|
|
898
|
+
var HEAD_DIVIDER_CELL = "after:pointer-events-none after:absolute after:inset-x-0 after:bottom-0 after:h-px after:bg-border-secondary";
|
|
899
|
+
var ROW_BASE = "relative bg-primary transition-colors duration-100 ease-linear";
|
|
900
|
+
var ROW_HOVER = "hover:bg-secondary";
|
|
901
|
+
var ROW_SELECTED = "bg-brand-primary hover:bg-brand-primary";
|
|
902
|
+
var ROW_STRIPE = "bg-secondary";
|
|
903
|
+
var ROW_HOVER_STRIPED = "hover:bg-tertiary";
|
|
904
|
+
var ROW_CLICKABLE = (
|
|
905
|
+
// `cursor-pointer` advertises the row to mouse users; the focus ring is what makes the same
|
|
906
|
+
// affordance visible to a keyboard user, who can now actually reach it (WCAG 2.1.1 — see the
|
|
907
|
+
// `tabIndex`/`onKeyDown` pair in `Table.tsx`). Inset, because a `<tr>` cannot be outlined
|
|
908
|
+
// outside the table box without being clipped by the scroll container.
|
|
909
|
+
//
|
|
910
|
+
// Offset **-3**, not -2, so the ring clears the shell's 1px edge overlay. A row is flush with the
|
|
911
|
+
// shell's inner edge, and `SURFACE_EDGE_OVERLAY` paints that hairline at `z-4` — above the row —
|
|
912
|
+
// so at -2 the ring occupied px 0–2 from the row's edge and the overlay covered px 0–1: the LEFT
|
|
913
|
+
// and RIGHT sides measured 1px against 2px top and bottom. At -3 the ring occupies px 1–3, clear
|
|
914
|
+
// of the overlay, and all four sides render the full 2px.
|
|
915
|
+
//
|
|
916
|
+
// Raising the row up the ladder instead (`focus-visible:z-5`) does not work: the ring has to be
|
|
917
|
+
// above the edge overlay, the overlay has to be above the sticky header's fill (that is what it
|
|
918
|
+
// is FOR — the fill was erasing the card's hairline), and the header has to be above the row. The
|
|
919
|
+
// three constraints are cyclic, and a row at `z-5` was measured painting straight over a
|
|
920
|
+
// `stickyHeader`, hiding it. Insetting one more pixel sidesteps the ladder entirely.
|
|
921
|
+
"cursor-pointer outline-focus-ring focus-visible:outline-2 focus-visible:-outline-offset-3"
|
|
922
|
+
);
|
|
923
|
+
var ROW_DISABLED = "[&>td]:opacity-50 [&>td]:pointer-events-none";
|
|
924
|
+
var CELL_FOCUS = "outline-focus-ring focus-visible:z-1 focus-visible:outline-2 focus-visible:-outline-offset-2";
|
|
925
|
+
var SORT_ICON = "size-3 shrink-0 text-fg-quaternary";
|
|
926
|
+
var PIN_BASE = "sticky z-2";
|
|
927
|
+
var PIN_SHADOW_START = "before:pointer-events-none before:absolute before:inset-y-0 before:-right-2 before:w-2 before:opacity-0 before:transition-opacity before:shadow-[inset_8px_0_8px_-8px_rgb(0_0_0/0.15)] group-data-[overflowing]/scroller:before:opacity-100";
|
|
928
|
+
var PIN_SHADOW_END = "before:pointer-events-none before:absolute before:inset-y-0 before:-left-2 before:w-2 before:opacity-0 before:transition-opacity before:shadow-[inset_-8px_0_8px_-8px_rgb(0_0_0/0.15)] group-data-[overflowing]/scroller:before:opacity-100";
|
|
929
|
+
var ALIGN = {
|
|
930
|
+
start: "text-left",
|
|
931
|
+
end: "text-right tabular-nums"
|
|
932
|
+
};
|
|
933
|
+
var ALIGN_FLEX = {
|
|
934
|
+
start: "justify-start",
|
|
935
|
+
end: "justify-end"
|
|
936
|
+
};
|
|
937
|
+
var BAND = "flex flex-wrap items-center gap-3 border-b border-secondary px-4 py-3 md:px-6";
|
|
938
|
+
function SelectionAnnouncer({ count }) {
|
|
939
|
+
const previouslyHad = React.useRef(false);
|
|
940
|
+
if (count > 0) previouslyHad.current = true;
|
|
941
|
+
const message = count > 0 ? `${count} ${count === 1 ? "row" : "rows"} selected` : previouslyHad.current ? "No rows selected" : "";
|
|
942
|
+
return /* @__PURE__ */ jsx("div", { "aria-live": "polite", role: "status", className: "sr-only", children: message });
|
|
943
|
+
}
|
|
944
|
+
function TableToolbarBar({
|
|
945
|
+
table,
|
|
946
|
+
columns,
|
|
947
|
+
toolbar,
|
|
948
|
+
bulkActions,
|
|
949
|
+
size,
|
|
950
|
+
disabled,
|
|
951
|
+
onConfirm,
|
|
952
|
+
rootRef
|
|
953
|
+
}) {
|
|
954
|
+
const selectedCount = table.selection.size;
|
|
955
|
+
const showBulk = selectedCount > 0 && bulkActions && bulkActions.length > 0;
|
|
956
|
+
const announcer = /* @__PURE__ */ jsx(SelectionAnnouncer, { count: selectedCount });
|
|
957
|
+
if (showBulk) {
|
|
958
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
959
|
+
announcer,
|
|
960
|
+
/* @__PURE__ */ jsx(BulkBar, { table, actions: bulkActions, size, disabled, onConfirm, rootRef })
|
|
961
|
+
] });
|
|
962
|
+
}
|
|
963
|
+
if (!toolbar) return announcer;
|
|
964
|
+
const search = toolbar.search;
|
|
965
|
+
const filterable = columns.filter((column) => column.filter);
|
|
966
|
+
const hideable = columns.filter((column) => (column.hideable ?? true) && column.header);
|
|
967
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
968
|
+
announcer,
|
|
969
|
+
/* @__PURE__ */ jsxs("div", { className: BAND, children: [
|
|
970
|
+
search ? /* @__PURE__ */ jsx(
|
|
971
|
+
Input,
|
|
972
|
+
{
|
|
973
|
+
size: size === "sm" ? "sm" : "md",
|
|
974
|
+
type: "text",
|
|
975
|
+
leading: /* @__PURE__ */ jsx(SearchIcon, {}),
|
|
976
|
+
placeholder: typeof search === "object" && search.placeholder || "Search",
|
|
977
|
+
"aria-label": typeof search === "object" && search.label || "Search",
|
|
978
|
+
value: table.query,
|
|
979
|
+
disabled,
|
|
980
|
+
onChange: (event) => table.setQuery(event.target.value),
|
|
981
|
+
className: "w-full sm:w-64"
|
|
982
|
+
}
|
|
983
|
+
) : null,
|
|
984
|
+
filterable.map((column) => /* @__PURE__ */ jsx(ColumnFilterControl, { column, table, size, disabled }, column.key)),
|
|
985
|
+
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-2", children: [
|
|
986
|
+
toolbar.columnVisibility && hideable.length > 0 ? /* @__PURE__ */ jsx(
|
|
987
|
+
DropdownMenu,
|
|
988
|
+
{
|
|
989
|
+
trigger: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: size === "sm" ? "sm" : "md", leading: /* @__PURE__ */ jsx(Columns3Icon, {}), disabled, children: "Columns" }),
|
|
990
|
+
items: hideable.map((column) => ({
|
|
991
|
+
type: "checkbox",
|
|
992
|
+
label: typeof column.header === "string" ? column.header : column.key,
|
|
993
|
+
checked: table.columnVisibility[column.key] !== false,
|
|
994
|
+
onCheckedChange: () => table.toggleColumn(column.key)
|
|
995
|
+
})),
|
|
996
|
+
align: "end"
|
|
997
|
+
}
|
|
998
|
+
) : null,
|
|
999
|
+
toolbar.actions
|
|
1000
|
+
] })
|
|
1001
|
+
] }),
|
|
1002
|
+
table.activeFilters.length > 0 ? /* @__PURE__ */ jsxs("div", { className: cn(BAND, "gap-2 py-2"), children: [
|
|
1003
|
+
table.activeFilters.map((filter) => /* @__PURE__ */ jsxs(Tag, { size: "sm", onRemove: filter.clear, removeLabel: `Remove ${filter.label} filter`, children: [
|
|
1004
|
+
filter.label,
|
|
1005
|
+
": ",
|
|
1006
|
+
filter.display
|
|
1007
|
+
] }, filter.key)),
|
|
1008
|
+
/* @__PURE__ */ jsx(Button, { variant: "link", size: "sm", onClick: table.clearFilters, children: "Clear all" })
|
|
1009
|
+
] }) : null
|
|
1010
|
+
] });
|
|
1011
|
+
}
|
|
1012
|
+
function ColumnFilterControl({
|
|
1013
|
+
column,
|
|
1014
|
+
table,
|
|
1015
|
+
size,
|
|
1016
|
+
disabled
|
|
1017
|
+
}) {
|
|
1018
|
+
const filter = column.filter;
|
|
1019
|
+
const label2 = "label" in filter && filter.label || (typeof column.header === "string" ? column.header : column.key);
|
|
1020
|
+
const current = table.filters[column.key];
|
|
1021
|
+
const controlSize = size === "sm" ? "sm" : "md";
|
|
1022
|
+
if (filter.kind === "facet") {
|
|
1023
|
+
const counts = table.facetCounts(column.key);
|
|
1024
|
+
const options = filter.options ?? // Sorted so the list is scannable. `toSorted` would be tidier but needs ES2023 and this
|
|
1025
|
+
// project targets ES2021 (tsconfig) — the spread already copies, so `sort` mutates nothing.
|
|
1026
|
+
// eslint-disable-next-line unicorn/no-array-sort, unicorn/prefer-iterator-to-array
|
|
1027
|
+
[...counts.keys()].sort((a, b) => a.localeCompare(b)).map((value) => ({ value, label: value }));
|
|
1028
|
+
const selected = current?.kind === "facet" ? current.values : [];
|
|
1029
|
+
return /* @__PURE__ */ jsx(
|
|
1030
|
+
Select,
|
|
1031
|
+
{
|
|
1032
|
+
multiple: true,
|
|
1033
|
+
size: controlSize,
|
|
1034
|
+
disabled,
|
|
1035
|
+
"aria-label": label2,
|
|
1036
|
+
placeholder: label2,
|
|
1037
|
+
maxRows: 1,
|
|
1038
|
+
value: selected,
|
|
1039
|
+
onValueChange: (values) => table.setFilter(column.key, { kind: "facet", values }),
|
|
1040
|
+
options: options.map((option) => ({
|
|
1041
|
+
value: option.value,
|
|
1042
|
+
label: option.label ?? option.value,
|
|
1043
|
+
trailing: counts.has(option.value) ? /* @__PURE__ */ jsx("span", { className: "text-xs text-fg-quaternary tabular-nums", children: counts.get(option.value) }) : void 0
|
|
1044
|
+
})),
|
|
1045
|
+
className: "w-40"
|
|
1046
|
+
}
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
1049
|
+
if (filter.kind === "text") {
|
|
1050
|
+
return /* @__PURE__ */ jsx(
|
|
1051
|
+
Input,
|
|
1052
|
+
{
|
|
1053
|
+
size: controlSize,
|
|
1054
|
+
type: "text",
|
|
1055
|
+
"aria-label": label2,
|
|
1056
|
+
placeholder: label2,
|
|
1057
|
+
disabled,
|
|
1058
|
+
value: current?.kind === "text" ? current.value : "",
|
|
1059
|
+
onChange: (event) => table.setFilter(column.key, { kind: "text", value: event.target.value }),
|
|
1060
|
+
className: "w-40"
|
|
1061
|
+
}
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
if (filter.kind === "number") {
|
|
1065
|
+
const value = current && current.kind === "number" ? current : void 0;
|
|
1066
|
+
const min = value?.min;
|
|
1067
|
+
const max = value?.max;
|
|
1068
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
1069
|
+
/* @__PURE__ */ jsx(
|
|
1070
|
+
Input,
|
|
1071
|
+
{
|
|
1072
|
+
size: controlSize,
|
|
1073
|
+
type: "text",
|
|
1074
|
+
inputMode: "numeric",
|
|
1075
|
+
"aria-label": `${label2} minimum`,
|
|
1076
|
+
placeholder: "Min",
|
|
1077
|
+
disabled,
|
|
1078
|
+
value: min ?? "",
|
|
1079
|
+
onChange: (event) => table.setFilter(column.key, { kind: "number", min: event.target.value === "" ? void 0 : Number(event.target.value), max }),
|
|
1080
|
+
className: "w-20"
|
|
1081
|
+
}
|
|
1082
|
+
),
|
|
1083
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-fg-quaternary", children: "\u2013" }),
|
|
1084
|
+
/* @__PURE__ */ jsx(
|
|
1085
|
+
Input,
|
|
1086
|
+
{
|
|
1087
|
+
size: controlSize,
|
|
1088
|
+
type: "text",
|
|
1089
|
+
inputMode: "numeric",
|
|
1090
|
+
"aria-label": `${label2} maximum`,
|
|
1091
|
+
placeholder: "Max",
|
|
1092
|
+
disabled,
|
|
1093
|
+
value: max ?? "",
|
|
1094
|
+
onChange: (event) => table.setFilter(column.key, { kind: "number", min, max: event.target.value === "" ? void 0 : Number(event.target.value) }),
|
|
1095
|
+
className: "w-20"
|
|
1096
|
+
}
|
|
1097
|
+
)
|
|
1098
|
+
] });
|
|
1099
|
+
}
|
|
1100
|
+
const range = current && current.kind === "dateRange" ? current : void 0;
|
|
1101
|
+
const from = range?.from;
|
|
1102
|
+
const to = range?.to;
|
|
1103
|
+
return /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5", children: [
|
|
1104
|
+
/* @__PURE__ */ jsx(
|
|
1105
|
+
"input",
|
|
1106
|
+
{
|
|
1107
|
+
type: "date",
|
|
1108
|
+
"aria-label": `${label2} from`,
|
|
1109
|
+
disabled,
|
|
1110
|
+
value: from ?? "",
|
|
1111
|
+
onChange: (event) => table.setFilter(column.key, { kind: "dateRange", from: event.target.value || void 0, to }),
|
|
1112
|
+
className: "h-10 rounded-lg bg-primary px-3 text-sm text-primary ring-1 ring-secondary outline-focus-ring ring-inset focus-visible:outline-2"
|
|
1113
|
+
}
|
|
1114
|
+
),
|
|
1115
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm text-fg-quaternary", children: "\u2013" }),
|
|
1116
|
+
/* @__PURE__ */ jsx(
|
|
1117
|
+
"input",
|
|
1118
|
+
{
|
|
1119
|
+
type: "date",
|
|
1120
|
+
"aria-label": `${label2} to`,
|
|
1121
|
+
disabled,
|
|
1122
|
+
value: to ?? "",
|
|
1123
|
+
onChange: (event) => table.setFilter(column.key, { kind: "dateRange", from, to: event.target.value || void 0 }),
|
|
1124
|
+
className: "h-10 rounded-lg bg-primary px-3 text-sm text-primary ring-1 ring-secondary outline-focus-ring ring-inset focus-visible:outline-2"
|
|
1125
|
+
}
|
|
1126
|
+
)
|
|
1127
|
+
] });
|
|
1128
|
+
}
|
|
1129
|
+
function BulkBar({
|
|
1130
|
+
table,
|
|
1131
|
+
actions,
|
|
1132
|
+
size,
|
|
1133
|
+
disabled,
|
|
1134
|
+
onConfirm,
|
|
1135
|
+
rootRef
|
|
1136
|
+
}) {
|
|
1137
|
+
const count = table.selection.size;
|
|
1138
|
+
const onPage = table.selectionOnPage;
|
|
1139
|
+
React.useEffect(() => {
|
|
1140
|
+
const onKeyDown = (event) => {
|
|
1141
|
+
if (event.key !== "Escape") return;
|
|
1142
|
+
const root = rootRef?.current;
|
|
1143
|
+
const active = root?.ownerDocument.activeElement ?? null;
|
|
1144
|
+
const focusIsIdle = active === null || active === root?.ownerDocument.body;
|
|
1145
|
+
if (root && !focusIsIdle && !root.contains(active)) return;
|
|
1146
|
+
table.clearSelection();
|
|
1147
|
+
};
|
|
1148
|
+
globalThis.addEventListener("keydown", onKeyDown);
|
|
1149
|
+
return () => globalThis.removeEventListener("keydown", onKeyDown);
|
|
1150
|
+
}, [table, rootRef]);
|
|
1151
|
+
return /* @__PURE__ */ jsxs("div", { className: cn(BAND, "bg-brand-primary"), children: [
|
|
1152
|
+
/* @__PURE__ */ jsxs("span", { className: "text-sm font-medium text-primary", children: [
|
|
1153
|
+
count,
|
|
1154
|
+
" selected",
|
|
1155
|
+
onPage < count ? /* @__PURE__ */ jsxs("span", { className: "font-normal text-tertiary", children: [
|
|
1156
|
+
" \xB7 ",
|
|
1157
|
+
onPage,
|
|
1158
|
+
" on this page"
|
|
1159
|
+
] }) : null
|
|
1160
|
+
] }),
|
|
1161
|
+
!table.manual && table.selectionState === "page" && table.totalRows > count ? /* @__PURE__ */ jsxs(Button, { variant: "link", size: "sm", onClick: table.selectAll, children: [
|
|
1162
|
+
"Select all ",
|
|
1163
|
+
table.totalRows
|
|
1164
|
+
] }) : null,
|
|
1165
|
+
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-2", children: [
|
|
1166
|
+
actions.map((action, index) => (
|
|
1167
|
+
// Index-keyed: `label` is caller-supplied free text, so two actions sharing one label
|
|
1168
|
+
// collided and React reused the wrong button's state.
|
|
1169
|
+
/* @__PURE__ */ jsx(
|
|
1170
|
+
Button,
|
|
1171
|
+
{
|
|
1172
|
+
variant: "secondary",
|
|
1173
|
+
color: action.tone ?? "neutral",
|
|
1174
|
+
size: size === "sm" ? "sm" : "md",
|
|
1175
|
+
leading: action.icon,
|
|
1176
|
+
disabled,
|
|
1177
|
+
onClick: () => {
|
|
1178
|
+
const ids = table.selection;
|
|
1179
|
+
const fire = () => action.onClick(ids);
|
|
1180
|
+
if (action.confirm) onConfirm({ label: action.label, tone: action.tone, confirm: action.confirm, run: fire });
|
|
1181
|
+
else fire();
|
|
1182
|
+
},
|
|
1183
|
+
children: action.label
|
|
1184
|
+
},
|
|
1185
|
+
`${action.label}-${index}`
|
|
1186
|
+
)
|
|
1187
|
+
)),
|
|
1188
|
+
/* @__PURE__ */ jsx(Button, { variant: "link", size: "sm", disabled, onClick: table.clearSelection, children: "Clear" })
|
|
1189
|
+
] })
|
|
1190
|
+
] });
|
|
1191
|
+
}
|
|
1192
|
+
function widthPx(column) {
|
|
1193
|
+
return typeof column.width === "number" ? column.width : void 0;
|
|
1194
|
+
}
|
|
1195
|
+
function pinOffsets(columns, gutterWidth) {
|
|
1196
|
+
const start = /* @__PURE__ */ new Map();
|
|
1197
|
+
const end = /* @__PURE__ */ new Map();
|
|
1198
|
+
let offset = gutterWidth;
|
|
1199
|
+
for (const column of columns) {
|
|
1200
|
+
if (column.pin !== "start") break;
|
|
1201
|
+
start.set(column.key, offset);
|
|
1202
|
+
offset += widthPx(column) ?? 0;
|
|
1203
|
+
}
|
|
1204
|
+
offset = 0;
|
|
1205
|
+
for (let i = columns.length - 1; i >= 0; i -= 1) {
|
|
1206
|
+
const column = columns[i];
|
|
1207
|
+
if (column.pin !== "end") break;
|
|
1208
|
+
end.set(column.key, offset);
|
|
1209
|
+
offset += widthPx(column) ?? 0;
|
|
1210
|
+
}
|
|
1211
|
+
return { start, end };
|
|
1212
|
+
}
|
|
1213
|
+
var TREE_LEAD = 28;
|
|
1214
|
+
var TREE_INDENT = 20;
|
|
1215
|
+
function Table(props) {
|
|
1216
|
+
const {
|
|
1217
|
+
table,
|
|
1218
|
+
size = "md",
|
|
1219
|
+
treatment = "divided",
|
|
1220
|
+
rowHover = "highlight",
|
|
1221
|
+
title,
|
|
1222
|
+
badge,
|
|
1223
|
+
description,
|
|
1224
|
+
headerActions,
|
|
1225
|
+
caption,
|
|
1226
|
+
rowActions,
|
|
1227
|
+
rowClick = "none",
|
|
1228
|
+
toolbar,
|
|
1229
|
+
bulkActions,
|
|
1230
|
+
pagination = false,
|
|
1231
|
+
pageSizeOptions,
|
|
1232
|
+
loading = false,
|
|
1233
|
+
loadingRows = 5,
|
|
1234
|
+
empty,
|
|
1235
|
+
error,
|
|
1236
|
+
onRetry,
|
|
1237
|
+
stickyHeader = false,
|
|
1238
|
+
maxHeight,
|
|
1239
|
+
responsive = "scroll",
|
|
1240
|
+
className
|
|
1241
|
+
} = props;
|
|
1242
|
+
const { columns, getRowId, expansion, disabledRows, isTree, selectionMode: selection } = table;
|
|
1243
|
+
const geometry = SIZE[size];
|
|
1244
|
+
const leafColumns = React.useMemo(() => flattenColumns(columns), [columns]);
|
|
1245
|
+
const banded = hasColumnGroups(columns);
|
|
1246
|
+
const visibleColumns = React.useMemo(
|
|
1247
|
+
() => leafColumns.filter((column) => table.columnVisibility[column.key] !== false),
|
|
1248
|
+
[leafColumns, table.columnVisibility]
|
|
1249
|
+
);
|
|
1250
|
+
const hasSelection = selection !== "none";
|
|
1251
|
+
const rootRef = React.useRef(null);
|
|
1252
|
+
const selectionName = React.useId();
|
|
1253
|
+
const expandable = typeof expansion === "function";
|
|
1254
|
+
const rowClickSelects = rowClick === "select";
|
|
1255
|
+
const rowClickExpands = rowClick === "expand";
|
|
1256
|
+
const onRowClick = typeof rowClick === "function" ? rowClick : null;
|
|
1257
|
+
const gutterExpander = expandable && !isTree;
|
|
1258
|
+
const hasRenderedChildRow = React.useMemo(() => table.rows.some((row) => (table.rowDepth.get(getRowId(row)) ?? 0) > 0), [table, getRowId]);
|
|
1259
|
+
const columnSpan = visibleColumns.length + (hasSelection ? 1 : 0) + (gutterExpander ? 1 : 0) + (rowActions ? 1 : 0);
|
|
1260
|
+
const gutterWidth = (hasSelection ? size === "sm" ? 36 : 44 : 0) + (gutterExpander ? 40 : 0);
|
|
1261
|
+
const offsets = React.useMemo(() => pinOffsets(visibleColumns, gutterWidth), [visibleColumns, gutterWidth]);
|
|
1262
|
+
const scrollerRef = React.useRef(null);
|
|
1263
|
+
React.useEffect(() => {
|
|
1264
|
+
const node = scrollerRef.current;
|
|
1265
|
+
if (!node) return;
|
|
1266
|
+
const sync = () => {
|
|
1267
|
+
if (node.scrollWidth - node.clientWidth > 4) node.dataset.overflowing = "";
|
|
1268
|
+
else delete node.dataset.overflowing;
|
|
1269
|
+
};
|
|
1270
|
+
sync();
|
|
1271
|
+
const observer = new ResizeObserver(sync);
|
|
1272
|
+
observer.observe(node);
|
|
1273
|
+
return () => observer.disconnect();
|
|
1274
|
+
}, [visibleColumns.length]);
|
|
1275
|
+
const [pendingAction, setPendingAction] = React.useState(null);
|
|
1276
|
+
const showEmpty = !loading && !error && table.rows.length === 0;
|
|
1277
|
+
const slicesRows = table.totalRows > table.rows.length;
|
|
1278
|
+
const showPagination = props.pagination === false ? false : Boolean(pagination) || slicesRows;
|
|
1279
|
+
const paginationOptions = typeof pagination === "string" ? { variant: pagination } : typeof pagination === "object" ? pagination : {};
|
|
1280
|
+
React.useEffect(() => {
|
|
1281
|
+
warnPositiveInt("Table", "loadingRows", loadingRows);
|
|
1282
|
+
if (rowClickSelects && !hasSelection) {
|
|
1283
|
+
devWarn('<Table rowClick="select"> has nothing to select \u2014 pass `selection: "single" | "multiple"` to useTable().');
|
|
1284
|
+
}
|
|
1285
|
+
if (rowClickExpands && !expandable) {
|
|
1286
|
+
devWarn('<Table rowClick="expand"> has nothing to expand \u2014 pass `expansion` to useTable().');
|
|
1287
|
+
}
|
|
1288
|
+
for (const column of visibleColumns) {
|
|
1289
|
+
if (column.pin && widthPx(column) === void 0) {
|
|
1290
|
+
devWarn(`<Table> column "${column.key}" is pinned but has no numeric \`width\` \u2014 sticky offsets cannot be computed from an auto width.`);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
for (const entry of columns) {
|
|
1294
|
+
if (!isColumnGroup(entry)) continue;
|
|
1295
|
+
const shown = entry.columns.filter((c) => table.columnVisibility[c.key] !== false);
|
|
1296
|
+
const pinned = shown.filter((c) => c.pin).length;
|
|
1297
|
+
if (pinned > 0 && pinned < shown.length) {
|
|
1298
|
+
devWarn(
|
|
1299
|
+
`<Table> banded header "${String(entry.header)}" straddles the pin boundary \u2014 some of its columns are pinned and some are not, so the band will scroll away from its own leaves. Pin the whole band, or move the pinned column out of it.`
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}, [columns, visibleColumns, table.columnVisibility, loadingRows, rowClickSelects, rowClickExpands, hasSelection, expandable]);
|
|
1304
|
+
const pinGutter = visibleColumns[0]?.pin === "start";
|
|
1305
|
+
const expanderWidth = gutterExpander ? 40 : 0;
|
|
1306
|
+
const renderHeadCell = (column, rowSpan) => {
|
|
1307
|
+
const sorted = table.sort?.key === column.key ? table.sort.dir : null;
|
|
1308
|
+
const align = column.align ?? "start";
|
|
1309
|
+
const pin = column.pin;
|
|
1310
|
+
const leadsTree = isTree && column.key === visibleColumns[0]?.key;
|
|
1311
|
+
return /* @__PURE__ */ jsx(
|
|
1312
|
+
"th",
|
|
1313
|
+
{
|
|
1314
|
+
scope: "col",
|
|
1315
|
+
rowSpan,
|
|
1316
|
+
style: {
|
|
1317
|
+
width: widthPx(column),
|
|
1318
|
+
...pin === "start" && { left: offsets.start.get(column.key) },
|
|
1319
|
+
...pin === "end" && { right: offsets.end.get(column.key) },
|
|
1320
|
+
...leadsTree && { paddingLeft: `calc(${geometry.pxValue} + ${TREE_LEAD}px)` }
|
|
1321
|
+
},
|
|
1322
|
+
"aria-sort": sorted ? sorted === "asc" ? "ascending" : "descending" : column.sortable ? "none" : void 0,
|
|
1323
|
+
className: cn(
|
|
1324
|
+
"relative bg-secondary",
|
|
1325
|
+
geometry.px,
|
|
1326
|
+
geometry.headPy,
|
|
1327
|
+
ALIGN[align],
|
|
1328
|
+
column.width === "grow" && "w-full",
|
|
1329
|
+
// A cell that spans both banded rows sits in the first one, out of reach of the leaf
|
|
1330
|
+
// row's HEAD_DIVIDER — it draws the header's bottom rule itself.
|
|
1331
|
+
rowSpan ? HEAD_DIVIDER_CELL : null,
|
|
1332
|
+
pin && cn(PIN_BASE, pin === "start" ? PIN_SHADOW_START : PIN_SHADOW_END)
|
|
1333
|
+
),
|
|
1334
|
+
children: /* @__PURE__ */ jsxs("span", { className: cn("flex items-center gap-1", ALIGN_FLEX[align]), children: [
|
|
1335
|
+
column.sortable ? /* @__PURE__ */ jsxs(
|
|
1336
|
+
"button",
|
|
1337
|
+
{
|
|
1338
|
+
type: "button",
|
|
1339
|
+
onClick: () => table.toggleSort(column.key),
|
|
1340
|
+
className: cn(
|
|
1341
|
+
"flex cursor-pointer items-center gap-1 rounded-sm outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
1342
|
+
HEAD_LABEL
|
|
1343
|
+
),
|
|
1344
|
+
children: [
|
|
1345
|
+
column.header,
|
|
1346
|
+
sorted ? /* @__PURE__ */ jsx(ArrowDownIcon, { className: cn(SORT_ICON, sorted === "asc" && "rotate-180") }) : /* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: SORT_ICON })
|
|
1347
|
+
]
|
|
1348
|
+
}
|
|
1349
|
+
) : /* @__PURE__ */ jsx("span", { className: HEAD_LABEL, children: column.header }),
|
|
1350
|
+
column.tooltip ? /* @__PURE__ */ jsx(TooltipExport, { content: column.tooltip, children: /* @__PURE__ */ jsx(
|
|
1351
|
+
"button",
|
|
1352
|
+
{
|
|
1353
|
+
type: "button",
|
|
1354
|
+
"aria-label": `About ${typeof column.header === "string" ? column.header : column.key}`,
|
|
1355
|
+
className: "cursor-pointer text-fg-quaternary hover:text-tertiary",
|
|
1356
|
+
children: /* @__PURE__ */ jsx(CircleAlertIcon, { className: "size-4" })
|
|
1357
|
+
}
|
|
1358
|
+
) }) : null
|
|
1359
|
+
] })
|
|
1360
|
+
},
|
|
1361
|
+
column.key
|
|
1362
|
+
);
|
|
1363
|
+
};
|
|
1364
|
+
const renderGutters = (rowSpan) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1365
|
+
gutterExpander ? /* @__PURE__ */ jsx(
|
|
1366
|
+
"th",
|
|
1367
|
+
{
|
|
1368
|
+
scope: "col",
|
|
1369
|
+
rowSpan,
|
|
1370
|
+
style: pinGutter ? { left: 0 } : void 0,
|
|
1371
|
+
className: cn("relative w-10 bg-secondary", geometry.gutterPx, rowSpan ? HEAD_DIVIDER_CELL : null, pinGutter && PIN_BASE),
|
|
1372
|
+
children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Expand" })
|
|
1373
|
+
}
|
|
1374
|
+
) : null,
|
|
1375
|
+
hasSelection ? /* @__PURE__ */ jsx(
|
|
1376
|
+
"th",
|
|
1377
|
+
{
|
|
1378
|
+
scope: "col",
|
|
1379
|
+
rowSpan,
|
|
1380
|
+
style: pinGutter ? { left: expanderWidth } : void 0,
|
|
1381
|
+
className: cn("relative bg-secondary", geometry.selectionWidth, geometry.gutterPx, rowSpan ? HEAD_DIVIDER_CELL : null, pinGutter && PIN_BASE),
|
|
1382
|
+
children: selection === "multiple" ? /* @__PURE__ */ jsx(
|
|
1383
|
+
Checkbox,
|
|
1384
|
+
{
|
|
1385
|
+
"aria-label": "Select all rows on this page",
|
|
1386
|
+
checked: table.selectionState === "page" || table.selectionState === "all",
|
|
1387
|
+
indeterminate: table.selectionOnPage > 0 && table.selectionState !== "page" && table.selectionState !== "all",
|
|
1388
|
+
onCheckedChange: () => table.togglePage()
|
|
1389
|
+
}
|
|
1390
|
+
) : (
|
|
1391
|
+
// `single` has nothing to select-all. UUI renders a checkbox here anyway (its row cell
|
|
1392
|
+
// never checks selectionMode) — that is a bug; the honest header for a radio column is
|
|
1393
|
+
// an empty one.
|
|
1394
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Select" })
|
|
1395
|
+
)
|
|
1396
|
+
}
|
|
1397
|
+
) : null
|
|
1398
|
+
] });
|
|
1399
|
+
const body = /* @__PURE__ */ jsxs("table", { className: "w-full border-separate border-spacing-0", "aria-busy": loading || void 0, children: [
|
|
1400
|
+
caption ? /* @__PURE__ */ jsx("caption", { className: "sr-only", children: caption }) : null,
|
|
1401
|
+
/* @__PURE__ */ jsxs("thead", { className: cn("bg-secondary", stickyHeader && "sticky top-0 z-3"), children: [
|
|
1402
|
+
banded ? /* @__PURE__ */ jsxs("tr", { className: geometry.head, children: [
|
|
1403
|
+
renderGutters(2),
|
|
1404
|
+
columns.map((entry, index) => {
|
|
1405
|
+
if (isColumnGroup(entry)) {
|
|
1406
|
+
const shown = entry.columns.filter((c) => table.columnVisibility[c.key] !== false);
|
|
1407
|
+
if (shown.length === 0) return null;
|
|
1408
|
+
const bandPin = shown.every((c) => c.pin === "start") ? "start" : shown.every((c) => c.pin === "end") ? "end" : void 0;
|
|
1409
|
+
const bandOffset = bandPin === "start" ? offsets.start.get(shown[0].key) : bandPin === "end" ? offsets.end.get(shown.at(-1).key) : void 0;
|
|
1410
|
+
return /* @__PURE__ */ jsx(
|
|
1411
|
+
"th",
|
|
1412
|
+
{
|
|
1413
|
+
scope: "colgroup",
|
|
1414
|
+
colSpan: shown.length,
|
|
1415
|
+
style: bandPin === "start" ? { left: bandOffset } : bandPin === "end" ? { right: bandOffset } : void 0,
|
|
1416
|
+
className: cn(
|
|
1417
|
+
"relative bg-secondary text-left",
|
|
1418
|
+
geometry.px,
|
|
1419
|
+
geometry.headPy,
|
|
1420
|
+
HEAD_LABEL,
|
|
1421
|
+
// NO rule under a band. Adjacent bands sit edge to edge, so a per-band
|
|
1422
|
+
// bottom rule merges with its neighbour's into one anonymous line floating
|
|
1423
|
+
// across mid-header, which then stair-steps down to the header's real bottom
|
|
1424
|
+
// edge at the first unbanded column. The header gets exactly ONE hairline —
|
|
1425
|
+
// its own bottom — and a band's scope is read from its label sitting over
|
|
1426
|
+
// its leaves, the same way the table communicates every other grouping
|
|
1427
|
+
// (it draws no vertical rules either).
|
|
1428
|
+
bandPin && cn(PIN_BASE, bandPin === "start" ? PIN_SHADOW_START : PIN_SHADOW_END)
|
|
1429
|
+
),
|
|
1430
|
+
children: entry.header
|
|
1431
|
+
},
|
|
1432
|
+
`band-${index}`
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
return table.columnVisibility[entry.key] === false ? null : renderHeadCell(entry, 2);
|
|
1436
|
+
}),
|
|
1437
|
+
rowActions ? /* @__PURE__ */ jsx("th", { "aria-hidden": "true", rowSpan: 2, className: cn("relative bg-secondary", HEAD_DIVIDER_CELL) }) : null
|
|
1438
|
+
] }) : null,
|
|
1439
|
+
/* @__PURE__ */ jsxs("tr", { className: cn(geometry.head, HEAD_DIVIDER), children: [
|
|
1440
|
+
banded ? null : renderGutters(),
|
|
1441
|
+
banded ? columns.flatMap(
|
|
1442
|
+
(entry) => isColumnGroup(entry) ? entry.columns.filter((c) => table.columnVisibility[c.key] !== false).map((c) => renderHeadCell(c)) : []
|
|
1443
|
+
) : visibleColumns.map((column) => renderHeadCell(column)),
|
|
1444
|
+
banded || !rowActions ? null : /* @__PURE__ */ jsx("th", { scope: "col", className: cn("relative bg-secondary", geometry.actionsPx), children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Actions" }) })
|
|
1445
|
+
] })
|
|
1446
|
+
] }),
|
|
1447
|
+
/* @__PURE__ */ jsx("tbody", { children: loading ? Array.from({ length: loadingRows }, (_, index) => /* @__PURE__ */ jsxs("tr", { className: cn(ROW_BASE, geometry.row, ROW_DIVIDER), children: [
|
|
1448
|
+
gutterExpander ? /* @__PURE__ */ jsx("td", { style: pinGutter ? { left: 0 } : void 0, className: cn("relative", geometry.gutterPx, pinGutter && cn(PIN_BASE, "bg-inherit")) }) : null,
|
|
1449
|
+
hasSelection ? /* @__PURE__ */ jsx(
|
|
1450
|
+
"td",
|
|
1451
|
+
{
|
|
1452
|
+
style: pinGutter ? { left: expanderWidth } : void 0,
|
|
1453
|
+
className: cn("relative", geometry.gutterPx, pinGutter && cn(PIN_BASE, "bg-inherit")),
|
|
1454
|
+
children: /* @__PURE__ */ jsx(SkeletonBar, { className: "size-4" })
|
|
1455
|
+
}
|
|
1456
|
+
) : null,
|
|
1457
|
+
visibleColumns.map((column, columnIndex) => /* @__PURE__ */ jsx(
|
|
1458
|
+
"td",
|
|
1459
|
+
{
|
|
1460
|
+
style: isTree && columnIndex === 0 ? { paddingLeft: `calc(${geometry.pxValue} + ${TREE_LEAD}px)` } : void 0,
|
|
1461
|
+
className: cn("relative", geometry.px, geometry.cellPy),
|
|
1462
|
+
children: /* @__PURE__ */ jsx(SkeletonBar, { className: cn("h-4", skeletonWidth(index + columnIndex)) })
|
|
1463
|
+
},
|
|
1464
|
+
column.key
|
|
1465
|
+
)),
|
|
1466
|
+
rowActions ? /* @__PURE__ */ jsx("td", { className: cn("relative", geometry.actionsPx), children: /* @__PURE__ */ jsx(SkeletonBar, { className: "ml-auto h-4 w-12" }) }) : null
|
|
1467
|
+
] }, `skeleton-${index}`)) : error ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columnSpan, children: /* @__PURE__ */ jsx(TableErrorState, { error, onRetry }) }) }) : showEmpty ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan: columnSpan, children: empty ?? /* @__PURE__ */ jsx(TableEmptyState, { isFiltered: table.isFiltered, query: table.query, onClearFilters: table.clearFilters }) }) }) : table.rows.map((row, rowIndex) => {
|
|
1468
|
+
const id = getRowId(row);
|
|
1469
|
+
const depth = table.rowDepth.get(id) ?? 0;
|
|
1470
|
+
const selected = table.selection.has(id);
|
|
1471
|
+
const disabled = disabledRows?.(row) ?? false;
|
|
1472
|
+
const striped = rowIndex % 2 === 0;
|
|
1473
|
+
const resolved = expansion?.(row);
|
|
1474
|
+
const isBranch = expansionChildren(resolved) !== null;
|
|
1475
|
+
const detail = expansionDetail(resolved);
|
|
1476
|
+
const isOpen = table.expanded.has(id);
|
|
1477
|
+
const rowExpandable = Boolean(isBranch || detail);
|
|
1478
|
+
const rowClickable = !disabled && (onRowClick !== null || rowClickSelects && hasSelection || rowClickExpands && rowExpandable);
|
|
1479
|
+
const activateRow = () => {
|
|
1480
|
+
if (onRowClick) onRowClick(row);
|
|
1481
|
+
else if (rowClickSelects) (selection === "single" ? table.selectOnly : table.toggleRow)(id);
|
|
1482
|
+
else if (rowClickExpands) table.toggleExpanded(id);
|
|
1483
|
+
};
|
|
1484
|
+
const twisty = rowExpandable ? /* @__PURE__ */ jsx(
|
|
1485
|
+
"button",
|
|
1486
|
+
{
|
|
1487
|
+
type: "button",
|
|
1488
|
+
"aria-label": isOpen ? "Collapse row" : "Expand row",
|
|
1489
|
+
onClick: (event) => {
|
|
1490
|
+
event.stopPropagation();
|
|
1491
|
+
table.toggleExpanded(id);
|
|
1492
|
+
},
|
|
1493
|
+
className: "flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-sm text-fg-quaternary outline-focus-ring hover:text-primary focus-visible:outline-2",
|
|
1494
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, { className: cn("size-4 transition-transform", isOpen && "rotate-90") })
|
|
1495
|
+
}
|
|
1496
|
+
) : null;
|
|
1497
|
+
return /* @__PURE__ */ jsxs(React.Fragment, { children: [
|
|
1498
|
+
/* @__PURE__ */ jsxs(
|
|
1499
|
+
"tr",
|
|
1500
|
+
{
|
|
1501
|
+
"data-selected": selected || void 0,
|
|
1502
|
+
"aria-selected": hasSelection ? selected : void 0,
|
|
1503
|
+
"aria-expanded": rowExpandable ? isOpen : void 0,
|
|
1504
|
+
"aria-level": hasRenderedChildRow ? depth + 1 : void 0,
|
|
1505
|
+
onClick: rowClickable ? activateRow : void 0,
|
|
1506
|
+
tabIndex: rowClickable && onRowClick ? 0 : void 0,
|
|
1507
|
+
onKeyDown: rowClickable && onRowClick ? (event) => {
|
|
1508
|
+
if (event.target !== event.currentTarget) return;
|
|
1509
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1510
|
+
event.preventDefault();
|
|
1511
|
+
activateRow();
|
|
1512
|
+
} : void 0,
|
|
1513
|
+
className: cn(
|
|
1514
|
+
ROW_BASE,
|
|
1515
|
+
geometry.row,
|
|
1516
|
+
treatment === "divided" ? ROW_DIVIDER : striped && ROW_STRIPE,
|
|
1517
|
+
// A striped table cannot hover to the stripe's own colour, or half its rows
|
|
1518
|
+
// show no feedback.
|
|
1519
|
+
selected ? ROW_SELECTED : rowHover === "none" ? void 0 : treatment === "divided" ? ROW_HOVER : ROW_HOVER_STRIPED,
|
|
1520
|
+
rowClickable && ROW_CLICKABLE,
|
|
1521
|
+
disabled && ROW_DISABLED
|
|
1522
|
+
),
|
|
1523
|
+
children: [
|
|
1524
|
+
gutterExpander ? /* @__PURE__ */ jsx("td", { style: pinGutter ? { left: 0 } : void 0, className: cn("relative w-10", geometry.gutterPx, pinGutter && cn(PIN_BASE, "bg-inherit")), children: twisty }) : null,
|
|
1525
|
+
hasSelection ? /* @__PURE__ */ jsx(
|
|
1526
|
+
"td",
|
|
1527
|
+
{
|
|
1528
|
+
style: pinGutter ? { left: expanderWidth } : void 0,
|
|
1529
|
+
className: cn("relative", geometry.gutterPx, pinGutter && cn(PIN_BASE, "bg-inherit")),
|
|
1530
|
+
onClick: rowClickSelects ? void 0 : (event) => event.stopPropagation(),
|
|
1531
|
+
children: /* @__PURE__ */ jsx("span", { className: "flex items-center", onClick: (event) => event.stopPropagation(), children: selection === "multiple" ? /* @__PURE__ */ jsx(Checkbox, { "aria-label": "Select row", checked: selected, disabled, onCheckedChange: () => table.toggleRow(id) }) : /* @__PURE__ */ jsx(
|
|
1532
|
+
"input",
|
|
1533
|
+
{
|
|
1534
|
+
type: "radio",
|
|
1535
|
+
name: selectionName,
|
|
1536
|
+
"aria-label": "Select row",
|
|
1537
|
+
checked: selected,
|
|
1538
|
+
disabled,
|
|
1539
|
+
onChange: () => table.selectOnly(id),
|
|
1540
|
+
className: "size-4 cursor-pointer accent-bg-brand-solid"
|
|
1541
|
+
}
|
|
1542
|
+
) })
|
|
1543
|
+
}
|
|
1544
|
+
) : null,
|
|
1545
|
+
visibleColumns.map((column, columnIndex) => {
|
|
1546
|
+
const align = column.align ?? "start";
|
|
1547
|
+
const mode = column.overflow ?? "truncate";
|
|
1548
|
+
const overflow = overflowClasses(mode, { shrinkRoot: true });
|
|
1549
|
+
const pin = column.pin;
|
|
1550
|
+
const indent = columnIndex === 0 && depth > 0;
|
|
1551
|
+
const leadsTree = isTree && columnIndex === 0;
|
|
1552
|
+
const content = mode === "visible" ? cellContent(column, row) : /* @__PURE__ */ jsx("span", { className: cn("block", overflow.label), children: cellContent(column, row) });
|
|
1553
|
+
return /* @__PURE__ */ jsx(
|
|
1554
|
+
"td",
|
|
1555
|
+
{
|
|
1556
|
+
style: {
|
|
1557
|
+
width: widthPx(column),
|
|
1558
|
+
...pin === "start" && { left: offsets.start.get(column.key) },
|
|
1559
|
+
...pin === "end" && { right: offsets.end.get(column.key) },
|
|
1560
|
+
// Indentation lands on the FIRST cell, never on the row — indenting a
|
|
1561
|
+
// row breaks pinning and striping.
|
|
1562
|
+
...indent && { paddingLeft: `calc(${geometry.pxValue} + ${depth * TREE_INDENT}px)` }
|
|
1563
|
+
},
|
|
1564
|
+
className: cn(
|
|
1565
|
+
"relative",
|
|
1566
|
+
CELL_TEXT,
|
|
1567
|
+
CELL_FOCUS,
|
|
1568
|
+
geometry.px,
|
|
1569
|
+
geometry.cellPy,
|
|
1570
|
+
ALIGN[align],
|
|
1571
|
+
overflow.root,
|
|
1572
|
+
// `bg-inherit` = the row's own fill, so a frozen column still shows the
|
|
1573
|
+
// hover wash, the stripe and the selected wash (a literal `bg-primary` here
|
|
1574
|
+
// painted over all three).
|
|
1575
|
+
pin && cn(PIN_BASE, "bg-inherit", pin === "start" ? PIN_SHADOW_START : PIN_SHADOW_END)
|
|
1576
|
+
),
|
|
1577
|
+
children: leadsTree ? /* @__PURE__ */ jsxs("span", { className: cn("flex items-center gap-1", ALIGN_FLEX[align]), children: [
|
|
1578
|
+
twisty ?? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "size-6 shrink-0" }),
|
|
1579
|
+
content
|
|
1580
|
+
] }) : content
|
|
1581
|
+
},
|
|
1582
|
+
column.key
|
|
1583
|
+
);
|
|
1584
|
+
}),
|
|
1585
|
+
rowActions ? /* @__PURE__ */ jsx("td", { className: cn("relative", geometry.actionsPx), onClick: (event) => event.stopPropagation(), children: /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(RowActionsCell, { row, config: rowActions, size, onConfirm: setPendingAction }) }) }) : null
|
|
1586
|
+
]
|
|
1587
|
+
}
|
|
1588
|
+
),
|
|
1589
|
+
detail && isOpen ? (
|
|
1590
|
+
// Takes its PARENT's stripe value, which is why the stripe is computed from the
|
|
1591
|
+
// row index above: it could never be inherited through `odd:`, because this row is
|
|
1592
|
+
// itself a `<tbody>` child and would have taken the next value in the cadence.
|
|
1593
|
+
/* @__PURE__ */ jsx("tr", { className: cn(ROW_BASE, treatment === "divided" ? ROW_DIVIDER : striped && ROW_STRIPE), children: /* @__PURE__ */ jsx("td", { colSpan: columnSpan, className: cn("relative bg-secondary", geometry.px, geometry.cellPy), children: detail }) })
|
|
1594
|
+
) : null
|
|
1595
|
+
] }, id);
|
|
1596
|
+
}) })
|
|
1597
|
+
] });
|
|
1598
|
+
return /* @__PURE__ */ jsxs("div", { ref: rootRef, className: cn(SHELL, className), children: [
|
|
1599
|
+
title || description || headerActions ? /* @__PURE__ */ jsxs(
|
|
1600
|
+
"div",
|
|
1601
|
+
{
|
|
1602
|
+
className: cn(
|
|
1603
|
+
"flex flex-col items-start gap-4 border-b border-secondary px-4 md:flex-row md:items-center",
|
|
1604
|
+
geometry.cardPy,
|
|
1605
|
+
size === "sm" ? "md:px-5" : "md:px-6"
|
|
1606
|
+
),
|
|
1607
|
+
children: [
|
|
1608
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col gap-0.5", children: [
|
|
1609
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1610
|
+
title ? /* @__PURE__ */ jsx("h2", { className: "text-md font-semibold text-primary", children: title }) : null,
|
|
1611
|
+
badge === null || badge === void 0 ? null : React.isValidElement(badge) ? badge : /* @__PURE__ */ jsx(Badge, { size: "sm", variant: "outline", children: badge })
|
|
1612
|
+
] }),
|
|
1613
|
+
description ? /* @__PURE__ */ jsx("p", { className: "text-sm text-tertiary", children: description }) : null
|
|
1614
|
+
] }),
|
|
1615
|
+
headerActions
|
|
1616
|
+
]
|
|
1617
|
+
}
|
|
1618
|
+
) : null,
|
|
1619
|
+
toolbar || bulkActions && bulkActions.length > 0 ? /* @__PURE__ */ jsx(
|
|
1620
|
+
TableToolbarBar,
|
|
1621
|
+
{
|
|
1622
|
+
table,
|
|
1623
|
+
columns: leafColumns,
|
|
1624
|
+
toolbar,
|
|
1625
|
+
bulkActions,
|
|
1626
|
+
size,
|
|
1627
|
+
disabled: loading,
|
|
1628
|
+
onConfirm: setPendingAction,
|
|
1629
|
+
rootRef
|
|
1630
|
+
}
|
|
1631
|
+
) : null,
|
|
1632
|
+
responsive === "cards" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1633
|
+
/* @__PURE__ */ jsx("div", { className: "hidden md:block", children: /* @__PURE__ */ jsx(
|
|
1634
|
+
"div",
|
|
1635
|
+
{
|
|
1636
|
+
ref: scrollerRef,
|
|
1637
|
+
className: cn("group/scroller relative overflow-x-auto", stickyHeader && "overflow-y-auto"),
|
|
1638
|
+
style: maxHeight ? { maxHeight } : void 0,
|
|
1639
|
+
children: body
|
|
1640
|
+
}
|
|
1641
|
+
) }),
|
|
1642
|
+
/* @__PURE__ */ jsx("div", { className: "md:hidden", children: /* @__PURE__ */ jsx(
|
|
1643
|
+
TableCardStack,
|
|
1644
|
+
{
|
|
1645
|
+
table,
|
|
1646
|
+
columns: visibleColumns,
|
|
1647
|
+
getRowId,
|
|
1648
|
+
size,
|
|
1649
|
+
selection,
|
|
1650
|
+
rowActions,
|
|
1651
|
+
expansion,
|
|
1652
|
+
rowClick,
|
|
1653
|
+
disabledRows,
|
|
1654
|
+
loading,
|
|
1655
|
+
loadingRows,
|
|
1656
|
+
onConfirm: setPendingAction,
|
|
1657
|
+
error,
|
|
1658
|
+
onRetry,
|
|
1659
|
+
empty
|
|
1660
|
+
}
|
|
1661
|
+
) })
|
|
1662
|
+
] }) : /* @__PURE__ */ jsx(
|
|
1663
|
+
"div",
|
|
1664
|
+
{
|
|
1665
|
+
ref: scrollerRef,
|
|
1666
|
+
className: cn("group/scroller relative overflow-x-auto", stickyHeader && "overflow-y-auto"),
|
|
1667
|
+
style: maxHeight ? { maxHeight } : void 0,
|
|
1668
|
+
children: body
|
|
1669
|
+
}
|
|
1670
|
+
),
|
|
1671
|
+
showPagination ? /* @__PURE__ */ jsx("div", { className: cn("border-t border-secondary px-4 py-3", size === "sm" ? "md:px-5" : "md:px-6"), children: /* @__PURE__ */ jsx(
|
|
1672
|
+
Pagination,
|
|
1673
|
+
{
|
|
1674
|
+
...paginationOptions,
|
|
1675
|
+
variant: paginationOptions.variant ?? "numbered",
|
|
1676
|
+
page: table.page,
|
|
1677
|
+
pageCount: table.pageCount,
|
|
1678
|
+
onPageChange: table.setPage,
|
|
1679
|
+
pageSize: table.pageSize,
|
|
1680
|
+
pageSizeOptions,
|
|
1681
|
+
onPageSizeChange: table.setPageSize,
|
|
1682
|
+
totalItems: table.totalRows,
|
|
1683
|
+
disabled: loading
|
|
1684
|
+
}
|
|
1685
|
+
) }) : null,
|
|
1686
|
+
pendingAction ? /* @__PURE__ */ jsx(ConfirmAction, { action: pendingAction, onClose: () => setPendingAction(null) }) : null
|
|
1687
|
+
] });
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
export { Table, expansionChildren, expansionDetail, flattenColumns, hasColumnGroups, isColumnGroup, useTable };
|
|
1691
|
+
//# sourceMappingURL=chunk-MKC5HNA7.js.map
|
|
1692
|
+
//# sourceMappingURL=chunk-MKC5HNA7.js.map
|