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