@fluentui/react-utilities 9.2.1 → 9.3.0
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 +60 -1
- package/CHANGELOG.md +21 -2
- package/dist/index.d.ts +17 -8
- 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 +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 +2 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/isHTMLElement.js +15 -0
- package/lib/utils/isHTMLElement.js.map +1 -0
- package/lib/utils/isInteractiveHTMLElement.js +26 -0
- package/lib/utils/isInteractiveHTMLElement.js.map +1 -0
- 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-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 +34 -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 +13 -0
- package/lib-amd/utils/index.js.map +1 -0
- package/lib-amd/utils/isHTMLElement.js +22 -0
- package/lib-amd/utils/isHTMLElement.js.map +1 -0
- package/lib-amd/utils/isInteractiveHTMLElement.js +25 -0
- package/lib-amd/utils/isInteractiveHTMLElement.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-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 +9 -3
- 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 +3 -1
- package/lib-commonjs/utils/index.js.map +1 -1
- package/lib-commonjs/utils/isHTMLElement.js +24 -0
- package/lib-commonjs/utils/isHTMLElement.js.map +1 -0
- package/lib-commonjs/utils/isInteractiveHTMLElement.js +36 -0
- package/lib-commonjs/utils/isInteractiveHTMLElement.js.map +1 -0
- 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/package.json +3 -4
- package/lib/utils/shouldPreventDefaultOnKeyDown.js +0 -25
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +0 -1
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +0 -35
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +0 -1
@@ -0,0 +1,36 @@
|
|
1
|
+
define(["require", "exports", "react", "./useIsomorphicLayoutEffect"], function (require, exports, React, useIsomorphicLayoutEffect_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useEventCallback = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
|
8
|
+
*
|
9
|
+
* Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
|
10
|
+
* e.g. user props are dependencies which could change on every render
|
11
|
+
* e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
|
12
|
+
*
|
13
|
+
* This should not be used often, but can be a useful re-render optimization since the callback is a ref and
|
14
|
+
* will not be invalidated between re-renders
|
15
|
+
*
|
16
|
+
* @param fn - The callback function that will be used
|
17
|
+
*/
|
18
|
+
var useEventCallback = function (fn) {
|
19
|
+
var callbackRef = React.useRef(function () {
|
20
|
+
throw new Error('Cannot call an event handler while rendering');
|
21
|
+
});
|
22
|
+
useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(function () {
|
23
|
+
callbackRef.current = fn;
|
24
|
+
}, [fn]);
|
25
|
+
return React.useCallback(function () {
|
26
|
+
var args = [];
|
27
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
28
|
+
args[_i] = arguments[_i];
|
29
|
+
}
|
30
|
+
var callback = callbackRef.current;
|
31
|
+
return callback.apply(void 0, args);
|
32
|
+
}, [callbackRef]);
|
33
|
+
};
|
34
|
+
exports.useEventCallback = useEventCallback;
|
35
|
+
});
|
36
|
+
//# sourceMappingURL=useEventCallback.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useEventCallback.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useEventCallback.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;;;;;;OAYG;IACI,IAAM,gBAAgB,GAAG,UAAiC,EAA6B;QAC5F,IAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAY;YAC1C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;QAEH,qDAAyB,CAAC;YACxB,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QAC3B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAET,OAAO,KAAK,CAAC,WAAW,CACtB;YAAC,cAAa;iBAAb,UAAa,EAAb,qBAAa,EAAb,IAAa;gBAAb,yBAAa;;YACZ,IAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;YACrC,OAAO,QAAQ,eAAI,IAAI,EAAE;QAC3B,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CAAC;IACJ,CAAC,CAAC;IAhBW,QAAA,gBAAgB,oBAgB3B","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"]}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, React) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useFirstMount = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Checks if components was mounted the first time.
|
8
|
+
* Since concurrent mode will be released in the future this needs to be verified
|
9
|
+
* Currently (React 17) will always render the initial mount once
|
10
|
+
* https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
|
11
|
+
* https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* const isFirstMount = useFirstMount();
|
15
|
+
*/
|
16
|
+
function useFirstMount() {
|
17
|
+
var isFirst = React.useRef(true);
|
18
|
+
if (isFirst.current) {
|
19
|
+
isFirst.current = false;
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
return isFirst.current;
|
23
|
+
}
|
24
|
+
exports.useFirstMount = useFirstMount;
|
25
|
+
});
|
26
|
+
//# sourceMappingURL=useFirstMount.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useFirstMount.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useFirstMount.ts"],"names":[],"mappings":";;;;IAEA;;;;;;;;;;OAUG;IACH,SAAgB,aAAa;QAC3B,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEnC,IAAI,OAAO,CAAC,OAAO,EAAE;YACnB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;YACxB,OAAO,IAAI,CAAC;SACb;QAED,OAAO,OAAO,CAAC,OAAO,CAAC;IACzB,CAAC;IATD,sCASC","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"]}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
define(["require", "exports", "react"], function (require, exports, react_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useForceUpdate = void 0;
|
5
|
+
/**
|
6
|
+
* @internal
|
7
|
+
* Forces a re-render, similar to `forceUpdate` in class components.
|
8
|
+
*/
|
9
|
+
function useForceUpdate() {
|
10
|
+
return react_1.useReducer(function (x) { return x + 1; }, 0)[1];
|
11
|
+
}
|
12
|
+
exports.useForceUpdate = useForceUpdate;
|
13
|
+
});
|
14
|
+
//# sourceMappingURL=useForceUpdate.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useForceUpdate.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useForceUpdate.ts"],"names":[],"mappings":";;;;IAEA;;;OAGG;IACH,SAAgB,cAAc;QAC5B,OAAO,kBAAU,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,GAAG,CAAC,EAAL,CAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC;IAFD,wCAEC","sourcesContent":["import { useReducer } from 'react';\n\n/**\n * @internal\n * Forces a re-render, similar to `forceUpdate` in class components.\n */\nexport function useForceUpdate() {\n return useReducer(x => x + 1, 0)[1];\n}\n"]}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
define(["require", "exports", "react", "../ssr/index"], function (require, exports, React, index_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useId = exports.resetIdsForTests = void 0;
|
5
|
+
/**
|
6
|
+
* Resets generated IDs, should be used only in tests.
|
7
|
+
*/
|
8
|
+
function resetIdsForTests() {
|
9
|
+
index_1.defaultSSRContextValue.current = 0;
|
10
|
+
}
|
11
|
+
exports.resetIdsForTests = resetIdsForTests;
|
12
|
+
/**
|
13
|
+
* Hook to generate a unique ID.
|
14
|
+
*
|
15
|
+
* @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
|
16
|
+
* @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
|
17
|
+
* without conditioning the hook call
|
18
|
+
* @returns The ID
|
19
|
+
*/
|
20
|
+
function useId(prefix, providedId) {
|
21
|
+
if (prefix === void 0) { prefix = 'fui-'; }
|
22
|
+
var contextValue = index_1.useSSRContext();
|
23
|
+
return React.useMemo(function () {
|
24
|
+
if (providedId) {
|
25
|
+
return providedId;
|
26
|
+
}
|
27
|
+
return "" + prefix + ++contextValue.current;
|
28
|
+
}, [prefix, providedId, contextValue]);
|
29
|
+
}
|
30
|
+
exports.useId = useId;
|
31
|
+
});
|
32
|
+
//# sourceMappingURL=useId.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useId.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useId.ts"],"names":[],"mappings":";;;;IAGA;;OAEG;IACH,SAAgB,gBAAgB;QAC9B,8BAAsB,CAAC,OAAO,GAAG,CAAC,CAAC;IACrC,CAAC;IAFD,4CAEC;IAED;;;;;;;OAOG;IACH,SAAgB,KAAK,CAAC,MAAuB,EAAE,UAAmB;QAA5C,uBAAA,EAAA,eAAuB;QAC3C,IAAM,YAAY,GAAG,qBAAa,EAAE,CAAC;QAErC,OAAO,KAAK,CAAC,OAAO,CAAC;YACnB,IAAI,UAAU,EAAE;gBACd,OAAO,UAAU,CAAC;aACnB;YAED,OAAO,KAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAS,CAAC;QAC9C,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IACzC,CAAC;IAVD,sBAUC","sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${prefix}${++contextValue.current}`;\n }, [prefix, providedId, contextValue]);\n}\n"]}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
define(["require", "exports", "react", "../ssr/index"], function (require, exports, React, index_1) {
|
2
|
+
"use strict";
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
exports.useIsomorphicLayoutEffect = void 0;
|
5
|
+
/**
|
6
|
+
* React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
|
7
|
+
* useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
|
8
|
+
* ensure we don't get a render flash for certain operations, but we may also need affected components to render on
|
9
|
+
* the server.
|
10
|
+
*
|
11
|
+
* https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
|
12
|
+
* https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
|
13
|
+
*/
|
14
|
+
// eslint-disable-next-line no-restricted-properties
|
15
|
+
exports.useIsomorphicLayoutEffect = index_1.canUseDOM() ? React.useLayoutEffect : React.useEffect;
|
16
|
+
});
|
17
|
+
//# sourceMappingURL=useIsomorphicLayoutEffect.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-utilities/src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;;OAQG;IACH,oDAAoD;IACvC,QAAA,yBAAyB,GAA2B,iBAAS,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC","sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"]}
|
@@ -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,34 @@
|
|
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.isInteractiveHTMLElement = exports.isHTMLElement = 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, "isHTMLElement", { enumerable: true, get: function () { return index_4.isHTMLElement; } });
|
29
|
+
Object.defineProperty(exports, "isInteractiveHTMLElement", { enumerable: true, get: function () { return index_4.isInteractiveHTMLElement; } });
|
30
|
+
Object.defineProperty(exports, "applyTriggerPropsToChildren", { enumerable: true, get: function () { return index_5.applyTriggerPropsToChildren; } });
|
31
|
+
Object.defineProperty(exports, "getTriggerChild", { enumerable: true, get: function () { return index_5.getTriggerChild; } });
|
32
|
+
Object.defineProperty(exports, "isFluentTrigger", { enumerable: true, get: function () { return index_5.isFluentTrigger; } });
|
33
|
+
});
|
34
|
+
//# 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,sGAAA,aAAa,OAAA;IACb,iHAAA,wBAAwB,OAAA;IAGjB,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 isHTMLElement,\n isInteractiveHTMLElement,\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"]}
|