@fluentui/react-virtualizer 9.0.0-alpha.75 → 9.0.0-alpha.76
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 +11 -2
- package/lib/components/Virtualizer/useVirtualizer.js +11 -9
- package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib/hooks/useDynamicPagination.js +8 -9
- package/lib/hooks/useDynamicPagination.js.map +1 -1
- package/lib/hooks/useIntersectionObserver.js +7 -3
- package/lib/hooks/useIntersectionObserver.js.map +1 -1
- package/lib/hooks/useStaticPagination.js +8 -9
- package/lib/hooks/useStaticPagination.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js +10 -8
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib-commonjs/hooks/useDynamicPagination.js +8 -9
- package/lib-commonjs/hooks/useDynamicPagination.js.map +1 -1
- package/lib-commonjs/hooks/useIntersectionObserver.js +7 -3
- package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
- package/lib-commonjs/hooks/useStaticPagination.js +8 -9
- package/lib-commonjs/hooks/useStaticPagination.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-virtualizer
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 02 May 2024 11:31:37 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.0.0-alpha.76](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.76)
|
|
8
|
+
|
|
9
|
+
Thu, 02 May 2024 11:31:37 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.75..@fluentui/react-virtualizer_v9.0.0-alpha.76)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
- Fix: Use Fluent hooks for IO and timeout functionality ([PR #31250](https://github.com/microsoft/fluentui/pull/31250) by mifraser@microsoft.com)
|
|
15
|
+
|
|
7
16
|
## [9.0.0-alpha.75](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.75)
|
|
8
17
|
|
|
9
|
-
Tue, 23 Apr 2024 08:
|
|
18
|
+
Tue, 23 Apr 2024 08:17:49 GMT
|
|
10
19
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.74..@fluentui/react-virtualizer_v9.0.0-alpha.75)
|
|
11
20
|
|
|
12
21
|
### Changes
|
|
@@ -2,7 +2,7 @@ import { useEffect, useRef, useCallback, useReducer, useImperativeHandle, useSta
|
|
|
2
2
|
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
|
|
3
3
|
import { flushSync } from 'react-dom';
|
|
4
4
|
import { useVirtualizerContextState_unstable } from '../../Utilities';
|
|
5
|
-
import { slot } from '@fluentui/react-utilities';
|
|
5
|
+
import { slot, useTimeout } from '@fluentui/react-utilities';
|
|
6
6
|
export function useVirtualizer_unstable(props) {
|
|
7
7
|
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;
|
|
8
8
|
/* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/ const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);
|
|
@@ -48,9 +48,9 @@ export function useVirtualizer_unstable(props) {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
const [isScrolling, setIsScrolling] = useState(false);
|
|
51
|
-
const
|
|
51
|
+
const [setScrollTimer, clearScrollTimer] = useTimeout();
|
|
52
52
|
const scrollCounter = useRef(0);
|
|
53
|
-
const initializeScrollingTimer = ()=>{
|
|
53
|
+
const initializeScrollingTimer = useCallback(()=>{
|
|
54
54
|
/*
|
|
55
55
|
* This can be considered the 'velocity' required to start 'isScrolling'
|
|
56
56
|
* INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling
|
|
@@ -62,18 +62,20 @@ export function useVirtualizer_unstable(props) {
|
|
|
62
62
|
if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {
|
|
63
63
|
setIsScrolling(true);
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
scrollTimer.current = setTimeout(()=>{
|
|
65
|
+
clearScrollTimer();
|
|
66
|
+
setScrollTimer(()=>{
|
|
69
67
|
setIsScrolling(false);
|
|
70
68
|
scrollCounter.current = 0;
|
|
71
69
|
}, INIT_SCROLL_FLAG_DELAY);
|
|
72
|
-
}
|
|
70
|
+
}, [
|
|
71
|
+
clearScrollTimer,
|
|
72
|
+
setScrollTimer
|
|
73
|
+
]);
|
|
73
74
|
useEffect(()=>{
|
|
74
75
|
initializeScrollingTimer();
|
|
75
76
|
}, [
|
|
76
|
-
actualIndex
|
|
77
|
+
actualIndex,
|
|
78
|
+
initializeScrollingTimer
|
|
77
79
|
]);
|
|
78
80
|
const batchUpdateNewIndex = (index)=>{
|
|
79
81
|
// Local updates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useVirtualizer.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { VirtualizerProps, VirtualizerState } from './Virtualizer.types';\n\nimport { useEffect, useRef, useCallback, useReducer, useImperativeHandle, useState } from 'react';\nimport { useIntersectionObserver } from '../../hooks/useIntersectionObserver';\nimport { flushSync } from 'react-dom';\nimport { useVirtualizerContextState_unstable } from '../../Utilities';\nimport { slot } from '@fluentui/react-utilities';\n\nexport function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerState {\n const {\n itemSize,\n numItems,\n virtualizerLength,\n children: renderChild,\n getItemSize,\n bufferItems = Math.round(virtualizerLength / 4.0),\n bufferSize = Math.floor(bufferItems / 2.0) * itemSize,\n scrollViewRef,\n axis = 'vertical',\n reversed = false,\n virtualizerContext,\n onRenderedFlaggedIndex,\n imperativeVirtualizerRef,\n } = props;\n\n /* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/\n const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);\n\n // We use this ref as a constant source to access the virtualizer's state imperatively\n const actualIndexRef = useRef<number>(_virtualizerContext.contextIndex);\n if (actualIndexRef.current !== _virtualizerContext.contextIndex) {\n actualIndexRef.current = _virtualizerContext.contextIndex;\n }\n const flaggedIndex = useRef<number | null>(null);\n\n const actualIndex = _virtualizerContext.contextIndex;\n const setActualIndex = _virtualizerContext.setContextIndex;\n\n // Store ref to before padding element\n const beforeElementRef = useRef<Element | null>(null);\n\n // Store ref to before padding element\n const afterElementRef = useRef<Element | null>(null);\n\n // We need to store an array to track dynamic sizes, we can use this to incrementally update changes\n const childSizes = useRef<number[]>(new Array<number>(getItemSize ? numItems : 0));\n\n /* We keep track of the progressive sizing/placement down the list,\n this helps us skip re-calculations unless children/size changes */\n const childProgressiveSizes = useRef<number[]>(new Array<number>(getItemSize ? numItems : 0));\n\n // The internal tracking REF for child array (updates often).\n const childArray = useRef<ReactNode[]>(new Array(virtualizerLength));\n\n // We want to be methodical about updating the render with child reference array\n const forceUpdate = useReducer(() => ({}), {})[1];\n\n const horizontal = axis === 'horizontal';\n\n const populateSizeArrays = () => {\n if (!getItemSize) {\n // Static sizes, never mind!\n return;\n }\n\n if (numItems !== childSizes.current.length) {\n childSizes.current = new Array<number>(numItems);\n }\n\n if (numItems !== childProgressiveSizes.current.length) {\n childProgressiveSizes.current = new Array<number>(numItems);\n }\n\n for (let index = 0; index < numItems; index++) {\n childSizes.current[index] = getItemSize(index);\n if (index === 0) {\n childProgressiveSizes.current[index] = childSizes.current[index];\n } else {\n childProgressiveSizes.current[index] = childProgressiveSizes.current[index - 1] + childSizes.current[index];\n }\n }\n };\n\n const [isScrolling, setIsScrolling] = useState<boolean>(false);\n const scrollTimer = useRef<ReturnType<typeof setTimeout> | null>();\n const scrollCounter = useRef<number>(0);\n\n const initializeScrollingTimer = () => {\n /*\n * This can be considered the 'velocity' required to start 'isScrolling'\n * INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling\n * INIT_SCROLL_FLAG_DELAY: Amount of time (ms) before current number of renders is reset\n * - Maybe we should let users customize these in the future.\n */\n const INIT_SCROLL_FLAG_REQ = 10;\n const INIT_SCROLL_FLAG_DELAY = 100;\n\n scrollCounter.current++;\n if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {\n setIsScrolling(true);\n }\n if (scrollTimer.current) {\n clearTimeout(scrollTimer.current);\n }\n scrollTimer.current = setTimeout(() => {\n setIsScrolling(false);\n scrollCounter.current = 0;\n }, INIT_SCROLL_FLAG_DELAY);\n };\n\n useEffect(() => {\n initializeScrollingTimer();\n }, [actualIndex]);\n\n const batchUpdateNewIndex = (index: number) => {\n // Local updates\n updateChildRows(index);\n updateCurrentItemSizes(index);\n\n // Set before 'setActualIndex' call\n // If it changes before render, or injected via context, re-render will update ref.\n actualIndexRef.current = index;\n\n // State setters\n setActualIndex(index);\n };\n\n // Observe intersections of virtualized components\n const { setObserverList } = useIntersectionObserver(\n (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => {\n /* Sanity check - do we even need virtualization? */\n if (virtualizerLength > numItems) {\n if (actualIndex !== 0) {\n batchUpdateNewIndex(0);\n }\n // No-op\n return;\n }\n\n /* IO initiates this function when needed (bookend entering view) */\n let measurementPos = 0;\n let bufferCount = bufferItems;\n\n // Grab latest entry that is intersecting\n const latestEntry =\n entries.length === 1\n ? entries[0]\n : entries\n .sort((entry1, entry2) => entry2.time - entry1.time)\n .find(entry => {\n return entry.intersectionRatio > 0;\n });\n\n if (!latestEntry) {\n // If we don't find an intersecting area, ignore for now.\n return;\n }\n\n if (latestEntry.target === afterElementRef.current) {\n // We need to inverse the buffer count\n bufferCount = virtualizerLength - bufferItems;\n measurementPos = reversed ? calculateAfter() : calculateTotalSize() - calculateAfter();\n if (!horizontal) {\n if (reversed) {\n // Scrolling 'up' and hit the after element below\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' and hit the after element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (reversed) {\n // Scrolling 'left' and hit the after element\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'right' and hit the after element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n } else if (latestEntry.target === beforeElementRef.current) {\n measurementPos = reversed ? calculateTotalSize() - calculateBefore() : calculateBefore();\n if (!horizontal) {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' in reverse order and hit the before element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'left' and hit before element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n }\n\n if (reversed) {\n // We're reversed, up is down, left is right, invert the scroll measure.\n measurementPos = Math.max(calculateTotalSize() - Math.abs(measurementPos), 0);\n }\n\n // For now lets use hardcoded size to assess current element to paginate on\n const startIndex = getIndexFromScrollPosition(measurementPos);\n const bufferedIndex = Math.max(startIndex - bufferCount, 0);\n\n // Safety limits\n const maxIndex = Math.max(numItems - virtualizerLength, 0);\n const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);\n\n if (actualIndex !== newStartIndex) {\n // We flush sync this and perform an immediate state update\n flushSync(() => {\n batchUpdateNewIndex(newStartIndex);\n });\n }\n },\n {\n root: scrollViewRef ? scrollViewRef?.current : null,\n rootMargin: '0px',\n threshold: 0,\n },\n );\n\n const findIndexRecursive = (scrollPos: number, lowIndex: number, highIndex: number): number => {\n if (lowIndex > highIndex) {\n // We shouldn't get here - but no-op the index if we do.\n return actualIndex;\n }\n const midpoint = Math.floor((lowIndex + highIndex) / 2);\n const iBefore = Math.max(midpoint - 1, 0);\n const iAfter = Math.min(midpoint + 1, childProgressiveSizes.current.length - 1);\n const indexValue = childProgressiveSizes.current[midpoint];\n const afterIndexValue = childProgressiveSizes.current[iAfter];\n const beforeIndexValue = childProgressiveSizes.current[iBefore];\n if (scrollPos <= afterIndexValue && scrollPos >= beforeIndexValue) {\n /* We've found our index - if we are exactly matching before/after index that's ok,\n better to reduce checks if it's right on the boundary. */\n return midpoint;\n }\n\n if (indexValue > scrollPos) {\n return findIndexRecursive(scrollPos, lowIndex, midpoint - 1);\n } else {\n return findIndexRecursive(scrollPos, midpoint + 1, highIndex);\n }\n };\n\n const getIndexFromSizeArray = (scrollPos: number): number => {\n /* Quick searches our progressive height array */\n if (\n scrollPos === 0 ||\n childProgressiveSizes.current.length === 0 ||\n scrollPos <= childProgressiveSizes.current[0]\n ) {\n // Check start\n return 0;\n }\n\n if (scrollPos >= childProgressiveSizes.current[childProgressiveSizes.current.length - 1]) {\n // Check end\n return childProgressiveSizes.current.length - 1;\n }\n\n return findIndexRecursive(scrollPos, 0, childProgressiveSizes.current.length - 1);\n };\n\n const getIndexFromScrollPosition = (scrollPos: number) => {\n if (!getItemSize) {\n return Math.round(scrollPos / itemSize);\n }\n\n return getIndexFromSizeArray(scrollPos);\n };\n\n const calculateTotalSize = useCallback(() => {\n if (!getItemSize) {\n return itemSize * numItems;\n }\n\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1];\n }, [getItemSize, itemSize, numItems]);\n\n const calculateBefore = useCallback(() => {\n const currentIndex = Math.min(actualIndex, numItems - 1);\n\n if (!getItemSize) {\n // The missing items from before virtualization starts height\n return currentIndex * itemSize;\n }\n\n if (currentIndex <= 0) {\n return 0;\n }\n\n // Time for custom size calcs\n return childProgressiveSizes.current[currentIndex - 1];\n }, [actualIndex, getItemSize, itemSize, numItems]);\n\n const calculateAfter = useCallback(() => {\n if (numItems === 0 || actualIndex + virtualizerLength >= numItems) {\n return 0;\n }\n\n const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems);\n if (!getItemSize) {\n // The missing items from after virtualization ends height\n const remainingItems = numItems - lastItemIndex;\n return remainingItems * itemSize;\n }\n\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex - 1];\n }, [actualIndex, getItemSize, itemSize, numItems, virtualizerLength]);\n\n const updateChildRows = useCallback(\n (newIndex: number) => {\n if (numItems === 0) {\n /* Nothing to virtualize */\n return;\n }\n\n /*\n We reset the array every time to ensure children are re-rendered\n This function should only be called when update is nessecary\n */\n childArray.current = new Array(virtualizerLength);\n const _actualIndex = Math.max(newIndex, 0);\n const end = Math.min(_actualIndex + virtualizerLength, numItems);\n for (let i = _actualIndex; i < end; i++) {\n childArray.current[i - _actualIndex] = renderChild(i, isScrolling);\n }\n },\n [isScrolling, numItems, renderChild, virtualizerLength],\n );\n\n const setBeforeRef = useCallback(\n (element: HTMLDivElement) => {\n if (!element || beforeElementRef.current === element) {\n return;\n }\n beforeElementRef.current = element;\n const newList = [];\n\n newList.push(beforeElementRef.current);\n\n if (afterElementRef.current) {\n newList.push(afterElementRef.current);\n }\n\n // Ensure we update array if before element changed\n setObserverList(newList);\n },\n [setObserverList],\n );\n\n const setAfterRef = useCallback(\n (element: HTMLDivElement) => {\n if (!element || afterElementRef.current === element) {\n return;\n }\n afterElementRef.current = element;\n const newList = [];\n\n if (beforeElementRef.current) {\n newList.push(beforeElementRef.current);\n }\n\n newList.push(afterElementRef.current);\n\n // Ensure we update array if after element changed\n setObserverList(newList);\n },\n [setObserverList],\n );\n\n const updateCurrentItemSizes = (newIndex: number) => {\n if (!getItemSize) {\n // Static sizes, not required.\n return;\n }\n // We should always call our size function on index change (only for the items that will be rendered)\n // This ensures we request the latest data for incoming items in case sizing has changed.\n const endIndex = Math.min(newIndex + virtualizerLength, numItems);\n const startIndex = Math.max(newIndex, 0);\n\n let didUpdate = false;\n for (let i = startIndex; i < endIndex; i++) {\n const newSize = getItemSize(i);\n if (newSize !== childSizes.current[i]) {\n childSizes.current[i] = newSize;\n didUpdate = true;\n }\n }\n\n if (didUpdate) {\n // Update our progressive size array\n for (let i = startIndex; i < numItems; i++) {\n const prevSize = i > 0 ? childProgressiveSizes.current[i - 1] : 0;\n childProgressiveSizes.current[i] = prevSize + childSizes.current[i];\n }\n }\n };\n\n // Initialize the size array before first render.\n const hasInitialized = useRef<boolean>(false);\n const initializeSizeArray = () => {\n if (hasInitialized.current === false) {\n hasInitialized.current = true;\n populateSizeArrays();\n }\n };\n\n useImperativeHandle(\n imperativeVirtualizerRef,\n () => {\n return {\n progressiveSizes: childProgressiveSizes,\n nodeSizes: childSizes,\n setFlaggedIndex: (index: number | null) => (flaggedIndex.current = index),\n currentIndex: actualIndexRef,\n };\n },\n [childProgressiveSizes, childSizes],\n );\n\n // Initialization on mount - update array index to 0 (ready state).\n // Only fire on mount (no deps).\n useEffect(() => {\n if (actualIndex < 0) {\n batchUpdateNewIndex(0);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // If the user passes in an updated renderChild function - update current children\n useEffect(() => {\n if (actualIndex >= 0) {\n updateChildRows(actualIndex);\n forceUpdate();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [renderChild, updateChildRows]);\n\n useEffect(() => {\n // Ensure we repopulate if getItemSize callback changes\n populateSizeArrays();\n\n // We only run this effect on getItemSize change (recalc dynamic sizes)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getItemSize]);\n\n // Effect to check flag index on updates\n useEffect(() => {\n if (!onRenderedFlaggedIndex || flaggedIndex.current === null) {\n return;\n }\n if (actualIndex <= flaggedIndex.current && actualIndex + virtualizerLength >= flaggedIndex.current) {\n onRenderedFlaggedIndex(flaggedIndex.current);\n flaggedIndex.current = null;\n }\n }, [actualIndex, onRenderedFlaggedIndex, virtualizerLength]);\n\n // Ensure we have run through and updated the whole size list array at least once.\n initializeSizeArray();\n\n if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {\n // Child length mismatch, repopulate size arrays.\n populateSizeArrays();\n }\n\n // Ensure we recalc if virtualizer length changes\n const maxCompare = Math.min(virtualizerLength, numItems);\n if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {\n updateChildRows(actualIndex);\n }\n\n const isFullyInitialized = hasInitialized.current && actualIndex >= 0;\n return {\n components: {\n before: 'div',\n after: 'div',\n beforeContainer: 'div',\n afterContainer: 'div',\n },\n virtualizedChildren: childArray.current,\n before: slot.always(props.before, {\n defaultProps: {\n ref: setBeforeRef,\n role: 'none',\n },\n elementType: 'div',\n }),\n after: slot.always(props.after, {\n defaultProps: {\n ref: setAfterRef,\n role: 'none',\n },\n elementType: 'div',\n }),\n beforeContainer: slot.always(props.beforeContainer, {\n defaultProps: {\n role: 'none',\n },\n elementType: 'div',\n }),\n afterContainer: slot.always(props.afterContainer, {\n defaultProps: {\n role: 'none',\n },\n elementType: 'div',\n }),\n beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,\n afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,\n totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,\n virtualizerStartIndex: actualIndex,\n axis,\n bufferSize,\n reversed,\n childSizes,\n childProgressiveSizes,\n };\n}\n"],"names":["useEffect","useRef","useCallback","useReducer","useImperativeHandle","useState","useIntersectionObserver","flushSync","useVirtualizerContextState_unstable","slot","useVirtualizer_unstable","props","itemSize","numItems","virtualizerLength","children","renderChild","getItemSize","bufferItems","Math","round","bufferSize","floor","scrollViewRef","axis","reversed","virtualizerContext","onRenderedFlaggedIndex","imperativeVirtualizerRef","_virtualizerContext","actualIndexRef","contextIndex","current","flaggedIndex","actualIndex","setActualIndex","setContextIndex","beforeElementRef","afterElementRef","childSizes","Array","childProgressiveSizes","childArray","forceUpdate","horizontal","populateSizeArrays","length","index","isScrolling","setIsScrolling","scrollTimer","scrollCounter","initializeScrollingTimer","INIT_SCROLL_FLAG_REQ","INIT_SCROLL_FLAG_DELAY","clearTimeout","setTimeout","batchUpdateNewIndex","updateChildRows","updateCurrentItemSizes","setObserverList","entries","observer","measurementPos","bufferCount","latestEntry","sort","entry1","entry2","time","find","entry","intersectionRatio","target","calculateAfter","calculateTotalSize","abs","boundingClientRect","bottom","top","right","left","calculateBefore","max","startIndex","getIndexFromScrollPosition","bufferedIndex","maxIndex","newStartIndex","min","root","rootMargin","threshold","findIndexRecursive","scrollPos","lowIndex","highIndex","midpoint","iBefore","iAfter","indexValue","afterIndexValue","beforeIndexValue","getIndexFromSizeArray","currentIndex","lastItemIndex","remainingItems","newIndex","_actualIndex","end","i","setBeforeRef","element","newList","push","setAfterRef","endIndex","didUpdate","newSize","prevSize","hasInitialized","initializeSizeArray","progressiveSizes","nodeSizes","setFlaggedIndex","maxCompare","isFullyInitialized","components","before","after","beforeContainer","afterContainer","virtualizedChildren","always","defaultProps","ref","role","elementType","beforeBufferHeight","afterBufferHeight","totalVirtualizerHeight","virtualizerStartIndex"],"mappings":"AAGA,SAASA,SAAS,EAAEC,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAEC,mBAAmB,EAAEC,QAAQ,QAAQ,QAAQ;AAClG,SAASC,uBAAuB,QAAQ,sCAAsC;AAC9E,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,mCAAmC,QAAQ,kBAAkB;AACtE,SAASC,IAAI,QAAQ,4BAA4B;AAEjD,OAAO,SAASC,wBAAwBC,KAAuB;IAC7D,MAAM,EACJC,QAAQ,EACRC,QAAQ,EACRC,iBAAiB,EACjBC,UAAUC,WAAW,EACrBC,WAAW,EACXC,cAAcC,KAAKC,KAAK,CAACN,oBAA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mBD;IAC/C,IAAI6B,WAAWV,OAAO,CAACc,MAAM,KAAK+E,cAAc3F,cAAcQ,WAAWV,OAAO,CAACc,MAAM,GAAGjC,UAAU;QAClG6C,gBAAgBxB;IAClB;IAEA,MAAM4F,qBAAqBN,eAAexF,OAAO,IAAIE,eAAe;IACpE,OAAO;QACL6F,YAAY;YACVC,QAAQ;YACRC,OAAO;YACPC,iBAAiB;YACjBC,gBAAgB;QAClB;QACAC,qBAAqB1F,WAAWV,OAAO;QACvCgG,QAAQvH,KAAK4H,MAAM,CAAC1H,MAAMqH,MAAM,EAAE;YAChCM,cAAc;gBACZC,KAAKxB;gBACLyB,MAAM;YACR;YACAC,aAAa;QACf;QACAR,OAAOxH,KAAK4H,MAAM,CAAC1H,MAAMsH,KAAK,EAAE;YAC9BK,cAAc;gBACZC,KAAKpB;gBACLqB,MAAM;YACR;YACAC,aAAa;QACf;QACAP,iBAAiBzH,KAAK4H,MAAM,CAAC1H,MAAMuH,eAAe,EAAE;YAClDI,cAAc;gBACZE,MAAM;YACR;YACAC,aAAa;QACf;QACAN,gBAAgB1H,KAAK4H,MAAM,CAAC1H,MAAMwH,cAAc,EAAE;YAChDG,cAAc;gBACZE,MAAM;YACR;YACAC,aAAa;QACf;QACAC,oBAAoBZ,qBAAqB5C,oBAAoB;QAC7DyD,mBAAmBb,qBAAqBpD,mBAAmB;QAC3DkE,wBAAwBd,qBAAqBnD,uBAAuB7D,oBAAoBF;QACxFiI,uBAAuB3G;QACvBV;QACAH;QACAI;QACAc;QACAE;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["useVirtualizer.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { VirtualizerProps, VirtualizerState } from './Virtualizer.types';\n\nimport { useEffect, useRef, useCallback, useReducer, useImperativeHandle, useState } from 'react';\nimport { useIntersectionObserver } from '../../hooks/useIntersectionObserver';\nimport { flushSync } from 'react-dom';\nimport { useVirtualizerContextState_unstable } from '../../Utilities';\nimport { slot, useTimeout } from '@fluentui/react-utilities';\n\nexport function useVirtualizer_unstable(props: VirtualizerProps): VirtualizerState {\n const {\n itemSize,\n numItems,\n virtualizerLength,\n children: renderChild,\n getItemSize,\n bufferItems = Math.round(virtualizerLength / 4.0),\n bufferSize = Math.floor(bufferItems / 2.0) * itemSize,\n scrollViewRef,\n axis = 'vertical',\n reversed = false,\n virtualizerContext,\n onRenderedFlaggedIndex,\n imperativeVirtualizerRef,\n } = props;\n\n /* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/\n const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);\n\n // We use this ref as a constant source to access the virtualizer's state imperatively\n const actualIndexRef = useRef<number>(_virtualizerContext.contextIndex);\n if (actualIndexRef.current !== _virtualizerContext.contextIndex) {\n actualIndexRef.current = _virtualizerContext.contextIndex;\n }\n const flaggedIndex = useRef<number | null>(null);\n\n const actualIndex = _virtualizerContext.contextIndex;\n const setActualIndex = _virtualizerContext.setContextIndex;\n\n // Store ref to before padding element\n const beforeElementRef = useRef<Element | null>(null);\n\n // Store ref to before padding element\n const afterElementRef = useRef<Element | null>(null);\n\n // We need to store an array to track dynamic sizes, we can use this to incrementally update changes\n const childSizes = useRef<number[]>(new Array<number>(getItemSize ? numItems : 0));\n\n /* We keep track of the progressive sizing/placement down the list,\n this helps us skip re-calculations unless children/size changes */\n const childProgressiveSizes = useRef<number[]>(new Array<number>(getItemSize ? numItems : 0));\n\n // The internal tracking REF for child array (updates often).\n const childArray = useRef<ReactNode[]>(new Array(virtualizerLength));\n\n // We want to be methodical about updating the render with child reference array\n const forceUpdate = useReducer(() => ({}), {})[1];\n\n const horizontal = axis === 'horizontal';\n\n const populateSizeArrays = () => {\n if (!getItemSize) {\n // Static sizes, never mind!\n return;\n }\n\n if (numItems !== childSizes.current.length) {\n childSizes.current = new Array<number>(numItems);\n }\n\n if (numItems !== childProgressiveSizes.current.length) {\n childProgressiveSizes.current = new Array<number>(numItems);\n }\n\n for (let index = 0; index < numItems; index++) {\n childSizes.current[index] = getItemSize(index);\n if (index === 0) {\n childProgressiveSizes.current[index] = childSizes.current[index];\n } else {\n childProgressiveSizes.current[index] = childProgressiveSizes.current[index - 1] + childSizes.current[index];\n }\n }\n };\n\n const [isScrolling, setIsScrolling] = useState<boolean>(false);\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const scrollCounter = useRef<number>(0);\n\n const initializeScrollingTimer = useCallback(() => {\n /*\n * This can be considered the 'velocity' required to start 'isScrolling'\n * INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling\n * INIT_SCROLL_FLAG_DELAY: Amount of time (ms) before current number of renders is reset\n * - Maybe we should let users customize these in the future.\n */\n const INIT_SCROLL_FLAG_REQ = 10;\n const INIT_SCROLL_FLAG_DELAY = 100;\n\n scrollCounter.current++;\n if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {\n setIsScrolling(true);\n }\n clearScrollTimer();\n setScrollTimer(() => {\n setIsScrolling(false);\n scrollCounter.current = 0;\n }, INIT_SCROLL_FLAG_DELAY);\n }, [clearScrollTimer, setScrollTimer]);\n\n useEffect(() => {\n initializeScrollingTimer();\n }, [actualIndex, initializeScrollingTimer]);\n\n const batchUpdateNewIndex = (index: number) => {\n // Local updates\n updateChildRows(index);\n updateCurrentItemSizes(index);\n\n // Set before 'setActualIndex' call\n // If it changes before render, or injected via context, re-render will update ref.\n actualIndexRef.current = index;\n\n // State setters\n setActualIndex(index);\n };\n\n // Observe intersections of virtualized components\n const { setObserverList } = useIntersectionObserver(\n (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => {\n /* Sanity check - do we even need virtualization? */\n if (virtualizerLength > numItems) {\n if (actualIndex !== 0) {\n batchUpdateNewIndex(0);\n }\n // No-op\n return;\n }\n\n /* IO initiates this function when needed (bookend entering view) */\n let measurementPos = 0;\n let bufferCount = bufferItems;\n\n // Grab latest entry that is intersecting\n const latestEntry =\n entries.length === 1\n ? entries[0]\n : entries\n .sort((entry1, entry2) => entry2.time - entry1.time)\n .find(entry => {\n return entry.intersectionRatio > 0;\n });\n\n if (!latestEntry) {\n // If we don't find an intersecting area, ignore for now.\n return;\n }\n\n if (latestEntry.target === afterElementRef.current) {\n // We need to inverse the buffer count\n bufferCount = virtualizerLength - bufferItems;\n measurementPos = reversed ? calculateAfter() : calculateTotalSize() - calculateAfter();\n if (!horizontal) {\n if (reversed) {\n // Scrolling 'up' and hit the after element below\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' and hit the after element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (reversed) {\n // Scrolling 'left' and hit the after element\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'right' and hit the after element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n } else if (latestEntry.target === beforeElementRef.current) {\n measurementPos = reversed ? calculateTotalSize() - calculateBefore() : calculateBefore();\n if (!horizontal) {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' in reverse order and hit the before element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'left' and hit before element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n }\n\n if (reversed) {\n // We're reversed, up is down, left is right, invert the scroll measure.\n measurementPos = Math.max(calculateTotalSize() - Math.abs(measurementPos), 0);\n }\n\n // For now lets use hardcoded size to assess current element to paginate on\n const startIndex = getIndexFromScrollPosition(measurementPos);\n const bufferedIndex = Math.max(startIndex - bufferCount, 0);\n\n // Safety limits\n const maxIndex = Math.max(numItems - virtualizerLength, 0);\n const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);\n\n if (actualIndex !== newStartIndex) {\n // We flush sync this and perform an immediate state update\n flushSync(() => {\n batchUpdateNewIndex(newStartIndex);\n });\n }\n },\n {\n root: scrollViewRef ? scrollViewRef?.current : null,\n rootMargin: '0px',\n threshold: 0,\n },\n );\n\n const findIndexRecursive = (scrollPos: number, lowIndex: number, highIndex: number): number => {\n if (lowIndex > highIndex) {\n // We shouldn't get here - but no-op the index if we do.\n return actualIndex;\n }\n const midpoint = Math.floor((lowIndex + highIndex) / 2);\n const iBefore = Math.max(midpoint - 1, 0);\n const iAfter = Math.min(midpoint + 1, childProgressiveSizes.current.length - 1);\n const indexValue = childProgressiveSizes.current[midpoint];\n const afterIndexValue = childProgressiveSizes.current[iAfter];\n const beforeIndexValue = childProgressiveSizes.current[iBefore];\n if (scrollPos <= afterIndexValue && scrollPos >= beforeIndexValue) {\n /* We've found our index - if we are exactly matching before/after index that's ok,\n better to reduce checks if it's right on the boundary. */\n return midpoint;\n }\n\n if (indexValue > scrollPos) {\n return findIndexRecursive(scrollPos, lowIndex, midpoint - 1);\n } else {\n return findIndexRecursive(scrollPos, midpoint + 1, highIndex);\n }\n };\n\n const getIndexFromSizeArray = (scrollPos: number): number => {\n /* Quick searches our progressive height array */\n if (\n scrollPos === 0 ||\n childProgressiveSizes.current.length === 0 ||\n scrollPos <= childProgressiveSizes.current[0]\n ) {\n // Check start\n return 0;\n }\n\n if (scrollPos >= childProgressiveSizes.current[childProgressiveSizes.current.length - 1]) {\n // Check end\n return childProgressiveSizes.current.length - 1;\n }\n\n return findIndexRecursive(scrollPos, 0, childProgressiveSizes.current.length - 1);\n };\n\n const getIndexFromScrollPosition = (scrollPos: number) => {\n if (!getItemSize) {\n return Math.round(scrollPos / itemSize);\n }\n\n return getIndexFromSizeArray(scrollPos);\n };\n\n const calculateTotalSize = useCallback(() => {\n if (!getItemSize) {\n return itemSize * numItems;\n }\n\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1];\n }, [getItemSize, itemSize, numItems]);\n\n const calculateBefore = useCallback(() => {\n const currentIndex = Math.min(actualIndex, numItems - 1);\n\n if (!getItemSize) {\n // The missing items from before virtualization starts height\n return currentIndex * itemSize;\n }\n\n if (currentIndex <= 0) {\n return 0;\n }\n\n // Time for custom size calcs\n return childProgressiveSizes.current[currentIndex - 1];\n }, [actualIndex, getItemSize, itemSize, numItems]);\n\n const calculateAfter = useCallback(() => {\n if (numItems === 0 || actualIndex + virtualizerLength >= numItems) {\n return 0;\n }\n\n const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems);\n if (!getItemSize) {\n // The missing items from after virtualization ends height\n const remainingItems = numItems - lastItemIndex;\n return remainingItems * itemSize;\n }\n\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex - 1];\n }, [actualIndex, getItemSize, itemSize, numItems, virtualizerLength]);\n\n const updateChildRows = useCallback(\n (newIndex: number) => {\n if (numItems === 0) {\n /* Nothing to virtualize */\n return;\n }\n\n /*\n We reset the array every time to ensure children are re-rendered\n This function should only be called when update is nessecary\n */\n childArray.current = new Array(virtualizerLength);\n const _actualIndex = Math.max(newIndex, 0);\n const end = Math.min(_actualIndex + virtualizerLength, numItems);\n for (let i = _actualIndex; i < end; i++) {\n childArray.current[i - _actualIndex] = renderChild(i, isScrolling);\n }\n },\n [isScrolling, numItems, renderChild, virtualizerLength],\n );\n\n const setBeforeRef = useCallback(\n (element: HTMLDivElement) => {\n if (!element || beforeElementRef.current === element) {\n return;\n }\n beforeElementRef.current = element;\n const newList = [];\n\n newList.push(beforeElementRef.current);\n\n if (afterElementRef.current) {\n newList.push(afterElementRef.current);\n }\n\n // Ensure we update array if before element changed\n setObserverList(newList);\n },\n [setObserverList],\n );\n\n const setAfterRef = useCallback(\n (element: HTMLDivElement) => {\n if (!element || afterElementRef.current === element) {\n return;\n }\n afterElementRef.current = element;\n const newList = [];\n\n if (beforeElementRef.current) {\n newList.push(beforeElementRef.current);\n }\n\n newList.push(afterElementRef.current);\n\n // Ensure we update array if after element changed\n setObserverList(newList);\n },\n [setObserverList],\n );\n\n const updateCurrentItemSizes = (newIndex: number) => {\n if (!getItemSize) {\n // Static sizes, not required.\n return;\n }\n // We should always call our size function on index change (only for the items that will be rendered)\n // This ensures we request the latest data for incoming items in case sizing has changed.\n const endIndex = Math.min(newIndex + virtualizerLength, numItems);\n const startIndex = Math.max(newIndex, 0);\n\n let didUpdate = false;\n for (let i = startIndex; i < endIndex; i++) {\n const newSize = getItemSize(i);\n if (newSize !== childSizes.current[i]) {\n childSizes.current[i] = newSize;\n didUpdate = true;\n }\n }\n\n if (didUpdate) {\n // Update our progressive size array\n for (let i = startIndex; i < numItems; i++) {\n const prevSize = i > 0 ? childProgressiveSizes.current[i - 1] : 0;\n childProgressiveSizes.current[i] = prevSize + childSizes.current[i];\n }\n }\n };\n\n // Initialize the size array before first render.\n const hasInitialized = useRef<boolean>(false);\n const initializeSizeArray = () => {\n if (hasInitialized.current === false) {\n hasInitialized.current = true;\n populateSizeArrays();\n }\n };\n\n useImperativeHandle(\n imperativeVirtualizerRef,\n () => {\n return {\n progressiveSizes: childProgressiveSizes,\n nodeSizes: childSizes,\n setFlaggedIndex: (index: number | null) => (flaggedIndex.current = index),\n currentIndex: actualIndexRef,\n };\n },\n [childProgressiveSizes, childSizes],\n );\n\n // Initialization on mount - update array index to 0 (ready state).\n // Only fire on mount (no deps).\n useEffect(() => {\n if (actualIndex < 0) {\n batchUpdateNewIndex(0);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // If the user passes in an updated renderChild function - update current children\n useEffect(() => {\n if (actualIndex >= 0) {\n updateChildRows(actualIndex);\n forceUpdate();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [renderChild, updateChildRows]);\n\n useEffect(() => {\n // Ensure we repopulate if getItemSize callback changes\n populateSizeArrays();\n\n // We only run this effect on getItemSize change (recalc dynamic sizes)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [getItemSize]);\n\n // Effect to check flag index on updates\n useEffect(() => {\n if (!onRenderedFlaggedIndex || flaggedIndex.current === null) {\n return;\n }\n if (actualIndex <= flaggedIndex.current && actualIndex + virtualizerLength >= flaggedIndex.current) {\n onRenderedFlaggedIndex(flaggedIndex.current);\n flaggedIndex.current = null;\n }\n }, [actualIndex, onRenderedFlaggedIndex, virtualizerLength]);\n\n // Ensure we have run through and updated the whole size list array at least once.\n initializeSizeArray();\n\n if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {\n // Child length mismatch, repopulate size arrays.\n populateSizeArrays();\n }\n\n // Ensure we recalc if virtualizer length changes\n const maxCompare = Math.min(virtualizerLength, numItems);\n if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {\n updateChildRows(actualIndex);\n }\n\n const isFullyInitialized = hasInitialized.current && actualIndex >= 0;\n return {\n components: {\n before: 'div',\n after: 'div',\n beforeContainer: 'div',\n afterContainer: 'div',\n },\n virtualizedChildren: childArray.current,\n before: slot.always(props.before, {\n defaultProps: {\n ref: setBeforeRef,\n role: 'none',\n },\n elementType: 'div',\n }),\n after: slot.always(props.after, {\n defaultProps: {\n ref: setAfterRef,\n role: 'none',\n },\n elementType: 'div',\n }),\n beforeContainer: slot.always(props.beforeContainer, {\n defaultProps: {\n role: 'none',\n },\n elementType: 'div',\n }),\n afterContainer: slot.always(props.afterContainer, {\n defaultProps: {\n role: 'none',\n },\n elementType: 'div',\n }),\n beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,\n afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,\n totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,\n virtualizerStartIndex: actualIndex,\n axis,\n bufferSize,\n reversed,\n childSizes,\n childProgressiveSizes,\n };\n}\n"],"names":["useEffect","useRef","useCallback","useReducer","useImperativeHandle","useState","useIntersectionObserver","flushSync","useVirtualizerContextState_unstable","slot","useTimeout","useVirtualizer_unstable","props","itemSize","numItems","virtualizerLength","children","renderChild","getItemSize","bufferItems","Math","round","bufferSize","floor","scrollViewRef","axis","reversed","virtualizerContext","onRenderedFlaggedIndex","imperativeVirtualizerRef","_virtualizerContext","actualIndexRef","contextIndex","current","flaggedIndex","actualIndex","setActualIndex","setContextIndex","beforeElementRef","afterElementRef","childSizes","Array","childProgressiveSizes","childArray","forceUpdate","horizontal","populateSizeArrays","length","index","isScrolling","setIsScrolling","setScrollTimer","clearScrollTimer","scrollCounter","initializeScrollingTimer","INIT_SCROLL_FLAG_REQ","INIT_SCROLL_FLAG_DELAY","batchUpdateNewIndex","updateChildRows","updateCurrentItemSizes","setObserverList","entries","observer","measurementPos","bufferCount","latestEntry","sort","entry1","entry2","time","find","entry","intersectionRatio","target","calculateAfter","calculateTotalSize","abs","boundingClientRect","bottom","top","right","left","calculateBefore","max","startIndex","getIndexFromScrollPosition","bufferedIndex","maxIndex","newStartIndex","min","root","rootMargin","threshold","findIndexRecursive","scrollPos","lowIndex","highIndex","midpoint","iBefore","iAfter","indexValue","afterIndexValue","beforeIndexValue","getIndexFromSizeArray","currentIndex","lastItemIndex","remainingItems","newIndex","_actualIndex","end","i","setBeforeRef","element","newList","push","setAfterRef","endIndex","didUpdate","newSize","prevSize","hasInitialized","initializeSizeArray","progressiveSizes","nodeSizes","setFlaggedIndex","maxCompare","isFullyInitialized","components","before","after","beforeContainer","afterContainer","virtualizedChildren","always","defaultProps","ref","role","elementType","beforeBufferHeight","afterBufferHeight","totalVirtualizerHeight","virtualizerStartIndex"],"mappings":"AAGA,SAASA,SAAS,EAAEC,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAEC,mBAAmB,EAAEC,QAAQ,QAAQ,QAAQ;AAClG,SAASC,uBAAuB,QAAQ,sCAAsC;AAC9E,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,mCAAmC,QAAQ,kBAAkB;AACtE,SAASC,IAAI,EAAEC,UAAU,QAAQ,4BAA4B;AAE7D,OAAO,SAASC,wBAAwBC,KAAuB;IAC7D,MAAM,E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H,iDAAiD;QACjDD;IACF;IAEA,iDAAiD;IACjD,MAAM+E,aAAazG,KAAKqE,GAAG,CAAC1E,mBAAmBD;IAC/C,IAAI6B,WAAWV,OAAO,CAACc,MAAM,KAAK8E,cAAc1F,cAAcQ,WAAWV,OAAO,CAACc,MAAM,GAAGjC,UAAU;QAClG4C,gBAAgBvB;IAClB;IAEA,MAAM2F,qBAAqBN,eAAevF,OAAO,IAAIE,eAAe;IACpE,OAAO;QACL4F,YAAY;YACVC,QAAQ;YACRC,OAAO;YACPC,iBAAiB;YACjBC,gBAAgB;QAClB;QACAC,qBAAqBzF,WAAWV,OAAO;QACvC+F,QAAQvH,KAAK4H,MAAM,CAACzH,MAAMoH,MAAM,EAAE;YAChCM,cAAc;gBACZC,KAAKxB;gBACLyB,MAAM;YACR;YACAC,aAAa;QACf;QACAR,OAAOxH,KAAK4H,MAAM,CAACzH,MAAMqH,KAAK,EAAE;YAC9BK,cAAc;gBACZC,KAAKpB;gBACLqB,MAAM;YACR;YACAC,aAAa;QACf;QACAP,iBAAiBzH,KAAK4H,MAAM,CAACzH,MAAMsH,eAAe,EAAE;YAClDI,cAAc;gBACZE,MAAM;YACR;YACAC,aAAa;QACf;QACAN,gBAAgB1H,KAAK4H,MAAM,CAACzH,MAAMuH,cAAc,EAAE;YAChDG,cAAc;gBACZE,MAAM;YACR;YACAC,aAAa;QACf;QACAC,oBAAoBZ,qBAAqB5C,oBAAoB;QAC7DyD,mBAAmBb,qBAAqBpD,mBAAmB;QAC3DkE,wBAAwBd,qBAAqBnD,uBAAuB5D,oBAAoBF;QACxFgI,uBAAuB1G;QACvBV;QACAH;QACAI;QACAc;QACAE;IACF;AACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
|
+
import { useTimeout } from '@fluentui/react-utilities';
|
|
3
4
|
/**
|
|
4
5
|
* Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position
|
|
5
6
|
* Sizes are dynamic so we require a progressive sizing array (passed in from Dynamic virtualizer hooks)
|
|
@@ -7,7 +8,7 @@ import { useRef } from 'react';
|
|
|
7
8
|
* All VirtualizerDynamicPaginationProps can be grabbed from dynamic Virtualizer hooks externally and passed in
|
|
8
9
|
*/ export const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
|
|
9
10
|
const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;
|
|
10
|
-
const
|
|
11
|
+
const [setScrollTimer, clearScrollTimer] = useTimeout();
|
|
11
12
|
const lastScrollPos = useRef(-1);
|
|
12
13
|
const lastIndexScrolled = useRef(-1);
|
|
13
14
|
const scrollContainer = React.useRef(null);
|
|
@@ -15,9 +16,7 @@ import { useRef } from 'react';
|
|
|
15
16
|
if (scrollContainer.current) {
|
|
16
17
|
scrollContainer.current.removeEventListener('scroll', onScroll);
|
|
17
18
|
scrollContainer.current = null;
|
|
18
|
-
|
|
19
|
-
clearTimeout(timeoutRef.current);
|
|
20
|
-
}
|
|
19
|
+
clearScrollTimer();
|
|
21
20
|
}
|
|
22
21
|
};
|
|
23
22
|
React.useEffect(()=>{
|
|
@@ -94,12 +93,12 @@ import { useRef } from 'react';
|
|
|
94
93
|
/**
|
|
95
94
|
* On scroll timer that will continuously delay callback until scrolling stops
|
|
96
95
|
*/ const onScroll = React.useCallback((event)=>{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
timeoutRef.current = setTimeout(onScrollEnd, 100);
|
|
96
|
+
clearScrollTimer();
|
|
97
|
+
setScrollTimer(onScrollEnd, 100);
|
|
101
98
|
}, [
|
|
102
|
-
onScrollEnd
|
|
99
|
+
onScrollEnd,
|
|
100
|
+
clearScrollTimer,
|
|
101
|
+
setScrollTimer
|
|
103
102
|
]);
|
|
104
103
|
/**
|
|
105
104
|
* Pagination ref will ensure we attach listeners to containers on change
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useDynamicPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerDynamicPaginationProps } from './hooks.types';\nimport { useRef } from 'react';\n\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are dynamic so we require a progressive sizing array (passed in from Dynamic virtualizer hooks)\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerDynamicPaginationProps can be grabbed from dynamic Virtualizer hooks externally and passed in\n */\nexport const useDynamicVirtualizerPagination = (\n virtualizerProps: VirtualizerDynamicPaginationProps,\n paginationEnabled: Boolean = true,\n) => {\n const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;\n\n const
|
|
1
|
+
{"version":3,"sources":["useDynamicPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerDynamicPaginationProps } from './hooks.types';\nimport { useRef } from 'react';\nimport { useTimeout } from '@fluentui/react-utilities';\n\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are dynamic so we require a progressive sizing array (passed in from Dynamic virtualizer hooks)\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerDynamicPaginationProps can be grabbed from dynamic Virtualizer hooks externally and passed in\n */\nexport const useDynamicVirtualizerPagination = (\n virtualizerProps: VirtualizerDynamicPaginationProps,\n paginationEnabled: Boolean = true,\n) => {\n const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;\n\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const lastScrollPos = useRef<number>(-1);\n const lastIndexScrolled = useRef<number>(-1);\n\n const scrollContainer = React.useRef<HTMLElement | null>(null);\n\n const clearListeners = () => {\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n scrollContainer.current = null;\n clearScrollTimer();\n }\n };\n\n React.useEffect(() => {\n return () => {\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n *\n * Users/Virtualizer-Hooks must pass in a cumulative array of sizes\n * This prevents the need to recalculate and ensures size arrays are synced externally\n */\n const onScrollEnd = React.useCallback(() => {\n if (!scrollContainer.current || !paginationEnabled || !progressiveItemSizes?.current) {\n // No container found\n return;\n }\n\n const currentScrollPos = Math.round(\n axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft,\n );\n let closestItemPos = 0;\n let closestItem = 0;\n const endItem = Math.min(currentIndex + virtualizerLength, progressiveItemSizes.current.length);\n\n for (let i = currentIndex; i < endItem - 1; i++) {\n if (\n currentScrollPos <= progressiveItemSizes.current[i + 1] &&\n currentScrollPos >= progressiveItemSizes.current[i]\n ) {\n // Found our in between position\n const distanceToPrev = Math.abs(currentScrollPos - progressiveItemSizes.current[i]);\n const distanceToNext = Math.abs(progressiveItemSizes.current[i + 1] - currentScrollPos);\n if (distanceToPrev < distanceToNext) {\n closestItem = i;\n } else {\n closestItem = i + 1;\n }\n break;\n }\n }\n\n let nextItem;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n // This will also handle a case where we scrolled to the exact correct position (noop)\n const isSecondaryScroll = Math.round(lastScrollPos.current - currentScrollPos) === 0;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n\n // Safeguard nextItem\n nextItem = Math.min(Math.max(0, nextItem), progressiveItemSizes.current.length);\n closestItemPos = progressiveItemSizes.current[nextItem];\n\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({ top: closestItemPos, behavior: 'smooth' });\n } else {\n scrollContainer.current.scrollTo({ left: closestItemPos, behavior: 'smooth' });\n }\n lastScrollPos.current = progressiveItemSizes.current[nextItem];\n lastIndexScrolled.current = nextItem;\n }, [paginationEnabled, currentIndex, scrollContainer, virtualizerLength, axis, progressiveItemSizes]);\n\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */\n const onScroll = React.useCallback(\n event => {\n clearScrollTimer();\n setScrollTimer(onScrollEnd, 100);\n },\n [onScrollEnd, clearScrollTimer, setScrollTimer],\n );\n\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */\n const paginationRef = React.useCallback(\n (instance: HTMLElement | HTMLDivElement | null) => {\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onScroll, onScrollEnd, paginationEnabled],\n );\n\n return paginationRef;\n};\n"],"names":["React","useRef","useTimeout","useDynamicVirtualizerPagination","virtualizerProps","paginationEnabled","axis","currentIndex","progressiveItemSizes","virtualizerLength","setScrollTimer","clearScrollTimer","lastScrollPos","lastIndexScrolled","scrollContainer","clearListeners","current","removeEventListener","onScroll","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItemPos","closestItem","endItem","min","length","i","distanceToPrev","abs","distanceToNext","nextItem","nextTarget","isSecondaryScroll","posMod","max","scrollTo","top","behavior","left","event","paginationRef","instance","addEventListener"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,MAAM,QAAQ,QAAQ;AAC/B,SAASC,UAAU,QAAQ,4BAA4B;AAEvD;;;;;CAKC,GACD,OAAO,MAAMC,kCAAkC,CAC7CC,kBACAC,oBAA6B,IAAI;IAEjC,MAAM,EAAEC,OAAO,UAAU,EAAEC,YAAY,EAAEC,oBAAoB,EAAEC,iBAAiB,EAAE,GAAGL;IAErF,MAAM,CAACM,gBAAgBC,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,KAAK+B,UAAU;YACxChC;YAEAD,gBAAgBE,OAAO,GAAG+B;YAC1B,IAAIjC,gBAAgBE,OAAO,EAAE;gBAC3BF,gBAAgBE,OAAO,CAACgC,gBAAgB,CAAC,UAAU9B;YACrD;QACF;IACF,GACA,uDAAuD;IACvD;QAACA;QAAUE;QAAaf;KAAkB;IAG5C,OAAOyC;AACT,EAAE"}
|
|
@@ -75,11 +75,14 @@ import { useMutationObserver } from './useMutationObserver';
|
|
|
75
75
|
// Observer elements in passed in list and clean up previous list
|
|
76
76
|
// This effect is only triggered when observerList is updated
|
|
77
77
|
useIsomorphicLayoutEffect(()=>{
|
|
78
|
-
|
|
78
|
+
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
|
79
|
+
if (!win) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
observer.current = new win.IntersectionObserver(callback, {
|
|
79
83
|
...observerInit,
|
|
80
84
|
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)
|
|
81
85
|
});
|
|
82
|
-
observer.current = new IntersectionObserver(callback, observerInit);
|
|
83
86
|
// If we have an instance of IO and a list with elements, observer the elements
|
|
84
87
|
if (observer.current && observerList && observerList.length > 0) {
|
|
85
88
|
observerList.forEach((element)=>{
|
|
@@ -96,7 +99,8 @@ import { useMutationObserver } from './useMutationObserver';
|
|
|
96
99
|
}, [
|
|
97
100
|
observerList,
|
|
98
101
|
observerInit,
|
|
99
|
-
callback
|
|
102
|
+
callback,
|
|
103
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView
|
|
100
104
|
]);
|
|
101
105
|
// Do not use internally, we need to track external settings only here
|
|
102
106
|
const setObserverInitExternal = useCallback((newInit)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useIntersectionObserver.ts"],"sourcesContent":["import type { Dispatch, MutableRefObject, SetStateAction } from 'react';\nimport * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */\nexport const getRTLRootMargin = (ltrRootMargin: string, target?: Element | Document | null | undefined): string => {\n if (target) {\n // get the computed dir for the target element\n const newDir = getComputedStyle(target as Element).direction;\n\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n\n return ltrRootMargin;\n};\n\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */\n\nexport const useIntersectionObserver = (\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n): {\n setObserverList: Dispatch<SetStateAction<Element[] | undefined>>;\n setObserverInit: (newInit: IntersectionObserverInit | undefined) => void;\n observer: MutableRefObject<IntersectionObserver | undefined>;\n} => {\n const observer = useRef<IntersectionObserver>();\n const [observerList, setObserverList] = useState<Element[]>();\n const { targetDocument } = useFluent();\n\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState<IntersectionObserverInit | undefined>(\n options && {\n ...options,\n rootMargin: getRTLRootMargin(options.rootMargin ?? '0px', options.root as Element),\n },\n );\n\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef<string>(options?.rootMargin ?? '0px');\n\n // Callback function to execute when mutations are observed\n const mutationObserverCallback: MutationCallback = useCallback(\n mutationList => {\n for (const mutation of mutationList) {\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'dir' &&\n options?.root &&\n mutation.target.contains(options?.root)\n ) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root),\n });\n }\n }\n },\n [ltrRootMargin, observerInit, options?.root],\n );\n\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: ['dir'],\n });\n\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(() => {\n observer.current = new IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root),\n });\n\n
|
|
1
|
+
{"version":3,"sources":["useIntersectionObserver.ts"],"sourcesContent":["import type { Dispatch, MutableRefObject, SetStateAction } from 'react';\nimport * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */\nexport const getRTLRootMargin = (ltrRootMargin: string, target?: Element | Document | null | undefined): string => {\n if (target) {\n // get the computed dir for the target element\n const newDir = getComputedStyle(target as Element).direction;\n\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n\n return ltrRootMargin;\n};\n\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */\n\nexport const useIntersectionObserver = (\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n): {\n setObserverList: Dispatch<SetStateAction<Element[] | undefined>>;\n setObserverInit: (newInit: IntersectionObserverInit | undefined) => void;\n observer: MutableRefObject<IntersectionObserver | undefined>;\n} => {\n const observer = useRef<IntersectionObserver>();\n const [observerList, setObserverList] = useState<Element[]>();\n const { targetDocument } = useFluent();\n\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState<IntersectionObserverInit | undefined>(\n options && {\n ...options,\n rootMargin: getRTLRootMargin(options.rootMargin ?? '0px', options.root as Element),\n },\n );\n\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef<string>(options?.rootMargin ?? '0px');\n\n // Callback function to execute when mutations are observed\n const mutationObserverCallback: MutationCallback = useCallback(\n mutationList => {\n for (const mutation of mutationList) {\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'dir' &&\n options?.root &&\n mutation.target.contains(options?.root)\n ) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root),\n });\n }\n }\n },\n [ltrRootMargin, observerInit, options?.root],\n );\n\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: ['dir'],\n });\n\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(() => {\n const win = targetDocument?.defaultView;\n if (!win) {\n return;\n }\n\n observer.current = new win.IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root),\n });\n\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach(element => {\n observer.current?.observe(element);\n });\n }\n\n // clean up previous elements being listened to\n return () => {\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [observerList, observerInit, callback, targetDocument?.defaultView]);\n\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback(\n (newInit: IntersectionObserverInit | undefined) => {\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = newInit?.rootMargin ?? '0px';\n\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit?.root as Element),\n });\n },\n [ltrRootMargin, setObserverInit],\n );\n\n return { setObserverList, setObserverInit: setObserverInitExternal, observer };\n};\n"],"names":["React","useIsomorphicLayoutEffect","useFluent_unstable","useFluent","useCallback","useState","useRef","useMutationObserver","getRTLRootMargin","ltrRootMargin","target","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","useIntersectionObserver","callback","options","observer","observerList","setObserverList","targetDocument","observerInit","setObserverInit","rootMargin","root","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","attributes","subtree","attributeFilter","win","defaultView","IntersectionObserver","forEach","element","observe","disconnect","setObserverInitExternal","newInit"],"mappings":"AACA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,4BAA4B;AACtE,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGN;AAC1C,SAASO,mBAAmB,QAAQ,wBAAwB;AAE5D;;;;;CAKC,GACD,OAAO,MAAMC,mBAAmB,CAACC,eAAuBC;IACtD,IAAIA,QAAQ;QACV,8CAA8C;QAC9C,MAAMC,SAASC,iBAAiBF,QAAmBG,SAAS;QAE5D,+FAA+F;QAC/F,IAAIF,WAAW,OAAO;YACpB,IAAIG,YAAYL;YAChB,MAAMM,eAAeN,cAAcO,KAAK,CAAC;YAEzC,2GAA2G;YAC3G,IAAID,aAAaE,MAAM,KAAK,GAAG;gBAC7BH,YAAY,CAAC,EAAEC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC;YAC3F;YAEA,OAAOD;QACT,OAAO;YACL,OAAOL;QACT;IACF;IAEA,OAAOA;AACT,EAAE;AAEF;;;;;;;;CAQC,GAED,OAAO,MAAMS,0BAA0B,CACrCC,UACAC;IAMA,MAAMC,WAAWf;IACjB,MAAM,CAACgB,cAAcC,gBAAgB,GAAGlB;IACxC,MAAM,EAAEmB,cAAc,EAAE,GAAGrB;QAMMiB;IAJjC,yGAAyG;IACzG,MAAM,CAACK,cAAcC,gBAAgB,GAAGrB,SACtCe,WAAW;QACT,GAAGA,OAAO;QACVO,YAAYnB,iBAAiBY,CAAAA,sBAAAA,QAAQO,UAAU,cAAlBP,iCAAAA,sBAAsB,OAAOA,QAAQQ,IAAI;IACxE;QAImCR;IADrC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IAAItB,SAASc,OAAO,EAAE;gBACpBd,SAASc,OAAO,CAACU,UAAU;YAC7B;QACF;IACF,GAAG;QAACvB;QAAcG;QAAcN;QAAUK,2BAAAA,qCAAAA,eAAgBgB,WAAW;KAAC;IAEtE,sEAAsE;IACtE,MAAMM,0BAA0B1C,YAC9B,CAAC2C;YAEyBA;QADxB,+FAA+F;QAC/FtC,cAAc0B,OAAO,GAAGY,CAAAA,sBAAAA,oBAAAA,8BAAAA,QAASpB,UAAU,cAAnBoB,iCAAAA,sBAAuB;QAE/C,iHAAiH;QACjHrB,gBAAgB;YACd,GAAGqB,OAAO;YACVpB,YAAYnB,iBAAiBC,cAAc0B,OAAO,EAAEY,oBAAAA,8BAAAA,QAASnB,IAAI;QACnE;IACF,GACA;QAACnB;QAAeiB;KAAgB;IAGlC,OAAO;QAAEH;QAAiBG,iBAAiBoB;QAAyBzB;IAAS;AAC/E,EAAE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useRef } from 'react';
|
|
3
|
+
import { useTimeout } from '@fluentui/react-utilities';
|
|
3
4
|
/**
|
|
4
5
|
* Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position
|
|
5
6
|
* Sizes are uniform/static, we round to the nearest item on long scrolls
|
|
@@ -7,7 +8,7 @@ import { useRef } from 'react';
|
|
|
7
8
|
* All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in
|
|
8
9
|
*/ export const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
|
|
9
10
|
const { itemSize, axis = 'vertical' } = virtualizerProps;
|
|
10
|
-
const
|
|
11
|
+
const [setScrollTimer, clearScrollTimer] = useTimeout();
|
|
11
12
|
const lastScrollPos = useRef(0);
|
|
12
13
|
const lastIndexScrolled = useRef(0);
|
|
13
14
|
const scrollContainer = React.useRef(null);
|
|
@@ -15,9 +16,7 @@ import { useRef } from 'react';
|
|
|
15
16
|
if (scrollContainer.current) {
|
|
16
17
|
scrollContainer.current.removeEventListener('scroll', onScroll);
|
|
17
18
|
scrollContainer.current = null;
|
|
18
|
-
|
|
19
|
-
clearTimeout(timeoutRef.current);
|
|
20
|
-
}
|
|
19
|
+
clearScrollTimer();
|
|
21
20
|
}
|
|
22
21
|
};
|
|
23
22
|
React.useEffect(()=>{
|
|
@@ -70,12 +69,12 @@ import { useRef } from 'react';
|
|
|
70
69
|
/**
|
|
71
70
|
* On scroll timer that will continuously delay callback until scrolling stops
|
|
72
71
|
*/ const onScroll = React.useCallback((event)=>{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
timeoutRef.current = setTimeout(onScrollEnd, 100);
|
|
72
|
+
clearScrollTimer();
|
|
73
|
+
setScrollTimer(onScrollEnd, 100);
|
|
77
74
|
}, [
|
|
78
|
-
onScrollEnd
|
|
75
|
+
onScrollEnd,
|
|
76
|
+
clearScrollTimer,
|
|
77
|
+
setScrollTimer
|
|
79
78
|
]);
|
|
80
79
|
/**
|
|
81
80
|
* Pagination ref will ensure we attach listeners to containers on change
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useStaticPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerStaticPaginationProps } from './hooks.types';\nimport { useRef } from 'react';\n\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are uniform/static, we round to the nearest item on long scrolls\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in\n */\nexport const useStaticVirtualizerPagination = (\n virtualizerProps: VirtualizerStaticPaginationProps,\n paginationEnabled: Boolean = true,\n) => {\n const { itemSize, axis = 'vertical' } = virtualizerProps;\n\n const
|
|
1
|
+
{"version":3,"sources":["useStaticPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerStaticPaginationProps } from './hooks.types';\nimport { useRef } from 'react';\nimport { useTimeout } from '@fluentui/react-utilities';\n\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are uniform/static, we round to the nearest item on long scrolls\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in\n */\nexport const useStaticVirtualizerPagination = (\n virtualizerProps: VirtualizerStaticPaginationProps,\n paginationEnabled: Boolean = true,\n) => {\n const { itemSize, axis = 'vertical' } = virtualizerProps;\n\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const lastScrollPos = useRef<number>(0);\n const lastIndexScrolled = useRef<number>(0);\n\n const scrollContainer = React.useRef<HTMLElement | null>(null);\n\n const clearListeners = () => {\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n\n scrollContainer.current = null;\n clearScrollTimer();\n }\n };\n\n React.useEffect(() => {\n return () => {\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n */\n const onScrollEnd = React.useCallback(() => {\n if (!scrollContainer.current || !paginationEnabled) {\n // No container found\n return;\n }\n\n const currentScrollPos = Math.round(\n axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft,\n );\n const closestItem = Math.round(currentScrollPos / itemSize);\n\n let nextItem = 0;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n const isSecondaryScroll = lastScrollPos.current === currentScrollPos;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n\n const nextItemPos = nextItem * itemSize;\n\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({ top: nextItemPos, behavior: 'smooth' });\n } else {\n scrollContainer.current.scrollTo({ left: nextItemPos, behavior: 'smooth' });\n }\n lastScrollPos.current = nextItemPos;\n lastIndexScrolled.current = nextItem;\n }, [paginationEnabled, axis, itemSize]);\n\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */\n const onScroll = React.useCallback(\n event => {\n clearScrollTimer();\n setScrollTimer(onScrollEnd, 100);\n },\n [onScrollEnd, clearScrollTimer, setScrollTimer],\n );\n\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */\n const paginationRef = React.useCallback(\n (instance: HTMLElement | HTMLDivElement | null) => {\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onScroll, onScrollEnd, paginationEnabled],\n );\n\n return paginationRef;\n};\n"],"names":["React","useRef","useTimeout","useStaticVirtualizerPagination","virtualizerProps","paginationEnabled","itemSize","axis","setScrollTimer","clearScrollTimer","lastScrollPos","lastIndexScrolled","scrollContainer","clearListeners","current","removeEventListener","onScroll","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItem","nextItem","nextTarget","isSecondaryScroll","posMod","nextItemPos","scrollTo","top","behavior","left","event","paginationRef","instance","addEventListener"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,MAAM,QAAQ,QAAQ;AAC/B,SAASC,UAAU,QAAQ,4BAA4B;AAEvD;;;;;CAKC,GACD,OAAO,MAAMC,iCAAiC,CAC5CC,kBACAC,oBAA6B,IAAI;IAEjC,MAAM,EAAEC,QAAQ,EAAEC,OAAO,UAAU,EAAE,GAAGH;IAExC,MAAM,CAACI,gBAAgBC,iBAAiB,GAAGP;IAC3C,MAAMQ,gBAAgBT,OAAe;IACr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B,GAAG;QAACrB;QAAmBE;QAAMD;KAAS;IAEtC;;GAEC,GACD,MAAMU,WAAWhB,MAAMmB,WAAW,CAChCgB,CAAAA;QACE1B;QACAD,eAAeU,aAAa;IAC9B,GACA;QAACA;QAAaT;QAAkBD;KAAe;IAGjD;;;GAGC,GACD,MAAM4B,gBAAgBpC,MAAMmB,WAAW,CACrC,CAACkB;QACC,IAAI,CAAChC,mBAAmB;YACtBQ;YACAD,gBAAgBE,OAAO,GAAG;YAC1B;QACF;QACA,IAAIF,gBAAgBE,OAAO,KAAKuB,UAAU;YACxCxB;YAEAD,gBAAgBE,OAAO,GAAGuB;YAC1B,IAAIzB,gBAAgBE,OAAO,EAAE;gBAC3BF,gBAAgBE,OAAO,CAACwB,gBAAgB,CAAC,UAAUtB;YACrD;QACF;IACF,GACA,uDAAuD;IACvD;QAACA;QAAUE;QAAab;KAAkB;IAG5C,OAAO+B;AACT,EAAE"}
|
|
@@ -58,9 +58,9 @@ function useVirtualizer_unstable(props) {
|
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
const [isScrolling, setIsScrolling] = (0, _react.useState)(false);
|
|
61
|
-
const
|
|
61
|
+
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
|
|
62
62
|
const scrollCounter = (0, _react.useRef)(0);
|
|
63
|
-
const initializeScrollingTimer = ()=>{
|
|
63
|
+
const initializeScrollingTimer = (0, _react.useCallback)(()=>{
|
|
64
64
|
/*
|
|
65
65
|
* This can be considered the 'velocity' required to start 'isScrolling'
|
|
66
66
|
* INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling
|
|
@@ -72,18 +72,20 @@ function useVirtualizer_unstable(props) {
|
|
|
72
72
|
if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {
|
|
73
73
|
setIsScrolling(true);
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
scrollTimer.current = setTimeout(()=>{
|
|
75
|
+
clearScrollTimer();
|
|
76
|
+
setScrollTimer(()=>{
|
|
79
77
|
setIsScrolling(false);
|
|
80
78
|
scrollCounter.current = 0;
|
|
81
79
|
}, INIT_SCROLL_FLAG_DELAY);
|
|
82
|
-
}
|
|
80
|
+
}, [
|
|
81
|
+
clearScrollTimer,
|
|
82
|
+
setScrollTimer
|
|
83
|
+
]);
|
|
83
84
|
(0, _react.useEffect)(()=>{
|
|
84
85
|
initializeScrollingTimer();
|
|
85
86
|
}, [
|
|
86
|
-
actualIndex
|
|
87
|
+
actualIndex,
|
|
88
|
+
initializeScrollingTimer
|
|
87
89
|
]);
|
|
88
90
|
const batchUpdateNewIndex = (index)=>{
|
|
89
91
|
// Local updates
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useVirtualizer.js"],"sourcesContent":["import { useEffect, useRef, useCallback, useReducer, useImperativeHandle, useState } from 'react';\nimport { useIntersectionObserver } from '../../hooks/useIntersectionObserver';\nimport { flushSync } from 'react-dom';\nimport { useVirtualizerContextState_unstable } from '../../Utilities';\nimport { slot } from '@fluentui/react-utilities';\nexport function useVirtualizer_unstable(props) {\n 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;\n /* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/ const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);\n // We use this ref as a constant source to access the virtualizer's state imperatively\n const actualIndexRef = useRef(_virtualizerContext.contextIndex);\n if (actualIndexRef.current !== _virtualizerContext.contextIndex) {\n actualIndexRef.current = _virtualizerContext.contextIndex;\n }\n const flaggedIndex = useRef(null);\n const actualIndex = _virtualizerContext.contextIndex;\n const setActualIndex = _virtualizerContext.setContextIndex;\n // Store ref to before padding element\n const beforeElementRef = useRef(null);\n // Store ref to before padding element\n const afterElementRef = useRef(null);\n // We need to store an array to track dynamic sizes, we can use this to incrementally update changes\n const childSizes = useRef(new Array(getItemSize ? numItems : 0));\n /* We keep track of the progressive sizing/placement down the list,\n this helps us skip re-calculations unless children/size changes */ const childProgressiveSizes = useRef(new Array(getItemSize ? numItems : 0));\n // The internal tracking REF for child array (updates often).\n const childArray = useRef(new Array(virtualizerLength));\n // We want to be methodical about updating the render with child reference array\n const forceUpdate = useReducer(()=>({}), {})[1];\n const horizontal = axis === 'horizontal';\n const populateSizeArrays = ()=>{\n if (!getItemSize) {\n // Static sizes, never mind!\n return;\n }\n if (numItems !== childSizes.current.length) {\n childSizes.current = new Array(numItems);\n }\n if (numItems !== childProgressiveSizes.current.length) {\n childProgressiveSizes.current = new Array(numItems);\n }\n for(let index = 0; index < numItems; index++){\n childSizes.current[index] = getItemSize(index);\n if (index === 0) {\n childProgressiveSizes.current[index] = childSizes.current[index];\n } else {\n childProgressiveSizes.current[index] = childProgressiveSizes.current[index - 1] + childSizes.current[index];\n }\n }\n };\n const [isScrolling, setIsScrolling] = useState(false);\n const scrollTimer = useRef();\n const scrollCounter = useRef(0);\n const initializeScrollingTimer = ()=>{\n /*\n * This can be considered the 'velocity' required to start 'isScrolling'\n * INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling\n * INIT_SCROLL_FLAG_DELAY: Amount of time (ms) before current number of renders is reset\n * - Maybe we should let users customize these in the future.\n */ const INIT_SCROLL_FLAG_REQ = 10;\n const INIT_SCROLL_FLAG_DELAY = 100;\n scrollCounter.current++;\n if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {\n setIsScrolling(true);\n }\n if (scrollTimer.current) {\n clearTimeout(scrollTimer.current);\n }\n scrollTimer.current = setTimeout(()=>{\n setIsScrolling(false);\n scrollCounter.current = 0;\n }, INIT_SCROLL_FLAG_DELAY);\n };\n useEffect(()=>{\n initializeScrollingTimer();\n }, [\n actualIndex\n ]);\n const batchUpdateNewIndex = (index)=>{\n // Local updates\n updateChildRows(index);\n updateCurrentItemSizes(index);\n // Set before 'setActualIndex' call\n // If it changes before render, or injected via context, re-render will update ref.\n actualIndexRef.current = index;\n // State setters\n setActualIndex(index);\n };\n // Observe intersections of virtualized components\n const { setObserverList } = useIntersectionObserver((entries, observer)=>{\n /* Sanity check - do we even need virtualization? */ if (virtualizerLength > numItems) {\n if (actualIndex !== 0) {\n batchUpdateNewIndex(0);\n }\n // No-op\n return;\n }\n /* IO initiates this function when needed (bookend entering view) */ let measurementPos = 0;\n let bufferCount = bufferItems;\n // Grab latest entry that is intersecting\n const latestEntry = entries.length === 1 ? entries[0] : entries.sort((entry1, entry2)=>entry2.time - entry1.time).find((entry)=>{\n return entry.intersectionRatio > 0;\n });\n if (!latestEntry) {\n // If we don't find an intersecting area, ignore for now.\n return;\n }\n if (latestEntry.target === afterElementRef.current) {\n // We need to inverse the buffer count\n bufferCount = virtualizerLength - bufferItems;\n measurementPos = reversed ? calculateAfter() : calculateTotalSize() - calculateAfter();\n if (!horizontal) {\n if (reversed) {\n // Scrolling 'up' and hit the after element below\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' and hit the after element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (reversed) {\n // Scrolling 'left' and hit the after element\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'right' and hit the after element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n } else if (latestEntry.target === beforeElementRef.current) {\n measurementPos = reversed ? calculateTotalSize() - calculateBefore() : calculateBefore();\n if (!horizontal) {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' in reverse order and hit the before element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'left' and hit before element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n }\n if (reversed) {\n // We're reversed, up is down, left is right, invert the scroll measure.\n measurementPos = Math.max(calculateTotalSize() - Math.abs(measurementPos), 0);\n }\n // For now lets use hardcoded size to assess current element to paginate on\n const startIndex = getIndexFromScrollPosition(measurementPos);\n const bufferedIndex = Math.max(startIndex - bufferCount, 0);\n // Safety limits\n const maxIndex = Math.max(numItems - virtualizerLength, 0);\n const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);\n if (actualIndex !== newStartIndex) {\n // We flush sync this and perform an immediate state update\n flushSync(()=>{\n batchUpdateNewIndex(newStartIndex);\n });\n }\n }, {\n root: scrollViewRef ? scrollViewRef === null || scrollViewRef === void 0 ? void 0 : scrollViewRef.current : null,\n rootMargin: '0px',\n threshold: 0\n });\n const findIndexRecursive = (scrollPos, lowIndex, highIndex)=>{\n if (lowIndex > highIndex) {\n // We shouldn't get here - but no-op the index if we do.\n return actualIndex;\n }\n const midpoint = Math.floor((lowIndex + highIndex) / 2);\n const iBefore = Math.max(midpoint - 1, 0);\n const iAfter = Math.min(midpoint + 1, childProgressiveSizes.current.length - 1);\n const indexValue = childProgressiveSizes.current[midpoint];\n const afterIndexValue = childProgressiveSizes.current[iAfter];\n const beforeIndexValue = childProgressiveSizes.current[iBefore];\n if (scrollPos <= afterIndexValue && scrollPos >= beforeIndexValue) {\n /* We've found our index - if we are exactly matching before/after index that's ok,\n better to reduce checks if it's right on the boundary. */ return midpoint;\n }\n if (indexValue > scrollPos) {\n return findIndexRecursive(scrollPos, lowIndex, midpoint - 1);\n } else {\n return findIndexRecursive(scrollPos, midpoint + 1, highIndex);\n }\n };\n const getIndexFromSizeArray = (scrollPos)=>{\n /* Quick searches our progressive height array */ if (scrollPos === 0 || childProgressiveSizes.current.length === 0 || scrollPos <= childProgressiveSizes.current[0]) {\n // Check start\n return 0;\n }\n if (scrollPos >= childProgressiveSizes.current[childProgressiveSizes.current.length - 1]) {\n // Check end\n return childProgressiveSizes.current.length - 1;\n }\n return findIndexRecursive(scrollPos, 0, childProgressiveSizes.current.length - 1);\n };\n const getIndexFromScrollPosition = (scrollPos)=>{\n if (!getItemSize) {\n return Math.round(scrollPos / itemSize);\n }\n return getIndexFromSizeArray(scrollPos);\n };\n const calculateTotalSize = useCallback(()=>{\n if (!getItemSize) {\n return itemSize * numItems;\n }\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1];\n }, [\n getItemSize,\n itemSize,\n numItems\n ]);\n const calculateBefore = useCallback(()=>{\n const currentIndex = Math.min(actualIndex, numItems - 1);\n if (!getItemSize) {\n // The missing items from before virtualization starts height\n return currentIndex * itemSize;\n }\n if (currentIndex <= 0) {\n return 0;\n }\n // Time for custom size calcs\n return childProgressiveSizes.current[currentIndex - 1];\n }, [\n actualIndex,\n getItemSize,\n itemSize,\n numItems\n ]);\n const calculateAfter = useCallback(()=>{\n if (numItems === 0 || actualIndex + virtualizerLength >= numItems) {\n return 0;\n }\n const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems);\n if (!getItemSize) {\n // The missing items from after virtualization ends height\n const remainingItems = numItems - lastItemIndex;\n return remainingItems * itemSize;\n }\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex - 1];\n }, [\n actualIndex,\n getItemSize,\n itemSize,\n numItems,\n virtualizerLength\n ]);\n const updateChildRows = useCallback((newIndex)=>{\n if (numItems === 0) {\n /* Nothing to virtualize */ return;\n }\n /*\n We reset the array every time to ensure children are re-rendered\n This function should only be called when update is nessecary\n */ childArray.current = new Array(virtualizerLength);\n const _actualIndex = Math.max(newIndex, 0);\n const end = Math.min(_actualIndex + virtualizerLength, numItems);\n for(let i = _actualIndex; i < end; i++){\n childArray.current[i - _actualIndex] = renderChild(i, isScrolling);\n }\n }, [\n isScrolling,\n numItems,\n renderChild,\n virtualizerLength\n ]);\n const setBeforeRef = useCallback((element)=>{\n if (!element || beforeElementRef.current === element) {\n return;\n }\n beforeElementRef.current = element;\n const newList = [];\n newList.push(beforeElementRef.current);\n if (afterElementRef.current) {\n newList.push(afterElementRef.current);\n }\n // Ensure we update array if before element changed\n setObserverList(newList);\n }, [\n setObserverList\n ]);\n const setAfterRef = useCallback((element)=>{\n if (!element || afterElementRef.current === element) {\n return;\n }\n afterElementRef.current = element;\n const newList = [];\n if (beforeElementRef.current) {\n newList.push(beforeElementRef.current);\n }\n newList.push(afterElementRef.current);\n // Ensure we update array if after element changed\n setObserverList(newList);\n }, [\n setObserverList\n ]);\n const updateCurrentItemSizes = (newIndex)=>{\n if (!getItemSize) {\n // Static sizes, not required.\n return;\n }\n // We should always call our size function on index change (only for the items that will be rendered)\n // This ensures we request the latest data for incoming items in case sizing has changed.\n const endIndex = Math.min(newIndex + virtualizerLength, numItems);\n const startIndex = Math.max(newIndex, 0);\n let didUpdate = false;\n for(let i = startIndex; i < endIndex; i++){\n const newSize = getItemSize(i);\n if (newSize !== childSizes.current[i]) {\n childSizes.current[i] = newSize;\n didUpdate = true;\n }\n }\n if (didUpdate) {\n // Update our progressive size array\n for(let i = startIndex; i < numItems; i++){\n const prevSize = i > 0 ? childProgressiveSizes.current[i - 1] : 0;\n childProgressiveSizes.current[i] = prevSize + childSizes.current[i];\n }\n }\n };\n // Initialize the size array before first render.\n const hasInitialized = useRef(false);\n const initializeSizeArray = ()=>{\n if (hasInitialized.current === false) {\n hasInitialized.current = true;\n populateSizeArrays();\n }\n };\n useImperativeHandle(imperativeVirtualizerRef, ()=>{\n return {\n progressiveSizes: childProgressiveSizes,\n nodeSizes: childSizes,\n setFlaggedIndex: (index)=>flaggedIndex.current = index,\n currentIndex: actualIndexRef\n };\n }, [\n childProgressiveSizes,\n childSizes\n ]);\n // Initialization on mount - update array index to 0 (ready state).\n // Only fire on mount (no deps).\n useEffect(()=>{\n if (actualIndex < 0) {\n batchUpdateNewIndex(0);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n // If the user passes in an updated renderChild function - update current children\n useEffect(()=>{\n if (actualIndex >= 0) {\n updateChildRows(actualIndex);\n forceUpdate();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n renderChild,\n updateChildRows\n ]);\n useEffect(()=>{\n // Ensure we repopulate if getItemSize callback changes\n populateSizeArrays();\n // We only run this effect on getItemSize change (recalc dynamic sizes)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n getItemSize\n ]);\n // Effect to check flag index on updates\n useEffect(()=>{\n if (!onRenderedFlaggedIndex || flaggedIndex.current === null) {\n return;\n }\n if (actualIndex <= flaggedIndex.current && actualIndex + virtualizerLength >= flaggedIndex.current) {\n onRenderedFlaggedIndex(flaggedIndex.current);\n flaggedIndex.current = null;\n }\n }, [\n actualIndex,\n onRenderedFlaggedIndex,\n virtualizerLength\n ]);\n // Ensure we have run through and updated the whole size list array at least once.\n initializeSizeArray();\n if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {\n // Child length mismatch, repopulate size arrays.\n populateSizeArrays();\n }\n // Ensure we recalc if virtualizer length changes\n const maxCompare = Math.min(virtualizerLength, numItems);\n if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {\n updateChildRows(actualIndex);\n }\n const isFullyInitialized = hasInitialized.current && actualIndex >= 0;\n return {\n components: {\n before: 'div',\n after: 'div',\n beforeContainer: 'div',\n afterContainer: 'div'\n },\n virtualizedChildren: childArray.current,\n before: slot.always(props.before, {\n defaultProps: {\n ref: setBeforeRef,\n role: 'none'\n },\n elementType: 'div'\n }),\n after: slot.always(props.after, {\n defaultProps: {\n ref: setAfterRef,\n role: 'none'\n },\n elementType: 'div'\n }),\n beforeContainer: slot.always(props.beforeContainer, {\n defaultProps: {\n role: 'none'\n },\n elementType: 'div'\n }),\n afterContainer: slot.always(props.afterContainer, {\n defaultProps: {\n role: 'none'\n },\n elementType: 'div'\n }),\n beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,\n afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,\n totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,\n virtualizerStartIndex: actualIndex,\n axis,\n bufferSize,\n reversed,\n childSizes,\n childProgressiveSizes\n };\n}\n"],"names":["useVirtualizer_unstable","props","itemSize","numItems","virtualizerLength","children","renderChild","getItemSize","bufferItems","Math","round","bufferSize","floor","scrollViewRef","axis","reversed","virtualizerContext","onRenderedFlaggedIndex","imperativeVirtualizerRef","_virtualizerContext","useVirtualizerContextState_unstable","actualIndexRef","useRef","contextIndex","current","flaggedIndex","actualIndex","setActualIndex","setContextIndex","beforeElementRef","afterElementRef","childSizes","Array","childProgressiveSizes","childArray","forceUpdate","useReducer","horizontal","populateSizeArrays","length","index","isScrolling","setIsScrolling","useState","scrollTimer","scrollCounter","initializeScrollingTimer","INIT_SCROLL_FLAG_REQ","INIT_SCROLL_FLAG_DELAY","clearTimeout","setTimeout","useEffect","batchUpdateNewIndex","updateChildRows","updateCurrentItemSizes","setObserverList","useIntersectionObserver","entries","observer","measurementPos","bufferCount","latestEntry","sort","entry1","entry2","time","find","entry","intersectionRatio","target","calculateAfter","calculateTotalSize","abs","boundingClientRect","bottom","top","right","left","calculateBefore","max","startIndex","getIndexFromScrollPosition","bufferedIndex","maxIndex","newStartIndex","min","flushSync","root","rootMargin","threshold","findIndexRecursive","scrollPos","lowIndex","highIndex","midpoint","iBefore","iAfter","indexValue","afterIndexValue","beforeIndexValue","getIndexFromSizeArray","useCallback","currentIndex","lastItemIndex","remainingItems","newIndex","_actualIndex","end","i","setBeforeRef","element","newList","push","setAfterRef","endIndex","didUpdate","newSize","prevSize","hasInitialized","initializeSizeArray","useImperativeHandle","progressiveSizes","nodeSizes","setFlaggedIndex","maxCompare","isFullyInitialized","components","before","after","beforeContainer","afterContainer","virtualizedChildren","slot","always","defaultProps","ref","role","elementType","beforeBufferHeight","afterBuffer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P,gBAAgBE,oBAAI,CAACC,MAAM,CAACpI,MAAMiI,cAAc,EAAE;YAC9CI,cAAc;gBACVE,MAAM;YACV;YACAC,aAAa;QACjB;QACAC,oBAAoBb,qBAAqB/C,oBAAoB;QAC7D6D,mBAAmBd,qBAAqBvD,mBAAmB;QAC3DsE,wBAAwBf,qBAAqBtD,uBAAuBnE,oBAAoBF;QACxF2I,uBAAuBnH;QACvBZ;QACAH;QACAI;QACAgB;QACAE;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useVirtualizer.js"],"sourcesContent":["import { useEffect, useRef, useCallback, useReducer, useImperativeHandle, useState } from 'react';\nimport { useIntersectionObserver } from '../../hooks/useIntersectionObserver';\nimport { flushSync } from 'react-dom';\nimport { useVirtualizerContextState_unstable } from '../../Utilities';\nimport { slot, useTimeout } from '@fluentui/react-utilities';\nexport function useVirtualizer_unstable(props) {\n 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;\n /* The context is optional, it's useful for injecting additional index logic, or performing uniform state updates*/ const _virtualizerContext = useVirtualizerContextState_unstable(virtualizerContext);\n // We use this ref as a constant source to access the virtualizer's state imperatively\n const actualIndexRef = useRef(_virtualizerContext.contextIndex);\n if (actualIndexRef.current !== _virtualizerContext.contextIndex) {\n actualIndexRef.current = _virtualizerContext.contextIndex;\n }\n const flaggedIndex = useRef(null);\n const actualIndex = _virtualizerContext.contextIndex;\n const setActualIndex = _virtualizerContext.setContextIndex;\n // Store ref to before padding element\n const beforeElementRef = useRef(null);\n // Store ref to before padding element\n const afterElementRef = useRef(null);\n // We need to store an array to track dynamic sizes, we can use this to incrementally update changes\n const childSizes = useRef(new Array(getItemSize ? numItems : 0));\n /* We keep track of the progressive sizing/placement down the list,\n this helps us skip re-calculations unless children/size changes */ const childProgressiveSizes = useRef(new Array(getItemSize ? numItems : 0));\n // The internal tracking REF for child array (updates often).\n const childArray = useRef(new Array(virtualizerLength));\n // We want to be methodical about updating the render with child reference array\n const forceUpdate = useReducer(()=>({}), {})[1];\n const horizontal = axis === 'horizontal';\n const populateSizeArrays = ()=>{\n if (!getItemSize) {\n // Static sizes, never mind!\n return;\n }\n if (numItems !== childSizes.current.length) {\n childSizes.current = new Array(numItems);\n }\n if (numItems !== childProgressiveSizes.current.length) {\n childProgressiveSizes.current = new Array(numItems);\n }\n for(let index = 0; index < numItems; index++){\n childSizes.current[index] = getItemSize(index);\n if (index === 0) {\n childProgressiveSizes.current[index] = childSizes.current[index];\n } else {\n childProgressiveSizes.current[index] = childProgressiveSizes.current[index - 1] + childSizes.current[index];\n }\n }\n };\n const [isScrolling, setIsScrolling] = useState(false);\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const scrollCounter = useRef(0);\n const initializeScrollingTimer = useCallback(()=>{\n /*\n * This can be considered the 'velocity' required to start 'isScrolling'\n * INIT_SCROLL_FLAG_REQ: Number of renders required to activate isScrolling\n * INIT_SCROLL_FLAG_DELAY: Amount of time (ms) before current number of renders is reset\n * - Maybe we should let users customize these in the future.\n */ const INIT_SCROLL_FLAG_REQ = 10;\n const INIT_SCROLL_FLAG_DELAY = 100;\n scrollCounter.current++;\n if (scrollCounter.current >= INIT_SCROLL_FLAG_REQ) {\n setIsScrolling(true);\n }\n clearScrollTimer();\n setScrollTimer(()=>{\n setIsScrolling(false);\n scrollCounter.current = 0;\n }, INIT_SCROLL_FLAG_DELAY);\n }, [\n clearScrollTimer,\n setScrollTimer\n ]);\n useEffect(()=>{\n initializeScrollingTimer();\n }, [\n actualIndex,\n initializeScrollingTimer\n ]);\n const batchUpdateNewIndex = (index)=>{\n // Local updates\n updateChildRows(index);\n updateCurrentItemSizes(index);\n // Set before 'setActualIndex' call\n // If it changes before render, or injected via context, re-render will update ref.\n actualIndexRef.current = index;\n // State setters\n setActualIndex(index);\n };\n // Observe intersections of virtualized components\n const { setObserverList } = useIntersectionObserver((entries, observer)=>{\n /* Sanity check - do we even need virtualization? */ if (virtualizerLength > numItems) {\n if (actualIndex !== 0) {\n batchUpdateNewIndex(0);\n }\n // No-op\n return;\n }\n /* IO initiates this function when needed (bookend entering view) */ let measurementPos = 0;\n let bufferCount = bufferItems;\n // Grab latest entry that is intersecting\n const latestEntry = entries.length === 1 ? entries[0] : entries.sort((entry1, entry2)=>entry2.time - entry1.time).find((entry)=>{\n return entry.intersectionRatio > 0;\n });\n if (!latestEntry) {\n // If we don't find an intersecting area, ignore for now.\n return;\n }\n if (latestEntry.target === afterElementRef.current) {\n // We need to inverse the buffer count\n bufferCount = virtualizerLength - bufferItems;\n measurementPos = reversed ? calculateAfter() : calculateTotalSize() - calculateAfter();\n if (!horizontal) {\n if (reversed) {\n // Scrolling 'up' and hit the after element below\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' and hit the after element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (reversed) {\n // Scrolling 'left' and hit the after element\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'right' and hit the after element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n } else if (latestEntry.target === beforeElementRef.current) {\n measurementPos = reversed ? calculateTotalSize() - calculateBefore() : calculateBefore();\n if (!horizontal) {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.bottom);\n } else if (latestEntry.boundingClientRect.top < 0) {\n // Scrolling 'down' in reverse order and hit the before element above top: 0\n measurementPos -= latestEntry.boundingClientRect.top;\n }\n } else {\n if (!reversed) {\n measurementPos -= Math.abs(latestEntry.boundingClientRect.right);\n } else if (latestEntry.boundingClientRect.left < 0) {\n // Scrolling 'left' and hit before element\n measurementPos -= latestEntry.boundingClientRect.left;\n }\n }\n }\n if (reversed) {\n // We're reversed, up is down, left is right, invert the scroll measure.\n measurementPos = Math.max(calculateTotalSize() - Math.abs(measurementPos), 0);\n }\n // For now lets use hardcoded size to assess current element to paginate on\n const startIndex = getIndexFromScrollPosition(measurementPos);\n const bufferedIndex = Math.max(startIndex - bufferCount, 0);\n // Safety limits\n const maxIndex = Math.max(numItems - virtualizerLength, 0);\n const newStartIndex = Math.min(Math.max(bufferedIndex, 0), maxIndex);\n if (actualIndex !== newStartIndex) {\n // We flush sync this and perform an immediate state update\n flushSync(()=>{\n batchUpdateNewIndex(newStartIndex);\n });\n }\n }, {\n root: scrollViewRef ? scrollViewRef === null || scrollViewRef === void 0 ? void 0 : scrollViewRef.current : null,\n rootMargin: '0px',\n threshold: 0\n });\n const findIndexRecursive = (scrollPos, lowIndex, highIndex)=>{\n if (lowIndex > highIndex) {\n // We shouldn't get here - but no-op the index if we do.\n return actualIndex;\n }\n const midpoint = Math.floor((lowIndex + highIndex) / 2);\n const iBefore = Math.max(midpoint - 1, 0);\n const iAfter = Math.min(midpoint + 1, childProgressiveSizes.current.length - 1);\n const indexValue = childProgressiveSizes.current[midpoint];\n const afterIndexValue = childProgressiveSizes.current[iAfter];\n const beforeIndexValue = childProgressiveSizes.current[iBefore];\n if (scrollPos <= afterIndexValue && scrollPos >= beforeIndexValue) {\n /* We've found our index - if we are exactly matching before/after index that's ok,\n better to reduce checks if it's right on the boundary. */ return midpoint;\n }\n if (indexValue > scrollPos) {\n return findIndexRecursive(scrollPos, lowIndex, midpoint - 1);\n } else {\n return findIndexRecursive(scrollPos, midpoint + 1, highIndex);\n }\n };\n const getIndexFromSizeArray = (scrollPos)=>{\n /* Quick searches our progressive height array */ if (scrollPos === 0 || childProgressiveSizes.current.length === 0 || scrollPos <= childProgressiveSizes.current[0]) {\n // Check start\n return 0;\n }\n if (scrollPos >= childProgressiveSizes.current[childProgressiveSizes.current.length - 1]) {\n // Check end\n return childProgressiveSizes.current.length - 1;\n }\n return findIndexRecursive(scrollPos, 0, childProgressiveSizes.current.length - 1);\n };\n const getIndexFromScrollPosition = (scrollPos)=>{\n if (!getItemSize) {\n return Math.round(scrollPos / itemSize);\n }\n return getIndexFromSizeArray(scrollPos);\n };\n const calculateTotalSize = useCallback(()=>{\n if (!getItemSize) {\n return itemSize * numItems;\n }\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1];\n }, [\n getItemSize,\n itemSize,\n numItems\n ]);\n const calculateBefore = useCallback(()=>{\n const currentIndex = Math.min(actualIndex, numItems - 1);\n if (!getItemSize) {\n // The missing items from before virtualization starts height\n return currentIndex * itemSize;\n }\n if (currentIndex <= 0) {\n return 0;\n }\n // Time for custom size calcs\n return childProgressiveSizes.current[currentIndex - 1];\n }, [\n actualIndex,\n getItemSize,\n itemSize,\n numItems\n ]);\n const calculateAfter = useCallback(()=>{\n if (numItems === 0 || actualIndex + virtualizerLength >= numItems) {\n return 0;\n }\n const lastItemIndex = Math.min(actualIndex + virtualizerLength, numItems);\n if (!getItemSize) {\n // The missing items from after virtualization ends height\n const remainingItems = numItems - lastItemIndex;\n return remainingItems * itemSize;\n }\n // Time for custom size calcs\n return childProgressiveSizes.current[numItems - 1] - childProgressiveSizes.current[lastItemIndex - 1];\n }, [\n actualIndex,\n getItemSize,\n itemSize,\n numItems,\n virtualizerLength\n ]);\n const updateChildRows = useCallback((newIndex)=>{\n if (numItems === 0) {\n /* Nothing to virtualize */ return;\n }\n /*\n We reset the array every time to ensure children are re-rendered\n This function should only be called when update is nessecary\n */ childArray.current = new Array(virtualizerLength);\n const _actualIndex = Math.max(newIndex, 0);\n const end = Math.min(_actualIndex + virtualizerLength, numItems);\n for(let i = _actualIndex; i < end; i++){\n childArray.current[i - _actualIndex] = renderChild(i, isScrolling);\n }\n }, [\n isScrolling,\n numItems,\n renderChild,\n virtualizerLength\n ]);\n const setBeforeRef = useCallback((element)=>{\n if (!element || beforeElementRef.current === element) {\n return;\n }\n beforeElementRef.current = element;\n const newList = [];\n newList.push(beforeElementRef.current);\n if (afterElementRef.current) {\n newList.push(afterElementRef.current);\n }\n // Ensure we update array if before element changed\n setObserverList(newList);\n }, [\n setObserverList\n ]);\n const setAfterRef = useCallback((element)=>{\n if (!element || afterElementRef.current === element) {\n return;\n }\n afterElementRef.current = element;\n const newList = [];\n if (beforeElementRef.current) {\n newList.push(beforeElementRef.current);\n }\n newList.push(afterElementRef.current);\n // Ensure we update array if after element changed\n setObserverList(newList);\n }, [\n setObserverList\n ]);\n const updateCurrentItemSizes = (newIndex)=>{\n if (!getItemSize) {\n // Static sizes, not required.\n return;\n }\n // We should always call our size function on index change (only for the items that will be rendered)\n // This ensures we request the latest data for incoming items in case sizing has changed.\n const endIndex = Math.min(newIndex + virtualizerLength, numItems);\n const startIndex = Math.max(newIndex, 0);\n let didUpdate = false;\n for(let i = startIndex; i < endIndex; i++){\n const newSize = getItemSize(i);\n if (newSize !== childSizes.current[i]) {\n childSizes.current[i] = newSize;\n didUpdate = true;\n }\n }\n if (didUpdate) {\n // Update our progressive size array\n for(let i = startIndex; i < numItems; i++){\n const prevSize = i > 0 ? childProgressiveSizes.current[i - 1] : 0;\n childProgressiveSizes.current[i] = prevSize + childSizes.current[i];\n }\n }\n };\n // Initialize the size array before first render.\n const hasInitialized = useRef(false);\n const initializeSizeArray = ()=>{\n if (hasInitialized.current === false) {\n hasInitialized.current = true;\n populateSizeArrays();\n }\n };\n useImperativeHandle(imperativeVirtualizerRef, ()=>{\n return {\n progressiveSizes: childProgressiveSizes,\n nodeSizes: childSizes,\n setFlaggedIndex: (index)=>flaggedIndex.current = index,\n currentIndex: actualIndexRef\n };\n }, [\n childProgressiveSizes,\n childSizes\n ]);\n // Initialization on mount - update array index to 0 (ready state).\n // Only fire on mount (no deps).\n useEffect(()=>{\n if (actualIndex < 0) {\n batchUpdateNewIndex(0);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n // If the user passes in an updated renderChild function - update current children\n useEffect(()=>{\n if (actualIndex >= 0) {\n updateChildRows(actualIndex);\n forceUpdate();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n renderChild,\n updateChildRows\n ]);\n useEffect(()=>{\n // Ensure we repopulate if getItemSize callback changes\n populateSizeArrays();\n // We only run this effect on getItemSize change (recalc dynamic sizes)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n getItemSize\n ]);\n // Effect to check flag index on updates\n useEffect(()=>{\n if (!onRenderedFlaggedIndex || flaggedIndex.current === null) {\n return;\n }\n if (actualIndex <= flaggedIndex.current && actualIndex + virtualizerLength >= flaggedIndex.current) {\n onRenderedFlaggedIndex(flaggedIndex.current);\n flaggedIndex.current = null;\n }\n }, [\n actualIndex,\n onRenderedFlaggedIndex,\n virtualizerLength\n ]);\n // Ensure we have run through and updated the whole size list array at least once.\n initializeSizeArray();\n if (getItemSize && (numItems !== childSizes.current.length || numItems !== childProgressiveSizes.current.length)) {\n // Child length mismatch, repopulate size arrays.\n populateSizeArrays();\n }\n // Ensure we recalc if virtualizer length changes\n const maxCompare = Math.min(virtualizerLength, numItems);\n if (childArray.current.length !== maxCompare && actualIndex + childArray.current.length < numItems) {\n updateChildRows(actualIndex);\n }\n const isFullyInitialized = hasInitialized.current && actualIndex >= 0;\n return {\n components: {\n before: 'div',\n after: 'div',\n beforeContainer: 'div',\n afterContainer: 'div'\n },\n virtualizedChildren: childArray.current,\n before: slot.always(props.before, {\n defaultProps: {\n ref: setBeforeRef,\n role: 'none'\n },\n elementType: 'div'\n }),\n after: slot.always(props.after, {\n defaultProps: {\n ref: setAfterRef,\n role: 'none'\n },\n elementType: 'div'\n }),\n beforeContainer: slot.always(props.beforeContainer, {\n defaultProps: {\n role: 'none'\n },\n elementType: 'div'\n }),\n afterContainer: slot.always(props.afterContainer, {\n defaultProps: {\n role: 'none'\n },\n elementType: 'div'\n }),\n beforeBufferHeight: isFullyInitialized ? calculateBefore() : 0,\n afterBufferHeight: isFullyInitialized ? calculateAfter() : 0,\n totalVirtualizerHeight: isFullyInitialized ? calculateTotalSize() : virtualizerLength * itemSize,\n virtualizerStartIndex: actualIndex,\n axis,\n bufferSize,\n reversed,\n childSizes,\n childProgressiveSizes\n };\n}\n"],"names":["useVirtualizer_unstable","props","itemSize","numItems","virtualizerLength","children","renderChild","getItemSize","bufferItems","Math","round","bufferSize","floor","scrollViewRef","axis","reversed","virtualizerContext","onRenderedFlaggedIndex","imperativeVirtualizerRef","_virtualizerContext","useVirtualizerContextState_unstable","actualIndexRef","useRef","contextIndex","current","flaggedIndex","actualIndex","setActualIndex","setContextIndex","beforeElementRef","afterElementRef","childSizes","Array","childProgressiveSizes","childArray","forceUpdate","useReducer","horizontal","populateSizeArrays","length","index","isScrolling","setIsScrolling","useState","setScrollTimer","clearScrollTimer","useTimeout","scrollCounter","initializeScrollingTimer","useCallback","INIT_SCROLL_FLAG_REQ","INIT_SCROLL_FLAG_DELAY","useEffect","batchUpdateNewIndex","updateChildRows","updateCurrentItemSizes","setObserverList","useIntersectionObserver","entries","observer","measurementPos","bufferCount","latestEntry","sort","entry1","entry2","time","find","entry","intersectionRatio","target","calculateAfter","calculateTotalSize","abs","boundingClientRect","bottom","top","right","left","calculateBefore","max","startIndex","getIndexFromScrollPosition","bufferedIndex","maxIndex","newStartIndex","min","flushSync","root","rootMargin","threshold","findIndexRecursive","scrollPos","lowIndex","highIndex","midpoint","iBefore","iAfter","indexValue","afterIndexValue","beforeIndexValue","getIndexFromSizeArray","currentIndex","lastItemIndex","remainingItems","newIndex","_actualIndex","end","i","setBeforeRef","element","newList","push","setAfterRef","endIndex","didUpdate","newSize","prevSize","hasInitialized","initializeSizeArray","useImperativeHandle","progressiveSizes","nodeSizes","setFlaggedIndex","maxCompare","isFullyInitialized","components","before","after","beforeContainer","afterContainer","virtualizedChildren","slot","always","defaultProps","ref","role","elementType","beforeBufferHeight","afterBufferHeight","totalVirtualizerHeight","virtualizerStartIndex"],"mappings":";;;;+BAKgBA;;;eAAAA;;;uBAL0E;yCAClD;0BACd;2BAC0B;gCACnB;AAC1B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,oBAAoBb,qBAAqB9C,oBAAoB;QAC7D4D,mBAAmBd,qBAAqBtD,mBAAmB;QAC3DqE,wBAAwBf,qBAAqBrD,uBAAuBpE,oBAAoBF;QACxF2I,uBAAuBnH;QACvBZ;QACAH;QACAI;QACAgB;QACAE;IACJ;AACJ"}
|
|
@@ -10,9 +10,10 @@ Object.defineProperty(exports, "useDynamicVirtualizerPagination", {
|
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
13
14
|
const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
|
|
14
15
|
const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;
|
|
15
|
-
const
|
|
16
|
+
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
|
|
16
17
|
const lastScrollPos = (0, _react.useRef)(-1);
|
|
17
18
|
const lastIndexScrolled = (0, _react.useRef)(-1);
|
|
18
19
|
const scrollContainer = _react.useRef(null);
|
|
@@ -20,9 +21,7 @@ const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = t
|
|
|
20
21
|
if (scrollContainer.current) {
|
|
21
22
|
scrollContainer.current.removeEventListener('scroll', onScroll);
|
|
22
23
|
scrollContainer.current = null;
|
|
23
|
-
|
|
24
|
-
clearTimeout(timeoutRef.current);
|
|
25
|
-
}
|
|
24
|
+
clearScrollTimer();
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
_react.useEffect(()=>{
|
|
@@ -99,12 +98,12 @@ const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = t
|
|
|
99
98
|
/**
|
|
100
99
|
* On scroll timer that will continuously delay callback until scrolling stops
|
|
101
100
|
*/ const onScroll = _react.useCallback((event)=>{
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
timeoutRef.current = setTimeout(onScrollEnd, 100);
|
|
101
|
+
clearScrollTimer();
|
|
102
|
+
setScrollTimer(onScrollEnd, 100);
|
|
106
103
|
}, [
|
|
107
|
-
onScrollEnd
|
|
104
|
+
onScrollEnd,
|
|
105
|
+
clearScrollTimer,
|
|
106
|
+
setScrollTimer
|
|
108
107
|
]);
|
|
109
108
|
/**
|
|
110
109
|
* Pagination ref will ensure we attach listeners to containers on change
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useDynamicPagination.js"],"sourcesContent":["import * as React from 'react';\nimport { useRef } from 'react';\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are dynamic so we require a progressive sizing array (passed in from Dynamic virtualizer hooks)\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerDynamicPaginationProps can be grabbed from dynamic Virtualizer hooks externally and passed in\n */ export const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{\n const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;\n const
|
|
1
|
+
{"version":3,"sources":["useDynamicPagination.js"],"sourcesContent":["import * as React from 'react';\nimport { useRef } from 'react';\nimport { useTimeout } from '@fluentui/react-utilities';\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are dynamic so we require a progressive sizing array (passed in from Dynamic virtualizer hooks)\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerDynamicPaginationProps can be grabbed from dynamic Virtualizer hooks externally and passed in\n */ export const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{\n const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const lastScrollPos = useRef(-1);\n const lastIndexScrolled = useRef(-1);\n const scrollContainer = React.useRef(null);\n const clearListeners = ()=>{\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n scrollContainer.current = null;\n clearScrollTimer();\n }\n };\n React.useEffect(()=>{\n return ()=>{\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n *\n * Users/Virtualizer-Hooks must pass in a cumulative array of sizes\n * This prevents the need to recalculate and ensures size arrays are synced externally\n */ const onScrollEnd = React.useCallback(()=>{\n if (!scrollContainer.current || !paginationEnabled || !(progressiveItemSizes === null || progressiveItemSizes === void 0 ? void 0 : progressiveItemSizes.current)) {\n // No container found\n return;\n }\n const currentScrollPos = Math.round(axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft);\n let closestItemPos = 0;\n let closestItem = 0;\n const endItem = Math.min(currentIndex + virtualizerLength, progressiveItemSizes.current.length);\n for(let i = currentIndex; i < endItem - 1; i++){\n if (currentScrollPos <= progressiveItemSizes.current[i + 1] && currentScrollPos >= progressiveItemSizes.current[i]) {\n // Found our in between position\n const distanceToPrev = Math.abs(currentScrollPos - progressiveItemSizes.current[i]);\n const distanceToNext = Math.abs(progressiveItemSizes.current[i + 1] - currentScrollPos);\n if (distanceToPrev < distanceToNext) {\n closestItem = i;\n } else {\n closestItem = i + 1;\n }\n break;\n }\n }\n let nextItem;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n // This will also handle a case where we scrolled to the exact correct position (noop)\n const isSecondaryScroll = Math.round(lastScrollPos.current - currentScrollPos) === 0;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n // Safeguard nextItem\n nextItem = Math.min(Math.max(0, nextItem), progressiveItemSizes.current.length);\n closestItemPos = progressiveItemSizes.current[nextItem];\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({\n top: closestItemPos,\n behavior: 'smooth'\n });\n } else {\n scrollContainer.current.scrollTo({\n left: closestItemPos,\n behavior: 'smooth'\n });\n }\n lastScrollPos.current = progressiveItemSizes.current[nextItem];\n lastIndexScrolled.current = nextItem;\n }, [\n paginationEnabled,\n currentIndex,\n scrollContainer,\n virtualizerLength,\n axis,\n progressiveItemSizes\n ]);\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */ const onScroll = React.useCallback((event)=>{\n clearScrollTimer();\n setScrollTimer(onScrollEnd, 100);\n }, [\n onScrollEnd,\n clearScrollTimer,\n setScrollTimer\n ]);\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */ const paginationRef = React.useCallback((instance)=>{\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n onScroll,\n onScrollEnd,\n paginationEnabled\n ]);\n return paginationRef;\n};\n"],"names":["useDynamicVirtualizerPagination","virtualizerProps","paginationEnabled","axis","currentIndex","progressiveItemSizes","virtualizerLength","setScrollTimer","clearScrollTimer","useTimeout","lastScrollPos","useRef","lastIndexScrolled","scrollContainer","React","clearListeners","current","removeEventListener","onScroll","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItemPos","closestItem","endItem","min","length","i","distanceToPrev","abs","distanceToNext","nextItem","nextTarget","isSecondaryScroll","posMod","max","scrollTo","top","behavior","left","event","paginationRef","instance","addEventListener"],"mappings":";;;;+BAQiBA;;;eAAAA;;;;iEARM;gCAEI;AAMhB,MAAMA,kCAAkC,CAACC,kBAAkBC,oBAAoB,IAAI;IAC1F,MAAM,EAAEC,OAAO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AgBhC,OAAMO,WAAW,CAAC,CAAC0B;QACvC,IAAI,CAAC7C,mBAAmB;YACpBa;YACAF,gBAAgBG,OAAO,GAAG;YAC1B;QACJ;QACA,IAAIH,gBAAgBG,OAAO,KAAK+B,UAAU;YACtChC;YACAF,gBAAgBG,OAAO,GAAG+B;YAC1B,IAAIlC,gBAAgBG,OAAO,EAAE;gBACzBH,gBAAgBG,OAAO,CAACgC,gBAAgB,CAAC,UAAU9B;YACvD;QACJ;IACJ,GACA;QACIA;QACAE;QACAlB;KACH;IACD,OAAO4C;AACX"}
|
|
@@ -81,11 +81,14 @@ const useIntersectionObserver = (callback, options)=>{
|
|
|
81
81
|
// Observer elements in passed in list and clean up previous list
|
|
82
82
|
// This effect is only triggered when observerList is updated
|
|
83
83
|
(0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
|
|
84
|
-
|
|
84
|
+
const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
|
85
|
+
if (!win) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
observer.current = new win.IntersectionObserver(callback, {
|
|
85
89
|
...observerInit,
|
|
86
90
|
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)
|
|
87
91
|
});
|
|
88
|
-
observer.current = new IntersectionObserver(callback, observerInit);
|
|
89
92
|
// If we have an instance of IO and a list with elements, observer the elements
|
|
90
93
|
if (observer.current && observerList && observerList.length > 0) {
|
|
91
94
|
observerList.forEach((element)=>{
|
|
@@ -102,7 +105,8 @@ const useIntersectionObserver = (callback, options)=>{
|
|
|
102
105
|
}, [
|
|
103
106
|
observerList,
|
|
104
107
|
observerInit,
|
|
105
|
-
callback
|
|
108
|
+
callback,
|
|
109
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView
|
|
106
110
|
]);
|
|
107
111
|
// Do not use internally, we need to track external settings only here
|
|
108
112
|
const setObserverInitExternal = useCallback((newInit)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useIntersectionObserver.js"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */ export const getRTLRootMargin = (ltrRootMargin, target)=>{\n if (target) {\n // get the computed dir for the target element\n const newDir = getComputedStyle(target).direction;\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n return ltrRootMargin;\n};\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */ export const useIntersectionObserver = (callback, options)=>{\n const observer = useRef();\n const [observerList, setObserverList] = useState();\n const { targetDocument } = useFluent();\n var _options_rootMargin;\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState(options && {\n ...options,\n rootMargin: getRTLRootMargin((_options_rootMargin = options.rootMargin) !== null && _options_rootMargin !== void 0 ? _options_rootMargin : '0px', options.root)\n });\n var _options_rootMargin1;\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef((_options_rootMargin1 = options === null || options === void 0 ? void 0 : options.rootMargin) !== null && _options_rootMargin1 !== void 0 ? _options_rootMargin1 : '0px');\n // Callback function to execute when mutations are observed\n const mutationObserverCallback = useCallback((mutationList)=>{\n for (const mutation of mutationList){\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (mutation.type === 'attributes' && mutation.attributeName === 'dir' && (options === null || options === void 0 ? void 0 : options.root) && mutation.target.contains(options === null || options === void 0 ? void 0 : options.root)) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)\n });\n }\n }\n }, [\n ltrRootMargin,\n observerInit,\n options === null || options === void 0 ? void 0 : options.root\n ]);\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: [\n 'dir'\n ]\n });\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(()=>{\n observer.current = new IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)\n });\n observer.current = new IntersectionObserver(callback, observerInit);\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach((element)=>{\n var _observer_current;\n (_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(element);\n });\n }\n // clean up previous elements being listened to\n return ()=>{\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [\n observerList,\n observerInit,\n callback\n ]);\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback((newInit)=>{\n var _newInit_rootMargin;\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = (_newInit_rootMargin = newInit === null || newInit === void 0 ? void 0 : newInit.rootMargin) !== null && _newInit_rootMargin !== void 0 ? _newInit_rootMargin : '0px';\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit === null || newInit === void 0 ? void 0 : newInit.root)\n });\n }, [\n ltrRootMargin,\n setObserverInit\n ]);\n return {\n setObserverList,\n setObserverInit: setObserverInitExternal,\n observer\n };\n};\n"],"names":["getRTLRootMargin","useIntersectionObserver","useCallback","useState","useRef","React","ltrRootMargin","target","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","callback","options","observer","observerList","setObserverList","targetDocument","useFluent","_options_rootMargin","observerInit","setObserverInit","rootMargin","root","_options_rootMargin1","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","useMutationObserver","attributes","subtree","attributeFilter","useIsomorphicLayoutEffect","IntersectionObserver","forEach","element","_observer_current","observe","disconnect","setObserverInitExternal","newInit","_newInit_rootMargin"],"mappings":";;;;;;;;;;;IAUiBA,gBAAgB;eAAhBA;;IA2BAC,uBAAuB;eAAvBA;;;;iEArCM;gCACmB;qCACM;qCAEZ;AADpC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGC;AAO/B,MAAML,mBAAmB,CAACM,eAAeC;IAChD,IAAIA,QAAQ;QACR,8CAA8C;QAC9C,MAAMC,SAASC,iBAAiBF,QAAQG,SAAS;QACjD,+FAA+F;QAC/F,IAAIF,WAAW,OAAO;YAClB,IAAIG,YAAYL;YAChB,MAAMM,eAAeN,cAAcO,KAAK,CAAC;YACzC,2GAA2G;YAC3G,IAAID,aAAaE,MAAM,KAAK,GAAG;gBAC3BH,YAAY,CAAC,EAAEC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAA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,KAAK,IAAI,KAAK,IAAIA,QAAQrB,IAAI;QACtH;IACJ,GAAG;QACCpB;QACAkB;KACH;IACD,OAAO;QACHL;QACAK,iBAAiBsB;QACjB7B;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useIntersectionObserver.js"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */ export const getRTLRootMargin = (ltrRootMargin, target)=>{\n if (target) {\n // get the computed dir for the target element\n const newDir = getComputedStyle(target).direction;\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n return ltrRootMargin;\n};\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */ export const useIntersectionObserver = (callback, options)=>{\n const observer = useRef();\n const [observerList, setObserverList] = useState();\n const { targetDocument } = useFluent();\n var _options_rootMargin;\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState(options && {\n ...options,\n rootMargin: getRTLRootMargin((_options_rootMargin = options.rootMargin) !== null && _options_rootMargin !== void 0 ? _options_rootMargin : '0px', options.root)\n });\n var _options_rootMargin1;\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef((_options_rootMargin1 = options === null || options === void 0 ? void 0 : options.rootMargin) !== null && _options_rootMargin1 !== void 0 ? _options_rootMargin1 : '0px');\n // Callback function to execute when mutations are observed\n const mutationObserverCallback = useCallback((mutationList)=>{\n for (const mutation of mutationList){\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (mutation.type === 'attributes' && mutation.attributeName === 'dir' && (options === null || options === void 0 ? void 0 : options.root) && mutation.target.contains(options === null || options === void 0 ? void 0 : options.root)) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)\n });\n }\n }\n }, [\n ltrRootMargin,\n observerInit,\n options === null || options === void 0 ? void 0 : options.root\n ]);\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: [\n 'dir'\n ]\n });\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(()=>{\n const win = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;\n if (!win) {\n return;\n }\n observer.current = new win.IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)\n });\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach((element)=>{\n var _observer_current;\n (_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(element);\n });\n }\n // clean up previous elements being listened to\n return ()=>{\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [\n observerList,\n observerInit,\n callback,\n targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView\n ]);\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback((newInit)=>{\n var _newInit_rootMargin;\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = (_newInit_rootMargin = newInit === null || newInit === void 0 ? void 0 : newInit.rootMargin) !== null && _newInit_rootMargin !== void 0 ? _newInit_rootMargin : '0px';\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit === null || newInit === void 0 ? void 0 : newInit.root)\n });\n }, [\n ltrRootMargin,\n setObserverInit\n ]);\n return {\n setObserverList,\n setObserverInit: setObserverInitExternal,\n observer\n };\n};\n"],"names":["getRTLRootMargin","useIntersectionObserver","useCallback","useState","useRef","React","ltrRootMargin","target","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","callback","options","observer","observerList","setObserverList","targetDocument","useFluent","_options_rootMargin","observerInit","setObserverInit","rootMargin","root","_options_rootMargin1","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","useMutationObserver","attributes","subtree","attributeFilter","useIsomorphicLayoutEffect","win","defaultView","IntersectionObserver","forEach","element","_observer_current","observe","disconnect","setObserverInitExternal","newInit","_newInit_rootMargin"],"mappings":";;;;;;;;;;;IAUiBA,gBAAgB;eAAhBA;;IA2BAC,uBAAuB;eAAvBA;;;;iEArCM;gCACmB;qCACM;qCAEZ;AADpC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGC;AAO/B,MAAML,mBAAmB,CAACM,eAAeC;IAChD,IAAIA,QAAQ;QACR,8CAA8C;QAC9C,MAAMC,SAASC,iBAAiBF,QAAQG,SAAS;QACjD,+FAA+F;QAC/F,IAAIF,WAAW,OAAO;YAClB,IAAIG,YAAYL;YAChB,MAAMM,eAAeN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F;IACD,sEAAsE;IACtE,MAAMO,0BAA0B9C,YAAY,CAAC+C;QACzC,IAAIC;QACJ,+FAA+F;QAC/F5C,cAAc4B,OAAO,GAAG,AAACgB,CAAAA,sBAAsBD,YAAY,QAAQA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQxB,UAAU,AAAD,MAAO,QAAQyB,wBAAwB,KAAK,IAAIA,sBAAsB;QACxL,iHAAiH;QACjH1B,gBAAgB;YACZ,GAAGyB,OAAO;YACVxB,YAAYzB,iBAAiBM,cAAc4B,OAAO,EAAEe,YAAY,QAAQA,YAAY,KAAK,IAAI,KAAK,IAAIA,QAAQvB,IAAI;QACtH;IACJ,GAAG;QACCpB;QACAkB;KACH;IACD,OAAO;QACHL;QACAK,iBAAiBwB;QACjB/B;IACJ;AACJ"}
|
|
@@ -10,9 +10,10 @@ Object.defineProperty(exports, "useStaticVirtualizerPagination", {
|
|
|
10
10
|
});
|
|
11
11
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _reactutilities = require("@fluentui/react-utilities");
|
|
13
14
|
const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{
|
|
14
15
|
const { itemSize, axis = 'vertical' } = virtualizerProps;
|
|
15
|
-
const
|
|
16
|
+
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
|
|
16
17
|
const lastScrollPos = (0, _react.useRef)(0);
|
|
17
18
|
const lastIndexScrolled = (0, _react.useRef)(0);
|
|
18
19
|
const scrollContainer = _react.useRef(null);
|
|
@@ -20,9 +21,7 @@ const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = tr
|
|
|
20
21
|
if (scrollContainer.current) {
|
|
21
22
|
scrollContainer.current.removeEventListener('scroll', onScroll);
|
|
22
23
|
scrollContainer.current = null;
|
|
23
|
-
|
|
24
|
-
clearTimeout(timeoutRef.current);
|
|
25
|
-
}
|
|
24
|
+
clearScrollTimer();
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
27
|
_react.useEffect(()=>{
|
|
@@ -75,12 +74,12 @@ const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = tr
|
|
|
75
74
|
/**
|
|
76
75
|
* On scroll timer that will continuously delay callback until scrolling stops
|
|
77
76
|
*/ const onScroll = _react.useCallback((event)=>{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
timeoutRef.current = setTimeout(onScrollEnd, 100);
|
|
77
|
+
clearScrollTimer();
|
|
78
|
+
setScrollTimer(onScrollEnd, 100);
|
|
82
79
|
}, [
|
|
83
|
-
onScrollEnd
|
|
80
|
+
onScrollEnd,
|
|
81
|
+
clearScrollTimer,
|
|
82
|
+
setScrollTimer
|
|
84
83
|
]);
|
|
85
84
|
/**
|
|
86
85
|
* Pagination ref will ensure we attach listeners to containers on change
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useStaticPagination.js"],"sourcesContent":["import * as React from 'react';\nimport { useRef } from 'react';\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are uniform/static, we round to the nearest item on long scrolls\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in\n */ export const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{\n const { itemSize, axis = 'vertical' } = virtualizerProps;\n const
|
|
1
|
+
{"version":3,"sources":["useStaticPagination.js"],"sourcesContent":["import * as React from 'react';\nimport { useRef } from 'react';\nimport { useTimeout } from '@fluentui/react-utilities';\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are uniform/static, we round to the nearest item on long scrolls\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in\n */ export const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = true)=>{\n const { itemSize, axis = 'vertical' } = virtualizerProps;\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const lastScrollPos = useRef(0);\n const lastIndexScrolled = useRef(0);\n const scrollContainer = React.useRef(null);\n const clearListeners = ()=>{\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n scrollContainer.current = null;\n clearScrollTimer();\n }\n };\n React.useEffect(()=>{\n return ()=>{\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n */ const onScrollEnd = React.useCallback(()=>{\n if (!scrollContainer.current || !paginationEnabled) {\n // No container found\n return;\n }\n const currentScrollPos = Math.round(axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft);\n const closestItem = Math.round(currentScrollPos / itemSize);\n let nextItem = 0;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n const isSecondaryScroll = lastScrollPos.current === currentScrollPos;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n const nextItemPos = nextItem * itemSize;\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({\n top: nextItemPos,\n behavior: 'smooth'\n });\n } else {\n scrollContainer.current.scrollTo({\n left: nextItemPos,\n behavior: 'smooth'\n });\n }\n lastScrollPos.current = nextItemPos;\n lastIndexScrolled.current = nextItem;\n }, [\n paginationEnabled,\n axis,\n itemSize\n ]);\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */ const onScroll = React.useCallback((event)=>{\n clearScrollTimer();\n setScrollTimer(onScrollEnd, 100);\n }, [\n onScrollEnd,\n clearScrollTimer,\n setScrollTimer\n ]);\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */ const paginationRef = React.useCallback((instance)=>{\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n onScroll,\n onScrollEnd,\n paginationEnabled\n ]);\n return paginationRef;\n};\n"],"names":["useStaticVirtualizerPagination","virtualizerProps","paginationEnabled","itemSize","axis","setScrollTimer","clearScrollTimer","useTimeout","lastScrollPos","useRef","lastIndexScrolled","scrollContainer","React","clearListeners","current","removeEventListener","onScroll","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItem","nextItem","nextTarget","isSecondaryScroll","posMod","nextItemPos","scrollTo","top","behavior","left","event","paginationRef","instance","addEventListener"],"mappings":";;;;+BAQiBA;;;eAAAA;;;;iEARM;gCAEI;AAMhB,MAAMA,iCAAiC,CAACC,kBAAkBC,oBAAoB,IAAI;IACzF,MAAM,EAAEC,QAAQ,EAAEC,OAAO,UAAU,EAAE,GAAGH;IACxC,MAAM,CAACI,gBAAgBC,iBAAiB,GAAGC,IAAAA,0BAAU;IACrD,MAAMC,gBAAgBC,IAAAA,aAAM,EAAC;IAC7B,MAAMC,oBAAoBD,IAAAA,aAAM,EAAC;IACjC,MAAME,kBAAkBC,OAAMH,MAAM,CAAC;IACrC,MAAMI,iBAAiB;QACnB,IAAIF,gBAAgBG,OAAO,EAAE;YACzBH,gBAAgBG,OAAO,CAACC,mBAAmB,CAAC,UAAUC;YACtDL,gBAAgBG,OAAO,GAAG;YAC1BR;QACJ;IACJ;IACAM,OAAMK,SAAS,CAAC;QACZ,OAAO;YACHJ;QACJ;IACJ,uDAAuD;IACvD,GAAG,EAAE;IACL;;;;GAID,GAAG,MAAMK,c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YACAF,gBAAgBG,OAAO,GAAGuB;YAC1B,IAAI1B,gBAAgBG,OAAO,EAAE;gBACzBH,gBAAgBG,OAAO,CAACwB,gBAAgB,CAAC,UAAUtB;YACvD;QACJ;IACJ,GACA;QACIA;QACAE;QACAhB;KACH;IACD,OAAOkC;AACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-virtualizer",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.76",
|
|
4
4
|
"description": "Generic and composable virtualizer framework built on browser intersection observer",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|