@mui/x-data-grid 8.9.1 → 8.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.
- package/CHANGELOG.md +217 -8
- package/DataGrid/DataGrid.js +5 -0
- package/DataGrid/useDataGridComponent.js +2 -0
- package/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/components/GridDetailPanels.d.ts +2 -2
- package/components/GridFooter.js +1 -1
- package/components/GridPagination.js +4 -3
- package/components/GridPinnedRows.d.ts +2 -2
- package/components/GridRow.js +8 -1
- package/components/cell/GridCell.js +7 -5
- package/components/cell/GridEditSingleSelectCell.js +1 -1
- package/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
- package/components/columnsManagement/GridColumnsManagement.js +17 -5
- package/components/containers/GridRootStyles.d.ts +1 -1
- package/components/toolbarV8/Toolbar.d.ts +1 -1
- package/components/virtualization/GridVirtualScroller.js +5 -5
- package/constants/dataGridPropsDefaultValues.js +1 -0
- package/esm/DataGrid/DataGrid.js +5 -0
- package/esm/DataGrid/useDataGridComponent.js +2 -0
- package/esm/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/esm/components/GridDetailPanels.d.ts +2 -2
- package/esm/components/GridFooter.js +1 -1
- package/esm/components/GridPagination.js +3 -2
- package/esm/components/GridPinnedRows.d.ts +2 -2
- package/esm/components/GridRow.js +8 -1
- package/esm/components/cell/GridCell.js +7 -5
- package/esm/components/cell/GridEditSingleSelectCell.js +1 -1
- package/esm/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
- package/esm/components/columnsManagement/GridColumnsManagement.js +17 -5
- package/esm/components/containers/GridRootStyles.d.ts +1 -1
- package/esm/components/toolbarV8/Toolbar.d.ts +1 -1
- package/esm/components/virtualization/GridVirtualScroller.js +5 -5
- package/esm/constants/dataGridPropsDefaultValues.js +1 -0
- package/esm/hooks/core/useGridVirtualizer.d.ts +9 -0
- package/esm/hooks/core/useGridVirtualizer.js +223 -0
- package/esm/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/esm/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -2
- package/esm/hooks/features/columns/useGridColumnSpanning.js +5 -90
- package/esm/hooks/features/dataSource/models.d.ts +11 -2
- package/esm/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
- package/esm/hooks/features/dataSource/useGridDataSourceBase.js +9 -2
- package/esm/hooks/features/dimensions/useGridDimensions.js +18 -188
- package/esm/hooks/features/editing/useGridRowEditing.js +4 -1
- package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -1
- package/esm/hooks/features/keyboardNavigation/utils.d.ts +3 -3
- package/esm/hooks/features/keyboardNavigation/utils.js +5 -5
- package/esm/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
- package/esm/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
- package/esm/hooks/features/pivoting/gridPivotingSelectors.js +1 -2
- package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +9 -0
- package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.js +1 -0
- package/esm/hooks/features/rowReorder/gridRowReorderSelector.d.ts +5 -0
- package/esm/hooks/features/rowReorder/gridRowReorderSelector.js +3 -0
- package/esm/hooks/features/rowSelection/useGridRowSelection.js +2 -2
- package/esm/hooks/features/rowSelection/utils.js +5 -0
- package/esm/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
- package/esm/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
- package/esm/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
- package/esm/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
- package/esm/hooks/features/rows/useGridRowSpanning.js +54 -85
- package/esm/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
- package/esm/hooks/features/rows/useGridRowsMeta.js +17 -187
- package/esm/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/esm/hooks/features/virtualization/index.d.ts +1 -0
- package/esm/hooks/features/virtualization/index.js +1 -0
- package/esm/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
- package/esm/hooks/features/virtualization/useGridVirtualization.js +41 -22
- package/esm/hooks/utils/index.d.ts +1 -1
- package/esm/hooks/utils/index.js +1 -1
- package/esm/hooks/utils/useFirstRender.d.ts +1 -1
- package/esm/hooks/utils/useFirstRender.js +1 -8
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +3 -1
- package/esm/internals/index.js +2 -1
- package/esm/internals/utils/getPinnedCellOffset.js +5 -0
- package/esm/locales/frFR.js +18 -21
- package/esm/locales/heIL.js +12 -12
- package/esm/locales/nnNO.js +96 -107
- package/esm/locales/plPL.js +22 -24
- package/esm/material/index.js +2 -2
- package/esm/models/api/gridApiCommon.d.ts +4 -1
- package/esm/models/api/gridColumnSpanning.d.ts +5 -11
- package/esm/models/gridStateCommunity.d.ts +2 -0
- package/esm/models/props/DataGridProps.d.ts +5 -0
- package/esm/utils/roundToDecimalPlaces.d.ts +1 -1
- package/esm/utils/roundToDecimalPlaces.js +1 -3
- package/hooks/core/useGridVirtualizer.d.ts +9 -0
- package/hooks/core/useGridVirtualizer.js +231 -0
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -3
- package/hooks/features/columns/useGridColumnSpanning.js +5 -91
- package/hooks/features/dataSource/models.d.ts +11 -2
- package/hooks/features/dataSource/useGridDataSourceBase.d.ts +1 -1
- package/hooks/features/dataSource/useGridDataSourceBase.js +10 -3
- package/hooks/features/dimensions/useGridDimensions.js +18 -188
- package/hooks/features/editing/useGridRowEditing.js +4 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -1
- package/hooks/features/keyboardNavigation/utils.d.ts +3 -3
- package/hooks/features/keyboardNavigation/utils.js +5 -5
- package/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
- package/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
- package/hooks/features/pivoting/gridPivotingSelectors.js +2 -3
- package/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +9 -0
- package/hooks/features/rowReorder/gridRowReorderInterfaces.js +5 -0
- package/hooks/features/rowReorder/gridRowReorderSelector.d.ts +5 -0
- package/hooks/features/rowReorder/gridRowReorderSelector.js +9 -0
- package/hooks/features/rowSelection/useGridRowSelection.js +2 -2
- package/hooks/features/rowSelection/utils.js +5 -0
- package/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
- package/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
- package/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
- package/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
- package/hooks/features/rows/useGridRowSpanning.js +54 -85
- package/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
- package/hooks/features/rows/useGridRowsMeta.js +15 -186
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/hooks/features/virtualization/index.d.ts +1 -0
- package/hooks/features/virtualization/index.js +12 -0
- package/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
- package/hooks/features/virtualization/useGridVirtualization.js +42 -24
- package/hooks/utils/index.d.ts +1 -1
- package/hooks/utils/index.js +12 -12
- package/hooks/utils/useFirstRender.d.ts +1 -1
- package/hooks/utils/useFirstRender.js +11 -11
- package/index.js +1 -1
- package/internals/index.d.ts +3 -1
- package/internals/index.js +12 -11
- package/internals/utils/getPinnedCellOffset.js +5 -0
- package/locales/frFR.js +18 -21
- package/locales/heIL.js +12 -12
- package/locales/nnNO.js +96 -107
- package/locales/plPL.js +22 -24
- package/material/index.js +2 -2
- package/models/api/gridApiCommon.d.ts +4 -1
- package/models/api/gridColumnSpanning.d.ts +5 -11
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/props/DataGridProps.d.ts +5 -0
- package/package.json +5 -6
- package/utils/roundToDecimalPlaces.d.ts +1 -1
- package/utils/roundToDecimalPlaces.js +7 -4
- package/esm/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
- package/esm/hooks/features/rows/gridRowSpanningSelectors.js +0 -5
- package/esm/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
- package/esm/hooks/features/virtualization/useGridVirtualScroller.js +0 -843
- package/esm/hooks/utils/useRunOnce.d.ts +0 -5
- package/esm/hooks/utils/useRunOnce.js +0 -18
- package/esm/utils/platform.d.ts +0 -1
- package/esm/utils/platform.js +0 -2
- package/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
- package/hooks/features/rows/gridRowSpanningSelectors.js +0 -11
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
- package/hooks/features/virtualization/useGridVirtualScroller.js +0 -854
- package/hooks/utils/useRunOnce.d.ts +0 -5
- package/hooks/utils/useRunOnce.js +0 -27
- package/utils/platform.d.ts +0 -1
- package/utils/platform.js +0 -8
|
@@ -9,18 +9,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
9
|
exports.useGridRowSpanning = exports.rowSpanningStateInitializer = void 0;
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
|
-
var
|
|
13
|
-
var _constants = require("../../../internals/constants");
|
|
12
|
+
var _features = require("@mui/x-virtualizer/features");
|
|
14
13
|
var _gridColumnsSelector = require("../columns/gridColumnsSelector");
|
|
15
14
|
var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
16
15
|
var _gridVirtualizationSelectors = require("../virtualization/gridVirtualizationSelectors");
|
|
17
16
|
var _gridRowSpanningUtils = require("./gridRowSpanningUtils");
|
|
18
|
-
var _gridCheckboxSelectionColDef = require("../../../colDef/gridCheckboxSelectionColDef");
|
|
19
17
|
var _useGridEvent = require("../../utils/useGridEvent");
|
|
20
18
|
var _utils = require("../../../utils/utils");
|
|
21
19
|
var _pagination = require("../pagination");
|
|
22
20
|
var _gridRowsSelector = require("./gridRowsSelector");
|
|
23
|
-
const
|
|
21
|
+
const EMPTY_CACHES = {
|
|
24
22
|
spannedCells: {},
|
|
25
23
|
hiddenCells: {},
|
|
26
24
|
hiddenCellOriginMap: {}
|
|
@@ -29,27 +27,31 @@ const EMPTY_RANGE = {
|
|
|
29
27
|
firstRowIndex: 0,
|
|
30
28
|
lastRowIndex: 0
|
|
31
29
|
};
|
|
32
|
-
const
|
|
30
|
+
const EMPTY_STATE = {
|
|
31
|
+
caches: EMPTY_CACHES,
|
|
32
|
+
processedRange: EMPTY_RANGE
|
|
33
|
+
};
|
|
34
|
+
|
|
33
35
|
/**
|
|
34
36
|
* Default number of rows to process during state initialization to avoid flickering.
|
|
35
37
|
* Number `20` is arbitrarily chosen to be large enough to cover most of the cases without
|
|
36
38
|
* compromising performance.
|
|
37
39
|
*/
|
|
38
40
|
const DEFAULT_ROWS_TO_PROCESS = 20;
|
|
39
|
-
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState) => {
|
|
42
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
43
|
+
const previousState = resetState ? EMPTY_STATE : _features.Rowspan.selectors.state(virtualizer.store.state);
|
|
44
|
+
const spannedCells = (0, _extends2.default)({}, previousState.caches.spannedCells);
|
|
45
|
+
const hiddenCells = (0, _extends2.default)({}, previousState.caches.hiddenCells);
|
|
46
|
+
const hiddenCellOriginMap = (0, _extends2.default)({}, previousState.caches.hiddenCellOriginMap);
|
|
47
|
+
const processedRange = {
|
|
48
|
+
firstRowIndex: Math.min(previousState.processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
49
|
+
lastRowIndex: Math.max(previousState.processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
50
|
+
};
|
|
51
|
+
colDefs.forEach((colDef, columnIndex) => {
|
|
50
52
|
for (let index = rangeToProcess.firstRowIndex; index < rangeToProcess.lastRowIndex; index += 1) {
|
|
51
53
|
const row = visibleRows[index];
|
|
52
|
-
if (hiddenCells[row.id]?.[
|
|
54
|
+
if (hiddenCells[row.id]?.[columnIndex]) {
|
|
53
55
|
continue;
|
|
54
56
|
}
|
|
55
57
|
const cellValue = (0, _gridRowSpanningUtils.getCellValue)(row.model, colDef, apiRef);
|
|
@@ -68,10 +70,10 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
68
70
|
while (prevIndex >= range.firstRowIndex && prevRowEntry && (0, _gridRowSpanningUtils.getCellValue)(prevRowEntry.model, colDef, apiRef) === cellValue) {
|
|
69
71
|
const currentRow = visibleRows[prevIndex + 1];
|
|
70
72
|
if (hiddenCells[currentRow.id]) {
|
|
71
|
-
hiddenCells[currentRow.id][
|
|
73
|
+
hiddenCells[currentRow.id][columnIndex] = true;
|
|
72
74
|
} else {
|
|
73
75
|
hiddenCells[currentRow.id] = {
|
|
74
|
-
[
|
|
76
|
+
[columnIndex]: true
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
backwardsHiddenCells.push(index);
|
|
@@ -84,10 +86,10 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
84
86
|
}
|
|
85
87
|
backwardsHiddenCells.forEach(hiddenCellIndex => {
|
|
86
88
|
if (hiddenCellOriginMap[hiddenCellIndex]) {
|
|
87
|
-
hiddenCellOriginMap[hiddenCellIndex][
|
|
89
|
+
hiddenCellOriginMap[hiddenCellIndex][columnIndex] = spannedRowIndex;
|
|
88
90
|
} else {
|
|
89
91
|
hiddenCellOriginMap[hiddenCellIndex] = {
|
|
90
|
-
[
|
|
92
|
+
[columnIndex]: spannedRowIndex
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
});
|
|
@@ -97,17 +99,17 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
97
99
|
while (relativeIndex <= range.lastRowIndex && visibleRows[relativeIndex] && (0, _gridRowSpanningUtils.getCellValue)(visibleRows[relativeIndex].model, colDef, apiRef) === cellValue) {
|
|
98
100
|
const currentRow = visibleRows[relativeIndex];
|
|
99
101
|
if (hiddenCells[currentRow.id]) {
|
|
100
|
-
hiddenCells[currentRow.id][
|
|
102
|
+
hiddenCells[currentRow.id][columnIndex] = true;
|
|
101
103
|
} else {
|
|
102
104
|
hiddenCells[currentRow.id] = {
|
|
103
|
-
[
|
|
105
|
+
[columnIndex]: true
|
|
104
106
|
};
|
|
105
107
|
}
|
|
106
108
|
if (hiddenCellOriginMap[relativeIndex]) {
|
|
107
|
-
hiddenCellOriginMap[relativeIndex][
|
|
109
|
+
hiddenCellOriginMap[relativeIndex][columnIndex] = spannedRowIndex;
|
|
108
110
|
} else {
|
|
109
111
|
hiddenCellOriginMap[relativeIndex] = {
|
|
110
|
-
[
|
|
112
|
+
[columnIndex]: spannedRowIndex
|
|
111
113
|
};
|
|
112
114
|
}
|
|
113
115
|
relativeIndex += 1;
|
|
@@ -115,23 +117,21 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
115
117
|
}
|
|
116
118
|
if (rowSpan > 0) {
|
|
117
119
|
if (spannedCells[spannedRowId]) {
|
|
118
|
-
spannedCells[spannedRowId][
|
|
120
|
+
spannedCells[spannedRowId][columnIndex] = rowSpan + 1;
|
|
119
121
|
} else {
|
|
120
122
|
spannedCells[spannedRowId] = {
|
|
121
|
-
[
|
|
123
|
+
[columnIndex]: rowSpan + 1
|
|
122
124
|
};
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
|
-
processedRange = {
|
|
127
|
-
firstRowIndex: Math.min(processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
128
|
-
lastRowIndex: Math.max(processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
129
|
-
};
|
|
130
128
|
});
|
|
131
129
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
caches: {
|
|
131
|
+
spannedCells,
|
|
132
|
+
hiddenCells,
|
|
133
|
+
hiddenCellOriginMap
|
|
134
|
+
},
|
|
135
135
|
processedRange
|
|
136
136
|
};
|
|
137
137
|
};
|
|
@@ -181,72 +181,43 @@ const rowSpanningStateInitializer = (state, props, apiRef) => {
|
|
|
181
181
|
model: dataRowIdToModelLookup[id]
|
|
182
182
|
}));
|
|
183
183
|
const colDefs = orderedFields.map(field => columnsLookup[field]);
|
|
184
|
-
const
|
|
185
|
-
spannedCells,
|
|
186
|
-
hiddenCells,
|
|
187
|
-
hiddenCellOriginMap
|
|
188
|
-
} = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true, EMPTY_RANGE);
|
|
184
|
+
const rowSpanning = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true);
|
|
189
185
|
return (0, _extends2.default)({}, state, {
|
|
190
|
-
rowSpanning
|
|
191
|
-
spannedCells,
|
|
192
|
-
hiddenCells,
|
|
193
|
-
hiddenCellOriginMap
|
|
194
|
-
}
|
|
186
|
+
rowSpanning
|
|
195
187
|
});
|
|
196
188
|
};
|
|
197
189
|
exports.rowSpanningStateInitializer = rowSpanningStateInitializer;
|
|
198
190
|
const useGridRowSpanning = (apiRef, props) => {
|
|
199
|
-
const
|
|
200
|
-
return apiRef.current.state.rowSpanning !== EMPTY_STATE ? getInitialRangeToProcess(props, apiRef) : EMPTY_RANGE;
|
|
201
|
-
});
|
|
191
|
+
const store = apiRef.current.virtualizer.store;
|
|
202
192
|
const updateRowSpanningState = React.useCallback((renderContext, resetState = false) => {
|
|
203
193
|
const {
|
|
204
194
|
range,
|
|
205
195
|
rows: visibleRows
|
|
206
|
-
} = (0, _useGridVisibleRows.getVisibleRows)(apiRef
|
|
207
|
-
pagination: props.pagination,
|
|
208
|
-
paginationMode: props.paginationMode
|
|
209
|
-
});
|
|
196
|
+
} = (0, _useGridVisibleRows.getVisibleRows)(apiRef);
|
|
210
197
|
if (range === null || !(0, _gridRowSpanningUtils.isRowContextInitialized)(renderContext)) {
|
|
211
198
|
return;
|
|
212
199
|
}
|
|
213
|
-
|
|
214
|
-
processedRange.current = EMPTY_RANGE;
|
|
215
|
-
}
|
|
200
|
+
const previousState = resetState ? EMPTY_STATE : _features.Rowspan.selectors.state(store.state);
|
|
216
201
|
const rangeToProcess = (0, _gridRowSpanningUtils.getUnprocessedRange)({
|
|
217
202
|
firstRowIndex: renderContext.firstRowIndex,
|
|
218
|
-
lastRowIndex: Math.min(renderContext.lastRowIndex, range.lastRowIndex + 1)
|
|
219
|
-
}, processedRange
|
|
203
|
+
lastRowIndex: Math.min(renderContext.lastRowIndex, range.lastRowIndex - range.firstRowIndex + 1)
|
|
204
|
+
}, previousState.processedRange);
|
|
220
205
|
if (rangeToProcess === null) {
|
|
221
206
|
return;
|
|
222
207
|
}
|
|
223
208
|
const colDefs = (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const newSpannedCellsCount = Object.keys(spannedCells).length;
|
|
232
|
-
const newHiddenCellsCount = Object.keys(hiddenCells).length;
|
|
233
|
-
const currentSpannedCellsCount = Object.keys(apiRef.current.state.rowSpanning.spannedCells).length;
|
|
234
|
-
const currentHiddenCellsCount = Object.keys(apiRef.current.state.rowSpanning.hiddenCells).length;
|
|
235
|
-
const shouldUpdateState = resetState || newSpannedCellsCount !== currentSpannedCellsCount || newHiddenCellsCount !== currentHiddenCellsCount;
|
|
236
|
-
const hasNoSpannedCells = newSpannedCellsCount === 0 && currentSpannedCellsCount === 0;
|
|
209
|
+
const newState = computeRowSpanningState(apiRef, colDefs, visibleRows, range, rangeToProcess, resetState);
|
|
210
|
+
const newSpannedCellsCount = Object.keys(newState.caches.spannedCells).length;
|
|
211
|
+
const newHiddenCellsCount = Object.keys(newState.caches.hiddenCells).length;
|
|
212
|
+
const previousSpannedCellsCount = Object.keys(previousState.caches.spannedCells).length;
|
|
213
|
+
const previousHiddenCellsCount = Object.keys(previousState.caches.hiddenCells).length;
|
|
214
|
+
const shouldUpdateState = resetState || newSpannedCellsCount !== previousSpannedCellsCount || newHiddenCellsCount !== previousHiddenCellsCount;
|
|
215
|
+
const hasNoSpannedCells = newSpannedCellsCount === 0 && previousSpannedCellsCount === 0;
|
|
237
216
|
if (!shouldUpdateState || hasNoSpannedCells) {
|
|
238
217
|
return;
|
|
239
218
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
rowSpanning: {
|
|
243
|
-
spannedCells,
|
|
244
|
-
hiddenCells,
|
|
245
|
-
hiddenCellOriginMap
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
}, [apiRef, processedRange, props.pagination, props.paginationMode]);
|
|
219
|
+
store.set('rowSpanning', newState);
|
|
220
|
+
}, [apiRef, store]);
|
|
250
221
|
|
|
251
222
|
// Reset events trigger a full re-computation of the row spanning state:
|
|
252
223
|
// - The `unstable_rowSpanning` prop is updated (feature flag)
|
|
@@ -268,14 +239,12 @@ const useGridRowSpanning = (apiRef, props) => {
|
|
|
268
239
|
(0, _useGridEvent.useGridEvent)(apiRef, 'columnsChange', (0, _utils.runIf)(props.rowSpanning, resetRowSpanningState));
|
|
269
240
|
React.useEffect(() => {
|
|
270
241
|
if (!props.rowSpanning) {
|
|
271
|
-
if (
|
|
272
|
-
|
|
273
|
-
rowSpanning: EMPTY_STATE
|
|
274
|
-
}));
|
|
242
|
+
if (store.state.rowSpanning !== EMPTY_STATE) {
|
|
243
|
+
store.set('rowSpanning', EMPTY_STATE);
|
|
275
244
|
}
|
|
276
|
-
} else if (
|
|
245
|
+
} else if (store.state.rowSpanning.caches === EMPTY_CACHES) {
|
|
277
246
|
resetRowSpanningState();
|
|
278
247
|
}
|
|
279
|
-
}, [apiRef, resetRowSpanningState, props.rowSpanning]);
|
|
248
|
+
}, [apiRef, store, resetRowSpanningState, props.rowSpanning]);
|
|
280
249
|
};
|
|
281
250
|
exports.useGridRowSpanning = useGridRowSpanning;
|
|
@@ -7,4 +7,4 @@ export declare const rowsMetaStateInitializer: GridStateInitializer;
|
|
|
7
7
|
* @requires useGridPageSize (method)
|
|
8
8
|
* @requires useGridPage (method)
|
|
9
9
|
*/
|
|
10
|
-
export declare const useGridRowsMeta: (apiRef: RefObject<GridPrivateApiCommunity>,
|
|
10
|
+
export declare const useGridRowsMeta: (apiRef: RefObject<GridPrivateApiCommunity>, _props: Pick<DataGridProcessedProps, "getRowHeight" | "getEstimatedRowHeight" | "getRowSpacing" | "pagination" | "paginationMode" | "rowHeight">) => void;
|
|
@@ -1,33 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.useGridRowsMeta = exports.rowsMetaStateInitializer = void 0;
|
|
9
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var React = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
12
|
-
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
13
|
-
var _ResizeObserver = require("../../../utils/ResizeObserver");
|
|
14
|
-
var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
15
|
-
var _utils = require("../../../utils/utils");
|
|
16
9
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
17
|
-
var _useGridSelector = require("../../utils/useGridSelector");
|
|
18
|
-
var _densitySelector = require("../density/densitySelector");
|
|
19
10
|
var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
|
|
20
11
|
var _pipeProcessing = require("../../core/pipeProcessing");
|
|
21
12
|
var _gridRowsSelector = require("./gridRowsSelector");
|
|
22
13
|
var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
|
|
23
|
-
var _gridRowsUtils = require("./gridRowsUtils");
|
|
24
|
-
var _gridFocusedVirtualCellSelector = require("../virtualization/gridFocusedVirtualCellSelector");
|
|
25
|
-
/* eslint-disable no-underscore-dangle */
|
|
26
|
-
|
|
27
14
|
const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
// FIXME: This should be handled in the virtualizer eventually, but there are interdependencies
|
|
16
|
+
// between state initializers that need to be untangled carefully.
|
|
17
|
+
|
|
31
18
|
const baseRowHeight = (0, _gridDimensionsSelectors.gridRowHeightSelector)(apiRef);
|
|
32
19
|
const dataRowCount = (0, _gridRowsSelector.gridRowCountSelector)(apiRef);
|
|
33
20
|
const pagination = (0, _gridPaginationSelector.gridPaginationSelector)(apiRef);
|
|
@@ -49,178 +36,20 @@ const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
|
49
36
|
* @requires useGridPage (method)
|
|
50
37
|
*/
|
|
51
38
|
exports.rowsMetaStateInitializer = rowsMetaStateInitializer;
|
|
52
|
-
const useGridRowsMeta = (apiRef,
|
|
39
|
+
const useGridRowsMeta = (apiRef, _props) => {
|
|
40
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
53
41
|
const {
|
|
54
|
-
getRowHeight
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
|
|
65
|
-
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridRowHeightSelector);
|
|
66
|
-
const getRowHeightEntry = rowId => {
|
|
67
|
-
let entry = heightCache.get(rowId);
|
|
68
|
-
if (entry === undefined) {
|
|
69
|
-
entry = {
|
|
70
|
-
content: rowHeight,
|
|
71
|
-
spacingTop: 0,
|
|
72
|
-
spacingBottom: 0,
|
|
73
|
-
detail: 0,
|
|
74
|
-
autoHeight: false,
|
|
75
|
-
needsFirstMeasurement: true
|
|
76
|
-
};
|
|
77
|
-
heightCache.set(rowId, entry);
|
|
78
|
-
}
|
|
79
|
-
return entry;
|
|
80
|
-
};
|
|
81
|
-
const processHeightEntry = React.useCallback(row => {
|
|
82
|
-
// HACK: rowHeight trails behind the most up-to-date value just enough to
|
|
83
|
-
// mess the initial rowsMeta hydration :/
|
|
84
|
-
const baseRowHeight = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef).rowHeight;
|
|
85
|
-
(0, _utils.eslintUseValue)(rowHeight);
|
|
86
|
-
const entry = apiRef.current.getRowHeightEntry(row.id);
|
|
87
|
-
if (!getRowHeightProp) {
|
|
88
|
-
entry.content = baseRowHeight;
|
|
89
|
-
entry.needsFirstMeasurement = false;
|
|
90
|
-
} else {
|
|
91
|
-
const rowHeightFromUser = getRowHeightProp((0, _extends2.default)({}, row, {
|
|
92
|
-
densityFactor
|
|
93
|
-
}));
|
|
94
|
-
if (rowHeightFromUser === 'auto') {
|
|
95
|
-
if (entry.needsFirstMeasurement) {
|
|
96
|
-
const estimatedRowHeight = getEstimatedRowHeight ? getEstimatedRowHeight((0, _extends2.default)({}, row, {
|
|
97
|
-
densityFactor
|
|
98
|
-
})) : baseRowHeight;
|
|
99
|
-
|
|
100
|
-
// If the row was not measured yet use the estimated row height
|
|
101
|
-
entry.content = estimatedRowHeight ?? baseRowHeight;
|
|
102
|
-
}
|
|
103
|
-
hasRowWithAutoHeight.current = true;
|
|
104
|
-
entry.autoHeight = true;
|
|
105
|
-
} else {
|
|
106
|
-
// Default back to base rowHeight if getRowHeight returns invalid value.
|
|
107
|
-
entry.content = (0, _gridRowsUtils.getValidRowHeight)(rowHeightFromUser, baseRowHeight, _gridRowsUtils.getRowHeightWarning);
|
|
108
|
-
entry.needsFirstMeasurement = false;
|
|
109
|
-
entry.autoHeight = false;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (getRowSpacing) {
|
|
113
|
-
const indexRelativeToCurrentPage = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
|
|
114
|
-
const spacing = getRowSpacing((0, _extends2.default)({}, row, {
|
|
115
|
-
isFirstVisible: indexRelativeToCurrentPage === 0,
|
|
116
|
-
isLastVisible: indexRelativeToCurrentPage === currentPage.rows.length - 1,
|
|
117
|
-
indexRelativeToCurrentPage
|
|
118
|
-
}));
|
|
119
|
-
entry.spacingTop = spacing.top ?? 0;
|
|
120
|
-
entry.spacingBottom = spacing.bottom ?? 0;
|
|
121
|
-
} else {
|
|
122
|
-
entry.spacingTop = 0;
|
|
123
|
-
entry.spacingBottom = 0;
|
|
124
|
-
}
|
|
125
|
-
apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row);
|
|
126
|
-
return entry;
|
|
127
|
-
}, [apiRef, currentPage.rows, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
|
|
128
|
-
const hydrateRowsMeta = React.useCallback(() => {
|
|
129
|
-
hasRowWithAutoHeight.current = false;
|
|
130
|
-
const pinnedTopRowsTotalHeight = pinnedRows.top.reduce((acc, row) => {
|
|
131
|
-
const entry = processHeightEntry(row);
|
|
132
|
-
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
133
|
-
}, 0);
|
|
134
|
-
const pinnedBottomRowsTotalHeight = pinnedRows.bottom.reduce((acc, row) => {
|
|
135
|
-
const entry = processHeightEntry(row);
|
|
136
|
-
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
137
|
-
}, 0);
|
|
138
|
-
const positions = [];
|
|
139
|
-
const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
|
|
140
|
-
positions.push(acc);
|
|
141
|
-
const entry = processHeightEntry(row);
|
|
142
|
-
const total = entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
143
|
-
return acc + total;
|
|
144
|
-
}, 0);
|
|
145
|
-
if (!hasRowWithAutoHeight.current) {
|
|
146
|
-
// No row has height=auto, so all rows are already measured
|
|
147
|
-
lastMeasuredRowIndex.current = Infinity;
|
|
148
|
-
}
|
|
149
|
-
const didHeightsChange = pinnedTopRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedTopRowsTotalHeight || pinnedBottomRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedBottomRowsTotalHeight || currentPageTotalHeight !== apiRef.current.state.rowsMeta.currentPageTotalHeight;
|
|
150
|
-
const rowsMeta = {
|
|
151
|
-
currentPageTotalHeight,
|
|
152
|
-
positions,
|
|
153
|
-
pinnedTopRowsTotalHeight,
|
|
154
|
-
pinnedBottomRowsTotalHeight
|
|
155
|
-
};
|
|
156
|
-
apiRef.current.setState(state => {
|
|
157
|
-
return (0, _extends2.default)({}, state, {
|
|
158
|
-
rowsMeta
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
if (didHeightsChange) {
|
|
162
|
-
apiRef.current.updateDimensions();
|
|
163
|
-
}
|
|
164
|
-
isHeightMetaValid.current = true;
|
|
165
|
-
}, [apiRef, pinnedRows, currentPage.rows, processHeightEntry]);
|
|
166
|
-
const getRowHeight = rowId => {
|
|
167
|
-
return heightCache.get(rowId)?.content ?? rowHeight;
|
|
168
|
-
};
|
|
169
|
-
const storeRowHeightMeasurement = (id, height) => {
|
|
170
|
-
const entry = apiRef.current.getRowHeightEntry(id);
|
|
171
|
-
const didChange = entry.content !== height;
|
|
172
|
-
entry.needsFirstMeasurement = false;
|
|
173
|
-
entry.content = height;
|
|
174
|
-
isHeightMetaValid.current && (isHeightMetaValid.current = !didChange);
|
|
175
|
-
};
|
|
176
|
-
const rowHasAutoHeight = id => {
|
|
177
|
-
return heightCache.get(id)?.autoHeight ?? false;
|
|
178
|
-
};
|
|
179
|
-
const getLastMeasuredRowIndex = () => {
|
|
180
|
-
return lastMeasuredRowIndex.current;
|
|
181
|
-
};
|
|
182
|
-
const setLastMeasuredRowIndex = index => {
|
|
183
|
-
if (hasRowWithAutoHeight.current && index > lastMeasuredRowIndex.current) {
|
|
184
|
-
lastMeasuredRowIndex.current = index;
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
const resetRowHeights = () => {
|
|
188
|
-
heightCache.clear();
|
|
189
|
-
hydrateRowsMeta();
|
|
190
|
-
};
|
|
191
|
-
const resizeObserver = (0, _useLazyRef.default)(() => new _ResizeObserver.ResizeObserver(entries => {
|
|
192
|
-
for (let i = 0; i < entries.length; i += 1) {
|
|
193
|
-
const entry = entries[i];
|
|
194
|
-
const height = entry.borderBoxSize && entry.borderBoxSize.length > 0 ? entry.borderBoxSize[0].blockSize : entry.contentRect.height;
|
|
195
|
-
const rowId = entry.target.__mui_id;
|
|
196
|
-
const focusedVirtualRowId = (0, _gridFocusedVirtualCellSelector.gridFocusedVirtualCellSelector)(apiRef)?.id;
|
|
197
|
-
if (focusedVirtualRowId === rowId && height === 0) {
|
|
198
|
-
// Focused virtual row has 0 height.
|
|
199
|
-
// We don't want to store it to avoid scroll jumping.
|
|
200
|
-
// https://github.com/mui/mui-x/issues/14726
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
apiRef.current.unstable_storeRowHeightMeasurement(rowId, height);
|
|
204
|
-
}
|
|
205
|
-
if (!isHeightMetaValid.current) {
|
|
206
|
-
// Avoids "ResizeObserver loop completed with undelivered notifications" error
|
|
207
|
-
requestAnimationFrame(() => {
|
|
208
|
-
apiRef.current.requestPipeProcessorsApplication('rowHeight');
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
})).current;
|
|
212
|
-
const observeRowHeight = (element, rowId) => {
|
|
213
|
-
element.__mui_id = rowId;
|
|
214
|
-
resizeObserver.observe(element);
|
|
215
|
-
return () => resizeObserver.unobserve(element);
|
|
216
|
-
};
|
|
42
|
+
getRowHeight,
|
|
43
|
+
setLastMeasuredRowIndex,
|
|
44
|
+
storeRowHeightMeasurement,
|
|
45
|
+
resetRowHeights,
|
|
46
|
+
hydrateRowsMeta,
|
|
47
|
+
observeRowHeight,
|
|
48
|
+
rowHasAutoHeight,
|
|
49
|
+
getRowHeightEntry,
|
|
50
|
+
getLastMeasuredRowIndex
|
|
51
|
+
} = virtualizer.api.rowsMeta;
|
|
217
52
|
(0, _pipeProcessing.useGridRegisterPipeApplier)(apiRef, 'rowHeight', hydrateRowsMeta);
|
|
218
|
-
|
|
219
|
-
// The effect is used to build the rows meta data - currentPageTotalHeight and positions.
|
|
220
|
-
// Because of variable row height this is needed for the virtualization
|
|
221
|
-
(0, _useEnhancedEffect.default)(() => {
|
|
222
|
-
hydrateRowsMeta();
|
|
223
|
-
}, [hydrateRowsMeta]);
|
|
224
53
|
const rowsMetaApi = {
|
|
225
54
|
unstable_getRowHeight: getRowHeight,
|
|
226
55
|
unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
|
|
@@ -34,7 +34,7 @@ export declare const gridVirtualizationRowEnabledSelector: (args_0: import("reac
|
|
|
34
34
|
*/
|
|
35
35
|
export declare const gridRenderContextSelector: (args_0: import("react").RefObject<{
|
|
36
36
|
state: GridStateCommunity;
|
|
37
|
-
} | null>) => import("@mui/x-
|
|
37
|
+
} | null>) => import("@mui/x-virtualizer/models").RenderContext;
|
|
38
38
|
/**
|
|
39
39
|
* Get the render context, with only columns filled in.
|
|
40
40
|
* This is cached, so it can be used to only re-render when the column interval changes.
|
|
@@ -3,9 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
EMPTY_RENDER_CONTEXT: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "EMPTY_RENDER_CONTEXT", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _xVirtualizer.EMPTY_RENDER_CONTEXT;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
var _xVirtualizer = require("@mui/x-virtualizer");
|
|
6
16
|
var _useGridVirtualization = require("./useGridVirtualization");
|
|
7
17
|
Object.keys(_useGridVirtualization).forEach(function (key) {
|
|
8
18
|
if (key === "default" || key === "__esModule") return;
|
|
19
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
9
20
|
if (key in exports && exports[key] === _useGridVirtualization[key]) return;
|
|
10
21
|
Object.defineProperty(exports, key, {
|
|
11
22
|
enumerable: true,
|
|
@@ -17,6 +28,7 @@ Object.keys(_useGridVirtualization).forEach(function (key) {
|
|
|
17
28
|
var _gridVirtualizationSelectors = require("./gridVirtualizationSelectors");
|
|
18
29
|
Object.keys(_gridVirtualizationSelectors).forEach(function (key) {
|
|
19
30
|
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
32
|
if (key in exports && exports[key] === _gridVirtualizationSelectors[key]) return;
|
|
21
33
|
Object.defineProperty(exports, key, {
|
|
22
34
|
enumerable: true,
|
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
-
import {
|
|
2
|
+
import { Virtualization } from '@mui/x-virtualizer';
|
|
3
3
|
import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
|
-
import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
|
|
5
4
|
import { GridStateInitializer } from "../../utils/useGridInitializeState.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
enabledForColumns: boolean;
|
|
10
|
-
enabledForRows: boolean;
|
|
11
|
-
renderContext: GridRenderContext;
|
|
12
|
-
};
|
|
13
|
-
export declare const EMPTY_RENDER_CONTEXT: {
|
|
14
|
-
firstRowIndex: number;
|
|
15
|
-
lastRowIndex: number;
|
|
16
|
-
firstColumnIndex: number;
|
|
17
|
-
lastColumnIndex: number;
|
|
18
|
-
};
|
|
5
|
+
import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
|
|
6
|
+
type RootProps = DataGridProcessedProps;
|
|
7
|
+
export type GridVirtualizationState = { [K in keyof Virtualization.State['virtualization']]: Virtualization.State['virtualization'][K] };
|
|
19
8
|
export declare const virtualizationStateInitializer: GridStateInitializer<RootProps>;
|
|
20
|
-
export declare function useGridVirtualization(apiRef: RefObject<GridPrivateApiCommunity>,
|
|
9
|
+
export declare function useGridVirtualization(apiRef: RefObject<GridPrivateApiCommunity>, rootProps: RootProps): void;
|
|
21
10
|
export {};
|