@fluentui/react-virtualizer 9.0.0-alpha.17 → 9.0.0-alpha.19
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.json +69 -1
- package/CHANGELOG.md +25 -2
- package/dist/index.d.ts +93 -10
- package/lib/Utilities.js +2 -0
- package/lib/Utilities.js.map +1 -0
- package/lib/VirtualizerScrollViewDynamic.js +2 -0
- package/lib/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib/components/Virtualizer/renderVirtualizer.js +11 -4
- package/lib/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib/components/Virtualizer/useVirtualizer.js +35 -32
- package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js +4 -4
- package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -1
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js +2 -1
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js.map +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +14 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +2 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/index.js +6 -0
- package/lib/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +11 -0
- package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +44 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js +46 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js.map +1 -0
- package/lib/hooks/hooks.types.js +2 -0
- package/lib/hooks/hooks.types.js.map +1 -0
- package/lib/hooks/index.js +3 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useDynamicVirtualizerMeasure.js +99 -0
- package/lib/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
- package/lib/hooks/useResizeObserverRef.js +40 -0
- package/lib/hooks/useResizeObserverRef.js.map +1 -0
- package/lib/hooks/useVirtualizerMeasure.js +6 -29
- package/lib/hooks/useVirtualizerMeasure.js.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/utilities/VirtualizerContext/VirtualizerContext.js +27 -0
- package/lib/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
- package/lib/utilities/VirtualizerContext/index.js +3 -0
- package/lib/utilities/VirtualizerContext/index.js.map +1 -0
- package/lib/utilities/VirtualizerContext/types.js +4 -0
- package/lib/utilities/VirtualizerContext/types.js.map +1 -0
- package/lib/utilities/index.js +2 -0
- package/lib/utilities/index.js.map +1 -0
- package/lib-commonjs/Utilities.js +9 -0
- package/lib-commonjs/Utilities.js.map +1 -0
- package/lib-commonjs/VirtualizerScrollViewDynamic.js +9 -0
- package/lib-commonjs/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js +19 -6
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js +35 -30
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js +4 -5
- package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js +2 -1
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +21 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +7 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js +13 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +17 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +49 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js +69 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js.map +1 -0
- package/lib-commonjs/hooks/hooks.types.js +7 -0
- package/lib-commonjs/hooks/hooks.types.js.map +1 -0
- package/lib-commonjs/hooks/index.js +3 -0
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js +107 -0
- package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
- package/lib-commonjs/hooks/useResizeObserverRef.js +51 -0
- package/lib-commonjs/hooks/useResizeObserverRef.js.map +1 -0
- package/lib-commonjs/hooks/useVirtualizerMeasure.js +7 -29
- package/lib-commonjs/hooks/useVirtualizerMeasure.js.map +1 -1
- package/lib-commonjs/index.js +12 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js +48 -0
- package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
- package/lib-commonjs/utilities/VirtualizerContext/index.js +10 -0
- package/lib-commonjs/utilities/VirtualizerContext/index.js.map +1 -0
- package/lib-commonjs/utilities/VirtualizerContext/types.js +9 -0
- package/lib-commonjs/utilities/VirtualizerContext/types.js.map +1 -0
- package/lib-commonjs/utilities/index.js +9 -0
- package/lib-commonjs/utilities/index.js.map +1 -0
- package/package.json +4 -3
- package/.swcrc +0 -30
- package/lib/hooks/useVirtualizerMeasure.types.js +0 -2
- package/lib/hooks/useVirtualizerMeasure.types.js.map +0 -1
- package/lib-commonjs/hooks/useVirtualizerMeasure.types.js +0 -7
- package/lib-commonjs/hooks/useVirtualizerMeasure.types.js.map +0 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,75 @@
|
|
|
2
2
|
"name": "@fluentui/react-virtualizer",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Fri, 12 May 2023 20:22:35 GMT",
|
|
6
|
+
"tag": "@fluentui/react-virtualizer_v9.0.0-alpha.19",
|
|
7
|
+
"version": "9.0.0-alpha.19",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"author": "martinhochel@microsoft.com",
|
|
12
|
+
"package": "@fluentui/react-virtualizer",
|
|
13
|
+
"commit": "dbda7fa69e3000aaf8dd4a061e254ebd35198b8e",
|
|
14
|
+
"comment": "fix: update npmignore files to fix npm8/node16 regression how npm publish works"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"prerelease": [
|
|
18
|
+
{
|
|
19
|
+
"author": "olfedias@microsoft.com",
|
|
20
|
+
"package": "@fluentui/react-virtualizer",
|
|
21
|
+
"commit": "c28decb23d191a0daaaf6d5d1832429715102129",
|
|
22
|
+
"comment": "chore: exclude .swcrc from being published"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"author": "mifraser@microsoft.com",
|
|
26
|
+
"package": "@fluentui/react-virtualizer",
|
|
27
|
+
"commit": "0ffdc48b94a76bfd209015b1a9c49eb62aca1ba0",
|
|
28
|
+
"comment": "feature: Add dynamically sized virtualizer scroll view"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"author": "beachball",
|
|
32
|
+
"package": "@fluentui/react-virtualizer",
|
|
33
|
+
"comment": "Bump @fluentui/react-jsx-runtime to v9.0.0-alpha.3",
|
|
34
|
+
"commit": "79c08ce5bbf6387b2b18ba4c3d2d5681e0177d4b"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"author": "beachball",
|
|
38
|
+
"package": "@fluentui/react-virtualizer",
|
|
39
|
+
"comment": "Bump @fluentui/react-utilities to v9.8.1",
|
|
40
|
+
"commit": "79c08ce5bbf6387b2b18ba4c3d2d5681e0177d4b"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"author": "beachball",
|
|
44
|
+
"package": "@fluentui/react-virtualizer",
|
|
45
|
+
"comment": "Bump @fluentui/react-conformance-griffel to v9.0.0-beta.21",
|
|
46
|
+
"commit": "79c08ce5bbf6387b2b18ba4c3d2d5681e0177d4b"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"date": "Mon, 24 Apr 2023 08:12:46 GMT",
|
|
53
|
+
"tag": "@fluentui/react-virtualizer_v9.0.0-alpha.18",
|
|
54
|
+
"version": "9.0.0-alpha.18",
|
|
55
|
+
"comments": {
|
|
56
|
+
"prerelease": [
|
|
57
|
+
{
|
|
58
|
+
"author": "bernardo.sunderhus@gmail.com",
|
|
59
|
+
"package": "@fluentui/react-virtualizer",
|
|
60
|
+
"commit": "142c07abdeedea8f6b2e0cc15acf02795ce7f0fc",
|
|
61
|
+
"comment": "chore: adopt custom JSX pragma"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"author": "beachball",
|
|
65
|
+
"package": "@fluentui/react-virtualizer",
|
|
66
|
+
"comment": "Bump @fluentui/react-jsx-runtime to v9.0.0-alpha.2",
|
|
67
|
+
"commit": "505433ac64f144c9cca456097413d6af4582e5ee"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"date": "Mon, 17 Apr 2023 17:54:02 GMT",
|
|
6
74
|
"tag": "@fluentui/react-virtualizer_v9.0.0-alpha.17",
|
|
7
75
|
"version": "9.0.0-alpha.17",
|
|
8
76
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-virtualizer
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 12 May 2023 20:22:35 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.0.0-alpha.19](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.19)
|
|
8
|
+
|
|
9
|
+
Fri, 12 May 2023 20:22:35 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.18..@fluentui/react-virtualizer_v9.0.0-alpha.19)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
- chore: exclude .swcrc from being published ([PR #27740](https://github.com/microsoft/fluentui/pull/27740) by olfedias@microsoft.com)
|
|
15
|
+
- feature: Add dynamically sized virtualizer scroll view ([PR #27298](https://github.com/microsoft/fluentui/pull/27298) by mifraser@microsoft.com)
|
|
16
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.0-alpha.3 ([PR #27827](https://github.com/microsoft/fluentui/pull/27827) by beachball)
|
|
17
|
+
- Bump @fluentui/react-utilities to v9.8.1 ([PR #27827](https://github.com/microsoft/fluentui/pull/27827) by beachball)
|
|
18
|
+
- Bump @fluentui/react-conformance-griffel to v9.0.0-beta.21 ([PR #27827](https://github.com/microsoft/fluentui/pull/27827) by beachball)
|
|
19
|
+
|
|
20
|
+
## [9.0.0-alpha.18](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.18)
|
|
21
|
+
|
|
22
|
+
Mon, 24 Apr 2023 08:12:46 GMT
|
|
23
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.17..@fluentui/react-virtualizer_v9.0.0-alpha.18)
|
|
24
|
+
|
|
25
|
+
### Changes
|
|
26
|
+
|
|
27
|
+
- chore: adopt custom JSX pragma ([PR #27629](https://github.com/microsoft/fluentui/pull/27629) by bernardo.sunderhus@gmail.com)
|
|
28
|
+
- Bump @fluentui/react-jsx-runtime to v9.0.0-alpha.2 ([commit](https://github.com/microsoft/fluentui/commit/505433ac64f144c9cca456097413d6af4582e5ee) by beachball)
|
|
29
|
+
|
|
7
30
|
## [9.0.0-alpha.17](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.17)
|
|
8
31
|
|
|
9
|
-
Mon, 17 Apr 2023 17:
|
|
32
|
+
Mon, 17 Apr 2023 17:54:02 GMT
|
|
10
33
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.16..@fluentui/react-virtualizer_v9.0.0-alpha.17)
|
|
11
34
|
|
|
12
35
|
### Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ComponentProps } from '@fluentui/react-utilities';
|
|
|
2
2
|
import { ComponentState } from '@fluentui/react-utilities';
|
|
3
3
|
import type { Dispatch } from 'react';
|
|
4
4
|
import type { FC } from 'react';
|
|
5
|
-
import
|
|
5
|
+
import { MutableRefObject } from 'react';
|
|
6
6
|
import * as React_2 from 'react';
|
|
7
7
|
import type { SetStateAction } from 'react';
|
|
8
8
|
import { Slot } from '@fluentui/react-utilities';
|
|
@@ -12,6 +12,26 @@ export declare const renderVirtualizer_unstable: (state: VirtualizerState) => JS
|
|
|
12
12
|
|
|
13
13
|
export declare const renderVirtualizerScrollView_unstable: (state: VirtualizerScrollViewState) => JSX.Element;
|
|
14
14
|
|
|
15
|
+
export declare const renderVirtualizerScrollViewDynamic_unstable: (state: VirtualizerScrollViewDynamicState) => JSX.Element;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Additional direct Ref prevents reading old resize entry data
|
|
19
|
+
* Backwards compatible with ResizeObserverCallback if preferred
|
|
20
|
+
*/
|
|
21
|
+
export declare interface ResizeCallbackWithRef {
|
|
22
|
+
(entries: ResizeObserverEntry[], observer: ResizeObserver, scrollRef?: MutableRefObject<HTMLElement | null>): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* React hook that measures virtualized space dynamically to ensure optimized virtualization length.
|
|
27
|
+
*/
|
|
28
|
+
export declare const useDynamicVirtualizerMeasure: <TElement extends HTMLElement>(virtualizerProps: VirtualizerMeasureDynamicProps) => {
|
|
29
|
+
virtualizerLength: number;
|
|
30
|
+
bufferItems: number;
|
|
31
|
+
bufferSize: number;
|
|
32
|
+
scrollRef: (instance: TElement | null) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
15
35
|
/**
|
|
16
36
|
* React hook that allows easy usage of the browser API IntersectionObserver within React
|
|
17
37
|
* @param callback - A function called when the percentage of the target element is visible crosses a threshold.
|
|
@@ -27,20 +47,34 @@ export declare const useIntersectionObserver: (callback: IntersectionObserverCal
|
|
|
27
47
|
observer: MutableRefObject<IntersectionObserver | undefined>;
|
|
28
48
|
};
|
|
29
49
|
|
|
50
|
+
/**
|
|
51
|
+
* useResizeObserverRef_unstable simplifies resize observer connection and ensures debounce/cleanup
|
|
52
|
+
*/
|
|
53
|
+
export declare const useResizeObserverRef_unstable: (resizeCallback: ResizeCallbackWithRef) => (instance: HTMLElement | HTMLDivElement | null) => void;
|
|
54
|
+
|
|
30
55
|
/**
|
|
31
56
|
* React hook that measures virtualized space based on a static size to ensure optimized virtualization length.
|
|
32
57
|
*/
|
|
33
|
-
export declare const useStaticVirtualizerMeasure: (virtualizerProps: VirtualizerMeasureProps) => {
|
|
58
|
+
export declare const useStaticVirtualizerMeasure: <TElement extends HTMLElement>(virtualizerProps: VirtualizerMeasureProps) => {
|
|
34
59
|
virtualizerLength: number;
|
|
35
60
|
bufferItems: number;
|
|
36
61
|
bufferSize: number;
|
|
37
|
-
scrollRef: (instance:
|
|
62
|
+
scrollRef: (instance: TElement | null) => void;
|
|
38
63
|
};
|
|
39
64
|
|
|
40
65
|
export declare function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerState;
|
|
41
66
|
|
|
67
|
+
export declare const useVirtualizerContext_unstable: () => VirtualizerContextProps;
|
|
68
|
+
|
|
42
69
|
export declare function useVirtualizerScrollView_unstable(props: VirtualizerScrollViewProps): VirtualizerScrollViewState;
|
|
43
70
|
|
|
71
|
+
export declare function useVirtualizerScrollViewDynamic_unstable(props: VirtualizerScrollViewDynamicProps): VirtualizerScrollViewDynamicState;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Apply styling to the Virtualizer states
|
|
75
|
+
*/
|
|
76
|
+
export declare const useVirtualizerScrollViewDynamicStyles_unstable: (state: VirtualizerScrollViewDynamicState) => VirtualizerScrollViewDynamicState;
|
|
77
|
+
|
|
44
78
|
/**
|
|
45
79
|
* Apply styling to the Virtualizer states
|
|
46
80
|
*/
|
|
@@ -124,13 +158,9 @@ declare type VirtualizerConfigProps = {
|
|
|
124
158
|
*/
|
|
125
159
|
getItemSize?: (index: number) => number;
|
|
126
160
|
/**
|
|
127
|
-
*
|
|
128
|
-
*/
|
|
129
|
-
onUpdateIndex?: (index: number, prevIndex: number) => void;
|
|
130
|
-
/**
|
|
131
|
-
* Allow users to intervene in index calculation changes
|
|
161
|
+
* Virtualizer context can be passed as a prop for extended class use
|
|
132
162
|
*/
|
|
133
|
-
|
|
163
|
+
virtualizerContext?: VirtualizerContextProps;
|
|
134
164
|
};
|
|
135
165
|
|
|
136
166
|
declare type VirtualizerConfigState = {
|
|
@@ -170,7 +200,25 @@ declare type VirtualizerConfigState = {
|
|
|
170
200
|
bufferSize: number;
|
|
171
201
|
};
|
|
172
202
|
|
|
173
|
-
|
|
203
|
+
/**
|
|
204
|
+
* {@docCategory Virtualizer}
|
|
205
|
+
*/
|
|
206
|
+
export declare type VirtualizerContextProps = {
|
|
207
|
+
contextIndex: number;
|
|
208
|
+
setContextIndex: (index: number) => void;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export declare const VirtualizerContextProvider: React_2.Provider<VirtualizerContextProps>;
|
|
212
|
+
|
|
213
|
+
export declare type VirtualizerMeasureDynamicProps = {
|
|
214
|
+
defaultItemSize: number;
|
|
215
|
+
currentIndex: number;
|
|
216
|
+
numItems: number;
|
|
217
|
+
getItemSize: (index: number) => number;
|
|
218
|
+
direction?: 'vertical' | 'horizontal';
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
export declare type VirtualizerMeasureProps = {
|
|
174
222
|
defaultItemSize: number;
|
|
175
223
|
direction?: 'vertical' | 'horizontal';
|
|
176
224
|
};
|
|
@@ -184,6 +232,41 @@ export declare const VirtualizerScrollView: React_2.FC<VirtualizerScrollViewProp
|
|
|
184
232
|
|
|
185
233
|
export declare const virtualizerScrollViewClassNames: SlotClassNames<VirtualizerScrollViewSlots>;
|
|
186
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Virtualizer ScrollView
|
|
237
|
+
*/
|
|
238
|
+
export declare const VirtualizerScrollViewDynamic: React_2.FC<VirtualizerScrollViewDynamicProps>;
|
|
239
|
+
|
|
240
|
+
export declare const virtualizerScrollViewDynamicClassNames: SlotClassNames<VirtualizerScrollViewDynamicSlots>;
|
|
241
|
+
|
|
242
|
+
export declare type VirtualizerScrollViewDynamicProps = ComponentProps<Partial<VirtualizerScrollViewDynamicSlots>> & Partial<Omit<VirtualizerConfigProps, 'itemSize' | 'numItems' | 'getItemSize' | 'children'>> & {
|
|
243
|
+
/**
|
|
244
|
+
* Set as the minimum item size.
|
|
245
|
+
* Axis: 'vertical' = Height
|
|
246
|
+
* Axis: 'horizontal' = Width
|
|
247
|
+
*/
|
|
248
|
+
itemSize: number;
|
|
249
|
+
/**
|
|
250
|
+
* Callback for acquiring size of individual items
|
|
251
|
+
* @param index - the index of the requested size's child
|
|
252
|
+
*/
|
|
253
|
+
getItemSize: (index: number) => number;
|
|
254
|
+
/**
|
|
255
|
+
* The total number of items to be virtualized.
|
|
256
|
+
*/
|
|
257
|
+
numItems: number;
|
|
258
|
+
/**
|
|
259
|
+
* Child render function.
|
|
260
|
+
* Iteratively called to return current virtualizer DOM children.
|
|
261
|
+
* Will act as a row or column indexer depending on Virtualizer settings.
|
|
262
|
+
*/
|
|
263
|
+
children: VirtualizerChildRenderFunction;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export declare type VirtualizerScrollViewDynamicSlots = VirtualizerScrollViewSlots;
|
|
267
|
+
|
|
268
|
+
export declare type VirtualizerScrollViewDynamicState = ComponentState<VirtualizerScrollViewDynamicSlots> & VirtualizerConfigState;
|
|
269
|
+
|
|
187
270
|
export declare type VirtualizerScrollViewProps = ComponentProps<Partial<VirtualizerScrollViewSlots>> & Partial<Omit<VirtualizerConfigProps, 'itemSize' | 'numItems' | 'getItemSize' | 'children'>> & {
|
|
188
271
|
/**
|
|
189
272
|
* Virtualizer item size in pixels - static.
|
package/lib/Utilities.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../src/Utilities.ts"],"sourcesContent":["export * from './utilities/index';\n"],"mappings":"AAAA,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../src/VirtualizerScrollViewDynamic.ts"],"sourcesContent":["export * from './components/VirtualizerScrollViewDynamic/index';\n"],"mappings":"AAAA,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React"],"sources":["../../../src/components/Virtualizer/Virtualizer.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\n\nexport type VirtualizerSlots = {\n /**\n * The intersection observed 'before' element will detect when scrolling towards the beginning.\n */\n before: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace at the beginning of current DOM children.\n */\n beforeContainer: NonNullable<Slot<'div', 'tr'>>;\n /**\n * The intersection observed 'after' element will detect when scrolling towards the end.\n */\n after: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace after the end of current DOM children.\n */\n afterContainer: NonNullable<Slot<'div', 'tr'>>;\n};\n\nexport type VirtualizerConfigState = {\n /**\n * The current virtualized array of children to show in the DOM.\n */\n virtualizedChildren: React.ReactNode[];\n /**\n * The current start index for the virtualizer, all previous index's will be removed from DOM.\n */\n virtualizerStartIndex: number;\n /**\n * Current buffer height required at beginning of array.\n */\n afterBufferHeight: number;\n /**\n * Current buffer height required at end of array.\n */\n beforeBufferHeight: number;\n /**\n * The total current height of the scrollView/child content.\n */\n totalVirtualizerHeight: number;\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n */\n reversed?: boolean;\n /**\n * Pixel size of intersection observers and how much they 'cross over' into the bufferItems index.\n * Minimum 1px.\n */\n bufferSize: number;\n};\n\nexport type VirtualizerState = ComponentState<VirtualizerSlots> & VirtualizerConfigState;\n\n// Virtualizer render function to procedurally generate children elements as rows or columns via index.\n// Q: Use generic typing and passing through object data or a simple index system?\nexport type VirtualizerChildRenderFunction = (index: number) => React.ReactNode;\n\nexport type VirtualizerConfigProps = {\n /**\n * Child render function.\n * Iteratively called to return current virtualizer DOM children.\n * Will act as a row or column indexer depending on Virtualizer settings.\n * Can be used dynamically.\n */\n children: VirtualizerChildRenderFunction;\n\n /**\n * Default cell size to use if no custom callback provided.\n * If implementing `getItemSize` this should be the initial and ideally minimum cell size.\n */\n itemSize: number;\n\n /**\n * The total number of items to be virtualized.\n */\n numItems: number;\n\n /**\n * Number of children to render in the DOM during virtualization.\n * Constraints:\n * - Large enough that the items rendered in DOM cover the viewport\n * and intersection observer buffers (buffersize) at both ends.\n */\n virtualizerLength: number;\n\n /**\n * Defaults to 1/4th of virtualizerLength.\n * Controls the number of elements rendered before the current index entering the virtualized viewport.\n * Constraints:\n * - Large enough to cover bufferSize (prevents buffers intersecting into the viewport during rest state).\n * - Small enough that the end buffer and end index (start index + virtualizerLength) is not within viewport at rest.\n */\n bufferItems?: number;\n\n /**\n * Defaults to half of bufferItems size (in pixels).\n * The length (in pixels) before the end/start DOM index where the virtualizer recalculation will be triggered.\n * Increasing this reduces whitespace on ultra-fast scroll, as additional elements\n * are buffered to appear while virtualization recalculates.\n * Constraints:\n * - At least 1px - although this will only trigger the recalculation after bookends (whitespace) enter viewport.\n * - BufferSize must be smaller than bufferItems pixel size, as it prevents bookends entering viewport at rest.\n */\n bufferSize?: number;\n\n /**\n * Enables users to override the intersectionObserverRoot.\n */\n scrollViewRef?: React.MutableRefObject<HTMLElement | null>;\n\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n * This value should be flipped in RTL implementation (TBD whether automate RTL).\n */\n reversed?: boolean;\n\n /**\n * Callback for acquiring size of individual items\n * @param index - the index of the requested size's child\n */\n getItemSize?: (index: number) => number;\n\n /**\n *
|
|
1
|
+
{"version":3,"names":["React"],"sources":["../../../src/components/Virtualizer/Virtualizer.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { VirtualizerContextProps } from '../../Utilities';\n\nexport type VirtualizerSlots = {\n /**\n * The intersection observed 'before' element will detect when scrolling towards the beginning.\n */\n before: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace at the beginning of current DOM children.\n */\n beforeContainer: NonNullable<Slot<'div', 'tr'>>;\n /**\n * The intersection observed 'after' element will detect when scrolling towards the end.\n */\n after: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace after the end of current DOM children.\n */\n afterContainer: NonNullable<Slot<'div', 'tr'>>;\n};\n\nexport type VirtualizerConfigState = {\n /**\n * The current virtualized array of children to show in the DOM.\n */\n virtualizedChildren: React.ReactNode[];\n /**\n * The current start index for the virtualizer, all previous index's will be removed from DOM.\n */\n virtualizerStartIndex: number;\n /**\n * Current buffer height required at beginning of array.\n */\n afterBufferHeight: number;\n /**\n * Current buffer height required at end of array.\n */\n beforeBufferHeight: number;\n /**\n * The total current height of the scrollView/child content.\n */\n totalVirtualizerHeight: number;\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n */\n reversed?: boolean;\n /**\n * Pixel size of intersection observers and how much they 'cross over' into the bufferItems index.\n * Minimum 1px.\n */\n bufferSize: number;\n};\n\nexport type VirtualizerState = ComponentState<VirtualizerSlots> & VirtualizerConfigState;\n\n// Virtualizer render function to procedurally generate children elements as rows or columns via index.\n// Q: Use generic typing and passing through object data or a simple index system?\nexport type VirtualizerChildRenderFunction = (index: number) => React.ReactNode;\n\nexport type VirtualizerConfigProps = {\n /**\n * Child render function.\n * Iteratively called to return current virtualizer DOM children.\n * Will act as a row or column indexer depending on Virtualizer settings.\n * Can be used dynamically.\n */\n children: VirtualizerChildRenderFunction;\n\n /**\n * Default cell size to use if no custom callback provided.\n * If implementing `getItemSize` this should be the initial and ideally minimum cell size.\n */\n itemSize: number;\n\n /**\n * The total number of items to be virtualized.\n */\n numItems: number;\n\n /**\n * Number of children to render in the DOM during virtualization.\n * Constraints:\n * - Large enough that the items rendered in DOM cover the viewport\n * and intersection observer buffers (buffersize) at both ends.\n */\n virtualizerLength: number;\n\n /**\n * Defaults to 1/4th of virtualizerLength.\n * Controls the number of elements rendered before the current index entering the virtualized viewport.\n * Constraints:\n * - Large enough to cover bufferSize (prevents buffers intersecting into the viewport during rest state).\n * - Small enough that the end buffer and end index (start index + virtualizerLength) is not within viewport at rest.\n */\n bufferItems?: number;\n\n /**\n * Defaults to half of bufferItems size (in pixels).\n * The length (in pixels) before the end/start DOM index where the virtualizer recalculation will be triggered.\n * Increasing this reduces whitespace on ultra-fast scroll, as additional elements\n * are buffered to appear while virtualization recalculates.\n * Constraints:\n * - At least 1px - although this will only trigger the recalculation after bookends (whitespace) enter viewport.\n * - BufferSize must be smaller than bufferItems pixel size, as it prevents bookends entering viewport at rest.\n */\n bufferSize?: number;\n\n /**\n * Enables users to override the intersectionObserverRoot.\n */\n scrollViewRef?: React.MutableRefObject<HTMLElement | null>;\n\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n * This value should be flipped in RTL implementation (TBD whether automate RTL).\n */\n reversed?: boolean;\n\n /**\n * Callback for acquiring size of individual items\n * @param index - the index of the requested size's child\n */\n getItemSize?: (index: number) => number;\n\n /**\n * Virtualizer context can be passed as a prop for extended class use\n */\n virtualizerContext?: VirtualizerContextProps;\n};\n\nexport type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>> & VirtualizerConfigProps;\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
1
|
+
/** @jsxRuntime classic */ /** @jsx createElement */import * as React from 'react';
|
|
2
|
+
import { createElement } from '@fluentui/react-jsx-runtime';
|
|
3
|
+
import { getSlotsNext } from '@fluentui/react-utilities';
|
|
3
4
|
export const renderVirtualizer_unstable = state => {
|
|
4
5
|
const {
|
|
5
6
|
slots,
|
|
6
7
|
slotProps
|
|
7
|
-
} =
|
|
8
|
-
return /*#__PURE__*/
|
|
8
|
+
} = getSlotsNext(state);
|
|
9
|
+
return /*#__PURE__*/createElement(React.Fragment, null, /*#__PURE__*/createElement(slots.beforeContainer, slotProps.beforeContainer, /*#__PURE__*/createElement(slots.before, slotProps.before)), state.virtualizedChildren, /*#__PURE__*/createElement(slots.afterContainer, slotProps.afterContainer, /*#__PURE__*/createElement(slots.after, slotProps.after)));
|
|
10
|
+
};
|
|
11
|
+
export const renderVirtualizerChildPlaceholder = (child, index) => {
|
|
12
|
+
return /*#__PURE__*/createElement(React.Suspense, {
|
|
13
|
+
key: `fui-virtualizer-placeholder-${index}`,
|
|
14
|
+
fallback: null
|
|
15
|
+
}, child);
|
|
9
16
|
};
|
|
10
17
|
//# sourceMappingURL=renderVirtualizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","
|
|
1
|
+
{"version":3,"names":["React","createElement","getSlotsNext","renderVirtualizer_unstable","state","slots","slotProps","Fragment","beforeContainer","before","virtualizedChildren","afterContainer","after","renderVirtualizerChildPlaceholder","child","index","Suspense","key","fallback"],"sources":["../../../src/components/Virtualizer/renderVirtualizer.tsx"],"sourcesContent":["/** @jsxRuntime classic */\n/** @jsx createElement */\n\nimport * as React from 'react';\nimport { createElement } from '@fluentui/react-jsx-runtime';\nimport { getSlotsNext } from '@fluentui/react-utilities';\nimport { VirtualizerSlots, VirtualizerState } from './Virtualizer.types';\nimport { ReactNode } from 'react';\n\nexport const renderVirtualizer_unstable = (state: VirtualizerState) => {\n const { slots, slotProps } = getSlotsNext<VirtualizerSlots>(state);\n\n return (\n <React.Fragment>\n {/* The 'before' bookend to hold items in place and detect scroll previous */}\n <slots.beforeContainer {...slotProps.beforeContainer}>\n <slots.before {...slotProps.before} />\n </slots.beforeContainer>\n {/* The reduced list of non-virtualized children to be rendered */}\n {state.virtualizedChildren}\n {/* The 'after' bookend to hold items in place and detect scroll next */}\n <slots.afterContainer {...slotProps.afterContainer}>\n <slots.after {...slotProps.after} />\n </slots.afterContainer>\n </React.Fragment>\n );\n};\n\nexport const renderVirtualizerChildPlaceholder = (child: ReactNode, index: number) => {\n return (\n <React.Suspense key={`fui-virtualizer-placeholder-${index}`} fallback={null}>\n {child}\n </React.Suspense>\n );\n};\n"],"mappings":"AAAA,2BACA,yBAEA,YAAYA,KAAA,MAAW;AACvB,SAASC,aAAa,QAAQ;AAC9B,SAASC,YAAY,QAAQ;AAI7B,OAAO,MAAMC,0BAAA,GAA8BC,KAAA,IAA4B;EACrE,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGJ,YAAA,CAA+BE,KAAA;EAE5D,oBACEH,aAZJ,CAYKD,KAAA,CAAMO,QAAQ,qBAEbN,aAdN,CAcOI,KAAA,CAAMG,eAAe,EAAKF,SAAA,CAAUE,eAAe,eAClDP,aAfR,CAeSI,KAAA,CAAMI,MAAM,EAAKH,SAAA,CAAUG,MAAM,IAGnCL,KAAA,CAAMM,mBAAmB,eAE1BT,aApBN,CAoBOI,KAAA,CAAMM,cAAc,EAAKL,SAAA,CAAUK,cAAc,eAChDV,aArBR,CAqBSI,KAAA,CAAMO,KAAK,EAAKN,SAAA,CAAUM,KAAK;AAIxC;AAEA,OAAO,MAAMC,iCAAA,GAAoCA,CAACC,KAAA,EAAkBC,KAAA,KAAkB;EACpF,oBACEd,aA7BJ,CA6BKD,KAAA,CAAMgB,QAAQ;IAACC,GAAA,EAAM,+BAA8BF,KAAM,EAAC;IAAEG,QAAA,EAAU;KACpEJ,KAAA;AAGP"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
|
|
2
|
-
import { useEffect, useRef,
|
|
2
|
+
import { useEffect, useRef, useCallback, useReducer } from 'react';
|
|
3
3
|
import { resolveShorthand } from '@fluentui/react-utilities';
|
|
4
4
|
import { flushSync } from 'react-dom';
|
|
5
|
+
import { useVirtualizerContextState_unstable } from '../../Utilities';
|
|
6
|
+
import { renderVirtualizerChildPlaceholder } from './renderVirtualizer';
|
|
5
7
|
export function useVirtualizer_unstable(props) {
|
|
6
8
|
const {
|
|
7
9
|
itemSize,
|
|
@@ -14,11 +16,12 @@ export function useVirtualizer_unstable(props) {
|
|
|
14
16
|
scrollViewRef,
|
|
15
17
|
axis = 'vertical',
|
|
16
18
|
reversed = false,
|
|
17
|
-
|
|
18
|
-
onCalculateIndex
|
|
19
|
+
virtualizerContext
|
|
19
20
|
} = props;
|
|
20
|
-
|
|
21
|
-
const
|
|
21
|
+
/* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/
|
|
22
|
+
const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);
|
|
23
|
+
const actualIndex = _virtualizerContext.contextIndex;
|
|
24
|
+
const setActualIndex = _virtualizerContext.setContextIndex;
|
|
22
25
|
// Store ref to before padding element
|
|
23
26
|
const beforeElementRef = useRef(null);
|
|
24
27
|
// Store ref to before padding element
|
|
@@ -55,18 +58,17 @@ export function useVirtualizer_unstable(props) {
|
|
|
55
58
|
};
|
|
56
59
|
const batchUpdateNewIndex = index => {
|
|
57
60
|
// Local updates
|
|
58
|
-
onUpdateIndex === null || onUpdateIndex === void 0 ? void 0 : onUpdateIndex(index, virtualizerStartIndex);
|
|
59
61
|
updateChildRows(index);
|
|
60
62
|
updateCurrentItemSizes(index);
|
|
61
63
|
// State setters
|
|
62
|
-
|
|
64
|
+
setActualIndex(index);
|
|
63
65
|
};
|
|
64
66
|
// Observe intersections of virtualized components
|
|
65
67
|
const {
|
|
66
68
|
setObserverList
|
|
67
69
|
} = useIntersectionObserver((entries, observer) => {
|
|
68
70
|
/* Sanity check - do we even need virtualization? */if (virtualizerLength > numItems) {
|
|
69
|
-
if (
|
|
71
|
+
if (actualIndex !== 0) {
|
|
70
72
|
batchUpdateNewIndex(0);
|
|
71
73
|
}
|
|
72
74
|
// No-op
|
|
@@ -128,18 +130,12 @@ export function useVirtualizer_unstable(props) {
|
|
|
128
130
|
}
|
|
129
131
|
// For now lets use hardcoded size to assess current element to paginate on
|
|
130
132
|
const startIndex = getIndexFromScrollPosition(measurementPos);
|
|
131
|
-
|
|
132
|
-
if (onCalculateIndex) {
|
|
133
|
-
// User has chance to intervene/customize prior to render
|
|
134
|
-
// They may want to normalize this value.
|
|
135
|
-
bufferedIndex = onCalculateIndex(bufferedIndex);
|
|
136
|
-
}
|
|
133
|
+
const bufferedIndex = Math.max(startIndex - bufferCount, 0);
|
|
137
134
|
// Safety limits
|
|
138
135
|
const maxIndex = Math.max(numItems - virtualizerLength, 0);
|
|
139
136
|
const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);
|
|
140
|
-
if (
|
|
137
|
+
if (actualIndex !== newStartIndex) {
|
|
141
138
|
// We flush sync this and perform an immediate state update
|
|
142
|
-
// due to virtualizerStartIndex invalidation.
|
|
143
139
|
flushSync(() => {
|
|
144
140
|
batchUpdateNewIndex(newStartIndex);
|
|
145
141
|
});
|
|
@@ -152,7 +148,7 @@ export function useVirtualizer_unstable(props) {
|
|
|
152
148
|
const findIndexRecursive = (scrollPos, lowIndex, highIndex) => {
|
|
153
149
|
if (lowIndex > highIndex) {
|
|
154
150
|
// We shouldn't get here - but no-op the index if we do.
|
|
155
|
-
return
|
|
151
|
+
return actualIndex;
|
|
156
152
|
}
|
|
157
153
|
const midpoint = Math.floor((lowIndex + highIndex) / 2);
|
|
158
154
|
const iBefore = Math.max(midpoint - 1, 0);
|
|
@@ -196,21 +192,22 @@ export function useVirtualizer_unstable(props) {
|
|
|
196
192
|
return childProgressiveSizes.current[numItems - 1];
|
|
197
193
|
};
|
|
198
194
|
const calculateBefore = () => {
|
|
195
|
+
const currentIndex = Math.min(actualIndex, numItems);
|
|
199
196
|
if (!getItemSize) {
|
|
200
197
|
// The missing items from before virtualization starts height
|
|
201
|
-
return
|
|
198
|
+
return currentIndex * itemSize;
|
|
202
199
|
}
|
|
203
|
-
if (
|
|
200
|
+
if (currentIndex <= 0) {
|
|
204
201
|
return 0;
|
|
205
202
|
}
|
|
206
203
|
// Time for custom size calcs
|
|
207
|
-
return childProgressiveSizes.current[
|
|
204
|
+
return childProgressiveSizes.current[currentIndex - 1];
|
|
208
205
|
};
|
|
209
206
|
const calculateAfter = () => {
|
|
210
207
|
if (numItems === 0) {
|
|
211
208
|
return 0;
|
|
212
209
|
}
|
|
213
|
-
const lastItemIndex = Math.min(
|
|
210
|
+
const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems - 1);
|
|
214
211
|
if (!getItemSize) {
|
|
215
212
|
// The missing items from after virtualization ends height
|
|
216
213
|
const remainingItems = numItems - lastItemIndex - 1;
|
|
@@ -226,10 +223,10 @@ export function useVirtualizer_unstable(props) {
|
|
|
226
223
|
if (childArray.current.length !== numItems) {
|
|
227
224
|
childArray.current = new Array(virtualizerLength);
|
|
228
225
|
}
|
|
229
|
-
const
|
|
230
|
-
const end = Math.min(
|
|
231
|
-
for (let i =
|
|
232
|
-
childArray.current[i -
|
|
226
|
+
const _actualIndex = Math.max(newIndex, 0);
|
|
227
|
+
const end = Math.min(_actualIndex + virtualizerLength, numItems);
|
|
228
|
+
for (let i = _actualIndex; i < end; i++) {
|
|
229
|
+
childArray.current[i - _actualIndex] = renderVirtualizerChildPlaceholder(renderChild(i), i);
|
|
233
230
|
}
|
|
234
231
|
}, [numItems, renderChild, virtualizerLength]);
|
|
235
232
|
const setBeforeRef = useCallback(element => {
|
|
@@ -294,19 +291,25 @@ export function useVirtualizer_unstable(props) {
|
|
|
294
291
|
// Initialization on mount - update array index to 0 (ready state).
|
|
295
292
|
// Only fire on mount (no deps).
|
|
296
293
|
useEffect(() => {
|
|
297
|
-
if (
|
|
294
|
+
if (actualIndex < 0) {
|
|
298
295
|
batchUpdateNewIndex(0);
|
|
299
296
|
}
|
|
300
297
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
301
298
|
}, []);
|
|
302
299
|
// If the user passes in an updated renderChild function - update current children
|
|
303
300
|
useEffect(() => {
|
|
304
|
-
if (
|
|
305
|
-
updateChildRows(
|
|
301
|
+
if (actualIndex >= 0) {
|
|
302
|
+
updateChildRows(actualIndex);
|
|
306
303
|
forceUpdate();
|
|
307
304
|
}
|
|
308
305
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
309
306
|
}, [renderChild, updateChildRows]);
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
// Ensure we repopulate if getItemSize callback changes
|
|
309
|
+
populateSizeArrays();
|
|
310
|
+
// We only run this effect on getItemSize change (recalc dynamic sizes)
|
|
311
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
312
|
+
}, [getItemSize]);
|
|
310
313
|
// Ensure we have run through and updated the whole size list array at least once.
|
|
311
314
|
initializeSizeArray();
|
|
312
315
|
if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {
|
|
@@ -315,10 +318,10 @@ export function useVirtualizer_unstable(props) {
|
|
|
315
318
|
}
|
|
316
319
|
// Ensure we recalc if virtualizer length changes
|
|
317
320
|
const maxCompare = Math.min(virtualizerLength, numItems);
|
|
318
|
-
if (childArray.current.length !== maxCompare &&
|
|
319
|
-
updateChildRows(
|
|
321
|
+
if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {
|
|
322
|
+
updateChildRows(actualIndex);
|
|
320
323
|
}
|
|
321
|
-
const isFullyInitialized = hasInitialized.current &&
|
|
324
|
+
const isFullyInitialized = hasInitialized.current && actualIndex >= 0;
|
|
322
325
|
return {
|
|
323
326
|
components: {
|
|
324
327
|
before: 'div',
|
|
@@ -356,7 +359,7 @@ export function useVirtualizer_unstable(props) {
|
|
|
356
359
|
beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,
|
|
357
360
|
afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,
|
|
358
361
|
totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,
|
|
359
|
-
virtualizerStartIndex,
|
|
362
|
+
virtualizerStartIndex: actualIndex,
|
|
360
363
|
axis,
|
|
361
364
|
bufferSize,
|
|
362
365
|
reversed
|