@uipath/apollo-wind 2.92.0 → 2.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/forms/field-renderer.cjs +1 -1
- package/dist/components/forms/field-renderer.js +1 -1
- package/dist/components/forms/field-rules-strings.cjs +40 -0
- package/dist/components/forms/field-rules-strings.d.ts +17 -0
- package/dist/components/forms/field-rules-strings.js +6 -0
- package/dist/components/forms/field-rules.cjs +526 -0
- package/dist/components/forms/field-rules.d.ts +97 -0
- package/dist/components/forms/field-rules.js +468 -0
- package/dist/components/forms/form-designer.cjs +208 -592
- package/dist/components/forms/form-designer.js +210 -594
- package/dist/components/forms/form-schema.d.ts +5 -0
- package/dist/components/forms/index.cjs +43 -3
- package/dist/components/forms/index.d.ts +4 -0
- package/dist/components/forms/index.js +5 -1
- package/dist/components/forms/metadata-form.cjs +1 -1
- package/dist/components/forms/metadata-form.js +1 -1
- package/dist/components/forms/rules-engine-dialect.cjs +644 -0
- package/dist/components/forms/rules-engine-dialect.d.ts +90 -0
- package/dist/components/forms/rules-engine-dialect.js +537 -0
- package/dist/components/forms/rules-engine.cjs +99 -10
- package/dist/components/forms/rules-engine.d.ts +5 -0
- package/dist/components/forms/rules-engine.js +99 -10
- package/dist/components/forms/use-field-rules.cjs +122 -0
- package/dist/components/forms/use-field-rules.d.ts +31 -0
- package/dist/components/forms/use-field-rules.js +88 -0
- package/dist/components/ui/conditions-editor/condition-row.cjs +458 -0
- package/dist/components/ui/conditions-editor/condition-row.d.ts +23 -0
- package/dist/components/ui/conditions-editor/condition-row.js +421 -0
- package/dist/components/ui/conditions-editor/conditions-editor.cjs +363 -0
- package/dist/components/ui/conditions-editor/conditions-editor.d.ts +67 -0
- package/dist/components/ui/conditions-editor/conditions-editor.js +329 -0
- package/dist/components/ui/conditions-editor/context.cjs +45 -0
- package/dist/components/ui/conditions-editor/context.d.ts +54 -0
- package/dist/components/ui/conditions-editor/context.js +8 -0
- package/dist/components/ui/conditions-editor/index.cjs +55 -0
- package/dist/components/ui/conditions-editor/index.d.ts +6 -0
- package/dist/components/ui/conditions-editor/index.js +6 -0
- package/dist/components/ui/conditions-editor/model.cjs +126 -0
- package/dist/components/ui/conditions-editor/model.d.ts +39 -0
- package/dist/components/ui/conditions-editor/model.js +71 -0
- package/dist/components/ui/conditions-editor/status.cjs +198 -0
- package/dist/components/ui/conditions-editor/status.d.ts +44 -0
- package/dist/components/ui/conditions-editor/status.js +131 -0
- package/dist/components/ui/conditions-editor/strings.cjs +86 -0
- package/dist/components/ui/conditions-editor/strings.d.ts +62 -0
- package/dist/components/ui/conditions-editor/strings.js +52 -0
- package/dist/components/ui/conditions-editor/vocabulary.cjs +163 -0
- package/dist/components/ui/conditions-editor/vocabulary.d.ts +51 -0
- package/dist/components/ui/conditions-editor/vocabulary.js +129 -0
- package/dist/components/ui/data-table.cjs +493 -104
- package/dist/components/ui/data-table.d.ts +88 -5
- package/dist/components/ui/data-table.js +491 -105
- package/dist/components/ui/editable-cell.cjs +91 -27
- package/dist/components/ui/editable-cell.d.ts +14 -1
- package/dist/components/ui/editable-cell.js +91 -27
- package/dist/components/ui/field-actions/index.cjs +9 -2
- package/dist/components/ui/field-actions/index.d.ts +1 -0
- package/dist/components/ui/field-actions/index.js +2 -1
- package/dist/components/ui/field-actions/insert-variable-action.cjs +3 -1
- package/dist/components/ui/field-actions/insert-variable-action.d.ts +4 -1
- package/dist/components/ui/field-actions/insert-variable-action.js +3 -1
- package/dist/components/ui/field-actions/rules-action.cjs +244 -0
- package/dist/components/ui/field-actions/rules-action.d.ts +42 -0
- package/dist/components/ui/field-actions/rules-action.js +207 -0
- package/dist/components/ui/index.cjs +282 -243
- package/dist/components/ui/index.d.ts +3 -0
- package/dist/components/ui/index.js +3 -0
- package/dist/components/ui/quick-form-field/components/field-header.cjs +137 -167
- package/dist/components/ui/quick-form-field/components/field-header.d.ts +1 -1
- package/dist/components/ui/quick-form-field/components/field-header.js +138 -168
- package/dist/components/ui/quick-form-field/components/header-actions.cjs +187 -0
- package/dist/components/ui/quick-form-field/components/header-actions.d.ts +59 -0
- package/dist/components/ui/quick-form-field/components/header-actions.js +138 -0
- package/dist/components/ui/quick-form-field/components/header-context.cjs +59 -0
- package/dist/components/ui/quick-form-field/components/header-context.d.ts +33 -0
- package/dist/components/ui/quick-form-field/components/header-context.js +16 -0
- package/dist/components/ui/quick-form-field/index.cjs +18 -4
- package/dist/components/ui/quick-form-field/index.d.ts +2 -0
- package/dist/components/ui/quick-form-field/index.js +3 -1
- package/dist/components/ui/quick-form-field/quick-form-field.cjs +1 -1
- package/dist/components/ui/quick-form-field/quick-form-field.d.ts +6 -6
- package/dist/components/ui/quick-form-field/quick-form-field.js +1 -1
- package/dist/components/ui/quick-form-field/types.d.ts +42 -11
- package/dist/components/ui/row-groups/add-row-button.cjs +54 -0
- package/dist/components/ui/row-groups/add-row-button.d.ts +10 -0
- package/dist/components/ui/row-groups/add-row-button.js +20 -0
- package/dist/components/ui/row-groups/after-press.cjs +73 -0
- package/dist/components/ui/row-groups/after-press.d.ts +7 -0
- package/dist/components/ui/row-groups/after-press.js +36 -0
- package/dist/components/ui/row-groups/collapsible-row-group.cjs +83 -0
- package/dist/components/ui/row-groups/collapsible-row-group.d.ts +13 -0
- package/dist/components/ui/row-groups/collapsible-row-group.js +49 -0
- package/dist/components/ui/row-groups/empty-rows.cjs +42 -0
- package/dist/components/ui/row-groups/empty-rows.d.ts +7 -0
- package/dist/components/ui/row-groups/empty-rows.js +8 -0
- package/dist/components/ui/row-groups/group-mode-toggle.cjs +80 -0
- package/dist/components/ui/row-groups/group-mode-toggle.d.ts +26 -0
- package/dist/components/ui/row-groups/group-mode-toggle.js +40 -0
- package/dist/components/ui/row-groups/index.cjs +62 -0
- package/dist/components/ui/row-groups/index.d.ts +6 -0
- package/dist/components/ui/row-groups/index.js +7 -0
- package/dist/components/ui/row-groups/row-delete-button.cjs +54 -0
- package/dist/components/ui/row-groups/row-delete-button.d.ts +18 -0
- package/dist/components/ui/row-groups/row-delete-button.js +20 -0
- package/dist/components/ui/row-groups/use-row-focus.cjs +82 -0
- package/dist/components/ui/row-groups/use-row-focus.d.ts +17 -0
- package/dist/components/ui/row-groups/use-row-focus.js +48 -0
- package/dist/components/ui/rules-editor/context.cjs +45 -0
- package/dist/components/ui/rules-editor/context.d.ts +52 -0
- package/dist/components/ui/rules-editor/context.js +8 -0
- package/dist/components/ui/rules-editor/index.cjs +56 -0
- package/dist/components/ui/rules-editor/index.d.ts +4 -0
- package/dist/components/ui/rules-editor/index.js +4 -0
- package/dist/components/ui/rules-editor/model.cjs +205 -0
- package/dist/components/ui/rules-editor/model.d.ts +128 -0
- package/dist/components/ui/rules-editor/model.js +144 -0
- package/dist/components/ui/rules-editor/rule-card.cjs +470 -0
- package/dist/components/ui/rules-editor/rule-card.d.ts +14 -0
- package/dist/components/ui/rules-editor/rule-card.js +436 -0
- package/dist/components/ui/rules-editor/rules-editor.cjs +160 -0
- package/dist/components/ui/rules-editor/rules-editor.d.ts +66 -0
- package/dist/components/ui/rules-editor/rules-editor.js +126 -0
- package/dist/components/ui/rules-editor/strings.cjs +68 -0
- package/dist/components/ui/rules-editor/strings.d.ts +56 -0
- package/dist/components/ui/rules-editor/strings.js +34 -0
- package/dist/index.cjs +132 -8
- package/dist/index.d.ts +19 -6
- package/dist/index.js +11 -4
- package/dist/styles.css +119 -24
- package/package.json +2 -2
|
@@ -1,23 +1,161 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { ArrowDown, ArrowUp, ArrowUpDown, ChevronDown } from "lucide-react";
|
|
4
4
|
import { Button } from "./button.js";
|
|
5
5
|
import { Checkbox } from "./checkbox.js";
|
|
6
6
|
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger } from "./dropdown-menu.js";
|
|
7
7
|
import { EditableCell } from "./editable-cell.js";
|
|
8
8
|
import { Input } from "./input.js";
|
|
9
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
10
|
+
import { Skeleton } from "./skeleton.js";
|
|
9
11
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./table.js";
|
|
10
12
|
import { cn } from "../../lib/index.js";
|
|
11
13
|
import { flexRender, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
|
|
12
|
-
|
|
14
|
+
const DEFAULT_DATA_TABLE_STRINGS = {
|
|
15
|
+
search: 'Search',
|
|
16
|
+
noResults: 'No results.',
|
|
17
|
+
loading: 'Loading',
|
|
18
|
+
previous: 'Previous',
|
|
19
|
+
next: 'Next',
|
|
20
|
+
page: (page, pageCount)=>`Page ${page} of ${pageCount}`,
|
|
21
|
+
rowsSelected: (selected, total)=>`${selected} of ${total} row(s) selected.`,
|
|
22
|
+
rowsPerPage: 'Rows per page',
|
|
23
|
+
selectAll: 'Select all',
|
|
24
|
+
selectRow: (rowNumber)=>`Select row ${rowNumber}`,
|
|
25
|
+
resizeColumn: (column)=>`Resize ${column} column`,
|
|
26
|
+
editCell: (column, rowNumber)=>`Edit ${column}, row ${rowNumber}`,
|
|
27
|
+
toggleCell: (column, rowNumber)=>`${column}, row ${rowNumber}`,
|
|
28
|
+
scrollRegion: 'Table rows'
|
|
29
|
+
};
|
|
30
|
+
const INTERNAL_META_KEY = '__apolloDataTable';
|
|
31
|
+
function getInternalMeta(table) {
|
|
32
|
+
return table.options.meta?.[INTERNAL_META_KEY];
|
|
33
|
+
}
|
|
34
|
+
function resolveColumnId(def) {
|
|
35
|
+
if (def.id) return def.id;
|
|
36
|
+
const accessorKey = def.accessorKey;
|
|
37
|
+
return 'string' == typeof accessorKey ? accessorKey.replace(/\./g, '_') : void 0;
|
|
38
|
+
}
|
|
39
|
+
function hasAccessor(def) {
|
|
40
|
+
const candidate = def;
|
|
41
|
+
return void 0 !== candidate.accessorKey || void 0 !== candidate.accessorFn;
|
|
42
|
+
}
|
|
43
|
+
function mapLeafColumns(defs, fn) {
|
|
44
|
+
return defs.map((def)=>{
|
|
45
|
+
const children = def.columns;
|
|
46
|
+
if (children?.length) return {
|
|
47
|
+
...def,
|
|
48
|
+
columns: mapLeafColumns(children, fn)
|
|
49
|
+
};
|
|
50
|
+
return fn(def);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function flattenLeafColumns(defs) {
|
|
54
|
+
return defs.flatMap((def)=>{
|
|
55
|
+
const children = def.columns;
|
|
56
|
+
return children?.length ? flattenLeafColumns(children) : [
|
|
57
|
+
def
|
|
58
|
+
];
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function getColumnLabel(column) {
|
|
62
|
+
const meta = column.columnDef.meta;
|
|
63
|
+
if (meta?.label) return meta.label;
|
|
64
|
+
const header = column.columnDef.header;
|
|
65
|
+
return 'string' == typeof header && '' !== header.trim() ? header : column.id;
|
|
66
|
+
}
|
|
67
|
+
const collator = new Intl.Collator(void 0, {
|
|
68
|
+
numeric: true,
|
|
69
|
+
sensitivity: 'base'
|
|
70
|
+
});
|
|
71
|
+
function compareValues(a, b) {
|
|
72
|
+
const aEmpty = null == a || '' === a;
|
|
73
|
+
const bEmpty = null == b || '' === b;
|
|
74
|
+
if (aEmpty || bEmpty) return aEmpty === bEmpty ? 0 : aEmpty ? 1 : -1;
|
|
75
|
+
if ('number' == typeof a && 'number' == typeof b) return a - b;
|
|
76
|
+
if ('bigint' == typeof a && 'bigint' == typeof b) return a < b ? -1 : a > b ? 1 : 0;
|
|
77
|
+
if ('boolean' == typeof a && 'boolean' == typeof b) return Number(a) - Number(b);
|
|
78
|
+
if (a instanceof Date && b instanceof Date) return a.getTime() - b.getTime();
|
|
79
|
+
return collator.compare(String(a), String(b));
|
|
80
|
+
}
|
|
81
|
+
const defaultSortingFn = (rowA, rowB, columnId)=>compareValues(rowA.getValue(columnId), rowB.getValue(columnId));
|
|
82
|
+
const containsTextFilterFn = (row, columnId, filterValue)=>{
|
|
83
|
+
const query = String(filterValue ?? '').toLowerCase();
|
|
84
|
+
if ('' === query) return true;
|
|
85
|
+
const value = row.getValue(columnId);
|
|
86
|
+
if (null == value) return false;
|
|
87
|
+
return String(value).toLowerCase().includes(query);
|
|
88
|
+
};
|
|
89
|
+
containsTextFilterFn.autoRemove = (value)=>!value;
|
|
90
|
+
function EditableCellRenderer(cellContext) {
|
|
91
|
+
const internal = getInternalMeta(cellContext.table);
|
|
92
|
+
const strings = internal?.strings ?? DEFAULT_DATA_TABLE_STRINGS;
|
|
93
|
+
const columnLabel = getColumnLabel(cellContext.column);
|
|
94
|
+
const rowNumber = cellContext.row.index + 1;
|
|
95
|
+
return /*#__PURE__*/ jsx(EditableCell, {
|
|
96
|
+
cell: cellContext,
|
|
97
|
+
editLabel: strings.editCell(columnLabel, rowNumber),
|
|
98
|
+
toggleLabel: strings.toggleCell(columnLabel, rowNumber),
|
|
99
|
+
onUpdate: (value)=>{
|
|
100
|
+
internal?.onCellUpdate.current?.(cellContext.row.index, cellContext.column.id, value);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const INTERACTIVE_SELECTOR = 'a, button, input, select, textarea, label, summary, [role="button"], [role="checkbox"], [role="switch"], [role="menuitem"], [role="combobox"], [role="separator"], [contenteditable="true"]';
|
|
105
|
+
const RESIZE_STEP = 10;
|
|
106
|
+
const RESIZE_STEP_LARGE = 50;
|
|
107
|
+
const RESIZE_FALLBACK_MIN = 20;
|
|
108
|
+
function DataTable({ columns, data, className, searchKey, searchPlaceholder = 'Search...', searchValue: controlledSearch, onSearchChange, showColumnToggle = true, showPagination = true, pageSize = 10, pageSizeOptions, pagination: controlledPagination, onPaginationChange: controlledOnPaginationChange, manualPagination = false, rowCount, editable = false, onCellUpdate, resizable = false, compact = false, columnToggleText = 'Columns', getRowId, rowSelection: controlledRowSelection, onRowSelectionChange: controlledOnRowSelectionChange, showSelectionCount, sorting: controlledSorting, onSortingChange: controlledOnSortingChange, initialSorting, columnSizing: controlledColumnSizing, onColumnSizingChange: controlledOnColumnSizingChange, columnVisibility: controlledColumnVisibility, onColumnVisibilityChange: controlledOnColumnVisibilityChange, globalFilterFn, allowWrap = false, toolbarContent, maxBodyHeight, onRowClick, loading = false, emptyState, strings: stringOverrides }) {
|
|
13
109
|
const useBlockLayout = void 0 !== maxBodyHeight;
|
|
14
110
|
const blockRowClasses = '[&>tr]:table [&>tr]:w-full [&>tr]:table-fixed';
|
|
111
|
+
const strings = useMemo(()=>{
|
|
112
|
+
const merged = {
|
|
113
|
+
...DEFAULT_DATA_TABLE_STRINGS
|
|
114
|
+
};
|
|
115
|
+
if (stringOverrides) for (const key of Object.keys(stringOverrides)){
|
|
116
|
+
const value = stringOverrides[key];
|
|
117
|
+
if (void 0 !== value) merged[key] = value;
|
|
118
|
+
}
|
|
119
|
+
return merged;
|
|
120
|
+
}, [
|
|
121
|
+
stringOverrides
|
|
122
|
+
]);
|
|
15
123
|
const [internalSorting, setInternalSorting] = useState(initialSorting ?? []);
|
|
16
|
-
const [columnFilters, setColumnFilters] = useState([]);
|
|
17
124
|
const [internalColumnVisibility, setInternalColumnVisibility] = useState({});
|
|
18
125
|
const [internalColumnSizing, setInternalColumnSizing] = useState({});
|
|
19
126
|
const [internalRowSelection, setInternalRowSelection] = useState({});
|
|
20
|
-
const [
|
|
127
|
+
const [internalSearch, setInternalSearch] = useState('');
|
|
128
|
+
const [internalPagination, setInternalPagination] = useState({
|
|
129
|
+
pageIndex: 0,
|
|
130
|
+
pageSize
|
|
131
|
+
});
|
|
132
|
+
const [appliedPageSize, setAppliedPageSize] = useState(pageSize);
|
|
133
|
+
if (appliedPageSize !== pageSize) {
|
|
134
|
+
setAppliedPageSize(pageSize);
|
|
135
|
+
setInternalPagination({
|
|
136
|
+
pageIndex: 0,
|
|
137
|
+
pageSize
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const isPaginationControlled = void 0 !== controlledPagination;
|
|
141
|
+
const pagination = isPaginationControlled ? controlledPagination : internalPagination;
|
|
142
|
+
const paginationRef = useRef(pagination);
|
|
143
|
+
paginationRef.current = pagination;
|
|
144
|
+
const onPaginationChange = useCallback((updater)=>{
|
|
145
|
+
if (!isPaginationControlled) setInternalPagination((prev)=>'function' == typeof updater ? updater(prev) : updater);
|
|
146
|
+
controlledOnPaginationChange?.(updater);
|
|
147
|
+
}, [
|
|
148
|
+
isPaginationControlled,
|
|
149
|
+
controlledOnPaginationChange
|
|
150
|
+
]);
|
|
151
|
+
const resetPageIndex = useCallback(()=>{
|
|
152
|
+
if (0 !== paginationRef.current.pageIndex) onPaginationChange((prev)=>({
|
|
153
|
+
...prev,
|
|
154
|
+
pageIndex: 0
|
|
155
|
+
}));
|
|
156
|
+
}, [
|
|
157
|
+
onPaginationChange
|
|
158
|
+
]);
|
|
21
159
|
const isRowSelectionControlled = void 0 !== controlledRowSelection;
|
|
22
160
|
const rowSelection = isRowSelectionControlled ? controlledRowSelection : internalRowSelection;
|
|
23
161
|
const rowSelectionRef = useRef(rowSelection);
|
|
@@ -35,9 +173,11 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
35
173
|
const onSortingChange = useCallback((updater)=>{
|
|
36
174
|
if (!isSortingControlled) setInternalSorting((prev)=>'function' == typeof updater ? updater(prev) : updater);
|
|
37
175
|
controlledOnSortingChange?.(updater);
|
|
176
|
+
resetPageIndex();
|
|
38
177
|
}, [
|
|
39
178
|
isSortingControlled,
|
|
40
|
-
controlledOnSortingChange
|
|
179
|
+
controlledOnSortingChange,
|
|
180
|
+
resetPageIndex
|
|
41
181
|
]);
|
|
42
182
|
const isColumnSizingControlled = void 0 !== controlledColumnSizing;
|
|
43
183
|
const columnSizing = isColumnSizingControlled ? controlledColumnSizing : internalColumnSizing;
|
|
@@ -60,40 +200,141 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
60
200
|
const tanstackGlobalFilterFn = useMemo(()=>globalFilterFn ? (row, _columnId, filterValue)=>globalFilterFn(row.original, filterValue) : void 0, [
|
|
61
201
|
globalFilterFn
|
|
62
202
|
]);
|
|
203
|
+
const leafColumnDefs = useMemo(()=>flattenLeafColumns(columns), [
|
|
204
|
+
columns
|
|
205
|
+
]);
|
|
206
|
+
const globalFilterColumnId = useMemo(()=>{
|
|
207
|
+
const def = leafColumnDefs.find((candidate)=>hasAccessor(candidate) && false !== candidate.enableGlobalFilter);
|
|
208
|
+
return def ? resolveColumnId(def) : void 0;
|
|
209
|
+
}, [
|
|
210
|
+
leafColumnDefs
|
|
211
|
+
]);
|
|
212
|
+
const searchColumnExists = useMemo(()=>void 0 !== searchKey && leafColumnDefs.some((def)=>resolveColumnId(def) === searchKey), [
|
|
213
|
+
leafColumnDefs,
|
|
214
|
+
searchKey
|
|
215
|
+
]);
|
|
216
|
+
const [internalColumnFilters, setInternalColumnFilters] = useState([]);
|
|
217
|
+
const usesColumnSearch = !globalFilterFn && void 0 !== searchKey;
|
|
218
|
+
const search = void 0 !== controlledSearch ? controlledSearch : usesColumnSearch ? String(internalColumnFilters.find((filter)=>filter.id === searchKey)?.value ?? '') : internalSearch;
|
|
219
|
+
const columnFilters = useMemo(()=>{
|
|
220
|
+
if (!usesColumnSearch) return internalColumnFilters;
|
|
221
|
+
const others = internalColumnFilters.filter((filter)=>filter.id !== searchKey);
|
|
222
|
+
return searchColumnExists && '' !== search ? [
|
|
223
|
+
...others,
|
|
224
|
+
{
|
|
225
|
+
id: searchKey,
|
|
226
|
+
value: search
|
|
227
|
+
}
|
|
228
|
+
] : others;
|
|
229
|
+
}, [
|
|
230
|
+
usesColumnSearch,
|
|
231
|
+
internalColumnFilters,
|
|
232
|
+
searchKey,
|
|
233
|
+
searchColumnExists,
|
|
234
|
+
search
|
|
235
|
+
]);
|
|
236
|
+
const columnFiltersRef = useRef(columnFilters);
|
|
237
|
+
columnFiltersRef.current = columnFilters;
|
|
238
|
+
const handleSearchChange = (value)=>{
|
|
239
|
+
if (void 0 === controlledSearch) if (usesColumnSearch) setInternalColumnFilters((prev)=>[
|
|
240
|
+
...prev.filter((filter)=>filter.id !== searchKey),
|
|
241
|
+
...'' === value ? [] : [
|
|
242
|
+
{
|
|
243
|
+
id: searchKey,
|
|
244
|
+
value
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
]);
|
|
248
|
+
else setInternalSearch(value);
|
|
249
|
+
onSearchChange?.(value);
|
|
250
|
+
resetPageIndex();
|
|
251
|
+
};
|
|
252
|
+
const onColumnFiltersChange = (updater)=>{
|
|
253
|
+
const next = 'function' == typeof updater ? updater(columnFiltersRef.current) : updater;
|
|
254
|
+
setInternalColumnFilters(next);
|
|
255
|
+
if (usesColumnSearch && void 0 !== controlledSearch) {
|
|
256
|
+
const value = String(next.find((filter)=>filter.id === searchKey)?.value ?? '');
|
|
257
|
+
if (value !== controlledSearch) onSearchChange?.(value);
|
|
258
|
+
}
|
|
259
|
+
resetPageIndex();
|
|
260
|
+
};
|
|
261
|
+
const onCellUpdateRef = useRef(onCellUpdate);
|
|
262
|
+
onCellUpdateRef.current = onCellUpdate;
|
|
263
|
+
const isEditable = editable && void 0 !== onCellUpdate;
|
|
264
|
+
useEffect(()=>{
|
|
265
|
+
if (editable && !onCellUpdate) console.warn('DataTable: `editable` has no effect without `onCellUpdate`.');
|
|
266
|
+
if (void 0 !== searchKey && !globalFilterFn && !searchColumnExists) console.warn(`DataTable: \`searchKey\` "${searchKey}" does not match any column id.`);
|
|
267
|
+
}, [
|
|
268
|
+
editable,
|
|
269
|
+
onCellUpdate,
|
|
270
|
+
searchKey,
|
|
271
|
+
globalFilterFn,
|
|
272
|
+
searchColumnExists
|
|
273
|
+
]);
|
|
63
274
|
const processedColumns = useMemo(()=>{
|
|
64
|
-
|
|
65
|
-
return columns
|
|
275
|
+
const needsSearchFilter = void 0 !== searchKey && !globalFilterFn;
|
|
276
|
+
if (!isEditable && !needsSearchFilter) return columns;
|
|
277
|
+
return mapLeafColumns(columns, (col)=>{
|
|
278
|
+
let next = col;
|
|
279
|
+
if (needsSearchFilter && resolveColumnId(col) === searchKey && void 0 === col.filterFn) next = {
|
|
280
|
+
...next,
|
|
281
|
+
filterFn: containsTextFilterFn
|
|
282
|
+
};
|
|
66
283
|
const meta = col.meta;
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
cell: (cellContext)=>/*#__PURE__*/ jsx(EditableCell, {
|
|
71
|
-
cell: cellContext,
|
|
72
|
-
onUpdate: (value)=>{
|
|
73
|
-
onCellUpdate(cellContext.row.index, cellContext.column.id, value);
|
|
74
|
-
}
|
|
75
|
-
})
|
|
284
|
+
if (isEditable && meta?.type && !col.cell) next = {
|
|
285
|
+
...next,
|
|
286
|
+
cell: EditableCellRenderer
|
|
76
287
|
};
|
|
288
|
+
return next;
|
|
77
289
|
});
|
|
78
290
|
}, [
|
|
79
291
|
columns,
|
|
80
|
-
|
|
81
|
-
|
|
292
|
+
isEditable,
|
|
293
|
+
searchKey,
|
|
294
|
+
globalFilterFn
|
|
82
295
|
]);
|
|
296
|
+
const tableMeta = useMemo(()=>({
|
|
297
|
+
[INTERNAL_META_KEY]: {
|
|
298
|
+
strings,
|
|
299
|
+
onCellUpdate: onCellUpdateRef
|
|
300
|
+
}
|
|
301
|
+
}), [
|
|
302
|
+
strings
|
|
303
|
+
]);
|
|
304
|
+
const paginate = showPagination || isPaginationControlled;
|
|
83
305
|
const table = useReactTable({
|
|
84
306
|
data,
|
|
85
307
|
columns: processedColumns,
|
|
308
|
+
meta: tableMeta,
|
|
309
|
+
getRowId,
|
|
310
|
+
defaultColumn: {
|
|
311
|
+
size: void 0,
|
|
312
|
+
minSize: void 0,
|
|
313
|
+
maxSize: void 0,
|
|
314
|
+
sortingFn: defaultSortingFn
|
|
315
|
+
},
|
|
86
316
|
onSortingChange,
|
|
87
|
-
onColumnFiltersChange
|
|
317
|
+
onColumnFiltersChange,
|
|
318
|
+
onGlobalFilterChange: (updater)=>{
|
|
319
|
+
if (!globalFilterFn) return;
|
|
320
|
+
const next = 'function' == typeof updater ? updater(search) : updater;
|
|
321
|
+
handleSearchChange(String(next ?? ''));
|
|
322
|
+
},
|
|
88
323
|
getCoreRowModel: getCoreRowModel(),
|
|
89
|
-
getPaginationRowModel: getPaginationRowModel(),
|
|
324
|
+
getPaginationRowModel: paginate && !manualPagination ? getPaginationRowModel() : void 0,
|
|
90
325
|
getSortedRowModel: getSortedRowModel(),
|
|
91
326
|
getFilteredRowModel: getFilteredRowModel(),
|
|
92
327
|
onColumnVisibilityChange,
|
|
93
328
|
onColumnSizingChange,
|
|
94
329
|
onRowSelectionChange: setRowSelection,
|
|
95
|
-
|
|
330
|
+
onPaginationChange,
|
|
331
|
+
manualPagination,
|
|
332
|
+
rowCount,
|
|
333
|
+
autoResetPageIndex: false,
|
|
96
334
|
globalFilterFn: tanstackGlobalFilterFn,
|
|
335
|
+
...globalFilterFn ? {
|
|
336
|
+
getColumnCanGlobalFilter: (column)=>column.id === globalFilterColumnId
|
|
337
|
+
} : {},
|
|
97
338
|
enableColumnResizing: resizable,
|
|
98
339
|
columnResizeMode: 'onChange',
|
|
99
340
|
state: {
|
|
@@ -102,31 +343,95 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
102
343
|
columnVisibility,
|
|
103
344
|
columnSizing,
|
|
104
345
|
rowSelection,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
initialState: {
|
|
108
|
-
pagination: {
|
|
109
|
-
pageSize
|
|
110
|
-
}
|
|
346
|
+
pagination,
|
|
347
|
+
globalFilter: globalFilterFn ? search : ''
|
|
111
348
|
}
|
|
112
349
|
});
|
|
350
|
+
const pageCount = paginate ? Math.max(table.getPageCount(), 1) : 1;
|
|
351
|
+
const lastPageIndex = pageCount - 1;
|
|
352
|
+
const pageIndexOutOfRange = paginate && !manualPagination && pagination.pageIndex > lastPageIndex;
|
|
353
|
+
if (pageIndexOutOfRange) table.setOptions((prev)=>({
|
|
354
|
+
...prev,
|
|
355
|
+
state: {
|
|
356
|
+
...prev.state,
|
|
357
|
+
pagination: {
|
|
358
|
+
...pagination,
|
|
359
|
+
pageIndex: lastPageIndex
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}));
|
|
363
|
+
useEffect(()=>{
|
|
364
|
+
if (pageIndexOutOfRange) onPaginationChange((prev)=>({
|
|
365
|
+
...prev,
|
|
366
|
+
pageIndex: lastPageIndex
|
|
367
|
+
}));
|
|
368
|
+
}, [
|
|
369
|
+
pageIndexOutOfRange,
|
|
370
|
+
lastPageIndex,
|
|
371
|
+
onPaginationChange
|
|
372
|
+
]);
|
|
373
|
+
const currentPageIndex = pageIndexOutOfRange ? lastPageIndex : pagination.pageIndex;
|
|
374
|
+
const rows = table.getRowModel().rows;
|
|
375
|
+
const visibleColumnCount = Math.max(table.getVisibleLeafColumns().length, 1);
|
|
376
|
+
const hasSelectColumn = leafColumnDefs.some((def)=>'select' === resolveColumnId(def));
|
|
377
|
+
const selectionCountVisible = showSelectionCount ?? (hasSelectColumn || isRowSelectionControlled || Object.keys(rowSelection).length > 0);
|
|
378
|
+
const showSearch = void 0 !== globalFilterFn || void 0 !== searchKey;
|
|
379
|
+
const resizeColumnBy = (header, delta)=>{
|
|
380
|
+
const { column } = header;
|
|
381
|
+
const min = column.columnDef.minSize ?? RESIZE_FALLBACK_MIN;
|
|
382
|
+
const max = column.columnDef.maxSize ?? Number.MAX_SAFE_INTEGER;
|
|
383
|
+
const current = column.getSize();
|
|
384
|
+
const target = 'min' === delta ? min : 'max' === delta ? max : current + delta;
|
|
385
|
+
const next = Math.min(Math.max(target, min), max);
|
|
386
|
+
if (next !== current) table.setColumnSizing((prev)=>({
|
|
387
|
+
...prev,
|
|
388
|
+
[column.id]: next
|
|
389
|
+
}));
|
|
390
|
+
};
|
|
391
|
+
const handleResizeKeyDown = (event, header)=>{
|
|
392
|
+
const step = event.shiftKey ? RESIZE_STEP_LARGE : RESIZE_STEP;
|
|
393
|
+
switch(event.key){
|
|
394
|
+
case 'ArrowLeft':
|
|
395
|
+
resizeColumnBy(header, -step);
|
|
396
|
+
break;
|
|
397
|
+
case 'ArrowRight':
|
|
398
|
+
resizeColumnBy(header, step);
|
|
399
|
+
break;
|
|
400
|
+
case 'Home':
|
|
401
|
+
resizeColumnBy(header, 'min');
|
|
402
|
+
break;
|
|
403
|
+
case 'End':
|
|
404
|
+
if (void 0 === header.column.columnDef.maxSize) return;
|
|
405
|
+
resizeColumnBy(header, 'max');
|
|
406
|
+
break;
|
|
407
|
+
case 'Enter':
|
|
408
|
+
header.column.resetSize();
|
|
409
|
+
break;
|
|
410
|
+
default:
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
event.preventDefault();
|
|
414
|
+
};
|
|
415
|
+
const cellSizeStyle = (column)=>({
|
|
416
|
+
width: resizable ? column.getSize() : column.columnDef.size,
|
|
417
|
+
minWidth: column.columnDef.minSize,
|
|
418
|
+
maxWidth: column.columnDef.maxSize
|
|
419
|
+
});
|
|
420
|
+
const bodyCellClasses = allowWrap ? compact ? 'min-h-8 px-2 py-1' : 'min-h-12 px-4 py-2' : compact ? 'h-8 truncate px-2 py-0' : 'h-12 truncate px-4 py-0';
|
|
421
|
+
const skeletonRowCount = Math.min(Math.max(pagination.pageSize, 1), 5);
|
|
113
422
|
return /*#__PURE__*/ jsxs("div", {
|
|
114
423
|
"data-slot": "data-table",
|
|
115
|
-
className:
|
|
424
|
+
className: cn('w-full', className),
|
|
116
425
|
children: [
|
|
117
426
|
/*#__PURE__*/ jsxs("div", {
|
|
118
|
-
className: "flex items-center gap-4 py-4",
|
|
427
|
+
className: "flex flex-wrap items-center gap-x-4 gap-y-2 py-4",
|
|
119
428
|
children: [
|
|
120
|
-
|
|
121
|
-
placeholder: searchPlaceholder,
|
|
122
|
-
value: globalFilter,
|
|
123
|
-
onChange: (event)=>setGlobalFilter(event.target.value),
|
|
124
|
-
className: "max-w-sm"
|
|
125
|
-
}) : searchKey && /*#__PURE__*/ jsx(Input, {
|
|
429
|
+
showSearch && /*#__PURE__*/ jsx(Input, {
|
|
126
430
|
placeholder: searchPlaceholder,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
431
|
+
"aria-label": stringOverrides?.search ?? searchPlaceholder,
|
|
432
|
+
value: search,
|
|
433
|
+
onChange: (event)=>handleSearchChange(event.target.value),
|
|
434
|
+
className: "min-w-0 max-w-sm flex-1 basis-48"
|
|
130
435
|
}),
|
|
131
436
|
toolbarContent,
|
|
132
437
|
showColumnToggle && /*#__PURE__*/ jsxs(DropdownMenu, {
|
|
@@ -140,19 +445,23 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
140
445
|
columnToggleText,
|
|
141
446
|
" ",
|
|
142
447
|
/*#__PURE__*/ jsx(ChevronDown, {
|
|
143
|
-
className: "ml-2 h-4 w-4"
|
|
448
|
+
className: "ml-2 h-4 w-4",
|
|
449
|
+
"aria-hidden": "true"
|
|
144
450
|
})
|
|
145
451
|
]
|
|
146
452
|
})
|
|
147
453
|
}),
|
|
148
454
|
/*#__PURE__*/ jsx(DropdownMenuContent, {
|
|
149
455
|
align: "end",
|
|
150
|
-
children: table.getAllColumns().filter((column)=>column.getCanHide()).map((column)
|
|
151
|
-
|
|
456
|
+
children: table.getAllColumns().filter((column)=>column.getCanHide()).map((column)=>{
|
|
457
|
+
const label = getColumnLabel(column);
|
|
458
|
+
return /*#__PURE__*/ jsx(DropdownMenuCheckboxItem, {
|
|
459
|
+
className: label === column.id ? 'capitalize' : void 0,
|
|
152
460
|
checked: column.getIsVisible(),
|
|
153
461
|
onCheckedChange: (value)=>column.toggleVisibility(!!value),
|
|
154
|
-
children:
|
|
155
|
-
}, column.id)
|
|
462
|
+
children: label
|
|
463
|
+
}, column.id);
|
|
464
|
+
})
|
|
156
465
|
})
|
|
157
466
|
]
|
|
158
467
|
})
|
|
@@ -166,33 +475,40 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
166
475
|
width: table.getTotalSize(),
|
|
167
476
|
tableLayout: 'fixed'
|
|
168
477
|
} : void 0,
|
|
478
|
+
"aria-busy": loading || void 0,
|
|
169
479
|
children: [
|
|
170
480
|
/*#__PURE__*/ jsx(TableHeader, {
|
|
171
|
-
className: cn('sticky top-0 z-10 bg-background', useBlockLayout && `block ${blockRowClasses}`),
|
|
481
|
+
className: cn('sticky top-0 z-10 bg-background', useBlockLayout && `block overflow-hidden [scrollbar-gutter:stable] ${blockRowClasses}`),
|
|
172
482
|
children: table.getHeaderGroups().map((headerGroup)=>/*#__PURE__*/ jsx(TableRow, {
|
|
173
|
-
children: headerGroup.headers.map((header)=>{
|
|
483
|
+
children: headerGroup.headers.map((header, headerIndex)=>{
|
|
174
484
|
const { column } = header;
|
|
485
|
+
const sorted = column.getIsSorted();
|
|
486
|
+
const isLastHeader = headerIndex === headerGroup.headers.length - 1;
|
|
175
487
|
return /*#__PURE__*/ jsxs(TableHead, {
|
|
488
|
+
colSpan: header.colSpan > 1 ? header.colSpan : void 0,
|
|
489
|
+
"aria-sort": 'asc' === sorted ? 'ascending' : 'desc' === sorted ? 'descending' : void 0,
|
|
176
490
|
className: cn(compact ? 'relative h-8 px-2 py-0' : 'relative py-0', resizable && 'overflow-visible'),
|
|
177
491
|
style: {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
maxWidth: column.columnDef.maxSize
|
|
492
|
+
...cellSizeStyle(column),
|
|
493
|
+
width: resizable ? header.getSize() : column.columnDef.size
|
|
181
494
|
},
|
|
182
495
|
children: [
|
|
183
496
|
header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext()),
|
|
184
497
|
resizable && header.column.getCanResize() && /*#__PURE__*/ jsx("div", {
|
|
185
498
|
role: "separator",
|
|
186
|
-
"aria-
|
|
187
|
-
"aria-
|
|
188
|
-
"aria-
|
|
189
|
-
"aria-
|
|
499
|
+
"aria-orientation": "vertical",
|
|
500
|
+
"aria-label": strings.resizeColumn(getColumnLabel(column)),
|
|
501
|
+
"aria-valuenow": Math.round(header.getSize()),
|
|
502
|
+
"aria-valuemin": column.columnDef.minSize ?? RESIZE_FALLBACK_MIN,
|
|
503
|
+
"aria-valuemax": column.columnDef.maxSize ?? Math.max(1000, Math.round(header.getSize())),
|
|
190
504
|
tabIndex: 0,
|
|
191
505
|
onMouseDown: header.getResizeHandler(),
|
|
192
506
|
onTouchStart: header.getResizeHandler(),
|
|
193
|
-
|
|
507
|
+
onDoubleClick: ()=>column.resetSize(),
|
|
508
|
+
onKeyDown: (event)=>handleResizeKeyDown(event, header),
|
|
509
|
+
className: cn('group absolute top-0 z-10 h-full w-2 cursor-col-resize touch-none select-none outline-none', isLastHeader ? 'right-0' : '-right-1'),
|
|
194
510
|
children: /*#__PURE__*/ jsx("div", {
|
|
195
|
-
className: cn('h-full
|
|
511
|
+
className: cn('h-full transition-all duration-150', isLastHeader ? 'ml-auto' : 'mx-auto', header.column.getIsResizing() ? 'w-0.5 bg-primary' : 'w-px group-hover:w-0.5 group-hover:bg-primary group-focus-visible:w-0.5 group-focus-visible:bg-primary')
|
|
196
512
|
})
|
|
197
513
|
})
|
|
198
514
|
]
|
|
@@ -201,80 +517,133 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
201
517
|
}, headerGroup.id))
|
|
202
518
|
}),
|
|
203
519
|
/*#__PURE__*/ jsx(TableBody, {
|
|
204
|
-
className: useBlockLayout
|
|
520
|
+
className: cn(useBlockLayout && `block overflow-y-auto [scrollbar-gutter:stable] ${blockRowClasses}`, loading && rows.length > 0 && 'opacity-60 transition-opacity'),
|
|
205
521
|
style: useBlockLayout ? {
|
|
206
522
|
maxHeight: maxBodyHeight
|
|
207
523
|
} : void 0,
|
|
208
524
|
tabIndex: useBlockLayout ? 0 : void 0,
|
|
209
|
-
|
|
210
|
-
|
|
525
|
+
"aria-label": useBlockLayout ? strings.scrollRegion : void 0,
|
|
526
|
+
children: rows.length ? rows.map((row)=>/*#__PURE__*/ jsx(TableRow, {
|
|
527
|
+
"data-state": row.getIsSelected() ? 'selected' : void 0,
|
|
528
|
+
className: onRowClick ? 'cursor-pointer' : void 0,
|
|
529
|
+
tabIndex: onRowClick ? 0 : void 0,
|
|
530
|
+
onClick: onRowClick ? (event)=>{
|
|
531
|
+
const target = event.target;
|
|
532
|
+
if (target.closest(INTERACTIVE_SELECTOR)) return;
|
|
533
|
+
onRowClick(row.original);
|
|
534
|
+
} : void 0,
|
|
535
|
+
onKeyDown: onRowClick ? (event)=>{
|
|
536
|
+
if ('Enter' === event.key && event.target === event.currentTarget) {
|
|
537
|
+
event.preventDefault();
|
|
538
|
+
onRowClick(row.original);
|
|
539
|
+
}
|
|
540
|
+
} : void 0,
|
|
211
541
|
children: row.getVisibleCells().map((cell)=>{
|
|
212
542
|
const { column } = cell;
|
|
213
543
|
return /*#__PURE__*/ jsx(TableCell, {
|
|
214
|
-
className:
|
|
544
|
+
className: bodyCellClasses,
|
|
215
545
|
onMouseEnter: (e)=>{
|
|
216
546
|
if (allowWrap) return;
|
|
217
547
|
const el = e.currentTarget;
|
|
218
548
|
const value = cell.getValue();
|
|
219
549
|
el.title = el.scrollWidth > el.clientWidth && ('string' == typeof value || 'number' == typeof value) ? String(value) : '';
|
|
220
550
|
},
|
|
221
|
-
style:
|
|
222
|
-
width: resizable ? cell.column.getSize() : 150 !== column.getSize() ? column.getSize() : void 0,
|
|
223
|
-
minWidth: column.columnDef.minSize,
|
|
224
|
-
maxWidth: column.columnDef.maxSize
|
|
225
|
-
},
|
|
551
|
+
style: cellSizeStyle(column),
|
|
226
552
|
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
227
553
|
}, cell.id);
|
|
228
554
|
})
|
|
229
|
-
}, row.id)) :
|
|
555
|
+
}, row.id)) : loading ? Array.from({
|
|
556
|
+
length: skeletonRowCount
|
|
557
|
+
}, (_, rowIndex)=>/*#__PURE__*/ jsx(TableRow, {
|
|
558
|
+
"data-slot": "data-table-loading-row",
|
|
559
|
+
"aria-hidden": "true",
|
|
560
|
+
children: table.getVisibleLeafColumns().map((column)=>/*#__PURE__*/ jsx(TableCell, {
|
|
561
|
+
className: bodyCellClasses,
|
|
562
|
+
style: cellSizeStyle(column),
|
|
563
|
+
children: /*#__PURE__*/ jsx(Skeleton, {
|
|
564
|
+
className: "h-4 w-full max-w-40"
|
|
565
|
+
})
|
|
566
|
+
}, column.id))
|
|
567
|
+
}, rowIndex)) : /*#__PURE__*/ jsx(TableRow, {
|
|
230
568
|
children: /*#__PURE__*/ jsx(TableCell, {
|
|
231
|
-
colSpan:
|
|
569
|
+
colSpan: visibleColumnCount,
|
|
232
570
|
className: "h-24 text-center",
|
|
233
|
-
children:
|
|
571
|
+
children: emptyState ?? strings.noResults
|
|
234
572
|
})
|
|
235
573
|
})
|
|
236
574
|
})
|
|
237
575
|
]
|
|
238
576
|
})
|
|
239
577
|
}),
|
|
578
|
+
loading && /*#__PURE__*/ jsx("output", {
|
|
579
|
+
className: "sr-only",
|
|
580
|
+
children: strings.loading
|
|
581
|
+
}),
|
|
240
582
|
showPagination && /*#__PURE__*/ jsxs("div", {
|
|
241
|
-
className: "flex items-center justify-between
|
|
583
|
+
className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2 py-4",
|
|
242
584
|
children: [
|
|
243
|
-
/*#__PURE__*/
|
|
585
|
+
/*#__PURE__*/ jsx("div", {
|
|
244
586
|
className: "flex-1 text-sm text-muted-foreground",
|
|
245
|
-
children:
|
|
246
|
-
table.getFilteredSelectedRowModel().rows.length,
|
|
247
|
-
" of",
|
|
248
|
-
' ',
|
|
249
|
-
table.getFilteredRowModel().rows.length,
|
|
250
|
-
" row(s) selected."
|
|
251
|
-
]
|
|
587
|
+
children: selectionCountVisible && strings.rowsSelected(table.getFilteredSelectedRowModel().rows.length, table.getFilteredRowModel().rows.length)
|
|
252
588
|
}),
|
|
253
589
|
/*#__PURE__*/ jsxs("div", {
|
|
254
|
-
className: "flex items-center
|
|
590
|
+
className: "flex flex-wrap items-center gap-x-4 gap-y-2",
|
|
255
591
|
children: [
|
|
256
|
-
/*#__PURE__*/
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
592
|
+
pageSizeOptions && pageSizeOptions.length > 0 && /*#__PURE__*/ jsxs("div", {
|
|
593
|
+
className: "flex items-center gap-2",
|
|
594
|
+
children: [
|
|
595
|
+
/*#__PURE__*/ jsx("span", {
|
|
596
|
+
className: "text-sm text-muted-foreground",
|
|
597
|
+
children: strings.rowsPerPage
|
|
598
|
+
}),
|
|
599
|
+
/*#__PURE__*/ jsxs(Select, {
|
|
600
|
+
value: String(pagination.pageSize),
|
|
601
|
+
onValueChange: (value)=>onPaginationChange({
|
|
602
|
+
pageIndex: 0,
|
|
603
|
+
pageSize: Number(value)
|
|
604
|
+
}),
|
|
605
|
+
children: [
|
|
606
|
+
/*#__PURE__*/ jsx(SelectTrigger, {
|
|
607
|
+
className: "h-8 w-auto min-w-[4.5rem] gap-2",
|
|
608
|
+
"aria-label": strings.rowsPerPage,
|
|
609
|
+
children: /*#__PURE__*/ jsx(SelectValue, {})
|
|
610
|
+
}),
|
|
611
|
+
/*#__PURE__*/ jsx(SelectContent, {
|
|
612
|
+
align: "end",
|
|
613
|
+
children: Array.from(new Set([
|
|
614
|
+
...pageSizeOptions,
|
|
615
|
+
pagination.pageSize
|
|
616
|
+
])).sort((a, b)=>a - b).map((option)=>/*#__PURE__*/ jsx(SelectItem, {
|
|
617
|
+
value: String(option),
|
|
618
|
+
children: option
|
|
619
|
+
}, option))
|
|
620
|
+
})
|
|
621
|
+
]
|
|
622
|
+
})
|
|
623
|
+
]
|
|
262
624
|
}),
|
|
263
625
|
/*#__PURE__*/ jsxs("div", {
|
|
264
|
-
className: "
|
|
626
|
+
className: "flex items-center space-x-2",
|
|
265
627
|
children: [
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
628
|
+
/*#__PURE__*/ jsx(Button, {
|
|
629
|
+
variant: "outline",
|
|
630
|
+
size: "sm",
|
|
631
|
+
onClick: ()=>table.previousPage(),
|
|
632
|
+
disabled: currentPageIndex <= 0,
|
|
633
|
+
children: strings.previous
|
|
634
|
+
}),
|
|
635
|
+
/*#__PURE__*/ jsx("div", {
|
|
636
|
+
className: "text-sm font-medium",
|
|
637
|
+
children: strings.page(currentPageIndex + 1, pageCount)
|
|
638
|
+
}),
|
|
639
|
+
/*#__PURE__*/ jsx(Button, {
|
|
640
|
+
variant: "outline",
|
|
641
|
+
size: "sm",
|
|
642
|
+
onClick: ()=>table.nextPage(),
|
|
643
|
+
disabled: currentPageIndex >= lastPageIndex,
|
|
644
|
+
children: strings.next
|
|
645
|
+
})
|
|
270
646
|
]
|
|
271
|
-
}),
|
|
272
|
-
/*#__PURE__*/ jsx(Button, {
|
|
273
|
-
variant: "outline",
|
|
274
|
-
size: "sm",
|
|
275
|
-
onClick: ()=>table.nextPage(),
|
|
276
|
-
disabled: !table.getCanNextPage(),
|
|
277
|
-
children: "Next"
|
|
278
647
|
})
|
|
279
648
|
]
|
|
280
649
|
})
|
|
@@ -285,10 +654,22 @@ function DataTable({ columns, data, searchKey, searchPlaceholder = 'Search...',
|
|
|
285
654
|
}
|
|
286
655
|
function DataTableColumnHeader({ column, title, children }) {
|
|
287
656
|
const sorted = column.getIsSorted();
|
|
288
|
-
|
|
289
|
-
|
|
657
|
+
if (column.getCanSort?.() === false) return /*#__PURE__*/ jsxs("span", {
|
|
658
|
+
"data-slot": "data-table-column-header",
|
|
659
|
+
className: "flex h-8 max-w-full items-center text-sm font-medium",
|
|
660
|
+
children: [
|
|
661
|
+
/*#__PURE__*/ jsx("span", {
|
|
662
|
+
className: "truncate min-w-0",
|
|
663
|
+
children: title
|
|
664
|
+
}),
|
|
665
|
+
children
|
|
666
|
+
]
|
|
667
|
+
});
|
|
668
|
+
const handleClick = (event)=>{
|
|
669
|
+
const multi = event.shiftKey && (column.getCanMultiSort?.() ?? false);
|
|
670
|
+
if ('asc' === sorted) column.toggleSorting(true, multi);
|
|
290
671
|
else if ('desc' === sorted) column.clearSorting();
|
|
291
|
-
else column.toggleSorting(false);
|
|
672
|
+
else column.toggleSorting(false, multi);
|
|
292
673
|
};
|
|
293
674
|
return /*#__PURE__*/ jsxs(Button, {
|
|
294
675
|
"data-slot": "data-table-column-header",
|
|
@@ -307,11 +688,14 @@ function DataTableColumnHeader({ column, title, children }) {
|
|
|
307
688
|
}),
|
|
308
689
|
children,
|
|
309
690
|
'asc' === sorted ? /*#__PURE__*/ jsx(ArrowUp, {
|
|
310
|
-
className: "ml-2 h-4 w-4"
|
|
691
|
+
className: "ml-2 h-4 w-4",
|
|
692
|
+
"aria-hidden": "true"
|
|
311
693
|
}) : 'desc' === sorted ? /*#__PURE__*/ jsx(ArrowDown, {
|
|
312
|
-
className: "ml-2 h-4 w-4"
|
|
694
|
+
className: "ml-2 h-4 w-4",
|
|
695
|
+
"aria-hidden": "true"
|
|
313
696
|
}) : /*#__PURE__*/ jsx(ArrowUpDown, {
|
|
314
|
-
className: "ml-2 h-4 w-4"
|
|
697
|
+
className: "ml-2 h-4 w-4",
|
|
698
|
+
"aria-hidden": "true"
|
|
315
699
|
})
|
|
316
700
|
]
|
|
317
701
|
});
|
|
@@ -322,15 +706,17 @@ function DataTableSelectColumn() {
|
|
|
322
706
|
header: ({ table })=>/*#__PURE__*/ jsx(Checkbox, {
|
|
323
707
|
checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && 'indeterminate',
|
|
324
708
|
onCheckedChange: (value)=>table.toggleAllPageRowsSelected(!!value),
|
|
325
|
-
"aria-label":
|
|
709
|
+
"aria-label": (getInternalMeta(table)?.strings ?? DEFAULT_DATA_TABLE_STRINGS).selectAll
|
|
326
710
|
}),
|
|
327
|
-
cell: ({ row })=>/*#__PURE__*/ jsx(Checkbox, {
|
|
711
|
+
cell: ({ row, table })=>/*#__PURE__*/ jsx(Checkbox, {
|
|
328
712
|
checked: row.getIsSelected(),
|
|
329
713
|
onCheckedChange: (value)=>row.toggleSelected(!!value),
|
|
330
|
-
"aria-label":
|
|
714
|
+
"aria-label": (getInternalMeta(table)?.strings ?? DEFAULT_DATA_TABLE_STRINGS).selectRow(row.index + 1)
|
|
331
715
|
}),
|
|
716
|
+
size: 48,
|
|
332
717
|
enableSorting: false,
|
|
333
|
-
enableHiding: false
|
|
718
|
+
enableHiding: false,
|
|
719
|
+
enableResizing: false
|
|
334
720
|
};
|
|
335
721
|
}
|
|
336
|
-
export { DataTable, DataTableColumnHeader, DataTableSelectColumn };
|
|
722
|
+
export { DEFAULT_DATA_TABLE_STRINGS, DataTable, DataTableColumnHeader, DataTableSelectColumn };
|