@mui/x-data-grid 8.0.0-alpha.10 → 8.0.0-alpha.11
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 +107 -2
- package/DataGrid/useDataGridComponent.js +2 -2
- package/components/GridRow.js +6 -2
- package/components/GridScrollArea.d.ts +5 -2
- package/components/GridScrollArea.js +31 -24
- package/components/GridSkeletonLoadingOverlay.js +2 -1
- package/components/containers/GridRoot.js +11 -9
- package/components/containers/GridRootStyles.js +3 -3
- package/components/menu/columnMenu/GridColumnMenuContainer.js +5 -2
- package/components/virtualization/GridMainContainer.d.ts +2 -2
- package/components/virtualization/GridMainContainer.js +1 -1
- package/components/virtualization/GridVirtualScroller.js +21 -14
- package/constants/index.d.ts +1 -0
- package/constants/index.js +2 -1
- package/constants/signature.d.ts +9 -0
- package/constants/signature.js +10 -0
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/hooks/core/useGridApiInitialization.js +1 -1
- package/hooks/core/useGridStateInitialization.js +3 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/hooks/features/columns/gridColumnsSelector.d.ts +0 -5
- package/hooks/features/columns/gridColumnsSelector.js +0 -12
- package/hooks/features/columns/useGridColumns.js +2 -1
- package/hooks/features/dimensions/gridDimensionsSelectors.d.ts +16 -0
- package/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
- package/hooks/features/dimensions/index.d.ts +1 -1
- package/hooks/features/dimensions/index.js +1 -2
- package/hooks/features/dimensions/useGridDimensions.js +97 -70
- package/hooks/features/editing/gridEditingSelectors.d.ts +5 -1
- package/hooks/features/editing/gridEditingSelectors.js +6 -1
- package/hooks/features/editing/useGridRowEditing.js +4 -4
- package/hooks/features/filter/gridFilterSelector.d.ts +2 -2
- package/hooks/features/filter/gridFilterSelector.js +4 -3
- package/hooks/features/filter/gridFilterState.d.ts +8 -3
- package/hooks/features/filter/gridFilterState.js +5 -0
- package/hooks/features/filter/useGridFilter.js +9 -14
- package/hooks/features/overlays/useGridOverlays.js +1 -1
- package/hooks/features/pagination/gridPaginationUtils.js +1 -1
- package/hooks/features/pagination/useGridPagination.js +1 -1
- package/hooks/features/rowSelection/useGridRowSelection.js +3 -2
- package/hooks/features/rowSelection/utils.js +2 -2
- package/hooks/features/rows/gridRowsMetaState.d.ts +8 -0
- package/hooks/features/rows/gridRowsUtils.d.ts +0 -4
- package/hooks/features/rows/gridRowsUtils.js +0 -16
- package/hooks/features/rows/useGridRows.js +4 -2
- package/hooks/features/rows/useGridRowsMeta.js +33 -17
- package/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +6 -0
- package/hooks/features/virtualization/useGridVirtualScroller.js +43 -27
- package/hooks/utils/index.d.ts +1 -1
- package/hooks/utils/index.js +1 -1
- package/hooks/utils/useGridApiEventHandler.d.ts +7 -17
- package/hooks/utils/useGridApiEventHandler.js +68 -75
- package/hooks/utils/useGridSelector.js +23 -5
- package/hooks/utils/useIsSSR.d.ts +1 -0
- package/hooks/utils/useIsSSR.js +5 -0
- package/index.js +1 -1
- package/internals/index.d.ts +3 -1
- package/internals/index.js +3 -1
- package/internals/utils/propValidation.js +1 -1
- package/models/api/gridStateApi.d.ts +1 -0
- package/models/events/gridEventLookup.d.ts +6 -0
- package/modern/DataGrid/useDataGridComponent.js +2 -2
- package/modern/components/GridRow.js +6 -2
- package/modern/components/GridScrollArea.js +31 -24
- package/modern/components/GridSkeletonLoadingOverlay.js +2 -1
- package/modern/components/containers/GridRoot.js +11 -9
- package/modern/components/containers/GridRootStyles.js +3 -3
- package/modern/components/menu/columnMenu/GridColumnMenuContainer.js +5 -2
- package/modern/components/virtualization/GridMainContainer.js +1 -1
- package/modern/components/virtualization/GridVirtualScroller.js +21 -14
- package/modern/constants/index.js +2 -1
- package/modern/constants/signature.js +10 -0
- package/modern/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/modern/hooks/core/useGridApiInitialization.js +1 -1
- package/modern/hooks/core/useGridStateInitialization.js +3 -2
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/modern/hooks/features/columns/gridColumnsSelector.js +0 -12
- package/modern/hooks/features/columns/useGridColumns.js +2 -1
- package/modern/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
- package/modern/hooks/features/dimensions/index.js +1 -2
- package/modern/hooks/features/dimensions/useGridDimensions.js +97 -70
- package/modern/hooks/features/editing/gridEditingSelectors.js +6 -1
- package/modern/hooks/features/editing/useGridRowEditing.js +4 -4
- package/modern/hooks/features/filter/gridFilterSelector.js +4 -3
- package/modern/hooks/features/filter/gridFilterState.js +5 -0
- package/modern/hooks/features/filter/useGridFilter.js +9 -14
- package/modern/hooks/features/overlays/useGridOverlays.js +1 -1
- package/modern/hooks/features/pagination/gridPaginationUtils.js +1 -1
- package/modern/hooks/features/pagination/useGridPagination.js +1 -1
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +3 -2
- package/modern/hooks/features/rowSelection/utils.js +2 -2
- package/modern/hooks/features/rows/gridRowsUtils.js +0 -16
- package/modern/hooks/features/rows/useGridRows.js +4 -2
- package/modern/hooks/features/rows/useGridRowsMeta.js +33 -17
- package/modern/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +43 -27
- package/modern/hooks/utils/index.js +1 -1
- package/modern/hooks/utils/useGridApiEventHandler.js +68 -75
- package/modern/hooks/utils/useGridSelector.js +23 -5
- package/modern/hooks/utils/useIsSSR.js +5 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +3 -1
- package/modern/internals/utils/propValidation.js +1 -1
- package/node/DataGrid/useDataGridComponent.js +2 -2
- package/node/components/GridRow.js +6 -2
- package/node/components/GridScrollArea.js +31 -24
- package/node/components/GridSkeletonLoadingOverlay.js +2 -1
- package/node/components/containers/GridRoot.js +10 -8
- package/node/components/containers/GridRootStyles.js +3 -3
- package/node/components/menu/columnMenu/GridColumnMenuContainer.js +5 -2
- package/node/components/virtualization/GridMainContainer.js +1 -1
- package/node/components/virtualization/GridVirtualScroller.js +21 -14
- package/node/constants/index.js +11 -0
- package/node/constants/signature.js +16 -0
- package/node/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/node/hooks/core/useGridApiInitialization.js +2 -2
- package/node/hooks/core/useGridStateInitialization.js +3 -2
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/node/hooks/features/columns/gridColumnsSelector.js +1 -13
- package/node/hooks/features/columns/useGridColumns.js +2 -1
- package/node/hooks/features/dimensions/gridDimensionsSelectors.js +38 -2
- package/node/hooks/features/dimensions/index.js +13 -11
- package/node/hooks/features/dimensions/useGridDimensions.js +94 -67
- package/node/hooks/features/editing/gridEditingSelectors.js +5 -1
- package/node/hooks/features/editing/useGridRowEditing.js +4 -4
- package/node/hooks/features/filter/gridFilterSelector.js +4 -3
- package/node/hooks/features/filter/gridFilterState.js +6 -1
- package/node/hooks/features/filter/useGridFilter.js +8 -13
- package/node/hooks/features/overlays/useGridOverlays.js +1 -1
- package/node/hooks/features/pagination/gridPaginationUtils.js +2 -2
- package/node/hooks/features/pagination/useGridPagination.js +1 -1
- package/node/hooks/features/rowSelection/useGridRowSelection.js +5 -4
- package/node/hooks/features/rowSelection/utils.js +3 -3
- package/node/hooks/features/rows/gridRowsUtils.js +0 -17
- package/node/hooks/features/rows/useGridRows.js +6 -4
- package/node/hooks/features/rows/useGridRowsMeta.js +31 -15
- package/node/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +42 -26
- package/node/hooks/utils/index.js +21 -11
- package/node/hooks/utils/useGridApiEventHandler.js +71 -78
- package/node/hooks/utils/useGridSelector.js +23 -5
- package/node/hooks/utils/useIsSSR.js +12 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +32 -7
- package/node/internals/utils/propValidation.js +2 -2
- package/package.json +3 -2
|
@@ -16,9 +16,7 @@ var _utils2 = require("../../../utils/utils");
|
|
|
16
16
|
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
17
17
|
var _useGridSelector = require("../../utils/useGridSelector");
|
|
18
18
|
var _densitySelector = require("../density/densitySelector");
|
|
19
|
-
var _gridFilterSelector = require("../filter/gridFilterSelector");
|
|
20
19
|
var _gridPaginationSelector = require("../pagination/gridPaginationSelector");
|
|
21
|
-
var _gridSortingSelector = require("../sorting/gridSortingSelector");
|
|
22
20
|
var _pipeProcessing = require("../../core/pipeProcessing");
|
|
23
21
|
var _gridRowsSelector = require("./gridRowsSelector");
|
|
24
22
|
var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
|
|
@@ -29,10 +27,18 @@ const rowsMetaStateInitializer = (state, props, apiRef) => {
|
|
|
29
27
|
apiRef.current.caches.rowsMeta = {
|
|
30
28
|
heights: new Map()
|
|
31
29
|
};
|
|
30
|
+
const baseRowHeight = (0, _gridDimensionsSelectors.gridRowHeightSelector)(apiRef.current.state);
|
|
31
|
+
const dataRowCount = (0, _gridRowsSelector.gridRowCountSelector)(apiRef.current.state);
|
|
32
|
+
const pagination = (0, _gridPaginationSelector.gridPaginationSelector)(apiRef.current.state);
|
|
33
|
+
const rowCount = Math.min(pagination.enabled ? pagination.paginationModel.pageSize : dataRowCount, dataRowCount);
|
|
32
34
|
return (0, _extends2.default)({}, state, {
|
|
33
35
|
rowsMeta: {
|
|
34
|
-
currentPageTotalHeight:
|
|
35
|
-
positions:
|
|
36
|
+
currentPageTotalHeight: rowCount * baseRowHeight,
|
|
37
|
+
positions: Array.from({
|
|
38
|
+
length: rowCount
|
|
39
|
+
}, (_, i) => i * baseRowHeight),
|
|
40
|
+
pinnedTopRowsTotalHeight: 0,
|
|
41
|
+
pinnedBottomRowsTotalHeight: 0
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
44
|
};
|
|
@@ -53,12 +59,9 @@ const useGridRowsMeta = (apiRef, props) => {
|
|
|
53
59
|
const hasRowWithAutoHeight = React.useRef(false);
|
|
54
60
|
const isHeightMetaValid = React.useRef(false);
|
|
55
61
|
const densityFactor = (0, _useGridSelector.useGridSelector)(apiRef, _densitySelector.gridDensityFactorSelector);
|
|
56
|
-
const filterModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridFilterSelector.gridFilterModelSelector);
|
|
57
|
-
const paginationState = (0, _useGridSelector.useGridSelector)(apiRef, _gridPaginationSelector.gridPaginationSelector);
|
|
58
|
-
const sortModel = (0, _useGridSelector.useGridSelector)(apiRef, _gridSortingSelector.gridSortModelSelector);
|
|
59
62
|
const currentPage = (0, _useGridVisibleRows.useGridVisibleRows)(apiRef, props);
|
|
60
63
|
const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
|
|
61
|
-
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef,
|
|
64
|
+
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridRowHeightSelector);
|
|
62
65
|
const getRowHeightEntry = rowId => {
|
|
63
66
|
let entry = heightCache.get(rowId);
|
|
64
67
|
if (entry === undefined) {
|
|
@@ -123,8 +126,14 @@ const useGridRowsMeta = (apiRef, props) => {
|
|
|
123
126
|
}, [apiRef, currentPage.rows, getRowHeightProp, getEstimatedRowHeight, rowHeight, getRowSpacing, densityFactor]);
|
|
124
127
|
const hydrateRowsMeta = React.useCallback(() => {
|
|
125
128
|
hasRowWithAutoHeight.current = false;
|
|
126
|
-
pinnedRows.top.
|
|
127
|
-
|
|
129
|
+
const pinnedTopRowsTotalHeight = pinnedRows.top.reduce((acc, row) => {
|
|
130
|
+
const entry = processHeightEntry(row);
|
|
131
|
+
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
132
|
+
}, 0);
|
|
133
|
+
const pinnedBottomRowsTotalHeight = pinnedRows.bottom.reduce((acc, row) => {
|
|
134
|
+
const entry = processHeightEntry(row);
|
|
135
|
+
return acc + entry.content + entry.spacingTop + entry.spacingBottom + entry.detail;
|
|
136
|
+
}, 0);
|
|
128
137
|
const positions = [];
|
|
129
138
|
const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
|
|
130
139
|
positions.push(acc);
|
|
@@ -136,14 +145,21 @@ const useGridRowsMeta = (apiRef, props) => {
|
|
|
136
145
|
// No row has height=auto, so all rows are already measured
|
|
137
146
|
lastMeasuredRowIndex.current = Infinity;
|
|
138
147
|
}
|
|
148
|
+
const didHeightsChange = pinnedTopRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedTopRowsTotalHeight || pinnedBottomRowsTotalHeight !== apiRef.current.state.rowsMeta.pinnedBottomRowsTotalHeight || currentPageTotalHeight !== apiRef.current.state.rowsMeta.currentPageTotalHeight;
|
|
149
|
+
const rowsMeta = {
|
|
150
|
+
currentPageTotalHeight,
|
|
151
|
+
positions,
|
|
152
|
+
pinnedTopRowsTotalHeight,
|
|
153
|
+
pinnedBottomRowsTotalHeight
|
|
154
|
+
};
|
|
139
155
|
apiRef.current.setState(state => {
|
|
140
156
|
return (0, _extends2.default)({}, state, {
|
|
141
|
-
rowsMeta
|
|
142
|
-
currentPageTotalHeight,
|
|
143
|
-
positions
|
|
144
|
-
}
|
|
157
|
+
rowsMeta
|
|
145
158
|
});
|
|
146
159
|
});
|
|
160
|
+
if (didHeightsChange) {
|
|
161
|
+
apiRef.current.updateDimensions();
|
|
162
|
+
}
|
|
147
163
|
isHeightMetaValid.current = true;
|
|
148
164
|
}, [apiRef, pinnedRows, currentPage.rows, processHeightEntry]);
|
|
149
165
|
const getRowHeight = rowId => {
|
|
@@ -193,7 +209,7 @@ const useGridRowsMeta = (apiRef, props) => {
|
|
|
193
209
|
// Because of variable row height this is needed for the virtualization
|
|
194
210
|
(0, _utils.unstable_useEnhancedEffect)(() => {
|
|
195
211
|
hydrateRowsMeta();
|
|
196
|
-
}, [
|
|
212
|
+
}, [hydrateRowsMeta]);
|
|
197
213
|
const rowsMetaApi = {
|
|
198
214
|
unstable_getRowHeight: getRowHeight,
|
|
199
215
|
unstable_setLastMeasuredRowIndex: setLastMeasuredRowIndex,
|
|
@@ -30,15 +30,16 @@ const gridSortedRowEntriesSelector = exports.gridSortedRowEntriesSelector = (0,
|
|
|
30
30
|
id,
|
|
31
31
|
model
|
|
32
32
|
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
} else {
|
|
34
|
+
const rowNode = rowTree[id];
|
|
35
|
+
if (rowNode && (0, _gridRowsUtils.isAutogeneratedRowNode)(rowNode)) {
|
|
36
|
+
acc.push({
|
|
37
|
+
id,
|
|
38
|
+
model: {
|
|
39
|
+
[_gridRowsUtils.GRID_ID_AUTOGENERATED]: id
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
42
43
|
}
|
|
43
44
|
return acc;
|
|
44
45
|
}, []));
|
|
@@ -17,12 +17,12 @@ var _useLazyRef = _interopRequireDefault(require("@mui/utils/useLazyRef"));
|
|
|
17
17
|
var _useTimeout = _interopRequireDefault(require("@mui/utils/useTimeout"));
|
|
18
18
|
var _RtlProvider = require("@mui/system/RtlProvider");
|
|
19
19
|
var _reactMajor = _interopRequireDefault(require("@mui/x-internals/reactMajor"));
|
|
20
|
+
var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
|
|
20
21
|
var _useGridPrivateApiContext = require("../../utils/useGridPrivateApiContext");
|
|
21
22
|
var _useGridRootProps = require("../../utils/useGridRootProps");
|
|
22
23
|
var _useGridSelector = require("../../utils/useGridSelector");
|
|
23
24
|
var _useRunOnce = require("../../utils/useRunOnce");
|
|
24
25
|
var _gridColumnsSelector = require("../columns/gridColumnsSelector");
|
|
25
|
-
var _gridDimensionsSelectors = require("../dimensions/gridDimensionsSelectors");
|
|
26
26
|
var _gridRowsSelector = require("../rows/gridRowsSelector");
|
|
27
27
|
var _useGridVisibleRows = require("../../utils/useGridVisibleRows");
|
|
28
28
|
var _utils2 = require("../../utils");
|
|
@@ -68,8 +68,6 @@ const useGridVirtualScroller = () => {
|
|
|
68
68
|
const visibleColumns = (0, _useGridSelector.useGridSelector)(apiRef, () => listView ? [(0, _gridListViewSelectors.gridListColumnSelector)(apiRef.current.state)] : (0, _gridColumnsSelector.gridVisibleColumnDefinitionsSelector)(apiRef));
|
|
69
69
|
const enabledForRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridVirtualizationRowEnabledSelector) && !_isJSDOM.isJSDOM;
|
|
70
70
|
const enabledForColumns = (0, _useGridSelector.useGridSelector)(apiRef, _gridVirtualizationSelectors.gridVirtualizationColumnEnabledSelector) && !_isJSDOM.isJSDOM;
|
|
71
|
-
const dimensions = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridDimensionsSelector);
|
|
72
|
-
const outerSize = dimensions.viewportOuterSize;
|
|
73
71
|
const pinnedRows = (0, _useGridSelector.useGridSelector)(apiRef, _gridRowsSelector.gridPinnedRowsSelector);
|
|
74
72
|
const pinnedColumnDefinitions = (0, _gridColumnsSelector.gridVisiblePinnedColumnDefinitionsSelector)(apiRef);
|
|
75
73
|
const pinnedColumns = listView ? _columns.EMPTY_PINNED_COLUMN_FIELDS : pinnedColumnDefinitions;
|
|
@@ -82,10 +80,14 @@ const useGridVirtualScroller = () => {
|
|
|
82
80
|
const scrollerRef = apiRef.current.virtualScrollerRef;
|
|
83
81
|
const scrollbarVerticalRef = apiRef.current.virtualScrollbarVerticalRef;
|
|
84
82
|
const scrollbarHorizontalRef = apiRef.current.virtualScrollbarHorizontalRef;
|
|
85
|
-
const contentHeight = dimensions.contentSize.height;
|
|
86
|
-
const columnsTotalWidth = dimensions.columnsTotalWidth;
|
|
87
83
|
const hasColSpan = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridHasColSpanSelector);
|
|
88
84
|
const isRenderContextReady = React.useRef(false);
|
|
85
|
+
const rowHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridRowHeightSelector);
|
|
86
|
+
const contentHeight = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridContentHeightSelector);
|
|
87
|
+
const columnsTotalWidth = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridColumnsTotalWidthSelector);
|
|
88
|
+
const needsHorizontalScrollbar = (0, _useGridSelector.useGridSelector)(apiRef, needsHorizontalScrollbarSelector);
|
|
89
|
+
const verticalScrollbarWidth = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridVerticalScrollbarWidthSelector);
|
|
90
|
+
const gridHasFiller = (0, _useGridSelector.useGridSelector)(apiRef, _gridDimensionsSelectors.gridHasFillerSelector);
|
|
89
91
|
const previousSize = React.useRef(null);
|
|
90
92
|
const mainRefCallback = React.useCallback(node => {
|
|
91
93
|
mainRef.current = node;
|
|
@@ -152,7 +154,7 @@ const useGridVirtualScroller = () => {
|
|
|
152
154
|
const focusedVirtualCell = (0, _useGridSelector.useGridSelector)(apiRef, _gridFocusedVirtualCellSelector.gridFocusedVirtualCellSelector);
|
|
153
155
|
const scrollTimeout = (0, _useTimeout.default)();
|
|
154
156
|
const frozenContext = React.useRef(undefined);
|
|
155
|
-
const scrollCache = (0, _useLazyRef.default)(() => createScrollCache(isRtl, rootProps.rowBufferPx, rootProps.columnBufferPx,
|
|
157
|
+
const scrollCache = (0, _useLazyRef.default)(() => createScrollCache(isRtl, rootProps.rowBufferPx, rootProps.columnBufferPx, rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6)).current;
|
|
156
158
|
const updateRenderContext = React.useCallback(nextRenderContext => {
|
|
157
159
|
if (areRenderContextsEqual(nextRenderContext, apiRef.current.state.virtualization.renderContext)) {
|
|
158
160
|
return;
|
|
@@ -167,19 +169,21 @@ const useGridVirtualScroller = () => {
|
|
|
167
169
|
});
|
|
168
170
|
|
|
169
171
|
// The lazy-loading hook is listening to `renderedRowsIntervalChange`,
|
|
170
|
-
// but only does something if
|
|
171
|
-
//
|
|
172
|
-
|
|
172
|
+
// but only does something if we already have a render context, because
|
|
173
|
+
// otherwise we would call an update directly on mount
|
|
174
|
+
const isReady = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state).isReady;
|
|
175
|
+
if (isReady && didRowsIntervalChange) {
|
|
173
176
|
previousRowContext.current = nextRenderContext;
|
|
174
177
|
apiRef.current.publishEvent('renderedRowsIntervalChange', nextRenderContext);
|
|
175
178
|
}
|
|
176
179
|
previousContextScrollPosition.current = scrollPosition.current;
|
|
177
|
-
}, [apiRef
|
|
180
|
+
}, [apiRef]);
|
|
178
181
|
const triggerUpdateRenderContext = (0, _utils.unstable_useEventCallback)(() => {
|
|
179
182
|
const scroller = scrollerRef.current;
|
|
180
183
|
if (!scroller) {
|
|
181
184
|
return undefined;
|
|
182
185
|
}
|
|
186
|
+
const dimensions = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state);
|
|
183
187
|
const maxScrollTop = Math.ceil(dimensions.minimumSize.height - dimensions.viewportOuterSize.height);
|
|
184
188
|
const maxScrollLeft = Math.ceil(dimensions.minimumSize.width - dimensions.viewportInnerSize.width);
|
|
185
189
|
|
|
@@ -199,7 +203,7 @@ const useGridVirtualScroller = () => {
|
|
|
199
203
|
const columnScroll = Math.abs(scrollPosition.current.left - previousContextScrollPosition.current.left);
|
|
200
204
|
|
|
201
205
|
// PERF: use the computed minimum column width instead of a static one
|
|
202
|
-
const didCrossThreshold = rowScroll >=
|
|
206
|
+
const didCrossThreshold = rowScroll >= rowHeight || columnScroll >= MINIMUM_COLUMN_WIDTH;
|
|
203
207
|
const didChangeDirection = scrollCache.direction !== direction;
|
|
204
208
|
const shouldUpdate = didCrossThreshold || didChangeDirection;
|
|
205
209
|
if (!shouldUpdate) {
|
|
@@ -221,7 +225,7 @@ const useGridVirtualScroller = () => {
|
|
|
221
225
|
}
|
|
222
226
|
}
|
|
223
227
|
scrollCache.direction = direction;
|
|
224
|
-
scrollCache.buffer = bufferForDirection(isRtl, direction, rootProps.rowBufferPx, rootProps.columnBufferPx,
|
|
228
|
+
scrollCache.buffer = bufferForDirection(isRtl, direction, rootProps.rowBufferPx, rootProps.columnBufferPx, rowHeight * 15, MINIMUM_COLUMN_WIDTH * 6);
|
|
225
229
|
const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
|
|
226
230
|
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
227
231
|
|
|
@@ -233,6 +237,10 @@ const useGridVirtualScroller = () => {
|
|
|
233
237
|
return nextRenderContext;
|
|
234
238
|
});
|
|
235
239
|
const forceUpdateRenderContext = () => {
|
|
240
|
+
// skip update if dimensions are not ready and virtualization is enabled
|
|
241
|
+
if (!(0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state).isReady && (enabledForRows || enabledForColumns)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
236
244
|
const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
|
|
237
245
|
const nextRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
238
246
|
// Reset the frozen context when the render context changes, see the illustration in https://github.com/mui/mui-x/pull/12353
|
|
@@ -261,7 +269,12 @@ const useGridVirtualScroller = () => {
|
|
|
261
269
|
if (!params.rows && !currentPage.range) {
|
|
262
270
|
return [];
|
|
263
271
|
}
|
|
264
|
-
|
|
272
|
+
let baseRenderContext = renderContext;
|
|
273
|
+
if (params.renderContext) {
|
|
274
|
+
baseRenderContext = params.renderContext;
|
|
275
|
+
baseRenderContext.firstColumnIndex = renderContext.firstColumnIndex;
|
|
276
|
+
baseRenderContext.lastColumnIndex = renderContext.lastColumnIndex;
|
|
277
|
+
}
|
|
265
278
|
const isLastSection = !hasBottomPinnedRows && params.position === undefined || hasBottomPinnedRows && params.position === 'bottom';
|
|
266
279
|
const isPinnedSection = params.position !== undefined;
|
|
267
280
|
let rowIndexOffset;
|
|
@@ -355,7 +368,7 @@ const useGridVirtualScroller = () => {
|
|
|
355
368
|
}
|
|
356
369
|
}
|
|
357
370
|
let currentRenderContext = baseRenderContext;
|
|
358
|
-
if (
|
|
371
|
+
if (frozenContext.current && rowIndexInPage >= frozenContext.current.firstRowIndex && rowIndexInPage < frozenContext.current.lastRowIndex) {
|
|
359
372
|
currentRenderContext = frozenContext.current;
|
|
360
373
|
}
|
|
361
374
|
const isVirtualFocusRow = rowIndexInPage === virtualRowIndex;
|
|
@@ -370,7 +383,7 @@ const useGridVirtualScroller = () => {
|
|
|
370
383
|
index: rowIndex,
|
|
371
384
|
selected: isSelected,
|
|
372
385
|
offsetLeft: offsetLeft,
|
|
373
|
-
columnsTotalWidth:
|
|
386
|
+
columnsTotalWidth: columnsTotalWidth,
|
|
374
387
|
rowHeight: baseRowHeight,
|
|
375
388
|
pinnedColumns: pinnedColumns,
|
|
376
389
|
visibleColumns: visibleColumns,
|
|
@@ -381,8 +394,8 @@ const useGridVirtualScroller = () => {
|
|
|
381
394
|
isLastVisible: isLastVisible,
|
|
382
395
|
isNotVisible: isVirtualFocusRow,
|
|
383
396
|
showBottomBorder: showBottomBorder,
|
|
384
|
-
scrollbarWidth:
|
|
385
|
-
gridHasFiller:
|
|
397
|
+
scrollbarWidth: verticalScrollbarWidth,
|
|
398
|
+
gridHasFiller: gridHasFiller
|
|
386
399
|
}, rowProps), id));
|
|
387
400
|
if (isVirtualFocusRow) {
|
|
388
401
|
return;
|
|
@@ -399,7 +412,6 @@ const useGridVirtualScroller = () => {
|
|
|
399
412
|
});
|
|
400
413
|
return rows;
|
|
401
414
|
};
|
|
402
|
-
const needsHorizontalScrollbar = outerSize.width && columnsTotalWidth > outerSize.width;
|
|
403
415
|
const scrollerStyle = React.useMemo(() => ({
|
|
404
416
|
overflowX: !needsHorizontalScrollbar || listView ? 'hidden' : undefined,
|
|
405
417
|
overflowY: rootProps.autoHeight ? 'hidden' : undefined
|
|
@@ -435,14 +447,11 @@ const useGridVirtualScroller = () => {
|
|
|
435
447
|
scrollerRef.current.scrollLeft = 0;
|
|
436
448
|
}
|
|
437
449
|
}, [listView, scrollerRef]);
|
|
438
|
-
(0, _useRunOnce.useRunOnce)(
|
|
439
|
-
const inputs = inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns);
|
|
440
|
-
const initialRenderContext = computeRenderContext(inputs, scrollPosition.current, scrollCache);
|
|
441
|
-
updateRenderContext(initialRenderContext);
|
|
450
|
+
(0, _useRunOnce.useRunOnce)(renderContext !== _useGridVirtualization.EMPTY_RENDER_CONTEXT, () => {
|
|
442
451
|
apiRef.current.publishEvent('scrollPositionChange', {
|
|
443
452
|
top: scrollPosition.current.top,
|
|
444
453
|
left: scrollPosition.current.left,
|
|
445
|
-
renderContext
|
|
454
|
+
renderContext
|
|
446
455
|
});
|
|
447
456
|
isRenderContextReady.current = true;
|
|
448
457
|
if (rootProps.initialState?.scroll && scrollerRef.current) {
|
|
@@ -495,9 +504,9 @@ const useGridVirtualScroller = () => {
|
|
|
495
504
|
apiRef.current.register('private', {
|
|
496
505
|
updateRenderContext: forceUpdateRenderContext
|
|
497
506
|
});
|
|
498
|
-
(0, _utils2.
|
|
499
|
-
(0, _utils2.
|
|
500
|
-
(0, _utils2.
|
|
507
|
+
(0, _utils2.useGridApiOptionHandler)(apiRef, 'sortedRowsSet', forceUpdateRenderContext);
|
|
508
|
+
(0, _utils2.useGridApiOptionHandler)(apiRef, 'paginationModelChange', forceUpdateRenderContext);
|
|
509
|
+
(0, _utils2.useGridApiOptionHandler)(apiRef, 'columnsChange', forceUpdateRenderContext);
|
|
501
510
|
return {
|
|
502
511
|
renderContext,
|
|
503
512
|
setPanels,
|
|
@@ -533,10 +542,17 @@ const useGridVirtualScroller = () => {
|
|
|
533
542
|
ref: scrollbarHorizontalRef,
|
|
534
543
|
role: 'presentation',
|
|
535
544
|
scrollPosition
|
|
545
|
+
}),
|
|
546
|
+
getScrollAreaProps: () => ({
|
|
547
|
+
scrollPosition
|
|
536
548
|
})
|
|
537
549
|
};
|
|
538
550
|
};
|
|
539
551
|
exports.useGridVirtualScroller = useGridVirtualScroller;
|
|
552
|
+
// dimension selectors
|
|
553
|
+
function needsHorizontalScrollbarSelector(state) {
|
|
554
|
+
return state.dimensions.viewportOuterSize.width > 0 && state.dimensions.columnsTotalWidth > state.dimensions.viewportOuterSize.width;
|
|
555
|
+
}
|
|
540
556
|
function inputsSelector(apiRef, rootProps, enabledForRows, enabledForColumns) {
|
|
541
557
|
const dimensions = (0, _gridDimensionsSelectors.gridDimensionsSelector)(apiRef.current.state);
|
|
542
558
|
const currentPage = (0, _useGridVisibleRows.getVisibleRows)(apiRef, rootProps);
|
|
@@ -4,8 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
useGridApiEventHandler: true,
|
|
8
|
+
useGridApiOptionHandler: true,
|
|
9
|
+
unstable_resetCleanupTracking: true,
|
|
7
10
|
useGridSelector: true
|
|
8
11
|
};
|
|
12
|
+
Object.defineProperty(exports, "unstable_resetCleanupTracking", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useGridApiEventHandler.unstable_resetCleanupTracking;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "useGridApiEventHandler", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _useGridApiEventHandler.useGridApiEventHandler;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "useGridApiOptionHandler", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _useGridApiEventHandler.useGridApiOptionHandler;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
9
30
|
Object.defineProperty(exports, "useGridSelector", {
|
|
10
31
|
enumerable: true,
|
|
11
32
|
get: function () {
|
|
@@ -13,17 +34,6 @@ Object.defineProperty(exports, "useGridSelector", {
|
|
|
13
34
|
}
|
|
14
35
|
});
|
|
15
36
|
var _useGridApiEventHandler = require("./useGridApiEventHandler");
|
|
16
|
-
Object.keys(_useGridApiEventHandler).forEach(function (key) {
|
|
17
|
-
if (key === "default" || key === "__esModule") return;
|
|
18
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
19
|
-
if (key in exports && exports[key] === _useGridApiEventHandler[key]) return;
|
|
20
|
-
Object.defineProperty(exports, key, {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return _useGridApiEventHandler[key];
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
37
|
var _useGridApiMethod = require("./useGridApiMethod");
|
|
28
38
|
Object.keys(_useGridApiMethod).forEach(function (key) {
|
|
29
39
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -4,39 +4,59 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.useGridApiEventHandler =
|
|
7
|
+
exports.internal_registryContainer = void 0;
|
|
8
|
+
exports.unstable_resetCleanupTracking = unstable_resetCleanupTracking;
|
|
9
|
+
exports.useGridApiEventHandler = useGridApiEventHandler;
|
|
10
10
|
exports.useGridApiOptionHandler = useGridApiOptionHandler;
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _TimerBasedCleanupTracking = require("../../utils/cleanupTracking/TimerBasedCleanupTracking");
|
|
13
13
|
var _FinalizationRegistryBasedCleanupTracking = require("../../utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking");
|
|
14
|
-
/**
|
|
15
|
-
* Signal to the underlying logic what version of the public component API
|
|
16
|
-
* of the Data Grid is exposed.
|
|
17
|
-
*/
|
|
18
|
-
var GridSignature = exports.GridSignature = /*#__PURE__*/function (GridSignature) {
|
|
19
|
-
GridSignature["DataGrid"] = "DataGrid";
|
|
20
|
-
GridSignature["DataGridPro"] = "DataGridPro";
|
|
21
|
-
GridSignature["DataGridPremium"] = "DataGridPremium";
|
|
22
|
-
return GridSignature;
|
|
23
|
-
}(GridSignature || {});
|
|
24
|
-
// We use class to make it easier to detect in heap snapshots by name
|
|
25
|
-
class ObjectToBeRetainedByReact {}
|
|
26
|
-
|
|
27
14
|
// Based on https://github.com/Bnaya/use-dispose-uncommitted/blob/main/src/finalization-registry-based-impl.ts
|
|
28
15
|
// Check https://github.com/facebook/react/issues/15317 to get more information
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
|
|
17
|
+
// We use class to make it easier to detect in heap snapshots by name
|
|
18
|
+
class ObjectToBeRetainedByReact {
|
|
19
|
+
static create() {
|
|
20
|
+
return new ObjectToBeRetainedByReact();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const registryContainer = {
|
|
24
|
+
current: createRegistry()
|
|
25
|
+
};
|
|
26
|
+
let cleanupTokensCounter = 0;
|
|
27
|
+
function useGridApiEventHandler(apiRef, eventName, handler, options) {
|
|
28
|
+
const objectRetainedByReact = React.useState(ObjectToBeRetainedByReact.create)[0];
|
|
29
|
+
const subscription = React.useRef(null);
|
|
30
|
+
const handlerRef = React.useRef(null);
|
|
31
|
+
handlerRef.current = handler;
|
|
32
|
+
const cleanupTokenRef = React.useRef(null);
|
|
33
|
+
if (!subscription.current && handlerRef.current) {
|
|
34
|
+
const enhancedHandler = (params, event, details) => {
|
|
35
|
+
if (!event.defaultMuiPrevented) {
|
|
36
|
+
handlerRef.current?.(params, event, details);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
|
|
40
|
+
cleanupTokensCounter += 1;
|
|
41
|
+
cleanupTokenRef.current = {
|
|
42
|
+
cleanupToken: cleanupTokensCounter
|
|
43
|
+
};
|
|
44
|
+
registryContainer.current.register(objectRetainedByReact,
|
|
45
|
+
// The callback below will be called once this reference stops being retained
|
|
46
|
+
() => {
|
|
47
|
+
subscription.current?.();
|
|
48
|
+
subscription.current = null;
|
|
49
|
+
cleanupTokenRef.current = null;
|
|
50
|
+
}, cleanupTokenRef.current);
|
|
51
|
+
} else if (!handlerRef.current && subscription.current) {
|
|
52
|
+
subscription.current();
|
|
53
|
+
subscription.current = null;
|
|
54
|
+
if (cleanupTokenRef.current) {
|
|
55
|
+
registryContainer.current.unregister(cleanupTokenRef.current);
|
|
56
|
+
cleanupTokenRef.current = null;
|
|
34
57
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const handlerRef = React.useRef(null);
|
|
38
|
-
handlerRef.current = handler;
|
|
39
|
-
const cleanupTokenRef = React.useRef(null);
|
|
58
|
+
}
|
|
59
|
+
React.useEffect(() => {
|
|
40
60
|
if (!subscription.current && handlerRef.current) {
|
|
41
61
|
const enhancedHandler = (params, event, details) => {
|
|
42
62
|
if (!event.defaultMuiPrevented) {
|
|
@@ -44,62 +64,35 @@ function createUseGridApiEventHandler(registryContainer) {
|
|
|
44
64
|
}
|
|
45
65
|
};
|
|
46
66
|
subscription.current = apiRef.current.subscribeEvent(eventName, enhancedHandler, options);
|
|
47
|
-
cleanupTokensCounter += 1;
|
|
48
|
-
cleanupTokenRef.current = {
|
|
49
|
-
cleanupToken: cleanupTokensCounter
|
|
50
|
-
};
|
|
51
|
-
registryContainer.registry.register(objectRetainedByReact,
|
|
52
|
-
// The callback below will be called once this reference stops being retained
|
|
53
|
-
() => {
|
|
54
|
-
subscription.current?.();
|
|
55
|
-
subscription.current = null;
|
|
56
|
-
cleanupTokenRef.current = null;
|
|
57
|
-
}, cleanupTokenRef.current);
|
|
58
|
-
} else if (!handlerRef.current && subscription.current) {
|
|
59
|
-
subscription.current();
|
|
60
|
-
subscription.current = null;
|
|
61
|
-
if (cleanupTokenRef.current) {
|
|
62
|
-
registryContainer.registry.unregister(cleanupTokenRef.current);
|
|
63
|
-
cleanupTokenRef.current = null;
|
|
64
|
-
}
|
|
65
67
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// so we can trust the cleanup function to remove the listener.
|
|
78
|
-
registryContainer.registry.unregister(cleanupTokenRef.current);
|
|
79
|
-
cleanupTokenRef.current = null;
|
|
80
|
-
}
|
|
81
|
-
return () => {
|
|
82
|
-
subscription.current?.();
|
|
83
|
-
subscription.current = null;
|
|
84
|
-
};
|
|
85
|
-
}, [apiRef, eventName, options]);
|
|
86
|
-
};
|
|
68
|
+
if (cleanupTokenRef.current && registryContainer.current) {
|
|
69
|
+
// If the effect was called, it means that this render was committed
|
|
70
|
+
// so we can trust the cleanup function to remove the listener.
|
|
71
|
+
registryContainer.current.unregister(cleanupTokenRef.current);
|
|
72
|
+
cleanupTokenRef.current = null;
|
|
73
|
+
}
|
|
74
|
+
return () => {
|
|
75
|
+
subscription.current?.();
|
|
76
|
+
subscription.current = null;
|
|
77
|
+
};
|
|
78
|
+
}, [apiRef, eventName, options]);
|
|
87
79
|
}
|
|
88
|
-
const
|
|
89
|
-
|
|
80
|
+
const OPTIONS_IS_FIRST = {
|
|
81
|
+
isFirst: true
|
|
90
82
|
};
|
|
83
|
+
function useGridApiOptionHandler(apiRef, eventName, handler) {
|
|
84
|
+
useGridApiEventHandler(apiRef, eventName, handler, OPTIONS_IS_FIRST);
|
|
85
|
+
}
|
|
91
86
|
|
|
92
87
|
// TODO: move to @mui/x-data-grid/internals
|
|
93
88
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
94
|
-
|
|
95
|
-
registryContainer.
|
|
96
|
-
registryContainer.
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
function useGridApiOptionHandler(apiRef, eventName, handler) {
|
|
104
|
-
useGridApiEventHandler(apiRef, eventName, handler, optionsSubscriberOptions);
|
|
89
|
+
function unstable_resetCleanupTracking() {
|
|
90
|
+
registryContainer.current?.reset();
|
|
91
|
+
registryContainer.current = createRegistry();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
95
|
+
const internal_registryContainer = exports.internal_registryContainer = registryContainer;
|
|
96
|
+
function createRegistry() {
|
|
97
|
+
return typeof FinalizationRegistry !== 'undefined' ? new _FinalizationRegistryBasedCleanupTracking.FinalizationRegistryBasedCleanupTracking() : new _TimerBasedCleanupTracking.TimerBasedCleanupTracking();
|
|
105
98
|
}
|
|
@@ -8,8 +8,8 @@ exports.useGridSelector = exports.objectShallowCompare = exports.argsEqual = voi
|
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _fastObjectShallowCompare = require("@mui/x-internals/fastObjectShallowCompare");
|
|
10
10
|
var _warning = require("@mui/x-internals/warning");
|
|
11
|
+
var _shim = require("use-sync-external-store/shim");
|
|
11
12
|
var _useLazyRef = require("./useLazyRef");
|
|
12
|
-
var _useOnMount = require("./useOnMount");
|
|
13
13
|
function isOutputSelector(selector) {
|
|
14
14
|
return selector.acceptsApiRef;
|
|
15
15
|
}
|
|
@@ -41,8 +41,10 @@ const createRefs = () => ({
|
|
|
41
41
|
state: null,
|
|
42
42
|
equals: null,
|
|
43
43
|
selector: null,
|
|
44
|
-
args:
|
|
44
|
+
args: undefined
|
|
45
45
|
});
|
|
46
|
+
const EMPTY = [];
|
|
47
|
+
const emptyGetSnapshot = () => null;
|
|
46
48
|
const useGridSelector = (apiRef, selector, args = undefined, equals = defaultCompare) => {
|
|
47
49
|
if (process.env.NODE_ENV !== 'production') {
|
|
48
50
|
if (!apiRef.current.state) {
|
|
@@ -66,15 +68,31 @@ const useGridSelector = (apiRef, selector, args = undefined, equals = defaultCom
|
|
|
66
68
|
setState(newState);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
const subscribe = React.useCallback(() => {
|
|
72
|
+
if (refs.current.subscription) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
refs.current.subscription = apiRef.current.store.subscribe(() => {
|
|
71
76
|
const newState = applySelector(apiRef, refs.current.selector, refs.current.args, apiRef.current.instanceId);
|
|
72
77
|
if (!refs.current.equals(refs.current.state, newState)) {
|
|
73
78
|
refs.current.state = newState;
|
|
74
79
|
setState(newState);
|
|
75
80
|
}
|
|
76
81
|
});
|
|
77
|
-
|
|
82
|
+
return null;
|
|
83
|
+
},
|
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
85
|
+
EMPTY);
|
|
86
|
+
const unsubscribe = React.useCallback(() => {
|
|
87
|
+
return () => {
|
|
88
|
+
if (refs.current.subscription) {
|
|
89
|
+
refs.current.subscription();
|
|
90
|
+
refs.current.subscription = undefined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, EMPTY);
|
|
95
|
+
(0, _shim.useSyncExternalStore)(unsubscribe, subscribe, emptyGetSnapshot);
|
|
78
96
|
return state;
|
|
79
97
|
};
|
|
80
98
|
exports.useGridSelector = useGridSelector;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useIsSSR = void 0;
|
|
7
|
+
var _shim = require("use-sync-external-store/shim");
|
|
8
|
+
const emptySubscribe = () => () => {};
|
|
9
|
+
const clientSnapshot = () => false;
|
|
10
|
+
const serverSnapshot = () => true;
|
|
11
|
+
const useIsSSR = () => (0, _shim.useSyncExternalStore)(emptySubscribe, clientSnapshot, serverSnapshot);
|
|
12
|
+
exports.useIsSSR = useIsSSR;
|
package/node/index.js
CHANGED