@mui/x-data-grid 6.2.0 → 6.2.1

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 (81) hide show
  1. package/CHANGELOG.md +49 -1
  2. package/components/GridHeader.d.ts +2 -2
  3. package/components/GridHeader.js +4 -6
  4. package/components/base/GridBody.d.ts +0 -1
  5. package/components/base/GridBody.js +32 -15
  6. package/components/columnSelection/GridCellCheckboxRenderer.d.ts +1 -1
  7. package/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
  8. package/components/columnSelection/GridHeaderCheckbox.d.ts +1 -1
  9. package/components/containers/GridMainContainer.d.ts +3 -1
  10. package/components/containers/GridMainContainer.js +3 -2
  11. package/components/containers/GridRoot.js +0 -5
  12. package/components/index.d.ts +0 -1
  13. package/components/index.js +0 -1
  14. package/components/panel/GridColumnsPanel.js +3 -2
  15. package/components/panel/GridPanel.d.ts +2 -2
  16. package/components/panel/GridPanel.js +2 -1
  17. package/components/panel/filterPanel/GridFilterPanel.js +5 -2
  18. package/hooks/features/dimensions/gridDimensionsApi.d.ts +4 -0
  19. package/hooks/features/dimensions/useGridDimensions.js +49 -10
  20. package/hooks/features/export/useGridPrintExport.js +3 -1
  21. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -0
  22. package/hooks/features/virtualization/useGridVirtualScroller.js +11 -5
  23. package/index.js +1 -1
  24. package/joy/index.d.ts +2 -0
  25. package/joy/index.js +2 -0
  26. package/joy/joySlots.d.ts +4 -0
  27. package/joy/joySlots.js +71 -0
  28. package/joy/package.json +6 -0
  29. package/legacy/components/GridHeader.js +4 -6
  30. package/legacy/components/base/GridBody.js +33 -16
  31. package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
  32. package/legacy/components/containers/GridMainContainer.js +3 -2
  33. package/legacy/components/containers/GridRoot.js +0 -5
  34. package/legacy/components/index.js +0 -1
  35. package/legacy/components/panel/GridColumnsPanel.js +3 -2
  36. package/legacy/components/panel/GridPanel.js +2 -1
  37. package/legacy/components/panel/filterPanel/GridFilterPanel.js +5 -2
  38. package/legacy/hooks/features/dimensions/useGridDimensions.js +55 -12
  39. package/legacy/hooks/features/export/useGridPrintExport.js +3 -1
  40. package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +12 -6
  41. package/legacy/index.js +1 -1
  42. package/legacy/joy/index.js +2 -0
  43. package/legacy/joy/joySlots.js +73 -0
  44. package/material/index.d.ts +1 -1
  45. package/models/gridSlotsComponent.d.ts +2 -2
  46. package/modern/components/GridHeader.js +4 -6
  47. package/modern/components/base/GridBody.js +32 -15
  48. package/modern/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
  49. package/modern/components/containers/GridMainContainer.js +3 -2
  50. package/modern/components/containers/GridRoot.js +0 -5
  51. package/modern/components/index.js +0 -1
  52. package/modern/components/panel/GridColumnsPanel.js +3 -2
  53. package/modern/components/panel/GridPanel.js +2 -1
  54. package/modern/components/panel/filterPanel/GridFilterPanel.js +5 -2
  55. package/modern/hooks/features/dimensions/useGridDimensions.js +48 -10
  56. package/modern/hooks/features/export/useGridPrintExport.js +3 -1
  57. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +11 -5
  58. package/modern/index.js +1 -1
  59. package/modern/joy/index.js +2 -0
  60. package/modern/joy/joySlots.js +71 -0
  61. package/node/components/GridHeader.js +5 -8
  62. package/node/components/base/GridBody.js +32 -15
  63. package/node/components/columnSelection/GridCellCheckboxRenderer.js +1 -1
  64. package/node/components/containers/GridMainContainer.js +5 -3
  65. package/node/components/containers/GridRoot.js +0 -5
  66. package/node/components/index.js +0 -11
  67. package/node/components/panel/GridColumnsPanel.js +3 -2
  68. package/node/components/panel/GridPanel.js +2 -1
  69. package/node/components/panel/filterPanel/GridFilterPanel.js +5 -2
  70. package/node/hooks/features/dimensions/useGridDimensions.js +47 -9
  71. package/node/hooks/features/export/useGridPrintExport.js +3 -1
  72. package/node/hooks/features/virtualization/useGridVirtualScroller.js +11 -5
  73. package/node/index.js +1 -1
  74. package/node/joy/index.js +13 -0
  75. package/node/joy/joySlots.js +79 -0
  76. package/package.json +1 -1
  77. package/components/GridAutoSizer.d.ts +0 -44
  78. package/components/GridAutoSizer.js +0 -126
  79. package/legacy/components/GridAutoSizer.js +0 -132
  80. package/modern/components/GridAutoSizer.js +0 -125
  81. package/node/components/GridAutoSizer.js +0 -132
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/joy/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -3,12 +3,10 @@ import * as React from 'react';
3
3
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
5
  import { jsxs as _jsxs } from "react/jsx-runtime";
