@mui/x-data-grid 7.8.0 → 7.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +140 -0
  2. package/DataGrid/DataGrid.js +1 -0
  3. package/DataGrid/useDataGridProps.js +30 -22
  4. package/components/GridLoadingOverlay.d.ts +15 -3
  5. package/components/GridLoadingOverlay.js +48 -4
  6. package/components/GridRow.js +2 -1
  7. package/components/GridSkeletonLoadingOverlay.d.ts +3 -0
  8. package/components/GridSkeletonLoadingOverlay.js +181 -0
  9. package/components/base/GridOverlays.d.ts +11 -1
  10. package/components/base/GridOverlays.js +26 -40
  11. package/components/cell/GridSkeletonCell.d.ts +13 -6
  12. package/components/cell/GridSkeletonCell.js +61 -19
  13. package/components/containers/GridRoot.js +4 -16
  14. package/components/containers/GridRootStyles.js +11 -2
  15. package/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -1
  16. package/components/virtualization/GridMainContainer.js +11 -3
  17. package/components/virtualization/GridVirtualScroller.js +10 -6
  18. package/components/virtualization/GridVirtualScrollerFiller.d.ts +5 -1
  19. package/components/virtualization/GridVirtualScrollerFiller.js +9 -6
  20. package/constants/gridClasses.d.ts +9 -0
  21. package/constants/gridClasses.js +1 -1
  22. package/hooks/features/filter/gridFilterSelector.d.ts +11 -0
  23. package/hooks/features/filter/gridFilterSelector.js +13 -0
  24. package/hooks/features/overlays/useGridOverlays.d.ts +11 -0
  25. package/hooks/features/overlays/useGridOverlays.js +35 -0
  26. package/hooks/features/virtualization/useGridVirtualScroller.js +4 -12
  27. package/hooks/utils/index.d.ts +0 -1
  28. package/hooks/utils/index.js +0 -1
  29. package/index.js +1 -1
  30. package/locales/esES.js +1 -2
  31. package/models/api/gridRowSelectionApi.d.ts +2 -2
  32. package/models/colDef/gridColDef.d.ts +4 -4
  33. package/models/gridRowSelectionModel.d.ts +2 -2
  34. package/models/gridSlotsComponentsProps.d.ts +2 -1
  35. package/models/props/DataGridProps.d.ts +5 -4
  36. package/modern/DataGrid/DataGrid.js +1 -0
  37. package/modern/DataGrid/useDataGridProps.js +30 -22
  38. package/modern/components/GridLoadingOverlay.js +48 -4
  39. package/modern/components/GridRow.js +2 -1
  40. package/modern/components/GridSkeletonLoadingOverlay.js +181 -0
  41. package/modern/components/base/GridOverlays.js +26 -40
  42. package/modern/components/cell/GridSkeletonCell.js +61 -19
  43. package/modern/components/containers/GridRoot.js +4 -16
  44. package/modern/components/containers/GridRootStyles.js +11 -2
  45. package/modern/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -1
  46. package/modern/components/virtualization/GridMainContainer.js +11 -3
  47. package/modern/components/virtualization/GridVirtualScroller.js +10 -6
  48. package/modern/components/virtualization/GridVirtualScrollerFiller.js +9 -6
  49. package/modern/constants/gridClasses.js +1 -1
  50. package/modern/hooks/features/filter/gridFilterSelector.js +13 -0
  51. package/modern/hooks/features/overlays/useGridOverlays.js +35 -0
  52. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +4 -12
  53. package/modern/hooks/utils/index.js +0 -1
  54. package/modern/index.js +1 -1
  55. package/modern/locales/esES.js +1 -2
  56. package/modern/utils/utils.js +10 -2
  57. package/node/DataGrid/DataGrid.js +1 -0
  58. package/node/DataGrid/useDataGridProps.js +30 -22
  59. package/node/components/GridLoadingOverlay.js +48 -4
  60. package/node/components/GridRow.js +2 -1
  61. package/node/components/GridSkeletonLoadingOverlay.js +189 -0
  62. package/node/components/base/GridOverlays.js +26 -40
  63. package/node/components/cell/GridSkeletonCell.js +60 -18
  64. package/node/components/containers/GridRoot.js +3 -15
  65. package/node/components/containers/GridRootStyles.js +11 -2
  66. package/node/components/panel/filterPanel/GridFilterInputMultipleValue.js +1 -1
  67. package/node/components/virtualization/GridMainContainer.js +10 -2
  68. package/node/components/virtualization/GridVirtualScroller.js +9 -5
  69. package/node/components/virtualization/GridVirtualScrollerFiller.js +9 -6
  70. package/node/constants/gridClasses.js +1 -1
  71. package/node/hooks/features/filter/gridFilterSelector.js +14 -1
  72. package/node/hooks/features/overlays/useGridOverlays.js +42 -0
  73. package/node/hooks/features/virtualization/useGridVirtualScroller.js +4 -12
  74. package/node/hooks/utils/index.js +0 -12
  75. package/node/index.js +1 -1
  76. package/node/locales/esES.js +1 -2
  77. package/node/utils/utils.js +11 -3
  78. package/package.json +5 -4
  79. package/utils/utils.d.ts +8 -1
  80. package/utils/utils.js +10 -2
  81. package/hooks/utils/useResizeObserver.d.ts +0 -2
  82. package/hooks/utils/useResizeObserver.js +0 -36
  83. package/modern/hooks/utils/useResizeObserver.js +0 -36
  84. package/node/hooks/utils/useResizeObserver.js +0 -44
