@mui/x-data-grid 8.18.0 → 8.20.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 +175 -0
- package/DataGrid/useDataGridComponent.js +4 -3
- package/components/GridRow.js +5 -2
- package/components/GridRowDragAndDropOverlay.d.ts +7 -0
- package/components/GridRowDragAndDropOverlay.js +73 -0
- package/components/cell/GridActionsCell.d.ts +9 -0
- package/components/cell/GridActionsCell.js +54 -34
- package/components/cell/GridBooleanCell.js +0 -10
- package/components/cell/GridCell.js +4 -10
- package/components/columnHeaders/GridColumnHeaderItem.js +2 -2
- package/components/columnSelection/GridCellCheckboxRenderer.js +37 -22
- package/components/containers/GridRootStyles.js +17 -40
- package/components/toolbarV8/Toolbar.js +1 -1
- package/components/virtualization/GridVirtualScrollbar.d.ts +1 -0
- package/components/virtualization/GridVirtualScrollbar.js +13 -8
- package/components/virtualization/GridVirtualScroller.js +2 -1
- package/components/virtualization/GridVirtualScrollerRenderZone.js +1 -1
- package/constants/dataGridPropsDefaultValues.js +2 -1
- package/constants/gridClasses.d.ts +0 -8
- package/constants/gridClasses.js +1 -1
- package/esm/DataGrid/useDataGridComponent.js +5 -4
- package/esm/components/GridRow.js +5 -2
- package/esm/components/GridRowDragAndDropOverlay.d.ts +7 -0
- package/esm/components/GridRowDragAndDropOverlay.js +66 -0
- package/esm/components/cell/GridActionsCell.d.ts +9 -0
- package/esm/components/cell/GridActionsCell.js +55 -34
- package/esm/components/cell/GridBooleanCell.js +0 -10
- package/esm/components/cell/GridCell.js +4 -10
- package/esm/components/columnHeaders/GridColumnHeaderItem.js +2 -2
- package/esm/components/columnSelection/GridCellCheckboxRenderer.js +37 -22
- package/esm/components/containers/GridRootStyles.js +17 -40
- package/esm/components/toolbarV8/Toolbar.js +1 -1
- package/esm/components/virtualization/GridVirtualScrollbar.d.ts +1 -0
- package/esm/components/virtualization/GridVirtualScrollbar.js +12 -7
- package/esm/components/virtualization/GridVirtualScroller.js +2 -1
- package/esm/components/virtualization/GridVirtualScrollerRenderZone.js +1 -1
- package/esm/constants/dataGridPropsDefaultValues.js +2 -1
- package/esm/constants/gridClasses.d.ts +0 -8
- package/esm/constants/gridClasses.js +1 -1
- package/esm/hooks/core/gridPropsSelectors.d.ts +2 -1
- package/esm/hooks/core/gridPropsSelectors.js +3 -0
- package/esm/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +4 -3
- package/esm/hooks/core/useGridProps.js +8 -2
- package/esm/hooks/core/useGridVirtualizer.d.ts +80 -6
- package/esm/hooks/core/useGridVirtualizer.js +27 -12
- package/esm/hooks/features/columnGrouping/useGridColumnGrouping.js +6 -1
- package/esm/hooks/features/columnMenu/useGridColumnMenu.js +14 -4
- package/esm/hooks/features/columns/useGridColumnSpanning.js +9 -4
- package/esm/hooks/features/dataSource/useGridDataSourceBase.js +2 -2
- package/esm/hooks/features/dimensions/useGridDimensions.js +12 -6
- package/esm/hooks/features/editing/useGridCellEditing.js +1 -1
- package/esm/hooks/features/editing/useGridRowEditing.js +1 -1
- package/esm/hooks/features/export/serializers/csvSerializer.js +2 -4
- package/esm/hooks/features/export/useGridPrintExport.js +18 -18
- package/esm/hooks/features/filter/gridFilterUtils.js +5 -11
- package/esm/hooks/features/filter/index.d.ts +1 -1
- package/esm/hooks/features/filter/index.js +1 -1
- package/esm/hooks/features/filter/useGridFilter.d.ts +1 -1
- package/esm/hooks/features/filter/useGridFilter.js +3 -1
- package/esm/hooks/features/focus/useGridFocus.js +0 -1
- package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
- package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +189 -25
- package/esm/hooks/features/pagination/useGridPaginationMeta.js +3 -3
- package/esm/hooks/features/pagination/useGridPaginationModel.js +7 -4
- package/esm/hooks/features/pagination/useGridRowCount.js +31 -15
- package/esm/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +19 -0
- package/esm/hooks/features/rowReorder/gridRowReorderSelector.d.ts +20 -1
- package/esm/hooks/features/rowReorder/gridRowReorderSelector.js +19 -1
- package/esm/hooks/features/rowSelection/useGridRowSelection.js +17 -8
- package/esm/hooks/features/rowSelection/utils.d.ts +1 -0
- package/esm/hooks/features/rowSelection/utils.js +17 -4
- package/esm/hooks/features/rows/useGridRowSpanning.js +23 -60
- package/esm/hooks/features/rows/useGridRows.js +3 -1
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +1 -0
- package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +57 -7
- package/esm/hooks/features/scroll/useGridScroll.js +2 -3
- package/esm/hooks/features/sorting/gridSortingUtils.js +1 -3
- package/esm/hooks/features/sorting/useGridSorting.d.ts +1 -1
- package/esm/hooks/features/sorting/useGridSorting.js +3 -1
- package/esm/hooks/features/virtualization/useGridVirtualization.js +24 -5
- package/esm/hooks/utils/useGridEvent.js +6 -2
- package/esm/hooks/utils/useGridSelector.js +2 -4
- package/esm/hooks/utils/useRunOncePerLoop.d.ts +4 -1
- package/esm/hooks/utils/useRunOncePerLoop.js +28 -18
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +5 -4
- package/esm/internals/index.js +3 -3
- package/esm/material/index.js +1 -4
- package/esm/models/api/gridRowApi.d.ts +14 -1
- package/esm/models/api/index.d.ts +1 -1
- package/esm/models/api/index.js +0 -1
- package/esm/models/colDef/gridColDef.d.ts +14 -0
- package/esm/models/configuration/gridConfiguration.d.ts +2 -2
- package/esm/models/configuration/gridRowConfiguration.d.ts +6 -5
- package/esm/models/events/gridEventLookup.d.ts +5 -0
- package/esm/models/gridStateCommunity.d.ts +1 -1
- package/esm/models/params/gridCellParams.d.ts +0 -10
- package/esm/models/props/DataGridProps.d.ts +13 -6
- package/esm/utils/keyboardUtils.d.ts +1 -8
- package/esm/utils/keyboardUtils.js +0 -7
- package/hooks/core/gridPropsSelectors.d.ts +2 -1
- package/hooks/core/gridPropsSelectors.js +4 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +4 -3
- package/hooks/core/useGridProps.js +8 -2
- package/hooks/core/useGridVirtualizer.d.ts +80 -6
- package/hooks/core/useGridVirtualizer.js +26 -11
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +6 -1
- package/hooks/features/columnMenu/useGridColumnMenu.js +14 -4
- package/hooks/features/columns/useGridColumnSpanning.js +9 -4
- package/hooks/features/dataSource/useGridDataSourceBase.js +2 -2
- package/hooks/features/dimensions/useGridDimensions.js +12 -6
- package/hooks/features/editing/useGridCellEditing.js +1 -1
- package/hooks/features/editing/useGridRowEditing.js +1 -1
- package/hooks/features/export/serializers/csvSerializer.js +2 -4
- package/hooks/features/export/useGridPrintExport.js +18 -18
- package/hooks/features/filter/gridFilterUtils.js +5 -11
- package/hooks/features/filter/index.d.ts +1 -1
- package/hooks/features/filter/index.js +6 -0
- package/hooks/features/filter/useGridFilter.d.ts +1 -1
- package/hooks/features/filter/useGridFilter.js +3 -1
- package/hooks/features/focus/useGridFocus.js +0 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -1
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +189 -25
- package/hooks/features/pagination/useGridPaginationMeta.js +2 -2
- package/hooks/features/pagination/useGridPaginationModel.js +7 -4
- package/hooks/features/pagination/useGridRowCount.js +30 -14
- package/hooks/features/rowReorder/gridRowReorderInterfaces.d.ts +19 -0
- package/hooks/features/rowReorder/gridRowReorderSelector.d.ts +20 -1
- package/hooks/features/rowReorder/gridRowReorderSelector.js +20 -2
- package/hooks/features/rowSelection/useGridRowSelection.js +17 -8
- package/hooks/features/rowSelection/utils.d.ts +1 -0
- package/hooks/features/rowSelection/utils.js +16 -3
- package/hooks/features/rows/useGridRowSpanning.js +23 -60
- package/hooks/features/rows/useGridRows.js +3 -1
- package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +1 -0
- package/hooks/features/rows/useGridRowsOverridableMethods.js +57 -7
- package/hooks/features/scroll/useGridScroll.js +2 -3
- package/hooks/features/sorting/gridSortingUtils.js +1 -3
- package/hooks/features/sorting/useGridSorting.d.ts +1 -1
- package/hooks/features/sorting/useGridSorting.js +3 -1
- package/hooks/features/virtualization/useGridVirtualization.js +24 -5
- package/hooks/utils/useGridEvent.js +6 -2
- package/hooks/utils/useGridSelector.js +2 -4
- package/hooks/utils/useRunOncePerLoop.d.ts +4 -1
- package/hooks/utils/useRunOncePerLoop.js +27 -18
- package/index.js +1 -1
- package/internals/index.d.ts +5 -4
- package/internals/index.js +16 -9
- package/material/index.js +1 -4
- package/models/api/gridRowApi.d.ts +14 -1
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -11
- package/models/colDef/gridColDef.d.ts +14 -0
- package/models/configuration/gridConfiguration.d.ts +2 -2
- package/models/configuration/gridRowConfiguration.d.ts +6 -5
- package/models/events/gridEventLookup.d.ts +5 -0
- package/models/gridStateCommunity.d.ts +1 -1
- package/models/params/gridCellParams.d.ts +0 -10
- package/models/props/DataGridProps.d.ts +13 -6
- package/package.json +3 -3
- package/utils/keyboardUtils.d.ts +1 -8
- package/utils/keyboardUtils.js +1 -13
|
@@ -70,7 +70,6 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
70
70
|
isRowSelectable: propIsRowSelectable
|
|
71
71
|
} = props;
|
|
72
72
|
const canHaveMultipleSelection = (0, _utils.isMultipleRowSelectionEnabled)(props);
|
|
73
|
-
const tree = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridRowTreeSelector);
|
|
74
73
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
75
74
|
let endId = id;
|
|
76
75
|
const startId = lastRowToggled.current ?? id;
|
|
@@ -109,6 +108,14 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
109
108
|
const currentModel = (0, _gridRowSelectionSelector.gridRowSelectionStateSelector)(apiRef);
|
|
110
109
|
if (currentModel !== model) {
|
|
111
110
|
logger.debug(`Setting selection model`);
|
|
111
|
+
|
|
112
|
+
// clear the reference to the last selected row if that row is not in the model anymore
|
|
113
|
+
if (lastRowToggled.current !== null) {
|
|
114
|
+
const isInModel = model.ids.has(lastRowToggled.current);
|
|
115
|
+
if (model.type === 'include' && !isInModel || model.type === 'exclude' && isInModel) {
|
|
116
|
+
lastRowToggled.current = null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
112
119
|
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
113
120
|
rowSelection: props.rowSelection ? model : emptyModel
|
|
114
121
|
}), reason);
|
|
@@ -136,7 +143,8 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
136
143
|
if (!apiRef.current.isRowSelectable(id)) {
|
|
137
144
|
return;
|
|
138
145
|
}
|
|
139
|
-
|
|
146
|
+
const tree = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef);
|
|
147
|
+
lastRowToggled.current = isSelected ? id : null;
|
|
140
148
|
if (resetSelection) {
|
|
141
149
|
logger.debug(`Setting selection for row ${id}`);
|
|
142
150
|
const newSelectionModel = {
|
|
@@ -181,12 +189,13 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
181
189
|
apiRef.current.setRowSelectionModel(newSelectionModel, 'singleRowSelection');
|
|
182
190
|
}
|
|
183
191
|
}
|
|
184
|
-
}, [apiRef, logger, applyAutoSelection,
|
|
192
|
+
}, [apiRef, logger, applyAutoSelection, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents, canHaveMultipleSelection]);
|
|
185
193
|
const selectRows = React.useCallback((ids, isSelected = true, resetSelection = false) => {
|
|
186
194
|
logger.debug(`Setting selection for several rows`);
|
|
187
195
|
if (props.rowSelection === false) {
|
|
188
196
|
return;
|
|
189
197
|
}
|
|
198
|
+
const tree = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef);
|
|
190
199
|
const selectableIds = new Set();
|
|
191
200
|
for (let i = 0; i < ids.length; i += 1) {
|
|
192
201
|
const id = ids[i];
|
|
@@ -247,7 +256,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
247
256
|
if (isSelectionValid) {
|
|
248
257
|
apiRef.current.setRowSelectionModel(newSelectionModel, 'multipleRowsSelection');
|
|
249
258
|
}
|
|
250
|
-
}, [logger, applyAutoSelection, canHaveMultipleSelection, apiRef,
|
|
259
|
+
}, [logger, applyAutoSelection, canHaveMultipleSelection, apiRef, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents, props.rowSelection]);
|
|
251
260
|
const getPropagatedRowSelectionModel = React.useCallback(inputSelectionModel => {
|
|
252
261
|
if (!isNestedData || !applyAutoSelection || inputSelectionModel.type === 'exclude' || inputSelectionModel.ids.size === 0 && inputSelectionModel.type === 'include') {
|
|
253
262
|
return inputSelectionModel;
|
|
@@ -256,6 +265,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
256
265
|
type: inputSelectionModel.type,
|
|
257
266
|
ids: new Set(inputSelectionModel.ids)
|
|
258
267
|
};
|
|
268
|
+
const tree = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef);
|
|
259
269
|
const selectionManager = (0, _gridRowSelectionManager.createRowSelectionManager)(propagatedSelectionModel);
|
|
260
270
|
const addRow = rowId => {
|
|
261
271
|
selectionManager.select(rowId);
|
|
@@ -264,7 +274,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
264
274
|
(0, _utils.findRowsToSelect)(apiRef, tree, id, props.rowSelectionPropagation?.descendants ?? false, props.rowSelectionPropagation?.parents ?? false, addRow, selectionManager);
|
|
265
275
|
}
|
|
266
276
|
return propagatedSelectionModel;
|
|
267
|
-
}, [apiRef,
|
|
277
|
+
}, [apiRef, props.rowSelectionPropagation?.descendants, props.rowSelectionPropagation?.parents, isNestedData, applyAutoSelection]);
|
|
268
278
|
const selectRowRange = React.useCallback(({
|
|
269
279
|
startId,
|
|
270
280
|
endId
|
|
@@ -333,7 +343,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
333
343
|
if (!props.rowSelectionPropagation?.parents) {
|
|
334
344
|
continue;
|
|
335
345
|
}
|
|
336
|
-
const node =
|
|
346
|
+
const node = rowTree[id];
|
|
337
347
|
if (node?.type === 'group') {
|
|
338
348
|
const isAutoGenerated = node.isAutoGenerated;
|
|
339
349
|
if (isAutoGenerated) {
|
|
@@ -374,7 +384,7 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
374
384
|
apiRef.current.setRowSelectionModel(newSelectionModel, 'multipleRowsSelection');
|
|
375
385
|
}
|
|
376
386
|
}
|
|
377
|
-
}, [apiRef, isNestedData, props.rowSelectionPropagation?.parents, props.keepNonExistentRowsSelected, props.filterMode,
|
|
387
|
+
}, [apiRef, isNestedData, props.rowSelectionPropagation?.parents, props.keepNonExistentRowsSelected, props.filterMode, getRowsToBeSelected]);
|
|
378
388
|
const handleSingleRowSelection = React.useCallback((id, event) => {
|
|
379
389
|
const hasCtrlKey = event.metaKey || event.ctrlKey;
|
|
380
390
|
|
|
@@ -538,7 +548,6 @@ const useGridRowSelection = (apiRef, props) => {
|
|
|
538
548
|
}
|
|
539
549
|
apiRef.current.setRowSelectionModel(propRowSelectionModel);
|
|
540
550
|
});
|
|
541
|
-
(0, _useGridEvent.useGridEvent)(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(() => removeOutdatedSelection(true)));
|
|
542
551
|
(0, _useGridEvent.useGridEvent)(apiRef, 'filteredRowsSet', runIfRowSelectionIsEnabled(() => removeOutdatedSelection()));
|
|
543
552
|
(0, _useGridEvent.useGridEvent)(apiRef, 'rowClick', runIfRowSelectionIsEnabled(handleRowClick));
|
|
544
553
|
(0, _useGridEvent.useGridEvent)(apiRef, 'rowSelectionCheckboxChange', runIfRowSelectionIsEnabled(handleRowSelectionCheckboxChange));
|
|
@@ -13,6 +13,7 @@ export declare const checkboxPropsSelector: (args_0: import("react").RefObject<{
|
|
|
13
13
|
}) => {
|
|
14
14
|
isIndeterminate: boolean;
|
|
15
15
|
isChecked: boolean;
|
|
16
|
+
isSelectable: boolean;
|
|
16
17
|
};
|
|
17
18
|
export declare function isMultipleRowSelectionEnabled(props: Pick<DataGridProcessedProps, 'signature' | 'disableMultipleRowSelection' | 'checkboxSelection'>): boolean;
|
|
18
19
|
export declare const findRowsToSelect: (apiRef: RefObject<GridPrivateApiCommunity>, tree: GridRowTreeConfig, selectedRow: GridRowId, autoSelectDescendants: boolean, autoSelectParents: boolean, addRow: (rowId: GridRowId) => void, rowSelectionManager?: RowSelectionManager) => void;
|
|
@@ -12,6 +12,8 @@ var _gridSortingSelector = require("../sorting/gridSortingSelector");
|
|
|
12
12
|
var _gridRowSelectionSelector = require("./gridRowSelectionSelector");
|
|
13
13
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
14
14
|
var _createSelector = require("../../../utils/createSelector");
|
|
15
|
+
var _columns = require("../columns");
|
|
16
|
+
var _gridPropsSelectors = require("../../core/gridPropsSelectors");
|
|
15
17
|
const ROW_SELECTION_PROPAGATION_DEFAULT = exports.ROW_SELECTION_PROPAGATION_DEFAULT = {
|
|
16
18
|
parents: true,
|
|
17
19
|
descendants: true
|
|
@@ -34,15 +36,25 @@ function getGridRowGroupSelectableDescendants(apiRef, groupId) {
|
|
|
34
36
|
}
|
|
35
37
|
return descendants;
|
|
36
38
|
}
|
|
37
|
-
const checkboxPropsSelector = exports.checkboxPropsSelector = (0, _createSelector.createSelector)(_gridRowsSelector.gridRowTreeSelector, _gridFilterSelector.gridFilteredRowsLookupSelector, _gridRowSelectionSelector.gridRowSelectionManagerSelector, (rowTree, filteredRowsLookup, rowSelectionManager, {
|
|
39
|
+
const checkboxPropsSelector = exports.checkboxPropsSelector = (0, _createSelector.createSelector)(_columns.gridColumnDefinitionsSelector, _gridRowsSelector.gridRowTreeSelector, _gridFilterSelector.gridFilteredRowsLookupSelector, _gridRowSelectionSelector.gridRowSelectionManagerSelector, _gridRowsSelector.gridRowsLookupSelector, _gridPropsSelectors.gridRowSelectableSelector, (columns, rowTree, filteredRowsLookup, rowSelectionManager, rowsLookup, isRowSelectable, {
|
|
38
40
|
groupId,
|
|
39
41
|
autoSelectParents
|
|
40
42
|
}) => {
|
|
41
43
|
const groupNode = rowTree[groupId];
|
|
44
|
+
const rowParams = {
|
|
45
|
+
id: groupId,
|
|
46
|
+
row: rowsLookup[groupId],
|
|
47
|
+
columns
|
|
48
|
+
};
|
|
49
|
+
let isSelectable = true;
|
|
50
|
+
if (typeof isRowSelectable === 'function') {
|
|
51
|
+
isSelectable = isRowSelectable(rowParams);
|
|
52
|
+
}
|
|
42
53
|
if (!groupNode || groupNode.type !== 'group' || rowSelectionManager.has(groupId)) {
|
|
43
54
|
return {
|
|
44
55
|
isIndeterminate: false,
|
|
45
|
-
isChecked: rowSelectionManager.has(groupId)
|
|
56
|
+
isChecked: rowSelectionManager.has(groupId),
|
|
57
|
+
isSelectable
|
|
46
58
|
};
|
|
47
59
|
}
|
|
48
60
|
let hasSelectedDescendant = false;
|
|
@@ -67,7 +79,8 @@ const checkboxPropsSelector = exports.checkboxPropsSelector = (0, _createSelecto
|
|
|
67
79
|
traverseDescendants(groupId);
|
|
68
80
|
return {
|
|
69
81
|
isIndeterminate: hasSelectedDescendant && hasUnSelectedDescendant,
|
|
70
|
-
isChecked: autoSelectParents ? hasSelectedDescendant && !hasUnSelectedDescendant : false
|
|
82
|
+
isChecked: autoSelectParents ? hasSelectedDescendant && !hasUnSelectedDescendant : false,
|
|
83
|
+
isSelectable
|
|
71
84
|
};
|
|
72
85
|
});
|
|
73
86
|
function isMultipleRowSelectionEnabled(props) {
|
|
@@ -16,8 +16,7 @@ var _gridVirtualizationSelectors = require("../virtualization/gridVirtualization
|
|
|
16
16
|
var _gridRowSpanningUtils = require("./gridRowSpanningUtils");
|
|
17
17
|
var _useGridEvent = require("../../utils/useGridEvent");
|
|
18
18
|
var _utils = require("../../../utils/utils");
|
|
19
|
-
var
|
|
20
|
-
var _gridRowsSelector = require("./gridRowsSelector");
|
|
19
|
+
var _useRunOncePerLoop = require("../../utils/useRunOncePerLoop");
|
|
21
20
|
const EMPTY_CACHES = {
|
|
22
21
|
spannedCells: {},
|
|
23
22
|
hiddenCells: {},
|
|
@@ -31,13 +30,6 @@ const EMPTY_STATE = {
|
|
|
31
30
|
caches: EMPTY_CACHES,
|
|
32
31
|
processedRange: EMPTY_RANGE
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Default number of rows to process during state initialization to avoid flickering.
|
|
37
|
-
* Number `20` is arbitrarily chosen to be large enough to cover most of the cases without
|
|
38
|
-
* compromising performance.
|
|
39
|
-
*/
|
|
40
|
-
const DEFAULT_ROWS_TO_PROCESS = 20;
|
|
41
33
|
const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToProcess, resetState) => {
|
|
42
34
|
const virtualizer = apiRef.current.virtualizer;
|
|
43
35
|
const previousState = resetState ? EMPTY_STATE : _features.Rowspan.selectors.state(virtualizer.store.state);
|
|
@@ -135,66 +127,26 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
|
|
|
135
127
|
processedRange
|
|
136
128
|
};
|
|
137
129
|
};
|
|
138
|
-
const getInitialRangeToProcess = (props, apiRef) => {
|
|
139
|
-
const rowCount = (0, _gridRowsSelector.gridDataRowIdsSelector)(apiRef).length;
|
|
140
|
-
if (props.pagination) {
|
|
141
|
-
const pageSize = (0, _pagination.gridPageSizeSelector)(apiRef);
|
|
142
|
-
let paginationLastRowIndex = DEFAULT_ROWS_TO_PROCESS;
|
|
143
|
-
if (pageSize > 0) {
|
|
144
|
-
paginationLastRowIndex = pageSize - 1;
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
firstRowIndex: 0,
|
|
148
|
-
lastRowIndex: Math.min(paginationLastRowIndex, rowCount)
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
firstRowIndex: 0,
|
|
153
|
-
lastRowIndex: Math.min(DEFAULT_ROWS_TO_PROCESS, rowCount)
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
130
|
|
|
157
131
|
/**
|
|
158
132
|
* @requires columnsStateInitializer (method) - should be initialized before
|
|
159
133
|
* @requires rowsStateInitializer (method) - should be initialized before
|
|
160
134
|
* @requires filterStateInitializer (method) - should be initialized before
|
|
161
135
|
*/
|
|
162
|
-
const rowSpanningStateInitializer =
|
|
163
|
-
if (!props.rowSpanning) {
|
|
164
|
-
return (0, _extends2.default)({}, state, {
|
|
165
|
-
rowSpanning: EMPTY_STATE
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
const rowIds = state.rows.dataRowIds || [];
|
|
169
|
-
const orderedFields = state.columns.orderedFields || [];
|
|
170
|
-
const dataRowIdToModelLookup = state.rows.dataRowIdToModelLookup;
|
|
171
|
-
const columnsLookup = state.columns.lookup;
|
|
172
|
-
const isFilteringPending = Boolean(state.filter.filterModel.items.length) || Boolean(state.filter.filterModel.quickFilterValues?.length);
|
|
173
|
-
if (!rowIds.length || !orderedFields.length || !dataRowIdToModelLookup || !columnsLookup || isFilteringPending) {
|
|
174
|
-
return (0, _extends2.default)({}, state, {
|
|
175
|
-
rowSpanning: EMPTY_STATE
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
const rangeToProcess = getInitialRangeToProcess(props, apiRef);
|
|
179
|
-
const rows = rowIds.map(id => ({
|
|
180
|
-
id,
|
|
181
|
-
model: dataRowIdToModelLookup[id]
|
|
182
|
-
}));
|
|
183
|
-
const colDefs = orderedFields.map(field => columnsLookup[field]);
|
|
184
|
-
const rowSpanning = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true);
|
|
136
|
+
const rowSpanningStateInitializer = state => {
|
|
185
137
|
return (0, _extends2.default)({}, state, {
|
|
186
|
-
rowSpanning
|
|
138
|
+
rowSpanning: EMPTY_STATE
|
|
187
139
|
});
|
|
188
140
|
};
|
|
189
141
|
exports.rowSpanningStateInitializer = rowSpanningStateInitializer;
|
|
190
142
|
const useGridRowSpanning = (apiRef, props) => {
|
|
191
|
-
const store = apiRef.current.virtualizer.store;
|
|
192
143
|
const updateRowSpanningState = React.useCallback((renderContext, resetState = false) => {
|
|
144
|
+
const store = apiRef.current.virtualizer.store;
|
|
193
145
|
const {
|
|
194
146
|
range,
|
|
195
147
|
rows: visibleRows
|
|
196
148
|
} = (0, _useGridVisibleRows.getVisibleRows)(apiRef);
|
|
197
|
-
if (resetState
|
|
149
|
+
if (resetState) {
|
|
198
150
|
store.set('rowSpanning', EMPTY_STATE);
|
|
199
151
|
}
|
|
200
152
|
if (range === null || !(0, _gridRowSpanningUtils.isRowContextInitialized)(renderContext)) {
|
|
@@ -220,7 +172,7 @@ const useGridRowSpanning = (apiRef, props) => {
|
|
|
220
172
|
return;
|
|
221
173
|
}
|
|
222
174
|
store.set('rowSpanning', newState);
|
|
223
|
-
}, [apiRef
|
|
175
|
+
}, [apiRef]);
|
|
224
176
|
|
|
225
177
|
// Reset events trigger a full re-computation of the row spanning state:
|
|
226
178
|
// - The `rowSpanning` prop is updated (feature flag)
|
|
@@ -228,26 +180,37 @@ const useGridRowSpanning = (apiRef, props) => {
|
|
|
228
180
|
// - The sorting is applied
|
|
229
181
|
// - The `paginationModel` is updated
|
|
230
182
|
// - The rows are updated
|
|
183
|
+
const {
|
|
184
|
+
schedule: deferredUpdateRowSpanningState,
|
|
185
|
+
cancel
|
|
186
|
+
} = (0, _useRunOncePerLoop.useRunOncePerLoop)(updateRowSpanningState);
|
|
231
187
|
const resetRowSpanningState = React.useCallback(() => {
|
|
232
188
|
const renderContext = (0, _gridVirtualizationSelectors.gridRenderContextSelector)(apiRef);
|
|
233
189
|
if (!(0, _gridRowSpanningUtils.isRowContextInitialized)(renderContext)) {
|
|
234
190
|
return;
|
|
235
191
|
}
|
|
236
|
-
|
|
237
|
-
}, [apiRef,
|
|
238
|
-
(0, _useGridEvent.useGridEvent)(apiRef, 'renderedRowsIntervalChange', (0, _utils.runIf)(props.rowSpanning,
|
|
192
|
+
deferredUpdateRowSpanningState(renderContext, true);
|
|
193
|
+
}, [apiRef, deferredUpdateRowSpanningState]);
|
|
194
|
+
(0, _useGridEvent.useGridEvent)(apiRef, 'renderedRowsIntervalChange', (0, _utils.runIf)(props.rowSpanning, renderContext => {
|
|
195
|
+
const didHavePendingReset = cancel();
|
|
196
|
+
updateRowSpanningState(renderContext, didHavePendingReset);
|
|
197
|
+
}));
|
|
239
198
|
(0, _useGridEvent.useGridEvent)(apiRef, 'sortedRowsSet', (0, _utils.runIf)(props.rowSpanning, resetRowSpanningState));
|
|
240
199
|
(0, _useGridEvent.useGridEvent)(apiRef, 'paginationModelChange', (0, _utils.runIf)(props.rowSpanning, resetRowSpanningState));
|
|
241
200
|
(0, _useGridEvent.useGridEvent)(apiRef, 'filteredRowsSet', (0, _utils.runIf)(props.rowSpanning, resetRowSpanningState));
|
|
242
201
|
(0, _useGridEvent.useGridEvent)(apiRef, 'columnsChange', (0, _utils.runIf)(props.rowSpanning, resetRowSpanningState));
|
|
243
202
|
React.useEffect(() => {
|
|
203
|
+
const store = apiRef.current.virtualizer?.store;
|
|
204
|
+
if (!store) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
244
207
|
if (!props.rowSpanning) {
|
|
245
208
|
if (store.state.rowSpanning !== EMPTY_STATE) {
|
|
246
209
|
store.set('rowSpanning', EMPTY_STATE);
|
|
247
210
|
}
|
|
248
|
-
} else if (store.state.rowSpanning
|
|
249
|
-
|
|
211
|
+
} else if (store.state.rowSpanning === EMPTY_STATE) {
|
|
212
|
+
updateRowSpanningState((0, _gridVirtualizationSelectors.gridRenderContextSelector)(apiRef));
|
|
250
213
|
}
|
|
251
|
-
}, [apiRef,
|
|
214
|
+
}, [apiRef, props.rowSpanning, updateRowSpanningState]);
|
|
252
215
|
};
|
|
253
216
|
exports.useGridRowSpanning = useGridRowSpanning;
|
|
@@ -60,7 +60,8 @@ const useGridRows = (apiRef, props, configuration) => {
|
|
|
60
60
|
|
|
61
61
|
// Get overridable methods from configuration
|
|
62
62
|
const {
|
|
63
|
-
setRowIndex
|
|
63
|
+
setRowIndex,
|
|
64
|
+
setRowPosition
|
|
64
65
|
} = configuration.hooks.useGridRowsOverridableMethods(apiRef, props);
|
|
65
66
|
const getRow = React.useCallback(id => {
|
|
66
67
|
const model = (0, _gridRowsSelector.gridRowsLookupSelector)(apiRef)[id];
|
|
@@ -345,6 +346,7 @@ const useGridRows = (apiRef, props, configuration) => {
|
|
|
345
346
|
};
|
|
346
347
|
const rowProApi = {
|
|
347
348
|
setRowIndex,
|
|
349
|
+
setRowPosition,
|
|
348
350
|
setRowChildrenExpansion,
|
|
349
351
|
getRowGroupChildren,
|
|
350
352
|
expandAllRows,
|
|
@@ -3,4 +3,5 @@ import { GridRowId } from "../../../models/gridRows.js";
|
|
|
3
3
|
import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
|
|
4
4
|
export declare const useGridRowsOverridableMethods: (apiRef: RefObject<GridPrivateApiCommunity>) => {
|
|
5
5
|
setRowIndex: (rowId: GridRowId, targetIndex: number) => void;
|
|
6
|
+
setRowPosition: (sourceRowId: GridRowId, targetRowId: GridRowId, position: import("../../../internals/index.js").RowReorderDropPosition) => void | Promise<void>;
|
|
6
7
|
};
|
|
@@ -9,20 +9,69 @@ exports.useGridRowsOverridableMethods = void 0;
|
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _gridRowsSelector = require("./gridRowsSelector");
|
|
12
|
+
var _gridFilterSelector = require("../filter/gridFilterSelector");
|
|
12
13
|
var _gridRowsUtils = require("./gridRowsUtils");
|
|
13
14
|
const useGridRowsOverridableMethods = apiRef => {
|
|
15
|
+
const setRowPosition = React.useCallback((sourceRowId, targetRowId, position) => {
|
|
16
|
+
const sourceNode = (0, _gridRowsSelector.gridRowNodeSelector)(apiRef, sourceRowId);
|
|
17
|
+
const targetNode = (0, _gridRowsSelector.gridRowNodeSelector)(apiRef, targetRowId);
|
|
18
|
+
if (!sourceNode) {
|
|
19
|
+
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
|
|
20
|
+
}
|
|
21
|
+
if (!targetNode) {
|
|
22
|
+
throw new Error(`MUI X: No row with id #${targetRowId} found.`);
|
|
23
|
+
}
|
|
24
|
+
if (sourceNode.type !== 'leaf') {
|
|
25
|
+
throw new Error(`MUI X: The row reordering does not support reordering of footer or grouping rows.`);
|
|
26
|
+
}
|
|
27
|
+
if (position === 'inside') {
|
|
28
|
+
throw new Error(`MUI X: The 'inside' position is only supported for tree data. Use 'above' or 'below' for flat data.`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Get the target index from the targetRowId using the lookup selector
|
|
32
|
+
const sortedFilteredRowIndexLookup = (0, _gridFilterSelector.gridExpandedSortedRowIndexLookupSelector)(apiRef);
|
|
33
|
+
const targetRowIndexUnadjusted = sortedFilteredRowIndexLookup[targetRowId];
|
|
34
|
+
if (targetRowIndexUnadjusted === undefined) {
|
|
35
|
+
throw new Error(`MUI X: Target row with id #${targetRowId} not found in current view.`);
|
|
36
|
+
}
|
|
37
|
+
const sourceRowIndex = sortedFilteredRowIndexLookup[sourceRowId];
|
|
38
|
+
if (sourceRowIndex === undefined) {
|
|
39
|
+
throw new Error(`MUI X: Source row with id #${sourceRowId} not found in current view.`);
|
|
40
|
+
}
|
|
41
|
+
const dragDirection = targetRowIndexUnadjusted < sourceRowIndex ? 'up' : 'down';
|
|
42
|
+
let targetRowIndex;
|
|
43
|
+
if (dragDirection === 'up') {
|
|
44
|
+
targetRowIndex = position === 'above' ? targetRowIndexUnadjusted : targetRowIndexUnadjusted + 1;
|
|
45
|
+
} else {
|
|
46
|
+
targetRowIndex = position === 'above' ? targetRowIndexUnadjusted - 1 : targetRowIndexUnadjusted;
|
|
47
|
+
}
|
|
48
|
+
if (targetRowIndex === sourceRowIndex) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
apiRef.current.setState(state => {
|
|
52
|
+
const group = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef)[_gridRowsUtils.GRID_ROOT_GROUP_ID];
|
|
53
|
+
const allRows = group.children;
|
|
54
|
+
const updatedRows = [...allRows];
|
|
55
|
+
updatedRows.splice(targetRowIndex, 0, updatedRows.splice(sourceRowIndex, 1)[0]);
|
|
56
|
+
return (0, _extends2.default)({}, state, {
|
|
57
|
+
rows: (0, _extends2.default)({}, state.rows, {
|
|
58
|
+
tree: (0, _extends2.default)({}, state.rows.tree, {
|
|
59
|
+
[_gridRowsUtils.GRID_ROOT_GROUP_ID]: (0, _extends2.default)({}, group, {
|
|
60
|
+
children: updatedRows
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
apiRef.current.publishEvent('rowsSet');
|
|
67
|
+
}, [apiRef]);
|
|
14
68
|
const setRowIndex = React.useCallback((rowId, targetIndex) => {
|
|
15
69
|
const node = (0, _gridRowsSelector.gridRowNodeSelector)(apiRef, rowId);
|
|
16
70
|
if (!node) {
|
|
17
71
|
throw new Error(`MUI X: No row with id #${rowId} found.`);
|
|
18
72
|
}
|
|
19
|
-
|
|
20
|
-
// TODO: Remove irrelevant checks
|
|
21
|
-
if (node.parent !== _gridRowsUtils.GRID_ROOT_GROUP_ID) {
|
|
22
|
-
throw new Error(`MUI X: The row reordering do not support reordering of grouped rows yet.`);
|
|
23
|
-
}
|
|
24
73
|
if (node.type !== 'leaf') {
|
|
25
|
-
throw new Error(`MUI X: The row reordering
|
|
74
|
+
throw new Error(`MUI X: The row reordering does not support reordering of footer or grouping rows.`);
|
|
26
75
|
}
|
|
27
76
|
apiRef.current.setState(state => {
|
|
28
77
|
const group = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef)[_gridRowsUtils.GRID_ROOT_GROUP_ID];
|
|
@@ -46,7 +95,8 @@ const useGridRowsOverridableMethods = apiRef => {
|
|
|
46
95
|
apiRef.current.publishEvent('rowsSet');
|
|
47
96
|
}, [apiRef]);
|
|
48
97
|
return {
|
|
49
|
-
setRowIndex
|
|
98
|
+
setRowIndex,
|
|
99
|
+
setRowPosition
|
|
50
100
|
};
|
|
51
101
|
};
|
|
52
102
|
exports.useGridRowsOverridableMethods = useGridRowsOverridableMethods;
|
|
@@ -9,7 +9,6 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
var _RtlProvider = require("@mui/system/RtlProvider");
|
|
10
10
|
var _useGridLogger = require("../../utils/useGridLogger");
|
|
11
11
|
var _gridColumnsSelector = require("../columns/gridColumnsSelector");
|
|
12
|
-
var _useGridSelector = require("../../utils/useGridSelector");
|
|
13
12
|
var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
|
|
14
13
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
15
14
|
var _gridRowsMetaSelector = require("../rows/gridRowsMetaSelector");
|
|
@@ -53,7 +52,6 @@ const useGridScroll = (apiRef, props) => {
|
|
|
53
52
|
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridScroll');
|
|
54
53
|
const colRef = apiRef.current.columnHeadersContainerRef;
|
|
55
54
|
const virtualScrollerRef = apiRef.current.virtualScrollerRef;
|
|
56
|
-
const visibleSortedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridFilterSelector.gridExpandedSortedRowEntriesSelector);
|
|
57
55
|
const scrollToIndexes = React.useCallback(params => {
|
|
58
56
|
const dimensions = (0, _dimensions.gridDimensionsSelector)(apiRef);
|
|
59
57
|
const totalRowCount = (0, _gridRowsSelector.gridRowCountSelector)(apiRef);
|
|
@@ -68,6 +66,7 @@ const useGridScroll = (apiRef, props) => {
|
|
|
68
66
|
const columnPositions = (0, _gridColumnsSelector.gridColumnPositionsSelector)(apiRef);
|
|
69
67
|
let cellWidth;
|
|
70
68
|
if (typeof params.rowIndex !== 'undefined') {
|
|
69
|
+
const visibleSortedRows = (0, _gridFilterSelector.gridExpandedSortedRowEntriesSelector)(apiRef);
|
|
71
70
|
const rowId = visibleSortedRows[params.rowIndex]?.id;
|
|
72
71
|
const cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, params.colIndex);
|
|
73
72
|
if (cellColSpanInfo && !cellColSpanInfo.spannedByColSpan) {
|
|
@@ -104,7 +103,7 @@ const useGridScroll = (apiRef, props) => {
|
|
|
104
103
|
return true;
|
|
105
104
|
}
|
|
106
105
|
return false;
|
|
107
|
-
}, [logger, apiRef, virtualScrollerRef, props.pagination
|
|
106
|
+
}, [logger, apiRef, virtualScrollerRef, props.pagination]);
|
|
108
107
|
const scroll = React.useCallback(params => {
|
|
109
108
|
if (virtualScrollerRef.current && params.left !== undefined && colRef.current) {
|
|
110
109
|
const direction = isRtl ? -1 : 1;
|
|
@@ -10,9 +10,7 @@ var _warning = require("@mui/x-internals/warning");
|
|
|
10
10
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
11
11
|
const sanitizeSortModel = (model, disableMultipleColumnsSorting) => {
|
|
12
12
|
if (disableMultipleColumnsSorting && model.length > 1) {
|
|
13
|
-
|
|
14
|
-
(0, _warning.warnOnce)(['MUI X: The `sortModel` can only contain a single item when the `disableMultipleColumnsSorting` prop is set to `true`.', 'If you are using the community version of the Data Grid, this prop is always `true`.'], 'error');
|
|
15
|
-
}
|
|
13
|
+
(0, _warning.warnOnce)(['MUI X: The `sortModel` can only contain a single item when the `disableMultipleColumnsSorting` prop is set to `true`.', 'If you are using the community version of the Data Grid, this prop is always `true`.'], 'error');
|
|
16
14
|
return [model[0]];
|
|
17
15
|
}
|
|
18
16
|
return model;
|
|
@@ -7,4 +7,4 @@ export declare const sortingStateInitializer: GridStateInitializer<Pick<DataGrid
|
|
|
7
7
|
* @requires useGridRows (event)
|
|
8
8
|
* @requires useGridColumns (event)
|
|
9
9
|
*/
|
|
10
|
-
export declare const useGridSorting: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "initialState" | "sortModel" | "onSortModelChange" | "sortingOrder" | "sortingMode" | "disableColumnSorting" | "disableMultipleColumnsSorting" | "multipleColumnsSortingMode">) => void;
|
|
10
|
+
export declare const useGridSorting: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "initialState" | "sortModel" | "onSortModelChange" | "sortingOrder" | "sortingMode" | "disableColumnSorting" | "disableMultipleColumnsSorting" | "multipleColumnsSortingMode" | "signature">) => void;
|
|
@@ -245,7 +245,9 @@ const useGridSorting = (apiRef, props) => {
|
|
|
245
245
|
* 1ST RENDER
|
|
246
246
|
*/
|
|
247
247
|
(0, _useFirstRender.useFirstRender)(() => {
|
|
248
|
-
|
|
248
|
+
if (props.signature === 'DataGrid') {
|
|
249
|
+
apiRef.current.applySorting();
|
|
250
|
+
}
|
|
249
251
|
});
|
|
250
252
|
|
|
251
253
|
/**
|
|
@@ -39,9 +39,6 @@ const virtualizationStateInitializer = (state, props) => {
|
|
|
39
39
|
};
|
|
40
40
|
exports.virtualizationStateInitializer = virtualizationStateInitializer;
|
|
41
41
|
function useGridVirtualization(apiRef, rootProps) {
|
|
42
|
-
const {
|
|
43
|
-
virtualizer
|
|
44
|
-
} = apiRef.current;
|
|
45
42
|
const {
|
|
46
43
|
autoHeight,
|
|
47
44
|
disableVirtualization
|
|
@@ -52,7 +49,14 @@ function useGridVirtualization(apiRef, rootProps) {
|
|
|
52
49
|
*/
|
|
53
50
|
|
|
54
51
|
const setVirtualization = enabled => {
|
|
52
|
+
const {
|
|
53
|
+
virtualizer
|
|
54
|
+
} = apiRef.current;
|
|
55
55
|
enabled && (enabled = HAS_LAYOUT);
|
|
56
|
+
const snapshot = virtualizer.store.getSnapshot();
|
|
57
|
+
if (snapshot.virtualization.enabled === enabled && snapshot.virtualization.enabledForRows === enabled && snapshot.virtualization.enabledForColumns === enabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
56
60
|
virtualizer.store.set('virtualization', (0, _extends2.default)({}, virtualizer.store.state.virtualization, {
|
|
57
61
|
enabled,
|
|
58
62
|
enabledForColumns: enabled,
|
|
@@ -60,7 +64,14 @@ function useGridVirtualization(apiRef, rootProps) {
|
|
|
60
64
|
}));
|
|
61
65
|
};
|
|
62
66
|
const setColumnVirtualization = enabled => {
|
|
67
|
+
const {
|
|
68
|
+
virtualizer
|
|
69
|
+
} = apiRef.current;
|
|
63
70
|
enabled && (enabled = HAS_LAYOUT);
|
|
71
|
+
const snapshot = virtualizer.store.getSnapshot();
|
|
72
|
+
if (snapshot.virtualization.enabledForColumns === enabled) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
64
75
|
virtualizer.store.set('virtualization', (0, _extends2.default)({}, virtualizer.store.state.virtualization, {
|
|
65
76
|
enabledForColumns: enabled
|
|
66
77
|
}));
|
|
@@ -70,7 +81,12 @@ function useGridVirtualization(apiRef, rootProps) {
|
|
|
70
81
|
unstable_setColumnVirtualization: setColumnVirtualization
|
|
71
82
|
};
|
|
72
83
|
(0, _useGridApiMethod.useGridApiMethod)(apiRef, api, 'public');
|
|
73
|
-
const forceUpdateRenderContext =
|
|
84
|
+
const forceUpdateRenderContext = () => {
|
|
85
|
+
const {
|
|
86
|
+
virtualizer
|
|
87
|
+
} = apiRef.current;
|
|
88
|
+
virtualizer?.api.scheduleUpdateRenderContext();
|
|
89
|
+
};
|
|
74
90
|
apiRef.current.register('private', {
|
|
75
91
|
updateRenderContext: forceUpdateRenderContext
|
|
76
92
|
});
|
|
@@ -85,7 +101,10 @@ function useGridVirtualization(apiRef, rootProps) {
|
|
|
85
101
|
|
|
86
102
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
87
103
|
React.useEffect(() => {
|
|
104
|
+
if (!apiRef.current.virtualizer) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
88
107
|
setVirtualization(!rootProps.disableVirtualization);
|
|
89
|
-
}, [disableVirtualization, autoHeight]);
|
|
108
|
+
}, [apiRef, disableVirtualization, autoHeight]);
|
|
90
109
|
/* eslint-enable react-hooks/exhaustive-deps */
|
|
91
110
|
}
|
|
@@ -33,7 +33,9 @@ function useGridEvent(apiRef, eventName, handler, options) {
|
|
|
33
33
|
const cleanupTokenRef = React.useRef(null);
|
|
34
34
|
if (!subscription.current && handlerRef.current) {
|
|
35
35
|
const enhancedHandler = (params, event, details) => {
|
|
36
|
-
|
|
36
|
+
// Check for the existence of the event once more to avoid Safari 26 issue
|
|
37
|
+
// https://github.com/mui/mui-x/issues/20159
|
|
38
|
+
if (event && !event.defaultMuiPrevented) {
|
|
37
39
|
handlerRef.current?.(params, event, details);
|
|
38
40
|
}
|
|
39
41
|
};
|
|
@@ -60,7 +62,9 @@ function useGridEvent(apiRef, eventName, handler, options) {
|
|
|
60
62
|
React.useEffect(() => {
|
|
61
63
|
if (!subscription.current && handlerRef.current) {
|
|
62
64
|
const enhancedHandler = (params, event, details) => {
|
|
63
|
-
|
|
65
|
+
// Check for the existence of the event once more to avoid Safari 26 issue
|
|
66
|
+
// https://github.com/mui/mui-x/issues/20159
|
|
67
|
+
if (event && !event.defaultMuiPrevented) {
|
|
64
68
|
handlerRef.current?.(params, event, details);
|
|
65
69
|
}
|
|
66
70
|
};
|
|
@@ -39,10 +39,8 @@ const createRefs = () => ({
|
|
|
39
39
|
const EMPTY = [];
|
|
40
40
|
const emptyGetSnapshot = () => null;
|
|
41
41
|
function useGridSelector(apiRef, selector, args = undefined, equals = defaultCompare) {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
(0, _warning.warnOnce)(['MUI X: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
|
|
45
|
-
}
|
|
42
|
+
if (!apiRef.current.state) {
|
|
43
|
+
(0, _warning.warnOnce)(['MUI X: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
|
|
46
44
|
}
|
|
47
45
|
const refs = (0, _useLazyRef.useLazyRef)(createRefs);
|
|
48
46
|
const didInit = refs.current.selector !== null;
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export declare function useRunOncePerLoop<T extends (...args: any[]) => void>(callback: T
|
|
1
|
+
export declare function useRunOncePerLoop<T extends (...args: any[]) => void>(callback: T): {
|
|
2
|
+
schedule: (...args: Parameters<T>) => void;
|
|
3
|
+
cancel: () => boolean;
|
|
4
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
'use client';
|
|
2
3
|
|
|
3
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -6,28 +7,36 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
7
|
});
|
|
7
8
|
exports.useRunOncePerLoop = useRunOncePerLoop;
|
|
8
9
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function useRunOncePerLoop(callback
|
|
10
|
-
const
|
|
10
|
+
function useRunOncePerLoop(callback) {
|
|
11
|
+
const scheduledCallbackRef = React.useRef(null);
|
|
11
12
|
const schedule = React.useCallback((...args) => {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
// for robustness, a fallback in case we don't react to state updates and layoutEffect is not run
|
|
14
|
+
// if we react to state updates, layoutEffect will run before microtasks
|
|
15
|
+
if (!scheduledCallbackRef.current) {
|
|
16
|
+
queueMicrotask(() => {
|
|
17
|
+
if (scheduledCallbackRef.current) {
|
|
18
|
+
scheduledCallbackRef.current();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
scheduledRef.current = false;
|
|
22
|
+
scheduledCallbackRef.current = () => {
|
|
23
|
+
scheduledCallbackRef.current = null;
|
|
18
24
|
callback(...args);
|
|
19
25
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return;
|
|
26
|
+
}, [callback]);
|
|
27
|
+
React.useLayoutEffect(() => {
|
|
28
|
+
if (scheduledCallbackRef.current) {
|
|
29
|
+
scheduledCallbackRef.current();
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
schedule,
|
|
34
|
+
cancel: () => {
|
|
35
|
+
if (scheduledCallbackRef.current) {
|
|
36
|
+
scheduledCallbackRef.current = null;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
30
40
|
}
|
|
31
|
-
}
|
|
32
|
-
return schedule;
|
|
41
|
+
};
|
|
33
42
|
}
|
package/index.js
CHANGED