6
- export var GridHeader = /*#__PURE__*/React.forwardRef(function GridHeader(props, ref) {
6
+ export function GridHeader() {
7
7
  var _rootProps$slotProps, _rootProps$slotProps2;
8
8
  var rootProps = useGridRootProps();
9
- return /*#__PURE__*/_jsxs("div", _extends({
10
- ref: ref
11
- }, props, {
9
+ return /*#__PURE__*/_jsxs(React.Fragment, {
12
10
  children: [/*#__PURE__*/_jsx(rootProps.slots.preferencesPanel, _extends({}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.preferencesPanel)), rootProps.slots.toolbar && /*#__PURE__*/_jsx(rootProps.slots.toolbar, _extends({}, (_rootProps$slotProps2 = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps2.toolbar))]
13
- }));
14
- });
11
+ });
12
+ }
@@ -2,10 +2,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import * as React from 'react';
4
4
  import PropTypes from 'prop-types';
5
+ import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
5
6
  import { useGridPrivateApiContext } from '../../hooks/utils/useGridPrivateApiContext';
6
7
  import { useGridSelector } from '../../hooks/utils/useGridSelector';
7
8
  import { GridMainContainer } from '../containers/GridMainContainer';
8
- import { GridAutoSizer } from '../GridAutoSizer';
9
9
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
10
10
  import { gridColumnPositionsSelector, gridColumnVisibilityModelSelector, gridVisibleColumnDefinitionsSelector } from '../../hooks/features/columns/gridColumnsSelector';
11
11
  import { gridFilterActiveItemsLookupSelector } from '../../hooks/features/filter/gridFilterSelector';
@@ -17,11 +17,11 @@ import { gridColumnMenuSelector } from '../../hooks/features/columnMenu/columnMe
17
17
  import { jsx as _jsx } from "react/jsx-runtime";
18
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
19
  function GridBody(props) {
20
- var children = props.children,
21
- VirtualScrollerComponent = props.VirtualScrollerComponent,
20
+ var VirtualScrollerComponent = props.VirtualScrollerComponent,
22
21
  ColumnHeadersProps = props.ColumnHeadersProps;
23
22
  var apiRef = useGridPrivateApiContext();
24
23
  var rootProps = useGridRootProps();
24
+ var rootRef = React.useRef(null);
25
25
  var visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
26
26
  var filterColumnLookup = useGridSelector(apiRef, gridFilterActiveItemsLookupSelector);
27
27
  var sortColumnLookup = useGridSelector(apiRef, gridSortColumnLookupSelector);
@@ -41,6 +41,24 @@ function GridBody(props) {
41
41
  _React$useState2 = _slicedToArray(_React$useState, 2),
42
42
  isVirtualizationDisabled = _React$useState2[0],
43
43
  setIsVirtualizationDisabled = _React$useState2[1];
44
+ useEnhancedEffect(function () {
45
+ apiRef.current.computeSizeAndPublishResizeEvent();
46
+ var elementToObserve = rootRef.current;
47
+ if (typeof ResizeObserver === 'undefined') {
48
+ return function () {};
49
+ }
50
+ var observer = new ResizeObserver(function () {
51
+ apiRef.current.computeSizeAndPublishResizeEvent();
52
+ });
53
+ if (elementToObserve) {
54
+ observer.observe(elementToObserve);
55
+ }
56
+ return function () {
57
+ if (elementToObserve) {
58
+ observer.unobserve(elementToObserve);
59
+ }
60
+ };
61
+ }, [apiRef]);
44
62
  var disableVirtualization = React.useCallback(function () {
45
63
  setIsVirtualizationDisabled(true);
46
64
  }, []);
@@ -67,10 +85,9 @@ function GridBody(props) {
67
85
  columnHeadersElementRef: columnHeadersRef,
68
86
  virtualScrollerRef: virtualScrollerRef
69
87
  });
70
- var handleResize = React.useCallback(function (size) {
71
- apiRef.current.publishEvent('resize', size);
72
- }, [apiRef]);
88
+ var hasDimensions = !!apiRef.current.getRootDimensions();
73
89
  return /*#__PURE__*/_jsxs(GridMainContainer, {
90
+ ref: rootRef,
74
91
  children: [/*#__PURE__*/_jsx(rootProps.slots.columnHeaders, _extends({
75
92
  ref: columnsContainerRef,
76
93
  innerRef: columnHeadersRef,
@@ -88,15 +105,16 @@ function GridBody(props) {
88
105
  columnVisibility: columnVisibility,
89
106
  columnGroupsHeaderStructure: columnGroupsHeaderStructure,
90
107
  hasOtherElementInTabSequence: hasOtherElementInTabSequence
91
- }, ColumnHeadersProps)), /*#__PURE__*/_jsx(GridAutoSizer, {
92
- nonce: rootProps.nonce,
93
- disableHeight: rootProps.autoHeight,
94
- onResize: handleResize,
95
- children: /*#__PURE__*/_jsx(VirtualScrollerComponent, {
96
- ref: virtualScrollerRef,
97
- disableVirtualization: isVirtualizationDisabled
98
- })
99
- }), children]
108
+ }, ColumnHeadersProps)), hasDimensions && /*#__PURE__*/_jsx(VirtualScrollerComponent
109
+ // The content is only rendered after dimensions are computed because
110
+ // the lazy-loading hook is listening to `renderedRowsIntervalChange`,
111
+ // but only does something if the dimensions are also available.
112
+ // If this event is published while dimensions haven't been computed,
113
+ // the `onFetchRows` prop won't be called during mount.
114
+ , {
115
+ ref: virtualScrollerRef,
116
+ disableVirtualization: isVirtualizationDisabled
117
+ })]
100
118
  });
