@fluentui/react-utilities 9.2.1 → 9.2.2
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 +24 -1
- package/CHANGELOG.md +11 -2
- package/lib/compose/getSlots.js.map +1 -1
- package/lib/compose/index.js.map +1 -1
- package/lib/compose/isResolvedShorthand.js.map +1 -1
- package/lib/compose/resolveShorthand.js.map +1 -1
- package/lib/compose/types.js.map +1 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useControllableState.js.map +1 -1
- package/lib/hooks/useEventCallback.js.map +1 -1
- package/lib/hooks/useFirstMount.js.map +1 -1
- package/lib/hooks/useForceUpdate.js.map +1 -1
- package/lib/hooks/useId.js.map +1 -1
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib/hooks/useMergedRefs.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnScrollOutside.js.map +1 -1
- package/lib/hooks/usePrevious.js.map +1 -1
- package/lib/hooks/useTimeout.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/ssr/SSRContext.js.map +1 -1
- package/lib/ssr/canUseDOM.js.map +1 -1
- package/lib/ssr/index.js.map +1 -1
- package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib/trigger/getTriggerChild.js.map +1 -1
- package/lib/trigger/index.js.map +1 -1
- package/lib/trigger/isFluentTrigger.js.map +1 -1
- package/lib/trigger/types.js.map +1 -1
- package/lib/utils/clamp.js.map +1 -1
- package/lib/utils/getNativeElementProps.js.map +1 -1
- package/lib/utils/getRTLSafeKey.js.map +1 -1
- package/lib/utils/getReactCallbackName.js.map +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/mergeCallbacks.js.map +1 -1
- package/lib/utils/omit.js.map +1 -1
- package/lib/utils/properties.js +1 -1
- package/lib/utils/properties.js.map +1 -1
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/lib-amd/compose/getSlots.js +58 -0
- package/lib-amd/compose/getSlots.js.map +1 -0
- package/lib-amd/compose/index.js +9 -0
- package/lib-amd/compose/index.js.map +1 -0
- package/lib-amd/compose/isResolvedShorthand.js +40 -0
- package/lib-amd/compose/isResolvedShorthand.js.map +1 -0
- package/lib-amd/compose/resolveShorthand.js +27 -0
- package/lib-amd/compose/resolveShorthand.js.map +1 -0
- package/lib-amd/compose/types.js +5 -0
- package/lib-amd/compose/types.js.map +1 -0
- package/lib-amd/hooks/index.js +16 -0
- package/lib-amd/hooks/index.js.map +1 -0
- package/lib-amd/hooks/useControllableState.js +81 -0
- package/lib-amd/hooks/useControllableState.js.map +1 -0
- package/lib-amd/hooks/useEventCallback.js +36 -0
- package/lib-amd/hooks/useEventCallback.js.map +1 -0
- package/lib-amd/hooks/useFirstMount.js +26 -0
- package/lib-amd/hooks/useFirstMount.js.map +1 -0
- package/lib-amd/hooks/useForceUpdate.js +14 -0
- package/lib-amd/hooks/useForceUpdate.js.map +1 -0
- package/lib-amd/hooks/useId.js +32 -0
- package/lib-amd/hooks/useId.js.map +1 -0
- package/lib-amd/hooks/useIsomorphicLayoutEffect.js +17 -0
- package/lib-amd/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib-amd/hooks/useMergedRefs.js +34 -0
- package/lib-amd/hooks/useMergedRefs.js.map +1 -0
- package/lib-amd/hooks/useOnClickOutside.js +116 -0
- package/lib-amd/hooks/useOnClickOutside.js.map +1 -0
- package/lib-amd/hooks/useOnScrollOutside.js +31 -0
- package/lib-amd/hooks/useOnScrollOutside.js.map +1 -0
- package/lib-amd/hooks/usePrevious.js +17 -0
- package/lib-amd/hooks/usePrevious.js.map +1 -0
- package/lib-amd/hooks/useTimeout.js +33 -0
- package/lib-amd/hooks/useTimeout.js.map +1 -0
- package/lib-amd/index.js +33 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/ssr/SSRContext.js +69 -0
- package/lib-amd/ssr/SSRContext.js.map +1 -0
- package/lib-amd/ssr/canUseDOM.js +16 -0
- package/lib-amd/ssr/canUseDOM.js.map +1 -0
- package/lib-amd/ssr/index.js +7 -0
- package/lib-amd/ssr/index.js.map +1 -0
- package/lib-amd/trigger/applyTriggerPropsToChildren.js +40 -0
- package/lib-amd/trigger/applyTriggerPropsToChildren.js.map +1 -0
- package/lib-amd/trigger/getTriggerChild.js +40 -0
- package/lib-amd/trigger/getTriggerChild.js.map +1 -0
- package/lib-amd/trigger/index.js +9 -0
- package/lib-amd/trigger/index.js.map +1 -0
- package/lib-amd/trigger/isFluentTrigger.js +15 -0
- package/lib-amd/trigger/isFluentTrigger.js.map +1 -0
- package/lib-amd/trigger/types.js +5 -0
- package/lib-amd/trigger/types.js.map +1 -0
- package/lib-amd/utils/clamp.js +16 -0
- package/lib-amd/utils/clamp.js.map +1 -0
- package/lib-amd/utils/getNativeElementProps.js +64 -0
- package/lib-amd/utils/getNativeElementProps.js.map +1 -0
- package/lib-amd/utils/getRTLSafeKey.js +24 -0
- package/lib-amd/utils/getRTLSafeKey.js.map +1 -0
- package/lib-amd/utils/index.js +12 -0
- package/lib-amd/utils/index.js.map +1 -0
- package/lib-amd/utils/mergeCallbacks.js +40 -0
- package/lib-amd/utils/mergeCallbacks.js.map +1 -0
- package/lib-amd/utils/omit.js +31 -0
- package/lib-amd/utils/omit.js.map +1 -0
- package/lib-amd/utils/properties.js +450 -0
- package/lib-amd/utils/properties.js.map +1 -0
- package/lib-amd/utils/shouldPreventDefaultOnKeyDown.js +26 -0
- package/lib-amd/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
- package/lib-commonjs/compose/getSlots.js.map +1 -1
- package/lib-commonjs/compose/index.js.map +1 -1
- package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
- package/lib-commonjs/hooks/index.js.map +1 -1
- package/lib-commonjs/hooks/useControllableState.js.map +1 -1
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
- package/lib-commonjs/hooks/useId.js.map +1 -1
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
- package/lib-commonjs/hooks/usePrevious.js.map +1 -1
- package/lib-commonjs/hooks/useTimeout.js.map +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/ssr/SSRContext.js.map +1 -1
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
- package/lib-commonjs/ssr/index.js.map +1 -1
- package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
- package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
- package/lib-commonjs/trigger/index.js.map +1 -1
- package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
- package/lib-commonjs/utils/clamp.js.map +1 -1
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
- package/lib-commonjs/utils/omit.js.map +1 -1
- package/lib-commonjs/utils/properties.js +1 -1
- package/lib-commonjs/utils/properties.js.map +1 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
- package/package.json +3 -4
@@ -0,0 +1,34 @@
|
|
1
|
+
define(["require", "exports", "tslib", "react"], function (require, exports, tslib_1, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useMergedRefs = void 0;
|
5
|
+
/**
|
6
|
+
* React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
|
7
|
+
* updates all provided refs
|
8
|
+
* @param refs - Refs to collectively update with one ref value.
|
9
|
+
* @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
|
10
|
+
*/
|
11
|
+
function useMergedRefs() {
|
12
|
+
var refs = [];
|
13
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
14
|
+
refs[_i] = arguments[_i];
|
15
|
+
}
|
16
|
+
var mergedCallback = React.useCallback(function (value) {
|
17
|
+
// Update the "current" prop hanging on the function.
|
18
|
+
mergedCallback.current = value;
|
19
|
+
for (var _i = 0, refs_1 = refs; _i < refs_1.length; _i++) {
|
20
|
+
var ref = refs_1[_i];
|
21
|
+
if (typeof ref === 'function') {
|
22
|
+
ref(value);
|
23
|
+
}
|
24
|
+
else if (ref) {
|
25
|
+
// work around the immutability of the React.Ref type
|
26
|
+
ref.current = value;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}, tslib_1.__spreadArray([], refs));
|
30
|
+
return mergedCallback;
|
31
|
+
}
|
32
|
+
exports.useMergedRefs = useMergedRefs;
|
33
|
+
});
|
34
|
+
//# sourceMappingURL=useMergedRefs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useMergedRefs.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useMergedRefs.ts"],"names":[],"mappings":";;;;IAQA;;;;;OAKG;IACH,SAAgB,aAAa;QAAI,cAAqC;aAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;YAArC,yBAAqC;;QACpE,IAAM,cAAc,GAA0B,KAAK,CAAC,WAAW,CAC7D,UAAC,KAAQ;YACP,qDAAqD;YACnD,cAAwD,CAAC,OAAO,GAAG,KAAK,CAAC;YAE3E,KAAkB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE;gBAAnB,IAAM,GAAG,aAAA;gBACZ,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;oBAC7B,GAAG,CAAC,KAAK,CAAC,CAAC;iBACZ;qBAAM,IAAI,GAAG,EAAE;oBACd,qDAAqD;oBACnD,GAA6C,CAAC,OAAO,GAAG,KAAK,CAAC;iBACjE;aACF;QACH,CAAC,4BAEG,IAAI,EAC2B,CAAC;QAEtC,OAAO,cAAc,CAAC;IACxB,CAAC;IApBD,sCAoBC","sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = (React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n ((mergedCallback as unknown) as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n ((ref as unknown) as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown) as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"]}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
define(["require", "exports", "react", "./useEventCallback"], function (require, exports, React, useEventCallback_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useOnClickOutside = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
8
|
+
*/
|
9
|
+
var useOnClickOutside = function (options) {
|
10
|
+
var refs = options.refs, callback = options.callback, element = options.element, disabled = options.disabled, containsProp = options.contains;
|
11
|
+
var timeoutId = React.useRef(undefined);
|
12
|
+
useIFrameFocus(!disabled, element, callback);
|
13
|
+
var listener = useEventCallback_1.useEventCallback(function (ev) {
|
14
|
+
var contains = containsProp || (function (parent, child) { return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)); });
|
15
|
+
var isOutside = refs.every(function (ref) { return !contains(ref.current || null, ev.target); });
|
16
|
+
if (isOutside && !disabled) {
|
17
|
+
callback(ev);
|
18
|
+
}
|
19
|
+
});
|
20
|
+
React.useEffect(function () {
|
21
|
+
// Store the current event to avoid triggering handlers immediately
|
22
|
+
// Note this depends on a deprecated but extremely well supported quirk of the web platform
|
23
|
+
// https://github.com/facebook/react/issues/20074
|
24
|
+
var currentEvent = getWindowEvent(window);
|
25
|
+
var conditionalHandler = function (event) {
|
26
|
+
// Skip if this event is the same as the one running when we added the handlers
|
27
|
+
if (event === currentEvent) {
|
28
|
+
currentEvent = undefined;
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
listener(event);
|
32
|
+
};
|
33
|
+
if (!disabled) {
|
34
|
+
// use capture phase because React can update DOM before the event bubbles to the document
|
35
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
|
36
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
|
37
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
|
38
|
+
}
|
39
|
+
// Garbage collect this event after it's no longer useful to avoid memory leaks
|
40
|
+
timeoutId.current = window.setTimeout(function () {
|
41
|
+
currentEvent = undefined;
|
42
|
+
}, 1);
|
43
|
+
return function () {
|
44
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('click', conditionalHandler, true);
|
45
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('touchstart', conditionalHandler, true);
|
46
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('contextmenu', conditionalHandler, true);
|
47
|
+
clearTimeout(timeoutId.current);
|
48
|
+
currentEvent = undefined;
|
49
|
+
};
|
50
|
+
}, [listener, element, disabled]);
|
51
|
+
};
|
52
|
+
exports.useOnClickOutside = useOnClickOutside;
|
53
|
+
var getWindowEvent = function (target) {
|
54
|
+
var _a, _b, _c;
|
55
|
+
if (target) {
|
56
|
+
if (typeof target.window === 'object' && target.window === target) {
|
57
|
+
// eslint-disable-next-line deprecation/deprecation
|
58
|
+
return target.event;
|
59
|
+
}
|
60
|
+
// eslint-disable-next-line deprecation/deprecation
|
61
|
+
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;
|
62
|
+
}
|
63
|
+
return undefined;
|
64
|
+
};
|
65
|
+
var FUI_FRAME_EVENT = 'fuiframefocus';
|
66
|
+
/**
|
67
|
+
* Since click events do not propagate past iframes, we use focus to detect if a
|
68
|
+
* click has happened inside an iframe, since the only ways of focusing inside an
|
69
|
+
* iframe are:
|
70
|
+
* - clicking inside
|
71
|
+
* - tabbing inside
|
72
|
+
*
|
73
|
+
* Polls the value of `document.activeElement`. If it is an iframe, then dispatch
|
74
|
+
* a custom DOM event. When the custom event is received call the provided callback
|
75
|
+
*
|
76
|
+
* @param enableFrameFocusDispatch - boolean flag to start dispatching events
|
77
|
+
* @param targetDocument - the document to dispatch events and set timeouts
|
78
|
+
* @param pollDuration - in milliseconds
|
79
|
+
*/
|
80
|
+
var useIFrameFocus = function (enableFrameFocusDispatch, targetDocument, callback, pollDuration) {
|
81
|
+
if (pollDuration === void 0) { pollDuration = 1000; }
|
82
|
+
var timeoutRef = React.useRef();
|
83
|
+
var listener = useEventCallback_1.useEventCallback(function (e) {
|
84
|
+
if (callback) {
|
85
|
+
callback(e);
|
86
|
+
}
|
87
|
+
});
|
88
|
+
// Adds listener to the custom iframe focus event
|
89
|
+
React.useEffect(function () {
|
90
|
+
if (enableFrameFocusDispatch) {
|
91
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
|
92
|
+
}
|
93
|
+
return function () {
|
94
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
|
95
|
+
};
|
96
|
+
}, [targetDocument, enableFrameFocusDispatch, listener]);
|
97
|
+
// Starts polling for the active element
|
98
|
+
React.useEffect(function () {
|
99
|
+
var _a;
|
100
|
+
if (enableFrameFocusDispatch) {
|
101
|
+
timeoutRef.current = (_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.setInterval(function () {
|
102
|
+
var activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
|
103
|
+
if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
|
104
|
+
var event_1 = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });
|
105
|
+
activeElement.dispatchEvent(event_1);
|
106
|
+
}
|
107
|
+
}, pollDuration);
|
108
|
+
}
|
109
|
+
return function () {
|
110
|
+
var _a;
|
111
|
+
(_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.clearTimeout(timeoutRef.current);
|
112
|
+
};
|
113
|
+
}, [targetDocument, enableFrameFocusDispatch, pollDuration]);
|
114
|
+
};
|
115
|
+
});
|
116
|
+
//# sourceMappingURL=useOnClickOutside.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useOnClickOutside.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useOnClickOutside.ts"],"names":[],"mappings":"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","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"]}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
define(["require", "exports", "react", "./useEventCallback"], function (require, exports, React, useEventCallback_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useOnScrollOutside = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
8
|
+
*/
|
9
|
+
var useOnScrollOutside = function (options) {
|
10
|
+
var refs = options.refs, callback = options.callback, element = options.element, disabled = options.disabled, containsProp = options.contains;
|
11
|
+
var listener = useEventCallback_1.useEventCallback(function (ev) {
|
12
|
+
var contains = containsProp || (function (parent, child) { return !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)); });
|
13
|
+
var isOutside = refs.every(function (ref) { return !contains(ref.current || null, ev.target); });
|
14
|
+
if (isOutside && !disabled) {
|
15
|
+
callback(ev);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
React.useEffect(function () {
|
19
|
+
if (!disabled) {
|
20
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
|
21
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
|
22
|
+
}
|
23
|
+
return function () {
|
24
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);
|
25
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);
|
26
|
+
};
|
27
|
+
}, [listener, element, disabled]);
|
28
|
+
};
|
29
|
+
exports.useOnScrollOutside = useOnScrollOutside;
|
30
|
+
});
|
31
|
+
//# sourceMappingURL=useOnScrollOutside.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useOnScrollOutside.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useOnScrollOutside.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACI,IAAM,kBAAkB,GAAG,UAAC,OAAyC;QAClE,IAAA,IAAI,GAA0D,OAAO,KAAjE,EAAE,QAAQ,GAAgD,OAAO,SAAvD,EAAE,OAAO,GAAuC,OAAO,QAA9C,EAAE,QAAQ,GAA6B,OAAO,SAApC,EAAY,YAAY,GAAK,OAAO,SAAZ,CAAa;QAE9E,IAAM,QAAQ,GAAG,mCAAgB,CAAC,UAAC,EAA2B;YAC5D,IAAM,QAAQ,GACZ,YAAY,IAAI,CAAC,UAAC,MAAM,EAAE,KAAK,IAAK,OAAA,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAC,KAAK,CAAC,CAAA,EAAzB,CAAyB,CAAC,CAAC;YAEjE,IAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAA,GAAG,IAAI,OAAA,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,IAAI,IAAI,EAAE,EAAE,CAAC,MAAqB,CAAC,EAAxD,CAAwD,CAAC,CAAC;YAC9F,IAAI,SAAS,IAAI,CAAC,QAAQ,EAAE;gBAC1B,QAAQ,CAAC,EAAE,CAAC,CAAC;aACd;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,SAAS,CAAC;YACd,IAAI,CAAC,QAAQ,EAAE;gBACb,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAC7C,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;aAClD;YAED,OAAO;gBACL,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAChD,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YACtD,CAAC,CAAC;QACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IACpC,CAAC,CAAC;IAxBW,QAAA,kBAAkB,sBAwB7B","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"]}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.usePrevious = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
*/
|
8
|
+
var usePrevious = function (value) {
|
9
|
+
var ref = React.useRef(null);
|
10
|
+
React.useEffect(function () {
|
11
|
+
ref.current = value;
|
12
|
+
}, [value]);
|
13
|
+
return ref.current;
|
14
|
+
};
|
15
|
+
exports.usePrevious = usePrevious;
|
16
|
+
});
|
17
|
+
//# sourceMappingURL=usePrevious.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/usePrevious.ts"],"names":[],"mappings":";;;;IAEA;;OAEG;IACI,IAAM,WAAW,GAAG,UAAsB,KAAgB;QAC/D,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAmB,IAAI,CAAC,CAAC;QACjD,KAAK,CAAC,SAAS,CAAC;YACd,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;QACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QACZ,OAAO,GAAG,CAAC,OAAO,CAAC;IACrB,CAAC,CAAC;IANW,QAAA,WAAW,eAMtB","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"]}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useTimeout = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Helper to manage a browser timeout.
|
8
|
+
* Ensures that the timeout isn't set multiple times at once,
|
9
|
+
* and is cleaned up when the component is unloaded.
|
10
|
+
*
|
11
|
+
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
12
|
+
*/
|
13
|
+
function useTimeout() {
|
14
|
+
var timeout = React.useState(function () { return ({
|
15
|
+
id: undefined,
|
16
|
+
set: function (fn, delay) {
|
17
|
+
timeout.clear();
|
18
|
+
timeout.id = setTimeout(fn, delay);
|
19
|
+
},
|
20
|
+
clear: function () {
|
21
|
+
if (timeout.id !== undefined) {
|
22
|
+
clearTimeout(timeout.id);
|
23
|
+
timeout.id = undefined;
|
24
|
+
}
|
25
|
+
},
|
26
|
+
}); })[0];
|
27
|
+
// Clean up the timeout when the component is unloaded
|
28
|
+
React.useEffect(function () { return timeout.clear; }, [timeout]);
|
29
|
+
return [timeout.set, timeout.clear];
|
30
|
+
}
|
31
|
+
exports.useTimeout = useTimeout;
|
32
|
+
});
|
33
|
+
//# sourceMappingURL=useTimeout.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useTimeout.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useTimeout.ts"],"names":[],"mappings":";;;;IAEA;;;;;;;OAOG;IACH,SAAgB,UAAU;QACjB,IAAA,OAAO,GAAI,KAAK,CAAC,QAAQ,CAAC,cAAM,OAAA,CAAC;YACtC,EAAE,EAAE,SAAsD;YAC1D,GAAG,EAAE,UAAC,EAAc,EAAE,KAAa;gBACjC,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACrC,CAAC;YACD,KAAK,EAAE;gBACL,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE;oBAC5B,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;oBACzB,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;iBACxB;YACH,CAAC;SACF,CAAC,EAZqC,CAYrC,CAAC,GAZW,CAYV;QAEJ,sDAAsD;QACtD,KAAK,CAAC,SAAS,CAAC,cAAM,OAAA,OAAO,CAAC,KAAK,EAAb,CAAa,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QAEhD,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,CAAU,CAAC;IAC/C,CAAC;IAnBD,gCAmBC","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-amd/index.js
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
define(["require", "exports", "./compose/index", "./hooks/index", "./ssr/index", "./utils/index", "./trigger/index"], function (require, exports, index_1, index_2, index_3, index_4, index_5) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.isFluentTrigger = exports.getTriggerChild = exports.applyTriggerPropsToChildren = exports.shouldPreventDefaultOnKeyDown = exports.mergeCallbacks = exports.getRTLSafeKey = exports.getPartitionedNativeProps = exports.getNativeElementProps = exports.clamp = exports.SSRProvider = exports.useIsSSR = exports.canUseDOM = exports.useTimeout = exports.usePrevious = exports.useOnScrollOutside = exports.useOnClickOutside = exports.useMergedRefs = exports.useIsomorphicLayoutEffect = exports.useId = exports.useForceUpdate = exports.useFirstMount = exports.useEventCallback = exports.useControllableState = exports.resetIdsForTests = exports.isResolvedShorthand = exports.resolveShorthand = exports.getSlots = void 0;
|
5
|
+
Object.defineProperty(exports, "getSlots", { enumerable: true, get: function () { return index_1.getSlots; } });
|
6
|
+
Object.defineProperty(exports, "resolveShorthand", { enumerable: true, get: function () { return index_1.resolveShorthand; } });
|
7
|
+
Object.defineProperty(exports, "isResolvedShorthand", { enumerable: true, get: function () { return index_1.isResolvedShorthand; } });
|
8
|
+
Object.defineProperty(exports, "resetIdsForTests", { enumerable: true, get: function () { return index_2.resetIdsForTests; } });
|
9
|
+
Object.defineProperty(exports, "useControllableState", { enumerable: true, get: function () { return index_2.useControllableState; } });
|
10
|
+
Object.defineProperty(exports, "useEventCallback", { enumerable: true, get: function () { return index_2.useEventCallback; } });
|
11
|
+
Object.defineProperty(exports, "useFirstMount", { enumerable: true, get: function () { return index_2.useFirstMount; } });
|
12
|
+
Object.defineProperty(exports, "useForceUpdate", { enumerable: true, get: function () { return index_2.useForceUpdate; } });
|
13
|
+
Object.defineProperty(exports, "useId", { enumerable: true, get: function () { return index_2.useId; } });
|
14
|
+
Object.defineProperty(exports, "useIsomorphicLayoutEffect", { enumerable: true, get: function () { return index_2.useIsomorphicLayoutEffect; } });
|
15
|
+
Object.defineProperty(exports, "useMergedRefs", { enumerable: true, get: function () { return index_2.useMergedRefs; } });
|
16
|
+
Object.defineProperty(exports, "useOnClickOutside", { enumerable: true, get: function () { return index_2.useOnClickOutside; } });
|
17
|
+
Object.defineProperty(exports, "useOnScrollOutside", { enumerable: true, get: function () { return index_2.useOnScrollOutside; } });
|
18
|
+
Object.defineProperty(exports, "usePrevious", { enumerable: true, get: function () { return index_2.usePrevious; } });
|
19
|
+
Object.defineProperty(exports, "useTimeout", { enumerable: true, get: function () { return index_2.useTimeout; } });
|
20
|
+
Object.defineProperty(exports, "canUseDOM", { enumerable: true, get: function () { return index_3.canUseDOM; } });
|
21
|
+
Object.defineProperty(exports, "useIsSSR", { enumerable: true, get: function () { return index_3.useIsSSR; } });
|
22
|
+
Object.defineProperty(exports, "SSRProvider", { enumerable: true, get: function () { return index_3.SSRProvider; } });
|
23
|
+
Object.defineProperty(exports, "clamp", { enumerable: true, get: function () { return index_4.clamp; } });
|
24
|
+
Object.defineProperty(exports, "getNativeElementProps", { enumerable: true, get: function () { return index_4.getNativeElementProps; } });
|
25
|
+
Object.defineProperty(exports, "getPartitionedNativeProps", { enumerable: true, get: function () { return index_4.getPartitionedNativeProps; } });
|
26
|
+
Object.defineProperty(exports, "getRTLSafeKey", { enumerable: true, get: function () { return index_4.getRTLSafeKey; } });
|
27
|
+
Object.defineProperty(exports, "mergeCallbacks", { enumerable: true, get: function () { return index_4.mergeCallbacks; } });
|
28
|
+
Object.defineProperty(exports, "shouldPreventDefaultOnKeyDown", { enumerable: true, get: function () { return index_4.shouldPreventDefaultOnKeyDown; } });
|
29
|
+
Object.defineProperty(exports, "applyTriggerPropsToChildren", { enumerable: true, get: function () { return index_5.applyTriggerPropsToChildren; } });
|
30
|
+
Object.defineProperty(exports, "getTriggerChild", { enumerable: true, get: function () { return index_5.getTriggerChild; } });
|
31
|
+
Object.defineProperty(exports, "isFluentTrigger", { enumerable: true, get: function () { return index_5.isFluentTrigger; } });
|
32
|
+
});
|
33
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-utilities/src/index.ts"],"names":[],"mappings":";;;;IAAS,iGAAA,QAAQ,OAAA;IAAE,yGAAA,gBAAgB,OAAA;IAAE,4GAAA,mBAAmB,OAAA;IAiBtD,yGAAA,gBAAgB,OAAA;IAChB,6GAAA,oBAAoB,OAAA;IACpB,yGAAA,gBAAgB,OAAA;IAChB,sGAAA,aAAa,OAAA;IACb,uGAAA,cAAc,OAAA;IACd,8FAAA,KAAK,OAAA;IACL,kHAAA,yBAAyB,OAAA;IACzB,sGAAA,aAAa,OAAA;IACb,0GAAA,iBAAiB,OAAA;IACjB,2GAAA,kBAAkB,OAAA;IAClB,oGAAA,WAAW,OAAA;IACX,mGAAA,UAAU,OAAA;IAIH,kGAAA,SAAS,OAAA;IAAE,iGAAA,QAAQ,OAAA;IAAE,oGAAA,WAAW,OAAA;IAGvC,8FAAA,KAAK,OAAA;IACL,8GAAA,qBAAqB,OAAA;IACrB,kHAAA,yBAAyB,OAAA;IACzB,sGAAA,aAAa,OAAA;IACb,uGAAA,cAAc,OAAA;IACd,sHAAA,6BAA6B,OAAA;IAGtB,oHAAA,2BAA2B,OAAA;IAAE,wGAAA,eAAe,OAAA;IAAE,wGAAA,eAAe,OAAA","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 shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n"]}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
define(["require", "exports", "react", "./canUseDOM"], function (require, exports, React, canUseDOM_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useIsSSR = exports.SSRProvider = exports.useSSRContext = exports.SSRContext = exports.defaultSSRContextValue = void 0;
|
5
|
+
/**
|
6
|
+
* Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
|
7
|
+
*
|
8
|
+
* @internal
|
9
|
+
*/
|
10
|
+
exports.defaultSSRContextValue = {
|
11
|
+
current: 0,
|
12
|
+
};
|
13
|
+
exports.SSRContext = React.createContext(undefined);
|
14
|
+
/**
|
15
|
+
* @internal
|
16
|
+
*/
|
17
|
+
function useSSRContext() {
|
18
|
+
var _a;
|
19
|
+
return (_a = React.useContext(exports.SSRContext)) !== null && _a !== void 0 ? _a : exports.defaultSSRContextValue;
|
20
|
+
}
|
21
|
+
exports.useSSRContext = useSSRContext;
|
22
|
+
/**
|
23
|
+
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
24
|
+
* are consistent between the client and server.
|
25
|
+
*
|
26
|
+
* @public
|
27
|
+
*/
|
28
|
+
var SSRProvider = function (props) {
|
29
|
+
var value = React.useState(function () { return ({ current: 0 }); })[0];
|
30
|
+
return React.createElement(exports.SSRContext.Provider, { value: value }, props.children);
|
31
|
+
};
|
32
|
+
exports.SSRProvider = SSRProvider;
|
33
|
+
/**
|
34
|
+
* Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
|
35
|
+
* browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
|
36
|
+
*/
|
37
|
+
function useIsSSR() {
|
38
|
+
var isInSSRContext = useSSRContext() !== exports.defaultSSRContextValue;
|
39
|
+
var _a = React.useState(isInSSRContext), isSSR = _a[0], setIsSSR = _a[1];
|
40
|
+
// If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the
|
41
|
+
// developer to add one.
|
42
|
+
if (process.env.NODE_ENV !== 'production') {
|
43
|
+
if (!isInSSRContext && !canUseDOM_1.canUseDOM()) {
|
44
|
+
// eslint-disable-next-line no-console
|
45
|
+
console.error([
|
46
|
+
'@fluentui/react-components: ',
|
47
|
+
'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' +
|
48
|
+
'generated between the client and server.',
|
49
|
+
'\n',
|
50
|
+
'\n',
|
51
|
+
'Check documentation at https://aka.ms/fluentui-ssr',
|
52
|
+
].join(''));
|
53
|
+
}
|
54
|
+
}
|
55
|
+
// If on the client, and the component was initially server rendered, then schedule a layout effect to update the
|
56
|
+
// component after hydration.
|
57
|
+
if (canUseDOM_1.canUseDOM() && isInSSRContext) {
|
58
|
+
// This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
|
59
|
+
// mounting.
|
60
|
+
// eslint-disable-next-line
|
61
|
+
React.useLayoutEffect(function () {
|
62
|
+
setIsSSR(false);
|
63
|
+
}, []);
|
64
|
+
}
|
65
|
+
return isSSR;
|
66
|
+
}
|
67
|
+
exports.useIsSSR = useIsSSR;
|
68
|
+
});
|
69
|
+
//# sourceMappingURL=SSRContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SSRContext.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/ssr/SSRContext.tsx"],"names":[],"mappings":";;;;IAaA;;;;OAIG;IACU,QAAA,sBAAsB,GAAoB;QACrD,OAAO,EAAE,CAAC;KACX,CAAC;IAEW,QAAA,UAAU,GAAG,KAAK,CAAC,aAAa,CAA8B,SAAS,CAAmC,CAAC;IAExH;;OAEG;IACH,SAAgB,aAAa;;QAC3B,OAAO,MAAA,KAAK,CAAC,UAAU,CAAC,kBAAU,CAAC,mCAAI,8BAAsB,CAAC;IAChE,CAAC;IAFD,sCAEC;IAED;;;;;OAKG;IACI,IAAM,WAAW,GAAa,UAAA,KAAK;QACjC,IAAA,KAAK,GAAI,KAAK,CAAC,QAAQ,CAAkB,cAAM,OAAA,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAhB,CAAgB,CAAC,GAA3D,CAA4D;QAExE,OAAO,oBAAC,kBAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,KAAK,CAAC,QAAQ,CAAuB,CAAC;IACnF,CAAC,CAAC;IAJW,QAAA,WAAW,eAItB;IAEF;;;OAGG;IACH,SAAgB,QAAQ;QACtB,IAAM,cAAc,GAAG,aAAa,EAAE,KAAK,8BAAsB,CAAC;QAC5D,IAAA,KAAoB,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAjD,KAAK,QAAA,EAAE,QAAQ,QAAkC,CAAC;QAEzD,6GAA6G;QAC7G,wBAAwB;QACxB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YACzC,IAAI,CAAC,cAAc,IAAI,CAAC,qBAAS,EAAE,EAAE;gBACnC,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CACX;oBACE,8BAA8B;oBAC9B,yGAAyG;wBACvG,0CAA0C;oBAC5C,IAAI;oBACJ,IAAI;oBACJ,oDAAoD;iBACrD,CAAC,IAAI,CAAC,EAAE,CAAC,CACX,CAAC;aACH;SACF;QAED,iHAAiH;QACjH,6BAA6B;QAC7B,IAAI,qBAAS,EAAE,IAAI,cAAc,EAAE;YACjC,iHAAiH;YACjH,YAAY;YACZ,2BAA2B;YAC3B,KAAK,CAAC,eAAe,CAAC;gBACpB,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC,EAAE,EAAE,CAAC,CAAC;SACR;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAlCD,4BAkCC","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"]}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.canUseDOM = void 0;
|
5
|
+
/**
|
6
|
+
* Verifies if an application can use DOM.
|
7
|
+
*/
|
8
|
+
function canUseDOM() {
|
9
|
+
return (typeof window !== 'undefined' &&
|
10
|
+
!!(window.document &&
|
11
|
+
// eslint-disable-next-line deprecation/deprecation
|
12
|
+
window.document.createElement));
|
13
|
+
}
|
14
|
+
exports.canUseDOM = canUseDOM;
|
15
|
+
});
|
16
|
+
//# sourceMappingURL=canUseDOM.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"canUseDOM.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/ssr/canUseDOM.ts"],"names":[],"mappings":";;;;IAAA;;OAEG;IACH,SAAgB,SAAS;QACvB,OAAO,CACL,OAAO,MAAM,KAAK,WAAW;YAC7B,CAAC,CAAC,CACA,MAAM,CAAC,QAAQ;gBACf,mDAAmD;gBACnD,MAAM,CAAC,QAAQ,CAAC,aAAa,CAC9B,CACF,CAAC;IACJ,CAAC;IATD,8BASC","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"]}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./canUseDOM", "./SSRContext"], function (require, exports, tslib_1, canUseDOM_1, SSRContext_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
tslib_1.__exportStar(canUseDOM_1, exports);
|
5
|
+
tslib_1.__exportStar(SSRContext_1, exports);
|
6
|
+
});
|
7
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/ssr/index.ts"],"names":[],"mappings":";;;IAAA,2CAA4B;IAC5B,4CAA6B","sourcesContent":["export * from './canUseDOM';\nexport * from './SSRContext';\n"]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
define(["require", "exports", "react", "./isFluentTrigger"], function (require, exports, React, isFluentTrigger_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.applyTriggerPropsToChildren = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* resolve the trigger props to the children, either by calling the render function, or cloning with the new props.
|
8
|
+
*/
|
9
|
+
function applyTriggerPropsToChildren(children, triggerChildProps) {
|
10
|
+
if (typeof children === 'function') {
|
11
|
+
return children(triggerChildProps);
|
12
|
+
}
|
13
|
+
else if (children) {
|
14
|
+
return cloneTriggerTree(children, triggerChildProps);
|
15
|
+
}
|
16
|
+
// Components in React should return either JSX elements or "null", otherwise React will throw:
|
17
|
+
// Nothing was returned from render.
|
18
|
+
// This usually means a return statement is missing. Or, to render nothing, return null.
|
19
|
+
return children || null;
|
20
|
+
}
|
21
|
+
exports.applyTriggerPropsToChildren = applyTriggerPropsToChildren;
|
22
|
+
/**
|
23
|
+
* Clones a React element tree, and applies the given props to the first grandchild that is not
|
24
|
+
* a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
|
25
|
+
*/
|
26
|
+
function cloneTriggerTree(child, triggerProps) {
|
27
|
+
if (!React.isValidElement(child) || child.type === React.Fragment) {
|
28
|
+
throw new Error('A trigger element must be a single element for this component. ' +
|
29
|
+
"Please ensure that you're not using React Fragments.");
|
30
|
+
}
|
31
|
+
if (isFluentTrigger_1.isFluentTrigger(child)) {
|
32
|
+
var grandchild = cloneTriggerTree(child.props.children, triggerProps);
|
33
|
+
return React.cloneElement(child, undefined, grandchild);
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
return React.cloneElement(child, triggerProps);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
});
|
40
|
+
//# sourceMappingURL=applyTriggerPropsToChildren.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"applyTriggerPropsToChildren.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACH,SAAgB,2BAA2B,CACzC,QAAqD,EACrD,iBAAoC;QAEpC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAClC,OAAO,QAAQ,CAAC,iBAAiB,CAAC,CAAC;SACpC;aAAM,IAAI,QAAQ,EAAE;YACnB,OAAO,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;SACtD;QAED,+FAA+F;QAC/F,sCAAsC;QACtC,0FAA0F;QAC1F,OAAO,QAAQ,IAAI,IAAI,CAAC;IAC1B,CAAC;IAdD,kEAcC;IAED;;;OAGG;IACH,SAAS,gBAAgB,CACvB,KAAsB,EACtB,YAA+B;QAE/B,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,QAAQ,EAAE;YACjE,MAAM,IAAI,KAAK,CACb,iEAAiE;gBAC/D,sDAAsD,CACzD,CAAC;SACH;QAED,IAAI,iCAAe,CAAC,KAAK,CAAC,EAAE;YAC1B,IAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YACxE,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;SACzD;aAAM;YACL,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE,YAAoD,CAAC,CAAC;SACxF;IACH,CAAC","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"]}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
define(["require", "exports", "react", "./isFluentTrigger"], function (require, exports, React, isFluentTrigger_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.getTriggerChild = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).
|
8
|
+
*
|
9
|
+
* In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,
|
10
|
+
* it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.
|
11
|
+
* This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.
|
12
|
+
*
|
13
|
+
* For example, the following returns `<div id="child" />`:
|
14
|
+
* ```jsx
|
15
|
+
* getTriggerChild(
|
16
|
+
* <Tooltip>
|
17
|
+
* <MenuTrigger>
|
18
|
+
* <div id="child" />
|
19
|
+
* </MenuTrigger>
|
20
|
+
* </Tooltip>
|
21
|
+
* );
|
22
|
+
* ```
|
23
|
+
*
|
24
|
+
* In the case where the immediate child is not a valid element,
|
25
|
+
* null is returned
|
26
|
+
*/
|
27
|
+
function getTriggerChild(children) {
|
28
|
+
if (!React.isValidElement(children)) {
|
29
|
+
return null;
|
30
|
+
}
|
31
|
+
return isFluentTrigger_1.isFluentTrigger(children)
|
32
|
+
? getTriggerChild(
|
33
|
+
// FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,
|
34
|
+
// but for some reason it's failing on build
|
35
|
+
children.props.children)
|
36
|
+
: children;
|
37
|
+
}
|
38
|
+
exports.getTriggerChild = getTriggerChild;
|
39
|
+
});
|
40
|
+
//# sourceMappingURL=getTriggerChild.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getTriggerChild.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/trigger/getTriggerChild.ts"],"names":[],"mappings":";;;;IAIA;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAgB,eAAe,CAC7B,QAAqD;QAGrD,IAAI,CAAC,KAAK,CAAC,cAAc,CAAoB,QAAQ,CAAC,EAAE;YACtD,OAAO,IAAI,CAAC;SACb;QACD,OAAO,iCAAe,CAAC,QAAQ,CAAC;YAC9B,CAAC,CAAC,eAAe;YACb,uFAAuF;YACvF,4CAA4C;YAC3C,QAAQ,CAAC,KAAsB,CAAC,QAAQ,CAC1C;YACH,CAAC,CAAC,QAAQ,CAAC;IACf,CAAC;IAdD,0CAcC","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"]}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
define(["require", "exports", "tslib", "./applyTriggerPropsToChildren", "./getTriggerChild", "./isFluentTrigger", "./types"], function (require, exports, tslib_1, applyTriggerPropsToChildren_1, getTriggerChild_1, isFluentTrigger_1, types_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
tslib_1.__exportStar(applyTriggerPropsToChildren_1, exports);
|
5
|
+
tslib_1.__exportStar(getTriggerChild_1, exports);
|
6
|
+
tslib_1.__exportStar(isFluentTrigger_1, exports);
|
7
|
+
tslib_1.__exportStar(types_1, exports);
|
8
|
+
});
|
9
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/trigger/index.ts"],"names":[],"mappings":";;;IAAA,6DAA8C;IAC9C,iDAAkC;IAClC,iDAAkC;IAClC,uCAAwB","sourcesContent":["export * from './applyTriggerPropsToChildren';\nexport * from './getTriggerChild';\nexport * from './isFluentTrigger';\nexport * from './types';\n"]}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.isFluentTrigger = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).
|
8
|
+
* See the {@link FluentTriggerComponent} type for more info.
|
9
|
+
*/
|
10
|
+
function isFluentTrigger(element) {
|
11
|
+
return Boolean(element.type.isFluentTriggerComponent);
|
12
|
+
}
|
13
|
+
exports.isFluentTrigger = isFluentTrigger;
|
14
|
+
});
|
15
|
+
//# sourceMappingURL=isFluentTrigger.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"isFluentTrigger.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/trigger/isFluentTrigger.ts"],"names":[],"mappings":";;;;IAGA;;;;OAIG;IACH,SAAgB,eAAe,CAAC,OAA2B;QACzD,OAAO,OAAO,CAAE,OAAO,CAAC,IAA+B,CAAC,wBAAwB,CAAC,CAAC;IACpF,CAAC;IAFD,0CAEC","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"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/trigger/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Allows a component to be tagged as a FluentUI trigger component.\n *\n * Triggers are special-case components: they attach event listeners and other props on their child,\n * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.\n *\n * A component can be tagged as a trigger as follows:\n * ```ts\n * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;\n *\n * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true\n * ```\n */\nexport type FluentTriggerComponent = {\n isFluentTriggerComponent?: boolean;\n};\n\n/**\n * A trigger may have a children that could be either:\n * 1. A single element\n * 2. A render function that will receive properties and must return a valid element or null\n * 3. null or undefined\n */\nexport type TriggerProps<TriggerChildProps = unknown> = {\n children?: React.ReactElement | ((props: TriggerChildProps) => React.ReactElement | null) | null;\n};\n"]}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.clamp = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Clamps `value` to a number between the min and max.
|
8
|
+
*
|
9
|
+
* @param value - the value to be clamped
|
10
|
+
* @param min - the lowest valid value
|
11
|
+
* @param max - the highest valid value
|
12
|
+
*/
|
13
|
+
var clamp = function (value, min, max) { return Math.max(min, Math.min(max, value || 0)); };
|
14
|
+
exports.clamp = clamp;
|
15
|
+
});
|
16
|
+
//# sourceMappingURL=clamp.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"clamp.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/utils/clamp.ts"],"names":[],"mappings":";;;;IAAA;;;;;;;OAOG;IACI,IAAM,KAAK,GAAG,UAAC,KAAa,EAAE,GAAW,EAAE,GAAW,IAAa,OAAA,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,EAAxC,CAAwC,CAAC;IAAtG,QAAA,KAAK,SAAiG","sourcesContent":["/**\n * @internal\n * Clamps `value` to a number between the min and max.\n *\n * @param value - the value to be clamped\n * @param min - the lowest valid value\n * @param max - the highest valid value\n */\nexport const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(max, value || 0));\n"]}
|