@mui/x-virtualizer 0.2.10 → 0.2.12

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +248 -0
  2. package/constants.d.ts +22 -0
  3. package/constants.js +26 -0
  4. package/esm/constants.d.ts +22 -0
  5. package/esm/constants.js +20 -0
  6. package/esm/features/colspan.d.ts +4 -4
  7. package/esm/features/dimensions.d.ts +14 -8
  8. package/esm/features/dimensions.js +26 -7
  9. package/esm/features/index.d.ts +1 -1
  10. package/esm/features/index.js +1 -1
  11. package/esm/features/keyboard.d.ts +3 -3
  12. package/esm/features/keyboard.js +1 -1
  13. package/esm/features/rowspan.d.ts +4 -4
  14. package/esm/features/virtualization/index.d.ts +2 -0
  15. package/esm/features/virtualization/index.js +2 -0
  16. package/esm/features/virtualization/layout.d.ts +129 -0
  17. package/esm/features/virtualization/layout.js +152 -0
  18. package/esm/features/{virtualization.d.ts → virtualization/virtualization.d.ts} +35 -58
  19. package/esm/features/{virtualization.js → virtualization/virtualization.js} +97 -134
  20. package/esm/index.d.ts +2 -1
  21. package/esm/index.js +3 -2
  22. package/esm/models/core.d.ts +7 -0
  23. package/esm/models/core.js +7 -0
  24. package/esm/models/dimensions.d.ts +8 -0
  25. package/esm/useVirtualizer.d.ts +25 -69
  26. package/esm/useVirtualizer.js +21 -4
  27. package/features/colspan.d.ts +4 -4
  28. package/features/dimensions.d.ts +14 -8
  29. package/features/dimensions.js +26 -7
  30. package/features/index.d.ts +1 -1
  31. package/features/keyboard.d.ts +3 -3
  32. package/features/rowspan.d.ts +4 -4
  33. package/features/virtualization/index.d.ts +2 -0
  34. package/features/virtualization/index.js +27 -0
  35. package/features/virtualization/layout.d.ts +129 -0
  36. package/features/virtualization/layout.js +163 -0
  37. package/features/{virtualization.d.ts → virtualization/virtualization.d.ts} +35 -58
  38. package/features/{virtualization.js → virtualization/virtualization.js} +97 -134
  39. package/index.d.ts +2 -1
  40. package/index.js +12 -1
  41. package/models/core.d.ts +7 -0
  42. package/models/core.js +8 -1
  43. package/models/dimensions.d.ts +8 -0
  44. package/package.json +2 -2
  45. package/useVirtualizer.d.ts +25 -69
  46. package/useVirtualizer.js +20 -3
@@ -1,13 +1,15 @@
1
1
  import { Store } from '@mui/x-internals/store';
2
2
  import { ColumnWithWidth, DimensionsState, RowId, RowsMetaState, Size } from "../models/index.js";
3
- import type { BaseState, VirtualizerParams } from "../useVirtualizer.js";
3
+ import type { BaseState, ParamsWithDefaults } from "../useVirtualizer.js";
4
4
  export type DimensionsParams = {
5
5
  rowHeight: number;
6
- columnsTotalWidth: number;
7
- leftPinnedWidth: number;
8
- rightPinnedWidth: number;
9
- topPinnedHeight: number;
10
- bottomPinnedHeight: number;
6
+ columnsTotalWidth?: number;
7
+ leftPinnedWidth?: number;
8
+ rightPinnedWidth?: number;
9
+ topPinnedHeight?: number;
10
+ bottomPinnedHeight?: number;
11
+ autoHeight?: boolean;
12
+ minimalContentHeight?: number | string;
11
13
  scrollbarSize?: number;
12
14
  };
13
15
  export declare const Dimensions: {
@@ -17,8 +19,12 @@ export declare const Dimensions: {
17
19
  rootSize: (state: BaseState) => Size;
18
20
  dimensions: (state: BaseState) => DimensionsState;
19
21
  rowHeight: (state: BaseState) => number;
22
+ columnsTotalWidth: (state: BaseState) => number;
20
23
  contentHeight: (state: BaseState) => number;
24
+ autoHeight: (state: BaseState) => boolean;
25
+ minimalContentHeight: (state: BaseState) => string | number | undefined;
21
26
  rowsMeta: (state: BaseState) => RowsMetaState;
27
+ rowPositions: (state: BaseState) => number[];
22
28
  columnPositions: (_: any, columns: ColumnWithWidth[]) => number[];
23
29
  needsHorizontalScrollbar: (state: BaseState) => boolean;
24
30
  };
@@ -32,8 +38,8 @@ export declare namespace Dimensions {
32
38
  };
33
39
  type API = ReturnType<typeof useDimensions>;
34
40
  }