101
119
  }
102
120
  process.env.NODE_ENV !== "production" ? GridBody.propTypes = {
@@ -104,7 +122,6 @@ process.env.NODE_ENV !== "production" ? GridBody.propTypes = {
104
122
  // | These PropTypes are generated from the TypeScript type definitions |
105
123
  // | To update them edit the TypeScript types and run "yarn proptypes" |
106
124
  // ----------------------------------------------------------------------
107
- children: PropTypes.node,
108
125
  ColumnHeadersProps: PropTypes.object,
109
126
  VirtualScrollerComponent: PropTypes.elementType.isRequired
110
127
  } : void 0;
@@ -38,7 +38,7 @@ var GridCellCheckboxForwardRef = /*#__PURE__*/React.forwardRef(function GridCell
38
38
  };
39
39
  var classes = useUtilityClasses(ownerState);
40
40
  var checkboxElement = React.useRef(null);
41
- var rippleRef = React.useRef();
41
+ var rippleRef = React.useRef(null);
42
42
  var handleRef = useForkRef(checkboxElement, ref);
43
43
  var element = apiRef.current.getCellElement(id, field);
44
44
  var handleChange = function handleChange(event) {
@@ -26,12 +26,13 @@ var GridMainContainerRoot = styled('div', {
26
26
  overflow: 'hidden'
27
27
  };
28
28
  });
29
- export function GridMainContainer(props) {
29
+ export var GridMainContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
30
30
  var rootProps = useGridRootProps();
31
31
  var classes = useUtilityClasses(rootProps);
32
32
  return /*#__PURE__*/_jsx(GridMainContainerRoot, {
33
+ ref: ref,
33
34
  className: classes.root,
34
35
  ownerState: rootProps,
35
36
  children: props.children
36
37
  });
37
- }
38
+ });
@@ -54,11 +54,6 @@ var GridRoot = /*#__PURE__*/React.forwardRef(function GridRoot(props, ref) {
54
54
  useEnhancedEffect(function () {
55
55
  setMountedState(true);
56
56
  }, []);
57
- useEnhancedEffect(function () {
58
- if (mountedState) {
59
- apiRef.current.updateGridDimensionsRef();
60
- }
61
- }, [apiRef, mountedState]);
62
57
  if (!mountedState) {
63
58
  return null;
64
59
  }
@@ -8,7 +8,6 @@ export * from './menu';
8
8
  export * from './panel';
9
9
  export * from './toolbar';
10
10
  export * from './GridApiContext';
11
- export * from './GridAutoSizer';
12
11
  export * from './GridFooter';
13
12
  export * from './GridHeader';
14
13
  export * from './GridLoadingOverlay';
@@ -108,8 +108,9 @@ function GridColumnsPanel(props) {
108
108
  var toggleAllColumns = React.useCallback(function (isVisible) {
109
109
  var currentModel = gridColumnVisibilityModelSelector(apiRef);
110
110
  var newModel = _extends({}, currentModel);
111
+ var togglableColumns = getTogglableColumns ? getTogglableColumns(columns) : null;
111
112
  columns.forEach(function (col) {
112
- if (col.hideable) {
113
+ if (col.hideable && (togglableColumns == null || togglableColumns.includes(col.field))) {
113
114
  if (isVisible) {
114
115
  // delete the key from the model instead of setting it to `true`
115
116
  delete newModel[col.field];
@@ -119,7 +120,7 @@ function GridColumnsPanel(props) {
119
120
  }
120
121
  });
121
122
  return apiRef.current.setColumnVisibilityModel(newModel);
122
- }, [apiRef, columns]);
123
+ }, [apiRef, columns, getTogglableColumns]);
123
124
  var handleSearchValueChange = React.useCallback(function (event) {
124
125
  setSearchValue(event.target.value);
125
126
  }, []);
@@ -132,6 +132,7 @@ process.env.NODE_ENV !== "production" ? GridPanel.propTypes = {
132
132
  /**
133
133
  * If `true`, the component is shown.
134
134
  */
135
- open: PropTypes.bool.isRequired
135
+ open: PropTypes.bool.isRequired,
136
+ ownerState: PropTypes.object
136
137
  } : void 0;
137
138
  export { GridPanel };
@@ -30,6 +30,7 @@ var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(pro
30
30
  var filterModel = useGridSelector(apiRef, gridFilterModelSelector);
31
31
  var filterableColumns = useGridSelector(apiRef, gridFilterableColumnDefinitionsSelector);
32
32
  var lastFilterRef = React.useRef(null);
33
+ var placeholderFilter = React.useRef(null);
33
34
  var _props$logicOperators = props.logicOperators,
34
35
  logicOperators = _props$logicOperators === void 0 ? [GridLogicOperator.And, GridLogicOperator.Or] : _props$logicOperators,
35
36
  columnsSort = props.columnsSort,
@@ -100,8 +101,10 @@ var GridFilterPanel = /*#__PURE__*/React.forwardRef(function GridFilterPanel(pro
100
101
  if (filterModel.items.length) {
101
102
  return filterModel.items;
102
103
  }
103
- var defaultFilter = getDefaultFilter();
104
- return defaultFilter ? [defaultFilter] : [];
104
+ if (!placeholderFilter.current) {
105
+ placeholderFilter.current = getDefaultFilter();
106
+ }
107
+ return placeholderFilter.current ? [placeholderFilter.current] : [];
105
108
  }, [filterModel.items, getDefaultFilter]);
106
109
  var hasMultipleFilters = items.length > 1;
107
110
  var addNewFilter = function addNewFilter() {
@@ -1,5 +1,6 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
1
2
  import * as React from 'react';
2
- import { unstable_debounce as debounce, unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
3
+ import { unstable_debounce as debounce, unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect, unstable_ownerWindow as ownerWindow } from '@mui/utils';
3
4
  import { useGridApiEventHandler, useGridApiOptionHandler } from '../../utils/useGridApiEventHandler';
4
5
  import { useGridApiMethod } from '../../utils/useGridApiMethod';
5
6
  import { useGridLogger } from '../../utils/useGridLogger';
@@ -10,6 +11,7 @@ import { getVisibleRows } from '../../utils/useGridVisibleRows';
10
11
  import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
11
12
  import { calculatePinnedRowsHeight } from '../rows/gridRowsUtils';
12
13
  import { getTotalHeaderHeight } from '../columns/gridColumnsUtils';
14
+ import { gridClasses } from '../../../constants/gridClasses';
13
15
  var isTestEnvironment = process.env.NODE_ENV === 'test';
14
16
  var hasScroll = function hasScroll(_ref) {
15
17
  var content = _ref.content,
@@ -113,10 +115,25 @@ export function useGridDimensions(apiRef, props) {
113
115
  apiRef.current.publishEvent('viewportInnerSizeChange', newFullDimensions.viewportInnerSize);
114
116
  }
115
117
  }, [apiRef, props.scrollbarSize, props.autoHeight, rowsMeta.currentPageTotalHeight, totalHeaderHeight]);
118
+ var _React$useState = React.useState(),
119
+ _React$useState2 = _slicedToArray(_React$useState, 2),
120
+ savedSize = _React$useState2[0],
121
+ setSavedSize = _React$useState2[1];
122
+ var debouncedSetSavedSize = React.useMemo(function () {
123
+ return debounce(setSavedSize, 60);
124
+ }, []);
125
+ var previousSize = React.useRef();
126
+ useEnhancedEffect(function () {
127
+ if (savedSize) {
128
+ updateGridDimensionsRef();
129
+ apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
130
+ }
131
+ }, [apiRef, savedSize, updateGridDimensionsRef]);
132
+
133
+ // This is the function called by apiRef.current.resize()
116
134
  var resize = React.useCallback(function () {
117
- updateGridDimensionsRef();
118
- apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
119
- }, [apiRef, updateGridDimensionsRef]);
135
+ apiRef.current.computeSizeAndPublishResizeEvent();
136
+ }, [apiRef]);
120
137
  var getRootDimensions = React.useCallback(function () {
121
138
  return fullDimensionsRef.current;
122
139
  }, []);
@@ -140,19 +157,45 @@ export function useGridDimensions(apiRef, props) {
140
157
  var maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
141
158
  return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
142
159
  }, [apiRef, props.pagination, props.paginationMode, props.getRowHeight, rowHeight]);
160
+ var computeSizeAndPublishResizeEvent = React.useCallback(function () {
161
+ var _apiRef$current$rootE2, _previousSize$current, _previousSize$current2;
162
+ var rootEl = (_apiRef$current$rootE2 = apiRef.current.rootElementRef) == null ? void 0 : _apiRef$current$rootE2.current;
163
+ var mainEl = rootEl == null ? void 0 : rootEl.querySelector(".".concat(gridClasses.main));
164
+ if (!mainEl) {
165
+ return;
166
+ }
167
+ var height = mainEl.offsetHeight || 0;
168
+ var width = mainEl.offsetWidth || 0;
169
+ var win = ownerWindow(mainEl);
170
+ var computedStyle = win.getComputedStyle(mainEl);
171
+ var paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
172
+ var paddingRight = parseInt(computedStyle.paddingRight, 10) || 0;
173
+ var paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
174
+ var paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
175
+ var newHeight = height - paddingTop - paddingBottom;
176
+ var newWidth = width - paddingLeft - paddingRight;
177
+ var hasHeightChanged = newHeight !== ((_previousSize$current = previousSize.current) == null ? void 0 : _previousSize$current.height);
178
+ var hasWidthChanged = newWidth !== ((_previousSize$current2 = previousSize.current) == null ? void 0 : _previousSize$current2.width);
179
+ if (!previousSize.current || hasHeightChanged || hasWidthChanged) {
180
+ var size = {
181
+ width: newWidth,
182
+ height: newHeight
183
+ };
184
+ apiRef.current.publishEvent('resize', size);
185
+ previousSize.current = size;
186
+ }
187
+ }, [apiRef]);
143
188
  var dimensionsApi = {
144
189
  resize: resize,
145
190
  getRootDimensions: getRootDimensions
146
191
  };
147
192
  var dimensionsPrivateApi = {
148
193
  getViewportPageSize: getViewportPageSize,
149
- updateGridDimensionsRef: updateGridDimensionsRef
194
+ updateGridDimensionsRef: updateGridDimensionsRef,
195
+ computeSizeAndPublishResizeEvent: computeSizeAndPublishResizeEvent
150
196
  };
151
197
  useGridApiMethod(apiRef, dimensionsApi, 'public');
152
198
  useGridApiMethod(apiRef, dimensionsPrivateApi, 'private');
153
- var debounceResize = React.useMemo(function () {
154
- return debounce(resize, 60);
155
- }, [resize]);
156
199
  var isFirstSizing = React.useRef(true);
157
200
  var handleResize = React.useCallback(function (size) {
158
201
  rootDimensionsRef.current = size;
@@ -169,18 +212,18 @@ export function useGridDimensions(apiRef, props) {
169
212
  }
170
213
  if (isTestEnvironment) {
171
214
  // We don't need to debounce the resize for tests.
172
- resize();
215
+ setSavedSize(size);
173
216
  isFirstSizing.current = false;
174
217
  return;
175
218
  }
176
219
  if (isFirstSizing.current) {
177
220
  // We want to initialize the grid dimensions as soon as possible to avoid flickering
178
- resize();
221
+ setSavedSize(size);
179
222
  isFirstSizing.current = false;
180
223
  return;
181
224
  }
182
- debounceResize();
183
- }, [props.autoHeight, debounceResize, logger, resize]);
225
+ debouncedSetSavedSize(size);
226
+ }, [props.autoHeight, debouncedSetSavedSize, logger]);
184
227
  useEnhancedEffect(function () {
185
228
  return updateGridDimensionsRef();
186
229
  }, [updateGridDimensionsRef]);
@@ -132,7 +132,9 @@ export var useGridPrintExport = function useGridPrintExport(apiRef, props) {
132
132
  (_printDoc$body$classL = printDoc.body.classList).add.apply(_printDoc$body$classL, _toConsumableArray(normalizeOptions.bodyClassName.split(' ')));
133
133
  }
134
134
  if (normalizeOptions.copyStyles) {
135
- var headStyleElements = doc.current.querySelectorAll("style, link[rel='stylesheet']");
135
+ var rootCandidate = gridRootElement.getRootNode();
136
+ var root = rootCandidate.constructor.name === 'ShadowRoot' ? rootCandidate : doc.current;
137
+ var headStyleElements = root.querySelectorAll("style, link[rel='stylesheet']");
136
138
  for (var i = 0; i < headStyleElements.length; i += 1) {
137
139
  var node = headStyleElements[i];
138
140
  if (node.tagName === 'STYLE') {
@@ -186,11 +186,13 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
186
186
  height: rootRef.current.clientHeight
187
187
  });
188
188
  }, [rowsMeta.currentPageTotalHeight]);
