@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.
Files changed (139) hide show
  1. package/CHANGELOG.json +383 -1
  2. package/CHANGELOG.md +184 -2
  3. package/dist/index.d.ts +180 -34
  4. package/lib/Hooks.js.map +1 -1
  5. package/lib/Utilities.js +2 -0
  6. package/lib/Utilities.js.map +1 -0
  7. package/lib/Virtualizer.js.map +1 -1
  8. package/lib/VirtualizerScrollView.js +2 -0
  9. package/lib/VirtualizerScrollView.js.map +1 -0
  10. package/lib/VirtualizerScrollViewDynamic.js +2 -0
  11. package/lib/VirtualizerScrollViewDynamic.js.map +1 -0
  12. package/lib/components/Virtualizer/Virtualizer.js.map +1 -1
  13. package/lib/components/Virtualizer/Virtualizer.types.js +1 -1
  14. package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
  15. package/lib/components/Virtualizer/index.js.map +1 -1
  16. package/lib/components/Virtualizer/renderVirtualizer.js +11 -12
  17. package/lib/components/Virtualizer/renderVirtualizer.js.map +1 -1
  18. package/lib/components/Virtualizer/useVirtualizer.js +46 -41
  19. package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
  20. package/lib/components/Virtualizer/useVirtualizerStyles.js.map +1 -1
  21. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js +14 -0
  22. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
  23. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js +2 -0
  24. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
  25. package/lib/components/VirtualizerScrollView/index.js +6 -0
  26. package/lib/components/VirtualizerScrollView/index.js.map +1 -0
  27. package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js +11 -0
  28. package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
  29. package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +38 -0
  30. package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
  31. package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js +47 -0
  32. package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js.map +1 -0
  33. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +14 -0
  34. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
  35. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +2 -0
  36. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
  37. package/lib/components/VirtualizerScrollViewDynamic/index.js +6 -0
  38. package/lib/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
  39. package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +11 -0
  40. package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
  41. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +44 -0
  42. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
  43. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js +46 -0
  44. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js.map +1 -0
  45. package/lib/hooks/hooks.types.js +2 -0
  46. package/lib/hooks/hooks.types.js.map +1 -0
  47. package/lib/hooks/index.js +4 -0
  48. package/lib/hooks/index.js.map +1 -1
  49. package/lib/hooks/useDynamicVirtualizerMeasure.js +99 -0
  50. package/lib/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
  51. package/lib/hooks/useIntersectionObserver.js +2 -10
  52. package/lib/hooks/useIntersectionObserver.js.map +1 -1
  53. package/lib/hooks/useResizeObserverRef.js +40 -0
  54. package/lib/hooks/useResizeObserverRef.js.map +1 -0
  55. package/lib/hooks/useVirtualizerMeasure.js +53 -0
  56. package/lib/hooks/useVirtualizerMeasure.js.map +1 -0
  57. package/lib/index.js +4 -1
  58. package/lib/index.js.map +1 -1
  59. package/lib/utilities/VirtualizerContext/VirtualizerContext.js +27 -0
  60. package/lib/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
  61. package/lib/utilities/VirtualizerContext/index.js +3 -0
  62. package/lib/utilities/VirtualizerContext/index.js.map +1 -0
  63. package/lib/utilities/VirtualizerContext/types.js +4 -0
  64. package/lib/utilities/VirtualizerContext/types.js.map +1 -0
  65. package/lib/utilities/debounce.js +20 -0
  66. package/lib/utilities/debounce.js.map +1 -0
  67. package/lib/utilities/index.js +2 -0
  68. package/lib/utilities/index.js.map +1 -0
  69. package/lib-commonjs/Hooks.js +5 -4
  70. package/lib-commonjs/Hooks.js.map +1 -1
  71. package/lib-commonjs/Utilities.js +9 -0
  72. package/lib-commonjs/Utilities.js.map +1 -0
  73. package/lib-commonjs/Virtualizer.js +5 -4
  74. package/lib-commonjs/Virtualizer.js.map +1 -1
  75. package/lib-commonjs/VirtualizerScrollView.js +9 -0
  76. package/lib-commonjs/VirtualizerScrollView.js.map +1 -0
  77. package/lib-commonjs/VirtualizerScrollViewDynamic.js +9 -0
  78. package/lib-commonjs/VirtualizerScrollViewDynamic.js.map +1 -0
  79. package/lib-commonjs/components/Virtualizer/Virtualizer.js +14 -17
  80. package/lib-commonjs/components/Virtualizer/Virtualizer.js.map +1 -1
  81. package/lib-commonjs/components/Virtualizer/Virtualizer.types.js +5 -2
  82. package/lib-commonjs/components/Virtualizer/Virtualizer.types.js.map +1 -1
  83. package/lib-commonjs/components/Virtualizer/index.js +9 -8
  84. package/lib-commonjs/components/Virtualizer/index.js.map +1 -1
  85. package/lib-commonjs/components/Virtualizer/renderVirtualizer.js +26 -21
  86. package/lib-commonjs/components/Virtualizer/renderVirtualizer.js.map +1 -1
  87. package/lib-commonjs/components/Virtualizer/useVirtualizer.js +363 -361
  88. package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
  89. package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js +112 -107
  90. package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js.map +1 -1
  91. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js +21 -0
  92. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
  93. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js +7 -0
  94. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
  95. package/lib-commonjs/components/VirtualizerScrollView/index.js +13 -0
  96. package/lib-commonjs/components/VirtualizerScrollView/index.js.map +1 -0
  97. package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js +17 -0
  98. package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
  99. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +43 -0
  100. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
  101. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js +70 -0
  102. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.js.map +1 -0
  103. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +21 -0
  104. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
  105. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +7 -0
  106. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
  107. package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js +13 -0
  108. package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
  109. package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +17 -0
  110. package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
  111. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +49 -0
  112. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
  113. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js +69 -0
  114. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.js.map +1 -0
  115. package/lib-commonjs/hooks/hooks.types.js +7 -0
  116. package/lib-commonjs/hooks/hooks.types.js.map +1 -0
  117. package/lib-commonjs/hooks/index.js +9 -4
  118. package/lib-commonjs/hooks/index.js.map +1 -1
  119. package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js +107 -0
  120. package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
  121. package/lib-commonjs/hooks/useIntersectionObserver.js +41 -54
  122. package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
  123. package/lib-commonjs/hooks/useResizeObserverRef.js +51 -0
  124. package/lib-commonjs/hooks/useResizeObserverRef.js.map +1 -0
  125. package/lib-commonjs/hooks/useVirtualizerMeasure.js +53 -0
  126. package/lib-commonjs/hooks/useVirtualizerMeasure.js.map +1 -0
  127. package/lib-commonjs/index.js +36 -40
  128. package/lib-commonjs/index.js.map +1 -1
  129. package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js +48 -0
  130. package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
  131. package/lib-commonjs/utilities/VirtualizerContext/index.js +10 -0
  132. package/lib-commonjs/utilities/VirtualizerContext/index.js.map +1 -0
  133. package/lib-commonjs/utilities/VirtualizerContext/types.js +9 -0
  134. package/lib-commonjs/utilities/VirtualizerContext/types.js.map +1 -0
  135. package/lib-commonjs/utilities/debounce.js +29 -0
  136. package/lib-commonjs/utilities/debounce.js.map +1 -0
  137. package/lib-commonjs/utilities/index.js +9 -0
  138. package/lib-commonjs/utilities/index.js.map +1 -0
  139. package/package.json +13 -10
