@fluentui/react-virtualizer 9.0.0-alpha.8 → 9.0.0-alpha.81

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 (183) hide show
  1. package/CHANGELOG.md +754 -8
  2. package/dist/index.d.ts +248 -30
  3. package/lib/Hooks.js +0 -1
  4. package/lib/Hooks.js.map +1 -1
  5. package/lib/Utilities.js +1 -0
  6. package/lib/Utilities.js.map +1 -0
  7. package/lib/Virtualizer.js +0 -1
  8. package/lib/Virtualizer.js.map +1 -1
  9. package/lib/VirtualizerScrollView.js +1 -0
  10. package/lib/VirtualizerScrollView.js.map +1 -0
  11. package/lib/VirtualizerScrollViewDynamic.js +1 -0
  12. package/lib/VirtualizerScrollViewDynamic.js.map +1 -0
  13. package/lib/components/Virtualizer/Virtualizer.js +5 -7
  14. package/lib/components/Virtualizer/Virtualizer.js.map +1 -1
  15. package/lib/components/Virtualizer/Virtualizer.types.js +1 -2
  16. package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
  17. package/lib/components/Virtualizer/index.js +1 -2
  18. package/lib/components/Virtualizer/index.js.map +1 -1
  19. package/lib/components/Virtualizer/renderVirtualizer.js +21 -16
  20. package/lib/components/Virtualizer/renderVirtualizer.js.map +1 -1
  21. package/lib/components/Virtualizer/useVirtualizer.js +439 -355
  22. package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
  23. package/lib/components/Virtualizer/{useVirtualizerStyles.js → useVirtualizerStyles.styles.js} +5 -3
  24. package/lib/components/Virtualizer/useVirtualizerStyles.styles.js.map +1 -0
  25. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js +12 -0
  26. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
  27. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js +1 -0
  28. package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
  29. package/lib/components/VirtualizerScrollView/index.js +5 -0
  30. package/lib/components/VirtualizerScrollView/index.js.map +1 -0
  31. package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js +9 -0
  32. package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
  33. package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +81 -0
  34. package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
  35. package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js +47 -0
  36. package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js.map +1 -0
  37. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +12 -0
  38. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
  39. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +1 -0
  40. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
  41. package/lib/components/VirtualizerScrollViewDynamic/index.js +5 -0
  42. package/lib/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
  43. package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +9 -0
  44. package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
  45. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +149 -0
  46. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
  47. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js +47 -0
  48. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js.map +1 -0
  49. package/lib/hooks/hooks.types.js +4 -0
  50. package/lib/hooks/hooks.types.js.map +1 -0
  51. package/lib/hooks/index.js +4 -1
  52. package/lib/hooks/index.js.map +1 -1
  53. package/lib/hooks/useDynamicPagination.js +127 -0
  54. package/lib/hooks/useDynamicPagination.js.map +1 -0
  55. package/lib/hooks/useDynamicVirtualizerMeasure.js +101 -0
  56. package/lib/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
  57. package/lib/hooks/useIntersectionObserver.js +117 -40
  58. package/lib/hooks/useIntersectionObserver.js.map +1 -1
  59. package/lib/hooks/useMeasureList.js +116 -0
  60. package/lib/hooks/useMeasureList.js.map +1 -0
  61. package/lib/hooks/useMutationObserver.js +38 -0
  62. package/lib/hooks/useMutationObserver.js.map +1 -0
  63. package/lib/hooks/useResizeObserverRef.js +50 -0
  64. package/lib/hooks/useResizeObserverRef.js.map +1 -0
  65. package/lib/hooks/useStaticPagination.js +103 -0
  66. package/lib/hooks/useStaticPagination.js.map +1 -0
  67. package/lib/hooks/useVirtualizerMeasure.js +46 -0
  68. package/lib/hooks/useVirtualizerMeasure.js.map +1 -0
  69. package/lib/index.js +4 -2
  70. package/lib/index.js.map +1 -1
  71. package/lib/utilities/ImperativeScrolling/imperativeScrolling.js +32 -0
  72. package/lib/utilities/ImperativeScrolling/imperativeScrolling.js.map +1 -0
  73. package/lib/utilities/ImperativeScrolling/imperativeScrolling.types.js +1 -0
  74. package/lib/utilities/ImperativeScrolling/imperativeScrolling.types.js.map +1 -0
  75. package/lib/utilities/ImperativeScrolling/imperativeScrollingDynamic.js +45 -0
  76. package/lib/utilities/ImperativeScrolling/imperativeScrollingDynamic.js.map +1 -0
  77. package/lib/utilities/ImperativeScrolling/index.js +3 -0
  78. package/lib/utilities/ImperativeScrolling/index.js.map +1 -0
  79. package/lib/utilities/VirtualizerContext/VirtualizerContext.js +33 -0
  80. package/lib/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
  81. package/lib/utilities/VirtualizerContext/index.js +2 -0
  82. package/lib/utilities/VirtualizerContext/index.js.map +1 -0
  83. package/lib/utilities/VirtualizerContext/types.js +3 -0
  84. package/lib/utilities/VirtualizerContext/types.js.map +1 -0
  85. package/lib/utilities/createResizeObserverFromDocument.js +13 -0
  86. package/lib/utilities/createResizeObserverFromDocument.js.map +1 -0
  87. package/lib/utilities/debounce.js +19 -0
  88. package/lib/utilities/debounce.js.map +1 -0
  89. package/lib/utilities/index.js +2 -0
  90. package/lib/utilities/index.js.map +1 -0
  91. package/lib-commonjs/Hooks.js +3 -5
  92. package/lib-commonjs/Hooks.js.map +1 -1
  93. package/lib-commonjs/Utilities.js +6 -0
  94. package/lib-commonjs/Utilities.js.map +1 -0
  95. package/lib-commonjs/Virtualizer.js +3 -5
  96. package/lib-commonjs/Virtualizer.js.map +1 -1
  97. package/lib-commonjs/VirtualizerScrollView.js +6 -0
  98. package/lib-commonjs/VirtualizerScrollView.js.map +1 -0
  99. package/lib-commonjs/VirtualizerScrollViewDynamic.js +6 -0
  100. package/lib-commonjs/VirtualizerScrollViewDynamic.js.map +1 -0
  101. package/lib-commonjs/components/Virtualizer/Virtualizer.js +15 -18
  102. package/lib-commonjs/components/Virtualizer/Virtualizer.js.map +1 -1
  103. package/lib-commonjs/components/Virtualizer/Virtualizer.types.js +3 -3
  104. package/lib-commonjs/components/Virtualizer/Virtualizer.types.js.map +1 -1
  105. package/lib-commonjs/components/Virtualizer/index.js +7 -9
  106. package/lib-commonjs/components/Virtualizer/index.js.map +1 -1
  107. package/lib-commonjs/components/Virtualizer/renderVirtualizer.js +38 -21
  108. package/lib-commonjs/components/Virtualizer/renderVirtualizer.js.map +1 -1
  109. package/lib-commonjs/components/Virtualizer/useVirtualizer.js +447 -361
  110. package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
  111. package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.styles.js +123 -0
  112. package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.styles.js.map +1 -0
  113. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js +21 -0
  114. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
  115. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js +4 -0
  116. package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
  117. package/lib-commonjs/components/VirtualizerScrollView/index.js +10 -0
  118. package/lib-commonjs/components/VirtualizerScrollView/index.js.map +1 -0
  119. package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js +19 -0
  120. package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
  121. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +91 -0
  122. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
  123. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js +70 -0
  124. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js.map +1 -0
  125. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +21 -0
  126. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
  127. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +4 -0
  128. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
  129. package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js +10 -0
  130. package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
  131. package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +19 -0
  132. package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
  133. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +158 -0
  134. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
  135. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js +70 -0
  136. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js.map +1 -0
  137. package/lib-commonjs/hooks/hooks.types.js +7 -0
  138. package/lib-commonjs/hooks/hooks.types.js.map +1 -0
  139. package/lib-commonjs/hooks/index.js +7 -5
  140. package/lib-commonjs/hooks/index.js.map +1 -1
  141. package/lib-commonjs/hooks/useDynamicPagination.js +131 -0
  142. package/lib-commonjs/hooks/useDynamicPagination.js.map +1 -0
  143. package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js +108 -0
  144. package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
  145. package/lib-commonjs/hooks/useIntersectionObserver.js +129 -53
  146. package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
  147. package/lib-commonjs/hooks/useMeasureList.js +122 -0
  148. package/lib-commonjs/hooks/useMeasureList.js.map +1 -0
  149. package/lib-commonjs/hooks/useMutationObserver.js +48 -0
  150. package/lib-commonjs/hooks/useMutationObserver.js.map +1 -0
  151. package/lib-commonjs/hooks/useResizeObserverRef.js +59 -0
  152. package/lib-commonjs/hooks/useResizeObserverRef.js.map +1 -0
  153. package/lib-commonjs/hooks/useStaticPagination.js +107 -0
  154. package/lib-commonjs/hooks/useStaticPagination.js.map +1 -0
  155. package/lib-commonjs/hooks/useVirtualizerMeasure.js +54 -0
  156. package/lib-commonjs/hooks/useVirtualizerMeasure.js.map +1 -0
  157. package/lib-commonjs/index.js +82 -41
  158. package/lib-commonjs/index.js.map +1 -1
  159. package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.js +42 -0
  160. package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.js.map +1 -0
  161. package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.types.js +4 -0
  162. package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.types.js.map +1 -0
  163. package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrollingDynamic.js +55 -0
  164. package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrollingDynamic.js.map +1 -0
  165. package/lib-commonjs/utilities/ImperativeScrolling/index.js +8 -0
  166. package/lib-commonjs/utilities/ImperativeScrolling/index.js.map +1 -0
  167. package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js +54 -0
  168. package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
  169. package/lib-commonjs/utilities/VirtualizerContext/index.js +7 -0
  170. package/lib-commonjs/utilities/VirtualizerContext/index.js.map +1 -0
  171. package/lib-commonjs/utilities/VirtualizerContext/types.js +6 -0
  172. package/lib-commonjs/utilities/VirtualizerContext/types.js.map +1 -0
  173. package/lib-commonjs/utilities/createResizeObserverFromDocument.js +23 -0
  174. package/lib-commonjs/utilities/createResizeObserverFromDocument.js.map +1 -0
  175. package/lib-commonjs/utilities/debounce.js +29 -0
  176. package/lib-commonjs/utilities/debounce.js.map +1 -0
  177. package/lib-commonjs/utilities/index.js +7 -0
  178. package/lib-commonjs/utilities/index.js.map +1 -0
  179. package/package.json +22 -13
  180. package/CHANGELOG.json +0 -125
  181. package/lib/components/Virtualizer/useVirtualizerStyles.js.map +0 -1
  182. package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js +0 -115
  183. package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js.map +0 -1