189
- var handleResize = React.useCallback(function (params) {
190
- setContainerDimensions({
191
- width: params.width,
192
- height: params.height
193
- });
189
+ var handleResize = React.useCallback(function () {
190
+ if (rootRef.current) {
191
+ setContainerDimensions({
192
+ width: rootRef.current.clientWidth,
193
+ height: rootRef.current.clientHeight
194
+ });
195
+ }
194
196
  }, []);
195
197
  useGridApiEventHandler(apiRef, 'debouncedResize', handleResize);
196
198
  var updateRenderZonePosition = React.useCallback(function (nextRenderContext) {
@@ -323,7 +325,8 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
323
325
  var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
324
326
  renderContext: renderContext
325
327
  };
326
- var nextRenderContext = params.renderContext,
328
+ var onRowRender = params.onRowRender,
329
+ nextRenderContext = params.renderContext,
327
330
  _params$minFirstColum = params.minFirstColumn,
328
331
  minFirstColumn = _params$minFirstColum === void 0 ? renderZoneMinColumnIndex : _params$minFirstColum,
329
332
  _params$maxLastColumn = params.maxLastColumn,
@@ -414,6 +417,9 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
414
417
  } else {
415
418
  isSelected = apiRef.current.isRowSelectable(_id);
416
419
  }
420
+ if (onRowRender) {
421
+ onRowRender(_id);
422
+ }
417
423
  var focusedCell = cellFocus !== null && cellFocus.id === _id ? cellFocus.field : null;
418
424
  var tabbableCell = null;
419
425
  if (cellTabIndex !== null && cellTabIndex.id === _id) {
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v6.2.0
2
+ * @mui/x-data-grid v6.2.1
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,2 @@
1
+ import joySlots from './joySlots';
2
+ export { joySlots as unstable_joySlots };
@@ -0,0 +1,73 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["touchRippleRef", "inputProps", "onChange", "color", "size", "checked", "sx", "value", "inputRef"];
4
+ import * as React from 'react';
5
+ import JoyCheckbox from '@mui/joy/Checkbox';
6
+ import JoyInput from '@mui/joy/Input';
7
+ import JoyFormControl from '@mui/joy/FormControl';
8
+ import JoyFormLabel from '@mui/joy/FormLabel';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ var Checkbox = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
12
+ var touchRippleRef = _ref.touchRippleRef,
13
+ inputProps = _ref.inputProps,
14
+ onChange = _ref.onChange,
15
+ color = _ref.color,
16
+ size = _ref.size,
17
+ checked = _ref.checked,
18
+ sx = _ref.sx,
19
+ value = _ref.value,
20
+ inputRef = _ref.inputRef,
21
+ props = _objectWithoutProperties(_ref, _excluded);
22
+ return /*#__PURE__*/_jsx(JoyCheckbox, _extends({}, props, {
23
+ slotProps: {
24
+ input: _extends({}, inputProps, {
25
+ ref: inputRef
26
+ })
27
+ },
28
+ ref: ref,
29
+ checked: checked,
30
+ onChange: onChange
31
+ }));
32
+ });
33
+ var TextField = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
34
+ var onChange = _ref2.onChange,
35
+ label = _ref2.label,
36
+ placeholder = _ref2.placeholder,
37
+ value = _ref2.value,
38
+ inputRef = _ref2.inputRef,
39
+ type = _ref2.type;
40
+ return /*#__PURE__*/_jsxs(JoyFormControl, {
41
+ ref: ref,
42
+ children: [/*#__PURE__*/_jsx(JoyFormLabel, {
43
+ sx: {
44
+ fontSize: 12
45
+ },
46
+ children: label
47
+ }), /*#__PURE__*/_jsx(JoyInput, {
48
+ type: type,
49
+ value: value,
50
+ onChange: onChange,
51
+ placeholder: placeholder,
52
+ size: "sm",
53
+ slotProps: {
54
+ input: {
55
+ ref: inputRef
56
+ }
57
+ }
58
+ })]
59
+ });
60
+ });
61
+ var joySlots = {
62
+ baseCheckbox: Checkbox,
63
+ baseTextField: TextField
64
+ // BaseFormControl: MUIFormControl,
65
+ // BaseSelect: MUISelect,
66
+ // BaseSwitch: MUISwitch,
67
+ // BaseButton: MUIButton,
68
+ // BaseIconButton: MUIIconButton,
69
+ // BaseTooltip: MUITooltip,
70
+ // BasePopper: MUIPopper,
71
+ };
72
+
73
+ export default joySlots;
@@ -20,7 +20,7 @@ declare const materialSlots: {
20
20
  Root?: import("react").ElementType<any> | undefined;
21
21
  } | undefined;