@@ -4,11 +4,11 @@ import * as ReactDOM from 'react-dom';
4
4
  import { unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback } from '@mui/utils';
5
5
  import useLazyRef from '@mui/utils/useLazyRef';
6
6
  import useTimeout from '@mui/utils/useTimeout';
7
+ import { useResizeObserver } from '@mui/x-internals/useResizeObserver';
7
8
  import { useTheme } from '@mui/material/styles';
8
9
  import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
9
10
  import { useGridRootProps } from '../../utils/useGridRootProps';
10
11
  import { useGridSelector } from '../../utils/useGridSelector';
11
- import { useResizeObserver } from '../../utils/useResizeObserver';
12
12
  import { useRunOnce } from '../../utils/useRunOnce';
13
13
  import { gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector, gridColumnPositionsSelector, gridHasColSpanSelector } from '../columns/gridColumnsSelector';
14
14
  import { gridDimensionsSelector } from '../dimensions/gridDimensionsSelectors';
@@ -361,20 +361,12 @@ export const useGridVirtualScroller = () => {
361
361
  overflowY: rootProps.autoHeight ? 'hidden' : undefined
362
362
  }), [needsHorizontalScrollbar, rootProps.autoHeight]);
363
363
  const contentSize = React.useMemo(() => {
364
- // In cases where the columns exceed the available width,
365
- // the horizontal scrollbar should be shown even when there're no rows.
366
- // Keeping 1px as minimum height ensures that the scrollbar will visible if necessary.
367
- const height = Math.max(contentHeight, 1);
368
364
  const size = {
369
365
  width: needsHorizontalScrollbar ? columnsTotalWidth : 'auto',
370
- height
366
+ height: contentHeight
371
367
  };
372
- if (rootProps.autoHeight) {
373
- if (currentPage.rows.length === 0) {
374
- size.height = getMinimalContentHeight(apiRef); // Give room to show the overlay when there no rows.
375
- } else {
376
- size.height = contentHeight;
377
- }
368
+ if (rootProps.autoHeight && currentPage.rows.length === 0) {
369
+ size.height = getMinimalContentHeight(apiRef); // Give room to show the overlay when there no rows.
378
370
  }
379
371
  return size;
380
372
  }, [apiRef, columnsTotalWidth, contentHeight, needsHorizontalScrollbar, rootProps.autoHeight, currentPage.rows.length]);
@@ -5,5 +5,4 @@ export { useGridSelector } from './useGridSelector';
5
5
  export * from './useGridNativeEventListener';
6
6
  export * from './useFirstRender';
7
7
  export * from './useOnMount';
8
- export * from './useResizeObserver';
9
8
  export * from './useRunOnce';
@@ -5,5 +5,4 @@ export { useGridSelector } from './useGridSelector';
5
5
  export * from './useGridNativeEventListener';
6
6
  export * from './useFirstRender';
7
7
  export * from './useOnMount';
8
- export * from './useResizeObserver';
9
8
  export * from './useRunOnce';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.8.0
2
+ * @mui/x-data-grid v7.10.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
package/locales/esES.js CHANGED
@@ -33,8 +33,7 @@ const esESGrid = {
33
33
  columnsManagementSearchTitle: 'Buscar',
34
34
  columnsManagementNoColumns: 'Sin columnas',
35
35
  columnsManagementShowHideAllText: 'Mostrar/Ocultar todas',
36
- // columnsManagementReset: 'Reset',
37
-
36
+ columnsManagementReset: 'Restablecer',
38
37
  // Filter panel text
39
38
  filterPanelAddFilter: 'Agregar filtro',
40
39
  filterPanelRemoveAll: 'Remover todos',
@@ -30,9 +30,9 @@ export interface GridRowSelectionApi {
30
30
  /**
31
31
  * Updates the selected rows to be those passed to the `rowIds` argument.
32
32
  * Any row already selected will be unselected.
33
- * @param {GridRowId[]} rowIds The row ids to select.
33
+ * @param {readonly GridRowId[]} rowIds The row ids to select.
34
34
  */
35
- setRowSelectionModel: (rowIds: GridRowId[]) => void;
35
+ setRowSelectionModel: (rowIds: readonly GridRowId[]) => void;
36
36
  }
37
37
  export interface GridRowMultiSelectionApi {
38
38
  /**
@@ -79,7 +79,7 @@ export interface GridBaseColDef<R extends GridValidRowModel = GridValidRowModel,
79
79
  /**
80
80
  * The order of the sorting sequence.
81
81
  */
82
- sortingOrder?: GridSortDirection[];
82
+ sortingOrder?: readonly GridSortDirection[];
83
83
  /**
84
84
  * If `true`, the column is resizable.
85
85
  * @default true
@@ -207,7 +207,7 @@ export interface GridBaseColDef<R extends GridValidRowModel = GridValidRowModel,
207
207
  /**
208
208
  * Allows setting the filter operators for this column.
209
209
  */
210
- filterOperators?: GridFilterOperator<R, V, F>[];
210
+ filterOperators?: readonly GridFilterOperator<R, V, F>[];
211
211
  /**
212
212
  * The callback that generates a filtering function for a given quick filter value.
213
213
  * This function can return `null` to skip filtering for this value and column.
@@ -247,9 +247,9 @@ export interface GridActionsColDef<R extends GridValidRowModel = any, V = any, F
247
247
  /**
248
248
  * Function that returns the actions to be shown.
249
249
  * @param {GridRowParams} params The params for each row.
250
- * @returns {React.ReactElement<GridActionsCellItemProps>[]} An array of [[GridActionsCell]] elements.
250
+ * @returns {readonly React.ReactElement<GridActionsCellItemProps>[]} An array of [[GridActionsCell]] elements.
251
251
  */
252
- getActions: (params: GridRowParams<R>) => React.ReactElement<GridActionsCellItemProps>[];
252
+ getActions: (params: GridRowParams<R>) => readonly React.ReactElement<GridActionsCellItemProps>[];
253
253
  }
254
254
  /**
255
255
  * Column Definition interface used for columns with the `singleSelect` type.
@@ -1,3 +1,3 @@
1
1
  import { GridRowId } from './gridRows';
2
- export type GridInputRowSelectionModel = GridRowId[] | GridRowId;
3
- export type GridRowSelectionModel = GridRowId[];
2
+ export type GridInputRowSelectionModel = readonly GridRowId[] | GridRowId;
3
+ export type GridRowSelectionModel = readonly GridRowId[];
@@ -27,6 +27,7 @@ import type { GridColumnHeadersProps } from '../components/GridColumnHeaders';
27
27
  import type { GridDetailPanelsProps } from '../components/GridDetailPanels';
28
28
  import type { GridPinnedRowsProps } from '../components/GridPinnedRows';
29
29
  import type { GridColumnsManagementProps } from '../components/columnsManagement/GridColumnsManagement';
30
+ import type { GridLoadingOverlayProps } from '../components/GridLoadingOverlay';
30
31
  import type { GridRowCountProps } from '../components/GridRowCount';
31
32
  import type { GridColumnHeaderSortIconProps } from '../components/columnHeaders/GridColumnHeaderSortIcon';
32
33
  export interface BaseCheckboxPropsOverrides {
@@ -122,7 +123,7 @@ export interface GridSlotProps {
122
123
  filterPanel: GridFilterPanelProps & FilterPanelPropsOverrides;
123
124
  footer: GridFooterContainerProps & FooterPropsOverrides;
124
125
  footerRowCount: GridRowCountProps & FooterRowCountOverrides;
125
- loadingOverlay: GridOverlayProps & LoadingOverlayPropsOverrides;
126
+ loadingOverlay: GridLoadingOverlayProps & LoadingOverlayPropsOverrides;
126
127
  noResultsOverlay: GridOverlayProps & NoResultsOverlayPropsOverrides;
127
128
  noRowsOverlay: GridOverlayProps & NoRowsOverlayPropsOverrides;
128
129
  pagination: Partial<TablePaginationProps> & PaginationPropsOverrides;
@@ -234,6 +234,11 @@ export interface DataGridPropsWithDefaultValues<R extends GridValidRowModel = an
234
234
  * @default "error" ("warn" in dev mode)
235
235
  */
236
236
  logLevel: keyof Logger | false;
237
+ /**
238
+ * If `true`, a loading overlay is displayed.
239
+ * @default false
240
+ */
241
+ loading: boolean;
237
242
  /**
238
243
  * If `true`, pagination is enabled.
239
244
  * @default false
@@ -698,10 +703,6 @@ export interface DataGridPropsWithoutDefaultValue<R extends GridValidRowModel =
698
703
  * Return the id of a given [[GridRowModel]].
699
704
  */
700
705
  getRowId?: GridRowIdGetter<R>;
701
- /**
702
- * If `true`, a loading overlay is displayed.
703
- */
704
- loading?: boolean;
705
706
  /**
706
707
  * Nonce of the inline styles for [Content Security Policy](https://www.w3.org/TR/2016/REC-CSP2-20161215/#script-src-the-nonce-attribute).
707
708
  */
@@ -333,6 +333,7 @@ DataGridRaw.propTypes = {
333
333
  keepNonExistentRowsSelected: PropTypes.bool,
334
334
  /**
335
335
  * If `true`, a loading overlay is displayed.
336
+ * @default false
336
337
  */
337
338
  loading: PropTypes.bool,
338
339
  /**
@@ -23,54 +23,55 @@ const DATA_GRID_FORCED_PROPS = {
23
23
  export const DATA_GRID_PROPS_DEFAULT_VALUES = {
24
24
  autoHeight: false,
25
25
  autoPageSize: false,
26
+ autosizeOnMount: false,
26
27
  checkboxSelection: false,
27
28
  checkboxSelectionVisibleOnly: false,
29
+ clipboardCopyCellDelimiter: '\t',
28
30
  columnBufferPx: 150,
29
- rowBufferPx: 150,
30
- rows: [],
31
- rowSelection: true,
31
+ columnHeaderHeight: 56,
32
+ disableAutosize: false,
32
33
  disableColumnFilter: false,
33
34
  disableColumnMenu: false,
35
+ disableColumnReorder: false,
36
+ disableColumnResize: false,
34
37
  disableColumnSelector: false,
38
+ disableColumnSorting: false,
35
39
  disableDensitySelector: false,
36
40
  disableEval: false,
37
41
  disableMultipleColumnsFiltering: false,
38
- disableMultipleRowSelection: false,
39
- disableColumnSorting: false,
40
42
  disableMultipleColumnsSorting: false,
43
+ disableMultipleRowSelection: false,
41
44
  disableRowSelectionOnClick: false,
42
45
  disableVirtualization: false,
43
46
  editMode: GridEditModes.Cell,
44
- filterMode: 'client',
45
47
  filterDebounceMs: 150,
46
- columnHeaderHeight: 56,
48
+ filterMode: 'client',
47
49
  hideFooter: false,
48
50
  hideFooterPagination: false,
49
51
  hideFooterRowCount: false,
50
52
  hideFooterSelectedRowCount: false,
51
53
  ignoreDiacritics: false,
54
+ ignoreValueFormatterDuringExport: false,
55
+ keepColumnPositionIfDraggedOutside: false,
56
+ keepNonExistentRowsSelected: false,
57
+ loading: false,
52
58
  logger: console,
53
59
  logLevel: process.env.NODE_ENV === 'production' ? 'error' : 'warn',
60
+ pageSizeOptions: [25, 50, 100],
54
61
  pagination: false,
55
62
  paginationMode: 'client',
56
- rowHeight: 52,
57
63
  resizeThrottleMs: 60,
58
- pageSizeOptions: [25, 50, 100],
64
+ rowBufferPx: 150,
65
+ rowHeight: 52,
66
+ rowPositionsDebounceMs: 166,
67
+ rows: [],
68
+ rowSelection: true,
59
69
  rowSpacingType: 'margin',
60
70
  showCellVerticalBorder: false,
61
71
  showColumnVerticalBorder: false,
62
- sortingOrder: ['asc', 'desc', null],
63
72
  sortingMode: 'client',
64
- throttleRowsMs: 0,
65
- disableColumnReorder: false,
66
- disableColumnResize: false,
67
- keepNonExistentRowsSelected: false,
68
- keepColumnPositionIfDraggedOutside: false,
69
- ignoreValueFormatterDuringExport: false,
70
- clipboardCopyCellDelimiter: '\t',
71
- rowPositionsDebounceMs: 166,
72
- autosizeOnMount: false,
73
- disableAutosize: false
73
+ sortingOrder: ['asc', 'desc', null],
74
+ throttleRowsMs: 0
74
75
  };
75
76
  const defaultSlots = DATA_GRID_DEFAULT_SLOTS_COMPONENTS;
76
77
  export const useDataGridProps = inProps => {
@@ -85,8 +86,15 @@ export const useDataGridProps = inProps => {
85
86
  defaultSlots,
86
87
  slots: themedProps.slots
87
88
  }), [themedProps.slots]);
88
- return React.useMemo(() => _extends({}, DATA_GRID_PROPS_DEFAULT_VALUES, themedProps, {
89
+ const injectDefaultProps = React.useMemo(() => {
90
+ return Object.keys(DATA_GRID_PROPS_DEFAULT_VALUES).reduce((acc, key) => {
91
+ // @ts-ignore
92
+ acc[key] = themedProps[key] ?? DATA_GRID_PROPS_DEFAULT_VALUES[key];
93
+ return acc;
94
+ }, {});
95
+ }, [themedProps]);
96
+ return React.useMemo(() => _extends({}, themedProps, injectDefaultProps, {
89
97
  localeText,
90
98
  slots
91
- }, DATA_GRID_FORCED_PROPS), [themedProps, localeText, slots]);
99
+ }, DATA_GRID_FORCED_PROPS), [themedProps, localeText, slots, injectDefaultProps]);
92
100
  };
@@ -1,14 +1,48 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["variant", "noRowsVariant", "style"];
2
4
  import * as React from 'react';
3
5
  import PropTypes from 'prop-types';
6
+ import LinearProgress from '@mui/material/LinearProgress';
4
7
  import CircularProgress from '@mui/material/CircularProgress';
5
8
  import { GridOverlay } from './containers/GridOverlay';
9
+ import { GridSkeletonLoadingOverlay } from './GridSkeletonLoadingOverlay';
10
+ import { useGridApiContext } from '../hooks/utils/useGridApiContext';
11
+ import { gridRowCountSelector, useGridSelector } from '../hooks';
6
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ const LOADING_VARIANTS = {
14
+ 'circular-progress': {
15
+ component: CircularProgress,
16
+ style: {}
17
+ },
18
+ 'linear-progress': {
19
+ component: LinearProgress,
20
+ style: {
21
+ display: 'block'
22
+ }
23
+ },
24
+ skeleton: {
25
+ component: GridSkeletonLoadingOverlay,
26
+ style: {
27
+ display: 'block'
28
+ }
29
+ }
30
+ };
7
31
  const GridLoadingOverlay = /*#__PURE__*/React.forwardRef(function GridLoadingOverlay(props, ref) {
32
+ const {
33
+ variant = 'circular-progress',
34
+ noRowsVariant = 'circular-progress',
35
+ style
36
+ } = props,
37
+ other = _objectWithoutPropertiesLoose(props, _excluded);
38
+ const apiRef = useGridApiContext();
39
+ const rowsCount = useGridSelector(apiRef, gridRowCountSelector);
40
+ const activeVariant = LOADING_VARIANTS[rowsCount === 0 ? noRowsVariant : variant];
8
41
  return /*#__PURE__*/_jsx(GridOverlay, _extends({
9
- ref: ref
10
- }, props, {
11
- children: /*#__PURE__*/_jsx(CircularProgress, {})
42
+ ref: ref,
43
+ style: _extends({}, activeVariant.style, style)
44
+ }, other, {
45
+ children: /*#__PURE__*/_jsx(activeVariant.component, {})
12
46
  }));
13
47
  });
14
48
  process.env.NODE_ENV !== "production" ? GridLoadingOverlay.propTypes = {
@@ -16,6 +50,16 @@ process.env.NODE_ENV !== "production" ? GridLoadingOverlay.propTypes = {
16
50
  // | These PropTypes are generated from the TypeScript type definitions |
17
51
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
18
52
  // ----------------------------------------------------------------------
19
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
53
+ /**
54
+ * The variant of the overlay when no rows are displayed.
55
+ * @default 'circular-progress'
56
+ */
57
+ noRowsVariant: PropTypes.oneOf(['circular-progress', 'linear-progress', 'skeleton']),
58
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
59
+ /**
60
+ * The variant of the overlay.
61
+ * @default 'circular-progress'
62
+ */
63
+ variant: PropTypes.oneOf(['circular-progress', 'linear-progress', 'skeleton'])
20
64
  } : void 0;
21
65
  export { GridLoadingOverlay };
@@ -249,10 +249,11 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
249
249
  const pinnedOffset = getPinnedCellOffset(gridPinnedColumnPositionLookup[pinnedPosition], column.computedWidth, indexRelativeToAllColumns, columnPositions, dimensions);
250
250
  if (rowNode?.type === 'skeletonRow') {
251
251
  return /*#__PURE__*/_jsx(slots.skeletonCell, {
252
+ type: column.type,
252
253
  width: width,
253
254
  height: rowHeight,
254
255
  field: column.field,
255
- align: column.align ?? 'left'
256
+ align: column.align
256
257
  }, column.field);
257
258
  }
258
259
  const editCellState = editRowsState[rowId]?.[column.field] ?? null;
@@ -0,0 +1,181 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import clsx from 'clsx';
4
+ import { styled } from '@mui/system';
5
+ import useForkRef from '@mui/utils/useForkRef';
6
+ import composeClasses from '@mui/utils/composeClasses';
7
+ import { useGridApiContext } from '../hooks/utils/useGridApiContext';
8
+ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
9
+ import { GridPinnedColumnPosition, gridColumnPositionsSelector, gridColumnsTotalWidthSelector, gridDimensionsSelector, gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector, useGridApiEventHandler, useGridSelector } from '../hooks';
10
+ import { getDataGridUtilityClass, gridClasses } from '../constants/gridClasses';
11
+ import { getPinnedCellOffset } from '../internals/utils/getPinnedCellOffset';
12
+ import { shouldCellShowLeftBorder, shouldCellShowRightBorder } from '../utils/cellBorderUtils';
13
+ import { escapeOperandAttributeSelector } from '../utils/domUtils';
14
+ import { GridScrollbarFillerCell } from './GridScrollbarFillerCell';
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ const SkeletonOverlay = styled('div', {
17
+ name: 'MuiDataGrid',
18
+ slot: 'SkeletonLoadingOverlay',
19
+ overridesResolver: (props, styles) => styles.skeletonLoadingOverlay
20
+ })({
21
+ minWidth: '100%',
22
+ width: 'max-content',
23
+ // prevents overflow: clip; cutting off the x axis
24
+ height: '100%',
25
+ overflow: 'clip' // y axis is hidden while the x axis is allowed to overflow
26
+ });
27
+ const useUtilityClasses = ownerState => {
28
+ const {
29
+ classes
30
+ } = ownerState;
31
+ const slots = {
32
+ root: ['skeletonLoadingOverlay']
33
+ };
34
+ return composeClasses(slots, getDataGridUtilityClass, classes);
35
+ };
36
+ const getColIndex = el => parseInt(el.getAttribute('data-colindex'), 10);
37
+ const GridSkeletonLoadingOverlay = /*#__PURE__*/React.forwardRef(function GridSkeletonLoadingOverlay(props, forwardedRef) {
38
+ const rootProps = useGridRootProps();
39
+ const {
40
+ slots
41
+ } = rootProps;
42
+ const classes = useUtilityClasses({
43
+ classes: rootProps.classes
44
+ });
45
+ const ref = React.useRef(null);
46
+ const handleRef = useForkRef(ref, forwardedRef);
47
+ const apiRef = useGridApiContext();
48
+ const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
49
+ const viewportHeight = dimensions?.viewportInnerSize.height ?? 0;
50
+ const skeletonRowsCount = Math.ceil(viewportHeight / dimensions.rowHeight);
51
+ const totalWidth = useGridSelector(apiRef, gridColumnsTotalWidthSelector);
52
+ const positions = useGridSelector(apiRef, gridColumnPositionsSelector);
53
+ const inViewportCount = React.useMemo(() => positions.filter(value => value <= totalWidth).length, [totalWidth, positions]);
54
+ const allVisibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
55
+ const columns = React.useMemo(() => allVisibleColumns.slice(0, inViewportCount), [allVisibleColumns, inViewportCount]);
56
+ const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
57
+ const getPinnedStyle = React.useCallback((computedWidth, index, position) => {
58
+ const pinnedOffset = getPinnedCellOffset(position, computedWidth, index, positions, dimensions);
59
+ return {
60
+ [position]: pinnedOffset
61
+ };
62
+ }, [dimensions, positions]);
63
+ const getPinnedPosition = React.useCallback(field => {
64
+ if (pinnedColumns.left.findIndex(col => col.field === field) !== -1) {
65
+ return GridPinnedColumnPosition.LEFT;
66
+ }
67
+ if (pinnedColumns.right.findIndex(col => col.field === field) !== -1) {
68
+ return GridPinnedColumnPosition.RIGHT;
69
+ }
70
+ return undefined;
71
+ }, [pinnedColumns.left, pinnedColumns.right]);
72
+ const children = React.useMemo(() => {
73
+ const array = [];
74
+ for (let i = 0; i < skeletonRowsCount; i += 1) {
75
+ const rowCells = [];
76
+ for (let colIndex = 0; colIndex < columns.length; colIndex += 1) {
77
+ const column = columns[colIndex];
78
+ const pinnedPosition = getPinnedPosition(column.field);
79
+ const isPinnedLeft = pinnedPosition === GridPinnedColumnPosition.LEFT;
80
+ const isPinnedRight = pinnedPosition === GridPinnedColumnPosition.RIGHT;
81
+ const sectionLength = pinnedPosition ? pinnedColumns[pinnedPosition].length // pinned section
82
+ : columns.length - pinnedColumns.left.length - pinnedColumns.right.length; // middle section
83
+ const sectionIndex = pinnedPosition ? pinnedColumns[pinnedPosition].findIndex(col => col.field === column.field) // pinned section
84
+ : colIndex - pinnedColumns.left.length; // middle section
85
+ const pinnedStyle = pinnedPosition && getPinnedStyle(column.computedWidth, colIndex, pinnedPosition);
86
+ const gridHasFiller = dimensions.columnsTotalWidth < dimensions.viewportOuterSize.width;
87
+ const showRightBorder = shouldCellShowRightBorder(pinnedPosition, sectionIndex, sectionLength, rootProps.showCellVerticalBorder, gridHasFiller);
88
+ const showLeftBorder = shouldCellShowLeftBorder(pinnedPosition, sectionIndex);
89
+ const isLastColumn = colIndex === columns.length - 1;
90
+ const isFirstPinnedRight = isPinnedRight && sectionIndex === 0;
91
+ const hasFillerBefore = isFirstPinnedRight && gridHasFiller;
92
+ const hasFillerAfter = isLastColumn && !isFirstPinnedRight && gridHasFiller;
93
+ const expandedWidth = dimensions.viewportOuterSize.width - dimensions.columnsTotalWidth;
94
+ const emptyCellWidth = Math.max(0, expandedWidth);
95
+ const emptyCell = /*#__PURE__*/_jsx(slots.skeletonCell, {
96
+ width: emptyCellWidth,
97
+ empty: true
98
+ }, `skeleton-filler-column-${i}`);
99
+ const scrollbarWidth = dimensions.hasScrollY ? dimensions.scrollbarSize : 0;
100
+ const hasScrollbarFiller = isLastColumn && scrollbarWidth !== 0;
101
+ if (hasFillerBefore) {
102
+ rowCells.push(emptyCell);
103
+ }
104
+ rowCells.push( /*#__PURE__*/_jsx(slots.skeletonCell, {
105
+ field: column.field,
106
+ type: column.type,
107
+ align: column.align,
108
+ width: "var(--width)",
109
+ height: dimensions.rowHeight,
110
+ "data-colindex": colIndex,
111
+ className: clsx(isPinnedLeft && gridClasses['cell--pinnedLeft'], isPinnedRight && gridClasses['cell--pinnedRight'], showRightBorder && gridClasses['cell--withRightBorder'], showLeftBorder && gridClasses['cell--withLeftBorder']),
112
+ style: _extends({
113
+ '--width': `${column.computedWidth}px`
114
+ }, pinnedStyle)
115
+ }, `skeleton-column-${i}-${column.field}`));
116
+ if (hasFillerAfter) {
117
+ rowCells.push(emptyCell);
118
+ }
119
+ if (hasScrollbarFiller) {
120
+ rowCells.push( /*#__PURE__*/_jsx(GridScrollbarFillerCell, {
121
+ pinnedRight: pinnedColumns.right.length > 0
122
+ }));
123
+ }
124
+ }
125
+ array.push( /*#__PURE__*/_jsx("div", {
126
+ className: clsx(gridClasses.row, gridClasses.rowSkeleton, i === 0 && gridClasses['row--firstVisible']),
127
+ children: rowCells
128
+ }, `skeleton-row-${i}`));
129
+ }
130
+ return array;
131
+ }, [slots, columns, pinnedColumns, skeletonRowsCount, rootProps.showCellVerticalBorder, dimensions.columnsTotalWidth, dimensions.viewportOuterSize.width, dimensions.rowHeight, dimensions.hasScrollY, dimensions.scrollbarSize, getPinnedPosition, getPinnedStyle]);
132
+
133
+ // Sync the column resize of the overlay columns with the grid
134
+ const handleColumnResize = params => {
135
+ const {
136
+ colDef,
137
+ width
138
+ } = params;
139
+ const cells = ref.current?.querySelectorAll(`[data-field="${escapeOperandAttributeSelector(colDef.field)}"]`);
140
+ if (!cells) {
141
+ throw new Error('MUI X: Expected skeleton cells to be defined with `data-field` attribute.');
142
+ }
143
+ const resizedColIndex = columns.findIndex(col => col.field === colDef.field);
144
+ const pinnedPosition = getPinnedPosition(colDef.field);
145
+ const isPinnedLeft = pinnedPosition === GridPinnedColumnPosition.LEFT;
146
+ const isPinnedRight = pinnedPosition === GridPinnedColumnPosition.RIGHT;
147
+ const currentWidth = getComputedStyle(cells[0]).getPropertyValue('--width');
148
+ const delta = parseInt(currentWidth, 10) - width;
149
+ if (cells) {
150
+ cells.forEach(element => {
151
+ element.style.setProperty('--width', `${width}px`);
152
+ });
153
+ }
154
+ if (isPinnedLeft) {
155
+ const pinnedCells = ref.current?.querySelectorAll(`.${gridClasses['cell--pinnedLeft']}`);
156
+ pinnedCells?.forEach(element => {
157
+ const colIndex = getColIndex(element);
158
+ if (colIndex > resizedColIndex) {
159
+ element.style.left = `${parseInt(getComputedStyle(element).left, 10) - delta}px`;
160
+ }
161
+ });
162
+ }
163
+ if (isPinnedRight) {
164
+ const pinnedCells = ref.current?.querySelectorAll(`.${gridClasses['cell--pinnedRight']}`);
165
+ pinnedCells?.forEach(element => {
166
+ const colIndex = getColIndex(element);
167
+ if (colIndex < resizedColIndex) {
168
+ element.style.right = `${parseInt(getComputedStyle(element).right, 10) + delta}px`;
169
+ }
170
+ });
171
+ }
172
+ };
173
+ useGridApiEventHandler(apiRef, 'columnResize', handleColumnResize);
174
+ return /*#__PURE__*/_jsx(SkeletonOverlay, _extends({
175
+ className: classes.root,
176
+ ref: handleRef
177
+ }, props, {
178
+ children: children
179
+ }));
180
+ });
181
+ export { GridSkeletonLoadingOverlay };
@@ -5,8 +5,6 @@ import { styled } from '@mui/system';
5
5
  import { unstable_composeClasses as composeClasses } from '@mui/utils';
6
6
  import clsx from 'clsx';
7
7
  import { useGridSelector } from '../../hooks/utils/useGridSelector';
8
- import { gridExpandedRowCountSelector } from '../../hooks/features/filter/gridFilterSelector';
9
- import { gridRowCountSelector, gridRowsLoadingSelector } from '../../hooks/features/rows/gridRowsSelector';
10
8
  import { gridDimensionsSelector } from '../../hooks/features/dimensions';
11
9
  import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
12
10
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
@@ -17,11 +15,14 @@ import { jsx as _jsx } from "react/jsx-runtime";
17
15
  const GridOverlayWrapperRoot = styled('div', {
18
16
  name: 'MuiDataGrid',
19
17
  slot: 'OverlayWrapper',
20
- shouldForwardProp: prop => prop !== 'overlayType',
18
+ shouldForwardProp: prop => prop !== 'overlayType' && prop !== 'loadingOverlayVariant',
21
19
  overridesResolver: (props, styles) => styles.overlayWrapper
22
20
  })(({
23
- overlayType
24
- }) => ({
21
+ overlayType,
22
+ loadingOverlayVariant
23
+ }) =>
24
+ // Skeleton overlay should flow with the scroll container and not be sticky
25
+ loadingOverlayVariant !== 'skeleton' ? {
25
26
  position: 'sticky',
26
27
  // To stay in place while scrolling
27
28
  top: 'var(--DataGrid-headersTotalHeight)',
@@ -32,11 +33,11 @@ const GridOverlayWrapperRoot = styled('div', {
32
33
  // To stay above the content instead of shifting it down
33
34
  zIndex: overlayType === 'loadingOverlay' ? 5 // Should be above pinned columns, pinned rows, and detail panel
34
35
  : 4 // Should be above pinned columns and detail panel
35
- }));
36
+ } : {});
36
37
  const GridOverlayWrapperInner = styled('div', {
37
38
  name: 'MuiDataGrid',
38
39
  slot: 'OverlayWrapperInner',
39
- shouldForwardProp: prop => prop !== 'overlayType',
40
+ shouldForwardProp: prop => prop !== 'overlayType' && prop !== 'loadingOverlayVariant',
40
41
  overridesResolver: (props, styles) => styles.overlayWrapperInner
41
42
  })({});
42
43
  const useUtilityClasses = ownerState => {
@@ -54,16 +55,16 @@ function GridOverlayWrapper(props) {
54
55
  const rootProps = useGridRootProps();
55
56
  const currentPage = useGridVisibleRows(apiRef, rootProps);
56
57
  const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
57
- let height = dimensions.viewportOuterSize.height - dimensions.headersTotalHeight - (dimensions.hasScrollX ? dimensions.scrollbarSize : 0);
58
+ let height = dimensions.viewportOuterSize.height - dimensions.topContainerHeight - dimensions.bottomContainerHeight - (dimensions.hasScrollX ? dimensions.scrollbarSize : 0);
58
59
  if (rootProps.autoHeight && currentPage.rows.length === 0 || height === 0) {
59
60
  height = getMinimalContentHeight(apiRef);
60
61
  }
61
62
  const classes = useUtilityClasses(_extends({}, props, {
62
63
  classes: rootProps.classes
63
64
  }));
64
- return /*#__PURE__*/_jsx(GridOverlayWrapperRoot, {
65
- className: clsx(classes.root),
66
- overlayType: props.overlayType,
65
+ return /*#__PURE__*/_jsx(GridOverlayWrapperRoot, _extends({
66
+ className: clsx(classes.root)
67
+ }, props, {
67
68
  children: /*#__PURE__*/_jsx(GridOverlayWrapperInner, _extends({
68
69
  className: clsx(classes.inner),
69
70
  style: {
@@ -71,42 +72,27 @@ function GridOverlayWrapper(props) {
71
72
  width: dimensions.viewportOuterSize.width
72
73
  }
73
74
  }, props))
74
- });
75
+ }));
75
76
  }
76
- process.env.NODE_ENV !== "production" ? GridOverlayWrapper.propTypes = {
77
+ process.env.NODE_ENV !== "production" ? GridOverlays.propTypes = {
77
78
  // ----------------------------- Warning --------------------------------
78
79
  // | These PropTypes are generated from the TypeScript type definitions |
79
80
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
80
81
  // ----------------------------------------------------------------------
81
- overlayType: PropTypes.string.isRequired
82
+ loadingOverlayVariant: PropTypes.oneOf(['circular-progress', 'linear-progress', 'skeleton']),
83
+ overlayType: PropTypes.oneOf(['loadingOverlay', 'noResultsOverlay', 'noRowsOverlay'])
82
84
  } : void 0;
83
- export function GridOverlays() {
84
- const apiRef = useGridApiContext();
85
+ export function GridOverlays(props) {
86
+ const {
87
+ overlayType
88
+ } = props;
85
89
  const rootProps = useGridRootProps();
86
- const totalRowCount = useGridSelector(apiRef, gridRowCountSelector);
87
- const visibleRowCount = useGridSelector(apiRef, gridExpandedRowCountSelector);
88
- const loading = useGridSelector(apiRef, gridRowsLoadingSelector);
89
- const showNoRowsOverlay = !loading && totalRowCount === 0;
90
- const showNoResultsOverlay = !loading && totalRowCount > 0 && visibleRowCount === 0;
91
- let overlay = null;
92
- let overlayType = '';
93
- if (showNoRowsOverlay) {
94
- overlay = /*#__PURE__*/_jsx(rootProps.slots.noRowsOverlay, _extends({}, rootProps.slotProps?.noRowsOverlay));
95
- overlayType = 'noRowsOverlay';
96
- }
97
- if (showNoResultsOverlay) {
98
- overlay = /*#__PURE__*/_jsx(rootProps.slots.noResultsOverlay, _extends({}, rootProps.slotProps?.noResultsOverlay));
99
- overlayType = 'noResultsOverlay';
100
- }
101
- if (loading) {
102
- overlay = /*#__PURE__*/_jsx(rootProps.slots.loadingOverlay, _extends({}, rootProps.slotProps?.loadingOverlay));
103
- overlayType = 'loadingOverlay';
104
- }
105
- if (overlay === null) {
90
+ if (!overlayType) {
106
91
  return null;
107
92
  }
108
- return /*#__PURE__*/_jsx(GridOverlayWrapper, {
109
- overlayType: overlayType,
110
- children: overlay
111
- });
93
+ const Overlay = rootProps.slots?.[overlayType];
94
+ const overlayProps = rootProps.slotProps?.[overlayType];
95
+ return /*#__PURE__*/_jsx(GridOverlayWrapper, _extends({}, props, {
96
+ children: /*#__PURE__*/_jsx(Overlay, _extends({}, overlayProps))
97
+ }));
112
98
  }