material-react-table 1.5.0-beta.1 → 1.5.0-beta.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/cjs/index.js CHANGED
@@ -305,10 +305,10 @@ const getIsFirstRightPinnedColumn = (column) => {
305
305
  return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
306
306
  };
307
307
  const getTotalRight = (table, column) => {
308
- return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160);
308
+ return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 200);
309
309
  };
310
310
  const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
311
- var _a, _b, _c, _d;
311
+ var _a, _b, _c, _d, _e, _f, _g, _h;
312
312
  return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
313
313
  ? styles.alpha(styles.lighten(theme.palette.background.default, 0.04), 0.97)
314
314
  : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
@@ -317,8 +317,20 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
317
317
  ? `4px 0 8px -6px ${styles.alpha(theme.palette.common.black, 0.2)} inset`
318
318
  : undefined, display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell', left: column.getIsPinned() === 'left'
319
319
  ? `${column.getStart('left')}px`
320
- : undefined, opacity: ((_a = table.getState().draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id ||
321
- ((_b = table.getState().hoveredColumn) === null || _b === void 0 ? void 0 : _b.id) === column.id
320
+ : undefined, ml: table.options.enableColumnVirtualization &&
321
+ column.getIsPinned() === 'left' &&
322
+ column.getPinnedIndex() === 0
323
+ ? `-${column.getSize() *
324
+ ((_b = (_a = table.getState().columnPinning.left) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1) *
325
+ 1.2}px`
326
+ : undefined, mr: table.options.enableColumnVirtualization &&
327
+ column.getIsPinned() === 'right' &&
328
+ column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
329
+ ? `-${column.getSize() *
330
+ ((_d = (_c = table.getState().columnPinning.right) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 1) *
331
+ 1.2}px`
332
+ : undefined, opacity: ((_e = table.getState().draggingColumn) === null || _e === void 0 ? void 0 : _e.id) === column.id ||
333
+ ((_f = table.getState().hoveredColumn) === null || _f === void 0 ? void 0 : _f.id) === column.id
322
334
  ? 0.5
323
335
  : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
324
336
  ? 'sticky'
@@ -330,7 +342,7 @@ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, })
330
342
  ? tableCellProps.sx(theme)
331
343
  : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { flex: table.options.layoutMode === 'grid'
332
344
  ? `${column.getSize()} 0 auto`
333
- : 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() }));
345
+ : 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() }));
334
346
  };
335
347
  const MRT_DefaultColumn = {
336
348
  minSize: 40,
@@ -2594,7 +2606,7 @@ const MRT_TableFooter = ({ table, virtualColumns, virtualPaddingLeft, virtualPad
2594
2606
  };
2595
2607
 
2596
2608
  const MRT_Table = ({ table }) => {
2597
- var _a, _b;
2609
+ var _a, _b, _c, _d;
2598
2610
  const { getState, options: { columnVirtualizerInstanceRef, columnVirtualizerProps, enableColumnResizing, enableColumnVirtualization, enablePinning, enableStickyHeader, enableTableFooter, enableTableHead, layoutMode, memoMode, muiTableProps, }, refs: { tableContainerRef }, } = table;
2599
2611
  const { isFullScreen, columnPinning, columnVisibility } = getState();
2600
2612
  const tableProps = muiTableProps instanceof Function
@@ -2608,26 +2620,25 @@ const MRT_Table = ({ table }) => {
2608
2620
  var _a, _b, _c, _d;
2609
2621
  const columnsWidths = (_d = (_c = (_b = (_a = table
2610
2622
  .getRowModel()
2611
- .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 : [];
2623
+ .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 : [];
2612
2624
  return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
2613
2625
  }, [table.getRowModel().rows, columnPinning, columnVisibility]);
2614
- const pinnedColumnIndexes = React.useMemo(() => enableColumnVirtualization && enablePinning
2626
+ const [leftPinnedIndexes, rightPinnedIndexes] = React.useMemo(() => enableColumnVirtualization && enablePinning
2615
2627
  ? [
2616
- ...table.getLeftFlatHeaders().map((h) => h.column.getPinnedIndex()),
2617
- ...table
2618
- .getRightFlatHeaders()
2619
- .map((h) => table.getVisibleFlatColumns().length -
2620
- h.column.getPinnedIndex() -
2621
- 1),
2628
+ table.getLeftLeafColumns().map((c) => c.getPinnedIndex()),
2629
+ table
2630
+ .getRightLeafColumns()
2631
+ .map((c) => table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1),
2622
2632
  ]
2623
- : [], [columnPinning, enableColumnVirtualization, enablePinning]);
2633
+ : [[], []], [columnPinning, enableColumnVirtualization, enablePinning]);
2624
2634
  const columnVirtualizer = enableColumnVirtualization
2625
- ? reactVirtual.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: React.useCallback((range) => [
2635
+ ? reactVirtual.useVirtualizer(Object.assign({ count: table.getVisibleLeafColumns().length, estimateSize: () => averageColumnWidth, getScrollElement: () => tableContainerRef.current, horizontal: true, overscan: 3, rangeExtractor: React.useCallback((range) => [
2626
2636
  ...new Set([
2627
- ...pinnedColumnIndexes,
2637
+ ...leftPinnedIndexes,
2628
2638
  ...reactVirtual.defaultRangeExtractor(range),
2639
+ ...rightPinnedIndexes,
2629
2640
  ]),
2630
- ].sort((a, b) => a - b), [pinnedColumnIndexes]) }, vProps))
2641
+ ], [leftPinnedIndexes, rightPinnedIndexes]) }, vProps))
2631
2642
  : undefined;
2632
2643
  if (columnVirtualizerInstanceRef && columnVirtualizer) {
2633
2644
  columnVirtualizerInstanceRef.current = columnVirtualizer;
@@ -2638,13 +2649,10 @@ const MRT_Table = ({ table }) => {
2638
2649
  let virtualPaddingLeft;
2639
2650
  let virtualPaddingRight;
2640
2651
  if (columnVirtualizer && (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)) {
2641
- virtualPaddingLeft = (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)
2642
- ? ((_a = virtualColumns[0]) === null || _a === void 0 ? void 0 : _a.start) || 0
2643
- : 0;
2644
- virtualPaddingRight = (virtualColumns === null || virtualColumns === void 0 ? void 0 : virtualColumns.length)
2645
- ? columnVirtualizer.getTotalSize() -
2646
- (((_b = virtualColumns[virtualColumns.length - 1]) === null || _b === void 0 ? void 0 : _b.end) || 0)
2647
- : 0;
2652
+ virtualPaddingLeft = (_b = (_a = virtualColumns[leftPinnedIndexes.length]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0;
2653
+ virtualPaddingRight =
2654
+ columnVirtualizer.getTotalSize() -
2655
+ ((_d = (_c = virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes.length]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0);
2648
2656
  }
2649
2657
  const props = {
2650
2658
  table,