22
22
  componentsProps?: {
23
- root?: import("@mui/base").SlotComponentProps<"div", import("@mui/base").PopperUnstyledRootSlotPropsOverrides, import("@mui/base").PopperUnstyledOwnerState> | undefined;
23
+ root?: import("@mui/base").SlotComponentProps<"div", import("@mui/base").PopperUnstyledRootSlotPropsOverrides, import("@mui/base").PopperUnstyledOwnProps> | undefined;
24
24
  } | undefined;
25
25
  sx?: import("@mui/system").SxProps<import("@mui/material").Theme> | undefined;
26
26
  } & import("react").RefAttributes<HTMLDivElement>>;
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { UncapitalizeObjectKeys } from '../internals/utils';
3
- import { GridIconSlotsComponent } from './gridIconSlotsComponent';
2
+ import type { UncapitalizeObjectKeys } from '../internals/utils';
3
+ import type { GridIconSlotsComponent } from './gridIconSlotsComponent';
4
4
  /**
5
5
  * Grid components React prop interface containing all the overridable components.
6
6
  */
@@ -3,11 +3,9 @@ import * as React from 'react';
3
3
  import { useGridRootProps } from '../hooks/utils/useGridRootProps';
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
5
  import { jsxs as _jsxs } from "react/jsx-runtime";
