material-react-table 0.33.4 → 0.34.0

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