@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
|
@@ -61,7 +61,7 @@ const useGridColumnHeaders = props => {
|
|
|
61
61
|
const renderContext = (0, _utils.useGridSelector)(apiRef, _virtualization.gridRenderContextColumnsSelector);
|
|
62
62
|
const pinnedColumns = (0, _utils.useGridSelector)(apiRef, _columns.gridVisiblePinnedColumnDefinitionsSelector);
|
|
63
63
|
const columnsLookup = (0, _utils.useGridSelector)(apiRef, _columns.gridColumnLookupSelector);
|
|
64
|
-
const offsetLeft = (0, _useGridVirtualScroller.computeOffsetLeft)(columnPositions, renderContext,
|
|
64
|
+
const offsetLeft = (0, _useGridVirtualScroller.computeOffsetLeft)(columnPositions, renderContext, pinnedColumns.left.length);
|
|
65
65
|
const gridHasFiller = dimensions.columnsTotalWidth < dimensions.viewportOuterSize.width;
|
|
66
66
|
React.useEffect(() => {
|
|
67
67
|
apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
|
|
@@ -91,7 +91,6 @@ const useGridColumnHeaders = props => {
|
|
|
91
91
|
const getColumnsToRender = params => {
|
|
92
92
|
const {
|
|
93
93
|
renderContext: currentContext = renderContext,
|
|
94
|
-
// TODO: `minFirstColumn` is not used anymore, could be refactored out.
|
|
95
94
|
maxLastColumn = visibleColumns.length
|
|
96
95
|
} = params || {};
|
|
97
96
|
const firstColumnToRender = currentContext.firstColumnIndex;
|
|
@@ -131,16 +130,22 @@ const useGridColumnHeaders = props => {
|
|
|
131
130
|
computedWidth
|
|
132
131
|
}) => {
|
|
133
132
|
let style;
|
|
134
|
-
|
|
133
|
+
const isLeftPinned = pinnedPosition === _columns.GridPinnedColumnPosition.LEFT;
|
|
134
|
+
const isRightPinned = pinnedPosition === _columns.GridPinnedColumnPosition.RIGHT;
|
|
135
|
+
if (isLeftPinned || isRightPinned) {
|
|
135
136
|
const pinnedOffset = (0, _getPinnedCellOffset.getPinnedCellOffset)(pinnedPosition, computedWidth, columnIndex, columnPositions, dimensions);
|
|
137
|
+
let side = isLeftPinned ? 'left' : 'right';
|
|
138
|
+
if (isRtl) {
|
|
139
|
+
side = isLeftPinned ? 'right' : 'left';
|
|
140
|
+
}
|
|
136
141
|
if (pinnedPosition === 'left') {
|
|
137
142
|
style = {
|
|
138
|
-
|
|
143
|
+
[side]: pinnedOffset
|
|
139
144
|
};
|
|
140
145
|
}
|
|
141
146
|
if (pinnedPosition === 'right') {
|
|
142
147
|
style = {
|
|
143
|
-
|
|
148
|
+
[side]: pinnedOffset
|
|
144
149
|
};
|
|
145
150
|
}
|
|
146
151
|
}
|
|
@@ -199,18 +204,15 @@ const useGridColumnHeaders = props => {
|
|
|
199
204
|
children: [leftRenderContext && getColumnHeaders({
|
|
200
205
|
position: _columns.GridPinnedColumnPosition.LEFT,
|
|
201
206
|
renderContext: leftRenderContext,
|
|
202
|
-
minFirstColumn: leftRenderContext.firstColumnIndex,
|
|
203
207
|
maxLastColumn: leftRenderContext.lastColumnIndex
|
|
204
208
|
}, {
|
|
205
209
|
disableReorder: true
|
|
206
210
|
}), getColumnHeaders({
|
|
207
211
|
renderContext,
|
|
208
|
-
minFirstColumn: pinnedColumns.left.length,
|
|
209
212
|
maxLastColumn: visibleColumns.length - pinnedColumns.right.length
|
|
210
213
|
}), rightRenderContext && getColumnHeaders({
|
|
211
214
|
position: _columns.GridPinnedColumnPosition.RIGHT,
|
|
212
215
|
renderContext: rightRenderContext,
|
|
213
|
-
minFirstColumn: rightRenderContext.firstColumnIndex,
|
|
214
216
|
maxLastColumn: rightRenderContext.lastColumnIndex
|
|
215
217
|
}, {
|
|
216
218
|
disableReorder: true,
|
|
@@ -290,7 +292,7 @@ const useGridColumnHeaders = props => {
|
|
|
290
292
|
depth: depth,
|
|
291
293
|
isLastColumn: headerInfo.colIndex === visibleColumns.length - headerInfo.fields.length,
|
|
292
294
|
maxDepth: headerGroupingMaxDepth,
|
|
293
|
-
height: dimensions.
|
|
295
|
+
height: dimensions.groupHeaderHeight,
|
|
294
296
|
hasFocus: hasFocus,
|
|
295
297
|
tabIndex: tabIndex,
|
|
296
298
|
pinnedPosition: pinnedPosition,
|
|
@@ -317,7 +319,6 @@ const useGridColumnHeaders = props => {
|
|
|
317
319
|
params: {
|
|
318
320
|
position: _columns.GridPinnedColumnPosition.LEFT,
|
|
319
321
|
renderContext: leftRenderContext,
|
|
320
|
-
minFirstColumn: leftRenderContext.firstColumnIndex,
|
|
321
322
|
maxLastColumn: leftRenderContext.lastColumnIndex
|
|
322
323
|
}
|
|
323
324
|
}), getColumnGroupHeaders({
|
|
@@ -330,7 +331,6 @@ const useGridColumnHeaders = props => {
|
|
|
330
331
|
params: {
|
|
331
332
|
position: _columns.GridPinnedColumnPosition.RIGHT,
|
|
332
333
|
renderContext: rightRenderContext,
|
|
333
|
-
minFirstColumn: rightRenderContext.firstColumnIndex,
|
|
334
334
|
maxLastColumn: rightRenderContext.lastColumnIndex
|
|
335
335
|
}
|
|
336
336
|
})]
|
|
@@ -311,13 +311,13 @@ const useGridColumnResize = (apiRef, props) => {
|
|
|
311
311
|
}
|
|
312
312
|
refs.groupHeaderElements = (0, _domUtils.findGroupHeaderElementsFromField)(apiRef.current.columnHeadersContainerRef?.current, colDef.field);
|
|
313
313
|
refs.cellElements = (0, _domUtils.findGridCellElementsFromCol)(refs.columnHeaderElement, apiRef.current);
|
|
314
|
-
refs.fillerLeft = (0, _domUtils.findGridElement)(apiRef.current, 'filler--pinnedLeft');
|
|
315
|
-
refs.fillerRight = (0, _domUtils.findGridElement)(apiRef.current, 'filler--pinnedRight');
|
|
314
|
+
refs.fillerLeft = (0, _domUtils.findGridElement)(apiRef.current, isRtl ? 'filler--pinnedRight' : 'filler--pinnedLeft');
|
|
315
|
+
refs.fillerRight = (0, _domUtils.findGridElement)(apiRef.current, isRtl ? 'filler--pinnedLeft' : 'filler--pinnedRight');
|
|
316
316
|
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, refs.colDef.field);
|
|
317
|
-
refs.leftPinnedCellsAfter = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.LEFT ? [] : (0, _domUtils.findLeftPinnedCellsAfterCol)(apiRef.current, refs.columnHeaderElement);
|
|
318
|
-
refs.rightPinnedCellsBefore = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.RIGHT ? [] : (0, _domUtils.findRightPinnedCellsBeforeCol)(apiRef.current, refs.columnHeaderElement);
|
|
319
|
-
refs.leftPinnedHeadersAfter = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.LEFT ? [] : (0, _domUtils.findLeftPinnedHeadersAfterCol)(apiRef.current, refs.columnHeaderElement);
|
|
320
|
-
refs.rightPinnedHeadersBefore = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.RIGHT ? [] : (0, _domUtils.findRightPinnedHeadersBeforeCol)(apiRef.current, refs.columnHeaderElement);
|
|
317
|
+
refs.leftPinnedCellsAfter = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.LEFT ? [] : (0, _domUtils.findLeftPinnedCellsAfterCol)(apiRef.current, refs.columnHeaderElement, isRtl);
|
|
318
|
+
refs.rightPinnedCellsBefore = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.RIGHT ? [] : (0, _domUtils.findRightPinnedCellsBeforeCol)(apiRef.current, refs.columnHeaderElement, isRtl);
|
|
319
|
+
refs.leftPinnedHeadersAfter = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.LEFT ? [] : (0, _domUtils.findLeftPinnedHeadersAfterCol)(apiRef.current, refs.columnHeaderElement, isRtl);
|
|
320
|
+
refs.rightPinnedHeadersBefore = pinnedPosition !== _gridColumnsInterfaces.GridPinnedColumnPosition.RIGHT ? [] : (0, _domUtils.findRightPinnedHeadersBeforeCol)(apiRef.current, refs.columnHeaderElement, isRtl);
|
|
321
321
|
resizeDirection.current = getResizeDirection(separator, isRtl);
|
|
322
322
|
initialOffsetToSeparator.current = computeOffsetToSeparator(xStart, refs.columnHeaderElement.getBoundingClientRect(), resizeDirection.current);
|
|
323
323
|
};
|
|
@@ -38,6 +38,7 @@ const EMPTY_DIMENSIONS = {
|
|
|
38
38
|
hasScrollY: false,
|
|
39
39
|
scrollbarSize: 0,
|
|
40
40
|
headerHeight: 0,
|
|
41
|
+
groupHeaderHeight: 0,
|
|
41
42
|
headerFilterHeight: 0,
|
|
42
43
|
rowWidth: 0,
|
|
43
44
|
rowHeight: 0,
|
|
@@ -65,6 +66,7 @@ function useGridDimensions(apiRef, props) {
|
|
|
65
66
|
const densityFactor = (0, _utils2.useGridSelector)(apiRef, _density.gridDensityFactorSelector);
|
|
66
67
|
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
67
68
|
const headerHeight = Math.floor(props.columnHeaderHeight * densityFactor);
|
|
69
|
+
const groupHeaderHeight = Math.floor((props.columnGroupHeaderHeight ?? props.columnHeaderHeight) * densityFactor);
|
|
68
70
|
const headerFilterHeight = Math.floor((props.headerFilterHeight ?? props.columnHeaderHeight) * densityFactor);
|
|
69
71
|
const columnsTotalWidth = roundToDecimalPlaces((0, _columns.gridColumnsTotalWidthSelector)(apiRef), 6);
|
|
70
72
|
const headersTotalHeight = (0, _gridColumnsUtils.getTotalHeaderHeight)(apiRef, props);
|
|
@@ -185,6 +187,7 @@ function useGridDimensions(apiRef, props) {
|
|
|
185
187
|
hasScrollY,
|
|
186
188
|
scrollbarSize,
|
|
187
189
|
headerHeight,
|
|
190
|
+
groupHeaderHeight,
|
|
188
191
|
headerFilterHeight,
|
|
189
192
|
rowWidth,
|
|
190
193
|
rowHeight,
|
|
@@ -201,7 +204,7 @@ function useGridDimensions(apiRef, props) {
|
|
|
201
204
|
apiRef.current.publishEvent('viewportInnerSizeChange', newDimensions.viewportInnerSize);
|
|
202
205
|
}
|
|
203
206
|
apiRef.current.updateRenderContext?.();
|
|
204
|
-
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowsMeta.currentPageTotalHeight, rowHeight, headerHeight, headerFilterHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
|
|
207
|
+
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowsMeta.currentPageTotalHeight, rowHeight, headerHeight, groupHeaderHeight, headerFilterHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
|
|
205
208
|
const apiPublic = {
|
|
206
209
|
resize,
|
|
207
210
|
getRootDimensions
|
|
@@ -20,6 +20,7 @@ var _keyboardUtils = require("../../../utils/keyboardUtils");
|
|
|
20
20
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
21
21
|
var _utils2 = require("../../../utils/utils");
|
|
22
22
|
var _gridEditCellParams = require("../../../models/params/gridEditCellParams");
|
|
23
|
+
var _utils3 = require("./utils");
|
|
23
24
|
const _excluded = ["id", "field"],
|
|
24
25
|
_excluded2 = ["id", "field"];
|
|
25
26
|
const useGridCellEditing = (apiRef, props) => {
|
|
@@ -257,24 +258,7 @@ const useGridCellEditing = (apiRef, props) => {
|
|
|
257
258
|
} = params;
|
|
258
259
|
let newValue = apiRef.current.getCellValue(id, field);
|
|
259
260
|
if (deleteValue) {
|
|
260
|
-
|
|
261
|
-
switch (fieldType) {
|
|
262
|
-
case 'boolean':
|
|
263
|
-
newValue = false;
|
|
264
|
-
break;
|
|
265
|
-
case 'date':
|
|
266
|
-
case 'dateTime':
|
|
267
|
-
case 'number':
|
|
268
|
-
newValue = undefined;
|
|
269
|
-
break;
|
|
270
|
-
case 'singleSelect':
|
|
271
|
-
newValue = null;
|
|
272
|
-
break;
|
|
273
|
-
case 'string':
|
|
274
|
-
default:
|
|
275
|
-
newValue = '';
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
261
|
+
newValue = (0, _utils3.getDefaultCellValue)(apiRef.current.getColumn(field));
|
|
278
262
|
} else if (initialValue) {
|
|
279
263
|
newValue = initialValue;
|
|
280
264
|
}
|
|
@@ -22,6 +22,7 @@ var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
|
22
22
|
var _utils2 = require("../../../utils/utils");
|
|
23
23
|
var _gridRowParams = require("../../../models/params/gridRowParams");
|
|
24
24
|
var _colDef = require("../../../colDef");
|
|
25
|
+
var _utils3 = require("./utils");
|
|
25
26
|
const _excluded = ["id"],
|
|
26
27
|
_excluded2 = ["id"];
|
|
27
28
|
const useGridRowEditing = (apiRef, props) => {
|
|
@@ -327,7 +328,11 @@ const useGridRowEditing = (apiRef, props) => {
|
|
|
327
328
|
}
|
|
328
329
|
let newValue = apiRef.current.getCellValue(id, field);
|
|
329
330
|
if (fieldToFocus === field && (deleteValue || initialValue)) {
|
|
330
|
-
|
|
331
|
+
if (deleteValue) {
|
|
332
|
+
newValue = (0, _utils3.getDefaultCellValue)(apiRef.current.getColumn(field));
|
|
333
|
+
} else if (initialValue) {
|
|
334
|
+
newValue = initialValue;
|
|
335
|
+
}
|
|
331
336
|
}
|
|
332
337
|
acc[field] = {
|
|
333
338
|
value: newValue,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getDefaultCellValue = void 0;
|
|
7
|
+
const getDefaultCellValue = colDef => {
|
|
8
|
+
switch (colDef.type) {
|
|
9
|
+
case 'boolean':
|
|
10
|
+
return false;
|
|
11
|
+
case 'date':
|
|
12
|
+
case 'dateTime':
|
|
13
|
+
case 'number':
|
|
14
|
+
return undefined;
|
|
15
|
+
case 'singleSelect':
|
|
16
|
+
return null;
|
|
17
|
+
case 'string':
|
|
18
|
+
default:
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.getDefaultCellValue = getDefaultCellValue;
|
|
@@ -46,6 +46,7 @@ function buildPrintWindow(title) {
|
|
|
46
46
|
* @requires useGridParamsApi (method)
|
|
47
47
|
*/
|
|
48
48
|
const useGridPrintExport = (apiRef, props) => {
|
|
49
|
+
const hasRootReference = apiRef.current.rootElementRef.current !== null;
|
|
49
50
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridPrintExport');
|
|
50
51
|
const doc = React.useRef(null);
|
|
51
52
|
const previousGridState = React.useRef(null);
|
|
@@ -54,7 +55,7 @@ const useGridPrintExport = (apiRef, props) => {
|
|
|
54
55
|
const previousVirtualizationState = React.useRef();
|
|
55
56
|
React.useEffect(() => {
|
|
56
57
|
doc.current = (0, _utils.unstable_ownerDocument)(apiRef.current.rootElementRef.current);
|
|
57
|
-
}, [apiRef]);
|
|
58
|
+
}, [apiRef, hasRootReference]);
|
|
58
59
|
|
|
59
60
|
// Returns a promise because updateColumns triggers state update and
|
|
60
61
|
// the new state needs to be in place before the grid can be sized correctly
|
|
@@ -43,6 +43,7 @@ exports.focusStateInitializer = focusStateInitializer;
|
|
|
43
43
|
const useGridFocus = (apiRef, props) => {
|
|
44
44
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridFocus');
|
|
45
45
|
const lastClickedCell = React.useRef(null);
|
|
46
|
+
const hasRootReference = apiRef.current.rootElementRef.current !== null;
|
|
46
47
|
const publishCellFocusOut = React.useCallback((cell, event) => {
|
|
47
48
|
if (cell) {
|
|
48
49
|
// The row might have been deleted
|
|
@@ -389,7 +390,7 @@ const useGridFocus = (apiRef, props) => {
|
|
|
389
390
|
return () => {
|
|
390
391
|
doc.removeEventListener('mouseup', handleDocumentClick);
|
|
391
392
|
};
|
|
392
|
-
}, [apiRef, handleDocumentClick]);
|
|
393
|
+
}, [apiRef, hasRootReference, handleDocumentClick]);
|
|
393
394
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'columnHeaderBlur', handleBlur);
|
|
394
395
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellDoubleClick', handleCellDoubleClick);
|
|
395
396
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellMouseDown', handleCellMouseDown);
|
|
@@ -17,51 +17,12 @@ var _gridClasses = require("../../../constants/gridClasses");
|
|
|
17
17
|
var _gridEditRowModel = require("../../../models/gridEditRowModel");
|
|
18
18
|
var _keyboardUtils = require("../../../utils/keyboardUtils");
|
|
19
19
|
var _gridDetailPanelToggleField = require("../../../constants/gridDetailPanelToggleField");
|
|
20
|
-
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
21
20
|
var _focus = require("../focus");
|
|
22
21
|
var _gridColumnGroupsSelector = require("../columnGrouping/gridColumnGroupsSelector");
|
|
23
22
|
var _gridHeaderFilteringSelectors = require("../headerFiltering/gridHeaderFilteringSelectors");
|
|
24
23
|
var _pipeProcessing = require("../../core/pipeProcessing");
|
|
25
24
|
var _domUtils = require("../../../utils/domUtils");
|
|
26
|
-
|
|
27
|
-
const pinnedRows = (0, _gridRowsSelector.gridPinnedRowsSelector)(apiRef) || {};
|
|
28
|
-
return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
|
|
29
|
-
}
|
|
30
|
-
const getLeftColumnIndex = ({
|
|
31
|
-
currentColIndex,
|
|
32
|
-
firstColIndex,
|
|
33
|
-
lastColIndex,
|
|
34
|
-
isRtl
|
|
35
|
-
}) => {
|
|
36
|
-
if (isRtl) {
|
|
37
|
-
if (currentColIndex < lastColIndex) {
|
|
38
|
-
return currentColIndex + 1;
|
|
39
|
-
}
|
|
40
|
-
} else if (!isRtl) {
|
|
41
|
-
if (currentColIndex > firstColIndex) {
|
|
42
|
-
return currentColIndex - 1;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
};
|
|
47
|
-
const getRightColumnIndex = ({
|
|
48
|
-
currentColIndex,
|
|
49
|
-
firstColIndex,
|
|
50
|
-
lastColIndex,
|
|
51
|
-
isRtl
|
|
52
|
-
}) => {
|
|
53
|
-
if (isRtl) {
|
|
54
|
-
if (currentColIndex > firstColIndex) {
|
|
55
|
-
return currentColIndex - 1;
|
|
56
|
-
}
|
|
57
|
-
} else if (!isRtl) {
|
|
58
|
-
if (currentColIndex < lastColIndex) {
|
|
59
|
-
return currentColIndex + 1;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
};
|
|
64
|
-
|
|
25
|
+
var _utils = require("./utils");
|
|
65
26
|
/**
|
|
66
27
|
* @requires useGridSorting (method) - can be after
|
|
67
28
|
* @requires useGridFilter (state) - can be after
|
|
@@ -75,16 +36,17 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
75
36
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridKeyboardNavigation');
|
|
76
37
|
const initialCurrentPageRows = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, props).rows;
|
|
77
38
|
const isRtl = (0, _RtlProvider.useRtl)();
|
|
78
|
-
const currentPageRows = React.useMemo(() => enrichPageRowsWithPinnedRows(apiRef, initialCurrentPageRows), [apiRef, initialCurrentPageRows]);
|
|
39
|
+
const currentPageRows = React.useMemo(() => (0, _utils.enrichPageRowsWithPinnedRows)(apiRef, initialCurrentPageRows), [apiRef, initialCurrentPageRows]);
|
|
79
40
|
const headerFilteringEnabled = props.signature !== 'DataGrid' && props.headerFilters;
|
|
80
41
|
|
|
81
42
|
/**
|
|
82
43
|
* @param {number} colIndex Index of the column to focus
|
|
83
|
-
* @param {
|
|
44
|
+
* @param {GridRowId} rowId index of the row to focus
|
|
84
45
|
* @param {string} closestColumnToUse Which closest column cell to use when the cell is spanned by `colSpan`.
|
|
46
|
+
* @param {string} rowSpanScanDirection Which direction to search to find the next cell not hidden by `rowSpan`.
|
|
85
47
|
* TODO replace with apiRef.current.moveFocusToRelativeCell()
|
|
86
48
|
*/
|
|
87
|
-
const goToCell = React.useCallback((colIndex, rowId, closestColumnToUse = 'left') => {
|
|
49
|
+
const goToCell = React.useCallback((colIndex, rowId, closestColumnToUse = 'left', rowSpanScanDirection = 'up') => {
|
|
88
50
|
const visibleSortedRows = (0, _gridFilterSelector.gridExpandedSortedRowEntriesSelector)(apiRef);
|
|
89
51
|
const nextCellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, colIndex);
|
|
90
52
|
if (nextCellColSpanInfo && nextCellColSpanInfo.spannedByColSpan) {
|
|
@@ -94,16 +56,17 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
94
56
|
colIndex = nextCellColSpanInfo.rightVisibleCellIndex;
|
|
95
57
|
}
|
|
96
58
|
}
|
|
59
|
+
const field = (0, _gridColumnsSelector.gridVisibleColumnFieldsSelector)(apiRef)[colIndex];
|
|
60
|
+
const nonRowSpannedRowId = (0, _utils.findNonRowSpannedCell)(apiRef, rowId, field, rowSpanScanDirection);
|
|
97
61
|
// `scrollToIndexes` requires a rowIndex relative to all visible rows.
|
|
98
62
|
// Those rows do not include pinned rows, but pinned rows do not need scroll anyway.
|
|
99
|
-
const rowIndexRelativeToAllRows = visibleSortedRows.findIndex(row => row.id ===
|
|
63
|
+
const rowIndexRelativeToAllRows = visibleSortedRows.findIndex(row => row.id === nonRowSpannedRowId);
|
|
100
64
|
logger.debug(`Navigating to cell row ${rowIndexRelativeToAllRows}, col ${colIndex}`);
|
|
101
65
|
apiRef.current.scrollToIndexes({
|
|
102
66
|
colIndex,
|
|
103
67
|
rowIndex: rowIndexRelativeToAllRows
|
|
104
68
|
});
|
|
105
|
-
|
|
106
|
-
apiRef.current.setCellFocus(rowId, field);
|
|
69
|
+
apiRef.current.setCellFocus(nonRowSpannedRowId, field);
|
|
107
70
|
}, [apiRef, logger]);
|
|
108
71
|
const goToHeader = React.useCallback((colIndex, event) => {
|
|
109
72
|
logger.debug(`Navigating to header col ${colIndex}`);
|
|
@@ -164,7 +127,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
164
127
|
}
|
|
165
128
|
case 'ArrowRight':
|
|
166
129
|
{
|
|
167
|
-
const rightColIndex = getRightColumnIndex({
|
|
130
|
+
const rightColIndex = (0, _utils.getRightColumnIndex)({
|
|
168
131
|
currentColIndex: colIndexBefore,
|
|
169
132
|
firstColIndex,
|
|
170
133
|
lastColIndex,
|
|
@@ -177,7 +140,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
177
140
|
}
|
|
178
141
|
case 'ArrowLeft':
|
|
179
142
|
{
|
|
180
|
-
const leftColIndex = getLeftColumnIndex({
|
|
143
|
+
const leftColIndex = (0, _utils.getLeftColumnIndex)({
|
|
181
144
|
currentColIndex: colIndexBefore,
|
|
182
145
|
firstColIndex,
|
|
183
146
|
lastColIndex,
|
|
@@ -257,7 +220,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
257
220
|
}
|
|
258
221
|
case 'ArrowRight':
|
|
259
222
|
{
|
|
260
|
-
const rightColIndex = getRightColumnIndex({
|
|
223
|
+
const rightColIndex = (0, _utils.getRightColumnIndex)({
|
|
261
224
|
currentColIndex: colIndexBefore,
|
|
262
225
|
firstColIndex,
|
|
263
226
|
lastColIndex,
|
|
@@ -270,7 +233,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
270
233
|
}
|
|
271
234
|
case 'ArrowLeft':
|
|
272
235
|
{
|
|
273
|
-
const leftColIndex = getLeftColumnIndex({
|
|
236
|
+
const leftColIndex = (0, _utils.getLeftColumnIndex)({
|
|
274
237
|
currentColIndex: colIndexBefore,
|
|
275
238
|
firstColIndex,
|
|
276
239
|
lastColIndex,
|
|
@@ -439,7 +402,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
439
402
|
{
|
|
440
403
|
// "Enter" is only triggered by the row / cell editing feature
|
|
441
404
|
if (rowIndexBefore < lastRowIndexInPage) {
|
|
442
|
-
goToCell(colIndexBefore, getRowIdFromIndex(rowIndexBefore + 1));
|
|
405
|
+
goToCell(colIndexBefore, getRowIdFromIndex(rowIndexBefore + 1), isRtl ? 'right' : 'left', 'down');
|
|
443
406
|
}
|
|
444
407
|
break;
|
|
445
408
|
}
|
|
@@ -456,7 +419,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
456
419
|
}
|
|
457
420
|
case 'ArrowRight':
|
|
458
421
|
{
|
|
459
|
-
const rightColIndex = getRightColumnIndex({
|
|
422
|
+
const rightColIndex = (0, _utils.getRightColumnIndex)({
|
|
460
423
|
currentColIndex: colIndexBefore,
|
|
461
424
|
firstColIndex,
|
|
462
425
|
lastColIndex,
|
|
@@ -469,7 +432,7 @@ const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
469
432
|
}
|
|
470
433
|
case 'ArrowLeft':
|
|
471
434
|
{
|
|
472
|
-
const leftColIndex = getLeftColumnIndex({
|
|
435
|
+
const leftColIndex = (0, _utils.getLeftColumnIndex)({
|
|
473
436
|
currentColIndex: colIndexBefore,
|
|
474
437
|
firstColIndex,
|
|
475
438
|
lastColIndex,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.enrichPageRowsWithPinnedRows = enrichPageRowsWithPinnedRows;
|
|
7
|
+
exports.findNonRowSpannedCell = findNonRowSpannedCell;
|
|
8
|
+
exports.getRightColumnIndex = exports.getLeftColumnIndex = void 0;
|
|
9
|
+
var _gridFilterSelector = require("../filter/gridFilterSelector");
|
|
10
|
+
var _gridRowSpanningSelectors = require("../rows/gridRowSpanningSelectors");
|
|
11
|
+
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
12
|
+
function enrichPageRowsWithPinnedRows(apiRef, rows) {
|
|
13
|
+
const pinnedRows = (0, _gridRowsSelector.gridPinnedRowsSelector)(apiRef) || {};
|
|
14
|
+
return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
|
|
15
|
+
}
|
|
16
|
+
const getLeftColumnIndex = ({
|
|
17
|
+
currentColIndex,
|
|
18
|
+
firstColIndex,
|
|
19
|
+
lastColIndex,
|
|
20
|
+
isRtl
|
|
21
|
+
}) => {
|
|
22
|
+
if (isRtl) {
|
|
23
|
+
if (currentColIndex < lastColIndex) {
|
|
24
|
+
return currentColIndex + 1;
|
|
25
|
+
}
|
|
26
|
+
} else if (!isRtl) {
|
|
27
|
+
if (currentColIndex > firstColIndex) {
|
|
28
|
+
return currentColIndex - 1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
exports.getLeftColumnIndex = getLeftColumnIndex;
|
|
34
|
+
const getRightColumnIndex = ({
|
|
35
|
+
currentColIndex,
|
|
36
|
+
firstColIndex,
|
|
37
|
+
lastColIndex,
|
|
38
|
+
isRtl
|
|
39
|
+
}) => {
|
|
40
|
+
if (isRtl) {
|
|
41
|
+
if (currentColIndex > firstColIndex) {
|
|
42
|
+
return currentColIndex - 1;
|
|
43
|
+
}
|
|
44
|
+
} else if (!isRtl) {
|
|
45
|
+
if (currentColIndex < lastColIndex) {
|
|
46
|
+
return currentColIndex + 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
exports.getRightColumnIndex = getRightColumnIndex;
|
|
52
|
+
function findNonRowSpannedCell(apiRef, rowId, field, rowSpanScanDirection) {
|
|
53
|
+
const rowSpanHiddenCells = (0, _gridRowSpanningSelectors.gridRowSpanningHiddenCellsSelector)(apiRef);
|
|
54
|
+
if (!rowSpanHiddenCells[rowId]?.[field]) {
|
|
55
|
+
return rowId;
|
|
56
|
+
}
|
|
57
|
+
const filteredSortedRowIds = (0, _gridFilterSelector.gridFilteredSortedRowIdsSelector)(apiRef);
|
|
58
|
+
// find closest non row spanned cell in the given `rowSpanScanDirection`
|
|
59
|
+
let nextRowIndex = filteredSortedRowIds.indexOf(rowId) + (rowSpanScanDirection === 'down' ? 1 : -1);
|
|
60
|
+
while (nextRowIndex >= 0 && nextRowIndex < filteredSortedRowIds.length) {
|
|
61
|
+
const nextRowId = filteredSortedRowIds[nextRowIndex];
|
|
62
|
+
if (!rowSpanHiddenCells[nextRowId]?.[field]) {
|
|
63
|
+
return nextRowId;
|
|
64
|
+
}
|
|
65
|
+
nextRowIndex += rowSpanScanDirection === 'down' ? 1 : -1;
|
|
66
|
+
}
|
|
67
|
+
return rowId;
|
|
68
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.gridRowSpanningSpannedCellsSelector = exports.gridRowSpanningHiddenCellsSelector = exports.gridRowSpanningHiddenCellsOriginMapSelector = void 0;
|
|
7
|
+
var _createSelector = require("../../../utils/createSelector");
|
|
8
|
+
const gridRowSpanningStateSelector = state => state.rowSpanning;
|
|
9
|
+
const gridRowSpanningHiddenCellsSelector = exports.gridRowSpanningHiddenCellsSelector = (0, _createSelector.createSelector)(gridRowSpanningStateSelector, rowSpanning => rowSpanning.hiddenCells);
|
|
10
|
+
const gridRowSpanningSpannedCellsSelector = exports.gridRowSpanningSpannedCellsSelector = (0, _createSelector.createSelector)(gridRowSpanningStateSelector, rowSpanning => rowSpanning.spannedCells);
|
|
11
|
+
const gridRowSpanningHiddenCellsOriginMapSelector = exports.gridRowSpanningHiddenCellsOriginMapSelector = (0, _createSelector.createSelector)(gridRowSpanningStateSelector, rowSpanning => rowSpanning.hiddenCellOriginMap);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getCellValue = void 0;
|
|
7
|
+
exports.getUnprocessedRange = getUnprocessedRange;
|
|
8
|
+
exports.isRowContextInitialized = isRowContextInitialized;
|
|
9
|
+
exports.isRowRangeUpdated = isRowRangeUpdated;
|
|
10
|
+
function getUnprocessedRange(testRange, processedRange) {
|
|
11
|
+
if (testRange.firstRowIndex >= processedRange.firstRowIndex && testRange.lastRowIndex <= processedRange.lastRowIndex) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
// Overflowing at the end
|
|
15
|
+
// Example: testRange={ firstRowIndex: 10, lastRowIndex: 20 }, processedRange={ firstRowIndex: 0, lastRowIndex: 15 }
|
|
16
|
+
// Unprocessed Range={ firstRowIndex: 16, lastRowIndex: 20 }
|
|
17
|
+
if (testRange.firstRowIndex >= processedRange.firstRowIndex && testRange.lastRowIndex > processedRange.lastRowIndex) {
|
|
18
|
+
return {
|
|
19
|
+
firstRowIndex: processedRange.lastRowIndex,
|
|
20
|
+
lastRowIndex: testRange.lastRowIndex
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Overflowing at the beginning
|
|
24
|
+
// Example: testRange={ firstRowIndex: 0, lastRowIndex: 20 }, processedRange={ firstRowIndex: 16, lastRowIndex: 30 }
|
|
25
|
+
// Unprocessed Range={ firstRowIndex: 0, lastRowIndex: 15 }
|
|
26
|
+
if (testRange.firstRowIndex < processedRange.firstRowIndex && testRange.lastRowIndex <= processedRange.lastRowIndex) {
|
|
27
|
+
return {
|
|
28
|
+
firstRowIndex: testRange.firstRowIndex,
|
|
29
|
+
lastRowIndex: processedRange.firstRowIndex - 1
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// TODO: Should return two ranges handle overflowing at both ends ?
|
|
33
|
+
return testRange;
|
|
34
|
+
}
|
|
35
|
+
function isRowContextInitialized(renderContext) {
|
|
36
|
+
return renderContext.firstRowIndex !== 0 || renderContext.lastRowIndex !== 0;
|
|
37
|
+
}
|
|
38
|
+
function isRowRangeUpdated(range1, range2) {
|
|
39
|
+
return range1.firstRowIndex !== range2.firstRowIndex || range1.lastRowIndex !== range2.lastRowIndex;
|
|
40
|
+
}
|
|
41
|
+
const getCellValue = (row, colDef, apiRef) => {
|
|
42
|
+
if (!row) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
let cellValue = row[colDef.field];
|
|
46
|
+
const valueGetter = colDef.rowSpanValueGetter ?? colDef.valueGetter;
|
|
47
|
+
if (valueGetter) {
|
|
48
|
+
cellValue = valueGetter(cellValue, row, colDef, apiRef);
|
|
49
|
+
}
|
|
50
|
+
return cellValue;
|
|
51
|
+
};
|
|
52
|
+
exports.getCellValue = getCellValue;
|