@mui/x-data-grid-pro 5.12.2 → 5.13.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 (48) hide show
  1. package/CHANGELOG.md +160 -6
  2. package/DataGridPro/DataGridPro.js +1 -1
  3. package/components/DataGridProColumnHeaders.js +14 -7
  4. package/components/DataGridProVirtualScroller.js +7 -18
  5. package/components/GridDetailPanel.d.ts +19 -0
  6. package/components/GridDetailPanel.js +65 -0
  7. package/hooks/features/detailPanel/gridDetailPanelInterface.d.ts +20 -1
  8. package/hooks/features/detailPanel/gridDetailPanelSelector.d.ts +14 -3
  9. package/hooks/features/detailPanel/gridDetailPanelSelector.js +9 -1
  10. package/hooks/features/detailPanel/index.d.ts +1 -1
  11. package/hooks/features/detailPanel/index.js +1 -1
  12. package/hooks/features/detailPanel/useGridDetailPanel.js +41 -7
  13. package/hooks/features/detailPanel/useGridDetailPanelCache.d.ts +4 -0
  14. package/hooks/features/detailPanel/useGridDetailPanelCache.js +64 -0
  15. package/index.js +1 -1
  16. package/legacy/DataGridPro/DataGridPro.js +1 -1
  17. package/legacy/components/DataGridProColumnHeaders.js +14 -7
  18. package/legacy/components/DataGridProVirtualScroller.js +12 -26
  19. package/legacy/components/GridDetailPanel.js +72 -0
  20. package/legacy/hooks/features/detailPanel/gridDetailPanelSelector.js +15 -2
  21. package/legacy/hooks/features/detailPanel/index.js +1 -1
  22. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +40 -7
  23. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +64 -0
  24. package/legacy/index.js +1 -1
  25. package/legacy/utils/releaseInfo.js +1 -1
  26. package/models/dataGridProProps.d.ts +2 -2
  27. package/modern/DataGridPro/DataGridPro.js +1 -1
  28. package/modern/components/DataGridProColumnHeaders.js +14 -7
  29. package/modern/components/DataGridProVirtualScroller.js +7 -18
  30. package/modern/components/GridDetailPanel.js +65 -0
  31. package/modern/hooks/features/detailPanel/gridDetailPanelSelector.js +9 -1
  32. package/modern/hooks/features/detailPanel/index.js +1 -1
  33. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +39 -7
  34. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +62 -0
  35. package/modern/index.js +1 -1
  36. package/modern/utils/releaseInfo.js +1 -1
  37. package/node/DataGridPro/DataGridPro.js +1 -1
  38. package/node/components/DataGridProColumnHeaders.js +14 -7
  39. package/node/components/DataGridProVirtualScroller.js +8 -19
  40. package/node/components/GridDetailPanel.js +83 -0
  41. package/node/hooks/features/detailPanel/gridDetailPanelSelector.js +12 -2
  42. package/node/hooks/features/detailPanel/index.js +25 -11
  43. package/node/hooks/features/detailPanel/useGridDetailPanel.js +40 -6
  44. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +81 -0
  45. package/node/index.js +1 -1
  46. package/node/utils/releaseInfo.js +1 -1
  47. package/package.json +6 -6
  48. package/utils/releaseInfo.js +1 -1
