@fluentui/react-virtualizer 9.0.0-alpha.83 → 9.0.0-alpha.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +22 -2
  2. package/dist/index.d.ts +78 -5
  3. package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
  4. package/lib/components/Virtualizer/useVirtualizer.js +208 -143
  5. package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
  6. package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +3 -3
  7. package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -1
  8. package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -1
  9. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +11 -9
  10. package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -1
  11. package/lib/hooks/hooks.types.js.map +1 -1
  12. package/lib/hooks/index.js +1 -0
  13. package/lib/hooks/index.js.map +1 -1
  14. package/lib/hooks/useDynamicVirtualizerMeasure.js +63 -45
  15. package/lib/hooks/useDynamicVirtualizerMeasure.js.map +1 -1
  16. package/lib/hooks/useMeasureList.js +14 -2
  17. package/lib/hooks/useMeasureList.js.map +1 -1
  18. package/lib/hooks/useResizeObserverRef.js +11 -1
  19. package/lib/hooks/useResizeObserverRef.js.map +1 -1
  20. package/lib/hooks/useVirtualizerMeasure.js +31 -15
  21. package/lib/hooks/useVirtualizerMeasure.js.map +1 -1
  22. package/lib/index.js +1 -1
  23. package/lib/index.js.map +1 -1
  24. package/lib/utilities/VirtualizerContext/VirtualizerContext.js +12 -14
  25. package/lib/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -1
  26. package/lib/utilities/VirtualizerContext/types.js +1 -3
  27. package/lib/utilities/VirtualizerContext/types.js.map +1 -1
  28. package/lib-commonjs/components/Virtualizer/Virtualizer.types.js.map +1 -1
  29. package/lib-commonjs/components/Virtualizer/useVirtualizer.js +206 -141
  30. package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
  31. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +3 -3
  32. package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -1
  33. package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -1
  34. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +11 -9
  35. package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -1
  36. package/lib-commonjs/hooks/hooks.types.js.map +1 -1
  37. package/lib-commonjs/hooks/index.js +1 -0
  38. package/lib-commonjs/hooks/index.js.map +1 -1
  39. package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js +62 -44
  40. package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js.map +1 -1
  41. package/lib-commonjs/hooks/useMeasureList.js +14 -2
  42. package/lib-commonjs/hooks/useMeasureList.js.map +1 -1
  43. package/lib-commonjs/hooks/useResizeObserverRef.js +11 -1
  44. package/lib-commonjs/hooks/useResizeObserverRef.js.map +1 -1
  45. package/lib-commonjs/hooks/useVirtualizerMeasure.js +31 -15
  46. package/lib-commonjs/hooks/useVirtualizerMeasure.js.map +1 -1
  47. package/lib-commonjs/index.js +3 -0
  48. package/lib-commonjs/index.js.map +1 -1
  49. package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js +11 -13
  50. package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -1
  51. package/lib-commonjs/utilities/VirtualizerContext/types.js +3 -3
  52. package/lib-commonjs/utilities/VirtualizerContext/types.js.map +1 -1
  53. package/package.json +4 -4