35
- declare function initializeState(params: VirtualizerParams): Dimensions.State;
36
- declare function useDimensions(store: Store<BaseState>, params: VirtualizerParams, _api: {}): {
41
+ declare function initializeState(params: ParamsWithDefaults): Dimensions.State;
42
+ declare function useDimensions(store: Store<BaseState>, params: ParamsWithDefaults, _api: {}): {
37
43
  updateDimensions: (firstUpdate?: boolean) => void;
38
44
  debouncedUpdateDimensions: (((firstUpdate?: boolean) => void) & import("@mui/x-internals/throttle").Cancelable) | undefined;
39
45
  rowsMeta: {
@@ -38,14 +38,20 @@ const EMPTY_DIMENSIONS = {
38
38
  leftPinnedWidth: 0,
39
39
  rightPinnedWidth: 0,
40
40
  topContainerHeight: 0,
41
- bottomContainerHeight: 0
41
+ bottomContainerHeight: 0,
42
+ autoHeight: false,
43
+ minimalContentHeight: undefined
42
44
  };
43
45
  const selectors = {
44
46
  rootSize: state => state.rootSize,
45
47
  dimensions: state => state.dimensions,
46
48
  rowHeight: state => state.dimensions.rowHeight,
49
+ columnsTotalWidth: state => state.dimensions.columnsTotalWidth,
47
50
  contentHeight: state => state.dimensions.contentSize.height,
51
+ autoHeight: state => state.dimensions.autoHeight,
52
+ minimalContentHeight: state => state.dimensions.minimalContentHeight,
48
53
  rowsMeta: state => state.rowsMeta,
54
+ rowPositions: state => state.rowsMeta.positions,
49
55
  columnPositions: (0, _store.createSelectorMemoized)((_, columns) => {
50
56
  const positions = [];
51
57
  let currentPosition = 0;
@@ -63,7 +69,10 @@ const Dimensions = exports.Dimensions = {
63
69
  selectors
64
70
  };
65
71
  function initializeState(params) {
66
- const dimensions = (0, _extends2.default)({}, EMPTY_DIMENSIONS, params.dimensions);
72
+ const dimensions = (0, _extends2.default)({}, EMPTY_DIMENSIONS, params.dimensions, {
73
+ autoHeight: params.dimensions.autoHeight,
74
+ minimalContentHeight: params.dimensions.minimalContentHeight
75
+ });
67
76
  const {
68
77
  rowCount
69
78
  } = params;
@@ -89,7 +98,7 @@ function initializeState(params) {
89
98
  function useDimensions(store, params, _api) {
90
99
  const isFirstSizing = React.useRef(true);
91
100
  const {
92
- refs,
101
+ layout,
93
102
  dimensions: {
94
103
  rowHeight,
95
104
  columnsTotalWidth,
@@ -107,7 +116,7 @@ function useDimensions(store, params, _api) {
107
116
  if (isFirstSizing.current) {
108
117
  return;
109
118
  }
110
- const containerNode = refs.container.current;
119
+ const containerNode = layout.refs.container.current;
111
120
  const rootSize = selectors.rootSize(store.state);
112
121
  const rowsMeta = selectors.rowsMeta(store.state);
113
122
 
@@ -125,7 +134,7 @@ function useDimensions(store, params, _api) {
125
134
  let viewportInnerSize;
126
135
  let hasScrollX = false;
127
136
  let hasScrollY = false;
128
- if (params.autoHeight) {
137
+ if (params.dimensions.autoHeight) {
129
138
  hasScrollY = false;
130
139
  hasScrollX = Math.round(columnsTotalWidth) > Math.round(rootSize.width);
131
140
  viewportOuterSize = {
@@ -192,7 +201,9 @@ function useDimensions(store, params, _api) {
192
201
  leftPinnedWidth,
193
202
  rightPinnedWidth,
194
203
  topContainerHeight,
195
- bottomContainerHeight
204
+ bottomContainerHeight,
205
+ autoHeight: params.dimensions.autoHeight,
206
+ minimalContentHeight: params.dimensions.minimalContentHeight
196
207
  };
197
208
  const prevDimensions = store.state.dimensions;
198
209
  if ((0, _isDeepEqual.isDeepEqual)(prevDimensions, newDimensions)) {
@@ -202,7 +213,7 @@ function useDimensions(store, params, _api) {
202
213
  dimensions: newDimensions
203
214
  });
204
215
  onResize?.(newDimensions.root);
205
- }, [store, refs.container, params.dimensions.scrollbarSize, params.autoHeight, params.disableHorizontalScroll, params.disableVerticalScroll, onResize, rowHeight, columnsTotalWidth, leftPinnedWidth, rightPinnedWidth, topPinnedHeight, bottomPinnedHeight]);
216
+ }, [store, layout.refs.container, params.dimensions.scrollbarSize, params.dimensions.autoHeight, params.dimensions.minimalContentHeight, params.disableHorizontalScroll, params.disableVerticalScroll, onResize, rowHeight, columnsTotalWidth, leftPinnedWidth, rightPinnedWidth, topPinnedHeight, bottomPinnedHeight]);
206
217
  const {
207
218
  resizeThrottleMs
208
219
  } = params;
@@ -210,6 +221,14 @@ function useDimensions(store, params, _api) {
210
221
  const debouncedUpdateDimensions = React.useMemo(() => resizeThrottleMs > 0 ? (0, _throttle.throttle)(updateDimensionCallback, resizeThrottleMs) : undefined, [resizeThrottleMs, updateDimensionCallback]);
211
222
  React.useEffect(() => debouncedUpdateDimensions?.clear, [debouncedUpdateDimensions]);
212
223
  (0, _useEnhancedEffect.default)(updateDimensions, [updateDimensions]);
224
+ (0, _useEnhancedEffect.default)(() => {
225
+ store.update({
226
+ dimensions: (0, _extends2.default)({}, store.state.dimensions, {
227
+ autoHeight: params.dimensions.autoHeight,
228
+ minimalContentHeight: params.dimensions.minimalContentHeight
229
+ })
230
+ });
231
+ }, [store, params.dimensions.autoHeight, params.dimensions.minimalContentHeight]);
213
232
  const rowsMeta = useRowsMeta(store, params, updateDimensions);
214
233
  return {
215
234
  updateDimensions,
@@ -2,4 +2,4 @@ export * from "./colspan.js";
2
2
  export * from "./dimensions.js";
3
3
  export * from "./keyboard.js";
4
4
  export * from "./rowspan.js";
5
- export * from "./virtualization.js";
5
+ export * from "./virtualization/index.js";
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@mui/x-internals/store';
2
- import type { BaseState, VirtualizerParams } from "../useVirtualizer.js";
2
+ import type { BaseState, ParamsWithDefaults } from "../useVirtualizer.js";
3
3
  export declare const Keyboard: {
4
4
  initialize: typeof initializeState;
5
5
  use: typeof useKeyboard;
@@ -9,8 +9,8 @@ export declare namespace Keyboard {
9
9
  type State = {};
10
10
  type API = ReturnType<typeof useKeyboard>;
11
11
  }
12
- declare function initializeState(_params: VirtualizerParams): Keyboard.State;
13
- declare function useKeyboard(store: Store<BaseState & Keyboard.State>, params: VirtualizerParams, _api: {}): {
12
+ declare function initializeState(_params: ParamsWithDefaults): Keyboard.State;
13
+ declare function useKeyboard(store: Store<BaseState & Keyboard.State>, params: ParamsWithDefaults, _api: {}): {
14
14
  getViewportPageSize: () => number;
15
15
  };
16
16
  export {};
@@ -1,7 +1,7 @@
1
1
  import { Store } from '@mui/x-internals/store';
2
- import type { BaseState, VirtualizerParams } from "../useVirtualizer.js";
2
+ import type { BaseState, ParamsWithDefaults } from "../useVirtualizer.js";
3
3
  import type { RowSpanningState } from "../models/rowspan.js";
4
- import { Virtualization } from "./virtualization.js";
4
+ import { Virtualization } from "./virtualization/index.js";
5
5
  export declare const Rowspan: {
6
6
  initialize: typeof initializeState;
7
7
  use: typeof useRowspan;
@@ -18,8 +18,8 @@ export declare namespace Rowspan {
18
18
  };
19
19
  type API = ReturnType<typeof useRowspan>;
20
20
  }
21
- declare function initializeState(params: VirtualizerParams): Rowspan.State;
22
- declare function useRowspan(store: Store<BaseState & Rowspan.State>, _params: VirtualizerParams, _api: Virtualization.API): {
21
+ declare function initializeState(params: ParamsWithDefaults): Rowspan.State;
22
+ declare function useRowspan(store: Store<BaseState & Rowspan.State>, _params: ParamsWithDefaults, _api: Virtualization.API): {
23
23
  getHiddenCellsOrigin: () => Record<number, Record<number, number>>;
24
24
  };
25
25
  export {};
@@ -0,0 +1,2 @@
1
+ export * from "./layout.js";
2
+ export * from "./virtualization.js";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _layout = require("./layout");
7
+ Object.keys(_layout).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _layout[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _layout[key];
14
+ }
15
+ });
16
+ });
17
+ var _virtualization = require("./virtualization");
18
+ Object.keys(_virtualization).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _virtualization[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _virtualization[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,129 @@
1
+ import * as React from 'react';
2
+ import { Store } from '@mui/x-internals/store';
3
+ import { Dimensions } from "../dimensions.js";
4
+ import { Virtualization, type VirtualizationLayoutParams } from "./virtualization.js";
5
+ import type { BaseState, ParamsWithDefaults } from "../../useVirtualizer.js";
6
+ type RequiredAPI = Dimensions.API;
7
+ type BaseElements = {
8
+ scroller: React.RefObject<HTMLElement | null>;
9
+ container: React.RefObject<HTMLElement | null>;
10
+ };
11
+ type AnyElements = BaseElements & Record<string, React.RefObject<HTMLElement | null>>;
12
+ export declare abstract class Layout<E extends AnyElements = AnyElements> {
13
+ static elements: readonly (keyof AnyElements)[];
14
+ refs: E;
15
+ constructor(refs: E);
16
+ abstract use(store: Store<BaseState>, params: ParamsWithDefaults, api: RequiredAPI, layoutParams: VirtualizationLayoutParams): any;
17
+ refSetter(name: keyof E): (node: HTMLDivElement | null) => void;
18
+ }
19
+ type DataGridElements = BaseElements & {
20
+ scrollbarVertical: React.RefObject<HTMLElement | null>;
21
+ scrollbarHorizontal: React.RefObject<HTMLElement | null>;
22
+ };
23
+ export declare class LayoutDataGrid extends Layout<DataGridElements> {
24
+ static elements: readonly ["scroller", "container", "content", "positioner", "scrollbarVertical", "scrollbarHorizontal"];
25
+ use(store: Store<BaseState>, _params: ParamsWithDefaults, _api: RequiredAPI, layoutParams: VirtualizationLayoutParams): void;
26
+ static selectors: {
27
+ containerProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
28
+ ref: any;
29
+ };
30
+ scrollerProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
31
+ ref: any;
32
+ style: {
33
+ overflowX: string | undefined;
34
+ overflowY: string | undefined;
35
+ };
36
+ role: string;
37
+ tabIndex: number | undefined;
38
+ };
39
+ contentProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
40
+ style: React.CSSProperties;
41
+ role: string;
42
+ };
43
+ positionerProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
44
+ style: {
45
+ transform: string;
46
+ };
47
+ };
48
+ scrollbarHorizontalProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
49
+ ref: any;
50
+ scrollPosition: {
51
+ current: import("../../models/index.js").ScrollPosition;
52
+ };
53
+ };
54
+ scrollbarVerticalProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
55
+ ref: any;
56
+ scrollPosition: {
57
+ current: import("../../models/index.js").ScrollPosition;
58
+ };
59
+ };
60
+ scrollAreaProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
61
+ scrollPosition: {
62
+ current: import("../../models/index.js").ScrollPosition;
63
+ };
64
+ };
65
+ };
66
+ }
67
+ export declare class LayoutDataGridLegacy extends LayoutDataGrid {
68
+ use(store: Store<BaseState>, _params: ParamsWithDefaults, _api: RequiredAPI, layoutParams: VirtualizationLayoutParams): {
69
+ getContainerProps: () => {
70
+ ref: any;
71
+ };
72
+ getScrollerProps: () => {
73
+ ref: any;
74
+ style: {
75
+ overflowX: string | undefined;
76
+ overflowY: string | undefined;
77
+ };
78
+ role: string;
79
+ tabIndex: number | undefined;
80
+ };
81
+ getContentProps: () => {
82
+ style: React.CSSProperties;
83
+ role: string;
84
+ };
85
+ getPositionerProps: () => {
86
+ style: {
87
+ transform: string;
88
+ };
89
+ };
90
+ getScrollbarVerticalProps: () => {
91
+ ref: any;
92
+ scrollPosition: {
93
+ current: import("../../models/index.js").ScrollPosition;
94
+ };
95
+ };
96
+ getScrollbarHorizontalProps: () => {
97
+ ref: any;
98
+ scrollPosition: {
99
+ current: import("../../models/index.js").ScrollPosition;
100
+ };
101
+ };
102
+ getScrollAreaProps: () => {
103
+ scrollPosition: {
104
+ current: import("../../models/index.js").ScrollPosition;
105
+ };
106
+ };
107
+ };
108
+ }
109
+ type ListElements = BaseElements;
110
+ export declare class LayoutList extends Layout<ListElements> {
111
+ static elements: readonly ["scroller", "container", "content", "positioner"];
112
+ use(store: Store<BaseState>, _params: ParamsWithDefaults, _api: RequiredAPI, layoutParams: VirtualizationLayoutParams): void;
113
+ static selectors: {
114
+ containerProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
115
+ ref: any;
116
+ style: React.CSSProperties;
117
+ role: string;
118
+ tabIndex: number | undefined;
119
+ };
120
+ contentProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
121
+ style: React.CSSProperties;
122
+ role: string;
123
+ };
124
+ positionerProps: (args_0: Virtualization.State<Layout<AnyElements>> & Dimensions.State) => {
125
+ style: React.CSSProperties;
126
+ };
127
+ };
128
+ }
129
+ export {};
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.LayoutList = exports.LayoutDataGridLegacy = exports.LayoutDataGrid = exports.Layout = void 0;
9
+ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
10
+ var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
11
+ var platform = _interopRequireWildcard(require("@mui/x-internals/platform"));
12
+ var _store = require("@mui/x-internals/store");
13
+ var _dimensions = require("../../features/dimensions");
14
+ var _virtualization = require("./virtualization");
15
+ /* eslint-disable react-hooks/rules-of-hooks */
16
+
17
+ class Layout {
18
+ static elements = ['scroller', 'container'];
19
+ constructor(refs) {
20
+ this.refs = refs;
21
+ }
22
+ refSetter(name) {
23
+ return node => {
24
+ if (node && this.refs[name].current !== node) {
25
+ this.refs[name].current = node;
26
+ }
27
+ };
28
+ }
29
+ }
30
+ exports.Layout = Layout;
31
+ class LayoutDataGrid extends Layout {
32
+ static elements = ['scroller', 'container', 'content', 'positioner', 'scrollbarVertical', 'scrollbarHorizontal'];
33
+ use(store, _params, _api, layoutParams) {
34
+ const {
35
+ scrollerRef,
36
+ containerRef
37
+ } = layoutParams;
38
+ const scrollbarVerticalRef = (0, _useEventCallback.default)(this.refSetter('scrollbarVertical'));
39
+ const scrollbarHorizontalRef = (0, _useEventCallback.default)(this.refSetter('scrollbarHorizontal'));
40
+ store.state.virtualization.context = {
41
+ scrollerRef,
42
+ containerRef,
43
+ scrollbarVerticalRef,
44
+ scrollbarHorizontalRef
45
+ };
46
+ }
47
+ static selectors = {
48
+ containerProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.context, context => ({
49
+ ref: context.containerRef
50
+ })),
51
+ scrollerProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.context, _dimensions.Dimensions.selectors.autoHeight, _dimensions.Dimensions.selectors.needsHorizontalScrollbar, (context, autoHeight, needsHorizontalScrollbar) => ({
52
+ ref: context.scrollerRef,
53
+ style: {
54
+ overflowX: !needsHorizontalScrollbar ? 'hidden' : undefined,
55
+ overflowY: autoHeight ? 'hidden' : undefined
56
+ },
57
+ role: 'presentation',
58
+ // `tabIndex` shouldn't be used along role=presentation, but it fixes a Firefox bug
59
+ // https://github.com/mui/mui-x/pull/13891#discussion_r1683416024
60
+ tabIndex: platform.isFirefox ? -1 : undefined
61
+ })),
62
+ contentProps: (0, _store.createSelectorMemoized)(_dimensions.Dimensions.selectors.contentHeight, _dimensions.Dimensions.selectors.minimalContentHeight, _dimensions.Dimensions.selectors.columnsTotalWidth, _dimensions.Dimensions.selectors.needsHorizontalScrollbar, (contentHeight, minimalContentHeight, columnsTotalWidth, needsHorizontalScrollbar) => ({
63
+ style: {
64
+ width: needsHorizontalScrollbar ? columnsTotalWidth : 'auto',
65
+ flexBasis: contentHeight === 0 ? minimalContentHeight : contentHeight,
66
+ flexShrink: 0
67
+ },
68
+ role: 'presentation'
69
+ })),
70
+ positionerProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.offsetTop, offsetTop => ({
71
+ style: {
72
+ transform: `translate3d(0, ${offsetTop}px, 0)`
73
+ }
74
+ })),
75
+ scrollbarHorizontalProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.context, _virtualization.Virtualization.selectors.scrollPosition, (context, scrollPosition) => ({
76
+ ref: context.scrollbarHorizontalRef,
77
+ scrollPosition
78
+ })),
79
+ scrollbarVerticalProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.context, _virtualization.Virtualization.selectors.scrollPosition, (context, scrollPosition) => ({
80
+ ref: context.scrollbarVerticalRef,
81
+ scrollPosition
82
+ })),
83
+ scrollAreaProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.scrollPosition, scrollPosition => ({
84
+ scrollPosition
85
+ }))
86
+ };
87
+ }
88
+
89
+ // The current virtualizer API is exposed on one of the DataGrid slots, so we need to keep
90
+ // the old API for backward compatibility. This API prevents using fine-grained reactivity
91
+ // as all props are returned in a single object, so everything re-renders on any change.
92
+ //
93
+ // TODO(v9): Remove the legacy API.
94
+ exports.LayoutDataGrid = LayoutDataGrid;
95
+ class LayoutDataGridLegacy extends LayoutDataGrid {
96
+ use(store, _params, _api, layoutParams) {
97
+ super.use(store, _params, _api, layoutParams);
98
+ const containerProps = store.use(LayoutDataGrid.selectors.containerProps);
99
+ const scrollerProps = store.use(LayoutDataGrid.selectors.scrollerProps);
100
+ const contentProps = store.use(LayoutDataGrid.selectors.contentProps);
101
+ const positionerProps = store.use(LayoutDataGrid.selectors.positionerProps);
102
+ const scrollbarVerticalProps = store.use(LayoutDataGrid.selectors.scrollbarVerticalProps);
103
+ const scrollbarHorizontalProps = store.use(LayoutDataGrid.selectors.scrollbarHorizontalProps);
104
+ const scrollAreaProps = store.use(LayoutDataGrid.selectors.scrollAreaProps);
105
+ return {
106
+ getContainerProps: () => containerProps,
107
+ getScrollerProps: () => scrollerProps,
108
+ getContentProps: () => contentProps,
109
+ getPositionerProps: () => positionerProps,
110
+ getScrollbarVerticalProps: () => scrollbarVerticalProps,
111
+ getScrollbarHorizontalProps: () => scrollbarHorizontalProps,
112
+ getScrollAreaProps: () => scrollAreaProps
113
+ };
114
+ }
115
+ }
116
+ exports.LayoutDataGridLegacy = LayoutDataGridLegacy;
117
+ class LayoutList extends Layout {
118
+ static elements = ['scroller', 'container', 'content', 'positioner'];
119
+ use(store, _params, _api, layoutParams) {
120
+ const {
121
+ scrollerRef,
122
+ containerRef
123
+ } = layoutParams;
124
+ const mergedRef = (0, _useForkRef.default)(scrollerRef, containerRef);
125
+ store.state.virtualization.context = {
126
+ mergedRef
127
+ };
128
+ }
129
+ static selectors = {
130
+ containerProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.context, _dimensions.Dimensions.selectors.autoHeight, _dimensions.Dimensions.selectors.needsHorizontalScrollbar, (context, autoHeight, needsHorizontalScrollbar) => ({
131
+ ref: context.mergedRef,
132
+ style: {
133
+ overflowX: !needsHorizontalScrollbar ? 'hidden' : undefined,
134
+ overflowY: autoHeight ? 'hidden' : undefined,
135
+ position: 'relative'
136
+ },
137
+ role: 'presentation',
138
+ // `tabIndex` shouldn't be used along role=presentation, but it fixes a Firefox bug
139
+ // https://github.com/mui/mui-x/pull/13891#discussion_r1683416024
140
+ tabIndex: platform.isFirefox ? -1 : undefined
141
+ })),
142
+ contentProps: (0, _store.createSelectorMemoized)(_dimensions.Dimensions.selectors.contentHeight, contentHeight => {
143
+ return {
144
+ style: {
145
+ position: 'absolute',
146
+ display: 'inline-block',
147
+ width: '100%',
148
+ height: contentHeight,
149
+ top: 0,
150
+ left: 0,
151
+ zIndex: -1
152
+ },
153
+ role: 'presentation'
154
+ };
155
+ }),
156
+ positionerProps: (0, _store.createSelectorMemoized)(_virtualization.Virtualization.selectors.offsetTop, offsetTop => ({
157
+ style: {
158
+ height: offsetTop
159
+ }
160
+ }))
161
+ };
162
+ }
163
+ exports.LayoutList = LayoutList;
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import type { integer } from '@mui/x-internals/types';
3
3
  import { Store } from '@mui/x-internals/store';
