material-react-table 1.9.4 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -278,13 +278,17 @@ const getTrailingDisplayColumnIds = (props) => {
278
278
  props.positionExpandColumn === 'last' &&
279
279
  showExpandColumn(props) &&
280
280
  'mrt-row-expand',
281
- ];
281
+ ].filter(Boolean);
282
+ };
283
+ const getDefaultColumnOrderIds = (props) => {
284
+ const leadingDisplayCols = getLeadingDisplayColumnIds(props);
285
+ const trailingDisplayCols = getTrailingDisplayColumnIds(props);
286
+ const allLeafColumnDefs = getAllLeafColumnDefs(props.columns)
287
+ .map((columnDef) => getColumnId(columnDef))
288
+ .filter((columnId) => !leadingDisplayCols.includes(columnId) &&
289
+ !trailingDisplayCols.includes(columnId));
290
+ return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
282
291
  };
283
- const getDefaultColumnOrderIds = (props) => [
284
- ...getLeadingDisplayColumnIds(props),
285
- ...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
286
- ...getTrailingDisplayColumnIds(props),
287
- ].filter(Boolean);
288
292
  const getDefaultColumnFilterFn = (columnDef) => {
289
293
  if (columnDef.filterVariant === 'multi-select')
290
294
  return 'arrIncludesSome';
@@ -314,28 +318,33 @@ const getTotalRight = (table, column) => {
314
318
  };
315
319
  const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
316
320
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
317
- return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
321
+ const widthStyles = {
322
+ 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
+ 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
+ };
325
+ return Object.assign(Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
318
326
  ? styles.alpha(styles.lighten(theme.palette.background.default, 0.04), 0.97)
319
327
  : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
320
328
  ? `-4px 0 8px -6px ${styles.alpha(theme.palette.common.black, 0.2)} inset`
321
329
  : getIsFirstRightPinnedColumn(column)
322
330
  ? `4px 0 8px -6px ${styles.alpha(theme.palette.common.black, 0.2)} inset`
323
331
  : undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', flex: table.options.layoutMode === 'grid'
324
- ? `var(--${header ? 'header' : 'col'}-${parseCSSVarId((_a = header === null || header === void 0 ? void 0 : header.id) !== null && _a !== void 0 ? _a : column.id)}-size) 0 auto`
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`
325
333
  : undefined, left: column.getIsPinned() === 'left'
326
334
  ? `${column.getStart('left')}px`
327
335
  : undefined, ml: table.options.enableColumnVirtualization &&
328
336
  column.getIsPinned() === 'left' &&
329
337
  column.getPinnedIndex() === 0
330
- ? `-${column.getSize() * ((_c = (_b = table.getState().columnPinning.left) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 1)}px`
338
+ ? `-${column.getSize() *
339
+ ((_f = (_e = table.getState().columnPinning.left) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 1)}px`
331
340
  : undefined, mr: table.options.enableColumnVirtualization &&
332
341
  column.getIsPinned() === 'right' &&
333
342
  column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
334
343
  ? `-${column.getSize() *
335
- ((_e = (_d = table.getState().columnPinning.right) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 1) *
344
+ ((_h = (_g = table.getState().columnPinning.right) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 1) *
336
345
  1.2}px`
337
- : undefined, opacity: ((_f = table.getState().draggingColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id ||
338
- ((_g = table.getState().hoveredColumn) === null || _g === void 0 ? void 0 : _g.id) === column.id
346
+ : undefined, opacity: ((_j = table.getState().draggingColumn) === null || _j === void 0 ? void 0 : _j.id) === column.id ||
347
+ ((_k = table.getState().hoveredColumn) === null || _k === void 0 ? void 0 : _k.id) === column.id
339
348
  ? 0.5
340
349
  : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
341
350
  ? 'sticky'
@@ -343,9 +352,9 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
343
352
  ? `${getTotalRight(table, column)}px`
344
353
  : undefined, transition: table.options.enableColumnVirtualization
345
354
  ? 'none'
346
- : `padding 150ms ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
355
+ : `padding 150ms ease-in-out` }, (!table.options.enableColumnResizing && widthStyles)), ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
347
356
  ? tableCellProps.sx(theme)
348
- : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_h = header === null || header === void 0 ? void 0 : header.id) !== null && _h !== void 0 ? _h : column.id)}-size) * 1px), ${(_j = column.columnDef.minSize) !== null && _j !== void 0 ? _j : 30}px)`, width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId((_k = header === null || header === void 0 ? void 0 : header.id) !== null && _k !== void 0 ? _k : column.id)}-size) * 1px)` }));
357
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), (table.options.enableColumnResizing && widthStyles));
349
358
  };
