@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
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["style"],
|
|
4
|
-
_excluded2 = ["style"]
|
|
5
|
-
_excluded3 = ["style"];
|
|
4
|
+
_excluded2 = ["style"];
|
|
6
5
|
import * as React from 'react';
|
|
7
6
|
import * as ReactDOM from 'react-dom';
|
|
8
|
-
import { unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/utils';
|
|
7
|
+
import { unstable_useForkRef as useForkRef, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
9
8
|
import { useTheme } from '@mui/material/styles';
|
|
10
9
|
import { defaultMemoize } from 'reselect';
|
|
11
10
|
import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
|
|
@@ -50,12 +49,17 @@ export const getRenderableIndexes = ({
|
|
|
50
49
|
}) => {
|
|
51
50
|
return [clamp(firstIndex - buffer, minFirstIndex, maxLastIndex), clamp(lastIndex + buffer, minFirstIndex, maxLastIndex)];
|
|
52
51
|
};
|
|
53
|
-
const areRenderContextsEqual = (context1, context2) => {
|
|
52
|
+
export const areRenderContextsEqual = (context1, context2) => {
|
|
54
53
|
if (context1 === context2) {
|
|
55
54
|
return true;
|
|
56
55
|
}
|
|
57
56
|
return context1.firstRowIndex === context2.firstRowIndex && context1.lastRowIndex === context2.lastRowIndex && context1.firstColumnIndex === context2.firstColumnIndex && context1.lastColumnIndex === context2.lastColumnIndex;
|
|
58
57
|
};
|
|
58
|
+
// The `maxSize` is 3 so that reselect caches the `renderedColumns` values for the pinned left,
|
|
59
|
+
// unpinned, and pinned right sections.
|
|
60
|
+
const MEMOIZE_OPTIONS = {
|
|
61
|
+
maxSize: 3
|
|
62
|
+
};
|
|
59
63
|
export const useGridVirtualScroller = props => {
|
|
60
64
|
var _currentPage$range3, _currentPage$range4;
|
|
61
65
|
const apiRef = useGridPrivateApiContext();
|
|
@@ -96,7 +100,7 @@ export const useGridVirtualScroller = props => {
|
|
|
96
100
|
const prevRootRowStyle = React.useRef();
|
|
97
101
|
const getRenderedColumnsRef = React.useRef(defaultMemoize((columns, firstColumnToRender, lastColumnToRender) => {
|
|
98
102
|
return columns.slice(firstColumnToRender, lastColumnToRender);
|
|
99
|
-
}));
|
|
103
|
+
}, MEMOIZE_OPTIONS));
|
|
100
104
|
const getNearestIndexToRender = React.useCallback(offset => {
|
|
101
105
|
var _currentPage$range, _currentPage$range2;
|
|
102
106
|
const lastMeasuredIndexRelativeToAllRows = apiRef.current.getLastMeasuredRowIndex();
|
|
@@ -255,7 +259,7 @@ export const useGridVirtualScroller = props => {
|
|
|
255
259
|
};
|
|
256
260
|
apiRef.current.publishEvent('scrollPositionChange', params);
|
|
257
261
|
}, [apiRef, computeRenderContext, containerDimensions.width, updateRenderContext]);
|
|
258
|
-
const handleScroll = event => {
|
|
262
|
+
const handleScroll = useEventCallback(event => {
|
|
259
263
|
const {
|
|
260
264
|
scrollTop,
|
|
261
265
|
scrollLeft
|
|
@@ -297,13 +301,13 @@ export const useGridVirtualScroller = props => {
|
|
|
297
301
|
});
|
|
298
302
|
prevTotalWidth.current = columnsTotalWidth;
|
|
299
303
|
}
|
|
300
|
-
};
|
|
301
|
-
const handleWheel = event => {
|
|
304
|
+
});
|
|
305
|
+
const handleWheel = useEventCallback(event => {
|
|
302
306
|
apiRef.current.publishEvent('virtualScrollerWheel', {}, event);
|
|
303
|
-
};
|
|
304
|
-
const handleTouchMove = event => {
|
|
307
|
+
});
|
|
308
|
+
const handleTouchMove = useEventCallback(event => {
|
|
305
309
|
apiRef.current.publishEvent('virtualScrollerTouchMove', {}, event);
|
|
306
|
-
};
|
|
310
|
+
});
|
|
307
311
|
const getRows = (params = {
|
|
308
312
|
renderContext
|
|
309
313
|
}) => {
|
|
@@ -450,22 +454,25 @@ export const useGridVirtualScroller = props => {
|
|
|
450
454
|
height,
|
|
451
455
|
minHeight: shouldExtendContent ? '100%' : 'auto'
|
|
452
456
|
};
|
|
457
|
+
if (rootProps.autoHeight && currentPage.rows.length === 0) {
|
|
458
|
+
size.height = getMinimalContentHeight(apiRef, rootProps.rowHeight); // Give room to show the overlay when there no rows.
|
|
459
|
+
}
|
|
460
|
+
|
|
453
461
|
return size;
|
|
454
|
-
}, [rootRef, columnsTotalWidth, rowsMeta.currentPageTotalHeight, needsHorizontalScrollbar]);
|
|
462
|
+
}, [apiRef, rootRef, columnsTotalWidth, rowsMeta.currentPageTotalHeight, needsHorizontalScrollbar, rootProps.autoHeight, rootProps.rowHeight, currentPage.rows.length]);
|
|
455
463
|
React.useEffect(() => {
|
|
456
464
|
apiRef.current.publishEvent('virtualScrollerContentSizeChange');
|
|
457
465
|
}, [apiRef, contentSize]);
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
466
|
+
const rootStyle = React.useMemo(() => {
|
|
467
|
+
const style = {};
|
|
468
|
+
if (!needsHorizontalScrollbar) {
|
|
469
|
+
style.overflowX = 'hidden';
|
|
470
|
+
}
|
|
471
|
+
if (rootProps.autoHeight) {
|
|
472
|
+
style.overflowY = 'hidden';
|
|
473
|
+
}
|
|
474
|
+
return style;
|
|
475
|
+
}, [needsHorizontalScrollbar, rootProps.autoHeight]);
|
|
469
476
|
const getRenderContext = React.useCallback(() => {
|
|
470
477
|
return prevRenderContext.current;
|
|
471
478
|
}, []);
|
|
@@ -476,23 +483,18 @@ export const useGridVirtualScroller = props => {
|
|
|
476
483
|
renderContext,
|
|
477
484
|
updateRenderZonePosition,
|
|
478
485
|
getRows,
|
|
479
|
-
getRootProps: (
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
onWheel: handleWheel,
|
|
488
|
-
onTouchMove: handleTouchMove,
|
|
489
|
-
style: _extends({}, style, rootStyle)
|
|
490
|
-
}, other);
|
|
491
|
-
},
|
|
486
|
+
getRootProps: (inputProps = {}) => _extends({
|
|
487
|
+
ref: handleRef,
|
|
488
|
+
onScroll: handleScroll,
|
|
489
|
+
onWheel: handleWheel,
|
|
490
|
+
onTouchMove: handleTouchMove
|
|
491
|
+
}, inputProps, {
|
|
492
|
+
style: inputProps.style ? _extends({}, inputProps.style, rootStyle) : rootStyle
|
|
493
|
+
}),
|
|
492
494
|
getContentProps: ({
|
|
493
|
-
style
|
|
495
|
+
style
|
|
494
496
|
} = {}) => ({
|
|
495
|
-
style: _extends({}, style, contentSize)
|
|
497
|
+
style: style ? _extends({}, style, contentSize) : contentSize
|
|
496
498
|
}),
|
|
497
499
|
getRenderZoneProps: () => ({
|
|
498
500
|
ref: renderZoneRef
|
package/hooks/utils/index.d.ts
CHANGED
|
@@ -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';
|
package/hooks/utils/index.js
CHANGED
|
@@ -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,4 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommon } from '../../models/api/gridApiCommon';
|
|
3
3
|
import { OutputSelector } from '../../utils/createSelector';
|
|
4
|
-
|
|
4
|
+
import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
|
|
5
|
+
export declare const objectShallowCompare: typeof fastObjectShallowCompare;
|
|
6
|
+
export declare const useGridSelector: <Api extends GridApiCommon<any, any>, T>(apiRef: React.MutableRefObject<Api>, selector: OutputSelector<Api["state"], T> | ((state: Api["state"]) => T), equals?: (a: T, b: T) => boolean) => T;
|
|
@@ -1,16 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useLazyRef } from './useLazyRef';
|
|
3
|
+
import { useOnMount } from './useOnMount';
|
|
1
4
|
import { buildWarning } from '../../utils/warning';
|
|
5
|
+
import { fastObjectShallowCompare } from '../../utils/fastObjectShallowCompare';
|
|
6
|
+
const 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
7
|
function isOutputSelector(selector) {
|
|
3
8
|
return selector.acceptsApiRef;
|
|
4
9
|
}
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
function applySelector(apiRef, selector) {
|
|
11
|
+
if (isOutputSelector(selector)) {
|
|
12
|
+
return selector(apiRef);
|
|
13
|
+
}
|
|
14
|
+
return selector(apiRef.current.state);
|
|
15
|
+
}
|
|
16
|
+
const defaultCompare = Object.is;
|
|
17
|
+
export const objectShallowCompare = fastObjectShallowCompare;
|
|
18
|
+
const createRefs = () => ({
|
|
19
|
+
state: null,
|
|
20
|
+
equals: null,
|
|
21
|
+
selector: null
|
|
22
|
+
});
|
|
23
|
+
export const useGridSelector = (apiRef, selector, equals = defaultCompare) => {
|
|
7
24
|
if (process.env.NODE_ENV !== 'production') {
|
|
8
25
|
if (!apiRef.current.state) {
|
|
9
26
|
stateNotInitializedWarning();
|
|
10
27
|
}
|
|
11
28
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
const refs = useLazyRef(createRefs);
|
|
30
|
+
const didInit = refs.current.selector !== null;
|
|
31
|
+
const [state, setState] = React.useState(
|
|
32
|
+
// We don't use an initialization function to avoid allocations
|
|
33
|
+
didInit ? null : applySelector(apiRef, selector));
|
|
34
|
+
refs.current.state = state;
|
|
35
|
+
refs.current.equals = equals;
|
|
36
|
+
refs.current.selector = selector;
|
|
37
|
+
useOnMount(() => {
|
|
38
|
+
return apiRef.current.store.subscribe(() => {
|
|
39
|
+
const newState = applySelector(apiRef, refs.current.selector);
|
|
40
|
+
if (!refs.current.equals(refs.current.state, newState)) {
|
|
41
|
+
refs.current.state = newState;
|
|
42
|
+
setState(newState);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return state;
|
|
16
47
|
};
|
package/index.js
CHANGED
package/internals/index.d.ts
CHANGED
|
@@ -61,7 +61,7 @@ export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
|
|
|
61
61
|
export type { GridStateInitializer } from '../hooks/utils/useGridInitializeState';
|
|
62
62
|
export type { GridExperimentalFeatures, DataGridPropsWithoutDefaultValue, DataGridPropsWithDefaultValues, DataGridPropsWithComplexDefaultValueAfterProcessing, DataGridPropsWithComplexDefaultValueBeforeProcessing, } from '../models/props/DataGridProps';
|
|
63
63
|
export { getColumnsToExport, defaultGetRowsToExport } from '../hooks/features/export/utils';
|
|
64
|
-
export { createSelector, unstable_resetCreateSelectorCache } from '../utils/createSelector';
|
|
64
|
+
export { createSelector, createSelectorMemoized, unstable_resetCreateSelectorCache, } from '../utils/createSelector';
|
|
65
65
|
export { findParentElementFromClassName, getActiveElement } from '../utils/domUtils';
|
|
66
66
|
export { isNavigationKey } from '../utils/keyboardUtils';
|
|
67
67
|
export { clamp, isDeepEqual, isNumber, isFunction, isObject } from '../utils/utils';
|
package/internals/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';
|
|
@@ -3,6 +3,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
3
3
|
var _excluded = ["innerRef", "className", "visibleColumns", "sortColumnLookup", "filterColumnLookup", "columnPositions", "columnHeaderTabIndexState", "columnGroupHeaderTabIndexState", "columnHeaderFocus", "columnGroupHeaderFocus", "densityFactor", "headerGroupingMaxDepth", "columnMenuState", "columnVisibility", "columnGroupsHeaderStructure", "hasOtherElementInTabSequence"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
+
import { fastMemo } from '../utils/fastMemo';
|
|
6
7
|
import { useGridColumnHeaders } from '../hooks/features/columnHeaders/useGridColumnHeaders';
|
|
7
8
|
import { GridBaseColumnHeaders } from './columnHeaders/GridBaseColumnHeaders';
|
|
8
9
|
import { GridColumnHeadersInner } from './columnHeaders/GridColumnHeadersInner';
|
|
@@ -98,4 +99,5 @@ process.env.NODE_ENV !== "production" ? GridColumnHeaders.propTypes = {
|
|
|
98
99
|
sortColumnLookup: PropTypes.object.isRequired,
|
|
99
100
|
visibleColumns: PropTypes.arrayOf(PropTypes.object).isRequired
|
|
100
101
|
} : void 0;
|
|
101
|
-
|
|
102
|
+
var MemoizedGridColumnHeaders = fastMemo(GridColumnHeaders);
|
|
103
|
+
export { MemoizedGridColumnHeaders as GridColumnHeaders };
|
|
@@ -2,18 +2,18 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
5
|
-
var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"]
|
|
6
|
-
_excluded2 = ["changeReason", "unstable_updateValueOnRender"];
|
|
5
|
+
var _excluded = ["selected", "rowId", "row", "index", "style", "position", "rowHeight", "className", "visibleColumns", "renderedColumns", "containerWidth", "firstColumnToRender", "lastColumnToRender", "isLastVisible", "focusedCell", "tabbableCell", "onClick", "onDoubleClick", "onMouseEnter", "onMouseLeave"];
|
|
7
6
|
import * as React from 'react';
|
|
8
7
|
import PropTypes from 'prop-types';
|
|
9
8
|
import clsx from 'clsx';
|
|
10
9
|
import { unstable_composeClasses as composeClasses, unstable_useForkRef as useForkRef } from '@mui/utils';
|
|
10
|
+
import { fastMemo } from '../utils/fastMemo';
|
|
11
11
|
import { GridEditModes, GridRowModes, GridCellModes } from '../models/gridEditRowModel';
|
|
12
12
|
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
13
13
|
import { getDataGridUtilityClass, gridClasses } from '../constants/gridClasses';
|
|
14
14
|
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
15
15
|
import { gridColumnsTotalWidthSelector } from '../hooks/features/columns/gridColumnsSelector';
|
|
16
|
-
import { useGridSelector } from '../hooks/utils/useGridSelector';
|
|
16
|
+
import { useGridSelector, objectShallowCompare } from '../hooks/utils/useGridSelector';
|
|
17
17
|
import { useGridVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
18
18
|
import { findParentElementFromClassName } from '../utils/domUtils';
|
|
19
19
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../colDef/gridCheckboxSelectionColDef';
|
|
@@ -23,6 +23,7 @@ import { gridSortModelSelector } from '../hooks/features/sorting/gridSortingSele
|
|
|
23
23
|
import { gridRowMaximumTreeDepthSelector } from '../hooks/features/rows/gridRowsSelector';
|
|
24
24
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../hooks/features/columnGrouping/gridColumnGroupsSelector';
|
|
25
25
|
import { randomNumberBetween } from '../utils/utils';
|
|
26
|
+
import { GridCellWrapper, GridCellV7 } from './cell/GridCell';
|
|
26
27
|
import { gridEditRowsStateSelector } from '../hooks/features/editing/gridEditingSelectors';
|
|
27
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
29
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -187,79 +188,29 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
|
|
|
187
188
|
}, [apiRef, onClick, publish, rowId]);
|
|
188
189
|
var slots = rootProps.slots,
|
|
189
190
|
slotProps = rootProps.slotProps,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
getCellClassName = rootProps.getCellClassName;
|
|
191
|
+
disableColumnReorder = rootProps.disableColumnReorder;
|
|
192
|
+
var CellComponent = slots.cell === GridCellV7 ? GridCellV7 : GridCellWrapper;
|
|
193
193
|
var rowReordering = rootProps.rowReordering;
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
var cellParams = apiRef.current.getCellParams(rowId, column.field);
|
|
197
|
-
var classNames = apiRef.current.unstable_applyPipeProcessors('cellClassName', [], {
|
|
198
|
-
id: rowId,
|
|
199
|
-
field: column.field
|
|
200
|
-
});
|
|
194
|
+
var getCell = function getCell(column, cellProps) {
|
|
195
|
+
var _editRowsState$rowId$, _editRowsState$rowId;
|
|
201
196
|
var disableDragEvents = disableColumnReorder && column.disableReorder || !rowReordering && !!sortModel.length && treeDepth > 1 && Object.keys(editRowsState).length > 0;
|
|
202
|
-
|
|
203
|
-
classNames.push(clsx(typeof column.cellClassName === 'function' ? column.cellClassName(cellParams) : column.cellClassName));
|
|
204
|
-
}
|
|
205
|
-
var editCellState = editRowsState[rowId] ? editRowsState[rowId][column.field] : null;
|
|
206
|
-
var content;
|
|
207
|
-
if (editCellState == null && column.renderCell) {
|
|
208
|
-
content = column.renderCell(_extends({}, cellParams, {
|
|
209
|
-
api: apiRef.current
|
|
210
|
-
}));
|
|
211
|
-
// TODO move to GridCell
|
|
212
|
-
classNames.push(clsx(gridClasses['cell--withRenderer'], rootClasses == null ? void 0 : rootClasses['cell--withRenderer']));
|
|
213
|
-
}
|
|
214
|
-
if (editCellState != null && column.renderEditCell) {
|
|
215
|
-
var updatedRow = apiRef.current.getRowWithUpdatedValues(rowId, column.field);
|
|
216
|
-
|
|
217
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
218
|
-
var changeReason = editCellState.changeReason,
|
|
219
|
-
unstable_updateValueOnRender = editCellState.unstable_updateValueOnRender,
|
|
220
|
-
editCellStateRest = _objectWithoutProperties(editCellState, _excluded2);
|
|
221
|
-
var params = _extends({}, cellParams, {
|
|
222
|
-
row: updatedRow
|
|
223
|
-
}, editCellStateRest, {
|
|
224
|
-
api: apiRef.current
|
|
225
|
-
});
|
|
226
|
-
content = column.renderEditCell(params);
|
|
227
|
-
// TODO move to GridCell
|
|
228
|
-
classNames.push(clsx(gridClasses['cell--editing'], rootClasses == null ? void 0 : rootClasses['cell--editing']));
|
|
229
|
-
}
|
|
230
|
-
if (getCellClassName) {
|
|
231
|
-
// TODO move to GridCell
|
|
232
|
-
classNames.push(getCellClassName(cellParams));
|
|
233
|
-
}
|
|
234
|
-
var hasFocus = focusedCell === column.field;
|
|
235
|
-
var tabIndex = tabbableCell === column.field ? 0 : -1;
|
|
236
|
-
var isSelected = apiRef.current.unstable_applyPipeProcessors('isCellSelected', false, {
|
|
237
|
-
id: rowId,
|
|
238
|
-
field: column.field
|
|
239
|
-
});
|
|
197
|
+
var editCellState = (_editRowsState$rowId$ = (_editRowsState$rowId = editRowsState[rowId]) == null ? void 0 : _editRowsState$rowId[column.field]) != null ? _editRowsState$rowId$ : null;
|
|
240
198
|
return /*#__PURE__*/_jsx(CellComponent, _extends({
|
|
241
|
-
|
|
242
|
-
field: column.field,
|
|
199
|
+
column: column,
|
|
243
200
|
width: cellProps.width,
|
|
244
201
|
rowId: rowId,
|
|
245
202
|
height: rowHeight,
|
|
246
203
|
showRightBorder: cellProps.showRightBorder,
|
|
247
|
-
formattedValue: cellParams.formattedValue,
|
|
248
204
|
align: column.align || 'left',
|
|
249
|
-
cellMode: cellParams.cellMode,
|
|
250
205
|
colIndex: cellProps.indexRelativeToAllColumns,
|
|
251
|
-
isEditable: cellParams.isEditable,
|
|
252
|
-
isSelected: isSelected,
|
|
253
|
-
hasFocus: hasFocus,
|
|
254
|
-
tabIndex: tabIndex,
|
|
255
|
-
className: clsx(classNames),
|
|
256
206
|
colSpan: cellProps.colSpan,
|
|
257
|
-
disableDragEvents: disableDragEvents
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
207
|
+
disableDragEvents: disableDragEvents,
|
|
208
|
+
editCellState: editCellState
|
|
209
|
+
}, slotProps == null ? void 0 : slotProps.cell), column.field);
|
|
210
|
+
};
|
|
211
|
+
var sizes = useGridSelector(apiRef, function () {
|
|
212
|
+
return _extends({}, apiRef.current.unstable_getRowInternalSizes(rowId));
|
|
213
|
+
}, objectShallowCompare);
|
|
263
214
|
var minHeight = rowHeight;
|
|
264
215
|
if (minHeight === 'auto' && sizes) {
|
|
265
216
|
var numberOfBaseSizes = 0;
|
|
@@ -312,7 +263,11 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
|
|
|
312
263
|
rowClassNames.push(rootProps.getRowClassName(rowParams));
|
|
313
264
|
}
|
|
314
265
|
var randomNumber = randomNumberBetween(10000, 20, 80);
|
|
315
|
-
var
|
|
266
|
+
var rowNode = apiRef.current.getRowNode(rowId);
|
|
267
|
+
if (!rowNode) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
var rowType = rowNode.type;
|
|
316
271
|
var cells = [];
|
|
317
272
|
for (var i = 0; i < renderedColumns.length; i += 1) {
|
|
318
273
|
var column = renderedColumns[i];
|
|
@@ -333,7 +288,7 @@ var GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
|
|
|
333
288
|
} else {
|
|
334
289
|
var _width = cellColSpanInfo.cellProps.width;
|
|
335
290
|
var contentWidth = Math.round(randomNumber());
|
|
336
|
-
cells.push( /*#__PURE__*/_jsx(
|
|
291
|
+
cells.push( /*#__PURE__*/_jsx(slots.skeletonCell, {
|
|
337
292
|
width: _width,
|
|
338
293
|
contentWidth: contentWidth,
|
|
339
294
|
field: column.field,
|
|
@@ -369,8 +324,8 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
|
|
|
369
324
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
370
325
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
371
326
|
// ----------------------------------------------------------------------
|
|
372
|
-
containerWidth: PropTypes.number,
|
|
373
|
-
firstColumnToRender: PropTypes.number,
|
|
327
|
+
containerWidth: PropTypes.number.isRequired,
|
|
328
|
+
firstColumnToRender: PropTypes.number.isRequired,
|
|
374
329
|
/**
|
|
375
330
|
* Determines which cell has focus.
|
|
376
331
|
* If `null`, no cell in this row has focus.
|
|
@@ -380,24 +335,25 @@ process.env.NODE_ENV !== "production" ? GridRow.propTypes = {
|
|
|
380
335
|
* Index of the row in the whole sorted and filtered dataset.
|
|
381
336
|
* If some rows above have expanded children, this index also take those children into account.
|
|
382
337
|
*/
|
|
383
|
-
index: PropTypes.number,
|
|
338
|
+
index: PropTypes.number.isRequired,
|
|
384
339
|
isLastVisible: PropTypes.bool,
|
|
385
|
-
lastColumnToRender: PropTypes.number,
|
|
340
|
+
lastColumnToRender: PropTypes.number.isRequired,
|
|
386
341
|
onClick: PropTypes.func,
|
|
387
342
|
onDoubleClick: PropTypes.func,
|
|
388
343
|
onMouseEnter: PropTypes.func,
|
|
389
344
|
onMouseLeave: PropTypes.func,
|
|
390
|
-
position: PropTypes.oneOf(['center', 'left', 'right']),
|
|
391
|
-
renderedColumns: PropTypes.arrayOf(PropTypes.object),
|
|
345
|
+
position: PropTypes.oneOf(['center', 'left', 'right']).isRequired,
|
|
346
|
+
renderedColumns: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
392
347
|
row: PropTypes.object,
|
|
393
|
-
rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
|
|
394
|
-
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
395
|
-
selected: PropTypes.bool,
|
|
348
|
+
rowHeight: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
|
|
349
|
+
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
350
|
+
selected: PropTypes.bool.isRequired,
|
|
396
351
|
/**
|
|
397
352
|
* Determines which cell should be tabbable by having tabIndex=0.
|
|
398
353
|
* If `null`, no cell in this row is in the tab sequence.
|
|
399
354
|
*/
|
|
400
355
|
tabbableCell: PropTypes.string,
|
|
401
|
-
visibleColumns: PropTypes.arrayOf(PropTypes.object)
|
|
356
|
+
visibleColumns: PropTypes.arrayOf(PropTypes.object).isRequired
|
|
402
357
|
} : void 0;
|
|
403
|
-
|
|
358
|
+
var MemoizedGridRow = fastMemo(GridRow);
|
|
359
|
+
export { MemoizedGridRow as GridRow };
|