@fluentui/react-virtualizer 9.0.0-alpha.87 → 9.0.0-alpha.89
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 +29 -5
- package/dist/index.d.ts +21 -22
- package/lib/Hooks.js +1 -1
- package/lib/Hooks.js.map +1 -1
- package/lib/Utilities.js +1 -1
- package/lib/Utilities.js.map +1 -1
- package/lib/Virtualizer.js +1 -1
- package/lib/Virtualizer.js.map +1 -1
- package/lib/VirtualizerScrollView.js +1 -1
- package/lib/VirtualizerScrollView.js.map +1 -1
- package/lib/VirtualizerScrollViewDynamic.js +1 -1
- package/lib/VirtualizerScrollViewDynamic.js.map +1 -1
- package/lib/components/Virtualizer/Virtualizer.js +1 -0
- package/lib/components/Virtualizer/Virtualizer.js.map +1 -1
- package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib/components/Virtualizer/index.js +4 -5
- package/lib/components/Virtualizer/index.js.map +1 -1
- package/lib/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib/components/Virtualizer/useVirtualizer.js +53 -45
- package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js +1 -1
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -1
- package/lib/components/VirtualizerScrollView/index.js +4 -5
- package/lib/components/VirtualizerScrollView/index.js.map +1 -1
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +1 -2
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/index.js +4 -5
- package/lib/components/VirtualizerScrollViewDynamic/index.js.map +1 -1
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +2 -3
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -1
- package/lib/hooks/hooks.types.js +1 -4
- package/lib/hooks/hooks.types.js.map +1 -1
- package/lib/hooks/index.js +5 -6
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useDynamicPagination.js +2 -3
- package/lib/hooks/useDynamicPagination.js.map +1 -1
- package/lib/hooks/useIntersectionObserver.js.map +1 -1
- package/lib/hooks/useMeasureList.js +1 -2
- package/lib/hooks/useMeasureList.js.map +1 -1
- package/lib/hooks/useMutationObserver.js.map +1 -1
- package/lib/hooks/useStaticPagination.js +2 -3
- package/lib/hooks/useStaticPagination.js.map +1 -1
- package/lib/utilities/ImperativeScrolling/imperativeScrolling.types.js +1 -1
- package/lib/utilities/ImperativeScrolling/imperativeScrolling.types.js.map +1 -1
- package/lib/utilities/ImperativeScrolling/index.js +2 -3
- package/lib/utilities/ImperativeScrolling/index.js.map +1 -1
- package/lib/utilities/VirtualizerContext/VirtualizerContext.js +3 -4
- package/lib/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -1
- package/lib/utilities/VirtualizerContext/index.js +1 -2
- package/lib/utilities/VirtualizerContext/index.js.map +1 -1
- package/lib/utilities/index.js +2 -2
- package/lib/utilities/index.js.map +1 -1
- package/lib-commonjs/Hooks.js +30 -2
- package/lib-commonjs/Hooks.js.map +1 -1
- package/lib-commonjs/Utilities.js +24 -2
- package/lib-commonjs/Utilities.js.map +1 -1
- package/lib-commonjs/Virtualizer.js +27 -2
- package/lib-commonjs/Virtualizer.js.map +1 -1
- package/lib-commonjs/VirtualizerScrollView.js +24 -2
- package/lib-commonjs/VirtualizerScrollView.js.map +1 -1
- package/lib-commonjs/VirtualizerScrollViewDynamic.js +24 -2
- package/lib-commonjs/VirtualizerScrollViewDynamic.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/Virtualizer.js +2 -0
- package/lib-commonjs/components/Virtualizer/Virtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/index.js +30 -6
- package/lib-commonjs/components/Virtualizer/index.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js +54 -45
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js +2 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/index.js +27 -6
- package/lib-commonjs/components/VirtualizerScrollView/index.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +1 -1
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +2 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js +27 -6
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js.map +1 -1
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +2 -2
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -1
- package/lib-commonjs/hooks/hooks.types.js +3 -4
- package/lib-commonjs/hooks/hooks.types.js.map +1 -1
- package/lib-commonjs/hooks/index.js +34 -7
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useDynamicPagination.js +2 -2
- package/lib-commonjs/hooks/useDynamicPagination.js.map +1 -1
- package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
- package/lib-commonjs/hooks/useMeasureList.js +1 -1
- package/lib-commonjs/hooks/useMeasureList.js.map +1 -1
- package/lib-commonjs/hooks/useMutationObserver.js.map +1 -1
- package/lib-commonjs/hooks/useStaticPagination.js +2 -2
- package/lib-commonjs/hooks/useStaticPagination.js.map +1 -1
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.types.js +2 -0
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.types.js.map +1 -1
- package/lib-commonjs/utilities/ImperativeScrolling/index.js +16 -4
- package/lib-commonjs/utilities/ImperativeScrolling/index.js.map +1 -1
- package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js +3 -3
- package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -1
- package/lib-commonjs/utilities/VirtualizerContext/index.js +18 -3
- package/lib-commonjs/utilities/VirtualizerContext/index.js.map +1 -1
- package/lib-commonjs/utilities/index.js +25 -3
- package/lib-commonjs/utilities/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -2,9 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
VirtualizerScrollViewDynamic: function() {
|
|
13
|
+
return _VirtualizerScrollViewDynamic.VirtualizerScrollViewDynamic;
|
|
14
|
+
},
|
|
15
|
+
renderVirtualizerScrollViewDynamic_unstable: function() {
|
|
16
|
+
return _renderVirtualizerScrollViewDynamic.renderVirtualizerScrollViewDynamic_unstable;
|
|
17
|
+
},
|
|
18
|
+
useVirtualizerScrollViewDynamicStyles_unstable: function() {
|
|
19
|
+
return _useVirtualizerScrollViewDynamicStylesstyles.useVirtualizerScrollViewDynamicStyles_unstable;
|
|
20
|
+
},
|
|
21
|
+
useVirtualizerScrollViewDynamic_unstable: function() {
|
|
22
|
+
return _useVirtualizerScrollViewDynamic.useVirtualizerScrollViewDynamic_unstable;
|
|
23
|
+
},
|
|
24
|
+
virtualizerScrollViewDynamicClassNames: function() {
|
|
25
|
+
return _useVirtualizerScrollViewDynamicStylesstyles.virtualizerScrollViewDynamicClassNames;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _VirtualizerScrollViewDynamic = require("./VirtualizerScrollViewDynamic");
|
|
29
|
+
const _useVirtualizerScrollViewDynamic = require("./useVirtualizerScrollViewDynamic");
|
|
30
|
+
const _renderVirtualizerScrollViewDynamic = require("./renderVirtualizerScrollViewDynamic");
|
|
31
|
+
const _useVirtualizerScrollViewDynamicStylesstyles = require("./useVirtualizerScrollViewDynamicStyles.styles");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/VirtualizerScrollViewDynamic/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../src/components/VirtualizerScrollViewDynamic/index.ts"],"sourcesContent":["export { VirtualizerScrollViewDynamic } from './VirtualizerScrollViewDynamic';\nexport type {\n VirtualizerScrollViewDynamicProps,\n VirtualizerScrollViewDynamicSlots,\n VirtualizerScrollViewDynamicState,\n} from './VirtualizerScrollViewDynamic.types';\nexport { useVirtualizerScrollViewDynamic_unstable } from './useVirtualizerScrollViewDynamic';\nexport { renderVirtualizerScrollViewDynamic_unstable } from './renderVirtualizerScrollViewDynamic';\nexport {\n useVirtualizerScrollViewDynamicStyles_unstable,\n virtualizerScrollViewDynamicClassNames,\n} from './useVirtualizerScrollViewDynamicStyles.styles';\n"],"names":["VirtualizerScrollViewDynamic","renderVirtualizerScrollViewDynamic_unstable","useVirtualizerScrollViewDynamicStyles_unstable","useVirtualizerScrollViewDynamic_unstable","virtualizerScrollViewDynamicClassNames"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAASA,4BAA4B;eAA5BA,0DAA4B;;IAO5BC,2CAA2C;eAA3CA,+EAA2C;;IAElDC,8CAA8C;eAA9CA,2FAA8C;;IAHvCC,wCAAwC;eAAxCA,yEAAwC;;IAI/CC,sCAAsC;eAAtCA,mFAAsC;;;8CAVK;iDAMY;oDACG;6DAIrD"}
|
package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js
CHANGED
|
@@ -23,7 +23,7 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
|
|
|
23
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
|
-
const [sizeUpdateCount, setSizeUpdateCount] =
|
|
26
|
+
const [sizeUpdateCount, setSizeUpdateCount] = _react.useState(0);
|
|
27
27
|
const getChildSizeAuto = _react.useCallback((index)=>{
|
|
28
28
|
if (sizeTrackingArray.current.length <= index || sizeTrackingArray.current[index] <= 0) {
|
|
29
29
|
// Default size for initial state or untracked
|
|
@@ -62,7 +62,7 @@ function useVirtualizerScrollViewDynamic_unstable(props) {
|
|
|
62
62
|
}
|
|
63
63
|
const scrollViewRef = (0, _reactutilities.useMergedRefs)(props.scrollViewRef, scrollRef, paginationRef);
|
|
64
64
|
const scrollCallbackRef = _react.useRef(null);
|
|
65
|
-
|
|
65
|
+
_react.useImperativeHandle(imperativeRef, ()=>{
|
|
66
66
|
var _imperativeVirtualizerRef_current;
|
|
67
67
|
return {
|
|
68
68
|
scrollTo (index, behavior = 'auto', callback) {
|
package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/VirtualizerScrollViewDynamic/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, updateScrollPosition } =\n 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);\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: scrollViewRef as React.RefObject<HTMLDivElement>,\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 scrollViewRef,\n updateScrollPosition,\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","updateScrollPosition","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;QAiD0BC;IA/C1B,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,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AAOG,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,CAACnF,MAAMiF,SAAS,EAAE;YACtCG,cAAc;gBACZT,KAAK9B;YACP;YACAwC,aAAa;QACf;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../src/components/VirtualizerScrollViewDynamic/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 { 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] = React.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, updateScrollPosition } =\n 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);\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\n\n React.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: scrollViewRef as React.RefObject<HTMLDivElement>,\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 scrollViewRef,\n updateScrollPosition,\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","updateScrollPosition","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":";;;;+BAcgBA;;;eAAAA;;;;iEAdO;gCACa;gCACI;uBAKK;2BAC4B;gCAE1C;sCAEiB;AAEzC,SAASA,yCACdC,KAAwC;IAExC;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D,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,MAAMtE,KAAK;oBACf0E,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,CAACnF,MAAMiF,SAAS,EAAE;YACtCG,cAAc;gBACZT,KAAK9B;YACP;YACAwC,aAAa;QACf;IACF;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
* Additional direct Ref prevents reading old resize entry data
|
|
3
|
-
* Backwards compatible with ResizeObserverCallback if preferred
|
|
4
|
-
*/ "use strict";
|
|
1
|
+
"use strict";
|
|
5
2
|
Object.defineProperty(exports, "__esModule", {
|
|
6
3
|
value: true
|
|
7
4
|
});
|
|
5
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
6
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/hooks.types.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/hooks/hooks.types.ts"],"sourcesContent":["import * as React 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: React.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?: React.MutableRefObject<HTMLElement | null>,\n ): void;\n}\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;iEAAuB"}
|
|
@@ -2,10 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
createResizeObserverFromDocument: function() {
|
|
13
|
+
return _useMeasureList.createResizeObserverFromDocument;
|
|
14
|
+
},
|
|
15
|
+
getRTLRootMargin: function() {
|
|
16
|
+
return _useIntersectionObserver.getRTLRootMargin;
|
|
17
|
+
},
|
|
18
|
+
useDynamicVirtualizerMeasure: function() {
|
|
19
|
+
return _useDynamicVirtualizerMeasure.useDynamicVirtualizerMeasure;
|
|
20
|
+
},
|
|
21
|
+
useIntersectionObserver: function() {
|
|
22
|
+
return _useIntersectionObserver.useIntersectionObserver;
|
|
23
|
+
},
|
|
24
|
+
useMeasureList: function() {
|
|
25
|
+
return _useMeasureList.useMeasureList;
|
|
26
|
+
},
|
|
27
|
+
useResizeObserverRef_unstable: function() {
|
|
28
|
+
return _useResizeObserverRef.useResizeObserverRef_unstable;
|
|
29
|
+
},
|
|
30
|
+
useStaticVirtualizerMeasure: function() {
|
|
31
|
+
return _useVirtualizerMeasure.useStaticVirtualizerMeasure;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
const _useIntersectionObserver = require("./useIntersectionObserver");
|
|
35
|
+
const _useVirtualizerMeasure = require("./useVirtualizerMeasure");
|
|
36
|
+
const _useDynamicVirtualizerMeasure = require("./useDynamicVirtualizerMeasure");
|
|
37
|
+
const _useResizeObserverRef = require("./useResizeObserverRef");
|
|
38
|
+
const _useMeasureList = require("./useMeasureList");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../src/hooks/index.ts"],"sourcesContent":["export { getRTLRootMargin, useIntersectionObserver } from './useIntersectionObserver';\nexport { useStaticVirtualizerMeasure } from './useVirtualizerMeasure';\nexport { useDynamicVirtualizerMeasure } from './useDynamicVirtualizerMeasure';\nexport { useResizeObserverRef_unstable } from './useResizeObserverRef';\nexport type {\n ResizeCallbackWithRef,\n VirtualizerDynamicPaginationProps,\n VirtualizerMeasureDynamicProps,\n VirtualizerMeasureProps,\n VirtualizerStaticPaginationProps,\n} from './hooks.types';\nexport type { IndexedResizeCallbackElement } from './useMeasureList';\nexport { createResizeObserverFromDocument, useMeasureList } from './useMeasureList';\n"],"names":["createResizeObserverFromDocument","getRTLRootMargin","useDynamicVirtualizerMeasure","useIntersectionObserver","useMeasureList","useResizeObserverRef_unstable","useStaticVirtualizerMeasure"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAYSA,gCAAgC;eAAhCA,gDAAgC;;IAZhCC,gBAAgB;eAAhBA,yCAAgB;;IAEhBC,4BAA4B;eAA5BA,0DAA4B;;IAFVC,uBAAuB;eAAvBA,gDAAuB;;IAYPC,cAAc;eAAdA,8BAAc;;IAThDC,6BAA6B;eAA7BA,mDAA6B;;IAF7BC,2BAA2B;eAA3BA,kDAA2B;;;yCADsB;uCACd;8CACC;sCACC;gCASmB"}
|
|
@@ -15,8 +15,8 @@ const useDynamicVirtualizerPagination = (virtualizerProps, paginationEnabled = t
|
|
|
15
15
|
'use no memo';
|
|
16
16
|
const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;
|
|
17
17
|
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
|
|
18
|
-
const lastScrollPos =
|
|
19
|
-
const lastIndexScrolled =
|
|
18
|
+
const lastScrollPos = _react.useRef(-1);
|
|
19
|
+
const lastIndexScrolled = _react.useRef(-1);
|
|
20
20
|
const scrollContainer = _react.useRef(null);
|
|
21
21
|
const clearListeners = ()=>{
|
|
22
22
|
if (scrollContainer.current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useDynamicPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerDynamicPaginationProps } from './hooks.types';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useDynamicPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerDynamicPaginationProps } from './hooks.types';\nimport { useTimeout } from '@fluentui/react-utilities';\n\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are dynamic so we require a progressive sizing array (passed in from Dynamic virtualizer hooks)\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerDynamicPaginationProps can be grabbed from dynamic Virtualizer hooks externally and passed in\n */\nexport const useDynamicVirtualizerPagination = (\n virtualizerProps: VirtualizerDynamicPaginationProps,\n paginationEnabled: Boolean = true,\n) => {\n 'use no memo';\n\n const { axis = 'vertical', currentIndex, progressiveItemSizes, virtualizerLength } = virtualizerProps;\n\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const lastScrollPos = React.useRef<number>(-1);\n const lastIndexScrolled = React.useRef<number>(-1);\n\n const scrollContainer = React.useRef<HTMLElement | null>(null);\n\n const clearListeners = () => {\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n scrollContainer.current = null;\n clearScrollTimer();\n }\n };\n\n React.useEffect(() => {\n return () => {\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n *\n * Users/Virtualizer-Hooks must pass in a cumulative array of sizes\n * This prevents the need to recalculate and ensures size arrays are synced externally\n */\n const onScrollEnd = React.useCallback(() => {\n if (!scrollContainer.current || !paginationEnabled || !progressiveItemSizes?.current) {\n // No container found\n return;\n }\n\n const currentScrollPos = Math.round(\n axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft,\n );\n let closestItemPos = 0;\n let closestItem = 0;\n const endItem = Math.min(currentIndex + virtualizerLength, progressiveItemSizes.current.length);\n\n for (let i = currentIndex; i < endItem - 1; i++) {\n if (\n currentScrollPos <= progressiveItemSizes.current[i + 1] &&\n currentScrollPos >= progressiveItemSizes.current[i]\n ) {\n // Found our in between position\n const distanceToPrev = Math.abs(currentScrollPos - progressiveItemSizes.current[i]);\n const distanceToNext = Math.abs(progressiveItemSizes.current[i + 1] - currentScrollPos);\n if (distanceToPrev < distanceToNext) {\n closestItem = i;\n } else {\n closestItem = i + 1;\n }\n break;\n }\n }\n\n let nextItem;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n // This will also handle a case where we scrolled to the exact correct position (noop)\n const isSecondaryScroll = Math.round(lastScrollPos.current - currentScrollPos) === 0;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n\n // Safeguard nextItem\n nextItem = Math.min(Math.max(0, nextItem), progressiveItemSizes.current.length);\n closestItemPos = progressiveItemSizes.current[nextItem];\n\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({ top: closestItemPos, behavior: 'smooth' });\n } else {\n scrollContainer.current.scrollTo({ left: closestItemPos, behavior: 'smooth' });\n }\n lastScrollPos.current = progressiveItemSizes.current[nextItem];\n lastIndexScrolled.current = nextItem;\n }, [paginationEnabled, currentIndex, scrollContainer, virtualizerLength, axis, progressiveItemSizes]);\n\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */\n const onScroll = React.useCallback(\n event => {\n clearScrollTimer();\n setScrollTimer(onScrollEnd, 100);\n },\n [onScrollEnd, clearScrollTimer, setScrollTimer],\n );\n\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */\n const paginationRef = React.useCallback(\n (instance: HTMLElement | HTMLDivElement | null) => {\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onScroll, onScrollEnd, paginationEnabled],\n );\n\n return paginationRef;\n};\n"],"names":["useDynamicVirtualizerPagination","virtualizerProps","paginationEnabled","axis","currentIndex","progressiveItemSizes","virtualizerLength","setScrollTimer","clearScrollTimer","useTimeout","lastScrollPos","React","useRef","lastIndexScrolled","scrollContainer","clearListeners","current","removeEventListener","onScroll","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItemPos","closestItem","endItem","min","length","i","distanceToPrev","abs","distanceToNext","nextItem","nextTarget","isSecondaryScroll","posMod","max","scrollTo","top","behavior","left","event","paginationRef","instance","addEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAUaA;;;eAAAA;;;;iEAVU;gCAEI;AAQpB,MAAMA,kCAAkC,CAC7CC,kBACAC,oBAA6B,IAAI;IAEjC;IAEA,MAAM,EAAEC,OAAO,UAAU,EAAEC,YAAY,EAAEC,oBAAoB,EAAEC,iBAAiB,EAAE,GAAGL;IAErF,MAAM,CAACM,gBAAgBC,iBAAiB,GAAGC,IAAAA,0BAAAA;IAC3C,MAAMC,gBAAgBC,OAAMC,MAAM,CAAS,CAAC;IAC5C,MAAMC,oBAAoBF,O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,gBAAgBE,OAAO,GAAG+B;YAC1B,IAAIjC,gBAAgBE,OAAO,EAAE;gBAC3BF,gBAAgBE,OAAO,CAACgC,gBAAgB,CAAC,UAAU9B;YACrD;QACF;IACF,GAEA;QAACA;QAAUE;QAAalB;KAAkB;IAG5C,OAAO4C;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useIntersectionObserver.ts"],"sourcesContent":["import type { Dispatch, MutableRefObject, SetStateAction } from 'react';\nimport * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */\nexport const getRTLRootMargin = (\n ltrRootMargin: string,\n target?: Element | Document | null | undefined,\n win?: Window | null,\n): string => {\n if (target && win) {\n // get the computed dir for the target element\n const newDir = win.getComputedStyle(target as Element).direction;\n\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n\n return ltrRootMargin;\n};\n\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */\n\nexport const useIntersectionObserver = (\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n): {\n setObserverList: Dispatch<SetStateAction<Element[] | undefined>>;\n setObserverInit: (newInit: IntersectionObserverInit | undefined) => void;\n // TODO: exclude types from this lint rule: https://github.com/microsoft/fluentui/issues/31286\n // eslint-disable-next-line no-restricted-globals\n observer: MutableRefObject<IntersectionObserver | undefined>;\n} => {\n 'use no memo';\n\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 observer = useRef<IntersectionObserver>();\n const [observerList, setObserverList] = useState<Element[]>();\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState<IntersectionObserverInit | undefined>(\n options && {\n ...options,\n rootMargin: getRTLRootMargin(options.rootMargin ?? '0px', options.root as Element, win),\n },\n );\n\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef<string>(options?.rootMargin ?? '0px');\n\n // Callback function to execute when mutations are observed\n const mutationObserverCallback: MutationCallback = useCallback(\n mutationList => {\n for (const mutation of mutationList) {\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'dir' &&\n options?.root &&\n mutation.target.contains(options?.root)\n ) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root, win),\n });\n }\n }\n },\n [ltrRootMargin, observerInit, options?.root, win],\n );\n\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: ['dir'],\n });\n\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(() => {\n if (!win) {\n return;\n }\n\n observer.current = new win.IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root, win),\n });\n\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach(element => {\n observer.current?.observe(element);\n });\n }\n\n // clean up previous elements being listened to\n return () => {\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [observerList, observerInit, callback, win]);\n\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback(\n (newInit: IntersectionObserverInit | undefined) => {\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = newInit?.rootMargin ?? '0px';\n\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit?.root as Element, win),\n });\n },\n [ltrRootMargin, setObserverInit, win],\n );\n\n return { setObserverList, setObserverInit: setObserverInitExternal, observer };\n};\n"],"names":["getRTLRootMargin","useIntersectionObserver","useCallback","useState","useRef","React","ltrRootMargin","target","win","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","callback","options","observer","observerList","setObserverList","targetDocument","useFluent","defaultView","observerInit","setObserverInit","rootMargin","root","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","useMutationObserver","attributes","subtree","attributeFilter","useIsomorphicLayoutEffect","IntersectionObserver","forEach","element","observe","disconnect","setObserverInitExternal","newInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAcaA,gBAAAA;eAAAA;;IAsCAC,uBAAAA;eAAAA;;;;iEAnDU;gCACmB;qCACM;qCAGZ;AADpC,MAAM,EAAEC,WAAW,E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A;oBACnBxB;gBAAAA,CAAAA,oBAAAA,SAASgB,OAAO,AAAPA,MAAO,QAAhBhB,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kBAAkByB,OAAO,CAACD;YAC5B;QACF;QAEA,+CAA+C;QAC/C,OAAO;YACL,IAAIxB,SAASgB,OAAO,EAAE;gBACpBhB,SAASgB,OAAO,CAACU,UAAU;YAC7B;QACF;IACF,GAAG;QAACzB;QAAcK;QAAcR;QAAUR;KAAI;IAE9C,sEAAsE;IACtE,MAAMqC,0BAA0B3C,YAC9B,CAAC4C;YAEyBA;QADxB,+FAA+F;QAC/FxC,cAAc4B,OAAO,GAAGY,CAAAA,sBAAAA,YAAAA,QAAAA,YAAAA,KAAAA,IAAAA,KAAAA,IAAAA,QAASpB,UAAU,AAAVA,MAAU,QAAnBoB,wBAAAA,KAAAA,IAAAA,sBAAuB;QAE/C,iHAAiH;QACjHrB,gBAAgB;YACd,GAAGqB,OAAO;YACVpB,YAAY1B,iBAAiBM,cAAc4B,OAAO,EAAEY,YAAAA,QAAAA,YAAAA,KAAAA,IAAAA,KAAAA,IAAAA,QAASnB,IAAI,EAAanB;QAChF;IACF,GACA;QAACF;QAAemB;QAAiBjB;KAAI;IAGvC,OAAO;QAAEY;QAAiBK,iBAAiBoB;QAAyB3B;IAAS;AAC/E"}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useIntersectionObserver.ts"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */\nexport const getRTLRootMargin = (\n ltrRootMargin: string,\n target?: Element | Document | null | undefined,\n win?: Window | null,\n): string => {\n if (target && win) {\n // get the computed dir for the target element\n const newDir = win.getComputedStyle(target as Element).direction;\n\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n\n return ltrRootMargin;\n};\n\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */\n\nexport const useIntersectionObserver = (\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n): {\n setObserverList: React.Dispatch<React.SetStateAction<Element[] | undefined>>;\n setObserverInit: (newInit: IntersectionObserverInit | undefined) => void;\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: React.MutableRefObject<IntersectionObserver | undefined>;\n} => {\n 'use no memo';\n\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 observer = useRef<IntersectionObserver>();\n const [observerList, setObserverList] = useState<Element[]>();\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState<IntersectionObserverInit | undefined>(\n options && {\n ...options,\n rootMargin: getRTLRootMargin(options.rootMargin ?? '0px', options.root as Element, win),\n },\n );\n\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef<string>(options?.rootMargin ?? '0px');\n\n // Callback function to execute when mutations are observed\n const mutationObserverCallback: MutationCallback = useCallback(\n mutationList => {\n for (const mutation of mutationList) {\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'dir' &&\n options?.root &&\n mutation.target.contains(options?.root)\n ) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root, win),\n });\n }\n }\n },\n [ltrRootMargin, observerInit, options?.root, win],\n );\n\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: ['dir'],\n });\n\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(() => {\n if (!win) {\n return;\n }\n\n observer.current = new win.IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root, win),\n });\n\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach(element => {\n observer.current?.observe(element);\n });\n }\n\n // clean up previous elements being listened to\n return () => {\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [observerList, observerInit, callback, win]);\n\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback(\n (newInit: IntersectionObserverInit | undefined) => {\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = newInit?.rootMargin ?? '0px';\n\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit?.root as Element, win),\n });\n },\n [ltrRootMargin, setObserverInit, win],\n );\n\n return { setObserverList, setObserverInit: setObserverInitExternal, observer };\n};\n"],"names":["getRTLRootMargin","useIntersectionObserver","useCallback","useState","useRef","React","ltrRootMargin","target","win","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","callback","options","observer","observerList","setObserverList","targetDocument","useFluent","defaultView","observerInit","setObserverInit","rootMargin","root","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","useMutationObserver","attributes","subtree","attributeFilter","useIsomorphicLayoutEffect","IntersectionObserver","forEach","element","observe","disconnect","setObserverInitExternal","newInit"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAaaA,gBAAAA;eAAAA;;IAsCAC,uBAAAA;eAAAA;;;;iEAnDU;gCACmB;qCACM;qCAGZ;AADpC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGC;AASnC,MAAML,mBAAmB,CAC9BM,eACAC,QACAC;IAEA,IAAID,UAAUC,KAAK;QACjB,8CAA8C;QAC9C,MAAMC,SAASD,IAAIE,gBAAgB,CAACH,QAAmBI,SAAS;QAEhE,+FAA+F;QAC/F,IAAIF,WAAW,OAAO;YACpB,IAAIG,YAAYN;YAChB,MAAMO,eAAeP,cAAcQ,KAAK,CAAC;YAEzC,2GAA2G;YAC3G,IAAID,aAAaE,MAAM,KAAK,GAAG;gBAC7BH,YAAY,CAAC,EAAEC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC;YAC3F;YAEA,OAAOD;QACT,OAAO;YACL,OAAON;QACT;IACF;IAEA,OAAOA;AACT;AAYO,MAAML,0BAA0B,CACrCe,UACAC;IAQA;IAEA,8FAA8F;IAC9F,iDAAiD;IACjD,MAAM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AAA,KAAAA,IAAAA,KAAAA,IAAAA,QAASnB,IAAI,EAAanB;QAChF;IACF,GACA;QAACF;QAAemB;QAAiBjB;KAAI;IAGvC,OAAO;QAAEY;QAAiBK,iBAAiBoB;QAAyB3B;IAAS;AAC/E"}
|
|
@@ -25,7 +25,7 @@ function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {
|
|
|
25
25
|
const refArray = _react.useRef([]);
|
|
26
26
|
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
|
27
27
|
// This lets us trigger updates when a size change occurs.
|
|
28
|
-
const sizeUpdateCount =
|
|
28
|
+
const sizeUpdateCount = _react.useRef(0);
|
|
29
29
|
// the handler for resize observer
|
|
30
30
|
const handleIndexUpdate = _react.useCallback((index)=>{
|
|
31
31
|
var _refArray_current_index;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useMeasureList.ts"],"sourcesContent":["import * as React from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/hooks/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 // This lets us trigger updates when a size change occurs.\n const sizeUpdateCount = React.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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kBE;gBACpB;YACF;YAEA,6BAA6B;YAC7B,IAAIN,SAASS,OAAO,CAACH,MAAM,KAAKwB,aAAa9B,SAASS,OAAO,CAACH,MAAM,KAAK,MAAM;gBAC7EoB,eAAejB,OAAO,CAACsB,SAAS,CAAC/B,SAASS,OAAO,CAACH,MAAM;YAC1D;YAEAN,SAASS,OAAO,CAACH,MAAM,GAAGwB;YAC1B,IAAID,IAAI;gBACN7B,SAASS,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useMutationObserver.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useMutationObserver.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useRef, useEffect } = React;\n\nexport const useMutationObserver = (\n target: Element | Document | undefined,\n callback: MutationCallback,\n options?: MutationObserverInit,\n): {\n observer: React.MutableRefObject<MutationObserver | undefined>; // eslint-disable-line no-restricted-globals\n} => {\n 'use no memo';\n\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 observer = useRef<MutationObserver>();\n const { targetDocument } = useFluent();\n const win = targetDocument?.defaultView;\n\n useEffect(() => {\n if (!win) {\n return;\n }\n // Create an observer instance linked to the callback function\n observer.current = new win.MutationObserver(callback);\n }, [callback, win]);\n\n useEffect(() => {\n if (target) {\n // Start observing the target node for configured mutations\n observer.current?.observe(target, options);\n }\n\n return () => {\n observer.current?.disconnect();\n };\n }, [target, options]);\n\n return { observer };\n};\n"],"names":["useMutationObserver","useRef","useEffect","React","target","callback","options","observer","targetDocument","useFluent","win","defaultView","current","MutationObserver","observe","disconnect"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAKaA;;;eAAAA;;;;iEALU;qCACyB;AAEhD,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGC;AAEvB,MAAMH,sBAAsB,CACjCI,QACAC,UACAC;IAIA;IAEA,8FAA8F;IAC9F,iDAAiD;IACjD,MAAMC,WAAWN;IACjB,MAAM,EAAEO,cAAc,EAAE,GAAGC,IAAAA,uCAAAA;IAC3B,MAAMC,MAAMF,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAgBG,WAAW;IAEvCT,UAAU;QACR,IAAI,CAACQ,KAAK;YACR;QACF;QACA,8DAA8D;QAC9DH,SAASK,OAAO,GAAG,IAAIF,IAAIG,gBAAgB,CAACR;IAC9C,GAAG;QAACA;QAAUK;KAAI;IAElBR,UAAU;QACR,IAAIE,QAAQ;gBAEVG;YAAAA,CAAAA,oBAAAA,SAASK,OAAO,AAAPA,MAAO,QAAhBL,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kBAAkBO,OAAO,CAACV,QAAQE;QACpC;QAEA,OAAO;gBACLC;YAAAA,CAAAA,oBAAAA,SAASK,OAAO,AAAPA,MAAO,QAAhBL,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,kBAAkBQ,UAAU;QAC9B;IACF,GAAG;QAACX;QAAQE;KAAQ;IAEpB,OAAO;QAAEC;IAAS;AACpB"}
|
|
@@ -15,8 +15,8 @@ const useStaticVirtualizerPagination = (virtualizerProps, paginationEnabled = tr
|
|
|
15
15
|
'use no memo';
|
|
16
16
|
const { itemSize, axis = 'vertical' } = virtualizerProps;
|
|
17
17
|
const [setScrollTimer, clearScrollTimer] = (0, _reactutilities.useTimeout)();
|
|
18
|
-
const lastScrollPos =
|
|
19
|
-
const lastIndexScrolled =
|
|
18
|
+
const lastScrollPos = _react.useRef(0);
|
|
19
|
+
const lastIndexScrolled = _react.useRef(0);
|
|
20
20
|
const scrollContainer = _react.useRef(null);
|
|
21
21
|
const clearListeners = ()=>{
|
|
22
22
|
if (scrollContainer.current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useStaticPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerStaticPaginationProps } from './hooks.types';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useStaticPagination.ts"],"sourcesContent":["import * as React from 'react';\nimport { VirtualizerStaticPaginationProps } from './hooks.types';\nimport { useTimeout } from '@fluentui/react-utilities';\n\n/**\n * Optional hook that will enable pagination on the virtualizer so that it 'autoscrolls' to an items exact position\n * Sizes are uniform/static, we round to the nearest item on long scrolls\n * On short scrolls, we will go at minimum to the next/previous item so that arrow pagination works\n * All VirtualizerStaticPaginationProps can be grabbed from Virtualizer hooks externally and passed in\n */\nexport const useStaticVirtualizerPagination = (\n virtualizerProps: VirtualizerStaticPaginationProps,\n paginationEnabled: Boolean = true,\n) => {\n 'use no memo';\n\n const { itemSize, axis = 'vertical' } = virtualizerProps;\n\n const [setScrollTimer, clearScrollTimer] = useTimeout();\n const lastScrollPos = React.useRef<number>(0);\n const lastIndexScrolled = React.useRef<number>(0);\n\n const scrollContainer = React.useRef<HTMLElement | null>(null);\n\n const clearListeners = () => {\n if (scrollContainer.current) {\n scrollContainer.current.removeEventListener('scroll', onScroll);\n\n scrollContainer.current = null;\n clearScrollTimer();\n }\n };\n\n React.useEffect(() => {\n return () => {\n clearListeners();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n /**\n * Handle scroll stop event and paginate to the closest item\n * If the closest item is the same as the previous scroll end\n * we paginate to the next/previous one based on direction\n */\n const onScrollEnd = React.useCallback(() => {\n if (!scrollContainer.current || !paginationEnabled) {\n // No container found\n return;\n }\n\n const currentScrollPos = Math.round(\n axis === 'vertical' ? scrollContainer.current.scrollTop : scrollContainer.current.scrollLeft,\n );\n const closestItem = Math.round(currentScrollPos / itemSize);\n\n let nextItem = 0;\n if (Math.round(closestItem - lastIndexScrolled.current) === 0) {\n // Special case for go to next/previous with minimum amount of scroll needed\n const nextTarget = lastScrollPos.current < currentScrollPos ? 1 : -1;\n const isSecondaryScroll = lastScrollPos.current === currentScrollPos;\n const posMod = isSecondaryScroll ? 0 : nextTarget;\n\n nextItem = closestItem + posMod;\n } else {\n // Pagination for anything else can just jump to the closest!\n nextItem = closestItem;\n }\n\n const nextItemPos = nextItem * itemSize;\n\n if (axis === 'vertical') {\n scrollContainer.current.scrollTo({ top: nextItemPos, behavior: 'smooth' });\n } else {\n scrollContainer.current.scrollTo({ left: nextItemPos, behavior: 'smooth' });\n }\n lastScrollPos.current = nextItemPos;\n lastIndexScrolled.current = nextItem;\n }, [paginationEnabled, axis, itemSize]);\n\n /**\n * On scroll timer that will continuously delay callback until scrolling stops\n */\n const onScroll = React.useCallback(\n event => {\n clearScrollTimer();\n setScrollTimer(onScrollEnd, 100);\n },\n [onScrollEnd, clearScrollTimer, setScrollTimer],\n );\n\n /**\n * Pagination ref will ensure we attach listeners to containers on change\n * It is returned from hook and merged into the scroll container externally\n */\n const paginationRef = React.useCallback(\n (instance: HTMLElement | HTMLDivElement | null) => {\n if (!paginationEnabled) {\n clearListeners();\n scrollContainer.current = null;\n return;\n }\n if (scrollContainer.current !== instance) {\n clearListeners();\n\n scrollContainer.current = instance;\n if (scrollContainer.current) {\n scrollContainer.current.addEventListener('scroll', onScroll);\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [onScroll, onScrollEnd, paginationEnabled],\n );\n\n return paginationRef;\n};\n"],"names":["useStaticVirtualizerPagination","virtualizerProps","paginationEnabled","itemSize","axis","setScrollTimer","clearScrollTimer","useTimeout","lastScrollPos","React","useRef","lastIndexScrolled","scrollContainer","clearListeners","current","removeEventListener","onScroll","useEffect","onScrollEnd","useCallback","currentScrollPos","Math","round","scrollTop","scrollLeft","closestItem","nextItem","nextTarget","isSecondaryScroll","posMod","nextItemPos","scrollTo","top","behavior","left","event","paginationRef","instance","addEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAUaA;;;eAAAA;;;;iEAVU;gCAEI;AAQpB,MAAMA,iCAAiC,CAC5CC,kBACAC,oBAA6B,IAAI;IAEjC;IAEA,MAAM,EAAEC,QAAQ,EAAEC,OAAO,UAAU,EAAE,GAAGH;IAExC,MAAM,CAACI,gBAAgBC,iBAAiB,GAAGC,IAAAA,0BAAAA;IAC3C,MAAMC,gBAAgBC,OAAMC,MAAM,CAAS;IAC3C,MAAMC,oBAAoBF,OAAMC,MAAM,CAAS;IAE/C,MAAME,kBAAkBH,OAAMC,MAAM,CAAqB;IAEzD,MAAMG,iBAAiB;QACrB,IAAID,gBAAgBE,OAAO,EAAE;YAC3BF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B,GACA;QAACA;QAAaZ;QAAkBD;KAAe;IAGjD;;;GAGC,GACD,MAAM+B,gBAAgB3B,OAAMU,WAAW,CACrC,CAACkB;QACC,IAAI,CAACnC,mBAAmB;YACtBW;YACAD,gBAAgBE,OAAO,GAAG;YAC1B;QACF;QACA,IAAIF,gBAAgBE,OAAO,KAAKuB,UAAU;YACxCxB;YAEAD,gBAAgBE,OAAO,GAAGuB;YAC1B,IAAIzB,gBAAgBE,OAAO,EAAE;gBAC3BF,gBAAgBE,OAAO,CAACwB,gBAAgB,CAAC,UAAUtB;YACrD;QACF;IACF,GAEA;QAACA;QAAUE;QAAahB;KAAkB;IAG5C,OAAOkC;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities/ImperativeScrolling/imperativeScrolling.types.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../src/utilities/ImperativeScrolling/imperativeScrolling.types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type ScrollToItemStaticParams = {\n index: number;\n itemSize: number;\n totalItems: number;\n scrollViewRef: React.RefObject<HTMLDivElement>;\n axis?: 'horizontal' | 'vertical';\n reversed?: boolean;\n behavior?: ScrollBehavior;\n};\n\nexport type ScrollToItemDynamicParams = {\n index: number;\n itemSizes: React.RefObject<number[]>;\n totalSize: number;\n scrollViewRef: React.RefObject<HTMLDivElement>;\n axis?: 'horizontal' | 'vertical';\n reversed?: boolean;\n behavior?: ScrollBehavior;\n};\n\nexport type ScrollToInterface = {\n scrollTo: (index: number, behavior?: ScrollBehavior, callback?: (index: number) => void) => void;\n virtualizerLength: React.RefObject<number>;\n currentIndex: React.RefObject<number> | undefined;\n};\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;iEAAuB"}
|
|
@@ -2,7 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
scrollToItemDynamic: function() {
|
|
13
|
+
return _imperativeScrollingDynamic.scrollToItemDynamic;
|
|
14
|
+
},
|
|
15
|
+
scrollToItemStatic: function() {
|
|
16
|
+
return _imperativeScrolling.scrollToItemStatic;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _imperativeScrolling = require("./imperativeScrolling");
|
|
20
|
+
const _imperativeScrollingDynamic = require("./imperativeScrollingDynamic");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities/ImperativeScrolling/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../src/utilities/ImperativeScrolling/index.ts"],"sourcesContent":["export { scrollToItemStatic } from './imperativeScrolling';\nexport type {\n ScrollToInterface,\n ScrollToItemDynamicParams,\n ScrollToItemStaticParams,\n} from './imperativeScrolling.types';\nexport { scrollToItemDynamic } from './imperativeScrollingDynamic';\n"],"names":["scrollToItemDynamic","scrollToItemStatic"],"rangeMappings":";;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAMSA,mBAAmB;eAAnBA,+CAAmB;;IANnBC,kBAAkB;eAAlBA,uCAAkB;;;qCAAQ;4CAMC"}
|
|
@@ -28,11 +28,11 @@ const useVirtualizerContext_unstable = ()=>{
|
|
|
28
28
|
};
|
|
29
29
|
const useVirtualizerContextState_unstable = (passedContext)=>{
|
|
30
30
|
const virtualizerContext = useVirtualizerContext_unstable();
|
|
31
|
-
const [_contextIndex, _setContextIndex] =
|
|
32
|
-
const childProgressiveSizes =
|
|
31
|
+
const [_contextIndex, _setContextIndex] = _react.useState(-1);
|
|
32
|
+
const childProgressiveSizes = _react.useRef([]);
|
|
33
33
|
/* We respect any wrapped providers while also ensuring defaults or passed through
|
|
34
34
|
* Order of usage -> Passed Prop -> Provider Context -> Internal State default
|
|
35
|
-
*/ const context =
|
|
35
|
+
*/ const context = _react.useMemo(()=>{
|
|
36
36
|
var _passedContext_contextIndex, _ref, _passedContext_setContextIndex, _ref1;
|
|
37
37
|
return {
|
|
38
38
|
contextIndex: (_ref = (_passedContext_contextIndex = passedContext === null || passedContext === void 0 ? void 0 : passedContext.contextIndex) !== null && _passedContext_contextIndex !== void 0 ? _passedContext_contextIndex : virtualizerContext === null || virtualizerContext === void 0 ? void 0 : virtualizerContext.contextIndex) !== null && _ref !== void 0 ? _ref : _contextIndex,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities/VirtualizerContext/VirtualizerContext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { DynamicVirtualizerContextProps, VirtualizerContextProps } from './types';\
|
|
1
|
+
{"version":3,"sources":["../src/utilities/VirtualizerContext/VirtualizerContext.ts"],"sourcesContent":["import * as React from 'react';\nimport type { DynamicVirtualizerContextProps, VirtualizerContextProps } from './types';\n\nconst VirtualizerContext = React.createContext<VirtualizerContextProps | undefined>(\n undefined,\n) as React.Context<VirtualizerContextProps>;\n\nexport const VirtualizerContextProvider = VirtualizerContext.Provider;\n\nexport const useVirtualizerContext_unstable = () => {\n return React.useContext(VirtualizerContext);\n};\n\nexport const useVirtualizerContextState_unstable = (\n passedContext?: VirtualizerContextProps,\n): DynamicVirtualizerContextProps => {\n const virtualizerContext = useVirtualizerContext_unstable();\n const [_contextIndex, _setContextIndex] = React.useState<number>(-1);\n const childProgressiveSizes = React.useRef<number[]>([]);\n\n /* We respect any wrapped providers while also ensuring defaults or passed through\n * Order of usage -> Passed Prop -> Provider Context -> Internal State default\n */\n const context = React.useMemo(\n () => ({\n contextIndex: passedContext?.contextIndex ?? virtualizerContext?.contextIndex ?? _contextIndex,\n setContextIndex: passedContext?.setContextIndex ?? virtualizerContext?.setContextIndex ?? _setContextIndex,\n childProgressiveSizes,\n }),\n [_contextIndex, passedContext, virtualizerContext],\n );\n\n return context;\n};\n"],"names":["VirtualizerContextProvider","useVirtualizerContextState_unstable","useVirtualizerContext_unstable","VirtualizerContext","React","createContext","undefined","Provider","useContext","passedContext","virtualizerContext","_contextIndex","_setContextIndex","useState","childProgressiveSizes","useRef","context","useMemo","contextIndex","setContextIndex"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAOaA,0BAAAA;eAAAA;;IAMAC,mCAAAA;eAAAA;;IAJAC,8BAAAA;eAAAA;;;;iEATU;AAGvB,MAAMC,mCAAqBC,OAAMC,aAAa,CAC5CC;AAGK,MAAMN,6BAA6BG,mBAAmBI,QAAQ;AAE9D,MAAML,iCAAiC;IAC5C,OAAOE,OAAMI,UAAU,CAACL;AAC1B;AAEO,MAAMF,sCAAsC,CACjDQ;IAEA,MAAMC,qBAAqBR;IAC3B,MAAM,CAACS,eAAeC,iBAAiB,GAAGR,OAAMS,QAAQ,CAAS,CAAC;IAClE,MAAMC,wBAAwBV,OAAMW,MAAM,CAAW,EAAE;IAEvD;;GAEC,GACD,MAAMC,UAAUZ,OAAMa,OAAO,CAC3B;YACgBR,6BAAAA,MACGA,gCAAAA;eAFZ;YACLS,cAAcT,CAAAA,OAAAA,CAAAA,8BAAAA,kBAAAA,QAAAA,kBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,cAAeS,YAAY,AAAZA,MAAY,QAA3BT,gCAAAA,KAAAA,IAAAA,8BAA+BC,uBAAAA,QAAAA,uBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,mBAAoBQ,YAAY,AAAZA,MAAY,QAA/DT,SAAAA,KAAAA,IAAAA,OAAmEE;YACjFQ,iBAAiBV,CAAAA,QAAAA,CAAAA,iCAAAA,kBAAAA,QAAAA,kBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,cAAeU,eAAe,AAAfA,MAAe,QAA9BV,mCAAAA,KAAAA,IAAAA,iCAAkCC,uBAAAA,QAAAA,uBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,mBAAoBS,eAAe,AAAfA,MAAe,QAArEV,UAAAA,KAAAA,IAAAA,QAAyEG;YAC1FE;QACF;IAAA,GACA;QAACH;QAAeF;QAAeC;KAAmB;IAGpD,OAAOM;AACT"}
|
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
VirtualizerContextProvider: function() {
|
|
13
|
+
return _VirtualizerContext.VirtualizerContextProvider;
|
|
14
|
+
},
|
|
15
|
+
useVirtualizerContextState_unstable: function() {
|
|
16
|
+
return _VirtualizerContext.useVirtualizerContextState_unstable;
|
|
17
|
+
},
|
|
18
|
+
useVirtualizerContext_unstable: function() {
|
|
19
|
+
return _VirtualizerContext.useVirtualizerContext_unstable;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _VirtualizerContext = require("./VirtualizerContext");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities/VirtualizerContext/index.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../src/utilities/VirtualizerContext/index.ts"],"sourcesContent":["export {\n VirtualizerContextProvider,\n useVirtualizerContextState_unstable,\n useVirtualizerContext_unstable,\n} from './VirtualizerContext';\nexport type { DynamicVirtualizerContextProps, VirtualizerContextProps } from './types';\n"],"names":["VirtualizerContextProvider","useVirtualizerContextState_unstable","useVirtualizerContext_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IACEA,0BAA0B;eAA1BA,8CAA0B;;IAC1BC,mCAAmC;eAAnCA,uDAAmC;;IACnCC,8BAA8B;eAA9BA,kDAA8B;;;oCACzB"}
|