@fluentui/react-virtualizer 9.0.0-alpha.58 → 9.0.0-alpha.59

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 CHANGED
@@ -1,12 +1,22 @@
1
1
  # Change Log - @fluentui/react-virtualizer
2
2
 
3
- This log was last generated on Mon, 20 Nov 2023 09:51:22 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 30 Nov 2023 13:37:55 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-alpha.59](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.59)
8
+
9
+ Thu, 30 Nov 2023 13:37:55 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.58..@fluentui/react-virtualizer_v9.0.0-alpha.59)
11
+
12
+ ### Changes
13
+
14
+ - feat: Add default auto-measuring on dynamic virtualizezr if no sizing function provided ([PR #29868](https://github.com/microsoft/fluentui/pull/29868) by mifraser@microsoft.com)
15
+ - Bump @fluentui/react-jsx-runtime to v9.0.20 ([PR #29957](https://github.com/microsoft/fluentui/pull/29957) by beachball)
16
+
7
17
  ## [9.0.0-alpha.58](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.58)
8
18
 
9
- Mon, 20 Nov 2023 09:51:22 GMT
19
+ Mon, 20 Nov 2023 09:55:10 GMT
10
20
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.57..@fluentui/react-virtualizer_v9.0.0-alpha.58)
11
21
 
12
22
  ### Changes
package/dist/index.d.ts CHANGED
@@ -238,6 +238,14 @@ declare type VirtualizerConfigState = {
238
238
  * Minimum 1px.
239
239
  */
240
240
  bufferSize: number;
241
+ /**
242
+ * Ref for access to internal size knowledge, can be used to measure updates
243
+ */
244
+ childSizes: React_2.MutableRefObject<number[]>;
245
+ /**
246
+ * Ref for access to internal progressive size knowledge, can be used to measure updates
247
+ */
248
+ childProgressiveSizes: React_2.MutableRefObject<number[]>;
241
249
  };
242
250
 
243
251
  /**
@@ -296,8 +304,9 @@ export declare type VirtualizerScrollViewDynamicProps = ComponentProps<Partial<V
296
304
  /**
297
305
  * Callback for acquiring size of individual items
298
306
  * @param index - the index of the requested size's child
307
+ * If undefined, Virtualizer will auto-measure by default (performance tradeoff)
299
308
  */
300
- getItemSize: (index: number) => number;
309
+ getItemSize?: (index: number) => number;
301
310
  /**
302
311
  * The total number of items to be virtualized.
303
312
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["Virtualizer.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { VirtualizerContextProps } from '../../Utilities';\nimport type { RefObject, MutableRefObject } from 'react';\n\nexport type VirtualizerSlots = {\n /**\n * The intersection observed 'before' element will detect when scrolling towards the beginning.\n */\n before: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace at the beginning of current DOM children.\n */\n beforeContainer: NonNullable<Slot<'div', 'tr'>>;\n /**\n * The intersection observed 'after' element will detect when scrolling towards the end.\n */\n after: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace after the end of current DOM children.\n */\n afterContainer: NonNullable<Slot<'div', 'tr'>>;\n};\n\nexport type VirtualizerConfigState = {\n /**\n * The current virtualized array of children to show in the DOM.\n */\n virtualizedChildren: React.ReactNode[];\n /**\n * The current start index for the virtualizer, all previous index's will be removed from DOM.\n */\n virtualizerStartIndex: number;\n /**\n * Current buffer height required at beginning of array.\n */\n afterBufferHeight: number;\n /**\n * Current buffer height required at end of array.\n */\n beforeBufferHeight: number;\n /**\n * The total current height of the scrollView/child content.\n */\n totalVirtualizerHeight: number;\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n */\n reversed?: boolean;\n /**\n * Pixel size of intersection observers and how much they 'cross over' into the bufferItems index.\n * Minimum 1px.\n */\n bufferSize: number;\n};\n\nexport type VirtualizerState = ComponentState<VirtualizerSlots> & VirtualizerConfigState;\n\n// Virtualizer render function to procedurally generate children elements as rows or columns via index.\n// Q: Use generic typing and passing through object data or a simple index system?\nexport type VirtualizerChildRenderFunction = (index: number, isScrolling: boolean) => React.ReactNode;\n\nexport type VirtualizerDataRef = {\n progressiveSizes: RefObject<number[]>;\n nodeSizes: RefObject<number[]>;\n setFlaggedIndex: (index: number | null) => void;\n currentIndex: RefObject<number>;\n};\n\nexport type VirtualizerConfigProps = {\n /**\n * Child render function.\n * Iteratively called to return current virtualizer DOM children.\n * Will act as a row or column indexer depending on Virtualizer settings.\n * Can be used dynamically.\n */\n children: VirtualizerChildRenderFunction;\n\n /**\n * Default cell size to use if no custom callback provided.\n * If implementing `getItemSize` this should be the initial and ideally minimum cell size.\n */\n itemSize: number;\n\n /**\n * The total number of items to be virtualized.\n */\n numItems: number;\n\n /**\n * Number of children to render in the DOM during virtualization.\n * Constraints:\n * - Large enough that the items rendered in DOM cover the viewport\n * and intersection observer buffers (buffersize) at both ends.\n */\n virtualizerLength: number;\n\n /**\n * Defaults to 1/4th of virtualizerLength.\n * Controls the number of elements rendered before the current index entering the virtualized viewport.\n * Constraints:\n * - Large enough to cover bufferSize (prevents buffers intersecting into the viewport during rest state).\n * - Small enough that the end buffer and end index (start index + virtualizerLength) is not within viewport at rest.\n */\n bufferItems?: number;\n\n /**\n * Defaults to half of bufferItems size (in pixels).\n * The length (in pixels) before the end/start DOM index where the virtualizer recalculation will be triggered.\n * Increasing this reduces whitespace on ultra-fast scroll, as additional elements\n * are buffered to appear while virtualization recalculates.\n * Constraints:\n * - At least 1px - although this will only trigger the recalculation after bookends (whitespace) enter viewport.\n * - BufferSize must be smaller than bufferItems pixel size, as it prevents bookends entering viewport at rest.\n */\n bufferSize?: number;\n\n /**\n * Enables users to override the intersectionObserverRoot.\n */\n scrollViewRef?: React.MutableRefObject<HTMLElement | null>;\n\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n * This value should be flipped in RTL implementation (TBD whether automate RTL).\n */\n reversed?: boolean;\n\n /**\n * Callback for acquiring size of individual items\n * @param index - the index of the requested size's child\n */\n getItemSize?: (index: number) => number;\n\n /**\n * Virtualizer context can be passed as a prop for extended class use\n */\n virtualizerContext?: VirtualizerContextProps;\n\n /**\n * Callback for notifying when a flagged index has been rendered\n */\n onRenderedFlaggedIndex?: (index: number) => void;\n\n /*\n * Callback for notifying when a flagged index has been rendered\n */\n flaggedIndex?: MutableRefObject<number | null>;\n\n /**\n * Imperative ref contains our scrollTo index functionality for user control.\n */\n imperativeVirtualizerRef?: RefObject<VirtualizerDataRef>;\n};\n\nexport type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>> & VirtualizerConfigProps;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
1
+ {"version":3,"sources":["Virtualizer.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport type { VirtualizerContextProps } from '../../Utilities';\nimport type { RefObject, MutableRefObject } from 'react';\n\nexport type VirtualizerSlots = {\n /**\n * The intersection observed 'before' element will detect when scrolling towards the beginning.\n */\n before: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace at the beginning of current DOM children.\n */\n beforeContainer: NonNullable<Slot<'div', 'tr'>>;\n /**\n * The intersection observed 'after' element will detect when scrolling towards the end.\n */\n after: NonNullable<Slot<'div', 'td'>>;\n /**\n * A block place holding whitespace after the end of current DOM children.\n */\n afterContainer: NonNullable<Slot<'div', 'tr'>>;\n};\n\nexport type VirtualizerConfigState = {\n /**\n * The current virtualized array of children to show in the DOM.\n */\n virtualizedChildren: React.ReactNode[];\n /**\n * The current start index for the virtualizer, all previous index's will be removed from DOM.\n */\n virtualizerStartIndex: number;\n /**\n * Current buffer height required at beginning of array.\n */\n afterBufferHeight: number;\n /**\n * Current buffer height required at end of array.\n */\n beforeBufferHeight: number;\n /**\n * The total current height of the scrollView/child content.\n */\n totalVirtualizerHeight: number;\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n */\n reversed?: boolean;\n /**\n * Pixel size of intersection observers and how much they 'cross over' into the bufferItems index.\n * Minimum 1px.\n */\n bufferSize: number;\n /**\n * Ref for access to internal size knowledge, can be used to measure updates\n */\n childSizes: React.MutableRefObject<number[]>;\n /**\n * Ref for access to internal progressive size knowledge, can be used to measure updates\n */\n childProgressiveSizes: React.MutableRefObject<number[]>;\n};\n\nexport type VirtualizerState = ComponentState<VirtualizerSlots> & VirtualizerConfigState;\n\n// Virtualizer render function to procedurally generate children elements as rows or columns via index.\n// Q: Use generic typing and passing through object data or a simple index system?\nexport type VirtualizerChildRenderFunction = (index: number, isScrolling: boolean) => React.ReactNode;\n\nexport type VirtualizerDataRef = {\n progressiveSizes: RefObject<number[]>;\n nodeSizes: RefObject<number[]>;\n setFlaggedIndex: (index: number | null) => void;\n currentIndex: RefObject<number>;\n};\n\nexport type VirtualizerConfigProps = {\n /**\n * Child render function.\n * Iteratively called to return current virtualizer DOM children.\n * Will act as a row or column indexer depending on Virtualizer settings.\n * Can be used dynamically.\n */\n children: VirtualizerChildRenderFunction;\n\n /**\n * Default cell size to use if no custom callback provided.\n * If implementing `getItemSize` this should be the initial and ideally minimum cell size.\n */\n itemSize: number;\n\n /**\n * The total number of items to be virtualized.\n */\n numItems: number;\n\n /**\n * Number of children to render in the DOM during virtualization.\n * Constraints:\n * - Large enough that the items rendered in DOM cover the viewport\n * and intersection observer buffers (buffersize) at both ends.\n */\n virtualizerLength: number;\n\n /**\n * Defaults to 1/4th of virtualizerLength.\n * Controls the number of elements rendered before the current index entering the virtualized viewport.\n * Constraints:\n * - Large enough to cover bufferSize (prevents buffers intersecting into the viewport during rest state).\n * - Small enough that the end buffer and end index (start index + virtualizerLength) is not within viewport at rest.\n */\n bufferItems?: number;\n\n /**\n * Defaults to half of bufferItems size (in pixels).\n * The length (in pixels) before the end/start DOM index where the virtualizer recalculation will be triggered.\n * Increasing this reduces whitespace on ultra-fast scroll, as additional elements\n * are buffered to appear while virtualization recalculates.\n * Constraints:\n * - At least 1px - although this will only trigger the recalculation after bookends (whitespace) enter viewport.\n * - BufferSize must be smaller than bufferItems pixel size, as it prevents bookends entering viewport at rest.\n */\n bufferSize?: number;\n\n /**\n * Enables users to override the intersectionObserverRoot.\n */\n scrollViewRef?: React.MutableRefObject<HTMLElement | null>;\n\n /**\n * The scroll direction\n * @default vertical\n */\n axis?: 'vertical' | 'horizontal';\n\n /**\n * Tells the virtualizer to measure in the reverse direction (for column-reverse order etc.)\n * This value should be flipped in RTL implementation (TBD whether automate RTL).\n */\n reversed?: boolean;\n\n /**\n * Callback for acquiring size of individual items\n * @param index - the index of the requested size's child\n */\n getItemSize?: (index: number) => number;\n\n /**\n * Virtualizer context can be passed as a prop for extended class use\n */\n virtualizerContext?: VirtualizerContextProps;\n\n /**\n * Callback for notifying when a flagged index has been rendered\n */\n onRenderedFlaggedIndex?: (index: number) => void;\n\n /*\n * Callback for notifying when a flagged index has been rendered\n */\n flaggedIndex?: MutableRefObject<number | null>;\n\n /**\n * Imperative ref contains our scrollTo index functionality for user control.\n */\n imperativeVirtualizerRef?: RefObject<VirtualizerDataRef>;\n};\n\nexport type VirtualizerProps = ComponentProps<Partial<VirtualizerSlots>> & VirtualizerConfigProps;\n"],"names":["React"],"mappings":"AAAA,YAAYA,WAAW,QAAQ"}
@@ -2,7 +2,6 @@ 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 { renderVirtualizerChildPlaceholder } from './renderVirtualizer';
6
5
  import { slot } from '@fluentui/react-utilities';
7
6
  export function useVirtualizer_unstable(props) {
8
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;
@@ -261,7 +260,7 @@ export function useVirtualizer_unstable(props) {
261
260
  const _actualIndex = Math.max(newIndex, 0);
262
261
  const end = Math.min(_actualIndex + virtualizerLength, numItems);
263
262
  for(let i = _actualIndex; i < end; i++){
264
- childArray.current[i - _actualIndex] = renderVirtualizerChildPlaceholder(renderChild(i, isScrolling), i);
263
+ childArray.current[i - _actualIndex] = renderChild(i, isScrolling);
265
264
  }
266
265
  }, [
267
266
  isScrolling,
@@ -436,6 +435,8 @@ export function useVirtualizer_unstable(props) {
436
435
  virtualizerStartIndex: actualIndex,
437
436
  axis,
438
437
  bufferSize,
439
- reversed
438
+ reversed,
439
+ childSizes,
440
+ childProgressiveSizes
440
441
  };
441
442
  }
@@ -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 { renderVirtualizerChildPlaceholder } from './renderVirtualizer';\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] = renderVirtualizerChildPlaceholder(renderChild(i, isScrolling), i);\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 };\n}\n"],"names":["useEffect","useRef","useCallback","useReducer","useImperativeHandle","useState","useIntersectionObserver","flushSync","useVirtualizerContextState_unstable","renderVirtualizerChildPlaceholder","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,iCAAiC,QAAQ,sBAAsB;AACxE,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,oBAAoB,IAAI,EACjDO,aAAaF,KAAKG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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;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 } 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,W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AiD;IACjD,MAAMgF,aAAa1G,KAAKsE,GAAG,CAAC3E,mBAAmBD;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 +1 @@
1
- {"version":3,"sources":["VirtualizerScrollViewDynamic.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState } from '@fluentui/react-utilities';\nimport type {\n VirtualizerConfigProps,\n VirtualizerConfigState,\n VirtualizerChildRenderFunction,\n} from '../Virtualizer/Virtualizer.types';\n\nimport type { VirtualizerScrollViewSlots } from '../VirtualizerScrollView/VirtualizerScrollView.types';\nimport type { RefObject } from 'react';\nimport type { ScrollToInterface } from '../../Utilities';\n\nexport type VirtualizerScrollViewDynamicSlots = VirtualizerScrollViewSlots;\n\nexport type VirtualizerScrollViewDynamicProps = ComponentProps<Partial<VirtualizerScrollViewDynamicSlots>> &\n Partial<Omit<VirtualizerConfigProps, 'itemSize' | 'numItems' | 'getItemSize' | 'children' | 'flagIndex'>> & {\n /**\n * Set as the minimum item size.\n * Axis: 'vertical' = Height\n * Axis: 'horizontal' = Width\n */\n itemSize: number;\n /**\n * Callback for acquiring size of individual items\n * @param index - the index of the requested size's child\n */\n getItemSize: (index: number) => number;\n /**\n * The total number of items to be virtualized.\n */\n numItems: number;\n /**\n * Child render function.\n * Iteratively called to return current virtualizer DOM children.\n * Will act as a row or column indexer depending on Virtualizer settings.\n */\n children: VirtualizerChildRenderFunction;\n /**\n * Imperative ref contains our scrollTo index functionality for user control.\n */\n imperativeRef?: RefObject<ScrollToInterface>;\n };\n\nexport type VirtualizerScrollViewDynamicState = ComponentState<VirtualizerScrollViewDynamicSlots> &\n VirtualizerConfigState;\n"],"names":[],"mappings":"AAAA,WA2CyB"}
1
+ {"version":3,"sources":["VirtualizerScrollViewDynamic.types.ts"],"sourcesContent":["import type { ComponentProps, ComponentState } from '@fluentui/react-utilities';\nimport type {\n VirtualizerConfigProps,\n VirtualizerConfigState,\n VirtualizerChildRenderFunction,\n} from '../Virtualizer/Virtualizer.types';\n\nimport type { VirtualizerScrollViewSlots } from '../VirtualizerScrollView/VirtualizerScrollView.types';\nimport type { RefObject } from 'react';\nimport type { ScrollToInterface } from '../../Utilities';\n\nexport type VirtualizerScrollViewDynamicSlots = VirtualizerScrollViewSlots;\n\nexport type VirtualizerScrollViewDynamicProps = ComponentProps<Partial<VirtualizerScrollViewDynamicSlots>> &\n Partial<Omit<VirtualizerConfigProps, 'itemSize' | 'numItems' | 'getItemSize' | 'children' | 'flagIndex'>> & {\n /**\n * Set as the minimum item size.\n * Axis: 'vertical' = Height\n * Axis: 'horizontal' = Width\n */\n itemSize: number;\n /**\n * Callback for acquiring size of individual items\n * @param index - the index of the requested size's child\n * If undefined, Virtualizer will auto-measure by default (performance tradeoff)\n */\n getItemSize?: (index: number) => number;\n /**\n * The total number of items to be virtualized.\n */\n numItems: number;\n /**\n * Child render function.\n * Iteratively called to return current virtualizer DOM children.\n * Will act as a row or column indexer depending on Virtualizer settings.\n */\n children: VirtualizerChildRenderFunction;\n /**\n * Imperative ref contains our scrollTo index functionality for user control.\n */\n imperativeRef?: RefObject<ScrollToInterface>;\n };\n\nexport type VirtualizerScrollViewDynamicState = ComponentState<VirtualizerScrollViewDynamicSlots> &\n VirtualizerConfigState;\n"],"names":[],"mappings":"AAAA,WA4CyB"}
@@ -4,14 +4,28 @@ import { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';
4
4
  import { useDynamicVirtualizerMeasure } from '../../Hooks';
5
5
  import { useVirtualizerContextState_unstable, scrollToItemDynamic } from '../../Utilities';
6
6
  import { useImperativeHandle } from 'react';
7
+ import { useMeasureList } from '../../hooks/useMeasureList';
7
8
  export function useVirtualizerScrollViewDynamic_unstable(props) {
8
9
  const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);
9
10
  const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;
10
- var _props_axis, _contextState_contextIndex;
11
+ let sizeTrackingArray = React.useRef(new Array(props.numItems).fill(props.itemSize));
12
+ const getChildSizeAuto = React.useCallback((index)=>{
13
+ if (sizeTrackingArray.current.length <= index || sizeTrackingArray.current[index] <= 0) {
14
+ // Default size for initial state or untracked
15
+ return props.itemSize;
16
+ }
17
+ /* Required to be defined prior to our measure function
18
+ * we use a sizing array ref that we will update post-render
19
+ */ return sizeTrackingArray.current[index];
20
+ }, [
21
+ sizeTrackingArray,
22
+ props.itemSize
23
+ ]);
24
+ var _props_axis, _props_getItemSize, _contextState_contextIndex;
11
25
  const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useDynamicVirtualizerMeasure({
12
26
  defaultItemSize: props.itemSize,
13
27
  direction: (_props_axis = props.axis) !== null && _props_axis !== void 0 ? _props_axis : 'vertical',
14
- getItemSize: props.getItemSize,
28
+ getItemSize: (_props_getItemSize = props.getItemSize) !== null && _props_getItemSize !== void 0 ? _props_getItemSize : getChildSizeAuto,
15
29
  currentIndex: (_contextState_contextIndex = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex !== void 0 ? _contextState_contextIndex : 0,
16
30
  numItems: props.numItems
17
31
  });
@@ -58,8 +72,10 @@ export function useVirtualizerScrollViewDynamic_unstable(props) {
58
72
  scrollCallbackRef.current(index);
59
73
  }
60
74
  };
75
+ var _props_getItemSize1;
61
76
  const virtualizerState = useVirtualizer_unstable({
62
77
  ...props,
78
+ getItemSize: (_props_getItemSize1 = props.getItemSize) !== null && _props_getItemSize1 !== void 0 ? _props_getItemSize1 : getChildSizeAuto,
63
79
  virtualizerLength,
64
80
  bufferItems,
65
81
  bufferSize,
@@ -68,6 +84,43 @@ export function useVirtualizerScrollViewDynamic_unstable(props) {
68
84
  imperativeVirtualizerRef: _imperativeVirtualizerRef,
69
85
  onRenderedFlaggedIndex: handleRenderedIndex
70
86
  });
87
+ const measureObject = useMeasureList(virtualizerState.virtualizerStartIndex, virtualizerLength, props.numItems, props.itemSize);
88
+ if (axis === 'horizontal') {
89
+ sizeTrackingArray = measureObject.widthArray;
90
+ } else {
91
+ sizeTrackingArray = measureObject.heightArray;
92
+ }
93
+ if (!props.getItemSize) {
94
+ // Auto-measuring is required
95
+ React.Children.map(virtualizerState.virtualizedChildren, (child, index)=>{
96
+ if (/*#__PURE__*/ React.isValidElement(child)) {
97
+ virtualizerState.virtualizedChildren[index] = /*#__PURE__*/ React.createElement(child.type, {
98
+ ...child.props,
99
+ key: child.key,
100
+ ref: (element)=>{
101
+ // If a ref exists in props, call it
102
+ if (typeof child.props.ref === 'function') {
103
+ child.props.ref(element);
104
+ } else if (child.props.ref) {
105
+ child.props.ref.current = element;
106
+ }
107
+ if (child.hasOwnProperty('ref')) {
108
+ // We must access this from the child directly, not props (forward ref).
109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
+ const localRef = child === null || child === void 0 ? void 0 : child.ref;
111
+ if (typeof localRef === 'function') {
112
+ localRef(element);
113
+ } else if (localRef) {
114
+ localRef.current = element;
115
+ }
116
+ }
117
+ // Call the auto-measure ref attachment.
118
+ measureObject.createIndexedRef(index)(element);
119
+ }
120
+ });
121
+ }
122
+ });
123
+ }
71
124
  return {
72
125
  ...virtualizerState,
73
126
  components: {
@@ -1 +1 @@
1
- {"version":3,"sources":["useVirtualizerScrollViewDynamic.ts"],"sourcesContent":["import * as React from 'react';\nimport { slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';\nimport type {\n VirtualizerScrollViewDynamicProps,\n VirtualizerScrollViewDynamicState,\n} from './VirtualizerScrollViewDynamic.types';\nimport { useDynamicVirtualizerMeasure } from '../../Hooks';\nimport { useVirtualizerContextState_unstable, scrollToItemDynamic } from '../../Utilities';\nimport type { VirtualizerDataRef } from '../Virtualizer/Virtualizer.types';\nimport { useImperativeHandle } from 'react';\n\nexport function useVirtualizerScrollViewDynamic_unstable(\n props: VirtualizerScrollViewDynamicProps,\n): VirtualizerScrollViewDynamicState {\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;\n\n const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useDynamicVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: props.axis ?? 'vertical',\n getItemSize: props.getItemSize,\n currentIndex: contextState?.contextIndex ?? 0,\n numItems: props.numItems,\n });\n\n // Store the virtualizer length as a ref for imperative ref access\n const virtualizerLengthRef = React.useRef<number>(virtualizerLength);\n if (virtualizerLengthRef.current !== virtualizerLength) {\n virtualizerLengthRef.current = virtualizerLength;\n }\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef) as React.RefObject<HTMLDivElement>;\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\n\n const _imperativeVirtualizerRef = useMergedRefs(React.useRef<VirtualizerDataRef>(null), imperativeVirtualizerRef);\n\n useImperativeHandle(\n imperativeRef,\n () => {\n return {\n scrollTo(index: number, behavior = 'auto', callback: undefined | ((index: number) => void)) {\n scrollCallbackRef.current = callback ?? null;\n if (_imperativeVirtualizerRef.current) {\n const progressiveSizes = _imperativeVirtualizerRef.current.progressiveSizes.current;\n const totalSize =\n progressiveSizes && progressiveSizes?.length > 0\n ? progressiveSizes[Math.max(progressiveSizes.length - 1, 0)]\n : 0;\n\n _imperativeVirtualizerRef.current.setFlaggedIndex(index);\n scrollToItemDynamic({\n index,\n itemSizes: _imperativeVirtualizerRef.current?.nodeSizes,\n totalSize,\n scrollViewRef,\n axis,\n reversed,\n behavior,\n });\n }\n },\n currentIndex: _imperativeVirtualizerRef.current?.currentIndex,\n virtualizerLength: virtualizerLengthRef,\n };\n },\n [axis, scrollViewRef, reversed, _imperativeVirtualizerRef],\n );\n\n const handleRenderedIndex = (index: number) => {\n if (scrollCallbackRef.current) {\n scrollCallbackRef.current(index);\n }\n };\n\n const virtualizerState = useVirtualizer_unstable({\n ...props,\n virtualizerLength,\n bufferItems,\n bufferSize,\n scrollViewRef,\n virtualizerContext: contextState,\n imperativeVirtualizerRef: _imperativeVirtualizerRef,\n onRenderedFlaggedIndex: handleRenderedIndex,\n });\n\n return {\n ...virtualizerState,\n components: {\n ...virtualizerState.components,\n container: 'div',\n },\n container: slot.always(props.container, {\n defaultProps: {\n ref: scrollViewRef,\n },\n elementType: 'div',\n }),\n };\n}\n"],"names":["React","slot","useMergedRefs","useVirtualizer_unstable","useDynamicVirtualizerMeasure","useVirtualizerContextState_unstable","scrollToItemDynamic","useImperativeHandle","useVirtualizerScrollViewDynamic_unstable","props","contextState","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","virtualizerLength","bufferItems","bufferSize","scrollRef","defaultItemSize","itemSize","direction","getItemSize","currentIndex","contextIndex","numItems","virtualizerLengthRef","useRef","current","scrollViewRef","scrollCallbackRef","_imperativeVirtualizerRef","scrollTo","index","behavior","callback","progressiveSizes","totalSize","length","Math","max","setFlaggedIndex","itemSizes","nodeSizes","handleRenderedIndex","virtualizerState","onRenderedFlaggedIndex","components","container","always","defaultProps","ref","elementType"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,IAAI,EAAEC,aAAa,QAAQ,4BAA4B;AAChE,SAASC,uBAAuB,QAAQ,gCAAgC;AAKxE,SAASC,4BAA4B,QAAQ,cAAc;AAC3D,SAASC,mCAAmC,EAAEC,mBAAmB,QAAQ,kBAAkB;AAE3F,SAASC,mBAAmB,QAAQ,QAAQ;AAE5C,OAAO,SAASC,yCACdC,KAAwC;IAExC,MAAMC,eAAeL,oCAAoCI,MAAME,kBAAkB;IACjF,MAAM,EAAEC,aAAa,EAAEC,OAAO,UAAU,EAAEC,QAAQ,EAAEC,wBAAwB,EAAE,GAAGN;QAIpEA,aAEGC;IAJhB,MAAM,EAAEM,iBAAiB,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGf,6BAA6B;QAC7FgB,iBAAiBX,MAAMY,QAAQ;QAC/BC,WAAWb,CAAAA,cAAAA,MAAMI,IAAI,cAAVJ,yBAAAA,cAAc;QACzBc,aAAad,MAAMc,WAAW;QAC9BC,cAAcd,CAAAA,6BAAAA,yBAAAA,mCAAAA,aAAce,YAAY,cAA1Bf,wCAAAA,6BAA8B;QAC5CgB,UAAUjB,MAAMiB,QAAQ;IAC1B;IAEA,kEAAkE;IAClE,MAAMC,uBAAuB3B,MAAM4B,MAAM,CAASZ;IAClD,IAAIW,qBAAqBE,OAAO,KAAKb,mBAAmB;QACtDW,qBAAqBE,OAAO,GAAGb;IACjC;IACA,MAAMc,gBAAgB5B,cAAcO,MAAMqB,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ACAA,WAAWhD,KAAKiD,MAAM,CAACzC,MAAMwC,SAAS,EAAE;YACtCE,cAAc;gBACZC,KAAKtB;YACP;YACAuB,aAAa;QACf;IACF;AACF"}
1
+ {"version":3,"sources":["useVirtualizerScrollViewDynamic.tsx"],"sourcesContent":["import * as React from 'react';\nimport { slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';\nimport type {\n VirtualizerScrollViewDynamicProps,\n VirtualizerScrollViewDynamicState,\n} from './VirtualizerScrollViewDynamic.types';\nimport { useDynamicVirtualizerMeasure } from '../../Hooks';\nimport { useVirtualizerContextState_unstable, scrollToItemDynamic } from '../../Utilities';\nimport type { VirtualizerDataRef } from '../Virtualizer/Virtualizer.types';\nimport { useImperativeHandle } from 'react';\nimport { useMeasureList } from '../../hooks/useMeasureList';\nimport type { IndexedResizeCallbackElement } from '../../hooks/useMeasureList';\n\nexport function useVirtualizerScrollViewDynamic_unstable(\n props: VirtualizerScrollViewDynamicProps,\n): VirtualizerScrollViewDynamicState {\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;\n\n let sizeTrackingArray = React.useRef<number[]>(new Array(props.numItems).fill(props.itemSize));\n\n const getChildSizeAuto = React.useCallback(\n (index: number) => {\n if (sizeTrackingArray.current.length <= index || sizeTrackingArray.current[index] <= 0) {\n // Default size for initial state or untracked\n return props.itemSize;\n }\n /* Required to be defined prior to our measure function\n * we use a sizing array ref that we will update post-render\n */\n return sizeTrackingArray.current[index];\n },\n [sizeTrackingArray, props.itemSize],\n );\n\n const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useDynamicVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: props.axis ?? 'vertical',\n getItemSize: props.getItemSize ?? getChildSizeAuto,\n currentIndex: contextState?.contextIndex ?? 0,\n numItems: props.numItems,\n });\n\n // Store the virtualizer length as a ref for imperative ref access\n const virtualizerLengthRef = React.useRef<number>(virtualizerLength);\n if (virtualizerLengthRef.current !== virtualizerLength) {\n virtualizerLengthRef.current = virtualizerLength;\n }\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef) as React.RefObject<HTMLDivElement>;\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\n\n const _imperativeVirtualizerRef = useMergedRefs(React.useRef<VirtualizerDataRef>(null), imperativeVirtualizerRef);\n\n useImperativeHandle(\n imperativeRef,\n () => {\n return {\n scrollTo(index: number, behavior = 'auto', callback: undefined | ((index: number) => void)) {\n scrollCallbackRef.current = callback ?? null;\n if (_imperativeVirtualizerRef.current) {\n const progressiveSizes = _imperativeVirtualizerRef.current.progressiveSizes.current;\n const totalSize =\n progressiveSizes && progressiveSizes?.length > 0\n ? progressiveSizes[Math.max(progressiveSizes.length - 1, 0)]\n : 0;\n\n _imperativeVirtualizerRef.current.setFlaggedIndex(index);\n scrollToItemDynamic({\n index,\n itemSizes: _imperativeVirtualizerRef.current?.nodeSizes,\n totalSize,\n scrollViewRef,\n axis,\n reversed,\n behavior,\n });\n }\n },\n currentIndex: _imperativeVirtualizerRef.current?.currentIndex,\n virtualizerLength: virtualizerLengthRef,\n };\n },\n [axis, scrollViewRef, reversed, _imperativeVirtualizerRef],\n );\n\n const handleRenderedIndex = (index: number) => {\n if (scrollCallbackRef.current) {\n scrollCallbackRef.current(index);\n }\n };\n\n const virtualizerState = useVirtualizer_unstable({\n ...props,\n getItemSize: props.getItemSize ?? getChildSizeAuto,\n virtualizerLength,\n bufferItems,\n bufferSize,\n scrollViewRef,\n virtualizerContext: contextState,\n imperativeVirtualizerRef: _imperativeVirtualizerRef,\n onRenderedFlaggedIndex: handleRenderedIndex,\n });\n\n const measureObject = useMeasureList(\n virtualizerState.virtualizerStartIndex,\n virtualizerLength,\n props.numItems,\n props.itemSize,\n );\n\n if (axis === 'horizontal') {\n sizeTrackingArray = measureObject.widthArray;\n } else {\n sizeTrackingArray = measureObject.heightArray;\n }\n\n if (!props.getItemSize) {\n // Auto-measuring is required\n React.Children.map(virtualizerState.virtualizedChildren, (child, index) => {\n if (React.isValidElement(child)) {\n virtualizerState.virtualizedChildren[index] = (\n <child.type\n {...child.props}\n key={child.key}\n ref={(element: HTMLElement & IndexedResizeCallbackElement) => {\n // If a ref exists in props, call it\n if (typeof child.props.ref === 'function') {\n child.props.ref(element);\n } else if (child.props.ref) {\n child.props.ref.current = element;\n }\n\n if (child.hasOwnProperty('ref')) {\n // We must access this from the child directly, not props (forward ref).\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const localRef = (child as any)?.ref;\n\n if (typeof localRef === 'function') {\n localRef(element);\n } else if (localRef) {\n localRef.current = element;\n }\n }\n\n // Call the auto-measure ref attachment.\n measureObject.createIndexedRef(index)(element);\n }}\n />\n );\n }\n });\n }\n\n return {\n ...virtualizerState,\n components: {\n ...virtualizerState.components,\n container: 'div',\n },\n container: slot.always(props.container, {\n defaultProps: {\n ref: scrollViewRef,\n },\n elementType: 'div',\n }),\n };\n}\n"],"names":["React","slot","useMergedRefs","useVirtualizer_unstable","useDynamicVirtualizerMeasure","useVirtualizerContextState_unstable","scrollToItemDynamic","useImperativeHandle","useMeasureList","useVirtualizerScrollViewDynamic_unstable","props","contextState","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","sizeTrackingArray","useRef","Array","numItems","fill","itemSize","getChildSizeAuto","useCallback","index","current","length","virtualizerLength","bufferItems","bufferSize","scrollRef","defaultItemSize","direction","getItemSize","currentIndex","contextIndex","virtualizerLengthRef","scrollViewRef","scrollCallbackRef","_imperativeVirtualizerRef","scrollTo","behavior","callback","progressiveSizes","totalSize","Math","max","setFlaggedIndex","itemSizes","nodeSizes","handleRenderedIndex","virtualizerState","onRenderedFlaggedIndex","measureObject","virtualizerStartIndex","widthArray","heightArray","Children","map","virtualizedChildren","child","isValidElement","type","key","ref","element","hasOwnProperty","localRef","createIndexedRef","components","container","always","defaultProps","elementType"],"mappings":"AAAA,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rB;wBACF;wBAEA,wCAAwC;wBACxCZ,cAAce,gBAAgB,CAAC5C,OAAOyC;oBACxC;;YAGN;QACF;IACF;IAEA,OAAO;QACL,GAAGd,gBAAgB;QACnBkB,YAAY;YACV,GAAGlB,iBAAiBkB,UAAU;YAC9BC,WAAW;QACb;QACAA,WAAWtE,KAAKuE,MAAM,CAAC9D,MAAM6D,SAAS,EAAE;YACtCE,cAAc;gBACZR,KAAK3B;YACP;YACAoC,aAAa;QACf;IACF;AACF"}
@@ -0,0 +1,101 @@
1
+ import * as React from 'react';
2
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
3
+ /**
4
+ * Provides a way of automating size in the virtualizer
5
+ * Returns
6
+ * `width` - element width ref (0 by default),
7
+ * `height` - element height ref (0 by default),
8
+ * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure
9
+ */ export function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {
10
+ const widthArray = React.useRef(new Array(totalLength).fill(defaultItemSize));
11
+ const heightArray = React.useRef(new Array(totalLength).fill(defaultItemSize));
12
+ const refArray = React.useRef([]);
13
+ const { targetDocument } = useFluent();
14
+ // the handler for resize observer
15
+ const handleIndexUpdate = React.useCallback((index)=>{
16
+ var _refArray_current_index;
17
+ const boundClientRect = (_refArray_current_index = refArray.current[index]) === null || _refArray_current_index === void 0 ? void 0 : _refArray_current_index.getBoundingClientRect();
18
+ const containerWidth = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.width;
19
+ widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;
20
+ const containerHeight = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.height;
21
+ heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;
22
+ }, [
23
+ currentIndex,
24
+ defaultItemSize
25
+ ]);
26
+ const handleElementResizeCallback = (entries)=>{
27
+ for (const entry of entries){
28
+ const target = entry.target;
29
+ // Call the elements own resize handler (indexed)
30
+ target.handleResize();
31
+ }
32
+ };
33
+ React.useEffect(()=>{
34
+ widthArray.current = new Array(totalLength).fill(defaultItemSize);
35
+ heightArray.current = new Array(totalLength).fill(defaultItemSize);
36
+ }, [
37
+ defaultItemSize,
38
+ totalLength
39
+ ]);
40
+ // Keep the reference of ResizeObserver as a ref, as it should live through renders
41
+ const resizeObserver = React.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));
42
+ /* createIndexedRef provides a dynamic function to create an undefined number of refs at render time
43
+ * these refs then provide an indexed callback via attaching 'handleResize' to the element itself
44
+ * this function is then called on resize by handleElementResize and relies on indexing
45
+ * to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.
46
+ */ const createIndexedRef = React.useCallback((index)=>{
47
+ const measureElementRef = (el)=>{
48
+ if (!targetDocument || !resizeObserver.current) {
49
+ return;
50
+ }
51
+ if (el) {
52
+ el.handleResize = ()=>{
53
+ handleIndexUpdate(index);
54
+ };
55
+ }
56
+ // cleanup previous container
57
+ if (refArray.current[index] !== undefined && refArray.current[index] !== null) {
58
+ resizeObserver.current.unobserve(refArray.current[index]);
59
+ }
60
+ refArray.current[index] = undefined;
61
+ if (el) {
62
+ refArray.current[index] = el;
63
+ resizeObserver.current.observe(el);
64
+ handleIndexUpdate(index);
65
+ }
66
+ };
67
+ return measureElementRef;
68
+ }, [
69
+ handleIndexUpdate,
70
+ resizeObserver,
71
+ targetDocument
72
+ ]);
73
+ React.useEffect(()=>{
74
+ const _resizeObserver = resizeObserver;
75
+ return ()=>{
76
+ var _resizeObserver_current;
77
+ return (_resizeObserver_current = _resizeObserver.current) === null || _resizeObserver_current === void 0 ? void 0 : _resizeObserver_current.disconnect();
78
+ };
79
+ }, [
80
+ resizeObserver
81
+ ]);
82
+ return {
83
+ widthArray,
84
+ heightArray,
85
+ createIndexedRef,
86
+ refArray
87
+ };
88
+ }
89
+ /**
90
+ * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar
91
+ * A utility method that creates a ResizeObserver from a target document
92
+ * @param targetDocument - document to use to create the ResizeObserver
93
+ * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback
94
+ * @returns a ResizeObserver instance or null if the global does not exist on the document
95
+ */ export function createResizeObserverFromDocument(targetDocument, callback) {
96
+ var _targetDocument_defaultView;
97
+ if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {
98
+ return null;
99
+ }
100
+ return new targetDocument.defaultView.ResizeObserver(callback);
101
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useMeasureList.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nexport interface IndexedResizeCallbackElement {\n handleResize: () => void;\n}\n/**\n * Provides a way of automating size in the virtualizer\n * Returns\n * `width` - element width ref (0 by default),\n * `height` - element height ref (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */\nexport function useMeasureList<\n TElement extends HTMLElement & IndexedResizeCallbackElement = HTMLElement & IndexedResizeCallbackElement,\n>(currentIndex: number, refLength: number, totalLength: number, defaultItemSize: number) {\n const widthArray = React.useRef(new Array(totalLength).fill(defaultItemSize));\n const heightArray = React.useRef(new Array(totalLength).fill(defaultItemSize));\n\n const refArray = React.useRef<Array<TElement | undefined | null>>([]);\n const { targetDocument } = useFluent();\n\n // the handler for resize observer\n const handleIndexUpdate = React.useCallback(\n (index: number) => {\n const boundClientRect = refArray.current[index]?.getBoundingClientRect();\n const containerWidth = boundClientRect?.width;\n widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;\n\n const containerHeight = boundClientRect?.height;\n heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;\n },\n [currentIndex, defaultItemSize],\n );\n\n const handleElementResizeCallback = (entries: ResizeObserverEntry[]) => {\n for (const entry of entries) {\n const target = entry.target as TElement;\n // Call the elements own resize handler (indexed)\n target.handleResize();\n }\n };\n\n React.useEffect(() => {\n widthArray.current = new Array(totalLength).fill(defaultItemSize);\n heightArray.current = new Array(totalLength).fill(defaultItemSize);\n }, [defaultItemSize, totalLength]);\n\n // Keep the reference of ResizeObserver as a ref, as it should live through renders\n const resizeObserver = React.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));\n\n /* createIndexedRef provides a dynamic function to create an undefined number of refs at render time\n * these refs then provide an indexed callback via attaching 'handleResize' to the element itself\n * this function is then called on resize by handleElementResize and relies on indexing\n * to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.\n */\n const createIndexedRef = React.useCallback(\n (index: number) => {\n const measureElementRef = (el: TElement) => {\n if (!targetDocument || !resizeObserver.current) {\n return;\n }\n\n if (el) {\n el.handleResize = () => {\n handleIndexUpdate(index);\n };\n }\n\n // cleanup previous container\n if (refArray.current[index] !== undefined && refArray.current[index] !== null) {\n resizeObserver.current.unobserve(refArray.current[index]!);\n }\n\n refArray.current[index] = undefined;\n if (el) {\n refArray.current[index] = el;\n resizeObserver.current.observe(el);\n handleIndexUpdate(index);\n }\n };\n\n return measureElementRef;\n },\n [handleIndexUpdate, resizeObserver, targetDocument],\n );\n\n React.useEffect(() => {\n const _resizeObserver = resizeObserver;\n return () => _resizeObserver.current?.disconnect();\n }, [resizeObserver]);\n\n return { widthArray, heightArray, createIndexedRef, refArray };\n}\n\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */\nexport function createResizeObserverFromDocument(\n targetDocument: Document | null | undefined,\n callback: ResizeObserverCallback,\n) {\n if (!targetDocument?.defaultView?.ResizeObserver) {\n return null;\n }\n\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["React","useFluent_unstable","useFluent","useMeasureList","currentIndex","refLength","totalLength","defaultItemSize","widthArray","useRef","Array","fill","heightArray","refArray","targetDocument","handleIndexUpdate","useCallback","index","boundClientRect","current","getBoundingClientRect","containerWidth","width","containerHeight","height","handleElementResizeCallback","entries","entry","target","handleResize","useEffect","resizeObserver","createResizeObserverFromDocument","createIndexedRef","measureElementRef","el","undefined","unobserve","observe","_resizeObserver","disconnect","callback","defaultView","ResizeObserver"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAKlF;;;;;;CAMC,GACD,OAAO,SAASC,eAEdC,YAAoB,EAAEC,SAAiB,EAAEC,WAAmB,EAAEC,eAAuB;IACrF,MAAMC,aAAaR,MAAMS,MAAM,CAAC,IAAIC,MAAMJ,aAAaK,IAAI,CAACJ;IAC5D,MAAMK,cAAcZ,MAAMS,MAAM,CAAC,IAAIC,MAAMJ,aAAaK,IAAI,CAACJ;IAE7D,MAAMM,WAAWb,MAAMS,MAAM,CAAqC,EAAE;IACpE,MAAM,EAAEK,cAAc,EAAE,GAAGZ;IAE3B,kCAAkC;IAClC,MAAMa,oBAAoBf,MAAMgB,WAAW,CACzC,CAACC;YACyBJ;QAAxB,MAAMK,mBAAkBL,0BAAAA,SAASM,OAAO,CAACF,MAAM,cAAvBJ,8CAAAA,wBAAyBO,qBAAqB;QACtE,MAAMC,iBAAiBH,4BAAAA,sCAAAA,gBAAiBI,KAAK;QAC7Cd,WAAWW,OAAO,CAACf,eAAea,MAAM,GAAGI,kBAAkBd;QAE7D,MAAMgB,kBAAkBL,4BAAAA,sCAAAA,gBAAiBM,MAAM;QAC/CZ,YAAYO,OAAO,CAACf,eAAea,MAAM,GAAGM,mBAAmBhB;IACjE,GACA;QAACH;QAAcG;KAAgB;IAGjC,MAAMkB,8BAA8B,CAACC;QACnC,KAAK,MAAMC,SAASD,QAAS;YAC3B,MAAME,SAASD,MAAMC,MAAM;YAC3B,i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AA2C,EAC3C2B,QAAgC;QAE3B3B;IAAL,IAAI,EAACA,2BAAAA,sCAAAA,8BAAAA,eAAgB4B,WAAW,cAA3B5B,kDAAAA,4BAA6B6B,cAAc,GAAE;QAChD,OAAO;IACT;IAEA,OAAO,IAAI7B,eAAe4B,WAAW,CAACC,cAAc,CAACF;AACvD"}
@@ -12,7 +12,6 @@ const _react = require("react");
12
12
  const _useIntersectionObserver = require("../../hooks/useIntersectionObserver");
13
13
  const _reactdom = require("react-dom");
14
14
  const _Utilities = require("../../Utilities");
15
- const _renderVirtualizer = require("./renderVirtualizer");
16
15
  const _reactutilities = require("@fluentui/react-utilities");
17
16
  function useVirtualizer_unstable(props) {
18
17
  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;
@@ -271,7 +270,7 @@ function useVirtualizer_unstable(props) {
271
270
  const _actualIndex = Math.max(newIndex, 0);
272
271
  const end = Math.min(_actualIndex + virtualizerLength, numItems);
273
272
  for(let i = _actualIndex; i < end; i++){
274
- childArray.current[i - _actualIndex] = (0, _renderVirtualizer.renderVirtualizerChildPlaceholder)(renderChild(i, isScrolling), i);
273
+ childArray.current[i - _actualIndex] = renderChild(i, isScrolling);
275
274
  }
276
275
  }, [
277
276
  isScrolling,
@@ -446,6 +445,8 @@ function useVirtualizer_unstable(props) {
446
445
  virtualizerStartIndex: actualIndex,
447
446
  axis,
448
447
  bufferSize,
449
- reversed
448
+ reversed,
449
+ childSizes,
450
+ childProgressiveSizes
450
451
  };
451
452
  }
@@ -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 { renderVirtualizerChildPlaceholder } from './renderVirtualizer';\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] = renderVirtualizerChildPlaceholder(renderChild(i, isScrolling), i);\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 };\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","renderVirtualizerChildPlaceholder","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":";;;;+BAMgBA;;;eAAAA;;;uBAN0E;yCAClD;0BACd;2BAC0B;mCACF;gCAC7B;AACd,SAASA,wBAAwBC,KAAK;IACzC,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,iBAAiB,EAAEC,UAAUC,WAAW,EAAEC,WAAW,EAAEC,cAAcC,KAAKC,KAAK,CAACN,oBAAoB,IAAI,EAAEO,aAAaF,KAAKG,KAAK,CAACJ,cAAc,OAAON,QAAQ,EAAEW,aAAa,EAAEC,OAAO,UAAU,EAAEC,WAAW,KAAK,EAAEC,kBAAkB,EAAEC,sBAAsB,EAAEC,wBAAwB,EAAE,GAAGjB;IAC1T,iHAAiH,GAAG,MAAMkB,sBAAsBC,IAAAA,8CAAmC,EAACJ;IACpL,sFAAsF;IACtF,MAAMK,iBAAiBC,IAAAA,aAAM,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AapH,KAAK4E,GAAG,CAACjF,mBAAmBD;IAC/C,IAAI+B,WAAWV,OAAO,CAACe,MAAM,KAAKsF,cAAcnG,cAAcQ,WAAWV,OAAO,CAACe,MAAM,GAAGpC,UAAU;QAChGkD,gBAAgB3B;IACpB;IACA,MAAMoG,qBAAqBP,eAAe/F,OAAO,IAAIE,eAAe;IACpE,OAAO;QACHqG,YAAY;YACRC,QAAQ;YACRC,OAAO;YACPC,iBAAiB;YACjBC,gBAAgB;QACpB;QACAC,qBAAqBlG,WAAWV,OAAO;QACvCwG,QAAQK,oBAAI,CAACC,MAAM,CAACrI,MAAM+H,MAAM,EAAE;YAC9BO,cAAc;gBACVC,KAAK1B;gBACL2B,MAAM;YACV;YACAC,aAAa;QACjB;QACAT,OAAOI,oBAAI,CAACC,MAAM,CAACrI,MAAMgI,KAAK,EAAE;YAC5BM,cAAc;gBACVC,KAAKtB;gBACLuB,MAAM;YACV;YACAC,aAAa;QACjB;QACAR,iBAAiBG,oBAAI,CAACC,MAAM,CAACrI,MAAMiI,eAAe,EAAE;YAChDK,cAAc;gBACVE,MAAM;YACV;YACAC,aAAa;QACjB;QACAP,gBAAgBE,oBAAI,CAACC,MAAM,CAACrI,MAAMkI,cAAc,EAAE;YAC9CI,cAAc;gBACVE,MAAM;YACV;YACAC,aAAa;QACjB;QACAC,oBAAoBb,qBAAqBhD,oBAAoB;QAC7D8D,mBAAmBd,qBAAqBxD,mBAAmB;QAC3DuE,wBAAwBf,qBAAqBvD,uBAAuBnE,oBAAoBF;QACxF4I,uBAAuBpH;QACvBZ;QACAH;QACAI;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 } 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","afterBufferHeight","totalVirtualizerHeight","virtualizerStartIndex"],"mappings":";;;;+BAKgBA;;;eAAAA;;;uBAL0E;yCAClD;0BACd;2BAC0B;gCAC/B;AACd,SAASA,wBAAwBC,KAAK;IACzC,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,iBAAiB,EAAEC,UAAUC,WAAW,EAAEC,WAAW,EAAEC,cAAcC,KAAKC,KAAK,CAACN,oBAAoB,IAAI,EAAEO,aAAaF,KAAKG,KAAK,CAACJ,cAAc,OAAON,QAAQ,EAAEW,aAAa,EAAEC,OAAO,UAAU,EAAEC,WAAW,KAAK,EAAEC,kBAAkB,EAAEC,sBAAsB,EAAEC,wBAAwB,EAAE,GAAGjB;IAC1T,iHAAiH,GAAG,MAAMkB,sBAAsBC,IAAAA,8CAAmC,EAACJ;IACpL,sFAAsF;IACtF,MAAMK,iBAAiBC,IAAAA,aAAM,EAACH,oBAAoBI,YAAY;IAC9D,IAAIF,eAAeG,OAAO,KAAKL,oBAAoBI,YAAY,EAAE;QAC7DF,eAAeG,OAAO,GAAGL,oBAAoBI,YAAY;IAC7D;IACA,MAAME,eAAeH,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AAMmG,qBAAqBP,eAAe9F,OAAO,IAAIE,eAAe;IACpE,OAAO;QACHoG,YAAY;YACRC,QAAQ;YACRC,OAAO;YACPC,iBAAiB;YACjBC,gBAAgB;QACpB;QACAC,qBAAqBjG,WAAWV,OAAO;QACvCuG,QAAQK,oBAAI,CAACC,MAAM,CAACpI,MAAM8H,MAAM,EAAE;YAC9BO,cAAc;gBACVC,KAAK1B;gBACL2B,MAAM;YACV;YACAC,aAAa;QACjB;QACAT,OAAOI,oBAAI,CAACC,MAAM,CAACpI,MAAM+H,KAAK,EAAE;YAC5BM,cAAc;gBACVC,KAAKtB;gBACLuB,MAAM;YACV;YACAC,aAAa;QACjB;QACAR,iBAAiBG,oBAAI,CAACC,MAAM,CAACpI,MAAMgI,eAAe,EAAE;YAChDK,cAAc;gBACVE,MAAM;YACV;YACAC,aAAa;QACjB;QACAP,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"}
@@ -14,14 +14,28 @@ const _reactutilities = require("@fluentui/react-utilities");
14
14
  const _useVirtualizer = require("../Virtualizer/useVirtualizer");
15
15
  const _Hooks = require("../../Hooks");
16
16
  const _Utilities = require("../../Utilities");
17
+ const _useMeasureList = require("../../hooks/useMeasureList");
17
18
  function useVirtualizerScrollViewDynamic_unstable(props) {
18
19
  const contextState = (0, _Utilities.useVirtualizerContextState_unstable)(props.virtualizerContext);
19
20
  const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;
20
- var _props_axis, _contextState_contextIndex;
21
+ let sizeTrackingArray = _react.useRef(new Array(props.numItems).fill(props.itemSize));
22
+ const getChildSizeAuto = _react.useCallback((index)=>{
23
+ if (sizeTrackingArray.current.length <= index || sizeTrackingArray.current[index] <= 0) {
24
+ // Default size for initial state or untracked
25
+ return props.itemSize;
26
+ }
27
+ /* Required to be defined prior to our measure function
28
+ * we use a sizing array ref that we will update post-render
29
+ */ return sizeTrackingArray.current[index];
30
+ }, [
31
+ sizeTrackingArray,
32
+ props.itemSize
33
+ ]);
34
+ var _props_axis, _props_getItemSize, _contextState_contextIndex;
21
35
  const { virtualizerLength, bufferItems, bufferSize, scrollRef } = (0, _Hooks.useDynamicVirtualizerMeasure)({
22
36
  defaultItemSize: props.itemSize,
23
37
  direction: (_props_axis = props.axis) !== null && _props_axis !== void 0 ? _props_axis : 'vertical',
24
- getItemSize: props.getItemSize,
38
+ getItemSize: (_props_getItemSize = props.getItemSize) !== null && _props_getItemSize !== void 0 ? _props_getItemSize : getChildSizeAuto,
25
39
  currentIndex: (_contextState_contextIndex = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex !== void 0 ? _contextState_contextIndex : 0,
26
40
  numItems: props.numItems
27
41
  });
@@ -68,8 +82,10 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
68
82
  scrollCallbackRef.current(index);
69
83
  }
70
84
  };
85
+ var _props_getItemSize1;
71
86
  const virtualizerState = (0, _useVirtualizer.useVirtualizer_unstable)({
72
87
  ...props,
88
+ getItemSize: (_props_getItemSize1 = props.getItemSize) !== null && _props_getItemSize1 !== void 0 ? _props_getItemSize1 : getChildSizeAuto,
73
89
  virtualizerLength,
74
90
  bufferItems,
75
91
  bufferSize,
@@ -78,6 +94,43 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
78
94
  imperativeVirtualizerRef: _imperativeVirtualizerRef,
79
95
  onRenderedFlaggedIndex: handleRenderedIndex
80
96
  });
97
+ const measureObject = (0, _useMeasureList.useMeasureList)(virtualizerState.virtualizerStartIndex, virtualizerLength, props.numItems, props.itemSize);
98
+ if (axis === 'horizontal') {
99
+ sizeTrackingArray = measureObject.widthArray;
100
+ } else {
101
+ sizeTrackingArray = measureObject.heightArray;
102
+ }
103
+ if (!props.getItemSize) {
104
+ // Auto-measuring is required
105
+ _react.Children.map(virtualizerState.virtualizedChildren, (child, index)=>{
106
+ if (/*#__PURE__*/ _react.isValidElement(child)) {
107
+ virtualizerState.virtualizedChildren[index] = /*#__PURE__*/ _react.createElement(child.type, {
108
+ ...child.props,
109
+ key: child.key,
110
+ ref: (element)=>{
111
+ // If a ref exists in props, call it
112
+ if (typeof child.props.ref === 'function') {
113
+ child.props.ref(element);
114
+ } else if (child.props.ref) {
115
+ child.props.ref.current = element;
116
+ }
117
+ if (child.hasOwnProperty('ref')) {
118
+ // We must access this from the child directly, not props (forward ref).
119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
+ const localRef = child === null || child === void 0 ? void 0 : child.ref;
121
+ if (typeof localRef === 'function') {
122
+ localRef(element);
123
+ } else if (localRef) {
124
+ localRef.current = element;
125
+ }
126
+ }
127
+ // Call the auto-measure ref attachment.
128
+ measureObject.createIndexedRef(index)(element);
129
+ }
130
+ });
131
+ }
132
+ });
133
+ }
81
134
  return {
82
135
  ...virtualizerState,
83
136
  components: {
@@ -1 +1 @@
1
- {"version":3,"sources":["useVirtualizerScrollViewDynamic.js"],"sourcesContent":["import * as React from 'react';\nimport { slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';\nimport { useDynamicVirtualizerMeasure } from '../../Hooks';\nimport { useVirtualizerContextState_unstable, scrollToItemDynamic } from '../../Utilities';\nimport { useImperativeHandle } from 'react';\nexport function useVirtualizerScrollViewDynamic_unstable(props) {\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;\n var _props_axis, _contextState_contextIndex;\n const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useDynamicVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: (_props_axis = props.axis) !== null && _props_axis !== void 0 ? _props_axis : 'vertical',\n getItemSize: props.getItemSize,\n currentIndex: (_contextState_contextIndex = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex !== void 0 ? _contextState_contextIndex : 0,\n numItems: props.numItems\n });\n // Store the virtualizer length as a ref for imperative ref access\n const virtualizerLengthRef = React.useRef(virtualizerLength);\n if (virtualizerLengthRef.current !== virtualizerLength) {\n virtualizerLengthRef.current = virtualizerLength;\n }\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef);\n const scrollCallbackRef = React.useRef(null);\n const _imperativeVirtualizerRef = useMergedRefs(React.useRef(null), imperativeVirtualizerRef);\n useImperativeHandle(imperativeRef, ()=>{\n var _imperativeVirtualizerRef_current;\n return {\n scrollTo (index, behavior = 'auto', callback) {\n scrollCallbackRef.current = callback !== null && callback !== void 0 ? callback : null;\n if (_imperativeVirtualizerRef.current) {\n var _imperativeVirtualizerRef_current;\n const progressiveSizes = _imperativeVirtualizerRef.current.progressiveSizes.current;\n const totalSize = progressiveSizes && (progressiveSizes === null || progressiveSizes === void 0 ? void 0 : progressiveSizes.length) > 0 ? progressiveSizes[Math.max(progressiveSizes.length - 1, 0)] : 0;\n _imperativeVirtualizerRef.current.setFlaggedIndex(index);\n scrollToItemDynamic({\n index,\n itemSizes: (_imperativeVirtualizerRef_current = _imperativeVirtualizerRef.current) === null || _imperativeVirtualizerRef_current === void 0 ? void 0 : _imperativeVirtualizerRef_current.nodeSizes,\n totalSize,\n scrollViewRef,\n axis,\n reversed,\n behavior\n });\n }\n },\n currentIndex: (_imperativeVirtualizerRef_current = _imperativeVirtualizerRef.current) === null || _imperativeVirtualizerRef_current === void 0 ? void 0 : _imperativeVirtualizerRef_current.currentIndex,\n virtualizerLength: virtualizerLengthRef\n };\n }, [\n axis,\n scrollViewRef,\n reversed,\n _imperativeVirtualizerRef\n ]);\n const handleRenderedIndex = (index)=>{\n if (scrollCallbackRef.current) {\n scrollCallbackRef.current(index);\n }\n };\n const virtualizerState = useVirtualizer_unstable({\n ...props,\n virtualizerLength,\n bufferItems,\n bufferSize,\n scrollViewRef,\n virtualizerContext: contextState,\n imperativeVirtualizerRef: _imperativeVirtualizerRef,\n onRenderedFlaggedIndex: handleRenderedIndex\n });\n return {\n ...virtualizerState,\n components: {\n ...virtualizerState.components,\n container: 'div'\n },\n container: slot.always(props.container, {\n defaultProps: {\n ref: scrollViewRef\n },\n elementType: 'div'\n })\n };\n}\n"],"names":["useVirtualizerScrollViewDynamic_unstable","props","contextState","useVirtualizerContextState_unstable","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","_props_axis","_contextState_contextIndex","virtualizerLength","bufferItems","bufferSize","scrollRef","useDynamicVirtualizerMeasure","defaultItemSize","itemSize","direction","getItemSize","currentIndex","contextIndex","numItems","virtualizerLengthRef","React","useRef","current","scrollViewRef","useMergedRefs","scrollCallbackRef","_imperativeVirtualizerRef","useImperativeHandle","_imperativeVirtualizerRef_current","scrollTo","index","behavior","callback","progressiveSizes","totalSize","length","Math","max","setFlaggedIndex","scrollToItemDynamic","itemSizes","nodeSizes","handleRenderedIndex","virtualizerState","useVirtualizer_unstable","onRenderedFlaggedIndex","components","container","slot","always","defaultProps","ref","elementType"],"mappings":";;;;+BAMgBA;;;eAAAA;;;;iEANO;gCACa;gCACI;uBACK;2BAC4B;AAElE,SAASA,yCAAyCC,KAAK;IAC1D,MAAMC,eAAeC,IAAAA,8CAAmC,EAACF,MAAMG,kBAAkB;IACjF,MAAM,EAAEC,aAAa,EAAEC,OAAO,UAAU,EAAEC,QAAQ,EAAEC,wBAAwB,EAAE,GAAGP;IACjF,IAAIQ,aAAaC;IACjB,MAAM,EAAEC,iBAAiB,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGC,IAAAA,mCAA4B,EAAC;QAC3FC,iBAAiBf,MAAMgB,QAAQ;QAC/BC,WAAW,AAACT,CAAA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CF,0BAA0BJ,OAAO,AAAD,MAAO,QAAQM,sCAAsC,KAAK,IAAI,KAAK,IAAIA,kCAAkCa,SAAS;wBAClMP;wBACAX;wBACArB;wBACAC;wBACA4B;oBACJ;gBACJ;YACJ;YACAf,cAAc,AAACY,CAAAA,oCAAoCF,0BAA0BJ,OAAO,AAAD,MAAO,QAAQM,sCAAsC,KAAK,IAAI,KAAK,IAAIA,kCAAkCZ,YAAY;YACxMT,mBAAmBY;QACvB;IACJ,GAAG;QACCjB;QACAqB;QACApB;QACAuB;KACH;IACD,MAAMgB,sBAAsB,CAACZ;QACzB,IAAIL,kBAAkBH,OAAO,EAAE;YAC3BG,kBAAkBH,OAAO,CAACQ;QAC9B;IACJ;IACA,MAAMa,mBAAmBC,IAAAA,uCAAuB,EAAC;QAC7C,GAAG/C,KAAK;QACRU;QACAC;QACAC;QACAc;QACAvB,oBAAoBF;QACpBM,0BAA0BsB;QAC1BmB,wBAAwBH;IAC5B;IACA,OAAO;QACH,GAAGC,gBAAgB;QACnBG,YAAY;YACR,GAAGH,iBAAiBG,UAAU;YAC9BC,WAAW;QACf;QACAA,WAAWC,oBAAI,CAACC,MAAM,CAACpD,MAAMkD,SAAS,EAAE;YACpCG,cAAc;gBACVC,KAAK5B;YACT;YACA6B,aAAa;QACjB;IACJ;AACJ"}
1
+ {"version":3,"sources":["useVirtualizerScrollViewDynamic.js"],"sourcesContent":["import * as React from 'react';\nimport { slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';\nimport { useDynamicVirtualizerMeasure } from '../../Hooks';\nimport { useVirtualizerContextState_unstable, scrollToItemDynamic } from '../../Utilities';\nimport { useImperativeHandle } from 'react';\nimport { useMeasureList } from '../../hooks/useMeasureList';\nexport function useVirtualizerScrollViewDynamic_unstable(props) {\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;\n let sizeTrackingArray = React.useRef(new Array(props.numItems).fill(props.itemSize));\n const getChildSizeAuto = React.useCallback((index)=>{\n if (sizeTrackingArray.current.length <= index || sizeTrackingArray.current[index] <= 0) {\n // Default size for initial state or untracked\n return props.itemSize;\n }\n /* Required to be defined prior to our measure function\n * we use a sizing array ref that we will update post-render\n */ return sizeTrackingArray.current[index];\n }, [\n sizeTrackingArray,\n props.itemSize\n ]);\n var _props_axis, _props_getItemSize, _contextState_contextIndex;\n const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useDynamicVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: (_props_axis = props.axis) !== null && _props_axis !== void 0 ? _props_axis : 'vertical',\n getItemSize: (_props_getItemSize = props.getItemSize) !== null && _props_getItemSize !== void 0 ? _props_getItemSize : getChildSizeAuto,\n currentIndex: (_contextState_contextIndex = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex !== void 0 ? _contextState_contextIndex : 0,\n numItems: props.numItems\n });\n // Store the virtualizer length as a ref for imperative ref access\n const virtualizerLengthRef = React.useRef(virtualizerLength);\n if (virtualizerLengthRef.current !== virtualizerLength) {\n virtualizerLengthRef.current = virtualizerLength;\n }\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef);\n const scrollCallbackRef = React.useRef(null);\n const _imperativeVirtualizerRef = useMergedRefs(React.useRef(null), imperativeVirtualizerRef);\n useImperativeHandle(imperativeRef, ()=>{\n var _imperativeVirtualizerRef_current;\n return {\n scrollTo (index, behavior = 'auto', callback) {\n scrollCallbackRef.current = callback !== null && callback !== void 0 ? callback : null;\n if (_imperativeVirtualizerRef.current) {\n var _imperativeVirtualizerRef_current;\n const progressiveSizes = _imperativeVirtualizerRef.current.progressiveSizes.current;\n const totalSize = progressiveSizes && (progressiveSizes === null || progressiveSizes === void 0 ? void 0 : progressiveSizes.length) > 0 ? progressiveSizes[Math.max(progressiveSizes.length - 1, 0)] : 0;\n _imperativeVirtualizerRef.current.setFlaggedIndex(index);\n scrollToItemDynamic({\n index,\n itemSizes: (_imperativeVirtualizerRef_current = _imperativeVirtualizerRef.current) === null || _imperativeVirtualizerRef_current === void 0 ? void 0 : _imperativeVirtualizerRef_current.nodeSizes,\n totalSize,\n scrollViewRef,\n axis,\n reversed,\n behavior\n });\n }\n },\n currentIndex: (_imperativeVirtualizerRef_current = _imperativeVirtualizerRef.current) === null || _imperativeVirtualizerRef_current === void 0 ? void 0 : _imperativeVirtualizerRef_current.currentIndex,\n virtualizerLength: virtualizerLengthRef\n };\n }, [\n axis,\n scrollViewRef,\n reversed,\n _imperativeVirtualizerRef\n ]);\n const handleRenderedIndex = (index)=>{\n if (scrollCallbackRef.current) {\n scrollCallbackRef.current(index);\n }\n };\n var _props_getItemSize1;\n const virtualizerState = useVirtualizer_unstable({\n ...props,\n getItemSize: (_props_getItemSize1 = props.getItemSize) !== null && _props_getItemSize1 !== void 0 ? _props_getItemSize1 : getChildSizeAuto,\n virtualizerLength,\n bufferItems,\n bufferSize,\n scrollViewRef,\n virtualizerContext: contextState,\n imperativeVirtualizerRef: _imperativeVirtualizerRef,\n onRenderedFlaggedIndex: handleRenderedIndex\n });\n const measureObject = useMeasureList(virtualizerState.virtualizerStartIndex, virtualizerLength, props.numItems, props.itemSize);\n if (axis === 'horizontal') {\n sizeTrackingArray = measureObject.widthArray;\n } else {\n sizeTrackingArray = measureObject.heightArray;\n }\n if (!props.getItemSize) {\n // Auto-measuring is required\n React.Children.map(virtualizerState.virtualizedChildren, (child, index)=>{\n if (/*#__PURE__*/ React.isValidElement(child)) {\n virtualizerState.virtualizedChildren[index] = /*#__PURE__*/ React.createElement(child.type, {\n ...child.props,\n key: child.key,\n ref: (element)=>{\n // If a ref exists in props, call it\n if (typeof child.props.ref === 'function') {\n child.props.ref(element);\n } else if (child.props.ref) {\n child.props.ref.current = element;\n }\n if (child.hasOwnProperty('ref')) {\n // We must access this from the child directly, not props (forward ref).\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const localRef = child === null || child === void 0 ? void 0 : child.ref;\n if (typeof localRef === 'function') {\n localRef(element);\n } else if (localRef) {\n localRef.current = element;\n }\n }\n // Call the auto-measure ref attachment.\n measureObject.createIndexedRef(index)(element);\n }\n });\n }\n });\n }\n return {\n ...virtualizerState,\n components: {\n ...virtualizerState.components,\n container: 'div'\n },\n container: slot.always(props.container, {\n defaultProps: {\n ref: scrollViewRef\n },\n elementType: 'div'\n })\n };\n}\n"],"names":["useVirtualizerScrollViewDynamic_unstable","props","contextState","useVirtualizerContextState_unstable","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","sizeTrackingArray","React","useRef","Array","numItems","fill","itemSize","getChildSizeAuto","useCallback","index","current","length","_props_axis","_props_getItemSize","_contextState_contextIndex","virtualizerLength","bufferItems","bufferSize","scrollRef","useDynamicVirtualizerMeasure","defaultItemSize","direction","getItemSize","currentIndex","contextIndex","virtualizerLengthRef","scrollViewRef","useMergedRefs","scrollCallbackRef","_imperativeVirtualizerRef","useImperativeHandle","_imperativeVirtualizerRef_current","scrollTo","behavior","callback","progressiveSizes","totalSize","Math","max","setFlaggedIndex","scrollToItemDynamic","itemSizes","nodeSizes","handleRenderedIndex","_props_getItemSize1","virtualizerState","useVirtualizer_unstable","onRenderedFlaggedIndex","measureObject","useMeasureList","virtualizerStartIndex","widthArray","heightArray","Children","map","virtualizedChildren","child","isValidElement","createElement","type","key","ref","element","hasOwnProperty","localRef","createIndexedRef","components","container","slot","always","defaultProps","elementType"],"mappings":";;;;+BAOgBA;;;eAAAA;;;;iEAPO;gCACa;gCACI;uBACK;2BAC4B;gCAE1C;AACxB,SAASA,yCAAyCC,KAAK;IAC1D,MAAMC,eAAeC,IAAAA,8CAAmC,EAACF,MAAMG,kBAAkB;IACjF,MAAM,EAAEC,aAAa,EAAEC,OAAO,UAAU,EAAEC,QAAQ,EAAEC,wBAAwB,EAAE,GAAGP;IACjF,IAAIQ,oBAAoBC,OAAMC,MAAM,CAAC,IAAIC,MAAMX,MAAMY,QAAQ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gBAAgB,CAACxD,OAAOqD;oBAC1C;gBACJ;YACJ;QACJ;IACJ;IACA,OAAO;QACH,GAAGjB,gBAAgB;QACnBqB,YAAY;YACR,GAAGrB,iBAAiBqB,UAAU;YAC9BC,WAAW;QACf;QACAA,WAAWC,oBAAI,CAACC,MAAM,CAAC7E,MAAM2E,SAAS,EAAE;YACpCG,cAAc;gBACVT,KAAKnC;YACT;YACA6C,aAAa;QACjB;IACJ;AACJ"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ useMeasureList: function() {
13
+ return useMeasureList;
14
+ },
15
+ createResizeObserverFromDocument: function() {
16
+ return createResizeObserverFromDocument;
17
+ }
18
+ });
19
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
20
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
21
+ const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
22
+ function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {
23
+ const widthArray = _react.useRef(new Array(totalLength).fill(defaultItemSize));
24
+ const heightArray = _react.useRef(new Array(totalLength).fill(defaultItemSize));
25
+ const refArray = _react.useRef([]);
26
+ const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
27
+ // the handler for resize observer
28
+ const handleIndexUpdate = _react.useCallback((index)=>{
29
+ var _refArray_current_index;
30
+ const boundClientRect = (_refArray_current_index = refArray.current[index]) === null || _refArray_current_index === void 0 ? void 0 : _refArray_current_index.getBoundingClientRect();
31
+ const containerWidth = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.width;
32
+ widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;
33
+ const containerHeight = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.height;
34
+ heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;
35
+ }, [
36
+ currentIndex,
37
+ defaultItemSize
38
+ ]);
39
+ const handleElementResizeCallback = (entries)=>{
40
+ for (const entry of entries){
41
+ const target = entry.target;
42
+ // Call the elements own resize handler (indexed)
43
+ target.handleResize();
44
+ }
45
+ };
46
+ _react.useEffect(()=>{
47
+ widthArray.current = new Array(totalLength).fill(defaultItemSize);
48
+ heightArray.current = new Array(totalLength).fill(defaultItemSize);
49
+ }, [
50
+ defaultItemSize,
51
+ totalLength
52
+ ]);
53
+ // Keep the reference of ResizeObserver as a ref, as it should live through renders
54
+ const resizeObserver = _react.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));
55
+ /* createIndexedRef provides a dynamic function to create an undefined number of refs at render time
56
+ * these refs then provide an indexed callback via attaching 'handleResize' to the element itself
57
+ * this function is then called on resize by handleElementResize and relies on indexing
58
+ * to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.
59
+ */ const createIndexedRef = _react.useCallback((index)=>{
60
+ const measureElementRef = (el)=>{
61
+ if (!targetDocument || !resizeObserver.current) {
62
+ return;
63
+ }
64
+ if (el) {
65
+ el.handleResize = ()=>{
66
+ handleIndexUpdate(index);
67
+ };
68
+ }
69
+ // cleanup previous container
70
+ if (refArray.current[index] !== undefined && refArray.current[index] !== null) {
71
+ resizeObserver.current.unobserve(refArray.current[index]);
72
+ }
73
+ refArray.current[index] = undefined;
74
+ if (el) {
75
+ refArray.current[index] = el;
76
+ resizeObserver.current.observe(el);
77
+ handleIndexUpdate(index);
78
+ }
79
+ };
80
+ return measureElementRef;
81
+ }, [
82
+ handleIndexUpdate,
83
+ resizeObserver,
84
+ targetDocument
85
+ ]);
86
+ _react.useEffect(()=>{
87
+ const _resizeObserver = resizeObserver;
88
+ return ()=>{
89
+ var _resizeObserver_current;
90
+ return (_resizeObserver_current = _resizeObserver.current) === null || _resizeObserver_current === void 0 ? void 0 : _resizeObserver_current.disconnect();
91
+ };
92
+ }, [
93
+ resizeObserver
94
+ ]);
95
+ return {
96
+ widthArray,
97
+ heightArray,
98
+ createIndexedRef,
99
+ refArray
100
+ };
101
+ }
102
+ function createResizeObserverFromDocument(targetDocument, callback) {
103
+ var _targetDocument_defaultView;
104
+ if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {
105
+ return null;
106
+ }
107
+ return new targetDocument.defaultView.ResizeObserver(callback);
108
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useMeasureList.js"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n/**\n * Provides a way of automating size in the virtualizer\n * Returns\n * `width` - element width ref (0 by default),\n * `height` - element height ref (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */ export function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {\n const widthArray = React.useRef(new Array(totalLength).fill(defaultItemSize));\n const heightArray = React.useRef(new Array(totalLength).fill(defaultItemSize));\n const refArray = React.useRef([]);\n const { targetDocument } = useFluent();\n // the handler for resize observer\n const handleIndexUpdate = React.useCallback((index)=>{\n var _refArray_current_index;\n const boundClientRect = (_refArray_current_index = refArray.current[index]) === null || _refArray_current_index === void 0 ? void 0 : _refArray_current_index.getBoundingClientRect();\n const containerWidth = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.width;\n widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;\n const containerHeight = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.height;\n heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;\n }, [\n currentIndex,\n defaultItemSize\n ]);\n const handleElementResizeCallback = (entries)=>{\n for (const entry of entries){\n const target = entry.target;\n // Call the elements own resize handler (indexed)\n target.handleResize();\n }\n };\n React.useEffect(()=>{\n widthArray.current = new Array(totalLength).fill(defaultItemSize);\n heightArray.current = new Array(totalLength).fill(defaultItemSize);\n }, [\n defaultItemSize,\n totalLength\n ]);\n // Keep the reference of ResizeObserver as a ref, as it should live through renders\n const resizeObserver = React.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));\n /* createIndexedRef provides a dynamic function to create an undefined number of refs at render time\n * these refs then provide an indexed callback via attaching 'handleResize' to the element itself\n * this function is then called on resize by handleElementResize and relies on indexing\n * to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.\n */ const createIndexedRef = React.useCallback((index)=>{\n const measureElementRef = (el)=>{\n if (!targetDocument || !resizeObserver.current) {\n return;\n }\n if (el) {\n el.handleResize = ()=>{\n handleIndexUpdate(index);\n };\n }\n // cleanup previous container\n if (refArray.current[index] !== undefined && refArray.current[index] !== null) {\n resizeObserver.current.unobserve(refArray.current[index]);\n }\n refArray.current[index] = undefined;\n if (el) {\n refArray.current[index] = el;\n resizeObserver.current.observe(el);\n handleIndexUpdate(index);\n }\n };\n return measureElementRef;\n }, [\n handleIndexUpdate,\n resizeObserver,\n targetDocument\n ]);\n React.useEffect(()=>{\n const _resizeObserver = resizeObserver;\n return ()=>{\n var _resizeObserver_current;\n return (_resizeObserver_current = _resizeObserver.current) === null || _resizeObserver_current === void 0 ? void 0 : _resizeObserver_current.disconnect();\n };\n }, [\n resizeObserver\n ]);\n return {\n widthArray,\n heightArray,\n createIndexedRef,\n refArray\n };\n}\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */ export function createResizeObserverFromDocument(targetDocument, callback) {\n var _targetDocument_defaultView;\n if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {\n return null;\n }\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["useMeasureList","createResizeObserverFromDocument","currentIndex","refLength","totalLength","defaultItemSize","widthArray","React","useRef","Array","fill","heightArray","refArray","targetDocument","useFluent","handleIndexUpdate","useCallback","index","_refArray_current_index","boundClientRect","current","getBoundingClientRect","containerWidth","width","containerHeight","height","handleElementResizeCallback","entries","entry","target","handleResize","useEffect","resizeObserver","createIndexedRef","measureElementRef","el","undefined","unobserve","observe","_resizeObserver","_resizeObserver_current","disconnect","callback","_targetDocument_defaultView","defaultView","ResizeObserver"],"mappings":";;;;;;;;;;;IAQoBA,cAAc;eAAdA;;IAsFAC,gCAAgC;eAAhCA;;;;iEA9FG;qCACyB;AAOrC,SAASD,eAAeE,YAAY,EAAEC,SAAS,EAAEC,WAAW,EAAEC,eAAe;IACpF,MAAMC,aAAaC,OAAMC,MAAM,CAAC,IAAIC,MAAML,aAAaM,IAAI,CAACL;IAC5D,MAAMM,cAAcJ,OAAMC,MAAM,CAAC,IAAIC,MAAML,aAAaM,IAAI,CAACL;IAC7D,MAAMO,WAAWL,OAAMC,MAAM,CAAC,EAAE;IAChC,MAAM,EAAEK,cAAc,EAAE,GAAGC,IAAAA,uCAAS;IACpC,kCAAkC;IAClC,MAAMC,oBAAoBR,OAAMS,WAAW,CAAC,CAACC;QACzC,IAAIC;QACJ,MAAMC,kBAAkB,AAACD,CAAAA,0BAA0BN,SAASQ,OAAO,CAACH,MAAM,AAAD,MAAO,QAAQC,4BAA4B,KAAK,IAAI,KAAK,IAAIA,wBAAwBG,qBAAqB;QACnL,MAAMC,iBAAiBH,oBAAoB,QAAQA,oBAAoB,KAAK,IAAI,KAAK,IAAIA,gBAAgBI,KAAK;QAC9GjB,WAAWc,OAAO,CAAClB,eAAee,MAAM,GAAGK,kBAAkBjB;QAC7D,MAAMmB,kBAAkBL,oBAAoB,QAAQA,oBAAoB,KAAK,IAAI,KAAK,IAAIA,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AAACA,CAAAA,0BAA0BD,gBAAgBnB,OAAO,AAAD,MAAO,QAAQoB,4BAA4B,KAAK,IAAI,KAAK,IAAIA,wBAAwBC,UAAU;QAC3J;IACJ,GAAG;QACCT;KACH;IACD,OAAO;QACH1B;QACAK;QACAsB;QACArB;IACJ;AACJ;AAOW,SAASX,iCAAiCY,cAAc,EAAE6B,QAAQ;IACzE,IAAIC;IACJ,IAAI,CAAE9B,CAAAA,mBAAmB,QAAQA,mBAAmB,KAAK,IAAI,KAAK,IAAI,AAAC8B,CAAAA,8BAA8B9B,eAAe+B,WAAW,AAAD,MAAO,QAAQD,gCAAgC,KAAK,IAAI,KAAK,IAAIA,4BAA4BE,cAAc,AAAD,GAAI;QACxO,OAAO;IACX;IACA,OAAO,IAAIhC,eAAe+B,WAAW,CAACC,cAAc,CAACH;AACzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/react-virtualizer",
3
- "version": "9.0.0-alpha.58",
3
+ "version": "9.0.0-alpha.59",
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",
@@ -32,7 +32,7 @@
32
32
  "@fluentui/scripts-tasks": "*"
33
33
  },
34
34
  "dependencies": {
35
- "@fluentui/react-jsx-runtime": "^9.0.19",
35
+ "@fluentui/react-jsx-runtime": "^9.0.20",
36
36
  "@fluentui/react-utilities": "^9.15.2",
37
37
  "@fluentui/react-shared-contexts": "^9.13.0",
38
38
  "@griffel/react": "^1.5.14",