@fluentui/react-virtualizer 9.0.0-alpha.6 → 9.0.0-alpha.61
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 +552 -2
- package/dist/index.d.ts +240 -30
- package/lib/Hooks.js +0 -1
- package/lib/Hooks.js.map +1 -1
- package/lib/Utilities.js +1 -0
- package/lib/Utilities.js.map +1 -0
- package/lib/Virtualizer.js +0 -1
- package/lib/Virtualizer.js.map +1 -1
- package/lib/VirtualizerScrollView.js +1 -0
- package/lib/VirtualizerScrollView.js.map +1 -0
- package/lib/VirtualizerScrollViewDynamic.js +1 -0
- package/lib/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/Virtualizer/Virtualizer.js +5 -7
- package/lib/components/Virtualizer/Virtualizer.js.map +1 -1
- package/lib/components/Virtualizer/Virtualizer.types.js +1 -2
- package/lib/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib/components/Virtualizer/index.js +1 -2
- package/lib/components/Virtualizer/index.js.map +1 -1
- package/lib/components/Virtualizer/renderVirtualizer.js +21 -16
- package/lib/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib/components/Virtualizer/useVirtualizer.js +434 -355
- package/lib/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib/components/Virtualizer/{useVirtualizerStyles.js → useVirtualizerStyles.styles.js} +3 -3
- package/lib/components/Virtualizer/useVirtualizerStyles.styles.js.map +1 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js +12 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js +1 -0
- package/lib/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
- package/lib/components/VirtualizerScrollView/index.js +5 -0
- package/lib/components/VirtualizerScrollView/index.js.map +1 -0
- package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js +9 -0
- package/lib/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js +76 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js +45 -0
- package/lib/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +12 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/index.js +5 -0
- package/lib/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +9 -0
- package/lib/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +137 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js +45 -0
- package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js.map +1 -0
- package/lib/hooks/hooks.types.js +1 -0
- package/lib/hooks/hooks.types.js.map +1 -0
- package/lib/hooks/index.js +4 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useDynamicVirtualizerMeasure.js +99 -0
- package/lib/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
- package/lib/hooks/useIntersectionObserver.js +108 -40
- package/lib/hooks/useIntersectionObserver.js.map +1 -1
- package/lib/hooks/useMeasureList.js +101 -0
- package/lib/hooks/useMeasureList.js.map +1 -0
- package/lib/hooks/useMutationObserver.js +28 -0
- package/lib/hooks/useMutationObserver.js.map +1 -0
- package/lib/hooks/useResizeObserverRef.js +47 -0
- package/lib/hooks/useResizeObserverRef.js.map +1 -0
- package/lib/hooks/useVirtualizerMeasure.js +44 -0
- package/lib/hooks/useVirtualizerMeasure.js.map +1 -0
- package/lib/index.js +4 -2
- package/lib/index.js.map +1 -1
- package/lib/utilities/ImperativeScrolling/imperativeScrolling.js +32 -0
- package/lib/utilities/ImperativeScrolling/imperativeScrolling.js.map +1 -0
- package/lib/utilities/ImperativeScrolling/imperativeScrolling.types.js +1 -0
- package/lib/utilities/ImperativeScrolling/imperativeScrolling.types.js.map +1 -0
- package/lib/utilities/ImperativeScrolling/imperativeScrollingDynamic.js +45 -0
- package/lib/utilities/ImperativeScrolling/imperativeScrollingDynamic.js.map +1 -0
- package/lib/utilities/ImperativeScrolling/index.js +3 -0
- package/lib/utilities/ImperativeScrolling/index.js.map +1 -0
- package/lib/utilities/VirtualizerContext/VirtualizerContext.js +33 -0
- package/lib/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
- package/lib/utilities/VirtualizerContext/index.js +2 -0
- package/lib/utilities/VirtualizerContext/index.js.map +1 -0
- package/lib/utilities/VirtualizerContext/types.js +3 -0
- package/lib/utilities/VirtualizerContext/types.js.map +1 -0
- package/lib/utilities/createResizeObserverFromDocument.js +13 -0
- package/lib/utilities/createResizeObserverFromDocument.js.map +1 -0
- package/lib/utilities/debounce.js +19 -0
- package/lib/utilities/debounce.js.map +1 -0
- package/lib/utilities/index.js +2 -0
- package/lib/utilities/index.js.map +1 -0
- package/lib-commonjs/Hooks.js +3 -5
- package/lib-commonjs/Hooks.js.map +1 -1
- package/lib-commonjs/Utilities.js +6 -0
- package/lib-commonjs/Utilities.js.map +1 -0
- package/lib-commonjs/Virtualizer.js +3 -5
- package/lib-commonjs/Virtualizer.js.map +1 -1
- package/lib-commonjs/VirtualizerScrollView.js +6 -0
- package/lib-commonjs/VirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/VirtualizerScrollViewDynamic.js +6 -0
- package/lib-commonjs/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/Virtualizer/Virtualizer.js +15 -18
- package/lib-commonjs/components/Virtualizer/Virtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/Virtualizer.types.js +3 -3
- package/lib-commonjs/components/Virtualizer/Virtualizer.types.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/index.js +7 -9
- package/lib-commonjs/components/Virtualizer/index.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js +38 -21
- package/lib-commonjs/components/Virtualizer/renderVirtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js +443 -361
- package/lib-commonjs/components/Virtualizer/useVirtualizer.js.map +1 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.styles.js +122 -0
- package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.styles.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js +21 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js +4 -0
- package/lib-commonjs/components/VirtualizerScrollView/VirtualizerScrollView.types.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/index.js +10 -0
- package/lib-commonjs/components/VirtualizerScrollView/index.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js +19 -0
- package/lib-commonjs/components/VirtualizerScrollView/renderVirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js +86 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollView.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js +69 -0
- package/lib-commonjs/components/VirtualizerScrollView/useVirtualizerScrollViewStyles.styles.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js +21 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js +4 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js +10 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/index.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js +19 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/renderVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js +147 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.js.map +1 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js +69 -0
- package/lib-commonjs/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js.map +1 -0
- package/lib-commonjs/hooks/hooks.types.js +4 -0
- package/lib-commonjs/hooks/hooks.types.js.map +1 -0
- package/lib-commonjs/hooks/index.js +7 -5
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js +107 -0
- package/lib-commonjs/hooks/useDynamicVirtualizerMeasure.js.map +1 -0
- package/lib-commonjs/hooks/useIntersectionObserver.js +120 -53
- package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
- package/lib-commonjs/hooks/useMeasureList.js +108 -0
- package/lib-commonjs/hooks/useMeasureList.js.map +1 -0
- package/lib-commonjs/hooks/useMutationObserver.js +38 -0
- package/lib-commonjs/hooks/useMutationObserver.js.map +1 -0
- package/lib-commonjs/hooks/useResizeObserverRef.js +56 -0
- package/lib-commonjs/hooks/useResizeObserverRef.js.map +1 -0
- package/lib-commonjs/hooks/useVirtualizerMeasure.js +53 -0
- package/lib-commonjs/hooks/useVirtualizerMeasure.js.map +1 -0
- package/lib-commonjs/index.js +82 -41
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.js +42 -0
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.js.map +1 -0
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.types.js +4 -0
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrolling.types.js.map +1 -0
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrollingDynamic.js +55 -0
- package/lib-commonjs/utilities/ImperativeScrolling/imperativeScrollingDynamic.js.map +1 -0
- package/lib-commonjs/utilities/ImperativeScrolling/index.js +8 -0
- package/lib-commonjs/utilities/ImperativeScrolling/index.js.map +1 -0
- package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js +54 -0
- package/lib-commonjs/utilities/VirtualizerContext/VirtualizerContext.js.map +1 -0
- package/lib-commonjs/utilities/VirtualizerContext/index.js +7 -0
- package/lib-commonjs/utilities/VirtualizerContext/index.js.map +1 -0
- package/lib-commonjs/utilities/VirtualizerContext/types.js +6 -0
- package/lib-commonjs/utilities/VirtualizerContext/types.js.map +1 -0
- package/lib-commonjs/utilities/createResizeObserverFromDocument.js +23 -0
- package/lib-commonjs/utilities/createResizeObserverFromDocument.js.map +1 -0
- package/lib-commonjs/utilities/debounce.js +29 -0
- package/lib-commonjs/utilities/debounce.js.map +1 -0
- package/lib-commonjs/utilities/index.js +7 -0
- package/lib-commonjs/utilities/index.js.map +1 -0
- package/package.json +22 -12
- package/CHANGELOG.json +0 -95
- package/lib/components/Virtualizer/useVirtualizerStyles.js.map +0 -1
- package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js +0 -115
- package/lib-commonjs/components/Virtualizer/useVirtualizerStyles.js.map +0 -1
|
@@ -0,0 +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 } from 'react';\nimport { useMeasureList } from '../../hooks/useMeasureList';\nimport type { IndexedResizeCallbackElement } from '../../hooks/useMeasureList';\n\nexport function useVirtualizerScrollViewDynamic_unstable(\n props: VirtualizerScrollViewDynamicProps,\n): VirtualizerScrollViewDynamicState {\n const contextState = useVirtualizerContextState_unstable(props.virtualizerContext);\n const { imperativeRef, axis = 'vertical', reversed, imperativeVirtualizerRef } = props;\n\n let sizeTrackingArray = React.useRef<number[]>(new Array(props.numItems).fill(props.itemSize));\n\n const getChildSizeAuto = React.useCallback(\n (index: number) => {\n if (sizeTrackingArray.current.length <= index || sizeTrackingArray.current[index] <= 0) {\n // Default size for initial state or untracked\n return props.itemSize;\n }\n /* Required to be defined prior to our measure function\n * we use a sizing array ref that we will update post-render\n */\n return sizeTrackingArray.current[index];\n },\n [sizeTrackingArray, props.itemSize],\n );\n\n const { virtualizerLength, bufferItems, bufferSize, scrollRef } = useDynamicVirtualizerMeasure({\n defaultItemSize: props.itemSize,\n direction: props.axis ?? 'vertical',\n getItemSize: props.getItemSize ?? getChildSizeAuto,\n currentIndex: contextState?.contextIndex ?? 0,\n numItems: props.numItems,\n });\n\n // Store the virtualizer length as a ref for imperative ref access\n const virtualizerLengthRef = React.useRef<number>(virtualizerLength);\n if (virtualizerLengthRef.current !== virtualizerLength) {\n virtualizerLengthRef.current = virtualizerLength;\n }\n const scrollViewRef = useMergedRefs(props.scrollViewRef, scrollRef) as React.RefObject<HTMLDivElement>;\n const scrollCallbackRef = React.useRef<null | ((index: number) => void)>(null);\n\n const _imperativeVirtualizerRef = useMergedRefs(React.useRef<VirtualizerDataRef>(null), imperativeVirtualizerRef);\n\n useImperativeHandle(\n imperativeRef,\n () => {\n return {\n scrollTo(index: number, behavior = 'auto', callback: undefined | ((index: number) => void)) {\n scrollCallbackRef.current = callback ?? null;\n if (_imperativeVirtualizerRef.current) {\n const progressiveSizes = _imperativeVirtualizerRef.current.progressiveSizes.current;\n const totalSize =\n progressiveSizes && progressiveSizes?.length > 0\n ? progressiveSizes[Math.max(progressiveSizes.length - 1, 0)]\n : 0;\n\n _imperativeVirtualizerRef.current.setFlaggedIndex(index);\n scrollToItemDynamic({\n index,\n itemSizes: _imperativeVirtualizerRef.current?.nodeSizes,\n totalSize,\n scrollViewRef,\n axis,\n reversed,\n behavior,\n });\n }\n },\n currentIndex: _imperativeVirtualizerRef.current?.currentIndex,\n virtualizerLength: virtualizerLengthRef,\n };\n },\n [axis, scrollViewRef, reversed, _imperativeVirtualizerRef],\n );\n\n const handleRenderedIndex = (index: number) => {\n if (scrollCallbackRef.current) {\n scrollCallbackRef.current(index);\n }\n };\n\n const virtualizerState = useVirtualizer_unstable({\n ...props,\n getItemSize: props.getItemSize ?? getChildSizeAuto,\n virtualizerLength,\n bufferItems,\n bufferSize,\n scrollViewRef,\n virtualizerContext: contextState,\n imperativeVirtualizerRef: _imperativeVirtualizerRef,\n onRenderedFlaggedIndex: handleRenderedIndex,\n });\n\n const measureObject = useMeasureList(\n virtualizerState.virtualizerStartIndex,\n virtualizerLength,\n props.numItems,\n props.itemSize,\n );\n\n if (axis === 'horizontal') {\n sizeTrackingArray = measureObject.widthArray;\n } else {\n sizeTrackingArray = measureObject.heightArray;\n }\n\n if (!props.getItemSize) {\n // Auto-measuring is required\n React.Children.map(virtualizerState.virtualizedChildren, (child, index) => {\n if (React.isValidElement(child)) {\n virtualizerState.virtualizedChildren[index] = (\n <child.type\n {...child.props}\n key={child.key}\n ref={(element: HTMLElement & IndexedResizeCallbackElement) => {\n // If a ref exists in props, call it\n if (typeof child.props.ref === 'function') {\n child.props.ref(element);\n } else if (child.props.ref) {\n child.props.ref.current = element;\n }\n\n if (child.hasOwnProperty('ref')) {\n // We must access this from the child directly, not props (forward ref).\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const localRef = (child as any)?.ref;\n\n if (typeof localRef === 'function') {\n localRef(element);\n } else if (localRef) {\n localRef.current = element;\n }\n }\n\n // Call the auto-measure ref attachment.\n measureObject.createIndexedRef(index)(element);\n }}\n />\n );\n }\n });\n }\n\n return {\n ...virtualizerState,\n components: {\n ...virtualizerState.components,\n container: 'div',\n },\n container: slot.always(props.container, {\n defaultProps: {\n ref: scrollViewRef,\n },\n elementType: 'div',\n }),\n };\n}\n"],"names":["React","slot","useMergedRefs","useVirtualizer_unstable","useDynamicVirtualizerMeasure","useVirtualizerContextState_unstable","scrollToItemDynamic","useImperativeHandle","useMeasureList","useVirtualizerScrollViewDynamic_unstable","props","contextState","virtualizerContext","imperativeRef","axis","reversed","imperativeVirtualizerRef","sizeTrackingArray","useRef","Array","numItems","fill","itemSize","getChildSizeAuto","useCallback","index","current","length","virtualizerLength","bufferItems","bufferSize","scrollRef","defaultItemSize","direction","getItemSize","currentIndex","contextIndex","virtualizerLengthRef","scrollViewRef","scrollCallbackRef","_imperativeVirtualizerRef","scrollTo","behavior","callback","progressiveSizes","totalSize","Math","max","setFlaggedIndex","itemSizes","nodeSizes","handleRenderedIndex","virtualizerState","onRenderedFlaggedIndex","measureObject","virtualizerStartIndex","widthArray","heightArray","Children","map","virtualizedChildren","child","isValidElement","type","key","ref","element","hasOwnProperty","localRef","createIndexedRef","components","container","always","defaultProps","elementType"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,IAAI,EAAEC,a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,CAAC5C,OAAOyC;oBACxC;;YAGN;QACF;IACF;IAEA,OAAO;QACL,GAAGd,gBAAgB;QACnBkB,YAAY;YACV,GAAGlB,iBAAiBkB,UAAU;YAC9BC,WAAW;QACb;QACAA,WAAWtE,KAAKuE,MAAM,CAAC9D,MAAM6D,SAAS,EAAE;YACtCE,cAAc;gBACZR,KAAK3B;YACP;YACAoC,aAAa;QACf;IACF;AACF"}
|
package/lib/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamicStyles.styles.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useVirtualizerStyles_unstable, virtualizerClassNames } from '../Virtualizer/useVirtualizerStyles.styles';
|
|
2
|
+
import { __styles, mergeClasses } from '@griffel/react';
|
|
3
|
+
const virtualizerScrollViewDynamicClassName = 'fui-Virtualizer-Scroll-View-Dynamic';
|
|
4
|
+
export const virtualizerScrollViewDynamicClassNames = {
|
|
5
|
+
...virtualizerClassNames,
|
|
6
|
+
container: `${virtualizerScrollViewDynamicClassName}__container`
|
|
7
|
+
};
|
|
8
|
+
const useStyles = /*#__PURE__*/__styles({
|
|
9
|
+
base: {
|
|
10
|
+
mc9l5x: "f22iagw",
|
|
11
|
+
a9b677: "fly5x3f",
|
|
12
|
+
Bqenvij: "f1l02sjl"
|
|
13
|
+
},
|
|
14
|
+
vertical: {
|
|
15
|
+
Beiy3e4: "f1vx9l62",
|
|
16
|
+
Bmxbyg5: "f5zp4f"
|
|
17
|
+
},
|
|
18
|
+
horizontal: {
|
|
19
|
+
Beiy3e4: "f1063pyq",
|
|
20
|
+
B68tc82: "f1oy3dpc"
|
|
21
|
+
},
|
|
22
|
+
verticalReversed: {
|
|
23
|
+
Beiy3e4: "f1gkdon0",
|
|
24
|
+
Bmxbyg5: "f5zp4f"
|
|
25
|
+
},
|
|
26
|
+
horizontalReversed: {
|
|
27
|
+
Beiy3e4: "f1oztnx0",
|
|
28
|
+
B68tc82: "f1oy3dpc"
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
d: [".f22iagw{display:flex;}", ".fly5x3f{width:100%;}", ".f1l02sjl{height:100%;}", ".f1vx9l62{flex-direction:column;}", ".f5zp4f{overflow-y:auto;}", ".f1063pyq{flex-direction:row;}", ".f1oy3dpc{overflow-x:auto;}", ".f1gkdon0{flex-direction:column-reverse;}", ".f1oztnx0{flex-direction:row-reverse;}"]
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Apply styling to the Virtualizer states
|
|
35
|
+
*/
|
|
36
|
+
export const useVirtualizerScrollViewDynamicStyles_unstable = state => {
|
|
37
|
+
const styles = useStyles();
|
|
38
|
+
// Default virtualizer styles base
|
|
39
|
+
useVirtualizerStyles_unstable(state);
|
|
40
|
+
const containerStyle = state.axis === 'horizontal' ? state.reversed ? styles.horizontalReversed : styles.horizontal : state.reversed ? styles.verticalReversed : styles.vertical;
|
|
41
|
+
// Add container styles
|
|
42
|
+
state.container.className = mergeClasses(virtualizerScrollViewDynamicClassNames.container, styles.base, containerStyle, state.container.className);
|
|
43
|
+
return state;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=useVirtualizerScrollViewDynamicStyles.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useVirtualizerStyles_unstable","virtualizerClassNames","__styles","mergeClasses","virtualizerScrollViewDynamicClassName","virtualizerScrollViewDynamicClassNames","container","useStyles","base","mc9l5x","a9b677","Bqenvij","vertical","Beiy3e4","Bmxbyg5","horizontal","B68tc82","verticalReversed","horizontalReversed","d","useVirtualizerScrollViewDynamicStyles_unstable","state","styles","containerStyle","axis","reversed","className"],"sources":["useVirtualizerScrollViewDynamicStyles.styles.js"],"sourcesContent":["import { useVirtualizerStyles_unstable, virtualizerClassNames } from '../Virtualizer/useVirtualizerStyles.styles';\nimport { makeStyles, mergeClasses } from '@griffel/react';\nconst virtualizerScrollViewDynamicClassName = 'fui-Virtualizer-Scroll-View-Dynamic';\nexport const virtualizerScrollViewDynamicClassNames = {\n ...virtualizerClassNames,\n container: `${virtualizerScrollViewDynamicClassName}__container`\n};\nconst useStyles = makeStyles({\n base: {\n display: 'flex',\n width: '100%',\n height: '100%'\n },\n vertical: {\n flexDirection: 'column',\n overflowY: 'auto'\n },\n horizontal: {\n flexDirection: 'row',\n overflowX: 'auto'\n },\n verticalReversed: {\n flexDirection: 'column-reverse',\n overflowY: 'auto'\n },\n horizontalReversed: {\n flexDirection: 'row-reverse',\n overflowX: 'auto'\n }\n});\n/**\n * Apply styling to the Virtualizer states\n */ export const useVirtualizerScrollViewDynamicStyles_unstable = (state)=>{\n const styles = useStyles();\n // Default virtualizer styles base\n useVirtualizerStyles_unstable(state);\n const containerStyle = state.axis === 'horizontal' ? state.reversed ? styles.horizontalReversed : styles.horizontal : state.reversed ? styles.verticalReversed : styles.vertical;\n // Add container styles\n state.container.className = mergeClasses(virtualizerScrollViewDynamicClassNames.container, styles.base, containerStyle, state.container.className);\n return state;\n};\n"],"mappings":"AAAA,SAASA,6BAA6B,EAAEC,qBAAqB,QAAQ,4CAA4C;AACjH,SAAAC,QAAA,EAAqBC,YAAY,QAAQ,gBAAgB;AACzD,MAAMC,qCAAqC,GAAG,qCAAqC;AACnF,OAAO,MAAMC,sCAAsC,GAAG;EAClD,GAAGJ,qBAAqB;EACxBK,SAAS,EAAG,GAAEF,qCAAsC;AACxD,CAAC;AACD,MAAMG,SAAS,gBAAGL,QAAA;EAAAM,IAAA;IAAAC,MAAA;IAAAC,MAAA;IAAAC,OAAA;EAAA;EAAAC,QAAA;IAAAC,OAAA;IAAAC,OAAA;EAAA;EAAAC,UAAA;IAAAF,OAAA;IAAAG,OAAA;EAAA;EAAAC,gBAAA;IAAAJ,OAAA;IAAAC,OAAA;EAAA;EAAAI,kBAAA;IAAAL,OAAA;IAAAG,OAAA;EAAA;AAAA;EAAAG,CAAA;AAAA,CAsBjB,CAAC;AACF;AACA;AACA;AAAI,OAAO,MAAMC,8CAA8C,GAAIC,KAAK,IAAG;EACvE,MAAMC,MAAM,GAAGf,SAAS,CAAC,CAAC;EAC1B;EACAP,6BAA6B,CAACqB,KAAK,CAAC;EACpC,MAAME,cAAc,GAAGF,KAAK,CAACG,IAAI,KAAK,YAAY,GAAGH,KAAK,CAACI,QAAQ,GAAGH,MAAM,CAACJ,kBAAkB,GAAGI,MAAM,CAACP,UAAU,GAAGM,KAAK,CAACI,QAAQ,GAAGH,MAAM,CAACL,gBAAgB,GAAGK,MAAM,CAACV,QAAQ;EAChL;EACAS,KAAK,CAACf,SAAS,CAACoB,SAAS,GAAGvB,YAAY,CAACE,sCAAsC,CAACC,SAAS,EAAEgB,MAAM,CAACd,IAAI,EAAEe,cAAc,EAAEF,KAAK,CAACf,SAAS,CAACoB,SAAS,CAAC;EAClJ,OAAOL,KAAK;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["hooks.types.ts"],"sourcesContent":["import { MutableRefObject } 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\n/**\n * Additional direct Ref prevents reading old resize entry data\n * Backwards compatible with ResizeObserverCallback if preferred\n */\nexport interface ResizeCallbackWithRef {\n (entries: ResizeObserverEntry[], observer: ResizeObserver, scrollRef?: MutableRefObject<HTMLElement | null>): void;\n}\n"],"names":[],"mappings":"AAAA,WAqBC"}
|
package/lib/hooks/index.js
CHANGED
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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":[],"mappings":"AAAA,cAAc,4BAA4B;AAC1C,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,yBAAyB;AACvC,cAAc,gBAAgB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useResizeObserverRef_unstable } from './useResizeObserverRef';
|
|
4
|
+
import { useRef } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* React hook that measures virtualized space dynamically to ensure optimized virtualization length.
|
|
7
|
+
*/ export const useDynamicVirtualizerMeasure = (virtualizerProps)=>{
|
|
8
|
+
const { defaultItemSize, direction = 'vertical', numItems, getItemSize, currentIndex } = virtualizerProps;
|
|
9
|
+
const indexRef = useRef(currentIndex);
|
|
10
|
+
indexRef.current = currentIndex;
|
|
11
|
+
const [state, setState] = React.useState({
|
|
12
|
+
virtualizerLength: 0,
|
|
13
|
+
virtualizerBufferItems: 0,
|
|
14
|
+
virtualizerBufferSize: 0
|
|
15
|
+
});
|
|
16
|
+
const { virtualizerLength, virtualizerBufferItems, virtualizerBufferSize } = state;
|
|
17
|
+
const container = React.useRef(null);
|
|
18
|
+
const handleScrollResize = React.useCallback((scrollRef)=>{
|
|
19
|
+
if (!(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current)) {
|
|
20
|
+
// Error? ignore?
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (scrollRef.current !== container.current) {
|
|
24
|
+
container.current = scrollRef.current;
|
|
25
|
+
}
|
|
26
|
+
const containerSize = direction === 'vertical' ? scrollRef.current.getBoundingClientRect().height : scrollRef.current.getBoundingClientRect().width;
|
|
27
|
+
let indexSizer = 0;
|
|
28
|
+
let length = 0;
|
|
29
|
+
while(indexSizer <= containerSize && length < numItems){
|
|
30
|
+
const iItemSize = getItemSize(indexRef.current + length);
|
|
31
|
+
// Increment
|
|
32
|
+
indexSizer += iItemSize;
|
|
33
|
+
length++;
|
|
34
|
+
}
|
|
35
|
+
/*
|
|
36
|
+
* Number of items to append at each end, i.e. 'preload' each side before entering view.
|
|
37
|
+
*/ const bufferItems = Math.max(Math.floor(length / 4), 4);
|
|
38
|
+
/*
|
|
39
|
+
* This is how far we deviate into the bufferItems to detect a redraw.
|
|
40
|
+
*/ const bufferSize = Math.max(Math.floor(length / 8 * defaultItemSize), 1);
|
|
41
|
+
const totalLength = length + bufferItems * 2 + 1;
|
|
42
|
+
setState({
|
|
43
|
+
virtualizerLength: totalLength,
|
|
44
|
+
virtualizerBufferSize: bufferSize,
|
|
45
|
+
virtualizerBufferItems: bufferItems
|
|
46
|
+
});
|
|
47
|
+
}, [
|
|
48
|
+
defaultItemSize,
|
|
49
|
+
direction,
|
|
50
|
+
getItemSize,
|
|
51
|
+
numItems
|
|
52
|
+
]);
|
|
53
|
+
const resizeCallback = React.useCallback((_entries, _observer, scrollRef)=>{
|
|
54
|
+
if (scrollRef) {
|
|
55
|
+
handleScrollResize(scrollRef);
|
|
56
|
+
}
|
|
57
|
+
}, [
|
|
58
|
+
handleScrollResize
|
|
59
|
+
]);
|
|
60
|
+
const scrollRef = useResizeObserverRef_unstable(resizeCallback);
|
|
61
|
+
useIsomorphicLayoutEffect(()=>{
|
|
62
|
+
var _container_current, _container_current1;
|
|
63
|
+
if (!container.current) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
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;
|
|
67
|
+
let couldBeSmaller = false;
|
|
68
|
+
let recheckTotal = 0;
|
|
69
|
+
for(let i = currentIndex; i < currentIndex + virtualizerLength; i++){
|
|
70
|
+
const newItemSize = getItemSize(i);
|
|
71
|
+
recheckTotal += newItemSize;
|
|
72
|
+
const newLength = i - currentIndex;
|
|
73
|
+
const bufferItems = Math.max(Math.floor(newLength / 4), 2);
|
|
74
|
+
const totalNewLength = newLength + bufferItems * 2 + 4;
|
|
75
|
+
const compareLengths = totalNewLength < virtualizerLength;
|
|
76
|
+
if (recheckTotal > containerSize && compareLengths) {
|
|
77
|
+
couldBeSmaller = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Check if the render has caused us to need a re-calc of virtualizer length
|
|
82
|
+
if (recheckTotal < containerSize || couldBeSmaller) {
|
|
83
|
+
handleScrollResize(container);
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
getItemSize,
|
|
87
|
+
currentIndex,
|
|
88
|
+
direction,
|
|
89
|
+
virtualizerLength,
|
|
90
|
+
resizeCallback,
|
|
91
|
+
handleScrollResize
|
|
92
|
+
]);
|
|
93
|
+
return {
|
|
94
|
+
virtualizerLength,
|
|
95
|
+
bufferItems: virtualizerBufferItems,
|
|
96
|
+
bufferSize: virtualizerBufferSize,
|
|
97
|
+
scrollRef
|
|
98
|
+
};
|
|
99
|
+
};
|
|
@@ -0,0 +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 _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":["useIsomorphicLayoutEffect","React","useResizeObserverRef_unstable","useRef","useDynamicVirtualizerMeasure","virtualizerProps","defaultItemSize","direction","numItems","getItemSize","currentIndex","indexRef","current","state","setState","useState","virtualizerLength","virtualizerBufferItems","virtualizerBufferSize","container","handleScrollResize","useCallback","scrollRef","containerSize","getBoundingClientRect","height","width","indexSizer","length","iItemSize","bufferItems","Math","max","floor","bufferSize","totalLength","resizeCallback","_entries","_observer","couldBeSmaller","recheckTotal","i","newItemSize","newLength","totalNewLength","compareLengths"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,4BAA4B;AACtE,YAAYC,WAAW,QAAQ;AAE/B,SAASC,6BAA6B,QAAQ,yBAAyB;AACvE,SAASC,MAAM,QAAQ,QAAQ;AAE/B;;CAEC,GACD,OAAO,MAAMC,+BAA+B,CAC1CC;IAOA,MAAM,EAAEC,eAAe,EAAEC,YAAY,UAAU,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGL;IACzF,MAAMM,WAAWR,OAAeO;IAChCC,SAASC,OAAO,GAAGF;IAEnB,MAAM,CAACG,OAAOC,SAAS,GAAGb,MAAMc,QAAQ,CAAC;QACvCC,mBAAmB;QACnBC,wBAAwB;QACxBC,uBAAuB;IACzB;IAEA,MAAM,EAAEF,iBAAiB,EAAEC,sBAAsB,EAA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,UAAUP,OAAO,cAAjBO,yCAAAA,mBAAmBK,qBAAqB,GAAGC,MAAM,IAAG,MACpDN,EAAAA,sBAAAA,UAAUP,OAAO,cAAjBO,0CAAAA,oBAAmBK,qBAAqB,GAAGE,KAAK,IAAG;QAEzD,IAAIa,iBAAiB;QACrB,IAAIC,eAAe;QACnB,IAAK,IAAIC,IAAI/B,cAAc+B,IAAI/B,eAAeM,mBAAmByB,IAAK;YACpE,MAAMC,cAAcjC,YAAYgC;YAChCD,gBAAgBE;YAEhB,MAAMC,YAAYF,IAAI/B;YAEtB,MAAMoB,cAAcC,KAAKC,GAAG,CAACD,KAAKE,KAAK,CAACU,YAAY,IAAI;YACxD,MAAMC,iBAAiBD,YAAYb,cAAc,IAAI;YACrD,MAAMe,iBAAiBD,iBAAiB5B;YAExC,IAAIwB,eAAejB,iBAAiBsB,gBAAgB;gBAClDN,iBAAiB;gBACjB;YACF;QACF;QAEA,4EAA4E;QAC5E,IAAIC,eAAejB,iBAAiBgB,gBAAgB;YAClDnB,mBAAmBD;QACrB;IACF,GAAG;QAACV;QAAaC;QAAcH;QAAWS;QAAmBoB;QAAgBhB;KAAmB;IAEhG,OAAO;QACLJ;QACAc,aAAab;QACbiB,YAAYhB;QACZI;IACF;AACF,EAAE"}
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
4
|
+
const { useCallback, useState, useRef } = React;
|
|
5
|
+
import { useMutationObserver } from './useMutationObserver';
|
|
6
|
+
/**
|
|
7
|
+
* 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.
|
|
8
|
+
* @param ltrRootMargin the margin to be processed and flipped if required
|
|
9
|
+
* @param target target element that will have its current reading direction determined
|
|
10
|
+
* @returns the corrected rootMargin (if it was necessary to correct)
|
|
11
|
+
*/ export const getRTLRootMargin = (ltrRootMargin, target)=>{
|
|
12
|
+
if (target) {
|
|
13
|
+
// get the computed dir for the target element
|
|
14
|
+
const newDir = getComputedStyle(target).direction;
|
|
15
|
+
// If we're in rtl reading direction, we might need to flip the margins on the left/right sides
|
|
16
|
+
if (newDir === 'rtl') {
|
|
17
|
+
let newMargin = ltrRootMargin;
|
|
18
|
+
const splitMargins = ltrRootMargin.split(' ');
|
|
19
|
+
// We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.
|
|
20
|
+
if (splitMargins.length === 4) {
|
|
21
|
+
newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;
|
|
22
|
+
}
|
|
23
|
+
return newMargin;
|
|
24
|
+
} else {
|
|
25
|
+
return ltrRootMargin;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return ltrRootMargin;
|
|
29
|
+
};
|
|
7
30
|
/**
|
|
8
31
|
* React hook that allows easy usage of the browser API IntersectionObserver within React
|
|
9
32
|
* @param callback - A function called when the percentage of the target element is visible crosses a threshold.
|
|
@@ -12,41 +35,86 @@ const {
|
|
|
12
35
|
* enough to trigger a callback).
|
|
13
36
|
* @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to
|
|
14
37
|
* update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
*/ export const useIntersectionObserver = (callback, options)=>{
|
|
39
|
+
const observer = useRef();
|
|
40
|
+
const [observerList, setObserverList] = useState();
|
|
41
|
+
const { targetDocument } = useFluent();
|
|
42
|
+
var _options_rootMargin;
|
|
43
|
+
// set the initial init with corrected margins based on the observed root's calculated reading direction.
|
|
44
|
+
const [observerInit, setObserverInit] = useState(options && {
|
|
45
|
+
...options,
|
|
46
|
+
rootMargin: getRTLRootMargin((_options_rootMargin = options.rootMargin) !== null && _options_rootMargin !== void 0 ? _options_rootMargin : '0px', options.root)
|
|
47
|
+
});
|
|
48
|
+
var _options_rootMargin1;
|
|
49
|
+
// 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.
|
|
50
|
+
const ltrRootMargin = useRef((_options_rootMargin1 = options === null || options === void 0 ? void 0 : options.rootMargin) !== null && _options_rootMargin1 !== void 0 ? _options_rootMargin1 : '0px');
|
|
51
|
+
// Callback function to execute when mutations are observed
|
|
52
|
+
const mutationObserverCallback = useCallback((mutationList)=>{
|
|
53
|
+
for (const mutation of mutationList){
|
|
54
|
+
// Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.
|
|
55
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'dir' && (options === null || options === void 0 ? void 0 : options.root) && mutation.target.contains(options === null || options === void 0 ? void 0 : options.root)) {
|
|
56
|
+
setObserverInit({
|
|
57
|
+
...observerInit,
|
|
58
|
+
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, [
|
|
63
|
+
ltrRootMargin,
|
|
64
|
+
observerInit,
|
|
65
|
+
options === null || options === void 0 ? void 0 : options.root
|
|
66
|
+
]);
|
|
67
|
+
// Mutation observer for dir attribute changes in the document
|
|
68
|
+
useMutationObserver(targetDocument, mutationObserverCallback, {
|
|
69
|
+
attributes: true,
|
|
70
|
+
subtree: true,
|
|
71
|
+
attributeFilter: [
|
|
72
|
+
'dir'
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
// Observer elements in passed in list and clean up previous list
|
|
76
|
+
// This effect is only triggered when observerList is updated
|
|
77
|
+
useIsomorphicLayoutEffect(()=>{
|
|
78
|
+
observer.current = new IntersectionObserver(callback, {
|
|
79
|
+
...observerInit,
|
|
80
|
+
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)
|
|
81
|
+
});
|
|
82
|
+
observer.current = new IntersectionObserver(callback, observerInit);
|
|
83
|
+
// If we have an instance of IO and a list with elements, observer the elements
|
|
84
|
+
if (observer.current && observerList && observerList.length > 0) {
|
|
85
|
+
observerList.forEach((element)=>{
|
|
86
|
+
var _observer_current;
|
|
87
|
+
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(element);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// clean up previous elements being listened to
|
|
91
|
+
return ()=>{
|
|
92
|
+
if (observer.current) {
|
|
93
|
+
observer.current.disconnect();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}, [
|
|
97
|
+
observerList,
|
|
98
|
+
observerInit,
|
|
99
|
+
callback
|
|
100
|
+
]);
|
|
101
|
+
// Do not use internally, we need to track external settings only here
|
|
102
|
+
const setObserverInitExternal = useCallback((newInit)=>{
|
|
103
|
+
var _newInit_rootMargin;
|
|
104
|
+
// Since we know this is coming from consumers, we can store this value as LTR somewhat safely.
|
|
105
|
+
ltrRootMargin.current = (_newInit_rootMargin = newInit === null || newInit === void 0 ? void 0 : newInit.rootMargin) !== null && _newInit_rootMargin !== void 0 ? _newInit_rootMargin : '0px';
|
|
106
|
+
// Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin
|
|
107
|
+
setObserverInit({
|
|
108
|
+
...newInit,
|
|
109
|
+
rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit === null || newInit === void 0 ? void 0 : newInit.root)
|
|
110
|
+
});
|
|
111
|
+
}, [
|
|
112
|
+
ltrRootMargin,
|
|
113
|
+
setObserverInit
|
|
114
|
+
]);
|
|
115
|
+
return {
|
|
116
|
+
setObserverList,
|
|
117
|
+
setObserverInit: setObserverInitExternal,
|
|
118
|
+
observer
|
|
44
119
|
};
|
|
45
|
-
}, [observerList, observerInit, callback]);
|
|
46
|
-
return {
|
|
47
|
-
setObserverList,
|
|
48
|
-
setObserverInit,
|
|
49
|
-
observer
|
|
50
|
-
};
|
|
51
120
|
};
|
|
52
|
-
//# sourceMappingURL=useIntersectionObserver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["useIntersectionObserver.ts"],"sourcesContent":["import type { Dispatch, MutableRefObject, SetStateAction } from 'react';\nimport * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */\nexport const getRTLRootMargin = (ltrRootMargin: string, target?: Element | Document | null | undefined): string => {\n if (target) {\n // get the computed dir for the target element\n const newDir = getComputedStyle(target as Element).direction;\n\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n\n return ltrRootMargin;\n};\n\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */\n\nexport const useIntersectionObserver = (\n callback: IntersectionObserverCallback,\n options?: IntersectionObserverInit,\n): {\n setObserverList: Dispatch<SetStateAction<Element[] | undefined>>;\n setObserverInit: (newInit: IntersectionObserverInit | undefined) => void;\n observer: MutableRefObject<IntersectionObserver | undefined>;\n} => {\n const observer = useRef<IntersectionObserver>();\n const [observerList, setObserverList] = useState<Element[]>();\n const { targetDocument } = useFluent();\n\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState<IntersectionObserverInit | undefined>(\n options && {\n ...options,\n rootMargin: getRTLRootMargin(options.rootMargin ?? '0px', options.root as Element),\n },\n );\n\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef<string>(options?.rootMargin ?? '0px');\n\n // Callback function to execute when mutations are observed\n const mutationObserverCallback: MutationCallback = useCallback(\n mutationList => {\n for (const mutation of mutationList) {\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (\n mutation.type === 'attributes' &&\n mutation.attributeName === 'dir' &&\n options?.root &&\n mutation.target.contains(options?.root)\n ) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root),\n });\n }\n }\n },\n [ltrRootMargin, observerInit, options?.root],\n );\n\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: ['dir'],\n });\n\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(() => {\n observer.current = new IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit?.root),\n });\n\n observer.current = new IntersectionObserver(callback, observerInit);\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]);\n\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback(\n (newInit: IntersectionObserverInit | undefined) => {\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = newInit?.rootMargin ?? '0px';\n\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit?.root as Element),\n });\n },\n [ltrRootMargin, setObserverInit],\n );\n\n return { setObserverList, setObserverInit: setObserverInitExternal, observer };\n};\n"],"names":["React","useIsomorphicLayoutEffect","useFluent_unstable","useFluent","useCallback","useState","useRef","useMutationObserver","getRTLRootMargin","ltrRootMargin","target","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","useIntersectionObserver","callback","options","observer","observerList","setObserverList","targetDocument","observerInit","setObserverInit","rootMargin","root","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","attributes","subtree","attributeFilter","IntersectionObserver","forEach","element","observe","disconnect","setObserverInitExternal","newInit"],"mappings":"AACA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ,4BAA4B;AACtE,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAElF,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGN;AAC1C,SAASO,mBAAmB,QAAQ,wBAAwB;AAE5D;;;;;CAKC,GACD,OAAO,MAAMC,mBAAmB,CAACC,eAAuBC;IACtD,IAAIA,QAAQ;QACV,8C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AeiB;KAAgB;IAGlC,OAAO;QAAEH;QAAiBG,iBAAiBkB;QAAyBvB;IAAS;AAC/E,EAAE"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
3
|
+
/**
|
|
4
|
+
* Provides a way of automating size in the virtualizer
|
|
5
|
+
* Returns
|
|
6
|
+
* `width` - element width ref (0 by default),
|
|
7
|
+
* `height` - element height ref (0 by default),
|
|
8
|
+
* `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure
|
|
9
|
+
*/ export function useMeasureList(currentIndex, refLength, totalLength, defaultItemSize) {
|
|
10
|
+
const widthArray = React.useRef(new Array(totalLength).fill(defaultItemSize));
|
|
11
|
+
const heightArray = React.useRef(new Array(totalLength).fill(defaultItemSize));
|
|
12
|
+
const refArray = React.useRef([]);
|
|
13
|
+
const { targetDocument } = useFluent();
|
|
14
|
+
// the handler for resize observer
|
|
15
|
+
const handleIndexUpdate = React.useCallback((index)=>{
|
|
16
|
+
var _refArray_current_index;
|
|
17
|
+
const boundClientRect = (_refArray_current_index = refArray.current[index]) === null || _refArray_current_index === void 0 ? void 0 : _refArray_current_index.getBoundingClientRect();
|
|
18
|
+
const containerWidth = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.width;
|
|
19
|
+
widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;
|
|
20
|
+
const containerHeight = boundClientRect === null || boundClientRect === void 0 ? void 0 : boundClientRect.height;
|
|
21
|
+
heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;
|
|
22
|
+
}, [
|
|
23
|
+
currentIndex,
|
|
24
|
+
defaultItemSize
|
|
25
|
+
]);
|
|
26
|
+
const handleElementResizeCallback = (entries)=>{
|
|
27
|
+
for (const entry of entries){
|
|
28
|
+
const target = entry.target;
|
|
29
|
+
// Call the elements own resize handler (indexed)
|
|
30
|
+
target.handleResize();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
React.useEffect(()=>{
|
|
34
|
+
widthArray.current = new Array(totalLength).fill(defaultItemSize);
|
|
35
|
+
heightArray.current = new Array(totalLength).fill(defaultItemSize);
|
|
36
|
+
}, [
|
|
37
|
+
defaultItemSize,
|
|
38
|
+
totalLength
|
|
39
|
+
]);
|
|
40
|
+
// Keep the reference of ResizeObserver as a ref, as it should live through renders
|
|
41
|
+
const resizeObserver = React.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));
|
|
42
|
+
/* createIndexedRef provides a dynamic function to create an undefined number of refs at render time
|
|
43
|
+
* these refs then provide an indexed callback via attaching 'handleResize' to the element itself
|
|
44
|
+
* this function is then called on resize by handleElementResize and relies on indexing
|
|
45
|
+
* to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.
|
|
46
|
+
*/ const createIndexedRef = React.useCallback((index)=>{
|
|
47
|
+
const measureElementRef = (el)=>{
|
|
48
|
+
if (!targetDocument || !resizeObserver.current) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (el) {
|
|
52
|
+
el.handleResize = ()=>{
|
|
53
|
+
handleIndexUpdate(index);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// cleanup previous container
|
|
57
|
+
if (refArray.current[index] !== undefined && refArray.current[index] !== null) {
|
|
58
|
+
resizeObserver.current.unobserve(refArray.current[index]);
|
|
59
|
+
}
|
|
60
|
+
refArray.current[index] = undefined;
|
|
61
|
+
if (el) {
|
|
62
|
+
refArray.current[index] = el;
|
|
63
|
+
resizeObserver.current.observe(el);
|
|
64
|
+
handleIndexUpdate(index);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return measureElementRef;
|
|
68
|
+
}, [
|
|
69
|
+
handleIndexUpdate,
|
|
70
|
+
resizeObserver,
|
|
71
|
+
targetDocument
|
|
72
|
+
]);
|
|
73
|
+
React.useEffect(()=>{
|
|
74
|
+
const _resizeObserver = resizeObserver;
|
|
75
|
+
return ()=>{
|
|
76
|
+
var _resizeObserver_current;
|
|
77
|
+
return (_resizeObserver_current = _resizeObserver.current) === null || _resizeObserver_current === void 0 ? void 0 : _resizeObserver_current.disconnect();
|
|
78
|
+
};
|
|
79
|
+
}, [
|
|
80
|
+
resizeObserver
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
widthArray,
|
|
84
|
+
heightArray,
|
|
85
|
+
createIndexedRef,
|
|
86
|
+
refArray
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar
|
|
91
|
+
* A utility method that creates a ResizeObserver from a target document
|
|
92
|
+
* @param targetDocument - document to use to create the ResizeObserver
|
|
93
|
+
* @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback
|
|
94
|
+
* @returns a ResizeObserver instance or null if the global does not exist on the document
|
|
95
|
+
*/ export function createResizeObserverFromDocument(targetDocument, callback) {
|
|
96
|
+
var _targetDocument_defaultView;
|
|
97
|
+
if (!(targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.ResizeObserver)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return new targetDocument.defaultView.ResizeObserver(callback);
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useMeasureList.ts"],"sourcesContent":["import * as React from 'react';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\n\nexport interface IndexedResizeCallbackElement {\n handleResize: () => void;\n}\n/**\n * Provides a way of automating size in the virtualizer\n * Returns\n * `width` - element width ref (0 by default),\n * `height` - element height ref (0 by default),\n * `measureElementRef` - a ref function to be passed as `ref` to the element you want to measure\n */\nexport function useMeasureList<\n TElement extends HTMLElement & IndexedResizeCallbackElement = HTMLElement & IndexedResizeCallbackElement,\n>(currentIndex: number, refLength: number, totalLength: number, defaultItemSize: number) {\n const widthArray = React.useRef(new Array(totalLength).fill(defaultItemSize));\n const heightArray = React.useRef(new Array(totalLength).fill(defaultItemSize));\n\n const refArray = React.useRef<Array<TElement | undefined | null>>([]);\n const { targetDocument } = useFluent();\n\n // the handler for resize observer\n const handleIndexUpdate = React.useCallback(\n (index: number) => {\n const boundClientRect = refArray.current[index]?.getBoundingClientRect();\n const containerWidth = boundClientRect?.width;\n widthArray.current[currentIndex + index] = containerWidth || defaultItemSize;\n\n const containerHeight = boundClientRect?.height;\n heightArray.current[currentIndex + index] = containerHeight || defaultItemSize;\n },\n [currentIndex, defaultItemSize],\n );\n\n const handleElementResizeCallback = (entries: ResizeObserverEntry[]) => {\n for (const entry of entries) {\n const target = entry.target as TElement;\n // Call the elements own resize handler (indexed)\n target.handleResize();\n }\n };\n\n React.useEffect(() => {\n widthArray.current = new Array(totalLength).fill(defaultItemSize);\n heightArray.current = new Array(totalLength).fill(defaultItemSize);\n }, [defaultItemSize, totalLength]);\n\n // Keep the reference of ResizeObserver as a ref, as it should live through renders\n const resizeObserver = React.useRef(createResizeObserverFromDocument(targetDocument, handleElementResizeCallback));\n\n /* createIndexedRef provides a dynamic function to create an undefined number of refs at render time\n * these refs then provide an indexed callback via attaching 'handleResize' to the element itself\n * this function is then called on resize by handleElementResize and relies on indexing\n * to track continuous sizes throughout renders while releasing all virtualized element refs each render cycle.\n */\n const createIndexedRef = React.useCallback(\n (index: number) => {\n const measureElementRef = (el: TElement) => {\n if (!targetDocument || !resizeObserver.current) {\n return;\n }\n\n if (el) {\n el.handleResize = () => {\n handleIndexUpdate(index);\n };\n }\n\n // cleanup previous container\n if (refArray.current[index] !== undefined && refArray.current[index] !== null) {\n resizeObserver.current.unobserve(refArray.current[index]!);\n }\n\n refArray.current[index] = undefined;\n if (el) {\n refArray.current[index] = el;\n resizeObserver.current.observe(el);\n handleIndexUpdate(index);\n }\n };\n\n return measureElementRef;\n },\n [handleIndexUpdate, resizeObserver, targetDocument],\n );\n\n React.useEffect(() => {\n const _resizeObserver = resizeObserver;\n return () => _resizeObserver.current?.disconnect();\n }, [resizeObserver]);\n\n return { widthArray, heightArray, createIndexedRef, refArray };\n}\n\n/**\n * FIXME - TS 3.8/3.9 don't have ResizeObserver types by default, move this to a shared utility once we bump the minbar\n * A utility method that creates a ResizeObserver from a target document\n * @param targetDocument - document to use to create the ResizeObserver\n * @param callback - https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback\n * @returns a ResizeObserver instance or null if the global does not exist on the document\n */\nexport function createResizeObserverFromDocument(\n targetDocument: Document | null | undefined,\n callback: ResizeObserverCallback,\n) {\n if (!targetDocument?.defaultView?.ResizeObserver) {\n return null;\n }\n\n return new targetDocument.defaultView.ResizeObserver(callback);\n}\n"],"names":["React","useFluent_unstable","useFluent","useMeasureList","currentIndex","refLength","totalLength","defaultItemSize","widthArray","useRef","Array","fill","heightArray","refArray","targetDocument","handleIndexUpdate","useCallback","index","boundClientRect","current","getBoundingClientRect","containerWidth","width","containerHeight","height","handleElementResizeCallback","entries","entry","target","handleResize","useEffect","resizeObserver","createResizeObserverFromDocument","createIndexedRef","measureElementRef","el","undefined","unobserve","observe","_resizeObserver","disconnect","callback","defaultView","ResizeObserver"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAKlF;;;;;;CAMC,GACD,OAAO,SAASC,eAEdC,YAAoB,EAAEC,SAAiB,EAAEC,WAAmB,EAAEC,eAAuB;IACrF,MAAMC,aAAaR,MAAMS,MAAM,CAAC,IAAIC,MAAMJ,aAAaK,IAAI,CAACJ;IAC5D,MAAMK,cAAcZ,MAAMS,MAAM,CAAC,IAAIC,MAAMJ,aAAaK,IAAI,CAACJ;IAE7D,MAAMM,WAAWb,MAAMS,MAAM,CAAqC,EAAE;IACpE,MAAM,EAAEK,cAAc,EAAE,GAAGZ;IAE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O,CAACF,MAAM;YAC1D;YAEAJ,SAASM,OAAO,CAACF,MAAM,GAAGmB;YAC1B,IAAID,IAAI;gBACNtB,SAASM,OAAO,CAACF,MAAM,GAAGkB;gBAC1BJ,eAAeZ,OAAO,CAACmB,OAAO,CAACH;gBAC/BpB,kBAAkBE;YACpB;QACF;QAEA,OAAOiB;IACT,GACA;QAACnB;QAAmBgB;QAAgBjB;KAAe;IAGrDd,MAAM8B,SAAS,CAAC;QACd,MAAMS,kBAAkBR;QACxB,OAAO;gBAAMQ;oBAAAA,0BAAAA,gBAAgBpB,OAAO,cAAvBoB,8CAAAA,wBAAyBC,UAAU;;IAClD,GAAG;QAACT;KAAe;IAEnB,OAAO;QAAEvB;QAAYI;QAAaqB;QAAkBpB;IAAS;AAC/D;AAEA;;;;;;CAMC,GACD,OAAO,SAASmB,iCACdlB,cAA2C,EAC3C2B,QAAgC;QAE3B3B;IAAL,IAAI,EAACA,2BAAAA,sCAAAA,8BAAAA,eAAgB4B,WAAW,cAA3B5B,kDAAAA,4BAA6B6B,cAAc,GAAE;QAChD,OAAO;IACT;IAEA,OAAO,IAAI7B,eAAe4B,WAAW,CAACC,cAAc,CAACF;AACvD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const { useRef, useEffect } = React;
|
|
3
|
+
export const useMutationObserver = (target, callback, options)=>{
|
|
4
|
+
const observer = useRef();
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
// Create an observer instance linked to the callback function
|
|
7
|
+
observer.current = new MutationObserver(callback);
|
|
8
|
+
}, [
|
|
9
|
+
callback
|
|
10
|
+
]);
|
|
11
|
+
useEffect(()=>{
|
|
12
|
+
if (target) {
|
|
13
|
+
var // Start observing the target node for configured mutations
|
|
14
|
+
_observer_current;
|
|
15
|
+
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(target, options);
|
|
16
|
+
}
|
|
17
|
+
return ()=>{
|
|
18
|
+
var _observer_current;
|
|
19
|
+
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.disconnect();
|
|
20
|
+
};
|
|
21
|
+
}, [
|
|
22
|
+
target,
|
|
23
|
+
options
|
|
24
|
+
]);
|
|
25
|
+
return {
|
|
26
|
+
observer
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useMutationObserver.ts"],"sourcesContent":["import type { MutableRefObject } from 'react';\nimport * as React from 'react';\n\nconst { useRef, useEffect } = React;\n\nexport const useMutationObserver = (\n target: Element | Document | undefined,\n callback: MutationCallback,\n options?: MutationObserverInit,\n): {\n observer: MutableRefObject<MutationObserver | undefined>;\n} => {\n const observer = useRef<MutationObserver>();\n\n useEffect(() => {\n // Create an observer instance linked to the callback function\n observer.current = new MutationObserver(callback);\n }, [callback]);\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":["React","useRef","useEffect","useMutationObserver","target","callback","options","observer","current","MutationObserver","observe","disconnect"],"mappings":"AACA,YAAYA,WAAW,QAAQ;AAE/B,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGF;AAE9B,OAAO,MAAMG,sBAAsB,CACjCC,QACAC,UACAC;IAIA,MAAMC,WAAWN;IAEjBC,UAAU;QACR,8DAA8D;QAC9DK,SAASC,OAAO,GAAG,IAAIC,iBAAiBJ;IAC1C,GAAG;QAACA;KAAS;IAEbH,UAAU;QACR,IAAIE,QAAQ;gBACV,2DAA2D;YAC3DG;aAAAA,oBAAAA,SAASC,OAAO,cAAhBD,wCAAAA,kBAAkBG,OAAO,CAACN,QAAQE;QACpC;QAEA,OAAO;gBACLC;aAAAA,oBAAAA,SAASC,OAAO,cAAhBD,wCAAAA,kBAAkBI,UAAU;QAC9B;IACF,GAAG;QAACP;QAAQE;KAAQ;IAEpB,OAAO;QAAEC;IAAS;AACpB,EAAE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
|
|
3
|
+
import { debounce } from '../utilities/debounce';
|
|
4
|
+
import { createResizeObserverFromDocument } from '../utilities/createResizeObserverFromDocument';
|
|
5
|
+
/**
|
|
6
|
+
* useResizeObserverRef_unstable simplifies resize observer connection and ensures debounce/cleanup
|
|
7
|
+
*/ export const useResizeObserverRef_unstable = (resizeCallback)=>{
|
|
8
|
+
const { targetDocument } = useFluent();
|
|
9
|
+
const container = React.useRef(null);
|
|
10
|
+
// the handler for resize observer
|
|
11
|
+
const handleResize = debounce((entries, observer)=>{
|
|
12
|
+
resizeCallback(entries, observer, container);
|
|
13
|
+
});
|
|
14
|
+
// Keep the reference of ResizeObserver in the state, as it should live through renders
|
|
15
|
+
const [resizeObserver, setResizeObserver] = React.useState(()=>createResizeObserverFromDocument(targetDocument, handleResize));
|
|
16
|
+
React.useEffect(()=>{
|
|
17
|
+
// Update our state when resizeCallback changes
|
|
18
|
+
container.current = null;
|
|
19
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
20
|
+
setResizeObserver(()=>createResizeObserverFromDocument(targetDocument, handleResize));
|
|
21
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
22
|
+
}, [
|
|
23
|
+
resizeCallback,
|
|
24
|
+
targetDocument
|
|
25
|
+
]);
|
|
26
|
+
React.useEffect(()=>{
|
|
27
|
+
return ()=>{
|
|
28
|
+
container.current = null;
|
|
29
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
30
|
+
};
|
|
31
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
+
}, []);
|
|
33
|
+
const scrollRef = React.useCallback((instance)=>{
|
|
34
|
+
if (container.current !== instance) {
|
|
35
|
+
if (container.current) {
|
|
36
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.unobserve(container.current);
|
|
37
|
+
}
|
|
38
|
+
container.current = instance;
|
|
39
|
+
if (container.current) {
|
|
40
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.observe(container.current);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, [
|
|
44
|
+
resizeObserver
|
|
45
|
+
]);
|
|
46
|
+
return scrollRef;
|
|
47
|
+
};
|