material-react-table 2.11.0 → 2.11.2
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.d.ts +8 -6
- package/dist/index.esm.js +73 -47
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +73 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/body/MRT_TableBody.tsx +1 -1
- package/src/components/inputs/MRT_SelectCheckbox.tsx +13 -22
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +4 -6
- package/src/hooks/useMRT_Rows.ts +1 -2
- package/src/utils/row.utils.ts +76 -25
package/dist/index.js
CHANGED
|
@@ -422,8 +422,8 @@ const MRT_SortingFns = Object.assign(Object.assign({}, reactTable.sortingFns), {
|
|
|
422
422
|
const rankGlobalFuzzy = (rowA, rowB) => Math.max(...Object.values(rowB.columnFiltersMeta).map((v) => v.rank)) -
|
|
423
423
|
Math.max(...Object.values(rowA.columnFiltersMeta).map((v) => v.rank));
|
|
424
424
|
|
|
425
|
-
const getMRT_Rows = (table,
|
|
426
|
-
const {
|
|
425
|
+
const getMRT_Rows = (table, all) => {
|
|
426
|
+
const { getCenterRows, getPrePaginationRowModel, getRowModel, getState, getTopRows, options: { createDisplayMode, enablePagination, enableRowPinning, manualPagination, positionCreatingRow, rowPinningDisplayMode, }, } = table;
|
|
427
427
|
const { creatingRow, pagination } = getState();
|
|
428
428
|
const isRankingRows = getIsRankingRows(table);
|
|
429
429
|
let rows = [];
|
|
@@ -436,19 +436,28 @@ const getMRT_Rows = (table, pinnedRowIds = [], all) => {
|
|
|
436
436
|
: getCenterRows();
|
|
437
437
|
}
|
|
438
438
|
else {
|
|
439
|
+
// fuzzy ranking adjustments
|
|
439
440
|
rows = getPrePaginationRowModel().rows.sort((a, b) => rankGlobalFuzzy(a, b));
|
|
440
441
|
if (enablePagination && !manualPagination && !all) {
|
|
441
442
|
const start = pagination.pageIndex * pagination.pageSize;
|
|
442
443
|
rows = rows.slice(start, start + pagination.pageSize);
|
|
443
444
|
}
|
|
445
|
+
if (enableRowPinning && !(rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky'))) {
|
|
446
|
+
// "re-center-ize" the rows (no top or bottom pinned rows unless sticky)
|
|
447
|
+
rows = rows.filter((row) => !row.getIsPinned());
|
|
448
|
+
}
|
|
444
449
|
}
|
|
450
|
+
// row pinning adjustments
|
|
445
451
|
if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('sticky'))) {
|
|
452
|
+
const centerPinnedRowIds = rows
|
|
453
|
+
.filter((row) => row.getIsPinned())
|
|
454
|
+
.map((r) => r.id);
|
|
446
455
|
rows = [
|
|
447
|
-
...getTopRows().filter((row) => !
|
|
456
|
+
...getTopRows().filter((row) => !centerPinnedRowIds.includes(row.id)),
|
|
448
457
|
...rows,
|
|
449
|
-
...getBottomRows().filter((row) => !pinnedRowIds.includes(row.id)),
|
|
450
458
|
];
|
|
451
459
|
}
|
|
460
|
+
// blank inserted creating row adjustments
|
|
452
461
|
if (positionCreatingRow !== undefined &&
|
|
453
462
|
creatingRow &&
|
|
454
463
|
createDisplayMode === 'row') {
|
|
@@ -490,42 +499,67 @@ const getIsRowSelected = ({ row, table, }) => {
|
|
|
490
499
|
row.getCanSelectSubRows() &&
|
|
491
500
|
row.getIsAllSubRowsSelected()));
|
|
492
501
|
};
|
|
493
|
-
const getMRT_RowSelectionHandler = (
|
|
502
|
+
const getMRT_RowSelectionHandler = ({ row, staticRowIndex = 0, table, }) => (event, value) => {
|
|
494
503
|
var _a;
|
|
495
|
-
const { getState, options: { enableBatchRowSelection, enableRowPinning, rowPinningDisplayMode, }, refs: { lastSelectedRowId: lastSelectedRowId }, } = table;
|
|
504
|
+
const { getState, options: { enableBatchRowSelection, enableMultiRowSelection, enableRowPinning, manualPagination, rowPinningDisplayMode, }, refs: { lastSelectedRowId: lastSelectedRowId }, } = table;
|
|
496
505
|
const { pagination: { pageIndex, pageSize }, } = getState();
|
|
497
|
-
const
|
|
498
|
-
const
|
|
499
|
-
// toggle
|
|
500
|
-
row.
|
|
506
|
+
const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
|
|
507
|
+
const wasCurrentRowChecked = getIsRowSelected({ row, table });
|
|
508
|
+
// toggle selection of this row
|
|
509
|
+
row.toggleSelected(value !== null && value !== void 0 ? value : !wasCurrentRowChecked);
|
|
510
|
+
const changedRowIds = new Set([row.id]);
|
|
501
511
|
// if shift key is pressed, select all rows between last selected and this one
|
|
502
512
|
if (enableBatchRowSelection &&
|
|
513
|
+
enableMultiRowSelection &&
|
|
503
514
|
event.nativeEvent.shiftKey &&
|
|
504
515
|
lastSelectedRowId.current !== null) {
|
|
505
|
-
const rows = getMRT_Rows(table,
|
|
516
|
+
const rows = getMRT_Rows(table, true);
|
|
506
517
|
const lastIndex = rows.findIndex((r) => r.id === lastSelectedRowId.current);
|
|
507
518
|
if (lastIndex !== -1) {
|
|
508
|
-
const
|
|
519
|
+
const isLastIndexChecked = getIsRowSelected({
|
|
520
|
+
row: rows === null || rows === void 0 ? void 0 : rows[lastIndex],
|
|
521
|
+
table,
|
|
522
|
+
});
|
|
523
|
+
const currentIndex = staticRowIndex + paginationOffset;
|
|
509
524
|
const [start, end] = lastIndex < currentIndex
|
|
510
525
|
? [lastIndex, currentIndex]
|
|
511
526
|
: [currentIndex, lastIndex];
|
|
512
|
-
|
|
513
|
-
|
|
527
|
+
// toggle selection of all rows between last selected and this one
|
|
528
|
+
// but only if the last selected row is not the same as the current one
|
|
529
|
+
if (wasCurrentRowChecked !== isLastIndexChecked) {
|
|
530
|
+
for (let i = start; i <= end; i++) {
|
|
531
|
+
rows[i].toggleSelected(!wasCurrentRowChecked);
|
|
532
|
+
changedRowIds.add(rows[i].id);
|
|
533
|
+
}
|
|
514
534
|
}
|
|
515
535
|
}
|
|
516
536
|
}
|
|
537
|
+
// record the last selected row id
|
|
517
538
|
lastSelectedRowId.current = row.id;
|
|
518
539
|
// if all sub rows were selected, unselect them
|
|
519
540
|
if (row.getCanSelectSubRows() && row.getIsAllSubRowsSelected()) {
|
|
520
541
|
(_a = row.subRows) === null || _a === void 0 ? void 0 : _a.forEach((r) => r.toggleSelected(false));
|
|
521
542
|
}
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
: '
|
|
527
|
-
|
|
543
|
+
if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
|
|
544
|
+
changedRowIds.forEach((rowId) => {
|
|
545
|
+
const rowToTogglePin = table.getRow(rowId);
|
|
546
|
+
rowToTogglePin.pin(!wasCurrentRowChecked //was not previously pinned or selected
|
|
547
|
+
? (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('bottom'))
|
|
548
|
+
? 'bottom'
|
|
549
|
+
: 'top'
|
|
550
|
+
: false);
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
const getMRT_SelectAllHandler = ({ table }) => (event, value) => {
|
|
555
|
+
const { options: { enableRowPinning, rowPinningDisplayMode, selectAllMode }, refs: { lastSelectedRowId }, } = table;
|
|
556
|
+
selectAllMode === 'all'
|
|
557
|
+
? table.toggleAllRowsSelected(value !== null && value !== void 0 ? value : event.target.checked)
|
|
558
|
+
: table.toggleAllPageRowsSelected(value !== null && value !== void 0 ? value : event.target.checked);
|
|
559
|
+
if (enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'))) {
|
|
560
|
+
table.setRowPinning({ bottom: [], top: [] });
|
|
528
561
|
}
|
|
562
|
+
lastSelectedRowId.current = null;
|
|
529
563
|
};
|
|
530
564
|
|
|
531
565
|
const MRT_AggregationFns = Object.assign({}, reactTable.aggregationFns);
|
|
@@ -1071,10 +1105,9 @@ const getMRT_RowPinningColumnDef = (tableOptions) => {
|
|
|
1071
1105
|
const MRT_SelectCheckbox = (_a) => {
|
|
1072
1106
|
var _b;
|
|
1073
1107
|
var { row, staticRowIndex, table } = _a, rest = __rest(_a, ["row", "staticRowIndex", "table"]);
|
|
1074
|
-
const { getState, options: { enableMultiRowSelection,
|
|
1108
|
+
const { getState, options: { enableMultiRowSelection, localization, muiSelectAllCheckboxProps, muiSelectCheckboxProps, selectAllMode, }, } = table;
|
|
1075
1109
|
const { density, isLoading } = getState();
|
|
1076
1110
|
const selectAll = !row;
|
|
1077
|
-
const isStickySelection = enableRowPinning && (rowPinningDisplayMode === null || rowPinningDisplayMode === void 0 ? void 0 : rowPinningDisplayMode.includes('select'));
|
|
1078
1111
|
const allRowsSelected = selectAll
|
|
1079
1112
|
? selectAllMode === 'page'
|
|
1080
1113
|
? table.getIsAllPageRowsSelected()
|
|
@@ -1089,16 +1122,14 @@ const MRT_SelectCheckbox = (_a) => {
|
|
|
1089
1122
|
row,
|
|
1090
1123
|
table,
|
|
1091
1124
|
}))), rest);
|
|
1092
|
-
const onSelectionChange =
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
lastSelectedRowId.current = null;
|
|
1101
|
-
};
|
|
1125
|
+
const onSelectionChange = row
|
|
1126
|
+
? getMRT_RowSelectionHandler({
|
|
1127
|
+
row,
|
|
1128
|
+
staticRowIndex,
|
|
1129
|
+
table,
|
|
1130
|
+
})
|
|
1131
|
+
: undefined;
|
|
1132
|
+
const onSelectAllChange = getMRT_SelectAllHandler({ table });
|
|
1102
1133
|
const commonProps = Object.assign(Object.assign({ 'aria-label': selectAll
|
|
1103
1134
|
? localization.toggleSelectAll
|
|
1104
1135
|
: localization.toggleSelectRow, checked: isChecked, disabled: isLoading || (row && !row.getCanSelect()) || (row === null || row === void 0 ? void 0 : row.id) === 'mrt-row-create', inputProps: {
|
|
@@ -1107,9 +1138,7 @@ const MRT_SelectCheckbox = (_a) => {
|
|
|
1107
1138
|
: localization.toggleSelectRow,
|
|
1108
1139
|
}, onChange: (event) => {
|
|
1109
1140
|
event.stopPropagation();
|
|
1110
|
-
row
|
|
1111
|
-
? onSelectionChange({ event, row, staticRowIndex, table })
|
|
1112
|
-
: onSelectAllChange(event);
|
|
1141
|
+
row ? onSelectionChange(event) : onSelectAllChange(event);
|
|
1113
1142
|
}, size: (density === 'compact' ? 'small' : 'medium') }, checkboxProps), { onClick: (e) => {
|
|
1114
1143
|
var _a;
|
|
1115
1144
|
e.stopPropagation();
|
|
@@ -1117,8 +1146,8 @@ const MRT_SelectCheckbox = (_a) => {
|
|
|
1117
1146
|
}, 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 });
|
|
1118
1147
|
return (jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, getCommonTooltipProps(), { title: (_b = checkboxProps === null || checkboxProps === void 0 ? void 0 : checkboxProps.title) !== null && _b !== void 0 ? _b : (selectAll
|
|
1119
1148
|
? localization.toggleSelectAll
|
|
1120
|
-
: localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsxRuntime.jsx(Radio__default["default"], Object.assign({}, commonProps))) : (jsxRuntime.jsx(Checkbox__default["default"], Object.assign({ indeterminate: selectAll
|
|
1121
|
-
? table.getIsSomeRowsSelected()
|
|
1149
|
+
: localization.toggleSelectRow), children: enableMultiRowSelection === false ? (jsxRuntime.jsx(Radio__default["default"], Object.assign({}, commonProps))) : (jsxRuntime.jsx(Checkbox__default["default"], Object.assign({ indeterminate: !isChecked && selectAll
|
|
1150
|
+
? table.getIsSomeRowsSelected()
|
|
1122
1151
|
: (row === null || row === void 0 ? void 0 : row.getIsSomeSelected()) && row.getCanSelectSubRows() }, commonProps))) })));
|
|
1123
1152
|
};
|
|
1124
1153
|
|
|
@@ -1769,10 +1798,10 @@ const useMRT_RowVirtualizer = (table, rows) => {
|
|
|
1769
1798
|
return rowVirtualizer;
|
|
1770
1799
|
};
|
|
1771
1800
|
|
|
1772
|
-
const useMRT_Rows = (table
|
|
1801
|
+
const useMRT_Rows = (table) => {
|
|
1773
1802
|
const { getRowModel, getState, options: { data, enableGlobalFilterRankedResults, positionCreatingRow }, } = table;
|
|
1774
1803
|
const { creatingRow, expanded, globalFilter, pagination, rowPinning, sorting, } = getState();
|
|
1775
|
-
const rows = react.useMemo(() => getMRT_Rows(table
|
|
1804
|
+
const rows = react.useMemo(() => getMRT_Rows(table), [
|
|
1776
1805
|
creatingRow,
|
|
1777
1806
|
data,
|
|
1778
1807
|
enableGlobalFilterRankedResults,
|
|
@@ -2300,7 +2329,7 @@ const MRT_TableBody = (_a) => {
|
|
|
2300
2329
|
.rows.filter((row) => row.getIsPinned())
|
|
2301
2330
|
.map((r) => r.id);
|
|
2302
2331
|
}, [rowPinning, getRowModel().rows]);
|
|
2303
|
-
const rows = useMRT_Rows(table
|
|
2332
|
+
const rows = useMRT_Rows(table);
|
|
2304
2333
|
const rowVirtualizer = useMRT_RowVirtualizer(table, rows);
|
|
2305
2334
|
const { virtualRows } = rowVirtualizer !== null && rowVirtualizer !== void 0 ? rowVirtualizer : {};
|
|
2306
2335
|
const commonRowProps = {
|
|
@@ -3505,7 +3534,7 @@ const MRT_TableHeadRow = (_a) => {
|
|
|
3505
3534
|
const MRT_ToolbarAlertBanner = (_a) => {
|
|
3506
3535
|
var _b, _c, _d;
|
|
3507
3536
|
var { stackAlertBanner, table } = _a, rest = __rest(_a, ["stackAlertBanner", "table"]);
|
|
3508
|
-
const { getFilteredSelectedRowModel, getPrePaginationRowModel, getState, options: { enableRowSelection, enableSelectAll, localization, manualPagination, muiToolbarAlertBannerChipProps, muiToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, refs: {
|
|
3537
|
+
const { getFilteredSelectedRowModel, getPrePaginationRowModel, getState, options: { enableRowSelection, enableSelectAll, localization, manualPagination, muiToolbarAlertBannerChipProps, muiToolbarAlertBannerProps, positionToolbarAlertBanner, renderToolbarAlertBannerContent, rowCount, }, refs: { tablePaperRef }, } = table;
|
|
3509
3538
|
const { density, grouping, rowSelection, showAlertBanner } = getState();
|
|
3510
3539
|
const alertProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiToolbarAlertBannerProps, {
|
|
3511
3540
|
table,
|
|
@@ -3513,14 +3542,11 @@ const MRT_ToolbarAlertBanner = (_a) => {
|
|
|
3513
3542
|
const chipProps = parseFromValuesOrFunc(muiToolbarAlertBannerChipProps, {
|
|
3514
3543
|
table,
|
|
3515
3544
|
});
|
|
3516
|
-
const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().
|
|
3545
|
+
const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().flatRows.length;
|
|
3517
3546
|
const selectedRowCount = react.useMemo(() => manualPagination
|
|
3518
3547
|
? Object.values(rowSelection).filter(Boolean).length
|
|
3519
3548
|
: getFilteredSelectedRowModel().rows.length, [rowSelection, totalRowCount, manualPagination]);
|
|
3520
|
-
const selectedAlert = selectedRowCount > 0 ? (jsxRuntime.jsxs(Stack__default["default"], { alignItems: "center", direction: "row", gap: "16px", children: [(_c = (_b = localization.selectedCountOfRowCountRowsSelected) === null || _b === void 0 ? void 0 : _b.replace('{selectedCount}', selectedRowCount.toLocaleString())) === null || _c === void 0 ? void 0 : _c.replace('{rowCount}', totalRowCount.toString()), jsxRuntime.jsx(Button__default["default"], { onClick: () => {
|
|
3521
|
-
table.toggleAllRowsSelected(false);
|
|
3522
|
-
lastSelectedRowId.current = null;
|
|
3523
|
-
}, size: "small", sx: { p: '2px' }, children: localization.clearSelection })] })) : null;
|
|
3549
|
+
const selectedAlert = selectedRowCount > 0 ? (jsxRuntime.jsxs(Stack__default["default"], { alignItems: "center", direction: "row", gap: "16px", children: [(_c = (_b = localization.selectedCountOfRowCountRowsSelected) === null || _b === void 0 ? void 0 : _b.replace('{selectedCount}', selectedRowCount.toLocaleString())) === null || _c === void 0 ? void 0 : _c.replace('{rowCount}', totalRowCount.toString()), jsxRuntime.jsx(Button__default["default"], { onClick: (event) => getMRT_SelectAllHandler({ table })(event, false), size: "small", sx: { p: '2px' }, children: localization.clearSelection })] })) : null;
|
|
3524
3550
|
const groupedAlert = grouping.length > 0 ? (jsxRuntime.jsxs("span", { children: [localization.groupedBy, ' ', grouping.map((columnId, index) => (jsxRuntime.jsxs(react.Fragment, { children: [index > 0 ? localization.thenBy : '', jsxRuntime.jsx(Chip__default["default"], Object.assign({ label: table.getColumn(columnId).columnDef.header, onDelete: () => table.getColumn(columnId).toggleGrouping() }, chipProps))] }, `${index}-${columnId}`)))] })) : null;
|
|
3525
3551
|
return (jsxRuntime.jsx(Collapse__default["default"], { in: showAlertBanner || !!selectedAlert || !!groupedAlert, timeout: stackAlertBanner ? 200 : 0, children: jsxRuntime.jsx(Alert__default["default"], Object.assign({ color: "info", icon: false }, alertProps, { sx: (theme) => {
|
|
3526
3552
|
var _a, _b;
|
|
@@ -4287,6 +4313,7 @@ exports.getIsRowSelected = getIsRowSelected;
|
|
|
4287
4313
|
exports.getLeadingDisplayColumnIds = getLeadingDisplayColumnIds;
|
|
4288
4314
|
exports.getMRT_RowSelectionHandler = getMRT_RowSelectionHandler;
|
|
4289
4315
|
exports.getMRT_Rows = getMRT_Rows;
|
|
4316
|
+
exports.getMRT_SelectAllHandler = getMRT_SelectAllHandler;
|
|
4290
4317
|
exports.getTotalRight = getTotalRight;
|
|
4291
4318
|
exports.getTrailingDisplayColumnIds = getTrailingDisplayColumnIds;
|
|
4292
4319
|
exports.isCellEditable = isCellEditable;
|