@fluentui/react-virtualizer 9.0.0-alpha.2 → 9.0.0-alpha.21
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 +383 -1
- package/CHANGELOG.md +184 -2
- package/dist/index.d.ts +180 -34
- package/lib/Hooks.js.map +1 -1
- package/lib/Utilities.js +2 -0
- package/lib/Utilities.js.map +1 -0
- package/lib/Virtualizer.js.map +1 -1
- package/lib/VirtualizerScrollView.js +2 -0
- package/lib/VirtualizerScrollView.js.map +1 -0
- package/lib/VirtualizerScrollViewDynamic.js +2 -0
- package/lib/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/Virtualizer/Virtualizer.js.map +1 -1
- package/lib/components/Virtualizer/Virtualizer.types.js +1 -1
- package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib/components/Virtualizer/index.js.map +1 -1
- package/lib/components/Virtualizer/renderVirtualizer.js +11 -12
- package/lib/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib/components/Virtualizer/useVirtualizer.js +46 -41
- package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib/components/Virtualizer/useVirtualizerStyles.js.map +1 -1
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js +14 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js +2 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
- package/lib/components/VirtualizerScrollView/index.js +6 -0
- package/lib/components/VirtualizerScrollView/index.js.map +1 -0
- package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js +11 -0
- package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +38 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js +47 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js.map +1 -0
- 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 +4 -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/useIntersectionObserver.js +2 -10
- package/lib/hooks/useIntersectionObserver.js.map +1 -1
- package/lib/hooks/useResizeObserverRef.js +40 -0
- package/lib/hooks/useResizeObserverRef.js.map +1 -0
- package/lib/hooks/useVirtualizerMeasure.js +53 -0
- package/lib/hooks/useVirtualizerMeasure.js.map +1 -0
- package/lib/index.js +4 -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/debounce.js +20 -0
- package/lib/utilities/debounce.js.map +1 -0
- package/lib/utilities/index.js +2 -0
- package/lib/utilities/index.js.map +1 -0
- package/lib-commonjs/Hooks.js +5 -4
- package/lib-commonjs/Hooks.js.map +1 -1
- package/lib-commonjs/Utilities.js +9 -0
- package/lib-commonjs/Utilities.js.map +1 -0
- package/lib-commonjs/Virtualizer.js +5 -4
- package/lib-commonjs/Virtualizer.js.map +1 -1
- package/lib-commonjs/VirtualizerScrollView.js +9 -0
- package/lib-commonjs/VirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/VirtualizerScrollViewDynamic.js +9 -0
- package/lib-commonjs/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/Virtualizer/Virtualizer.js +14 -17
- package/lib-commonjs/components/Virtualizer/Virtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/Virtualizer.types.js +5 -2
- package/lib-commonjs/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/index.js +9 -8
- package/lib-commonjs/components/Virtualizer/index.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js +26 -21
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js +363 -361
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js +112 -107
- package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js +21 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js +7 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/index.js +13 -0
- package/lib-commonjs/components/VirtualizerScrollView/index.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js +17 -0
- package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +43 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js +70 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js.map +1 -0
- 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 +9 -4
- 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/useIntersectionObserver.js +41 -54
- package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
- package/lib-commonjs/hooks/useResizeObserverRef.js +51 -0
- package/lib-commonjs/hooks/useResizeObserverRef.js.map +1 -0
- package/lib-commonjs/hooks/useVirtualizerMeasure.js +53 -0
- package/lib-commonjs/hooks/useVirtualizerMeasure.js.map +1 -0
- package/lib-commonjs/index.js +36 -40
- 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/debounce.js +29 -0
- package/lib-commonjs/utilities/debounce.js.map +1 -0
- package/lib-commonjs/utilities/index.js +9 -0
- package/lib-commonjs/utilities/index.js.map +1 -0
- package/package.json +13 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ComponentProps } from '@fluentui/react-utilities';
|
|
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
|
-
import
|
|
8
|
+
import { Slot } from '@fluentui/react-utilities';
|
|
9
9
|
import type { SlotClassNames } from '@fluentui/react-utilities';
|
|
10
10
|
|
|
11
11
|
export declare const renderVirtualizer_unstable: (state: VirtualizerState) => JSX.Element;
|
|
12
12
|
|
|
13
|
+
export declare const renderVirtualizerScrollView_unstable: (state: VirtualizerScrollViewState) => JSX.Element;
|
|
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
|
+
|
|
13
35
|
/**
|
|
14
36
|
* React hook that allows easy usage of the browser API IntersectionObserver within React
|
|
15
37
|
* @param callback - A function called when the percentage of the target element is visible crosses a threshold.
|
|
@@ -25,8 +47,39 @@ export declare const useIntersectionObserver: (callback: IntersectionObserverCal
|
|
|
25
47
|
observer: MutableRefObject<IntersectionObserver | undefined>;
|
|
26
48
|
};
|
|
27
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
|
+
|
|
55
|
+
/**
|
|
56
|
+
* React hook that measures virtualized space based on a static size to ensure optimized virtualization length.
|
|
57
|
+
*/
|
|
58
|
+
export declare const useStaticVirtualizerMeasure: <TElement extends HTMLElement>(virtualizerProps: VirtualizerMeasureProps) => {
|
|
59
|
+
virtualizerLength: number;
|
|
60
|
+
bufferItems: number;
|
|
61
|
+
bufferSize: number;
|
|
62
|
+
scrollRef: (instance: TElement | null) => void;
|
|
63
|
+
};
|
|
64
|
+
|
|
28
65
|
export declare function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerState;
|
|
29
66
|
|
|
67
|
+
export declare const useVirtualizerContext_unstable: () => VirtualizerContextProps;
|
|
68
|
+
|
|
69
|
+
export declare function useVirtualizerScrollView_unstable(props: VirtualizerScrollViewProps): VirtualizerScrollViewState;
|
|
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
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Apply styling to the Virtualizer states
|
|
80
|
+
*/
|
|
81
|
+
export declare const useVirtualizerScrollViewStyles_unstable: (state: VirtualizerScrollViewState) => VirtualizerScrollViewState;
|
|
82
|
+
|
|
30
83
|
/**
|
|
31
84
|
* Apply styling to the Virtualizer states
|
|
32
85
|
*/
|
|
@@ -43,7 +96,7 @@ export declare type VirtualizerChildRenderFunction = (index: number) => React_2.
|
|
|
43
96
|
|
|
44
97
|
export declare const virtualizerClassNames: SlotClassNames<VirtualizerSlots>;
|
|
45
98
|
|
|
46
|
-
|
|
99
|
+
declare type VirtualizerConfigProps = {
|
|
47
100
|
/**
|
|
48
101
|
* Child render function.
|
|
49
102
|
* Iteratively called to return current virtualizer DOM children.
|
|
@@ -87,9 +140,8 @@ export declare type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>>
|
|
|
87
140
|
bufferSize?: number;
|
|
88
141
|
/**
|
|
89
142
|
* Enables users to override the intersectionObserverRoot.
|
|
90
|
-
* @default null
|
|
91
143
|
*/
|
|
92
|
-
|
|
144
|
+
scrollViewRef?: React_2.MutableRefObject<HTMLElement | null>;
|
|
93
145
|
/**
|
|
94
146
|
* The scroll direction
|
|
95
147
|
* @default vertical
|
|
@@ -106,35 +158,12 @@ export declare type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>>
|
|
|
106
158
|
*/
|
|
107
159
|
getItemSize?: (index: number) => number;
|
|
108
160
|
/**
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
onUpdateIndex?: (index: number, prevIndex: number) => void;
|
|
112
|
-
/**
|
|
113
|
-
* Allow users to intervene in index calculation changes
|
|
161
|
+
* Virtualizer context can be passed as a prop for extended class use
|
|
114
162
|
*/
|
|
115
|
-
|
|
163
|
+
virtualizerContext?: VirtualizerContextProps;
|
|
116
164
|
};
|
|
117
165
|
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* The intersection observed 'before' element will detect when scrolling towards the beginning.
|
|
121
|
-
*/
|
|
122
|
-
before: NonNullable<Slot<'div', 'td'>>;
|
|
123
|
-
/**
|
|
124
|
-
* A block place holding whitespace at the beginning of current DOM children.
|
|
125
|
-
*/
|
|
126
|
-
beforeContainer: NonNullable<Slot<'div', 'tr'>>;
|
|
127
|
-
/**
|
|
128
|
-
* The intersection observed 'after' element will detect when scrolling towards the end.
|
|
129
|
-
*/
|
|
130
|
-
after: NonNullable<Slot<'div', 'td'>>;
|
|
131
|
-
/**
|
|
132
|
-
* A block place holding whitespace after the end of current DOM children.
|
|
133
|
-
*/
|
|
134
|
-
afterContainer: NonNullable<Slot<'div', 'tr'>>;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export declare type VirtualizerState = ComponentState<VirtualizerSlots> & {
|
|
166
|
+
declare type VirtualizerConfigState = {
|
|
138
167
|
/**
|
|
139
168
|
* The current virtualized array of children to show in the DOM.
|
|
140
169
|
*/
|
|
@@ -165,9 +194,126 @@ export declare type VirtualizerState = ComponentState<VirtualizerSlots> & {
|
|
|
165
194
|
*/
|
|
166
195
|
reversed?: boolean;
|
|
167
196
|
/**
|
|
168
|
-
*
|
|
197
|
+
* Pixel size of intersection observers and how much they 'cross over' into the bufferItems index.
|
|
198
|
+
* Minimum 1px.
|
|
169
199
|
*/
|
|
170
200
|
bufferSize: number;
|
|
171
201
|
};
|
|
172
202
|
|
|
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 = {
|
|
222
|
+
defaultItemSize: number;
|
|
223
|
+
direction?: 'vertical' | 'horizontal';
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export declare type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>> & VirtualizerConfigProps;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Virtualizer ScrollView
|
|
230
|
+
*/
|
|
231
|
+
export declare const VirtualizerScrollView: React_2.FC<VirtualizerScrollViewProps>;
|
|
232
|
+
|
|
233
|
+
export declare const virtualizerScrollViewClassNames: SlotClassNames<VirtualizerScrollViewSlots>;
|
|
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
|
+
|
|
270
|
+
export declare type VirtualizerScrollViewProps = ComponentProps<Partial<VirtualizerScrollViewSlots>> & Partial<Omit<VirtualizerConfigProps, 'itemSize' | 'numItems' | 'getItemSize' | 'children'>> & {
|
|
271
|
+
/**
|
|
272
|
+
* Virtualizer item size in pixels - static.
|
|
273
|
+
* Axis: 'vertical' = Height
|
|
274
|
+
* Axis: 'horizontal' = Width
|
|
275
|
+
*/
|
|
276
|
+
itemSize: number;
|
|
277
|
+
/**
|
|
278
|
+
* The total number of items to be virtualized.
|
|
279
|
+
*/
|
|
280
|
+
numItems: number;
|
|
281
|
+
/**
|
|
282
|
+
* Child render function.
|
|
283
|
+
* Iteratively called to return current virtualizer DOM children.
|
|
284
|
+
* Will act as a row or column indexer depending on Virtualizer settings.
|
|
285
|
+
*/
|
|
286
|
+
children: VirtualizerChildRenderFunction;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export declare type VirtualizerScrollViewSlots = VirtualizerSlots & {
|
|
290
|
+
/**
|
|
291
|
+
* The root container that provides embedded scrolling.
|
|
292
|
+
*/
|
|
293
|
+
container: NonNullable<Slot<'div'>>;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
export declare type VirtualizerScrollViewState = ComponentState<VirtualizerScrollViewSlots> & VirtualizerConfigState;
|
|
297
|
+
|
|
298
|
+
export declare type VirtualizerSlots = {
|
|
299
|
+
/**
|
|
300
|
+
* The intersection observed 'before' element will detect when scrolling towards the beginning.
|
|
301
|
+
*/
|
|
302
|
+
before: NonNullable<Slot<'div', 'td'>>;
|
|
303
|
+
/**
|
|
304
|
+
* A block place holding whitespace at the beginning of current DOM children.
|
|
305
|
+
*/
|
|
306
|
+
beforeContainer: NonNullable<Slot<'div', 'tr'>>;
|
|
307
|
+
/**
|
|
308
|
+
* The intersection observed 'after' element will detect when scrolling towards the end.
|
|
309
|
+
*/
|
|
310
|
+
after: NonNullable<Slot<'div', 'td'>>;
|
|
311
|
+
/**
|
|
312
|
+
* A block place holding whitespace after the end of current DOM children.
|
|
313
|
+
*/
|
|
314
|
+
afterContainer: NonNullable<Slot<'div', 'tr'>>;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
export declare type VirtualizerState = ComponentState<VirtualizerSlots> & VirtualizerConfigState;
|
|
318
|
+
|
|
173
319
|
export { }
|
package/lib/Hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["../src/Hooks.ts"],"sourcesContent":["export * from './hooks/index';\n"],"mappings":"AAAA,cAAc"}
|
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"}
|
package/lib/Virtualizer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["../src/Virtualizer.ts"],"sourcesContent":["export * from './components/Virtualizer/index';\n"],"mappings":"AAAA,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../src/VirtualizerScrollView.ts"],"sourcesContent":["export * from './components/VirtualizerScrollView/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,"
|
|
1
|
+
{"version":3,"names":["useVirtualizerStyles_unstable","useVirtualizer_unstable","renderVirtualizer_unstable","Virtualizer","props","state","displayName"],"sources":["../../../src/components/Virtualizer/Virtualizer.ts"],"sourcesContent":["import type { VirtualizerProps } from './Virtualizer.types';\nimport { useVirtualizerStyles_unstable } from './useVirtualizerStyles';\nimport { useVirtualizer_unstable } from './useVirtualizer';\nimport { renderVirtualizer_unstable } from './renderVirtualizer';\nimport type { FC } from 'react';\n\n/**\n * Virtualizer pseudo-component, this functional wrapper\n * provides a simple interface for reducing the total number\n * of elements rendered at one time in large lists.\n */\nexport const Virtualizer: FC<VirtualizerProps> = (props: VirtualizerProps) => {\n const state = useVirtualizer_unstable(props);\n useVirtualizerStyles_unstable(state);\n\n return renderVirtualizer_unstable(state);\n};\n\nVirtualizer.displayName = 'Virtualizer';\n"],"mappings":"AACA,SAASA,6BAA6B,QAAQ;AAC9C,SAASC,uBAAuB,QAAQ;AACxC,SAASC,0BAA0B,QAAQ;AAG3C;;;;;AAKA,OAAO,MAAMC,WAAA,GAAqCC,KAAA,IAA4B;EAC5E,MAAMC,KAAA,GAAQJ,uBAAA,CAAwBG,KAAA;EACtCJ,6BAAA,CAA8BK,KAAA;EAE9B,OAAOH,0BAAA,CAA2BG,KAAA;AACpC;AAEAF,WAAA,CAAYG,WAAW,GAAG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
//# sourceMappingURL=Virtualizer.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/components/Virtualizer/index.ts"],"sourcesContent":["export * from './Virtualizer';\nexport * from './Virtualizer.types';\nexport * from './useVirtualizer';\nexport * from './renderVirtualizer';\nexport * from './useVirtualizerStyles';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
|
|
@@ -1,18 +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__*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
...slotProps.after
|
|
16
|
-
})));
|
|
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);
|
|
17
16
|
};
|
|
18
17
|
//# sourceMappingURL=renderVirtualizer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,
|
|
@@ -11,14 +13,15 @@ export function useVirtualizer_unstable(props) {
|
|
|
11
13
|
getItemSize,
|
|
12
14
|
bufferItems = Math.round(virtualizerLength / 4.0),
|
|
13
15
|
bufferSize = Math.floor(bufferItems / 2.0) * itemSize,
|
|
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,19 +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
|
-
/* Sanity check - do we even need virtualization? */
|
|
69
|
-
|
|
70
|
-
if (virtualizerStartIndex !== 0) {
|
|
70
|
+
/* Sanity check - do we even need virtualization? */if (virtualizerLength > numItems) {
|
|
71
|
+
if (actualIndex !== 0) {
|
|
71
72
|
batchUpdateNewIndex(0);
|
|
72
73
|
}
|
|
73
74
|
// No-op
|
|
@@ -129,31 +130,25 @@ export function useVirtualizer_unstable(props) {
|
|
|
129
130
|
}
|
|
130
131
|
// For now lets use hardcoded size to assess current element to paginate on
|
|
131
132
|
const startIndex = getIndexFromScrollPosition(measurementPos);
|
|
132
|
-
|
|
133
|
-
if (onCalculateIndex) {
|
|
134
|
-
// User has chance to intervene/customize prior to render
|
|
135
|
-
// They may want to normalize this value.
|
|
136
|
-
bufferedIndex = onCalculateIndex(bufferedIndex);
|
|
137
|
-
}
|
|
133
|
+
const bufferedIndex = Math.max(startIndex - bufferCount, 0);
|
|
138
134
|
// Safety limits
|
|
139
135
|
const maxIndex = Math.max(numItems - virtualizerLength, 0);
|
|
140
136
|
const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);
|
|
141
|
-
if (
|
|
137
|
+
if (actualIndex !== newStartIndex) {
|
|
142
138
|
// We flush sync this and perform an immediate state update
|
|
143
|
-
// due to virtualizerStartIndex invalidation.
|
|
144
139
|
flushSync(() => {
|
|
145
140
|
batchUpdateNewIndex(newStartIndex);
|
|
146
141
|
});
|
|
147
142
|
}
|
|
148
143
|
}, {
|
|
149
|
-
root:
|
|
144
|
+
root: scrollViewRef ? scrollViewRef === null || scrollViewRef === void 0 ? void 0 : scrollViewRef.current : null,
|
|
150
145
|
rootMargin: '0px',
|
|
151
146
|
threshold: 0
|
|
152
147
|
});
|
|
153
148
|
const findIndexRecursive = (scrollPos, lowIndex, highIndex) => {
|
|
154
149
|
if (lowIndex > highIndex) {
|
|
155
150
|
// We shouldn't get here - but no-op the index if we do.
|
|
156
|
-
return
|
|
151
|
+
return actualIndex;
|
|
157
152
|
}
|
|
158
153
|
const midpoint = Math.floor((lowIndex + highIndex) / 2);
|
|
159
154
|
const iBefore = Math.max(midpoint - 1, 0);
|
|
@@ -173,8 +168,7 @@ export function useVirtualizer_unstable(props) {
|
|
|
173
168
|
}
|
|
174
169
|
};
|
|
175
170
|
const getIndexFromSizeArray = scrollPos => {
|
|
176
|
-
/* Quick searches our progressive height array */
|
|
177
|
-
if (scrollPos === 0 || childProgressiveSizes.current.length === 0 || scrollPos <= childProgressiveSizes.current[0]) {
|
|
171
|
+
/* Quick searches our progressive height array */if (scrollPos === 0 || childProgressiveSizes.current.length === 0 || scrollPos <= childProgressiveSizes.current[0]) {
|
|
178
172
|
// Check start
|
|
179
173
|
return 0;
|
|
180
174
|
}
|
|
@@ -198,21 +192,22 @@ export function useVirtualizer_unstable(props) {
|
|
|
198
192
|
return childProgressiveSizes.current[numItems - 1];
|
|
199
193
|
};
|
|
200
194
|
const calculateBefore = () => {
|
|
195
|
+
const currentIndex = Math.min(actualIndex, numItems);
|
|
201
196
|
if (!getItemSize) {
|
|
202
197
|
// The missing items from before virtualization starts height
|
|
203
|
-
return
|
|
198
|
+
return currentIndex * itemSize;
|
|
204
199
|
}
|
|
205
|
-
if (
|
|
200
|
+
if (currentIndex <= 0) {
|
|
206
201
|
return 0;
|
|
207
202
|
}
|
|
208
203
|
// Time for custom size calcs
|
|
209
|
-
return childProgressiveSizes.current[
|
|
204
|
+
return childProgressiveSizes.current[currentIndex - 1];
|
|
210
205
|
};
|
|
211
206
|
const calculateAfter = () => {
|
|
212
207
|
if (numItems === 0) {
|
|
213
208
|
return 0;
|
|
214
209
|
}
|
|
215
|
-
const lastItemIndex = Math.min(
|
|
210
|
+
const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems - 1);
|
|
216
211
|
if (!getItemSize) {
|
|
217
212
|
// The missing items from after virtualization ends height
|
|
218
213
|
const remainingItems = numItems - lastItemIndex - 1;
|
|
@@ -221,20 +216,19 @@ export function useVirtualizer_unstable(props) {
|
|
|
221
216
|
// Time for custom size calcs
|
|
222
217
|
return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex];
|
|
223
218
|
};
|
|
224
|
-
const updateChildRows = newIndex => {
|
|
219
|
+
const updateChildRows = useCallback(newIndex => {
|
|
225
220
|
if (numItems === 0) {
|
|
226
|
-
/* Nothing to virtualize */
|
|
227
|
-
return [];
|
|
221
|
+
/* Nothing to virtualize */return [];
|
|
228
222
|
}
|
|
229
223
|
if (childArray.current.length !== numItems) {
|
|
230
224
|
childArray.current = new Array(virtualizerLength);
|
|
231
225
|
}
|
|
232
|
-
const
|
|
233
|
-
const end = Math.min(
|
|
234
|
-
for (let i =
|
|
235
|
-
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);
|
|
236
230
|
}
|
|
237
|
-
};
|
|
231
|
+
}, [numItems, renderChild, virtualizerLength]);
|
|
238
232
|
const setBeforeRef = useCallback(element => {
|
|
239
233
|
if (!element || beforeElementRef.current === element) {
|
|
240
234
|
return;
|
|
@@ -297,26 +291,37 @@ export function useVirtualizer_unstable(props) {
|
|
|
297
291
|
// Initialization on mount - update array index to 0 (ready state).
|
|
298
292
|
// Only fire on mount (no deps).
|
|
299
293
|
useEffect(() => {
|
|
300
|
-
if (
|
|
294
|
+
if (actualIndex < 0) {
|
|
301
295
|
batchUpdateNewIndex(0);
|
|
302
296
|
}
|
|
303
297
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
304
298
|
}, []);
|
|
305
299
|
// If the user passes in an updated renderChild function - update current children
|
|
306
300
|
useEffect(() => {
|
|
307
|
-
if (
|
|
308
|
-
updateChildRows(
|
|
301
|
+
if (actualIndex >= 0) {
|
|
302
|
+
updateChildRows(actualIndex);
|
|
309
303
|
forceUpdate();
|
|
310
304
|
}
|
|
311
305
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
312
|
-
}, [renderChild]);
|
|
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]);
|
|
313
313
|
// Ensure we have run through and updated the whole size list array at least once.
|
|
314
314
|
initializeSizeArray();
|
|
315
315
|
if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {
|
|
316
316
|
// Child length mismatch, repopulate size arrays.
|
|
317
317
|
populateSizeArrays();
|
|
318
318
|
}
|
|
319
|
-
|
|
319
|
+
// Ensure we recalc if virtualizer length changes
|
|
320
|
+
const maxCompare = Math.min(virtualizerLength, numItems);
|
|
321
|
+
if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {
|
|
322
|
+
updateChildRows(actualIndex);
|
|
323
|
+
}
|
|
324
|
+
const isFullyInitialized = hasInitialized.current && actualIndex >= 0;
|
|
320
325
|
return {
|
|
321
326
|
components: {
|
|
322
327
|
before: 'div',
|
|
@@ -354,7 +359,7 @@ export function useVirtualizer_unstable(props) {
|
|
|
354
359
|
beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,
|
|
355
360
|
afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,
|
|
356
361
|
totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,
|
|
357
|
-
virtualizerStartIndex,
|
|
362
|
+
virtualizerStartIndex: actualIndex,
|
|
358
363
|
axis,
|
|
359
364
|
bufferSize,
|
|
360
365
|
reversed
|