material-react-table 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -11,7 +11,7 @@ import { lighten, darken, alpha, useTheme } from '@mui/material/styles';
11
11
  import Skeleton from '@mui/material/Skeleton';
12
12
  import TableCell from '@mui/material/TableCell';
13
13
  import Box from '@mui/material/Box';
14
- import { flexRender as flexRender$1, createRow as createRow$1, sortingFns, aggregationFns, filterFns, useReactTable, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel } from '@tanstack/react-table';
14
+ import { flexRender as flexRender$1, createRow as createRow$1, sortingFns, useReactTable, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel, aggregationFns, filterFns } from '@tanstack/react-table';
15
15
  import highlightWords from 'highlight-words';
16
16
  import IconButton from '@mui/material/IconButton';
17
17
  import Tooltip from '@mui/material/Tooltip';
@@ -688,7 +688,8 @@ const MRT_TableBodyCell = (_a) => {
688
688
  hoveredRow,
689
689
  rowIndex,
690
690
  ]);
691
- const isEditable = parseFromValuesOrFunc(enableEditing, row) &&
691
+ const isEditable = !cell.getIsPlaceholder() &&
692
+ parseFromValuesOrFunc(enableEditing, row) &&
692
693
  parseFromValuesOrFunc(columnDef.enableEditing, row) !== false;
693
694
  const isEditing = isEditable &&
694
695
  !['custom', 'modal'].includes(editDisplayMode) &&
@@ -727,7 +728,8 @@ const MRT_TableBodyCell = (_a) => {
727
728
  measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
728
729
  }
729
730
  } }, tableCellProps, { onDoubleClick: handleDoubleClick, onDragEnter: handleDragEnter, sx: (theme) => (Object.assign(Object.assign({ '&:hover': {
730
- outline: ['cell', 'table'].includes(editDisplayMode !== null && editDisplayMode !== void 0 ? editDisplayMode : '') && isEditable
731
+ outline: (editDisplayMode === 'cell' && isEditable) ||
732
+ (editDisplayMode === 'table' && (isCreating || isEditing))
731
733
  ? `1px solid ${theme.palette.grey[500]}`
732
734
  : undefined,
733
735
  outlineOffset: '-1px',
@@ -1903,14 +1905,14 @@ const MRT_TableHeadCellResizeHandle = (_a) => {
1903
1905
  },
1904
1906
  cursor: 'col-resize',
1905
1907
  mr: density === 'compact'
1906
- ? '-12px'
1908
+ ? '-8px'
1907
1909
  : density === 'comfortable'
1908
- ? '-20px'
1909
- : '-28px',
1910
+ ? '-16px'
1911
+ : '-24px',
1910
1912
  position: 'absolute',
1911
1913
  px: '4px',
1912
1914
  right: column.columnDef.columnDefType === 'display' ? '4px' : '0',
1913
- }), children: jsx(Divider, { className: "Mui-TableHeadCell-ResizeHandle-Divider", flexItem: true, orientation: "vertical", sx: (theme) => (Object.assign({ borderRadius: '2px', borderWidth: '2px', height: '24px', touchAction: 'none', transition: column.getIsResizing()
1915
+ }), children: jsx(Divider, { className: "Mui-TableHeadCell-ResizeHandle-Divider", flexItem: true, orientation: "vertical", sx: (theme) => (Object.assign({ borderRadius: '2px', borderWidth: '2px', height: '24px', touchAction: 'none', transform: 'translateX(4px)', transition: column.getIsResizing()
1914
1916
  ? undefined
1915
1917
  : 'all 150ms ease-in-out', userSelect: 'none', zIndex: 4 }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))) }) }));
1916
1918
  };
@@ -2087,7 +2089,9 @@ const MRT_TableHeadCell = (_a) => {
2087
2089
  whiteSpace: ((_h = (_g = columnDef.header) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0) < 20
2088
2090
  ? 'nowrap'
2089
2091
  : 'normal',
2090
- }, title: columnDefType === 'data' ? columnDef.header : undefined, children: headerElement }), column.getCanFilter() && (jsx(MRT_TableHeadCellFilterLabel, { header: header, table: table })), column.getCanSort() && (jsx(MRT_TableHeadCellSortLabel, { header: header, table: table }))] }), columnDefType !== 'group' && (jsxs(Box, { className: "Mui-TableHeadCell-Content-Actions", sx: { whiteSpace: 'nowrap' }, children: [showDragHandle && (jsx(MRT_TableHeadCellGrabHandle, { column: column, table: table, tableHeadCellRef: {
2092
+ }, title: columnDefType === 'data' ? columnDef.header : undefined, children: headerElement }), column.getCanFilter() && (jsx(MRT_TableHeadCellFilterLabel, { header: header, table: table })), column.getCanSort() && (jsx(MRT_TableHeadCellSortLabel, { header: header, table: table }))] }), columnDefType !== 'group' && (jsxs(Box, { className: "Mui-TableHeadCell-Content-Actions", sx: {
2093
+ whiteSpace: 'nowrap',
2094
+ }, children: [showDragHandle && (jsx(MRT_TableHeadCellGrabHandle, { column: column, table: table, tableHeadCellRef: {
2091
2095
  current: tableHeadCellRefs.current[column.id],
2092
2096
  } })), showColumnActions && (jsx(MRT_TableHeadCellColumnActionsButton, { header: header, table: table }))] })), column.getCanResize() && (jsx(MRT_TableHeadCellResizeHandle, { header: header, table: table }))] })), columnFilterDisplayMode === 'subheader' && column.getCanFilter() && (jsx(MRT_TableHeadCellFilterContainer, { header: header, table: table }))] })));
2093
2097
  };
@@ -2136,7 +2140,7 @@ const MRT_TablePagination = (_a) => {
2136
2140
  const showFirstLastPageButtons = numberOfPages > 2;
2137
2141
  const firstRowIndex = pageIndex * pageSize;
2138
2142
  const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
2139
- const _b = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { SelectProps, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true } = _b, _rest = __rest(_b, ["SelectProps", "rowsPerPageOptions", "showFirstButton", "showLastButton", "showRowsPerPage"]);
2143
+ const _b = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { SelectProps, disabled = false, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons, showRowsPerPage = true } = _b, _rest = __rest(_b, ["SelectProps", "disabled", "rowsPerPageOptions", "showFirstButton", "showLastButton", "showRowsPerPage"]);
2140
2144
  return (jsxs(Box, { className: "MuiTablePagination-root", sx: {
2141
2145
  alignItems: 'center',
2142
2146
  display: 'flex',
@@ -2153,17 +2157,17 @@ const MRT_TablePagination = (_a) => {
2153
2157
  px: '8px',
2154
2158
  py: '12px',
2155
2159
  zIndex: 2,
2156
- }, children: [showRowsPerPage && (jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsx(InputLabel, { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsx(Select, Object.assign({ disableUnderline: true, id: "mrt-rows-per-page", inputProps: { 'aria-label': localization.rowsPerPage }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard" }, SelectProps, { children: rowsPerPageOptions.map((option) => {
2160
+ }, children: [showRowsPerPage && (jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsx(InputLabel, { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsx(Select, Object.assign({ disableUnderline: true, disabled: disabled, id: "mrt-rows-per-page", inputProps: { 'aria-label': localization.rowsPerPage }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard" }, SelectProps, { children: rowsPerPageOptions.map((option) => {
2157
2161
  var _a;
2158
2162
  const value = typeof option !== 'number' ? option.value : option;
2159
2163
  const label = typeof option !== 'number' ? option.label : `${option}`;
2160
2164
  return ((_a = SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.children) !== null && _a !== void 0 ? _a : ((SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.native) ? (jsx("option", { value: value, children: label }, value)) : (jsx(MenuItem, { sx: { m: 0 }, value: value, children: label }, value))));
2161
- }) }))] })), paginationDisplayMode === 'pages' ? (jsx(Pagination, Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsx(PaginationItem, Object.assign({ slots: {
2165
+ }) }))] })), paginationDisplayMode === 'pages' ? (jsx(Pagination, Object.assign({ count: numberOfPages, disabled: disabled, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsx(PaginationItem, Object.assign({ slots: {
2162
2166
  first: FirstPageIcon,
2163
2167
  last: LastPageIcon,
2164
2168
  next: ChevronRightIcon,
2165
2169
  previous: ChevronLeftIcon,
2166
- } }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, _rest))) : paginationDisplayMode === 'default' ? (jsxs(Fragment, { children: [jsx(Typography, { align: "center", component: "span", sx: { m: '0 4px', minWidth: '8ch' }, variant: "body2", children: `${lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()}-${lastRowIndex.toLocaleString()} ${localization.of} ${totalRowCount.toLocaleString()}` }), jsxs(Box, { gap: "xs", children: [showFirstButton && (jsx(IconButton, { "aria-label": localization.goToFirstPage, disabled: pageIndex <= 0, onClick: () => setPageIndex(0), size: "small", children: jsx(FirstPageIcon, {}) })), jsx(IconButton, { "aria-label": localization.goToPreviousPage, disabled: pageIndex <= 0, onClick: () => setPageIndex(pageIndex - 1), size: "small", children: jsx(ChevronLeftIcon, {}) }), jsx(IconButton, { "aria-label": localization.goToNextPage, disabled: lastRowIndex >= totalRowCount, onClick: () => setPageIndex(pageIndex + 1), size: "small", children: jsx(ChevronRightIcon, {}) }), showLastButton && (jsx(IconButton, { "aria-label": localization.goToLastPage, disabled: lastRowIndex >= totalRowCount, onClick: () => setPageIndex(numberOfPages - 1), size: "small", children: jsx(LastPageIcon, {}) }))] })] })) : null] }));
2170
+ } }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, _rest))) : paginationDisplayMode === 'default' ? (jsxs(Fragment, { children: [jsx(Typography, { align: "center", component: "span", sx: { m: '0 4px', minWidth: '8ch' }, variant: "body2", children: `${lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()}-${lastRowIndex.toLocaleString()} ${localization.of} ${totalRowCount.toLocaleString()}` }), jsxs(Box, { gap: "xs", children: [showFirstButton && (jsx(IconButton, { "aria-label": localization.goToFirstPage, disabled: pageIndex <= 0 || disabled, onClick: () => setPageIndex(0), size: "small", children: jsx(FirstPageIcon, {}) })), jsx(IconButton, { "aria-label": localization.goToPreviousPage, disabled: pageIndex <= 0 || disabled, onClick: () => setPageIndex(pageIndex - 1), size: "small", children: jsx(ChevronLeftIcon, {}) }), jsx(IconButton, { "aria-label": localization.goToNextPage, disabled: lastRowIndex >= totalRowCount || disabled, onClick: () => setPageIndex(pageIndex + 1), size: "small", children: jsx(ChevronRightIcon, {}) }), showLastButton && (jsx(IconButton, { "aria-label": localization.goToLastPage, disabled: lastRowIndex >= totalRowCount || disabled, onClick: () => setPageIndex(numberOfPages - 1), size: "small", children: jsx(LastPageIcon, {}) }))] })] })) : null] }));
2167
2171
  };