4
- import type { CellColSpanInfo } from "../models/colspan.js";
5
- import { Dimensions } from "./dimensions.js";
6
- import type { BaseState, VirtualizerParams } from "../useVirtualizer.js";
7
- import { PinnedRowPosition, RenderContext, ColumnsRenderContext, ColumnWithWidth, RowId, RowEntry } from "../models/index.js";
4
+ import type { CellColSpanInfo } from "../../models/colspan.js";
5
+ import { Dimensions } from "../dimensions.js";
6
+ import type { BaseState, ParamsWithDefaults } from "../../useVirtualizer.js";
7
+ import type { Layout } from "./layout.js";
8
+ import { RenderContext, ColumnsRenderContext, ColumnWithWidth, RowId, ScrollPosition } from "../../models/index.js";
8
9
  export type VirtualizationParams = {
9
10
  /** @default false */
10
11
  isRtl?: boolean;
@@ -15,11 +16,16 @@ export type VirtualizationParams = {
15
16
  * @default 150 */
16
17
  columnBufferPx?: number;
17
18
  };
18
- export type VirtualizationState = {
19
+ export type VirtualizationState<K extends string = string> = {
19
20
  enabled: boolean;
20
21
  enabledForRows: boolean;
21
22
  enabledForColumns: boolean;
22
23
  renderContext: RenderContext;
24
+ props: Record<K, Record<string, any>>;
25
+ context: Record<string, any>;
26
+ scrollPosition: {
27
+ current: ScrollPosition;
28
+ };
23
29
  };
24
30
  export declare const EMPTY_RENDER_CONTEXT: {
25
31
  firstRowIndex: number;
@@ -31,20 +37,31 @@ export declare const Virtualization: {
31
37
  initialize: typeof initializeState;
32
38
  use: typeof useVirtualization;
33
39
  selectors: {
34
- store: (state: BaseState) => VirtualizationState;
40
+ store: (state: BaseState) => VirtualizationState<string>;
35
41
  renderContext: (state: BaseState) => RenderContext;
36
42
  enabledForRows: (state: BaseState) => boolean;
37
43
  enabledForColumns: (state: BaseState) => boolean;
44
+ offsetTop: (args_0: Virtualization.State<Layout<{
45
+ scroller: React.RefObject<HTMLElement | null>;
46
+ container: React.RefObject<HTMLElement | null>;
47
+ } & Record<string, React.RefObject<HTMLElement | null>>>> & Dimensions.State) => number;
48
+ context: (state: BaseState) => Record<string, any>;
49
+ scrollPosition: (state: BaseState) => {
50
+ current: ScrollPosition;
51
+ };
38
52
  };
39
53
  };
40
54
  export declare namespace Virtualization {
41
- type State = {
42
- virtualization: VirtualizationState;
55
+ type State<L extends Layout> = {
56
+ virtualization: VirtualizationState<L extends Layout<infer E> ? keyof E : string>;
43
57
  getters: ReturnType<typeof useVirtualization>['getters'];
44
58
  };
45
59
  type API = ReturnType<typeof useVirtualization>;
46
60
  }
47
- declare function initializeState(params: VirtualizerParams): Virtualization.State;
61
+ declare function initializeState(params: ParamsWithDefaults): Virtualization.State<Layout<{
62
+ scroller: React.RefObject<HTMLElement | null>;
63
+ container: React.RefObject<HTMLElement | null>;
64
+ } & Record<string, React.RefObject<HTMLElement | null>>>>;
48
65
  /** APIs to override for colspan/rowspan */
49
66
  type AbstractAPI = {
50
67
  getCellColSpanInfo: (rowId: RowId, columnIndex: integer) => CellColSpanInfo;
@@ -52,58 +69,18 @@ type AbstractAPI = {
52
69
  getHiddenCellsOrigin: () => Record<RowId, Record<number, number>>;
53
70
  };
54
71
  type RequiredAPI = Dimensions.API & AbstractAPI;
55
- declare function useVirtualization(store: Store<BaseState>, params: VirtualizerParams, api: RequiredAPI): {
56
- getters: {
57
- setPanels: React.Dispatch<React.SetStateAction<Readonly<Map<any, React.ReactNode>>>>;
58
- getOffsetTop: () => number;
59
- getRows: (rowParams?: {
60
- rows?: RowEntry[];
61
- position?: PinnedRowPosition;
62
- renderContext?: RenderContext;
63
- }, unstable_rowTree?: Record<RowId, any>) => React.ReactNode[];
64
- rows: RowEntry[];
65
- getContainerProps: () => {
66
- ref: (node: HTMLDivElement | null) => (() => void | undefined) | undefined;
67
- };
68
- getScrollerProps: () => {
69
- ref: (node: HTMLDivElement | null) => (() => void | undefined) | undefined;
70
- style: React.CSSProperties;
71
- role: string;
72
- tabIndex: number | undefined;
73
- };
74
- getContentProps: () => {
75
- ref: (node: HTMLDivElement | null) => void;
76
- style: React.CSSProperties;
77
- role: string;
78
- };
79
- getScrollbarVerticalProps: () => {
80
- ref: (node: HTMLDivElement | null) => void;
81
- scrollPosition: React.RefObject<{
82
- top: number;
83
- left: number;
84
- }>;
85
- };
86
- getScrollbarHorizontalProps: () => {
87
- ref: (node: HTMLDivElement | null) => void;
88
- scrollPosition: React.RefObject<{
89
- top: number;
90
- left: number;
91
- }>;
92
- };
93
- getScrollAreaProps: () => {
94
- scrollPosition: React.RefObject<{
95
- top: number;
96
- left: number;
97
- }>;
98
- };
99
- };
100
- useVirtualization: () => BaseState;
101
- setPanels: React.Dispatch<React.SetStateAction<Readonly<Map<any, React.ReactNode>>>>;
102
- forceUpdateRenderContext: () => void;
103
- scheduleUpdateRenderContext: () => void;
72
+ export type VirtualizationLayoutParams = {
73
+ containerRef: (node: HTMLDivElement | null) => void;
74
+ scrollerRef: (node: HTMLDivElement | null) => void;
75
+ };
76
+ declare function useVirtualization(store: Store<BaseState>, params: ParamsWithDefaults, api: RequiredAPI): {
104
77
  getCellColSpanInfo: (rowId: RowId, columnIndex: integer) => CellColSpanInfo;
105
78
  calculateColSpan: (rowId: RowId, minFirstColumn: integer, maxLastColumn: integer, columns: ColumnWithWidth[]) => void;
106
79
  getHiddenCellsOrigin: () => Record<RowId, Record<number, number>>;
80
+ getters: any;
81
+ setPanels: React.Dispatch<React.SetStateAction<Readonly<Map<any, React.ReactNode>>>>;
82
+ forceUpdateRenderContext: () => void;
83
+ scheduleUpdateRenderContext: () => void;
107
84
  };
108
85
  export declare function areRenderContextsEqual(context1: RenderContext, context2: RenderContext): boolean;
109
86
  export declare function computeOffsetLeft(columnPositions: number[], renderContext: ColumnsRenderContext, pinnedLeftLength: number): number;