@mui/x-data-grid 7.17.0 → 7.19.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 +208 -5
- package/DataGrid/DataGrid.js +16 -1
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +2 -1
- package/components/GridRow.js +1 -0
- package/components/cell/GridCell.js +33 -9
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/components/columnSelection/GridCellCheckboxRenderer.js +12 -4
- package/components/columnSelection/GridHeaderCheckbox.d.ts +1 -1
- package/components/containers/GridRoot.js +1 -1
- package/components/containers/GridRootStyles.js +32 -23
- package/components/containers/GridToolbarContainer.js +1 -1
- package/components/menu/GridMenu.js +1 -1
- package/components/panel/GridPanel.d.ts +1 -1
- package/components/panel/GridPanel.js +1 -1
- package/components/panel/GridPanelContent.js +1 -1
- package/components/panel/GridPanelFooter.js +1 -1
- package/components/panel/GridPanelHeader.js +1 -1
- package/components/panel/GridPanelWrapper.js +1 -1
- package/components/panel/filterPanel/filterPanelUtils.d.ts +1 -1
- package/components/toolbar/GridToolbarQuickFilter.js +1 -1
- package/components/virtualization/GridBottomContainer.d.ts +1 -1
- package/components/virtualization/GridBottomContainer.js +18 -1
- package/components/virtualization/GridMainContainer.js +3 -1
- package/components/virtualization/GridTopContainer.d.ts +1 -1
- package/components/virtualization/GridTopContainer.js +1 -1
- package/components/virtualization/GridVirtualScrollbar.js +1 -7
- package/components/virtualization/GridVirtualScroller.js +1 -0
- package/components/virtualization/GridVirtualScrollerFiller.js +3 -4
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.d.ts +4 -4
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/hooks/features/columnResize/columnResizeSelector.d.ts +1 -1
- package/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/hooks/features/columns/gridColumnsSelector.d.ts +12 -12
- package/hooks/features/columns/gridColumnsUtils.js +3 -2
- package/hooks/features/density/densitySelector.d.ts +1 -1
- 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 +3 -19
- package/hooks/features/editing/useGridRowEditing.js +7 -2
- 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/filter/gridFilterSelector.d.ts +17 -17
- package/hooks/features/focus/gridFocusStateSelector.d.ts +8 -8
- package/hooks/features/focus/useGridFocus.js +2 -1
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +3 -3
- 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/pagination/gridPaginationSelector.d.ts +9 -9
- package/hooks/features/rowSelection/gridRowSelectionSelector.d.ts +3 -3
- package/hooks/features/rowSelection/useGridRowSelection.d.ts +1 -1
- package/hooks/features/rowSelection/useGridRowSelection.js +105 -29
- package/hooks/features/rowSelection/utils.d.ts +10 -0
- package/hooks/features/rowSelection/utils.js +156 -1
- 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/gridRowsSelector.d.ts +14 -14
- package/hooks/features/rows/useGridRowSpanning.d.ts +27 -0
- package/hooks/features/rows/useGridRowSpanning.js +257 -0
- package/hooks/features/rows/useGridRows.d.ts +1 -1
- package/hooks/features/rows/useGridRows.js +7 -1
- package/hooks/features/scroll/useGridScroll.js +19 -19
- package/hooks/features/sorting/gridSortingSelector.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +5 -5
- 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/hooks/utils/useGridVisibleRows.d.ts +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +2 -0
- package/internals/index.js +2 -0
- package/locales/bgBG.js +8 -9
- package/locales/deDE.js +4 -4
- package/locales/frFR.js +4 -4
- package/locales/hrHR.d.ts +1 -1
- package/locales/hrHR.js +69 -46
- package/locales/jaJP.js +1 -2
- package/locales/ptPT.d.ts +1 -1
- package/locales/ptPT.js +4 -4
- package/locales/viVN.js +20 -20
- package/locales/zhHK.d.ts +1 -1
- package/models/colDef/gridColDef.d.ts +4 -0
- package/models/gridRowSelectionModel.d.ts +4 -0
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/props/DataGridProps.d.ts +30 -1
- package/modern/DataGrid/DataGrid.js +16 -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 +33 -9
- package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/modern/components/columnSelection/GridCellCheckboxRenderer.js +12 -4
- package/modern/components/containers/GridRoot.js +1 -1
- package/modern/components/containers/GridRootStyles.js +32 -23
- package/modern/components/containers/GridToolbarContainer.js +1 -1
- package/modern/components/menu/GridMenu.js +1 -1
- package/modern/components/panel/GridPanel.js +1 -1
- package/modern/components/panel/GridPanelContent.js +1 -1
- package/modern/components/panel/GridPanelFooter.js +1 -1
- package/modern/components/panel/GridPanelHeader.js +1 -1
- package/modern/components/panel/GridPanelWrapper.js +1 -1
- package/modern/components/toolbar/GridToolbarQuickFilter.js +1 -1
- package/modern/components/virtualization/GridBottomContainer.js +18 -1
- package/modern/components/virtualization/GridMainContainer.js +3 -1
- package/modern/components/virtualization/GridTopContainer.js +1 -1
- package/modern/components/virtualization/GridVirtualScrollbar.js +1 -7
- package/modern/components/virtualization/GridVirtualScroller.js +1 -0
- package/modern/components/virtualization/GridVirtualScrollerFiller.js +3 -4
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/modern/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/modern/hooks/features/columns/gridColumnsUtils.js +3 -2
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/modern/hooks/features/editing/useGridCellEditing.js +3 -19
- package/modern/hooks/features/editing/useGridRowEditing.js +7 -2
- 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/rowSelection/useGridRowSelection.js +105 -29
- package/modern/hooks/features/rowSelection/utils.js +156 -1
- 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/rows/useGridRows.js +7 -1
- package/modern/hooks/features/scroll/useGridScroll.js +19 -19
- 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 +2 -0
- package/modern/locales/bgBG.js +8 -9
- package/modern/locales/deDE.js +4 -4
- package/modern/locales/frFR.js +4 -4
- package/modern/locales/hrHR.js +69 -46
- package/modern/locales/jaJP.js +1 -2
- package/modern/locales/ptPT.js +4 -4
- package/modern/locales/viVN.js +20 -20
- package/modern/utils/createSelector.js +6 -0
- package/modern/utils/domUtils.js +12 -12
- package/node/DataGrid/DataGrid.js +16 -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 +33 -9
- package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -1
- package/node/components/columnSelection/GridCellCheckboxRenderer.js +12 -4
- package/node/components/containers/GridRoot.js +1 -1
- package/node/components/containers/GridRootStyles.js +32 -23
- package/node/components/containers/GridToolbarContainer.js +1 -1
- package/node/components/menu/GridMenu.js +1 -1
- package/node/components/panel/GridPanel.js +1 -1
- package/node/components/panel/GridPanelContent.js +1 -1
- package/node/components/panel/GridPanelFooter.js +1 -1
- package/node/components/panel/GridPanelHeader.js +1 -1
- package/node/components/panel/GridPanelWrapper.js +1 -1
- package/node/components/toolbar/GridToolbarQuickFilter.js +1 -1
- package/node/components/virtualization/GridBottomContainer.js +18 -1
- package/node/components/virtualization/GridMainContainer.js +3 -1
- package/node/components/virtualization/GridTopContainer.js +1 -1
- package/node/components/virtualization/GridVirtualScrollbar.js +1 -7
- package/node/components/virtualization/GridVirtualScroller.js +1 -0
- package/node/components/virtualization/GridVirtualScrollerFiller.js +3 -4
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +11 -11
- package/node/hooks/features/columnResize/useGridColumnResize.js +6 -6
- package/node/hooks/features/columns/gridColumnsUtils.js +3 -2
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -1
- package/node/hooks/features/editing/useGridCellEditing.js +3 -19
- package/node/hooks/features/editing/useGridRowEditing.js +7 -2
- 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/rowSelection/useGridRowSelection.js +102 -26
- package/node/hooks/features/rowSelection/utils.js +160 -1
- 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/rows/useGridRows.js +7 -1
- package/node/hooks/features/scroll/useGridScroll.js +19 -19
- 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 +38 -15
- package/node/locales/bgBG.js +8 -9
- package/node/locales/deDE.js +4 -4
- package/node/locales/frFR.js +4 -4
- package/node/locales/hrHR.js +69 -46
- package/node/locales/jaJP.js +1 -2
- package/node/locales/ptPT.js +4 -4
- package/node/locales/viVN.js +20 -20
- package/node/utils/createSelector.js +6 -0
- package/node/utils/domUtils.js +12 -12
- package/package.json +3 -3
- package/utils/createSelector.js +6 -0
- package/utils/domUtils.d.ts +4 -4
- package/utils/domUtils.js +12 -12
|
@@ -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
|
+
}
|
|
@@ -11,6 +11,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
11
11
|
var _useGridApiEventHandler = require("../../utils/useGridApiEventHandler");
|
|
12
12
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
13
13
|
var _useGridLogger = require("../../utils/useGridLogger");
|
|
14
|
+
var _useGridSelector = require("../../utils/useGridSelector");
|
|
14
15
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
15
16
|
var _gridRowSelectionSelector = require("./gridRowSelectionSelector");
|
|
16
17
|
var _pagination = require("../pagination");
|
|
@@ -49,11 +50,12 @@ const rowSelectionStateInitializer = (state, props) => (0, _extends2.default)({}
|
|
|
49
50
|
exports.rowSelectionStateInitializer = rowSelectionStateInitializer;
|
|
50
51
|
const useGridRowSelection = (apiRef, props) => {
|
|
51
52
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridSelection');
|
|
52
|
-
const runIfRowSelectionIsEnabled = callback => (...args) => {
|
|
53
|
+
const runIfRowSelectionIsEnabled = React.useCallback(callback => (...args) => {
|
|
53
54
|
if (props.rowSelection) {
|
|
54
55
|
callback(...args);
|
|
55
56
|
}
|
|
56
|
-
};
|
|
57
|
+
}, [props.rowSelection]);
|
|
58
|
+
const applyAutoSelection = props.signature !== _useGridApiEventHandler.GridSignature.DataGrid && (props.rowSelectionPropagation?.parents || props.rowSelectionPropagation?.descendants);
|
|
57
59
|
const propRowSelectionModel = React.useMemo(() => {
|
|
58
60
|
return getSelectionModelPropValue(props.rowSelectionModel, (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef.current.state));
|
|
59
61
|
}, [apiRef, props.rowSelectionModel]);
|
|
@@ -72,6 +74,8 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
72
74
|
} = props;
|
|
73
75
|
const canHaveMultipleSelection = (0, _utils.isMultipleRowSelectionEnabled)(props);
|
|
74
76
|
const visibleRows = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, props);
|
|
77
|
+
const tree = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridRowTreeSelector);
|
|
78
|
+
const isNestedData = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridRowMaximumTreeDepthSelector) > 1;
|
|
75
79
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
76
80
|
let endId = id;
|
|
77
81
|
const startId = lastRowToggled.current ?? id;
|
|
@@ -96,7 +100,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
96
100
|
}, !isSelected);
|
|
97
101
|
}, [apiRef]);
|
|
98
102
|
|
|
99
|
-
|
|
103
|
+
/*
|
|
100
104
|
* API METHODS
|
|
101
105
|
*/
|
|
102
106
|
const setRowSelectionModel = React.useCallback(model => {
|
|
@@ -134,34 +138,80 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
134
138
|
lastRowToggled.current = id;
|
|
135
139
|
if (resetSelection) {
|
|
136
140
|
logger.debug(`Setting selection for row ${id}`);
|
|
137
|
-
|
|
141
|
+
const newSelection = [];
|
|
142
|
+
const addRow = rowId => {
|
|
143
|
+
newSelection.push(rowId);
|
|
144
|
+
};
|
|
145
|
+
if (isSelected) {
|
|
146
|
+
addRow(id);
|
|
147
|
+
if (applyAutoSelection) {
|
|
148
|
+
(0, _utils.findRowsToSelect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
138
152
|
} else {
|
|
139
153
|
logger.debug(`Toggling selection for row ${id}`);
|
|
140
154
|
const selection = (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef.current.state);
|
|
141
|
-
const newSelection = selection
|
|
155
|
+
const newSelection = new Set(selection);
|
|
156
|
+
newSelection.delete(id);
|
|
157
|
+
const addRow = rowId => {
|
|
158
|
+
newSelection.add(rowId);
|
|
159
|
+
};
|
|
160
|
+
const removeRow = rowId => {
|
|
161
|
+
newSelection.delete(rowId);
|
|
162
|
+
};
|
|
142
163
|
if (isSelected) {
|
|
143
|
-
|
|
164
|
+
addRow(id);
|
|
165
|
+
if (applyAutoSelection) {
|
|
166
|
+
(0, _utils.findRowsToSelect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
167
|
+
}
|
|
168
|
+
} else if (applyAutoSelection) {
|
|
169
|
+
(0, _utils.findRowsToDeselect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, removeRow);
|
|
144
170
|
}
|
|
145
|
-
const isSelectionValid = newSelection.
|
|
171
|
+
const isSelectionValid = newSelection.size < 2 || canHaveMultipleSelection;
|
|
146
172
|
if (isSelectionValid) {
|
|
147
|
-
apiRef.current.setRowSelectionModel(newSelection);
|
|
173
|
+
apiRef.current.setRowSelectionModel(Array.from(newSelection));
|
|
148
174
|
}
|
|
149
175
|
}
|
|
150
|
-
}, [apiRef, logger, canHaveMultipleSelection]);
|
|
176
|
+
}, [apiRef, logger, applyAutoSelection, tree, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents, canHaveMultipleSelection]);
|
|
151
177
|
const selectRows = React.useCallback((ids, isSelected = true, resetSelection = false) => {
|
|
152
178
|
logger.debug(`Setting selection for several rows`);
|
|
153
179
|
const selectableIds = ids.filter(id => apiRef.current.isRowSelectable(id));
|
|
154
180
|
let newSelection;
|
|
155
181
|
if (resetSelection) {
|
|
156
|
-
|
|
182
|
+
if (isSelected) {
|
|
183
|
+
newSelection = selectableIds;
|
|
184
|
+
if (applyAutoSelection) {
|
|
185
|
+
const addRow = rowId => {
|
|
186
|
+
newSelection.push(rowId);
|
|
187
|
+
};
|
|
188
|
+
selectableIds.forEach(id => {
|
|
189
|
+
(0, _utils.findRowsToSelect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
newSelection = [];
|
|
194
|
+
}
|
|
157
195
|
} else {
|
|
158
196
|
// We clone the existing object to avoid mutating the same object returned by the selector to others part of the project
|
|
159
197
|
const selectionLookup = (0, _extends2.default)({}, (0, _gridRowSelectionSelector.selectedIdsLookupSelector)(apiRef));
|
|
198
|
+
const addRow = rowId => {
|
|
199
|
+
selectionLookup[rowId] = rowId;
|
|
200
|
+
};
|
|
201
|
+
const removeRow = rowId => {
|
|
202
|
+
delete selectionLookup[rowId];
|
|
203
|
+
};
|
|
160
204
|
selectableIds.forEach(id => {
|
|
161
205
|
if (isSelected) {
|
|
162
206
|
selectionLookup[id] = id;
|
|
207
|
+
if (applyAutoSelection) {
|
|
208
|
+
(0, _utils.findRowsToSelect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow);
|
|
209
|
+
}
|
|
163
210
|
} else {
|
|
164
|
-
|
|
211
|
+
removeRow(id);
|
|
212
|
+
if (applyAutoSelection) {
|
|
213
|
+
(0, _utils.findRowsToDeselect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, removeRow);
|
|
214
|
+
}
|
|
165
215
|
}
|
|
166
216
|
});
|
|
167
217
|
newSelection = Object.values(selectionLookup);
|
|
@@ -170,7 +220,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
170
220
|
if (isSelectionValid) {
|
|
171
221
|
apiRef.current.setRowSelectionModel(newSelection);
|
|
172
222
|
}
|
|
173
|
-
}, [apiRef,
|
|
223
|
+
}, [logger, applyAutoSelection, canHaveMultipleSelection, apiRef, tree, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents]);
|
|
174
224
|
const selectRowRange = React.useCallback(({
|
|
175
225
|
startId,
|
|
176
226
|
endId
|
|
@@ -202,29 +252,52 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
202
252
|
(0, _useGridApiMethod.useGridApiMethod)(apiRef, selectionPublicApi, 'public');
|
|
203
253
|
(0, _useGridApiMethod.useGridApiMethod)(apiRef, selectionPrivateApi, props.signature === _useGridApiEventHandler.GridSignature.DataGrid ? 'private' : 'public');
|
|
204
254
|
|
|
205
|
-
|
|
255
|
+
/*
|
|
206
256
|
* EVENTS
|
|
207
257
|
*/
|
|
208
|
-
const removeOutdatedSelection = React.useCallback(() => {
|
|
209
|
-
if (props.keepNonExistentRowsSelected) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
258
|
+
const removeOutdatedSelection = React.useCallback((sortModelUpdated = false) => {
|
|
212
259
|
const currentSelection = (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef.current.state);
|
|
213
|
-
const
|
|
260
|
+
const filteredRowsLookup = (0, _gridFilterSelector.gridFilteredRowsLookupSelector)(apiRef);
|
|
214
261
|
|
|
215
262
|
// We clone the existing object to avoid mutating the same object returned by the selector to others part of the project
|
|
216
263
|
const selectionLookup = (0, _extends2.default)({}, (0, _gridRowSelectionSelector.selectedIdsLookupSelector)(apiRef));
|
|
217
264
|
let hasChanged = false;
|
|
218
265
|
currentSelection.forEach(id => {
|
|
219
|
-
if (
|
|
266
|
+
if (filteredRowsLookup[id] === false) {
|
|
267
|
+
if (props.keepNonExistentRowsSelected) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
220
270
|
delete selectionLookup[id];
|
|
221
271
|
hasChanged = true;
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (!props.rowSelectionPropagation?.parents) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const node = tree[id];
|
|
278
|
+
if (node.type === 'group') {
|
|
279
|
+
const isAutoGenerated = node.isAutoGenerated;
|
|
280
|
+
if (isAutoGenerated) {
|
|
281
|
+
delete selectionLookup[id];
|
|
282
|
+
hasChanged = true;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
// Keep previously selected tree data parents selected if all their children are filtered out
|
|
286
|
+
if (!node.children.every(childId => filteredRowsLookup[childId] === false)) {
|
|
287
|
+
delete selectionLookup[id];
|
|
288
|
+
hasChanged = true;
|
|
289
|
+
}
|
|
222
290
|
}
|
|
223
291
|
});
|
|
224
|
-
if (hasChanged) {
|
|
225
|
-
|
|
292
|
+
if (hasChanged || isNestedData && !sortModelUpdated) {
|
|
293
|
+
const newSelection = Object.values(selectionLookup);
|
|
294
|
+
if (isNestedData) {
|
|
295
|
+
apiRef.current.selectRows(newSelection, true, true);
|
|
296
|
+
} else {
|
|
297
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
298
|
+
}
|
|
226
299
|
}
|
|
227
|
-
}, [apiRef, props.keepNonExistentRowsSelected]);
|
|
300
|
+
}, [apiRef, isNestedData, props.rowSelectionPropagation?.parents, props.keepNonExistentRowsSelected, tree]);
|
|
228
301
|
const handleSingleRowSelection = React.useCallback((id, event) => {
|
|
229
302
|
const hasCtrlKey = event.metaKey || event.ctrlKey;
|
|
230
303
|
|
|
@@ -285,8 +358,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
285
358
|
}, [apiRef, expandMouseRowRangeSelection, canHaveMultipleSelection]);
|
|
286
359
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
287
360
|
const rowsToBeSelected = props.pagination && props.checkboxSelectionVisibleOnly && props.paginationMode === 'client' ? (0, _pagination.gridPaginatedVisibleSortedGridRowIdsSelector)(apiRef) : (0, _gridFilterSelector.gridExpandedSortedRowIdsSelector)(apiRef);
|
|
288
|
-
|
|
289
|
-
apiRef.current.selectRows(rowsToBeSelected, params.value, filterModel?.items.length > 0);
|
|
361
|
+
apiRef.current.selectRows(rowsToBeSelected, params.value);
|
|
290
362
|
}, [apiRef, props.checkboxSelectionVisibleOnly, props.pagination, props.paginationMode]);
|
|
291
363
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
292
364
|
// Get the most recent cell mode because it may have been changed by another listener
|
|
@@ -350,14 +422,15 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
350
422
|
selectRows(apiRef.current.getAllRowIds(), true);
|
|
351
423
|
}
|
|
352
424
|
}, [apiRef, handleSingleRowSelection, selectRows, visibleRows.rows, canHaveMultipleSelection]);
|
|
353
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(removeOutdatedSelection));
|
|
425
|
+
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(() => removeOutdatedSelection(true)));
|
|
426
|
+
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'filteredRowsSet', runIfRowSelectionIsEnabled(removeOutdatedSelection));
|
|
354
427
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'rowClick', runIfRowSelectionIsEnabled(handleRowClick));
|
|
355
428
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'rowSelectionCheckboxChange', runIfRowSelectionIsEnabled(handleRowSelectionCheckboxChange));
|
|
356
429
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'headerSelectionCheckboxChange', handleHeaderSelectionCheckboxChange);
|
|
357
430
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellMouseDown', runIfRowSelectionIsEnabled(preventSelectionOnShift));
|
|
358
431
|
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellKeyDown', runIfRowSelectionIsEnabled(handleCellKeyDown));
|
|
359
432
|
|
|
360
|
-
|
|
433
|
+
/*
|
|
361
434
|
* EFFECTS
|
|
362
435
|
*/
|
|
363
436
|
React.useEffect(() => {
|
|
@@ -395,5 +468,8 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
395
468
|
apiRef.current.setRowSelectionModel([]);
|
|
396
469
|
}
|
|
397
470
|
}, [apiRef, canHaveMultipleSelection, checkboxSelection, isStateControlled, props.rowSelection]);
|
|
471
|
+
React.useEffect(() => {
|
|
472
|
+
runIfRowSelectionIsEnabled(removeOutdatedSelection);
|
|
473
|
+
}, [removeOutdatedSelection, runIfRowSelectionIsEnabled]);
|
|
398
474
|
};
|
|
399
475
|
exports.useGridRowSelection = useGridRowSelection;
|
|
@@ -3,12 +3,171 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.findRowsToSelect = exports.findRowsToDeselect = exports.ROW_SELECTION_PROPAGATION_DEFAULT = void 0;
|
|
7
|
+
exports.getCheckboxPropsSelector = getCheckboxPropsSelector;
|
|
6
8
|
exports.isMultipleRowSelectionEnabled = isMultipleRowSelectionEnabled;
|
|
7
9
|
var _useGridApiEventHandler = require("../../utils/useGridApiEventHandler");
|
|
10
|
+
var _gridRowsUtils = require("../rows/gridRowsUtils");
|
|
11
|
+
var _gridFilterSelector = require("../filter/gridFilterSelector");
|
|
12
|
+
var _gridSortingSelector = require("../sorting/gridSortingSelector");
|
|
13
|
+
var _gridRowSelectionSelector = require("./gridRowSelectionSelector");
|
|
14
|
+
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
15
|
+
var _createSelector = require("../../../utils/createSelector");
|
|
16
|
+
const ROW_SELECTION_PROPAGATION_DEFAULT = exports.ROW_SELECTION_PROPAGATION_DEFAULT = {
|
|
17
|
+
parents: false,
|
|
18
|
+
descendants: false
|
|
19
|
+
};
|
|
20
|
+
function getGridRowGroupSelectableDescendants(apiRef, groupId) {
|
|
21
|
+
const rowTree = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef);
|
|
22
|
+
const sortedRowIds = (0, _gridSortingSelector.gridSortedRowIdsSelector)(apiRef);
|
|
23
|
+
const filteredRowsLookup = (0, _gridFilterSelector.gridFilteredRowsLookupSelector)(apiRef);
|
|
24
|
+
const groupNode = rowTree[groupId];
|
|
25
|
+
if (!groupNode || groupNode.type !== 'group') {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const descendants = [];
|
|
29
|
+
const startIndex = sortedRowIds.findIndex(id => id === groupId) + 1;
|
|
30
|
+
for (let index = startIndex; index < sortedRowIds.length && rowTree[sortedRowIds[index]]?.depth > groupNode.depth; index += 1) {
|
|
31
|
+
const id = sortedRowIds[index];
|
|
32
|
+
if (filteredRowsLookup[id] !== false && apiRef.current.isRowSelectable(id)) {
|
|
33
|
+
descendants.push(id);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return descendants;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// TODO v8: Use `createSelectorV8`
|
|
40
|
+
function getCheckboxPropsSelector(groupId, autoSelectParents) {
|
|
41
|
+
return (0, _createSelector.createSelector)(_gridRowsSelector.gridRowTreeSelector, _gridSortingSelector.gridSortedRowIdsSelector, _gridFilterSelector.gridFilteredRowsLookupSelector, _gridRowSelectionSelector.selectedIdsLookupSelector, (rowTree, sortedRowIds, filteredRowsLookup, rowSelectionLookup) => {
|
|
42
|
+
const groupNode = rowTree[groupId];
|
|
43
|
+
if (!groupNode || groupNode.type !== 'group') {
|
|
44
|
+
return {
|
|
45
|
+
isIndeterminate: false,
|
|
46
|
+
isChecked: rowSelectionLookup[groupId] === groupId
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (rowSelectionLookup[groupId] === groupId) {
|
|
50
|
+
return {
|
|
51
|
+
isIndeterminate: false,
|
|
52
|
+
isChecked: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
let selectableDescendentsCount = 0;
|
|
56
|
+
let selectedDescendentsCount = 0;
|
|
57
|
+
const startIndex = sortedRowIds.findIndex(id => id === groupId) + 1;
|
|
58
|
+
for (let index = startIndex; index < sortedRowIds.length && rowTree[sortedRowIds[index]]?.depth > groupNode.depth; index += 1) {
|
|
59
|
+
const id = sortedRowIds[index];
|
|
60
|
+
if (filteredRowsLookup[id] !== false) {
|
|
61
|
+
selectableDescendentsCount += 1;
|
|
62
|
+
if (rowSelectionLookup[id] !== undefined) {
|
|
63
|
+
selectedDescendentsCount += 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
isIndeterminate: selectedDescendentsCount > 0 && selectedDescendentsCount < selectableDescendentsCount || selectedDescendentsCount === selectableDescendentsCount && rowSelectionLookup[groupId] === undefined,
|
|
69
|
+
isChecked: autoSelectParents ? selectedDescendentsCount > 0 : rowSelectionLookup[groupId] === groupId
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
8
73
|
function isMultipleRowSelectionEnabled(props) {
|
|
9
74
|
if (props.signature === _useGridApiEventHandler.GridSignature.DataGrid) {
|
|
10
75
|
// DataGrid Community has multiple row selection enabled only if checkbox selection is enabled.
|
|
11
76
|
return props.checkboxSelection && props.disableMultipleRowSelection !== true;
|
|
12
77
|
}
|
|
13
78
|
return !props.disableMultipleRowSelection;
|
|
14
|
-
}
|
|
79
|
+
}
|
|
80
|
+
const getRowNodeParents = (tree, id) => {
|
|
81
|
+
const parents = [];
|
|
82
|
+
let parent = id;
|
|
83
|
+
while (parent != null && parent !== _gridRowsUtils.GRID_ROOT_GROUP_ID) {
|
|
84
|
+
const node = tree[parent];
|
|
85
|
+
if (!node) {
|
|
86
|
+
return parents;
|
|
87
|
+
}
|
|
88
|
+
parents.push(parent);
|
|
89
|
+
parent = node.parent;
|
|
90
|
+
}
|
|
91
|
+
return parents;
|
|
92
|
+
};
|
|
93
|
+
const getFilteredRowNodeSiblings = (tree, filteredRows, id) => {
|
|
94
|
+
const node = tree[id];
|
|
95
|
+
if (!node) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const parent = node.parent;
|
|
99
|
+
if (parent == null) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
const parentNode = tree[parent];
|
|
103
|
+
return parentNode.children.filter(childId => childId !== id && filteredRows[childId]);
|
|
104
|
+
};
|
|
105
|
+
const findRowsToSelect = (apiRef, tree, selectedRow, autoSelectDescendants, autoSelectParents, addRow) => {
|
|
106
|
+
const filteredRows = (0, _gridFilterSelector.gridFilteredRowsLookupSelector)(apiRef);
|
|
107
|
+
const selectedIdsLookup = (0, _gridRowSelectionSelector.selectedIdsLookupSelector)(apiRef);
|
|
108
|
+
const selectedDescendants = new Set([]);
|
|
109
|
+
if (!autoSelectDescendants && !autoSelectParents) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (autoSelectDescendants) {
|
|
113
|
+
const rowNode = tree[selectedRow];
|
|
114
|
+
if (rowNode?.type === 'group') {
|
|
115
|
+
const descendants = getGridRowGroupSelectableDescendants(apiRef, selectedRow);
|
|
116
|
+
descendants.forEach(rowId => {
|
|
117
|
+
addRow(rowId);
|
|
118
|
+
selectedDescendants.add(rowId);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (autoSelectParents) {
|
|
123
|
+
const checkAllDescendantsSelected = rowId => {
|
|
124
|
+
if (selectedIdsLookup[rowId] !== rowId && !selectedDescendants.has(rowId)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
const node = tree[rowId];
|
|
128
|
+
if (node?.type !== 'group') {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return node.children.every(checkAllDescendantsSelected);
|
|
132
|
+
};
|
|
133
|
+
const traverseParents = rowId => {
|
|
134
|
+
const siblings = getFilteredRowNodeSiblings(tree, filteredRows, rowId);
|
|
135
|
+
if (siblings.length === 0 || siblings.every(checkAllDescendantsSelected)) {
|
|
136
|
+
const rowNode = tree[rowId];
|
|
137
|
+
const parent = rowNode.parent;
|
|
138
|
+
if (parent != null && parent !== _gridRowsUtils.GRID_ROOT_GROUP_ID && apiRef.current.isRowSelectable(parent)) {
|
|
139
|
+
addRow(parent);
|
|
140
|
+
selectedDescendants.add(parent);
|
|
141
|
+
traverseParents(parent);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
traverseParents(selectedRow);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
exports.findRowsToSelect = findRowsToSelect;
|
|
149
|
+
const findRowsToDeselect = (apiRef, tree, deselectedRow, autoSelectDescendants, autoSelectParents, removeRow) => {
|
|
150
|
+
const selectedIdsLookup = (0, _gridRowSelectionSelector.selectedIdsLookupSelector)(apiRef);
|
|
151
|
+
if (!autoSelectParents && !autoSelectDescendants) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (autoSelectParents) {
|
|
155
|
+
const allParents = getRowNodeParents(tree, deselectedRow);
|
|
156
|
+
allParents.forEach(parent => {
|
|
157
|
+
const isSelected = selectedIdsLookup[parent] === parent;
|
|
158
|
+
if (isSelected) {
|
|
159
|
+
removeRow(parent);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if (autoSelectDescendants) {
|
|
164
|
+
const rowNode = tree[deselectedRow];
|
|
165
|
+
if (rowNode?.type === 'group') {
|
|
166
|
+
const descendants = getGridRowGroupSelectableDescendants(apiRef, deselectedRow);
|
|
167
|
+
descendants.forEach(descendant => {
|
|
168
|
+
removeRow(descendant);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
exports.findRowsToDeselect = findRowsToDeselect;
|
|
@@ -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);
|