6
- export const GridHeader = /*#__PURE__*/React.forwardRef(function GridHeader(props, ref) {
6
+ export function GridHeader() {
7
7
  const rootProps = useGridRootProps();
8
- return /*#__PURE__*/_jsxs("div", _extends({
9
- ref: ref
10
- }, props, {
8
+ return /*#__PURE__*/_jsxs(React.Fragment, {
11
9
  children: [/*#__PURE__*/_jsx(rootProps.slots.preferencesPanel, _extends({}, rootProps.slotProps?.preferencesPanel)), rootProps.slots.toolbar && /*#__PURE__*/_jsx(rootProps.slots.toolbar, _extends({}, rootProps.slotProps?.toolbar))]
12
- }));
13
- });
10
+ });
11
+ }
@@ -1,10 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import PropTypes from 'prop-types';
4
+ import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
4
5
  import { useGridPrivateApiContext } from '../../hooks/utils/useGridPrivateApiContext';
5
6
  import { useGridSelector } from '../../hooks/utils/useGridSelector';
6
7
  import { GridMainContainer } from '../containers/GridMainContainer';
7
- import { GridAutoSizer } from '../GridAutoSizer';
8
8
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
9
9
  import { gridColumnPositionsSelector, gridColumnVisibilityModelSelector, gridVisibleColumnDefinitionsSelector } from '../../hooks/features/columns/gridColumnsSelector';
