@mui/x-virtualizer 0.2.9 → 0.2.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 +174 -0
- package/constants.d.ts +22 -0
- package/constants.js +26 -0
- package/esm/constants.d.ts +22 -0
- package/esm/constants.js +20 -0
- package/esm/features/colspan.d.ts +4 -4
- package/esm/features/dimensions.d.ts +14 -8
- package/esm/features/dimensions.js +26 -7
- package/esm/features/index.d.ts +1 -1
- package/esm/features/index.js +1 -1
- package/esm/features/keyboard.d.ts +3 -3
- package/esm/features/keyboard.js +1 -1
- package/esm/features/rowspan.d.ts +4 -4
- package/esm/features/virtualization/index.d.ts +2 -0
- package/esm/features/virtualization/index.js +2 -0
- package/esm/features/virtualization/layout.d.ts +129 -0
- package/esm/features/virtualization/layout.js +152 -0
- package/esm/features/{virtualization.d.ts → virtualization/virtualization.d.ts} +35 -58
- package/esm/features/{virtualization.js → virtualization/virtualization.js} +98 -136
- package/esm/index.d.ts +2 -1
- package/esm/index.js +3 -2
- package/esm/models/core.d.ts +7 -0
- package/esm/models/core.js +7 -0
- package/esm/models/dimensions.d.ts +8 -0
- package/esm/useVirtualizer.d.ts +25 -69
- package/esm/useVirtualizer.js +21 -4
- package/features/colspan.d.ts +4 -4
- package/features/dimensions.d.ts +14 -8
- package/features/dimensions.js +26 -7
- package/features/index.d.ts +1 -1
- package/features/keyboard.d.ts +3 -3
- package/features/rowspan.d.ts +4 -4
- package/features/virtualization/index.d.ts +2 -0
- package/features/virtualization/index.js +27 -0
- package/features/virtualization/layout.d.ts +129 -0
- package/features/virtualization/layout.js +163 -0
- package/features/{virtualization.d.ts → virtualization/virtualization.d.ts} +35 -58
- package/features/{virtualization.js → virtualization/virtualization.js} +98 -136
- package/index.d.ts +2 -1
- package/index.js +12 -1
- package/models/core.d.ts +7 -0
- package/models/core.js +8 -1
- package/models/dimensions.d.ts +8 -0
- package/package.json +2 -2
- package/useVirtualizer.d.ts +25 -69
- package/useVirtualizer.js +20 -3
|
@@ -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 "
|
|
5
|
-
import { Dimensions } from "
|
|
6
|
-
import type { BaseState,
|
|
7
|
-
import {
|
|
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:
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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;
|