material-react-table 0.9.0 → 0.9.3

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.
@@ -5,6 +5,7 @@ import { Tooltip, IconButton, Menu, MenuItem, Box, FormControlLabel, Switch, But
5
5
  import { rankItem, rankings } from '@tanstack/match-sorter-utils';
6
6
  import { useDrop, useDrag, DndProvider } from 'react-dnd';
7
7
  import { HTML5Backend } from 'react-dnd-html5-backend';
8
+ import { useVirtual } from 'react-virtual';
8
9
 
9
10
  function _extends() {
10
11
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -1911,7 +1912,7 @@ var MRT_ToolbarBottom = function MRT_ToolbarBottom(_ref) {
1911
1912
  }, toolbarProps == null ? void 0 : toolbarProps.sx);
1912
1913
  }
1913
1914
  }), React.createElement(MRT_LinearProgressBar, {
1914
- alignTo: 'top',
1915
+ alignTo: "top",
1915
1916
  tableInstance: tableInstance
1916
1917
  }), positionToolbarAlertBanner === 'bottom' && React.createElement(MRT_ToolbarAlertBanner, {
1917
1918
  tableInstance: tableInstance
@@ -2736,11 +2737,13 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2736
2737
  editingMode = _tableInstance$option.editingMode,
2737
2738
  enableClickToCopy = _tableInstance$option.enableClickToCopy,
2738
2739
  enableColumnOrdering = _tableInstance$option.enableColumnOrdering,
2740
+ enableColumnResizing = _tableInstance$option.enableColumnResizing,
2739
2741
  enableEditing = _tableInstance$option.enableEditing,
2740
- tableId = _tableInstance$option.tableId,
2742
+ enableRowVirtualization = _tableInstance$option.enableRowVirtualization,
2741
2743
  muiTableBodyCellProps = _tableInstance$option.muiTableBodyCellProps,
2742
2744
  muiTableBodyCellSkeletonProps = _tableInstance$option.muiTableBodyCellSkeletonProps,
2743
2745
  onMrtCellClick = _tableInstance$option.onMrtCellClick,
2746
+ tableId = _tableInstance$option.tableId,
2744
2747
  setColumnOrder = tableInstance.setColumnOrder,
2745
2748
  setCurrentEditingCell = tableInstance.setCurrentEditingCell;
2746
2749
 
@@ -2816,7 +2819,8 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2816
2819
  tableInstance: tableInstance
2817
2820
  });
2818
2821
  },
2819
- onDoubleClick: handleDoubleClick
2822
+ onDoubleClick: handleDoubleClick,
2823
+ title: (enableRowVirtualization || enableColumnResizing) && !(columnDef != null && columnDef.Cell) && !cell.getIsGrouped() && !columnDef.enableClickToCopy && typeof cell.getValue() === 'string' ? cell.getValue() : ''
2820
2824
  }, tableCellProps, {
2821
2825
  ref: columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined,
2822
2826
  sx: function sx(theme) {
@@ -2825,15 +2829,17 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2825
2829
  boxShadow: getIsLastLeftPinnedColumn() ? "4px 0 4px -2px " + alpha(theme.palette.common.black, 0.1) : getIsFirstRightPinnedColumn() ? "-4px 0 4px -2px " + alpha(theme.palette.common.black, 0.1) : undefined,
2826
2830
  cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
2827
2831
  left: column.getIsPinned() === 'left' ? column.getStart('left') + "px" : undefined,
2832
+ overflow: 'hidden',
2828
2833
  p: isDensePadding ? columnDefType === 'display' ? '0 0.5rem' : '0.5rem' : columnDefType === 'display' ? '0.5rem 0.75rem' : '1rem',
2829
2834
  pl: column.id === 'mrt-expand' ? row.depth + (isDensePadding ? 0.5 : 0.75) + "rem" : undefined,
2830
2835
  position: column.getIsPinned() ? 'sticky' : 'relative',
2831
2836
  right: column.getIsPinned() === 'right' ? getTotalRight() + "px" : undefined,
2837
+ textOverflow: 'ellipsis',
2832
2838
  transition: 'all 0.2s ease-in-out',
2833
2839
  whiteSpace: isDensePadding ? 'nowrap' : 'normal',
2834
2840
  zIndex: column.getIsPinned() ? 1 : undefined,
2835
2841
  '&:hover': {
2836
- backgroundColor: enableHover ? theme.palette.mode === 'dark' ? lighten(theme.palette.background["default"], 0.13) + " !important" : darken(theme.palette.background["default"], 0.07) + " !important" : undefined
2842
+ backgroundColor: enableHover && enableEditing && editingMode !== 'row' ? theme.palette.mode === 'dark' ? lighten(theme.palette.background["default"], 0.13) + " !important" : darken(theme.palette.background["default"], 0.07) + " !important" : undefined
2837
2843
  }
2838
2844
  }, tableCellProps == null ? void 0 : tableCellProps.sx);
2839
2845
  },