2168
2172
 
2169
2173
  const MRT_GlobalFilterTextField = (_a) => {
@@ -2979,228 +2983,582 @@ const MRT_ToggleRowActionMenuButton = (_a) => {
2979
2983
  ['modal', 'row'].includes(editDisplayMode) ? (jsx(Tooltip, { placement: "right", title: localization.edit, children: jsx(IconButton, Object.assign({ "aria-label": localization.edit, onClick: handleStartEditMode, sx: commonIconButtonStyles }, rest, { children: jsx(EditIcon, {}) })) })) : renderRowActionMenuItems ? (jsxs(Fragment, { children: [jsx(Tooltip, { enterDelay: 1000, enterNextDelay: 1000, title: localization.rowActions, children: jsx(IconButton, Object.assign({ "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles }, rest, { children: jsx(MoreHorizIcon, {}) })) }), jsx(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, table: table })] })) : null }));
2980
2984
  };
2981
2985
 
2982
- const MRT_AggregationFns = Object.assign({}, aggregationFns);
2983
-
2984
- const fuzzy = (row, columnId, filterValue, addMeta) => {
2985
- const itemRank = rankItem(row.getValue(columnId), filterValue, {
2986
- threshold: rankings.MATCHES,
2987
- });
2988
- addMeta(itemRank);
2989
- return itemRank.passed;
2986
+ const useMRT_DisplayColumns = (params) => {
2987
+ var _a, _b, _c, _d;
2988
+ const { columnOrder, creatingRow, grouping, tableOptions } = params;
2989
+ const order = (_b = (_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.columnOrder) !== null && _b !== void 0 ? _b : columnOrder;
2990
+ return useMemo(() => [
2991
+ makeRowPinColumn,
2992
+ makeRowDragColumn,
2993
+ makeRowActionsColumn,
2994
+ makeRowExpandColumn,
2995
+ makeRowSelectColumn,
2996
+ makeRowNumbersColumn,
2997
+ makeSpacerColumn,
2998
+ ]
2999
+ .map((makeCol) => makeCol(params, order))
3000
+ .filter(Boolean), [
3001
+ columnOrder,
3002
+ creatingRow,
3003
+ grouping,
3004
+ tableOptions.displayColumnDefOptions,
3005
+ tableOptions.editDisplayMode,
3006
+ tableOptions.enableColumnDragging,
3007
+ tableOptions.enableColumnFilterModes,
3008
+ tableOptions.enableColumnOrdering,
3009
+ tableOptions.enableEditing,
3010
+ tableOptions.enableExpandAll,
3011
+ tableOptions.enableExpanding,
3012
+ tableOptions.enableGrouping,
3013
+ tableOptions.enableRowActions,
3014
+ tableOptions.enableRowDragging,
3015
+ tableOptions.enableRowNumbers,
3016
+ tableOptions.enableRowOrdering,
3017
+ tableOptions.enableRowSelection,
3018
+ tableOptions.enableSelectAll,
3019
+ tableOptions.localization,
3020
+ tableOptions.positionActionsColumn,
3021
+ tableOptions.renderDetailPanel,
3022
+ tableOptions.renderRowActionMenuItems,
3023
+ tableOptions.renderRowActions,
3024
+ (_c = tableOptions.state) === null || _c === void 0 ? void 0 : _c.columnOrder,
3025
+ (_d = tableOptions.state) === null || _d === void 0 ? void 0 : _d.grouping,
3026
+ ]);
2990
3027
  };
2991
- fuzzy.autoRemove = (val) => !val;
2992
- const contains = (row, id, filterValue) => row
2993
- .getValue(id)
2994
- .toString()
2995
- .toLowerCase()
2996
- .trim()
2997
- .includes(filterValue.toString().toLowerCase().trim());
2998
- contains.autoRemove = (val) => !val;
2999
- const startsWith = (row, id, filterValue) => row
3000
- .getValue(id)
3001
- .toString()
3002
- .toLowerCase()
3003
- .trim()
3004
- .startsWith(filterValue.toString().toLowerCase().trim());
3005
- startsWith.autoRemove = (val) => !val;
3006
- const endsWith = (row, id, filterValue) => row
3007
- .getValue(id)
3008
- .toString()
3009
- .toLowerCase()
3010
- .trim()
3011
- .endsWith(filterValue.toString().toLowerCase().trim());
3012
- endsWith.autoRemove = (val) => !val;
3013
- const equals = (row, id, filterValue) => row.getValue(id).toString().toLowerCase().trim() ===
3014
- (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString().toLowerCase().trim());
3015
- equals.autoRemove = (val) => !val;
3016
- const notEquals = (row, id, filterValue) => row.getValue(id).toString().toLowerCase().trim() !==
3017
- filterValue.toString().toLowerCase().trim();
3018
- notEquals.autoRemove = (val) => !val;
3019
- const greaterThan = (row, id, filterValue) => !isNaN(+filterValue) && !isNaN(+row.getValue(id))
3020
- ? +row.getValue(id) > +filterValue
3021
- : row.getValue(id).toString().toLowerCase().trim() >
3022
- (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString().toLowerCase().trim());
3023
- greaterThan.autoRemove = (val) => !val;
3024
- const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
3025
- greaterThanOrEqualTo.autoRemove = (val) => !val;
3026
- const lessThan = (row, id, filterValue) => !isNaN(+filterValue) && !isNaN(+row.getValue(id))
3027
- ? +row.getValue(id) < +filterValue
3028
- : row.getValue(id).toString().toLowerCase().trim() <
3029
- (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString().toLowerCase().trim());
3030
- lessThan.autoRemove = (val) => !val;
3031
- const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
3032
- lessThanOrEqualTo.autoRemove = (val) => !val;
3033
- const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
3034
- greaterThan(row, id, filterValues[0])) &&
3035
- ((!isNaN(+filterValues[0]) &&
3036
- !isNaN(+filterValues[1]) &&
3037
- +filterValues[0] > +filterValues[1]) ||
3038
- ['', undefined].includes(filterValues[1]) ||
3039
- lessThan(row, id, filterValues[1]));
3040
- between.autoRemove = (val) => !val;
3041
- const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
3042
- greaterThanOrEqualTo(row, id, filterValues[0])) &&
3043
- ((!isNaN(+filterValues[0]) &&
3044
- !isNaN(+filterValues[1]) &&
3045
- +filterValues[0] > +filterValues[1]) ||
3046
- ['', undefined].includes(filterValues[1]) ||
3047
- lessThanOrEqualTo(row, id, filterValues[1]));
3048
- betweenInclusive.autoRemove = (val) => !val;
3049
- const empty = (row, id, _filterValue) => !row.getValue(id).toString().trim();
3050
- empty.autoRemove = (val) => !val;
3051
- const notEmpty = (row, id, _filterValue) => !!row.getValue(id).toString().trim();
3052
- notEmpty.autoRemove = (val) => !val;
3053
- const MRT_FilterFns = Object.assign(Object.assign({}, filterFns), { between,
3054
- betweenInclusive,
3055
- contains,
3056
- empty,
3057
- endsWith,
3058
- equals,
3059
- fuzzy,
3060
- greaterThan,
3061
- greaterThanOrEqualTo,
3062
- lessThan,
3063
- lessThanOrEqualTo,
3064
- notEmpty,
3065
- notEquals,
3066
- startsWith });
3028
+ function defaultDisplayColumnProps({ defaultDisplayColumn, displayColumnDefOptions, localization, }, id, header, size = 60) {
3029
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, defaultDisplayColumn), { header: header ? localization[header] : '', size }), displayColumnDefOptions === null || displayColumnDefOptions === void 0 ? void 0 : displayColumnDefOptions[id]), { id });
3030
+ }
3031
+ function makeRowPinColumn({ tableOptions }, order) {
3032
+ const id = 'mrt-row-pin';
3033
+ if (order.includes(id)) {
3034
+ return Object.assign({ Cell: ({ row, table }) => (jsx(MRT_TableBodyRowPinButton, { row: row, table: table })) }, defaultDisplayColumnProps(tableOptions, id, 'pin'));
3035
+ }
3036
+ return null;
3037
+ }
3038
+ function makeRowDragColumn({ tableOptions }, order) {
3039
+ const id = 'mrt-row-drag';
3040
+ if (order.includes(id)) {
3041
+ return Object.assign({ Cell: ({ row, rowRef, table }) => (jsx(MRT_TableBodyRowGrabHandle, { row: row, rowRef: rowRef, table: table })) }, defaultDisplayColumnProps(tableOptions, id, 'move'));
3042
+ }
3043
+ return null;
3044
+ }
3045
+ function makeRowActionsColumn({ creatingRow, tableOptions }, order) {
3046
+ const id = 'mrt-row-actions';
3047
+ if (order.includes(id) ||
3048
+ (creatingRow && tableOptions.createDisplayMode === 'row')) {
3049
+ return Object.assign({ Cell: ({ cell, row, table }) => (jsx(MRT_ToggleRowActionMenuButton, { cell: cell, row: row, table: table })) }, defaultDisplayColumnProps(tableOptions, id, 'actions'));
3050
+ }
3051
+ return null;
3052
+ }
3053
+ function makeRowExpandColumn({ grouping, tableOptions }, order) {
3054
+ var _a, _b;
3055
+ const id = 'mrt-row-expand';
3056
+ if (order.includes(id) &&
3057
+ showExpandColumn(tableOptions, (_b = (_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.grouping) !== null && _b !== void 0 ? _b : grouping)) {
3058
+ return Object.assign({ Cell: ({ row, table }) => jsx(MRT_ExpandButton, { row: row, table: table }), Header: tableOptions.enableExpandAll
3059
+ ? ({ table }) => jsx(MRT_ExpandAllButton, { table: table })
3060
+ : undefined }, defaultDisplayColumnProps(tableOptions, id, 'expand'));
3061
+ }
3062
+ return null;
3063
+ }
3064
+ function makeRowSelectColumn({ tableOptions }, order) {
3065
+ const id = 'mrt-row-select';
3066
+ if (order.includes(id)) {
3067
+ return Object.assign({ Cell: ({ row, table }) => jsx(MRT_SelectCheckbox, { row: row, table: table }), Header: tableOptions.enableSelectAll && tableOptions.enableMultiRowSelection
3068
+ ? ({ table }) => jsx(MRT_SelectCheckbox, { selectAll: true, table: table })
3069
+ : undefined }, defaultDisplayColumnProps(tableOptions, id, 'select'));
3070
+ }
3071
+ return null;
3072
+ }
3073
+ function makeRowNumbersColumn({ tableOptions }, order) {
3074
+ const id = 'mrt-row-numbers';
3075
+ if (order.includes(id) || tableOptions.enableRowNumbers)
3076
+ return Object.assign({ Cell: ({ row }) => row.index + 1, Header: () => tableOptions.localization.rowNumber }, defaultDisplayColumnProps(tableOptions, id, 'rowNumbers'));
3077
+ return null;
3078
+ }
3079
+ const blankColProps = {
3080
+ children: null,
3081
+ sx: {
3082
+ flex: '1 0 auto',
3083
+ minWidth: 0,
3084
+ p: 0,
3085
+ width: 0,
3086
+ },
3087
+ };
3088
+ function makeSpacerColumn({ tableOptions }, order) {
3089
+ const id = 'mrt-row-spacer';
3090
+ if (order.includes(id)) {
3091
+ return Object.assign(Object.assign({}, defaultDisplayColumnProps(tableOptions, id, undefined, 0)), { muiTableBodyCellProps: blankColProps, muiTableFooterCellProps: blankColProps, muiTableHeadCellProps: blankColProps });
3092
+ }
3093
+ return null;
3094
+ }
3067
3095
 
3068
- const MRT_Default_Icons = {
3069
- ArrowDownwardIcon,
3070
- ArrowRightIcon,
3071
- CancelIcon,
3072
- ChevronLeftIcon,
3073
- ChevronRightIcon,
3074
- ClearAllIcon,
3075
- CloseIcon,
3076
- DensityLargeIcon,
3077
- DensityMediumIcon,
3078
- DensitySmallIcon,
3079
- DragHandleIcon,
3080
- DynamicFeedIcon,
3081
- EditIcon,
3082
- ExpandMoreIcon,
3083
- FilterAltIcon,
3084
- FilterListIcon,
3085
- FilterListOffIcon,
3086
- FirstPageIcon,
3087
- FullscreenExitIcon,
3088
- FullscreenIcon,
3089
- KeyboardDoubleArrowDownIcon,
3090
- LastPageIcon,
3091
- MoreHorizIcon,
3092
- MoreVertIcon,
3093
- PushPinIcon,
3094
- RestartAltIcon,
3095
- SaveIcon,
3096
- SearchIcon,
3097
- SearchOffIcon,
3098
- SortIcon,
3099
- SyncAltIcon,
3100
- ViewColumnIcon,
3101
- VisibilityOffIcon,
3096
+ const useMRT_Effects = (table) => {
3097
+ const { getIsSomeRowsPinned, getState, options: { enablePagination, enableRowPinning, rowCount }, } = table;
3098
+ const { density, globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting, } = getState();
3099
+ const rerender = useReducer(() => ({}), {})[1];
3100
+ const isMounted = useRef(false);
3101
+ const initialBodyHeight = useRef();
3102
+ const previousTop = useRef();
3103
+ useEffect(() => {
3104
+ if (typeof window !== 'undefined') {
3105
+ initialBodyHeight.current = document.body.style.height;
3106
+ }
3107
+ }, []);
3108
+ useEffect(() => {
3109
+ if (isMounted && typeof window !== 'undefined') {
3110
+ if (isFullScreen) {
3111
+ previousTop.current = document.body.getBoundingClientRect().top; //save scroll position
3112
+ document.body.style.height = '100vh'; //hide page scrollbars when table is in full screen mode
3113
+ }
3114
+ else {
3115
+ document.body.style.height = initialBodyHeight.current;
3116
+ if (!previousTop.current)
3117
+ return;
3118
+ //restore scroll position
3119
+ window.scrollTo({
3120
+ behavior: 'instant',
3121
+ top: -1 * previousTop.current,
3122
+ });
3123
+ }
3124
+ }
3125
+ isMounted.current = true;
3126
+ }, [isFullScreen]);
3127
+ //if page index is out of bounds, set it to the last page
3128
+ useEffect(() => {
3129
+ if (!enablePagination || isLoading || showSkeletons)
3130
+ return;
3131
+ const { pageIndex, pageSize } = pagination;
3132
+ const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : table.getPrePaginationRowModel().rows.length;
3133
+ const firstVisibleRowIndex = pageIndex * pageSize;
3134
+ if (firstVisibleRowIndex > totalRowCount) {
3135
+ table.setPageIndex(Math.floor(totalRowCount / pageSize));
3136
+ }
3137
+ }, [rowCount, table.getPrePaginationRowModel().rows.length]);
3138
+ //turn off sort when global filter is looking for ranked results
3139
+ const appliedSort = useRef(sorting);
3140
+ useEffect(() => {
3141
+ if (sorting.length) {
3142
+ appliedSort.current = sorting;
3143
+ }
3144
+ }, [sorting]);
3145
+ useEffect(() => {
3146
+ if (!getCanRankRows(table))
3147
+ return;
3148
+ if (globalFilter) {
3149
+ table.setSorting([]);
3150
+ }
3151
+ else {
3152
+ table.setSorting(() => appliedSort.current || []);
3153
+ }
3154
+ }, [globalFilter]);
3155
+ useEffect(() => {
3156
+ if (enableRowPinning && getIsSomeRowsPinned()) {
3157
+ setTimeout(() => {
3158
+ rerender();
3159
+ }, 150);
3160
+ }
3161
+ }, [density]);
3102
3162
  };
3103
3163
 
3104
- const MRT_Localization_EN = {
3105
- actions: 'Actions',
3106
- and: 'and',
3107
- cancel: 'Cancel',
3108
- changeFilterMode: 'Change filter mode',
3109
- changeSearchMode: 'Change search mode',
3110
- clearFilter: 'Clear filter',
3111
- clearSearch: 'Clear search',
3112
- clearSort: 'Clear sort',
3113
- clickToCopy: 'Click to copy',
3114
- collapse: 'Collapse',
3115
- collapseAll: 'Collapse all',
3116
- columnActions: 'Column Actions',
3117
- copiedToClipboard: 'Copied to clipboard',
3118
- dropToGroupBy: 'Drop to group by {column}',
3119
- edit: 'Edit',
3120
- expand: 'Expand',
3121
- expandAll: 'Expand all',
3122
- filterArrIncludes: 'Includes',
3123
- filterArrIncludesAll: 'Includes all',
3124
- filterArrIncludesSome: 'Includes',
3125
- filterBetween: 'Between',
3126
- filterBetweenInclusive: 'Between Inclusive',
3127
- filterByColumn: 'Filter by {column}',
3128
- filterContains: 'Contains',
3129
- filterEmpty: 'Empty',
3130
- filterEndsWith: 'Ends With',
3131
- filterEquals: 'Equals',
3132
- filterEqualsString: 'Equals',
3133
- filterFuzzy: 'Fuzzy',
3134
- filterGreaterThan: 'Greater Than',
3135
- filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
3136
- filterInNumberRange: 'Between',
3137
- filterIncludesString: 'Contains',
3138
- filterIncludesStringSensitive: 'Contains',
3139
- filterLessThan: 'Less Than',
3140
- filterLessThanOrEqualTo: 'Less Than Or Equal To',
3141
- filterMode: 'Filter Mode: {filterType}',
3142
- filterNotEmpty: 'Not Empty',
3143
- filterNotEquals: 'Not Equals',
3144
- filterStartsWith: 'Starts With',
3145
- filterWeakEquals: 'Equals',
3146
- filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
3147
- goToFirstPage: 'Go to first page',
3148
- goToLastPage: 'Go to last page',
3149
- goToNextPage: 'Go to next page',
3150
- goToPreviousPage: 'Go to previous page',
3151
- grab: 'Grab',
3152
- groupByColumn: 'Group by {column}',
3153
- groupedBy: 'Grouped by ',
3154
- hideAll: 'Hide all',
3155
- hideColumn: 'Hide {column} column',
3156
- max: 'Max',
3157
- min: 'Min',
3158
- move: 'Move',
3159
- noRecordsToDisplay: 'No records to display',
3160
- noResultsFound: 'No results found',
3161
- of: 'of',
3162
- or: 'or',
3163
- pin: 'Pin',
3164
- pinToLeft: 'Pin to left',
3165
- pinToRight: 'Pin to right',
3166
- resetColumnSize: 'Reset column size',
3167
- resetOrder: 'Reset order',
3168
- rowActions: 'Row Actions',
3169
- rowNumber: '#',
3170
- rowNumbers: 'Row Numbers',
3171
- rowsPerPage: 'Rows per page',
3172
- save: 'Save',
3173
- search: 'Search',
3174
- selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
3175
- select: 'Select',
3176
- showAll: 'Show all',
3177
- showAllColumns: 'Show all columns',
3178
- showHideColumns: 'Show/Hide columns',
3179
- showHideFilters: 'Show/Hide filters',
3180
- showHideSearch: 'Show/Hide search',
3181
- sortByColumnAsc: 'Sort by {column} ascending',
3182
- sortByColumnDesc: 'Sort by {column} descending',
3183
- sortedByColumnAsc: 'Sorted by {column} ascending',
3184
- sortedByColumnDesc: 'Sorted by {column} descending',
3185
- thenBy: ', then by ',
3186
- toggleDensity: 'Toggle density',
3187
- toggleFullScreen: 'Toggle full screen',
3188
- toggleSelectAll: 'Toggle select all',
3189
- toggleSelectRow: 'Toggle select row',
3190
- toggleVisibility: 'Toggle visibility',
3191
- ungroupByColumn: 'Ungroup by {column}',
3192
- unpin: 'Unpin',
3193
- unpinAll: 'Unpin all',
3164
+ const useMRT_TableInstance = (tableOptions) => {
3165
+ 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, _5, _6, _7, _8, _9, _10;
3166
+ const bottomToolbarRef = useRef(null);
3167
+ const editInputRefs = useRef({});
3168
+ const filterInputRefs = useRef({});
3169
+ const searchInputRef = useRef(null);
3170
+ const tableContainerRef = useRef(null);
3171
+ const tableHeadCellRefs = useRef({});
3172
+ const tablePaperRef = useRef(null);
3173
+ const topToolbarRef = useRef(null);
3174
+ const tableHeadRef = useRef(null);
3175
+ const tableFooterRef = useRef(null);
3176
+ const initialState = useMemo(() => {
3177
+ var _a, _b, _c;
3178
+ const initState = (_a = tableOptions.initialState) !== null && _a !== void 0 ? _a : {};
3179
+ initState.columnOrder =
3180
+ (_b = initState.columnOrder) !== null && _b !== void 0 ? _b : getDefaultColumnOrderIds(tableOptions);
3181
+ initState.globalFilterFn = (_c = tableOptions.globalFilterFn) !== null && _c !== void 0 ? _c : 'fuzzy';
3182
+ return initState;
3183
+ }, []);
3184
+ const [creatingRow, _setCreatingRow] = useState((_a = initialState.creatingRow) !== null && _a !== void 0 ? _a : null);
3185
+ const [columnFilterFns, setColumnFilterFns] = useState(() => Object.assign({}, ...getAllLeafColumnDefs(tableOptions.columns).map((col) => {
3186
+ var _a, _b, _c, _d;
3187
+ return ({
3188
+ [getColumnId(col)]: col.filterFn instanceof Function
3189
+ ? (_a = col.filterFn.name) !== null && _a !== void 0 ? _a : 'custom'
3190
+ : (_d = (_b = col.filterFn) !== null && _b !== void 0 ? _b : (_c = initialState === null || initialState === void 0 ? void 0 : initialState.columnFilterFns) === null || _c === void 0 ? void 0 : _c[getColumnId(col)]) !== null && _d !== void 0 ? _d : getDefaultColumnFilterFn(col),
3191
+ });
3192
+ })));
3193
+ const [columnOrder, setColumnOrder] = useState((_b = initialState.columnOrder) !== null && _b !== void 0 ? _b : []);
3194
+ const [density, setDensity] = useState((_c = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _c !== void 0 ? _c : 'comfortable');
3195
+ const [draggingColumn, setDraggingColumn] = useState((_d = initialState.draggingColumn) !== null && _d !== void 0 ? _d : null);
3196
+ const [draggingRow, setDraggingRow] = useState((_e = initialState.draggingRow) !== null && _e !== void 0 ? _e : null);
3197
+ const [editingCell, setEditingCell] = useState((_f = initialState.editingCell) !== null && _f !== void 0 ? _f : null);
3198
+ const [editingRow, setEditingRow] = useState((_g = initialState.editingRow) !== null && _g !== void 0 ? _g : null);
3199
+ const [globalFilterFn, setGlobalFilterFn] = useState((_h = initialState.globalFilterFn) !== null && _h !== void 0 ? _h : 'fuzzy');
3200
+ const [grouping, setGrouping] = useState((_j = initialState.grouping) !== null && _j !== void 0 ? _j : []);
3201
+ const [hoveredColumn, setHoveredColumn] = useState((_k = initialState.hoveredColumn) !== null && _k !== void 0 ? _k : null);
3202
+ const [hoveredRow, setHoveredRow] = useState((_l = initialState.hoveredRow) !== null && _l !== void 0 ? _l : null);
3203
+ const [isFullScreen, setIsFullScreen] = useState((_m = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _m !== void 0 ? _m : false);
3204
+ const [showAlertBanner, setShowAlertBanner] = useState((_p = (_o = tableOptions.initialState) === null || _o === void 0 ? void 0 : _o.showAlertBanner) !== null && _p !== void 0 ? _p : false);
3205
+ const [showColumnFilters, setShowColumnFilters] = useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _q !== void 0 ? _q : false);
3206
+ const [showGlobalFilter, setShowGlobalFilter] = useState((_r = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _r !== void 0 ? _r : false);
3207
+ const [showToolbarDropZone, setShowToolbarDropZone] = useState((_s = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _s !== void 0 ? _s : false);
3208
+ const displayColumns = useMRT_DisplayColumns({
3209
+ columnOrder,
3210
+ creatingRow,
3211
+ grouping,
3212
+ tableOptions,
3213
+ });
3214
+ const columnDefs = useMemo(() => {
3215
+ var _a, _b, _c;
3216
+ return prepareColumns({
3217
+ aggregationFns: tableOptions.aggregationFns,
3218
+ columnDefs: [...displayColumns, ...tableOptions.columns],
3219
+ columnFilterFns: (_b = (_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.columnFilterFns) !== null && _b !== void 0 ? _b : columnFilterFns,
3220
+ defaultDisplayColumn: (_c = tableOptions.defaultDisplayColumn) !== null && _c !== void 0 ? _c : {},
3221
+ filterFns: tableOptions.filterFns,
3222
+ sortingFns: tableOptions.sortingFns,
3223
+ });
3224
+ }, [
3225
+ columnFilterFns,
3226
+ displayColumns,
3227
+ tableOptions.columns,
3228
+ (_t = tableOptions.state) === null || _t === void 0 ? void 0 : _t.columnFilterFns,
3229
+ ]);
3230
+ const data = useMemo(() => {
3231
+ var _a, _b, _c, _d, _e;
3232
+ return (((_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.isLoading) || ((_b = tableOptions.state) === null || _b === void 0 ? void 0 : _b.showSkeletons)) &&
3233
+ !tableOptions.data.length
3234
+ ? [
3235
+ ...Array(((_d = (_c = tableOptions.state) === null || _c === void 0 ? void 0 : _c.pagination) === null || _d === void 0 ? void 0 : _d.pageSize) ||
3236
+ ((_e = initialState === null || initialState === void 0 ? void 0 : initialState.pagination) === null || _e === void 0 ? void 0 : _e.pageSize) ||
3237
+ 10).fill(null),
3238
+ ].map(() => Object.assign({}, ...getAllLeafColumnDefs(tableOptions.columns).map((col) => ({
3239
+ [getColumnId(col)]: null,
3240
+ }))))
3241
+ : tableOptions.data;
3242
+ }, [
3243
+ tableOptions.data,
3244
+ (_u = tableOptions.state) === null || _u === void 0 ? void 0 : _u.isLoading,
3245
+ (_v = tableOptions.state) === null || _v === void 0 ? void 0 : _v.showSkeletons,
3246
+ ]);
3247
+ //@ts-ignore
3248
+ const table = useReactTable(Object.assign(Object.assign({ getCoreRowModel: getCoreRowModel(), getExpandedRowModel: tableOptions.enableExpanding || tableOptions.enableGrouping
3249
+ ? getExpandedRowModel()
3250
+ : undefined, getFacetedMinMaxValues: tableOptions.enableFacetedValues
3251
+ ? getFacetedMinMaxValues()
3252
+ : undefined, getFacetedRowModel: tableOptions.enableFacetedValues
3253
+ ? getFacetedRowModel()
3254
+ : undefined, getFacetedUniqueValues: tableOptions.enableFacetedValues
3255
+ ? getFacetedUniqueValues()
3256
+ : undefined, getFilteredRowModel: tableOptions.enableColumnFilters ||
3257
+ tableOptions.enableGlobalFilter ||
3258
+ tableOptions.enableFilters
3259
+ ? getFilteredRowModel()
3260
+ : undefined, getGroupedRowModel: tableOptions.enableGrouping
3261
+ ? getGroupedRowModel()
3262
+ : undefined, getPaginationRowModel: tableOptions.enablePagination
3263
+ ? getPaginationRowModel()
3264
+ : undefined, getSortedRowModel: tableOptions.enableSorting
3265
+ ? getSortedRowModel()
3266
+ : undefined, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows, onColumnOrderChange: setColumnOrder, onGroupingChange: setGrouping }, tableOptions), {
3267
+ //@ts-ignore
3268
+ columns: columnDefs, data, globalFilterFn: (_w = tableOptions.filterFns) === null || _w === void 0 ? void 0 : _w[globalFilterFn !== null && globalFilterFn !== void 0 ? globalFilterFn : 'fuzzy'], initialState, state: Object.assign({ columnFilterFns,
3269
+ columnOrder,
3270
+ creatingRow,
3271
+ density,
3272
+ draggingColumn,
3273
+ draggingRow,
3274
+ editingCell,
3275
+ editingRow,
3276
+ globalFilterFn,
3277
+ grouping,
3278
+ hoveredColumn,
3279
+ hoveredRow,
3280
+ isFullScreen,
3281
+ showAlertBanner,
3282
+ showColumnFilters,
3283
+ showGlobalFilter,
3284
+ showToolbarDropZone }, tableOptions.state) }));
3285
+ // @ts-ignore
3286
+ table.refs = {
3287
+ // @ts-ignore
3288
+ bottomToolbarRef,
3289
+ editInputRefs,
3290
+ filterInputRefs,
3291
+ // @ts-ignore
3292
+ searchInputRef,
3293
+ // @ts-ignore
3294
+ tableContainerRef,
3295
+ // @ts-ignore
3296
+ tableFooterRef,
3297
+ tableHeadCellRefs,
3298
+ // @ts-ignore
3299
+ tableHeadRef,
3300
+ // @ts-ignore
3301
+ tablePaperRef,
3302
+ // @ts-ignore
3303
+ topToolbarRef,
3304
+ };
3305
+ const setCreatingRow = (row) => {
3306
+ var _a, _b;
3307
+ let _row = row;
3308
+ if (row === true) {
3309
+ _row = createRow(table);
3310
+ }
3311
+ (_b = (_a = tableOptions === null || tableOptions === void 0 ? void 0 : tableOptions.onCreatingRowChange) === null || _a === void 0 ? void 0 : _a.call(tableOptions, _row)) !== null && _b !== void 0 ? _b : _setCreatingRow(_row);
3312
+ };
3313
+ table.setCreatingRow = setCreatingRow;
3314
+ table.setColumnFilterFns =
3315
+ (_x = tableOptions.onColumnFilterFnsChange) !== null && _x !== void 0 ? _x : setColumnFilterFns;
3316
+ table.setDensity = (_y = tableOptions.onDensityChange) !== null && _y !== void 0 ? _y : setDensity;
3317
+ table.setDraggingColumn =
3318
+ (_z = tableOptions.onDraggingColumnChange) !== null && _z !== void 0 ? _z : setDraggingColumn;
3319
+ table.setDraggingRow = (_0 = tableOptions.onDraggingRowChange) !== null && _0 !== void 0 ? _0 : setDraggingRow;
3320
+ table.setEditingCell = (_1 = tableOptions.onEditingCellChange) !== null && _1 !== void 0 ? _1 : setEditingCell;
3321
+ table.setEditingRow = (_2 = tableOptions.onEditingRowChange) !== null && _2 !== void 0 ? _2 : setEditingRow;
3322
+ table.setGlobalFilterFn =
3323
+ (_3 = tableOptions.onGlobalFilterFnChange) !== null && _3 !== void 0 ? _3 : setGlobalFilterFn;
3324
+ table.setHoveredColumn =
3325
+ (_4 = tableOptions.onHoveredColumnChange) !== null && _4 !== void 0 ? _4 : setHoveredColumn;
3326
+ table.setHoveredRow = (_5 = tableOptions.onHoveredRowChange) !== null && _5 !== void 0 ? _5 : setHoveredRow;
3327
+ table.setIsFullScreen = (_6 = tableOptions.onIsFullScreenChange) !== null && _6 !== void 0 ? _6 : setIsFullScreen;
3328
+ table.setShowAlertBanner =
3329
+ (_7 = tableOptions.onShowAlertBannerChange) !== null && _7 !== void 0 ? _7 : setShowAlertBanner;
3330
+ table.setShowColumnFilters =
3331
+ (_8 = tableOptions.onShowColumnFiltersChange) !== null && _8 !== void 0 ? _8 : setShowColumnFilters;
3332
+ table.setShowGlobalFilter =
3333
+ (_9 = tableOptions.onShowGlobalFilterChange) !== null && _9 !== void 0 ? _9 : setShowGlobalFilter;
3334
+ table.setShowToolbarDropZone =
3335
+ (_10 = tableOptions.onShowToolbarDropZoneChange) !== null && _10 !== void 0 ? _10 : setShowToolbarDropZone;
3336
+ useMRT_Effects(table);
3337
+ return table;
3194
3338
  };
3195
3339
 
3196
- const MRT_DefaultColumn = {
3197
- filterVariant: 'text',
3198
- maxSize: 1000,
3199
- minSize: 40,
3200
- size: 180,
3340
+ const MRT_AggregationFns = Object.assign({}, aggregationFns);
3341
+
3342
+ const fuzzy = (row, columnId, filterValue, addMeta) => {
3343
+ const itemRank = rankItem(row.getValue(columnId), filterValue, {
3344
+ threshold: rankings.MATCHES,
3345
+ });
3346
+ addMeta(itemRank);
3347
+ return itemRank.passed;
3201
3348
  };
3202
- const MRT_DefaultDisplayColumn = {
3203
- columnDefType: 'display',
3349
+ fuzzy.autoRemove = (val) => !val;
3350
+ const contains = (row, id, filterValue) => row
3351
+ .getValue(id)
3352
+ .toString()
3353
+ .toLowerCase()
3354
+ .trim()
3355
+ .includes(filterValue.toString().toLowerCase().trim());
3356
+ contains.autoRemove = (val) => !val;
3357
+ const startsWith = (row, id, filterValue) => row
3358
+ .getValue(id)
3359
+ .toString()
3360
+ .toLowerCase()
3361
+ .trim()
3362
+ .startsWith(filterValue.toString().toLowerCase().trim());
3363
+ startsWith.autoRemove = (val) => !val;
3364
+ const endsWith = (row, id, filterValue) => row
3365
+ .getValue(id)
3366
+ .toString()
3367
+ .toLowerCase()
3368
+ .trim()
3369
+ .endsWith(filterValue.toString().toLowerCase().trim());
3370
+ endsWith.autoRemove = (val) => !val;
3371
+ const equals = (row, id, filterValue) => row.getValue(id).toString().toLowerCase().trim() ===
3372
+ (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString().toLowerCase().trim());
3373
+ equals.autoRemove = (val) => !val;
3374
+ const notEquals = (row, id, filterValue) => row.getValue(id).toString().toLowerCase().trim() !==
3375
+ filterValue.toString().toLowerCase().trim();
3376
+ notEquals.autoRemove = (val) => !val;
3377
+ const greaterThan = (row, id, filterValue) => !isNaN(+filterValue) && !isNaN(+row.getValue(id))
3378
+ ? +row.getValue(id) > +filterValue
3379
+ : row.getValue(id).toString().toLowerCase().trim() >
3380
+ (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString().toLowerCase().trim());
3381
+ greaterThan.autoRemove = (val) => !val;
3382
+ const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
3383
+ greaterThanOrEqualTo.autoRemove = (val) => !val;
3384
+ const lessThan = (row, id, filterValue) => !isNaN(+filterValue) && !isNaN(+row.getValue(id))
3385
+ ? +row.getValue(id) < +filterValue
3386
+ : row.getValue(id).toString().toLowerCase().trim() <
3387
+ (filterValue === null || filterValue === void 0 ? void 0 : filterValue.toString().toLowerCase().trim());
3388
+ lessThan.autoRemove = (val) => !val;
3389
+ const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
3390
+ lessThanOrEqualTo.autoRemove = (val) => !val;
3391
+ const between = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
3392
+ greaterThan(row, id, filterValues[0])) &&
3393
+ ((!isNaN(+filterValues[0]) &&
3394
+ !isNaN(+filterValues[1]) &&
3395
+ +filterValues[0] > +filterValues[1]) ||
3396
+ ['', undefined].includes(filterValues[1]) ||
3397
+ lessThan(row, id, filterValues[1]));
3398
+ between.autoRemove = (val) => !val;
3399
+ const betweenInclusive = (row, id, filterValues) => (['', undefined].includes(filterValues[0]) ||
3400
+ greaterThanOrEqualTo(row, id, filterValues[0])) &&
3401
+ ((!isNaN(+filterValues[0]) &&
3402
+ !isNaN(+filterValues[1]) &&
3403
+ +filterValues[0] > +filterValues[1]) ||
3404
+ ['', undefined].includes(filterValues[1]) ||
3405
+ lessThanOrEqualTo(row, id, filterValues[1]));
3406
+ betweenInclusive.autoRemove = (val) => !val;
3407
+ const empty = (row, id, _filterValue) => !row.getValue(id).toString().trim();
3408
+ empty.autoRemove = (val) => !val;
3409
+ const notEmpty = (row, id, _filterValue) => !!row.getValue(id).toString().trim();
3410
+ notEmpty.autoRemove = (val) => !val;
3411
+ const MRT_FilterFns = Object.assign(Object.assign({}, filterFns), { between,
3412
+ betweenInclusive,
3413
+ contains,
3414
+ empty,
3415
+ endsWith,
3416
+ equals,
3417
+ fuzzy,
3418
+ greaterThan,
3419
+ greaterThanOrEqualTo,
3420
+ lessThan,
3421
+ lessThanOrEqualTo,
3422
+ notEmpty,
3423
+ notEquals,
3424
+ startsWith });
3425
+
3426
+ const MRT_Default_Icons = {
3427
+ ArrowDownwardIcon,
3428
+ ArrowRightIcon,
3429
+ CancelIcon,
3430
+ ChevronLeftIcon,
3431
+ ChevronRightIcon,
3432
+ ClearAllIcon,
3433
+ CloseIcon,
3434
+ DensityLargeIcon,
3435
+ DensityMediumIcon,
3436
+ DensitySmallIcon,
3437
+ DragHandleIcon,
3438
+ DynamicFeedIcon,
3439
+ EditIcon,
3440
+ ExpandMoreIcon,
3441
+ FilterAltIcon,
3442
+ FilterListIcon,
3443
+ FilterListOffIcon,
3444
+ FirstPageIcon,
3445
+ FullscreenExitIcon,
3446
+ FullscreenIcon,
3447
+ KeyboardDoubleArrowDownIcon,
3448
+ LastPageIcon,
3449
+ MoreHorizIcon,
3450
+ MoreVertIcon,
3451
+ PushPinIcon,
3452
+ RestartAltIcon,
3453
+ SaveIcon,
3454
+ SearchIcon,
3455
+ SearchOffIcon,
3456
+ SortIcon,
3457
+ SyncAltIcon,
3458
+ ViewColumnIcon,
3459
+ VisibilityOffIcon,
3460
+ };
3461
+
3462
+ const MRT_Localization_EN = {
3463
+ actions: 'Actions',
3464
+ and: 'and',
3465
+ cancel: 'Cancel',
3466
+ changeFilterMode: 'Change filter mode',
3467
+ changeSearchMode: 'Change search mode',
3468
+ clearFilter: 'Clear filter',
3469
+ clearSearch: 'Clear search',
3470
+ clearSort: 'Clear sort',
3471
+ clickToCopy: 'Click to copy',
3472
+ collapse: 'Collapse',
3473
+ collapseAll: 'Collapse all',
3474
+ columnActions: 'Column Actions',
3475
+ copiedToClipboard: 'Copied to clipboard',
3476
+ dropToGroupBy: 'Drop to group by {column}',
3477
+ edit: 'Edit',
3478
+ expand: 'Expand',
3479
+ expandAll: 'Expand all',
3480
+ filterArrIncludes: 'Includes',
3481
+ filterArrIncludesAll: 'Includes all',
3482
+ filterArrIncludesSome: 'Includes',
3483
+ filterBetween: 'Between',
3484
+ filterBetweenInclusive: 'Between Inclusive',
3485
+ filterByColumn: 'Filter by {column}',
3486
+ filterContains: 'Contains',
3487
+ filterEmpty: 'Empty',
3488
+ filterEndsWith: 'Ends With',
3489
+ filterEquals: 'Equals',
3490
+ filterEqualsString: 'Equals',
3491
+ filterFuzzy: 'Fuzzy',
3492
+ filterGreaterThan: 'Greater Than',
3493
+ filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
3494
+ filterInNumberRange: 'Between',
3495
+ filterIncludesString: 'Contains',
3496
+ filterIncludesStringSensitive: 'Contains',
3497
+ filterLessThan: 'Less Than',
3498
+ filterLessThanOrEqualTo: 'Less Than Or Equal To',
3499
+ filterMode: 'Filter Mode: {filterType}',
3500
+ filterNotEmpty: 'Not Empty',
3501
+ filterNotEquals: 'Not Equals',
3502
+ filterStartsWith: 'Starts With',
3503
+ filterWeakEquals: 'Equals',
3504
+ filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
3505
+ goToFirstPage: 'Go to first page',
3506
+ goToLastPage: 'Go to last page',
3507
+ goToNextPage: 'Go to next page',
3508
+ goToPreviousPage: 'Go to previous page',
3509
+ grab: 'Grab',
3510
+ groupByColumn: 'Group by {column}',
3511
+ groupedBy: 'Grouped by ',
3512
+ hideAll: 'Hide all',
3513
+ hideColumn: 'Hide {column} column',
3514
+ max: 'Max',
3515
+ min: 'Min',
3516
+ move: 'Move',
3517
+ noRecordsToDisplay: 'No records to display',
3518
+ noResultsFound: 'No results found',
3519
+ of: 'of',
3520
+ or: 'or',
3521
+ pin: 'Pin',
3522
+ pinToLeft: 'Pin to left',
3523
+ pinToRight: 'Pin to right',
3524
+ resetColumnSize: 'Reset column size',
3525
+ resetOrder: 'Reset order',
3526
+ rowActions: 'Row Actions',
3527
+ rowNumber: '#',
3528
+ rowNumbers: 'Row Numbers',
3529
+ rowsPerPage: 'Rows per page',
3530
+ save: 'Save',
3531
+ search: 'Search',
3532
+ selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
3533
+ select: 'Select',
3534
+ showAll: 'Show all',
3535
+ showAllColumns: 'Show all columns',
3536
+ showHideColumns: 'Show/Hide columns',
3537
+ showHideFilters: 'Show/Hide filters',
3538
+ showHideSearch: 'Show/Hide search',
3539
+ sortByColumnAsc: 'Sort by {column} ascending',
3540
+ sortByColumnDesc: 'Sort by {column} descending',
3541
+ sortedByColumnAsc: 'Sorted by {column} ascending',
3542
+ sortedByColumnDesc: 'Sorted by {column} descending',
3543
+ thenBy: ', then by ',
3544
+ toggleDensity: 'Toggle density',
3545
+ toggleFullScreen: 'Toggle full screen',
3546
+ toggleSelectAll: 'Toggle select all',
3547
+ toggleSelectRow: 'Toggle select row',
3548
+ toggleVisibility: 'Toggle visibility',
3549
+ ungroupByColumn: 'Ungroup by {column}',
3550
+ unpin: 'Unpin',
3551
+ unpinAll: 'Unpin all',
3552
+ };
3553
+
3554
+ const MRT_DefaultColumn = {
3555
+ filterVariant: 'text',
3556
+ maxSize: 1000,
3557
+ minSize: 40,
3558
+ size: 180,
3559
+ };
3560
+ const MRT_DefaultDisplayColumn = {
3561
+ columnDefType: 'display',
3204
3562
  enableClickToCopy: false,
3205
3563
  enableColumnActions: false,
3206
3564
  enableColumnDragging: false,
@@ -3288,307 +3646,6 @@ const useMRT_TableOptions = (_a) => {
3288
3646
  selectAllMode, sortingFns: _sortingFns }, rest);
3289
3647
  };
3290
3648
 
3291
- const blankColProps = {
3292
- children: null,
3293
- sx: {
3294
- flex: '1 0 auto',
3295
- minWidth: 0,
3296
- p: 0,
3297
- width: 0,
3298
- },
3299
- };
3300
- const useMRT_DisplayColumns = ({ columnOrder, creatingRow, grouping, tableOptions, }) => {
3301
- var _a, _b;
3302
- return useMemo(() => {
3303
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
3304
- return [
3305
- ((_b = (_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.columnOrder) !== null && _b !== void 0 ? _b : columnOrder).includes('mrt-row-pin') && Object.assign(Object.assign({ Cell: ({ row, table }) => (jsx(MRT_TableBodyRowPinButton, { row: row, table: table })), header: tableOptions.localization.pin, size: 60 }, (_c = tableOptions.displayColumnDefOptions) === null || _c === void 0 ? void 0 : _c['mrt-row-pin']), { columnDefType: 'display', id: 'mrt-row-pin' }),
3306
- ((_e = (_d = tableOptions.state) === null || _d === void 0 ? void 0 : _d.columnOrder) !== null && _e !== void 0 ? _e : columnOrder).includes('mrt-row-drag') && Object.assign(Object.assign({ Cell: ({ row, rowRef, table }) => (jsx(MRT_TableBodyRowGrabHandle, { row: row, rowRef: rowRef, table: table })), header: tableOptions.localization.move, size: 60 }, (_f = tableOptions.displayColumnDefOptions) === null || _f === void 0 ? void 0 : _f['mrt-row-drag']), { columnDefType: 'display', id: 'mrt-row-drag' }),
3307
- (((_h = (_g = tableOptions.state) === null || _g === void 0 ? void 0 : _g.columnOrder) !== null && _h !== void 0 ? _h : columnOrder).includes('mrt-row-actions') ||
3308
- (creatingRow && tableOptions.createDisplayMode === 'row')) && Object.assign(Object.assign({ Cell: ({ cell, row, table }) => (jsx(MRT_ToggleRowActionMenuButton, { cell: cell, row: row, table: table })), header: tableOptions.localization.actions, size: 70 }, (_j = tableOptions.displayColumnDefOptions) === null || _j === void 0 ? void 0 : _j['mrt-row-actions']), { columnDefType: 'display', id: 'mrt-row-actions' }),
3309
- ((_l = (_k = tableOptions.state) === null || _k === void 0 ? void 0 : _k.columnOrder) !== null && _l !== void 0 ? _l : columnOrder).includes('mrt-row-expand') &&
3310
- showExpandColumn(tableOptions, (_o = (_m = tableOptions.state) === null || _m === void 0 ? void 0 : _m.grouping) !== null && _o !== void 0 ? _o : grouping) && Object.assign(Object.assign({ Cell: ({ row, table }) => (jsx(MRT_ExpandButton, { row: row, table: table })), Header: tableOptions.enableExpandAll
3311
- ? ({ table }) => jsx(MRT_ExpandAllButton, { table: table })
3312
- : null, header: tableOptions.localization.expand, size: 60 }, (_p = tableOptions.displayColumnDefOptions) === null || _p === void 0 ? void 0 : _p['mrt-row-expand']), { columnDefType: 'display', id: 'mrt-row-expand' }),
3313
- ((_r = (_q = tableOptions.state) === null || _q === void 0 ? void 0 : _q.columnOrder) !== null && _r !== void 0 ? _r : columnOrder).includes('mrt-row-select') && Object.assign(Object.assign({ Cell: ({ row, table }) => (jsx(MRT_SelectCheckbox, { row: row, table: table })), Header: tableOptions.enableSelectAll &&
3314
- tableOptions.enableMultiRowSelection
3315
- ? ({ table }) => jsx(MRT_SelectCheckbox, { selectAll: true, table: table })
3316
- : null, header: tableOptions.localization.select, size: 60 }, (_s = tableOptions.displayColumnDefOptions) === null || _s === void 0 ? void 0 : _s['mrt-row-select']), { columnDefType: 'display', id: 'mrt-row-select' }),
3317
- ((_u = (_t = tableOptions.state) === null || _t === void 0 ? void 0 : _t.columnOrder) !== null && _u !== void 0 ? _u : columnOrder).includes('mrt-row-numbers') && Object.assign(Object.assign({ Cell: ({ row }) => row.index + 1, Header: () => tableOptions.localization.rowNumber, header: tableOptions.localization.rowNumbers, size: 60 }, (_v = tableOptions.displayColumnDefOptions) === null || _v === void 0 ? void 0 : _v['mrt-row-numbers']), { columnDefType: 'display', id: 'mrt-row-numbers' }),
3318
- ((_x = (_w = tableOptions.state) === null || _w === void 0 ? void 0 : _w.columnOrder) !== null && _x !== void 0 ? _x : columnOrder).includes('mrt-row-spacer') && Object.assign(Object.assign(Object.assign({}, (_y = tableOptions.displayColumnDefOptions) === null || _y === void 0 ? void 0 : _y['mrt-row-spacer']), MRT_DefaultDisplayColumn), { columnDefType: 'display', header: '', id: 'mrt-row-spacer', muiTableBodyCellProps: blankColProps, muiTableFooterCellProps: blankColProps, muiTableHeadCellProps: blankColProps }),
3319
- ].filter(Boolean);
3320
- }, [
3321
- columnOrder,
3322
- grouping,
3323
- tableOptions.displayColumnDefOptions,
3324
- tableOptions.editDisplayMode,
3325
- tableOptions.enableColumnDragging,
3326
- tableOptions.enableColumnFilterModes,
3327
- tableOptions.enableColumnOrdering,
3328
- tableOptions.enableEditing,
3329
- tableOptions.enableExpandAll,
3330
- tableOptions.enableExpanding,
3331
- tableOptions.enableGrouping,
3332
- tableOptions.enableRowActions,
3333
- tableOptions.enableRowDragging,
3334
- tableOptions.enableRowNumbers,
3335
- tableOptions.enableRowOrdering,
3336
- tableOptions.enableRowSelection,
3337
- tableOptions.enableSelectAll,
3338
- tableOptions.localization,
3339
- tableOptions.positionActionsColumn,
3340
- tableOptions.renderDetailPanel,
3341
- tableOptions.renderRowActionMenuItems,
3342
- tableOptions.renderRowActions,
3343
- (_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.columnOrder,
3344
- (_b = tableOptions.state) === null || _b === void 0 ? void 0 : _b.grouping,
3345
- ]);
3346
- };
3347
-
3348
- const useMRT_Effects = (table) => {
3349
- const { getIsSomeRowsPinned, getState, options: { enablePagination, enableRowPinning, rowCount }, } = table;
3350
- const { density, globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting, } = getState();
3351
- const rerender = useReducer(() => ({}), {})[1];
3352
- const isMounted = useRef(false);
3353
- const initialBodyHeight = useRef();
3354
- const previousTop = useRef();
3355
- useEffect(() => {
3356
- if (typeof window !== 'undefined') {
3357
- initialBodyHeight.current = document.body.style.height;
3358
- }
3359
- }, []);
3360
- useEffect(() => {
3361
- if (isMounted && typeof window !== 'undefined') {
3362
- if (isFullScreen) {
3363
- previousTop.current = document.body.getBoundingClientRect().top; //save scroll position
3364
- document.body.style.height = '100vh'; //hide page scrollbars when table is in full screen mode
3365
- }
3366
- else {
3367
- document.body.style.height = initialBodyHeight.current;
3368
- if (!previousTop.current)
3369
- return;
3370
- //restore scroll position
3371
- window.scrollTo({
3372
- behavior: 'instant',
3373
- top: -1 * previousTop.current,
3374
- });
3375
- }
3376
- }
3377
- isMounted.current = true;
3378
- }, [isFullScreen]);
3379
- //if page index is out of bounds, set it to the last page
3380
- useEffect(() => {
3381
- if (!enablePagination || isLoading || showSkeletons)
3382
- return;
3383
- const { pageIndex, pageSize } = pagination;
3384
- const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : table.getPrePaginationRowModel().rows.length;
3385
- const firstVisibleRowIndex = pageIndex * pageSize;
3386
- if (firstVisibleRowIndex > totalRowCount) {
3387
- table.setPageIndex(Math.floor(totalRowCount / pageSize));
3388
- }
3389
- }, [rowCount, table.getPrePaginationRowModel().rows.length]);
3390
- //turn off sort when global filter is looking for ranked results
3391
- const appliedSort = useRef(sorting);
3392
- useEffect(() => {
3393
- if (sorting.length) {
3394
- appliedSort.current = sorting;
3395
- }
3396
- }, [sorting]);
3397
- useEffect(() => {
3398
- if (!getCanRankRows(table))
3399
- return;
3400
- if (globalFilter) {
3401
- table.setSorting([]);
3402
- }
3403
- else {
3404
- table.setSorting(() => appliedSort.current || []);
3405
- }
3406
- }, [globalFilter]);
3407
- useEffect(() => {
3408
- if (enableRowPinning && getIsSomeRowsPinned()) {
3409
- setTimeout(() => {
3410
- rerender();
3411
- }, 150);
3412
- }
3413
- }, [density]);
3414
- };
3415
-
3416
- const useMRT_TableInstance = (tableOptions) => {
3417
- 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, _5, _6, _7, _8, _9, _10;
3418
- const bottomToolbarRef = useRef(null);
3419
- const editInputRefs = useRef({});
3420
- const filterInputRefs = useRef({});
3421
- const searchInputRef = useRef(null);
3422
- const tableContainerRef = useRef(null);
3423
- const tableHeadCellRefs = useRef({});
3424
- const tablePaperRef = useRef(null);
3425
- const topToolbarRef = useRef(null);
3426
- const tableHeadRef = useRef(null);
3427
- const tableFooterRef = useRef(null);
3428
- const initialState = useMemo(() => {
3429
- var _a, _b, _c;
3430
- const initState = (_a = tableOptions.initialState) !== null && _a !== void 0 ? _a : {};
3431
- initState.columnOrder =
3432
- (_b = initState.columnOrder) !== null && _b !== void 0 ? _b : getDefaultColumnOrderIds(tableOptions);
3433
- initState.globalFilterFn = (_c = tableOptions.globalFilterFn) !== null && _c !== void 0 ? _c : 'fuzzy';
3434
- return initState;
3435
- }, []);
3436
- const [creatingRow, _setCreatingRow] = useState((_a = initialState.creatingRow) !== null && _a !== void 0 ? _a : null);
3437
- const [columnFilterFns, setColumnFilterFns] = useState(() => Object.assign({}, ...getAllLeafColumnDefs(tableOptions.columns).map((col) => {
3438
- var _a, _b, _c, _d;
3439
- return ({
3440
- [getColumnId(col)]: col.filterFn instanceof Function
3441
- ? (_a = col.filterFn.name) !== null && _a !== void 0 ? _a : 'custom'
3442
- : (_d = (_b = col.filterFn) !== null && _b !== void 0 ? _b : (_c = initialState === null || initialState === void 0 ? void 0 : initialState.columnFilterFns) === null || _c === void 0 ? void 0 : _c[getColumnId(col)]) !== null && _d !== void 0 ? _d : getDefaultColumnFilterFn(col),
3443
- });
3444
- })));
3445
- const [columnOrder, setColumnOrder] = useState((_b = initialState.columnOrder) !== null && _b !== void 0 ? _b : []);
3446
- const [density, setDensity] = useState((_c = initialState === null || initialState === void 0 ? void 0 : initialState.density) !== null && _c !== void 0 ? _c : 'comfortable');
3447
- const [draggingColumn, setDraggingColumn] = useState((_d = initialState.draggingColumn) !== null && _d !== void 0 ? _d : null);
3448
- const [draggingRow, setDraggingRow] = useState((_e = initialState.draggingRow) !== null && _e !== void 0 ? _e : null);
3449
- const [editingCell, setEditingCell] = useState((_f = initialState.editingCell) !== null && _f !== void 0 ? _f : null);
3450
- const [editingRow, setEditingRow] = useState((_g = initialState.editingRow) !== null && _g !== void 0 ? _g : null);
3451
- const [globalFilterFn, setGlobalFilterFn] = useState((_h = initialState.globalFilterFn) !== null && _h !== void 0 ? _h : 'fuzzy');
3452
- const [grouping, setGrouping] = useState((_j = initialState.grouping) !== null && _j !== void 0 ? _j : []);
3453
- const [hoveredColumn, setHoveredColumn] = useState((_k = initialState.hoveredColumn) !== null && _k !== void 0 ? _k : null);
3454
- const [hoveredRow, setHoveredRow] = useState((_l = initialState.hoveredRow) !== null && _l !== void 0 ? _l : null);
3455
- const [isFullScreen, setIsFullScreen] = useState((_m = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _m !== void 0 ? _m : false);
3456
- const [showAlertBanner, setShowAlertBanner] = useState((_p = (_o = tableOptions.initialState) === null || _o === void 0 ? void 0 : _o.showAlertBanner) !== null && _p !== void 0 ? _p : false);
3457
- const [showColumnFilters, setShowColumnFilters] = useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _q !== void 0 ? _q : false);
3458
- const [showGlobalFilter, setShowGlobalFilter] = useState((_r = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _r !== void 0 ? _r : false);
3459
- const [showToolbarDropZone, setShowToolbarDropZone] = useState((_s = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _s !== void 0 ? _s : false);
3460
- const displayColumns = useMRT_DisplayColumns({
3461
- columnOrder,
3462
- creatingRow,
3463
- grouping,
3464
- tableOptions,
3465
- });
3466
- const columnDefs = useMemo(() => {
3467
- var _a, _b, _c;
3468
- return prepareColumns({
3469
- aggregationFns: tableOptions.aggregationFns,
3470
- columnDefs: [...displayColumns, ...tableOptions.columns],
3471
- columnFilterFns: (_b = (_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.columnFilterFns) !== null && _b !== void 0 ? _b : columnFilterFns,
3472
- defaultDisplayColumn: (_c = tableOptions.defaultDisplayColumn) !== null && _c !== void 0 ? _c : {},
3473
- filterFns: tableOptions.filterFns,
3474
- sortingFns: tableOptions.sortingFns,
3475
- });
3476
- }, [
3477
- columnFilterFns,
3478
- displayColumns,
3479
- tableOptions.columns,
3480
- (_t = tableOptions.state) === null || _t === void 0 ? void 0 : _t.columnFilterFns,
3481
- ]);
3482
- const data = useMemo(() => {
3483
- var _a, _b, _c, _d, _e;
3484
- return (((_a = tableOptions.state) === null || _a === void 0 ? void 0 : _a.isLoading) || ((_b = tableOptions.state) === null || _b === void 0 ? void 0 : _b.showSkeletons)) &&
3485
- !tableOptions.data.length
3486
- ? [
3487
- ...Array(((_d = (_c = tableOptions.state) === null || _c === void 0 ? void 0 : _c.pagination) === null || _d === void 0 ? void 0 : _d.pageSize) ||
3488
- ((_e = initialState === null || initialState === void 0 ? void 0 : initialState.pagination) === null || _e === void 0 ? void 0 : _e.pageSize) ||
3489
- 10).fill(null),
3490
- ].map(() => Object.assign({}, ...getAllLeafColumnDefs(tableOptions.columns).map((col) => ({
3491
- [getColumnId(col)]: null,
3492
- }))))
3493
- : tableOptions.data;
3494
- }, [
3495
- tableOptions.data,
3496
- (_u = tableOptions.state) === null || _u === void 0 ? void 0 : _u.isLoading,
3497
- (_v = tableOptions.state) === null || _v === void 0 ? void 0 : _v.showSkeletons,
3498
- ]);
3499
- //@ts-ignore
3500
- const table = useReactTable(Object.assign(Object.assign({ getCoreRowModel: getCoreRowModel(), getExpandedRowModel: tableOptions.enableExpanding || tableOptions.enableGrouping
3501
- ? getExpandedRowModel()
3502
- : undefined, getFacetedMinMaxValues: tableOptions.enableFacetedValues
3503
- ? getFacetedMinMaxValues()
3504
- : undefined, getFacetedRowModel: tableOptions.enableFacetedValues
3505
- ? getFacetedRowModel()
3506
- : undefined, getFacetedUniqueValues: tableOptions.enableFacetedValues
3507
- ? getFacetedUniqueValues()
3508
- : undefined, getFilteredRowModel: tableOptions.enableColumnFilters ||
3509
- tableOptions.enableGlobalFilter ||
3510
- tableOptions.enableFilters
3511
- ? getFilteredRowModel()
3512
- : undefined, getGroupedRowModel: tableOptions.enableGrouping
3513
- ? getGroupedRowModel()
3514
- : undefined, getPaginationRowModel: tableOptions.enablePagination
3515
- ? getPaginationRowModel()
3516
- : undefined, getSortedRowModel: tableOptions.enableSorting
3517
- ? getSortedRowModel()
3518
- : undefined, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows, onColumnOrderChange: setColumnOrder, onGroupingChange: setGrouping }, tableOptions), {
3519
- //@ts-ignore
3520
- columns: columnDefs, data, globalFilterFn: (_w = tableOptions.filterFns) === null || _w === void 0 ? void 0 : _w[globalFilterFn !== null && globalFilterFn !== void 0 ? globalFilterFn : 'fuzzy'], initialState, state: Object.assign({ columnFilterFns,
3521
- columnOrder,
3522
- creatingRow,
3523
- density,
3524
- draggingColumn,
3525
- draggingRow,
3526
- editingCell,
3527
- editingRow,
3528
- globalFilterFn,
3529
- grouping,
3530
- hoveredColumn,
3531
- hoveredRow,
3532
- isFullScreen,
3533
- showAlertBanner,
3534
- showColumnFilters,
3535
- showGlobalFilter,
3536
- showToolbarDropZone }, tableOptions.state) }));
3537
- // @ts-ignore
3538
- table.refs = {
3539
- // @ts-ignore
3540
- bottomToolbarRef,
3541
- editInputRefs,
3542
- filterInputRefs,
3543
- // @ts-ignore
3544
- searchInputRef,
3545
- // @ts-ignore
3546
- tableContainerRef,
3547
- // @ts-ignore
3548
- tableFooterRef,
3549
- tableHeadCellRefs,
3550
- // @ts-ignore
3551
- tableHeadRef,
3552
- // @ts-ignore
3553
- tablePaperRef,
3554
- // @ts-ignore
3555
- topToolbarRef,
3556
- };
3557
- const setCreatingRow = (row) => {
3558
- var _a, _b;
3559
- let _row = row;
3560
- if (row === true) {
3561
- _row = createRow(table);
3562
- }
3563
- (_b = (_a = tableOptions === null || tableOptions === void 0 ? void 0 : tableOptions.onCreatingRowChange) === null || _a === void 0 ? void 0 : _a.call(tableOptions, _row)) !== null && _b !== void 0 ? _b : _setCreatingRow(_row);
3564
- };
3565
- table.setCreatingRow = setCreatingRow;
3566
- table.setColumnFilterFns =
3567
- (_x = tableOptions.onColumnFilterFnsChange) !== null && _x !== void 0 ? _x : setColumnFilterFns;
3568
- table.setDensity = (_y = tableOptions.onDensityChange) !== null && _y !== void 0 ? _y : setDensity;
3569
- table.setDraggingColumn =
3570
- (_z = tableOptions.onDraggingColumnChange) !== null && _z !== void 0 ? _z : setDraggingColumn;
3571
- table.setDraggingRow = (_0 = tableOptions.onDraggingRowChange) !== null && _0 !== void 0 ? _0 : setDraggingRow;
3572
- table.setEditingCell = (_1 = tableOptions.onEditingCellChange) !== null && _1 !== void 0 ? _1 : setEditingCell;
3573
- table.setEditingRow = (_2 = tableOptions.onEditingRowChange) !== null && _2 !== void 0 ? _2 : setEditingRow;
3574
- table.setGlobalFilterFn =
3575
- (_3 = tableOptions.onGlobalFilterFnChange) !== null && _3 !== void 0 ? _3 : setGlobalFilterFn;
3576
- table.setHoveredColumn =
3577
- (_4 = tableOptions.onHoveredColumnChange) !== null && _4 !== void 0 ? _4 : setHoveredColumn;
3578
- table.setHoveredRow = (_5 = tableOptions.onHoveredRowChange) !== null && _5 !== void 0 ? _5 : setHoveredRow;
3579
- table.setIsFullScreen = (_6 = tableOptions.onIsFullScreenChange) !== null && _6 !== void 0 ? _6 : setIsFullScreen;
3580
- table.setShowAlertBanner =
3581
- (_7 = tableOptions.onShowAlertBannerChange) !== null && _7 !== void 0 ? _7 : setShowAlertBanner;
3582
- table.setShowColumnFilters =
3583
- (_8 = tableOptions.onShowColumnFiltersChange) !== null && _8 !== void 0 ? _8 : setShowColumnFilters;
3584
- table.setShowGlobalFilter =
3585
- (_9 = tableOptions.onShowGlobalFilterChange) !== null && _9 !== void 0 ? _9 : setShowGlobalFilter;
3586
- table.setShowToolbarDropZone =
3587
- (_10 = tableOptions.onShowToolbarDropZoneChange) !== null && _10 !== void 0 ? _10 : setShowToolbarDropZone;
3588
- useMRT_Effects(table);
3589
- return table;
3590
- };
3591
-
3592
3649
  const useMaterialReactTable = (tableOptions) => useMRT_TableInstance(useMRT_TableOptions(tableOptions));
3593
3650
 
3594
3651
  const isTableInstanceProp = (props) => props.table !== undefined;