@@ -18,7 +18,7 @@ const _useStaticPagination = require("../../hooks/useStaticPagination");
18
18
  function useVirtualizerScrollView_unstable(props) {
19
19
  const { imperativeRef, itemSize, numItems, axis = 'vertical', reversed, enablePagination = false } = props;
20
20
  var _props_axis;
21
- const { virtualizerLength, bufferItems, bufferSize, scrollRef } = (0, _Hooks.useStaticVirtualizerMeasure)({
21
+ const { virtualizerLength, bufferItems, bufferSize, scrollRef, containerSizeRef } = (0, _Hooks.useStaticVirtualizerMeasure)({
22
22
  defaultItemSize: props.itemSize,
23
23
  direction: (_props_axis = props.axis) !== null && _props_axis !== void 0 ? _props_axis : 'vertical'
24
24
  });
@@ -71,9 +71,9 @@ function useVirtualizerScrollView_unstable(props) {
71
71
  virtualizerLength,
72
72
  bufferItems,
73
73
  bufferSize,
74
- scrollViewRef,
75
74
  onRenderedFlaggedIndex: handleRenderedIndex,
76
- imperativeVirtualizerRef
75
+ imperativeVirtualizerRef,
76
+ containerSizeRef
77
77
  });
78
78
  return {
79
79
  ...virtualizerState,
@@ -1 +1 @@
1
- {"version":3,"sources":["useVirtualizerScrollView.ts"],"sourcesContent":["import * as React from 'react';\nimport { slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';\nimport type { VirtualizerScrollViewProps, VirtualizerScrollViewState } from './VirtualizerScrollView.types';\nimport { useStaticVirtualizerMeasure } from '../../Hooks';\nimport { useImperativeHandle } from 'react';\nimport { scrollToItemStatic } from '../../Utilities';\nimport type { VirtualizerDataRef } from '../Virtualizer/Virtualizer.types';\nimport { useStaticVirtualizerPagination } from '../../hooks/useStaticPagination';\n\nexport function useVirtualizerScrollView_unstable(props: VirtualizerScrollViewProps): VirtualizerScrollViewState {\n const { imperativeRef, itemSize, numItems, axis = 'vertical', reversed, enablePagination = false } = props;\n const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useStaticVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: props.axis ?? 'vertical',\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\n const paginationRef = useStaticVirtualizerPagination({ axis, itemSize }, enablePagination);\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef, paginationRef) as React.RefObject<HTMLDivElement>;\n const imperativeVirtualizerRef = React.useRef<VirtualizerDataRef | null>(null);\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\n\n useImperativeHandle(\n imperativeRef,\n () => {\n return {\n scrollTo(index: number, behavior = 'auto', callback: ((index: number) => void) | undefined) {\n scrollCallbackRef.current = callback ?? null;\n imperativeVirtualizerRef.current?.setFlaggedIndex(index);\n scrollToItemStatic({\n index,\n itemSize,\n totalItems: numItems,\n scrollViewRef,\n axis,\n reversed,\n behavior,\n });\n },\n currentIndex: imperativeVirtualizerRef.current?.currentIndex,\n virtualizerLength: virtualizerLengthRef,\n };\n },\n [axis, scrollViewRef, itemSize, numItems, reversed],\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 onRenderedFlaggedIndex: handleRenderedIndex,\n imperativeVirtualizerRef,\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 as React.RefObject<HTMLDivElement>,\n },\n elementType: 'div',\n }),\n };\n}\n"],"names":["useVirtualizerScrollView_unstable","props","imperativeRef","itemSize","numItems","axis","reversed","enablePagination","virtualizerLength","bufferItems","bufferSize","scrollRef","useStaticVirtualizerMeasure","defaultItemSize","direction","virtualizerLengthRef","React","useRef","current","paginationRef","useStaticVirtualizerPagination","scrollViewRef","useMergedRefs","imperativeVirtualizerRef","scrollCallbackRef","useImperativeHandle","scrollTo","index","behavior","callback","setFlaggedIndex","scrollToItemStatic","totalItems","currentIndex","handleRenderedIndex","virtualizerState","useVirtualizer_unstable","onRenderedFlaggedIndex","components","container","slot","always","defaultProps","ref","elementType"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAUgBA;;;eAAAA;;;;iEAVO;gCACa;gCACI;uBAEI;2BAET;qCAEY;AAExC,SAASA,kCAAkCC,KAAiC;IACjF,MAAM,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,OAAO,UAAU,EAAEC,QAAQ,EAAEC,mBAAmB,KAAK,EAAE,GAAGN;QAGxFA;IAFb,MAAM,EAAEO,iBAAiB,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGC,IAAAA,kCAAAA,EAA4B;QAC5FC,iBAAiBZ,MAAME,QAAQ;QAC/BW,WAAWb,CAAAA,cAAAA,MAAMI,IAAI,AAAJA,MAAI,QAAVJ,gBAAAA,KAAAA,IAAAA,cAAc;IAC3B;IAEA,kEAAkE;IAClE,MAAMc,uBAAuBC,OAAMC,MAAM,CAAST;IAClD,IAAIO,qBAAqBG,OAAO,KAAKV,mBAAmB;QACtDO,qBAAqBG,OAAO,GAAGV;IACjC;IAEA,MAAMW,gBAAgBC,IAAAA,mDAAAA,EAA+B;QAAEf;QAAMF;IAAS,GAAGI;IACzE,MAAMc,gBAAgBC,IAAAA,6BAAAA,EAAcrB,MAAMoB,aAAa,EAAEV,WAAWQ;IACpE,MAAMI,2BAA2BP,OAAMC,MAAM,CAA4B;IACzE,MAAMO,oBAAoBR,OAAMC,MAAM,CAAmC;IAEzEQ,IAAAA,0BAAAA,EACEvB,eACA;YAekBqB;QAdhB,OAAO;YACLG,UAASC,KAAa,EAAEC,WAAW,MAAM,EAAEC,QAA+C;oBAExFN;gBADAC,kBAAkBN,OAAO,GAAGW,aAAAA,QAAAA,aAAAA,KAAAA,IAAAA,WAAY;gBACxCN,CAAAA,oCAAAA,yBAAyBL,OAAO,AAAPA,MAAO,QAAhCK,sCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kCAAkCO,eAAe,CAACH;gBAClDI,IAAAA,6BAAAA,EAAmB;oBACjBJ;oBACAxB;oBACA6B,YAAY5B;oBACZiB;oBACAhB;oBACAC;oBACAsB;gBACF;YACF;YACAK,cAAY,AAAEV,CAAAA,oCAAAA,yBAAyBL,OAAO,AAAPA,MAAO,QAAhCK,sCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kCAAkCU,YAAY;YAC5DzB,mBAAmBO;QACrB;IACF,GACA;QAACV;QAAMgB;QAAelB;QAAUC;QAAUE;KAAS;IAGrD,MAAM4B,sBAAsB,CAACP;QAC3B,IAAIH,kBAAkBN,OAAO,EAAE;YAC7BM,kBAAkBN,OAAO,CAACS;QAC5B;IACF;IAEA,MAAMQ,mBAAmBC,IAAAA,uCAAAA,EAAwB;QAC/C,GAAGnC,KAAK;QACRO;QACAC;QACAC;QACAW;QACAgB,wBAAwBH;QACxBX;IACF;IAEA,OAAO;QACL,GAAGY,gBAAgB;QACnBG,YAAY;YACV,GAAGH,iBAAiBG,UAAU;YAC9BC,WAAW;QACb;QACAA,WAAWC,oBAAAA,CAAKC,MAAM,CAACxC,MAAMsC,SAAS,EAAE;YACtCG,cAAc;gBACZC,KAAKtB;YACP;YACAuB,aAAa;QACf;IACF;AACF"}
1
+ {"version":3,"sources":["useVirtualizerScrollView.ts"],"sourcesContent":["import * as React from 'react';\nimport { slot, useMergedRefs } from '@fluentui/react-utilities';\nimport { useVirtualizer_unstable } from '../Virtualizer/useVirtualizer';\nimport type { VirtualizerScrollViewProps, VirtualizerScrollViewState } from './VirtualizerScrollView.types';\nimport { useStaticVirtualizerMeasure } from '../../Hooks';\nimport { useImperativeHandle } from 'react';\nimport { scrollToItemStatic } from '../../Utilities';\nimport type { VirtualizerDataRef } from '../Virtualizer/Virtualizer.types';\nimport { useStaticVirtualizerPagination } from '../../hooks/useStaticPagination';\n\nexport function useVirtualizerScrollView_unstable(props: VirtualizerScrollViewProps): VirtualizerScrollViewState {\n const { imperativeRef, itemSize, numItems, axis = 'vertical', reversed, enablePagination = false } = props;\n const { virtualizerLength, bufferItems, bufferSize, scrollRef, containerSizeRef } = useStaticVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: props.axis ?? 'vertical',\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\n const paginationRef = useStaticVirtualizerPagination({ axis, itemSize }, enablePagination);\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef, paginationRef) as React.RefObject<HTMLDivElement>;\n const imperativeVirtualizerRef = React.useRef<VirtualizerDataRef | null>(null);\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\n\n useImperativeHandle(\n imperativeRef,\n () => {\n return {\n scrollTo(index: number, behavior = 'auto', callback: ((index: number) => void) | undefined) {\n scrollCallbackRef.current = callback ?? null;\n imperativeVirtualizerRef.current?.setFlaggedIndex(index);\n scrollToItemStatic({\n index,\n itemSize,\n totalItems: numItems,\n scrollViewRef,\n axis,\n reversed,\n behavior,\n });\n },\n currentIndex: imperativeVirtualizerRef.current?.currentIndex,\n virtualizerLength: virtualizerLengthRef,\n };\n },\n [axis, scrollViewRef, itemSize, numItems, reversed],\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 onRenderedFlaggedIndex: handleRenderedIndex,\n imperativeVirtualizerRef,\n containerSizeRef,\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 as React.RefObject<HTMLDivElement>,\n },\n elementType: 'div',\n }),\n };\n}\n"],"names":["useVirtualizerScrollView_unstable","props","imperativeRef","itemSize","numItems","axis","reversed","enablePagination","virtualizerLength","bufferItems","bufferSize","scrollRef","containerSizeRef","useStaticVirtualizerMeasure","defaultItemSize","direction","virtualizerLengthRef","React","useRef","current","paginationRef","useStaticVirtualizerPagination","scrollViewRef","useMergedRefs","imperativeVirtualizerRef","scrollCallbackRef","useImperativeHandle","scrollTo","index","behavior","callback","setFlaggedIndex","scrollToItemStatic","totalItems","currentIndex","handleRenderedIndex","virtualizerState","useVirtualizer_unstable","onRenderedFlaggedIndex","components","container","slot","always","defaultProps","ref","elementType"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAUgBA;;;eAAAA;;;;iEAVO;gCACa;gCACI;uBAEI;2BAET;qCAEY;AAExC,SAASA,kCAAkCC,KAAiC;IACjF,MAAM,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,OAAO,UAAU,EAAEC,QAAQ,EAAEC,mBAAmB,KAAK,EAAE,GAAGN;QAGxFA;IAFb,MAAM,EAAEO,iBAAiB,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,gBAAgB,EAAE,GAAGC,IAAAA,kCAAAA,EAA4B;QAC9GC,iBAAiBb,MAAME,QAAQ;QAC/BY,WAAWd,CAAAA,cAAAA,MAAMI,IAAI,AAAJA,MAAI,QAAVJ,gBAAAA,KAAAA,IAAAA,cAAc;IAC3B;IAEA,kEAAkE;IAClE,MAAMe,uBAAuBC,OAAMC,MAAM,CAASV;IAClD,IAAIQ,qBAAqBG,OAAO,KAAKX,mBAAmB;QACtDQ,qBAAqBG,OAAO,GAAGX;IACjC;IAEA,MAAMY,gBAAgBC,IAAAA,mDAAAA,EAA+B;QAAEhB;QAAMF;IAAS,GAAGI;IACzE,MAAMe,gBAAgBC,IAAAA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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 * Imperative ref contains our scrollTo index functionality for user control.\n */\n enablePagination?: boolean;\n };\n\nexport type VirtualizerScrollViewDynamicState = ComponentState<VirtualizerScrollViewDynamicSlots> &\n VirtualizerConfigState;\n"],"names":[],"rangeMappings":"","mappings":""}
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 { DynamicVirtualizerContextProps, ScrollToInterface } from '../../Utilities';\n\nexport type VirtualizerScrollViewDynamicSlots = VirtualizerScrollViewSlots;\n\nexport type VirtualizerScrollViewDynamicProps = ComponentProps<Partial<VirtualizerScrollViewDynamicSlots>> &\n Partial<\n Omit<\n VirtualizerConfigProps,\n 'itemSize' | 'numItems' | 'getItemSize' | 'children' | 'flagIndex' | 'virtualizerContext'\n >\n > & {\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 * Imperative ref contains our scrollTo index functionality for user control.\n */\n enablePagination?: boolean;\n /**\n * Enables override of dynamic virtualizer context if required.\n */\n virtualizerContext?: DynamicVirtualizerContextProps;\n };\n\nexport type VirtualizerScrollViewDynamicState = ComponentState<VirtualizerScrollViewDynamicSlots> &\n VirtualizerConfigState;\n"],"names":[],"rangeMappings":"","mappings":""}
@@ -20,7 +20,7 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
20
20
  'use no memo';
21
21
  var _imperativeVirtualizerRef_current;
22
22
  const contextState = (0, _Utilities.useVirtualizerContextState_unstable)(props.virtualizerContext);
23
- const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef, enablePagination = false } = props;
23
+ const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef, enablePagination = false, bufferItems: _bufferItems, bufferSize: _bufferSize } = props;
24
24
  let sizeTrackingArray = _react.useRef(new Array(props.numItems).fill(props.itemSize));
25
25
  // This lets us trigger updates when a size change occurs.
26
26
  const [sizeUpdateCount, setSizeUpdateCount] = (0, _react.useState)(0);
@@ -37,21 +37,23 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
37
37
  props.itemSize,
38
38
  sizeUpdateCount
39
39
  ]);
40
- var _props_axis, _props_getItemSize, _contextState_contextIndex;
41
- const { virtualizerLength, bufferItems, bufferSize, scrollRef } = (0, _Hooks.useDynamicVirtualizerMeasure)({
40
+ var _props_axis, _props_getItemSize;
41
+ const { virtualizerLength, bufferItems, bufferSize, scrollRef, containerSizeRef } = (0, _Hooks.useDynamicVirtualizerMeasure)({
42
42
  defaultItemSize: props.itemSize,
43
43
  direction: (_props_axis = props.axis) !== null && _props_axis !== void 0 ? _props_axis : 'vertical',
44
44
  getItemSize: (_props_getItemSize = props.getItemSize) !== null && _props_getItemSize !== void 0 ? _props_getItemSize : getChildSizeAuto,
45
- currentIndex: (_contextState_contextIndex = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex !== void 0 ? _contextState_contextIndex : 0,
46
- numItems: props.numItems
45
+ virtualizerContext: contextState,
46
+ numItems: props.numItems,
47
+ bufferItems: _bufferItems,
48
+ bufferSize: _bufferSize
47
49
  });
48
50
  const _imperativeVirtualizerRef = (0, _reactutilities.useMergedRefs)(_react.useRef(null), imperativeVirtualizerRef);
49
- var _contextState_contextIndex1;
51
+ var _contextState_contextIndex;
50
52
  const paginationRef = (0, _useDynamicPagination.useDynamicVirtualizerPagination)({
51
53
  axis,
52
54
  progressiveItemSizes: (_imperativeVirtualizerRef_current = _imperativeVirtualizerRef.current) === null || _imperativeVirtualizerRef_current === void 0 ? void 0 : _imperativeVirtualizerRef_current.progressiveSizes,
53
55
  virtualizerLength,
54
- currentIndex: (_contextState_contextIndex1 = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex1 !== void 0 ? _contextState_contextIndex1 : 0
56
+ currentIndex: (_contextState_contextIndex = contextState === null || contextState === void 0 ? void 0 : contextState.contextIndex) !== null && _contextState_contextIndex !== void 0 ? _contextState_contextIndex : 0
55
57
  }, enablePagination);
56
58
  // Store the virtualizer length as a ref for imperative ref access
57
59
  const virtualizerLengthRef = _react.useRef(virtualizerLength);
@@ -102,10 +104,10 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
102
104
  virtualizerLength,
103
105
  bufferItems,
104
106
  bufferSize,
105
- scrollViewRef,
106
107
  virtualizerContext: contextState,
107
108
  imperativeVirtualizerRef: _imperativeVirtualizerRef,
108
- onRenderedFlaggedIndex: handleRenderedIndex
109
+ onRenderedFlaggedIndex: handleRenderedIndex,
110
+ containerSizeRef
109
111
  });
110
112
  const measureObject = (0, _useMeasureList.useMeasureList)(virtualizerState.virtualizerStartIndex, virtualizerLength, props.numItems, props.itemSize);
111
113
  if (enablePagination && measureObject.sizeUpdateCount !== sizeUpdateCount) {
@@ -1 +1 @@
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, useState } from 'react';\nimport { useMeasureList } from '../../hooks/useMeasureList';\nimport type { IndexedResizeCallbackElement } from '../../hooks/useMeasureList';\nimport { useDynamicVirtualizerPagination } from '../../hooks/useDynamicPagination';\n\nexport function useVirtualizerScrollViewDynamic_unstable(\n props: VirtualizerScrollViewDynamicProps,\n): VirtualizerScrollViewDynamicState {\n 'use no memo';\n\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef, enablePagination = false } = props;\n\n let sizeTrackingArray = React.useRef<number[]>(new Array(props.numItems).fill(props.itemSize));\n\n // This lets us trigger updates when a size change occurs.\n const [sizeUpdateCount, setSizeUpdateCount] = useState(0);\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n [sizeTrackingArray, props.itemSize, sizeUpdateCount],\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 const _imperativeVirtualizerRef = useMergedRefs(React.useRef<VirtualizerDataRef>(null), imperativeVirtualizerRef);\n\n const paginationRef = useDynamicVirtualizerPagination(\n {\n axis,\n progressiveItemSizes: _imperativeVirtualizerRef.current?.progressiveSizes,\n virtualizerLength,\n currentIndex: contextState?.contextIndex ?? 0,\n },\n enablePagination,\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, paginationRef) as React.RefObject<HTMLDivElement>;\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\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 (enablePagination && measureObject.sizeUpdateCount !== sizeUpdateCount) {\n /* This enables us to let callback know that the sizes have been updated\n triggers a re-render but is only required on pagination (else index change handles) */\n setSizeUpdateCount(measureObject.sizeUpdateCount);\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 (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":["useVirtualizerScrollViewDynamic_unstable","props","_imperativeVirtualizerRef","contextState","useVirtualizerContextState_unstable","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","enablePagination","sizeTrackingArray","React","useRef","Array","numItems","fill","itemSize","sizeUpdateCount","setSizeUpdateCount","useState","getChildSizeAuto","useCallback","index","current","length","virtualizerLength","bufferItems","bufferSize","scrollRef","useDynamicVirtualizerMeasure","defaultItemSize","direction","getItemSize","currentIndex","contextIndex","useMergedRefs","paginationRef","useDynamicVirtualizerPagination","progressiveItemSizes","progressiveSizes","virtualizerLengthRef","scrollViewRef","scrollCallbackRef","useImperativeHandle","scrollTo","behavior","callback","totalSize","Math","max","setFlaggedIndex","scrollToItemDynamic","itemSizes","nodeSizes","handleRenderedIndex","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAegBA;;;eAAAA;;;;iEAfO;gCACa;gCACI;uBAKK;2BAC4B;gCAG1C;sCAEiB;AAEzC,SAAS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EAAE;QACtB,6BAA6B;QAC7BrB,OAAMoD,QAAQ,CAACC,GAAG,CAACT,iBAAiBU,mBAAmB,EAAE,CAACC,OAAO5C;YAC/D,IAAA,WAAA,GAAIX,OAAMwD,cAAc,CAACD,QAAQ;gBAC/BX,iBAAiBU,mBAAmB,CAAC3C,MAAM,GAAA,WAAA,GACzCX,OAAAyD,aAAA,CAACF,MAAMG,IAAI,EAAA;oBACR,GAAGH,MAAMlE,KAAK;oBACfsE,KAAKJ,MAAMI,GAAG;oBACdC,KAAK,CAACC;wBACJ,IAAIN,MAAMO,cAAc,CAAC,QAAQ;4BAC/B,wEAAwE;4BACxE,+DAA+D;4BAC/D,MAAMC,WAAYR,UAAAA,QAAAA,UAAAA,KAAAA,IAAAA,KAAAA,IAADA,MAAgBK,GAAG;4BAEpC,IAAI,OAAOG,aAAa,YAAY;gCAClCA,SAASF;4BACX,OAAO,IAAIE,UAAU;gCACnBA,SAASnD,OAAO,GAAGiD;4BACrB;wBACF;wBAEA,wCAAwC;wBACxCd,cAAciB,gBAAgB,CAACrD,OAAOkD;oBACxC;;YAGN;QACF;IACF;IAEA,OAAO;QACL,GAAGjB,gBAAgB;QACnBqB,YAAY;YACV,GAAGrB,iBAAiBqB,UAAU;YAC9BC,WAAW;QACb;QACAA,WAAWC,oBAAAA,CAAKC,MAAM,CAAC/E,MAAM6E,SAAS,EAAE;YACtCG,cAAc;gBACZT,KAAK9B;YACP;YACAwC,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, useState } from 'react';\nimport { useMeasureList } from '../../hooks/useMeasureList';\nimport type { IndexedResizeCallbackElement } from '../../hooks/useMeasureList';\nimport { useDynamicVirtualizerPagination } from '../../hooks/useDynamicPagination';\n\nexport function useVirtualizerScrollViewDynamic_unstable(\n props: VirtualizerScrollViewDynamicProps,\n): VirtualizerScrollViewDynamicState {\n 'use no memo';\n\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const {\n imperativeRef,\n axis = 'vertical',\n reversed,\n imperativeVirtualizerRef,\n enablePagination = false,\n bufferItems: _bufferItems,\n bufferSize: _bufferSize,\n } = props;\n\n let sizeTrackingArray = React.useRef<number[]>(new Array(props.numItems).fill(props.itemSize));\n\n // This lets us trigger updates when a size change occurs.\n const [sizeUpdateCount, setSizeUpdateCount] = useState(0);\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 // eslint-disable-next-line react-hooks/exhaustive-deps\n [sizeTrackingArray, props.itemSize, sizeUpdateCount],\n );\n\n const { virtualizerLength, bufferItems, bufferSize, scrollRef, containerSizeRef } = useDynamicVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: props.axis ?? 'vertical',\n getItemSize: props.getItemSize ?? getChildSizeAuto,\n virtualizerContext: contextState,\n numItems: props.numItems,\n bufferItems: _bufferItems,\n bufferSize: _bufferSize,\n });\n\n const _imperativeVirtualizerRef = useMergedRefs(React.useRef<VirtualizerDataRef>(null), imperativeVirtualizerRef);\n\n const paginationRef = useDynamicVirtualizerPagination(\n {\n axis,\n progressiveItemSizes: _imperativeVirtualizerRef.current?.progressiveSizes,\n virtualizerLength,\n currentIndex: contextState?.contextIndex ?? 0,\n },\n enablePagination,\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, paginationRef) as React.RefObject<HTMLDivElement>;\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\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 virtualizerContext: contextState,\n imperativeVirtualizerRef: _imperativeVirtualizerRef,\n onRenderedFlaggedIndex: handleRenderedIndex,\n containerSizeRef,\n });\n\n const measureObject = useMeasureList(\n virtualizerState.virtualizerStartIndex,\n virtualizerLength,\n props.numItems,\n props.itemSize,\n );\n\n if (enablePagination && measureObject.sizeUpdateCount !== sizeUpdateCount) {\n /* This enables us to let callback know that the sizes have been updated\n triggers a re-render but is only required on pagination (else index change handles) */\n setSizeUpdateCount(measureObject.sizeUpdateCount);\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 (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":["useVirtualizerScrollViewDynamic_unstable","props","_imperativeVirtualizerRef","contextState","useVirtualizerContextState_unstable","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","enablePagination","bufferItems","_bufferItems","bufferSize","_bufferSize","sizeTrackingArray","React","useRef","Array","numItems","fill","itemSize","sizeUpdateCount","setSizeUpdateCount","useState","getChildSizeAuto","useCallback","index","current","length","virtualizerLength","scrollRef","containerSizeRef","useDynamicVirtualizerMeasure","defaultItemSize","direction","getItemSize","useMergedRefs","paginationRef","useDynamicVirtualizerPagination","progressiveItemSizes","progressiveSizes","currentIndex","contextIndex","virtualizerLengthRef","scrollViewRef","scrollCallbackRef","useImperativeHandle","scrollTo","behavior","callback","totalSize","Math","max","setFlaggedIndex","scrollToItemDynamic","itemSizes","nodeSizes","handleRenderedIndex","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAegBA;;;eAAAA;;;;iEAfO;gCACa;gCACI;uBAKK;2BAC4B;gCAG1C;sCAEiB;AAEzC,SAASA,yCACdC,KAAwC;IAExC;QAgD0BC;IA9C1B,MAAMC,eAAeC,IAAAA,8CAAAA,EAAoCH,MAAMI,kBAAkB;IACjF,MAAM,EACJC,aAAa,EACbC,OAAO,UAAU,EACjBC,QAAQ,EACRC,wBAAwB,EACxBC,mBAAmB,KAAK,EACxBC,aAAaC,YAAY,EACzBC,YAAYC,WAAW,EACxB,GAAGb;IAEJ,IAAIc,oBAAoBC,OAAMC,MAAM,CAAW,IAAIC,MAAMjB,MAAMkB,QAAQ,EAAEC,IAAI,CAACnB,MAAMoB,QAAQ;IAE5F,0DAA0D;IAC1D,MAAM,CAACC,iBAAiBC,mBAAmB,GAAGC,IAAAA,eAAAA,EAAS;IAEvD,MAAMC,mBAAmBT,OAAMU,WAAW,CACxC,CAACC;QACC,IAAIZ,kBAAkBa,OAAO,CAACC,MAAM,IAAIF,SAASZ,kBAAkBa,OAAO,CAACD,MAAM,IAAI,GAAG;YACtF,8CAA8C;YAC9C,OAAO1B,MAAMoB,QAAQ;QACvB;QACA;;OAEC,GACD,OAAON,kBAAkBa,OAAO,CAACD,MAAM;IACzC,GAEA;QAACZ;QAAmBd,MAAMoB,QAAQ;QAAEC;KAAgB;QAKzCrB,aACEA;IAHf,MAAM,EAAE6B,iBAAiB,EAAEnB,WAAW,EAAEE,UAAU,EAAEk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gBACZT,KAAK9B;YACP;YACAwC,aAAa;QACf;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks.types.ts"],"sourcesContent":["import { MutableRefObject, RefObject } from 'react';\n\nexport type VirtualizerMeasureProps = {\n defaultItemSize: number;\n direction?: 'vertical' | 'horizontal';\n};\n\nexport type VirtualizerMeasureDynamicProps = {\n defaultItemSize: number;\n currentIndex: number;\n numItems: number;\n getItemSize: (index: number) => number;\n direction?: 'vertical' | 'horizontal';\n};\n\nexport type VirtualizerStaticPaginationProps = {\n itemSize: number;\n axis?: 'vertical' | 'horizontal';\n};\n\n/**\n * Props to be passed into dynamic virtualization hooks\n * All props can be acquired from useVirtualizer hooks themselves and passed in\n */\nexport type VirtualizerDynamicPaginationProps = {\n /**\n * An array that tracks the sizing of each item in virtualizer cumulatively\n */\n progressiveItemSizes: RefObject<number[]> | undefined;\n /**\n * The current starting index of the virtualizer's DOM elements\n */\n currentIndex: number;\n /**\n * The axis we should paginate on (should match virtualizer's axis)\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * The current length of Virtualizer's actual DOM elements\n */\n virtualizerLength: number;\n};\n\n/**\n * Additional direct Ref prevents reading old resize entry data\n * Backwards compatible with ResizeObserverCallback if preferred\n */\nexport interface ResizeCallbackWithRef {\n (\n entries: ResizeObserverEntry[],\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n observer: ResizeObserver,\n scrollRef?: MutableRefObject<HTMLElement | null>,\n ): void;\n}\n"],"names":[],"rangeMappings":";;;","mappings":"AA2CA;;;CAGC"}
1
+ {"version":3,"sources":["hooks.types.ts"],"sourcesContent":["import { MutableRefObject, RefObject } from 'react';\nimport { DynamicVirtualizerContextProps } from '../Utilities';\n\nexport type VirtualizerMeasureProps = {\n defaultItemSize: number;\n direction?: 'vertical' | 'horizontal';\n\n /**\n * Override recommended number of buffer items\n */\n bufferItems?: number;\n\n /**\n * Override recommended buffer size (px)\n */\n bufferSize?: number;\n};\n\nexport type VirtualizerMeasureDynamicProps = {\n defaultItemSize: number;\n virtualizerContext: DynamicVirtualizerContextProps;\n numItems: number;\n getItemSize: (index: number) => number;\n direction?: 'vertical' | 'horizontal';\n\n /**\n * Override recommended number of buffer items\n */\n bufferItems?: number;\n\n /**\n * Override recommended buffer size (px)\n */\n bufferSize?: number;\n};\n\nexport type VirtualizerStaticPaginationProps = {\n itemSize: number;\n axis?: 'vertical' | 'horizontal';\n};\n\n/**\n * Props to be passed into dynamic virtualization hooks\n * All props can be acquired from useVirtualizer hooks themselves and passed in\n */\nexport type VirtualizerDynamicPaginationProps = {\n /**\n * An array that tracks the sizing of each item in virtualizer cumulatively\n */\n progressiveItemSizes: RefObject<number[]> | undefined;\n /**\n * The current starting index of the virtualizer's DOM elements\n */\n currentIndex: number;\n /**\n * The axis we should paginate on (should match virtualizer's axis)\n */\n axis?: 'vertical' | 'horizontal';\n /**\n * The current length of Virtualizer's actual DOM elements\n */\n virtualizerLength: number;\n};\n\n/**\n * Additional direct Ref prevents reading old resize entry data\n * Backwards compatible with ResizeObserverCallback if preferred\n */\nexport interface ResizeCallbackWithRef {\n (\n entries: ResizeObserverEntry[],\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n observer: ResizeObserver,\n scrollRef?: MutableRefObject<HTMLElement | null>,\n ): void;\n}\n"],"names":[],"rangeMappings":";;;","mappings":"AAgEA;;;CAGC"}
@@ -8,3 +8,4 @@ _export_star._(require("./useVirtualizerMeasure"), exports);
8
8
  _export_star._(require("./useDynamicVirtualizerMeasure"), exports);
9
9
  _export_star._(require("./useResizeObserverRef"), exports);
10
10
  _export_star._(require("./hooks.types"), exports);
11
+ _export_star._(require("./useMeasureList"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useIntersectionObserver';\nexport * from './useVirtualizerMeasure';\nexport * from './useDynamicVirtualizerMeasure';\nexport * from './useResizeObserverRef';\nexport * from './hooks.types';\n"],"names":[],"rangeMappings":";;;;;;;;;","mappings":";;;;;uBAAc;uBACA;uBACA;uBACA;uBACA"}
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export * from './useIntersectionObserver';\nexport * from './useVirtualizerMeasure';\nexport * from './useDynamicVirtualizerMeasure';\nexport * from './useResizeObserverRef';\nexport * from './hooks.types';\nexport * from './useMeasureList';\n"],"names":[],"rangeMappings":";;;;;;;;;;","mappings":";;;;;uBAAc;uBACA;uBACA;uBACA;uBACA;uBACA"}
@@ -12,51 +12,89 @@ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildc
12
12
  const _reactutilities = require("@fluentui/react-utilities");
13
13
  const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
14
14
  const _useResizeObserverRef = require("./useResizeObserverRef");
15
+ const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
15
16
  const useDynamicVirtualizerMeasure = (virtualizerProps)=>{
16
- const { defaultItemSize, direction = 'vertical', numItems, getItemSize, currentIndex } = virtualizerProps;
17
- const indexRef = (0, _react.useRef)(currentIndex);
18
- indexRef.current = currentIndex;
17
+ const { defaultItemSize, direction = 'vertical', numItems, getItemSize, bufferItems, bufferSize, virtualizerContext } = virtualizerProps;
18
+ const indexRef = (0, _react.useRef)(virtualizerContext.contextIndex);
19
+ indexRef.current = virtualizerContext.contextIndex;
19
20
  const [state, setState] = _react.useState({
20
21
  virtualizerLength: 0,
21
22
  virtualizerBufferItems: 0,
22
23
  virtualizerBufferSize: 0
23
24
  });
25
+ const containerSizeRef = _react.useRef(0);
24
26
  const { virtualizerLength, virtualizerBufferItems, virtualizerBufferSize } = state;
27
+ const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
25
28
  const container = _react.useRef(null);
26
29
  const handleScrollResize = _react.useCallback((scrollRef)=>{
27
30
  if (!(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
28
31
  // Error? ignore?
29
32
  return;
30
33
  }
31
- if (scrollRef.current !== container.current) {
32
- container.current = scrollRef.current;
34
+ if (scrollRef.current !== (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body)) {
35
+ // We have a local scroll container
36
+ containerSizeRef.current = direction === 'vertical' ? scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.getBoundingClientRect().height : scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current.getBoundingClientRect().width;
37
+ } else if (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) {
38
+ var _targetDocument_defaultView, _targetDocument_defaultView1;
39
+ // If our scroll ref is the document body, we should check window height
40
+ containerSizeRef.current = direction === 'vertical' ? targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.innerHeight : targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.innerWidth;
33
41
  }
34
- const containerSize = direction === 'vertical' ? scrollRef.current.getBoundingClientRect().height : scrollRef.current.getBoundingClientRect().width;
35
42
  let indexSizer = 0;
43
+ let i = 0;
36
44
  let length = 0;
37
- while(indexSizer <= containerSize && length < numItems){
38
- const iItemSize = getItemSize(indexRef.current + length);
45
+ const sizeToBeat = containerSizeRef.current + virtualizerBufferSize * 2;
46
+ while(indexSizer <= sizeToBeat && i + virtualizerContext.contextIndex < numItems){
47
+ const iItemSize = getItemSize(indexRef.current + i);
48
+ if (virtualizerContext.childProgressiveSizes.current.length < numItems) {
49
+ /* We are in unknown territory, either an initial render or an update
50
+ in virtualizer item length has occurred.
51
+ We need to let the new items render first then we can accurately assess.*/ return virtualizerLength - virtualizerBufferSize * 2;
52
+ }
53
+ const currentScrollPos = virtualizerContext.contextPosition;
54
+ const currentItemPos = virtualizerContext.childProgressiveSizes.current[indexRef.current + i] - iItemSize;
55
+ if (currentScrollPos > currentItemPos + iItemSize) {
56
+ // The item isn't in view, ignore for now.
57
+ i++;
58
+ continue;
59
+ } else if (currentScrollPos > currentItemPos) {
60
+ // The item is partially out of view, ignore the out of bounds portion
61
+ const variance = currentItemPos + iItemSize - currentScrollPos;
62
+ indexSizer += variance;
63
+ } else {
64
+ // Item is in view
65
+ indexSizer += iItemSize;
66
+ }
39
67
  // Increment
40
- indexSizer += iItemSize;
68
+ i++;
41
69
  length++;
42
70
  }
43
71
  /*
44
72
  * Number of items to append at each end, i.e. 'preload' each side before entering view.
45
- */ const bufferItems = Math.max(Math.floor(length / 4), 4);
73
+ * Minimum: 2 - we give slightly more buffer for dynamic version.
74
+ */ const newBufferItems = bufferItems !== null && bufferItems !== void 0 ? bufferItems : Math.max(Math.ceil(length / 3), 1);
46
75
  /*
47
76
  * This is how far we deviate into the bufferItems to detect a redraw.
48
- */ const bufferSize = Math.max(Math.floor(length / 8 * defaultItemSize), 1);
49
- const totalLength = length + bufferItems * 2 + 1;
77
+ */ const newBufferSize = bufferSize !== null && bufferSize !== void 0 ? bufferSize : Math.max(defaultItemSize / 2.0, 1);
78
+ const totalLength = length + newBufferItems * 2;
50
79
  setState({
51
80
  virtualizerLength: totalLength,
52
- virtualizerBufferSize: bufferSize,
53
- virtualizerBufferItems: bufferItems
81
+ virtualizerBufferSize: newBufferSize,
82
+ virtualizerBufferItems: newBufferItems
54
83
  });
55
84
  }, [
85
+ bufferItems,
86
+ bufferSize,
56
87
  defaultItemSize,
57
88
  direction,
58
89
  getItemSize,
59
- numItems
90
+ numItems,
91
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body,
92
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView,
93
+ virtualizerBufferSize,
94
+ virtualizerContext.childProgressiveSizes,
95
+ virtualizerContext.contextIndex,
96
+ virtualizerContext.contextPosition,
97
+ virtualizerLength
60
98
  ]);
61
99
  const resizeCallback = _react.useCallback((_entries, // eslint-disable-next-line no-restricted-globals
62
100
  _observer, scrollRef)=>{
@@ -66,43 +104,23 @@ const useDynamicVirtualizerMeasure = (virtualizerProps)=>{
66
104
  }, [
67
105
  handleScrollResize
68
106
  ]);
69
- const scrollRef = (0, _useResizeObserverRef.useResizeObserverRef_unstable)(resizeCallback);
107
+ const scrollRef = (0, _reactutilities.useMergedRefs)(container, (0, _useResizeObserverRef.useResizeObserverRef_unstable)(resizeCallback));
70
108
  (0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
71
- var _container_current, _container_current1;
72
- if (!container.current) {
73
- return;
74
- }
75
- const containerSize = direction === 'vertical' ? ((_container_current = container.current) === null || _container_current === void 0 ? void 0 : _container_current.getBoundingClientRect().height) * 1.5 : ((_container_current1 = container.current) === null || _container_current1 === void 0 ? void 0 : _container_current1.getBoundingClientRect().width) * 1.5;
76
- let couldBeSmaller = false;
77
- let recheckTotal = 0;
78
- for(let i = currentIndex; i < currentIndex + virtualizerLength; i++){
79
- const newItemSize = getItemSize(i);
80
- recheckTotal += newItemSize;
81
- const newLength = i - currentIndex;
82
- const bufferItems = Math.max(Math.floor(newLength / 4), 2);
83
- const totalNewLength = newLength + bufferItems * 2 + 4;
84
- const compareLengths = totalNewLength < virtualizerLength;
85
- if (recheckTotal > containerSize && compareLengths) {
86
- couldBeSmaller = true;
87
- break;
88
- }
89
- }
90
- // Check if the render has caused us to need a re-calc of virtualizer length
91
- if (recheckTotal < containerSize || couldBeSmaller) {
109
+ if (virtualizerContext.contextIndex + virtualizerLength < numItems) {
110
+ // Avoid re-rendering/re-calculating when the end index has already been reached
92
111
  handleScrollResize(container);
93
112
  }
94
113
  }, [
95
- getItemSize,
96
- currentIndex,
97
- direction,
98
- virtualizerLength,
99
- resizeCallback,
100
- handleScrollResize
114
+ handleScrollResize,
115
+ numItems,
116
+ virtualizerContext.contextIndex,
117
+ virtualizerLength
101
118
  ]);
102
119
  return {
103
120
  virtualizerLength,
104
121
  bufferItems: virtualizerBufferItems,
105
122
  bufferSize: virtualizerBufferSize,
106
- scrollRef
123
+ scrollRef,
124
+ containerSizeRef
107
125
  };
108
126
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["useDynamicVirtualizerMeasure.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { VirtualizerMeasureDynamicProps } from './hooks.types';\nimport { useResizeObserverRef_unstable } from './useResizeObserverRef';\nimport { useRef } from 'react';\n\n/**\n * React hook that measures virtualized space dynamically to ensure optimized virtualization length.\n */\nexport const useDynamicVirtualizerMeasure = <TElement extends HTMLElement>(\n virtualizerProps: VirtualizerMeasureDynamicProps,\n): {\n virtualizerLength: number;\n bufferItems: number;\n bufferSize: number;\n scrollRef: (instance: TElement | null) => void;\n} => {\n const { defaultItemSize, direction = 'vertical', numItems, getItemSize, currentIndex } = virtualizerProps;\n const indexRef = useRef<number>(currentIndex);\n indexRef.current = currentIndex;\n\n const [state, setState] = React.useState({\n virtualizerLength: 0,\n virtualizerBufferItems: 0,\n virtualizerBufferSize: 0,\n });\n\n const { virtualizerLength, virtualizerBufferItems, virtualizerBufferSize } = state;\n\n const container = React.useRef<HTMLElement | null>(null);\n const handleScrollResize = React.useCallback(\n (scrollRef: React.MutableRefObject<HTMLElement | null>) => {\n if (!scrollRef?.current) {\n // Error? ignore?\n return;\n }\n\n if (scrollRef.current !== container.current) {\n container.current = scrollRef.current;\n }\n\n const containerSize =\n direction === 'vertical'\n ? scrollRef.current.getBoundingClientRect().height\n : scrollRef.current.getBoundingClientRect().width;\n\n let indexSizer = 0;\n let length = 0;\n\n while (indexSizer <= containerSize && length < numItems) {\n const iItemSize = getItemSize(indexRef.current + length);\n\n // Increment\n indexSizer += iItemSize;\n length++;\n }\n\n /*\n * Number of items to append at each end, i.e. 'preload' each side before entering view.\n */\n const bufferItems = Math.max(Math.floor(length / 4), 4);\n\n /*\n * This is how far we deviate into the bufferItems to detect a redraw.\n */\n const bufferSize = Math.max(Math.floor((length / 8) * defaultItemSize), 1);\n\n const totalLength = length + bufferItems * 2 + 1;\n setState({\n virtualizerLength: totalLength,\n virtualizerBufferSize: bufferSize,\n virtualizerBufferItems: bufferItems,\n });\n },\n [defaultItemSize, direction, getItemSize, numItems],\n );\n\n const resizeCallback = React.useCallback(\n (\n _entries: ResizeObserverEntry[],\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n _observer: ResizeObserver,\n scrollRef?: React.MutableRefObject<HTMLElement | null>,\n ) => {\n if (scrollRef) {\n handleScrollResize(scrollRef);\n }\n },\n [handleScrollResize],\n );\n\n const scrollRef = useResizeObserverRef_unstable(resizeCallback);\n\n useIsomorphicLayoutEffect(() => {\n if (!container.current) {\n return;\n }\n\n const containerSize =\n direction === 'vertical'\n ? container.current?.getBoundingClientRect().height * 1.5\n : container.current?.getBoundingClientRect().width * 1.5;\n\n let couldBeSmaller = false;\n let recheckTotal = 0;\n for (let i = currentIndex; i < currentIndex + virtualizerLength; i++) {\n const newItemSize = getItemSize(i);\n recheckTotal += newItemSize;\n\n const newLength = i - currentIndex;\n\n const bufferItems = Math.max(Math.floor(newLength / 4), 2);\n const totalNewLength = newLength + bufferItems * 2 + 4;\n const compareLengths = totalNewLength < virtualizerLength;\n\n if (recheckTotal > containerSize && compareLengths) {\n couldBeSmaller = true;\n break;\n }\n }\n\n // Check if the render has caused us to need a re-calc of virtualizer length\n if (recheckTotal < containerSize || couldBeSmaller) {\n handleScrollResize(container);\n }\n }, [getItemSize, currentIndex, direction, virtualizerLength, resizeCallback, handleScrollResize]);\n\n return {\n virtualizerLength,\n bufferItems: virtualizerBufferItems,\n bufferSize: virtualizerBufferSize,\n scrollRef,\n };\n};\n"],"names":["useDynamicVirtualizerMeasure","virtualizerProps","defaultItemSize","direction","numItems","getItemSize","currentIndex","indexRef","useRef","current","state","setState","React","useState","virtualizerLength","virtualizerBufferItems","virtualizerBufferSize","container","handleScrollResize","useCallback","scrollRef","containerSize","getBoundingClientRect","height","width","indexSizer","length","iItemSize","bufferItems","Math","max","floor","bufferSize","totalLength","resizeCallback","_entries","_observer","useResizeObserverRef_unstable","useIsomorphicLayoutEffect","couldBeSmaller","recheckTotal","i","newItemSize","newLength","totalNewLength","compareLengths"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BASaA;;;eAAAA;;;;gCAT6B;iEACnB;sCAEuB;AAMvC,MAAMA,+BAA+B,CAC1CC;IAOA,MAAM,EAAEC,eAAe,EAAEC,YAAY,UAAU,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGL;IACzF,MAAMM,WAAWC,IAAAA,aAAAA,EAAeF;IAChCC,SAASE,OAAO,GAAGH;IAEnB,MAAM,CAACI,OAAOC,SAAS,GAAGC,OAAMC,QAAQ,CAAC;QACvCC,mBAAmB;QACnBC,wBAAwB;QACxBC,uBAAuB;IACzB;IAEA,MAAM,EAAEF,iBAAiB,EAAEC,sBAAsB,EAAEC,qBAAqB,EAAE,GAAGN;IAE7E,MAAMO,YAAYL,OAAMJ,MAAM,CAAqB;IACnD,MAAMU,qBAAqBN,OAAMO,WAAW,CAC1C,CAACC;QACC,IAAI,CAACA,CAAAA,cAAAA,QAAAA,cAAAA,KAAAA,IAAAA,KAAAA,IAAAA,UAAWX,OAAO,AAAPA,GAAS;YACvB,iBAAiB;YACjB;QACF;QAEA,IAAIW,UAAUX,OAAO,KAAKQ,UAAUR,OAAO,EAAE;YAC3CQ,UAAUR,OAAO,GAAGW,UAAUX,OAAO;QACvC;QAEA,MAAMY,gBACJlB,cAAc,aACViB,UAAUX,OAAO,CAACa,qBAAqB,GAAGC,MAAM,GAChDH,UAAUX,OAAO,CAACa,qBAAqB,GAAGE,KAAK;QAErD,IAAIC,aAAa;QACjB,IAAIC,SAAS;QAEb,MAAOD,cAAcJ,i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YF,IAAInC;YAEtB,MAAMsB,cAAcC,KAAKC,GAAG,CAACD,KAAKE,KAAK,CAACY,YAAY,IAAI;YACxD,MAAMC,iBAAiBD,YAAYf,cAAc,IAAI;YACrD,MAAMiB,iBAAiBD,iBAAiB9B;YAExC,IAAI0B,eAAenB,iBAAiBwB,gBAAgB;gBAClDN,iBAAiB;gBACjB;YACF;QACF;QAEA,4EAA4E;QAC5E,IAAIC,eAAenB,iBAAiBkB,gBAAgB;YAClDrB,mBAAmBD;QACrB;IACF,GAAG;QAACZ;QAAaC;QAAcH;QAAWW;QAAmBoB;QAAgBhB;KAAmB;IAEhG,OAAO;QACLJ;QACAc,aAAab;QACbiB,YAAYhB;QACZI;IACF;AACF"}
1
+ {"version":3,"sources":["useDynamicVirtualizerMeasure.ts"],"sourcesContent":["import { useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { VirtualizerMeasureDynamicProps } from './hooks.types';\nimport { useResizeObserverRef_unstable } from './useResizeObserverRef';\nimport { useRef } from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\n/**\n * React hook that measures virtualized space dynamically to ensure optimized virtualization length.\n */\nexport const useDynamicVirtualizerMeasure = <TElement extends HTMLElement>(\n virtualizerProps: VirtualizerMeasureDynamicProps,\n): {\n virtualizerLength: number;\n bufferItems: number;\n bufferSize: number;\n scrollRef: (instance: TElement | null) => void;\n containerSizeRef: React.RefObject<number>;\n} => {\n const {\n defaultItemSize,\n direction = 'vertical',\n numItems,\n getItemSize,\n bufferItems,\n bufferSize,\n virtualizerContext,\n } = virtualizerProps;\n const indexRef = useRef<number>(virtualizerContext.contextIndex);\n indexRef.current = virtualizerContext.contextIndex;\n\n const [state, setState] = React.useState({\n virtualizerLength: 0,\n virtualizerBufferItems: 0,\n virtualizerBufferSize: 0,\n });\n\n const containerSizeRef = React.useRef<number>(0);\n const { virtualizerLength, virtualizerBufferItems, virtualizerBufferSize } = state;\n\n const { targetDocument } = useFluent();\n const container = React.useRef<HTMLElement | null>(null);\n const handleScrollResize = React.useCallback(\n (scrollRef: React.MutableRefObject<HTMLElement | null>) => {\n if (!scrollRef?.current) {\n // Error? ignore?\n return;\n }\n\n if (scrollRef.current !== targetDocument?.body) {\n // We have a local scroll container\n containerSizeRef.current =\n direction === 'vertical'\n ? scrollRef?.current.getBoundingClientRect().height\n : scrollRef?.current.getBoundingClientRect().width;\n } else if (targetDocument?.defaultView) {\n // If our scroll ref is the document body, we should check window height\n containerSizeRef.current =\n direction === 'vertical' ? targetDocument?.defaultView?.innerHeight : targetDocument?.defaultView?.innerWidth;\n }\n\n let indexSizer = 0;\n let i = 0;\n let length = 0;\n\n const sizeToBeat = containerSizeRef.current + virtualizerBufferSize * 2;\n while (indexSizer <= sizeToBeat && i + virtualizerContext.contextIndex < numItems) {\n const iItemSize = getItemSize(indexRef.current + i);\n if (virtualizerContext.childProgressiveSizes.current.length < numItems) {\n /* We are in unknown territory, either an initial render or an update\n in virtualizer item length has occurred.\n We need to let the new items render first then we can accurately assess.*/\n return virtualizerLength - virtualizerBufferSize * 2;\n }\n\n const currentScrollPos = virtualizerContext.contextPosition;\n const currentItemPos = virtualizerContext.childProgressiveSizes.current[indexRef.current + i] - iItemSize;\n\n if (currentScrollPos > currentItemPos + iItemSize) {\n // The item isn't in view, ignore for now.\n i++;\n continue;\n } else if (currentScrollPos > currentItemPos) {\n // The item is partially out of view, ignore the out of bounds portion\n const variance = currentItemPos + iItemSize - currentScrollPos;\n indexSizer += variance;\n } else {\n // Item is in view\n indexSizer += iItemSize;\n }\n // Increment\n i++;\n length++;\n }\n\n /*\n * Number of items to append at each end, i.e. 'preload' each side before entering view.\n * Minimum: 2 - we give slightly more buffer for dynamic version.\n */\n const newBufferItems = bufferItems ?? Math.max(Math.ceil(length / 3), 1);\n\n /*\n * This is how far we deviate into the bufferItems to detect a redraw.\n */\n const newBufferSize = bufferSize ?? Math.max(defaultItemSize / 2.0, 1);\n const totalLength = length + newBufferItems * 2;\n setState({\n virtualizerLength: totalLength,\n virtualizerBufferSize: newBufferSize,\n virtualizerBufferItems: newBufferItems,\n });\n },\n [\n bufferItems,\n bufferSize,\n defaultItemSize,\n direction,\n getItemSize,\n numItems,\n targetDocument?.body,\n targetDocument?.defaultView,\n virtualizerBufferSize,\n virtualizerContext.childProgressiveSizes,\n virtualizerContext.contextIndex,\n virtualizerContext.contextPosition,\n virtualizerLength,\n ],\n );\n\n const resizeCallback = React.useCallback(\n (\n _entries: ResizeObserverEntry[],\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n _observer: ResizeObserver,\n scrollRef?: React.MutableRefObject<HTMLElement | null>,\n ) => {\n if (scrollRef) {\n handleScrollResize(scrollRef);\n }\n },\n [handleScrollResize],\n );\n\n const scrollRef = useMergedRefs(container, useResizeObserverRef_unstable(resizeCallback));\n\n useIsomorphicLayoutEffect(() => {\n if (virtualizerContext.contextIndex + virtualizerLength < numItems) {\n // Avoid re-rendering/re-calculating when the end index has already been reached\n handleScrollResize(container);\n }\n }, [handleScrollResize, numItems, virtualizerContext.contextIndex, virtualizerLength]);\n\n return {\n virtualizerLength,\n bufferItems: virtualizerBufferItems,\n bufferSize: virtualizerBufferSize,\n scrollRef,\n containerSizeRef,\n };\n};\n"],"names":["useDynamicVirtualizerMeasure","virtualizerProps","defaultItemSize","direction","numItems","getItemSize","bufferItems","bufferSize","virtualizerContext","indexRef","useRef","contextIndex","current","state","setState","React","useState","virtualizerLength","virtualizerBufferItems","virtualizerBufferSize","containerSizeRef","targetDocument","useFluent","container","handleScrollResize","useCallback","scrollRef","body","getBoundingClientRect","height","width","defaultView","innerHeight","innerWidth","indexSizer","i","length","sizeToBeat","iItemSize","childProgressiveSizes","currentScrollPos","contextPosition","currentItemPos","variance","newBufferItems","Math","max","ceil","newBufferSize","totalLength","resizeCallback","_entries","_observer","useMergedRefs","useResizeObserverRef_unstable","useIsomorphicLayoutEffect"],"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,aAAaY;QACbX,YAAYY;QACZO;QACAN;IACF;AACF"}
@@ -57,8 +57,20 @@ function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {
57
57
  }
58
58
  };
59
59
  _react.useEffect(()=>{
60
- widthArray.current = new Array(totalLength).fill(defaultItemSize);
61
- heightArray.current = new Array(totalLength).fill(defaultItemSize);
60
+ const newHeightLength = totalLength - heightArray.current.length;
61
+ const newWidthLength = totalLength - widthArray.current.length;
62
+ /* Ensure we grow or truncate arrays with prior properties,
63
+ keeping the existing values is important for whitespace assumptions.
64
+ Even if items in the 'middle' are deleted, we will recalc the whitespace as it is explored.*/ if (newWidthLength > 0) {
65
+ widthArray.current = widthArray.current.concat(new Array(newWidthLength).fill(defaultItemSize));
66
+ } else if (newWidthLength < 0) {
67
+ widthArray.current = widthArray.current.slice(0, totalLength);
68
+ }
69
+ if (newHeightLength > 0) {
70
+ heightArray.current = heightArray.current.concat(new Array(newHeightLength).fill(defaultItemSize));
71
+ } else if (newHeightLength < 0) {
72
+ heightArray.current = heightArray.current.slice(0, totalLength);
73
+ }
62
74
  }, [
63
75
  defaultItemSize,
64
76
  totalLength
@@ -1 +1 @@
1
- {"version":3,"sources":["useMeasureList.ts"],"sourcesContent":["import * as React from 'react';\nimport { useRef } 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 // This lets us trigger updates when a size change occurs.\n const sizeUpdateCount = useRef(0);\n\n // the handler for resize observer\n const handleIndexUpdate = React.useCallback(\n (index: number) => {\n let isChanged = false;\n const boundClientRect = refArray.current[index]?.getBoundingClientRect();\n const containerWidth = boundClientRect?.width;\n if (containerWidth !== widthArray.current[currentIndex + index]) {\n isChanged = true;\n }\n widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;\n\n const containerHeight = boundClientRect?.height;\n\n if (containerHeight !== heightArray.current[currentIndex + index]) {\n isChanged = true;\n }\n heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;\n\n if (isChanged) {\n sizeUpdateCount.current = sizeUpdateCount.current + 1;\n }\n },\n [currentIndex, defaultItemSize, sizeUpdateCount],\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, sizeUpdateCount: sizeUpdateCount.current };\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":["createResizeObserverFromDocument","useMeasureList","currentIndex","refLength","totalLength","defaultItemSize","widthArray","React","useRef","Array","fill","heightArray","refArray","targetDocument","useFluent","sizeUpdateCount","handleIndexUpdate","useCallback","index","isChanged","boundClientRect","current","getBoundingClientRect","containerWidth","width","containerHeight","height","handleElementResizeCallback","entries","entry","target","handleResize","useEffect","resizeObserver","createIndexedRef","measureElementRef","el","undefined","unobserve","observe","_resizeObserver","disconnect","callback","defaultView","ResizeObserver"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAsHgBA,gCAAAA;eAAAA;;IAxGAC,cAAAA;eAAAA;;;;iEAdO;qCAEyB;AAYzC,SAASA,eAEdC,YAAoB,EAAEC,SAAiB,EAAEC,WAAmB,EAAEC,eAAuB;IACrF,MAAMC,aAAaC,O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ASO,SAASrB,iCACda,cAA2C,EAC3C6B,QAAgC;QAE3B7B;IAAL,IAAI,CAACA,CAAAA,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,CAAAA,8BAAAA,eAAgB8B,WAAW,AAAXA,MAAW,QAA3B9B,gCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,4BAA6B+B,cAAc,AAAdA,GAAgB;QAChD,OAAO;IACT;IAEA,OAAO,IAAI/B,eAAe8B,WAAW,CAACC,cAAc,CAACF;AACvD"}
1
+ {"version":3,"sources":["useMeasureList.ts"],"sourcesContent":["import * as React from 'react';\nimport { useRef } 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 // This lets us trigger updates when a size change occurs.\n const sizeUpdateCount = useRef(0);\n\n // the handler for resize observer\n const handleIndexUpdate = React.useCallback(\n (index: number) => {\n let isChanged = false;\n const boundClientRect = refArray.current[index]?.getBoundingClientRect();\n const containerWidth = boundClientRect?.width;\n if (containerWidth !== widthArray.current[currentIndex + index]) {\n isChanged = true;\n }\n widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;\n\n const containerHeight = boundClientRect?.height;\n\n if (containerHeight !== heightArray.current[currentIndex + index]) {\n isChanged = true;\n }\n heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;\n\n if (isChanged) {\n sizeUpdateCount.current = sizeUpdateCount.current + 1;\n }\n },\n [currentIndex, defaultItemSize, sizeUpdateCount],\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 const newHeightLength = totalLength - heightArray.current.length;\n const newWidthLength = totalLength - widthArray.current.length;\n /* Ensure we grow or truncate arrays with prior properties,\n keeping the existing values is important for whitespace assumptions.\n Even if items in the 'middle' are deleted, we will recalc the whitespace as it is explored.*/\n if (newWidthLength > 0) {\n widthArray.current = widthArray.current.concat(new Array(newWidthLength).fill(defaultItemSize));\n } else if (newWidthLength < 0) {\n widthArray.current = widthArray.current.slice(0, totalLength);\n }\n if (newHeightLength > 0) {\n heightArray.current = heightArray.current.concat(new Array(newHeightLength).fill(defaultItemSize));\n } else if (newHeightLength < 0) {\n heightArray.current = heightArray.current.slice(0, totalLength);\n }\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, sizeUpdateCount: sizeUpdateCount.current };\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":["createResizeObserverFromDocument","useMeasureList","currentIndex","refLength","totalLength","defaultItemSize","widthArray","React","useRef","Array","fill","heightArray","refArray","targetDocument","useFluent","sizeUpdateCount","handleIndexUpdate","useCallback","index","isChanged","boundClientRect","current","getBoundingClientRect","containerWidth","width","containerHeight","height","handleElementResizeCallback","entries","entry","target","handleResize","useEffect","newHeightLength","length","newWidthLength","concat","slice","resizeObserver","createIndexedRef","measureElementRef","el","undefined","unobserve","observe","_resizeObserver","disconnect","callback","defaultView","ResizeObserver"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAmIgBA,gCAAAA;eAAAA;;IArHAC,cAAAA;eAAAA;;;;iEAdO;qCAEyB;AAYzC,SAASA,eAEdC,YAAoB,EAAEC,SAAiB,EAAEC,WAAmB,EAAEC,eAAuB;IACrF,MAAMC,aAAaC,OAAMC,MAAM,CAAC,IA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AASS,OAAO,CAACH,MAAM,GAAGuB;gBAC1BH,eAAejB,OAAO,CAACuB,OAAO,CAACH;gBAC/BzB,kBAAkBE;YACpB;QACF;QAEA,OAAOsB;IACT,GACA;QAACxB;QAAmBsB;QAAgBzB;KAAe;IAGrDN,OAAMyB,SAAS,CAAC;QACd,MAAMa,kBAAkBP;QACxB,OAAO;gBAAMO;mBAAAA,CAAAA,0BAAAA,gBAAgBxB,OAAO,AAAPA,MAAO,QAAvBwB,4BAAAA,KAAAA,IAAAA,KAAAA,IAAAA,wBAAyBC,UAAU;;IAClD,GAAG;QAACR;KAAe;IAEnB,OAAO;QAAEhC;QAAYK;QAAa4B;QAAkB3B;QAAUG,iBAAiBA,gBAAgBM,OAAO;IAAC;AACzG;AASO,SAASrB,iCACda,cAA2C,EAC3CkC,QAAgC;QAE3BlC;IAAL,IAAI,CAACA,CAAAA,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,CAAAA,8BAAAA,eAAgBmC,WAAW,AAAXA,MAAW,QAA3BnC,gCAAAA,KAAAA,IAAAA,KAAAA,IAAAA,4BAA6BoC,cAAc,AAAdA,GAAgB;QAChD,OAAO;IACT;IAEA,OAAO,IAAIpC,eAAemC,WAAW,CAACC,cAAc,CAACF;AACvD"}
@@ -17,11 +17,21 @@ const useResizeObserverRef_unstable = (resizeCallback)=>{
17
17
  'use no memo';
18
18
  const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
19
19
  const container = _react.useRef(null);
20
+ const containerHeightRef = _react.useRef(0);
21
+ const containerWidthRef = _react.useRef(0);
20
22
  // the handler for resize observer
21
23
  // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286
22
24
  // eslint-disable-next-line no-restricted-globals
23
25
  const handleResize = (0, _debounce.debounce)((entries, observer)=>{
24
- resizeCallback(entries, observer, container);
26
+ var _container_current, _container_current1;
27
+ const containerHeight = (_container_current = container.current) === null || _container_current === void 0 ? void 0 : _container_current.clientHeight;
28
+ const containerWidth = (_container_current1 = container.current) === null || _container_current1 === void 0 ? void 0 : _container_current1.clientWidth;
29
+ // Our resize observer will fire on scroll resize, let index change handle that instead.
30
+ if (containerHeightRef.current !== containerHeight || containerWidth !== containerWidthRef.current) {
31
+ containerWidthRef.current = containerWidth !== null && containerWidth !== void 0 ? containerWidth : 0;
32
+ containerHeightRef.current = containerHeight !== null && containerHeight !== void 0 ? containerHeight : 0;
33
+ resizeCallback(entries, observer, container);
34
+ }
25
35
  });
26
36
  // Keep the reference of ResizeObserver in the state, as it should live through renders
27
37
  const [resizeObserver, setResizeObserver] = _react.useState(()=>(0, _createResizeObserverFromDocument.createResizeObserverFromDocument)(targetDocument, handleResize));
@@ -1 +1 @@
1
- {"version":3,"sources":["useResizeObserverRef.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { debounce } from '../utilities/debounce';\nimport { createResizeObserverFromDocument } from '../utilities/createResizeObserverFromDocument';\nimport { ResizeCallbackWithRef } from './hooks.types';\n\n/**\n * useResizeObserverRef_unstable simplifies resize observer connection and ensures debounce/cleanup\n */\nexport const useResizeObserverRef_unstable = (resizeCallback: ResizeCallbackWithRef) => {\n 'use no memo';\n\n const { targetDocument } = useFluent();\n const container = React.useRef<HTMLElement | null>(null);\n // the handler for resize observer\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n const handleResize = debounce((entries: ResizeObserverEntry[], observer: ResizeObserver) => {\n resizeCallback(entries, observer, container);\n });\n\n // Keep the reference of ResizeObserver in the state, as it should live through renders\n const [resizeObserver, setResizeObserver] = React.useState(() =>\n createResizeObserverFromDocument(targetDocument, handleResize),\n );\n\n React.useEffect(() => {\n // Update our state when resizeCallback changes\n container.current = null;\n resizeObserver?.disconnect();\n setResizeObserver(() => createResizeObserverFromDocument(targetDocument, handleResize));\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [resizeCallback, targetDocument]);\n\n React.useEffect(() => {\n return () => {\n container.current = null;\n resizeObserver?.disconnect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const scrollRef = React.useCallback(\n (instance: HTMLElement | HTMLDivElement | null) => {\n if (container.current !== instance) {\n if (container.current) {\n resizeObserver?.unobserve(container.current);\n }\n\n container.current = instance;\n if (container.current) {\n resizeObserver?.observe(container.current);\n }\n }\n },\n [resizeObserver],\n );\n\n return scrollRef;\n};\n"],"names":["useResizeObserverRef_unstable","resizeCallback","targetDocument","useFluent","container","React","useRef","handleResize","debounce","entries","observer","resizeObserver","setResizeObserver","useState","createResizeObserverFromDocument","useEffect","current","disconnect","scrollRef","useCallback","instance","unobserve","observe"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BASaA;;;eAAAA;;;;iEATU;qCACyB;0BACvB;kDACwB;AAM1C,MAAMA,gCAAgC,CAACC;IAC5C;IAEA,MAAM,EAAEC,cAAc,EAAE,GAAGC,IAAAA,uCAAAA;IAC3B,MAAMC,YAAYC,OAAMC,MAAM,CAAqB;IACnD,kCAAkC;IAClC,8FAA8F;IAC9F,iDAAiD;IACjD,MAAMC,eAAeC,IAAAA,kBAAAA,EAAS,CAACC,SAAgCC;QAC7DT,eAAeQ,SAASC,UAAUN;IACpC;IAEA,uFAAuF;IACvF,MAAM,CAACO,gBAAgBC,kBAAkB,GAAGP,OAAMQ,QAAQ,CAAC,IACzDC,IAAAA,kEAAAA,EAAiCZ,gBAAgBK;IAGnDF,OAAMU,SAAS,CAAC;QACd,+CAA+C;QAC/CX,UAAUY,OAAO,GAAG;QACpBL,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBM,UAAU;QAC1BL,kBAAkB,IAAME,IAAAA,kEAAAA,EAAiCZ,gBAAgBK;IACzE,uDAAuD;IACzD,GAAG;QAACN;QAAgBC;KAAe;IAEnCG,OAAMU,SAAS,CAAC;QACd,OAAO;YACLX,UAAUY,OAAO,GAAG;YACpBL,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBM,UAAU;QAC5B;IACA,uDAAuD;IACzD,GAAG,EAAE;IAEL,MAAMC,YAAYb,OAAMc,WAAW,CACjC,CAACC;QACC,IAAIhB,UAAUY,OAAO,KAAKI,UAAU;YAClC,IAAIhB,UAAUY,OAAO,EAAE;gBACrBL,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBU,SAAS,CAACjB,UAAUY,OAAO;YAC7C;YAEAZ,UAAUY,OAAO,GAAGI;YACpB,IAAIhB,UAAUY,OAAO,EAAE;gBACrBL,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBW,OAAO,CAAClB,UAAUY,OAAO;YAC3C;QACF;IACF,GACA;QAACL;KAAe;IAGlB,OAAOO;AACT"}
1
+ {"version":3,"sources":["useResizeObserverRef.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { debounce } from '../utilities/debounce';\nimport { createResizeObserverFromDocument } from '../utilities/createResizeObserverFromDocument';\nimport { ResizeCallbackWithRef } from './hooks.types';\n\n/**\n * useResizeObserverRef_unstable simplifies resize observer connection and ensures debounce/cleanup\n */\nexport const useResizeObserverRef_unstable = (resizeCallback: ResizeCallbackWithRef) => {\n 'use no memo';\n\n const { targetDocument } = useFluent();\n const container = React.useRef<HTMLElement | null>(null);\n const containerHeightRef = React.useRef<number>(0);\n const containerWidthRef = React.useRef<number>(0);\n // the handler for resize observer\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n const handleResize = debounce((entries: ResizeObserverEntry[], observer: ResizeObserver) => {\n const containerHeight = container.current?.clientHeight;\n const containerWidth = container.current?.clientWidth;\n // Our resize observer will fire on scroll resize, let index change handle that instead.\n if (containerHeightRef.current !== containerHeight || containerWidth !== containerWidthRef.current) {\n containerWidthRef.current = containerWidth ?? 0;\n containerHeightRef.current = containerHeight ?? 0;\n resizeCallback(entries, observer, container);\n }\n });\n\n // Keep the reference of ResizeObserver in the state, as it should live through renders\n const [resizeObserver, setResizeObserver] = React.useState(() =>\n createResizeObserverFromDocument(targetDocument, handleResize),\n );\n\n React.useEffect(() => {\n // Update our state when resizeCallback changes\n container.current = null;\n resizeObserver?.disconnect();\n setResizeObserver(() => createResizeObserverFromDocument(targetDocument, handleResize));\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [resizeCallback, targetDocument]);\n\n React.useEffect(() => {\n return () => {\n container.current = null;\n resizeObserver?.disconnect();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const scrollRef = React.useCallback(\n (instance: HTMLElement | HTMLDivElement | null) => {\n if (container.current !== instance) {\n if (container.current) {\n resizeObserver?.unobserve(container.current);\n }\n\n container.current = instance;\n if (container.current) {\n resizeObserver?.observe(container.current);\n }\n }\n },\n [resizeObserver],\n );\n\n return scrollRef;\n};\n"],"names":["useResizeObserverRef_unstable","resizeCallback","targetDocument","useFluent","container","React","useRef","containerHeightRef","containerWidthRef","handleResize","debounce","entries","observer","containerHeight","current","clientHeight","containerWidth","clientWidth","resizeObserver","setResizeObserver","useState","createResizeObserverFromDocument","useEffect","disconnect","scrollRef","useCallback","instance","unobserve","observe"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BASaA;;;eAAAA;;;;iEATU;qCACyB;0BACvB;kDACwB;AAM1C,MAAMA,gCAAgC,CAACC;IAC5C;IAEA,MAAM,EAAEC,cAAc,EAAE,GAAGC,IAAAA,uCAAAA;IAC3B,MAAMC,YAAYC,OAAMC,MAAM,CAAqB;IACnD,MAAMC,qBAAqBF,OAAMC,MAAM,CAAS;I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