@@ -2908,7 +2914,8 @@ var MRT_TableDetailPanel = function MRT_TableDetailPanel(_ref) {
2908
2914
  var MRT_TableBodyRow = function MRT_TableBodyRow(_ref) {
2909
2915
  var row = _ref.row,
2910
2916
  tableInstance = _ref.tableInstance;
2911
- var _tableInstance$option = tableInstance.options,
2917
+ var getIsSomeColumnsPinned = tableInstance.getIsSomeColumnsPinned,
2918
+ _tableInstance$option = tableInstance.options,
2912
2919
  muiTableBodyRowProps = _tableInstance$option.muiTableBodyRowProps,
2913
2920
  onMrtRowClick = _tableInstance$option.onMrtRowClick,
2914
2921
  renderDetailPanel = _tableInstance$option.renderDetailPanel;
@@ -2932,7 +2939,7 @@ var MRT_TableBodyRow = function MRT_TableBodyRow(_ref) {
2932
2939
  backgroundColor: lighten(theme.palette.background["default"], 0.06),
2933
2940
  transition: 'all 0.2s ease-in-out',
2934
2941
  '&:hover td': {
2935
- backgroundColor: (tableRowProps == null ? void 0 : tableRowProps.hover) !== false ? theme.palette.mode === 'dark' ? "" + lighten(theme.palette.background["default"], 0.12) : "" + darken(theme.palette.background["default"], 0.05) : undefined
2942
+ backgroundColor: (tableRowProps == null ? void 0 : tableRowProps.hover) !== false && getIsSomeColumnsPinned() ? theme.palette.mode === 'dark' ? "" + lighten(theme.palette.background["default"], 0.12) : "" + darken(theme.palette.background["default"], 0.05) : undefined
2936
2943
  }
2937
2944
  }, tableRowProps == null ? void 0 : tableRowProps.sx);
2938
2945
  }
@@ -2950,23 +2957,47 @@ var MRT_TableBodyRow = function MRT_TableBodyRow(_ref) {
2950
2957
  };
2951
2958
 
2952
2959
  var MRT_TableBody = function MRT_TableBody(_ref) {
2953
- var tableInstance = _ref.tableInstance;
2960
+ var tableInstance = _ref.tableInstance,
2961
+ tableContainerRef = _ref.tableContainerRef;
2954
2962
  var getPaginationRowModel = tableInstance.getPaginationRowModel,
2955
2963
  getPrePaginationRowModel = tableInstance.getPrePaginationRowModel,
2964
+ getState = tableInstance.getState,
2956
2965
  _tableInstance$option = tableInstance.options,
2957
2966
  enablePagination = _tableInstance$option.enablePagination,
2967
+ enableRowVirtualization = _tableInstance$option.enableRowVirtualization,
2958
2968
  muiTableBodyProps = _tableInstance$option.muiTableBodyProps;
2959
- var rows = enablePagination ? getPaginationRowModel().rows : getPrePaginationRowModel().rows;
2969
+
2970
+ var _getState = getState(),
2971
+ isDensePadding = _getState.isDensePadding;
2972
+
2960
2973
  var tableBodyProps = muiTableBodyProps instanceof Function ? muiTableBodyProps({
2961
2974
  tableInstance: tableInstance
2962
2975
  }) : muiTableBodyProps;
2963
- return React.createElement(TableBody, Object.assign({}, tableBodyProps), rows.map(function (row) {
2976
+ var rows = enablePagination ? getPaginationRowModel().rows : getPrePaginationRowModel().rows;
2977
+ var rowVirtualizer = enableRowVirtualization ? useVirtual({
2978
+ overscan: isDensePadding ? 15 : 5,
2979
+ size: rows.length,
2980
+ parentRef: tableContainerRef
2981
+ }) : {};
2982
+ var virtualRows = rowVirtualizer.virtualItems;
2983
+ var paddingTop = (virtualRows == null ? void 0 : virtualRows.length) > 0 ? virtualRows[0].start : 0;
2984
+ var paddingBottom = (virtualRows == null ? void 0 : virtualRows.length) > 0 ? rowVirtualizer.totalSize - virtualRows[virtualRows.length - 1].end : 0;
2985
+ return React.createElement(TableBody, Object.assign({}, tableBodyProps), enableRowVirtualization && paddingTop > 0 && React.createElement("tr", null, React.createElement("td", {
2986
+ style: {
2987
+ height: paddingTop + "px"
2988
+ }
2989
+ })), (enableRowVirtualization ? virtualRows : rows).map(function (rowOrVirtualRow) {
2990
+ var row = enableRowVirtualization ? rows[rowOrVirtualRow.index] : rowOrVirtualRow;
2964
2991
  return React.createElement(MRT_TableBodyRow, {
2965
2992
  key: row.id,
2966
2993
  row: row,
2967
2994
  tableInstance: tableInstance
2968
2995
  });
2969
- }));
2996
+ }), enableRowVirtualization && paddingBottom > 0 && React.createElement("tr", null, React.createElement("td", {
2997
+ style: {
2998
+ height: paddingBottom + "px"
2999
+ }
3000
+ })));
2970
3001
  };