350
359
  const MRT_DefaultColumn = {
351
360
  filterVariant: 'text',
@@ -1448,6 +1457,7 @@ const MRT_ToolbarDropZone = ({ table, }) => {
1448
1457
  if (((_a = table.options.state) === null || _a === void 0 ? void 0 : _a.showToolbarDropZone) !== undefined) {
1449
1458
  setShowToolbarDropZone(!!enableGrouping &&
1450
1459
  !!draggingColumn &&
1460
+ draggingColumn.columnDef.enableGrouping !== false &&
1451
1461
  !grouping.includes(draggingColumn.id));
1452
1462
  }
1453
1463
  }, [enableGrouping, draggingColumn, grouping]);
@@ -2514,11 +2524,11 @@ const MRT_TableBodyCell = ({ cell, measureElement, numRows, rowIndex, rowRef, ta
2514
2524
  };
2515
2525
  const Memo_MRT_TableBodyCell = React.memo(MRT_TableBodyCell, (prev, next) => next.cell === prev.cell);
2516
2526
 
2517
- const MRT_TableDetailPanel = ({ parentRowRef, row, table, virtualRow, }) => {
2527
+ const MRT_TableDetailPanel = ({ parentRowRef, row, rowIndex, table, virtualRow, }) => {
2518
2528
  const { getVisibleLeafColumns, getState, options: { layoutMode, muiTableBodyRowProps, muiTableDetailPanelProps, renderDetailPanel, }, } = table;
2519
2529
  const { isLoading } = getState();
2520
2530
  const tableRowProps = muiTableBodyRowProps instanceof Function
2521
- ? muiTableBodyRowProps({ isDetailPanel: true, row, table })
2531
+ ? muiTableBodyRowProps({ isDetailPanel: true, row, staticRowIndex: rowIndex, table })
2522
2532
  : muiTableBodyRowProps;
2523
2533
  const tableCellProps = muiTableDetailPanelProps instanceof Function
2524
2534
  ? muiTableDetailPanelProps({ row, table })
@@ -2544,7 +2554,7 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
2544
2554
  const { getState, options: { enableRowOrdering, layoutMode, memoMode, muiTableBodyRowProps, renderDetailPanel, }, setHoveredRow, } = table;
2545
2555
  const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } = getState();
2546
2556
  const tableRowProps = muiTableBodyRowProps instanceof Function
2547
- ? muiTableBodyRowProps({ row, table })
2557
+ ? muiTableBodyRowProps({ row, staticRowIndex: rowIndex, table })
2548
2558
  : muiTableBodyRowProps;
2549
2559
  const handleDragEnter = (_e) => {
2550
2560
  if (enableRowOrdering && draggingRow) {
@@ -2596,13 +2606,13 @@ const MRT_TableBodyRow = ({ columnVirtualizer, measureElement, numRows, row, row
2596
2606
  (editingRow === null || editingRow === void 0 ? void 0 : editingRow.id) !== row.id ? (React__default["default"].createElement(Memo_MRT_TableBodyCell, Object.assign({}, props))) : (React__default["default"].createElement(MRT_TableBodyCell, Object.assign({}, props)));
2597
2607
  }),
2598
2608
  virtualPaddingRight ? (React__default["default"].createElement("td", { style: { display: 'flex', width: virtualPaddingRight } })) : null),
2599
- renderDetailPanel && !row.getIsGrouped() && (React__default["default"].createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, table: table, virtualRow: virtualRow }))));
2609
+ renderDetailPanel && !row.getIsGrouped() && (React__default["default"].createElement(MRT_TableDetailPanel, { parentRowRef: rowRef, row: row, rowIndex: rowIndex, table: table, virtualRow: virtualRow }))));
2600
2610
  };
