@fluentui/react-utilities 9.3.0 → 9.3.1
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.json +30 -1
- package/CHANGELOG.md +11 -2
- package/dist/index.d.ts +2 -2
- package/lib/compose/getSlots.js +0 -8
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/isResolvedShorthand.js +0 -1
- package/lib/compose/isResolvedShorthand.js.map +1 -1
- package/lib/compose/resolveShorthand.js +2 -6
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/hooks/useControllableState.js +6 -12
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js +0 -1
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js +0 -3
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js +0 -1
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js +0 -3
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js +0 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedRefs.js +2 -3
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js +8 -26
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js +0 -4
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js +0 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js +2 -3
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js +4 -11
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js +2 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/trigger/applyTriggerPropsToChildren.js +2 -6
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/trigger/getTriggerChild.js +2 -3
- package/lib/trigger/getTriggerChild.js.map +1 -1
- package/lib/trigger/isFluentTrigger.js.map +1 -1
- package/lib/utils/getNativeElementProps.js +0 -2
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js +0 -2
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js +0 -3
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/isHTMLElement.js +2 -2
- package/lib/utils/isHTMLElement.js.map +1 -1
- package/lib/utils/isInteractiveHTMLElement.js +0 -4
- package/lib/utils/isInteractiveHTMLElement.js.map +1 -1
- package/lib/utils/mergeCallbacks.js.map +1 -1
- package/lib/utils/omit.js +0 -2
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/properties.js +7 -36
- package/lib/utils/properties.js.map +1 -1
- package/lib-amd/utils/isHTMLElement.js +4 -3
- package/lib-amd/utils/isHTMLElement.js.map +1 -1
- package/lib-amd/utils/isInteractiveHTMLElement.js.map +1 -1
- package/lib-commonjs/compose/getSlots.js +0 -12
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.js +0 -5
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/isResolvedShorthand.js +0 -4
- package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js +2 -9
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/compose/types.js.map +1 -1
- package/lib-commonjs/hooks/index.js +0 -12
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js +6 -14
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js +0 -5
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js +0 -6
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js +0 -4
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js +0 -8
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +0 -4
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js +2 -6
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js +8 -30
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js +0 -8
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js +0 -4
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js +2 -6
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js +0 -10
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js +4 -17
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js +2 -3
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/ssr/index.js +0 -3
- package/lib-commonjs/ssr/index.js.map +1 -1
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js +2 -10
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/trigger/getTriggerChild.js +2 -7
- package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
- package/lib-commonjs/trigger/index.js +0 -5
- package/lib-commonjs/trigger/index.js.map +1 -1
- package/lib-commonjs/trigger/isFluentTrigger.js +0 -2
- package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
- package/lib-commonjs/trigger/types.js.map +1 -1
- package/lib-commonjs/utils/clamp.js +0 -2
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js +0 -6
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js +0 -4
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js +0 -5
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/index.js +0 -9
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isHTMLElement.js +2 -4
- package/lib-commonjs/utils/isHTMLElement.js.map +1 -1
- package/lib-commonjs/utils/isInteractiveHTMLElement.js +0 -7
- package/lib-commonjs/utils/isInteractiveHTMLElement.js.map +1 -1
- package/lib-commonjs/utils/mergeCallbacks.js +0 -2
- package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
- package/lib-commonjs/utils/omit.js +0 -4
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/properties.js +7 -38
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/package.json +2 -2
@@ -4,7 +4,6 @@ import { useEventCallback } from './useEventCallback';
|
|
4
4
|
* @internal
|
5
5
|
* Utility to perform checks where a click/touch event was made outside a component
|
6
6
|
*/
|
7
|
-
|
8
7
|
export const useOnClickOutside = options => {
|
9
8
|
const {
|
10
9
|
refs,
|
@@ -17,9 +16,7 @@ export const useOnClickOutside = options => {
|
|
17
16
|
useIFrameFocus(!disabled, element, callback);
|
18
17
|
const listener = useEventCallback(ev => {
|
19
18
|
const contains = containsProp || ((parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
|
20
|
-
|
21
19
|
const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));
|
22
|
-
|
23
20
|
if (isOutside && !disabled) {
|
24
21
|
callback(ev);
|
25
22
|
}
|
@@ -29,25 +26,21 @@ export const useOnClickOutside = options => {
|
|
29
26
|
// Note this depends on a deprecated but extremely well supported quirk of the web platform
|
30
27
|
// https://github.com/facebook/react/issues/20074
|
31
28
|
let currentEvent = getWindowEvent(window);
|
32
|
-
|
33
29
|
const conditionalHandler = event => {
|
34
30
|
// Skip if this event is the same as the one running when we added the handlers
|
35
31
|
if (event === currentEvent) {
|
36
32
|
currentEvent = undefined;
|
37
33
|
return;
|
38
34
|
}
|
39
|
-
|
40
35
|
listener(event);
|
41
36
|
};
|
42
|
-
|
43
37
|
if (!disabled) {
|
44
38
|
// use capture phase because React can update DOM before the event bubbles to the document
|
45
39
|
element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
|
46
40
|
element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
|
47
41
|
element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
|
48
|
-
}
|
49
|
-
|
50
|
-
|
42
|
+
}
|
43
|
+
// Garbage collect this event after it's no longer useful to avoid memory leaks
|
51
44
|
timeoutId.current = window.setTimeout(() => {
|
52
45
|
currentEvent = undefined;
|
53
46
|
}, 1);
|
@@ -60,23 +53,18 @@ export const useOnClickOutside = options => {
|
|
60
53
|
};
|
61
54
|
}, [listener, element, disabled]);
|
62
55
|
};
|
63
|
-
|
64
56
|
const getWindowEvent = target => {
|
65
57
|
var _a, _b, _c;
|
66
|
-
|
67
58
|
if (target) {
|
68
59
|
if (typeof target.window === 'object' && target.window === target) {
|
69
60
|
// eslint-disable-next-line deprecation/deprecation
|
70
61
|
return target.event;
|
71
|
-
}
|
72
|
-
|
73
|
-
|
62
|
+
}
|
63
|
+
// eslint-disable-next-line deprecation/deprecation
|
74
64
|
return (_c = (_b = (_a = target.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.event) !== null && _c !== void 0 ? _c : undefined;
|
75
65
|
}
|
76
|
-
|
77
66
|
return undefined;
|
78
67
|
};
|
79
|
-
|
80
68
|
const FUI_FRAME_EVENT = 'fuiframefocus';
|
81
69
|
/**
|
82
70
|
* Since click events do not propagate past iframes, we use focus to detect if a
|
@@ -92,32 +80,28 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
|
|
92
80
|
* @param targetDocument - the document to dispatch events and set timeouts
|
93
81
|
* @param pollDuration - in milliseconds
|
94
82
|
*/
|
95
|
-
|
96
83
|
const useIFrameFocus = (enableFrameFocusDispatch, targetDocument, callback, pollDuration = 1000) => {
|
97
84
|
const timeoutRef = React.useRef();
|
98
85
|
const listener = useEventCallback(e => {
|
99
86
|
if (callback) {
|
100
87
|
callback(e);
|
101
88
|
}
|
102
|
-
});
|
103
|
-
|
89
|
+
});
|
90
|
+
// Adds listener to the custom iframe focus event
|
104
91
|
React.useEffect(() => {
|
105
92
|
if (enableFrameFocusDispatch) {
|
106
93
|
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
|
107
94
|
}
|
108
|
-
|
109
95
|
return () => {
|
110
96
|
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
|
111
97
|
};
|
112
|
-
}, [targetDocument, enableFrameFocusDispatch, listener]);
|
113
|
-
|
98
|
+
}, [targetDocument, enableFrameFocusDispatch, listener]);
|
99
|
+
// Starts polling for the active element
|
114
100
|
React.useEffect(() => {
|
115
101
|
var _a;
|
116
|
-
|
117
102
|
if (enableFrameFocusDispatch) {
|
118
103
|
timeoutRef.current = (_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.setInterval(() => {
|
119
104
|
const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
|
120
|
-
|
121
105
|
if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
|
122
106
|
const event = new CustomEvent(FUI_FRAME_EVENT, {
|
123
107
|
bubbles: true
|
@@ -126,10 +110,8 @@ const useIFrameFocus = (enableFrameFocusDispatch, targetDocument, callback, poll
|
|
126
110
|
}
|
127
111
|
}, pollDuration);
|
128
112
|
}
|
129
|
-
|
130
113
|
return () => {
|
131
114
|
var _a;
|
132
|
-
|
133
115
|
(_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.clearTimeout(timeoutRef.current);
|
134
116
|
};
|
135
117
|
}, [targetDocument, enableFrameFocusDispatch, pollDuration]);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useOnClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AAiCA;;;AAGG;;AACH,OAAO,MAAM,iBAAiB,GAAI,OAAD,IAA8C;EAC7E,MAAM;IAAE,IAAF;IAAQ,QAAR;IAAkB,OAAlB;IAA2B,QAA3B;IAAqC,QAAQ,EAAE;EAA/C,IAAgE,OAAtE;EACA,MAAM,SAAS,GAAG,KAAK,CAAC,MAAN,CAAiC,SAAjC,CAAlB;EACA,cAAc,CAAC,CAAC,QAAF,EAAY,OAAZ,EAAqB,QAArB,CAAd;EAEA,MAAM,QAAQ,GAAG,gBAAgB,CAAE,EAAD,IAAgC;IAChE,MAAM,QAAQ,GACZ,YAAY,KAAK,CAAC,MAAD,EAAS,KAAT,KAAmB,CAAC,EAAC,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,QAAR,CAAiB,KAAjB,CAAD,CAAzB,CADd;;IAGA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAL,CAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAJ,IAAe,IAAhB,EAAsB,EAAE,CAAC,MAAzB,CAA3B,CAAlB;;IACA,IAAI,SAAS,IAAI,CAAC,QAAlB,EAA4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eAAhB,EAAiC;YAAE,OAAO,EAAE;UAAX,CAAjC,CAAd;UACA,aAAa,CAAC,aAAd,CAA4B,KAA5B;QACD;MACF,CAN+C,EAM7C,YAN6C,CAAhD;IAOD;;IACD,OAAO,MAAK;;;MACV,CAAA,EAAA,GAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,MAA2B,IAA3B,IAA2B,EAAA,KAAA,KAAA,CAA3B,GAA2B,KAAA,CAA3B,GAA2B,EAAA,CAAE,YAAF,CAAe,UAAU,CAAC,OAA1B,CAA3B;IACD,CAFD;EAGD,CAbD,EAaG,CAAC,cAAD,EAAiB,wBAAjB,EAA2C,YAA3C,CAbH;AAcD,CAvCD","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n * @param parentRef - provided parent ref\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n useIFrameFocus(!disabled, element, callback as (e: Event) => void);\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n if (!disabled) {\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n }\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\n\nconst getWindowEvent = (target: Node | Window): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n *\n * @param enableFrameFocusDispatch - boolean flag to start dispatching events\n * @param targetDocument - the document to dispatch events and set timeouts\n * @param pollDuration - in milliseconds\n */\nconst useIFrameFocus = (\n enableFrameFocusDispatch: boolean,\n targetDocument: Document | undefined,\n callback: (e: Event) => void,\n pollDuration: number = 1000,\n) => {\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n if (callback) {\n callback(e);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n }\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, enableFrameFocusDispatch, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, enableFrameFocusDispatch, pollDuration]);\n};\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,gBAAgB,QAAQ,oBAAoB;AAiCrD;;;;AAIA,OAAO,MAAMC,iBAAiB,GAAIC,OAAyC,IAAI;EAC7E,MAAM;IAAEC,IAAI;IAAEC,QAAQ;IAAEC,OAAO;IAAEC,QAAQ;IAAEC,QAAQ,EAAEC;EAAY,CAAE,GAAGN,OAAO;EAC7E,MAAMO,SAAS,GAAGV,KAAK,CAACW,MAAM,CAAqBC,SAAS,CAAC;EAC7DC,cAAc,CAAC,CAACN,QAAQ,EAAED,OAAO,EAAED,QAA8B,CAAC;EAElE,MAAMS,QAAQ,GAAGb,gBAAgB,CAAEc,EAA2B,IAAI;IAChE,MAAMP,QAAQ,GACZC,YAAY,KAAK,CAACO,MAAM,EAAEC,KAAK,KAAK,CAAC,EAACD,MAAM,aAANA,MAA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AEN,mBAAmB,CAACI,eAAe,EAAErB,QAAQ,EAAE,IAAI,CAAC;IACtE,CAAC;EACH,CAAC,EAAE,CAACuB,cAAc,EAAED,wBAAwB,EAAEtB,QAAQ,CAAC,CAAC;EAExD;EACAd,KAAK,CAACuB,SAAS,CAAC,MAAK;;IACnB,IAAIa,wBAAwB,EAAE;MAC5BG,UAAU,CAAClB,OAAO,GAAG,oBAAc,aAAdgB,cAAc,uBAAdA,cAAc,CAAEH,WAAW,0CAAEO,WAAW,CAAC,MAAK;QACjE,MAAMC,aAAa,GAAGL,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEK,aAAa;QACnD,IAAI,cAAa,aAAbA,aAAa,uBAAbA,aAAa,CAAEC,OAAO,MAAK,QAAQ,IAAI,cAAa,aAAbD,aAAa,uBAAbA,aAAa,CAAEC,OAAO,MAAK,SAAS,EAAE;UAC/E,MAAMf,KAAK,GAAG,IAAIgB,WAAW,CAACT,eAAe,EAAE;YAAEU,OAAO,EAAE;UAAI,CAAE,CAAC;UACjEH,aAAa,CAACI,aAAa,CAAClB,KAAK,CAAC;;MAEtC,CAAC,EAAEU,YAAY,CAAC;;IAElB,OAAO,MAAK;;MACV,oBAAc,aAAdD,cAAc,uBAAdA,cAAc,CAAEH,WAAW,0CAAEF,YAAY,CAACO,UAAU,CAAClB,OAAO,CAAC;IAC/D,CAAC;EACH,CAAC,EAAE,CAACgB,cAAc,EAAED,wBAAwB,EAAEE,YAAY,CAAC,CAAC;AAC9D,CAAC","names":["React","useEventCallback","useOnClickOutside","options","refs","callback","element","disabled","contains","containsProp","timeoutId","useRef","undefined","useIFrameFocus","listener","ev","parent","child","isOutside","every","ref","current","target","useEffect","currentEvent","getWindowEvent","window","conditionalHandler","event","addEventListener","setTimeout","removeEventListener","clearTimeout","ownerDocument","defaultView","FUI_FRAME_EVENT","enableFrameFocusDispatch","targetDocument","pollDuration","timeoutRef","e","setInterval","activeElement","tagName","CustomEvent","bubbles","dispatchEvent"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useOnClickOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n * @param parentRef - provided parent ref\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n useIFrameFocus(!disabled, element, callback as (e: Event) => void);\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n if (!disabled) {\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n }\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\n\nconst getWindowEvent = (target: Node | Window): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n *\n * @param enableFrameFocusDispatch - boolean flag to start dispatching events\n * @param targetDocument - the document to dispatch events and set timeouts\n * @param pollDuration - in milliseconds\n */\nconst useIFrameFocus = (\n enableFrameFocusDispatch: boolean,\n targetDocument: Document | undefined,\n callback: (e: Event) => void,\n pollDuration: number = 1000,\n) => {\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n if (callback) {\n callback(e);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n }\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, enableFrameFocusDispatch, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, enableFrameFocusDispatch, pollDuration]);\n};\n"]}
|
@@ -4,7 +4,6 @@ import { useEventCallback } from './useEventCallback';
|
|
4
4
|
* @internal
|
5
5
|
* Utility to perform checks where a click/touch event was made outside a component
|
6
6
|
*/
|
7
|
-
|
8
7
|
export const useOnScrollOutside = options => {
|
9
8
|
const {
|
10
9
|
refs,
|
@@ -15,9 +14,7 @@ export const useOnScrollOutside = options => {
|
|
15
14
|
} = options;
|
16
15
|
const listener = useEventCallback(ev => {
|
17
16
|
const contains = containsProp || ((parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
|
18
|
-
|
19
17
|
const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));
|
20
|
-
|
21
18
|
if (isOutside && !disabled) {
|
22
19
|
callback(ev);
|
23
20
|
}
|
@@ -27,7 +24,6 @@ export const useOnScrollOutside = options => {
|
|
27
24
|
element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
|
28
25
|
element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
|
29
26
|
}
|
30
|
-
|
31
27
|
return () => {
|
32
28
|
element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);
|
33
29
|
element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,gBAAgB,QAAQ,oBAAoB;AAGrD;;;;AAIA,OAAO,MAAMC,kBAAkB,GAAIC,OAAyC,IAAI;EAC9E,MAAM;IAAEC,IAAI;IAAEC,QAAQ;IAAEC,OAAO;IAAEC,QAAQ;IAAEC,QAAQ,EAAEC;EAAY,CAAE,GAAGN,OAAO;EAE7E,MAAMO,QAAQ,GAAGT,gBAAgB,CAAEU,EAA2B,IAAI;IAChE,MAAMH,QAAQ,GACZC,YAAY,KAAK,CAACG,MAAM,EAAEC,KAAK,KAAK,CAAC,EAACD,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEJ,QAAQ,CAACK,KAAK,CAAC,EAAC;IAEhE,MAAMC,SAAS,GAAGV,IAAI,CAACW,KAAK,CAACC,GAAG,IAAI,CAACR,QAAQ,CAACQ,GAAG,CAACC,OAAO,IAAI,IAAI,EAAEN,EAAE,CAACO,MAAqB,CAAC,CAAC;IAC7F,IAAIJ,SAAS,IAAI,CAACP,QAAQ,EAAE;MAC1BF,QAAQ,CAACM,EAAE,CAAC;;EAEhB,CAAC,CAAC;EAEFX,KAAK,CAACmB,SAAS,CAAC,MAAK;IACnB,IAAI,CAACZ,QAAQ,EAAE;MACbD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEc,gBAAgB,CAAC,OAAO,EAAEV,QAAQ,CAAC;MAC5CJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEc,gBAAgB,CAAC,WAAW,EAAEV,QAAQ,CAAC;;IAGlD,OAAO,MAAK;MACVJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEe,mBAAmB,CAAC,OAAO,EAAEX,QAAQ,CAAC;MAC/CJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEe,mBAAmB,CAAC,WAAW,EAAEX,QAAQ,CAAC;IACrD,CAAC;EACH,CAAC,EAAE,CAACA,QAAQ,EAAEJ,OAAO,EAAEC,QAAQ,CAAC,CAAC;AACnC,CAAC","names":["React","useEventCallback","useOnScrollOutside","options","refs","callback","element","disabled","contains","containsProp","listener","ev","parent","child","isOutside","every","ref","current","target","useEffect","addEventListener","removeEventListener"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useOnScrollOutside.ts"],"sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (!disabled) {\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n }\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"]}
|
package/lib/hooks/usePrevious.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B;;;AAGA,OAAO,MAAMC,WAAW,GAAyBC,KAAgB,IAAI;EACnE,MAAMC,GAAG,GAAGH,KAAK,CAACI,MAAM,CAAmB,IAAI,CAAC;EAChDJ,KAAK,CAACK,SAAS,CAAC,MAAK;IACnBF,GAAG,CAACG,OAAO,GAAGJ,KAAK;EACrB,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EACX,OAAOC,GAAG,CAACG,OAAO;AACpB,CAAC","names":["React","usePrevious","value","ref","useRef","useEffect","current"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/usePrevious.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport const usePrevious = <ValueType = unknown>(value: ValueType) => {\n const ref = React.useRef<ValueType | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n};\n"]}
|
package/lib/hooks/useTimeout.js
CHANGED
@@ -7,7 +7,6 @@ import * as React from 'react';
|
|
7
7
|
*
|
8
8
|
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
9
9
|
*/
|
10
|
-
|
11
10
|
export function useTimeout() {
|
12
11
|
const [timeout] = React.useState(() => ({
|
13
12
|
id: undefined,
|
@@ -21,8 +20,8 @@ export function useTimeout() {
|
|
21
20
|
timeout.id = undefined;
|
22
21
|
}
|
23
22
|
}
|
24
|
-
}));
|
25
|
-
|
23
|
+
}));
|
24
|
+
// Clean up the timeout when the component is unloaded
|
26
25
|
React.useEffect(() => timeout.clear, [timeout]);
|
27
26
|
return [timeout.set, timeout.clear];
|
28
27
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B;;;;;;;;AAQA,OAAM,SAAUC,UAAU;EACxB,MAAM,CAACC,OAAO,CAAC,GAAGF,KAAK,CAACG,QAAQ,CAAC,OAAO;IACtCC,EAAE,EAAEC,SAAsD;IAC1DC,GAAG,EAAE,CAACC,EAAc,EAAEC,KAAa,KAAI;MACrCN,OAAO,CAACO,KAAK,EAAE;MACfP,OAAO,CAACE,EAAE,GAAGM,UAAU,CAACH,EAAE,EAAEC,KAAK,CAAC;IACpC,CAAC;IACDC,KAAK,EAAE,MAAK;MACV,IAAIP,OAAO,CAACE,EAAE,KAAKC,SAAS,EAAE;QAC5BM,YAAY,CAACT,OAAO,CAACE,EAAE,CAAC;QACxBF,OAAO,CAACE,EAAE,GAAGC,SAAS;;IAE1B;GACD,CAAC,CAAC;EAEH;EACAL,KAAK,CAACY,SAAS,CAAC,MAAMV,OAAO,CAACO,KAAK,EAAE,CAACP,OAAO,CAAC,CAAC;EAE/C,OAAO,CAACA,OAAO,CAACI,GAAG,EAAEJ,OAAO,CAACO,KAAK,CAAU;AAC9C","names":["React","useTimeout","timeout","useState","id","undefined","set","fn","delay","clear","setTimeout","clearTimeout","useEffect"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useTimeout.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once,\n * and is cleaned up when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const [timeout] = React.useState(() => ({\n id: undefined as ReturnType<typeof setTimeout> | undefined,\n set: (fn: () => void, delay: number) => {\n timeout.clear();\n timeout.id = setTimeout(fn, delay);\n },\n clear: () => {\n if (timeout.id !== undefined) {\n clearTimeout(timeout.id);\n timeout.id = undefined;\n }\n },\n }));\n\n // Clean up the timeout when the component is unloaded\n React.useEffect(() => timeout.clear, [timeout]);\n\n return [timeout.set, timeout.clear] as const;\n}\n"]}
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA,SAASA,QAAQ,EAAEC,gBAAgB,EAAEC,mBAAmB,QAAQ,iBAAiB;AAgBjF,SACEC,gBAAgB,EAChBC,oBAAoB,EACpBC,gBAAgB,EAChBC,aAAa,EACbC,cAAc,EACdC,KAAK,EACLC,yBAAyB,EACzBC,aAAa,EACbC,iBAAiB,EACjBC,kBAAkB,EAClBC,WAAW,EACXC,UAAU,QACL,eAAe;AAGtB,SAASC,SAAS,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,aAAa;AAE9D,SACEC,KAAK,EACLC,qBAAqB,EACrBC,yBAAyB,EACzBC,aAAa,EACbC,cAAc,EACdC,aAAa,EACbC,wBAAwB,QACnB,eAAe;AAEtB,SAASC,2BAA2B,EAAEC,eAAe,EAAEC,eAAe,QAAQ,iBAAiB","names":["getSlots","resolveShorthand","isResolvedShorthand","resetIdsForTests","useControllableState","useEventCallback","useFirstMount","useForceUpdate","useId","useIsomorphicLayoutEffect","useMergedRefs","useOnClickOutside","useOnScrollOutside","usePrevious","useTimeout","canUseDOM","useIsSSR","SSRProvider","clamp","getNativeElementProps","getPartitionedNativeProps","getRTLSafeKey","mergeCallbacks","isHTMLElement","isInteractiveHTMLElement","applyTriggerPropsToChildren","getTriggerChild","isFluentTrigger"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/index.ts"],"sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n"]}
|
package/lib/ssr/SSRContext.js
CHANGED
@@ -5,7 +5,6 @@ import { canUseDOM } from './canUseDOM';
|
|
5
5
|
*
|
6
6
|
* @internal
|
7
7
|
*/
|
8
|
-
|
9
8
|
export const defaultSSRContextValue = {
|
10
9
|
current: 0
|
11
10
|
};
|
@@ -13,10 +12,8 @@ export const SSRContext = /*#__PURE__*/React.createContext(undefined);
|
|
13
12
|
/**
|
14
13
|
* @internal
|
15
14
|
*/
|
16
|
-
|
17
15
|
export function useSSRContext() {
|
18
16
|
var _a;
|
19
|
-
|
20
17
|
return (_a = React.useContext(SSRContext)) !== null && _a !== void 0 ? _a : defaultSSRContextValue;
|
21
18
|
}
|
22
19
|
/**
|
@@ -25,7 +22,6 @@ export function useSSRContext() {
|
|
25
22
|
*
|
26
23
|
* @public
|
27
24
|
*/
|
28
|
-
|
29
25
|
export const SSRProvider = props => {
|
30
26
|
const [value] = React.useState(() => ({
|
31
27
|
current: 0
|
@@ -38,21 +34,19 @@ export const SSRProvider = props => {
|
|
38
34
|
* Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
|
39
35
|
* browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
|
40
36
|
*/
|
41
|
-
|
42
37
|
export function useIsSSR() {
|
43
38
|
const isInSSRContext = useSSRContext() !== defaultSSRContextValue;
|
44
|
-
const [isSSR, setIsSSR] = React.useState(isInSSRContext);
|
39
|
+
const [isSSR, setIsSSR] = React.useState(isInSSRContext);
|
40
|
+
// If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the
|
45
41
|
// developer to add one.
|
46
|
-
|
47
42
|
if (process.env.NODE_ENV !== 'production') {
|
48
43
|
if (!isInSSRContext && !canUseDOM()) {
|
49
44
|
// eslint-disable-next-line no-console
|
50
45
|
console.error(['@fluentui/react-components: ', 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' + 'generated between the client and server.', '\n', '\n', 'Check documentation at https://aka.ms/fluentui-ssr'].join(''));
|
51
46
|
}
|
52
|
-
}
|
47
|
+
}
|
48
|
+
// If on the client, and the component was initially server rendered, then schedule a layout effect to update the
|
53
49
|
// component after hydration.
|
54
|
-
|
55
|
-
|
56
50
|
if (canUseDOM() && isInSSRContext) {
|
57
51
|
// This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
|
58
52
|
// mounting.
|
@@ -61,7 +55,6 @@ export function useIsSSR() {
|
|
61
55
|
setIsSSR(false);
|
62
56
|
}, []);
|
63
57
|
}
|
64
|
-
|
65
58
|
return isSSR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AAc,EAAE;IACjC;IACA;IACA;IACAhB,KAAK,CAACyB,eAAe,CAAC,MAAK;MACzBP,QAAQ,CAAC,KAAK,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC;;EAGR,OAAOD,KAAK;AACd","names":["React","canUseDOM","defaultSSRContextValue","current","SSRContext","createContext","undefined","useSSRContext","useContext","SSRProvider","props","value","useState","Provider","children","useIsSSR","isInSSRContext","isSSR","setIsSSR","process","env","NODE_ENV","console","error","join","useLayoutEffect"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/ssr/SSRContext.tsx"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from './canUseDOM';\n\n/**\n * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request\n * to ensure the client and server are consistent.\n *\n * @internal\n */\nexport type SSRContextValue = {\n current: number;\n};\n\n/**\n * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.\n *\n * @internal\n */\nexport const defaultSSRContextValue: SSRContextValue = {\n current: 0,\n};\n\nexport const SSRContext = React.createContext<SSRContextValue | undefined>(undefined) as React.Context<SSRContextValue>;\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext) ?? defaultSSRContextValue;\n}\n\n/**\n * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids\n * are consistent between the client and server.\n *\n * @public\n */\nexport const SSRProvider: React.FC = props => {\n const [value] = React.useState<SSRContextValue>(() => ({ current: 0 }));\n\n return <SSRContext.Provider value={value}>{props.children}</SSRContext.Provider>;\n};\n\n/**\n * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay\n * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.\n */\nexport function useIsSSR(): boolean {\n const isInSSRContext = useSSRContext() !== defaultSSRContextValue;\n const [isSSR, setIsSSR] = React.useState(isInSSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the\n // developer to add one.\n if (process.env.NODE_ENV !== 'production') {\n if (!isInSSRContext && !canUseDOM()) {\n // eslint-disable-next-line no-console\n console.error(\n [\n '@fluentui/react-components: ',\n 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' +\n 'generated between the client and server.',\n '\\n',\n '\\n',\n 'Check documentation at https://aka.ms/fluentui-ssr',\n ].join(''),\n );\n }\n }\n\n // If on the client, and the component was initially server rendered, then schedule a layout effect to update the\n // component after hydration.\n if (canUseDOM() && isInSSRContext) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line\n React.useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return isSSR;\n}\n"]}
|
package/lib/ssr/canUseDOM.js
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
* Verifies if an application can use DOM.
|
3
3
|
*/
|
4
4
|
export function canUseDOM() {
|
5
|
-
return typeof window !== 'undefined' && !!(window.document &&
|
5
|
+
return typeof window !== 'undefined' && !!(window.document &&
|
6
|
+
// eslint-disable-next-line deprecation/deprecation
|
6
7
|
window.document.createElement);
|
7
8
|
}
|
8
9
|
//# sourceMappingURL=canUseDOM.js.map
|
package/lib/ssr/canUseDOM.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA;;;AAGA,OAAM,SAAUA,SAAS;EACvB,OACE,OAAOC,MAAM,KAAK,WAAW,IAC7B,CAAC,EACCA,MAAM,CAACC,QAAQ;EACf;EACAD,MAAM,CAACC,QAAQ,CAACC,aAAa,CAC9B;AAEL","names":["canUseDOM","window","document","createElement"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/ssr/canUseDOM.ts"],"sourcesContent":["/**\n * Verifies if an application can use DOM.\n */\nexport function canUseDOM(): boolean {\n return (\n typeof window !== 'undefined' &&\n !!(\n window.document &&\n // eslint-disable-next-line deprecation/deprecation\n window.document.createElement\n )\n );\n}\n"]}
|
@@ -4,29 +4,25 @@ import { isFluentTrigger } from './isFluentTrigger';
|
|
4
4
|
* @internal
|
5
5
|
* resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
|
6
6
|
*/
|
7
|
-
|
8
7
|
export function applyTriggerPropsToChildren(children, triggerChildProps) {
|
9
8
|
if (typeof children === 'function') {
|
10
9
|
return children(triggerChildProps);
|
11
10
|
} else if (children) {
|
12
11
|
return cloneTriggerTree(children, triggerChildProps);
|
13
|
-
}
|
12
|
+
}
|
13
|
+
// Components in React should return either JSX elements or "null", otherwise React will throw:
|
14
14
|
// Nothing was returned from render.
|
15
15
|
// This usually means a return statement is missing. Or, to render nothing, return null.
|
16
|
-
|
17
|
-
|
18
16
|
return children || null;
|
19
17
|
}
|
20
18
|
/**
|
21
19
|
* Clones a React element tree, and applies the given props to the first grandchild that is not
|
22
20
|
* a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
|
23
21
|
*/
|
24
|
-
|
25
22
|
function cloneTriggerTree(child, triggerProps) {
|
26
23
|
if (! /*#__PURE__*/React.isValidElement(child) || child.type === React.Fragment) {
|
27
24
|
throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
|
28
25
|
}
|
29
|
-
|
30
26
|
if (isFluentTrigger(child)) {
|
31
27
|
const grandchild = cloneTriggerTree(child.props.children, triggerProps);
|
32
28
|
return /*#__PURE__*/React.cloneElement(child, undefined, grandchild);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,eAAe,QAAQ,mBAAmB;AAGnD;;;;AAIA,OAAM,SAAUC,2BAA2B,CACzCC,QAAqD,EACrDC,iBAAoC;EAEpC,IAAI,OAAOD,QAAQ,KAAK,UAAU,EAAE;IAClC,OAAOA,QAAQ,CAACC,iBAAiB,CAAC;GACnC,MAAM,IAAID,QAAQ,EAAE;IACnB,OAAOE,gBAAgB,CAACF,QAAQ,EAAEC,iBAAiB,CAAC;;EAGtD;EACA;EACA;EACA,OAAOD,QAAQ,IAAI,IAAI;AACzB;AAEA;;;;AAIA,SAASE,gBAAgB,CACvBC,KAAsB,EACtBC,YAA+B;EAE/B,IAAI,eAACP,KAAK,CAACQ,cAAc,CAACF,KAAK,CAAC,IAAIA,KAAK,CAACG,IAAI,KAAKT,KAAK,CAACU,QAAQ,EAAE;IACjE,MAAM,IAAIC,KAAK,CACb,iEAAiE,GAC/D,sDAAsD,CACzD;;EAGH,IAAIV,eAAe,CAACK,KAAK,CAAC,EAAE;IAC1B,MAAMM,UAAU,GAAGP,gBAAgB,CAACC,KAAK,CAACO,KAAK,CAACV,QAAQ,EAAEI,YAAY,CAAC;IACvE,oBAAOP,KAAK,CAACc,YAAY,CAACR,KAAK,EAAES,SAAS,EAAEH,UAAU,CAAC;GACxD,MAAM;IACL,oBAAOZ,KAAK,CAACc,YAAY,CAACR,KAAK,EAAEC,YAAoD,CAAC;;AAE1F","names":["React","isFluentTrigger","applyTriggerPropsToChildren","children","triggerChildProps","cloneTriggerTree","child","triggerProps","isValidElement","type","Fragment","Error","grandchild","props","cloneElement","undefined"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/trigger/applyTriggerPropsToChildren.ts"],"sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport function applyTriggerPropsToChildren<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n triggerChildProps: TriggerChildProps,\n): React.ReactElement | null {\n if (typeof children === 'function') {\n return children(triggerChildProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerChildProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n}\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nfunction cloneTriggerTree<TriggerChildProps>(\n child: React.ReactNode,\n triggerProps: TriggerChildProps,\n): React.ReactElement {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps as TriggerChildProps & React.Attributes);\n }\n}\n"]}
|
@@ -22,13 +22,12 @@ import { isFluentTrigger } from './isFluentTrigger';
|
|
22
22
|
* In the case where the immediate child is not a valid element,
|
23
23
|
* null is returned
|
24
24
|
*/
|
25
|
-
|
26
25
|
export function getTriggerChild(children) {
|
27
26
|
if (! /*#__PURE__*/React.isValidElement(children)) {
|
28
27
|
return null;
|
29
28
|
}
|
30
|
-
|
31
|
-
|
29
|
+
return isFluentTrigger(children) ? getTriggerChild(
|
30
|
+
// FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,
|
32
31
|
// but for some reason it's failing on build
|
33
32
|
children.props.children) : children;
|
34
33
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,eAAe,QAAQ,mBAAmB;AAGnD;;;;;;;;;;;;;;;;;;;;;;AAsBA,OAAM,SAAUC,eAAe,CAC7BC,QAAqD;EAGrD,IAAI,eAACH,KAAK,CAACI,cAAc,CAAoBD,QAAQ,CAAC,EAAE;IACtD,OAAO,IAAI;;EAEb,OAAOF,eAAe,CAACE,QAAQ,CAAC,GAC5BD,eAAe;EACb;EACA;EACCC,QAAQ,CAACE,KAAsB,CAACF,QAAQ,CAC1C,GACDA,QAAQ;AACd","names":["React","isFluentTrigger","getTriggerChild","children","isValidElement","props"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/trigger/getTriggerChild.ts"],"sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n *\n * In the case where the immediate child is not a valid element,\n * null is returned\n */\nexport function getTriggerChild<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (React.ReactElement<Partial<TriggerChildProps>> & { ref?: React.Ref<any> }) | null {\n if (!React.isValidElement<TriggerChildProps>(children)) {\n return null;\n }\n return isFluentTrigger(children)\n ? getTriggerChild(\n // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,\n // but for some reason it's failing on build\n (children.props as TriggerProps).children,\n )\n : children;\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAGA;;;;;AAKA,OAAM,SAAUA,eAAe,CAACC,OAA2B;EACzD,OAAOC,OAAO,CAAED,OAAO,CAACE,IAA+B,CAACC,wBAAwB,CAAC;AACnF","names":["isFluentTrigger","element","Boolean","type","isFluentTriggerComponent"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/trigger/isFluentTrigger.ts"],"sourcesContent":["import * as React from 'react';\nimport type { FluentTriggerComponent, TriggerProps } from './types';\n\n/**\n * @internal\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport function isFluentTrigger(element: React.ReactElement): element is React.ReactElement<TriggerProps> {\n return Boolean((element.type as FluentTriggerComponent).isFluentTriggerComponent);\n}\n"]}
|
@@ -32,7 +32,6 @@ const nativeElementMap = {
|
|
32
32
|
* @param excludedPropNames - List of props to disallow
|
33
33
|
*/
|
34
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
35
|
-
|
36
35
|
export function getNativeElementProps(tagName, props, excludedPropNames) {
|
37
36
|
const allowedPropNames = tagName && nativeElementMap[tagName] || htmlElementProperties;
|
38
37
|
allowedPropNames.as = 1;
|
@@ -46,7 +45,6 @@ export function getNativeElementProps(tagName, props, excludedPropNames) {
|
|
46
45
|
*
|
47
46
|
* @returns An object containing the native props for the `root` and primary slots.
|
48
47
|
*/
|
49
|
-
|
50
48
|
export const getPartitionedNativeProps = ({
|
51
49
|
primarySlotTagName,
|
52
50
|
props,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AACA,SACEA,eAAe,EACfC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,YAAY,EACZC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,EACfC,kBAAkB,EAClBC,gBAAgB,EAChBC,gBAAgB,EAChBC,eAAe,EACfC,YAAY,EACZC,YAAY,EACZC,YAAY,EACZC,kBAAkB,EAClBC,aAAa,EACbC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,aAAa,EACbC,qBAAqB,EACrBC,cAAc,EACdC,cAAc,EACdC,gBAAgB,QACX,cAAc;AAErB,MAAMC,gBAAgB,GAA2C;EAC/DC,KAAK,EAAE1B,eAAe;EACtB2B,KAAK,EAAE1B,eAAe;EACtB2B,KAAK,EAAE1B,eAAe;EACtB2B,EAAE,EAAE1B,YAAY;EAChB2B,EAAE,EAAE1B,YAAY;EAChB2B,CAAC,EAAE1B,gBAAgB;EACnB2B,MAAM,EAAE1B,gBAAgB;EACxB2B,KAAK,EAAE1B,eAAe;EACtB2B,QAAQ,EAAE1B,kBAAkB;EAC5B2B,MAAM,EAAE1B,gBAAgB;EACxB2B,MAAM,EAAE1B,gBAAgB;EACxB2B,KAAK,EAAE1B,eAAe;EACtB2B,EAAE,EAAE1B,YAAY;EAChB2B,EAAE,EAAE1B,YAAY;EAChB2B,EAAE,EAAE1B,YAAY;EAChB2B,QAAQ,EAAE1B,kBAAkB;EAC5B2B,GAAG,EAAE1B,aAAa;EAClB2B,QAAQ,EAAE1B,kBAAkB;EAC5B2B,IAAI,EAAE1B,cAAc;EACpB2B,MAAM,EAAE1B,gBAAgB;EACxB2B,GAAG,EAAE1B,aAAa;EAClB2B,IAAI,EAAExB,cAAc;EACpByB,MAAM,EAAExB;CACT;AAED;;;;;;;AAOA;AACA,OAAM,SAAUyB,qBAAqB,CACnCC,OAAe,EACfC,KAAS,EACTC,iBAA4B;EAE5B,MAAMC,gBAAgB,GAAIH,OAAO,IAAIzB,gBAAgB,CAACyB,OAAO,CAAC,IAAK7B,qBAAqB;EACxFgC,gBAAgB,CAACC,EAAE,GAAG,CAAC;EAEvB,OAAOhC,cAAc,CAAC6B,KAAK,EAAEE,gBAAgB,EAAED,iBAAiB,CAAC;AACnE;AAEA;;;;;;;;AAQA,OAAO,MAAMG,yBAAyB,GAAG,CAGvC;EACAC,kBAAkB;EAClBL,KAAK;EACLC;AAAiB,CAUlB,KAAI;EACH,OAAO;IACLK,IAAI,EAAE;MAAEC,KAAK,EAAEP,KAAK,CAACO,KAAK;MAAEC,SAAS,EAAER,KAAK,CAACQ;IAAS,CAAE;IACxDC,OAAO,EAAEX,qBAAqB,CAAgCO,kBAAkB,EAAEL,KAAK,EAAE,CACvF,IAAIC,iBAAiB,IAAI,EAAE,CAAC,EAC5B,OAAO,EACP,WAAW,CACZ;GACF;AACH,CAAC","names":["labelProperties","audioProperties","videoProperties","olProperties","liProperties","anchorProperties","buttonProperties","inputProperties","textAreaProperties","selectProperties","optionProperties","tableProperties","trProperties","thProperties","tdProperties","colGroupProperties","colProperties","fieldsetProperties","formProperties","iframeProperties","imgProperties","htmlElementProperties","getNativeProps","timeProperties","dialogProperties","nativeElementMap","label","audio","video","ol","li","a","button","input","textarea","select","option","table","tr","th","td","colGroup","col","fieldset","form","iframe","img","time","dialog","getNativeElementProps","tagName","props","excludedPropNames","allowedPropNames","as","getPartitionedNativeProps","primarySlotTagName","root","style","className","primary"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/utils/getNativeElementProps.ts"],"sourcesContent":["import * as React from 'react';\nimport {\n labelProperties,\n audioProperties,\n videoProperties,\n olProperties,\n liProperties,\n anchorProperties,\n buttonProperties,\n inputProperties,\n textAreaProperties,\n selectProperties,\n optionProperties,\n tableProperties,\n trProperties,\n thProperties,\n tdProperties,\n colGroupProperties,\n colProperties,\n fieldsetProperties,\n formProperties,\n iframeProperties,\n imgProperties,\n htmlElementProperties,\n getNativeProps,\n timeProperties,\n dialogProperties,\n} from './properties';\n\nconst nativeElementMap: Record<string, Record<string, number>> = {\n label: labelProperties,\n audio: audioProperties,\n video: videoProperties,\n ol: olProperties,\n li: liProperties,\n a: anchorProperties,\n button: buttonProperties,\n input: inputProperties,\n textarea: textAreaProperties,\n select: selectProperties,\n option: optionProperties,\n table: tableProperties,\n tr: trProperties,\n th: thProperties,\n td: tdProperties,\n colGroup: colGroupProperties,\n col: colProperties,\n fieldset: fieldsetProperties,\n form: formProperties,\n iframe: iframeProperties,\n img: imgProperties,\n time: timeProperties,\n dialog: dialogProperties,\n};\n\n/**\n * Given an element tagname and user props, filters the props to only allowed props for the given\n * element type.\n * @param tagName - Tag name (e.g. \"div\")\n * @param props - Props object\n * @param excludedPropNames - List of props to disallow\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(\n tagName: string,\n props: {},\n excludedPropNames?: string[],\n): TAttributes {\n const allowedPropNames = (tagName && nativeElementMap[tagName]) || htmlElementProperties;\n allowedPropNames.as = 1;\n\n return getNativeProps(props, allowedPropNames, excludedPropNames);\n}\n\n/**\n * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.\n *\n * This function is only for use with components that have a primary slot other than `root`.\n * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.\n *\n * @returns An object containing the native props for the `root` and primary slots.\n */\nexport const getPartitionedNativeProps = <\n Props extends Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>,\n ExcludedPropKeys extends Extract<keyof Props, string> = never\n>({\n primarySlotTagName,\n props,\n excludedPropNames,\n}: {\n /** The primary slot's element type (e.g. 'div') */\n primarySlotTagName: keyof JSX.IntrinsicElements;\n\n /** The component's props object */\n props: Props;\n\n /** List of native props to exclude from the returned value */\n excludedPropNames?: ExcludedPropKeys[];\n}) => {\n return {\n root: { style: props.style, className: props.className },\n primary: getNativeElementProps<Omit<Props, ExcludedPropKeys>>(primarySlotTagName, props, [\n ...(excludedPropNames || []),\n 'style',\n 'className',\n ]),\n };\n};\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAAA;;;;AAIA,OAAO,MAAMA,aAAa,GAAG,CAACC,GAAW,EAAEC,GAAkB,KAAI;EAC/D,IAAIA,GAAG,KAAK,KAAK,EAAE;IACjB,QAAQD,GAAG;MACT,KAAK,WAAW;QAAE;UAChB,OAAO,YAAY;;MAGrB,KAAK,YAAY;QAAE;UACjB,OAAO,WAAW;;IACnB;;EAIL,OAAOA,GAAG;AACZ,CAAC","names":["getRTLSafeKey","key","dir"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/utils/getRTLSafeKey.ts"],"sourcesContent":["/**\n * @internal\n * Finds and swaps a provided key for it's right to left format.\n */\nexport const getRTLSafeKey = (key: string, dir: 'ltr' | 'rtl') => {\n if (dir === 'rtl') {\n switch (key) {\n case 'ArrowLeft': {\n return 'ArrowRight';\n }\n\n case 'ArrowRight': {\n return 'ArrowLeft';\n }\n }\n }\n\n return key;\n};\n"]}
|
@@ -9,15 +9,12 @@ export function getReactCallbackName(event) {
|
|
9
9
|
if (event._reactName) {
|
10
10
|
return event._reactName;
|
11
11
|
}
|
12
|
-
|
13
12
|
if (event.dispatchConfig) {
|
14
13
|
if (event.dispatchConfig.registrationName) {
|
15
14
|
return event.dispatchConfig.registrationName;
|
16
15
|
}
|
17
|
-
|
18
16
|
return event.dispatchConfig.phasedRegistrationNames.bubbled;
|
19
17
|
}
|
20
|
-
|
21
18
|
if (process.env.NODE_ENV !== 'production') {
|
22
19
|
// eslint-disable-next-line no-console
|
23
20
|
console.error(['Passed React.SyntheticEvent does not contain ".dispatchConfig" or "._reactName".', 'This should not happen, please report it to https://github.com/microsoft/fluentui']);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"AAwBA;;;;;;;AAOA,OAAM,SAAUA,oBAAoB,CAACC,KAA0B;EAC7D,IAAIA,KAAK,CAACC,UAAU,EAAE;IACpB,OAAOD,KAAK,CAACC,UAA+B;;EAG9C,IAAID,KAAK,CAACE,cAAc,EAAE;IACxB,IAAIF,KAAK,CAACE,cAAc,CAACC,gBAAgB,EAAE;MACzC,OAAOH,KAAK,CAACE,cAAc,CAACC,gBAAqC;;IAGnE,OAAOH,KAAK,CAACE,cAAc,CAACE,uBAAuB,CAACC,OAA4B;;EAGlF,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC;IACAC,OAAO,CAACC,KAAK,CAAC,CACZ,kFAAkF,EAClF,mFAAmF,CACpF,CAAC;;AAEN","names":["getReactCallbackName","event","_reactName","dispatchConfig","registrationName","phasedRegistrationNames","bubbled","process","env","NODE_ENV","console","error"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/utils/getReactCallbackName.ts"],"sourcesContent":["import * as React from 'react';\n\ninterface ReactSyntheticEvent extends React.SyntheticEvent<unknown> {\n // React 17/18\n // See https://github.com/facebook/react/pull/19236\n _reactName?: string;\n\n // React 16\n dispatchConfig?: {\n registrationName: string;\n phasedRegistrationNames: {\n bubbled: string;\n captured: string;\n };\n };\n}\n\ntype NonUndefined<A> = A extends undefined ? never : A;\ntype FunctionKeys<T extends object> = {\n [K in keyof T]-?: NonUndefined<T[K]> extends Function ? K : never;\n}[keyof T];\n\nexport type ReactCallbackName = FunctionKeys<React.DOMAttributes<unknown>>;\n\n/**\n * React.SyntheticEvent contains name of a callback that should be fired, this function returns it.\n *\n * Ideally, it should also distinguish regular and \"capture\" callbacks, but it's possible only with React 17 as\n * \".eventPhase\" there has proper value, see https://github.com/facebook/react/pull/19244. In React 16 all events\n * are handled in bubble phase.\n */\nexport function getReactCallbackName(event: ReactSyntheticEvent): ReactCallbackName | undefined {\n if (event._reactName) {\n return event._reactName as ReactCallbackName;\n }\n\n if (event.dispatchConfig) {\n if (event.dispatchConfig.registrationName) {\n return event.dispatchConfig.registrationName as ReactCallbackName;\n }\n\n return event.dispatchConfig.phasedRegistrationNames.bubbled as ReactCallbackName;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error([\n 'Passed React.SyntheticEvent does not contain \".dispatchConfig\" or \"._reactName\".',\n 'This should not happen, please report it to https://github.com/microsoft/fluentui',\n ]);\n }\n}\n"]}
|