@@ -0,0 +1,65 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["rowId", "height", "style"];
4
+ import * as React from 'react';
5
+ import Box from '@mui/material/Box';
6
+ import { styled } from '@mui/material/styles';
7
+ import { useGridApiContext } from '../hooks/utils/useGridApiContext';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const DetailPanel = styled(Box, {
10
+ name: 'MuiDataGrid',
11
+ slot: 'DetailPanel',
12
+ overridesResolver: (props, styles) => styles.detailPanel
13
+ })(({
14
+ theme
15
+ }) => ({
16
+ zIndex: 2,
17
+ width: '100%',
18
+ position: 'absolute',
19
+ backgroundColor: theme.palette.background.default,
20
+ overflow: 'auto'
21
+ }));
22
+
23
+ const GridDetailPanel = props => {
24
+ const {
25
+ rowId,
26
+ height,
27
+ style: styleProp = {}
28
+ } = props,
29
+ other = _objectWithoutPropertiesLoose(props, _excluded);
30
+
31
+ const apiRef = useGridApiContext();
32
+ const ref = React.useRef();
33
+ React.useLayoutEffect(() => {
34
+ if (height === 'auto' && ref.current && typeof ResizeObserver === 'undefined') {
35
+ // Fallback for IE
36
+ apiRef.current.unstable_storeDetailPanelHeight(rowId, ref.current.clientHeight);
37
+ }
38
+ }, [apiRef, height, rowId]);
39
+ React.useLayoutEffect(() => {
40
+ const hasFixedHeight = height !== 'auto';
41
+
42
+ if (!ref.current || hasFixedHeight || typeof ResizeObserver === 'undefined') {
43
+ return undefined;
44
+ }
45
+
46
+ const resizeObserver = new ResizeObserver(entries => {
47
+ const [entry] = entries;
48
+ const observedHeight = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
49
+ apiRef.current.unstable_storeDetailPanelHeight(rowId, observedHeight);
50
+ });
51
+ resizeObserver.observe(ref.current);
52
+ return () => resizeObserver.disconnect();
53
+ }, [apiRef, height, rowId]);
54
+
55
+ const style = _extends({}, styleProp, {
56
+ height
57
+ });
58
+
59
+ return /*#__PURE__*/_jsx(DetailPanel, _extends({
60
+ ref: ref,
61
+ style: style
62
+ }, other));
63
+ };
64
+
65
+ export { GridDetailPanel };
@@ -1,3 +1,11 @@
1
+ import { createSelector } from '@mui/x-data-grid/internals';
1
2
  export const gridDetailPanelExpandedRowIdsSelector = state => state.detailPanel.expandedRowIds;
2
3
  export const gridDetailPanelExpandedRowsContentCacheSelector = state => state.detailPanel.contentCache;
3
- export const gridDetailPanelExpandedRowsHeightCacheSelector = state => state.detailPanel.heightCache;
4
+ export const gridDetailPanelRawHeightCacheSelector = state => state.detailPanel.heightCache; // TODO v6: Make this selector return the full object, including the autoHeight flag
5
+
6
+ export const gridDetailPanelExpandedRowsHeightCacheSelector = createSelector(gridDetailPanelRawHeightCacheSelector, heightCache => Object.entries(heightCache).reduce((acc, [id, {
7
+ height
8
+ }]) => {
9
+ acc[id] = height || 0;
10
+ return acc;
11
+ }, {}));
@@ -1,3 +1,3 @@
1
1
  export * from './gridDetailPanelToggleColDef';
2
- export * from './gridDetailPanelSelector';
2
+ export { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
3
3
  export * from './gridDetailPanelInterface';
@@ -3,16 +3,17 @@ import * as React from 'react';
3
3
  import { useGridSelector, useGridApiEventHandler, useGridApiMethod, gridRowIdsSelector } from '@mui/x-data-grid';
4
4
  import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
5
5
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
6
- import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
6
+ import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector, gridDetailPanelRawHeightCacheSelector } from './gridDetailPanelSelector';
7
7
  export const detailPanelStateInitializer = (state, props) => {
8
8
  return _extends({}, state, {
9
9
  detailPanel: {
10
+ heightCache: {},
10
11
  expandedRowIds: props.detailPanelExpandedRowIds ?? props.initialState?.detailPanel?.expandedRowIds ?? []
11
12
  }
12
13
  });
13
14
  };
14
15
 
15
- function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight) {
16
+ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight, previousHeightCache) {
16
17
  if (typeof getDetailPanelContent !== 'function') {
17
18
  return {};
18
19
  } // TODO change to lazy approach using a Proxy
@@ -31,7 +32,12 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
31
32
  }
32
33
 
33
34
  const params = apiRef.current.getRowParams(id);
34
- acc[id] = getDetailPanelHeight(params);
35
+ const height = getDetailPanelHeight(params);
36
+ const autoHeight = height === 'auto';
37
+ acc[id] = {
38
+ autoHeight,
39
+ height: autoHeight ? previousHeightCache[id]?.height : height
40
+ };
35
41
  return acc;