@@ -1,363 +1,447 @@
1
+ import { useEffect, useRef, useCallback, useReducer, useImperativeHandle, useState } from 'react';
1
2
  import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
2
- import { useEffect, useRef, useState, useCallback, useReducer } from 'react';
3
- import { resolveShorthand } from '@fluentui/react-utilities';
4
3
  import { flushSync } from 'react-dom';
4
+ import { useVirtualizerContextState_unstable } from '../../Utilities';
5
+ import { slot, useTimeout } from '@fluentui/react-utilities';
5
6
  export function useVirtualizer_unstable(props) {
6
- const {
7
- itemSize,
8
- numItems,
9
- virtualizerLength,
10
- children: renderChild,
11
- getItemSize,
12
- bufferItems = Math.round(virtualizerLength / 4.0),
13
- bufferSize = Math.floor(bufferItems / 2.0) * itemSize,
14
- intersectionObserverRoot,
15
- axis = 'vertical',
16
- reversed = false,
17
- onUpdateIndex,
18
- onCalculateIndex
19
- } = props;
20
- // Tracks the initial item to start virtualizer at, -1 implies first render cycle
21
- const [virtualizerStartIndex, setVirtualizerStartIndex] = useState(-1);
22
- // Store ref to before padding element
23
- const beforeElementRef = useRef(null);
24
- // Store ref to before padding element
25
- const afterElementRef = useRef(null);
26
- // We need to store an array to track dynamic sizes, we can use this to incrementally update changes
27
- const childSizes = useRef(new Array(getItemSize ? numItems : 0));
28
- /* We keep track of the progressive sizing/placement down the list,
29
- this helps us skip re-calculations unless children/size changes */
30
- const childProgressiveSizes = useRef(new Array(getItemSize ? numItems : 0));
31
- // The internal tracking REF for child array (updates often).
32
- const childArray = useRef(new Array(virtualizerLength));
33
- // We want to be methodical about updating the render with child reference array
34
- const forceUpdate = useReducer(() => ({}), {})[1];
35
- const horizontal = axis === 'horizontal';
36
- const populateSizeArrays = () => {
37
- if (!getItemSize) {
38
- // Static sizes, never mind!
39
- return;
40
- }
41
- if (numItems !== childSizes.current.length) {
42
- childSizes.current = new Array(numItems);
43
- }
44
- if (numItems !== childProgressiveSizes.current.length) {
45
- childProgressiveSizes.current = new Array(numItems);
46
- }
47
- for (let index = 0; index < numItems; index++) {
48
- childSizes.current[index] = getItemSize(index);
49
- if (index === 0) {
50
- childProgressiveSizes.current[index] = childSizes.current[index];
51
- } else {
52
- childProgressiveSizes.current[index] = childProgressiveSizes.current[index - 1] + childSizes.current[index];
53
- }
54
- }
55
- };
56
- const batchUpdateNewIndex = index => {
57
- // Local updates
58
- onUpdateIndex === null || onUpdateIndex === void 0 ? void 0 : onUpdateIndex(index, virtualizerStartIndex);
59
- updateChildRows(index);
60
- updateCurrentItemSizes(index);
61
- // State setters
62
- setVirtualizerStartIndex(index);
63
- };
64
- // Observe intersections of virtualized components
65
- const {
66
- setObserverList
67
- } = useIntersectionObserver((entries, observer) => {
68
- /* Sanity check - do we even need virtualization? */
69
- if (virtualizerLength > numItems) {
70
- if (virtualizerStartIndex !== 0) {
71
- batchUpdateNewIndex(0);
72
- }
73
- // No-op
74
- return;
75
- }
76
- /* IO initiates this function when needed (bookend entering view) */
77
- let measurementPos = 0;
78
- let bufferCount = bufferItems;
79
- // Grab latest entry that is intersecting
80
- const latestEntry = entries.length === 1 ? entries[0] : entries.sort((entry1, entry2) => entry2.time - entry1.time).find(entry => {
81
- return entry.intersectionRatio > 0;
82
- });
83
- if (!latestEntry) {
84
- // If we don't find an intersecting area, ignore for now.
85
- return;
86
- }
87
- if (latestEntry.target === afterElementRef.current) {
88
- // We need to inverse the buffer count
89
- bufferCount = virtualizerLength - bufferItems;
90
- measurementPos = reversed ? calculateAfter() : calculateTotalSize() - calculateAfter();
91
- if (!horizontal) {
92
- if (reversed) {
93
- // Scrolling 'up' and hit the after element below
94
- measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);
95
- } else if (latestEntry.boundingClientRect.top < 0) {
96
- // Scrolling 'down' and hit the after element above top: 0
97
- measurementPos -= latestEntry.boundingClientRect.top;
7
+ 'use no memo';
8
+ const { itemSize, numItems, virtualizerLength, children: renderChild, getItemSize, bufferItems = Math.round(virtualizerLength / 4.0), bufferSize = Math.floor(bufferItems / 2.0) * itemSize, scrollViewRef, axis = 'vertical', reversed = false, virtualizerContext, onRenderedFlaggedIndex, imperativeVirtualizerRef } = props;
9
+ /* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/ const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);
10
+ // We use this ref as a constant source to access the virtualizer's state imperatively
11
+ const actualIndexRef = useRef(_virtualizerContext.contextIndex);
12
+ if (actualIndexRef.current !== _virtualizerContext.contextIndex) {
13
+ actualIndexRef.current = _virtualizerContext.contextIndex;
14
+ }
15
+ const flaggedIndex = useRef(null);
16
+ const actualIndex = _virtualizerContext.contextIndex;
17
+ const setActualIndex = _virtualizerContext.setContextIndex;
18
+ // Store ref to before padding element
19
+ const beforeElementRef = useRef(null);
20
+ // Store ref to before padding element
21
+ const afterElementRef = useRef(null);
22
+ // We need to store an array to track dynamic sizes, we can use this to incrementally update changes
23
+ const childSizes = useRef(new Array(getItemSize ? numItems : 0));
24
+ /* We keep track of the progressive sizing/placement down the list,
25
+ this helps us skip re-calculations unless children/size changes */ const childProgressiveSizes = useRef(new Array(getItemSize ? numItems : 0));
26
+ // The internal tracking REF for child array (updates often).
27
+ const childArray = useRef(new Array(virtualizerLength));
28
+ // We want to be methodical about updating the render with child reference array
29
+ const forceUpdate = useReducer(()=>({}), {})[1];
30
+ const horizontal = axis === 'horizontal';
31
+ const populateSizeArrays = ()=>{
32
+ if (!getItemSize) {
33
+ // Static sizes, never mind!
34
+ return;
35
+ }
36
+ if (numItems !== childSizes.current.length) {
37
+ childSizes.current = new Array(numItems);
38
+ }
39
+ if (numItems !== childProgressiveSizes.current.length) {
40
+ childProgressiveSizes.current = new Array(numItems);
41
+ }
42
+ for(let index = 0; index < numItems; index++){
43
+ childSizes.current[index] = getItemSize(index);
44
+ if (index === 0) {
45
+ childProgressiveSizes.current[index] = childSizes.current[index];
46
+ } else {
47
+ childProgressiveSizes.current[index] = childProgressiveSizes.current[index - 1] + childSizes.current[index];
48
+ }
49
+ }
50
+ };
51
+ const [isScrolling, setIsScrolling] = useState(false);
52
+ const [setScrollTimer, clearScrollTimer] = useTimeout();
53
+ const scrollCounter = useRef(0);
54
+ const initializeScrollingTimer = useCallback(()=>{
55
+ /*
56
+ * This can be considered the 'velocity' required to start 'isScrolling'
57
+ * INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling
58
+ * INIT_SCROLL_FLAG_DELAY: Amount of time (ms) before current number of renders is reset
59
+ * - Maybe we should let users customize these in the future.
60
+ */ const INIT_SCROLL_FLAG_REQ = 10;
61
+ const INIT_SCROLL_FLAG_DELAY = 100;
62
+ scrollCounter.current++;
63
+ if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {
64
+ setIsScrolling(true);
65
+ }
66
+ clearScrollTimer();
67
+ setScrollTimer(()=>{
68
+ setIsScrolling(false);
69
+ scrollCounter.current = 0;
70
+ }, INIT_SCROLL_FLAG_DELAY);
71
+ }, [
72
+ clearScrollTimer,
73
+ setScrollTimer
74
+ ]);
75
+ useEffect(()=>{
76
+ initializeScrollingTimer();
77
+ }, [
78
+ actualIndex,
79
+ initializeScrollingTimer
80
+ ]);
81
+ const batchUpdateNewIndex = (index)=>{
82
+ // Local updates
83
+ updateChildRows(index);
84
+ updateCurrentItemSizes(index);
85
+ // Set before 'setActualIndex' call
86
+ // If it changes before render, or injected via context, re-render will update ref.
87
+ actualIndexRef.current = index;
88
+ // State setters
89
+ setActualIndex(index);
90
+ };
91
+ // Observe intersections of virtualized components
92
+ const { setObserverList } = useIntersectionObserver(// TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286
93
+ // eslint-disable-next-line no-restricted-globals
94
+ (entries, observer)=>{
95
+ /* Sanity check - do we even need virtualization? */ if (virtualizerLength > numItems) {
96
+ if (actualIndex !== 0) {
97
+ batchUpdateNewIndex(0);
98
+ }
99
+ // No-op
100
+ return;
101
+ }
102
+ /* IO initiates this function when needed (bookend entering view) */ let measurementPos = 0;
103
+ let bufferCount = bufferItems;
104
+ // Grab latest entry that is intersecting
105
+ const latestEntry = entries.length === 1 ? entries[0] : entries.sort((entry1, entry2)=>entry2.time - entry1.time).find((entry)=>{
106
+ return entry.intersectionRatio > 0;
107
+ });
108
+ if (!latestEntry) {
109
+ // If we don't find an intersecting area, ignore for now.
110
+ return;
111
+ }
112
+ if (latestEntry.target === afterElementRef.current) {
113
+ // We need to inverse the buffer count
114
+ bufferCount = virtualizerLength - bufferItems;
115
+ measurementPos = reversed ? calculateAfter() : calculateTotalSize() - calculateAfter();
116
+ if (!horizontal) {
117
+ if (reversed) {
118
+ // Scrolling 'up' and hit the after element below
119
+ measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);
120
+ } else if (latestEntry.boundingClientRect.top < 0) {
121
+ // Scrolling 'down' and hit the after element above top: 0
122
+ measurementPos -= latestEntry.boundingClientRect.top;
123
+ }
124
+ } else {
125
+ if (reversed) {
126
+ // Scrolling 'left' and hit the after element
127
+ measurementPos -= Math.abs(latestEntry.boundingClientRect.right);
128
+ } else if (latestEntry.boundingClientRect.left < 0) {
129
+ // Scrolling 'right' and hit the after element
130
+ measurementPos -= latestEntry.boundingClientRect.left;
131
+ }
132
+ }
133
+ } else if (latestEntry.target === beforeElementRef.current) {
134
+ measurementPos = reversed ? calculateTotalSize() - calculateBefore() : calculateBefore();
135
+ if (!horizontal) {
136
+ if (!reversed) {
137
+ measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);
138
+ } else if (latestEntry.boundingClientRect.top < 0) {
139
+ // Scrolling 'down' in reverse order and hit the before element above top: 0
140
+ measurementPos -= latestEntry.boundingClientRect.top;
141
+ }
142
+ } else {
143
+ if (!reversed) {
144
+ measurementPos -= Math.abs(latestEntry.boundingClientRect.right);
145
+ } else if (latestEntry.boundingClientRect.left < 0) {
146
+ // Scrolling 'left' and hit before element
147
+ measurementPos -= latestEntry.boundingClientRect.left;
148
+ }
149
+ }
98
150
  }
99
- } else {
100
151
  if (reversed) {
101
- // Scrolling 'left' and hit the after element
102
- measurementPos -= Math.abs(latestEntry.boundingClientRect.right);
103
- } else if (latestEntry.boundingClientRect.left < 0) {
104
- // Scrolling 'right' and hit the after element
105
- measurementPos -= latestEntry.boundingClientRect.left;
106
- }
107
- }
108
- } else if (latestEntry.target === beforeElementRef.current) {
109
- measurementPos = reversed ? calculateTotalSize() - calculateBefore() : calculateBefore();
110
- if (!horizontal) {
111
- if (!reversed) {
112
- measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);
113
- } else if (latestEntry.boundingClientRect.top < 0) {
114
- // Scrolling 'down' in reverse order and hit the before element above top: 0
115
- measurementPos -= latestEntry.boundingClientRect.top;
116
- }
117
- } else {
118
- if (!reversed) {
119
- measurementPos -= Math.abs(latestEntry.boundingClientRect.right);
120
- } else if (latestEntry.boundingClientRect.left < 0) {
121
- // Scrolling 'left' and hit before element
122
- measurementPos -= latestEntry.boundingClientRect.left;
123
- }
124
- }
125
- }
126
- if (reversed) {
127
- // We're reversed, up is down, left is right, invert the scroll measure.
128
- measurementPos = Math.max(calculateTotalSize() - Math.abs(measurementPos), 0);
129
- }
130
- // For now lets use hardcoded size to assess current element to paginate on
131
- 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
- }
138
- // Safety limits
139
- const maxIndex = Math.max(numItems - virtualizerLength, 0);
140
- const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);
141
- if (virtualizerStartIndex !== newStartIndex) {
142
- // We flush sync this and perform an immediate state update
143
- // due to virtualizerStartIndex invalidation.
144
- flushSync(() => {
145
- batchUpdateNewIndex(newStartIndex);
146
- });
147
- }
148
- }, {
149
- root: intersectionObserverRoot ? intersectionObserverRoot === null || intersectionObserverRoot === void 0 ? void 0 : intersectionObserverRoot.current : null,
150
- rootMargin: '0px',
151
- threshold: 0
152
- });
153
- const findIndexRecursive = (scrollPos, lowIndex, highIndex) => {
154
- if (lowIndex > highIndex) {
155
- // We shouldn't get here - but no-op the index if we do.
156
- return virtualizerStartIndex;
157
- }
158
- const midpoint = Math.floor((lowIndex + highIndex) / 2);
159
- const iBefore = Math.max(midpoint - 1, 0);
160
- const iAfter = Math.min(midpoint + 1, childProgressiveSizes.current.length - 1);
161
- const indexValue = childProgressiveSizes.current[midpoint];
162
- const afterIndexValue = childProgressiveSizes.current[iAfter];
163
- const beforeIndexValue = childProgressiveSizes.current[iBefore];
164
- if (scrollPos <= afterIndexValue && scrollPos >= beforeIndexValue) {
165
- /* We've found our index - if we are exactly matching before/after index that's ok,
166
- better to reduce checks if it's right on the boundary. */
167
- return midpoint;
168
- }
169
- if (indexValue > scrollPos) {
170
- return findIndexRecursive(scrollPos, lowIndex, midpoint - 1);
171
- } else {
172
- return findIndexRecursive(scrollPos, midpoint + 1, highIndex);
173
- }
174
- };
175
- const getIndexFromSizeArray = scrollPos => {
176
- /* Quick searches our progressive height array */
177
- if (scrollPos === 0 || childProgressiveSizes.current.length === 0 || scrollPos <= childProgressiveSizes.current[0]) {
178
- // Check start
179
- return 0;
180
- }
181
- if (scrollPos >= childProgressiveSizes.current[childProgressiveSizes.current.length - 1]) {
182
- // Check end
183
- return childProgressiveSizes.current.length - 1;
184
- }
185
- return findIndexRecursive(scrollPos, 0, childProgressiveSizes.current.length - 1);
186
- };
187
- const getIndexFromScrollPosition = scrollPos => {
188
- if (!getItemSize) {
189
- return Math.round(scrollPos / itemSize);
190
- }
191
- return getIndexFromSizeArray(scrollPos);
192
- };
193
- const calculateTotalSize = () => {
194
- if (!getItemSize) {
195
- return itemSize * numItems;
196
- }
197
- // Time for custom size calcs
198
- return childProgressiveSizes.current[numItems - 1];
199
- };
200
- const calculateBefore = () => {
201
- if (!getItemSize) {
202
- // The missing items from before virtualization starts height
203
- return virtualizerStartIndex * itemSize;
204
- }
205
- if (virtualizerStartIndex <= 0) {
206
- return 0;
207
- }
208
- // Time for custom size calcs
209
- return childProgressiveSizes.current[virtualizerStartIndex - 1];
210
- };
211
- const calculateAfter = () => {
212
- if (numItems === 0) {
213
- return 0;
214
- }
215
- const lastItemIndex = Math.min(virtualizerStartIndex + virtualizerLength, numItems - 1);
216
- if (!getItemSize) {
217
- // The missing items from after virtualization ends height
218
- const remainingItems = numItems - lastItemIndex - 1;
219
- return remainingItems * itemSize;
220
- }
221
- // Time for custom size calcs
222
- return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex];
223
- };
224
- const updateChildRows = newIndex => {
225
- if (numItems === 0) {
226
- /* Nothing to virtualize */
227
- return [];
228
- }
229
- if (childArray.current.length !== numItems) {
230
- childArray.current = new Array(virtualizerLength);
231
- }
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);
236
- }
237
- };
238
- const setBeforeRef = useCallback(element => {
239
- if (!element || beforeElementRef.current === element) {
240
- return;
241
- }
242
- beforeElementRef.current = element;
243
- const newList = [];
244
- newList.push(beforeElementRef.current);
245
- if (afterElementRef.current) {
246
- newList.push(afterElementRef.current);
247
- }
248
- // Ensure we update array if before element changed
249
- setObserverList(newList);
250
- }, [setObserverList]);
251
- const setAfterRef = useCallback(element => {
252
- if (!element || afterElementRef.current === element) {
253
- return;
254
- }
255
- afterElementRef.current = element;
256
- const newList = [];
257
- if (beforeElementRef.current) {
258
- newList.push(beforeElementRef.current);
259
- }
260
- newList.push(afterElementRef.current);
261
- // Ensure we update array if after element changed
262
- setObserverList(newList);
263
- }, [setObserverList]);
264
- const updateCurrentItemSizes = newIndex => {
265
- if (!getItemSize) {
266
- // Static sizes, not required.
267
- return;
268
- }
269
- // We should always call our size function on index change (only for the items that will be rendered)
270
- // This ensures we request the latest data for incoming items in case sizing has changed.
271
- const endIndex = Math.min(newIndex + virtualizerLength, numItems);
272
- const startIndex = Math.max(newIndex, 0);
273
- let didUpdate = false;
274
- for (let i = startIndex; i < endIndex; i++) {
275
- const newSize = getItemSize(i);
276
- if (newSize !== childSizes.current[i]) {
277
- childSizes.current[i] = newSize;
278
- didUpdate = true;
279
- }
280
- }
281
- if (didUpdate) {
282
- // Update our progressive size array
283
- for (let i = startIndex; i < numItems; i++) {
284
- const prevSize = i > 0 ? childProgressiveSizes.current[i - 1] : 0;
285
- childProgressiveSizes.current[i] = prevSize + childSizes.current[i];
286
- }
287
- }
288
- };
289
- // Initialize the size array before first render.
290
- const hasInitialized = useRef(false);
291
- const initializeSizeArray = () => {
292
- if (hasInitialized.current === false) {
293
- hasInitialized.current = true;
294
- populateSizeArrays();
295
- }
296
- };
297
- // Initialization on mount - update array index to 0 (ready state).
298
- // Only fire on mount (no deps).
299
- useEffect(() => {
300
- if (virtualizerStartIndex < 0) {
301
- batchUpdateNewIndex(0);
302
- }
152
+ // We're reversed, up is down, left is right, invert the scroll measure.
153
+ measurementPos = Math.max(calculateTotalSize() - Math.abs(measurementPos), 0);
154
+ }
155
+ // For now lets use hardcoded size to assess current element to paginate on
156
+ const startIndex = getIndexFromScrollPosition(measurementPos);
157
+ const bufferedIndex = Math.max(startIndex - bufferCount, 0);
158
+ // Safety limits
159
+ const maxIndex = Math.max(numItems - virtualizerLength, 0);
160
+ const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);
161
+ if (actualIndex !== newStartIndex) {
162
+ // We flush sync this and perform an immediate state update
163
+ flushSync(()=>{
164
+ batchUpdateNewIndex(newStartIndex);
165
+ });
166
+ }
167
+ }, {
168
+ root: scrollViewRef ? scrollViewRef === null || scrollViewRef === void 0 ? void 0 : scrollViewRef.current : null,
169
+ rootMargin: '0px',
170
+ threshold: 0
171
+ });
172
+ const findIndexRecursive = (scrollPos, lowIndex, highIndex)=>{
173
+ if (lowIndex > highIndex) {
174
+ // We shouldn't get here - but no-op the index if we do.
175
+ return actualIndex;
176
+ }
177
+ const midpoint = Math.floor((lowIndex + highIndex) / 2);
178
+ const iBefore = Math.max(midpoint - 1, 0);
179
+ const iAfter = Math.min(midpoint + 1, childProgressiveSizes.current.length - 1);
180
+ const indexValue = childProgressiveSizes.current[midpoint];
181
+ const afterIndexValue = childProgressiveSizes.current[iAfter];
182
+ const beforeIndexValue = childProgressiveSizes.current[iBefore];
183
+ if (scrollPos <= afterIndexValue && scrollPos >= beforeIndexValue) {
184
+ /* We've found our index - if we are exactly matching before/after index that's ok,
185
+ better to reduce checks if it's right on the boundary. */ return midpoint;
186
+ }
187
+ if (indexValue > scrollPos) {
188
+ return findIndexRecursive(scrollPos, lowIndex, midpoint - 1);
189
+ } else {
190
+ return findIndexRecursive(scrollPos, midpoint + 1, highIndex);
191
+ }
192
+ };
193
+ const getIndexFromSizeArray = (scrollPos)=>{
194
+ /* Quick searches our progressive height array */ if (scrollPos === 0 || childProgressiveSizes.current.length === 0 || scrollPos <= childProgressiveSizes.current[0]) {
195
+ // Check start
196
+ return 0;
197
+ }
198
+ if (scrollPos >= childProgressiveSizes.current[childProgressiveSizes.current.length - 1]) {
199
+ // Check end
200
+ return childProgressiveSizes.current.length - 1;
201
+ }
202
+ return findIndexRecursive(scrollPos, 0, childProgressiveSizes.current.length - 1);
203
+ };
204
+ const getIndexFromScrollPosition = (scrollPos)=>{
205
+ if (!getItemSize) {
206
+ return Math.round(scrollPos / itemSize);
207
+ }
208
+ return getIndexFromSizeArray(scrollPos);
209
+ };
210
+ const calculateTotalSize = useCallback(()=>{
211
+ if (!getItemSize) {
212
+ return itemSize * numItems;
213
+ }
214
+ // Time for custom size calcs
215
+ return childProgressiveSizes.current[numItems - 1];
216
+ }, [
217
+ getItemSize,
218
+ itemSize,
219
+ numItems
220
+ ]);
221
+ const calculateBefore = useCallback(()=>{
222
+ const currentIndex = Math.min(actualIndex, numItems - 1);
223
+ if (!getItemSize) {
224
+ // The missing items from before virtualization starts height
225
+ return currentIndex * itemSize;
226
+ }
227
+ if (currentIndex <= 0) {
228
+ return 0;
229
+ }
230
+ // Time for custom size calcs
231
+ return childProgressiveSizes.current[currentIndex - 1];
232
+ }, [
233
+ actualIndex,
234
+ getItemSize,
235
+ itemSize,
236
+ numItems
237
+ ]);
238
+ const calculateAfter = useCallback(()=>{
239
+ if (numItems === 0 || actualIndex + virtualizerLength >= numItems) {
240
+ return 0;
241
+ }
242
+ const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems);
243
+ if (!getItemSize) {
244
+ // The missing items from after virtualization ends height
245
+ const remainingItems = numItems - lastItemIndex;
246
+ return remainingItems * itemSize;
247
+ }
248
+ // Time for custom size calcs
249
+ return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex - 1];
250
+ }, [
251
+ actualIndex,
252
+ getItemSize,
253
+ itemSize,
254
+ numItems,
255
+ virtualizerLength
256
+ ]);
257
+ const updateChildRows = useCallback((newIndex)=>{
258
+ if (numItems === 0) {
259
+ /* Nothing to virtualize */ return;
260
+ }
261
+ /*
262
+ We reset the array every time to ensure children are re-rendered
263
+ This function should only be called when update is nessecary
264
+ */ childArray.current = new Array(virtualizerLength);
265
+ const _actualIndex = Math.max(newIndex, 0);
266
+ const end = Math.min(_actualIndex + virtualizerLength, numItems);
267
+ for(let i = _actualIndex; i < end; i++){
268
+ childArray.current[i - _actualIndex] = renderChild(i, isScrolling);
269
+ }
270
+ }, [
271
+ isScrolling,
272
+ numItems,
273
+ renderChild,
274
+ virtualizerLength
275
+ ]);
276
+ const setBeforeRef = useCallback((element)=>{
277
+ if (!element || beforeElementRef.current === element) {
278
+ return;
279
+ }
280
+ beforeElementRef.current = element;
281
+ const newList = [];
282
+ newList.push(beforeElementRef.current);
283
+ if (afterElementRef.current) {
284
+ newList.push(afterElementRef.current);
285
+ }
286
+ // Ensure we update array if before element changed
287
+ setObserverList(newList);
288
+ }, [
289
+ setObserverList
290
+ ]);
291
+ const setAfterRef = useCallback((element)=>{
292
+ if (!element || afterElementRef.current === element) {
293
+ return;
294
+ }
295
+ afterElementRef.current = element;
296
+ const newList = [];
297
+ if (beforeElementRef.current) {
298
+ newList.push(beforeElementRef.current);
299
+ }
300
+ newList.push(afterElementRef.current);
301
+ // Ensure we update array if after element changed
302
+ setObserverList(newList);
303
+ }, [
304
+ setObserverList
305
+ ]);
306
+ const updateCurrentItemSizes = (newIndex)=>{
307
+ if (!getItemSize) {
308
+ // Static sizes, not required.
309
+ return;
310
+ }
311
+ // We should always call our size function on index change (only for the items that will be rendered)
312
+ // This ensures we request the latest data for incoming items in case sizing has changed.
313
+ const endIndex = Math.min(newIndex + virtualizerLength, numItems);
314
+ const startIndex = Math.max(newIndex, 0);
315
+ let didUpdate = false;
316
+ for(let i = startIndex; i < endIndex; i++){
317
+ const newSize = getItemSize(i);
318
+ if (newSize !== childSizes.current[i]) {
319
+ childSizes.current[i] = newSize;
320
+ didUpdate = true;
321
+ }
322
+ }
323
+ if (didUpdate) {
324
+ // Update our progressive size array
325
+ for(let i = startIndex; i < numItems; i++){
326
+ const prevSize = i > 0 ? childProgressiveSizes.current[i - 1] : 0;
327
+ childProgressiveSizes.current[i] = prevSize + childSizes.current[i];
328
+ }
329
+ }
330
+ };
331
+ // Initialize the size array before first render.
332
+ const hasInitialized = useRef(false);
333
+ const initializeSizeArray = ()=>{
334
+ if (hasInitialized.current === false) {
335
+ hasInitialized.current = true;
336
+ populateSizeArrays();
337
+ }
338
+ };
339
+ useImperativeHandle(imperativeVirtualizerRef, ()=>{
340
+ return {
341
+ progressiveSizes: childProgressiveSizes,
342
+ nodeSizes: childSizes,
343
+ setFlaggedIndex: (index)=>flaggedIndex.current = index,
344
+ currentIndex: actualIndexRef
345
+ };
346
+ }, [
347
+ childProgressiveSizes,
348
+ childSizes
349
+ ]);
350
+ // Initialization on mount - update array index to 0 (ready state).
351
+ // Only fire on mount (no deps).
352
+ useEffect(()=>{
353
+ if (actualIndex < 0) {
354
+ batchUpdateNewIndex(0);
355
+ }
303
356
  // eslint-disable-next-line react-hooks/exhaustive-deps
304
- }, []);
305
- // If the user passes in an updated renderChild function - update current children
306
- useEffect(() => {
307
- if (virtualizerStartIndex >= 0) {
308
- updateChildRows(virtualizerStartIndex);
309
- forceUpdate();
310
- }
357
+ }, []);
358
+ // If the user passes in an updated renderChild function - update current children
359
+ useEffect(()=>{
360
+ if (actualIndex >= 0) {
361
+ updateChildRows(actualIndex);
362
+ forceUpdate();
363
+ }
364
+ // eslint-disable-next-line react-hooks/exhaustive-deps
365
+ }, [
366
+ renderChild,
367
+ updateChildRows
368
+ ]);
369
+ useEffect(()=>{
370
+ // Ensure we repopulate if getItemSize callback changes
371
+ populateSizeArrays();
372
+ // We only run this effect on getItemSize change (recalc dynamic sizes)
311
373
  // eslint-disable-next-line react-hooks/exhaustive-deps
312
- }, [renderChild]);
313
- // Ensure we have run through and updated the whole size list array at least once.
314
- initializeSizeArray();
315
- if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {
316
- // Child length mismatch, repopulate size arrays.
317
- populateSizeArrays();
318
- }
319
- const isFullyInitialized = hasInitialized.current && virtualizerStartIndex >= 0;
320
- return {
321
- components: {
322
- before: 'div',
323
- after: 'div',
324
- beforeContainer: 'div',
325
- afterContainer: 'div'
326
- },
327
- virtualizedChildren: childArray.current,
328
- before: resolveShorthand(props.before, {
329
- required: true,
330
- defaultProps: {
331
- ref: setBeforeRef,
332
- role: 'none'
333
- }
334
- }),
335
- after: resolveShorthand(props.after, {
336
- required: true,
337
- defaultProps: {
338
- ref: setAfterRef,
339
- role: 'none'
340
- }
341
- }),
342
- beforeContainer: resolveShorthand(props.beforeContainer, {
343
- required: true,
344
- defaultProps: {
345
- role: 'none'
346
- }
347
- }),
348
- afterContainer: resolveShorthand(props.afterContainer, {
349
- required: true,
350
- defaultProps: {
351
- role: 'none'
352
- }
353
- }),
354
- beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,
355
- afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,
356
- totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,
357
- virtualizerStartIndex,
358
- axis,
359
- bufferSize,
360
- reversed
361
- };
374
+ }, [
375
+ getItemSize
376
+ ]);
377
+ // Effect to check flag index on updates
378
+ useEffect(()=>{
379
+ if (!onRenderedFlaggedIndex || flaggedIndex.current === null) {
380
+ return;
381
+ }
382
+ if (actualIndex <= flaggedIndex.current && actualIndex + virtualizerLength >= flaggedIndex.current) {
383
+ onRenderedFlaggedIndex(flaggedIndex.current);
384
+ flaggedIndex.current = null;
385
+ }
386
+ }, [
387
+ actualIndex,
388
+ onRenderedFlaggedIndex,
389
+ virtualizerLength
390
+ ]);
391
+ // Ensure we have run through and updated the whole size list array at least once.
392
+ initializeSizeArray();
393
+ if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {
394
+ // Child length mismatch, repopulate size arrays.
395
+ populateSizeArrays();
396
+ }
397
+ // Ensure we recalc if virtualizer length changes
398
+ const maxCompare = Math.min(virtualizerLength, numItems);
399
+ if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {
400
+ updateChildRows(actualIndex);
401
+ }
402
+ const isFullyInitialized = hasInitialized.current && actualIndex >= 0;
403
+ return {
404
+ components: {
405
+ before: 'div',
406
+ after: 'div',
407
+ beforeContainer: 'div',
408
+ afterContainer: 'div'
409
+ },
410
+ virtualizedChildren: childArray.current,
411
+ before: slot.always(props.before, {
412
+ defaultProps: {
413
+ ref: setBeforeRef,
414
+ role: 'none'
415
+ },
416
+ elementType: 'div'
417
+ }),
418
+ after: slot.always(props.after, {
419
+ defaultProps: {
420
+ ref: setAfterRef,
421
+ role: 'none'
422
+ },
423
+ elementType: 'div'
424
+ }),
425
+ beforeContainer: slot.always(props.beforeContainer, {
426
+ defaultProps: {
427
+ role: 'none'
428
+ },
429
+ elementType: 'div'
430
+ }),
431
+ afterContainer: slot.always(props.afterContainer, {
432
+ defaultProps: {
433
+ role: 'none'
434
+ },
435
+ elementType: 'div'
436
+ }),
437
+ beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,
438
+ afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,
439
+ totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,
440
+ virtualizerStartIndex: actualIndex,
441
+ axis,
442
+ bufferSize,
443
+ reversed,
444
+ childSizes,
445
+ childProgressiveSizes
446
+ };
362
447
  }
363
- //# sourceMappingURL=useVirtualizer.js.map