10
10
  import { gridFilterActiveItemsLookupSelector } from '../../hooks/features/filter/gridFilterSelector';
@@ -17,12 +17,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
17
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
18
  function GridBody(props) {
19
19
  const {
20
- children,
21
20
  VirtualScrollerComponent,
22
21
  ColumnHeadersProps
23
22
  } = props;
24
23
  const apiRef = useGridPrivateApiContext();
25
24
  const rootProps = useGridRootProps();
25
+ const rootRef = React.useRef(null);
26
26
  const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
27
27
  const filterColumnLookup = useGridSelector(apiRef, gridFilterActiveItemsLookupSelector);
28
28
  const sortColumnLookup = useGridSelector(apiRef, gridSortColumnLookupSelector);
@@ -39,6 +39,24 @@ function GridBody(props) {
39
39
  const columnGroupsHeaderStructure = useGridSelector(apiRef, gridColumnGroupsHeaderStructureSelector);
40
40
  const hasOtherElementInTabSequence = !(columnGroupHeaderTabIndexState === null && columnHeaderTabIndexState === null && cellTabIndexState === null);
41
41
  const [isVirtualizationDisabled, setIsVirtualizationDisabled] = React.useState(rootProps.disableVirtualization);
42
+ useEnhancedEffect(() => {
43
+ apiRef.current.computeSizeAndPublishResizeEvent();
44
+ const elementToObserve = rootRef.current;
45
+ if (typeof ResizeObserver === 'undefined') {
46
+ return () => {};
47
+ }
48
+ const observer = new ResizeObserver(() => {
49
+ apiRef.current.computeSizeAndPublishResizeEvent();
50
+ });
51
+ if (elementToObserve) {
52
+ observer.observe(elementToObserve);
53
+ }
54
+ return () => {
55
+ if (elementToObserve) {
56
+ observer.unobserve(elementToObserve);
57
+ }
58
+ };
59
+ }, [apiRef]);
42
60
  const disableVirtualization = React.useCallback(() => {
43
61
  setIsVirtualizationDisabled(true);
44
62
  }, []);
@@ -65,10 +83,9 @@ function GridBody(props) {
65
83
  columnHeadersElementRef: columnHeadersRef,
66
84
  virtualScrollerRef
67
85
  });
68
- const handleResize = React.useCallback(size => {
69
- apiRef.current.publishEvent('resize', size);
70
- }, [apiRef]);
86
+ const hasDimensions = !!apiRef.current.getRootDimensions();
71
87
  return /*#__PURE__*/_jsxs(GridMainContainer, {
88
+ ref: rootRef,
72
89
  children: [/*#__PURE__*/_jsx(rootProps.slots.columnHeaders, _extends({
73
90
  ref: columnsContainerRef,
74
91
  innerRef: columnHeadersRef,
@@ -86,15 +103,16 @@ function GridBody(props) {
86
103
  columnVisibility: columnVisibility,
87
104
  columnGroupsHeaderStructure: columnGroupsHeaderStructure,
88
105
  hasOtherElementInTabSequence: hasOtherElementInTabSequence
89
- }, ColumnHeadersProps)), /*#__PURE__*/_jsx(GridAutoSizer, {
90
- nonce: rootProps.nonce,
91
- disableHeight: rootProps.autoHeight,
92
- onResize: handleResize,
93
- children: /*#__PURE__*/_jsx(VirtualScrollerComponent, {
94
- ref: virtualScrollerRef,
95
- disableVirtualization: isVirtualizationDisabled
96
- })
97
- }), children]
106
+ }, ColumnHeadersProps)), hasDimensions && /*#__PURE__*/_jsx(VirtualScrollerComponent
107
+ // The content is only rendered after dimensions are computed because
108
+ // the lazy-loading hook is listening to `renderedRowsIntervalChange`,
109
+ // but only does something if the dimensions are also available.
110
+ // If this event is published while dimensions haven't been computed,
111
+ // the `onFetchRows` prop won't be called during mount.
112
+ , {
113
+ ref: virtualScrollerRef,
114
+ disableVirtualization: isVirtualizationDisabled
115
+ })]
98
116
  });