2971
3002
 
2972
3003
  var MRT_TableFooterCell = function MRT_TableFooterCell(_ref) {
@@ -3060,8 +3091,11 @@ var MRT_TableFooter = function MRT_TableFooter(_ref) {
3060
3091
  };
3061
3092
 
3062
3093
  var MRT_Table = function MRT_Table(_ref) {
3063
- var tableInstance = _ref.tableInstance;
3094
+ var tableContainerRef = _ref.tableContainerRef,
3095
+ tableInstance = _ref.tableInstance;
3064
3096
  var _tableInstance$option = tableInstance.options,
3097
+ enableColumnResizing = _tableInstance$option.enableColumnResizing,
3098
+ enableRowVirtualization = _tableInstance$option.enableRowVirtualization,
3065
3099
  enableStickyHeader = _tableInstance$option.enableStickyHeader,
3066
3100
  enableTableFooter = _tableInstance$option.enableTableFooter,
3067
3101
  enableTableHead = _tableInstance$option.enableTableHead,
@@ -3071,9 +3105,14 @@ var MRT_Table = function MRT_Table(_ref) {
3071
3105
  }) : muiTableProps;
3072
3106
  return React.createElement(Table, Object.assign({
3073
3107
  stickyHeader: enableStickyHeader
3074
- }, tableProps), enableTableHead && React.createElement(MRT_TableHead, {
3108
+ }, tableProps, {
3109
+ sx: _extends({
3110
+ tableLayout: enableColumnResizing || enableRowVirtualization ? 'fixed' : undefined
3111
+ }, tableProps == null ? void 0 : tableProps.sx)
3112
+ }), enableTableHead && React.createElement(MRT_TableHead, {
3075
3113
  tableInstance: tableInstance
3076
3114
  }), React.createElement(MRT_TableBody, {
3115
+ tableContainerRef: tableContainerRef,
3077
3116
  tableInstance: tableInstance
3078
3117
  }), enableTableFooter && React.createElement(MRT_TableFooter, {
3079
3118
  tableInstance: tableInstance
@@ -3086,8 +3125,8 @@ var MRT_TableContainer = function MRT_TableContainer(_ref) {
3086
3125
  var getState = tableInstance.getState,
3087
3126
  _tableInstance$option = tableInstance.options,
3088
3127
  enableStickyHeader = _tableInstance$option.enableStickyHeader,
3089
- tableId = _tableInstance$option.tableId,
3090
- muiTableContainerProps = _tableInstance$option.muiTableContainerProps;
3128
+ muiTableContainerProps = _tableInstance$option.muiTableContainerProps,
3129
+ tableId = _tableInstance$option.tableId;
3091
3130
 
3092
3131
  var _getState = getState(),
3093
3132
  isFullScreen = _getState.isFullScreen;
@@ -3106,7 +3145,9 @@ var MRT_TableContainer = function MRT_TableContainer(_ref) {
3106
3145
  var bottomToolbarHeight = typeof document !== 'undefined' ? (_document$getElementB3 = (_document2 = document) == null ? void 0 : (_document2$getElement = _document2.getElementById("mrt-" + tableId + "-toolbar-bottom")) == null ? void 0 : _document2$getElement.offsetHeight) != null ? _document$getElementB3 : 0 : 0;
3107
3146
  setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
3108
3147
  });
3148
+ var tableContainerRef = React.useRef(null);
3109
3149
  return React.createElement(TableContainer, Object.assign({}, tableContainerProps, {
3150
+ ref: tableContainerRef,
3110
3151
  sx: _extends({
3111
3152
  maxWidth: '100%',
3112
3153
  maxHeight: enableStickyHeader ? "clamp(350px, calc(100vh - " + totalToolbarHeight + "px), 2000px)" : undefined,
@@ -3116,6 +3157,7 @@ var MRT_TableContainer = function MRT_TableContainer(_ref) {
3116
3157
  maxHeight: isFullScreen ? "calc(100vh - " + totalToolbarHeight + "px)" : undefined
3117
3158
  }
3118
3159
  }), React.createElement(MRT_Table, {
3160
+ tableContainerRef: tableContainerRef,
3119
3161
  tableInstance: tableInstance
3120
3162
  }));
3121
3163
  };
@@ -3437,9 +3479,9 @@ var MaterialReactTable = (function (_ref) {
3437
3479
  columnResizeMode = _ref$columnResizeMode === void 0 ? 'onEnd' : _ref$columnResizeMode,
3438
3480
  _ref$defaultColumn = _ref.defaultColumn,
3439
3481
  defaultColumn = _ref$defaultColumn === void 0 ? {
3440
- minSize: 50,
3482
+ minSize: 30,
3441
3483
  maxSize: 1000,
3442
- size: 150
3484
+ size: 180
3443
3485
  } : _ref$defaultColumn,
3444
3486
  _ref$editingMode = _ref.editingMode,
3445
3487
  editingMode = _ref$editingMode === void 0 ? 'row' : _ref$editingMode,