2601
2611
  const Memo_MRT_TableBodyRow = React.memo(MRT_TableBodyRow, (prev, next) => prev.row === next.row && prev.rowIndex === next.rowIndex);
2602
2612
 
2603
2613
  const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddingLeft, virtualPaddingRight, }) => {
2604
- var _a, _b, _c;
2605
- 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;
2614
+ var _a, _b, _c, _d;
2615
+ const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, layoutMode, localization, manualExpanding, manualFiltering, manualGrouping, manualPagination, manualSorting, memoMode, muiTableBodyProps, renderEmptyRowsFallback, rowVirtualizerInstanceRef, rowVirtualizerProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
2606
2616
  const { columnFilters, density, expanded, globalFilter, globalFilterFn, pagination, sorting, } = getState();
2607
2617
  const tableBodyProps = muiTableBodyProps instanceof Function
2608
2618
  ? muiTableBodyProps({ table })
@@ -2665,17 +2675,18 @@ const MRT_TableBody = ({ columnVirtualizer, table, virtualColumns, virtualPaddin
2665
2675
  : 'inherit', minHeight: !rows.length ? '100px' : undefined, position: 'relative' }, ((tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx) instanceof Function
2666
2676
  ? tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx(theme)
2667
2677
  : tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.sx))) }), (_a = tableBodyProps === null || tableBodyProps === void 0 ? void 0 : tableBodyProps.children) !== null && _a !== void 0 ? _a : (!rows.length ? (React__default["default"].createElement("tr", { style: { display: layoutMode === 'grid' ? 'grid' : 'table-row' } },
2668
- React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: { display: layoutMode === 'grid' ? 'grid' : 'table-cell' } },
2669
- React__default["default"].createElement(Typography__default["default"], { sx: {
2670
- color: 'text.secondary',
2671
- fontStyle: 'italic',
2672
- maxWidth: `min(100vw, ${(_c = (_b = tablePaperRef.current) === null || _b === void 0 ? void 0 : _b.clientWidth) !== null && _c !== void 0 ? _c : 360}px)`,
2673
- py: '2rem',
2674
- textAlign: 'center',
2675
- width: '100%',
2676
- } }, globalFilter || columnFilters.length
2677
- ? localization.noResultsFound
2678
- : localization.noRecordsToDisplay)))) : (React__default["default"].createElement(React__default["default"].Fragment, null, (virtualRows !== null && virtualRows !== void 0 ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
2678
+ React__default["default"].createElement("td", { colSpan: table.getVisibleLeafColumns().length, style: {
2679
+ display: layoutMode === 'grid' ? 'grid' : 'table-cell',
2680
+ } }, (_b = renderEmptyRowsFallback === null || renderEmptyRowsFallback === void 0 ? void 0 : renderEmptyRowsFallback({ table })) !== null && _b !== void 0 ? _b : (React__default["default"].createElement(Typography__default["default"], { sx: {
2681
+ color: 'text.secondary',
2682
+ fontStyle: 'italic',
2683
+ maxWidth: `min(100vw, ${(_d = (_c = tablePaperRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 360}px)`,
2684
+ py: '2rem',
2685
+ textAlign: 'center',
2686
+ width: '100%',
2687
+ } }, globalFilter || columnFilters.length
2688
+ ? localization.noResultsFound
2689
+ : localization.noRecordsToDisplay))))) : (React__default["default"].createElement(React__default["default"].Fragment, null, (virtualRows !== null && virtualRows !== void 0 ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
2679
2690
  const row = rowVirtualizer
2680
2691
  ? rows[rowOrVirtualRow.index]
2681
2692
  : rowOrVirtualRow;