@fluentui/react-utilities 0.0.0-nightly-20220302-0405.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +1844 -0
- package/CHANGELOG.md +736 -0
- package/LICENSE +15 -0
- package/README.md +5 -0
- package/dist/react-utilities.d.ts +782 -0
- package/lib/compose/getSlots.d.ts +30 -0
- package/lib/compose/getSlots.js +63 -0
- package/lib/compose/getSlots.js.map +1 -0
- package/lib/compose/index.d.ts +3 -0
- package/lib/compose/index.js +4 -0
- package/lib/compose/index.js.map +1 -0
- package/lib/compose/resolveShorthand.d.ts +16 -0
- package/lib/compose/resolveShorthand.js +31 -0
- package/lib/compose/resolveShorthand.js.map +1 -0
- package/lib/compose/types.d.ts +155 -0
- package/lib/compose/types.js +6 -0
- package/lib/compose/types.js.map +1 -0
- package/lib/hooks/index.d.ts +16 -0
- package/lib/hooks/index.js +17 -0
- package/lib/hooks/index.js.map +1 -0
- package/lib/hooks/useBoolean.d.ts +17 -0
- package/lib/hooks/useBoolean.js +28 -0
- package/lib/hooks/useBoolean.js.map +1 -0
- package/lib/hooks/useConst.d.ts +12 -0
- package/lib/hooks/useConst.js +30 -0
- package/lib/hooks/useConst.js.map +1 -0
- package/lib/hooks/useControllableState.d.ts +31 -0
- package/lib/hooks/useControllableState.js +73 -0
- package/lib/hooks/useControllableState.js.map +1 -0
- package/lib/hooks/useEventCallback.d.ts +13 -0
- package/lib/hooks/useEventCallback.js +28 -0
- package/lib/hooks/useEventCallback.js.map +1 -0
- package/lib/hooks/useFirstMount.d.ts +11 -0
- package/lib/hooks/useFirstMount.js +23 -0
- package/lib/hooks/useFirstMount.js.map +1 -0
- package/lib/hooks/useForceUpdate.d.ts +4 -0
- package/lib/hooks/useForceUpdate.js +9 -0
- package/lib/hooks/useForceUpdate.js.map +1 -0
- package/lib/hooks/useId.d.ts +15 -0
- package/lib/hooks/useId.js +31 -0
- package/lib/hooks/useId.js.map +1 -0
- package/lib/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
- package/lib/hooks/useIsomorphicLayoutEffect.js +15 -0
- package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
- package/lib/hooks/useMergedEventCallbacks.js +26 -0
- package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
- package/lib/hooks/useMergedRefs.d.ts +13 -0
- package/lib/hooks/useMergedRefs.js +26 -0
- package/lib/hooks/useMergedRefs.js.map +1 -0
- package/lib/hooks/useMount.d.ts +6 -0
- package/lib/hooks/useMount.js +17 -0
- package/lib/hooks/useMount.js.map +1 -0
- package/lib/hooks/useOnClickOutside.d.ts +29 -0
- package/lib/hooks/useOnClickOutside.js +136 -0
- package/lib/hooks/useOnClickOutside.js.map +1 -0
- package/lib/hooks/useOnScrollOutside.d.ts +5 -0
- package/lib/hooks/useOnScrollOutside.js +36 -0
- package/lib/hooks/useOnScrollOutside.js.map +1 -0
- package/lib/hooks/usePrevious.d.ts +1 -0
- package/lib/hooks/usePrevious.js +9 -0
- package/lib/hooks/usePrevious.js.map +1 -0
- package/lib/hooks/useTimeout.d.ts +8 -0
- package/lib/hooks/useTimeout.js +29 -0
- package/lib/hooks/useTimeout.js.map +1 -0
- package/lib/hooks/useUnmount.d.ts +6 -0
- package/lib/hooks/useUnmount.js +17 -0
- package/lib/hooks/useUnmount.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/ssr/SSRContext.d.ts +33 -0
- package/lib/ssr/SSRContext.js +65 -0
- package/lib/ssr/SSRContext.js.map +1 -0
- package/lib/ssr/canUseDOM.d.ts +4 -0
- package/lib/ssr/canUseDOM.js +8 -0
- package/lib/ssr/canUseDOM.js.map +1 -0
- package/lib/ssr/index.d.ts +2 -0
- package/lib/ssr/index.js +3 -0
- package/lib/ssr/index.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/utils/applyTriggerPropsToChildren.d.ts +5 -0
- package/lib/utils/applyTriggerPropsToChildren.js +36 -0
- package/lib/utils/applyTriggerPropsToChildren.js.map +1 -0
- package/lib/utils/clamp.d.ts +8 -0
- package/lib/utils/clamp.js +9 -0
- package/lib/utils/clamp.js.map +1 -0
- package/lib/utils/getNativeElementProps.d.ts +31 -0
- package/lib/utils/getNativeElementProps.js +61 -0
- package/lib/utils/getNativeElementProps.js.map +1 -0
- package/lib/utils/getRTLSafeKey.d.ts +4 -0
- package/lib/utils/getRTLSafeKey.js +21 -0
- package/lib/utils/getRTLSafeKey.js.map +1 -0
- package/lib/utils/getReactCallbackName.d.ts +25 -0
- package/lib/utils/getReactCallbackName.js +26 -0
- package/lib/utils/getReactCallbackName.js.map +1 -0
- package/lib/utils/getTriggerChild.d.ts +22 -0
- package/lib/utils/getTriggerChild.js +26 -0
- package/lib/utils/getTriggerChild.js.map +1 -0
- package/lib/utils/index.d.ts +9 -0
- package/lib/utils/index.js +10 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/isFluentTrigger.d.ts +22 -0
- package/lib/utils/isFluentTrigger.js +8 -0
- package/lib/utils/isFluentTrigger.js.map +1 -0
- package/lib/utils/omit.d.ts +14 -0
- package/lib/utils/omit.js +27 -0
- package/lib/utils/omit.js.map +1 -0
- package/lib/utils/properties.d.ts +154 -0
- package/lib/utils/properties.js +237 -0
- package/lib/utils/properties.js.map +1 -0
- package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
- package/lib/utils/shouldPreventDefaultOnKeyDown.js +24 -0
- package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
- package/lib-commonjs/compose/getSlots.d.ts +30 -0
- package/lib-commonjs/compose/getSlots.js +74 -0
- package/lib-commonjs/compose/getSlots.js.map +1 -0
- package/lib-commonjs/compose/index.d.ts +3 -0
- package/lib-commonjs/compose/index.js +14 -0
- package/lib-commonjs/compose/index.js.map +1 -0
- package/lib-commonjs/compose/resolveShorthand.d.ts +16 -0
- package/lib-commonjs/compose/resolveShorthand.js +41 -0
- package/lib-commonjs/compose/resolveShorthand.js.map +1 -0
- package/lib-commonjs/compose/types.d.ts +155 -0
- package/lib-commonjs/compose/types.js +10 -0
- package/lib-commonjs/compose/types.js.map +1 -0
- package/lib-commonjs/hooks/index.d.ts +16 -0
- package/lib-commonjs/hooks/index.js +40 -0
- package/lib-commonjs/hooks/index.js.map +1 -0
- package/lib-commonjs/hooks/useBoolean.d.ts +17 -0
- package/lib-commonjs/hooks/useBoolean.js +39 -0
- package/lib-commonjs/hooks/useBoolean.js.map +1 -0
- package/lib-commonjs/hooks/useConst.d.ts +12 -0
- package/lib-commonjs/hooks/useConst.js +40 -0
- package/lib-commonjs/hooks/useConst.js.map +1 -0
- package/lib-commonjs/hooks/useControllableState.d.ts +31 -0
- package/lib-commonjs/hooks/useControllableState.js +83 -0
- package/lib-commonjs/hooks/useControllableState.js.map +1 -0
- package/lib-commonjs/hooks/useEventCallback.d.ts +13 -0
- package/lib-commonjs/hooks/useEventCallback.js +39 -0
- package/lib-commonjs/hooks/useEventCallback.js.map +1 -0
- package/lib-commonjs/hooks/useFirstMount.d.ts +11 -0
- package/lib-commonjs/hooks/useFirstMount.js +33 -0
- package/lib-commonjs/hooks/useFirstMount.js.map +1 -0
- package/lib-commonjs/hooks/useForceUpdate.d.ts +4 -0
- package/lib-commonjs/hooks/useForceUpdate.js +19 -0
- package/lib-commonjs/hooks/useForceUpdate.js.map +1 -0
- package/lib-commonjs/hooks/useId.d.ts +15 -0
- package/lib-commonjs/hooks/useId.js +44 -0
- package/lib-commonjs/hooks/useId.js.map +1 -0
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +24 -0
- package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
- package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
- package/lib-commonjs/hooks/useMergedRefs.d.ts +13 -0
- package/lib-commonjs/hooks/useMergedRefs.js +36 -0
- package/lib-commonjs/hooks/useMergedRefs.js.map +1 -0
- package/lib-commonjs/hooks/useMount.d.ts +6 -0
- package/lib-commonjs/hooks/useMount.js +27 -0
- package/lib-commonjs/hooks/useMount.js.map +1 -0
- package/lib-commonjs/hooks/useOnClickOutside.d.ts +29 -0
- package/lib-commonjs/hooks/useOnClickOutside.js +147 -0
- package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -0
- package/lib-commonjs/hooks/useOnScrollOutside.d.ts +5 -0
- package/lib-commonjs/hooks/useOnScrollOutside.js +47 -0
- package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -0
- package/lib-commonjs/hooks/usePrevious.d.ts +1 -0
- package/lib-commonjs/hooks/usePrevious.js +19 -0
- package/lib-commonjs/hooks/usePrevious.js.map +1 -0
- package/lib-commonjs/hooks/useTimeout.d.ts +8 -0
- package/lib-commonjs/hooks/useTimeout.js +40 -0
- package/lib-commonjs/hooks/useTimeout.js.map +1 -0
- package/lib-commonjs/hooks/useUnmount.d.ts +6 -0
- package/lib-commonjs/hooks/useUnmount.js +27 -0
- package/lib-commonjs/hooks/useUnmount.js.map +1 -0
- package/lib-commonjs/index.d.ts +4 -0
- package/lib-commonjs/index.js +16 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/ssr/SSRContext.d.ts +33 -0
- package/lib-commonjs/ssr/SSRContext.js +80 -0
- package/lib-commonjs/ssr/SSRContext.js.map +1 -0
- package/lib-commonjs/ssr/canUseDOM.d.ts +4 -0
- package/lib-commonjs/ssr/canUseDOM.js +17 -0
- package/lib-commonjs/ssr/canUseDOM.js.map +1 -0
- package/lib-commonjs/ssr/index.d.ts +2 -0
- package/lib-commonjs/ssr/index.js +12 -0
- package/lib-commonjs/ssr/index.js.map +1 -0
- package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +5 -0
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js +47 -0
- package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -0
- package/lib-commonjs/utils/clamp.d.ts +8 -0
- package/lib-commonjs/utils/clamp.js +18 -0
- package/lib-commonjs/utils/clamp.js.map +1 -0
- package/lib-commonjs/utils/getNativeElementProps.d.ts +31 -0
- package/lib-commonjs/utils/getNativeElementProps.js +73 -0
- package/lib-commonjs/utils/getNativeElementProps.js.map +1 -0
- package/lib-commonjs/utils/getRTLSafeKey.d.ts +4 -0
- package/lib-commonjs/utils/getRTLSafeKey.js +30 -0
- package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -0
- package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
- package/lib-commonjs/utils/getReactCallbackName.js +35 -0
- package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
- package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
- package/lib-commonjs/utils/getTriggerChild.js +37 -0
- package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
- package/lib-commonjs/utils/index.d.ts +9 -0
- package/lib-commonjs/utils/index.js +26 -0
- package/lib-commonjs/utils/index.js.map +1 -0
- package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
- package/lib-commonjs/utils/isFluentTrigger.js +17 -0
- package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
- package/lib-commonjs/utils/omit.d.ts +14 -0
- package/lib-commonjs/utils/omit.js +36 -0
- package/lib-commonjs/utils/omit.js.map +1 -0
- package/lib-commonjs/utils/properties.d.ts +154 -0
- package/lib-commonjs/utils/properties.js +246 -0
- package/lib-commonjs/utils/properties.js.map +1 -0
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +34 -0
- package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
- package/package.json +50 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useOnScrollOutside = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const useEventCallback_1 = /*#__PURE__*/require("./useEventCallback");
|
11
|
+
/**
|
12
|
+
* Utility to perform checks where a click/touch event was made outside a component
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
const useOnScrollOutside = options => {
|
17
|
+
const {
|
18
|
+
refs,
|
19
|
+
callback,
|
20
|
+
element,
|
21
|
+
disabled,
|
22
|
+
contains: containsProp
|
23
|
+
} = options;
|
24
|
+
const listener = useEventCallback_1.useEventCallback(ev => {
|
25
|
+
const contains = containsProp || ((parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
|
26
|
+
|
27
|
+
const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));
|
28
|
+
|
29
|
+
if (isOutside && !disabled) {
|
30
|
+
callback(ev);
|
31
|
+
}
|
32
|
+
});
|
33
|
+
React.useEffect(() => {
|
34
|
+
if (!disabled) {
|
35
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('wheel', listener);
|
36
|
+
element === null || element === void 0 ? void 0 : element.addEventListener('touchmove', listener);
|
37
|
+
}
|
38
|
+
|
39
|
+
return () => {
|
40
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('wheel', listener);
|
41
|
+
element === null || element === void 0 ? void 0 : element.removeEventListener('touchmove', listener);
|
42
|
+
};
|
43
|
+
}, [listener, element, disabled]);
|
44
|
+
};
|
45
|
+
|
46
|
+
exports.useOnScrollOutside = useOnScrollOutside;
|
47
|
+
//# sourceMappingURL=useOnScrollOutside.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useOnScrollOutside.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,kBAAA,gBAAA,OAAA,CAAA,oBAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,kBAAkB,GAAI,OAAD,IAA8C;AAC9E,QAAM;AAAE,IAAA,IAAF;AAAQ,IAAA,QAAR;AAAkB,IAAA,OAAlB;AAA2B,IAAA,QAA3B;AAAqC,IAAA,QAAQ,EAAE;AAA/C,MAAgE,OAAtE;AAEA,QAAM,QAAQ,GAAG,kBAAA,CAAA,gBAAA,CAAkB,EAAD,IAAgC;AAChE,UAAM,QAAQ,GACZ,YAAY,KAAK,CAAC,MAAD,EAAS,KAAT,KAAmB,CAAC,EAAC,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,QAAR,CAAiB,KAAjB,CAAD,CAAzB,CADd;;AAGA,UAAM,SAAS,GAAG,IAAI,CAAC,KAAL,CAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAJ,IAAe,IAAhB,EAAsB,EAAE,CAAC,MAAzB,CAA3B,CAAlB;;AACA,QAAI,SAAS,IAAI,CAAC,QAAlB,EAA4B;AAC1B,MAAA,QAAQ,CAAC,EAAD,CAAR;AACD;AACF,GARgB,CAAjB;AAUA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,QAAI,CAAC,QAAL,EAAe;AACb,MAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,gBAAT,CAA0B,OAA1B,EAAmC,QAAnC,CAAA;AACA,MAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,gBAAT,CAA0B,WAA1B,EAAuC,QAAvC,CAAA;AACD;;AAED,WAAO,MAAK;AACV,MAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,mBAAT,CAA6B,OAA7B,EAAsC,QAAtC,CAAA;AACA,MAAA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,mBAAT,CAA6B,WAA7B,EAA0C,QAA1C,CAAA;AACD,KAHD;AAID,GAVD,EAUG,CAAC,QAAD,EAAW,OAAX,EAAoB,QAApB,CAVH;AAWD,CAxBM;;AAAM,OAAA,CAAA,kBAAA,GAAkB,kBAAlB","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const usePrevious: <ValueType = unknown>(value: ValueType) => ValueType | null;
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.usePrevious = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const usePrevious = value => {
|
11
|
+
const ref = React.useRef(null);
|
12
|
+
React.useEffect(() => {
|
13
|
+
ref.current = value;
|
14
|
+
}, [value]);
|
15
|
+
return ref.current;
|
16
|
+
};
|
17
|
+
|
18
|
+
exports.usePrevious = usePrevious;
|
19
|
+
//# sourceMappingURL=usePrevious.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/usePrevious.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAEO,MAAM,WAAW,GAAyB,KAAtB,IAA0C;AACnE,QAAM,GAAG,GAAG,KAAK,CAAC,MAAN,CAA+B,IAA/B,CAAZ;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,IAAA,GAAG,CAAC,OAAJ,GAAc,KAAd;AACD,GAFD,EAEG,CAAC,KAAD,CAFH;AAGA,SAAO,GAAG,CAAC,OAAX;AACD,CANM;;AAAM,OAAA,CAAA,WAAA,GAAW,WAAX","sourcesContent":["import * as React from 'react';\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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Helper to manage a browser timeout.
|
3
|
+
* Ensures that the timeout isn't set multiple times at once,
|
4
|
+
* and is cleaned up when the component is unloaded.
|
5
|
+
*
|
6
|
+
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
7
|
+
*/
|
8
|
+
export declare function useTimeout(): readonly [(fn: () => void, delay: number) => void, () => void];
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useTimeout = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const useConst_1 = /*#__PURE__*/require("./useConst");
|
11
|
+
/**
|
12
|
+
* Helper to manage a browser timeout.
|
13
|
+
* Ensures that the timeout isn't set multiple times at once,
|
14
|
+
* and is cleaned up when the component is unloaded.
|
15
|
+
*
|
16
|
+
* @returns A pair of [setTimeout, clearTimeout] that are stable between renders.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
function useTimeout() {
|
21
|
+
const timeout = useConst_1.useConst(() => ({
|
22
|
+
id: undefined,
|
23
|
+
set: (fn, delay) => {
|
24
|
+
timeout.clear();
|
25
|
+
timeout.id = setTimeout(fn, delay);
|
26
|
+
},
|
27
|
+
clear: () => {
|
28
|
+
if (timeout.id !== undefined) {
|
29
|
+
clearTimeout(timeout.id);
|
30
|
+
timeout.id = undefined;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
})); // Clean up the timeout when the component is unloaded
|
34
|
+
|
35
|
+
React.useEffect(() => timeout.clear, [timeout]);
|
36
|
+
return [timeout.set, timeout.clear];
|
37
|
+
}
|
38
|
+
|
39
|
+
exports.useTimeout = useTimeout;
|
40
|
+
//# sourceMappingURL=useTimeout.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useTimeout.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;AAEA;;;;;;AAMG;;;AACH,SAAgB,UAAhB,GAA0B;AACxB,QAAM,OAAO,GAAG,UAAA,CAAA,QAAA,CAAS,OAAO;AAC9B,IAAA,EAAE,EAAE,SAD0B;AAE9B,IAAA,GAAG,EAAE,CAAC,EAAD,EAAiB,KAAjB,KAAkC;AACrC,MAAA,OAAO,CAAC,KAAR;AACA,MAAA,OAAO,CAAC,EAAR,GAAa,UAAU,CAAC,EAAD,EAAK,KAAL,CAAvB;AACD,KAL6B;AAM9B,IAAA,KAAK,EAAE,MAAK;AACV,UAAI,OAAO,CAAC,EAAR,KAAe,SAAnB,EAA8B;AAC5B,QAAA,YAAY,CAAC,OAAO,CAAC,EAAT,CAAZ;AACA,QAAA,OAAO,CAAC,EAAR,GAAa,SAAb;AACD;AACF;AAX6B,GAAP,CAAT,CAAhB,CADwB,CAexB;;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAM,OAAO,CAAC,KAA9B,EAAqC,CAAC,OAAD,CAArC;AAEA,SAAO,CAAC,OAAO,CAAC,GAAT,EAAc,OAAO,CAAC,KAAtB,CAAP;AACD;;AAnBD,OAAA,CAAA,UAAA,GAAA,UAAA","sourcesContent":["import * as React from 'react';\nimport { useConst } from './useConst';\n\n/**\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 = useConst(() => ({\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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useUnmount = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
/**
|
10
|
+
* Hook which synchronously executes a callback when the component is about to unmount.
|
11
|
+
*
|
12
|
+
* @param callback - Function to call during unmount.
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
const useUnmount = callback => {
|
17
|
+
const unmountRef = React.useRef(callback);
|
18
|
+
unmountRef.current = callback;
|
19
|
+
React.useEffect(() => () => {
|
20
|
+
var _a;
|
21
|
+
|
22
|
+
(_a = unmountRef.current) === null || _a === void 0 ? void 0 : _a.call(unmountRef);
|
23
|
+
}, []);
|
24
|
+
};
|
25
|
+
|
26
|
+
exports.useUnmount = useUnmount;
|
27
|
+
//# sourceMappingURL=useUnmount.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["hooks/useUnmount.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;AAIG;;;AACI,MAAM,UAAU,GAAI,QAAD,IAAyB;AACjD,QAAM,UAAU,GAAG,KAAK,CAAC,MAAN,CAAa,QAAb,CAAnB;AACA,EAAA,UAAU,CAAC,OAAX,GAAqB,QAArB;AACA,EAAA,KAAK,CAAC,SAAN,CACE,MAAM,MAAK;;;AACT,KAAA,EAAA,GAAA,UAAU,CAAC,OAAX,MAAkB,IAAlB,IAAkB,EAAA,KAAA,KAAA,CAAlB,GAAkB,KAAA,CAAlB,GAAkB,EAAA,CAAA,IAAA,CAAlB,UAAkB,CAAlB;AACD,GAHH,EAIE,EAJF;AAMD,CATM;;AAAM,OAAA,CAAA,UAAA,GAAU,UAAV","sourcesContent":["import * as React from 'react';\n\n/**\n * Hook which synchronously executes a callback when the component is about to unmount.\n *\n * @param callback - Function to call during unmount.\n */\nexport const useUnmount = (callback: () => void) => {\n const unmountRef = React.useRef(callback);\n unmountRef.current = callback;\n React.useEffect(\n () => () => {\n unmountRef.current?.();\n },\n [],\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
|
+
|
9
|
+
tslib_1.__exportStar(require("./compose/index"), exports);
|
10
|
+
|
11
|
+
tslib_1.__exportStar(require("./hooks/index"), exports);
|
12
|
+
|
13
|
+
tslib_1.__exportStar(require("./ssr/index"), exports);
|
14
|
+
|
15
|
+
tslib_1.__exportStar(require("./utils/index"), exports);
|
16
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './compose/index';\nexport * from './hooks/index';\nexport * from './ssr/index';\nexport * from './utils/index';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
/**
|
3
|
+
* To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request
|
4
|
+
* to ensure the client and server are consistent.
|
5
|
+
*
|
6
|
+
* @internal
|
7
|
+
*/
|
8
|
+
export declare type SSRContextValue = {
|
9
|
+
current: number;
|
10
|
+
};
|
11
|
+
/**
|
12
|
+
* Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
|
13
|
+
*
|
14
|
+
* @internal
|
15
|
+
*/
|
16
|
+
export declare const defaultSSRContextValue: SSRContextValue;
|
17
|
+
export declare const SSRContext: React.Context<SSRContextValue>;
|
18
|
+
/**
|
19
|
+
* @internal
|
20
|
+
*/
|
21
|
+
export declare function useSSRContext(): SSRContextValue;
|
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
|
+
export declare const SSRProvider: React.FC;
|
29
|
+
/**
|
30
|
+
* Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
|
31
|
+
* browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
|
32
|
+
*/
|
33
|
+
export declare function useIsSSR(): boolean;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useIsSSR = exports.SSRProvider = exports.useSSRContext = exports.SSRContext = exports.defaultSSRContextValue = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const canUseDOM_1 = /*#__PURE__*/require("./canUseDOM");
|
11
|
+
/**
|
12
|
+
* Default context value to use in case there is no SSRProvider. This is fine for client-only apps.
|
13
|
+
*
|
14
|
+
* @internal
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
exports.defaultSSRContextValue = {
|
19
|
+
current: 0
|
20
|
+
};
|
21
|
+
exports.SSRContext = /*#__PURE__*/React.createContext(exports.defaultSSRContextValue);
|
22
|
+
/**
|
23
|
+
* @internal
|
24
|
+
*/
|
25
|
+
|
26
|
+
function useSSRContext() {
|
27
|
+
return React.useContext(exports.SSRContext);
|
28
|
+
}
|
29
|
+
|
30
|
+
exports.useSSRContext = useSSRContext;
|
31
|
+
/**
|
32
|
+
* When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids
|
33
|
+
* are consistent between the client and server.
|
34
|
+
*
|
35
|
+
* @public
|
36
|
+
*/
|
37
|
+
|
38
|
+
const SSRProvider = props => {
|
39
|
+
const [value] = React.useState(() => ({
|
40
|
+
current: 0
|
41
|
+
}));
|
42
|
+
return React.createElement(exports.SSRContext.Provider, {
|
43
|
+
value: value
|
44
|
+
}, props.children);
|
45
|
+
};
|
46
|
+
|
47
|
+
exports.SSRProvider = SSRProvider;
|
48
|
+
/**
|
49
|
+
* Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay
|
50
|
+
* browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.
|
51
|
+
*/
|
52
|
+
|
53
|
+
function useIsSSR() {
|
54
|
+
const isInSSRContext = useSSRContext() !== exports.defaultSSRContextValue;
|
55
|
+
const [isSSR, setIsSSR] = React.useState(isInSSRContext); // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the
|
56
|
+
// developer to add one.
|
57
|
+
|
58
|
+
if (process.env.NODE_ENV !== 'production') {
|
59
|
+
if (!isInSSRContext && !canUseDOM_1.canUseDOM()) {
|
60
|
+
// eslint-disable-next-line no-console
|
61
|
+
console.error('When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' + 'generated between the client and server.');
|
62
|
+
}
|
63
|
+
} // If on the client, and the component was initially server rendered, then schedule a layout effect to update the
|
64
|
+
// component after hydration.
|
65
|
+
|
66
|
+
|
67
|
+
if (canUseDOM_1.canUseDOM() && isInSSRContext) {
|
68
|
+
// This if statement technically breaks the rules of hooks, but is safe because the condition never changes after
|
69
|
+
// mounting.
|
70
|
+
// eslint-disable-next-line
|
71
|
+
React.useLayoutEffect(() => {
|
72
|
+
setIsSSR(false);
|
73
|
+
}, []);
|
74
|
+
}
|
75
|
+
|
76
|
+
return isSSR;
|
77
|
+
}
|
78
|
+
|
79
|
+
exports.useIsSSR = useIsSSR;
|
80
|
+
//# sourceMappingURL=SSRContext.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["ssr/SSRContext.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,WAAA,gBAAA,OAAA,CAAA,aAAA,CAAA;AAYA;;;;AAIG;;;AACU,OAAA,CAAA,sBAAA,GAA0C;AACrD,EAAA,OAAO,EAAE;AAD4C,CAA1C;AAIA,OAAA,CAAA,UAAA,gBAAa,KAAK,CAAC,aAAN,CAAqC,OAAA,CAAA,sBAArC,CAAb;AAEb;;AAEG;;AACH,SAAgB,aAAhB,GAA6B;AAC3B,SAAO,KAAK,CAAC,UAAN,CAAiB,OAAA,CAAA,UAAjB,CAAP;AACD;;AAFD,OAAA,CAAA,aAAA,GAAA,aAAA;AAIA;;;;;AAKG;;AACI,MAAM,WAAW,GAAa,KAAK,IAAG;AAC3C,QAAM,CAAC,KAAD,IAAU,KAAK,CAAC,QAAN,CAAgC,OAAO;AAAE,IAAA,OAAO,EAAE;AAAX,GAAP,CAAhC,CAAhB;AAEA,SAAO,KAAA,CAAA,aAAA,CAAC,OAAA,CAAA,UAAA,CAAW,QAAZ,EAAoB;AAAC,IAAA,KAAK,EAAE;AAAR,GAApB,EAAoC,KAAK,CAAC,QAA1C,CAAP;AACD,CAJM;;AAAM,OAAA,CAAA,WAAA,GAAW,WAAX;AAMb;;;AAGG;;AACH,SAAgB,QAAhB,GAAwB;AACtB,QAAM,cAAc,GAAG,aAAa,OAAO,OAAA,CAAA,sBAA3C;AACA,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,cAAf,CAA1B,CAFsB,CAItB;AACA;;AACA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QAAI,CAAC,cAAD,IAAmB,CAAC,WAAA,CAAA,SAAA,EAAxB,EAAqC;AACnC;AACA,MAAA,OAAO,CAAC,KAAR,CACE,4GACE,0CAFJ;AAID;AACF,GAdqB,CAgBtB;AACA;;;AACA,MAAI,WAAA,CAAA,SAAA,MAAe,cAAnB,EAAmC;AACjC;AACA;AACA;AACA,IAAA,KAAK,CAAC,eAAN,CAAsB,MAAK;AACzB,MAAA,QAAQ,CAAC,KAAD,CAAR;AACD,KAFD,EAEG,EAFH;AAGD;;AAED,SAAO,KAAP;AACD;;AA5BD,OAAA,CAAA,QAAA,GAAA,QAAA","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>(defaultSSRContextValue);\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext);\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 '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 // 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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.canUseDOM = void 0;
|
7
|
+
/**
|
8
|
+
* Verifies if an application can use DOM.
|
9
|
+
*/
|
10
|
+
|
11
|
+
function canUseDOM() {
|
12
|
+
return typeof window !== 'undefined' && !!(window.document && // eslint-disable-next-line deprecation/deprecation
|
13
|
+
window.document.createElement);
|
14
|
+
}
|
15
|
+
|
16
|
+
exports.canUseDOM = canUseDOM;
|
17
|
+
//# sourceMappingURL=canUseDOM.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["ssr/canUseDOM.ts"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACH,SAAgB,SAAhB,GAAyB;AACvB,SACE,OAAO,MAAP,KAAkB,WAAlB,IACA,CAAC,EACC,MAAM,CAAC,QAAP,IACA;AACA,EAAA,MAAM,CAAC,QAAP,CAAgB,aAHjB,CAFH;AAQD;;AATD,OAAA,CAAA,SAAA,GAAA,SAAA","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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
|
+
|
9
|
+
tslib_1.__exportStar(require("./canUseDOM"), exports);
|
10
|
+
|
11
|
+
tslib_1.__exportStar(require("./SSRContext"), exports);
|
12
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["ssr/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,aAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './canUseDOM';\nexport * from './SSRContext';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
/**
|
3
|
+
* Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
|
4
|
+
*/
|
5
|
+
export declare const applyTriggerPropsToChildren: <TTriggerProps>(children: React.ReactElement<any, string | React.JSXElementConstructor<any>> | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined, triggerProps: TTriggerProps) => React.ReactElement | null;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.applyTriggerPropsToChildren = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const isFluentTrigger_1 = /*#__PURE__*/require("./isFluentTrigger");
|
11
|
+
/**
|
12
|
+
* Apply the trigger props to the children, either by calling the render function, or cloning with the new props.
|
13
|
+
*/
|
14
|
+
|
15
|
+
|
16
|
+
const applyTriggerPropsToChildren = (children, triggerProps) => {
|
17
|
+
if (typeof children === 'function') {
|
18
|
+
return children(triggerProps);
|
19
|
+
} else if (children) {
|
20
|
+
return cloneTriggerTree(children, triggerProps);
|
21
|
+
} // Components in React should return either JSX elements or "null", otherwise React will throw:
|
22
|
+
// Nothing was returned from render.
|
23
|
+
// This usually means a return statement is missing. Or, to render nothing, return null.
|
24
|
+
|
25
|
+
|
26
|
+
return children || null;
|
27
|
+
};
|
28
|
+
|
29
|
+
exports.applyTriggerPropsToChildren = applyTriggerPropsToChildren;
|
30
|
+
/**
|
31
|
+
* Clones a React element tree, and applies the given props to the first grandchild that is not
|
32
|
+
* a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).
|
33
|
+
*/
|
34
|
+
|
35
|
+
const cloneTriggerTree = (child, triggerProps) => {
|
36
|
+
if (!React.isValidElement(child) || child.type === React.Fragment) {
|
37
|
+
throw new Error('A trigger element must be a single element for this component. ' + "Please ensure that you're not using React Fragments.");
|
38
|
+
}
|
39
|
+
|
40
|
+
if (isFluentTrigger_1.isFluentTrigger(child)) {
|
41
|
+
const grandchild = cloneTriggerTree(child.props.children, triggerProps);
|
42
|
+
return React.cloneElement(child, undefined, grandchild);
|
43
|
+
} else {
|
44
|
+
return React.cloneElement(child, triggerProps);
|
45
|
+
}
|
46
|
+
};
|
47
|
+
//# sourceMappingURL=applyTriggerPropsToChildren.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/applyTriggerPropsToChildren.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;AAEA;;AAEG;;;AACI,MAAM,2BAA2B,GAAG,CACzC,QADyC,EAEzC,YAFyC,KAGZ;AAC7B,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,WAAO,QAAQ,CAAC,YAAD,CAAf;AACD,GAFD,MAEO,IAAI,QAAJ,EAAc;AACnB,WAAO,gBAAgB,CAAC,QAAD,EAAW,YAAX,CAAvB;AACD,GAL4B,CAO7B;AACA;AACA;;;AACA,SAAO,QAAQ,IAAI,IAAnB;AACD,CAdM;;AAAM,OAAA,CAAA,2BAAA,GAA2B,2BAA3B;AAgBb;;;AAGG;;AACH,MAAM,gBAAgB,GAAG,CAAgB,KAAhB,EAAwC,YAAxC,KAA2F;AAClH,MAAI,CAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;AACjE,UAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;AAID;;AAED,MAAI,iBAAA,CAAA,eAAA,CAAgB,KAAhB,CAAJ,EAA4B;AAC1B,UAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;AACA,WAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;AACD,GAHD,MAGO;AACL,WAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;AACD;AACF,CAdD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\n\n/**\n * Apply the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport const applyTriggerPropsToChildren = <TTriggerProps>(\n children: React.ReactElement | ((props: TTriggerProps) => React.ReactElement | null) | null | undefined,\n triggerProps: TTriggerProps,\n): React.ReactElement | null => {\n if (typeof children === 'function') {\n return children(triggerProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerProps);\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 */\nconst cloneTriggerTree = <TTriggerProps>(child: React.ReactNode, triggerProps: TTriggerProps): 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);\n }\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/**
|
2
|
+
* Clamps `value` to a number between the min and max.
|
3
|
+
*
|
4
|
+
* @param value - the value to be clamped
|
5
|
+
* @param min - the lowest valid value
|
6
|
+
* @param max - the highest valid value
|
7
|
+
*/
|
8
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.clamp = void 0;
|
7
|
+
/**
|
8
|
+
* Clamps `value` to a number between the min and max.
|
9
|
+
*
|
10
|
+
* @param value - the value to be clamped
|
11
|
+
* @param min - the lowest valid value
|
12
|
+
* @param max - the highest valid value
|
13
|
+
*/
|
14
|
+
|
15
|
+
const clamp = (value, min, max) => Math.max(min, Math.min(max, value || 0));
|
16
|
+
|
17
|
+
exports.clamp = clamp;
|
18
|
+
//# sourceMappingURL=clamp.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/clamp.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;AAMG;;AACI,MAAM,KAAK,GAAG,CAAC,KAAD,EAAgB,GAAhB,EAA6B,GAA7B,KAAqD,IAAI,CAAC,GAAL,CAAS,GAAT,EAAc,IAAI,CAAC,GAAL,CAAS,GAAT,EAAc,KAAK,IAAI,CAAvB,CAAd,CAAnE;;AAAM,OAAA,CAAA,KAAA,GAAK,KAAL","sourcesContent":["/**\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"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
/**
|
3
|
+
* Given an element tagname and user props, filters the props to only allowed props for the given
|
4
|
+
* element type.
|
5
|
+
* @param tagName - Tag name (e.g. "div")
|
6
|
+
* @param props - Props object
|
7
|
+
* @param excludedPropNames - List of props to disallow
|
8
|
+
*/
|
9
|
+
export declare function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;
|
10
|
+
/**
|
11
|
+
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
12
|
+
*
|
13
|
+
* This function is only for use with components that have a primary slot other than `root`.
|
14
|
+
* Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
|
15
|
+
*
|
16
|
+
* @returns An object containing the native props for the `root` and primary slots.
|
17
|
+
*/
|
18
|
+
export declare const getPartitionedNativeProps: <Props extends Pick<React.HTMLAttributes<HTMLElement>, "style" | "className">, ExcludedPropKeys extends Extract<keyof Props, string> = never>({ primarySlotTagName, props, excludedPropNames, }: {
|
19
|
+
/** The primary slot's element type (e.g. 'div') */
|
20
|
+
primarySlotTagName: keyof JSX.IntrinsicElements;
|
21
|
+
/** The component's props object */
|
22
|
+
props: Props;
|
23
|
+
/** List of native props to exclude from the returned value */
|
24
|
+
excludedPropNames?: ExcludedPropKeys[] | undefined;
|
25
|
+
}) => {
|
26
|
+
root: {
|
27
|
+
style: React.CSSProperties | undefined;
|
28
|
+
className: string | undefined;
|
29
|
+
};
|
30
|
+
primary: Omit<Props, ExcludedPropKeys>;
|
31
|
+
};
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getPartitionedNativeProps = exports.getNativeElementProps = void 0;
|
7
|
+
|
8
|
+
const properties_1 = /*#__PURE__*/require("./properties");
|
9
|
+
|
10
|
+
const nativeElementMap = {
|
11
|
+
label: properties_1.labelProperties,
|
12
|
+
audio: properties_1.audioProperties,
|
13
|
+
video: properties_1.videoProperties,
|
14
|
+
ol: properties_1.olProperties,
|
15
|
+
li: properties_1.liProperties,
|
16
|
+
a: properties_1.anchorProperties,
|
17
|
+
button: properties_1.buttonProperties,
|
18
|
+
input: properties_1.inputProperties,
|
19
|
+
textarea: properties_1.textAreaProperties,
|
20
|
+
select: properties_1.selectProperties,
|
21
|
+
option: properties_1.optionProperties,
|
22
|
+
table: properties_1.tableProperties,
|
23
|
+
tr: properties_1.trProperties,
|
24
|
+
th: properties_1.thProperties,
|
25
|
+
td: properties_1.tdProperties,
|
26
|
+
colGroup: properties_1.colGroupProperties,
|
27
|
+
col: properties_1.colProperties,
|
28
|
+
fieldset: properties_1.fieldsetProperties,
|
29
|
+
form: properties_1.formProperties,
|
30
|
+
iframe: properties_1.iframeProperties,
|
31
|
+
img: properties_1.imgProperties
|
32
|
+
};
|
33
|
+
/**
|
34
|
+
* Given an element tagname and user props, filters the props to only allowed props for the given
|
35
|
+
* element type.
|
36
|
+
* @param tagName - Tag name (e.g. "div")
|
37
|
+
* @param props - Props object
|
38
|
+
* @param excludedPropNames - List of props to disallow
|
39
|
+
*/
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
41
|
+
|
42
|
+
function getNativeElementProps(tagName, props, excludedPropNames) {
|
43
|
+
const allowedPropNames = tagName && nativeElementMap[tagName] || properties_1.htmlElementProperties;
|
44
|
+
allowedPropNames.as = 1;
|
45
|
+
return properties_1.getNativeProps(props, allowedPropNames, excludedPropNames);
|
46
|
+
}
|
47
|
+
|
48
|
+
exports.getNativeElementProps = getNativeElementProps;
|
49
|
+
/**
|
50
|
+
* Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.
|
51
|
+
*
|
52
|
+
* This function is only for use with components that have a primary slot other than `root`.
|
53
|
+
* Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.
|
54
|
+
*
|
55
|
+
* @returns An object containing the native props for the `root` and primary slots.
|
56
|
+
*/
|
57
|
+
|
58
|
+
const getPartitionedNativeProps = ({
|
59
|
+
primarySlotTagName,
|
60
|
+
props,
|
61
|
+
excludedPropNames
|
62
|
+
}) => {
|
63
|
+
return {
|
64
|
+
root: {
|
65
|
+
style: props.style,
|
66
|
+
className: props.className
|
67
|
+
},
|
68
|
+
primary: getNativeElementProps(primarySlotTagName, props, [...(excludedPropNames || []), 'style', 'className'])
|
69
|
+
};
|
70
|
+
};
|
71
|
+
|
72
|
+
exports.getPartitionedNativeProps = getPartitionedNativeProps;
|
73
|
+
//# sourceMappingURL=getNativeElementProps.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/getNativeElementProps.ts"],"names":[],"mappings":";;;;;;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AA0BA,MAAM,gBAAgB,GAA2C;AAC/D,EAAA,KAAK,EAAE,YAAA,CAAA,eADwD;AAE/D,EAAA,KAAK,EAAE,YAAA,CAAA,eAFwD;AAG/D,EAAA,KAAK,EAAE,YAAA,CAAA,eAHwD;AAI/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAJ2D;AAK/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAL2D;AAM/D,EAAA,CAAC,EAAE,YAAA,CAAA,gBAN4D;AAO/D,EAAA,MAAM,EAAE,YAAA,CAAA,gBAPuD;AAQ/D,EAAA,KAAK,EAAE,YAAA,CAAA,eARwD;AAS/D,EAAA,QAAQ,EAAE,YAAA,CAAA,kBATqD;AAU/D,EAAA,MAAM,EAAE,YAAA,CAAA,gBAVuD;AAW/D,EAAA,MAAM,EAAE,YAAA,CAAA,gBAXuD;AAY/D,EAAA,KAAK,EAAE,YAAA,CAAA,eAZwD;AAa/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAb2D;AAc/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAd2D;AAe/D,EAAA,EAAE,EAAE,YAAA,CAAA,YAf2D;AAgB/D,EAAA,QAAQ,EAAE,YAAA,CAAA,kBAhBqD;AAiB/D,EAAA,GAAG,EAAE,YAAA,CAAA,aAjB0D;AAkB/D,EAAA,QAAQ,EAAE,YAAA,CAAA,kBAlBqD;AAmB/D,EAAA,IAAI,EAAE,YAAA,CAAA,cAnByD;AAoB/D,EAAA,MAAM,EAAE,YAAA,CAAA,gBApBuD;AAqB/D,EAAA,GAAG,EAAE,YAAA,CAAA;AArB0D,CAAjE;AAwBA;;;;;;AAMG;AACH;;AACA,SAAgB,qBAAhB,CACE,OADF,EAEE,KAFF,EAGE,iBAHF,EAG8B;AAE5B,QAAM,gBAAgB,GAAI,OAAO,IAAI,gBAAgB,CAAC,OAAD,CAA5B,IAA0C,YAAA,CAAA,qBAAnE;AACA,EAAA,gBAAgB,CAAC,EAAjB,GAAsB,CAAtB;AAEA,SAAO,YAAA,CAAA,cAAA,CAAe,KAAf,EAAsB,gBAAtB,EAAwC,iBAAxC,CAAP;AACD;;AATD,OAAA,CAAA,qBAAA,GAAA,qBAAA;AAWA;;;;;;;AAOG;;AACI,MAAM,yBAAyB,GAAG,CAGvC;AACA,EAAA,kBADA;AAEA,EAAA,KAFA;AAGA,EAAA;AAHA,CAHuC,KAgBpC;AACH,SAAO;AACL,IAAA,IAAI,EAAE;AAAE,MAAA,KAAK,EAAE,KAAK,CAAC,KAAf;AAAsB,MAAA,SAAS,EAAE,KAAK,CAAC;AAAvC,KADD;AAEL,IAAA,OAAO,EAAE,qBAAqB,CAAgC,kBAAhC,EAAoD,KAApD,EAA2D,CACvF,IAAI,iBAAiB,IAAI,EAAzB,CADuF,EAEvF,OAFuF,EAGvF,WAHuF,CAA3D;AAFzB,GAAP;AAQD,CAzBM;;AAAM,OAAA,CAAA,yBAAA,GAAyB,yBAAzB","sourcesContent":["import * as React from 'react';\nimport {\n labelProperties,\n audioProperties,\n videoProperties,\n olProperties,\n liProperties,\n anchorProperties,\n buttonProperties,\n inputProperties,\n textAreaProperties,\n selectProperties,\n optionProperties,\n tableProperties,\n trProperties,\n thProperties,\n tdProperties,\n colGroupProperties,\n colProperties,\n fieldsetProperties,\n formProperties,\n iframeProperties,\n imgProperties,\n htmlElementProperties,\n getNativeProps,\n} from './properties';\n\nconst nativeElementMap: Record<string, Record<string, number>> = {\n label: labelProperties,\n audio: audioProperties,\n video: videoProperties,\n ol: olProperties,\n li: liProperties,\n a: anchorProperties,\n button: buttonProperties,\n input: inputProperties,\n textarea: textAreaProperties,\n select: selectProperties,\n option: optionProperties,\n table: tableProperties,\n tr: trProperties,\n th: thProperties,\n td: tdProperties,\n colGroup: colGroupProperties,\n col: colProperties,\n fieldset: fieldsetProperties,\n form: formProperties,\n iframe: iframeProperties,\n img: imgProperties,\n};\n\n/**\n * Given an element tagname and user props, filters the props to only allowed props for the given\n * element type.\n * @param tagName - Tag name (e.g. \"div\")\n * @param props - Props object\n * @param excludedPropNames - List of props to disallow\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(\n tagName: string,\n props: {},\n excludedPropNames?: string[],\n): TAttributes {\n const allowedPropNames = (tagName && nativeElementMap[tagName]) || htmlElementProperties;\n allowedPropNames.as = 1;\n\n return getNativeProps(props, allowedPropNames, excludedPropNames);\n}\n\n/**\n * Splits the native props into ones that go to the `root` slot, and ones that go to the primary slot.\n *\n * This function is only for use with components that have a primary slot other than `root`.\n * Most components should use {@link getNativeElementProps} for their root slot if it is the primary slot.\n *\n * @returns An object containing the native props for the `root` and primary slots.\n */\nexport const getPartitionedNativeProps = <\n Props extends Pick<React.HTMLAttributes<HTMLElement>, 'style' | 'className'>,\n ExcludedPropKeys extends Extract<keyof Props, string> = never\n>({\n primarySlotTagName,\n props,\n excludedPropNames,\n}: {\n /** The primary slot's element type (e.g. 'div') */\n primarySlotTagName: keyof JSX.IntrinsicElements;\n\n /** The component's props object */\n props: Props;\n\n /** List of native props to exclude from the returned value */\n excludedPropNames?: ExcludedPropKeys[];\n}) => {\n return {\n root: { style: props.style, className: props.className },\n primary: getNativeElementProps<Omit<Props, ExcludedPropKeys>>(primarySlotTagName, props, [\n ...(excludedPropNames || []),\n 'style',\n 'className',\n ]),\n };\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.getRTLSafeKey = void 0;
|
7
|
+
/**
|
8
|
+
* Finds and swaps a provided key for it's right to left format.
|
9
|
+
*/
|
10
|
+
|
11
|
+
const getRTLSafeKey = (key, dir) => {
|
12
|
+
if (dir === 'rtl') {
|
13
|
+
switch (key) {
|
14
|
+
case 'ArrowLeft':
|
15
|
+
{
|
16
|
+
return 'ArrowRight';
|
17
|
+
}
|
18
|
+
|
19
|
+
case 'ArrowRight':
|
20
|
+
{
|
21
|
+
return 'ArrowLeft';
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
return key;
|
27
|
+
};
|
28
|
+
|
29
|
+
exports.getRTLSafeKey = getRTLSafeKey;
|
30
|
+
//# sourceMappingURL=getRTLSafeKey.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["utils/getRTLSafeKey.ts"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACI,MAAM,aAAa,GAAG,CAAC,GAAD,EAAc,GAAd,KAAoC;AAC/D,MAAI,GAAG,KAAK,KAAZ,EAAmB;AACjB,YAAQ,GAAR;AACE,WAAK,WAAL;AAAkB;AAChB,iBAAO,YAAP;AACD;;AAED,WAAK,YAAL;AAAmB;AACjB,iBAAO,WAAP;AACD;AAPH;AASD;;AAED,SAAO,GAAP;AACD,CAdM;;AAAM,OAAA,CAAA,aAAA,GAAa,aAAb","sourcesContent":["/**\n * Finds and swaps a provided key for it's right to left format.\n */\nexport const getRTLSafeKey = (key: string, dir: 'ltr' | 'rtl') => {\n if (dir === 'rtl') {\n switch (key) {\n case 'ArrowLeft': {\n return 'ArrowRight';\n }\n\n case 'ArrowRight': {\n return 'ArrowLeft';\n }\n }\n }\n\n return key;\n};\n"],"sourceRoot":"../src/"}
|