@mui/x-virtualizer 0.1.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 +10645 -0
- package/README.md +3 -0
- package/esm/features/colspan.d.ts +28 -0
- package/esm/features/colspan.js +88 -0
- package/esm/features/dimensions.d.ts +41 -0
- package/esm/features/dimensions.js +465 -0
- package/esm/features/index.d.ts +5 -0
- package/esm/features/index.js +5 -0
- package/esm/features/keyboard.d.ts +16 -0
- package/esm/features/keyboard.js +35 -0
- package/esm/features/rowspan.d.ts +25 -0
- package/esm/features/rowspan.js +36 -0
- package/esm/features/virtualization.d.ts +103 -0
- package/esm/features/virtualization.js +844 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +9 -0
- package/esm/models/colspan.d.ts +13 -0
- package/esm/models/colspan.js +1 -0
- package/esm/models/core.d.ts +72 -0
- package/esm/models/core.js +43 -0
- package/esm/models/dimensions.d.ts +132 -0
- package/esm/models/dimensions.js +1 -0
- package/esm/models/index.d.ts +4 -0
- package/esm/models/index.js +4 -0
- package/esm/models/rowspan.d.ts +17 -0
- package/esm/models/rowspan.js +1 -0
- package/esm/package.json +1 -0
- package/esm/useVirtualizer.d.ts +193 -0
- package/esm/useVirtualizer.js +26 -0
- package/features/colspan.d.ts +28 -0
- package/features/colspan.js +94 -0
- package/features/dimensions.d.ts +41 -0
- package/features/dimensions.js +472 -0
- package/features/index.d.ts +5 -0
- package/features/index.js +60 -0
- package/features/keyboard.d.ts +16 -0
- package/features/keyboard.js +40 -0
- package/features/rowspan.d.ts +25 -0
- package/features/rowspan.js +42 -0
- package/features/virtualization.d.ts +103 -0
- package/features/virtualization.js +853 -0
- package/index.d.ts +2 -0
- package/index.js +34 -0
- package/models/colspan.d.ts +13 -0
- package/models/colspan.js +5 -0
- package/models/core.d.ts +72 -0
- package/models/core.js +49 -0
- package/models/dimensions.d.ts +132 -0
- package/models/dimensions.js +5 -0
- package/models/index.d.ts +4 -0
- package/models/index.js +49 -0
- package/models/rowspan.d.ts +17 -0
- package/models/rowspan.js +5 -0
- package/package.json +67 -0
- package/useVirtualizer.d.ts +193 -0
- package/useVirtualizer.js +33 -0
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @mui/x-virtualizer v0.1.0
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./useVirtualizer.js";
|
|
9
|
+
export * from "./features/index.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { float, integer } from '@mui/x-internals/types';
|
|
2
|
+
export type ColumnIndex = number;
|
|
3
|
+
export type CellColSpanInfo = {
|
|
4
|
+
spannedByColSpan: true;
|
|
5
|
+
rightVisibleCellIndex: ColumnIndex;
|
|
6
|
+
leftVisibleCellIndex: ColumnIndex;
|
|
7
|
+
} | {
|
|
8
|
+
spannedByColSpan: false;
|
|
9
|
+
cellProps: {
|
|
10
|
+
colSpan: integer;
|
|
11
|
+
width: float;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type Size = {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
};
|
|
5
|
+
export declare namespace Size {
|
|
6
|
+
const EMPTY: {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
};
|
|
10
|
+
function equals(a: Size, b: Size): boolean;
|
|
11
|
+
}
|
|
12
|
+
export type Row = {
|
|
13
|
+
[key: string | symbol]: any;
|
|
14
|
+
};
|
|
15
|
+
export type Column = {
|
|
16
|
+
[key: string | symbol]: any;
|
|
17
|
+
};
|
|
18
|
+
export type ColumnWithWidth = {
|
|
19
|
+
computedWidth: number;
|
|
20
|
+
} & Column;
|
|
21
|
+
export type RowId = any;
|
|
22
|
+
export type RowEntry = {
|
|
23
|
+
id: any;
|
|
24
|
+
model: Row;
|
|
25
|
+
};
|
|
26
|
+
export type PinnedRows = {
|
|
27
|
+
top: RowEntry[];
|
|
28
|
+
bottom: RowEntry[];
|
|
29
|
+
};
|
|
30
|
+
export type PinnedColumns = {
|
|
31
|
+
left: Column[];
|
|
32
|
+
right: Column[];
|
|
33
|
+
};
|
|
34
|
+
export type FocusedCell = {
|
|
35
|
+
rowIndex: number;
|
|
36
|
+
columnIndex: number;
|
|
37
|
+
id?: any;
|
|
38
|
+
field?: string;
|
|
39
|
+
};
|
|
40
|
+
export interface ColumnsRenderContext {
|
|
41
|
+
firstColumnIndex: number;
|
|
42
|
+
lastColumnIndex: number;
|
|
43
|
+
}
|
|
44
|
+
export interface RenderContext extends ColumnsRenderContext {
|
|
45
|
+
firstRowIndex: number;
|
|
46
|
+
lastRowIndex: number;
|
|
47
|
+
}
|
|
48
|
+
export interface GridScrollParams {
|
|
49
|
+
left: number;
|
|
50
|
+
top: number;
|
|
51
|
+
renderContext?: RenderContext;
|
|
52
|
+
}
|
|
53
|
+
export type GridScrollFn = (v: GridScrollParams) => void;
|
|
54
|
+
export type PinnedRowPosition = keyof PinnedRows;
|
|
55
|
+
export type ScrollPosition = {
|
|
56
|
+
top: number;
|
|
57
|
+
left: number;
|
|
58
|
+
};
|
|
59
|
+
export declare enum ScrollDirection {
|
|
60
|
+
NONE = 0,
|
|
61
|
+
UP = 1,
|
|
62
|
+
DOWN = 2,
|
|
63
|
+
LEFT = 3,
|
|
64
|
+
RIGHT = 4,
|
|
65
|
+
}
|
|
66
|
+
export declare namespace ScrollDirection {
|
|
67
|
+
function forDelta(dx: number, dy: number): ScrollDirection;
|
|
68
|
+
}
|
|
69
|
+
export type RowRange = {
|
|
70
|
+
firstRowIndex: number;
|
|
71
|
+
lastRowIndex: number;
|
|
72
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-redeclare */
|
|
2
|
+
export let Size;
|
|
3
|
+
(function (_Size) {
|
|
4
|
+
const EMPTY = _Size.EMPTY = {
|
|
5
|
+
width: 0,
|
|
6
|
+
height: 0
|
|
7
|
+
};
|
|
8
|
+
function equals(a, b) {
|
|
9
|
+
return a.width === b.width && a.height === b.height;
|
|
10
|
+
}
|
|
11
|
+
_Size.equals = equals;
|
|
12
|
+
})(Size || (Size = {})); // TODO
|
|
13
|
+
export let ScrollDirection = /*#__PURE__*/function (ScrollDirection) {
|
|
14
|
+
ScrollDirection[ScrollDirection["NONE"] = 0] = "NONE";
|
|
15
|
+
ScrollDirection[ScrollDirection["UP"] = 1] = "UP";
|
|
16
|
+
ScrollDirection[ScrollDirection["DOWN"] = 2] = "DOWN";
|
|
17
|
+
ScrollDirection[ScrollDirection["LEFT"] = 3] = "LEFT";
|
|
18
|
+
ScrollDirection[ScrollDirection["RIGHT"] = 4] = "RIGHT";
|
|
19
|
+
return ScrollDirection;
|
|
20
|
+
}({});
|
|
21
|
+
(function (_ScrollDirection) {
|
|
22
|
+
function forDelta(dx, dy) {
|
|
23
|
+
if (dx === 0 && dy === 0) {
|
|
24
|
+
return ScrollDirection.NONE;
|
|
25
|
+
}
|
|
26
|
+
/* eslint-disable */
|
|
27
|
+
if (Math.abs(dy) >= Math.abs(dx)) {
|
|
28
|
+
if (dy > 0) {
|
|
29
|
+
return ScrollDirection.DOWN;
|
|
30
|
+
} else {
|
|
31
|
+
return ScrollDirection.UP;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
if (dx > 0) {
|
|
35
|
+
return ScrollDirection.RIGHT;
|
|
36
|
+
} else {
|
|
37
|
+
return ScrollDirection.LEFT;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/* eslint-enable */
|
|
41
|
+
}
|
|
42
|
+
_ScrollDirection.forDelta = forDelta;
|
|
43
|
+
})(ScrollDirection || (ScrollDirection = {}));
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Size } from "./core.js";
|
|
2
|
+
export interface DimensionsState {
|
|
3
|
+
/**
|
|
4
|
+
* Indicates that the dimensions have been initialized.
|
|
5
|
+
*/
|
|
6
|
+
isReady: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The root container size.
|
|
9
|
+
*/
|
|
10
|
+
root: Size;
|
|
11
|
+
/**
|
|
12
|
+
* The viewport size including scrollbars.
|
|
13
|
+
*/
|
|
14
|
+
viewportOuterSize: Size;
|
|
15
|
+
/**
|
|
16
|
+
* The viewport size not including scrollbars.
|
|
17
|
+
*/
|
|
18
|
+
viewportInnerSize: Size;
|
|
19
|
+
/**
|
|
20
|
+
* The size of the main content (unpinned rows & columns).
|
|
21
|
+
*/
|
|
22
|
+
contentSize: Size;
|
|
23
|
+
/**
|
|
24
|
+
* The minimum size to display the grid, including all pinned sections and headers.
|
|
25
|
+
*/
|
|
26
|
+
minimumSize: Size;
|
|
27
|
+
/**
|
|
28
|
+
* Indicates if a scroll is currently needed to go from the beginning of the first column to the end of the last column.
|
|
29
|
+
*/
|
|
30
|
+
hasScrollX: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Indicates if a scroll is currently needed to go from the beginning of the first row to the end of the last row.
|
|
33
|
+
*/
|
|
34
|
+
hasScrollY: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Size of the scrollbar used to scroll the rows in pixel.
|
|
37
|
+
* It is defined even when the scrollbar is currently not needed.
|
|
38
|
+
*/
|
|
39
|
+
scrollbarSize: number;
|
|
40
|
+
/**
|
|
41
|
+
* Width of a row.
|
|
42
|
+
*/
|
|
43
|
+
rowWidth: number;
|
|
44
|
+
/**
|
|
45
|
+
* Height of a row.
|
|
46
|
+
*/
|
|
47
|
+
rowHeight: number;
|
|
48
|
+
/**
|
|
49
|
+
* Size of all the visible columns.
|
|
50
|
+
*/
|
|
51
|
+
columnsTotalWidth: number;
|
|
52
|
+
/**
|
|
53
|
+
* Size of left pinned columns.
|
|
54
|
+
*/
|
|
55
|
+
leftPinnedWidth: number;
|
|
56
|
+
/**
|
|
57
|
+
* Size of right pinned columns.
|
|
58
|
+
*/
|
|
59
|
+
rightPinnedWidth: number;
|
|
60
|
+
/**
|
|
61
|
+
* Height of one column header.
|
|
62
|
+
*/
|
|
63
|
+
headerHeight: number;
|
|
64
|
+
/**
|
|
65
|
+
* Height of one column group header.
|
|
66
|
+
*/
|
|
67
|
+
groupHeaderHeight: number;
|
|
68
|
+
/**
|
|
69
|
+
* Height of header filters.
|
|
70
|
+
*/
|
|
71
|
+
headerFilterHeight: number;
|
|
72
|
+
/**
|
|
73
|
+
* Height of all the column headers.
|
|
74
|
+
*/
|
|
75
|
+
headersTotalHeight: number;
|
|
76
|
+
/**
|
|
77
|
+
* Size of the top container.
|
|
78
|
+
*/
|
|
79
|
+
topContainerHeight: number;
|
|
80
|
+
/**
|
|
81
|
+
* Size of the bottom container.
|
|
82
|
+
*/
|
|
83
|
+
bottomContainerHeight: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The rows total height and positions.
|
|
87
|
+
*/
|
|
88
|
+
export interface RowsMetaState {
|
|
89
|
+
/**
|
|
90
|
+
* The grid rows positions.
|
|
91
|
+
*/
|
|
92
|
+
positions: number[];
|
|
93
|
+
/**
|
|
94
|
+
* The sum of all visible grid rows in the current rows.
|
|
95
|
+
*/
|
|
96
|
+
currentPageTotalHeight: number;
|
|
97
|
+
/**
|
|
98
|
+
* The total height of the pinned top rows.
|
|
99
|
+
*/
|
|
100
|
+
pinnedTopRowsTotalHeight: number;
|
|
101
|
+
/**
|
|
102
|
+
* The total height of the pinned bottom rows.
|
|
103
|
+
*/
|
|
104
|
+
pinnedBottomRowsTotalHeight: number;
|
|
105
|
+
}
|
|
106
|
+
export interface RowVisibilityParams {
|
|
107
|
+
/**
|
|
108
|
+
* Whether this row is the first visible or not.
|
|
109
|
+
*/
|
|
110
|
+
isFirstVisible: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Whether this row is the last visible or not.
|
|
113
|
+
*/
|
|
114
|
+
isLastVisible: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Index of the row in the current page.
|
|
117
|
+
* If the pagination is disabled, it will be the index relative to all filtered rows.
|
|
118
|
+
*/
|
|
119
|
+
indexRelativeToCurrentPage: number;
|
|
120
|
+
}
|
|
121
|
+
export interface RowSpacing {
|
|
122
|
+
top?: number;
|
|
123
|
+
bottom?: number;
|
|
124
|
+
}
|
|
125
|
+
export type HeightEntry = {
|
|
126
|
+
content: number;
|
|
127
|
+
spacingTop: number;
|
|
128
|
+
spacingBottom: number;
|
|
129
|
+
detail: number;
|
|
130
|
+
autoHeight: boolean;
|
|
131
|
+
needsFirstMeasurement: boolean;
|
|
132
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RowId, RowRange } from "./core.js";
|
|
2
|
+
type ColumnIndex = number;
|
|
3
|
+
export interface RowSpanningCaches {
|
|
4
|
+
spannedCells: Record<RowId, Record<ColumnIndex, number>>;
|
|
5
|
+
hiddenCells: Record<RowId, Record<ColumnIndex, boolean>>;
|
|
6
|
+
/**
|
|
7
|
+
* For each hidden cell, it contains the row index corresponding to the cell that is
|
|
8
|
+
* the origin of the hidden cell. i.e. the cell which is spanned.
|
|
9
|
+
* Used by the virtualization to properly keep the spanned cells in view.
|
|
10
|
+
*/
|
|
11
|
+
hiddenCellOriginMap: Record<number, Record<ColumnIndex, number>>;
|
|
12
|
+
}
|
|
13
|
+
export interface RowSpanningState {
|
|
14
|
+
caches: RowSpanningCaches;
|
|
15
|
+
processedRange: RowRange;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","sideEffects":false}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { integer, RefObject } from '@mui/x-internals/types';
|
|
3
|
+
import { Store } from '@mui/x-internals/store';
|
|
4
|
+
import { Colspan } from "./features/colspan.js";
|
|
5
|
+
import { Dimensions } from "./features/dimensions.js";
|
|
6
|
+
import { Rowspan } from "./features/rowspan.js";
|
|
7
|
+
import { Virtualization } from "./features/virtualization.js";
|
|
8
|
+
import type { RowId } from "./models/core.js";
|
|
9
|
+
import type { HeightEntry, RowSpacing, RowVisibilityParams } from "./models/dimensions.js";
|
|
10
|
+
import { ColumnWithWidth, FocusedCell, Size, PinnedRows, PinnedColumns, RenderContext, Row, RowEntry } from "./models/index.js";
|
|
11
|
+
export type Virtualizer = ReturnType<typeof useVirtualizer>;
|
|
12
|
+
export type VirtualScrollerCompat = Virtualization.State['getters'];
|
|
13
|
+
export type BaseState = Virtualization.State & Dimensions.State;
|
|
14
|
+
export type VirtualizerParams = {
|
|
15
|
+
scrollbarSize?: number;
|
|
16
|
+
dimensions: {
|
|
17
|
+
rowHeight: number;
|
|
18
|
+
headerHeight: number;
|
|
19
|
+
groupHeaderHeight: number;
|
|
20
|
+
headerFilterHeight: number;
|
|
21
|
+
columnsTotalWidth: number;
|
|
22
|
+
headersTotalHeight: number;
|
|
23
|
+
leftPinnedWidth: number;
|
|
24
|
+
rightPinnedWidth: number;
|
|
25
|
+
};
|
|
26
|
+
initialState?: {
|
|
27
|
+
scroll?: {
|
|
28
|
+
top: number;
|
|
29
|
+
left: number;
|
|
30
|
+
};
|
|
31
|
+
dimensions?: Partial<Dimensions.State['dimensions']>;
|
|
32
|
+
rowSpanning?: Rowspan.State['rowSpanning'];
|
|
33
|
+
virtualization?: Partial<Virtualization.State['virtualization']>;
|
|
34
|
+
};
|
|
35
|
+
isRtl: boolean;
|
|
36
|
+
/** current page rows */
|
|
37
|
+
rows: RowEntry[];
|
|
38
|
+
/** current page range */
|
|
39
|
+
range: {
|
|
40
|
+
firstRowIndex: integer;
|
|
41
|
+
lastRowIndex: integer;
|
|
42
|
+
} | null;
|
|
43
|
+
rowIdToIndexMap: Map<RowId, number>;
|
|
44
|
+
rowCount: integer;
|
|
45
|
+
columns: ColumnWithWidth[];
|
|
46
|
+
pinnedRows: PinnedRows;
|
|
47
|
+
pinnedColumns: PinnedColumns;
|
|
48
|
+
refs: {
|
|
49
|
+
container: RefObject<HTMLDivElement | null>;
|
|
50
|
+
scroller: RefObject<HTMLDivElement | null>;
|
|
51
|
+
scrollbarVertical: RefObject<HTMLDivElement | null>;
|
|
52
|
+
scrollbarHorizontal: RefObject<HTMLDivElement | null>;
|
|
53
|
+
};
|
|
54
|
+
hasColSpan: boolean;
|
|
55
|
+
contentHeight: number;
|
|
56
|
+
minimalContentHeight: number | string;
|
|
57
|
+
autoHeight: boolean;
|
|
58
|
+
getRowHeight?: (row: RowEntry) => number | null | undefined | 'auto';
|
|
59
|
+
/**
|
|
60
|
+
* Function that returns the estimated height for a row.
|
|
61
|
+
* Only works if dynamic row height is used.
|
|
62
|
+
* Once the row height is measured this value is discarded.
|
|
63
|
+
* @param rowEntry
|
|
64
|
+
* @returns The estimated row height value. If `null` or `undefined` then the default row height, based on the density, is applied.
|
|
65
|
+
*/
|
|
66
|
+
getEstimatedRowHeight?: (rowEntry: RowEntry) => number | null;
|
|
67
|
+
/**
|
|
68
|
+
* Function that allows to specify the spacing between rows.
|
|
69
|
+
* @param rowEntry
|
|
70
|
+
* @param visibility With all properties from [[RowVisibilityParams]].
|
|
71
|
+
* @returns The row spacing values.
|
|
72
|
+
*/
|
|
73
|
+
getRowSpacing?: (rowEntry: RowEntry, visibility: RowVisibilityParams) => RowSpacing;
|
|
74
|
+
/** Update the row height values before they're used.
|
|
75
|
+
* Used to add detail panel heights.
|
|
76
|
+
* @param entry
|
|
77
|
+
* @param rowEntry
|
|
78
|
+
*/
|
|
79
|
+
applyRowHeight?: (entry: HeightEntry, rowEntry: RowEntry) => void;
|
|
80
|
+
virtualizeColumnsWithAutoRowHeight?: boolean;
|
|
81
|
+
resizeThrottleMs: number;
|
|
82
|
+
onResize?: (lastSize: Size) => void;
|
|
83
|
+
onWheel?: (event: React.WheelEvent) => void;
|
|
84
|
+
onTouchMove?: (event: React.TouchEvent) => void;
|
|
85
|
+
onRenderContextChange?: (c: RenderContext) => void;
|
|
86
|
+
onScrollChange?: (scrollPosition: {
|
|
87
|
+
top: number;
|
|
88
|
+
left: number;
|
|
89
|
+
}, nextRenderContext: RenderContext) => void;
|
|
90
|
+
focusedVirtualCell: () => FocusedCell | null;
|
|
91
|
+
rowBufferPx: number;
|
|
92
|
+
columnBufferPx: number;
|
|
93
|
+
scrollReset?: any;
|
|
94
|
+
getColspan: (rowId: RowId, column: ColumnWithWidth, columnIndex: integer) => number;
|
|
95
|
+
renderRow: (params: {
|
|
96
|
+
id: any;
|
|
97
|
+
model: Row;
|
|
98
|
+
rowIndex: number;
|
|
99
|
+
offsetLeft: number;
|
|
100
|
+
columnsTotalWidth: number;
|
|
101
|
+
baseRowHeight: number | 'auto';
|
|
102
|
+
columns: ColumnWithWidth[];
|
|
103
|
+
firstColumnIndex: number;
|
|
104
|
+
lastColumnIndex: number;
|
|
105
|
+
focusedColumnIndex: number | undefined;
|
|
106
|
+
isFirstVisible: boolean;
|
|
107
|
+
isLastVisible: boolean;
|
|
108
|
+
isVirtualFocusRow: boolean;
|
|
109
|
+
showBottomBorder: boolean;
|
|
110
|
+
}) => React.ReactElement;
|
|
111
|
+
renderInfiniteLoadingTrigger: (id: any) => React.ReactElement;
|
|
112
|
+
};
|
|
113
|
+
export declare const useVirtualizer: (params: VirtualizerParams) => {
|
|
114
|
+
store: Store<Dimensions.State & Virtualization.State & Colspan.State & Rowspan.State>;
|
|
115
|
+
api: {
|
|
116
|
+
updateDimensions: () => void;
|
|
117
|
+
debouncedUpdateDimensions: ((() => void) & import("@mui/x-internals/throttle/throttle").Cancelable) | undefined;
|
|
118
|
+
rowsMeta: {
|
|
119
|
+
getRowHeight: (rowId: RowId) => any;
|
|
120
|
+
setLastMeasuredRowIndex: (index: number) => void;
|
|
121
|
+
storeRowHeightMeasurement: (id: RowId, height: number) => void;
|
|
122
|
+
hydrateRowsMeta: () => void;
|
|
123
|
+
observeRowHeight: (element: Element, rowId: RowId) => () => void | undefined;
|
|
124
|
+
rowHasAutoHeight: (id: RowId) => any;
|
|
125
|
+
getRowHeightEntry: (rowId: RowId) => any;
|
|
126
|
+
getLastMeasuredRowIndex: () => number;
|
|
127
|
+
resetRowHeights: () => void;
|
|
128
|
+
};
|
|
129
|
+
} & {
|
|
130
|
+
getters: {
|
|
131
|
+
setPanels: React.Dispatch<React.SetStateAction<Readonly<Map<any, React.ReactNode>>>>;
|
|
132
|
+
getRows: (rowParams: {
|
|
133
|
+
rows?: RowEntry[];
|
|
134
|
+
position?: import("./models/index.js").PinnedRowPosition;
|
|
135
|
+
renderContext?: RenderContext;
|
|
136
|
+
} | undefined, unstable_rowTree: Record<RowId, any>) => React.ReactNode[];
|
|
137
|
+
getContainerProps: () => {
|
|
138
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
139
|
+
};
|
|
140
|
+
getScrollerProps: () => {
|
|
141
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
142
|
+
onScroll: () => void;
|
|
143
|
+
onWheel: ((event: React.WheelEvent) => void) | undefined;
|
|
144
|
+
onTouchMove: ((event: React.TouchEvent) => void) | undefined;
|
|
145
|
+
style: React.CSSProperties;
|
|
146
|
+
role: string;
|
|
147
|
+
tabIndex: number | undefined;
|
|
148
|
+
};
|
|
149
|
+
getContentProps: () => {
|
|
150
|
+
style: React.CSSProperties;
|
|
151
|
+
role: string;
|
|
152
|
+
ref: (node: HTMLDivElement | null) => void;
|
|
153
|
+
};
|
|
154
|
+
getRenderZoneProps: () => {
|
|
155
|
+
role: string;
|
|
156
|
+
};
|
|
157
|
+
getScrollbarVerticalProps: () => {
|
|
158
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
159
|
+
scrollPosition: React.RefObject<{
|
|
160
|
+
top: number;
|
|
161
|
+
left: number;
|
|
162
|
+
}>;
|
|
163
|
+
};
|
|
164
|
+
getScrollbarHorizontalProps: () => {
|
|
165
|
+
ref: React.RefObject<HTMLDivElement | null>;
|
|
166
|
+
scrollPosition: React.RefObject<{
|
|
167
|
+
top: number;
|
|
168
|
+
left: number;
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
getScrollAreaProps: () => {
|
|
172
|
+
scrollPosition: React.RefObject<{
|
|
173
|
+
top: number;
|
|
174
|
+
left: number;
|
|
175
|
+
}>;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
useVirtualization: () => BaseState;
|
|
179
|
+
setPanels: React.Dispatch<React.SetStateAction<Readonly<Map<any, React.ReactNode>>>>;
|
|
180
|
+
forceUpdateRenderContext: () => void;
|
|
181
|
+
getCellColSpanInfo: (rowId: RowId, columnIndex: integer) => import("./models/index.js").CellColSpanInfo;
|
|
182
|
+
calculateColSpan: (rowId: RowId, minFirstColumn: integer, maxLastColumn: integer, columns: ColumnWithWidth[]) => void;
|
|
183
|
+
getHiddenCellsOrigin: () => Record<RowId, Record<number, number>>;
|
|
184
|
+
} & {
|
|
185
|
+
resetColSpan: () => void;
|
|
186
|
+
getCellColSpanInfo: (rowId: RowId, columnIndex: integer) => import("./models/index.js").CellColSpanInfo | undefined;
|
|
187
|
+
calculateColSpan: (rowId: RowId, minFirstColumn: integer, maxLastColumn: integer, columns: ColumnWithWidth[]) => void;
|
|
188
|
+
} & {
|
|
189
|
+
getHiddenCellsOrigin: () => Record<number, Record<number, number>>;
|
|
190
|
+
} & {
|
|
191
|
+
getViewportPageSize: () => number;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import useLazyRef from '@mui/utils/useLazyRef';
|
|
2
|
+
import { Store } from '@mui/x-internals/store';
|
|
3
|
+
import { Colspan } from "./features/colspan.js";
|
|
4
|
+
import { Dimensions } from "./features/dimensions.js";
|
|
5
|
+
import { Keyboard } from "./features/keyboard.js";
|
|
6
|
+
import { Rowspan } from "./features/rowspan.js";
|
|
7
|
+
import { Virtualization } from "./features/virtualization.js";
|
|
8
|
+
|
|
9
|
+
/* eslint-disable jsdoc/require-param-type */
|
|
10
|
+
/* eslint-disable jsdoc/require-param-description */
|
|
11
|
+
/* eslint-disable jsdoc/require-returns-type */
|
|
12
|
+
|
|
13
|
+
const FEATURES = [Dimensions, Virtualization, Colspan, Rowspan, Keyboard];
|
|
14
|
+
export const useVirtualizer = params => {
|
|
15
|
+
const store = useLazyRef(() => {
|
|
16
|
+
return new Store(FEATURES.map(f => f.initialize(params)).reduce((state, partial) => Object.assign(state, partial), {}));
|
|
17
|
+
}).current;
|
|
18
|
+
const api = {};
|
|
19
|
+
for (const feature of FEATURES) {
|
|
20
|
+
Object.assign(api, feature.use(store, params, api));
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
store,
|
|
24
|
+
api
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Store } from '@mui/x-internals/store';
|
|
2
|
+
import type { integer } from '@mui/x-internals/types';
|
|
3
|
+
import type { BaseState, VirtualizerParams } from "../useVirtualizer.js";
|
|
4
|
+
import type { ColumnWithWidth, RowId } from "../models/index.js";
|
|
5
|
+
import type { CellColSpanInfo } from "../models/colspan.js";
|
|
6
|
+
import { Virtualization } from "./virtualization.js";
|
|
7
|
+
type ColumnIndex = number;
|
|
8
|
+
type ColspanMap = Map<RowId, Record<ColumnIndex, CellColSpanInfo>>;
|
|
9
|
+
export declare const Colspan: {
|
|
10
|
+
initialize: typeof initializeState;
|
|
11
|
+
use: typeof useColspan;
|
|
12
|
+
selectors: {};
|
|
13
|
+
};
|
|
14
|
+
export declare namespace Colspan {
|
|
15
|
+
type State = {
|
|
16
|
+
colspanMap: ColspanMap;
|
|
17
|
+
};
|
|
18
|
+
type API = ReturnType<typeof useColspan>;
|
|
19
|
+
}
|
|
20
|
+
declare function initializeState(_params: VirtualizerParams): {
|
|
21
|
+
colspanMap: Map<any, any>;
|
|
22
|
+
};
|
|
23
|
+
declare function useColspan(store: Store<BaseState & Colspan.State>, params: VirtualizerParams, api: Virtualization.API): {
|
|
24
|
+
resetColSpan: () => void;
|
|
25
|
+
getCellColSpanInfo: (rowId: RowId, columnIndex: integer) => CellColSpanInfo | undefined;
|
|
26
|
+
calculateColSpan: (rowId: RowId, minFirstColumn: integer, maxLastColumn: integer, columns: ColumnWithWidth[]) => void;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Colspan = void 0;
|
|
8
|
+
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
9
|
+
/* eslint-disable import/export, @typescript-eslint/no-redeclare */
|
|
10
|
+
|
|
11
|
+
const selectors = {};
|
|
12
|
+
const Colspan = exports.Colspan = {
|
|
13
|
+
initialize: initializeState,
|
|
14
|
+
use: useColspan,
|
|
15
|
+
selectors
|
|
16
|
+
};
|
|
17
|
+
function initializeState(_params) {
|
|
18
|
+
return {
|
|
19
|
+
colspanMap: new Map()
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function useColspan(store, params, api) {
|
|
23
|
+
const resetColSpan = () => {
|
|
24
|
+
store.state.colspanMap = new Map();
|
|
25
|
+
};
|
|
26
|
+
const getCellColSpanInfo = (rowId, columnIndex) => {
|
|
27
|
+
return store.state.colspanMap.get(rowId)?.[columnIndex];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Calculate `colSpan` for each cell in the row
|
|
31
|
+
const calculateColSpan = (0, _useEventCallback.default)((rowId, minFirstColumn, maxLastColumn, columns) => {
|
|
32
|
+
for (let i = minFirstColumn; i < maxLastColumn; i += 1) {
|
|
33
|
+
const cellProps = calculateCellColSpan(store.state.colspanMap, i, rowId, minFirstColumn, maxLastColumn, columns, params.getColspan);
|
|
34
|
+
if (cellProps.colSpan > 1) {
|
|
35
|
+
i += cellProps.colSpan - 1;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
api.calculateColSpan = calculateColSpan;
|
|
40
|
+
return {
|
|
41
|
+
resetColSpan,
|
|
42
|
+
getCellColSpanInfo,
|
|
43
|
+
calculateColSpan
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function calculateCellColSpan(lookup, columnIndex, rowId, minFirstColumnIndex, maxLastColumnIndex, columns, getColspan) {
|
|
47
|
+
const columnsLength = columns.length;
|
|
48
|
+
const column = columns[columnIndex];
|
|
49
|
+
const colSpan = getColspan(rowId, column, columnIndex);
|
|
50
|
+
if (!colSpan || colSpan === 1) {
|
|
51
|
+
setCellColSpanInfo(lookup, rowId, columnIndex, {
|
|
52
|
+
spannedByColSpan: false,
|
|
53
|
+
cellProps: {
|
|
54
|
+
colSpan: 1,
|
|
55
|
+
width: column.computedWidth
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
colSpan: 1
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
let width = column.computedWidth;
|
|
63
|
+
for (let j = 1; j < colSpan; j += 1) {
|
|
64
|
+
const nextColumnIndex = columnIndex + j;
|
|
65
|
+
// Cells should be spanned only within their column section (left-pinned, right-pinned and unpinned).
|
|
66
|
+
if (nextColumnIndex >= minFirstColumnIndex && nextColumnIndex < maxLastColumnIndex) {
|
|
67
|
+
const nextColumn = columns[nextColumnIndex];
|
|
68
|
+
width += nextColumn.computedWidth;
|
|
69
|
+
setCellColSpanInfo(lookup, rowId, columnIndex + j, {
|
|
70
|
+
spannedByColSpan: true,
|
|
71
|
+
rightVisibleCellIndex: Math.min(columnIndex + colSpan, columnsLength - 1),
|
|
72
|
+
leftVisibleCellIndex: columnIndex
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
setCellColSpanInfo(lookup, rowId, columnIndex, {
|
|
76
|
+
spannedByColSpan: false,
|
|
77
|
+
cellProps: {
|
|
78
|
+
colSpan,
|
|
79
|
+
width
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
colSpan
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function setCellColSpanInfo(colspanMap, rowId, columnIndex, cellColSpanInfo) {
|
|
88
|
+
let columnInfo = colspanMap.get(rowId);
|
|
89
|
+
if (!columnInfo) {
|
|
90
|
+
columnInfo = {};
|
|
91
|
+
colspanMap.set(rowId, columnInfo);
|
|
92
|
+
}
|
|
93
|
+
columnInfo[columnIndex] = cellColSpanInfo;
|
|
94
|
+
}
|