36
42
  }, {});
37
43
  return {
@@ -110,10 +116,36 @@ export const useGridDetailPanel = (apiRef, props) => {
110
116
  });
111
117
  apiRef.current.forceUpdate();
112
118
  }, [apiRef]);
119
+ const storeDetailPanelHeight = React.useCallback((id, height) => {
120
+ const heightCache = gridDetailPanelRawHeightCacheSelector(apiRef.current.state);
121
+
122
+ if (!heightCache[id] || heightCache[id].height === height) {
123
+ return;
124
+ }
125
+
126
+ apiRef.current.setState(state => {
127
+ return _extends({}, state, {
128
+ detailPanel: _extends({}, state.detailPanel, {
129
+ heightCache: _extends({}, heightCache, {
130
+ [id]: _extends({}, heightCache[id], {
131
+ height
132
+ })
133
+ })
134
+ })
135
+ });
136
+ });
137
+ apiRef.current.unstable_requestPipeProcessorsApplication('rowHeight');
138
+ }, [apiRef]);
139
+ const detailPanelHasAutoHeight = React.useCallback(id => {
140
+ const heightCache = gridDetailPanelRawHeightCacheSelector(apiRef.current.state);
141
+ return heightCache[id] ? heightCache[id].autoHeight : false;
142
+ }, [apiRef]);
113
143
  const detailPanelApi = {
114
144
  toggleDetailPanel,
115
145
  getExpandedDetailPanels,
116
- setExpandedDetailPanels
146
+ setExpandedDetailPanels,
147
+ unstable_storeDetailPanelHeight: storeDetailPanelHeight,
148
+ unstable_detailPanelHasAutoHeight: detailPanelHasAutoHeight
117
149
  };
118
150
  useGridApiMethod(apiRef, detailPanelApi, 'detailPanelApi');
