@mui/x-data-grid 6.7.0 → 6.9.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 +145 -5541
- package/components/GridColumnHeaders.d.ts +2 -2
- package/components/GridColumnHeaders.js +3 -1
- package/components/GridPagination.d.ts +2 -2
- package/components/GridRow.d.ts +2 -2
- package/components/GridRow.js +33 -79
- package/components/cell/GridCell.d.ts +24 -15
- package/components/cell/GridCell.js +422 -45
- package/components/cell/GridEditInputCell.js +9 -9
- package/components/cell/index.d.ts +2 -1
- package/components/cell/index.js +1 -1
- package/components/containers/GridRootStyles.js +30 -16
- package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/components/panel/GridPanel.d.ts +1 -1
- package/components/toolbar/GridToolbar.js +2 -2
- package/components/virtualization/GridVirtualScroller.js +4 -9
- package/components/virtualization/GridVirtualScrollerContent.js +11 -20
- package/constants/defaultGridSlotsComponents.js +6 -2
- package/hooks/core/useGridApiInitialization.js +4 -1
- package/hooks/core/useGridStateInitialization.js +2 -9
- package/hooks/features/clipboard/useGridClipboard.js +1 -4
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
- package/hooks/features/columns/gridColumnsSelector.js +7 -7
- package/hooks/features/dimensions/useGridDimensions.js +6 -12
- package/hooks/features/editing/useGridCellEditing.js +5 -3
- package/hooks/features/editing/useGridRowEditing.js +14 -6
- package/hooks/features/filter/gridFilterSelector.js +8 -8
- package/hooks/features/filter/gridFilterUtils.d.ts +4 -1
- package/hooks/features/filter/gridFilterUtils.js +19 -13
- package/hooks/features/filter/useGridFilter.js +2 -1
- package/hooks/features/focus/useGridFocus.js +9 -4
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
- package/hooks/features/pagination/gridPaginationSelector.js +4 -4
- package/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
- package/hooks/features/rows/gridRowsSelector.js +3 -3
- package/hooks/features/rows/useGridParamsApi.d.ts +2 -0
- package/hooks/features/rows/useGridParamsApi.js +7 -15
- package/hooks/features/sorting/gridSortingSelector.js +3 -3
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +8 -816
- package/hooks/features/virtualization/useGridVirtualScroller.js +40 -38
- package/hooks/utils/index.d.ts +1 -1
- package/hooks/utils/index.js +1 -1
- package/hooks/utils/useGridSelector.d.ts +3 -1
- package/hooks/utils/useGridSelector.js +37 -6
- package/hooks/utils/useLazyRef.d.ts +2 -0
- package/hooks/utils/useLazyRef.js +9 -0
- package/hooks/utils/useOnMount.d.ts +2 -0
- package/hooks/utils/useOnMount.js +7 -0
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +1 -1
- package/legacy/components/GridColumnHeaders.js +3 -1
- package/legacy/components/GridRow.js +35 -79
- package/legacy/components/cell/GridCell.js +425 -46
- package/legacy/components/cell/GridEditInputCell.js +9 -9
- package/legacy/components/cell/index.js +1 -1
- package/legacy/components/containers/GridRootStyles.js +20 -17
- package/legacy/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/legacy/components/toolbar/GridToolbar.js +2 -2
- package/legacy/components/virtualization/GridVirtualScroller.js +4 -7
- package/legacy/components/virtualization/GridVirtualScrollerContent.js +10 -17
- package/legacy/constants/defaultGridSlotsComponents.js +6 -2
- package/legacy/hooks/core/useGridApiInitialization.js +4 -1
- package/legacy/hooks/core/useGridStateInitialization.js +2 -7
- package/legacy/hooks/features/clipboard/useGridClipboard.js +1 -4
- package/legacy/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
- package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
- package/legacy/hooks/features/columns/gridColumnsSelector.js +7 -7
- package/legacy/hooks/features/dimensions/useGridDimensions.js +6 -12
- package/legacy/hooks/features/editing/useGridCellEditing.js +5 -3
- package/legacy/hooks/features/editing/useGridRowEditing.js +15 -7
- package/legacy/hooks/features/filter/gridFilterSelector.js +8 -8
- package/legacy/hooks/features/filter/gridFilterUtils.js +23 -19
- package/legacy/hooks/features/filter/useGridFilter.js +2 -1
- package/legacy/hooks/features/focus/useGridFocus.js +9 -4
- package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
- package/legacy/hooks/features/pagination/gridPaginationSelector.js +4 -4
- package/legacy/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
- package/legacy/hooks/features/rows/gridRowsSelector.js +3 -3
- package/legacy/hooks/features/rows/useGridParamsApi.js +23 -15
- package/legacy/hooks/features/sorting/gridSortingSelector.js +3 -3
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +38 -34
- package/legacy/hooks/utils/index.js +1 -1
- package/legacy/hooks/utils/useGridSelector.js +43 -5
- package/legacy/hooks/utils/useLazyRef.js +9 -0
- package/legacy/hooks/utils/useOnMount.js +7 -0
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +1 -1
- package/legacy/locales/elGR.js +70 -79
- package/legacy/locales/ptBR.js +12 -13
- package/legacy/utils/Store.js +34 -0
- package/legacy/utils/createSelector.js +74 -6
- package/legacy/utils/doesSupportPreventScroll.js +13 -0
- package/legacy/utils/fastMemo.js +5 -0
- package/legacy/utils/fastObjectShallowCompare.js +32 -0
- package/legacy/utils/keyboardUtils.js +4 -2
- package/locales/elGR.js +66 -79
- package/locales/ptBR.js +12 -13
- package/models/api/gridCoreApi.d.ts +6 -0
- package/models/colDef/gridColDef.d.ts +4 -3
- package/models/colDef/gridColType.d.ts +3 -1
- package/models/events/gridEventLookup.d.ts +3 -3
- package/modern/components/GridColumnHeaders.js +3 -1
- package/modern/components/GridRow.js +32 -79
- package/modern/components/cell/GridCell.js +421 -45
- package/modern/components/cell/GridEditInputCell.js +9 -9
- package/modern/components/cell/index.js +1 -1
- package/modern/components/containers/GridRootStyles.js +30 -16
- package/modern/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/modern/components/toolbar/GridToolbar.js +2 -2
- package/modern/components/virtualization/GridVirtualScroller.js +4 -9
- package/modern/components/virtualization/GridVirtualScrollerContent.js +10 -20
- package/modern/constants/defaultGridSlotsComponents.js +6 -2
- package/modern/hooks/core/useGridApiInitialization.js +4 -1
- package/modern/hooks/core/useGridStateInitialization.js +2 -9
- package/modern/hooks/features/clipboard/useGridClipboard.js +1 -4
- package/modern/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -4
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +9 -3
- package/modern/hooks/features/columns/gridColumnsSelector.js +7 -7
- package/modern/hooks/features/dimensions/useGridDimensions.js +6 -12
- package/modern/hooks/features/editing/useGridCellEditing.js +5 -3
- package/modern/hooks/features/editing/useGridRowEditing.js +14 -6
- package/modern/hooks/features/filter/gridFilterSelector.js +8 -8
- package/modern/hooks/features/filter/gridFilterUtils.js +17 -12
- package/modern/hooks/features/filter/useGridFilter.js +2 -1
- package/modern/hooks/features/focus/useGridFocus.js +8 -4
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
- package/modern/hooks/features/pagination/gridPaginationSelector.js +4 -4
- package/modern/hooks/features/rowSelection/gridRowSelectionSelector.js +3 -3
- package/modern/hooks/features/rows/gridRowsSelector.js +3 -3
- package/modern/hooks/features/rows/useGridParamsApi.js +7 -15
- package/modern/hooks/features/sorting/gridSortingSelector.js +3 -3
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +40 -38
- package/modern/hooks/utils/index.js +1 -1
- package/modern/hooks/utils/useGridSelector.js +37 -6
- package/modern/hooks/utils/useLazyRef.js +9 -0
- package/modern/hooks/utils/useOnMount.js +7 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -1
- package/modern/locales/elGR.js +66 -79
- package/modern/locales/ptBR.js +12 -13
- package/modern/utils/Store.js +24 -0
- package/modern/utils/createSelector.js +74 -6
- package/modern/utils/doesSupportPreventScroll.js +13 -0
- package/modern/utils/fastMemo.js +5 -0
- package/modern/utils/fastObjectShallowCompare.js +32 -0
- package/modern/utils/keyboardUtils.js +4 -2
- package/node/components/GridColumnHeaders.js +4 -2
- package/node/components/GridRow.js +32 -79
- package/node/components/cell/GridCell.js +424 -47
- package/node/components/cell/GridEditInputCell.js +9 -9
- package/node/components/cell/index.js +17 -10
- package/node/components/containers/GridRootStyles.js +30 -16
- package/node/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/node/components/toolbar/GridToolbar.js +2 -2
- package/node/components/virtualization/GridVirtualScroller.js +4 -9
- package/node/components/virtualization/GridVirtualScrollerContent.js +10 -20
- package/node/constants/defaultGridSlotsComponents.js +4 -1
- package/node/hooks/core/useGridApiInitialization.js +4 -1
- package/node/hooks/core/useGridStateInitialization.js +2 -9
- package/node/hooks/features/clipboard/useGridClipboard.js +1 -4
- package/node/hooks/features/columnGrouping/gridColumnGroupsSelector.js +3 -3
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +8 -2
- package/node/hooks/features/columns/gridColumnsSelector.js +6 -6
- package/node/hooks/features/dimensions/useGridDimensions.js +6 -12
- package/node/hooks/features/editing/useGridCellEditing.js +5 -3
- package/node/hooks/features/editing/useGridRowEditing.js +14 -6
- package/node/hooks/features/filter/gridFilterSelector.js +7 -7
- package/node/hooks/features/filter/gridFilterUtils.js +17 -12
- package/node/hooks/features/filter/useGridFilter.js +2 -1
- package/node/hooks/features/focus/useGridFocus.js +8 -4
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +2 -3
- package/node/hooks/features/pagination/gridPaginationSelector.js +3 -3
- package/node/hooks/features/rowSelection/gridRowSelectionSelector.js +2 -2
- package/node/hooks/features/rows/gridRowsSelector.js +2 -2
- package/node/hooks/features/rows/useGridParamsApi.js +9 -15
- package/node/hooks/features/sorting/gridSortingSelector.js +2 -2
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +40 -36
- package/node/hooks/utils/index.js +14 -10
- package/node/hooks/utils/useGridSelector.js +41 -7
- package/node/hooks/utils/useLazyRef.js +17 -0
- package/node/hooks/utils/useOnMount.js +15 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +7 -0
- package/node/locales/elGR.js +66 -79
- package/node/locales/ptBR.js +12 -13
- package/node/utils/Store.js +31 -0
- package/node/utils/createSelector.js +77 -8
- package/node/utils/doesSupportPreventScroll.js +19 -0
- package/node/utils/fastMemo.js +13 -0
- package/node/utils/fastObjectShallowCompare.js +38 -0
- package/node/utils/keyboardUtils.js +4 -2
- package/package.json +2 -2
- package/utils/Store.d.ts +11 -0
- package/utils/Store.js +24 -0
- package/utils/createSelector.d.ts +1 -0
- package/utils/createSelector.js +74 -6
- package/utils/doesSupportPreventScroll.d.ts +1 -0
- package/utils/doesSupportPreventScroll.js +13 -0
- package/utils/fastMemo.d.ts +1 -0
- package/utils/fastMemo.js +5 -0
- package/utils/fastObjectShallowCompare.d.ts +1 -0
- package/utils/fastObjectShallowCompare.js +32 -0
- package/utils/keyboardUtils.js +4 -2
|
@@ -208,30 +208,32 @@ export var buildAggregatedFilterApplier = function buildAggregatedFilterApplier(
|
|
|
208
208
|
};
|
|
209
209
|
};
|
|
210
210
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var
|
|
225
|
-
var
|
|
211
|
+
var isNotNull = function isNotNull(result) {
|
|
212
|
+
return result != null;
|
|
213
|
+
};
|
|
214
|
+
var filterModelItems = function filterModelItems(cache, apiRef, items) {
|
|
215
|
+
if (!cache.cleanedFilterItems) {
|
|
216
|
+
cache.cleanedFilterItems = items.filter(function (item) {
|
|
217
|
+
return getFilterCallbackFromItem(item, apiRef) !== null;
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return cache.cleanedFilterItems;
|
|
221
|
+
};
|
|
222
|
+
export var passFilterLogic = function passFilterLogic(allFilterItemResults, allQuickFilterResults, filterModel, apiRef, cache) {
|
|
223
|
+
var cleanedFilterItems = filterModelItems(cache, apiRef, filterModel.items);
|
|
224
|
+
var cleanedFilterItemResults = allFilterItemResults.filter(isNotNull);
|
|
225
|
+
var cleanedQuickFilterResults = allQuickFilterResults.filter(isNotNull);
|
|
226
226
|
|
|
227
227
|
// get result for filter items model
|
|
228
|
-
if (
|
|
228
|
+
if (cleanedFilterItemResults.length > 0) {
|
|
229
|
+
var _filterModel$logicOpe;
|
|
229
230
|
// Return true if the item pass with one of the rows
|
|
230
231
|
var filterItemPredicate = function filterItemPredicate(item) {
|
|
231
|
-
return
|
|
232
|
+
return cleanedFilterItemResults.some(function (filterItemResult) {
|
|
232
233
|
return filterItemResult[item.id];
|
|
233
234
|
});
|
|
234
235
|
};
|
|
236
|
+
var logicOperator = (_filterModel$logicOpe = filterModel.logicOperator) != null ? _filterModel$logicOpe : getDefaultGridFilterModel().logicOperator;
|
|
235
237
|
if (logicOperator === GridLogicOperator.And) {
|
|
236
238
|
var passesAllFilters = cleanedFilterItems.every(filterItemPredicate);
|
|
237
239
|
if (!passesAllFilters) {
|
|
@@ -246,13 +248,15 @@ export var passFilterLogic = function passFilterLogic(allFilterItemResults, allQ
|
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
// get result for quick filter model
|
|
249
|
-
if (
|
|
251
|
+
if (cleanedQuickFilterResults.length > 0 && filterModel.quickFilterValues != null) {
|
|
252
|
+
var _filterModel$quickFil2;
|
|
250
253
|
// Return true if the item pass with one of the rows
|
|
251
254
|
var quickFilterValuePredicate = function quickFilterValuePredicate(value) {
|
|
252
|
-
return
|
|
255
|
+
return cleanedQuickFilterResults.some(function (quickFilterValueResult) {
|
|
253
256
|
return quickFilterValueResult[value];
|
|
254
257
|
});
|
|
255
258
|
};
|
|
259
|
+
var quickFilterLogicOperator = (_filterModel$quickFil2 = filterModel.quickFilterLogicOperator) != null ? _filterModel$quickFil2 : getDefaultGridFilterModel().quickFilterLogicOperator;
|
|
256
260
|
if (quickFilterLogicOperator === GridLogicOperator.And) {
|
|
257
261
|
var passesAllQuickFilterValues = filterModel.quickFilterValues.every(quickFilterValuePredicate);
|
|
258
262
|
if (!passesAllQuickFilterValues) {
|
|
@@ -272,6 +272,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
|
|
|
272
272
|
var tree = gridRowTreeSelector(apiRef);
|
|
273
273
|
var rowIds = tree[GRID_ROOT_GROUP_ID].children;
|
|
274
274
|
var filteredRowsLookup = {};
|
|
275
|
+
var filterCache = {};
|
|
275
276
|
for (var i = 0; i < rowIds.length; i += 1) {
|
|
276
277
|
var rowId = rowIds[i];
|
|
277
278
|
var isRowPassing = void 0;
|
|
@@ -281,7 +282,7 @@ export var useGridFilter = function useGridFilter(apiRef, props) {
|
|
|
281
282
|
var _params$isRowMatching = params.isRowMatchingFilters(rowId),
|
|
282
283
|
passingFilterItems = _params$isRowMatching.passingFilterItems,
|
|
283
284
|
passingQuickFilterValues = _params$isRowMatching.passingQuickFilterValues;
|
|
284
|
-
isRowPassing = passFilterLogic([passingFilterItems], [passingQuickFilterValues], params.filterModel, apiRef);
|
|
285
|
+
isRowPassing = passFilterLogic([passingFilterItems], [passingQuickFilterValues], params.filterModel, apiRef, filterCache);
|
|
285
286
|
}
|
|
286
287
|
filteredRowsLookup[rowId] = isRowPassing;
|
|
287
288
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { unstable_ownerDocument as ownerDocument } from '@mui/utils';
|
|
4
|
+
import { gridClasses } from '../../../constants/gridClasses';
|
|
4
5
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
5
6
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
6
7
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
@@ -243,20 +244,24 @@ export var useGridFocus = function useGridFocus(apiRef, props) {
|
|
|
243
244
|
}
|
|
244
245
|
apiRef.current.setColumnHeaderFocus(field, event);
|
|
245
246
|
}, [apiRef]);
|
|
246
|
-
var focussedColumnGroup = unstable_gridFocusColumnGroupHeaderSelector(apiRef);
|
|
247
247
|
var handleColumnGroupHeaderFocus = React.useCallback(function (_ref3, event) {
|
|
248
248
|
var fields = _ref3.fields,
|
|
249
249
|
depth = _ref3.depth;
|
|
250
250
|
if (event.target !== event.currentTarget) {
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
|
-
|
|
253
|
+
var focusedColumnGroup = unstable_gridFocusColumnGroupHeaderSelector(apiRef);
|
|
254
|
+
if (focusedColumnGroup !== null && focusedColumnGroup.depth === depth && fields.includes(focusedColumnGroup.field)) {
|
|
254
255
|
// This group cell has already been focused
|
|
255
256
|
return;
|
|
256
257
|
}
|
|
257
258
|
apiRef.current.setColumnGroupHeaderFocus(fields[0], depth, event);
|
|
258
|
-
}, [apiRef
|
|
259
|
-
var handleBlur = React.useCallback(function () {
|
|
259
|
+
}, [apiRef]);
|
|
260
|
+
var handleBlur = React.useCallback(function (_, event) {
|
|
261
|
+
var _event$relatedTarget;
|
|
262
|
+
if ((_event$relatedTarget = event.relatedTarget) != null && _event$relatedTarget.className.includes(gridClasses.columnHeader)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
260
265
|
logger.debug("Clearing focus");
|
|
261
266
|
apiRef.current.setState(function (state) {
|
|
262
267
|
return _extends({}, state, {
|
|
@@ -14,7 +14,6 @@ import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from '../../../constants/gridDetailPan
|
|
|
14
14
|
import { gridPinnedRowsSelector } from '../rows/gridRowsSelector';
|
|
15
15
|
import { unstable_gridFocusColumnGroupHeaderSelector } from '../focus';
|
|
16
16
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
17
|
-
import { useGridSelector } from '../../utils/useGridSelector';
|
|
18
17
|
import { unstable_gridHeaderFilteringEditFieldSelector, unstable_gridHeaderFilteringMenuSelector } from '../headerFiltering/gridHeaderFilteringSelectors';
|
|
19
18
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
20
19
|
function enrichPageRowsWithPinnedRows(apiRef, rows) {
|
|
@@ -324,12 +323,12 @@ export var useGridKeyboardNavigation = function useGridKeyboardNavigation(apiRef
|
|
|
324
323
|
event.preventDefault();
|
|
325
324
|
}
|
|
326
325
|
}, [apiRef, currentPageRows.length, goToHeaderFilter, theme.direction, goToHeader, goToCell, getRowIdFromIndex]);
|
|
327
|
-
var focusedColumnGroup = useGridSelector(apiRef, unstable_gridFocusColumnGroupHeaderSelector);
|
|
328
326
|
var handleColumnGroupHeaderKeyDown = React.useCallback(function (params, event) {
|
|
329
327
|
var dimensions = apiRef.current.getRootDimensions();
|
|
330
328
|
if (!dimensions) {
|
|
331
329
|
return;
|
|
332
330
|
}
|
|
331
|
+
var focusedColumnGroup = unstable_gridFocusColumnGroupHeaderSelector(apiRef);
|
|
333
332
|
if (focusedColumnGroup === null) {
|
|
334
333
|
return;
|
|
335
334
|
}
|
|
@@ -409,7 +408,7 @@ export var useGridKeyboardNavigation = function useGridKeyboardNavigation(apiRef
|
|
|
409
408
|
if (shouldPreventDefault) {
|
|
410
409
|
event.preventDefault();
|
|
411
410
|
}
|
|
412
|
-
}, [apiRef,
|
|
411
|
+
}, [apiRef, currentPageRows.length, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
|
|
413
412
|
var handleCellKeyDown = React.useCallback(function (params, event) {
|
|
414
413
|
// Ignore portal
|
|
415
414
|
if (!event.currentTarget.contains(event.target)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSelector } from '../../../utils/createSelector';
|
|
1
|
+
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
|
|
2
2
|
import { gridFilteredTopLevelRowCountSelector, gridExpandedSortedRowEntriesSelector, gridExpandedSortedRowIdsSelector, gridFilteredSortedTopLevelRowEntriesSelector } from '../filter/gridFilterSelector';
|
|
3
3
|
import { gridRowMaximumTreeDepthSelector, gridRowTreeSelector } from '../rows/gridRowsSelector';
|
|
4
4
|
import { getPageCount } from './gridPaginationUtils';
|
|
@@ -47,7 +47,7 @@ export var gridPageCountSelector = createSelector(gridPaginationModelSelector, g
|
|
|
47
47
|
* Get the index of the first and the last row to include in the current page if the pagination is enabled.
|
|
48
48
|
* @category Pagination
|
|
49
49
|
*/
|
|
50
|
-
export var gridPaginationRowRangeSelector =
|
|
50
|
+
export var gridPaginationRowRangeSelector = createSelectorMemoized(gridPaginationModelSelector, gridRowTreeSelector, gridRowMaximumTreeDepthSelector, gridExpandedSortedRowEntriesSelector, gridFilteredSortedTopLevelRowEntriesSelector, function (paginationModel, rowTree, rowTreeDepth, visibleSortedRowEntries, visibleSortedTopLevelRowEntries) {
|
|
51
51
|
var visibleTopLevelRowCount = visibleSortedTopLevelRowEntries.length;
|
|
52
52
|
var topLevelFirstRowIndex = Math.min(paginationModel.pageSize * paginationModel.page, visibleTopLevelRowCount - 1);
|
|
53
53
|
var topLevelLastRowIndex = Math.min(topLevelFirstRowIndex + paginationModel.pageSize - 1, visibleTopLevelRowCount - 1);
|
|
@@ -91,7 +91,7 @@ export var gridPaginationRowRangeSelector = createSelector(gridPaginationModelSe
|
|
|
91
91
|
* Get the id and the model of each row to include in the current page if the pagination is enabled.
|
|
92
92
|
* @category Pagination
|
|
93
93
|
*/
|
|
94
|
-
export var gridPaginatedVisibleSortedGridRowEntriesSelector =
|
|
94
|
+
export var gridPaginatedVisibleSortedGridRowEntriesSelector = createSelectorMemoized(gridExpandedSortedRowEntriesSelector, gridPaginationRowRangeSelector, function (visibleSortedRowEntries, paginationRange) {
|
|
95
95
|
if (!paginationRange) {
|
|
96
96
|
return [];
|
|
97
97
|
}
|
|
@@ -102,7 +102,7 @@ export var gridPaginatedVisibleSortedGridRowEntriesSelector = createSelector(gri
|
|
|
102
102
|
* Get the id of each row to include in the current page if the pagination is enabled.
|
|
103
103
|
* @category Pagination
|
|
104
104
|
*/
|
|
105
|
-
export var gridPaginatedVisibleSortedGridRowIdsSelector =
|
|
105
|
+
export var gridPaginatedVisibleSortedGridRowIdsSelector = createSelectorMemoized(gridExpandedSortedRowIdsSelector, gridPaginationRowRangeSelector, function (visibleSortedRowIds, paginationRange) {
|
|
106
106
|
if (!paginationRange) {
|
|
107
107
|
return [];
|
|
108
108
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSelector } from '../../../utils/createSelector';
|
|
1
|
+
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
|
|
2
2
|
import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
|
|
3
3
|
export var gridRowSelectionStateSelector = function gridRowSelectionStateSelector(state) {
|
|
4
4
|
return state.rowSelection;
|
|
@@ -6,12 +6,12 @@ export var gridRowSelectionStateSelector = function gridRowSelectionStateSelecto
|
|
|
6
6
|
export var selectedGridRowsCountSelector = createSelector(gridRowSelectionStateSelector, function (selection) {
|
|
7
7
|
return selection.length;
|
|
8
8
|
});
|
|
9
|
-
export var selectedGridRowsSelector =
|
|
9
|
+
export var selectedGridRowsSelector = createSelectorMemoized(gridRowSelectionStateSelector, gridRowsLookupSelector, function (selectedRows, rowsLookup) {
|
|
10
10
|
return new Map(selectedRows.map(function (id) {
|
|
11
11
|
return [id, rowsLookup[id]];
|
|
12
12
|
}));
|
|
13
13
|
});
|
|
14
|
-
export var selectedIdsLookupSelector =
|
|
14
|
+
export var selectedIdsLookupSelector = createSelectorMemoized(gridRowSelectionStateSelector, function (selection) {
|
|
15
15
|
return selection.reduce(function (lookup, rowId) {
|
|
16
16
|
lookup[rowId] = rowId;
|
|
17
17
|
return lookup;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import { createSelector } from '../../../utils/createSelector';
|
|
2
|
+
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
|
|
3
3
|
var gridRowsStateSelector = function gridRowsStateSelector(state) {
|
|
4
4
|
return state.rows;
|
|
5
5
|
};
|
|
@@ -29,7 +29,7 @@ export var gridRowGroupingNameSelector = createSelector(gridRowsStateSelector, f
|
|
|
29
29
|
export var gridRowTreeDepthsSelector = createSelector(gridRowsStateSelector, function (rows) {
|
|
30
30
|
return rows.treeDepths;
|
|
31
31
|
});
|
|
32
|
-
export var gridRowMaximumTreeDepthSelector =
|
|
32
|
+
export var gridRowMaximumTreeDepthSelector = createSelectorMemoized(gridRowsStateSelector, function (rows) {
|
|
33
33
|
var entries = Object.entries(rows.treeDepths);
|
|
34
34
|
if (entries.length === 0) {
|
|
35
35
|
return 1;
|
|
@@ -60,7 +60,7 @@ export var gridAdditionalRowGroupsSelector = createSelector(gridRowsStateSelecto
|
|
|
60
60
|
/**
|
|
61
61
|
* @ignore - do not document.
|
|
62
62
|
*/
|
|
63
|
-
export var gridPinnedRowsSelector =
|
|
63
|
+
export var gridPinnedRowsSelector = createSelectorMemoized(gridAdditionalRowGroupsSelector, function (additionalRowGroups) {
|
|
64
64
|
var _rawPinnedRows$bottom, _rawPinnedRows$top;
|
|
65
65
|
var rawPinnedRows = additionalRowGroups == null ? void 0 : additionalRowGroups.pinnedRows;
|
|
66
66
|
return {
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
6
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/esm/wrapNativeSuper";
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
1
9
|
import * as React from 'react';
|
|
2
10
|
import { getGridCellElement, getGridColumnHeaderElement, getGridRowElement } from '../../../utils/domUtils';
|
|
3
11
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
12
|
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
export var MissingRowIdError = /*#__PURE__*/function (_Error) {
|
|
14
|
+
_inherits(MissingRowIdError, _Error);
|
|
15
|
+
var _super = _createSuper(MissingRowIdError);
|
|
16
|
+
function MissingRowIdError() {
|
|
17
|
+
_classCallCheck(this, MissingRowIdError);
|
|
18
|
+
return _super.apply(this, arguments);
|
|
19
|
+
}
|
|
20
|
+
return _createClass(MissingRowIdError);
|
|
21
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
10
22
|
|
|
11
23
|
/**
|
|
12
24
|
* @requires useGridColumns (method)
|
|
@@ -26,7 +38,7 @@ export function useGridParamsApi(apiRef) {
|
|
|
26
38
|
var getRowParams = React.useCallback(function (id) {
|
|
27
39
|
var row = apiRef.current.getRow(id);
|
|
28
40
|
if (!row) {
|
|
29
|
-
throw new
|
|
41
|
+
throw new MissingRowIdError("No row with id #".concat(id, " found"));
|
|
30
42
|
}
|
|
31
43
|
var params = {
|
|
32
44
|
id: id,
|
|
@@ -39,7 +51,7 @@ export function useGridParamsApi(apiRef) {
|
|
|
39
51
|
var row = apiRef.current.getRow(id);
|
|
40
52
|
var rowNode = apiRef.current.getRowNode(id);
|
|
41
53
|
if (!row || !rowNode) {
|
|
42
|
-
throw new
|
|
54
|
+
throw new MissingRowIdError("No row with id #".concat(id, " found"));
|
|
43
55
|
}
|
|
44
56
|
var cellFocus = gridFocusCellSelector(apiRef);
|
|
45
57
|
var cellTabIndex = gridTabIndexCellSelector(apiRef);
|
|
@@ -63,7 +75,7 @@ export function useGridParamsApi(apiRef) {
|
|
|
63
75
|
var row = apiRef.current.getRow(id);
|
|
64
76
|
var rowNode = apiRef.current.getRowNode(id);
|
|
65
77
|
if (!row || !rowNode) {
|
|
66
|
-
throw new
|
|
78
|
+
throw new MissingRowIdError("No row with id #".concat(id, " found"));
|
|
67
79
|
}
|
|
68
80
|
var cellFocus = gridFocusCellSelector(apiRef);
|
|
69
81
|
var cellTabIndex = gridTabIndexCellSelector(apiRef);
|
|
@@ -77,7 +89,8 @@ export function useGridParamsApi(apiRef) {
|
|
|
77
89
|
hasFocus: cellFocus !== null && cellFocus.field === field && cellFocus.id === id,
|
|
78
90
|
tabIndex: cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === id ? 0 : -1,
|
|
79
91
|
value: value,
|
|
80
|
-
formattedValue: value
|
|
92
|
+
formattedValue: value,
|
|
93
|
+
isEditable: false
|
|
81
94
|
};
|
|
82
95
|
if (colDef && colDef.valueFormatter) {
|
|
83
96
|
params.formattedValue = colDef.valueFormatter({
|
|
@@ -92,15 +105,10 @@ export function useGridParamsApi(apiRef) {
|
|
|
92
105
|
}, [apiRef]);
|
|
93
106
|
var getCellValue = React.useCallback(function (id, field) {
|
|
94
107
|
var colDef = apiRef.current.getColumn(field);
|
|
95
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
96
|
-
if (!colDef && !warnedOnceMissingColumn) {
|
|
97
|
-
warnMissingColumn(field);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
108
|
if (!colDef || !colDef.valueGetter) {
|
|
101
109
|
var rowModel = apiRef.current.getRow(id);
|
|
102
110
|
if (!rowModel) {
|
|
103
|
-
throw new
|
|
111
|
+
throw new MissingRowIdError("No row with id #".concat(id, " found"));
|
|
104
112
|
}
|
|
105
113
|
return rowModel[field];
|
|
106
114
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createSelector } from '../../../utils/createSelector';
|
|
1
|
+
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
|
|
2
2
|
import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -21,7 +21,7 @@ export var gridSortedRowIdsSelector = createSelector(gridSortingStateSelector, f
|
|
|
21
21
|
* Get the id and the model of the rows after the sorting process.
|
|
22
22
|
* @category Sorting
|
|
23
23
|
*/
|
|
24
|
-
export var gridSortedRowEntriesSelector =
|
|
24
|
+
export var gridSortedRowEntriesSelector = createSelectorMemoized(gridSortedRowIdsSelector, gridRowsLookupSelector,
|
|
25
25
|
// TODO rows v6: Is this the best approach ?
|
|
26
26
|
function (sortedIds, idRowsLookup) {
|
|
27
27
|
return sortedIds.map(function (id) {
|
|
@@ -44,7 +44,7 @@ export var gridSortModelSelector = createSelector(gridSortingStateSelector, func
|
|
|
44
44
|
* @category Sorting
|
|
45
45
|
* @ignore - do not document.
|
|
46
46
|
*/
|
|
47
|
-
export var gridSortColumnLookupSelector =
|
|
47
|
+
export var gridSortColumnLookupSelector = createSelectorMemoized(gridSortModelSelector, function (sortModel) {
|
|
48
48
|
var result = sortModel.reduce(function (res, sortItem, index) {
|
|
49
49
|
res[sortItem.field] = {
|
|
50
50
|
sortDirection: sortItem.sort,
|
|
@@ -2,11 +2,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
4
|
var _excluded = ["style"],
|
|
5
|
-
_excluded2 = ["style"]
|
|
6
|
-
_excluded3 = ["style"];
|
|
5
|
+
_excluded2 = ["style"];
|
|
7
6
|
import * as React from 'react';
|
|
8
7
|
import * as ReactDOM from 'react-dom';
|
|
9
|
-
import { unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
8
|
+
import { unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
10
9
|
import { useTheme } from '@mui/material/styles';
|
|
11
10
|
import { defaultMemoize } from 'reselect';
|
|
12
11
|
import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
|
|
@@ -52,12 +51,17 @@ export var getRenderableIndexes = function getRenderableIndexes(_ref) {
|
|
|
52
51
|
maxLastIndex = _ref.maxLastIndex;
|
|
53
52
|
return [clamp(firstIndex - buffer, minFirstIndex, maxLastIndex), clamp(lastIndex + buffer, minFirstIndex, maxLastIndex)];
|
|
54
53
|
};
|
|
55
|
-
var areRenderContextsEqual = function areRenderContextsEqual(context1, context2) {
|
|
54
|
+
export var areRenderContextsEqual = function areRenderContextsEqual(context1, context2) {
|
|
56
55
|
if (context1 === context2) {
|
|
57
56
|
return true;
|
|
58
57
|
}
|
|
59
58
|
return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
|
|
60
59
|
};
|
|
60
|
+
// The `maxSize` is 3 so that reselect caches the `renderedColumns` values for the pinned left,
|
|
61
|
+
// unpinned, and pinned right sections.
|
|
62
|
+
var MEMOIZE_OPTIONS = {
|
|
63
|
+
maxSize: 3
|
|
64
|
+
};
|
|
61
65
|
export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
62
66
|
var _currentPage$range3, _currentPage$range4;
|
|
63
67
|
var apiRef = useGridPrivateApiContext();
|
|
@@ -104,7 +108,7 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
|
104
108
|
var prevRootRowStyle = React.useRef();
|
|
105
109
|
var getRenderedColumnsRef = React.useRef(defaultMemoize(function (columns, firstColumnToRender, lastColumnToRender) {
|
|
106
110
|
return columns.slice(firstColumnToRender, lastColumnToRender);
|
|
107
|
-
}));
|
|
111
|
+
}, MEMOIZE_OPTIONS));
|
|
108
112
|
var getNearestIndexToRender = React.useCallback(function (offset) {
|
|
109
113
|
var _currentPage$range, _currentPage$range2;
|
|
110
114
|
var lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
|
|
@@ -272,7 +276,7 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
|
272
276
|
};
|
|
273
277
|
apiRef.current.publishEvent('scrollPositionChange', params);
|
|
274
278
|
}, [apiRef, computeRenderContext, containerDimensions.width, updateRenderContext]);
|
|
275
|
-
var handleScroll = function
|
|
279
|
+
var handleScroll = useEventCallback(function (event) {
|
|
276
280
|
var _event$currentTarget = event.currentTarget,
|
|
277
281
|
scrollTop = _event$currentTarget.scrollTop,
|
|
278
282
|
scrollLeft = _event$currentTarget.scrollLeft;
|
|
@@ -313,13 +317,13 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
|
313
317
|
});
|
|
314
318
|
prevTotalWidth.current = columnsTotalWidth;
|
|
315
319
|
}
|
|
316
|
-
};
|
|
317
|
-
var handleWheel = function
|
|
320
|
+
});
|
|
321
|
+
var handleWheel = useEventCallback(function (event) {
|
|
318
322
|
apiRef.current.publishEvent('virtualScrollerWheel', {}, event);
|
|
319
|
-
};
|
|
320
|
-
var handleTouchMove = function
|
|
323
|
+
});
|
|
324
|
+
var handleTouchMove = useEventCallback(function (event) {
|
|
321
325
|
apiRef.current.publishEvent('virtualScrollerTouchMove', {}, event);
|
|
322
|
-
};
|
|
326
|
+
});
|
|
323
327
|
var getRows = function getRows() {
|
|
324
328
|
var _rootProps$slotProps;
|
|
325
329
|
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
@@ -471,22 +475,25 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
|
471
475
|
height: height,
|
|
472
476
|
minHeight: shouldExtendContent ? '100%' : 'auto'
|
|
473
477
|
};
|
|
478
|
+
if (rootProps.autoHeight && currentPage.rows.length === 0) {
|
|
479
|
+
size.height = getMinimalContentHeight(apiRef, rootProps.rowHeight); // Give room to show the overlay when there no rows.
|
|
480
|
+
}
|
|
481
|
+
|
|
474
482
|
return size;
|
|
475
|
-
}, [rootRef, columnsTotalWidth, rowsMeta.currentPageTotalHeight, needsHorizontalScrollbar]);
|
|
483
|
+
}, [apiRef, rootRef, columnsTotalWidth, rowsMeta.currentPageTotalHeight, needsHorizontalScrollbar, rootProps.autoHeight, rootProps.rowHeight, currentPage.rows.length]);
|
|
476
484
|
React.useEffect(function () {
|
|
477
485
|
apiRef.current.publishEvent('virtualScrollerContentSizeChange');
|
|
478
486
|
}, [apiRef, contentSize]);
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
487
|
+
var rootStyle = React.useMemo(function () {
|
|
488
|
+
var style = {};
|
|
489
|
+
if (!needsHorizontalScrollbar) {
|
|
490
|
+
style.overflowX = 'hidden';
|
|
491
|
+
}
|
|
492
|
+
if (rootProps.autoHeight) {
|
|
493
|
+
style.overflowY = 'hidden';
|
|
494
|
+
}
|
|
495
|
+
return style;
|
|
496
|
+
}, [needsHorizontalScrollbar, rootProps.autoHeight]);
|
|
490
497
|
var getRenderContext = React.useCallback(function () {
|
|
491
498
|
return prevRenderContext.current;
|
|
492
499
|
}, []);
|
|
@@ -498,24 +505,21 @@ export var useGridVirtualScroller = function useGridVirtualScroller(props) {
|
|
|
498
505
|
updateRenderZonePosition: updateRenderZonePosition,
|
|
499
506
|
getRows: getRows,
|
|
500
507
|
getRootProps: function getRootProps() {
|
|
501
|
-
var
|
|
502
|
-
var _ref6$style = _ref6.style,
|
|
503
|
-
style = _ref6$style === void 0 ? {} : _ref6$style,
|
|
504
|
-
other = _objectWithoutProperties(_ref6, _excluded3);
|
|
508
|
+
var inputProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
505
509
|
return _extends({
|
|
506
510
|
ref: handleRef,
|
|
507
511
|
onScroll: handleScroll,
|
|
508
512
|
onWheel: handleWheel,
|
|
509
|
-
onTouchMove: handleTouchMove
|
|
510
|
-
|
|
511
|
-
|
|
513
|
+
onTouchMove: handleTouchMove
|
|
514
|
+
}, inputProps, {
|
|
515
|
+
style: inputProps.style ? _extends({}, inputProps.style, rootStyle) : rootStyle
|
|
516
|
+
});
|
|
512
517
|
},
|
|
513
518
|
getContentProps: function getContentProps() {
|
|
514
|
-
var
|
|
515
|
-
|
|
516
|
-
style = _ref7$style === void 0 ? {} : _ref7$style;
|
|
519
|
+
var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
520
|
+
style = _ref6.style;
|
|
517
521
|
return {
|
|
518
|
-
style: _extends({}, style, contentSize)
|
|
522
|
+
style: style ? _extends({}, style, contentSize) : contentSize
|
|
519
523
|
};
|
|
520
524
|
},
|
|
521
525
|
getRenderZoneProps: function getRenderZoneProps() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './useGridApiEventHandler';
|
|
2
2
|
export * from './useGridApiMethod';
|
|
3
3
|
export * from './useGridLogger';
|
|
4
|
-
export
|
|
4
|
+
export { useGridSelector } from './useGridSelector';
|
|
5
5
|
export * from './useGridNativeEventListener';
|
|
6
6
|
export * from './useFirstRender';
|
|
@@ -1,16 +1,54 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useLazyRef } from './useLazyRef';
|
|
4
|
+
import { useOnMount } from './useOnMount';
|
|
1
5
|
import { buildWarning } from '../../utils/warning';
|
|
6
|
+
import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
|
|
7
|
+
var stateNotInitializedWarning = buildWarning(['MUI: `useGridSelector` has been called before the initialization of the state.', 'This hook can only be used inside the context of the grid.']);
|
|
2
8
|
function isOutputSelector(selector) {
|
|
3
9
|
return selector.acceptsApiRef;
|
|
4
10
|
}
|
|
5
|
-
|
|
11
|
+
function applySelector(apiRef, selector) {
|
|
12
|
+
if (isOutputSelector(selector)) {
|
|
13
|
+
return selector(apiRef);
|
|
14
|
+
}
|
|
15
|
+
return selector(apiRef.current.state);
|
|
16
|
+
}
|
|
17
|
+
var defaultCompare = Object.is;
|
|
18
|
+
export var objectShallowCompare = fastObjectShallowCompare;
|
|
19
|
+
var createRefs = function createRefs() {
|
|
20
|
+
return {
|
|
21
|
+
state: null,
|
|
22
|
+
equals: null,
|
|
23
|
+
selector: null
|
|
24
|
+
};
|
|
25
|
+
};
|
|
6
26
|
export var useGridSelector = function useGridSelector(apiRef, selector) {
|
|
27
|
+
var equals = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultCompare;
|
|
7
28
|
if (process.env.NODE_ENV !== 'production') {
|
|
8
29
|
if (!apiRef.current.state) {
|
|
9
30
|
stateNotInitializedWarning();
|
|
10
31
|
}
|
|
11
32
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
33
|
+
var refs = useLazyRef(createRefs);
|
|
34
|
+
var didInit = refs.current.selector !== null;
|
|
35
|
+
var _React$useState = React.useState(
|
|
36
|
+
// We don't use an initialization function to avoid allocations
|
|
37
|
+
didInit ? null : applySelector(apiRef, selector)),
|
|
38
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
39
|
+
state = _React$useState2[0],
|
|
40
|
+
setState = _React$useState2[1];
|
|
41
|
+
refs.current.state = state;
|
|
42
|
+
refs.current.equals = equals;
|
|
43
|
+
refs.current.selector = selector;
|
|
44
|
+
useOnMount(function () {
|
|
45
|
+
return apiRef.current.store.subscribe(function () {
|
|
46
|
+
var newState = applySelector(apiRef, refs.current.selector);
|
|
47
|
+
if (!refs.current.equals(refs.current.state, newState)) {
|
|
48
|
+
refs.current.state = newState;
|
|
49
|
+
setState(newState);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return state;
|
|
16
54
|
};
|
package/legacy/index.js
CHANGED
|
@@ -48,7 +48,7 @@ export { useGridVirtualScroller, getRenderableIndexes } from '../hooks/features/
|
|
|
48
48
|
export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
49
49
|
export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
|
|
50
50
|
export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
|
|
51
|
-
export { createSelector, unstable_resetCreateSelectorCache } from '../utils/createSelector';
|
|
51
|
+
export { createSelector, createSelectorMemoized, unstable_resetCreateSelectorCache } from '../utils/createSelector';
|
|
52
52
|
export { findParentElementFromClassName, getActiveElement } from '../utils/domUtils';
|
|
53
53
|
export { isNavigationKey } from '../utils/keyboardUtils';
|
|
54
54
|
export { clamp, isDeepEqual, isNumber, isFunction, isObject } from '../utils/utils';
|