material-react-table 0.7.2 → 0.7.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.
@@ -2190,8 +2190,12 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
2190
2190
  tableInstance = _ref.tableInstance;
2191
2191
  var getState = tableInstance.getState,
2192
2192
  _tableInstance$option = tableInstance.options,
2193
+ idPrefix = _tableInstance$option.idPrefix,
2193
2194
  enableEditing = _tableInstance$option.enableEditing,
2194
2195
  muiTableBodyCellEditTextFieldProps = _tableInstance$option.muiTableBodyCellEditTextFieldProps,
2196
+ onCellEditBlur = _tableInstance$option.onCellEditBlur,
2197
+ onCellEditChange = _tableInstance$option.onCellEditChange,
2198
+ setCurrentEditingCell = tableInstance.setCurrentEditingCell,
2195
2199
  setCurrentEditingRow = tableInstance.setCurrentEditingRow;
2196
2200
 
2197
2201
  var _useState = useState(cell.value),
@@ -2208,6 +2212,11 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
2208
2212
  cell: cell,
2209
2213
  tableInstance: tableInstance
2210
2214
  });
2215
+ onCellEditChange == null ? void 0 : onCellEditChange({
2216
+ event: event,
2217
+ cell: cell,
2218
+ tableInstance: tableInstance
2219
+ });
2211
2220
  };
2212
2221
 
2213
2222
  var handleBlur = function handleBlur(event) {
@@ -2216,11 +2225,17 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
2216
2225
  setCurrentEditingRow(_extends({}, getState().currentEditingRow));
2217
2226
  }
2218
2227
 
2228
+ setCurrentEditingCell(null);
2219
2229
  column.onCellEditBlur == null ? void 0 : column.onCellEditBlur({
2220
2230
  event: event,
2221
2231
  cell: cell,
2222
2232
  tableInstance: tableInstance
2223
2233
  });
2234
+ onCellEditBlur == null ? void 0 : onCellEditBlur({
2235
+ event: event,
2236
+ cell: cell,
2237
+ tableInstance: tableInstance
2238
+ });
2224
2239
  };
2225
2240
 
