@fluentui/react-virtualizer 9.0.0-alpha.56 → 9.0.0-alpha.58
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 +20 -2
- package/dist/index.d.ts +1 -1
- package/lib/hooks/useIntersectionObserver.js +80 -3
- package/lib/hooks/useIntersectionObserver.js.map +1 -1
- package/lib/hooks/useMutationObserver.js +28 -0
- package/lib/hooks/useMutationObserver.js.map +1 -0
- package/lib-commonjs/hooks/useIntersectionObserver.js +86 -6
- package/lib-commonjs/hooks/useIntersectionObserver.js.map +1 -1
- package/lib-commonjs/hooks/useMutationObserver.js +38 -0
- package/lib-commonjs/hooks/useMutationObserver.js.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-virtualizer
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 20 Nov 2023 09:51:22 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.0.0-alpha.58](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.58)
|
|
8
|
+
|
|
9
|
+
Mon, 20 Nov 2023 09:51:22 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.57..@fluentui/react-virtualizer_v9.0.0-alpha.58)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
- Bump @fluentui/react-shared-contexts to v9.13.0 ([PR #29878](https://github.com/microsoft/fluentui/pull/29878) by beachball)
|
|
15
|
+
|
|
16
|
+
## [9.0.0-alpha.57](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.57)
|
|
17
|
+
|
|
18
|
+
Fri, 10 Nov 2023 13:46:33 GMT
|
|
19
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.56..@fluentui/react-virtualizer_v9.0.0-alpha.57)
|
|
20
|
+
|
|
21
|
+
### Changes
|
|
22
|
+
|
|
23
|
+
- feat: Ensure IO handles RTL margin and mutations ([PR #29501](https://github.com/microsoft/fluentui/pull/29501) by mifraser@microsoft.com)
|
|
24
|
+
|
|
7
25
|
## [9.0.0-alpha.56](https://github.com/microsoft/fluentui/tree/@fluentui/react-virtualizer_v9.0.0-alpha.56)
|
|
8
26
|
|
|
9
|
-
Thu, 09 Nov 2023 17:
|
|
27
|
+
Thu, 09 Nov 2023 17:29:48 GMT
|
|
10
28
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-virtualizer_v9.0.0-alpha.55..@fluentui/react-virtualizer_v9.0.0-alpha.56)
|
|
11
29
|
|
|
12
30
|
### Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export declare const useDynamicVirtualizerMeasure: <TElement extends HTMLElement
|
|
|
74
74
|
*/
|
|
75
75
|
export declare const useIntersectionObserver: (callback: IntersectionObserverCallback, options?: IntersectionObserverInit) => {
|
|
76
76
|
setObserverList: Dispatch<SetStateAction<Element[] | undefined>>;
|
|
77
|
-
setObserverInit:
|
|
77
|
+
setObserverInit: (newInit: IntersectionObserverInit | undefined) => void;
|
|
78
78
|
observer: MutableRefObject<IntersectionObserver | undefined>;
|
|
79
79
|
};
|
|
80
80
|
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';
|
|
3
|
-
|
|
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
|
+
};
|
|
4
30
|
/**
|
|
5
31
|
* React hook that allows easy usage of the browser API IntersectionObserver within React
|
|
6
32
|
* @param callback - A function called when the percentage of the target element is visible crosses a threshold.
|
|
@@ -12,10 +38,47 @@ const { useState, useRef } = React;
|
|
|
12
38
|
*/ export const useIntersectionObserver = (callback, options)=>{
|
|
13
39
|
const observer = useRef();
|
|
14
40
|
const [observerList, setObserverList] = useState();
|
|
15
|
-
const
|
|
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
|
+
});
|
|
16
75
|
// Observer elements in passed in list and clean up previous list
|
|
17
76
|
// This effect is only triggered when observerList is updated
|
|
18
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
|
+
});
|
|
19
82
|
observer.current = new IntersectionObserver(callback, observerInit);
|
|
20
83
|
// If we have an instance of IO and a list with elements, observer the elements
|
|
21
84
|
if (observer.current && observerList && observerList.length > 0) {
|
|
@@ -35,9 +98,23 @@ const { useState, useRef } = React;
|
|
|
35
98
|
observerInit,
|
|
36
99
|
callback
|
|
37
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
|
+
]);
|
|
38
115
|
return {
|
|
39
116
|
setObserverList,
|
|
40
|
-
setObserverInit,
|
|
117
|
+
setObserverInit: setObserverInitExternal,
|
|
41
118
|
observer
|
|
42
119
|
};
|
|
43
120
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useIntersectionObserver.ts"],"sourcesContent":["import type { Dispatch, MutableRefObject, SetStateAction } from 'react';\nimport * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\n\nconst { useState, useRef } = React;\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:
|
|
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,8CAA8C;QAC9C,MAAMC,SAASC,iBAAiBF,QAAmBG,SAAS;QAE5D,+FAA+F;QAC/F,IAAIF,WAAW,OAAO;YACpB,IAAIG,YAAYL;YAChB,MAAMM,eAAeN,cAAcO,KAAK,CAAC;YAEzC,2GAA2G;YAC3G,IAAID,aAAaE,MAAM,KAAK,GAAG;gBAC7BH,YAAY,CAAC,EAAEC,YA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C5DO,YAAY;QACZC,SAAS;QACTC,iBAAiB;YAAC;SAAM;IAC1B;IAEA,iEAAiE;IACjE,6DAA6D;IAC7DrC,0BAA0B;QACxBoB,SAASc,OAAO,GAAG,IAAII,qBAAqBpB,UAAU;YACpD,GAAGM,YAAY;YACfE,YAAYnB,iBAAiBC,cAAc0B,OAAO,EAAEV,yBAAAA,mCAAAA,aAAcG,IAAI;QACxE;QAEAP,SAASc,OAAO,GAAG,IAAII,qBAAqBpB,UAAUM;QAEtD,+EAA+E;QAC/E,IAAIJ,SAASc,OAAO,IAAIb,gBAAgBA,aAAaL,MAAM,GAAG,GAAG;YAC/DK,aAAakB,OAAO,CAACC,CAAAA;oBACnBpB;iBAAAA,oBAAAA,SAASc,OAAO,cAAhBd,wCAAAA,kBAAkBqB,OAAO,CAACD;YAC5B;QACF;QAEA,+CAA+C;QAC/C,OAAO;YACL,IAAIpB,SAASc,OAAO,EAAE;gBACpBd,SAASc,OAAO,CAACQ,UAAU;YAC7B;QACF;IACF,GAAG;QAACrB;QAAcG;QAAcN;KAAS;IAEzC,sEAAsE;IACtE,MAAMyB,0BAA0BxC,YAC9B,CAACyC;YAEyBA;QADxB,+FAA+F;QAC/FpC,cAAc0B,OAAO,GAAGU,CAAAA,sBAAAA,oBAAAA,8BAAAA,QAASlB,UAAU,cAAnBkB,iCAAAA,sBAAuB;QAE/C,iHAAiH;QACjHnB,gBAAgB;YACd,GAAGmB,OAAO;YACVlB,YAAYnB,iBAAiBC,cAAc0B,OAAO,EAAEU,oBAAAA,8BAAAA,QAASjB,IAAI;QACnE;IACF,GACA;QAACnB;QAAeiB;KAAgB;IAGlC,OAAO;QAAEH;QAAiBG,iBAAiBkB;QAAyBvB;IAAS;AAC/E,EAAE"}
|
|
@@ -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"}
|
|
@@ -2,23 +2,89 @@
|
|
|
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
|
+
getRTLRootMargin: function() {
|
|
13
|
+
return getRTLRootMargin;
|
|
14
|
+
},
|
|
15
|
+
useIntersectionObserver: function() {
|
|
8
16
|
return useIntersectionObserver;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
11
19
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
20
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
21
|
const _reactutilities = require("@fluentui/react-utilities");
|
|
14
|
-
const
|
|
22
|
+
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
|
|
23
|
+
const _useMutationObserver = require("./useMutationObserver");
|
|
24
|
+
const { useCallback, useState, useRef } = _react;
|
|
25
|
+
const getRTLRootMargin = (ltrRootMargin, target)=>{
|
|
26
|
+
if (target) {
|
|
27
|
+
// get the computed dir for the target element
|
|
28
|
+
const newDir = getComputedStyle(target).direction;
|
|
29
|
+
// If we're in rtl reading direction, we might need to flip the margins on the left/right sides
|
|
30
|
+
if (newDir === 'rtl') {
|
|
31
|
+
let newMargin = ltrRootMargin;
|
|
32
|
+
const splitMargins = ltrRootMargin.split(' ');
|
|
33
|
+
// We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.
|
|
34
|
+
if (splitMargins.length === 4) {
|
|
35
|
+
newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;
|
|
36
|
+
}
|
|
37
|
+
return newMargin;
|
|
38
|
+
} else {
|
|
39
|
+
return ltrRootMargin;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return ltrRootMargin;
|
|
43
|
+
};
|
|
15
44
|
const useIntersectionObserver = (callback, options)=>{
|
|
16
45
|
const observer = useRef();
|
|
17
46
|
const [observerList, setObserverList] = useState();
|
|
18
|
-
const
|
|
47
|
+
const { targetDocument } = (0, _reactsharedcontexts.useFluent_unstable)();
|
|
48
|
+
var _options_rootMargin;
|
|
49
|
+
// set the initial init with corrected margins based on the observed root's calculated reading direction.
|
|
50
|
+
const [observerInit, setObserverInit] = useState(options && {
|
|
51
|
+
...options,
|
|
52
|
+
rootMargin: getRTLRootMargin((_options_rootMargin = options.rootMargin) !== null && _options_rootMargin !== void 0 ? _options_rootMargin : '0px', options.root)
|
|
53
|
+
});
|
|
54
|
+
var _options_rootMargin1;
|
|
55
|
+
// 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.
|
|
56
|
+
const ltrRootMargin = useRef((_options_rootMargin1 = options === null || options === void 0 ? void 0 : options.rootMargin) !== null && _options_rootMargin1 !== void 0 ? _options_rootMargin1 : '0px');
|
|
57
|
+
// Callback function to execute when mutations are observed
|
|
58
|
+
const mutationObserverCallback = useCallback((mutationList)=>{
|
|
59
|
+
for (const mutation of mutationList){
|
|
60
|
+
// Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.
|
|
61
|
+
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)) {
|
|
62
|
+
setObserverInit({
|
|
63
|
+
...observerInit,
|
|
64
|
+
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, [
|
|
69
|
+
ltrRootMargin,
|
|
70
|
+
observerInit,
|
|
71
|
+
options === null || options === void 0 ? void 0 : options.root
|
|
72
|
+
]);
|
|
73
|
+
// Mutation observer for dir attribute changes in the document
|
|
74
|
+
(0, _useMutationObserver.useMutationObserver)(targetDocument, mutationObserverCallback, {
|
|
75
|
+
attributes: true,
|
|
76
|
+
subtree: true,
|
|
77
|
+
attributeFilter: [
|
|
78
|
+
'dir'
|
|
79
|
+
]
|
|
80
|
+
});
|
|
19
81
|
// Observer elements in passed in list and clean up previous list
|
|
20
82
|
// This effect is only triggered when observerList is updated
|
|
21
83
|
(0, _reactutilities.useIsomorphicLayoutEffect)(()=>{
|
|
84
|
+
observer.current = new IntersectionObserver(callback, {
|
|
85
|
+
...observerInit,
|
|
86
|
+
rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)
|
|
87
|
+
});
|
|
22
88
|
observer.current = new IntersectionObserver(callback, observerInit);
|
|
23
89
|
// If we have an instance of IO and a list with elements, observer the elements
|
|
24
90
|
if (observer.current && observerList && observerList.length > 0) {
|
|
@@ -38,9 +104,23 @@ const useIntersectionObserver = (callback, options)=>{
|
|
|
38
104
|
observerInit,
|
|
39
105
|
callback
|
|
40
106
|
]);
|
|
107
|
+
// Do not use internally, we need to track external settings only here
|
|
108
|
+
const setObserverInitExternal = useCallback((newInit)=>{
|
|
109
|
+
var _newInit_rootMargin;
|
|
110
|
+
// Since we know this is coming from consumers, we can store this value as LTR somewhat safely.
|
|
111
|
+
ltrRootMargin.current = (_newInit_rootMargin = newInit === null || newInit === void 0 ? void 0 : newInit.rootMargin) !== null && _newInit_rootMargin !== void 0 ? _newInit_rootMargin : '0px';
|
|
112
|
+
// Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin
|
|
113
|
+
setObserverInit({
|
|
114
|
+
...newInit,
|
|
115
|
+
rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit === null || newInit === void 0 ? void 0 : newInit.root)
|
|
116
|
+
});
|
|
117
|
+
}, [
|
|
118
|
+
ltrRootMargin,
|
|
119
|
+
setObserverInit
|
|
120
|
+
]);
|
|
41
121
|
return {
|
|
42
122
|
setObserverList,
|
|
43
|
-
setObserverInit,
|
|
123
|
+
setObserverInit: setObserverInitExternal,
|
|
44
124
|
observer
|
|
45
125
|
};
|
|
46
126
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useIntersectionObserver.js"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nconst { useState, useRef } = React;\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */ export const useIntersectionObserver = (callback, options)=>{\n const observer = useRef();\n const [observerList, setObserverList] = useState();\n const [observerInit, setObserverInit] = useState(options);\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, observerInit);\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach((element)=>{\n var _observer_current;\n (_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(element);\n });\n }\n // clean up previous elements being listened to\n return ()=>{\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [\n observerList,\n observerInit,\n callback\n ]);\n return {\n setObserverList,\n setObserverInit,\n observer\n };\n};\n"],"names":["useIntersectionObserver","useState","useRef","React","callback","options","observer","observerList","setObserverList","observerInit","setObserverInit","useIsomorphicLayoutEffect","current","IntersectionObserver","length","forEach","element","_observer_current","observe","disconnect"],"mappings":";;;;+BAWiBA;;;eAAAA;;;;iEAXM;gCACmB;AAC1C,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGC;AASlB,MAAMH,0BAA0B,CAACI,UAAUC;IAClD,MAAMC,WAAWJ;IACjB,MAAM,CAACK,cAAcC,gBAAgB,GAAGP;IACxC,MAAM,CAACQ,cAAcC,gBAAgB,GAAGT,SAASI;IACjD,iEAAiE;IACjE,6DAA6D;IAC7DM,IAAAA,yCAAyB,EAAC;QACtBL,SAASM,OAAO,GAAG,IAAIC,qBAAqBT,UAAUK;QACtD,+EAA+E;QAC/E,IAAIH,SAASM,OAAO,IAAIL,gBAAgBA,aAAaO,MAAM,GAAG,GAAG;YAC7DP,aAAaQ,OAAO,CAAC,CAACC;gBAClB,IAAIC;gBACHA,CAAAA,oBAAoBX,SAASM,OAAO,AAAD,MAAO,QAAQK,sBAAsB,KAAK,IAAI,KAAK,IAAIA,kBAAkBC,OAAO,CAACF;YACzH;QACJ;QACA,+CAA+C;QAC/C,OAAO;YACH,IAAIV,SAASM,OAAO,EAAE;gBAClBN,SAASM,OAAO,CAACO,UAAU;YAC/B;QACJ;IACJ,GAAG;QACCZ;QACAE;QACAL;KACH;IACD,OAAO;QACHI;QACAE;QACAJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"sources":["useIntersectionObserver.js"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nconst { useCallback, useState, useRef } = React;\nimport { useMutationObserver } from './useMutationObserver';\n/**\n * This function will take the rootMargin and flip the sides if we are in RTL based on the computed reading direction of the target element.\n * @param ltrRootMargin the margin to be processed and flipped if required\n * @param target target element that will have its current reading direction determined\n * @returns the corrected rootMargin (if it was necessary to correct)\n */ export const getRTLRootMargin = (ltrRootMargin, target)=>{\n if (target) {\n // get the computed dir for the target element\n const newDir = getComputedStyle(target).direction;\n // If we're in rtl reading direction, we might need to flip the margins on the left/right sides\n if (newDir === 'rtl') {\n let newMargin = ltrRootMargin;\n const splitMargins = ltrRootMargin.split(' ');\n // We only need to do this if we get four values, otherwise the sides are equal and don't require flipping.\n if (splitMargins.length === 4) {\n newMargin = `${splitMargins[0]} ${splitMargins[3]} ${splitMargins[2]} ${splitMargins[1]}`;\n }\n return newMargin;\n } else {\n return ltrRootMargin;\n }\n }\n return ltrRootMargin;\n};\n/**\n * React hook that allows easy usage of the browser API IntersectionObserver within React\n * @param callback - A function called when the percentage of the target element is visible crosses a threshold.\n * @param options - An optional object which customizes the observer. If options isn't specified, the observer uses the\n * document's viewport as the root, with no margin, and a 0% threshold (meaning that even a one-pixel change is\n * enough to trigger a callback).\n * @returns An array containing a callback to update the list of Elements the observer should listen to, a callback to\n * update the init options of the IntersectionObserver and a ref to the IntersectionObserver instance itself.\n */ export const useIntersectionObserver = (callback, options)=>{\n const observer = useRef();\n const [observerList, setObserverList] = useState();\n const { targetDocument } = useFluent();\n var _options_rootMargin;\n // set the initial init with corrected margins based on the observed root's calculated reading direction.\n const [observerInit, setObserverInit] = useState(options && {\n ...options,\n rootMargin: getRTLRootMargin((_options_rootMargin = options.rootMargin) !== null && _options_rootMargin !== void 0 ? _options_rootMargin : '0px', options.root)\n });\n var _options_rootMargin1;\n // We have to assume that any values passed in for rootMargin by the consuming app are ltr values. As such we will store the ltr value.\n const ltrRootMargin = useRef((_options_rootMargin1 = options === null || options === void 0 ? void 0 : options.rootMargin) !== null && _options_rootMargin1 !== void 0 ? _options_rootMargin1 : '0px');\n // Callback function to execute when mutations are observed\n const mutationObserverCallback = useCallback((mutationList)=>{\n for (const mutation of mutationList){\n // Ensuring that the right attribute is being observed and that the root is within the tree of the element being mutated.\n if (mutation.type === 'attributes' && mutation.attributeName === 'dir' && (options === null || options === void 0 ? void 0 : options.root) && mutation.target.contains(options === null || options === void 0 ? void 0 : options.root)) {\n setObserverInit({\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)\n });\n }\n }\n }, [\n ltrRootMargin,\n observerInit,\n options === null || options === void 0 ? void 0 : options.root\n ]);\n // Mutation observer for dir attribute changes in the document\n useMutationObserver(targetDocument, mutationObserverCallback, {\n attributes: true,\n subtree: true,\n attributeFilter: [\n 'dir'\n ]\n });\n // Observer elements in passed in list and clean up previous list\n // This effect is only triggered when observerList is updated\n useIsomorphicLayoutEffect(()=>{\n observer.current = new IntersectionObserver(callback, {\n ...observerInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, observerInit === null || observerInit === void 0 ? void 0 : observerInit.root)\n });\n observer.current = new IntersectionObserver(callback, observerInit);\n // If we have an instance of IO and a list with elements, observer the elements\n if (observer.current && observerList && observerList.length > 0) {\n observerList.forEach((element)=>{\n var _observer_current;\n (_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(element);\n });\n }\n // clean up previous elements being listened to\n return ()=>{\n if (observer.current) {\n observer.current.disconnect();\n }\n };\n }, [\n observerList,\n observerInit,\n callback\n ]);\n // Do not use internally, we need to track external settings only here\n const setObserverInitExternal = useCallback((newInit)=>{\n var _newInit_rootMargin;\n // Since we know this is coming from consumers, we can store this value as LTR somewhat safely.\n ltrRootMargin.current = (_newInit_rootMargin = newInit === null || newInit === void 0 ? void 0 : newInit.rootMargin) !== null && _newInit_rootMargin !== void 0 ? _newInit_rootMargin : '0px';\n // Call the internal setter to update the value and ensure if our calculated direction is rtl, we flip the margin\n setObserverInit({\n ...newInit,\n rootMargin: getRTLRootMargin(ltrRootMargin.current, newInit === null || newInit === void 0 ? void 0 : newInit.root)\n });\n }, [\n ltrRootMargin,\n setObserverInit\n ]);\n return {\n setObserverList,\n setObserverInit: setObserverInitExternal,\n observer\n };\n};\n"],"names":["getRTLRootMargin","useIntersectionObserver","useCallback","useState","useRef","React","ltrRootMargin","target","newDir","getComputedStyle","direction","newMargin","splitMargins","split","length","callback","options","observer","observerList","setObserverList","targetDocument","useFluent","_options_rootMargin","observerInit","setObserverInit","rootMargin","root","_options_rootMargin1","mutationObserverCallback","mutationList","mutation","type","attributeName","contains","current","useMutationObserver","attributes","subtree","attributeFilter","useIsomorphicLayoutEffect","IntersectionObserver","forEach","element","_observer_current","observe","disconnect","setObserverInitExternal","newInit","_newInit_rootMargin"],"mappings":";;;;;;;;;;;IAUiBA,gBAAgB;eAAhBA;;IA2BAC,uBAAuB;eAAvBA;;;;iEArCM;gCACmB;qCACM;qCAEZ;AADpC,MAAM,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,MAAM,EAAE,GAAGC;AAO/B,MAAML,mBAAmB,CAACM,eAAeC;IAChD,IAAIA,QAAQ;QACR,8CAA8C;QAC9C,MAAMC,SAASC,iBAAiBF,QAAQG,SAAS;QACjD,+FAA+F;QAC/F,IAAIF,WAAW,OAAO;YAClB,IAAIG,YAAYL;YAChB,MAAMM,eAAeN,cAAcO,KAAK,CAAC;YACzC,2GAA2G;YAC3G,IAAID,aAAaE,MAAM,KAAK,GAAG;gBAC3BH,YAAY,CAAC,EAAEC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC,EAAEA,YAAY,CAAC,EAAE,CAAC,CAAC;YAC7F;YACA,OAAOD;QACX,OAAO;YACH,OAAOL;QACX;IACJ;IACA,OAAOA;AACX;AASW,MAAML,0BAA0B,CAACc,UAAUC;IAClD,MAAMC,WAAWb;IACjB,MAAM,CAACc,cAAcC,gBAAgB,GA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Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "useMutationObserver", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return useMutationObserver;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const { useRef, useEffect } = _react;
|
|
14
|
+
const useMutationObserver = (target, callback, options)=>{
|
|
15
|
+
const observer = useRef();
|
|
16
|
+
useEffect(()=>{
|
|
17
|
+
// Create an observer instance linked to the callback function
|
|
18
|
+
observer.current = new MutationObserver(callback);
|
|
19
|
+
}, [
|
|
20
|
+
callback
|
|
21
|
+
]);
|
|
22
|
+
useEffect(()=>{
|
|
23
|
+
if (target) {
|
|
24
|
+
var _observer_current;
|
|
25
|
+
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(target, options);
|
|
26
|
+
}
|
|
27
|
+
return ()=>{
|
|
28
|
+
var _observer_current;
|
|
29
|
+
(_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.disconnect();
|
|
30
|
+
};
|
|
31
|
+
}, [
|
|
32
|
+
target,
|
|
33
|
+
options
|
|
34
|
+
]);
|
|
35
|
+
return {
|
|
36
|
+
observer
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useMutationObserver.js"],"sourcesContent":["import * as React from 'react';\nconst { useRef, useEffect } = React;\nexport const useMutationObserver = (target, callback, options)=>{\n const observer = useRef();\n useEffect(()=>{\n // Create an observer instance linked to the callback function\n observer.current = new MutationObserver(callback);\n }, [\n callback\n ]);\n useEffect(()=>{\n if (target) {\n var // Start observing the target node for configured mutations\n _observer_current;\n (_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.observe(target, options);\n }\n return ()=>{\n var _observer_current;\n (_observer_current = observer.current) === null || _observer_current === void 0 ? void 0 : _observer_current.disconnect();\n };\n }, [\n target,\n options\n ]);\n return {\n observer\n };\n};\n"],"names":["useMutationObserver","useRef","useEffect","React","target","callback","options","observer","current","MutationObserver","_observer_current","observe","disconnect"],"mappings":";;;;+BAEaA;;;eAAAA;;;;iEAFU;AACvB,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAE,GAAGC;AACvB,MAAMH,sBAAsB,CAACI,QAAQC,UAAUC;IAClD,MAAMC,WAAWN;IACjBC,UAAU;QACN,8DAA8D;QAC9DK,SAASC,OAAO,GAAG,IAAIC,iBAAiBJ;IAC5C,GAAG;QACCA;KACH;IACDH,UAAU;QACN,IAAIE,QAAQ;YACR,IACAM;YACCA,CAAAA,oBAAoBH,SAASC,OAAO,AAAD,MAAO,QAAQE,sBAAsB,KAAK,IAAI,KAAK,IAAIA,kBAAkBC,OAAO,CAACP,QAAQE;QACjI;QACA,OAAO;YACH,IAAII;YACHA,CAAAA,oBAAoBH,SAASC,OAAO,AAAD,MAAO,QAAQE,sBAAsB,KAAK,IAAI,KAAK,IAAIA,kBAAkBE,UAAU;QAC3H;IACJ,GAAG;QACCR;QACAE;KACH;IACD,OAAO;QACHC;IACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentui/react-virtualizer",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.58",
|
|
4
4
|
"description": "Generic and composable virtualizer framework built on browser intersection observer",
|
|
5
5
|
"main": "lib-commonjs/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@fluentui/react-jsx-runtime": "^9.0.19",
|
|
36
36
|
"@fluentui/react-utilities": "^9.15.2",
|
|
37
|
-
"@fluentui/react-shared-contexts": "^9.
|
|
37
|
+
"@fluentui/react-shared-contexts": "^9.13.0",
|
|
38
38
|
"@griffel/react": "^1.5.14",
|
|
39
39
|
"@swc/helpers": "^0.5.1"
|
|
40
40
|
},
|