119
151
  React.useEffect(() => {
@@ -128,7 +160,7 @@ export const useGridDetailPanel = (apiRef, props) => {
128
160
  const updateCachesAndForceUpdate = React.useCallback(() => {
129
161
  apiRef.current.setState(state => {
130
162
  return _extends({}, state, {
131
- detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
163
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
132
164
  });
133
165
  });
134
166
  apiRef.current.forceUpdate();
@@ -143,7 +175,7 @@ export const useGridDetailPanel = (apiRef, props) => {
143
175
 
144
176
  apiRef.current.setState(state => {
145
177
  return _extends({}, state, {
146
- detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
178
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
147
179
  });
148
180
  });
149
181
  previousGetDetailPanelContentProp.current = props.getDetailPanelContent;
@@ -157,7 +189,7 @@ export const useGridDetailPanel = (apiRef, props) => {
157
189
  }
158
190
 
159
191
  updateCachesIfNeeded();
160
- const heightCache = gridDetailPanelExpandedRowsHeightCacheSelector(apiRef.current.state);
192
+ const heightCache = gridDetailPanelExpandedRowsHeightCacheSelector(apiRef);
161
193
  return _extends({}, initialValue, {
162
194
  detail: heightCache[row.id] ?? 0 // Fallback to zero because the cache might not be ready yet (e.g. page was changed)
163
195
 
@@ -0,0 +1,62 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { useGridApiEventHandler, gridRowIdsSelector } from '@mui/x-data-grid';
4
+
5
+ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight, previousHeightCache) {
6
+ if (typeof getDetailPanelContent !== 'function') {
7
+ return {};
8
+ } // TODO change to lazy approach using a Proxy
9
+ // only call getDetailPanelContent when asked for an id
10
+
11
+
12
+ const rowIds = gridRowIdsSelector(apiRef);
13
+ const contentCache = rowIds.reduce((acc, id) => {
14
+ const params = apiRef.current.getRowParams(id);
15
+ acc[id] = getDetailPanelContent(params);
16
+ return acc;
17
+ }, {});
18
+ const heightCache = rowIds.reduce((acc, id) => {
19
+ if (contentCache[id] == null) {
20
+ return acc;
21
+ }
22
+
23
+ const params = apiRef.current.getRowParams(id);
24
+ const height = getDetailPanelHeight(params);
25
+ const autoHeight = height === 'auto';
26
+ acc[id] = {
27
+ autoHeight,
28
+ height: !autoHeight ? height : previousHeightCache[id]?.height
29
+ };
30
+ return acc;
31
+ }, {});
32
+ return {
33
+ contentCache,
34
+ heightCache
35
+ };
36
+ }
37
+
38
+ export const useGridDetailPanelCache = (apiRef, props) => {
39
+ const updateCaches = React.useCallback(() => {
40
+ apiRef.current.setState(state => {
41
+ return _extends({}, state, {
42
+ detailPanel: _extends({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
43
+ });
44
+ });
45
+ apiRef.current.forceUpdate();
46
+ }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
47
+ useGridApiEventHandler(apiRef, 'sortedRowsSet', updateCaches);
48
+ const isFirstRender = React.useRef(true);
49
+
50
+ if (isFirstRender.current) {
51
+ isFirstRender.current = false;
52
+ updateCaches();
53
+ }
54
+
55
+ React.useEffect(() => {
56
+ if (isFirstRender.current) {
57
+ return;
58
+ }
59
+
60
+ updateCaches();
61
+ }, [updateCaches]);
62
+ };
package/modern/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.12.2
1
+ /** @license MUI v5.13.1
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,6 +1,6 @@
1
1
  import { ponyfillGlobal } from '@mui/utils';
2
2
  export const getReleaseInfo = () => {
3
- const releaseInfo = "MTY1NTMzMDQwMDAwMA==";
3
+ const releaseInfo = "MTY1Nzg1NDAwMDAwMA==";
4
4
 
5
5
  if (process.env.NODE_ENV !== 'production') {
6
6
  // A simple hack to set the value in the test environment (has no build step).
@@ -342,7 +342,7 @@ DataGridProRaw.propTypes = {
342
342
  /**
343
343
  * Function that returns the height of the row detail panel.
344
344
  * @param {GridRowParams} params With all properties from [[GridRowParams]].
345
- * @returns {number} The height in pixels.
345
+ * @returns {number | string} The height in pixels or "auto" to use the content height.
346
346
  * @default "() => 500"
347
347
  */
348
348
  getDetailPanelHeight: _propTypes.default.func,
@@ -141,15 +141,21 @@ const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function DataGrid
141
141
  firstColumnIndex: visibleColumnFields.length - rightPinnedColumns.length,
142
142
  lastColumnIndex: visibleColumnFields.length
143
143
  }) : null;
144
+ const innerProps = getInnerProps();
145
+ const pinnedColumnHeadersProps = {
146
+ role: innerProps.role,
147
+ 'aria-rowindex': innerProps['aria-rowindex']
148
+ };
144
149
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_internals.GridColumnHeaders, (0, _extends2.default)({
145
150
  ref: ref,
146
151
  className: className
147
152
  }, getRootProps(other), {
148
- children: [leftRenderContext && /*#__PURE__*/(0, _jsxRuntime.jsx)(GridColumnHeadersPinnedColumnHeaders, {
153
+ children: [leftRenderContext && /*#__PURE__*/(0, _jsxRuntime.jsx)(GridColumnHeadersPinnedColumnHeaders, (0, _extends2.default)({
149
154
  className: classes.leftPinnedColumns,
150
155
  ownerState: {
151
156
  side: _columnPinning.GridPinnedPosition.left
152
- },
157
+ }
158
+ }, pinnedColumnHeadersProps, {
153
159
  children: getColumns({
154
160
  renderContext: leftRenderContext,
155
161
  minFirstColumn: leftRenderContext.firstColumnIndex,
@@ -157,22 +163,23 @@ const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function DataGrid
157
163
  }, {
158
164
  disableReorder: true
159
165
  })
160
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.GridColumnHeadersInner, (0, _extends2.default)({
166
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.GridColumnHeadersInner, (0, _extends2.default)({
161
167
  isDragging: isDragging
162
- }, getInnerProps(), {
168
+ }, innerProps, {
163
169
  children: getColumns({
164
170
  renderContext,
165
171
  minFirstColumn: leftPinnedColumns.length,
166
172
  maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length
167
173
  })
168
- })), rightRenderContext && /*#__PURE__*/(0, _jsxRuntime.jsx)(GridColumnHeadersPinnedColumnHeaders, {
174
+ })), rightRenderContext && /*#__PURE__*/(0, _jsxRuntime.jsx)(GridColumnHeadersPinnedColumnHeaders, (0, _extends2.default)({
169
175
  ownerState: {
170
176
  side: _columnPinning.GridPinnedPosition.right
171
177
  },
172
178
  className: classes.rightPinnedColumns,
173
179
  style: {
174
180
  paddingRight: scrollbarSize
175
- },
181
+ }
182
+ }, pinnedColumnHeadersProps, {
176
183
  children: getColumns({
177
184
  renderContext: rightRenderContext,
178
185
  minFirstColumn: rightRenderContext.firstColumnIndex,
@@ -181,7 +188,7 @@ const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function DataGrid
181
188
  disableReorder: true,
182
189
  separatorSide: _xDataGrid.GridColumnHeaderSeparatorSides.Left
183
190
  })
184
- })]
191
+ }))]
185
192
  }));
186
193
  });
187
194
  exports.DataGridProColumnHeaders = DataGridProColumnHeaders;
@@ -15,8 +15,6 @@ var React = _interopRequireWildcard(require("react"));
15
15
 
16
16
  var _styles = require("@mui/material/styles");
17
17
 
18
- var _Box = _interopRequireDefault(require("@mui/material/Box"));
19
-
20
18
  var _material = require("@mui/material");
21
19
 
22
20
  var _xDataGrid = require("@mui/x-data-grid");
@@ -31,6 +29,8 @@ var _columnPinning = require("../hooks/features/columnPinning");
31
29
 
32
30
  var _detailPanel = require("../hooks/features/detailPanel");
33
31
 
32
+ var _GridDetailPanel = require("./GridDetailPanel");
33
+
34
34
  var _jsxRuntime = require("react/jsx-runtime");
35
35
 
36
36
  const _excluded = ["className", "disableVirtualization"];
@@ -102,19 +102,6 @@ const VirtualScrollerDetailPanels = (0, _styles.styled)('div', {
102
102
  })({
103
103
  position: 'relative'
104
104
  });
105
- const VirtualScrollerDetailPanel = (0, _styles.styled)(_Box.default, {
106
- name: 'MuiDataGrid',
107
- slot: 'DetailPanel',
108
- overridesResolver: (props, styles) => styles.detailPanel
109
- })(({
110
- theme
111
- }) => ({
112
- zIndex: 2,
113
- width: '100%',
114
- position: 'absolute',
115
- backgroundColor: theme.palette.background.default,
116
- overflow: 'auto'
117
- }));
118
105
  const VirtualScrollerPinnedColumns = (0, _styles.styled)('div', {
119
106
  name: 'MuiDataGrid',
120
107
  slot: 'PinnedColumns',
@@ -237,15 +224,17 @@ const DataGridProVirtualScroller = /*#__PURE__*/React.forwardRef(function DataGr
237
224
  const exists = rowIndex !== undefined;
238
225
 
239
226
  if ( /*#__PURE__*/React.isValidElement(content) && exists) {
240
- const height = detailPanelsHeights[id];
227
+ const hasAutoHeight = apiRef.current.unstable_detailPanelHasAutoHeight(id);
228
+ const height = hasAutoHeight ? 'auto' : detailPanelsHeights[id];
241
229
  const sizes = apiRef.current.unstable_getRowInternalSizes(id);
242
230
  const spacingTop = (sizes == null ? void 0 : sizes.spacingTop) || 0;
243
231
  const top = rowsMeta.positions[rowIndex] + apiRef.current.unstable_getRowHeight(id) + spacingTop;
244
- panels.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(VirtualScrollerDetailPanel, {
232
+ panels.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridDetailPanel.GridDetailPanel, {
233
+ rowId: id,
245
234
  style: {
246
- top,
247
- height
235
+ top
248
236
  },
237
+ height: height,
249
238
  className: classes.detailPanel,
250
239
  children: content
251
240
  }, i));
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.GridDetailPanel = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
13
+
14
+ var React = _interopRequireWildcard(require("react"));
15
+
16
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
17
+
18
+ var _styles = require("@mui/material/styles");
19
+
20
+ var _useGridApiContext = require("../hooks/utils/useGridApiContext");
21
+
22
+ var _jsxRuntime = require("react/jsx-runtime");
23
+
24
+ const _excluded = ["rowId", "height", "style"];
25
+
26
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
+
28
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
+
30
+ const DetailPanel = (0, _styles.styled)(_Box.default, {
31
+ name: 'MuiDataGrid',
32
+ slot: 'DetailPanel',
33
+ overridesResolver: (props, styles) => styles.detailPanel
34
+ })(({
35
+ theme
36
+ }) => ({
37
+ zIndex: 2,
38
+ width: '100%',
39
+ position: 'absolute',
40
+ backgroundColor: theme.palette.background.default,
41
+ overflow: 'auto'
42
+ }));
43
+
44
+ const GridDetailPanel = props => {
45
+ const {
46
+ rowId,
47
+ height,
48
+ style: styleProp = {}
49
+ } = props,
50
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
51
+ const apiRef = (0, _useGridApiContext.useGridApiContext)();
52
+ const ref = React.useRef();
53
+ React.useLayoutEffect(() => {
54
+ if (height === 'auto' && ref.current && typeof ResizeObserver === 'undefined') {
55
+ // Fallback for IE
56
+ apiRef.current.unstable_storeDetailPanelHeight(rowId, ref.current.clientHeight);
57
+ }
58
+ }, [apiRef, height, rowId]);
59
+ React.useLayoutEffect(() => {
60
+ const hasFixedHeight = height !== 'auto';
61
+
62
+ if (!ref.current || hasFixedHeight || typeof ResizeObserver === 'undefined') {
63
+ return undefined;
64
+ }
65
+
66
+ const resizeObserver = new ResizeObserver(entries => {
67
+ const [entry] = entries;
68
+ const observedHeight = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
69
+ apiRef.current.unstable_storeDetailPanelHeight(rowId, observedHeight);
70
+ });
71
+ resizeObserver.observe(ref.current);
72
+ return () => resizeObserver.disconnect();
73
+ }, [apiRef, height, rowId]);
74
+ const style = (0, _extends2.default)({}, styleProp, {
75
+ height
76
+ });
77
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(DetailPanel, (0, _extends2.default)({
78
+ ref: ref,
79
+ style: style
80
+ }, other));
81
+ };
82
+
83
+ exports.GridDetailPanel = GridDetailPanel;
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.gridDetailPanelExpandedRowsHeightCacheSelector = exports.gridDetailPanelExpandedRowsContentCacheSelector = exports.gridDetailPanelExpandedRowIdsSelector = void 0;
6
+ exports.gridDetailPanelRawHeightCacheSelector = exports.gridDetailPanelExpandedRowsHeightCacheSelector = exports.gridDetailPanelExpandedRowsContentCacheSelector = exports.gridDetailPanelExpandedRowIdsSelector = void 0;
7
+
8
+ var _internals = require("@mui/x-data-grid/internals");
7
9
 
8
10
  const gridDetailPanelExpandedRowIdsSelector = state => state.detailPanel.expandedRowIds;
9
11
 
@@ -13,6 +15,14 @@ const gridDetailPanelExpandedRowsContentCacheSelector = state => state.detailPan
13
15
 
14
16
  exports.gridDetailPanelExpandedRowsContentCacheSelector = gridDetailPanelExpandedRowsContentCacheSelector;
15
17
 
16
- const gridDetailPanelExpandedRowsHeightCacheSelector = state => state.detailPanel.heightCache;
18
+ const gridDetailPanelRawHeightCacheSelector = state => state.detailPanel.heightCache; // TODO v6: Make this selector return the full object, including the autoHeight flag
19
+
17
20
 
21
+ exports.gridDetailPanelRawHeightCacheSelector = gridDetailPanelRawHeightCacheSelector;
22
+ const gridDetailPanelExpandedRowsHeightCacheSelector = (0, _internals.createSelector)(gridDetailPanelRawHeightCacheSelector, heightCache => Object.entries(heightCache).reduce((acc, [id, {
23
+ height
24
+ }]) => {
25
+ acc[id] = height || 0;
26
+ return acc;
27
+ }, {}));
18
28
  exports.gridDetailPanelExpandedRowsHeightCacheSelector = gridDetailPanelExpandedRowsHeightCacheSelector;
@@ -3,11 +3,35 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ gridDetailPanelExpandedRowIdsSelector: true,
8
+ gridDetailPanelExpandedRowsContentCacheSelector: true,
9
+ gridDetailPanelExpandedRowsHeightCacheSelector: true
10
+ };
11
+ Object.defineProperty(exports, "gridDetailPanelExpandedRowIdsSelector", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _gridDetailPanelSelector.gridDetailPanelExpandedRowIdsSelector;
15
+ }
16
+ });
17
+ Object.defineProperty(exports, "gridDetailPanelExpandedRowsContentCacheSelector", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _gridDetailPanelSelector.gridDetailPanelExpandedRowsContentCacheSelector;
21
+ }
22
+ });
23
+ Object.defineProperty(exports, "gridDetailPanelExpandedRowsHeightCacheSelector", {
24
+ enumerable: true,
25
+ get: function () {
26
+ return _gridDetailPanelSelector.gridDetailPanelExpandedRowsHeightCacheSelector;
27
+ }
28
+ });
6
29
 
7
30
  var _gridDetailPanelToggleColDef = require("./gridDetailPanelToggleColDef");
8
31
 
9
32
  Object.keys(_gridDetailPanelToggleColDef).forEach(function (key) {
10
33
  if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
11
35
  if (key in exports && exports[key] === _gridDetailPanelToggleColDef[key]) return;
12
36
  Object.defineProperty(exports, key, {
13
37
  enumerable: true,
@@ -19,21 +43,11 @@ Object.keys(_gridDetailPanelToggleColDef).forEach(function (key) {
19
43
 
20
44
  var _gridDetailPanelSelector = require("./gridDetailPanelSelector");
21
45
 
22
- Object.keys(_gridDetailPanelSelector).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _gridDetailPanelSelector[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _gridDetailPanelSelector[key];
29
- }
30
- });
31
- });
32
-
33
46
  var _gridDetailPanelInterface = require("./gridDetailPanelInterface");
34
47
 
35
48
  Object.keys(_gridDetailPanelInterface).forEach(function (key) {
36
49
  if (key === "default" || key === "__esModule") return;
50
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
37
51
  if (key in exports && exports[key] === _gridDetailPanelInterface[key]) return;
38
52
  Object.defineProperty(exports, key, {
39
53
  enumerable: true,
@@ -28,6 +28,7 @@ const detailPanelStateInitializer = (state, props) => {
28
28
 
29
29
  return (0, _extends2.default)({}, state, {
30
30
  detailPanel: {
31
+ heightCache: {},
31
32
  expandedRowIds: (_ref = (_props$detailPanelExp = props.detailPanelExpandedRowIds) != null ? _props$detailPanelExp : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$d = _props$initialState.detailPanel) == null ? void 0 : _props$initialState$d.expandedRowIds) != null ? _ref : []
32
33
  }
33
34
  });
@@ -35,7 +36,7 @@ const detailPanelStateInitializer = (state, props) => {
35
36
 
36
37
  exports.detailPanelStateInitializer = detailPanelStateInitializer;
37
38
 
38
- function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight) {
39
+ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight, previousHeightCache) {
39
40
  if (typeof getDetailPanelContent !== 'function') {
40
41
  return {};
41
42
  } // TODO change to lazy approach using a Proxy
@@ -49,12 +50,19 @@ function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeig
49
50
  return acc;
50
51
  }, {});
51
52
  const heightCache = rowIds.reduce((acc, id) => {
53
+ var _previousHeightCache$;
54
+
52
55
  if (contentCache[id] == null) {
53
56
  return acc;
54
57
  }
55
58
 
56
59
  const params = apiRef.current.getRowParams(id);
57
- acc[id] = getDetailPanelHeight(params);
60
+ const height = getDetailPanelHeight(params);
61
+ const autoHeight = height === 'auto';
62
+ acc[id] = {
63
+ autoHeight,
64
+ height: autoHeight ? (_previousHeightCache$ = previousHeightCache[id]) == null ? void 0 : _previousHeightCache$.height : height
65
+ };
58
66
  return acc;
59
67
  }, {});
60
68
  return {
@@ -133,10 +141,36 @@ const useGridDetailPanel = (apiRef, props) => {
133
141
  });
134
142
  apiRef.current.forceUpdate();
135
143
  }, [apiRef]);
144
+ const storeDetailPanelHeight = React.useCallback((id, height) => {
145
+ const heightCache = (0, _gridDetailPanelSelector.gridDetailPanelRawHeightCacheSelector)(apiRef.current.state);
146
+
147
+ if (!heightCache[id] || heightCache[id].height === height) {
148
+ return;
149
+ }
150
+
151
+ apiRef.current.setState(state => {
152
+ return (0, _extends2.default)({}, state, {
153
+ detailPanel: (0, _extends2.default)({}, state.detailPanel, {
154
+ heightCache: (0, _extends2.default)({}, heightCache, {
155
+ [id]: (0, _extends2.default)({}, heightCache[id], {
156
+ height
157
+ })
158
+ })
159
+ })
160
+ });
161
+ });
162
+ apiRef.current.unstable_requestPipeProcessorsApplication('rowHeight');
163
+ }, [apiRef]);
164
+ const detailPanelHasAutoHeight = React.useCallback(id => {
165
+ const heightCache = (0, _gridDetailPanelSelector.gridDetailPanelRawHeightCacheSelector)(apiRef.current.state);
166
+ return heightCache[id] ? heightCache[id].autoHeight : false;
167
+ }, [apiRef]);
136
168
  const detailPanelApi = {
137
169
  toggleDetailPanel,
138
170
  getExpandedDetailPanels,
139
- setExpandedDetailPanels
171
+ setExpandedDetailPanels,
172
+ unstable_storeDetailPanelHeight: storeDetailPanelHeight,
173
+ unstable_detailPanelHasAutoHeight: detailPanelHasAutoHeight
140
174
  };
141
175
  (0, _xDataGrid.useGridApiMethod)(apiRef, detailPanelApi, 'detailPanelApi');
142
176
  React.useEffect(() => {
@@ -151,7 +185,7 @@ const useGridDetailPanel = (apiRef, props) => {
151
185
  const updateCachesAndForceUpdate = React.useCallback(() => {
152
186
  apiRef.current.setState(state => {
153
187
  return (0, _extends2.default)({}, state, {
154
- detailPanel: (0, _extends2.default)({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
188
+ detailPanel: (0, _extends2.default)({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
155
189
  });
156
190
  });
157
191
  apiRef.current.forceUpdate();
@@ -166,7 +200,7 @@ const useGridDetailPanel = (apiRef, props) => {
166
200
 
167
201
  apiRef.current.setState(state => {
168
202
  return (0, _extends2.default)({}, state, {
169
- detailPanel: (0, _extends2.default)({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight))
203
+ detailPanel: (0, _extends2.default)({}, state.detailPanel, cacheContentAndHeight(apiRef, props.getDetailPanelContent, props.getDetailPanelHeight, state.detailPanel.heightCache))
170
204
  });
171
205
  });
172
206
  previousGetDetailPanelContentProp.current = props.getDetailPanelContent;
@@ -182,7 +216,7 @@ const useGridDetailPanel = (apiRef, props) => {
182
216
  }
183
217
 
184
218
  updateCachesIfNeeded();
185
- const heightCache = (0, _gridDetailPanelSelector.gridDetailPanelExpandedRowsHeightCacheSelector)(apiRef.current.state);
219
+ const heightCache = (0, _gridDetailPanelSelector.gridDetailPanelExpandedRowsHeightCacheSelector)(apiRef);
186
220
  return (0, _extends2.default)({}, initialValue, {
187
221
  detail: (_heightCache$row$id = heightCache[row.id]) != null ? _heightCache$row$id : 0 // Fallback to zero because the cache might not be ready yet (e.g. page was changed)
188
222