99
117
  }
100
118
  process.env.NODE_ENV !== "production" ? GridBody.propTypes = {
@@ -102,7 +120,6 @@ process.env.NODE_ENV !== "production" ? GridBody.propTypes = {
102
120
  // | These PropTypes are generated from the TypeScript type definitions |
103
121
  // | To update them edit the TypeScript types and run "yarn proptypes" |
104
122
  // ----------------------------------------------------------------------
105
- children: PropTypes.node,
106
123
  ColumnHeadersProps: PropTypes.object,
107
124
  VirtualScrollerComponent: PropTypes.elementType.isRequired
108
125
  } : void 0;
@@ -35,7 +35,7 @@ const GridCellCheckboxForwardRef = /*#__PURE__*/React.forwardRef(function GridCe
35
35
  };
36
36
  const classes = useUtilityClasses(ownerState);
37
37
  const checkboxElement = React.useRef(null);
38
- const rippleRef = React.useRef();
38
+ const rippleRef = React.useRef(null);
39
39
  const handleRef = useForkRef(checkboxElement, ref);
40
40
  const element = apiRef.current.getCellElement(id, field);
41
41
  const handleChange = event => {
@@ -24,12 +24,13 @@ const GridMainContainerRoot = styled('div', {
24
24
  flexDirection: 'column',
25
25
  overflow: 'hidden'
26
26
  }));
27
- export function GridMainContainer(props) {
27
+ export const GridMainContainer = /*#__PURE__*/React.forwardRef((props, ref) => {
28
28
  const rootProps = useGridRootProps();
29
29
  const classes = useUtilityClasses(rootProps);
30
30
  return /*#__PURE__*/_jsx(GridMainContainerRoot, {
31
+ ref: ref,
31
32
  className: classes.root,
32
33
  ownerState: rootProps,
33
34
  children: props.children
34
35
  });
35
- }
36
+ });
@@ -54,11 +54,6 @@ const GridRoot = /*#__PURE__*/React.forwardRef(function GridRoot(props, ref) {
54
54
  useEnhancedEffect(() => {
55
55
  setMountedState(true);
56
56
  }, []);
57
- useEnhancedEffect(() => {
58
- if (mountedState) {
59
- apiRef.current.updateGridDimensionsRef();
60
- }
61
- }, [apiRef, mountedState]);
62
57
  if (!mountedState) {
63
58
  return null;
64
59
  }