material-react-table 0.33.3 → 0.33.6

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.
@@ -0,0 +1,2302 @@
1
+ import React, { useMemo, useState, useCallback, Fragment, useEffect, useRef, useLayoutEffect } from 'react';
2
+ import { aggregationFns, filterFns, sortingFns, useReactTable, getCoreRowModel, getExpandedRowModel, getFacetedRowModel, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel } from '@tanstack/react-table';
3
+ import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityLarge, DensityMedium, DensitySmall, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, KeyboardDoubleArrowDown, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
4
+ import { rankItem, rankings, compareItems } from '@tanstack/match-sorter-utils';
5
+ import { Tooltip, IconButton, Menu, MenuItem, Box, FormControlLabel, Switch, Typography, Button, Divider, ListItemIcon, Checkbox, debounce, Collapse, TextField, InputAdornment, LinearProgress, TablePagination, Chip, Alert, AlertTitle, Fade, alpha, useMediaQuery, Toolbar, lighten, ListItemText, Grow, TableSortLabel, useTheme, TableCell, TableRow, TableHead, darken, Skeleton, TableBody, TableFooter, Table, TableContainer, Paper, Dialog } from '@mui/material';
6
+ import { useVirtualizer } from '@tanstack/react-virtual';
7
+
8
+ /******************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** */
22
+
23
+ function __rest(s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
+ t[p] = s[p];
27
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
+ t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ }
34
+
35
+ const MRT_AggregationFns = Object.assign({}, aggregationFns);
36
+
37
+ const MRT_Default_Icons = {
38
+ ArrowRightIcon: ArrowRight,
39
+ CancelIcon: Cancel,
40
+ CheckBoxIcon: CheckBox,
41
+ ClearAllIcon: ClearAll,
42
+ CloseIcon: Close,
43
+ DensityLargeIcon: DensityLarge,
44
+ DensityMediumIcon: DensityMedium,
45
+ DensitySmallIcon: DensitySmall,
46
+ DragHandleIcon: DragHandle,
47
+ DynamicFeedIcon: DynamicFeed,
48
+ EditIcon: Edit,
49
+ ExpandLessIcon: ExpandLess,
50
+ ExpandMoreIcon: ExpandMore,
51
+ FilterAltIcon: FilterAlt,
52
+ FilterAltOffIcon: FilterAltOff,
53
+ FilterListIcon: FilterList,
54
+ FilterListOffIcon: FilterListOff,
55
+ FullscreenExitIcon: FullscreenExit,
56
+ FullscreenIcon: Fullscreen,
57
+ KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
58
+ MoreHorizIcon: MoreHoriz,
59
+ MoreVertIcon: MoreVert,
60
+ PushPinIcon: PushPin,
61
+ RestartAltIcon: RestartAlt,
62
+ SaveIcon: Save,
63
+ SearchIcon: Search,
64
+ SearchOffIcon: SearchOff,
65
+ SortIcon: Sort,
66
+ ViewColumnIcon: ViewColumn,
67
+ VisibilityOffIcon: VisibilityOff,
68
+ };
69
+
70
+ const fuzzy$1 = (row, columnId, filterValue, addMeta) => {
71
+ const itemRank = rankItem(row.getValue(columnId), filterValue, {
72
+ threshold: rankings.MATCHES,
73
+ });
74
+ addMeta(itemRank);
75
+ return itemRank.passed;
76
+ };
77
+ fuzzy$1.autoRemove = (val) => !val;
78
+ const contains = (row, id, filterValue) => row
79
+ .getValue(id)
80
+ .toString()
81
+ .toLowerCase()
82
+ .trim()
83
+ .includes(filterValue.toString().toLowerCase().trim());
84
+ contains.autoRemove = (val) => !val;
85
+ const startsWith = (row, id, filterValue) => row
86
+ .getValue(id)
87
+ .toString()
88
+ .toLowerCase()
89
+ .trim()
90
+ .startsWith(filterValue.toString().toLowerCase().trim());
91
+ startsWith.autoRemove = (val) => !val;
92
+ const endsWith = (row, id, filterValue) => row
93
+ .getValue(id)
94
+ .toString()
95
+ .toLowerCase()
96
+ .trim()
97
+ .endsWith(filterValue.toString().toLowerCase().trim());
98
+ endsWith.autoRemove = (val) => !val;
99
+ const equals = (row, id, filterValue) => row.getValue(id).toString().toLowerCase().trim() ===
100
+ filterValue.toString().toLowerCase().trim();
101
+ equals.autoRemove = (val) => !val;
102
+ const notEquals = (row, id, filterValue) => row.getValue(id).toString().toLowerCase().trim() !==
103
+ filterValue.toString().toLowerCase().trim();
104
+ notEquals.autoRemove = (val) => !val;
105
+ const greaterThan = (row, id, filterValue) => !isNaN(+filterValue) && !isNaN(+row.getValue(id))
106
+ ? +row.getValue(id) > +filterValue
107
+ : row.getValue(id).toString().toLowerCase().trim() >
108
+ filterValue.toString().toLowerCase().trim();
109
+ greaterThan.autoRemove = (val) => !val;
110
+ const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
111
+ greaterThanOrEqualTo.autoRemove = (val) => !val;
112
+ const lessThan = (row, id, filterValue) => !isNaN(+filterValue) && !isNaN(+row.getValue(id))
113
+ ? +row.getValue(id) < +filterValue
114
+ : row.getValue(id).toString().toLowerCase().trim() <
115
+ filterValue.toString().toLowerCase().trim();
116
+ lessThan.autoRemove = (val) => !val;
117
+ const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
118
+ lessThanOrEqualTo.autoRemove = (val) => !val;
119
+ const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
120
+ greaterThan(row, id, filterValues[0])) &&
121
+ ((!isNaN(+filterValues[0]) &&
122
+ !isNaN(+filterValues[1]) &&
123
+ +filterValues[0] > +filterValues[1]) ||
124
+ ['', undefined].includes(filterValues[1]) ||
125
+ lessThan(row, id, filterValues[1]));
126
+ between.autoRemove = (val) => !val;
127
+ const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
128
+ greaterThanOrEqualTo(row, id, filterValues[0])) &&
129
+ ((!isNaN(+filterValues[0]) &&
130
+ !isNaN(+filterValues[1]) &&
131
+ +filterValues[0] > +filterValues[1]) ||
132
+ ['', undefined].includes(filterValues[1]) ||
133
+ lessThanOrEqualTo(row, id, filterValues[1]));
134
+ betweenInclusive.autoRemove = (val) => !val;
135
+ const empty = (row, id, _filterValue) => !row.getValue(id).toString().trim();
136
+ empty.autoRemove = (val) => !val;
137
+ const notEmpty = (row, id, _filterValue) => !!row.getValue(id).toString().trim();
138
+ notEmpty.autoRemove = (val) => !val;
139
+ const MRT_FilterFns = Object.assign(Object.assign({}, filterFns), { between,
140
+ betweenInclusive,
141
+ contains,
142
+ empty,
143
+ endsWith,
144
+ equals,
145
+ fuzzy: fuzzy$1,
146
+ greaterThan,
147
+ greaterThanOrEqualTo,
148
+ lessThan,
149
+ lessThanOrEqualTo,
150
+ notEmpty,
151
+ notEquals,
152
+ startsWith });
153
+
154
+ const MRT_DefaultLocalization_EN = {
155
+ actions: 'Actions',
156
+ and: 'and',
157
+ cancel: 'Cancel',
158
+ changeFilterMode: 'Change filter mode',
159
+ changeSearchMode: 'Change search mode',
160
+ clearFilter: 'Clear filter',
161
+ clearSearch: 'Clear search',
162
+ clearSort: 'Clear sort',
163
+ clickToCopy: 'Click to copy',
164
+ columnActions: 'Column Actions',
165
+ copiedToClipboard: 'Copied to clipboard',
166
+ dropToGroupBy: 'Drop to group by {column}',
167
+ edit: 'Edit',
168
+ expand: 'Expand',
169
+ expandAll: 'Expand all',
170
+ filterArrIncludes: 'Includes',
171
+ filterArrIncludesAll: 'Includes all',
172
+ filterArrIncludesSome: 'Includes',
173
+ filterBetween: 'Between',
174
+ filterBetweenInclusive: 'Between Inclusive',
175
+ filterByColumn: 'Filter by {column}',
176
+ filterContains: 'Contains',
177
+ filterEmpty: 'Empty',
178
+ filterEndsWith: 'Ends With',
179
+ filterEquals: 'Equals',
180
+ filterEqualsString: 'Equals',
181
+ filterFuzzy: 'Fuzzy',
182
+ filterGreaterThan: 'Greater Than',
183
+ filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
184
+ filterInNumberRange: 'Between',
185
+ filterIncludesString: 'Contains',
186
+ filterIncludesStringSensitive: 'Contains',
187
+ filterLessThan: 'Less Than',
188
+ filterLessThanOrEqualTo: 'Less Than Or Equal To',
189
+ filterMode: 'Filter Mode: {filterType}',
190
+ filterNotEmpty: 'Not Empty',
191
+ filterNotEquals: 'Not Equals',
192
+ filterStartsWith: 'Starts With',
193
+ filterWeakEquals: 'Equals',
194
+ filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
195
+ grab: 'Grab',
196
+ groupByColumn: 'Group by {column}',
197
+ groupedBy: 'Grouped by ',
198
+ hideAll: 'Hide all',
199
+ hideColumn: 'Hide {column} column',
200
+ max: 'Max',
201
+ min: 'Min',
202
+ move: 'Move',
203
+ or: 'or',
204
+ pinToLeft: 'Pin to left',
205
+ pinToRight: 'Pin to right',
206
+ resetColumnSize: 'Reset column size',
207
+ resetOrder: 'Reset order',
208
+ rowActions: 'Row Actions',
209
+ rowNumber: '#',
210
+ rowNumbers: 'Row Numbers',
211
+ save: 'Save',
212
+ search: 'Search',
213
+ selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
214
+ select: 'Select',
215
+ showAll: 'Show all',
216
+ showAllColumns: 'Show all columns',
217
+ showHideColumns: 'Show/Hide columns',
218
+ showHideFilters: 'Show/Hide filters',
219
+ showHideSearch: 'Show/Hide search',
220
+ sortByColumnAsc: 'Sort by {column} ascending',
221
+ sortByColumnDesc: 'Sort by {column} descending',
222
+ sortedByColumnAsc: 'Sorted by {column} ascending',
223
+ sortedByColumnDesc: 'Sorted by {column} descending',
224
+ thenBy: ', then by ',
225
+ toggleDensity: 'Toggle density',
226
+ toggleFullScreen: 'Toggle full screen',
227
+ toggleSelectAll: 'Toggle select all',
228
+ toggleSelectRow: 'Toggle select row',
229
+ toggleVisibility: 'Toggle visibility',
230
+ ungroupByColumn: 'Ungroup by {column}',
231
+ unpin: 'Unpin',
232
+ unpinAll: 'Unpin all',
233
+ unsorted: 'Unsorted',
234
+ };
235
+
236
+ const fuzzy = (rowA, rowB, columnId) => {
237
+ let dir = 0;
238
+ if (rowA.columnFiltersMeta[columnId]) {
239
+ dir = compareItems(rowA.columnFiltersMeta[columnId], rowB.columnFiltersMeta[columnId]);
240
+ }
241
+ // Provide a fallback for when the item ranks are equal
242
+ return dir === 0
243
+ ? sortingFns.alphanumeric(rowA, rowB, columnId)
244
+ : dir;
245
+ };
246
+ const MRT_SortingFns = Object.assign(Object.assign({}, sortingFns), { fuzzy });
247
+ const rankGlobalFuzzy = (rowA, rowB) => Math.max(...Object.values(rowB.columnFiltersMeta).map((v) => v.rank)) -
248
+ Math.max(...Object.values(rowA.columnFiltersMeta).map((v) => v.rank));
249
+
250
+ const MRT_ExpandAllButton = ({ table }) => {
251
+ const { getIsAllRowsExpanded, getIsSomeRowsExpanded, getCanSomeRowsExpand, getState, options: { icons: { KeyboardDoubleArrowDownIcon }, localization, muiExpandAllButtonProps, renderDetailPanel, }, toggleAllRowsExpanded, } = table;
252
+ const { density } = getState();
253
+ const iconButtonProps = muiExpandAllButtonProps instanceof Function
254
+ ? muiExpandAllButtonProps({ table })
255
+ : muiExpandAllButtonProps;
256
+ return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.expandAll },
257
+ React.createElement("span", null,
258
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.expandAll, disabled: !getCanSomeRowsExpand() && !renderDetailPanel, onClick: () => toggleAllRowsExpanded(!getIsAllRowsExpanded()) }, iconButtonProps, { sx: Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', width: density === 'compact' ? '1.75rem' : '2.25rem', mt: density !== 'compact' ? '-0.25rem' : undefined }, iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) }),
259
+ React.createElement(KeyboardDoubleArrowDownIcon, { style: {
260
+ transform: `rotate(${getIsAllRowsExpanded()
261
+ ? -180
262
+ : getIsSomeRowsExpanded()
263
+ ? -90
264
+ : 0}deg)`,
265
+ transition: 'transform 0.2s',
266
+ } })))));
267
+ };
268
+
269
+ const MRT_ExpandButton = ({ row, table }) => {
270
+ const { getState, options: { icons: { ExpandMoreIcon }, localization, muiExpandButtonProps, renderDetailPanel, }, } = table;
271
+ const { density } = getState();
272
+ const iconButtonProps = muiExpandButtonProps instanceof Function
273
+ ? muiExpandButtonProps({ table, row })
274
+ : muiExpandButtonProps;
275
+ const handleToggleExpand = () => {
276
+ row.toggleExpanded();
277
+ };
278
+ return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.expand },
279
+ React.createElement("span", null,
280
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.expand, disabled: !row.getCanExpand() && !renderDetailPanel, onClick: handleToggleExpand }, iconButtonProps, { sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.25rem', width: density === 'compact' ? '1.75rem' : '2.25rem' }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
281
+ ? iconButtonProps.sx(theme)
282
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))) }),
283
+ React.createElement(ExpandMoreIcon, { style: {
284
+ transform: `rotate(${!row.getCanExpand() && !renderDetailPanel
285
+ ? -90
286
+ : row.getIsExpanded()
287
+ ? -180
288
+ : 0}deg)`,
289
+ transition: 'transform 0.2s',
290
+ } })))));
291
+ };
292
+
293
+ const internalFilterOptions = (localization) => [
294
+ {
295
+ option: 'fuzzy',
296
+ symbol: '≈',
297
+ label: localization.filterFuzzy,
298
+ divider: false,
299
+ },
300
+ {
301
+ option: 'contains',
302
+ symbol: '*',
303
+ label: localization.filterContains,
304
+ divider: false,
305
+ },
306
+ {
307
+ option: 'startsWith',
308
+ symbol: 'a',
309
+ label: localization.filterStartsWith,
310
+ divider: false,
311
+ },
312
+ {
313
+ option: 'endsWith',
314
+ symbol: 'z',
315
+ label: localization.filterEndsWith,
316
+ divider: true,
317
+ },
318
+ {
319
+ option: 'equals',
320
+ symbol: '=',
321
+ label: localization.filterEquals,
322
+ divider: false,
323
+ },
324
+ {
325
+ option: 'notEquals',
326
+ symbol: '≠',
327
+ label: localization.filterNotEquals,
328
+ divider: true,
329
+ },
330
+ {
331
+ option: 'between',
332
+ symbol: '⇿',
333
+ label: localization.filterBetween,
334
+ divider: false,
335
+ },
336
+ {
337
+ option: 'betweenInclusive',
338
+ symbol: '⬌',
339
+ label: localization.filterBetweenInclusive,
340
+ divider: true,
341
+ },
342
+ {
343
+ option: 'greaterThan',
344
+ symbol: '>',
345
+ label: localization.filterGreaterThan,
346
+ divider: false,
347
+ },
348
+ {
349
+ option: 'greaterThanOrEqualTo',
350
+ symbol: '≥',
351
+ label: localization.filterGreaterThanOrEqualTo,
352
+ divider: false,
353
+ },
354
+ {
355
+ option: 'lessThan',
356
+ symbol: '<',
357
+ label: localization.filterLessThan,
358
+ divider: false,
359
+ },
360
+ {
361
+ option: 'lessThanOrEqualTo',
362
+ symbol: '≤',
363
+ label: localization.filterLessThanOrEqualTo,
364
+ divider: true,
365
+ },
366
+ {
367
+ option: 'empty',
368
+ symbol: '∅',
369
+ label: localization.filterEmpty,
370
+ divider: false,
371
+ },
372
+ {
373
+ option: 'notEmpty',
374
+ symbol: '!∅',
375
+ label: localization.filterNotEmpty,
376
+ divider: false,
377
+ },
378
+ ];
379
+ const MRT_FilterOptionMenu = ({ anchorEl, header, onSelect, setAnchorEl, table, }) => {
380
+ var _a;
381
+ const { getState, options: { enabledGlobalFilterOptions, columnFilterModeOptions, localization, }, setColumnFilterFns, setGlobalFilterFn, } = table;
382
+ const { columnFilterFns, globalFilterFn, density } = getState();
383
+ const { column } = header !== null && header !== void 0 ? header : {};
384
+ const { columnDef } = column !== null && column !== void 0 ? column : {};
385
+ const allowedColumnFilterOptions = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.columnFilterModeOptions) !== null && _a !== void 0 ? _a : columnFilterModeOptions;
386
+ const filterOptions = useMemo(() => internalFilterOptions(localization).filter((filterOption) => columnDef
387
+ ? allowedColumnFilterOptions === undefined ||
388
+ (allowedColumnFilterOptions === null || allowedColumnFilterOptions === void 0 ? void 0 : allowedColumnFilterOptions.includes(filterOption.option))
389
+ : (!enabledGlobalFilterOptions ||
390
+ enabledGlobalFilterOptions.includes(filterOption.option)) &&
391
+ ['fuzzy', 'contains'].includes(filterOption.option)), []);
392
+ const handleSelectFilterType = (option) => {
393
+ if (header && column) {
394
+ setColumnFilterFns((prev) => (Object.assign(Object.assign({}, prev), { [header.id]: option })));
395
+ if (['empty', 'notEmpty'].includes(option)) {
396
+ column.setFilterValue(' ');
397
+ }
398
+ else if (option === 'between') {
399
+ column.setFilterValue(['', '']);
400
+ }
401
+ else {
402
+ column.setFilterValue('');
403
+ }
404
+ }
405
+ else {
406
+ setGlobalFilterFn(option);
407
+ }
408
+ setAnchorEl(null);
409
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect();
410
+ };
411
+ const filterOption = !!header ? columnFilterFns[header.id] : globalFilterFn;
412
+ return (React.createElement(Menu, { anchorEl: anchorEl, anchorOrigin: { vertical: 'center', horizontal: 'right' }, onClose: () => setAnchorEl(null), open: !!anchorEl, MenuListProps: {
413
+ dense: density === 'compact',
414
+ } }, filterOptions.map(({ option, label, divider, symbol }, index) => (React.createElement(MenuItem, { divider: divider, key: index, onClick: () => handleSelectFilterType(option), selected: option === filterOption, sx: {
415
+ py: '6px',
416
+ my: 0,
417
+ alignItems: 'center',
418
+ display: 'flex',
419
+ gap: '2ch',
420
+ }, value: option },
421
+ React.createElement(Box, { sx: { fontSize: '1.25rem', width: '2ch' } }, symbol),
422
+ label)))));
423
+ };
424
+
425
+ const MRT_ColumnPinningButtons = ({ column, table }) => {
426
+ const { options: { icons: { PushPinIcon }, localization, }, } = table;
427
+ const handlePinColumn = (pinDirection) => {
428
+ column.pin(pinDirection);
429
+ };
430
+ return (React.createElement(Box, { sx: { minWidth: '70px', textAlign: 'center' } }, column.getIsPinned() ? (React.createElement(Tooltip, { arrow: true, title: localization.unpin },
431
+ React.createElement(IconButton, { onClick: () => handlePinColumn(false), size: "small" },
432
+ React.createElement(PushPinIcon, null)))) : (React.createElement(React.Fragment, null,
433
+ React.createElement(Tooltip, { arrow: true, title: localization.pinToLeft },
434
+ React.createElement(IconButton, { onClick: () => handlePinColumn('left'), size: "small" },
435
+ React.createElement(PushPinIcon, { style: {
436
+ transform: 'rotate(90deg)',
437
+ } }))),
438
+ React.createElement(Tooltip, { arrow: true, title: localization.pinToRight },
439
+ React.createElement(IconButton, { onClick: () => handlePinColumn('right'), size: "small" },
440
+ React.createElement(PushPinIcon, { style: {
441
+ transform: 'rotate(-90deg)',
442
+ } })))))));
443
+ };
444
+
445
+ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table, }) => {
446
+ const { options: { icons: { DragHandleIcon }, localization, }, } = table;
447
+ return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: localization.move },
448
+ React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { sx: Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
449
+ backgroundColor: 'transparent',
450
+ opacity: 1,
451
+ }, '&:active': {
452
+ cursor: 'grabbing',
453
+ } }, iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) }),
454
+ React.createElement(DragHandleIcon, null))));
455
+ };
456
+
457
+ const defaultDisplayColumnDefOptions = {
458
+ columnDefType: 'display',
459
+ enableClickToCopy: false,
460
+ enableColumnActions: false,
461
+ enableColumnDragging: false,
462
+ enableColumnFilter: false,
463
+ enableColumnOrdering: false,
464
+ enableEditing: false,
465
+ enableGlobalFilter: false,
466
+ enableGrouping: false,
467
+ enableHiding: false,
468
+ enableResizing: false,
469
+ enableSorting: false,
470
+ };
471
+ const getColumnId = (columnDef) => { var _a, _b, _c, _d; return (_d = (_a = columnDef.id) !== null && _a !== void 0 ? _a : (_c = (_b = columnDef.accessorKey) === null || _b === void 0 ? void 0 : _b.toString) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : columnDef.header; };
472
+ const getAllLeafColumnDefs = (columns) => {
473
+ let lowestLevelColumns = columns;
474
+ let currentCols = columns;
475
+ while (!!(currentCols === null || currentCols === void 0 ? void 0 : currentCols.length) && currentCols.some((col) => col.columns)) {
476
+ const nextCols = currentCols
477
+ .filter((col) => !!col.columns)
478
+ .map((col) => col.columns)
479
+ .flat();
480
+ if (nextCols.every((col) => !(col === null || col === void 0 ? void 0 : col.columns))) {
481
+ lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
482
+ }
483
+ currentCols = nextCols;
484
+ }
485
+ return lowestLevelColumns.filter((col) => !col.columns);
486
+ };
487
+ const prepareColumns = (columnDefs, columnFilterFns, filterFns, sortingFns) => columnDefs.map((columnDef) => {
488
+ var _a, _b;
489
+ if (!columnDef.id)
490
+ columnDef.id = getColumnId(columnDef);
491
+ if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
492
+ console.error('Column definitions must have a valid `accessorKey` or `id` property');
493
+ }
494
+ if (!columnDef.columnDefType)
495
+ columnDef.columnDefType = 'data';
496
+ if (!!((_a = columnDef.columns) === null || _a === void 0 ? void 0 : _a.length)) {
497
+ columnDef.columnDefType = 'group';
498
+ columnDef.columns = prepareColumns(columnDef.columns, columnFilterFns, filterFns, sortingFns);
499
+ }
500
+ else if (columnDef.columnDefType === 'data') {
501
+ if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
502
+ columnDef.filterFn =
503
+ // @ts-ignore
504
+ (_b = filterFns[columnFilterFns[columnDef.id]]) !== null && _b !== void 0 ? _b : filterFns.fuzzy;
505
+ //@ts-ignore
506
+ columnDef._filterFn = columnFilterFns[columnDef.id];
507
+ }
508
+ if (Object.keys(sortingFns).includes(columnDef.sortingFn)) {
509
+ // @ts-ignore
510
+ columnDef.sortingFn = sortingFns[columnDef.sortingFn];
511
+ }
512
+ }
513
+ else if (columnDef.columnDefType === 'display') {
514
+ columnDef = Object.assign(Object.assign({}, defaultDisplayColumnDefOptions), columnDef);
515
+ }
516
+ return columnDef;
517
+ });
518
+ const reorderColumn = (draggedColumn, targetColumn, columnOrder) => {
519
+ if (draggedColumn.getCanPin()) {
520
+ draggedColumn.pin(targetColumn.getIsPinned());
521
+ }
522
+ columnOrder.splice(columnOrder.indexOf(targetColumn.id), 0, columnOrder.splice(columnOrder.indexOf(draggedColumn.id), 1)[0]);
523
+ return [...columnOrder];
524
+ };
525
+ const getLeadingDisplayColumnIds = (props) => [
526
+ (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
527
+ ((props.positionActionsColumn === 'first' && props.enableRowActions) ||
528
+ (props.enableEditing && props.editingMode === 'row')) &&
529
+ 'mrt-row-actions',
530
+ props.positionExpandColumn === 'first' &&
531
+ (props.enableExpanding ||
532
+ props.enableGrouping ||
533
+ props.renderDetailPanel) &&
534
+ 'mrt-row-expand',
535
+ props.enableRowSelection && 'mrt-row-select',
536
+ props.enableRowNumbers && 'mrt-row-numbers',
537
+ ].filter(Boolean);
538
+ const getTrailingDisplayColumnIds = (props) => [
539
+ ((props.positionActionsColumn === 'last' && props.enableRowActions) ||
540
+ (props.enableEditing && props.editingMode === 'row')) &&
541
+ 'mrt-row-actions',
542
+ props.positionExpandColumn === 'last' &&
543
+ (props.enableExpanding ||
544
+ props.enableGrouping ||
545
+ props.renderDetailPanel) &&
546
+ 'mrt-row-expand',
547
+ ];
548
+ const getDefaultColumnOrderIds = (props) => [
549
+ ...getLeadingDisplayColumnIds(props),
550
+ ...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
551
+ ...getTrailingDisplayColumnIds(props),
552
+ ].filter(Boolean);
553
+ const getDefaultColumnFilterFn = (columnDef) => {
554
+ if (columnDef.filterVariant === 'multi-select')
555
+ return 'arrIncludesSome';
556
+ if (columnDef.filterVariant === 'select')
557
+ return 'equals';
558
+ if (columnDef.filterVariant === 'range')
559
+ return 'betweenInclusive';
560
+ return 'fuzzy';
561
+ };
562
+
563
+ const MRT_ShowHideColumnsMenuItems = ({ allColumns, currentHoveredColumn, setCurrentHoveredColumn, column, isSubMenu, table, }) => {
564
+ var _a;
565
+ const { getState, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, setColumnOrder, } = table;
566
+ const { columnOrder } = getState();
567
+ const { columnDef } = column;
568
+ const { columnDefType } = columnDef;
569
+ const switchChecked = (columnDefType !== 'group' && column.getIsVisible()) ||
570
+ (columnDefType === 'group' &&
571
+ column.getLeafColumns().some((col) => col.getIsVisible()));
572
+ const handleToggleColumnHidden = (column) => {
573
+ var _a, _b;
574
+ if (columnDefType === 'group') {
575
+ (_b = (_a = column === null || column === void 0 ? void 0 : column.columns) === null || _a === void 0 ? void 0 : _a.forEach) === null || _b === void 0 ? void 0 : _b.call(_a, (childColumn) => {
576
+ childColumn.toggleVisibility(!switchChecked);
577
+ });
578
+ }
579
+ else {
580
+ column.toggleVisibility();
581
+ }
582
+ };
583
+ const menuItemRef = React.useRef(null);
584
+ const [isDragging, setIsDragging] = useState(false);
585
+ const handleDragStart = (e) => {
586
+ setIsDragging(true);
587
+ e.dataTransfer.setDragImage(menuItemRef.current, 0, 0);
588
+ };
589
+ const handleDragEnd = (_e) => {
590
+ setIsDragging(false);
591
+ setCurrentHoveredColumn(null);
592
+ if (currentHoveredColumn) {
593
+ setColumnOrder(reorderColumn(column, currentHoveredColumn, columnOrder));
594
+ }
595
+ };
596
+ const handleDragEnter = (_e) => {
597
+ if (!isDragging) {
598
+ setCurrentHoveredColumn(column);
599
+ }
600
+ };
601
+ return (React.createElement(React.Fragment, null,
602
+ React.createElement(MenuItem, { disableRipple: true, ref: menuItemRef, onDragEnter: handleDragEnter, sx: (theme) => ({
603
+ alignItems: 'center',
604
+ justifyContent: 'flex-start',
605
+ my: 0,
606
+ opacity: isDragging ? 0.5 : 1,
607
+ outline: isDragging
608
+ ? `1px dashed ${theme.palette.divider}`
609
+ : (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
610
+ ? `2px dashed ${theme.palette.primary.main}`
611
+ : 'none',
612
+ pl: `${(column.depth + 0.5) * 2}rem`,
613
+ py: '6px',
614
+ }) },
615
+ React.createElement(Box, { sx: {
616
+ display: 'flex',
617
+ flexWrap: 'nowrap',
618
+ gap: '8px',
619
+ } },
620
+ !isSubMenu &&
621
+ columnDefType !== 'group' &&
622
+ enableColumnOrdering &&
623
+ !allColumns.some((col) => col.columnDef.columnDefType === 'group') &&
624
+ (columnDef.enableColumnOrdering !== false ? (React.createElement(MRT_GrabHandleButton, { onDragEnd: handleDragEnd, onDragStart: handleDragStart, table: table })) : (React.createElement(Box, { sx: { width: '28px' } }))),
625
+ !isSubMenu &&
626
+ enablePinning &&
627
+ (column.getCanPin() ? (React.createElement(MRT_ColumnPinningButtons, { column: column, table: table })) : (React.createElement(Box, { sx: { width: '70px' } }))),
628
+ enableHiding ? (React.createElement(FormControlLabel, { componentsProps: {
629
+ typography: {
630
+ sx: {
631
+ mb: 0,
632
+ opacity: columnDefType !== 'display' ? 1 : 0.5,
633
+ },
634
+ },
635
+ }, checked: switchChecked, control: React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.toggleVisibility },
636
+ React.createElement(Switch, null)), disabled: (isSubMenu && switchChecked) ||
637
+ !column.getCanHide() ||
638
+ column.getIsGrouped(), label: columnDef.header, onChange: () => handleToggleColumnHidden(column) })) : (React.createElement(Typography, { sx: { alignSelf: 'center' } }, columnDef.header)))), (_a = column.columns) === null || _a === void 0 ? void 0 :
639
+ _a.map((c, i) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: c, currentHoveredColumn: currentHoveredColumn, isSubMenu: isSubMenu, key: `${i}-${c.id}`, setCurrentHoveredColumn: setCurrentHoveredColumn, table: table })))));
640
+ };
641
+
642
+ const MRT_ShowHideColumnsMenu = ({ anchorEl, isSubMenu, setAnchorEl, table, }) => {
643
+ const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, toggleAllColumnsVisible, options: { localization, enablePinning, enableColumnOrdering }, } = table;
644
+ const { density, columnOrder, columnPinning } = getState();
645
+ const hideAllColumns = () => {
646
+ getAllLeafColumns()
647
+ .filter((col) => col.columnDef.enableHiding !== false)
648
+ .forEach((col) => col.toggleVisibility(false));
649
+ };
650
+ const allColumns = useMemo(() => {
651
+ const columns = getAllColumns();
652
+ if (columnOrder.length > 0 &&
653
+ !columns.some((col) => col.columnDef.columnDefType === 'group')) {
654
+ return [
655
+ ...getLeftLeafColumns(),
656
+ ...Array.from(new Set(columnOrder)).map((colId) => getCenterLeafColumns().find((col) => (col === null || col === void 0 ? void 0 : col.id) === colId)),
657
+ ...getRightLeafColumns(),
658
+ ].filter(Boolean);
659
+ }
660
+ return columns;
661
+ }, [
662
+ columnOrder,
663
+ columnPinning,
664
+ getAllColumns(),
665
+ getCenterLeafColumns(),
666
+ getLeftLeafColumns(),
667
+ getRightLeafColumns(),
668
+ ]);
669
+ const [currentHoveredColumn, setCurrentHoveredColumn] = useState(null);
670
+ return (React.createElement(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
671
+ dense: density === 'compact',
672
+ } },
673
+ React.createElement(Box, { sx: {
674
+ display: 'flex',
675
+ justifyContent: isSubMenu ? 'center' : 'space-between',
676
+ p: '0.5rem',
677
+ pt: 0,
678
+ } },
679
+ !isSubMenu && (React.createElement(Button, { disabled: !getIsSomeColumnsVisible(), onClick: hideAllColumns }, localization.hideAll)),
680
+ !isSubMenu && enableColumnOrdering && (React.createElement(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options)) }, localization.resetOrder)),
681
+ !isSubMenu && enablePinning && (React.createElement(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true) }, localization.unpinAll)),
682
+ React.createElement(Button, { disabled: getIsAllColumnsVisible(), onClick: () => toggleAllColumnsVisible(true) }, localization.showAll)),
683
+ React.createElement(Divider, null),
684
+ allColumns.map((column, index) => (React.createElement(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, currentHoveredColumn: currentHoveredColumn, isSubMenu: isSubMenu, key: `${index}-${column.id}`, setCurrentHoveredColumn: setCurrentHoveredColumn, table: table })))));
685
+ };
686
+
687
+ const commonMenuItemStyles = {
688
+ py: '6px',
689
+ my: 0,
690
+ justifyContent: 'space-between',
691
+ alignItems: 'center',
692
+ };
693
+ const commonListItemStyles = {
694
+ display: 'flex',
695
+ alignItems: 'center',
696
+ };
697
+ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
698
+ var _a, _b, _c, _d, _e, _f, _g;
699
+ const { getState, toggleAllColumnsVisible, setColumnOrder, options: { enableColumnFilterChangeMode, enableColumnFilters, enableColumnResizing, enableGrouping, enableHiding, enablePinning, enableSorting, columnFilterModeOptions, icons: { ArrowRightIcon, ClearAllIcon, ViewColumnIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, SortIcon, RestartAltIcon, VisibilityOffIcon, }, tableId, localization, }, setShowFilters, } = table;
700
+ const { column } = header;
701
+ const { columnDef } = column;
702
+ const { columnSizing, columnVisibility, density } = getState();
703
+ const [filterMenuAnchorEl, setFilterMenuAnchorEl] = useState(null);
704
+ const [showHideColumnsMenuAnchorEl, setShowHideColumnsMenuAnchorEl] = useState(null);
705
+ const handleClearSort = () => {
706
+ column.clearSorting();
707
+ setAnchorEl(null);
708
+ };
709
+ const handleSortAsc = () => {
710
+ column.toggleSorting(false);
711
+ setAnchorEl(null);
712
+ };
713
+ const handleSortDesc = () => {
714
+ column.toggleSorting(true);
715
+ setAnchorEl(null);
716
+ };
717
+ const handleResetColumnSize = () => {
718
+ column.resetSize();
719
+ setAnchorEl(null);
720
+ };
721
+ const handleHideColumn = () => {
722
+ column.toggleVisibility(false);
723
+ setAnchorEl(null);
724
+ };
725
+ const handlePinColumn = (pinDirection) => {
726
+ column.pin(pinDirection);
727
+ setAnchorEl(null);
728
+ };
729
+ const handleGroupByColumn = () => {
730
+ column.toggleGrouping();
731
+ setColumnOrder((old) => ['mrt-row-expand', ...old]);
732
+ setAnchorEl(null);
733
+ };
734
+ const handleClearFilter = () => {
735
+ column.setFilterValue('');
736
+ setAnchorEl(null);
737
+ };
738
+ const handleFilterByColumn = () => {
739
+ setShowFilters(true);
740
+ setTimeout(() => {
741
+ var _a, _b, _c;
742
+ return (_c = document
743
+ .getElementById(
744
+ // @ts-ignore
745
+ (_b = (_a = header.muiTableHeadCellFilterTextFieldProps) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : `mrt-${tableId}-${header.id}-filter-text-field`)) === null || _c === void 0 ? void 0 : _c.focus();
746
+ }, 200);
747
+ setAnchorEl(null);
748
+ };
749
+ const handleShowAllColumns = () => {
750
+ toggleAllColumnsVisible(true);
751
+ setAnchorEl(null);
752
+ };
753
+ const handleOpenFilterModeMenu = (event) => {
754
+ event.stopPropagation();
755
+ setFilterMenuAnchorEl(event.currentTarget);
756
+ };
757
+ const handleOpenShowHideColumnsMenu = (event) => {
758
+ event.stopPropagation();
759
+ setShowHideColumnsMenuAnchorEl(event.currentTarget);
760
+ };
761
+ const isSelectFilter = !!columnDef.filterSelectOptions;
762
+ const allowedColumnFilterOptions = (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.columnFilterModeOptions) !== null && _a !== void 0 ? _a : columnFilterModeOptions;
763
+ const showFilterModeSubMenu = enableColumnFilterChangeMode &&
764
+ columnDef.enableColumnFilterChangeMode !== false &&
765
+ !isSelectFilter &&
766
+ (allowedColumnFilterOptions === undefined ||
767
+ !!(allowedColumnFilterOptions === null || allowedColumnFilterOptions === void 0 ? void 0 : allowedColumnFilterOptions.length));
768
+ return (React.createElement(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
769
+ dense: density === 'compact',
770
+ } },
771
+ enableSorting &&
772
+ column.getCanSort() && [
773
+ React.createElement(MenuItem, { disabled: !column.getIsSorted(), key: 0, onClick: handleClearSort, sx: commonMenuItemStyles },
774
+ React.createElement(Box, { sx: commonListItemStyles },
775
+ React.createElement(ListItemIcon, null,
776
+ React.createElement(ClearAllIcon, null)),
777
+ localization.clearSort)),
778
+ React.createElement(MenuItem, { disabled: column.getIsSorted() === 'asc', key: 1, onClick: handleSortAsc, sx: commonMenuItemStyles },
779
+ React.createElement(Box, { sx: commonListItemStyles },
780
+ React.createElement(ListItemIcon, null,
781
+ React.createElement(SortIcon, { style: { transform: 'rotate(180deg) scaleX(-1)' } })), (_b = localization.sortByColumnAsc) === null || _b === void 0 ? void 0 :
782
+ _b.replace('{column}', String(columnDef.header)))),
783
+ React.createElement(MenuItem, { divider: enableColumnFilters || enableGrouping || enableHiding, key: 2, disabled: column.getIsSorted() === 'desc', onClick: handleSortDesc, sx: commonMenuItemStyles },
784
+ React.createElement(Box, { sx: commonListItemStyles },
785
+ React.createElement(ListItemIcon, null,
786
+ React.createElement(SortIcon, null)), (_c = localization.sortByColumnDesc) === null || _c === void 0 ? void 0 :
787
+ _c.replace('{column}', String(columnDef.header)))),
788
+ ],
789
+ enableColumnFilters &&
790
+ column.getCanFilter() &&
791
+ [
792
+ React.createElement(MenuItem, { disabled: !column.getFilterValue(), key: 0, onClick: handleClearFilter, sx: commonMenuItemStyles },
793
+ React.createElement(Box, { sx: commonListItemStyles },
794
+ React.createElement(ListItemIcon, null,
795
+ React.createElement(FilterListOffIcon, null)),
796
+ localization.clearFilter)),
797
+ React.createElement(MenuItem, { divider: enableGrouping || enableHiding, key: 1, onClick: handleFilterByColumn, sx: commonMenuItemStyles },
798
+ React.createElement(Box, { sx: commonListItemStyles },
799
+ React.createElement(ListItemIcon, null,
800
+ React.createElement(FilterListIcon, null)), (_d = localization.filterByColumn) === null || _d === void 0 ? void 0 :
801
+ _d.replace('{column}', String(columnDef.header))),
802
+ showFilterModeSubMenu && (React.createElement(IconButton, { onClick: handleOpenFilterModeMenu, onMouseEnter: handleOpenFilterModeMenu, size: "small", sx: { p: 0 } },
803
+ React.createElement(ArrowRightIcon, null)))),
804
+ showFilterModeSubMenu && (React.createElement(MRT_FilterOptionMenu, { anchorEl: filterMenuAnchorEl, header: header, key: 2, onSelect: handleFilterByColumn, setAnchorEl: setFilterMenuAnchorEl, table: table })),
805
+ ].filter(Boolean),
806
+ enableGrouping &&
807
+ column.getCanGroup() && [
808
+ React.createElement(MenuItem, { divider: enablePinning, key: 0, onClick: handleGroupByColumn, sx: commonMenuItemStyles },
809
+ React.createElement(Box, { sx: commonListItemStyles },
810
+ React.createElement(ListItemIcon, null,
811
+ React.createElement(DynamicFeedIcon, null)), (_e = localization[column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn']) === null || _e === void 0 ? void 0 :
812
+ _e.replace('{column}', String(columnDef.header)))),
813
+ ],
814
+ enablePinning &&
815
+ column.getCanPin() && [
816
+ React.createElement(MenuItem, { disabled: column.getIsPinned() === 'left' || !column.getCanPin(), key: 0, onClick: () => handlePinColumn('left'), sx: commonMenuItemStyles },
817
+ React.createElement(Box, { sx: commonListItemStyles },
818
+ React.createElement(ListItemIcon, null,
819
+ React.createElement(PushPinIcon, { style: { transform: 'rotate(90deg)' } })),
820
+ localization.pinToLeft)),
821
+ React.createElement(MenuItem, { disabled: column.getIsPinned() === 'right' || !column.getCanPin(), key: 1, onClick: () => handlePinColumn('right'), sx: commonMenuItemStyles },
822
+ React.createElement(Box, { sx: commonListItemStyles },
823
+ React.createElement(ListItemIcon, null,
824
+ React.createElement(PushPinIcon, { style: { transform: 'rotate(-90deg)' } })),
825
+ localization.pinToRight)),
826
+ React.createElement(MenuItem, { disabled: !column.getIsPinned(), divider: enableHiding, key: 2, onClick: () => handlePinColumn(false), sx: commonMenuItemStyles },
827
+ React.createElement(Box, { sx: commonListItemStyles },
828
+ React.createElement(ListItemIcon, null,
829
+ React.createElement(PushPinIcon, null)),
830
+ localization.unpin)),
831
+ ],
832
+ enableColumnResizing &&
833
+ column.getCanResize() && [
834
+ React.createElement(MenuItem, { disabled: !columnSizing[column.id], key: 0, onClick: handleResetColumnSize, sx: commonMenuItemStyles },
835
+ React.createElement(Box, { sx: commonListItemStyles },
836
+ React.createElement(ListItemIcon, null,
837
+ React.createElement(RestartAltIcon, null)),
838
+ localization.resetColumnSize)),
839
+ ],
840
+ enableHiding && [
841
+ React.createElement(MenuItem, { disabled: columnDef.enableHiding === false, key: 0, onClick: handleHideColumn, sx: commonMenuItemStyles },
842
+ React.createElement(Box, { sx: commonListItemStyles },
843
+ React.createElement(ListItemIcon, null,
844
+ React.createElement(VisibilityOffIcon, null)), (_f = localization.hideColumn) === null || _f === void 0 ? void 0 :
845
+ _f.replace('{column}', String(columnDef.header)))),
846
+ React.createElement(MenuItem, { disabled: !Object.values(columnVisibility).filter((visible) => !visible)
847
+ .length, key: 1, onClick: handleShowAllColumns, sx: commonMenuItemStyles },
848
+ React.createElement(Box, { sx: commonListItemStyles },
849
+ React.createElement(ListItemIcon, null,
850
+ React.createElement(ViewColumnIcon, null)), (_g = localization.showAllColumns) === null || _g === void 0 ? void 0 :
851
+ _g.replace('{column}', String(columnDef.header))),
852
+ React.createElement(IconButton, { onClick: handleOpenShowHideColumnsMenu, onMouseEnter: handleOpenShowHideColumnsMenu, size: "small", sx: { p: 0 } },
853
+ React.createElement(ArrowRightIcon, null))),
854
+ React.createElement(MRT_ShowHideColumnsMenu, { anchorEl: showHideColumnsMenuAnchorEl, isSubMenu: true, key: 2, setAnchorEl: setShowHideColumnsMenuAnchorEl, table: table }),
855
+ ]));
856
+ };
857
+
858
+ const MRT_RowActionMenu = ({ anchorEl, handleEdit, row, setAnchorEl, table, }) => {
859
+ const { getState, options: { icons: { EditIcon }, enableEditing, localization, renderRowActionMenuItems, }, } = table;
860
+ const { density } = getState();
861
+ return (React.createElement(Menu, { anchorEl: anchorEl, open: !!anchorEl, onClose: () => setAnchorEl(null), MenuListProps: {
862
+ dense: density === 'compact',
863
+ } },
864
+ enableEditing && (React.createElement(MenuItem, { onClick: handleEdit, sx: commonMenuItemStyles },
865
+ React.createElement(Box, { sx: commonListItemStyles },
866
+ React.createElement(ListItemIcon, null,
867
+ React.createElement(EditIcon, null)),
868
+ localization.edit))), renderRowActionMenuItems === null || renderRowActionMenuItems === void 0 ? void 0 :
869
+ renderRowActionMenuItems({
870
+ row,
871
+ table,
872
+ closeMenu: () => setAnchorEl(null),
873
+ })));
874
+ };
875
+
876
+ const MRT_EditActionButtons = ({ row, table }) => {
877
+ const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onEditRowSubmit, }, setCurrentEditingRow, } = table;
878
+ const { currentEditingRow } = getState();
879
+ const handleCancel = () => {
880
+ var _a;
881
+ row._valuesCache = (_a = row.original) !== null && _a !== void 0 ? _a : {};
882
+ setCurrentEditingRow(null);
883
+ };
884
+ const handleSave = () => {
885
+ onEditRowSubmit === null || onEditRowSubmit === void 0 ? void 0 : onEditRowSubmit({ row: currentEditingRow !== null && currentEditingRow !== void 0 ? currentEditingRow : row, table });
886
+ setCurrentEditingRow(null);
887
+ };
888
+ return (React.createElement(Box, { sx: { display: 'flex', gap: '0.75rem' } },
889
+ React.createElement(Tooltip, { arrow: true, title: localization.cancel },
890
+ React.createElement(IconButton, { "aria-label": localization.cancel, onClick: handleCancel },
891
+ React.createElement(CancelIcon, null))),
892
+ React.createElement(Tooltip, { arrow: true, title: localization.save },
893
+ React.createElement(IconButton, { "aria-label": localization.save, color: "info", onClick: handleSave },
894
+ React.createElement(SaveIcon, null)))));
895
+ };
896
+
897
+ const commonIconButtonStyles = {
898
+ height: '2rem',
899
+ ml: '10px',
900
+ opacity: 0.5,
901
+ transition: 'opacity 0.2s',
902
+ width: '2rem',
903
+ '&:hover': {
904
+ opacity: 1,
905
+ },
906
+ };
907
+ const MRT_ToggleRowActionMenuButton = ({ row, table }) => {
908
+ const { getState, options: { enableEditing, icons: { EditIcon, MoreHorizIcon }, localization, renderRowActionMenuItems, renderRowActions, }, setCurrentEditingRow, } = table;
909
+ const { currentEditingRow } = getState();
910
+ const [anchorEl, setAnchorEl] = useState(null);
911
+ const handleOpenRowActionMenu = (event) => {
912
+ event.stopPropagation();
913
+ event.preventDefault();
914
+ setAnchorEl(event.currentTarget);
915
+ };
916
+ const handleStartEditMode = () => {
917
+ setCurrentEditingRow(Object.assign({}, row));
918
+ setAnchorEl(null);
919
+ };
920
+ return (React.createElement(React.Fragment, null, renderRowActions ? (React.createElement(React.Fragment, null, renderRowActions({ row, table }))) : row.id === (currentEditingRow === null || currentEditingRow === void 0 ? void 0 : currentEditingRow.id) ? (React.createElement(MRT_EditActionButtons, { row: row, table: table })) : !renderRowActionMenuItems && enableEditing ? (React.createElement(Tooltip, { placement: "right", arrow: true, title: localization.edit },
921
+ React.createElement(IconButton, { sx: commonIconButtonStyles, onClick: handleStartEditMode },
922
+ React.createElement(EditIcon, null)))) : renderRowActionMenuItems ? (React.createElement(React.Fragment, null,
923
+ React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.rowActions },
924
+ React.createElement(IconButton, { "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles },
925
+ React.createElement(MoreHorizIcon, null))),
926
+ React.createElement(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, table: table }))) : null));
927
+ };
928
+
929
+ const MRT_SelectCheckbox = ({ row, selectAll, table }) => {
930
+ const { getState, options: { localization, muiSelectCheckboxProps, muiSelectAllCheckboxProps, selectAllMode, }, } = table;
931
+ const { density } = getState();
932
+ const checkboxProps = !row
933
+ ? muiSelectAllCheckboxProps instanceof Function
934
+ ? muiSelectAllCheckboxProps({ table })
935
+ : muiSelectAllCheckboxProps
936
+ : muiSelectCheckboxProps instanceof Function
937
+ ? muiSelectCheckboxProps({ row, table })
938
+ : muiSelectCheckboxProps;
939
+ return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: selectAll ? localization.toggleSelectAll : localization.toggleSelectRow },
940
+ React.createElement(Checkbox, Object.assign({ checked: selectAll ? table.getIsAllRowsSelected() : row === null || row === void 0 ? void 0 : row.getIsSelected(), indeterminate: selectAll ? table.getIsSomeRowsSelected() : row === null || row === void 0 ? void 0 : row.getIsSomeSelected(), inputProps: {
941
+ 'aria-label': selectAll
942
+ ? localization.toggleSelectAll
943
+ : localization.toggleSelectRow,
944
+ }, onChange: !row
945
+ ? selectAllMode === 'all'
946
+ ? table.getToggleAllRowsSelectedHandler()
947
+ : table.getToggleAllPageRowsSelectedHandler()
948
+ : row.getToggleSelectedHandler(), size: density === 'compact' ? 'small' : 'medium' }, checkboxProps, { sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.5rem', width: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined }, ((checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx) instanceof Function
949
+ ? checkboxProps.sx(theme)
950
+ : checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx))) }))));
951
+ };
952
+
953
+ const MRT_GlobalFilterTextField = ({ table }) => {
954
+ var _a;
955
+ const { getState, setGlobalFilter, options: { enableGlobalFilterChangeMode, icons: { SearchIcon, CloseIcon }, localization, muiSearchTextFieldProps, tableId, }, } = table;
956
+ const { globalFilter, showGlobalFilter } = getState();
957
+ const [anchorEl, setAnchorEl] = useState(null);
958
+ const [searchValue, setSearchValue] = useState(globalFilter !== null && globalFilter !== void 0 ? globalFilter : '');
959
+ const handleChangeDebounced = useCallback(debounce((event) => {
960
+ var _a;
961
+ setGlobalFilter((_a = event.target.value) !== null && _a !== void 0 ? _a : undefined);
962
+ }, 250), []);
963
+ const handleChange = (event) => {
964
+ setSearchValue(event.target.value);
965
+ handleChangeDebounced(event);
966
+ };
967
+ const handleGlobalFilterMenuOpen = (event) => {
968
+ setAnchorEl(event.currentTarget);
969
+ };
970
+ const handleClear = () => {
971
+ setSearchValue('');
972
+ setGlobalFilter(undefined);
973
+ };
974
+ const textFieldProps = muiSearchTextFieldProps instanceof Function
975
+ ? muiSearchTextFieldProps({ table })
976
+ : muiSearchTextFieldProps;
977
+ return (React.createElement(Collapse, { in: showGlobalFilter, orientation: "horizontal" },
978
+ React.createElement(TextField, Object.assign({ id: `mrt-${tableId}-search-text-field`, placeholder: localization.search, onChange: handleChange, value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "standard", InputProps: {
979
+ startAdornment: enableGlobalFilterChangeMode ? (React.createElement(InputAdornment, { position: "start" },
980
+ React.createElement(Tooltip, { arrow: true, title: localization.changeSearchMode },
981
+ React.createElement(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' } },
982
+ React.createElement(SearchIcon, null))))) : (React.createElement(SearchIcon, { style: { marginRight: '4px' } })),
983
+ endAdornment: (React.createElement(InputAdornment, { position: "end" },
984
+ React.createElement(Tooltip, { arrow: true, title: (_a = localization.clearSearch) !== null && _a !== void 0 ? _a : '' },
985
+ React.createElement("span", null,
986
+ React.createElement(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small" },
987
+ React.createElement(CloseIcon, null)))))),
988
+ } }, textFieldProps)),
989
+ React.createElement(MRT_FilterOptionMenu, { anchorEl: anchorEl, setAnchorEl: setAnchorEl, table: table })));
990
+ };
991
+
992
+ const MRT_LinearProgressBar = ({ isTopToolbar, table }) => {
993
+ const { options: { muiLinearProgressProps }, getState, } = table;
994
+ const { isLoading, showProgressBars } = getState();
995
+ const linearProgressProps = muiLinearProgressProps instanceof Function
996
+ ? muiLinearProgressProps({ isTopToolbar, table })
997
+ : muiLinearProgressProps;
998
+ return (React.createElement(Collapse, { in: isLoading || showProgressBars, mountOnEnter: true, unmountOnExit: true, sx: {
999
+ bottom: isTopToolbar ? 0 : undefined,
1000
+ position: 'absolute',
1001
+ top: !isTopToolbar ? 0 : undefined,
1002
+ width: '100%',
1003
+ } },
1004
+ React.createElement(LinearProgress, Object.assign({ "aria-label": "Loading", "aria-busy": "true", sx: { position: 'relative' } }, linearProgressProps))));
1005
+ };
1006
+
1007
+ const MRT_TablePagination = ({ table, position }) => {
1008
+ const { getPrePaginationRowModel, getState, setPageIndex, setPageSize, options: { muiTablePaginationProps, enableToolbarInternalActions, rowCount, }, } = table;
1009
+ const { pagination: { pageSize = 10, pageIndex = 0 }, showGlobalFilter, } = getState();
1010
+ const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length;
1011
+ const showFirstLastPageButtons = totalRowCount / pageSize > 2;
1012
+ const tablePaginationProps = muiTablePaginationProps instanceof Function
1013
+ ? muiTablePaginationProps({ table })
1014
+ : muiTablePaginationProps;
1015
+ const handleChangeRowsPerPage = (event) => {
1016
+ setPageSize(+event.target.value);
1017
+ };
1018
+ return (React.createElement(TablePagination, Object.assign({ SelectProps: {
1019
+ sx: { m: '0 1rem 0 1ch' },
1020
+ MenuProps: { MenuListProps: { disablePadding: true } },
1021
+ }, component: "div", count: totalRowCount, onPageChange: (_, newPage) => setPageIndex(newPage), onRowsPerPageChange: handleChangeRowsPerPage, page: pageIndex, rowsPerPage: pageSize, rowsPerPageOptions: [5, 10, 15, 20, 25, 30, 50, 100], showFirstButton: showFirstLastPageButtons, showLastButton: showFirstLastPageButtons }, tablePaginationProps, { sx: (theme) => (Object.assign({ m: '0 0.5rem', mt: position === 'top' &&
1022
+ enableToolbarInternalActions &&
1023
+ !showGlobalFilter
1024
+ ? '3.5rem'
1025
+ : undefined, position: 'relative', zIndex: 2 }, ((tablePaginationProps === null || tablePaginationProps === void 0 ? void 0 : tablePaginationProps.sx) instanceof Function
1026
+ ? tablePaginationProps.sx(theme)
1027
+ : tablePaginationProps === null || tablePaginationProps === void 0 ? void 0 : tablePaginationProps.sx))) })));
1028
+ };
1029
+
1030
+ const MRT_ToolbarAlertBanner = ({ stackAlertBanner, table, }) => {
1031
+ var _a, _b;
1032
+ const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { localization, muiTableToolbarAlertBannerProps }, } = table;
1033
+ const { grouping, showAlertBanner } = getState();
1034
+ const alertProps = muiTableToolbarAlertBannerProps instanceof Function
1035
+ ? muiTableToolbarAlertBannerProps({ table })
1036
+ : muiTableToolbarAlertBannerProps;
1037
+ const selectMessage = getSelectedRowModel().rows.length > 0
1038
+ ? (_b = (_a = localization.selectedCountOfRowCountRowsSelected) === null || _a === void 0 ? void 0 : _a.replace('{selectedCount}', getSelectedRowModel().rows.length.toString())) === null || _b === void 0 ? void 0 : _b.replace('{rowCount}', getPrePaginationRowModel().rows.length.toString())
1039
+ : null;
1040
+ const groupedByMessage = grouping.length > 0 ? (React.createElement("span", null,
1041
+ localization.groupedBy,
1042
+ ' ',
1043
+ grouping.map((columnId, index) => (React.createElement(Fragment, { key: `${index}-${columnId}` },
1044
+ index > 0 ? localization.thenBy : '',
1045
+ React.createElement(Chip, { color: "secondary", label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() })))))) : null;
1046
+ return (React.createElement(Collapse, { in: showAlertBanner || !!selectMessage || !!groupedByMessage, timeout: stackAlertBanner ? 200 : 0 },
1047
+ React.createElement(Alert, Object.assign({ color: "info", icon: false }, alertProps, { sx: (theme) => (Object.assign({ borderRadius: 0, fontSize: '1rem', left: 0, p: 0, position: 'relative', right: 0, top: 0, width: '100%', zIndex: 2 }, ((alertProps === null || alertProps === void 0 ? void 0 : alertProps.sx) instanceof Function
1048
+ ? alertProps.sx(theme)
1049
+ : alertProps === null || alertProps === void 0 ? void 0 : alertProps.sx))) }),
1050
+ (alertProps === null || alertProps === void 0 ? void 0 : alertProps.title) && React.createElement(AlertTitle, null, alertProps.title),
1051
+ React.createElement(Box, { sx: { p: '0.5rem 1rem' } }, alertProps === null || alertProps === void 0 ? void 0 :
1052
+ alertProps.children,
1053
+ (alertProps === null || alertProps === void 0 ? void 0 : alertProps.children) && (selectMessage || groupedByMessage) && (React.createElement("br", null)),
1054
+ selectMessage,
1055
+ selectMessage && groupedByMessage && React.createElement("br", null),
1056
+ groupedByMessage))));
1057
+ };
1058
+
1059
+ const MRT_FullScreenToggleButton = (_a) => {
1060
+ var { table } = _a, rest = __rest(_a, ["table"]);
1061
+ const { getState, options: { icons: { FullscreenExitIcon, FullscreenIcon }, localization, }, setIsFullScreen, } = table;
1062
+ const { isFullScreen } = getState();
1063
+ const handleToggleFullScreen = () => {
1064
+ setIsFullScreen(!isFullScreen);
1065
+ };
1066
+ return (React.createElement(Tooltip, { arrow: true, title: localization.toggleFullScreen },
1067
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.showHideFilters, onClick: handleToggleFullScreen }, rest), isFullScreen ? React.createElement(FullscreenExitIcon, null) : React.createElement(FullscreenIcon, null))));
1068
+ };
1069
+
1070
+ const MRT_ShowHideColumnsButton = (_a) => {
1071
+ var { table } = _a, rest = __rest(_a, ["table"]);
1072
+ const { options: { icons: { ViewColumnIcon }, localization, }, } = table;
1073
+ const [anchorEl, setAnchorEl] = useState(null);
1074
+ const handleClick = (event) => {
1075
+ setAnchorEl(event.currentTarget);
1076
+ };
1077
+ return (React.createElement(React.Fragment, null,
1078
+ React.createElement(Tooltip, { arrow: true, title: localization.showHideColumns },
1079
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.showHideColumns, onClick: handleClick }, rest),
1080
+ React.createElement(ViewColumnIcon, null))),
1081
+ React.createElement(MRT_ShowHideColumnsMenu, { anchorEl: anchorEl, setAnchorEl: setAnchorEl, table: table })));
1082
+ };
1083
+
1084
+ const MRT_ToggleDensePaddingButton = (_a) => {
1085
+ var { table } = _a, rest = __rest(_a, ["table"]);
1086
+ const { getState, options: { icons: { DensityLargeIcon, DensityMediumIcon, DensitySmallIcon }, localization, }, setDensity, } = table;
1087
+ const { density } = getState();
1088
+ const handleToggleDensePadding = () => {
1089
+ const nextDensity = density === 'comfortable'
1090
+ ? 'compact'
1091
+ : density === 'compact'
1092
+ ? 'spacious'
1093
+ : 'comfortable';
1094
+ setDensity(nextDensity);
1095
+ };
1096
+ return (React.createElement(Tooltip, { arrow: true, title: localization.toggleDensity },
1097
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.toggleDensity, onClick: handleToggleDensePadding }, rest), density === 'compact' ? (React.createElement(DensitySmallIcon, null)) : density === 'comfortable' ? (React.createElement(DensityMediumIcon, null)) : (React.createElement(DensityLargeIcon, null)))));
1098
+ };
1099
+
1100
+ const MRT_ToggleFiltersButton = (_a) => {
1101
+ var { table } = _a, rest = __rest(_a, ["table"]);
1102
+ const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, }, setShowFilters, } = table;
1103
+ const { showColumnFilters } = getState();
1104
+ const handleToggleShowFilters = () => {
1105
+ setShowFilters(!showColumnFilters);
1106
+ };
1107
+ return (React.createElement(Tooltip, { arrow: true, title: localization.showHideFilters },
1108
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.showHideFilters, onClick: handleToggleShowFilters }, rest), showColumnFilters ? React.createElement(FilterListOffIcon, null) : React.createElement(FilterListIcon, null))));
1109
+ };
1110
+
1111
+ const MRT_ToggleGlobalFilterButton = (_a) => {
1112
+ var { table } = _a, rest = __rest(_a, ["table"]);
1113
+ const { getState, options: { icons: { SearchIcon, SearchOffIcon }, tableId, localization, muiSearchTextFieldProps, }, setShowGlobalFilter, } = table;
1114
+ const { showGlobalFilter } = getState();
1115
+ const textFieldProps = muiSearchTextFieldProps instanceof Function
1116
+ ? muiSearchTextFieldProps({ table })
1117
+ : muiSearchTextFieldProps;
1118
+ const handleToggleSearch = () => {
1119
+ setShowGlobalFilter(!showGlobalFilter);
1120
+ setTimeout(() => {
1121
+ var _a, _b;
1122
+ return (_b = document
1123
+ .getElementById((_a = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.id) !== null && _a !== void 0 ? _a : `mrt-${tableId}-search-text-field`)) === null || _b === void 0 ? void 0 : _b.focus();
1124
+ }, 200);
1125
+ };
1126
+ return (React.createElement(Tooltip, { arrow: true, title: localization.showHideSearch },
1127
+ React.createElement(IconButton, Object.assign({ onClick: handleToggleSearch }, rest), showGlobalFilter ? React.createElement(SearchOffIcon, null) : React.createElement(SearchIcon, null))));
1128
+ };
1129
+
1130
+ const MRT_ToolbarInternalButtons = ({ table }) => {
1131
+ var _a;
1132
+ const { options: { enableColumnFilters, enableColumnOrdering, enableDensityToggle, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableHiding, enablePinning, positionGlobalFilter, renderToolbarInternalActions, }, } = table;
1133
+ return (React.createElement(Box, { sx: {
1134
+ alignItems: 'center',
1135
+ display: 'flex',
1136
+ zIndex: 3,
1137
+ } }, (_a = renderToolbarInternalActions === null || renderToolbarInternalActions === void 0 ? void 0 : renderToolbarInternalActions({
1138
+ MRT_FullScreenToggleButton,
1139
+ MRT_ShowHideColumnsButton,
1140
+ MRT_ToggleDensePaddingButton,
1141
+ MRT_ToggleFiltersButton,
1142
+ MRT_ToggleGlobalFilterButton,
1143
+ table,
1144
+ })) !== null && _a !== void 0 ? _a : (React.createElement(React.Fragment, null,
1145
+ enableGlobalFilter && positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })),
1146
+ enableFilters && enableGlobalFilter && (React.createElement(MRT_ToggleGlobalFilterButton, { table: table })),
1147
+ enableFilters && enableColumnFilters && (React.createElement(MRT_ToggleFiltersButton, { table: table })),
1148
+ (enableHiding || enableColumnOrdering || enablePinning) && (React.createElement(MRT_ShowHideColumnsButton, { table: table })),
1149
+ enableDensityToggle && (React.createElement(MRT_ToggleDensePaddingButton, { table: table })),
1150
+ enableFullScreenToggle && (React.createElement(MRT_FullScreenToggleButton, { table: table }))))));
1151
+ };
1152
+
1153
+ const MRT_ToolbarDropZone = ({ table }) => {
1154
+ var _a, _b;
1155
+ const { getState, options: { enableGrouping, localization }, setCurrentHoveredColumn, } = table;
1156
+ const { currentDraggingColumn, currentHoveredColumn } = getState();
1157
+ const handleDragEnter = (_event) => {
1158
+ setCurrentHoveredColumn({ id: 'drop-zone' });
1159
+ };
1160
+ return (React.createElement(Fade, { unmountOnExit: true, mountOnEnter: true, in: !!enableGrouping && !!currentDraggingColumn },
1161
+ React.createElement(Box, { sx: (theme) => ({
1162
+ alignItems: 'center',
1163
+ backgroundColor: alpha(theme.palette.info.main, (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone' ? 0.2 : 0.1),
1164
+ border: `dashed ${theme.palette.info.main} 2px`,
1165
+ display: 'flex',
1166
+ justifyContent: 'center',
1167
+ height: 'calc(100% - 4px)',
1168
+ position: 'absolute',
1169
+ width: 'calc(100% - 4px)',
1170
+ zIndex: 2,
1171
+ }), onDragEnter: handleDragEnter },
1172
+ React.createElement(Typography, null, localization.dropToGroupBy.replace('{column}', (_b = (_a = currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.columnDef) === null || _a === void 0 ? void 0 : _a.header) !== null && _b !== void 0 ? _b : '')))));
1173
+ };
1174
+
1175
+ const commonToolbarStyles = ({ theme }) => ({
1176
+ alignItems: 'flex-start',
1177
+ backgroundColor: lighten(theme.palette.background.default, 0.04),
1178
+ backgroundImage: 'none',
1179
+ display: 'grid',
1180
+ minHeight: '3.5rem',
1181
+ overflow: 'hidden',
1182
+ p: '0 !important',
1183
+ transition: 'all 0.2s ease-in-out',
1184
+ zIndex: 1,
1185
+ });
1186
+ const MRT_TopToolbar = ({ table }) => {
1187
+ var _a;
1188
+ const { getState, options: { enableGlobalFilter, enablePagination, enableToolbarInternalActions, muiTableTopToolbarProps, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderTopToolbarCustomActions, tableId, }, } = table;
1189
+ const { isFullScreen, showGlobalFilter } = getState();
1190
+ const isMobile = useMediaQuery('(max-width:720px)');
1191
+ const toolbarProps = muiTableTopToolbarProps instanceof Function
1192
+ ? muiTableTopToolbarProps({ table })
1193
+ : muiTableTopToolbarProps;
1194
+ const stackAlertBanner = isMobile || !!renderTopToolbarCustomActions || showGlobalFilter;
1195
+ return (React.createElement(Toolbar, Object.assign({ id: `mrt-${tableId}-toolbar-top`, variant: "dense" }, toolbarProps, { sx: (theme) => (Object.assign(Object.assign({ position: isFullScreen ? 'sticky' : undefined, top: isFullScreen ? '0' : undefined }, commonToolbarStyles({ theme })), ((toolbarProps === null || toolbarProps === void 0 ? void 0 : toolbarProps.sx) instanceof Function
1196
+ ? toolbarProps.sx(theme)
1197
+ : toolbarProps === null || toolbarProps === void 0 ? void 0 : toolbarProps.sx))) }),
1198
+ positionToolbarAlertBanner === 'top' && (React.createElement(MRT_ToolbarAlertBanner, { stackAlertBanner: stackAlertBanner, table: table })),
1199
+ ['both', 'top'].includes(positionToolbarDropZone !== null && positionToolbarDropZone !== void 0 ? positionToolbarDropZone : '') && (React.createElement(MRT_ToolbarDropZone, { table: table })),
1200
+ React.createElement(Box, { sx: {
1201
+ alignItems: 'flex-start',
1202
+ boxSizing: 'border-box',
1203
+ display: 'flex',
1204
+ justifyContent: 'space-between',
1205
+ p: '0.5rem',
1206
+ position: stackAlertBanner ? 'relative' : 'absolute',
1207
+ right: 0,
1208
+ top: 0,
1209
+ width: '100%',
1210
+ } },
1211
+ enableGlobalFilter && positionGlobalFilter === 'left' && (React.createElement(MRT_GlobalFilterTextField, { table: table })), (_a = renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({ table })) !== null && _a !== void 0 ? _a : React.createElement("span", null),
1212
+ enableToolbarInternalActions ? (React.createElement(MRT_ToolbarInternalButtons, { table: table })) : (enableGlobalFilter &&
1213
+ positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })))),
1214
+ enablePagination &&
1215
+ ['top', 'both'].includes(positionPagination !== null && positionPagination !== void 0 ? positionPagination : '') && (React.createElement(MRT_TablePagination, { table: table, position: "top" })),
1216
+ React.createElement(MRT_LinearProgressBar, { isTopToolbar: true, table: table })));
1217
+ };
1218
+
1219
+ const MRT_BottomToolbar = ({ table }) => {
1220
+ const { getState, options: { enablePagination, muiTableBottomToolbarProps, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderBottomToolbarCustomActions, tableId, }, } = table;
1221
+ const { isFullScreen } = getState();
1222
+ const isMobile = useMediaQuery('(max-width:720px)');
1223
+ const toolbarProps = muiTableBottomToolbarProps instanceof Function
1224
+ ? muiTableBottomToolbarProps({ table })
1225
+ : muiTableBottomToolbarProps;
1226
+ const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
1227
+ return (React.createElement(Toolbar, Object.assign({ id: `mrt-${tableId}-toolbar-bottom`, variant: "dense" }, toolbarProps, { sx: (theme) => (Object.assign(Object.assign(Object.assign({}, commonToolbarStyles({ theme })), { bottom: isFullScreen ? '0' : undefined, boxShadow: `-3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`, left: 0, position: isFullScreen ? 'fixed' : 'relative', right: 0 }), ((toolbarProps === null || toolbarProps === void 0 ? void 0 : toolbarProps.sx) instanceof Function
1228
+ ? toolbarProps.sx(theme)
1229
+ : toolbarProps === null || toolbarProps === void 0 ? void 0 : toolbarProps.sx))) }),
1230
+ React.createElement(MRT_LinearProgressBar, { isTopToolbar: false, table: table }),
1231
+ positionToolbarAlertBanner === 'bottom' && (React.createElement(MRT_ToolbarAlertBanner, { table: table })),
1232
+ ['both', 'bottom'].includes(positionToolbarDropZone !== null && positionToolbarDropZone !== void 0 ? positionToolbarDropZone : '') && (React.createElement(MRT_ToolbarDropZone, { table: table })),
1233
+ React.createElement(Box, { sx: {
1234
+ display: 'flex',
1235
+ justifyContent: 'space-between',
1236
+ width: '100%',
1237
+ } },
1238
+ renderBottomToolbarCustomActions ? (React.createElement(Box, { sx: { p: '0.5rem' } }, renderBottomToolbarCustomActions({ table }))) : (React.createElement("span", null)),
1239
+ React.createElement(Box, { sx: {
1240
+ display: 'flex',
1241
+ justifyContent: 'flex-end',
1242
+ position: stackAlertBanner ? 'relative' : 'absolute',
1243
+ right: 0,
1244
+ top: 0,
1245
+ } }, enablePagination &&
1246
+ ['bottom', 'both'].includes(positionPagination !== null && positionPagination !== void 0 ? positionPagination : '') && (React.createElement(MRT_TablePagination, { table: table, position: "bottom" }))))));
1247
+ };
1248
+
1249
+ const MRT_TableHeadCellColumnActionsButton = ({ header, table, }) => {
1250
+ const { options: { icons: { MoreVertIcon }, localization, muiTableHeadCellColumnActionsButtonProps, }, } = table;
1251
+ const { column } = header;
1252
+ const { columnDef } = column;
1253
+ const [anchorEl, setAnchorEl] = useState(null);
1254
+ const handleClick = (event) => {
1255
+ event.stopPropagation();
1256
+ event.preventDefault();
1257
+ setAnchorEl(event.currentTarget);
1258
+ };
1259
+ const mTableHeadCellColumnActionsButtonProps = muiTableHeadCellColumnActionsButtonProps instanceof Function
1260
+ ? muiTableHeadCellColumnActionsButtonProps({ column, table })
1261
+ : muiTableHeadCellColumnActionsButtonProps;
1262
+ const mcTableHeadCellColumnActionsButtonProps = columnDef.muiTableHeadCellColumnActionsButtonProps instanceof Function
1263
+ ? columnDef.muiTableHeadCellColumnActionsButtonProps({
1264
+ column,
1265
+ table,
1266
+ })
1267
+ : columnDef.muiTableHeadCellColumnActionsButtonProps;
1268
+ const iconButtonProps = Object.assign(Object.assign({}, mTableHeadCellColumnActionsButtonProps), mcTableHeadCellColumnActionsButtonProps);
1269
+ return (React.createElement(React.Fragment, null,
1270
+ React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: localization.columnActions },
1271
+ React.createElement(IconButton, Object.assign({ "aria-label": localization.columnActions, onClick: handleClick, size: "small" }, iconButtonProps, { sx: (theme) => (Object.assign({ height: '2rem', mt: '-0.2rem', opacity: 0.5, transition: 'opacity 0.2s', width: '2rem', '&:hover': {
1272
+ opacity: 1,
1273
+ } }, ((iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx) instanceof Function
1274
+ ? iconButtonProps.sx(theme)
1275
+ : iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.sx))) }),
1276
+ React.createElement(MoreVertIcon, null))),
1277
+ React.createElement(MRT_ColumnActionMenu, { anchorEl: anchorEl, header: header, setAnchorEl: setAnchorEl, table: table })));
1278
+ };
1279
+
1280
+ const MRT_FilterTextField = ({ header, rangeFilterIndex, table, }) => {
1281
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1282
+ const { getState, options: { enableColumnFilterChangeMode, columnFilterModeOptions, icons: { FilterListIcon, CloseIcon }, localization, muiTableHeadCellFilterTextFieldProps, tableId, }, setColumnFilterFns, } = table;
1283
+ const { column } = header;
1284
+ const { columnDef } = column;
1285
+ const { columnFilterFns } = getState();
1286
+ const mTableHeadCellFilterTextFieldProps = muiTableHeadCellFilterTextFieldProps instanceof Function
1287
+ ? muiTableHeadCellFilterTextFieldProps({
1288
+ column,
1289
+ table,
1290
+ rangeFilterIndex,
1291
+ })
1292
+ : muiTableHeadCellFilterTextFieldProps;
1293
+ const mcTableHeadCellFilterTextFieldProps = columnDef.muiTableHeadCellFilterTextFieldProps instanceof Function
1294
+ ? columnDef.muiTableHeadCellFilterTextFieldProps({
1295
+ column,
1296
+ table,
1297
+ rangeFilterIndex,
1298
+ })
1299
+ : columnDef.muiTableHeadCellFilterTextFieldProps;
1300
+ const textFieldProps = Object.assign(Object.assign({}, mTableHeadCellFilterTextFieldProps), mcTableHeadCellFilterTextFieldProps);
1301
+ const isRangeFilter = columnDef.filterVariant === 'range' || rangeFilterIndex !== undefined;
1302
+ const isSelectFilter = columnDef.filterVariant === 'select';
1303
+ const isMultiSelectFilter = columnDef.filterVariant === 'multi-select';
1304
+ const isTextboxFilter = columnDef.filterVariant === 'text' ||
1305
+ (!isSelectFilter && !isMultiSelectFilter);
1306
+ const currentFilterOption = columnFilterFns === null || columnFilterFns === void 0 ? void 0 : columnFilterFns[header.id];
1307
+ const filterId = `mrt-${tableId}-${header.id}-filter-text-field${rangeFilterIndex !== null && rangeFilterIndex !== void 0 ? rangeFilterIndex : ''}`;
1308
+ const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
1309
+ ? //@ts-ignore
1310
+ localization[`filter${((_b = (_a = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt) === null || _a === void 0 ? void 0 : _a.call(currentFilterOption, 0)) === null || _b === void 0 ? void 0 : _b.toUpperCase()) +
1311
+ (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]
1312
+ : '';
1313
+ const filterPlaceholder = !isRangeFilter
1314
+ ? (_c = localization.filterByColumn) === null || _c === void 0 ? void 0 : _c.replace('{column}', String(columnDef.header))
1315
+ : rangeFilterIndex === 0
1316
+ ? localization.min
1317
+ : rangeFilterIndex === 1
1318
+ ? localization.max
1319
+ : '';
1320
+ const allowedColumnFilterOptions = (_d = columnDef === null || columnDef === void 0 ? void 0 : columnDef.columnFilterModeOptions) !== null && _d !== void 0 ? _d : columnFilterModeOptions;
1321
+ const showChangeModeButton = enableColumnFilterChangeMode &&
1322
+ columnDef.enableColumnFilterChangeMode !== false &&
1323
+ !rangeFilterIndex &&
1324
+ (allowedColumnFilterOptions === undefined ||
1325
+ !!(allowedColumnFilterOptions === null || allowedColumnFilterOptions === void 0 ? void 0 : allowedColumnFilterOptions.length));
1326
+ const [anchorEl, setAnchorEl] = useState(null);
1327
+ const [filterValue, setFilterValue] = useState(() => {
1328
+ var _a, _b;
1329
+ return isMultiSelectFilter
1330
+ ? column.getFilterValue() || []
1331
+ : isRangeFilter
1332
+ ? ((_a = column.getFilterValue()) === null || _a === void 0 ? void 0 : _a[rangeFilterIndex]) || []
1333
+ : (_b = column.getFilterValue()) !== null && _b !== void 0 ? _b : '';
1334
+ });
1335
+ const handleChangeDebounced = useCallback(debounce((event) => {
1336
+ let value = textFieldProps.type === 'date'
1337
+ ? new Date(event.target.value)
1338
+ : event.target.value;
1339
+ if (isRangeFilter) {
1340
+ column.setFilterValue((old) => {
1341
+ const newFilterValues = old !== null && old !== void 0 ? old : ['', ''];
1342
+ newFilterValues[rangeFilterIndex] = value;
1343
+ return newFilterValues;
1344
+ });
1345
+ }
1346
+ else {
1347
+ column.setFilterValue(value !== null && value !== void 0 ? value : undefined);
1348
+ }
1349
+ }, isTextboxFilter ? 200 : 1), []);
1350
+ const handleChange = (event) => {
1351
+ setFilterValue(event.target.value);
1352
+ handleChangeDebounced(event);
1353
+ };
1354
+ const handleClear = () => {
1355
+ if (isMultiSelectFilter) {
1356
+ setFilterValue([]);
1357
+ column.setFilterValue([]);
1358
+ }
1359
+ else if (isRangeFilter) {
1360
+ setFilterValue('');
1361
+ column.setFilterValue((old) => {
1362
+ const newFilterValues = old !== null && old !== void 0 ? old : ['', ''];
1363
+ newFilterValues[rangeFilterIndex] = undefined;
1364
+ return newFilterValues;
1365
+ });
1366
+ }
1367
+ else {
1368
+ setFilterValue('');
1369
+ column.setFilterValue(undefined);
1370
+ }
1371
+ };
1372
+ const handleClearEmptyFilterChip = () => {
1373
+ setFilterValue('');
1374
+ column.setFilterValue(undefined);
1375
+ setColumnFilterFns((prev) => (Object.assign(Object.assign({}, prev), { [header.id]: 'fuzzy' })));
1376
+ };
1377
+ const handleFilterMenuOpen = (event) => {
1378
+ setAnchorEl(event.currentTarget);
1379
+ };
1380
+ if (columnDef.Filter) {
1381
+ return React.createElement(React.Fragment, null, (_e = columnDef.Filter) === null || _e === void 0 ? void 0 : _e.call(columnDef, { column, header, table }));
1382
+ }
1383
+ return (React.createElement(React.Fragment, null,
1384
+ React.createElement(TextField, Object.assign({ fullWidth: true, id: filterId, inputProps: {
1385
+ disabled: !!filterChipLabel,
1386
+ sx: {
1387
+ textOverflow: 'ellipsis',
1388
+ width: filterChipLabel ? 0 : undefined,
1389
+ },
1390
+ title: filterPlaceholder,
1391
+ }, helperText: showChangeModeButton ? (React.createElement("label", { htmlFor: filterId }, localization.filterMode.replace('{filterType}',
1392
+ // @ts-ignore
1393
+ localization[`filter${((_f = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _f === void 0 ? void 0 : _f.toUpperCase()) +
1394
+ (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`]))) : null, FormHelperTextProps: {
1395
+ sx: {
1396
+ fontSize: '0.6rem',
1397
+ lineHeight: '0.8rem',
1398
+ whiteSpace: 'nowrap',
1399
+ },
1400
+ }, margin: "none", placeholder: filterChipLabel || isSelectFilter || isMultiSelectFilter
1401
+ ? undefined
1402
+ : filterPlaceholder, onChange: handleChange, onClick: (e) => e.stopPropagation(), select: isSelectFilter || isMultiSelectFilter, value: filterValue, variant: "standard", InputProps: {
1403
+ startAdornment: showChangeModeButton ? (React.createElement(InputAdornment, { position: "start" },
1404
+ React.createElement(Tooltip, { arrow: true, title: localization.changeFilterMode },
1405
+ React.createElement("span", null,
1406
+ React.createElement(IconButton, { "aria-label": localization.changeFilterMode, onClick: handleFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' } },
1407
+ React.createElement(FilterListIcon, null)))),
1408
+ filterChipLabel && (React.createElement(Chip, { onDelete: handleClearEmptyFilterChip, label: filterChipLabel })))) : (React.createElement(FilterListIcon, { style: { marginRight: '4px' } })),
1409
+ endAdornment: !filterChipLabel && (React.createElement(InputAdornment, { position: "end" },
1410
+ React.createElement(Tooltip, { arrow: true, placement: "right", title: (_g = localization.clearFilter) !== null && _g !== void 0 ? _g : '' },
1411
+ React.createElement("span", null,
1412
+ React.createElement(IconButton, { "aria-label": localization.clearFilter, disabled: !(filterValue === null || filterValue === void 0 ? void 0 : filterValue.length), onClick: handleClear, size: "small", sx: {
1413
+ height: '1.75rem',
1414
+ width: '1.75rem',
1415
+ } },
1416
+ React.createElement(CloseIcon, null)))))),
1417
+ }, SelectProps: {
1418
+ displayEmpty: true,
1419
+ multiple: isMultiSelectFilter,
1420
+ renderValue: isMultiSelectFilter
1421
+ ? (selected) => !(selected === null || selected === void 0 ? void 0 : selected.length) ? (React.createElement(Box, { sx: { opacity: 0.5 } }, filterPlaceholder)) : (React.createElement(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: '2px' } }, selected === null || selected === void 0 ? void 0 : selected.map((value) => (React.createElement(Chip, { key: value, label: value })))))
1422
+ : undefined,
1423
+ } }, textFieldProps, { sx: (theme) => (Object.assign({ p: 0, minWidth: !filterChipLabel ? '6rem' : 'auto', width: '100%', '& .MuiSelect-icon': {
1424
+ mr: '1.5rem',
1425
+ } }, ((textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx) instanceof Function
1426
+ ? textFieldProps.sx(theme)
1427
+ : textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.sx))) }),
1428
+ (isSelectFilter || isMultiSelectFilter) && (React.createElement(MenuItem, { divider: true, disabled: true, hidden: true, value: "" },
1429
+ React.createElement(Box, { sx: { opacity: 0.5 } }, filterPlaceholder))), (_h = columnDef === null || columnDef === void 0 ? void 0 : columnDef.filterSelectOptions) === null || _h === void 0 ? void 0 :
1430
+ _h.map((option) => {
1431
+ var _a;
1432
+ let value;
1433
+ let text;
1434
+ if (typeof option !== 'object') {
1435
+ value = option;
1436
+ text = option;
1437
+ }
1438
+ else {
1439
+ value = option.value;
1440
+ text = option.text;
1441
+ }
1442
+ return (React.createElement(MenuItem, { key: value, value: value },
1443
+ isMultiSelectFilter && (React.createElement(Checkbox, { checked: ((_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : []).includes(value), sx: { mr: '0.5rem' } })),
1444
+ React.createElement(ListItemText, null, text)));
1445
+ })),
1446
+ React.createElement(MRT_FilterOptionMenu, { anchorEl: anchorEl, header: header, setAnchorEl: setAnchorEl, table: table })));
1447
+ };
1448
+
1449
+ const MRT_FilterRangeFields = ({ header, table }) => {
1450
+ return (React.createElement(Box, { sx: { display: 'grid', gridTemplateColumns: '6fr 6fr', gap: '1rem' } },
1451
+ React.createElement(MRT_FilterTextField, { header: header, rangeFilterIndex: 0, table: table }),
1452
+ React.createElement(MRT_FilterTextField, { header: header, rangeFilterIndex: 1, table: table })));
1453
+ };
1454
+
1455
+ const MRT_TableHeadCellFilterContainer = ({ header, table, }) => {
1456
+ const { getState } = table;
1457
+ const { columnFilterFns, showColumnFilters } = getState();
1458
+ const { column } = header;
1459
+ return (React.createElement(Collapse, { in: showColumnFilters, mountOnEnter: true, unmountOnExit: true }, ['between', 'betweenInclusive', 'inNumberRange'].includes(columnFilterFns[column.id]) ? (React.createElement(MRT_FilterRangeFields, { header: header, table: table })) : (React.createElement(MRT_FilterTextField, { header: header, table: table }))));
1460
+ };
1461
+
1462
+ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1463
+ var _a, _b, _c;
1464
+ const { getState, options: { icons: { FilterAltIcon }, localization, }, } = table;
1465
+ const { columnFilterFns } = getState();
1466
+ const { column } = header;
1467
+ const { columnDef } = column;
1468
+ const isRangeFilter = [
1469
+ 'between',
1470
+ 'betweenInclusive',
1471
+ 'inNumberRange',
1472
+ ].includes(columnDef._filterFn);
1473
+ const currentFilterOption = columnFilterFns === null || columnFilterFns === void 0 ? void 0 : columnFilterFns[header.id];
1474
+ const filterTooltip = localization.filteringByColumn
1475
+ .replace('{column}', String(columnDef.header))
1476
+ .replace('{filterType}',
1477
+ // @ts-ignore
1478
+ localization[`filter${((_a = currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.charAt(0)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) +
1479
+ (currentFilterOption === null || currentFilterOption === void 0 ? void 0 : currentFilterOption.slice(1))}`])
1480
+ .replace('{filterValue}', `"${Array.isArray(column.getFilterValue())
1481
+ ? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1482
+ : column.getFilterValue()}"`)
1483
+ .replace('" "', '');
1484
+ return (React.createElement(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && isRangeFilter) ||
1485
+ (!isRangeFilter && // @ts-ignore
1486
+ (!!((_b = column.getFilterValue()) === null || _b === void 0 ? void 0 : _b[0]) || !!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[1]))) },
1487
+ React.createElement("span", null,
1488
+ React.createElement(Tooltip, { arrow: true, placement: "top", title: filterTooltip },
1489
+ React.createElement(IconButton, { disableRipple: true, onClick: (event) => {
1490
+ event.stopPropagation();
1491
+ }, size: "small", sx: {
1492
+ m: 0,
1493
+ opacity: 0.8,
1494
+ p: '2px',
1495
+ transform: 'scale(0.66)',
1496
+ width: '1.5ch',
1497
+ } },
1498
+ React.createElement(FilterAltIcon, null))))));
1499
+ };
1500
+
1501
+ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1502
+ const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setCurrentDraggingColumn, setCurrentHoveredColumn, } = table;
1503
+ const { columnDef } = column;
1504
+ const { currentHoveredColumn, currentDraggingColumn, columnOrder } = getState();
1505
+ const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
1506
+ ? muiTableHeadCellDragHandleProps({ column, table })
1507
+ : muiTableHeadCellDragHandleProps;
1508
+ const mcIconButtonProps = columnDef.muiTableHeadCellDragHandleProps instanceof Function
1509
+ ? columnDef.muiTableHeadCellDragHandleProps({ column, table })
1510
+ : columnDef.muiTableHeadCellDragHandleProps;
1511
+ const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
1512
+ const handleDragStart = (e) => {
1513
+ setCurrentDraggingColumn(column);
1514
+ e.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1515
+ };
1516
+ const handleDragEnd = (event) => {
1517
+ onColumnDrop === null || onColumnDrop === void 0 ? void 0 : onColumnDrop({
1518
+ event,
1519
+ draggedColumn: column,
1520
+ targetColumn: currentHoveredColumn,
1521
+ });
1522
+ if ((currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone') {
1523
+ column.toggleGrouping();
1524
+ }
1525
+ else if (enableColumnOrdering &&
1526
+ currentHoveredColumn &&
1527
+ (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) !== (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id)) {
1528
+ setColumnOrder(reorderColumn(column, currentHoveredColumn, columnOrder));
1529
+ }
1530
+ setCurrentDraggingColumn(null);
1531
+ setCurrentHoveredColumn(null);
1532
+ };
1533
+ return (React.createElement(MRT_GrabHandleButton, { iconButtonProps: iconButtonProps, onDragStart: handleDragStart, onDragEnd: handleDragEnd, table: table }));
1534
+ };
1535
+
1536
+ const MRT_TableHeadCellResizeHandle = ({ header, table }) => {
1537
+ var _a;
1538
+ const { getState, options: { columnResizeMode }, } = table;
1539
+ const { density, showColumnFilters } = getState();
1540
+ const { column } = header;
1541
+ const { columnDef } = column;
1542
+ const { columnDefType } = columnDef;
1543
+ return (React.createElement(Divider, { flexItem: true, orientation: "vertical", onDoubleClick: () => column.resetSize(), sx: (theme) => ({
1544
+ borderRadius: '2px',
1545
+ borderRightWidth: '2px',
1546
+ cursor: 'col-resize',
1547
+ height: showColumnFilters && columnDefType === 'data' ? '4rem' : '2rem',
1548
+ mr: density === 'compact' ? '-0.5rem' : '-1rem',
1549
+ opacity: 0.8,
1550
+ position: 'absolute',
1551
+ right: '1px',
1552
+ touchAction: 'none',
1553
+ transition: column.getIsResizing() ? undefined : 'all 0.2s ease-in-out',
1554
+ userSelect: 'none',
1555
+ zIndex: 4,
1556
+ '&:active': {
1557
+ backgroundColor: theme.palette.info.main,
1558
+ opacity: 1,
1559
+ },
1560
+ }), onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), style: {
1561
+ transform: column.getIsResizing()
1562
+ ? `translateX(${((_a = getState().columnSizingInfo.deltaOffset) !== null && _a !== void 0 ? _a : 0) /
1563
+ (columnResizeMode === 'onChange' ? 16 : 1)}px)`
1564
+ : 'none',
1565
+ } }));
1566
+ };
1567
+
1568
+ const MRT_TableHeadCellSortLabel = ({ header, table }) => {
1569
+ const { options: { localization }, } = table;
1570
+ const { column } = header;
1571
+ const { columnDef } = column;
1572
+ const sortTooltip = !!column.getIsSorted()
1573
+ ? column.getIsSorted() === 'desc'
1574
+ ? localization.sortedByColumnDesc.replace('{column}', columnDef.header)
1575
+ : localization.sortedByColumnAsc.replace('{column}', columnDef.header)
1576
+ : localization.unsorted;
1577
+ return (React.createElement(Tooltip, { arrow: true, placement: "top", title: sortTooltip },
1578
+ React.createElement(TableSortLabel, { "aria-label": sortTooltip, active: !!column.getIsSorted(), direction: column.getIsSorted()
1579
+ ? column.getIsSorted()
1580
+ : undefined, sx: {
1581
+ width: '2ch',
1582
+ transform: 'translateX(-0.5ch)',
1583
+ } })));
1584
+ };
1585
+
1586
+ const MRT_TableHeadCell = ({ header, table }) => {
1587
+ var _a, _b, _c, _d;
1588
+ const theme = useTheme();
1589
+ const { getState, options: { enableColumnActions, enableColumnDragging, enableColumnOrdering, enableColumnResizing, enableGrouping, enableMultiSort, muiTableHeadCellProps, }, setCurrentHoveredColumn, } = table;
1590
+ const { density, currentDraggingColumn, currentHoveredColumn, showColumnFilters, } = getState();
1591
+ const { column } = header;
1592
+ const { columnDef } = column;
1593
+ const { columnDefType } = columnDef;
1594
+ const mTableHeadCellProps = muiTableHeadCellProps instanceof Function
1595
+ ? muiTableHeadCellProps({ column, table })
1596
+ : muiTableHeadCellProps;
1597
+ const mcTableHeadCellProps = columnDef.muiTableHeadCellProps instanceof Function
1598
+ ? columnDef.muiTableHeadCellProps({ column, table })
1599
+ : columnDef.muiTableHeadCellProps;
1600
+ const tableCellProps = Object.assign(Object.assign({}, mTableHeadCellProps), mcTableHeadCellProps);
1601
+ const getIsLastLeftPinnedColumn = () => {
1602
+ return (column.getIsPinned() === 'left' &&
1603
+ table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
1604
+ };
1605
+ const getIsFirstRightPinnedColumn = () => {
1606
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
1607
+ };
1608
+ const getTotalRight = () => {
1609
+ return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 150);
1610
+ };
1611
+ const handleDragEnter = (_e) => {
1612
+ if (enableGrouping && (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone') {
1613
+ setCurrentHoveredColumn(null);
1614
+ }
1615
+ if (enableColumnOrdering && currentDraggingColumn) {
1616
+ setCurrentHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1617
+ }
1618
+ };
1619
+ const draggingBorder = (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1620
+ ? `1px dashed ${theme.palette.text.secondary}`
1621
+ : (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1622
+ ? `2px dashed ${theme.palette.primary.main}`
1623
+ : undefined;
1624
+ const draggingBorders = draggingBorder
1625
+ ? {
1626
+ borderLeft: draggingBorder,
1627
+ borderRight: draggingBorder,
1628
+ borderTop: draggingBorder,
1629
+ }
1630
+ : undefined;
1631
+ const headerElement = ((_b = ((columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) instanceof Function
1632
+ ? (_a = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
1633
+ column,
1634
+ header,
1635
+ table,
1636
+ })
1637
+ : columnDef === null || columnDef === void 0 ? void 0 : columnDef.Header)) !== null && _b !== void 0 ? _b : columnDef.header);
1638
+ const tableHeadCellRef = React.useRef(null);
1639
+ return (React.createElement(TableCell, Object.assign({ align: columnDefType === 'group' ? 'center' : 'left', colSpan: header.colSpan, onDragEnter: handleDragEnter, ref: tableHeadCellRef }, tableCellProps, { sx: (theme) => {
1640
+ var _a;
1641
+ return (Object.assign(Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && columnDefType !== 'group'
1642
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
1643
+ : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn()
1644
+ ? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
1645
+ : getIsFirstRightPinnedColumn()
1646
+ ? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
1647
+ : undefined, fontWeight: 'bold', left: column.getIsPinned() === 'left'
1648
+ ? `${column.getStart('left')}px`
1649
+ : undefined, overflow: 'visible', opacity: (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id ||
1650
+ (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1651
+ ? 0.5
1652
+ : 1, p: density === 'compact'
1653
+ ? '0.5rem'
1654
+ : density === 'comfortable'
1655
+ ? columnDefType === 'display'
1656
+ ? '0.75rem'
1657
+ : '1rem'
1658
+ : columnDefType === 'display'
1659
+ ? '1rem 1.25rem'
1660
+ : '1.5rem', pb: columnDefType === 'display'
1661
+ ? 0
1662
+ : showColumnFilters || density === 'compact'
1663
+ ? '0.4rem'
1664
+ : '0.6rem', position: column.getIsPinned() && columnDefType !== 'group'
1665
+ ? 'sticky'
1666
+ : undefined, pt: columnDefType === 'group'
1667
+ ? 0
1668
+ : density === 'compact'
1669
+ ? '0.25'
1670
+ : density === 'comfortable'
1671
+ ? '.75rem'
1672
+ : '1.25rem', right: column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined, transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`, userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined, verticalAlign: 'top', zIndex: column.getIsResizing() || (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1673
+ ? 3
1674
+ : column.getIsPinned() && columnDefType !== 'group'
1675
+ ? 2
1676
+ : 1 }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
1677
+ ? tableCellProps.sx(theme)
1678
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), draggingBorders), { maxWidth: `min(${column.getSize()}px, fit-content)`, minWidth: `max(${column.getSize()}px, ${(_a = columnDef.minSize) !== null && _a !== void 0 ? _a : 30}px)`, width: header.getSize() }));
1679
+ } }),
1680
+ header.isPlaceholder ? null : (React.createElement(Box, { sx: {
1681
+ alignItems: 'flex-start',
1682
+ display: 'flex',
1683
+ justifyContent: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'right'
1684
+ ? 'flex-end'
1685
+ : columnDefType === 'group' ||
1686
+ (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center'
1687
+ ? 'center'
1688
+ : 'space-between',
1689
+ position: 'relative',
1690
+ width: '100%',
1691
+ } },
1692
+ React.createElement(Box, { onClick: column.getToggleSortingHandler(), sx: {
1693
+ alignItems: 'center',
1694
+ cursor: column.getCanSort() && columnDefType !== 'group'
1695
+ ? 'pointer'
1696
+ : undefined,
1697
+ display: 'flex',
1698
+ flexWrap: 'nowrap',
1699
+ m: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center' ? 'auto' : undefined,
1700
+ pl: (tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.align) === 'center' && column.getCanSort()
1701
+ ? '1rem'
1702
+ : undefined,
1703
+ whiteSpace: ((_d = (_c = columnDef.header) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) < 24 ? 'nowrap' : 'normal',
1704
+ } },
1705
+ headerElement,
1706
+ column.getCanSort() && (React.createElement(MRT_TableHeadCellSortLabel, { header: header, table: table })),
1707
+ column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterLabel, { header: header, table: table }))),
1708
+ columnDefType !== 'group' && (React.createElement(Box, { sx: { whiteSpace: 'nowrap' } },
1709
+ ((enableColumnDragging &&
1710
+ columnDef.enableColumnDragging !== false) ||
1711
+ (enableColumnOrdering &&
1712
+ columnDef.enableColumnOrdering !== false) ||
1713
+ (enableGrouping && columnDef.enableGrouping !== false)) && (React.createElement(MRT_TableHeadCellGrabHandle, { column: column, table: table, tableHeadCellRef: tableHeadCellRef })),
1714
+ (enableColumnActions || columnDef.enableColumnActions) &&
1715
+ columnDef.enableColumnActions !== false && (React.createElement(MRT_TableHeadCellColumnActionsButton, { header: header, table: table })))),
1716
+ column.getCanResize() && (React.createElement(MRT_TableHeadCellResizeHandle, { header: header, table: table })))),
1717
+ column.getCanFilter() && (React.createElement(MRT_TableHeadCellFilterContainer, { header: header, table: table }))));
1718
+ };
1719
+
1720
+ const MRT_TableHeadRow = ({ headerGroup, table }) => {
1721
+ const { options: { muiTableHeadRowProps }, } = table;
1722
+ const tableRowProps = muiTableHeadRowProps instanceof Function
1723
+ ? muiTableHeadRowProps({ headerGroup, table })
1724
+ : muiTableHeadRowProps;
1725
+ return (React.createElement(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`, backgroundColor: lighten(theme.palette.background.default, 0.04) }, tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)) }), headerGroup.headers.map((header, index) => (React.createElement(MRT_TableHeadCell, { header: header, key: header.id || index, table: table })))));
1726
+ };
1727
+
1728
+ const MRT_TableHead = ({ table }) => {
1729
+ const { getHeaderGroups, options: { muiTableHeadProps }, } = table;
1730
+ const tableHeadProps = muiTableHeadProps instanceof Function
1731
+ ? muiTableHeadProps({ table })
1732
+ : muiTableHeadProps;
1733
+ return (React.createElement(TableHead, Object.assign({}, tableHeadProps), getHeaderGroups().map((headerGroup) => (React.createElement(MRT_TableHeadRow, { headerGroup: headerGroup, key: headerGroup.id, table: table })))));
1734
+ };
1735
+
1736
+ const MRT_EditCellTextField = ({ cell, table }) => {
1737
+ var _a;
1738
+ const { getState, options: { tableId, enableEditing, muiTableBodyCellEditTextFieldProps, onCellEditBlur, onCellEditChange, }, setCurrentEditingCell, setCurrentEditingRow, } = table;
1739
+ const { column, row } = cell;
1740
+ const { columnDef } = column;
1741
+ const [value, setValue] = useState(cell.getValue());
1742
+ const handleChange = (event) => {
1743
+ var _a;
1744
+ setValue(event.target.value);
1745
+ (_a = columnDef.onCellEditChange) === null || _a === void 0 ? void 0 : _a.call(columnDef, { event, cell, table });
1746
+ onCellEditChange === null || onCellEditChange === void 0 ? void 0 : onCellEditChange({ event, cell, table });
1747
+ };
1748
+ const handleBlur = (event) => {
1749
+ var _a;
1750
+ if (getState().currentEditingRow) {
1751
+ if (!row._valuesCache)
1752
+ row._valuesCache = {};
1753
+ row._valuesCache[column.id] = value;
1754
+ setCurrentEditingRow(Object.assign({}, getState().currentEditingRow));
1755
+ }
1756
+ setCurrentEditingCell(null);
1757
+ (_a = columnDef.onCellEditBlur) === null || _a === void 0 ? void 0 : _a.call(columnDef, { event, cell, table });
1758
+ onCellEditBlur === null || onCellEditBlur === void 0 ? void 0 : onCellEditBlur({ event, cell, table });
1759
+ };
1760
+ const mTableBodyCellEditTextFieldProps = muiTableBodyCellEditTextFieldProps instanceof Function
1761
+ ? muiTableBodyCellEditTextFieldProps({ cell, table })
1762
+ : muiTableBodyCellEditTextFieldProps;
1763
+ const mcTableBodyCellEditTextFieldProps = columnDef.muiTableBodyCellEditTextFieldProps instanceof Function
1764
+ ? columnDef.muiTableBodyCellEditTextFieldProps({
1765
+ cell,
1766
+ table,
1767
+ })
1768
+ : columnDef.muiTableBodyCellEditTextFieldProps;
1769
+ const textFieldProps = Object.assign(Object.assign({}, mTableBodyCellEditTextFieldProps), mcTableBodyCellEditTextFieldProps);
1770
+ if (enableEditing && columnDef.enableEditing !== false && columnDef.Edit) {
1771
+ return React.createElement(React.Fragment, null, (_a = columnDef.Edit) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, table }));
1772
+ }
1773
+ return (React.createElement(TextField, Object.assign({ id: `mrt-${tableId}-edit-cell-text-field-${cell.id}`, margin: "dense", onBlur: handleBlur, onChange: handleChange, onClick: (e) => e.stopPropagation(), placeholder: columnDef.header, value: value, variant: "standard" }, textFieldProps)));
1774
+ };
1775
+
1776
+ const MRT_CopyButton = ({ cell, children, table }) => {
1777
+ const { options: { localization, muiTableBodyCellCopyButtonProps }, } = table;
1778
+ const { column } = cell;
1779
+ const { columnDef } = column;
1780
+ const [copied, setCopied] = useState(false);
1781
+ const handleCopy = (text) => {
1782
+ navigator.clipboard.writeText(text);
1783
+ setCopied(true);
1784
+ setTimeout(() => setCopied(false), 4000);
1785
+ };
1786
+ const mTableBodyCellCopyButtonProps = muiTableBodyCellCopyButtonProps instanceof Function
1787
+ ? muiTableBodyCellCopyButtonProps({ cell, table })
1788
+ : muiTableBodyCellCopyButtonProps;
1789
+ const mcTableBodyCellCopyButtonProps = columnDef.muiTableBodyCellCopyButtonProps instanceof Function
1790
+ ? columnDef.muiTableBodyCellCopyButtonProps({
1791
+ cell,
1792
+ table,
1793
+ })
1794
+ : columnDef.muiTableBodyCellCopyButtonProps;
1795
+ const buttonProps = Object.assign(Object.assign({}, mTableBodyCellCopyButtonProps), mcTableBodyCellCopyButtonProps);
1796
+ return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: copied ? localization.copiedToClipboard : localization.clickToCopy },
1797
+ React.createElement(Button, Object.assign({ onClick: () => handleCopy(cell.getValue()), size: "small", type: "button", variant: "text" }, buttonProps, { sx: (theme) => (Object.assign({ backgroundColor: 'transparent', border: 'none', color: 'inherit', cursor: 'copy', fontFamily: 'inherit', fontSize: 'inherit', letterSpacing: 'inherit', m: '-0.25rem', minWidth: 'unset', textAlign: 'inherit', textTransform: 'inherit' }, ((buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.sx) instanceof Function
1798
+ ? buttonProps.sx(theme)
1799
+ : buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.sx))) }), children)));
1800
+ };
1801
+
1802
+ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1803
+ const { options: { muiTableBodyRowDragHandleProps, onRowDrop }, } = table;
1804
+ const iconButtonProps = muiTableBodyRowDragHandleProps instanceof Function
1805
+ ? muiTableBodyRowDragHandleProps({ row: cell.row, table })
1806
+ : muiTableBodyRowDragHandleProps;
1807
+ const handleDragStart = (e) => {
1808
+ e.dataTransfer.setDragImage(rowRef.current, 0, 0);
1809
+ table.setCurrentDraggingRow(cell.row);
1810
+ };
1811
+ const handleDragEnd = (event) => {
1812
+ onRowDrop === null || onRowDrop === void 0 ? void 0 : onRowDrop({
1813
+ event,
1814
+ draggedRow: table.getState().currentDraggingRow,
1815
+ targetRow: table.getState().currentHoveredRow,
1816
+ });
1817
+ table.setCurrentDraggingRow(null);
1818
+ table.setCurrentHoveredRow(null);
1819
+ };
1820
+ return (React.createElement(MRT_GrabHandleButton, { iconButtonProps: iconButtonProps, onDragStart: handleDragStart, onDragEnd: handleDragEnd, table: table }));
1821
+ };
1822
+
1823
+ const MRT_TableBodyCell = ({ cell, enableHover, rowIndex, rowRef, table, }) => {
1824
+ var _a, _b, _c, _d, _f, _g, _h, _j;
1825
+ const theme = useTheme();
1826
+ const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enablePagination, enableRowNumbers, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, tableId, }, setCurrentEditingCell, setCurrentHoveredColumn, } = table;
1827
+ const { currentDraggingColumn, currentEditingCell, currentEditingRow, currentHoveredColumn, density, isLoading, showSkeletons, } = getState();
1828
+ const { column, row } = cell;
1829
+ const { columnDef } = column;
1830
+ const { columnDefType } = columnDef;
1831
+ const mTableCellBodyProps = muiTableBodyCellProps instanceof Function
1832
+ ? muiTableBodyCellProps({ cell, table })
1833
+ : muiTableBodyCellProps;
1834
+ const mcTableCellBodyProps = columnDef.muiTableBodyCellProps instanceof Function
1835
+ ? columnDef.muiTableBodyCellProps({ cell, table })
1836
+ : columnDef.muiTableBodyCellProps;
1837
+ const tableCellProps = Object.assign(Object.assign({}, mTableCellBodyProps), mcTableCellBodyProps);
1838
+ const isEditable = (enableEditing || columnDef.enableEditing) &&
1839
+ columnDef.enableEditing !== false;
1840
+ const isEditing = isEditable &&
1841
+ (editingMode === 'table' ||
1842
+ (currentEditingRow === null || currentEditingRow === void 0 ? void 0 : currentEditingRow.id) === row.id ||
1843
+ (currentEditingCell === null || currentEditingCell === void 0 ? void 0 : currentEditingCell.id) === cell.id);
1844
+ const [skeletonWidth, setSkeletonWidth] = useState(0);
1845
+ useEffect(() => setSkeletonWidth(isLoading || showSkeletons
1846
+ ? columnDefType === 'display'
1847
+ ? column.getSize() / 2
1848
+ : Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
1849
+ column.getSize() / 3)
1850
+ : 100), [isLoading, showSkeletons]);
1851
+ const handleDoubleClick = (_event) => {
1852
+ if ((enableEditing || columnDef.enableEditing) &&
1853
+ columnDef.enableEditing !== false &&
1854
+ editingMode === 'cell') {
1855
+ setCurrentEditingCell(cell);
1856
+ setTimeout(() => {
1857
+ const textField = document.getElementById(`mrt-${tableId}-edit-cell-text-field-${cell.id}`);
1858
+ if (textField) {
1859
+ textField.focus();
1860
+ textField.select();
1861
+ }
1862
+ }, 200);
1863
+ }
1864
+ };
1865
+ const getIsLastLeftPinnedColumn = () => {
1866
+ return (column.getIsPinned() === 'left' &&
1867
+ table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
1868
+ };
1869
+ const getIsFirstRightPinnedColumn = () => {
1870
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
1871
+ };
1872
+ const getTotalRight = () => {
1873
+ return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 150);
1874
+ };
1875
+ const handleDragEnter = (_e) => {
1876
+ if (enableGrouping && (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === 'drop-zone') {
1877
+ setCurrentHoveredColumn(null);
1878
+ }
1879
+ if (enableColumnOrdering && currentDraggingColumn) {
1880
+ setCurrentHoveredColumn(columnDef.enableColumnOrdering !== false ? column : null);
1881
+ }
1882
+ };
1883
+ const draggingBorder = (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1884
+ ? `1px dashed ${theme.palette.text.secondary}`
1885
+ : (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1886
+ ? `2px dashed ${theme.palette.primary.main}`
1887
+ : undefined;
1888
+ const draggingBorders = draggingBorder
1889
+ ? {
1890
+ borderLeft: draggingBorder,
1891
+ borderRight: draggingBorder,
1892
+ borderBottom: row.index ===
1893
+ (enablePagination
1894
+ ? table.getRowModel()
1895
+ : table.getPrePaginationRowModel()).rows.length -
1896
+ 1
1897
+ ? draggingBorder
1898
+ : undefined,
1899
+ }
1900
+ : undefined;
1901
+ return (React.createElement(TableCell, Object.assign({ onDoubleClick: handleDoubleClick, onDragEnter: handleDragEnter }, tableCellProps, { sx: (theme) => {
1902
+ var _a;
1903
+ return (Object.assign(Object.assign(Object.assign({ backgroundColor: column.getIsPinned()
1904
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
1905
+ : undefined, boxShadow: getIsLastLeftPinnedColumn()
1906
+ ? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
1907
+ : getIsFirstRightPinnedColumn()
1908
+ ? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
1909
+ : undefined, cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text', left: column.getIsPinned() === 'left'
1910
+ ? `${column.getStart('left')}px`
1911
+ : undefined, opacity: (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id ||
1912
+ (currentHoveredColumn === null || currentHoveredColumn === void 0 ? void 0 : currentHoveredColumn.id) === column.id
1913
+ ? 0.5
1914
+ : 1, overflow: 'hidden', p: density === 'compact'
1915
+ ? columnDefType === 'display'
1916
+ ? '0 0.5rem'
1917
+ : '0.5rem'
1918
+ : density === 'comfortable'
1919
+ ? columnDefType === 'display'
1920
+ ? '0.5rem 0.75rem'
1921
+ : '1rem'
1922
+ : columnDefType === 'display'
1923
+ ? '1rem 1.25rem'
1924
+ : '1.5rem', pl: column.id === 'mrt-row-expand'
1925
+ ? `${row.depth +
1926
+ (density === 'compact'
1927
+ ? 0.5
1928
+ : density === 'comfortable'
1929
+ ? 0.75
1930
+ : 1.25)}rem`
1931
+ : undefined, position: column.getIsPinned() ? 'sticky' : 'relative', right: column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined, textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined, transition: 'all 0.2s ease-in-out', whiteSpace: density === 'compact' ? 'nowrap' : 'normal', zIndex: (currentDraggingColumn === null || currentDraggingColumn === void 0 ? void 0 : currentDraggingColumn.id) === column.id
1932
+ ? 2
1933
+ : column.getIsPinned()
1934
+ ? 1
1935
+ : undefined, '&:hover': {
1936
+ backgroundColor: enableHover && enableEditing && editingMode !== 'row'
1937
+ ? theme.palette.mode === 'dark'
1938
+ ? `${lighten(theme.palette.background.default, 0.13)} !important`
1939
+ : `${darken(theme.palette.background.default, 0.07)} !important`
1940
+ : undefined,
1941
+ } }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
1942
+ ? tableCellProps.sx(theme)
1943
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), draggingBorders), { maxWidth: `min(${column.getSize()}px, fit-content)`, minWidth: `max(${column.getSize()}px, ${(_a = columnDef.minSize) !== null && _a !== void 0 ? _a : 30}px)`, width: column.getSize() }));
1944
+ } }),
1945
+ React.createElement(React.Fragment, null, cell.getIsPlaceholder() ? null : isLoading || showSkeletons ? (React.createElement(Skeleton, Object.assign({ animation: "wave", height: 20, width: skeletonWidth }, muiTableBodyCellSkeletonProps))) : enableRowNumbers &&
1946
+ rowNumberMode === 'static' &&
1947
+ column.id === 'mrt-row-numbers' ? (rowIndex + 1) : column.id === 'mrt-row-drag' ? (React.createElement(MRT_TableBodyRowGrabHandle, { cell: cell, rowRef: rowRef, table: table })) : columnDefType === 'display' ? ((_a = columnDef.Cell) === null || _a === void 0 ? void 0 : _a.call(columnDef, { cell, column, table })) : isEditing ? (React.createElement(MRT_EditCellTextField, { cell: cell, table: table })) : (enableClickToCopy || columnDef.enableClickToCopy) &&
1948
+ columnDef.enableClickToCopy !== false ? (React.createElement(React.Fragment, null,
1949
+ React.createElement(MRT_CopyButton, { cell: cell, table: table },
1950
+ React.createElement(React.Fragment, null, (_c = (_b = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _b === void 0 ? void 0 : _b.call(columnDef, { cell, column, table })) !== null && _c !== void 0 ? _c : cell.renderValue())),
1951
+ cell.getIsGrouped() && React.createElement(React.Fragment, null,
1952
+ " (", (_d = row.subRows) === null || _d === void 0 ? void 0 :
1953
+ _d.length,
1954
+ ")"))) : (React.createElement(React.Fragment, null, (_g = (_f = columnDef === null || columnDef === void 0 ? void 0 : columnDef.Cell) === null || _f === void 0 ? void 0 : _f.call(columnDef, { cell, column, table })) !== null && _g !== void 0 ? _g : cell.renderValue(),
1955
+ cell.getIsGrouped() && React.createElement(React.Fragment, null,
1956
+ " (", (_j = (_h = row.subRows) === null || _h === void 0 ? void 0 : _h.length) !== null && _j !== void 0 ? _j : '',
1957
+ ")"))))));
1958
+ };
1959
+
1960
+ const MRT_TableDetailPanel = ({ row, table }) => {
1961
+ const { getVisibleLeafColumns, options: { muiTableBodyRowProps, muiTableDetailPanelProps, renderDetailPanel, }, } = table;
1962
+ const tableRowProps = muiTableBodyRowProps instanceof Function
1963
+ ? muiTableBodyRowProps({ row, table })
1964
+ : muiTableBodyRowProps;
1965
+ const tableCellProps = muiTableDetailPanelProps instanceof Function
1966
+ ? muiTableDetailPanelProps({ row, table })
1967
+ : muiTableDetailPanelProps;
1968
+ return (React.createElement(TableRow, Object.assign({}, tableRowProps),
1969
+ React.createElement(TableCell, Object.assign({ colSpan: getVisibleLeafColumns().length }, tableCellProps, { sx: (theme) => (Object.assign({ borderBottom: !row.getIsExpanded() ? 'none' : undefined, pb: row.getIsExpanded() ? '1rem' : 0, pt: row.getIsExpanded() ? '1rem' : 0, transition: 'all 0.2s ease-in-out', width: `${table.getTotalSize()}px` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
1970
+ ? tableCellProps.sx(theme)
1971
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }), renderDetailPanel && (React.createElement(Collapse, { in: row.getIsExpanded() }, renderDetailPanel({ row, table }))))));
1972
+ };
1973
+
1974
+ const MRT_TableBodyRow = ({ row, rowIndex, table }) => {
1975
+ var _a, _b;
1976
+ const theme = useTheme();
1977
+ const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, muiTableBodyRowProps, renderDetailPanel }, setCurrentHoveredRow, } = table;
1978
+ const { currentDraggingRow, currentHoveredRow } = getState();
1979
+ const tableRowProps = muiTableBodyRowProps instanceof Function
1980
+ ? muiTableBodyRowProps({ row, table })
1981
+ : muiTableBodyRowProps;
1982
+ const handleDragEnter = (_e) => {
1983
+ if (enableRowOrdering && currentDraggingRow) {
1984
+ setCurrentHoveredRow(row);
1985
+ }
1986
+ };
1987
+ const rowRef = useRef(null);
1988
+ const draggingBorder = (currentDraggingRow === null || currentDraggingRow === void 0 ? void 0 : currentDraggingRow.id) === row.id
1989
+ ? `1px dashed ${theme.palette.text.secondary}`
1990
+ : (currentHoveredRow === null || currentHoveredRow === void 0 ? void 0 : currentHoveredRow.id) === row.id
1991
+ ? `2px dashed ${theme.palette.primary.main}`
1992
+ : undefined;
1993
+ const draggingBorders = draggingBorder
1994
+ ? {
1995
+ border: draggingBorder,
1996
+ }
1997
+ : undefined;
1998
+ return (React.createElement(React.Fragment, null,
1999
+ React.createElement(TableRow, Object.assign({ onDragEnter: handleDragEnter, hover: true, selected: row.getIsSelected(), ref: rowRef }, tableRowProps, { sx: (theme) => (Object.assign(Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.06), opacity: (currentDraggingRow === null || currentDraggingRow === void 0 ? void 0 : currentDraggingRow.id) === row.id ||
2000
+ (currentHoveredRow === null || currentHoveredRow === void 0 ? void 0 : currentHoveredRow.id) === row.id
2001
+ ? 0.5
2002
+ : 1, transition: 'all 0.2s ease-in-out', '&:hover td': {
2003
+ backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned()
2004
+ ? theme.palette.mode === 'dark'
2005
+ ? `${lighten(theme.palette.background.default, 0.12)}`
2006
+ : `${darken(theme.palette.background.default, 0.05)}`
2007
+ : undefined,
2008
+ } }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
2009
+ ? tableRowProps.sx(theme)
2010
+ : tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx)), draggingBorders)) }), (_b = (_a = row === null || row === void 0 ? void 0 : row.getVisibleCells()) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (cell) => (React.createElement(MRT_TableBodyCell, { cell: cell, key: cell.id, enableHover: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false, rowIndex: rowIndex, rowRef: rowRef, table: table })))),
2011
+ renderDetailPanel && !row.getIsGrouped() && (React.createElement(MRT_TableDetailPanel, { row: row, table: table }))));
2012
+ };
2013
+
2014
+ const MRT_TableBody = ({ table, tableContainerRef }) => {
2015
+ const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, muiTableBodyProps, virtualizerProps, }, } = table;
2016
+ const { density, globalFilter, pagination, sorting } = getState();
2017
+ const tableBodyProps = muiTableBodyProps instanceof Function
2018
+ ? muiTableBodyProps({ table })
2019
+ : muiTableBodyProps;
2020
+ const vProps = virtualizerProps instanceof Function
2021
+ ? virtualizerProps({ table })
2022
+ : virtualizerProps;
2023
+ const rows = useMemo(() => {
2024
+ if (enableGlobalFilterRankedResults &&
2025
+ globalFilter &&
2026
+ !Object.values(sorting).some(Boolean)) {
2027
+ const rankedRows = getPrePaginationRowModel().rows.sort((a, b) => rankGlobalFuzzy(a, b));
2028
+ if (enablePagination) {
2029
+ return rankedRows.slice(pagination.pageIndex, pagination.pageSize);
2030
+ }
2031
+ return rankedRows;
2032
+ }
2033
+ return enablePagination
2034
+ ? getRowModel().rows
2035
+ : getPrePaginationRowModel().rows;
2036
+ }, [
2037
+ enableGlobalFilterRankedResults,
2038
+ (enableGlobalFilterRankedResults && globalFilter) || !enablePagination
2039
+ ? getPrePaginationRowModel().rows
2040
+ : getRowModel().rows,
2041
+ globalFilter,
2042
+ ]);
2043
+ const rowVirtualizer = enableRowVirtualization
2044
+ ? useVirtualizer(Object.assign({ count: rows.length, estimateSize: () => (density === 'compact' ? 20 : 50), getScrollElement: () => tableContainerRef.current, overscan: 10 }, vProps))
2045
+ : {};
2046
+ const virtualRows = enableRowVirtualization
2047
+ ? rowVirtualizer.getVirtualItems()
2048
+ : [];
2049
+ let paddingTop = 0;
2050
+ let paddingBottom = 0;
2051
+ if (enableRowVirtualization) {
2052
+ paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
2053
+ paddingBottom = !!virtualRows.length
2054
+ ? rowVirtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
2055
+ : 0;
2056
+ }
2057
+ return (React.createElement(TableBody, Object.assign({}, tableBodyProps),
2058
+ enableRowVirtualization && paddingTop > 0 && (React.createElement("tr", null,
2059
+ React.createElement("td", { style: { height: `${paddingTop}px` } }))),
2060
+ (enableRowVirtualization ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
2061
+ const row = enableRowVirtualization
2062
+ ? rows[rowOrVirtualRow.index]
2063
+ : rowOrVirtualRow;
2064
+ return (React.createElement(MRT_TableBodyRow, { key: row.id, row: row, rowIndex: enableRowVirtualization ? rowOrVirtualRow.index : rowIndex, table: table }));
2065
+ }),
2066
+ enableRowVirtualization && paddingBottom > 0 && (React.createElement("tr", null,
2067
+ React.createElement("td", { style: { height: `${paddingBottom}px` } })))));
2068
+ };
2069
+
2070
+ const MRT_TableFooterCell = ({ footer, table }) => {
2071
+ var _a, _b, _c;
2072
+ const { getState, options: { muiTableFooterCellProps, enableColumnResizing }, } = table;
2073
+ const { density } = getState();
2074
+ const { column } = footer;
2075
+ const { columnDef } = column;
2076
+ const { columnDefType } = columnDef;
2077
+ const mTableFooterCellProps = muiTableFooterCellProps instanceof Function
2078
+ ? muiTableFooterCellProps({ column, table })
2079
+ : muiTableFooterCellProps;
2080
+ const mcTableFooterCellProps = columnDef.muiTableFooterCellProps instanceof Function
2081
+ ? columnDef.muiTableFooterCellProps({ column, table })
2082
+ : columnDef.muiTableFooterCellProps;
2083
+ const tableCellProps = Object.assign(Object.assign({}, mTableFooterCellProps), mcTableFooterCellProps);
2084
+ return (React.createElement(TableCell, Object.assign({ align: columnDefType === 'group' ? 'center' : 'left', colSpan: footer.colSpan, variant: "head" }, tableCellProps, { sx: (theme) => (Object.assign({ backgroundColor: theme.palette.background.default, backgroundImage: `linear-gradient(${alpha(theme.palette.common.white, 0.05)},${alpha(theme.palette.common.white, 0.05)})`, fontWeight: 'bold', maxWidth: `${column.getSize()}px`, minWidth: `${column.getSize()}px`, p: density === 'compact'
2085
+ ? '0.5rem'
2086
+ : density === 'comfortable'
2087
+ ? '1rem'
2088
+ : '1.5rem', transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`, width: column.getSize(), verticalAlign: 'text-top' }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
2089
+ ? tableCellProps.sx(theme)
2090
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx))) }),
2091
+ React.createElement(React.Fragment, null, footer.isPlaceholder
2092
+ ? null
2093
+ : (_c = (_b = (columnDef.Footer instanceof Function
2094
+ ? (_a = columnDef.Footer) === null || _a === void 0 ? void 0 : _a.call(columnDef, {
2095
+ column,
2096
+ footer,
2097
+ table,
2098
+ })
2099
+ : columnDef.Footer)) !== null && _b !== void 0 ? _b : columnDef.footer) !== null && _c !== void 0 ? _c : null)));
2100
+ };
2101
+
2102
+ const MRT_TableFooterRow = ({ footerGroup, table }) => {
2103
+ var _a;
2104
+ const { options: { muiTableFooterRowProps }, } = table;
2105
+ // if no content in row, skip row
2106
+ if (!((_a = footerGroup.headers) === null || _a === void 0 ? void 0 : _a.some((header) => (typeof header.column.columnDef.footer === 'string' &&
2107
+ !!header.column.columnDef.footer) ||
2108
+ header.column.columnDef.Footer)))
2109
+ return null;
2110
+ const tableRowProps = muiTableFooterRowProps instanceof Function
2111
+ ? muiTableFooterRowProps({ footerGroup, table })
2112
+ : muiTableFooterRowProps;
2113
+ return (React.createElement(TableRow, Object.assign({}, tableRowProps), footerGroup.headers.map((footer) => (React.createElement(MRT_TableFooterCell, { footer: footer, key: footer.id, table: table })))));
2114
+ };
2115
+
2116
+ const MRT_TableFooter = ({ table }) => {
2117
+ const { getFooterGroups, options: { muiTableFooterProps }, } = table;
2118
+ const tableFooterProps = muiTableFooterProps instanceof Function
2119
+ ? muiTableFooterProps({ table })
2120
+ : muiTableFooterProps;
2121
+ return (React.createElement(TableFooter, Object.assign({}, tableFooterProps), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2122
+ };
2123
+
2124
+ const MRT_Table = ({ tableContainerRef, table }) => {
2125
+ const { getState, options: { enableColumnResizing, enableRowVirtualization, enableStickyHeader, enableTableFooter, enableTableHead, muiTableProps, }, } = table;
2126
+ const { isFullScreen } = getState();
2127
+ const tableProps = muiTableProps instanceof Function
2128
+ ? muiTableProps({ table })
2129
+ : muiTableProps;
2130
+ return (React.createElement(Table, Object.assign({ stickyHeader: enableStickyHeader || enableRowVirtualization || isFullScreen }, tableProps, { sx: (theme) => (Object.assign({ tableLayout: enableColumnResizing || enableRowVirtualization ? 'fixed' : 'auto' }, ((tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx) instanceof Function
2131
+ ? tableProps.sx(theme)
2132
+ : tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx))) }),
2133
+ enableTableHead && React.createElement(MRT_TableHead, { table: table }),
2134
+ React.createElement(MRT_TableBody, { tableContainerRef: tableContainerRef, table: table }),
2135
+ enableTableFooter && React.createElement(MRT_TableFooter, { table: table })));
2136
+ };
2137
+
2138
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
2139
+ const MRT_TableContainer = ({ table }) => {
2140
+ var _a;
2141
+ const { getState, options: { enableStickyHeader, enableRowVirtualization, muiTableContainerProps, tableId, }, } = table;
2142
+ const { isFullScreen } = getState();
2143
+ const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
2144
+ const tableContainerProps = muiTableContainerProps instanceof Function
2145
+ ? muiTableContainerProps({ table })
2146
+ : muiTableContainerProps;
2147
+ const tableContainerRef = (_a = tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.ref) !== null && _a !== void 0 ? _a : useRef(null);
2148
+ useIsomorphicLayoutEffect(() => {
2149
+ var _a, _b, _c, _d;
2150
+ const topToolbarHeight = typeof document !== 'undefined'
2151
+ ? (_b = (_a = document === null || document === void 0 ? void 0 : document.getElementById(`mrt-${tableId}-toolbar-top`)) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0
2152
+ : 0;
2153
+ const bottomToolbarHeight = typeof document !== 'undefined'
2154
+ ? (_d = (_c = document === null || document === void 0 ? void 0 : document.getElementById(`mrt-${tableId}-toolbar-bottom`)) === null || _c === void 0 ? void 0 : _c.offsetHeight) !== null && _d !== void 0 ? _d : 0
2155
+ : 0;
2156
+ setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
2157
+ });
2158
+ return (React.createElement(TableContainer, Object.assign({ ref: tableContainerRef }, tableContainerProps, { sx: (theme) => (Object.assign({ maxWidth: '100%', maxHeight: enableStickyHeader || enableRowVirtualization
2159
+ ? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
2160
+ : undefined, overflow: 'auto' }, ((tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx) instanceof Function
2161
+ ? tableContainerProps.sx(theme)
2162
+ : tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx))), style: Object.assign({ maxHeight: isFullScreen
2163
+ ? `calc(100vh - ${totalToolbarHeight}px)`
2164
+ : undefined }, tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.style) }),
2165
+ React.createElement(MRT_Table, { tableContainerRef: tableContainerRef, table: table })));
2166
+ };
2167
+
2168
+ const MRT_TablePaper = ({ table }) => {
2169
+ const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, } = table;
2170
+ const { isFullScreen } = getState();
2171
+ useEffect(() => {
2172
+ if (typeof window !== 'undefined') {
2173
+ if (isFullScreen) {
2174
+ document.body.style.height = '100vh';
2175
+ }
2176
+ else {
2177
+ document.body.style.height = 'auto';
2178
+ }
2179
+ }
2180
+ }, [isFullScreen]);
2181
+ const tablePaperProps = muiTablePaperProps instanceof Function
2182
+ ? muiTablePaperProps({ table })
2183
+ : muiTablePaperProps;
2184
+ return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { sx: Object.assign({ transition: 'all 0.2s ease-in-out' }, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), { height: isFullScreen ? '100vh' : undefined, margin: isFullScreen ? '0' : undefined, maxHeight: isFullScreen ? '100vh' : undefined, maxWidth: isFullScreen ? '100vw' : undefined, padding: isFullScreen ? '0' : undefined, width: isFullScreen ? '100vw' : undefined }) }),
2185
+ enableTopToolbar && React.createElement(MRT_TopToolbar, { table: table }),
2186
+ React.createElement(MRT_TableContainer, { table: table }),
2187
+ enableBottomToolbar && React.createElement(MRT_BottomToolbar, { table: table })));
2188
+ };
2189
+
2190
+ const MRT_TableRoot = (props) => {
2191
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
2192
+ const [tableId, setIdPrefix] = useState(props.tableId);
2193
+ useEffect(() => { var _a; return setIdPrefix((_a = props.tableId) !== null && _a !== void 0 ? _a : Math.random().toString(36).substring(2, 9)); }, [props.tableId]);
2194
+ const initialState = useMemo(() => {
2195
+ var _a, _b;
2196
+ const initState = (_a = props.initialState) !== null && _a !== void 0 ? _a : {};
2197
+ initState.columnOrder =
2198
+ (_b = initState.columnOrder) !== null && _b !== void 0 ? _b : getDefaultColumnOrderIds(props);
2199
+ return initState;
2200
+ }, []);
2201
+ const [columnOrder, setColumnOrder] = useState((_a = initialState.columnOrder) !== null && _a !== void 0 ? _a : []);
2202
+ const [currentDraggingColumn, setCurrentDraggingColumn] = useState((_b = initialState.currentDraggingColumn) !== null && _b !== void 0 ? _b : null);
2203
+ const [currentDraggingRow, setCurrentDraggingRow] = useState((_c = initialState.currentDraggingRow) !== null && _c !== void 0 ? _c : null);
2204
+ const [currentEditingCell, setCurrentEditingCell] = useState((_d = initialState.currentEditingCell) !== null && _d !== void 0 ? _d : null);
2205
+ const [currentEditingRow, setCurrentEditingRow] = useState((_e = initialState.currentEditingRow) !== null && _e !== void 0 ? _e : null);
2206
+ const [currentHoveredColumn, setCurrentHoveredColumn] = useState((_f = initialState.currentHoveredColumn) !== null && _f !== void 0 ? _f : null);
2207
+ const [currentHoveredRow, setCurrentHoveredRow] = useState((_g = initialState.currentHoveredRow) !== null && _g !== void 0 ? _g : null);
2208
+ const [density, setDensity] = useState((_h = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _h !== void 0 ? _h : 'comfortable');
2209
+ const [isFullScreen, setIsFullScreen] = useState((_j = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _j !== void 0 ? _j : false);
2210
+ const [showAlertBanner, setShowAlertBanner] = useState((_l = (_k = props.initialState) === null || _k === void 0 ? void 0 : _k.showAlertBanner) !== null && _l !== void 0 ? _l : false);
2211
+ const [showColumnFilters, setShowFilters] = useState((_m = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _m !== void 0 ? _m : false);
2212
+ const [showGlobalFilter, setShowGlobalFilter] = useState((_o = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _o !== void 0 ? _o : false);
2213
+ const [columnFilterFns, setColumnFilterFns] = useState(() => Object.assign({}, ...getAllLeafColumnDefs(props.columns).map((col) => {
2214
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2215
+ return ({
2216
+ [(_d = (_b = (_a = col.id) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : (_c = col.accessorKey) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '']: col.filterFn instanceof Function
2217
+ ? (_e = col.filterFn.name) !== null && _e !== void 0 ? _e : 'custom'
2218
+ : (_m = (_f = col.filterFn) !== null && _f !== void 0 ? _f : (_g = initialState === null || initialState === void 0 ? void 0 : initialState.columnFilterFns) === null || _g === void 0 ? void 0 : _g[(_l = (_j = (_h = col.id) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : (_k = col.accessorKey) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : '']) !== null && _m !== void 0 ? _m : getDefaultColumnFilterFn(col),
2219
+ });
2220
+ })));
2221
+ const [globalFilterFn, setGlobalFilterFn] = useState(props.globalFilterFn instanceof String
2222
+ ? props.globalFilterFn
2223
+ : 'fuzzy');
2224
+ const displayColumns = useMemo(() => {
2225
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
2226
+ return [
2227
+ columnOrder.includes('mrt-row-drag') && Object.assign(Object.assign(Object.assign({ header: (_a = props.localization) === null || _a === void 0 ? void 0 : _a.move, size: 60 }, defaultDisplayColumnDefOptions), (_b = props.displayColumnDefOptions) === null || _b === void 0 ? void 0 : _b['mrt-row-drag']), { id: 'mrt-row-drag' }),
2228
+ columnOrder.includes('mrt-row-actions') && Object.assign(Object.assign(Object.assign({ Cell: ({ cell }) => (React.createElement(MRT_ToggleRowActionMenuButton, { row: cell.row, table: table })), header: (_c = props.localization) === null || _c === void 0 ? void 0 : _c.actions, size: 70 }, defaultDisplayColumnDefOptions), (_d = props.displayColumnDefOptions) === null || _d === void 0 ? void 0 : _d['mrt-row-actions']), { id: 'mrt-row-actions' }),
2229
+ columnOrder.includes('mrt-row-expand') && Object.assign(Object.assign(Object.assign({ Cell: ({ cell }) => (React.createElement(MRT_ExpandButton, { row: cell.row, table: table })), Header: () => props.enableExpandAll ? (React.createElement(MRT_ExpandAllButton, { table: table })) : null, header: (_e = props.localization) === null || _e === void 0 ? void 0 : _e.expand, size: 60 }, defaultDisplayColumnDefOptions), (_f = props.displayColumnDefOptions) === null || _f === void 0 ? void 0 : _f['mrt-row-expand']), { id: 'mrt-row-expand' }),
2230
+ columnOrder.includes('mrt-row-select') && Object.assign(Object.assign(Object.assign({ Cell: ({ cell }) => (React.createElement(MRT_SelectCheckbox, { row: cell.row, table: table })), Header: () => props.enableSelectAll ? (React.createElement(MRT_SelectCheckbox, { selectAll: true, table: table })) : null, header: (_g = props.localization) === null || _g === void 0 ? void 0 : _g.select, size: 60 }, defaultDisplayColumnDefOptions), (_h = props.displayColumnDefOptions) === null || _h === void 0 ? void 0 : _h['mrt-row-select']), { id: 'mrt-row-select' }),
2231
+ columnOrder.includes('mrt-row-numbers') && Object.assign(Object.assign(Object.assign({ Cell: ({ cell }) => cell.row.index + 1, Header: () => { var _a; return (_a = props.localization) === null || _a === void 0 ? void 0 : _a.rowNumber; }, header: (_j = props.localization) === null || _j === void 0 ? void 0 : _j.rowNumbers, size: 60 }, defaultDisplayColumnDefOptions), (_k = props.displayColumnDefOptions) === null || _k === void 0 ? void 0 : _k['mrt-row-numbers']), { id: 'mrt-row-numbers' }),
2232
+ ].filter(Boolean);
2233
+ }, [
2234
+ columnOrder,
2235
+ props.displayColumnDefOptions,
2236
+ props.editingMode,
2237
+ props.enableColumnDragging,
2238
+ props.enableColumnOrdering,
2239
+ props.enableEditing,
2240
+ props.enableExpandAll,
2241
+ props.enableExpanding,
2242
+ props.enableGrouping,
2243
+ props.enableRowActions,
2244
+ props.enableRowDragging,
2245
+ props.enableRowNumbers,
2246
+ props.enableRowOrdering,
2247
+ props.enableRowSelection,
2248
+ props.enableSelectAll,
2249
+ props.localization,
2250
+ props.muiTableBodyCellProps,
2251
+ props.muiTableHeadCellProps,
2252
+ props.positionActionsColumn,
2253
+ ]);
2254
+ const columnDefs = useMemo(() => prepareColumns([...displayColumns, ...props.columns], columnFilterFns, props.filterFns, props.sortingFns), [columnFilterFns, displayColumns, props.columns]);
2255
+ const data = useMemo(() => {
2256
+ var _a, _b, _c, _d, _e;
2257
+ return (((_a = props.state) === null || _a === void 0 ? void 0 : _a.isLoading) || ((_b = props.state) === null || _b === void 0 ? void 0 : _b.showSkeletons)) &&
2258
+ !props.data.length
2259
+ ? [
2260
+ ...Array(((_d = (_c = props.state) === null || _c === void 0 ? void 0 : _c.pagination) === null || _d === void 0 ? void 0 : _d.pageSize) ||
2261
+ ((_e = initialState === null || initialState === void 0 ? void 0 : initialState.pagination) === null || _e === void 0 ? void 0 : _e.pageSize) ||
2262
+ 10).fill(null),
2263
+ ].map(() => Object.assign({}, ...getAllLeafColumnDefs(props.columns).map((col) => {
2264
+ var _a, _b;
2265
+ return ({
2266
+ [(_b = (_a = col.id) !== null && _a !== void 0 ? _a : col.accessorKey) !== null && _b !== void 0 ? _b : '']: null,
2267
+ });
2268
+ })))
2269
+ : props.data;
2270
+ }, [props.data, (_p = props.state) === null || _p === void 0 ? void 0 : _p.isLoading, (_q = props.state) === null || _q === void 0 ? void 0 : _q.showSkeletons]);
2271
+ //@ts-ignore
2272
+ const table = Object.assign(Object.assign({}, useReactTable(Object.assign(Object.assign({ getCoreRowModel: getCoreRowModel(), getExpandedRowModel: getExpandedRowModel(), getFacetedRowModel: getFacetedRowModel(), getFilteredRowModel: getFilteredRowModel(), getGroupedRowModel: getGroupedRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), onColumnOrderChange: setColumnOrder, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows }, props), {
2273
+ //@ts-ignore
2274
+ columns: columnDefs, data, globalFilterFn:
2275
+ //@ts-ignore
2276
+ (_r = props.filterFns[globalFilterFn]) !== null && _r !== void 0 ? _r : props.filterFns.fuzzy, initialState, state: Object.assign({ columnOrder,
2277
+ currentDraggingColumn,
2278
+ currentDraggingRow,
2279
+ currentEditingCell,
2280
+ currentEditingRow,
2281
+ columnFilterFns,
2282
+ globalFilterFn,
2283
+ currentHoveredColumn,
2284
+ currentHoveredRow,
2285
+ density,
2286
+ isFullScreen,
2287
+ showAlertBanner,
2288
+ showColumnFilters,
2289
+ showGlobalFilter }, props.state), tableId }))), { setCurrentDraggingColumn: (_s = props.onCurrentDraggingColumnChange) !== null && _s !== void 0 ? _s : setCurrentDraggingColumn, setCurrentDraggingRow: (_t = props.onCurrentDraggingRowChange) !== null && _t !== void 0 ? _t : setCurrentDraggingRow, setCurrentEditingCell: (_u = props.onCurrentEditingCellChange) !== null && _u !== void 0 ? _u : setCurrentEditingCell, setCurrentEditingRow: (_v = props.onCurrentEditingRowChange) !== null && _v !== void 0 ? _v : setCurrentEditingRow, setColumnFilterFns: (_w = props.onCurrentFilterFnsChange) !== null && _w !== void 0 ? _w : setColumnFilterFns, setGlobalFilterFn: (_x = props.onCurrentGlobalFilterFnChange) !== null && _x !== void 0 ? _x : setGlobalFilterFn, setCurrentHoveredColumn: (_y = props.onCurrentHoveredColumnChange) !== null && _y !== void 0 ? _y : setCurrentHoveredColumn, setCurrentHoveredRow: (_z = props.onCurrentHoveredRowChange) !== null && _z !== void 0 ? _z : setCurrentHoveredRow, setDensity: (_0 = props.onDensityChange) !== null && _0 !== void 0 ? _0 : setDensity, setIsFullScreen: (_1 = props.onIsFullScreenChange) !== null && _1 !== void 0 ? _1 : setIsFullScreen, setShowAlertBanner: (_2 = props.onShowAlertBannerChange) !== null && _2 !== void 0 ? _2 : setShowAlertBanner, setShowFilters: (_3 = props.onShowFiltersChange) !== null && _3 !== void 0 ? _3 : setShowFilters, setShowGlobalFilter: (_4 = props.onShowGlobalFilterChange) !== null && _4 !== void 0 ? _4 : setShowGlobalFilter });
2290
+ return (React.createElement(React.Fragment, null,
2291
+ React.createElement(Dialog, { PaperComponent: Box, TransitionComponent: Grow, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => setIsFullScreen(false), open: isFullScreen, transitionDuration: 400 },
2292
+ React.createElement(MRT_TablePaper, { table: table })),
2293
+ !isFullScreen && React.createElement(MRT_TablePaper, { table: table })));
2294
+ };
2295
+
2296
+ var MaterialReactTable = (_a) => {
2297
+ var { aggregationFns, autoResetExpanded = false, columnResizeMode = 'onEnd', defaultColumn = { minSize: 40, maxSize: 1000, size: 180 }, editingMode = 'row', enableBottomToolbar = true, enableColumnActions = true, enableColumnFilterChangeMode = false, enableColumnFilters = true, enableColumnOrdering = false, enableColumnResizing = false, enableDensityToggle = true, enableExpandAll = true, enableFilters = true, enableFullScreenToggle = true, enableGlobalFilter = true, enableGlobalFilterChangeMode = false, enableGlobalFilterRankedResults = true, enableGrouping = false, enableHiding = true, enableMultiRowSelection = true, enableMultiSort = true, enablePagination = true, enablePinning = false, enableRowSelection = false, enableSelectAll = true, enableSorting = true, enableStickyHeader = false, enableTableFooter = true, enableTableHead = true, enableToolbarInternalActions = true, enableTopToolbar = true, filterFns, icons, localization, positionActionsColumn = 'first', positionExpandColumn = 'first', positionGlobalFilter = 'right', positionPagination = 'bottom', positionToolbarAlertBanner = 'top', positionToolbarDropZone = 'top', rowNumberMode = 'original', selectAllMode = 'all', sortingFns } = _a, rest = __rest(_a, ["aggregationFns", "autoResetExpanded", "columnResizeMode", "defaultColumn", "editingMode", "enableBottomToolbar", "enableColumnActions", "enableColumnFilterChangeMode", "enableColumnFilters", "enableColumnOrdering", "enableColumnResizing", "enableDensityToggle", "enableExpandAll", "enableFilters", "enableFullScreenToggle", "enableGlobalFilter", "enableGlobalFilterChangeMode", "enableGlobalFilterRankedResults", "enableGrouping", "enableHiding", "enableMultiRowSelection", "enableMultiSort", "enablePagination", "enablePinning", "enableRowSelection", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarInternalActions", "enableTopToolbar", "filterFns", "icons", "localization", "positionActionsColumn", "positionExpandColumn", "positionGlobalFilter", "positionPagination", "positionToolbarAlertBanner", "positionToolbarDropZone", "rowNumberMode", "selectAllMode", "sortingFns"]);
2298
+ return (React.createElement(MRT_TableRoot, Object.assign({ aggregationFns: Object.assign(Object.assign({}, MRT_AggregationFns), aggregationFns), autoResetExpanded: autoResetExpanded, columnResizeMode: columnResizeMode, defaultColumn: defaultColumn, editingMode: editingMode, enableBottomToolbar: enableBottomToolbar, enableColumnActions: enableColumnActions, enableColumnFilterChangeMode: enableColumnFilterChangeMode, enableColumnFilters: enableColumnFilters, enableColumnOrdering: enableColumnOrdering, enableColumnResizing: enableColumnResizing, enableDensityToggle: enableDensityToggle, enableExpandAll: enableExpandAll, enableFilters: enableFilters, enableFullScreenToggle: enableFullScreenToggle, enableGlobalFilter: enableGlobalFilter, enableGlobalFilterChangeMode: enableGlobalFilterChangeMode, enableGlobalFilterRankedResults: enableGlobalFilterRankedResults, enableGrouping: enableGrouping, enableHiding: enableHiding, enableMultiRowSelection: enableMultiRowSelection, enableMultiSort: enableMultiSort, enablePagination: enablePagination, enablePinning: enablePinning, enableRowSelection: enableRowSelection, enableSelectAll: enableSelectAll, enableSorting: enableSorting, enableStickyHeader: enableStickyHeader, enableTableFooter: enableTableFooter, enableTableHead: enableTableHead, enableToolbarInternalActions: enableToolbarInternalActions, enableTopToolbar: enableTopToolbar, filterFns: Object.assign(Object.assign({}, MRT_FilterFns), filterFns), icons: Object.assign(Object.assign({}, MRT_Default_Icons), icons), localization: Object.assign(Object.assign({}, MRT_DefaultLocalization_EN), localization), positionActionsColumn: positionActionsColumn, positionExpandColumn: positionExpandColumn, positionGlobalFilter: positionGlobalFilter, positionPagination: positionPagination, positionToolbarAlertBanner: positionToolbarAlertBanner, positionToolbarDropZone: positionToolbarDropZone, rowNumberMode: rowNumberMode, selectAllMode: selectAllMode, sortingFns: Object.assign(Object.assign({}, MRT_SortingFns), sortingFns) }, rest)));
2299
+ };
2300
+
2301
+ export { MaterialReactTable as default };
2302
+ //# sourceMappingURL=material-react-table.esm.js.map