material-react-table 2.0.0-alpha.3 → 2.0.0-alpha.5
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/cjs/index.js +489 -435
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/icons.d.ts +4 -0
- package/dist/cjs/types/locales/hy.d.ts +2 -0
- package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/cjs/types/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
- package/dist/cjs/types/types.d.ts +18 -7
- package/dist/esm/material-react-table.esm.js +457 -410
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/icons.d.ts +4 -0
- package/dist/esm/types/locales/hy.d.ts +2 -0
- package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/esm/types/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
- package/dist/esm/types/types.d.ts +18 -7
- package/dist/index.d.ts +25 -10
- package/locales/hy.d.ts +2 -0
- package/locales/hy.esm.d.ts +2 -0
- package/locales/hy.esm.js +93 -0
- package/locales/hy.esm.js.map +1 -0
- package/locales/hy.js +97 -0
- package/locales/hy.js.map +1 -0
- package/package.json +7 -7
- package/src/body/MRT_TableBody.tsx +13 -21
- package/src/body/MRT_TableBodyCell.tsx +2 -2
- package/src/body/MRT_TableBodyRow.tsx +3 -3
- package/src/body/MRT_TableDetailPanel.tsx +3 -3
- package/src/buttons/MRT_GrabHandleButton.tsx +1 -2
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -2
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +1 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +1 -2
- package/src/buttons/MRT_ToggleFullScreenButton.tsx +2 -3
- package/src/column.utils.ts +15 -9
- package/src/footer/MRT_TableFooter.tsx +1 -1
- package/src/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/footer/MRT_TableFooterRow.tsx +2 -2
- package/src/head/MRT_TableHead.tsx +36 -14
- package/src/head/MRT_TableHeadCell.tsx +1 -1
- package/src/head/MRT_TableHeadRow.tsx +2 -2
- package/src/hooks/useMRT_Effects.ts +13 -2
- package/src/hooks/useMRT_TableOptions.ts +7 -2
- package/src/icons.ts +12 -0
- package/src/locales/hy.ts +93 -0
- package/src/table/MRT_Table.tsx +4 -2
- package/src/toolbar/MRT_TablePagination.tsx +135 -68
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +53 -15
- package/src/toolbar/MRT_TopToolbar.tsx +1 -1
- package/src/types.ts +22 -9
@@ -1,6 +1,6 @@
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
2
2
|
import Paper from '@mui/material/Paper';
|
3
|
-
import { useState, memo, useEffect, useMemo, useRef, useCallback,
|
3
|
+
import { useState, memo, useEffect, useMemo, useRef, useCallback, Fragment as Fragment$1, useLayoutEffect, useReducer } from 'react';
|
4
4
|
import TableContainer from '@mui/material/TableContainer';
|
5
5
|
import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
|
6
6
|
import Table from '@mui/material/Table';
|
@@ -39,23 +39,28 @@ import Popover from '@mui/material/Popover';
|
|
39
39
|
import Divider from '@mui/material/Divider';
|
40
40
|
import Badge from '@mui/material/Badge';
|
41
41
|
import TableSortLabel from '@mui/material/TableSortLabel';
|
42
|
-
import Dialog from '@mui/material/Dialog';
|
43
|
-
import DialogActions from '@mui/material/DialogActions';
|
44
|
-
import DialogContent from '@mui/material/DialogContent';
|
45
|
-
import DialogTitle from '@mui/material/DialogTitle';
|
46
|
-
import CircularProgress from '@mui/material/CircularProgress';
|
47
42
|
import Toolbar from '@mui/material/Toolbar';
|
48
43
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
49
44
|
import LinearProgress from '@mui/material/LinearProgress';
|
50
|
-
import
|
45
|
+
import InputLabel from '@mui/material/InputLabel';
|
46
|
+
import Pagination from '@mui/material/Pagination';
|
47
|
+
import PaginationItem from '@mui/material/PaginationItem';
|
48
|
+
import Select from '@mui/material/Select';
|
51
49
|
import Alert from '@mui/material/Alert';
|
52
50
|
import AlertTitle from '@mui/material/AlertTitle';
|
51
|
+
import Radio from '@mui/material/Radio';
|
53
52
|
import Fade from '@mui/material/Fade';
|
54
53
|
import Switch from '@mui/material/Switch';
|
55
|
-
import
|
54
|
+
import Dialog from '@mui/material/Dialog';
|
55
|
+
import DialogActions from '@mui/material/DialogActions';
|
56
|
+
import DialogContent from '@mui/material/DialogContent';
|
57
|
+
import DialogTitle from '@mui/material/DialogTitle';
|
58
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
56
59
|
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
|
57
60
|
import ArrowRightIcon from '@mui/icons-material/ArrowRight';
|
58
61
|
import CancelIcon from '@mui/icons-material/Cancel';
|
62
|
+
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
|
63
|
+
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
59
64
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
60
65
|
import CloseIcon from '@mui/icons-material/Close';
|
61
66
|
import DensityLargeIcon from '@mui/icons-material/DensityLarge';
|
@@ -68,9 +73,11 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
68
73
|
import FilterAltIcon from '@mui/icons-material/FilterAlt';
|
69
74
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
70
75
|
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
76
|
+
import FirstPageIcon from '@mui/icons-material/FirstPage';
|
71
77
|
import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
72
78
|
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
73
79
|
import KeyboardDoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
80
|
+
import LastPageIcon from '@mui/icons-material/LastPage';
|
74
81
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
75
82
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
76
83
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
@@ -318,19 +325,24 @@ const getCanRankRows = (table) => {
|
|
318
325
|
};
|
319
326
|
const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
|
320
327
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
328
|
+
const { options: { layoutMode }, } = table;
|
321
329
|
const widthStyles = {
|
322
330
|
minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) * 1px), ${(_b = column.columnDef.minSize) !== null && _b !== void 0 ? _b : 30}px)`,
|
323
331
|
width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_c = header === null || header === void 0 ? void 0 : header.id) !== null && _c !== void 0 ? _c : column.id)}-size) * 1px)`,
|
324
332
|
};
|
333
|
+
if (layoutMode === 'grid') {
|
334
|
+
widthStyles.flex = `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_d = header === null || header === void 0 ? void 0 : header.id) !== null && _d !== void 0 ? _d : column.id)}-size) 0 auto`;
|
335
|
+
}
|
336
|
+
else if (layoutMode === 'grid-no-grow') {
|
337
|
+
widthStyles.flex = '0 0 auto';
|
338
|
+
}
|
325
339
|
return Object.assign(Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
326
340
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
|
327
341
|
: 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
|
328
342
|
? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
329
343
|
: getIsFirstRightPinnedColumn(column)
|
330
344
|
? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
331
|
-
: undefined, display:
|
332
|
-
? `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_d = header === null || header === void 0 ? void 0 : header.id) !== null && _d !== void 0 ? _d : column.id)}-size) 0 auto`
|
333
|
-
: undefined, left: column.getIsPinned() === 'left'
|
345
|
+
: undefined, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, left: column.getIsPinned() === 'left'
|
334
346
|
? `${column.getStart('left')}px`
|
335
347
|
: undefined, ml: table.options.enableColumnVirtualization &&
|
336
348
|
column.getIsPinned() === 'left' &&
|
@@ -643,7 +655,7 @@ const MRT_TableBodyCell = ({ cell, measureElement, numRows, rowIndex, rowRef, ta
|
|
643
655
|
: undefined,
|
644
656
|
outlineOffset: '-1px',
|
645
657
|
textOverflow: 'clip',
|
646
|
-
}, alignItems: layoutMode === 'grid' ? 'center' : undefined, cursor: isEditable && editDisplayMode === 'cell' ? 'pointer' : 'inherit', justifyContent: layoutMode === 'grid' ? tableCellProps.align : undefined, overflow: 'hidden', p: density === 'compact'
|
658
|
+
}, alignItems: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'center' : undefined, cursor: isEditable && editDisplayMode === 'cell' ? 'pointer' : 'inherit', justifyContent: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? tableCellProps.align : undefined, overflow: 'hidden', p: density === 'compact'
|
647
659
|
? columnDefType === 'display'
|
648
660
|
? '0 0.5rem'
|
649
661
|
: '0.5rem'
|
@@ -696,14 +708,14 @@ const MRT_TableDetailPanel = ({ parentRowRef, row, rowIndex, table, virtualRow,
|
|
696
708
|
});
|
697
709
|
return (jsx(TableRow, Object.assign({ className: "Mui-TableBodyCell-DetailPanel" }, tableRowProps, { sx: (theme) => {
|
698
710
|
var _a, _b;
|
699
|
-
return (Object.assign({ display: layoutMode === 'grid' ? 'flex' :
|
711
|
+
return (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, position: virtualRow ? 'absolute' : undefined, top: virtualRow
|
700
712
|
? `${(_b = (_a = parentRowRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect()) === null || _b === void 0 ? void 0 : _b.height}px`
|
701
713
|
: undefined, transform: virtualRow
|
702
714
|
? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
|
703
715
|
: undefined, width: '100%', zIndex: virtualRow ? 2 : undefined }, parseFromValuesOrFunc(tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx, theme)));
|
704
716
|
}, children: jsx(TableCell, Object.assign({ className: "Mui-TableBodyCell-DetailPanel", colSpan: getVisibleLeafColumns().length }, tableCellProps, { sx: (theme) => (Object.assign({ backgroundColor: virtualRow
|
705
|
-
? lighten(theme.palette.background.default, 0.
|
706
|
-
: undefined, borderBottom: !row.getIsExpanded() ? 'none' : undefined, display: layoutMode === 'grid' ? 'flex' : 'table-cell', pb: row.getIsExpanded() ? '1rem' : 0, pt: row.getIsExpanded() ? '1rem' : 0, transition: 'all 150ms ease-in-out', width: `${table.getTotalSize()}px` }, parseFromValuesOrFunc(tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx, theme))), children: renderDetailPanel && (jsx(Collapse, { in: row.getIsExpanded(), mountOnEnter: true, unmountOnExit: true, children: !isLoading && renderDetailPanel({ row, table }) })) })) })));
|
717
|
+
? lighten(theme.palette.background.default, 0.05)
|
718
|
+
: undefined, borderBottom: !row.getIsExpanded() ? 'none' : undefined, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : 'table-cell', pb: row.getIsExpanded() ? '1rem' : 0, pt: row.getIsExpanded() ? '1rem' : 0, transition: 'all 150ms ease-in-out', width: `${table.getTotalSize()}px` }, parseFromValuesOrFunc(tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx, theme))), children: renderDetailPanel && (jsx(Collapse, { in: row.getIsExpanded(), mountOnEnter: true, unmountOnExit: true, children: !isLoading && renderDetailPanel({ row, table }) })) })) })));
|
707
719
|
};
|
708
720
|
|
709
721
|
const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRowIds, row, rowIndex, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, virtualRow, }) => {
|
@@ -758,10 +770,10 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRo
|
|
758
770
|
? `${lighten(theme.palette.background.default, 0.12)}`
|
759
771
|
: `${darken(theme.palette.background.default, 0.05)}`
|
760
772
|
: undefined,
|
761
|
-
}, backgroundColor: `${lighten(theme.palette.background.default, 0.
|
773
|
+
}, backgroundColor: `${lighten(theme.palette.background.default, 0.05)} !important`, bottom: !virtualRow && bottomPinnedIndex !== undefined && isPinned
|
762
774
|
? `${bottomPinnedIndex * rowHeight +
|
763
775
|
(enableStickyFooter ? tableFooterHeight - 1 : 0)}px`
|
764
|
-
: undefined, boxSizing: 'border-box', display: layoutMode === 'grid' ? 'flex' :
|
776
|
+
: undefined, boxSizing: 'border-box', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, opacity: isPinned
|
765
777
|
? 0.98
|
766
778
|
: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
|
767
779
|
? 0.5
|
@@ -781,7 +793,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, pinnedRo
|
|
781
793
|
? `${topPinnedIndex * rowHeight +
|
782
794
|
(enableStickyHeader || isFullScreen ? tableHeadHeight - 1 : 0)}px`
|
783
795
|
: undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', width: '100%', zIndex: (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) && isPinned
|
784
|
-
?
|
796
|
+
? 2
|
785
797
|
: undefined }, sx)), children: [virtualPaddingLeft ? (jsx("td", { style: { display: 'flex', width: virtualPaddingLeft } })) : null, (virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : row.getVisibleCells()).map((cellOrVirtualCell) => {
|
786
798
|
const cell = columnVirtualizer
|
787
799
|
? row.getVisibleCells()[cellOrVirtualCell.index]
|
@@ -824,7 +836,7 @@ const rankGlobalFuzzy = (rowA, rowB) => Math.max(...Object.values(rowB.columnFil
|
|
824
836
|
const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
825
837
|
var _a, _b, _c, _d, _e, _f;
|
826
838
|
const { getBottomRows, getCenterRows, getIsSomeRowsPinned, getPrePaginationRowModel, getRowModel, getState, getTopRows, options: { enableGlobalFilterRankedResults, enablePagination, enableRowPinning, enableRowVirtualization, enableStickyFooter, enableStickyHeader, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, renderEmptyRowsFallback, rowPinningDisplayMode, rowVirtualizerInstanceRef, rowVirtualizerOptions, }, refs: { tableContainerRef, tableFooterRef, tableHeadRef, tablePaperRef }, } = table;
|
827
|
-
const { columnFilters, density, expanded, globalFilter,
|
839
|
+
const { columnFilters, density, expanded, globalFilter, isFullScreen, pagination, rowPinning, sorting, } = getState();
|
828
840
|
const tableBodyProps = parseFromValuesOrFunc(muiTableBodyProps, { table });
|
829
841
|
const rowVirtualizerProps = parseFromValuesOrFunc(rowVirtualizerOptions, {
|
830
842
|
table,
|
@@ -833,16 +845,9 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
833
845
|
((_a = tableHeadRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight)) ||
|
834
846
|
0;
|
835
847
|
const tableFooterHeight = (enableStickyFooter && ((_b = tableFooterRef.current) === null || _b === void 0 ? void 0 : _b.clientHeight)) || 0;
|
836
|
-
const
|
837
|
-
!manualFiltering &&
|
838
|
-
!manualGrouping &&
|
839
|
-
!manualSorting &&
|
840
|
-
enableGlobalFilterRankedResults &&
|
841
|
-
globalFilter &&
|
842
|
-
globalFilterFn === 'fuzzy' &&
|
843
|
-
expanded !== true &&
|
848
|
+
const shouldRankRows = useMemo(() => getCanRankRows(table) &&
|
844
849
|
!Object.values(sorting).some(Boolean) &&
|
845
|
-
|
850
|
+
globalFilter, [
|
846
851
|
enableGlobalFilterRankedResults,
|
847
852
|
expanded,
|
848
853
|
globalFilter,
|
@@ -857,7 +862,7 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
857
862
|
.map((r) => r.id), [rowPinning, table.getRowModel().rows]);
|
858
863
|
const rows = useMemo(() => {
|
859
864
|
let rows = [];
|
860
|
-
if (!
|
865
|
+
if (!shouldRankRows) {
|
861
866
|
rows =
|
862
867
|
!enableRowPinning || (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky'))
|
863
868
|
? getRowModel().rows
|
@@ -879,8 +884,8 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
879
884
|
}
|
880
885
|
return rows;
|
881
886
|
}, [
|
882
|
-
|
883
|
-
|
887
|
+
shouldRankRows,
|
888
|
+
shouldRankRows ? getPrePaginationRowModel().rows : getRowModel().rows,
|
884
889
|
pagination.pageIndex,
|
885
890
|
pagination.pageSize,
|
886
891
|
rowPinning,
|
@@ -898,7 +903,7 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
898
903
|
? rowVirtualizer.getVirtualItems()
|
899
904
|
: undefined;
|
900
905
|
return (jsxs(Fragment, { children: [!(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
|
901
|
-
getIsSomeRowsPinned('top') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' :
|
906
|
+
getIsSomeRowsPinned('top') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', top: tableHeadHeight - 1, zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getTopRows().map((row, rowIndex) => {
|
902
907
|
const props = {
|
903
908
|
columnVirtualizer,
|
904
909
|
measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
|
@@ -911,10 +916,10 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
911
916
|
virtualPaddingRight,
|
912
917
|
};
|
913
918
|
return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
|
914
|
-
}) }))), jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' :
|
919
|
+
}) }))), jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, height: rowVirtualizer
|
915
920
|
? `${rowVirtualizer.getTotalSize()}px`
|
916
|
-
: 'inherit', minHeight: !rows.length ? '100px' : undefined, position: 'relative' }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: (_c = tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.children) !== null && _c !== void 0 ? _c : (!rows.length ? (jsx("tr", { style: { display: layoutMode === 'grid' ? 'grid' :
|
917
|
-
display: layoutMode === 'grid' ? 'grid' : 'table-cell',
|
921
|
+
: 'inherit', minHeight: !rows.length ? '100px' : undefined, position: 'relative' }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: (_c = tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.children) !== null && _c !== void 0 ? _c : (!rows.length ? (jsx("tr", { style: { display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined }, children: jsx("td", { colSpan: table.getVisibleLeafColumns().length, style: {
|
922
|
+
display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : 'table-cell',
|
918
923
|
}, children: (_d = renderEmptyRowsFallback === null || renderEmptyRowsFallback === void 0 ? void 0 : renderEmptyRowsFallback({ table })) !== null && _d !== void 0 ? _d : (jsx(Typography, { sx: {
|
919
924
|
color: 'text.secondary',
|
920
925
|
fontStyle: 'italic',
|
@@ -945,7 +950,7 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
945
950
|
};
|
946
951
|
return memoMode === 'rows' ? (jsx(Memo_MRT_TableBodyRow, Object.assign({}, props), row.id)) : (jsx(MRT_TableBodyRow, Object.assign({}, props), row.id));
|
947
952
|
}) }))) })), !(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky')) &&
|
948
|
-
getIsSomeRowsPinned('bottom') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ bottom: tableFooterHeight - 1, display: layoutMode === 'grid' ? 'grid' :
|
953
|
+
getIsSomeRowsPinned('bottom') && (jsx(TableBody, Object.assign({}, tableBodyProps, { sx: (theme) => (Object.assign({ bottom: tableFooterHeight - 1, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, position: 'sticky', zIndex: 1 }, parseFromValuesOrFunc(tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx, theme))), children: getBottomRows().map((row, rowIndex) => {
|
949
954
|
const props = {
|
950
955
|
columnVirtualizer,
|
951
956
|
measureElement: rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.measureElement,
|
@@ -973,7 +978,7 @@ const MRT_TableFooterCell = ({ footer, table, }) => {
|
|
973
978
|
column,
|
974
979
|
table,
|
975
980
|
}));
|
976
|
-
return (jsx(TableCell, Object.assign({ align: columnDefType === 'group' ? 'center' : 'left', colSpan: footer.colSpan, variant: "head" }, tableCellProps, { sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table-cell', fontWeight: 'bold', justifyContent: columnDefType === 'group' ? 'center' : undefined, p: density === 'compact'
|
981
|
+
return (jsx(TableCell, Object.assign({ align: columnDefType === 'group' ? 'center' : 'left', colSpan: footer.colSpan, variant: "head" }, tableCellProps, { sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : 'table-cell', fontWeight: 'bold', justifyContent: columnDefType === 'group' ? 'center' : undefined, p: density === 'compact'
|
977
982
|
? '0.5rem'
|
978
983
|
: density === 'comfortable'
|
979
984
|
? '1rem'
|
@@ -999,7 +1004,7 @@ const MRT_TableFooterRow = ({ footerGroup, table, virtualColumns, virtualPadding
|
|
999
1004
|
footerGroup,
|
1000
1005
|
table,
|
1001
1006
|
});
|
1002
|
-
return (jsxs(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.
|
1007
|
+
return (jsxs(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.05), display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, width: '100%' }, parseFromValuesOrFunc(tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx, theme))), children: [virtualPaddingLeft ? (jsx("th", { style: { display: 'flex', width: virtualPaddingLeft } })) : null, (virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : footerGroup.headers).map((footerOrVirtualFooter) => {
|
1003
1008
|
const footer = virtualColumns
|
1004
1009
|
? footerGroup.headers[footerOrVirtualFooter.index]
|
1005
1010
|
: footerOrVirtualFooter;
|
@@ -1020,7 +1025,7 @@ const MRT_TableFooter = ({ table, virtualColumns, virtualPaddingLeft, virtualPad
|
|
1020
1025
|
// @ts-ignore
|
1021
1026
|
tableFooterProps.ref.current = ref;
|
1022
1027
|
}
|
1023
|
-
}, sx: (theme) => (Object.assign({ bottom: stickFooter ? 0 : undefined, display: layoutMode === 'grid' ? 'grid' :
|
1028
|
+
}, sx: (theme) => (Object.assign({ bottom: stickFooter ? 0 : undefined, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, opacity: stickFooter ? 0.97 : undefined, outline: stickFooter
|
1024
1029
|
? theme.palette.mode === 'light'
|
1025
1030
|
? `1px solid ${theme.palette.grey[300]}`
|
1026
1031
|
: `1px solid ${theme.palette.grey[700]}`
|
@@ -1938,7 +1943,7 @@ const MRT_TableHeadCell = ({ header, table, }) => {
|
|
1938
1943
|
if (node) {
|
1939
1944
|
tableHeadCellRefs.current[column.id] = node;
|
1940
1945
|
}
|
1941
|
-
} }, tableCellProps, { sx: (theme) => (Object.assign(Object.assign({ flexDirection: layoutMode === 'grid' ? 'column' : undefined, fontWeight: 'bold', overflow: 'visible', p: density === 'compact'
|
1946
|
+
} }, tableCellProps, { sx: (theme) => (Object.assign(Object.assign({ flexDirection: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'column' : undefined, fontWeight: 'bold', overflow: 'visible', p: density === 'compact'
|
1942
1947
|
? '0.5rem'
|
1943
1948
|
: density === 'comfortable'
|
1944
1949
|
? columnDefType === 'display'
|
@@ -2005,7 +2010,7 @@ const MRT_TableHeadRow = ({ headerGroup, table, virtualColumns, virtualPaddingLe
|
|
2005
2010
|
headerGroup,
|
2006
2011
|
table,
|
2007
2012
|
});
|
2008
|
-
return (jsxs(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.
|
2013
|
+
return (jsxs(TableRow, Object.assign({}, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.05), boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`, display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'flex' : undefined, top: 0 }, parseFromValuesOrFunc(tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx, theme))), children: [virtualPaddingLeft ? (jsx("th", { style: { display: 'flex', width: virtualPaddingLeft } })) : null, (virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : headerGroup.headers).map((headerOrVirtualHeader) => {
|
2009
2014
|
const header = virtualColumns
|
2010
2015
|
? headerGroup.headers[headerOrVirtualHeader.index]
|
2011
2016
|
: headerOrVirtualHeader;
|
@@ -2013,208 +2018,6 @@ const MRT_TableHeadRow = ({ headerGroup, table, virtualColumns, virtualPaddingLe
|
|
2013
2018
|
}), virtualPaddingRight ? (jsx("th", { style: { display: 'flex', width: virtualPaddingRight } })) : null] })));
|
2014
2019
|
};
|
2015
2020
|
|
2016
|
-
const MRT_TableHead = ({ table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2017
|
-
const { getHeaderGroups, getState, options: { enableStickyHeader, layoutMode, muiTableHeadProps }, refs: { tableHeadRef }, } = table;
|
2018
|
-
const { isFullScreen } = getState();
|
2019
|
-
const tableHeadProps = parseFromValuesOrFunc(muiTableHeadProps, { table });
|
2020
|
-
const stickyHeader = enableStickyHeader || isFullScreen;
|
2021
|
-
return (jsx(TableHead, Object.assign({}, tableHeadProps, { ref: (ref) => {
|
2022
|
-
tableHeadRef.current = ref;
|
2023
|
-
if (tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.ref) {
|
2024
|
-
// @ts-ignore
|
2025
|
-
tableHeadProps.ref.current = ref;
|
2026
|
-
}
|
2027
|
-
}, sx: (theme) => (Object.assign({ display: layoutMode === 'grid' ? 'grid' : 'table-row-group', opacity: 0.97, position: stickyHeader ? 'sticky' : 'relative', top: stickyHeader && layoutMode === 'grid' ? 0 : undefined, zIndex: stickyHeader ? 2 : undefined }, parseFromValuesOrFunc(tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx, theme))), children: getHeaderGroups().map((headerGroup) => (jsx(MRT_TableHeadRow, { headerGroup: headerGroup, table: table, virtualColumns: virtualColumns, virtualPaddingLeft: virtualPaddingLeft, virtualPaddingRight: virtualPaddingRight }, headerGroup.id))) })));
|
2028
|
-
};
|
2029
|
-
|
2030
|
-
const MRT_Table = ({ table, }) => {
|
2031
|
-
var _a, _b, _c, _d;
|
2032
|
-
const { getFlatHeaders, getState, options: { columnVirtualizerInstanceRef, columnVirtualizerOptions, columns, enableColumnPinning, enableColumnResizing, enableColumnVirtualization, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, }, refs: { tableContainerRef }, } = table;
|
2033
|
-
const { columnPinning, columnSizing, columnSizingInfo, columnVisibility, isFullScreen, } = getState();
|
2034
|
-
const tableProps = parseFromValuesOrFunc(muiTableProps, { table });
|
2035
|
-
const columnVirtualizerProps = parseFromValuesOrFunc(columnVirtualizerOptions, { table });
|
2036
|
-
const columnSizeVars = useMemo(() => {
|
2037
|
-
const headers = getFlatHeaders();
|
2038
|
-
const colSizes = {};
|
2039
|
-
for (let i = 0; i < headers.length; i++) {
|
2040
|
-
const header = headers[i];
|
2041
|
-
const colSize = header.getSize();
|
2042
|
-
colSizes[`--header-${parseCSSVarId(header.id)}-size`] = colSize;
|
2043
|
-
colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
|
2044
|
-
}
|
2045
|
-
return colSizes;
|
2046
|
-
}, [columns, columnSizing, columnSizingInfo, columnVisibility]);
|
2047
|
-
//get first 16 column widths and average them
|
2048
|
-
const averageColumnWidth = useMemo(() => {
|
2049
|
-
var _a, _b, _c, _d;
|
2050
|
-
if (!enableColumnVirtualization)
|
2051
|
-
return 0;
|
2052
|
-
const columnsWidths = (_d = (_c = (_b = (_a = table
|
2053
|
-
.getRowModel()
|
2054
|
-
.rows[0]) === null || _a === void 0 ? void 0 : _a.getCenterVisibleCells()) === null || _b === void 0 ? void 0 : _b.slice(0, 16)) === null || _c === void 0 ? void 0 : _c.map((cell) => cell.column.getSize() * 1.2)) !== null && _d !== void 0 ? _d : [];
|
2055
|
-
return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
|
2056
|
-
}, [table.getRowModel().rows, columnPinning, columnVisibility]);
|
2057
|
-
const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(() => enableColumnVirtualization && enableColumnPinning
|
2058
|
-
? [
|
2059
|
-
table.getLeftLeafColumns().map((c) => c.getPinnedIndex()),
|
2060
|
-
table
|
2061
|
-
.getRightLeafColumns()
|
2062
|
-
.map((c) => table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1),
|
2063
|
-
]
|
2064
|
-
: [[], []], [columnPinning, enableColumnVirtualization, enableColumnPinning]);
|
2065
|
-
const columnVirtualizer = enableColumnVirtualization
|
2066
|
-
? useVirtualizer(Object.assign({ count: table.getVisibleLeafColumns().length, estimateSize: () => averageColumnWidth, getScrollElement: () => tableContainerRef.current, horizontal: true, overscan: 3, rangeExtractor: useCallback((range) => [
|
2067
|
-
...new Set([
|
2068
|
-
...leftPinnedIndexes,
|
2069
|
-
...defaultRangeExtractor(range),
|
2070
|
-
...rightPinnedIndexes,
|
2071
|
-
]),
|
2072
|
-
], [leftPinnedIndexes, rightPinnedIndexes]) }, columnVirtualizerProps))
|
2073
|
-
: undefined;
|
2074
|
-
if (columnVirtualizerInstanceRef && columnVirtualizer) {
|
2075
|
-
columnVirtualizerInstanceRef.current = columnVirtualizer;
|
2076
|
-
}
|
2077
|
-
const virtualColumns = columnVirtualizer
|
2078
|
-
? columnVirtualizer.getVirtualItems()
|
2079
|
-
: undefined;
|
2080
|
-
let virtualPaddingLeft;
|
2081
|
-
let virtualPaddingRight;
|
2082
|
-
if (columnVirtualizer && (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)) {
|
2083
|
-
virtualPaddingLeft = (_b = (_a = virtualColumns[leftPinnedIndexes.length]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0;
|
2084
|
-
virtualPaddingRight =
|
2085
|
-
columnVirtualizer.getTotalSize() -
|
2086
|
-
((_d = (_c = virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes.length]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0);
|
2087
|
-
}
|
2088
|
-
const props = {
|
2089
|
-
table,
|
2090
|
-
virtualColumns,
|
2091
|
-
virtualPaddingLeft,
|
2092
|
-
virtualPaddingRight,
|
2093
|
-
};
|
2094
|
-
return (jsx(Fragment, { children: jsxs(Table, Object.assign({ stickyHeader: enableStickyHeader || isFullScreen }, tableProps, { style: Object.assign(Object.assign({}, columnSizeVars), tableProps === null || tableProps === void 0 ? void 0 : tableProps.style), sx: (theme) => (Object.assign({ borderCollapse: 'separate', display: layoutMode === 'grid' ? 'grid' : 'table', tableLayout: layoutMode !== 'grid' && enableColumnResizing ? 'fixed' : undefined }, parseFromValuesOrFunc(tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx, theme))), children: [enableTableHead && jsx(MRT_TableHead, Object.assign({}, props)), memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? (jsx(Memo_MRT_TableBody, Object.assign({ columnVirtualizer: columnVirtualizer }, props))) : (jsx(MRT_TableBody, Object.assign({ columnVirtualizer: columnVirtualizer }, props))), enableTableFooter && jsx(MRT_TableFooter, Object.assign({}, props))] })) }));
|
2095
|
-
};
|
2096
|
-
|
2097
|
-
const MRT_EditActionButtons = ({ row, table, variant = 'icon', }) => {
|
2098
|
-
const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowCancel, onEditingRowSave, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table;
|
2099
|
-
const { creatingRow, editingRow, isSaving } = getState();
|
2100
|
-
const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
|
2101
|
-
const isEditing = (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id;
|
2102
|
-
const handleCancel = () => {
|
2103
|
-
if (isCreating) {
|
2104
|
-
onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
|
2105
|
-
setCreatingRow(null);
|
2106
|
-
}
|
2107
|
-
else if (isEditing) {
|
2108
|
-
onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
|
2109
|
-
setEditingRow(null);
|
2110
|
-
}
|
2111
|
-
row._valuesCache = {}; //reset values cache
|
2112
|
-
};
|
2113
|
-
const handleSubmitRow = () => {
|
2114
|
-
var _a;
|
2115
|
-
//look for auto-filled input values
|
2116
|
-
(_a = Object.values(editInputRefs === null || editInputRefs === void 0 ? void 0 : editInputRefs.current)
|
2117
|
-
.filter((inputRef) => { var _a, _b; return row.id === ((_b = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.name) === null || _a === void 0 ? void 0 : _a.split('_')) === null || _b === void 0 ? void 0 : _b[0]); })) === null || _a === void 0 ? void 0 : _a.forEach((input) => {
|
2118
|
-
if (input.value !== undefined &&
|
2119
|
-
Object.hasOwn(row === null || row === void 0 ? void 0 : row._valuesCache, input.name)) {
|
2120
|
-
// @ts-ignore
|
2121
|
-
row._valuesCache[input.name] = input.value;
|
2122
|
-
}
|
2123
|
-
});
|
2124
|
-
if (isCreating)
|
2125
|
-
onCreatingRowSave === null || onCreatingRowSave === void 0 ? void 0 : onCreatingRowSave({
|
2126
|
-
exitCreatingMode: () => setCreatingRow(null),
|
2127
|
-
row,
|
2128
|
-
table,
|
2129
|
-
values: row._valuesCache,
|
2130
|
-
});
|
2131
|
-
else if (isEditing) {
|
2132
|
-
onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
|
2133
|
-
exitEditingMode: () => setEditingRow(null),
|
2134
|
-
row,
|
2135
|
-
table,
|
2136
|
-
values: row === null || row === void 0 ? void 0 : row._valuesCache,
|
2137
|
-
});
|
2138
|
-
}
|
2139
|
-
};
|
2140
|
-
return (jsx(Box, { onClick: (e) => e.stopPropagation(), sx: { display: 'flex', gap: '0.75rem' }, children: variant === 'icon' ? (jsxs(Fragment, { children: [jsx(Tooltip, { arrow: true, title: localization.cancel, children: jsx(IconButton, { "aria-label": localization.cancel, onClick: handleCancel, children: jsx(CancelIcon, {}) }) }), jsx(Tooltip, { arrow: true, title: localization.save, children: jsx(IconButton, { "aria-label": localization.save, color: "info", onClick: handleSubmitRow, children: isSaving ? jsx(CircularProgress, { size: 18 }) : jsx(SaveIcon, {}) }) })] })) : (jsxs(Fragment, { children: [jsx(Button, { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxs(Button, { onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsx(CircularProgress, { color: "inherit", size: 18 }), localization.save] })] })) }));
|
2141
|
-
};
|
2142
|
-
|
2143
|
-
const MRT_EditRowModal = ({ open, table, }) => {
|
2144
|
-
var _a;
|
2145
|
-
const { getState, options: { localization, muiCreateRowModalProps, muiEditRowModalProps, onCreatingRowCancel, onEditingRowCancel, renderCreateRowModalContent, renderEditRowModalContent, }, setCreatingRow, setEditingRow, } = table;
|
2146
|
-
const { creatingRow, editingRow } = getState();
|
2147
|
-
const row = (creatingRow !== null && creatingRow !== void 0 ? creatingRow : editingRow);
|
2148
|
-
const dialogProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiEditRowModalProps, { row, table })), (creatingRow &&
|
2149
|
-
parseFromValuesOrFunc(muiCreateRowModalProps, { row, table })));
|
2150
|
-
const internalEditComponents = row
|
2151
|
-
.getAllCells()
|
2152
|
-
.filter((cell) => cell.column.columnDef.columnDefType === 'data')
|
2153
|
-
.map((cell) => (jsx(MRT_EditCellTextField, { cell: cell, table: table }, cell.id)));
|
2154
|
-
return (jsx(Dialog, Object.assign({ fullWidth: true, maxWidth: "xs", onClose: (event, reason) => {
|
2155
|
-
var _a;
|
2156
|
-
if (creatingRow) {
|
2157
|
-
onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
|
2158
|
-
setCreatingRow(null);
|
2159
|
-
}
|
2160
|
-
else {
|
2161
|
-
onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
|
2162
|
-
setEditingRow(null);
|
2163
|
-
}
|
2164
|
-
row._valuesCache = {}; //reset values cache
|
2165
|
-
(_a = dialogProps.onClose) === null || _a === void 0 ? void 0 : _a.call(dialogProps, event, reason);
|
2166
|
-
}, open: open }, dialogProps, { children: (_a = ((creatingRow &&
|
2167
|
-
(renderCreateRowModalContent === null || renderCreateRowModalContent === void 0 ? void 0 : renderCreateRowModalContent({
|
2168
|
-
internalEditComponents,
|
2169
|
-
row,
|
2170
|
-
table,
|
2171
|
-
}))) ||
|
2172
|
-
(renderEditRowModalContent === null || renderEditRowModalContent === void 0 ? void 0 : renderEditRowModalContent({
|
2173
|
-
internalEditComponents,
|
2174
|
-
row,
|
2175
|
-
table,
|
2176
|
-
})))) !== null && _a !== void 0 ? _a : (jsxs(Fragment, { children: [jsx(DialogTitle, { sx: { textAlign: 'center' }, children: localization.edit }), jsx(DialogContent, { children: jsx("form", { onSubmit: (e) => e.preventDefault(), children: jsx(Stack, { sx: {
|
2177
|
-
gap: '24px',
|
2178
|
-
paddingTop: '16px',
|
2179
|
-
width: '100%',
|
2180
|
-
}, children: internalEditComponents }) }) }), jsx(DialogActions, { sx: { p: '1.25rem' }, children: jsx(MRT_EditActionButtons, { row: row, table: table, variant: "text" }) })] })) })));
|
2181
|
-
};
|
2182
|
-
|
2183
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
2184
|
-
const MRT_TableContainer = ({ table, }) => {
|
2185
|
-
const { getState, options: { createDisplayMode, editDisplayMode, enableStickyHeader, muiTableContainerProps, }, refs: { bottomToolbarRef, tableContainerRef, topToolbarRef }, } = table;
|
2186
|
-
const { creatingRow, editingRow, isFullScreen } = getState();
|
2187
|
-
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
2188
|
-
const tableContainerProps = parseFromValuesOrFunc(muiTableContainerProps, {
|
2189
|
-
table,
|
2190
|
-
});
|
2191
|
-
useIsomorphicLayoutEffect(() => {
|
2192
|
-
var _a, _b, _c, _d;
|
2193
|
-
const topToolbarHeight = typeof document !== 'undefined'
|
2194
|
-
? (_b = (_a = topToolbarRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0
|
2195
|
-
: 0;
|
2196
|
-
const bottomToolbarHeight = typeof document !== 'undefined'
|
2197
|
-
? (_d = (_c = bottomToolbarRef === null || bottomToolbarRef === void 0 ? void 0 : bottomToolbarRef.current) === null || _c === void 0 ? void 0 : _c.offsetHeight) !== null && _d !== void 0 ? _d : 0
|
2198
|
-
: 0;
|
2199
|
-
setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
|
2200
|
-
});
|
2201
|
-
const createModalOpen = createDisplayMode === 'modal' && creatingRow;
|
2202
|
-
const editModalOpen = editDisplayMode === 'modal' && editingRow;
|
2203
|
-
return (jsxs(TableContainer, Object.assign({}, tableContainerProps, { ref: (node) => {
|
2204
|
-
if (node) {
|
2205
|
-
tableContainerRef.current = node;
|
2206
|
-
if (tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.ref) {
|
2207
|
-
//@ts-ignore
|
2208
|
-
tableContainerProps.ref.current = node;
|
2209
|
-
}
|
2210
|
-
}
|
2211
|
-
}, style: Object.assign({ maxHeight: isFullScreen
|
2212
|
-
? `calc(100vh - ${totalToolbarHeight}px)`
|
2213
|
-
: undefined }, tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.style), sx: (theme) => (Object.assign({ maxHeight: enableStickyHeader
|
2214
|
-
? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
|
2215
|
-
: undefined, maxWidth: '100%', overflow: 'auto' }, parseFromValuesOrFunc(tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx, theme))), children: [jsx(MRT_Table, { table: table }), (createModalOpen || editModalOpen) && (jsx(MRT_EditRowModal, { open: true, table: table }))] })));
|
2216
|
-
};
|
2217
|
-
|
2218
2021
|
const MRT_LinearProgressBar = ({ isTopToolbar, table, }) => {
|
2219
2022
|
const { getState, options: { muiLinearProgressProps }, } = table;
|
2220
2023
|
const { isLoading, showProgressBars } = getState();
|
@@ -2230,62 +2033,202 @@ const MRT_LinearProgressBar = ({ isTopToolbar, table, }) => {
|
|
2230
2033
|
}, unmountOnExit: true, children: jsx(LinearProgress, Object.assign({ "aria-busy": "true", "aria-label": "Loading", sx: { position: 'relative' } }, linearProgressProps)) }));
|
2231
2034
|
};
|
2232
2035
|
|
2036
|
+
/******************************************************************************
|
2037
|
+
Copyright (c) Microsoft Corporation.
|
2038
|
+
|
2039
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
2040
|
+
purpose with or without fee is hereby granted.
|
2041
|
+
|
2042
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
2043
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
2044
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
2045
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
2046
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
2047
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
2048
|
+
PERFORMANCE OF THIS SOFTWARE.
|
2049
|
+
***************************************************************************** */
|
2050
|
+
function __rest(s, e) {
|
2051
|
+
var t = {};
|
2052
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
2053
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
2054
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
2055
|
+
}
|
2056
|
+
return t;
|
2057
|
+
}
|
2058
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
2059
|
+
var e = new Error(message);
|
2060
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
2061
|
+
};
|
2062
|
+
|
2063
|
+
const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
|
2233
2064
|
const MRT_TablePagination = ({ position = 'bottom', table, }) => {
|
2234
|
-
const { getPrePaginationRowModel, getState, options: { enableToolbarInternalActions, localization,
|
2065
|
+
const { getPrePaginationRowModel, getState, options: { enableToolbarInternalActions, icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, localization, muiPaginationProps, paginationDisplayMode, rowCount, }, setPageIndex, setPageSize, } = table;
|
2235
2066
|
const { pagination: { pageIndex = 0, pageSize = 10 }, showGlobalFilter, } = getState();
|
2236
|
-
const
|
2237
|
-
const showFirstLastPageButtons = totalRowCount / pageSize > 2;
|
2238
|
-
const tablePaginationProps = parseFromValuesOrFunc(muiTablePaginationProps, {
|
2067
|
+
const paginationProps = parseFromValuesOrFunc(muiPaginationProps, {
|
2239
2068
|
table,
|
2240
2069
|
});
|
2241
|
-
const
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
}, '& .MuiTablePagination-displayedRows': {
|
2255
|
-
m: '0 1px',
|
2256
|
-
}, '& .MuiTablePagination-selectLabel': {
|
2257
|
-
m: '0 -1px',
|
2258
|
-
}, '& .MuiTablePagination-toolbar': {
|
2259
|
-
alignItems: 'center',
|
2260
|
-
display: 'flex',
|
2261
|
-
}, '&. MuiInputBase-root': {
|
2262
|
-
m: '0 1px',
|
2263
|
-
}, mt: position === 'top' &&
|
2070
|
+
const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length;
|
2071
|
+
const numberOfPages = Math.ceil(totalRowCount / pageSize);
|
2072
|
+
const showFirstLastPageButtons = numberOfPages > 2;
|
2073
|
+
const firstRowIndex = pageIndex * pageSize;
|
2074
|
+
const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
|
2075
|
+
const _a = paginationProps !== null && paginationProps !== void 0 ? paginationProps : {}, { showRowsPerPage = true, rowsPerPageOptions = defaultRowsPerPage, showFirstButton = showFirstLastPageButtons, showLastButton = showFirstLastPageButtons } = _a, rest = __rest(_a, ["showRowsPerPage", "rowsPerPageOptions", "showFirstButton", "showLastButton"]);
|
2076
|
+
return (jsxs(Box, { sx: {
|
2077
|
+
alignItems: 'center',
|
2078
|
+
display: 'flex',
|
2079
|
+
gap: '8px',
|
2080
|
+
justifyContent: 'space-between',
|
2081
|
+
justifySelf: 'flex-end',
|
2082
|
+
mt: position === 'top' &&
|
2264
2083
|
enableToolbarInternalActions &&
|
2265
2084
|
!showGlobalFilter
|
2266
|
-
? '
|
2267
|
-
: undefined,
|
2085
|
+
? '3rem'
|
2086
|
+
: undefined,
|
2087
|
+
position: 'relative',
|
2088
|
+
px: '4px',
|
2089
|
+
py: '12px',
|
2090
|
+
zIndex: 2,
|
2091
|
+
}, 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, { inputProps: { 'aria-label': localization.rowsPerPage }, id: "mrt-rows-per-page", label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { '&::before': { border: 'none' }, mb: 0 }, value: pageSize, variant: "standard", children: rowsPerPageOptions.map((value) => (jsx(MenuItem, { sx: { m: 0 }, value: value, children: value }, value))) })] })), paginationDisplayMode === 'pages' ? (jsx(Pagination, Object.assign({ count: numberOfPages, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsx(PaginationItem, Object.assign({ slots: {
|
2092
|
+
first: FirstPageIcon,
|
2093
|
+
last: LastPageIcon,
|
2094
|
+
next: ChevronRightIcon,
|
2095
|
+
previous: ChevronLeftIcon,
|
2096
|
+
} }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, rest))) : paginationDisplayMode === 'default' ? (jsxs(Fragment, { children: [jsx(Typography, { sx: { mb: 0, mx: '4px', minWidth: '10ch' }, 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] }));
|
2268
2097
|
};
|
2269
2098
|
|
2270
|
-
const
|
2271
|
-
var _a
|
2272
|
-
const {
|
2273
|
-
const {
|
2099
|
+
const MRT_GlobalFilterTextField = ({ table, }) => {
|
2100
|
+
var _a;
|
2101
|
+
const { getState, options: { enableGlobalFilterModes, icons: { CloseIcon, SearchIcon }, localization, manualFiltering, muiSearchTextFieldProps, }, refs: { searchInputRef }, setGlobalFilter, } = table;
|
2102
|
+
const { globalFilter, showGlobalFilter } = getState();
|
2103
|
+
const textFieldProps = parseFromValuesOrFunc(muiSearchTextFieldProps, {
|
2104
|
+
table,
|
2105
|
+
});
|
2106
|
+
const isMounted = useRef(false);
|
2107
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
2108
|
+
const [searchValue, setSearchValue] = useState(globalFilter !== null && globalFilter !== void 0 ? globalFilter : '');
|
2109
|
+
const handleChangeDebounced = useCallback(debounce((event) => {
|
2110
|
+
var _a;
|
2111
|
+
setGlobalFilter((_a = event.target.value) !== null && _a !== void 0 ? _a : undefined);
|
2112
|
+
}, manualFiltering ? 500 : 250), []);
|
2113
|
+
const handleChange = (event) => {
|
2114
|
+
setSearchValue(event.target.value);
|
2115
|
+
handleChangeDebounced(event);
|
2116
|
+
};
|
2117
|
+
const handleGlobalFilterMenuOpen = (event) => {
|
2118
|
+
setAnchorEl(event.currentTarget);
|
2119
|
+
};
|
2120
|
+
const handleClear = () => {
|
2121
|
+
setSearchValue('');
|
2122
|
+
setGlobalFilter(undefined);
|
2123
|
+
};
|
2124
|
+
useEffect(() => {
|
2125
|
+
if (isMounted.current) {
|
2126
|
+
if (globalFilter === undefined) {
|
2127
|
+
handleClear();
|
2128
|
+
}
|
2129
|
+
else {
|
2130
|
+
setSearchValue(globalFilter);
|
2131
|
+
}
|
2132
|
+
}
|
2133
|
+
isMounted.current = true;
|
2134
|
+
}, [globalFilter]);
|
2135
|
+
return (jsxs(Collapse, { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsx(TextField, Object.assign({ InputProps: {
|
2136
|
+
endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { arrow: true, title: (_a = localization.clearSearch) !== null && _a !== void 0 ? _a : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsx(CloseIcon, {}) }) }) }) })),
|
2137
|
+
startAdornment: enableGlobalFilterModes ? (jsx(InputAdornment, { position: "start", children: jsx(Tooltip, { arrow: true, title: localization.changeSearchMode, children: jsx(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(SearchIcon, {}) }) }) })) : (jsx(SearchIcon, { style: { marginRight: '4px' } })),
|
2138
|
+
}, onChange: handleChange, placeholder: localization.search, value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "standard" }, textFieldProps, { inputRef: (inputRef) => {
|
2139
|
+
searchInputRef.current = inputRef;
|
2140
|
+
if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.inputRef) {
|
2141
|
+
textFieldProps.inputRef = inputRef;
|
2142
|
+
}
|
2143
|
+
} })), jsx(MRT_FilterOptionMenu, { anchorEl: anchorEl, onSelect: handleClear, setAnchorEl: setAnchorEl, table: table })] }));
|
2144
|
+
};
|
2145
|
+
|
2146
|
+
const MRT_SelectCheckbox = ({ row, selectAll, table, }) => {
|
2147
|
+
var _a;
|
2148
|
+
const { getState, options: { enableMultiRowSelection, enableRowPinning, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, rowPinningDisplayMode, selectAllMode, }, } = table;
|
2149
|
+
const { density, isLoading } = getState();
|
2150
|
+
const checkboxProps = !row
|
2151
|
+
? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
|
2152
|
+
: parseFromValuesOrFunc(muiSelectCheckboxProps, { row, table });
|
2153
|
+
const allRowsSelected = selectAll
|
2154
|
+
? selectAllMode === 'page'
|
2155
|
+
? table.getIsAllPageRowsSelected()
|
2156
|
+
: table.getIsAllRowsSelected()
|
2157
|
+
: undefined;
|
2158
|
+
const commonProps = Object.assign(Object.assign({ checked: selectAll ? allRowsSelected : row === null || row === void 0 ? void 0 : row.getIsSelected(), disabled: isLoading || (row && !row.getCanSelect()), inputProps: {
|
2159
|
+
'aria-label': selectAll
|
2160
|
+
? localization.toggleSelectAll
|
2161
|
+
: localization.toggleSelectRow,
|
2162
|
+
}, onChange: (event) => {
|
2163
|
+
event.stopPropagation();
|
2164
|
+
row
|
2165
|
+
? row.getToggleSelectedHandler()(event)
|
2166
|
+
: selectAllMode === 'all'
|
2167
|
+
? table.getToggleAllRowsSelectedHandler()(event)
|
2168
|
+
: table.getToggleAllPageRowsSelectedHandler()(event);
|
2169
|
+
if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
|
2170
|
+
if (row) {
|
2171
|
+
row.pin(!row.getIsPinned() && event.target.checked
|
2172
|
+
? (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('bottom'))
|
2173
|
+
? 'bottom'
|
2174
|
+
: 'top'
|
2175
|
+
: false);
|
2176
|
+
}
|
2177
|
+
else {
|
2178
|
+
table.setRowPinning({ bottom: [], top: [] });
|
2179
|
+
}
|
2180
|
+
}
|
2181
|
+
}, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
|
2182
|
+
var _a;
|
2183
|
+
e.stopPropagation();
|
2184
|
+
(_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
|
2185
|
+
}, sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.5rem', zIndex: 0 }, parseFromValuesOrFunc(checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx, theme))), title: undefined });
|
2186
|
+
return (jsx(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: (_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _a !== void 0 ? _a : (selectAll
|
2187
|
+
? localization.toggleSelectAll
|
2188
|
+
: localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsx(Radio, Object.assign({}, commonProps))) : (jsx(Checkbox, Object.assign({ indeterminate: selectAll
|
2189
|
+
? table.getIsSomeRowsSelected() && !allRowsSelected
|
2190
|
+
: row === null || row === void 0 ? void 0 : row.getIsSomeSelected() }, commonProps))) }));
|
2191
|
+
};
|
2192
|
+
|
2193
|
+
const MRT_ToolbarAlertBanner = ({ stackAlertBanner, table, }) => {
|
2194
|
+
var _a, _b, _c;
|
2195
|
+
const { getPrePaginationRowModel, getSelectedRowModel, getState, options: { enableRowSelection, enableSelectAll, localization, muiToolbarAlertBannerChipProps, muiToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, refs: { tablePaperRef }, } = table;
|
2196
|
+
const { density, grouping, showAlertBanner } = getState();
|
2274
2197
|
const alertProps = parseFromValuesOrFunc(muiToolbarAlertBannerProps, {
|
2275
2198
|
table,
|
2276
2199
|
});
|
2277
2200
|
const chipProps = parseFromValuesOrFunc(muiToolbarAlertBannerChipProps, {
|
2278
2201
|
table,
|
2279
2202
|
});
|
2280
|
-
const
|
2203
|
+
const selectedAlert = getSelectedRowModel().rows.length > 0
|
2281
2204
|
? (_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}', (rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length).toString())
|
2282
2205
|
: null;
|
2283
|
-
const
|
2284
|
-
return (jsx(Collapse, { in: showAlertBanner || !!
|
2285
|
-
|
2286
|
-
|
2287
|
-
?
|
2288
|
-
|
2206
|
+
const groupedAlert = grouping.length > 0 ? (jsxs("span", { children: [localization.groupedBy, ' ', grouping.map((columnId, index) => (jsxs(Fragment$1, { children: [index > 0 ? localization.thenBy : '', jsx(Chip, Object.assign({ label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() }, chipProps))] }, `${index}-${columnId}`)))] })) : null;
|
2207
|
+
return (jsx(Collapse, { in: showAlertBanner || !!selectedAlert || !!groupedAlert, timeout: stackAlertBanner ? 200 : 0, children: jsx(Alert, Object.assign({ color: "info", icon: false }, alertProps, { sx: (theme) => {
|
2208
|
+
var _a, _b;
|
2209
|
+
return (Object.assign({ '& .MuiAlert-message': {
|
2210
|
+
maxWidth: `calc(${(_b = (_a = tablePaperRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : 360}px - 1rem)`,
|
2211
|
+
width: '100%',
|
2212
|
+
}, borderRadius: 0, fontSize: '1rem', left: 0, mb: stackAlertBanner
|
2213
|
+
? 0
|
2214
|
+
: positionToolbarAlertBanner === 'bottom'
|
2215
|
+
? '-1rem'
|
2216
|
+
: undefined, p: 0, position: 'relative', right: 0, top: 0, width: '100%', zIndex: 2 }, parseFromValuesOrFunc(alertProps === null || alertProps === void 0 ? void 0 : alertProps.sx, theme)));
|
2217
|
+
}, children: (_c = renderToolbarAlertBannerContent === null || renderToolbarAlertBannerContent === void 0 ? void 0 : renderToolbarAlertBannerContent({
|
2218
|
+
groupedAlert,
|
2219
|
+
selectedAlert,
|
2220
|
+
table,
|
2221
|
+
})) !== null && _c !== void 0 ? _c : (jsxs(Fragment, { children: [(alertProps === null || alertProps === void 0 ? void 0 : alertProps.title) && jsx(AlertTitle, { children: alertProps.title }), jsxs(Stack, { sx: {
|
2222
|
+
p: positionToolbarAlertBanner !== 'head-overlay'
|
2223
|
+
? '0.5rem 1rem'
|
2224
|
+
: density === 'spacious'
|
2225
|
+
? '0.75rem 1.25rem'
|
2226
|
+
: density === 'comfortable'
|
2227
|
+
? '0.5rem 0.75rem'
|
2228
|
+
: '0.25rem 0.5rem',
|
2229
|
+
}, children: [alertProps === null || alertProps === void 0 ? void 0 : alertProps.children, (alertProps === null || alertProps === void 0 ? void 0 : alertProps.children) && (selectedAlert || groupedAlert) && (jsx("br", {})), jsxs(Box, { sx: { display: 'flex' }, children: [enableRowSelection &&
|
2230
|
+
enableSelectAll &&
|
2231
|
+
positionToolbarAlertBanner === 'head-overlay' && (jsx(MRT_SelectCheckbox, { selectAll: true, table: table })), ' ', selectedAlert] }), selectedAlert && groupedAlert && jsx("br", {}), groupedAlert] })] })) })) }));
|
2289
2232
|
};
|
2290
2233
|
|
2291
2234
|
const MRT_ToolbarDropZone = ({ table, }) => {
|
@@ -2319,33 +2262,6 @@ const MRT_ToolbarDropZone = ({ table, }) => {
|
|
2319
2262
|
}), children: jsx(Typography, { fontStyle: "italic", children: localization.dropToGroupBy.replace('{column}', (_b = (_a = draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.columnDef) === null || _a === void 0 ? void 0 : _a.header) !== null && _b !== void 0 ? _b : '') }) }) }));
|
2320
2263
|
};
|
2321
2264
|
|
2322
|
-
/******************************************************************************
|
2323
|
-
Copyright (c) Microsoft Corporation.
|
2324
|
-
|
2325
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
2326
|
-
purpose with or without fee is hereby granted.
|
2327
|
-
|
2328
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
2329
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
2330
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
2331
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
2332
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
2333
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
2334
|
-
PERFORMANCE OF THIS SOFTWARE.
|
2335
|
-
***************************************************************************** */
|
2336
|
-
function __rest(s, e) {
|
2337
|
-
var t = {};
|
2338
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
2339
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
2340
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
2341
|
-
}
|
2342
|
-
return t;
|
2343
|
-
}
|
2344
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
2345
|
-
var e = new Error(message);
|
2346
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
2347
|
-
};
|
2348
|
-
|
2349
2265
|
const MRT_ColumnPinningButtons = ({ column, table, }) => {
|
2350
2266
|
const { options: { icons: { PushPinIcon }, localization, }, } = table;
|
2351
2267
|
const handlePinColumn = (pinDirection) => {
|
@@ -2513,7 +2429,7 @@ const MRT_ToggleFullScreenButton = (_a) => {
|
|
2513
2429
|
setTooltipOpened(false);
|
2514
2430
|
setIsFullScreen(!isFullScreen);
|
2515
2431
|
};
|
2516
|
-
return (jsx(Tooltip, { arrow: true, open: tooltipOpened, title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.toggleFullScreen, children: jsx(IconButton, Object.assign({ "aria-label": localization.
|
2432
|
+
return (jsx(Tooltip, { arrow: true, open: tooltipOpened, title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.toggleFullScreen, children: jsx(IconButton, Object.assign({ "aria-label": localization.toggleFullScreen, onClick: handleToggleFullScreen, onMouseEnter: () => setTooltipOpened(true), onMouseLeave: () => setTooltipOpened(false) }, rest, { title: undefined, children: isFullScreen ? jsx(FullscreenExitIcon, {}) : jsx(FullscreenIcon, {}) })) }));
|
2517
2433
|
};
|
2518
2434
|
|
2519
2435
|
const MRT_ToggleGlobalFilterButton = (_a) => {
|
@@ -2544,56 +2460,9 @@ const MRT_ToolbarInternalButtons = ({ table, }) => {
|
|
2544
2460
|
columnFilterDisplayMode !== 'popover' && (jsx(MRT_ToggleFiltersButton, { table: table })), (enableHiding || enableColumnOrdering || enableColumnPinning) && (jsx(MRT_ShowHideColumnsButton, { table: table })), enableDensityToggle && (jsx(MRT_ToggleDensePaddingButton, { table: table })), enableFullScreenToggle && (jsx(MRT_ToggleFullScreenButton, { table: table }))] })) }));
|
2545
2461
|
};
|
2546
2462
|
|
2547
|
-
const MRT_GlobalFilterTextField = ({ table, }) => {
|
2548
|
-
var _a;
|
2549
|
-
const { getState, options: { enableGlobalFilterModes, icons: { CloseIcon, SearchIcon }, localization, manualFiltering, muiSearchTextFieldProps, }, refs: { searchInputRef }, setGlobalFilter, } = table;
|
2550
|
-
const { globalFilter, showGlobalFilter } = getState();
|
2551
|
-
const textFieldProps = parseFromValuesOrFunc(muiSearchTextFieldProps, {
|
2552
|
-
table,
|
2553
|
-
});
|
2554
|
-
const isMounted = useRef(false);
|
2555
|
-
const [anchorEl, setAnchorEl] = useState(null);
|
2556
|
-
const [searchValue, setSearchValue] = useState(globalFilter !== null && globalFilter !== void 0 ? globalFilter : '');
|
2557
|
-
const handleChangeDebounced = useCallback(debounce((event) => {
|
2558
|
-
var _a;
|
2559
|
-
setGlobalFilter((_a = event.target.value) !== null && _a !== void 0 ? _a : undefined);
|
2560
|
-
}, manualFiltering ? 500 : 250), []);
|
2561
|
-
const handleChange = (event) => {
|
2562
|
-
setSearchValue(event.target.value);
|
2563
|
-
handleChangeDebounced(event);
|
2564
|
-
};
|
2565
|
-
const handleGlobalFilterMenuOpen = (event) => {
|
2566
|
-
setAnchorEl(event.currentTarget);
|
2567
|
-
};
|
2568
|
-
const handleClear = () => {
|
2569
|
-
setSearchValue('');
|
2570
|
-
setGlobalFilter(undefined);
|
2571
|
-
};
|
2572
|
-
useEffect(() => {
|
2573
|
-
if (isMounted.current) {
|
2574
|
-
if (globalFilter === undefined) {
|
2575
|
-
handleClear();
|
2576
|
-
}
|
2577
|
-
else {
|
2578
|
-
setSearchValue(globalFilter);
|
2579
|
-
}
|
2580
|
-
}
|
2581
|
-
isMounted.current = true;
|
2582
|
-
}, [globalFilter]);
|
2583
|
-
return (jsxs(Collapse, { in: showGlobalFilter, mountOnEnter: true, orientation: "horizontal", unmountOnExit: true, children: [jsx(TextField, Object.assign({ InputProps: {
|
2584
|
-
endAdornment: (jsx(InputAdornment, { position: "end", children: jsx(Tooltip, { arrow: true, title: (_a = localization.clearSearch) !== null && _a !== void 0 ? _a : '', children: jsx("span", { children: jsx(IconButton, { "aria-label": localization.clearSearch, disabled: !(searchValue === null || searchValue === void 0 ? void 0 : searchValue.length), onClick: handleClear, size: "small", children: jsx(CloseIcon, {}) }) }) }) })),
|
2585
|
-
startAdornment: enableGlobalFilterModes ? (jsx(InputAdornment, { position: "start", children: jsx(Tooltip, { arrow: true, title: localization.changeSearchMode, children: jsx(IconButton, { "aria-label": localization.changeSearchMode, onClick: handleGlobalFilterMenuOpen, size: "small", sx: { height: '1.75rem', width: '1.75rem' }, children: jsx(SearchIcon, {}) }) }) })) : (jsx(SearchIcon, { style: { marginRight: '4px' } })),
|
2586
|
-
}, onChange: handleChange, placeholder: localization.search, value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "standard" }, textFieldProps, { inputRef: (inputRef) => {
|
2587
|
-
searchInputRef.current = inputRef;
|
2588
|
-
if (textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.inputRef) {
|
2589
|
-
textFieldProps.inputRef = inputRef;
|
2590
|
-
}
|
2591
|
-
} })), jsx(MRT_FilterOptionMenu, { anchorEl: anchorEl, onSelect: handleClear, setAnchorEl: setAnchorEl, table: table })] }));
|
2592
|
-
};
|
2593
|
-
|
2594
2463
|
const commonToolbarStyles = ({ theme }) => ({
|
2595
2464
|
alignItems: 'flex-start',
|
2596
|
-
backgroundColor: lighten(theme.palette.background.default, 0.
|
2465
|
+
backgroundColor: lighten(theme.palette.background.default, 0.05),
|
2597
2466
|
backgroundImage: 'none',
|
2598
2467
|
display: 'grid',
|
2599
2468
|
flexWrap: 'wrap-reverse',
|
@@ -2666,6 +2535,214 @@ const MRT_BottomToolbar = ({ table, }) => {
|
|
2666
2535
|
['both', 'bottom'].includes(positionPagination !== null && positionPagination !== void 0 ? positionPagination : '') && (jsx(MRT_TablePagination, { position: "bottom", table: table })) })] })] })));
|
2667
2536
|
};
|
2668
2537
|
|
2538
|
+
const MRT_TableHead = ({ table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2539
|
+
const { getHeaderGroups, getSelectedRowModel, getState, options: { enableStickyHeader, layoutMode, muiTableHeadProps, positionToolbarAlertBanner, }, refs: { tableHeadRef }, } = table;
|
2540
|
+
const { isFullScreen, showAlertBanner } = getState();
|
2541
|
+
const tableHeadProps = parseFromValuesOrFunc(muiTableHeadProps, { table });
|
2542
|
+
const stickyHeader = enableStickyHeader || isFullScreen;
|
2543
|
+
return (jsx(TableHead, Object.assign({}, tableHeadProps, { ref: (ref) => {
|
2544
|
+
tableHeadRef.current = ref;
|
2545
|
+
if (tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.ref) {
|
2546
|
+
// @ts-ignore
|
2547
|
+
tableHeadProps.ref.current = ref;
|
2548
|
+
}
|
2549
|
+
}, sx: (theme) => (Object.assign({ display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, opacity: 0.97, position: stickyHeader ? 'sticky' : 'relative', top: stickyHeader && (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 0 : undefined, zIndex: stickyHeader ? 2 : undefined }, parseFromValuesOrFunc(tableHeadProps === null || tableHeadProps === void 0 ? void 0 : tableHeadProps.sx, theme))), children: positionToolbarAlertBanner === 'head-overlay' &&
|
2550
|
+
(showAlertBanner || getSelectedRowModel().rows.length > 0) ? (jsx("tr", { style: { display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined }, children: jsx("th", { colSpan: table.getVisibleLeafColumns().length, style: {
|
2551
|
+
display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : 'table-cell',
|
2552
|
+
padding: 0,
|
2553
|
+
}, children: jsx(MRT_ToolbarAlertBanner, { table: table }) }) })) : (getHeaderGroups().map((headerGroup) => (jsx(MRT_TableHeadRow, { headerGroup: headerGroup, table: table, virtualColumns: virtualColumns, virtualPaddingLeft: virtualPaddingLeft, virtualPaddingRight: virtualPaddingRight }, headerGroup.id)))) })));
|
2554
|
+
};
|
2555
|
+
|
2556
|
+
const MRT_Table = ({ table, }) => {
|
2557
|
+
var _a, _b, _c, _d;
|
2558
|
+
const { getFlatHeaders, getState, options: { columnVirtualizerInstanceRef, columnVirtualizerOptions, columns, enableColumnPinning, enableColumnResizing, enableColumnVirtualization, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, }, refs: { tableContainerRef }, } = table;
|
2559
|
+
const { columnPinning, columnSizing, columnSizingInfo, columnVisibility, isFullScreen, } = getState();
|
2560
|
+
const tableProps = parseFromValuesOrFunc(muiTableProps, { table });
|
2561
|
+
const columnVirtualizerProps = parseFromValuesOrFunc(columnVirtualizerOptions, { table });
|
2562
|
+
const columnSizeVars = useMemo(() => {
|
2563
|
+
const headers = getFlatHeaders();
|
2564
|
+
const colSizes = {};
|
2565
|
+
for (let i = 0; i < headers.length; i++) {
|
2566
|
+
const header = headers[i];
|
2567
|
+
const colSize = header.getSize();
|
2568
|
+
colSizes[`--header-${parseCSSVarId(header.id)}-size`] = colSize;
|
2569
|
+
colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
|
2570
|
+
}
|
2571
|
+
return colSizes;
|
2572
|
+
}, [columns, columnSizing, columnSizingInfo, columnVisibility]);
|
2573
|
+
//get first 16 column widths and average them
|
2574
|
+
const averageColumnWidth = useMemo(() => {
|
2575
|
+
var _a, _b, _c, _d;
|
2576
|
+
if (!enableColumnVirtualization)
|
2577
|
+
return 0;
|
2578
|
+
const columnsWidths = (_d = (_c = (_b = (_a = table
|
2579
|
+
.getRowModel()
|
2580
|
+
.rows[0]) === null || _a === void 0 ? void 0 : _a.getCenterVisibleCells()) === null || _b === void 0 ? void 0 : _b.slice(0, 16)) === null || _c === void 0 ? void 0 : _c.map((cell) => cell.column.getSize() * 1.2)) !== null && _d !== void 0 ? _d : [];
|
2581
|
+
return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
|
2582
|
+
}, [table.getRowModel().rows, columnPinning, columnVisibility]);
|
2583
|
+
const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(() => enableColumnVirtualization && enableColumnPinning
|
2584
|
+
? [
|
2585
|
+
table.getLeftLeafColumns().map((c) => c.getPinnedIndex()),
|
2586
|
+
table
|
2587
|
+
.getRightLeafColumns()
|
2588
|
+
.map((c) => table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1),
|
2589
|
+
]
|
2590
|
+
: [[], []], [columnPinning, enableColumnVirtualization, enableColumnPinning]);
|
2591
|
+
const columnVirtualizer = enableColumnVirtualization
|
2592
|
+
? useVirtualizer(Object.assign({ count: table.getVisibleLeafColumns().length, estimateSize: () => averageColumnWidth, getScrollElement: () => tableContainerRef.current, horizontal: true, overscan: 3, rangeExtractor: useCallback((range) => [
|
2593
|
+
...new Set([
|
2594
|
+
...leftPinnedIndexes,
|
2595
|
+
...defaultRangeExtractor(range),
|
2596
|
+
...rightPinnedIndexes,
|
2597
|
+
]),
|
2598
|
+
], [leftPinnedIndexes, rightPinnedIndexes]) }, columnVirtualizerProps))
|
2599
|
+
: undefined;
|
2600
|
+
if (columnVirtualizerInstanceRef && columnVirtualizer) {
|
2601
|
+
columnVirtualizerInstanceRef.current = columnVirtualizer;
|
2602
|
+
}
|
2603
|
+
const virtualColumns = columnVirtualizer
|
2604
|
+
? columnVirtualizer.getVirtualItems()
|
2605
|
+
: undefined;
|
2606
|
+
let virtualPaddingLeft;
|
2607
|
+
let virtualPaddingRight;
|
2608
|
+
if (columnVirtualizer && (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)) {
|
2609
|
+
virtualPaddingLeft = (_b = (_a = virtualColumns[leftPinnedIndexes.length]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0;
|
2610
|
+
virtualPaddingRight =
|
2611
|
+
columnVirtualizer.getTotalSize() -
|
2612
|
+
((_d = (_c = virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes.length]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0);
|
2613
|
+
}
|
2614
|
+
const props = {
|
2615
|
+
table,
|
2616
|
+
virtualColumns,
|
2617
|
+
virtualPaddingLeft,
|
2618
|
+
virtualPaddingRight,
|
2619
|
+
};
|
2620
|
+
return (jsx(Fragment, { children: jsxs(Table, Object.assign({ stickyHeader: enableStickyHeader || isFullScreen }, tableProps, { style: Object.assign(Object.assign({}, columnSizeVars), tableProps === null || tableProps === void 0 ? void 0 : tableProps.style), sx: (theme) => (Object.assign({ borderCollapse: 'separate', display: (layoutMode === null || layoutMode === void 0 ? void 0 : layoutMode.startsWith('grid')) ? 'grid' : undefined, tableLayout: layoutMode === 'semantic' && enableColumnResizing
|
2621
|
+
? 'fixed'
|
2622
|
+
: undefined }, parseFromValuesOrFunc(tableProps === null || tableProps === void 0 ? void 0 : tableProps.sx, theme))), children: [enableTableHead && jsx(MRT_TableHead, Object.assign({}, props)), memoMode === 'table-body' || columnSizingInfo.isResizingColumn ? (jsx(Memo_MRT_TableBody, Object.assign({ columnVirtualizer: columnVirtualizer }, props))) : (jsx(MRT_TableBody, Object.assign({ columnVirtualizer: columnVirtualizer }, props))), enableTableFooter && jsx(MRT_TableFooter, Object.assign({}, props))] })) }));
|
2623
|
+
};
|
2624
|
+
|
2625
|
+
const MRT_EditActionButtons = ({ row, table, variant = 'icon', }) => {
|
2626
|
+
const { getState, options: { icons: { CancelIcon, SaveIcon }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowCancel, onEditingRowSave, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table;
|
2627
|
+
const { creatingRow, editingRow, isSaving } = getState();
|
2628
|
+
const isCreating = (creatingRow === null || creatingRow === void 0 ? void 0 : creatingRow.id) === row.id;
|
2629
|
+
const isEditing = (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) === row.id;
|
2630
|
+
const handleCancel = () => {
|
2631
|
+
if (isCreating) {
|
2632
|
+
onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
|
2633
|
+
setCreatingRow(null);
|
2634
|
+
}
|
2635
|
+
else if (isEditing) {
|
2636
|
+
onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
|
2637
|
+
setEditingRow(null);
|
2638
|
+
}
|
2639
|
+
row._valuesCache = {}; //reset values cache
|
2640
|
+
};
|
2641
|
+
const handleSubmitRow = () => {
|
2642
|
+
var _a;
|
2643
|
+
//look for auto-filled input values
|
2644
|
+
(_a = Object.values(editInputRefs === null || editInputRefs === void 0 ? void 0 : editInputRefs.current)
|
2645
|
+
.filter((inputRef) => { var _a, _b; return row.id === ((_b = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.name) === null || _a === void 0 ? void 0 : _a.split('_')) === null || _b === void 0 ? void 0 : _b[0]); })) === null || _a === void 0 ? void 0 : _a.forEach((input) => {
|
2646
|
+
if (input.value !== undefined &&
|
2647
|
+
Object.hasOwn(row === null || row === void 0 ? void 0 : row._valuesCache, input.name)) {
|
2648
|
+
// @ts-ignore
|
2649
|
+
row._valuesCache[input.name] = input.value;
|
2650
|
+
}
|
2651
|
+
});
|
2652
|
+
if (isCreating)
|
2653
|
+
onCreatingRowSave === null || onCreatingRowSave === void 0 ? void 0 : onCreatingRowSave({
|
2654
|
+
exitCreatingMode: () => setCreatingRow(null),
|
2655
|
+
row,
|
2656
|
+
table,
|
2657
|
+
values: row._valuesCache,
|
2658
|
+
});
|
2659
|
+
else if (isEditing) {
|
2660
|
+
onEditingRowSave === null || onEditingRowSave === void 0 ? void 0 : onEditingRowSave({
|
2661
|
+
exitEditingMode: () => setEditingRow(null),
|
2662
|
+
row,
|
2663
|
+
table,
|
2664
|
+
values: row === null || row === void 0 ? void 0 : row._valuesCache,
|
2665
|
+
});
|
2666
|
+
}
|
2667
|
+
};
|
2668
|
+
return (jsx(Box, { onClick: (e) => e.stopPropagation(), sx: { display: 'flex', gap: '0.75rem' }, children: variant === 'icon' ? (jsxs(Fragment, { children: [jsx(Tooltip, { arrow: true, title: localization.cancel, children: jsx(IconButton, { "aria-label": localization.cancel, onClick: handleCancel, children: jsx(CancelIcon, {}) }) }), jsx(Tooltip, { arrow: true, title: localization.save, children: jsx(IconButton, { "aria-label": localization.save, color: "info", onClick: handleSubmitRow, children: isSaving ? jsx(CircularProgress, { size: 18 }) : jsx(SaveIcon, {}) }) })] })) : (jsxs(Fragment, { children: [jsx(Button, { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxs(Button, { onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsx(CircularProgress, { color: "inherit", size: 18 }), localization.save] })] })) }));
|
2669
|
+
};
|
2670
|
+
|
2671
|
+
const MRT_EditRowModal = ({ open, table, }) => {
|
2672
|
+
var _a;
|
2673
|
+
const { getState, options: { localization, muiCreateRowModalProps, muiEditRowModalProps, onCreatingRowCancel, onEditingRowCancel, renderCreateRowModalContent, renderEditRowModalContent, }, setCreatingRow, setEditingRow, } = table;
|
2674
|
+
const { creatingRow, editingRow } = getState();
|
2675
|
+
const row = (creatingRow !== null && creatingRow !== void 0 ? creatingRow : editingRow);
|
2676
|
+
const dialogProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiEditRowModalProps, { row, table })), (creatingRow &&
|
2677
|
+
parseFromValuesOrFunc(muiCreateRowModalProps, { row, table })));
|
2678
|
+
const internalEditComponents = row
|
2679
|
+
.getAllCells()
|
2680
|
+
.filter((cell) => cell.column.columnDef.columnDefType === 'data')
|
2681
|
+
.map((cell) => (jsx(MRT_EditCellTextField, { cell: cell, table: table }, cell.id)));
|
2682
|
+
return (jsx(Dialog, Object.assign({ fullWidth: true, maxWidth: "xs", onClose: (event, reason) => {
|
2683
|
+
var _a;
|
2684
|
+
if (creatingRow) {
|
2685
|
+
onCreatingRowCancel === null || onCreatingRowCancel === void 0 ? void 0 : onCreatingRowCancel({ row, table });
|
2686
|
+
setCreatingRow(null);
|
2687
|
+
}
|
2688
|
+
else {
|
2689
|
+
onEditingRowCancel === null || onEditingRowCancel === void 0 ? void 0 : onEditingRowCancel({ row, table });
|
2690
|
+
setEditingRow(null);
|
2691
|
+
}
|
2692
|
+
row._valuesCache = {}; //reset values cache
|
2693
|
+
(_a = dialogProps.onClose) === null || _a === void 0 ? void 0 : _a.call(dialogProps, event, reason);
|
2694
|
+
}, open: open }, dialogProps, { children: (_a = ((creatingRow &&
|
2695
|
+
(renderCreateRowModalContent === null || renderCreateRowModalContent === void 0 ? void 0 : renderCreateRowModalContent({
|
2696
|
+
internalEditComponents,
|
2697
|
+
row,
|
2698
|
+
table,
|
2699
|
+
}))) ||
|
2700
|
+
(renderEditRowModalContent === null || renderEditRowModalContent === void 0 ? void 0 : renderEditRowModalContent({
|
2701
|
+
internalEditComponents,
|
2702
|
+
row,
|
2703
|
+
table,
|
2704
|
+
})))) !== null && _a !== void 0 ? _a : (jsxs(Fragment, { children: [jsx(DialogTitle, { sx: { textAlign: 'center' }, children: localization.edit }), jsx(DialogContent, { children: jsx("form", { onSubmit: (e) => e.preventDefault(), children: jsx(Stack, { sx: {
|
2705
|
+
gap: '24px',
|
2706
|
+
paddingTop: '16px',
|
2707
|
+
width: '100%',
|
2708
|
+
}, children: internalEditComponents }) }) }), jsx(DialogActions, { sx: { p: '1.25rem' }, children: jsx(MRT_EditActionButtons, { row: row, table: table, variant: "text" }) })] })) })));
|
2709
|
+
};
|
2710
|
+
|
2711
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
2712
|
+
const MRT_TableContainer = ({ table, }) => {
|
2713
|
+
const { getState, options: { createDisplayMode, editDisplayMode, enableStickyHeader, muiTableContainerProps, }, refs: { bottomToolbarRef, tableContainerRef, topToolbarRef }, } = table;
|
2714
|
+
const { creatingRow, editingRow, isFullScreen } = getState();
|
2715
|
+
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
2716
|
+
const tableContainerProps = parseFromValuesOrFunc(muiTableContainerProps, {
|
2717
|
+
table,
|
2718
|
+
});
|
2719
|
+
useIsomorphicLayoutEffect(() => {
|
2720
|
+
var _a, _b, _c, _d;
|
2721
|
+
const topToolbarHeight = typeof document !== 'undefined'
|
2722
|
+
? (_b = (_a = topToolbarRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) !== null && _b !== void 0 ? _b : 0
|
2723
|
+
: 0;
|
2724
|
+
const bottomToolbarHeight = typeof document !== 'undefined'
|
2725
|
+
? (_d = (_c = bottomToolbarRef === null || bottomToolbarRef === void 0 ? void 0 : bottomToolbarRef.current) === null || _c === void 0 ? void 0 : _c.offsetHeight) !== null && _d !== void 0 ? _d : 0
|
2726
|
+
: 0;
|
2727
|
+
setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
|
2728
|
+
});
|
2729
|
+
const createModalOpen = createDisplayMode === 'modal' && creatingRow;
|
2730
|
+
const editModalOpen = editDisplayMode === 'modal' && editingRow;
|
2731
|
+
return (jsxs(TableContainer, Object.assign({}, tableContainerProps, { ref: (node) => {
|
2732
|
+
if (node) {
|
2733
|
+
tableContainerRef.current = node;
|
2734
|
+
if (tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.ref) {
|
2735
|
+
//@ts-ignore
|
2736
|
+
tableContainerProps.ref.current = node;
|
2737
|
+
}
|
2738
|
+
}
|
2739
|
+
}, style: Object.assign({ maxHeight: isFullScreen
|
2740
|
+
? `calc(100vh - ${totalToolbarHeight}px)`
|
2741
|
+
: undefined }, tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.style), sx: (theme) => (Object.assign({ maxHeight: enableStickyHeader
|
2742
|
+
? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
|
2743
|
+
: undefined, maxWidth: '100%', overflow: 'auto' }, parseFromValuesOrFunc(tableContainerProps === null || tableContainerProps === void 0 ? void 0 : tableContainerProps.sx, theme))), children: [jsx(MRT_Table, { table: table }), (createModalOpen || editModalOpen) && (jsx(MRT_EditRowModal, { open: true, table: table }))] })));
|
2744
|
+
};
|
2745
|
+
|
2669
2746
|
const MRT_TablePaper = ({ table, }) => {
|
2670
2747
|
var _a, _b;
|
2671
2748
|
const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps, renderBottomToolbar, renderTopToolbar, }, refs: { tablePaperRef }, } = table;
|
@@ -2817,53 +2894,6 @@ const MRT_ToggleRowActionMenuButton = ({ cell, row, table, }) => {
|
|
2817
2894
|
parseFromValuesOrFunc(enableEditing, row) ? (jsx(Tooltip, { arrow: true, placement: "right", title: localization.edit, children: jsx(IconButton, { "aria-label": localization.edit, onClick: handleStartEditMode, sx: commonIconButtonStyles, children: jsx(EditIcon, {}) }) })) : renderRowActionMenuItems ? (jsxs(Fragment, { children: [jsx(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: localization.rowActions, children: jsx(IconButton, { "aria-label": localization.rowActions, onClick: handleOpenRowActionMenu, size: "small", sx: commonIconButtonStyles, children: jsx(MoreHorizIcon, {}) }) }), jsx(MRT_RowActionMenu, { anchorEl: anchorEl, handleEdit: handleStartEditMode, row: row, setAnchorEl: setAnchorEl, table: table })] })) : null }));
|
2818
2895
|
};
|
2819
2896
|
|
2820
|
-
const MRT_SelectCheckbox = ({ row, selectAll, table, }) => {
|
2821
|
-
var _a;
|
2822
|
-
const { getState, options: { enableMultiRowSelection, enableRowPinning, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, rowPinningDisplayMode, selectAllMode, }, } = table;
|
2823
|
-
const { density, isLoading } = getState();
|
2824
|
-
const checkboxProps = !row
|
2825
|
-
? parseFromValuesOrFunc(muiSelectAllCheckboxProps, { table })
|
2826
|
-
: parseFromValuesOrFunc(muiSelectCheckboxProps, { row, table });
|
2827
|
-
const allRowsSelected = selectAll
|
2828
|
-
? selectAllMode === 'page'
|
2829
|
-
? table.getIsAllPageRowsSelected()
|
2830
|
-
: table.getIsAllRowsSelected()
|
2831
|
-
: undefined;
|
2832
|
-
const commonProps = Object.assign(Object.assign({ checked: selectAll ? allRowsSelected : row === null || row === void 0 ? void 0 : row.getIsSelected(), disabled: isLoading || (row && !row.getCanSelect()), inputProps: {
|
2833
|
-
'aria-label': selectAll
|
2834
|
-
? localization.toggleSelectAll
|
2835
|
-
: localization.toggleSelectRow,
|
2836
|
-
}, onChange: (event) => {
|
2837
|
-
event.stopPropagation();
|
2838
|
-
row
|
2839
|
-
? row.getToggleSelectedHandler()(event)
|
2840
|
-
: selectAllMode === 'all'
|
2841
|
-
? table.getToggleAllRowsSelectedHandler()(event)
|
2842
|
-
: table.getToggleAllPageRowsSelectedHandler()(event);
|
2843
|
-
if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
|
2844
|
-
if (row) {
|
2845
|
-
row.pin(!row.getIsPinned() && event.target.checked
|
2846
|
-
? (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('bottom'))
|
2847
|
-
? 'bottom'
|
2848
|
-
: 'top'
|
2849
|
-
: false);
|
2850
|
-
}
|
2851
|
-
else {
|
2852
|
-
table.setRowPinning({ bottom: [], top: [] });
|
2853
|
-
}
|
2854
|
-
}
|
2855
|
-
}, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
|
2856
|
-
var _a;
|
2857
|
-
e.stopPropagation();
|
2858
|
-
(_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.onClick) === null || _a === void 0 ? void 0 : _a.call(checkboxProps, e);
|
2859
|
-
}, sx: (theme) => (Object.assign({ height: density === 'compact' ? '1.75rem' : '2.5rem', m: density !== 'compact' ? '-0.4rem' : undefined, width: density === 'compact' ? '1.75rem' : '2.5rem', zIndex: 0 }, parseFromValuesOrFunc(checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.sx, theme))), title: undefined });
|
2860
|
-
return (jsx(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, title: (_a = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _a !== void 0 ? _a : (selectAll
|
2861
|
-
? localization.toggleSelectAll
|
2862
|
-
: localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsx(Radio, Object.assign({}, commonProps))) : (jsx(Checkbox, Object.assign({ indeterminate: selectAll
|
2863
|
-
? table.getIsSomeRowsSelected() && !allRowsSelected
|
2864
|
-
: row === null || row === void 0 ? void 0 : row.getIsSomeSelected() }, commonProps))) }));
|
2865
|
-
};
|
2866
|
-
|
2867
2897
|
const useMRT_DisplayColumns = ({ columnOrder, creatingRow, grouping, tableOptions, }) => {
|
2868
2898
|
var _a, _b;
|
2869
2899
|
return useMemo(() => {
|
@@ -2912,8 +2942,9 @@ const useMRT_DisplayColumns = ({ columnOrder, creatingRow, grouping, tableOption
|
|
2912
2942
|
};
|
2913
2943
|
|
2914
2944
|
const useMRT_Effects = (table) => {
|
2915
|
-
const { getState, options: { enablePagination, rowCount }, } = table;
|
2916
|
-
const { globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting, } = getState();
|
2945
|
+
const { getIsSomeRowsPinned, getState, options: { enablePagination, enableRowPinning, rowCount }, } = table;
|
2946
|
+
const { density, globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting, } = getState();
|
2947
|
+
const rerender = useReducer(() => ({}), {})[1];
|
2917
2948
|
const isMounted = useRef(false);
|
2918
2949
|
const initialBodyHeight = useRef();
|
2919
2950
|
const previousTop = useRef();
|
@@ -2969,6 +3000,13 @@ const useMRT_Effects = (table) => {
|
|
2969
3000
|
table.setSorting(() => appliedSort.current || []);
|
2970
3001
|
}
|
2971
3002
|
}, [globalFilter]);
|
3003
|
+
useEffect(() => {
|
3004
|
+
if (enableRowPinning && getIsSomeRowsPinned()) {
|
3005
|
+
setTimeout(() => {
|
3006
|
+
rerender();
|
3007
|
+
}, 150);
|
3008
|
+
}
|
3009
|
+
}, [density]);
|
2972
3010
|
};
|
2973
3011
|
|
2974
3012
|
const useMRT_TableInstance = (tableOptions) => {
|
@@ -3237,6 +3275,8 @@ const MRT_Default_Icons = {
|
|
3237
3275
|
ArrowDownwardIcon,
|
3238
3276
|
ArrowRightIcon,
|
3239
3277
|
CancelIcon,
|
3278
|
+
ChevronLeftIcon,
|
3279
|
+
ChevronRightIcon,
|
3240
3280
|
ClearAllIcon,
|
3241
3281
|
CloseIcon,
|
3242
3282
|
DensityLargeIcon,
|
@@ -3249,9 +3289,11 @@ const MRT_Default_Icons = {
|
|
3249
3289
|
FilterAltIcon,
|
3250
3290
|
FilterListIcon,
|
3251
3291
|
FilterListOffIcon,
|
3292
|
+
FirstPageIcon,
|
3252
3293
|
FullscreenExitIcon,
|
3253
3294
|
FullscreenIcon,
|
3254
3295
|
KeyboardDoubleArrowDownIcon,
|
3296
|
+
LastPageIcon,
|
3255
3297
|
MoreHorizIcon,
|
3256
3298
|
MoreVertIcon,
|
3257
3299
|
PushPinIcon,
|
@@ -3366,8 +3408,13 @@ const useMRT_TableOptions = (_a) => {
|
|
3366
3408
|
const _sortingFns = useMemo(() => (Object.assign(Object.assign({}, MRT_SortingFns), sortingFns)), []);
|
3367
3409
|
const _defaultColumn = useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultColumn), defaultColumn)), [defaultColumn]);
|
3368
3410
|
const _defaultDisplayColumn = useMemo(() => (Object.assign(Object.assign({}, MRT_DefaultDisplayColumn), defaultDisplayColumn)), [defaultDisplayColumn]);
|
3369
|
-
if (
|
3370
|
-
|
3411
|
+
if (layoutMode === 'semantic') {
|
3412
|
+
if (rest.enableRowVirtualization || rest.enableColumnVirtualization) {
|
3413
|
+
layoutMode = 'grid';
|
3414
|
+
}
|
3415
|
+
if (enableColumnResizing) {
|
3416
|
+
layoutMode = 'grid-no-grow';
|
3417
|
+
}
|
3371
3418
|
}
|
3372
3419
|
if (rest.enableRowVirtualization) {
|
3373
3420
|
enableStickyHeader = true;
|