package/dist/index.d.ts CHANGED
@@ -1,15 +1,37 @@
1
- import type { ComponentProps } from '@fluentui/react-utilities';
2
- import type { ComponentState } from '@fluentui/react-utilities';
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 type { MutableRefObject } from 'react';
5
+ import { MutableRefObject } from 'react';
6
6
  import * as React_2 from 'react';
7
7
  import type { SetStateAction } from 'react';
8
- import type { Slot } from '@fluentui/react-utilities';
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
- export declare type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>> & {
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
- intersectionObserverRoot?: React_2.MutableRefObject<HTMLElement | null>;
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
- * Notify users of index changes
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
- onCalculateIndex?: (newIndex: number) => number;
163
+ virtualizerContext?: VirtualizerContextProps;
116
164
  };
117
165
 
118
- export declare type VirtualizerSlots = {
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
- * Tells the virtualizer how much
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,"file":"Hooks.js","sourceRoot":"../src/","sources":["packages/react-components/react-virtualizer/src/Hooks.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC","sourcesContent":["export * from './hooks/index';\n"]}
1
+ {"version":3,"names":[],"sources":["../src/Hooks.ts"],"sourcesContent":["export * from './hooks/index';\n"],"mappings":"AAAA,cAAc"}
@@ -0,0 +1,2 @@
1
+ export * from './utilities/index';
2
+ //# sourceMappingURL=Utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../src/Utilities.ts"],"sourcesContent":["export * from './utilities/index';\n"],"mappings":"AAAA,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Virtualizer.js","sourceRoot":"../src/","sources":["packages/react-components/react-virtualizer/src/Virtualizer.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC","sourcesContent":["export * from './components/Virtualizer/index';\n"]}
1
+ {"version":3,"names":[],"sources":["../src/Virtualizer.ts"],"sourcesContent":["export * from './components/Virtualizer/index';\n"],"mappings":"AAAA,cAAc"}
@@ -0,0 +1,2 @@
1
+ export * from './components/VirtualizerScrollView/index';
2
+ //# sourceMappingURL=VirtualizerScrollView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../src/VirtualizerScrollView.ts"],"sourcesContent":["export * from './components/VirtualizerScrollView/index';\n"],"mappings":"AAAA,cAAc"}
@@ -0,0 +1,2 @@
1
+ export * from './components/VirtualizerScrollViewDynamic/index';
2
+ //# sourceMappingURL=VirtualizerScrollViewDynamic.js.map
@@ -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,"mappings":"AACA,SAASA,6BAA6B,QAAQ,wBAAwB;AACtE,SAASC,uBAAuB,QAAQ,kBAAkB;AAC1D,SAASC,0BAA0B,QAAQ,qBAAqB;AAGhE;;;;;AAKA,OAAO,MAAMC,WAAW,GAA0BC,KAAuB,IAAI;EAC3E,MAAMC,KAAK,GAAGJ,uBAAuB,CAACG,KAAK,CAAC;EAC5CJ,6BAA6B,CAACK,KAAK,CAAC;EAEpC,OAAOH,0BAA0B,CAACG,KAAK,CAAC;AAC1C,CAAC;AAEDF,WAAW,CAACG,WAAW,GAAG,aAAa","names":["useVirtualizerStyles_unstable","useVirtualizer_unstable","renderVirtualizer_unstable","Virtualizer","props","state","displayName"],"sourceRoot":"../src/","sources":["packages/react-components/react-virtualizer/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"]}
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
- export {};
1
+ import * as React from 'react';
2
2
  //# sourceMappingURL=Virtualizer.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Virtualizer.types.js","sourceRoot":"../src/","sources":["packages/react-components/react-virtualizer/src/components/Virtualizer/Virtualizer.types.ts"],"names":[],"mappings":"","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 VirtualizerState = ComponentState<VirtualizerSlots> & {\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 * Tells the virtualizer how much\n */\n bufferSize: number;\n};\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 VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>> & {\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 * @default null\n */\n intersectionObserverRoot?: 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 * Notify users of index changes\n */\n onUpdateIndex?: (index: number, prevIndex: number) => void;\n\n /**\n * Allow users to intervene in index calculation changes\n */\n onCalculateIndex?: (newIndex: number) => number;\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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-virtualizer/src/components/Virtualizer/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from './Virtualizer';\nexport * from './Virtualizer.types';\nexport * from './useVirtualizer';\nexport * from './renderVirtualizer';\nexport * from './useVirtualizerStyles';\n"]}
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 { getSlots } from '@fluentui/react-utilities';
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
- } = getSlots(state);
8
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(slots.beforeContainer, {
9
- ...slotProps.beforeContainer
10
- }, /*#__PURE__*/React.createElement(slots.before, {
11
- ...slotProps.before
12
- })), state.virtualizedChildren, /*#__PURE__*/React.createElement(slots.afterContainer, {
13
- ...slotProps.afterContainer
14
- }, /*#__PURE__*/React.createElement(slots.after, {
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,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD,OAAO,MAAMC,0BAA0B,GAAIC,KAAuB,IAAI;EACpE,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAAmBE,KAAK,CAAC;EAE9D,oBACEH,oBAACA,KAAK,CAACM,QAAQ,qBAEbN,oBAACI,KAAK,CAACG,eAAe;IAAA,GAAKF,SAAS,CAACE;EAAe,gBAClDP,oBAACI,KAAK,CAACI,MAAM;IAAA,GAAKH,SAAS,CAACG;EAAM,EAAI,CAChB,EAEvBL,KAAK,CAACM,mBAAmB,eAE1BT,oBAACI,KAAK,CAACM,cAAc;IAAA,GAAKL,SAAS,CAACK;EAAc,gBAChDV,oBAACI,KAAK,CAACO,KAAK;IAAA,GAAKN,SAAS,CAACM;EAAK,EAAI,CACf,CACR;AAErB,CAAC","names":["React","getSlots","renderVirtualizer_unstable","state","slots","slotProps","Fragment","beforeContainer","before","virtualizedChildren","afterContainer","after"],"sourceRoot":"../src/","sources":["packages/react-components/react-virtualizer/src/components/Virtualizer/renderVirtualizer.tsx"],"sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { VirtualizerSlots, VirtualizerState } from './Virtualizer.types';\n\nexport const renderVirtualizer_unstable = (state: VirtualizerState) => {\n const { slots, slotProps } = getSlots<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"]}
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, useState, useCallback, useReducer } from 'react';
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
- intersectionObserverRoot,
16
+ scrollViewRef,
15
17
  axis = 'vertical',
16
18
  reversed = false,
17
- onUpdateIndex,
18
- onCalculateIndex
19
+ virtualizerContext
19
20
  } = props;
20
- // Tracks the initial item to start virtualizer at, -1 implies first render cycle
21
- const [virtualizerStartIndex, setVirtualizerStartIndex] = useState(-1);
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
- setVirtualizerStartIndex(index);
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
- if (virtualizerLength > numItems) {
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
- let bufferedIndex = Math.max(startIndex - bufferCount, 0);
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 (virtualizerStartIndex !== newStartIndex) {
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: intersectionObserverRoot ? intersectionObserverRoot === null || intersectionObserverRoot === void 0 ? void 0 : intersectionObserverRoot.current : null,
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 virtualizerStartIndex;
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 virtualizerStartIndex * itemSize;
198
+ return currentIndex * itemSize;
204
199
  }
205
- if (virtualizerStartIndex <= 0) {
200
+ if (currentIndex <= 0) {
206
201
  return 0;
207
202
  }
208
203
  // Time for custom size calcs
209
- return childProgressiveSizes.current[virtualizerStartIndex - 1];
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(virtualizerStartIndex + virtualizerLength, numItems - 1);
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 actualIndex = Math.max(newIndex, 0);
233
- const end = Math.min(actualIndex + virtualizerLength, numItems);
234
- for (let i = actualIndex; i < end; i++) {
235
- childArray.current[i - actualIndex] = renderChild(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 (virtualizerStartIndex < 0) {
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 (virtualizerStartIndex >= 0) {
308
- updateChildRows(virtualizerStartIndex);
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
- const isFullyInitialized = hasInitialized.current && virtualizerStartIndex >= 0;
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