@mui/x-data-grid 7.17.0 → 7.18.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 +98 -5
- package/DataGrid/DataGrid.js +11 -1
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +2 -1
- package/components/GridRow.js +1 -0
- package/components/cell/GridCell.js +30 -5
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +0 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/hooks/features/dimensions/gridDimensionsApi.d.ts +4 -0
- package/hooks/features/dimensions/useGridDimensions.d.ts +1 -1
- package/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/hooks/features/editing/useGridCellEditing.js +2 -18
- package/hooks/features/editing/useGridRowEditing.js +6 -1
- package/hooks/features/editing/utils.d.ts +2 -0
- package/hooks/features/editing/utils.js +15 -0
- package/hooks/features/export/useGridPrintExport.js +2 -1
- package/hooks/features/focus/useGridFocus.js +2 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +10 -46
- package/hooks/features/keyboardNavigation/utils.d.ts +17 -0
- package/hooks/features/keyboardNavigation/utils.js +58 -0
- package/hooks/features/rows/gridRowSpanningSelectors.d.ts +4 -0
- package/hooks/features/rows/gridRowSpanningSelectors.js +5 -0
- package/hooks/features/rows/gridRowSpanningUtils.d.ts +10 -0
- package/hooks/features/rows/gridRowSpanningUtils.js +42 -0
- package/hooks/features/rows/useGridRowSpanning.d.ts +27 -0
- package/hooks/features/rows/useGridRowSpanning.js +257 -0
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +17 -7
- package/hooks/utils/useGridApiEventHandler.js +0 -1
- package/index.js +1 -1
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/models/colDef/gridColDef.d.ts +4 -0
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/props/DataGridProps.d.ts +10 -0
- package/modern/DataGrid/DataGrid.js +11 -1
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +2 -1
- package/modern/components/GridRow.js +1 -0
- package/modern/components/cell/GridCell.js +30 -5
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/modern/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/modern/hooks/features/editing/useGridCellEditing.js +2 -18
- package/modern/hooks/features/editing/useGridRowEditing.js +6 -1
- package/modern/hooks/features/editing/utils.js +15 -0
- package/modern/hooks/features/export/useGridPrintExport.js +2 -1
- package/modern/hooks/features/focus/useGridFocus.js +2 -1
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +10 -46
- package/modern/hooks/features/keyboardNavigation/utils.js +58 -0
- package/modern/hooks/features/rows/gridRowSpanningSelectors.js +5 -0
- package/modern/hooks/features/rows/gridRowSpanningUtils.js +42 -0
- package/modern/hooks/features/rows/useGridRowSpanning.js +257 -0
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +17 -7
- package/modern/hooks/utils/useGridApiEventHandler.js +0 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -0
- package/modern/utils/domUtils.js +12 -12
- package/node/DataGrid/DataGrid.js +11 -1
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +2 -1
- package/node/components/GridRow.js +1 -0
- package/node/components/cell/GridCell.js +30 -5
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/node/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/node/hooks/features/editing/useGridCellEditing.js +2 -18
- package/node/hooks/features/editing/useGridRowEditing.js +6 -1
- package/node/hooks/features/editing/utils.js +22 -0
- package/node/hooks/features/export/useGridPrintExport.js +2 -1
- package/node/hooks/features/focus/useGridFocus.js +2 -1
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +16 -53
- package/node/hooks/features/keyboardNavigation/utils.js +68 -0
- package/node/hooks/features/rows/gridRowSpanningSelectors.js +11 -0
- package/node/hooks/features/rows/gridRowSpanningUtils.js +52 -0
- package/node/hooks/features/rows/useGridRowSpanning.js +267 -0
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +17 -7
- package/node/hooks/utils/useGridApiEventHandler.js +0 -1
- package/node/index.js +1 -1
- package/node/internals/index.js +15 -0
- package/node/utils/domUtils.js +12 -12
- package/package.json +3 -3
- package/utils/domUtils.d.ts +4 -4
- package/utils/domUtils.js +12 -12
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useGridRowSpanning = exports.rowSpanningStateInitializer = void 0;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
12
|
+
var _gridColumnsSelector = require("../columns/gridColumnsSelector");
|
|
13
|
+
var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
14
|
+
var _gridVirtualizationSelectors = require("../virtualization/gridVirtualizationSelectors");
|
|
15
|
+
var _useGridSelector = require("../../utils/useGridSelector");
|
|
16
|
+
var _gridRowSpanningUtils = require("./gridRowSpanningUtils");
|
|
17
|
+
const EMPTY_STATE = {
|
|
18
|
+
spannedCells: {},
|
|
19
|
+
hiddenCells: {},
|
|
20
|
+
hiddenCellOriginMap: {}
|
|
21
|
+
};
|
|
22
|
+
const EMPTY_RANGE = {
|
|
23
|
+
firstRowIndex: 0,
|
|
24
|
+
lastRowIndex: 0
|
|
25
|
+
};
|
|
26
|
+
const skippedFields = new Set(['__check__', '__reorder__', '__detail_panel_toggle__']);
|
|
27
|
+
/**
|
|
28
|
+
* Default number of rows to process during state initialization to avoid flickering.
|
|
29
|
+
* Number `20` is arbitrarily chosen to be large enough to cover most of the cases without
|
|
30
|
+
* compromising performance.
|
|
31
|
+
*/
|
|
32
|
+
const DEFAULT_ROWS_TO_PROCESS = 20;
|
|
33
|
+
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState, processedRange) => {
|
|
34
|
+
const spannedCells = resetState ? {} : (0, _extends2.default)({}, apiRef.current.state.rowSpanning.spannedCells);
|
|
35
|
+
const hiddenCells = resetState ? {} : (0, _extends2.default)({}, apiRef.current.state.rowSpanning.hiddenCells);
|
|
36
|
+
const hiddenCellOriginMap = resetState ? {} : (0, _extends2.default)({}, apiRef.current.state.rowSpanning.hiddenCellOriginMap);
|
|
37
|
+
if (resetState) {
|
|
38
|
+
processedRange = EMPTY_RANGE;
|
|
39
|
+
}
|
|
40
|
+
colDefs.forEach(colDef => {
|
|
41
|
+
if (skippedFields.has(colDef.field)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (let index = rangeToProcess.firstRowIndex; index <= rangeToProcess.lastRowIndex; index += 1) {
|
|
45
|
+
const row = visibleRows[index];
|
|
46
|
+
if (hiddenCells[row.id]?.[colDef.field]) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const cellValue = (0, _gridRowSpanningUtils.getCellValue)(row.model, colDef, apiRef);
|
|
50
|
+
if (cellValue == null) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let spannedRowId = row.id;
|
|
54
|
+
let spannedRowIndex = index;
|
|
55
|
+
let rowSpan = 0;
|
|
56
|
+
|
|
57
|
+
// For first index, also scan in the previous rows to handle the reset state case e.g by sorting
|
|
58
|
+
const backwardsHiddenCells = [];
|
|
59
|
+
if (index === rangeToProcess.firstRowIndex) {
|
|
60
|
+
let prevIndex = index - 1;
|
|
61
|
+
const prevRowEntry = visibleRows[prevIndex];
|
|
62
|
+
while (prevIndex >= range.firstRowIndex && (0, _gridRowSpanningUtils.getCellValue)(prevRowEntry.model, colDef, apiRef) === cellValue) {
|
|
63
|
+
const currentRow = visibleRows[prevIndex + 1];
|
|
64
|
+
if (hiddenCells[currentRow.id]) {
|
|
65
|
+
hiddenCells[currentRow.id][colDef.field] = true;
|
|
66
|
+
} else {
|
|
67
|
+
hiddenCells[currentRow.id] = {
|
|
68
|
+
[colDef.field]: true
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
backwardsHiddenCells.push(index);
|
|
72
|
+
rowSpan += 1;
|
|
73
|
+
spannedRowId = prevRowEntry.id;
|
|
74
|
+
spannedRowIndex = prevIndex;
|
|
75
|
+
prevIndex -= 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
backwardsHiddenCells.forEach(hiddenCellIndex => {
|
|
79
|
+
if (hiddenCellOriginMap[hiddenCellIndex]) {
|
|
80
|
+
hiddenCellOriginMap[hiddenCellIndex][colDef.field] = spannedRowIndex;
|
|
81
|
+
} else {
|
|
82
|
+
hiddenCellOriginMap[hiddenCellIndex] = {
|
|
83
|
+
[colDef.field]: spannedRowIndex
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Scan the next rows
|
|
89
|
+
let relativeIndex = index + 1;
|
|
90
|
+
while (relativeIndex <= range.lastRowIndex && visibleRows[relativeIndex] && (0, _gridRowSpanningUtils.getCellValue)(visibleRows[relativeIndex].model, colDef, apiRef) === cellValue) {
|
|
91
|
+
const currentRow = visibleRows[relativeIndex];
|
|
92
|
+
if (hiddenCells[currentRow.id]) {
|
|
93
|
+
hiddenCells[currentRow.id][colDef.field] = true;
|
|
94
|
+
} else {
|
|
95
|
+
hiddenCells[currentRow.id] = {
|
|
96
|
+
[colDef.field]: true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (hiddenCellOriginMap[relativeIndex]) {
|
|
100
|
+
hiddenCellOriginMap[relativeIndex][colDef.field] = spannedRowIndex;
|
|
101
|
+
} else {
|
|
102
|
+
hiddenCellOriginMap[relativeIndex] = {
|
|
103
|
+
[colDef.field]: spannedRowIndex
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
relativeIndex += 1;
|
|
107
|
+
rowSpan += 1;
|
|
108
|
+
}
|
|
109
|
+
if (rowSpan > 0) {
|
|
110
|
+
if (spannedCells[spannedRowId]) {
|
|
111
|
+
spannedCells[spannedRowId][colDef.field] = rowSpan + 1;
|
|
112
|
+
} else {
|
|
113
|
+
spannedCells[spannedRowId] = {
|
|
114
|
+
[colDef.field]: rowSpan + 1
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
processedRange = {
|
|
120
|
+
firstRowIndex: Math.min(processedRange.firstRowIndex, rangeToProcess.firstRowIndex),
|
|
121
|
+
lastRowIndex: Math.max(processedRange.lastRowIndex, rangeToProcess.lastRowIndex)
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
spannedCells,
|
|
126
|
+
hiddenCells,
|
|
127
|
+
hiddenCellOriginMap,
|
|
128
|
+
processedRange
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @requires columnsStateInitializer (method) - should be initialized before
|
|
134
|
+
* @requires rowsStateInitializer (method) - should be initialized before
|
|
135
|
+
* @requires filterStateInitializer (method) - should be initialized before
|
|
136
|
+
*/
|
|
137
|
+
const rowSpanningStateInitializer = (state, props, apiRef) => {
|
|
138
|
+
if (props.unstable_rowSpanning) {
|
|
139
|
+
const rowIds = state.rows.dataRowIds || [];
|
|
140
|
+
const orderedFields = state.columns.orderedFields || [];
|
|
141
|
+
const dataRowIdToModelLookup = state.rows.dataRowIdToModelLookup;
|
|
142
|
+
const columnsLookup = state.columns.lookup;
|
|
143
|
+
const isFilteringPending = Boolean(state.filter.filterModel.items.length) || Boolean(state.filter.filterModel.quickFilterValues?.length);
|
|
144
|
+
if (!rowIds.length || !orderedFields.length || !dataRowIdToModelLookup || !columnsLookup || isFilteringPending) {
|
|
145
|
+
return (0, _extends2.default)({}, state, {
|
|
146
|
+
rowSpanning: EMPTY_STATE
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const rangeToProcess = {
|
|
150
|
+
firstRowIndex: 0,
|
|
151
|
+
lastRowIndex: Math.min(DEFAULT_ROWS_TO_PROCESS - 1, Math.max(rowIds.length - 1, 0))
|
|
152
|
+
};
|
|
153
|
+
const rows = rowIds.map(id => ({
|
|
154
|
+
id,
|
|
155
|
+
model: dataRowIdToModelLookup[id]
|
|
156
|
+
}));
|
|
157
|
+
const colDefs = orderedFields.map(field => columnsLookup[field]);
|
|
158
|
+
const {
|
|
159
|
+
spannedCells,
|
|
160
|
+
hiddenCells,
|
|
161
|
+
hiddenCellOriginMap
|
|
162
|
+
} = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true, EMPTY_RANGE);
|
|
163
|
+
return (0, _extends2.default)({}, state, {
|
|
164
|
+
rowSpanning: {
|
|
165
|
+
spannedCells,
|
|
166
|
+
hiddenCells,
|
|
167
|
+
hiddenCellOriginMap
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return (0, _extends2.default)({}, state, {
|
|
172
|
+
rowSpanning: EMPTY_STATE
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
exports.rowSpanningStateInitializer = rowSpanningStateInitializer;
|
|
176
|
+
const useGridRowSpanning = (apiRef, props) => {
|
|
177
|
+
const {
|
|
178
|
+
range,
|
|
179
|
+
rows: visibleRows
|
|
180
|
+
} = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, props);
|
|
181
|
+
const renderContext = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridRenderContextSelector);
|
|
182
|
+
const colDefs = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector);
|
|
183
|
+
const processedRange = (0, _useLazyRef.default)(() => {
|
|
184
|
+
return Object.keys(apiRef.current.state.rowSpanning.spannedCells).length > 0 ? {
|
|
185
|
+
firstRowIndex: 0,
|
|
186
|
+
lastRowIndex: Math.min(DEFAULT_ROWS_TO_PROCESS - 1, Math.max(apiRef.current.state.rows.dataRowIds.length - 1, 0))
|
|
187
|
+
} : EMPTY_RANGE;
|
|
188
|
+
});
|
|
189
|
+
const lastRange = React.useRef(EMPTY_RANGE);
|
|
190
|
+
const updateRowSpanningState = React.useCallback(
|
|
191
|
+
// A reset needs to occur when:
|
|
192
|
+
// - The `unstable_rowSpanning` prop is updated (feature flag)
|
|
193
|
+
// - The filtering is applied
|
|
194
|
+
// - The sorting is applied
|
|
195
|
+
// - The `paginationModel` is updated
|
|
196
|
+
// - The rows are updated
|
|
197
|
+
(resetState = true) => {
|
|
198
|
+
if (!props.unstable_rowSpanning) {
|
|
199
|
+
if (apiRef.current.state.rowSpanning !== EMPTY_STATE) {
|
|
200
|
+
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
201
|
+
rowSpanning: EMPTY_STATE
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (range === null || !(0, _gridRowSpanningUtils.isRowContextInitialized)(renderContext)) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (resetState) {
|
|
210
|
+
processedRange.current = EMPTY_RANGE;
|
|
211
|
+
}
|
|
212
|
+
const rangeToProcess = (0, _gridRowSpanningUtils.getUnprocessedRange)({
|
|
213
|
+
firstRowIndex: renderContext.firstRowIndex,
|
|
214
|
+
lastRowIndex: renderContext.lastRowIndex - 1
|
|
215
|
+
}, processedRange.current);
|
|
216
|
+
if (rangeToProcess === null) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const {
|
|
220
|
+
spannedCells,
|
|
221
|
+
hiddenCells,
|
|
222
|
+
hiddenCellOriginMap,
|
|
223
|
+
processedRange: newProcessedRange
|
|
224
|
+
} = computeRowSpanningState(apiRef, colDefs, visibleRows, range, rangeToProcess, resetState, processedRange.current);
|
|
225
|
+
processedRange.current = newProcessedRange;
|
|
226
|
+
const newSpannedCellsCount = Object.keys(spannedCells).length;
|
|
227
|
+
const newHiddenCellsCount = Object.keys(hiddenCells).length;
|
|
228
|
+
const currentSpannedCellsCount = Object.keys(apiRef.current.state.rowSpanning.spannedCells).length;
|
|
229
|
+
const currentHiddenCellsCount = Object.keys(apiRef.current.state.rowSpanning.hiddenCells).length;
|
|
230
|
+
const shouldUpdateState = resetState || newSpannedCellsCount !== currentSpannedCellsCount || newHiddenCellsCount !== currentHiddenCellsCount;
|
|
231
|
+
if (!shouldUpdateState) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
apiRef.current.setState(state => {
|
|
235
|
+
return (0, _extends2.default)({}, state, {
|
|
236
|
+
rowSpanning: {
|
|
237
|
+
spannedCells,
|
|
238
|
+
hiddenCells,
|
|
239
|
+
hiddenCellOriginMap
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}, [apiRef, props.unstable_rowSpanning, range, renderContext, visibleRows, colDefs, processedRange]);
|
|
244
|
+
const prevRenderContext = React.useRef(renderContext);
|
|
245
|
+
const isFirstRender = React.useRef(true);
|
|
246
|
+
const shouldResetState = React.useRef(false);
|
|
247
|
+
React.useEffect(() => {
|
|
248
|
+
const firstRender = isFirstRender.current;
|
|
249
|
+
if (isFirstRender.current) {
|
|
250
|
+
isFirstRender.current = false;
|
|
251
|
+
}
|
|
252
|
+
if (range && lastRange.current && (0, _gridRowSpanningUtils.isRowRangeUpdated)(range, lastRange.current)) {
|
|
253
|
+
lastRange.current = range;
|
|
254
|
+
shouldResetState.current = true;
|
|
255
|
+
}
|
|
256
|
+
if (!firstRender && prevRenderContext.current !== renderContext) {
|
|
257
|
+
if ((0, _gridRowSpanningUtils.isRowRangeUpdated)(prevRenderContext.current, renderContext)) {
|
|
258
|
+
updateRowSpanningState(shouldResetState.current);
|
|
259
|
+
shouldResetState.current = false;
|
|
260
|
+
}
|
|
261
|
+
prevRenderContext.current = renderContext;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
updateRowSpanningState();
|
|
265
|
+
}, [updateRowSpanningState, renderContext, range, lastRange]);
|
|
266
|
+
};
|
|
267
|
+
exports.useGridRowSpanning = useGridRowSpanning;
|
|
@@ -35,6 +35,7 @@ var _gridColumnsUtils = require("../columns/gridColumnsUtils");
|
|
|
35
35
|
var _gridRowsUtils = require("../rows/gridRowsUtils");
|
|
36
36
|
var _gridVirtualizationSelectors = require("./gridVirtualizationSelectors");
|
|
37
37
|
var _useGridVirtualization = require("./useGridVirtualization");
|
|
38
|
+
var _gridRowSpanningSelectors = require("../rows/gridRowSpanningSelectors");
|
|
38
39
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
39
40
|
const MINIMUM_COLUMN_WIDTH = 50;
|
|
40
41
|
var ScrollDirection = /*#__PURE__*/function (ScrollDirection) {
|
|
@@ -336,7 +337,7 @@ const useGridVirtualScroller = () => {
|
|
|
336
337
|
if (!isPinnedSection && frozenContext.current && rowIndexInPage >= frozenContext.current.firstRowIndex && rowIndexInPage < frozenContext.current.lastRowIndex) {
|
|
337
338
|
currentRenderContext = frozenContext.current;
|
|
338
339
|
}
|
|
339
|
-
const offsetLeft = computeOffsetLeft(columnPositions, currentRenderContext,
|
|
340
|
+
const offsetLeft = computeOffsetLeft(columnPositions, currentRenderContext, pinnedColumns.left.length);
|
|
340
341
|
const showBottomBorder = isLastVisibleInSection && params.position === 'top';
|
|
341
342
|
rows.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.row, (0, _extends2.default)({
|
|
342
343
|
row: model,
|
|
@@ -364,7 +365,7 @@ const useGridVirtualScroller = () => {
|
|
|
364
365
|
if (panel) {
|
|
365
366
|
rows.push(panel);
|
|
366
367
|
}
|
|
367
|
-
if (
|
|
368
|
+
if (params.position === undefined && isLastVisibleInSection) {
|
|
368
369
|
rows.push(apiRef.current.getInfiniteLoadingTriggerElement?.({
|
|
369
370
|
lastRowId: id
|
|
370
371
|
}));
|
|
@@ -459,6 +460,7 @@ function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
|
|
|
459
460
|
const dimensions = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state);
|
|
460
461
|
const currentPage = (0, _useGridVisibleRows.getVisibleRows)(apiRef, rootProps);
|
|
461
462
|
const visibleColumns = (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef);
|
|
463
|
+
const hiddenCellsOriginMap = (0, _gridRowSpanningSelectors.gridRowSpanningHiddenCellsOriginMapSelector)(apiRef);
|
|
462
464
|
const lastRowId = apiRef.current.state.rows.dataRowIds.at(-1);
|
|
463
465
|
const lastColumn = visibleColumns.at(-1);
|
|
464
466
|
return {
|
|
@@ -479,7 +481,8 @@ function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
|
|
|
479
481
|
rows: currentPage.rows,
|
|
480
482
|
range: currentPage.range,
|
|
481
483
|
pinnedColumns: (0, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector)(apiRef),
|
|
482
|
-
visibleColumns
|
|
484
|
+
visibleColumns,
|
|
485
|
+
hiddenCellsOriginMap
|
|
483
486
|
};
|
|
484
487
|
}
|
|
485
488
|
function computeRenderContext(inputs, scrollPosition, scrollCache) {
|
|
@@ -497,10 +500,18 @@ function computeRenderContext(inputs, scrollPosition, scrollCache) {
|
|
|
497
500
|
if (inputs.enabledForRows) {
|
|
498
501
|
// Clamp the value because the search may return an index out of bounds.
|
|
499
502
|
// In the last index, this is not needed because Array.slice doesn't include it.
|
|
500
|
-
|
|
503
|
+
let firstRowIndex = Math.min(getNearestIndexToRender(inputs, top, {
|
|
501
504
|
atStart: true,
|
|
502
505
|
lastPosition: inputs.rowsMeta.positions[inputs.rowsMeta.positions.length - 1] + inputs.lastRowHeight
|
|
503
506
|
}), inputs.rowsMeta.positions.length - 1);
|
|
507
|
+
|
|
508
|
+
// If any of the cells in the `firstRowIndex` is hidden due to an extended row span,
|
|
509
|
+
// Make sure the row from where the rowSpan is originated is visible.
|
|
510
|
+
const rowSpanHiddenCellOrigin = inputs.hiddenCellsOriginMap[firstRowIndex];
|
|
511
|
+
if (rowSpanHiddenCellOrigin) {
|
|
512
|
+
const minSpannedRowIndex = Math.min(...Object.values(rowSpanHiddenCellOrigin));
|
|
513
|
+
firstRowIndex = Math.min(firstRowIndex, minSpannedRowIndex);
|
|
514
|
+
}
|
|
504
515
|
const lastRowIndex = inputs.autoHeight ? firstRowIndex + inputs.rows.length : getNearestIndexToRender(inputs, top + inputs.viewportInnerHeight);
|
|
505
516
|
renderContext.firstRowIndex = firstRowIndex;
|
|
506
517
|
renderContext.lastRowIndex = lastRowIndex;
|
|
@@ -654,9 +665,8 @@ function areRenderContextsEqual(context1, context2) {
|
|
|
654
665
|
}
|
|
655
666
|
return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
|
|
656
667
|
}
|
|
657
|
-
function computeOffsetLeft(columnPositions, renderContext,
|
|
658
|
-
const
|
|
659
|
-
const left = factor * (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
|
|
668
|
+
function computeOffsetLeft(columnPositions, renderContext, pinnedLeftLength) {
|
|
669
|
+
const left = (columnPositions[renderContext.firstColumnIndex] ?? 0) - (columnPositions[pinnedLeftLength] ?? 0);
|
|
660
670
|
return Math.abs(left);
|
|
661
671
|
}
|
|
662
672
|
function directionForDelta(dx, dy) {
|
|
@@ -101,6 +101,5 @@ const optionsSubscriberOptions = {
|
|
|
101
101
|
isFirst: true
|
|
102
102
|
};
|
|
103
103
|
function useGridApiOptionHandler(apiRef, eventName, handler) {
|
|
104
|
-
// Validate that only one per event name?
|
|
105
104
|
useGridApiEventHandler(apiRef, eventName, handler, optionsSubscriberOptions);
|
|
106
105
|
}
|
package/node/index.js
CHANGED
package/node/internals/index.js
CHANGED
|
@@ -48,6 +48,8 @@ var _exportNames = {
|
|
|
48
48
|
gridEditRowsStateSelector: true,
|
|
49
49
|
useGridRows: true,
|
|
50
50
|
rowsStateInitializer: true,
|
|
51
|
+
useGridRowSpanning: true,
|
|
52
|
+
rowSpanningStateInitializer: true,
|
|
51
53
|
useGridAriaAttributes: true,
|
|
52
54
|
useGridRowAriaAttributes: true,
|
|
53
55
|
useGridRowsPreProcessors: true,
|
|
@@ -398,6 +400,12 @@ Object.defineProperty(exports, "rowSelectionStateInitializer", {
|
|
|
398
400
|
return _useGridRowSelection.rowSelectionStateInitializer;
|
|
399
401
|
}
|
|
400
402
|
});
|
|
403
|
+
Object.defineProperty(exports, "rowSpanningStateInitializer", {
|
|
404
|
+
enumerable: true,
|
|
405
|
+
get: function () {
|
|
406
|
+
return _useGridRowSpanning.rowSpanningStateInitializer;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
401
409
|
Object.defineProperty(exports, "rowsMetaStateInitializer", {
|
|
402
410
|
enumerable: true,
|
|
403
411
|
get: function () {
|
|
@@ -596,6 +604,12 @@ Object.defineProperty(exports, "useGridRowSelectionPreProcessors", {
|
|
|
596
604
|
return _useGridRowSelectionPreProcessors.useGridRowSelectionPreProcessors;
|
|
597
605
|
}
|
|
598
606
|
});
|
|
607
|
+
Object.defineProperty(exports, "useGridRowSpanning", {
|
|
608
|
+
enumerable: true,
|
|
609
|
+
get: function () {
|
|
610
|
+
return _useGridRowSpanning.useGridRowSpanning;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
599
613
|
Object.defineProperty(exports, "useGridRows", {
|
|
600
614
|
enumerable: true,
|
|
601
615
|
get: function () {
|
|
@@ -723,6 +737,7 @@ var _useGridPreferencesPanel = require("../hooks/features/preferencesPanel/useGr
|
|
|
723
737
|
var _useGridEditing = require("../hooks/features/editing/useGridEditing");
|
|
724
738
|
var _gridEditingSelectors = require("../hooks/features/editing/gridEditingSelectors");
|
|
725
739
|
var _useGridRows = require("../hooks/features/rows/useGridRows");
|
|
740
|
+
var _useGridRowSpanning = require("../hooks/features/rows/useGridRowSpanning");
|
|
726
741
|
var _useGridAriaAttributes = require("../hooks/utils/useGridAriaAttributes");
|
|
727
742
|
var _useGridRowAriaAttributes = require("../hooks/features/rows/useGridRowAriaAttributes");
|
|
728
743
|
var _useGridRowsPreProcessors = require("../hooks/features/rows/useGridRowsPreProcessors");
|
package/node/utils/domUtils.js
CHANGED
|
@@ -146,22 +146,22 @@ const findPinnedCells = ({
|
|
|
146
146
|
});
|
|
147
147
|
return cells;
|
|
148
148
|
};
|
|
149
|
-
function findLeftPinnedCellsAfterCol(api, col) {
|
|
149
|
+
function findLeftPinnedCellsAfterCol(api, col, isRtl) {
|
|
150
150
|
const colIndex = parseCellColIndex(col);
|
|
151
151
|
return findPinnedCells({
|
|
152
152
|
api,
|
|
153
153
|
colIndex,
|
|
154
|
-
position: 'left',
|
|
155
|
-
filterFn: index => index > colIndex
|
|
154
|
+
position: isRtl ? 'right' : 'left',
|
|
155
|
+
filterFn: index => isRtl ? index < colIndex : index > colIndex
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
function findRightPinnedCellsBeforeCol(api, col) {
|
|
158
|
+
function findRightPinnedCellsBeforeCol(api, col, isRtl) {
|
|
159
159
|
const colIndex = parseCellColIndex(col);
|
|
160
160
|
return findPinnedCells({
|
|
161
161
|
api,
|
|
162
162
|
colIndex,
|
|
163
|
-
position: 'right',
|
|
164
|
-
filterFn: index => index < colIndex
|
|
163
|
+
position: isRtl ? 'left' : 'right',
|
|
164
|
+
filterFn: index => isRtl ? index > colIndex : index < colIndex
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
const findPinnedHeaders = ({
|
|
@@ -185,22 +185,22 @@ const findPinnedHeaders = ({
|
|
|
185
185
|
});
|
|
186
186
|
return elements;
|
|
187
187
|
};
|
|
188
|
-
function findLeftPinnedHeadersAfterCol(api, col) {
|
|
188
|
+
function findLeftPinnedHeadersAfterCol(api, col, isRtl) {
|
|
189
189
|
const colIndex = parseCellColIndex(col);
|
|
190
190
|
return findPinnedHeaders({
|
|
191
191
|
api,
|
|
192
|
-
position: 'left',
|
|
192
|
+
position: isRtl ? 'right' : 'left',
|
|
193
193
|
colIndex,
|
|
194
|
-
filterFn: index => index > colIndex
|
|
194
|
+
filterFn: index => isRtl ? index < colIndex : index > colIndex
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
function findRightPinnedHeadersBeforeCol(api, col) {
|
|
197
|
+
function findRightPinnedHeadersBeforeCol(api, col, isRtl) {
|
|
198
198
|
const colIndex = parseCellColIndex(col);
|
|
199
199
|
return findPinnedHeaders({
|
|
200
200
|
api,
|
|
201
|
-
position: 'right',
|
|
201
|
+
position: isRtl ? 'left' : 'right',
|
|
202
202
|
colIndex,
|
|
203
|
-
filterFn: index => index < colIndex
|
|
203
|
+
filterFn: index => isRtl ? index > colIndex : index < colIndex
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
function findGridHeader(api, field) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-data-grid",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.18.0",
|
|
4
4
|
"description": "The Community plan edition of the Data Grid components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
|
-
"url": "https://github.com/mui/mui-x.git",
|
|
36
|
+
"url": "git+https://github.com/mui/mui-x.git",
|
|
37
37
|
"directory": "packages/x-data-grid"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"clsx": "^2.1.1",
|
|
43
43
|
"prop-types": "^15.8.1",
|
|
44
44
|
"reselect": "^5.1.1",
|
|
45
|
-
"@mui/x-internals": "7.
|
|
45
|
+
"@mui/x-internals": "7.18.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@emotion/react": "^11.9.0",
|
package/utils/domUtils.d.ts
CHANGED
|
@@ -18,9 +18,9 @@ export declare function getFieldsFromGroupHeaderElem(colCellEl: Element): string
|
|
|
18
18
|
export declare function findGroupHeaderElementsFromField(elem: Element, field: string): Element[];
|
|
19
19
|
export declare function findGridCellElementsFromCol(col: HTMLElement, api: GridPrivateApiCommunity): Element[];
|
|
20
20
|
export declare function findGridElement(api: GridPrivateApiCommunity, klass: keyof typeof gridClasses): HTMLElement;
|
|
21
|
-
export declare function findLeftPinnedCellsAfterCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
|
|
22
|
-
export declare function findRightPinnedCellsBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
|
|
23
|
-
export declare function findLeftPinnedHeadersAfterCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
|
|
24
|
-
export declare function findRightPinnedHeadersBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement): HTMLElement[];
|
|
21
|
+
export declare function findLeftPinnedCellsAfterCol(api: GridPrivateApiCommunity, col: HTMLElement, isRtl: boolean): HTMLElement[];
|
|
22
|
+
export declare function findRightPinnedCellsBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement, isRtl: boolean): HTMLElement[];
|
|
23
|
+
export declare function findLeftPinnedHeadersAfterCol(api: GridPrivateApiCommunity, col: HTMLElement, isRtl: boolean): HTMLElement[];
|
|
24
|
+
export declare function findRightPinnedHeadersBeforeCol(api: GridPrivateApiCommunity, col: HTMLElement, isRtl: boolean): HTMLElement[];
|
|
25
25
|
export declare function findGridHeader(api: GridPrivateApiCommunity, field: string): Element | null;
|
|
26
26
|
export declare function findGridCells(api: GridPrivateApiCommunity, field: string): Element[];
|
package/utils/domUtils.js
CHANGED
|
@@ -120,22 +120,22 @@ const findPinnedCells = ({
|
|
|
120
120
|
});
|
|
121
121
|
return cells;
|
|
122
122
|
};
|
|
123
|
-
export function findLeftPinnedCellsAfterCol(api, col) {
|
|
123
|
+
export function findLeftPinnedCellsAfterCol(api, col, isRtl) {
|
|
124
124
|
const colIndex = parseCellColIndex(col);
|
|
125
125
|
return findPinnedCells({
|
|
126
126
|
api,
|
|
127
127
|
colIndex,
|
|
128
|
-
position: 'left',
|
|
129
|
-
filterFn: index => index > colIndex
|
|
128
|
+
position: isRtl ? 'right' : 'left',
|
|
129
|
+
filterFn: index => isRtl ? index < colIndex : index > colIndex
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
|
-
export function findRightPinnedCellsBeforeCol(api, col) {
|
|
132
|
+
export function findRightPinnedCellsBeforeCol(api, col, isRtl) {
|
|
133
133
|
const colIndex = parseCellColIndex(col);
|
|
134
134
|
return findPinnedCells({
|
|
135
135
|
api,
|
|
136
136
|
colIndex,
|
|
137
|
-
position: 'right',
|
|
138
|
-
filterFn: index => index < colIndex
|
|
137
|
+
position: isRtl ? 'left' : 'right',
|
|
138
|
+
filterFn: index => isRtl ? index > colIndex : index < colIndex
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
const findPinnedHeaders = ({
|
|
@@ -159,22 +159,22 @@ const findPinnedHeaders = ({
|
|
|
159
159
|
});
|
|
160
160
|
return elements;
|
|
161
161
|
};
|
|
162
|
-
export function findLeftPinnedHeadersAfterCol(api, col) {
|
|
162
|
+
export function findLeftPinnedHeadersAfterCol(api, col, isRtl) {
|
|
163
163
|
const colIndex = parseCellColIndex(col);
|
|
164
164
|
return findPinnedHeaders({
|
|
165
165
|
api,
|
|
166
|
-
position: 'left',
|
|
166
|
+
position: isRtl ? 'right' : 'left',
|
|
167
167
|
colIndex,
|
|
168
|
-
filterFn: index => index > colIndex
|
|
168
|
+
filterFn: index => isRtl ? index < colIndex : index > colIndex
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
|
-
export function findRightPinnedHeadersBeforeCol(api, col) {
|
|
171
|
+
export function findRightPinnedHeadersBeforeCol(api, col, isRtl) {
|
|
172
172
|
const colIndex = parseCellColIndex(col);
|
|
173
173
|
return findPinnedHeaders({
|
|
174
174
|
api,
|
|
175
|
-
position: 'right',
|
|
175
|
+
position: isRtl ? 'left' : 'right',
|
|
176
176
|
colIndex,
|
|
177
|
-
filterFn: index => index < colIndex
|
|
177
|
+
filterFn: index => isRtl ? index > colIndex : index < colIndex
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
180
|
export function findGridHeader(api, field) {
|