2226
2241
  var mTableBodyCellEditTextFieldProps = muiTableBodyCellEditTextFieldProps instanceof Function ? muiTableBodyCellEditTextFieldProps({
@@ -2242,6 +2257,7 @@ var MRT_EditCellTextField = function MRT_EditCellTextField(_ref) {
2242
2257
  }
2243
2258
 
2244
2259
  return React.createElement(TextField, Object.assign({
2260
+ id: "mrt-" + idPrefix + "-edit-cell-text-field-" + cell.id,
2245
2261
  margin: "dense",
2246
2262
  onBlur: handleBlur,
2247
2263
  onChange: handleChange,
@@ -2302,6 +2318,7 @@ var MRT_CopyButton = function MRT_CopyButton(_ref) {
2302
2318
  backgroundColor: 'transparent',
2303
2319
  border: 'none',
2304
2320
  color: 'inherit',
2321
+ cursor: 'copy',
2305
2322
  fontFamily: 'inherit',
2306
2323
  fontSize: 'inherit',
2307
2324
  letterSpacing: 'inherit',
@@ -2322,15 +2339,19 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2322
2339
  var getIsSomeColumnsPinned = tableInstance.getIsSomeColumnsPinned,
2323
2340
  getState = tableInstance.getState,
2324
2341
  _tableInstance$option = tableInstance.options,
2342
+ editingMode = _tableInstance$option.editingMode,
2325
2343
  enableClickToCopy = _tableInstance$option.enableClickToCopy,
2326
- enablePinning = _tableInstance$option.enablePinning,
2327
2344
  enableEditing = _tableInstance$option.enableEditing,
2345
+ enablePinning = _tableInstance$option.enablePinning,
2346
+ idPrefix = _tableInstance$option.idPrefix,
2328
2347
  isLoading = _tableInstance$option.isLoading,
2329
2348
  muiTableBodyCellProps = _tableInstance$option.muiTableBodyCellProps,
2330
2349
  muiTableBodyCellSkeletonProps = _tableInstance$option.muiTableBodyCellSkeletonProps,
2331
- onCellClick = _tableInstance$option.onCellClick;
2350
+ onCellClick = _tableInstance$option.onCellClick,
2351
+ setCurrentEditingCell = tableInstance.setCurrentEditingCell;
2332
2352
 
2333
2353
  var _getState = getState(),
2354
+ currentEditingCell = _getState.currentEditingCell,
2334
2355
  currentEditingRow = _getState.currentEditingRow,
2335
2356
  isDensePadding = _getState.isDensePadding;
2336
2357
 
@@ -2350,6 +2371,23 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2350
2371
  var skeletonWidth = useMemo(function () {
2351
2372
  return column.columnDefType === 'display' ? column.getWidth() / 2 : Math.random() * (column.getWidth() - column.getWidth() / 3) + column.getWidth() / 3;
2352
2373
  }, [column.columnDefType, column.getWidth()]);
2374
+ var isEditable = (enableEditing || column.enableEditing) && column.enableEditing !== false;
2375
+ var isEditing = isEditable && (editingMode === 'table' || (currentEditingRow == null ? void 0 : currentEditingRow.id) === row.id || (currentEditingCell == null ? void 0 : currentEditingCell.id) === cell.id);
2376
+
2377
+ var handleDoubleClick = function handleDoubleClick(_event) {
2378
+ if ((enableEditing || column.enableEditing) && column.enableEditing !== false && editingMode === 'cell') {
2379
+ setCurrentEditingCell(cell);
2380
+ setTimeout(function () {
2381
+ var textField = document.getElementById("mrt-" + idPrefix + "-edit-cell-text-field-" + cell.id);
2382
+
2383
+ if (textField) {
2384
+ textField.focus();
2385
+ textField.select();
2386
+ }
2387
+ }, 200);
2388
+ }
2389
+ };
2390
+
2353
2391
  return React.createElement(TableCell, Object.assign({
2354
2392
  onClick: function onClick(event) {
2355
2393
  return onCellClick == null ? void 0 : onCellClick({
@@ -2357,9 +2395,11 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2357
2395
  cell: cell,
2358
2396
  tableInstance: tableInstance
2359
2397
  });
2360
- }
2398
+ },
2399
+ onDoubleClick: handleDoubleClick
2361
2400
  }, tableCellProps, {
2362
2401
  sx: _extends({
2402
+ cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
2363
2403
  maxWidth: "min(" + column.getWidth() + "px, fit-content)",
2364
2404
  minWidth: "max(" + column.getWidth() + "px, " + column.minWidth + "px)",
2365
2405
  p: isDensePadding ? column.columnDefType === 'display' ? '0 0.5rem' : '0.5rem' : column.columnDefType === 'display' ? '0.5rem 0.75rem' : '1rem',
@@ -2375,7 +2415,7 @@ var MRT_TableBodyCell = function MRT_TableBodyCell(_ref) {
2375
2415
  }, muiTableBodyCellSkeletonProps)) : column.columnDefType === 'display' ? column.Cell == null ? void 0 : column.Cell({
2376
2416
  cell: cell,
2377
2417
  tableInstance: tableInstance
2378
- }) : cell.getIsPlaceholder() || row.getIsGrouped() && column.id !== row.groupingColumnId ? null : cell.getIsAggregated() ? cell.renderAggregatedCell() : enableEditing && column.enableEditing !== false && (currentEditingRow == null ? void 0 : currentEditingRow.id) === row.id ? React.createElement(MRT_EditCellTextField, {
2418
+ }) : cell.getIsPlaceholder() || row.getIsGrouped() && column.id !== row.groupingColumnId ? null : cell.getIsAggregated() ? cell.renderAggregatedCell() : isEditing ? React.createElement(MRT_EditCellTextField, {
2379
2419
  cell: cell,
2380
2420
  tableInstance: tableInstance
2381
2421
  }) : (enableClickToCopy || column.enableClickToCopy) && column.enableClickToCopy !== false ? React.createElement(React.Fragment, null, React.createElement(MRT_CopyButton, {
@@ -2832,7 +2872,7 @@ var createDisplayColumn = function createDisplayColumn(table, column) {
2832
2872
  };
2833
2873
 
2834
2874
  var MRT_TableRoot = function MRT_TableRoot(props) {
2835
- var _props$initialState$i, _props$initialState, _props$initialState$i2, _props$initialState2, _props$initialState$s, _props$initialState3, _props$initialState$s2, _props$initialState4, _props$initialState$p, _props$initialState5, _props$initialState5$, _props$initialState$p2, _props$initialState6, _props$initialState6$, _props$initialState$p3, _props$initialState7, _props$initialState7$, _props$globalFilterTy;
2875
+ var _props$initialState$c, _props$initialState, _props$initialState$c2, _props$initialState2, _props$initialState$i, _props$initialState3, _props$initialState$i2, _props$initialState4, _props$initialState$s, _props$initialState5, _props$initialState$s2, _props$initialState6, _props$initialState$p, _props$initialState7, _props$initialState7$, _props$initialState$p2, _props$initialState8, _props$initialState8$, _props$initialState$p3, _props$initialState9, _props$initialState9$, _props$globalFilterTy;
2836
2876
 
2837
2877
  var _useState = useState(props.idPrefix),
2838
2878
  idPrefix = _useState[0],
@@ -2844,49 +2884,53 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
2844
2884
  return setIdPrefix((_props$idPrefix = props.idPrefix) != null ? _props$idPrefix : Math.random().toString(36).substring(2, 9));
2845
2885
  }, [props.idPrefix]);
2846
2886
 
2847
- var _useState2 = useState(null),
2848
- currentEditingRow = _useState2[0],
2849
- setCurrentEditingRow = _useState2[1];
2887
+ var _useState2 = useState((_props$initialState$c = (_props$initialState = props.initialState) == null ? void 0 : _props$initialState.currentEditingCell) != null ? _props$initialState$c : null),
2888
+ currentEditingCell = _useState2[0],
2889
+ setCurrentEditingCell = _useState2[1];
2890
+
2891
+ var _useState3 = useState((_props$initialState$c2 = (_props$initialState2 = props.initialState) == null ? void 0 : _props$initialState2.currentEditingRow) != null ? _props$initialState$c2 : null),
2892
+ currentEditingRow = _useState3[0],
2893
+ setCurrentEditingRow = _useState3[1];
2850
2894
 
2851
- var _useState3 = useState((_props$initialState$i = (_props$initialState = props.initialState) == null ? void 0 : _props$initialState.isDensePadding) != null ? _props$initialState$i : false),
2852
- isDensePadding = _useState3[0],
2853
- setIsDensePadding = _useState3[1];
2895
+ var _useState4 = useState((_props$initialState$i = (_props$initialState3 = props.initialState) == null ? void 0 : _props$initialState3.isDensePadding) != null ? _props$initialState$i : false),
2896
+ isDensePadding = _useState4[0],
2897
+ setIsDensePadding = _useState4[1];
2854
2898
 
2855
- var _useState4 = useState((_props$initialState$i2 = (_props$initialState2 = props.initialState) == null ? void 0 : _props$initialState2.isFullScreen) != null ? _props$initialState$i2 : false),
2856
- isFullScreen = _useState4[0],
2857
- setIsFullScreen = _useState4[1];
2899
+ var _useState5 = useState((_props$initialState$i2 = (_props$initialState4 = props.initialState) == null ? void 0 : _props$initialState4.isFullScreen) != null ? _props$initialState$i2 : false),
2900
+ isFullScreen = _useState5[0],
2901
+ setIsFullScreen = _useState5[1];
2858
2902
 
2859
- var _useState5 = useState((_props$initialState$s = (_props$initialState3 = props.initialState) == null ? void 0 : _props$initialState3.showFilters) != null ? _props$initialState$s : false),
2860
- showFilters = _useState5[0],
2861
- setShowFilters = _useState5[1];
2903
+ var _useState6 = useState((_props$initialState$s = (_props$initialState5 = props.initialState) == null ? void 0 : _props$initialState5.showFilters) != null ? _props$initialState$s : false),
2904
+ showFilters = _useState6[0],
2905
+ setShowFilters = _useState6[1];
2862
2906
 
2863
- var _useState6 = useState((_props$initialState$s2 = (_props$initialState4 = props.initialState) == null ? void 0 : _props$initialState4.showGlobalFilter) != null ? _props$initialState$s2 : false),
2864
- showGlobalFilter = _useState6[0],
2865
- setShowGlobalFilter = _useState6[1];
2907
+ var _useState7 = useState((_props$initialState$s2 = (_props$initialState6 = props.initialState) == null ? void 0 : _props$initialState6.showGlobalFilter) != null ? _props$initialState$s2 : false),
2908
+ showGlobalFilter = _useState7[0],
2909
+ setShowGlobalFilter = _useState7[1];
2866
2910
 
2867
- var _useState7 = useState({
2868
- pageIndex: (_props$initialState$p = (_props$initialState5 = props.initialState) == null ? void 0 : (_props$initialState5$ = _props$initialState5.pagination) == null ? void 0 : _props$initialState5$.pageIndex) != null ? _props$initialState$p : 0,
2869
- pageSize: (_props$initialState$p2 = (_props$initialState6 = props.initialState) == null ? void 0 : (_props$initialState6$ = _props$initialState6.pagination) == null ? void 0 : _props$initialState6$.pageSize) != null ? _props$initialState$p2 : 10,
2870
- pageCount: (_props$initialState$p3 = (_props$initialState7 = props.initialState) == null ? void 0 : (_props$initialState7$ = _props$initialState7.pagination) == null ? void 0 : _props$initialState7$.pageCount) != null ? _props$initialState$p3 : -1
2911
+ var _useState8 = useState({
2912
+ pageIndex: (_props$initialState$p = (_props$initialState7 = props.initialState) == null ? void 0 : (_props$initialState7$ = _props$initialState7.pagination) == null ? void 0 : _props$initialState7$.pageIndex) != null ? _props$initialState$p : 0,
2913
+ pageSize: (_props$initialState$p2 = (_props$initialState8 = props.initialState) == null ? void 0 : (_props$initialState8$ = _props$initialState8.pagination) == null ? void 0 : _props$initialState8$.pageSize) != null ? _props$initialState$p2 : 10,
2914
+ pageCount: (_props$initialState$p3 = (_props$initialState9 = props.initialState) == null ? void 0 : (_props$initialState9$ = _props$initialState9.pagination) == null ? void 0 : _props$initialState9$.pageCount) != null ? _props$initialState$p3 : -1
2871
2915
  }),
2872
- pagination = _useState7[0],
2873
- setPagination = _useState7[1];
2916
+ pagination = _useState8[0],
2917
+ setPagination = _useState8[1];
2874
2918
 
2875
- var _useState8 = useState(function () {
2919
+ var _useState9 = useState(function () {
2876
2920
  return Object.assign.apply(Object, [{}].concat(getAllLeafColumnDefs(props.columns).map(function (c) {
2877
- var _ref, _c$filter, _props$initialState8, _props$initialState8$, _c$filterSelectOption, _ref2;
2921
+ var _ref, _c$filter, _props$initialState10, _props$initialState11, _c$filterSelectOption, _ref2;
2878
2922
 
2879
- return _ref2 = {}, _ref2[c.id] = (_ref = (_c$filter = c.filter) != null ? _c$filter : props == null ? void 0 : (_props$initialState8 = props.initialState) == null ? void 0 : (_props$initialState8$ = _props$initialState8.columnFilters) == null ? void 0 : _props$initialState8$.find(function (cf) {
2923
+ return _ref2 = {}, _ref2[c.id] = (_ref = (_c$filter = c.filter) != null ? _c$filter : props == null ? void 0 : (_props$initialState10 = props.initialState) == null ? void 0 : (_props$initialState11 = _props$initialState10.columnFilters) == null ? void 0 : _props$initialState11.find(function (cf) {
2880
2924
  return cf.id === c.id;
2881
2925
  })) != null ? _ref : !!((_c$filterSelectOption = c.filterSelectOptions) != null && _c$filterSelectOption.length) ? MRT_FILTER_TYPE.EQUALS : MRT_FILTER_TYPE.BEST_MATCH, _ref2;
2882
2926
  })));
2883
2927
  }),
2884
- currentFilterTypes = _useState8[0],
2885
- setCurrentFilterTypes = _useState8[1];
2928
+ currentFilterTypes = _useState9[0],
2929
+ setCurrentFilterTypes = _useState9[1];
2886
2930
 
2887
- var _useState9 = useState((_props$globalFilterTy = props.globalFilterType) != null ? _props$globalFilterTy : MRT_FILTER_TYPE.BEST_MATCH_FIRST),
2888
- currentGlobalFilterType = _useState9[0],
2889
- setCurrentGlobalFilterType = _useState9[1];
2931
+ var _useState10 = useState((_props$globalFilterTy = props.globalFilterType) != null ? _props$globalFilterTy : MRT_FILTER_TYPE.BEST_MATCH_FIRST),
2932
+ currentGlobalFilterType = _useState10[0],
2933
+ setCurrentGlobalFilterType = _useState10[1];
2890
2934
 
2891
2935
  var table = useMemo(function () {
2892
2936
  return createTable();
@@ -2894,7 +2938,7 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
2894
2938
  var displayColumns = useMemo(function () {
2895
2939
  var _props$localization, _props$localization2, _props$localization3, _props$localization5;
2896
2940
 
2897
- return [(props.enableRowActions || props.enableEditing) && createDisplayColumn(table, {
2941
+ return [(props.enableRowActions || props.enableEditing && props.editingMode === 'row') && createDisplayColumn(table, {
2898
2942
  Cell: function Cell(_ref3) {
2899
2943
  var cell = _ref3.cell;
2900
2944
  return React.createElement(MRT_ToggleRowActionMenuButton, {
@@ -2957,7 +3001,7 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
2957
3001
  width: 40,
2958
3002
  minWidth: 40
2959
3003
  })].filter(Boolean);
2960
- }, [props.enableEditing, props.enableExpandAll, props.enableExpanded, props.enableGrouping, props.enableRowActions, props.enableRowNumbers, props.enableRowSelection, props.enableSelectAll, props.localization, table]);
3004
+ }, [props.editingMode, props.enableEditing, props.enableExpandAll, props.enableExpanded, props.enableGrouping, props.enableRowActions, props.enableRowNumbers, props.enableRowSelection, props.enableSelectAll, props.localization, table]);
2961
3005
  var columns = useMemo(function () {
2962
3006
  return table.createColumns([].concat(displayColumns, props.columns.map(function (column) {
2963
3007
  return column.columns ? createGroup(table, column, currentFilterTypes) : createDataColumn(table, column, currentFilterTypes);
@@ -2997,6 +3041,7 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
2997
3041
  columns: columns,
2998
3042
  data: data,
2999
3043
  state: _extends({
3044
+ currentEditingCell: currentEditingCell,
3000
3045
  currentEditingRow: currentEditingRow,
3001
3046
  currentFilterTypes: currentFilterTypes,
3002
3047
  currentGlobalFilterType: currentGlobalFilterType,
@@ -3008,6 +3053,9 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
3008
3053
  showGlobalFilter: showGlobalFilter
3009
3054
  }, props.state)
3010
3055
  })), {
3056
+ //@ts-ignore
3057
+ setCurrentEditingCell: setCurrentEditingCell,
3058
+ //@ts-ignore
3011
3059
  setCurrentEditingRow: setCurrentEditingRow,
3012
3060
  setCurrentFilterTypes: setCurrentFilterTypes,
3013
3061
  setCurrentGlobalFilterType: setCurrentGlobalFilterType,
@@ -3035,12 +3083,14 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
3035
3083
  }));
3036
3084
  };
3037
3085
 
3038
- var _excluded$5 = ["autoResetExpanded", "columnResizeMode", "enableColumnActions", "enableColumnFilters", "enableColumnResizing", "enableDensePaddingToggle", "enableExpandAll", "enableFilters", "enableFullScreenToggle", "enableGlobalFilter", "enableHiding", "enableMultiRowSelection", "enablePagination", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarBottom", "enableToolbarInternalActions", "enableToolbarTop", "icons", "localization", "positionActionsColumn", "positionPagination", "positionToolbarActions", "positionToolbarAlertBanner"];
3086
+ var _excluded$5 = ["autoResetExpanded", "columnResizeMode", "editingMode", "enableColumnActions", "enableColumnFilters", "enableColumnResizing", "enableDensePaddingToggle", "enableExpandAll", "enableFilters", "enableFullScreenToggle", "enableGlobalFilter", "enableHiding", "enableMultiRowSelection", "enablePagination", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarBottom", "enableToolbarInternalActions", "enableToolbarTop", "icons", "localization", "positionActionsColumn", "positionPagination", "positionToolbarActions", "positionToolbarAlertBanner"];
3039
3087
  var MaterialReactTable = (function (_ref) {
3040
3088
  var _ref$autoResetExpande = _ref.autoResetExpanded,
3041
3089
  autoResetExpanded = _ref$autoResetExpande === void 0 ? false : _ref$autoResetExpande,
3042
3090
  _ref$columnResizeMode = _ref.columnResizeMode,
3043
3091
  columnResizeMode = _ref$columnResizeMode === void 0 ? 'onEnd' : _ref$columnResizeMode,
3092
+ _ref$editingMode = _ref.editingMode,
3093
+ editingMode = _ref$editingMode === void 0 ? 'row' : _ref$editingMode,
3044
3094
  _ref$enableColumnActi = _ref.enableColumnActions,
3045
3095
  enableColumnActions = _ref$enableColumnActi === void 0 ? true : _ref$enableColumnActi,
3046
3096
  _ref$enableColumnFilt = _ref.enableColumnFilters,
@@ -3094,6 +3144,7 @@ var MaterialReactTable = (function (_ref) {
3094
3144
  return React.createElement(MRT_TableRoot, Object.assign({
3095
3145
  autoResetExpanded: autoResetExpanded,
3096
3146
  columnResizeMode: columnResizeMode,
3147
+ editingMode: editingMode,
3097
3148
  enableColumnActions: enableColumnActions,
3098
3149
  enableColumnResizing: enableColumnResizing,
3099
3150
  enableColumnFilters: enableColumnFilters,