material-react-table 1.5.0-beta.1 → 1.5.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.
@@ -226,10 +226,10 @@ const getIsFirstRightPinnedColumn = (column) => {
226
226
  return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
227
227
  };
228
228
  const getTotalRight = (table, column) => {
229
- return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160);
229
+ return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 200);
230
230
  };
231
231
  const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
232
- var _a, _b, _c, _d;
232
+ var _a, _b, _c, _d, _e, _f, _g, _h;
233
233
  return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
234
234
  ? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
235
235
  : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
@@ -238,8 +238,18 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
238
238
  ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
239
239
  : undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', left: column.getIsPinned() === 'left'
240
240
  ? `${column.getStart('left')}px`
241
- : undefined, opacity: ((_a = table.getState().draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id ||
242
- ((_b = table.getState().hoveredColumn) === null || _b === void 0 ? void 0 : _b.id) === column.id
241
+ : undefined, ml: table.options.enableColumnVirtualization &&
242
+ column.getIsPinned() === 'left' &&
243
+ column.getPinnedIndex() === 0
244
+ ? `-${column.getSize() * ((_b = (_a = table.getState().columnPinning.left) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1)}px`
245
+ : undefined, mr: table.options.enableColumnVirtualization &&
246
+ column.getIsPinned() === 'right' &&
247
+ column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
248
+ ? `-${column.getSize() *
249
+ ((_d = (_c = table.getState().columnPinning.right) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 1) *
250
+ 1.2}px`
251
+ : undefined, opacity: ((_e = table.getState().draggingColumn) === null || _e === void 0 ? void 0 : _e.id) === column.id ||
252
+ ((_f = table.getState().hoveredColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id
243
253
  ? 0.5
244
254
  : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
245
255
  ? 'sticky'
@@ -251,7 +261,7 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
251
261
  ? tableCellProps.sx(theme)
252
262
  : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { flex: table.options.layoutMode === 'grid'
253
263
  ? `${column.getSize()} 0 auto`
254
- : undefined, minWidth: `max(${column.getSize()}px, ${(_c = column.columnDef.minSize) !== null && _c !== void 0 ? _c : 30}px)`, width: (_d = header === null || header === void 0 ? void 0 : header.getSize()) !== null && _d !== void 0 ? _d : column.getSize() }));
264
+ : undefined, minWidth: `max(${column.getSize()}px, ${(_g = column.columnDef.minSize) !== null && _g !== void 0 ? _g : 30}px)`, width: (_h = header === null || header === void 0 ? void 0 : header.getSize()) !== null && _h !== void 0 ? _h : column.getSize() }));
255
265
  };
256
266
  const MRT_DefaultColumn = {
257
267
  minSize: 40,
@@ -2515,7 +2525,7 @@ const MRT_TableFooter = ({ table, virtualColumns, virtualPaddingLeft, virtualPad
2515
2525
  };
2516
2526
 
2517
2527
  const MRT_Table = ({ table }) => {
2518
- var _a, _b;
2528
+ var _a, _b, _c, _d;
2519
2529
  const { getState, options: { columnVirtualizerInstanceRef, columnVirtualizerProps, enableColumnResizing, enableColumnVirtualization, enablePinning, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, }, refs: { tableContainerRef }, } = table;
2520
2530
  const { isFullScreen, columnPinning, columnVisibility } = getState();
2521
2531
  const tableProps = muiTableProps instanceof Function
@@ -2527,28 +2537,29 @@ const MRT_Table = ({ table }) => {
2527
2537
  //get first 16 column widths and average them
2528
2538
  const averageColumnWidth = useMemo(() => {
2529
2539
  var _a, _b, _c, _d;
2540
+ if (!enableColumnVirtualization)
2541
+ return 0;
2530
2542
  const columnsWidths = (_d = (_c = (_b = (_a = table
2531
2543
  .getRowModel()
2532
- .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.25)) !== null && _d !== void 0 ? _d : [];
2544
+ .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 : [];
2533
2545
  return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
2534
2546
  }, [table.getRowModel().rows, columnPinning, columnVisibility]);
2535
- const pinnedColumnIndexes = useMemo(() => enableColumnVirtualization && enablePinning
2547
+ const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(() => enableColumnVirtualization && enablePinning
2536
2548
  ? [
2537
- ...table.getLeftFlatHeaders().map((h) => h.column.getPinnedIndex()),
2538
- ...table
2539
- .getRightFlatHeaders()
2540
- .map((h) => table.getVisibleFlatColumns().length -
2541
- h.column.getPinnedIndex() -
2542
- 1),
2549
+ table.getLeftLeafColumns().map((c) => c.getPinnedIndex()),
2550
+ table
2551
+ .getRightLeafColumns()
2552
+ .map((c) => table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1),
2543
2553
  ]
2544
- : [], [columnPinning, enableColumnVirtualization, enablePinning]);
2554
+ : [[], []], [columnPinning, enableColumnVirtualization, enablePinning]);
2545
2555
  const columnVirtualizer = enableColumnVirtualization
2546
- ? useVirtualizer(Object.assign({ count: table.getRowModel().rows[0].getVisibleCells().length, estimateSize: () => averageColumnWidth, getScrollElement: () => tableContainerRef.current, horizontal: true, measureElement: (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect().width, overscan: 3, rangeExtractor: useCallback((range) => [
2556
+ ? useVirtualizer(Object.assign({ count: table.getVisibleLeafColumns().length, estimateSize: () => averageColumnWidth, getScrollElement: () => tableContainerRef.current, horizontal: true, overscan: 3, rangeExtractor: useCallback((range) => [
2547
2557
  ...new Set([
2548
- ...pinnedColumnIndexes,
2558
+ ...leftPinnedIndexes,
2549
2559
  ...defaultRangeExtractor(range),
2560
+ ...rightPinnedIndexes,
2550
2561
  ]),
2551
- ].sort((a, b) => a - b), [pinnedColumnIndexes]) }, vProps))
2562
+ ], [leftPinnedIndexes, rightPinnedIndexes]) }, vProps))
2552
2563
  : undefined;
2553
2564
  if (columnVirtualizerInstanceRef && columnVirtualizer) {
2554
2565
  columnVirtualizerInstanceRef.current = columnVirtualizer;
@@ -2559,13 +2570,10 @@ const MRT_Table = ({ table }) => {
2559
2570
  let virtualPaddingLeft;
2560
2571
  let virtualPaddingRight;
2561
2572
  if (columnVirtualizer && (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)) {
2562
- virtualPaddingLeft = (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)
2563
- ? ((_a = virtualColumns[0]) === null || _a === void 0 ? void 0 : _a.start) || 0
2564
- : 0;
2565
- virtualPaddingRight = (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)
2566
- ? columnVirtualizer.getTotalSize() -
2567
- (((_b = virtualColumns[virtualColumns.length - 1]) === null || _b === void 0 ? void 0 : _b.end) || 0)
2568
- : 0;
2573
+ virtualPaddingLeft = (_b = (_a = virtualColumns[leftPinnedIndexes.length]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0;
2574
+ virtualPaddingRight =
2575
+ columnVirtualizer.getTotalSize() -
2576
+ ((_d = (_c = virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes.length]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0);
2569
2577
  }
2570
2578
  const props = {
2571
2579
  table,