material-react-table 1.6.2 → 1.6.4
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 +72 -45
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/column.utils.d.ts +2 -0
- package/dist/esm/material-react-table.esm.js +72 -45
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/column.utils.d.ts +2 -0
- package/package.json +1 -1
- package/src/body/MRT_TableBody.tsx +44 -22
- package/src/body/MRT_TableBodyCell.tsx +44 -21
- package/src/body/MRT_TableBodyRow.tsx +2 -20
- package/src/column.utils.ts +15 -0
package/dist/cjs/index.js
CHANGED
@@ -295,6 +295,13 @@ const getDefaultColumnFilterFn = (columnDef) => {
|
|
295
295
|
return 'equals';
|
296
296
|
return 'fuzzy';
|
297
297
|
};
|
298
|
+
const getIsFirstColumn = (column, table) => {
|
299
|
+
return table.getVisibleLeafColumns()[0].id === column.id;
|
300
|
+
};
|
301
|
+
const getIsLastColumn = (column, table) => {
|
302
|
+
const columns = table.getVisibleLeafColumns();
|
303
|
+
return columns[columns.length - 1].id === column.id;
|
304
|
+
};
|
298
305
|
const getIsLastLeftPinnedColumn = (table, column) => {
|
299
306
|
return (column.getIsPinned() === 'left' &&
|
300
307
|
table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
|
@@ -2281,7 +2288,7 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
|
|
2281
2288
|
var _a, _b;
|
2282
2289
|
const theme = styles.useTheme();
|
2283
2290
|
const { getState, options: { editingMode, enableClickToCopy, enableColumnOrdering, enableEditing, enableGrouping, enableRowNumbers, layoutMode, muiTableBodyCellProps, muiTableBodyCellSkeletonProps, rowNumberMode, }, refs: { editInputRefs }, setEditingCell, setHoveredColumn, } = table;
|
2284
|
-
const { draggingColumn, editingCell, editingRow, hoveredColumn, density, isLoading, showSkeletons, } = getState();
|
2291
|
+
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredColumn, hoveredRow, density, isLoading, showSkeletons, } = getState();
|
2285
2292
|
const { column, row } = cell;
|
2286
2293
|
const { columnDef } = column;
|
2287
2294
|
const { columnDefType } = columnDef;
|
@@ -2302,18 +2309,38 @@ const MRT_TableBodyCell = ({ cell, enableHover, measureElement, numRows, rowInde
|
|
2302
2309
|
: Math.round(Math.random() * (column.getSize() - column.getSize() / 3) +
|
2303
2310
|
column.getSize() / 3)
|
2304
2311
|
: 100), []);
|
2305
|
-
const
|
2306
|
-
?
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2312
|
+
const draggingBorders = React.useMemo(() => {
|
2313
|
+
const isDraggingColumn = (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id) === column.id;
|
2314
|
+
const isHoveredColumn = (hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === column.id;
|
2315
|
+
const isDraggingRow = (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id;
|
2316
|
+
const isHoveredRow = (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id;
|
2317
|
+
const isFirstColumn = getIsFirstColumn(column, table);
|
2318
|
+
const isLastColumn = getIsLastColumn(column, table);
|
2319
|
+
const isLastRow = rowIndex === numRows - 1;
|
2320
|
+
const borderStyle = isDraggingColumn || isDraggingRow
|
2321
|
+
? `1px dashed ${theme.palette.text.secondary} !important`
|
2322
|
+
: isHoveredColumn || isHoveredRow
|
2323
|
+
? `2px dashed ${theme.palette.primary.main} !important`
|
2324
|
+
: undefined;
|
2325
|
+
return borderStyle
|
2326
|
+
? {
|
2327
|
+
borderLeft: isDraggingColumn ||
|
2328
|
+
isHoveredColumn ||
|
2329
|
+
((isDraggingRow || isHoveredRow) && isFirstColumn)
|
2330
|
+
? borderStyle
|
2331
|
+
: undefined,
|
2332
|
+
borderRight: isDraggingColumn ||
|
2333
|
+
isHoveredColumn ||
|
2334
|
+
((isDraggingRow || isHoveredRow) && isLastColumn)
|
2335
|
+
? borderStyle
|
2336
|
+
: undefined,
|
2337
|
+
borderBottom: isDraggingRow || isHoveredRow || isLastRow
|
2338
|
+
? borderStyle
|
2339
|
+
: undefined,
|
2340
|
+
borderTop: isDraggingRow || isHoveredRow ? borderStyle : undefined,
|
2341
|
+
}
|
2342
|
+
: undefined;
|
2343
|
+
}, [draggingColumn, draggingRow, hoveredColumn, hoveredRow, rowIndex]);
|
2317
2344
|
const isEditable = (enableEditing || columnDef.enableEditing) &&
|
2318
2345
|
columnDef.enableEditing !== false;
|
2319
2346
|
const isEditing = isEditable &&
|
@@ -2433,7 +2460,6 @@ const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
|
|
2433
2460
|
};
|
2434
2461
|
|
2435
2462
|
const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, rowIndex, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, virtualRow, }) => {
|
2436
|
-
const theme = styles.useTheme();
|
2437
2463
|
const { getIsSomeColumnsPinned, getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
|
2438
2464
|
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
|
2439
2465
|
const tableRowProps = muiTableBodyRowProps instanceof Function
|
@@ -2445,23 +2471,13 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2445
2471
|
}
|
2446
2472
|
};
|
2447
2473
|
const rowRef = React.useRef(null);
|
2448
|
-
const draggingBorder = React.useMemo(() => (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id
|
2449
|
-
? `1px dashed ${theme.palette.text.secondary}`
|
2450
|
-
: (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id
|
2451
|
-
? `2px dashed ${theme.palette.primary.main}`
|
2452
|
-
: undefined, [draggingRow, hoveredRow]);
|
2453
|
-
const draggingBorders = draggingBorder
|
2454
|
-
? {
|
2455
|
-
border: draggingBorder,
|
2456
|
-
}
|
2457
|
-
: undefined;
|
2458
2474
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
2459
2475
|
React__default["default"].createElement(TableRow__default["default"], Object.assign({ "data-index": virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.index, hover: true, onDragEnter: handleDragEnter, selected: row.getIsSelected(), ref: (node) => {
|
2460
2476
|
if (node) {
|
2461
2477
|
rowRef.current = node;
|
2462
2478
|
measureElement === null || measureElement === void 0 ? void 0 : measureElement(node);
|
2463
2479
|
}
|
2464
|
-
} }, tableRowProps, { sx: (theme) => (Object.assign(
|
2480
|
+
} }, tableRowProps, { sx: (theme) => (Object.assign({ backgroundColor: styles.lighten(theme.palette.background.default, 0.06), display: layoutMode === 'grid' ? 'flex' : 'table-row', opacity: (draggingRow === null || draggingRow === void 0 ? void 0 : draggingRow.id) === row.id || (hoveredRow === null || hoveredRow === void 0 ? void 0 : hoveredRow.id) === row.id ? 0.5 : 1, position: virtualRow ? 'absolute' : undefined, top: virtualRow ? 0 : undefined, transform: virtualRow
|
2465
2481
|
? `translateY(${virtualRow === null || virtualRow === void 0 ? void 0 : virtualRow.start}px)`
|
2466
2482
|
: undefined, transition: virtualRow ? 'none' : 'all 150ms ease-in-out', width: '100%', '&:hover td': {
|
2467
2483
|
backgroundColor: (tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned()
|
@@ -2471,7 +2487,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
|
|
2471
2487
|
: undefined,
|
2472
2488
|
} }, ((tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx) instanceof Function
|
2473
2489
|
? tableRowProps.sx(theme)
|
2474
|
-
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))
|
2490
|
+
: tableRowProps === null || tableRowProps === void 0 ? void 0 : tableRowProps.sx))) }),
|
2475
2491
|
virtualPaddingLeft ? (React__default["default"].createElement("td", { style: { display: 'flex', width: virtualPaddingLeft } })) : null,
|
2476
2492
|
(virtualColumns !== null && virtualColumns !== void 0 ? virtualColumns : row.getVisibleCells()).map((cellOrVirtualCell) => {
|
2477
2493
|
const cell = columnVirtualizer
|
@@ -2504,8 +2520,8 @@ const Memo_MRT_TableBodyRow = React.memo(MRT_TableBodyRow, (prev, next) => prev.
|
|
2504
2520
|
|
2505
2521
|
const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
|
2506
2522
|
var _a, _b, _c;
|
2507
|
-
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualFiltering, manualPagination, manualSorting, memoMode, muiTableBodyProps, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2508
|
-
const { columnFilters, density, globalFilter, pagination, sorting } = getState();
|
2523
|
+
const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
|
2524
|
+
const { columnFilters, density, expanded, globalFilter, globalFilterFn, pagination, sorting, } = getState();
|
2509
2525
|
const tableBodyProps = muiTableBodyProps instanceof Function
|
2510
2526
|
? muiTableBodyProps({ table })
|
2511
2527
|
: muiTableBodyProps;
|
@@ -2515,26 +2531,37 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
|
|
2515
2531
|
const vProps = rowVirtualizerProps instanceof Function
|
2516
2532
|
? rowVirtualizerProps({ table })
|
2517
2533
|
: rowVirtualizerProps;
|
2534
|
+
const shouldRankResults = React.useMemo(() => !manualExpanding &&
|
2535
|
+
!manualFiltering &&
|
2536
|
+
!manualGrouping &&
|
2537
|
+
!manualSorting &&
|
2538
|
+
enableGlobalFilterRankedResults &&
|
2539
|
+
globalFilter &&
|
2540
|
+
globalFilterFn === 'fuzzy' &&
|
2541
|
+
expanded !== true &&
|
2542
|
+
!Object.values(sorting).some(Boolean) &&
|
2543
|
+
!Object.values(expanded).some(Boolean), [
|
2544
|
+
enableGlobalFilterRankedResults,
|
2545
|
+
expanded,
|
2546
|
+
globalFilter,
|
2547
|
+
manualExpanding,
|
2548
|
+
manualFiltering,
|
2549
|
+
manualGrouping,
|
2550
|
+
manualSorting,
|
2551
|
+
sorting,
|
2552
|
+
]);
|
2518
2553
|
const rows = React.useMemo(() => {
|
2519
|
-
if (
|
2520
|
-
|
2521
|
-
|
2522
|
-
|
2523
|
-
|
2524
|
-
|
2525
|
-
if (enablePagination && !manualPagination) {
|
2526
|
-
const start = pagination.pageIndex * pagination.pageSize;
|
2527
|
-
return rankedRows.slice(start, start + pagination.pageSize);
|
2528
|
-
}
|
2529
|
-
return rankedRows;
|
2554
|
+
if (!shouldRankResults)
|
2555
|
+
return getRowModel().rows;
|
2556
|
+
const rankedRows = getPrePaginationRowModel().rows.sort((a, b) => rankGlobalFuzzy(a, b));
|
2557
|
+
if (enablePagination && !manualPagination) {
|
2558
|
+
const start = pagination.pageIndex * pagination.pageSize;
|
2559
|
+
return rankedRows.slice(start, start + pagination.pageSize);
|
2530
2560
|
}
|
2531
|
-
return
|
2561
|
+
return rankedRows;
|
2532
2562
|
}, [
|
2533
|
-
|
2534
|
-
|
2535
|
-
? getPrePaginationRowModel().rows
|
2536
|
-
: getRowModel().rows,
|
2537
|
-
globalFilter,
|
2563
|
+
shouldRankResults,
|
2564
|
+
shouldRankResults ? getPrePaginationRowModel().rows : getRowModel().rows,
|
2538
2565
|
pagination.pageIndex,
|
2539
2566
|
pagination.pageSize,
|
2540
2567
|
]);
|