@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.
Files changed (223) hide show
  1. package/CHANGELOG.json +1844 -0
  2. package/CHANGELOG.md +736 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/dist/react-utilities.d.ts +782 -0
  6. package/lib/compose/getSlots.d.ts +30 -0
  7. package/lib/compose/getSlots.js +63 -0
  8. package/lib/compose/getSlots.js.map +1 -0
  9. package/lib/compose/index.d.ts +3 -0
  10. package/lib/compose/index.js +4 -0
  11. package/lib/compose/index.js.map +1 -0
  12. package/lib/compose/resolveShorthand.d.ts +16 -0
  13. package/lib/compose/resolveShorthand.js +31 -0
  14. package/lib/compose/resolveShorthand.js.map +1 -0
  15. package/lib/compose/types.d.ts +155 -0
  16. package/lib/compose/types.js +6 -0
  17. package/lib/compose/types.js.map +1 -0
  18. package/lib/hooks/index.d.ts +16 -0
  19. package/lib/hooks/index.js +17 -0
  20. package/lib/hooks/index.js.map +1 -0
  21. package/lib/hooks/useBoolean.d.ts +17 -0
  22. package/lib/hooks/useBoolean.js +28 -0
  23. package/lib/hooks/useBoolean.js.map +1 -0
  24. package/lib/hooks/useConst.d.ts +12 -0
  25. package/lib/hooks/useConst.js +30 -0
  26. package/lib/hooks/useConst.js.map +1 -0
  27. package/lib/hooks/useControllableState.d.ts +31 -0
  28. package/lib/hooks/useControllableState.js +73 -0
  29. package/lib/hooks/useControllableState.js.map +1 -0
  30. package/lib/hooks/useEventCallback.d.ts +13 -0
  31. package/lib/hooks/useEventCallback.js +28 -0
  32. package/lib/hooks/useEventCallback.js.map +1 -0
  33. package/lib/hooks/useFirstMount.d.ts +11 -0
  34. package/lib/hooks/useFirstMount.js +23 -0
  35. package/lib/hooks/useFirstMount.js.map +1 -0
  36. package/lib/hooks/useForceUpdate.d.ts +4 -0
  37. package/lib/hooks/useForceUpdate.js +9 -0
  38. package/lib/hooks/useForceUpdate.js.map +1 -0
  39. package/lib/hooks/useId.d.ts +15 -0
  40. package/lib/hooks/useId.js +31 -0
  41. package/lib/hooks/useId.js.map +1 -0
  42. package/lib/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  43. package/lib/hooks/useIsomorphicLayoutEffect.js +15 -0
  44. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  45. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  46. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  47. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  48. package/lib/hooks/useMergedRefs.d.ts +13 -0
  49. package/lib/hooks/useMergedRefs.js +26 -0
  50. package/lib/hooks/useMergedRefs.js.map +1 -0
  51. package/lib/hooks/useMount.d.ts +6 -0
  52. package/lib/hooks/useMount.js +17 -0
  53. package/lib/hooks/useMount.js.map +1 -0
  54. package/lib/hooks/useOnClickOutside.d.ts +29 -0
  55. package/lib/hooks/useOnClickOutside.js +136 -0
  56. package/lib/hooks/useOnClickOutside.js.map +1 -0
  57. package/lib/hooks/useOnScrollOutside.d.ts +5 -0
  58. package/lib/hooks/useOnScrollOutside.js +36 -0
  59. package/lib/hooks/useOnScrollOutside.js.map +1 -0
  60. package/lib/hooks/usePrevious.d.ts +1 -0
  61. package/lib/hooks/usePrevious.js +9 -0
  62. package/lib/hooks/usePrevious.js.map +1 -0
  63. package/lib/hooks/useTimeout.d.ts +8 -0
  64. package/lib/hooks/useTimeout.js +29 -0
  65. package/lib/hooks/useTimeout.js.map +1 -0
  66. package/lib/hooks/useUnmount.d.ts +6 -0
  67. package/lib/hooks/useUnmount.js +17 -0
  68. package/lib/hooks/useUnmount.js.map +1 -0
  69. package/lib/index.d.ts +4 -0
  70. package/lib/index.js +5 -0
  71. package/lib/index.js.map +1 -0
  72. package/lib/ssr/SSRContext.d.ts +33 -0
  73. package/lib/ssr/SSRContext.js +65 -0
  74. package/lib/ssr/SSRContext.js.map +1 -0
  75. package/lib/ssr/canUseDOM.d.ts +4 -0
  76. package/lib/ssr/canUseDOM.js +8 -0
  77. package/lib/ssr/canUseDOM.js.map +1 -0
  78. package/lib/ssr/index.d.ts +2 -0
  79. package/lib/ssr/index.js +3 -0
  80. package/lib/ssr/index.js.map +1 -0
  81. package/lib/tsdoc-metadata.json +11 -0
  82. package/lib/utils/applyTriggerPropsToChildren.d.ts +5 -0
  83. package/lib/utils/applyTriggerPropsToChildren.js +36 -0
  84. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -0
  85. package/lib/utils/clamp.d.ts +8 -0
  86. package/lib/utils/clamp.js +9 -0
  87. package/lib/utils/clamp.js.map +1 -0
  88. package/lib/utils/getNativeElementProps.d.ts +31 -0
  89. package/lib/utils/getNativeElementProps.js +61 -0
  90. package/lib/utils/getNativeElementProps.js.map +1 -0
  91. package/lib/utils/getRTLSafeKey.d.ts +4 -0
  92. package/lib/utils/getRTLSafeKey.js +21 -0
  93. package/lib/utils/getRTLSafeKey.js.map +1 -0
  94. package/lib/utils/getReactCallbackName.d.ts +25 -0
  95. package/lib/utils/getReactCallbackName.js +26 -0
  96. package/lib/utils/getReactCallbackName.js.map +1 -0
  97. package/lib/utils/getTriggerChild.d.ts +22 -0
  98. package/lib/utils/getTriggerChild.js +26 -0
  99. package/lib/utils/getTriggerChild.js.map +1 -0
  100. package/lib/utils/index.d.ts +9 -0
  101. package/lib/utils/index.js +10 -0
  102. package/lib/utils/index.js.map +1 -0
  103. package/lib/utils/isFluentTrigger.d.ts +22 -0
  104. package/lib/utils/isFluentTrigger.js +8 -0
  105. package/lib/utils/isFluentTrigger.js.map +1 -0
  106. package/lib/utils/omit.d.ts +14 -0
  107. package/lib/utils/omit.js +27 -0
  108. package/lib/utils/omit.js.map +1 -0
  109. package/lib/utils/properties.d.ts +154 -0
  110. package/lib/utils/properties.js +237 -0
  111. package/lib/utils/properties.js.map +1 -0
  112. package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  113. package/lib/utils/shouldPreventDefaultOnKeyDown.js +24 -0
  114. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  115. package/lib-commonjs/compose/getSlots.d.ts +30 -0
  116. package/lib-commonjs/compose/getSlots.js +74 -0
  117. package/lib-commonjs/compose/getSlots.js.map +1 -0
  118. package/lib-commonjs/compose/index.d.ts +3 -0
  119. package/lib-commonjs/compose/index.js +14 -0
  120. package/lib-commonjs/compose/index.js.map +1 -0
  121. package/lib-commonjs/compose/resolveShorthand.d.ts +16 -0
  122. package/lib-commonjs/compose/resolveShorthand.js +41 -0
  123. package/lib-commonjs/compose/resolveShorthand.js.map +1 -0
  124. package/lib-commonjs/compose/types.d.ts +155 -0
  125. package/lib-commonjs/compose/types.js +10 -0
  126. package/lib-commonjs/compose/types.js.map +1 -0
  127. package/lib-commonjs/hooks/index.d.ts +16 -0
  128. package/lib-commonjs/hooks/index.js +40 -0
  129. package/lib-commonjs/hooks/index.js.map +1 -0
  130. package/lib-commonjs/hooks/useBoolean.d.ts +17 -0
  131. package/lib-commonjs/hooks/useBoolean.js +39 -0
  132. package/lib-commonjs/hooks/useBoolean.js.map +1 -0
  133. package/lib-commonjs/hooks/useConst.d.ts +12 -0
  134. package/lib-commonjs/hooks/useConst.js +40 -0
  135. package/lib-commonjs/hooks/useConst.js.map +1 -0
  136. package/lib-commonjs/hooks/useControllableState.d.ts +31 -0
  137. package/lib-commonjs/hooks/useControllableState.js +83 -0
  138. package/lib-commonjs/hooks/useControllableState.js.map +1 -0
  139. package/lib-commonjs/hooks/useEventCallback.d.ts +13 -0
  140. package/lib-commonjs/hooks/useEventCallback.js +39 -0
  141. package/lib-commonjs/hooks/useEventCallback.js.map +1 -0
  142. package/lib-commonjs/hooks/useFirstMount.d.ts +11 -0
  143. package/lib-commonjs/hooks/useFirstMount.js +33 -0
  144. package/lib-commonjs/hooks/useFirstMount.js.map +1 -0
  145. package/lib-commonjs/hooks/useForceUpdate.d.ts +4 -0
  146. package/lib-commonjs/hooks/useForceUpdate.js +19 -0
  147. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -0
  148. package/lib-commonjs/hooks/useId.d.ts +15 -0
  149. package/lib-commonjs/hooks/useId.js +44 -0
  150. package/lib-commonjs/hooks/useId.js.map +1 -0
  151. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  152. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +24 -0
  153. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  154. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  155. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  156. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  157. package/lib-commonjs/hooks/useMergedRefs.d.ts +13 -0
  158. package/lib-commonjs/hooks/useMergedRefs.js +36 -0
  159. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -0
  160. package/lib-commonjs/hooks/useMount.d.ts +6 -0
  161. package/lib-commonjs/hooks/useMount.js +27 -0
  162. package/lib-commonjs/hooks/useMount.js.map +1 -0
  163. package/lib-commonjs/hooks/useOnClickOutside.d.ts +29 -0
  164. package/lib-commonjs/hooks/useOnClickOutside.js +147 -0
  165. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -0
  166. package/lib-commonjs/hooks/useOnScrollOutside.d.ts +5 -0
  167. package/lib-commonjs/hooks/useOnScrollOutside.js +47 -0
  168. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -0
  169. package/lib-commonjs/hooks/usePrevious.d.ts +1 -0
  170. package/lib-commonjs/hooks/usePrevious.js +19 -0
  171. package/lib-commonjs/hooks/usePrevious.js.map +1 -0
  172. package/lib-commonjs/hooks/useTimeout.d.ts +8 -0
  173. package/lib-commonjs/hooks/useTimeout.js +40 -0
  174. package/lib-commonjs/hooks/useTimeout.js.map +1 -0
  175. package/lib-commonjs/hooks/useUnmount.d.ts +6 -0
  176. package/lib-commonjs/hooks/useUnmount.js +27 -0
  177. package/lib-commonjs/hooks/useUnmount.js.map +1 -0
  178. package/lib-commonjs/index.d.ts +4 -0
  179. package/lib-commonjs/index.js +16 -0
  180. package/lib-commonjs/index.js.map +1 -0
  181. package/lib-commonjs/ssr/SSRContext.d.ts +33 -0
  182. package/lib-commonjs/ssr/SSRContext.js +80 -0
  183. package/lib-commonjs/ssr/SSRContext.js.map +1 -0
  184. package/lib-commonjs/ssr/canUseDOM.d.ts +4 -0
  185. package/lib-commonjs/ssr/canUseDOM.js +17 -0
  186. package/lib-commonjs/ssr/canUseDOM.js.map +1 -0
  187. package/lib-commonjs/ssr/index.d.ts +2 -0
  188. package/lib-commonjs/ssr/index.js +12 -0
  189. package/lib-commonjs/ssr/index.js.map +1 -0
  190. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +5 -0
  191. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +47 -0
  192. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -0
  193. package/lib-commonjs/utils/clamp.d.ts +8 -0
  194. package/lib-commonjs/utils/clamp.js +18 -0
  195. package/lib-commonjs/utils/clamp.js.map +1 -0
  196. package/lib-commonjs/utils/getNativeElementProps.d.ts +31 -0
  197. package/lib-commonjs/utils/getNativeElementProps.js +73 -0
  198. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -0
  199. package/lib-commonjs/utils/getRTLSafeKey.d.ts +4 -0
  200. package/lib-commonjs/utils/getRTLSafeKey.js +30 -0
  201. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -0
  202. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  203. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  204. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  205. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  206. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  207. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  208. package/lib-commonjs/utils/index.d.ts +9 -0
  209. package/lib-commonjs/utils/index.js +26 -0
  210. package/lib-commonjs/utils/index.js.map +1 -0
  211. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  212. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  213. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  214. package/lib-commonjs/utils/omit.d.ts +14 -0
  215. package/lib-commonjs/utils/omit.js +36 -0
  216. package/lib-commonjs/utils/omit.js.map +1 -0
  217. package/lib-commonjs/utils/properties.d.ts +154 -0
  218. package/lib-commonjs/utils/properties.js +246 -0
  219. package/lib-commonjs/utils/properties.js.map +1 -0
  220. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  221. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +34 -0
  222. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  223. package/package.json +50 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useEventCallback = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const useIsomorphicLayoutEffect_1 = /*#__PURE__*/require("./useIsomorphicLayoutEffect");
11
+ /**
12
+ * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
13
+ *
14
+ * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
15
+ * e.g. user props are dependencies which could change on every render
16
+ * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
17
+ *
18
+ * This should not be used often, but can be a useful re-render optimization since the callback is a ref and
19
+ * will not be invalidated between re-renders
20
+ *
21
+ * @param fn - The callback function that will be used
22
+ */
23
+
24
+
25
+ const useEventCallback = fn => {
26
+ const callbackRef = React.useRef(() => {
27
+ throw new Error('Cannot call an event handler while rendering');
28
+ });
29
+ useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(() => {
30
+ callbackRef.current = fn;
31
+ }, [fn]);
32
+ return React.useCallback((...args) => {
33
+ const callback = callbackRef.current;
34
+ return callback(...args);
35
+ }, [callbackRef]);
36
+ };
37
+
38
+ exports.useEventCallback = useEventCallback;
39
+ //# sourceMappingURL=useEventCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useEventCallback.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,2BAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;AAEA;;;;;;;;;;;AAWG;;;AACI,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;AAChG,QAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;AAC/C,UAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;AACD,GAFmB,CAApB;AAIA,EAAA,2BAAA,CAAA,yBAAA,CAA0B,MAAK;AAC7B,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFD,EAEG,CAAC,EAAD,CAFH;AAIA,SAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;AAChB,UAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;AACA,WAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;AACD,GAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks if components was mounted the first time.
3
+ * Since concurrent mode will be released in the future this needs to be verified
4
+ * Currently (React 17) will always render the initial mount once
5
+ * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
6
+ * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
7
+ *
8
+ * @example
9
+ * const isFirstMount = useFirstMount();
10
+ */
11
+ export declare function useFirstMount(): boolean;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFirstMount = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+ /**
10
+ * Checks if components was mounted the first time.
11
+ * Since concurrent mode will be released in the future this needs to be verified
12
+ * Currently (React 17) will always render the initial mount once
13
+ * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
14
+ * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
15
+ *
16
+ * @example
17
+ * const isFirstMount = useFirstMount();
18
+ */
19
+
20
+
21
+ function useFirstMount() {
22
+ const isFirst = React.useRef(true);
23
+
24
+ if (isFirst.current) {
25
+ isFirst.current = false;
26
+ return true;
27
+ }
28
+
29
+ return isFirst.current;
30
+ }
31
+
32
+ exports.useFirstMount = useFirstMount;
33
+ //# sourceMappingURL=useFirstMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useFirstMount.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;AASG;;;AACH,SAAgB,aAAhB,GAA6B;AAC3B,QAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;AAEA,MAAI,OAAO,CAAC,OAAZ,EAAqB;AACnB,IAAA,OAAO,CAAC,OAAR,GAAkB,KAAlB;AACA,WAAO,IAAP;AACD;;AAED,SAAO,OAAO,CAAC,OAAf;AACD;;AATD,OAAA,CAAA,aAAA,GAAA,aAAA","sourcesContent":["import * as React from 'react';\n\n/**\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Forces a re-render, similar to `forceUpdate` in class components.
3
+ */
4
+ export declare function useForceUpdate(): import("react").DispatchWithoutAction;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useForceUpdate = void 0;
7
+
8
+ const react_1 = /*#__PURE__*/require("react");
9
+ /**
10
+ * Forces a re-render, similar to `forceUpdate` in class components.
11
+ */
12
+
13
+
14
+ function useForceUpdate() {
15
+ return react_1.useReducer(x => x + 1, 0)[1];
16
+ }
17
+
18
+ exports.useForceUpdate = useForceUpdate;
19
+ //# sourceMappingURL=useForceUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useForceUpdate.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;AAEG;;;AACH,SAAgB,cAAhB,GAA8B;AAC5B,SAAO,OAAA,CAAA,UAAA,CAAW,CAAC,IAAI,CAAC,GAAG,CAApB,EAAuB,CAAvB,EAA0B,CAA1B,CAAP;AACD;;AAFD,OAAA,CAAA,cAAA,GAAA,cAAA","sourcesContent":["import { useReducer } from 'react';\n\n/**\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Resets generated IDs, should be used only in tests.
3
+ *
4
+ * @private
5
+ */
6
+ export declare function resetIdsForTests(): void;
7
+ /**
8
+ * Hook to generate a unique ID.
9
+ *
10
+ * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
11
+ * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
12
+ * without conditioning the hook call
13
+ * @returns The ID
14
+ */
15
+ export declare function useId(prefix?: string, providedId?: string): string;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useId = exports.resetIdsForTests = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const index_1 = /*#__PURE__*/require("../ssr/index");
11
+ /**
12
+ * Resets generated IDs, should be used only in tests.
13
+ *
14
+ * @private
15
+ */
16
+
17
+
18
+ function resetIdsForTests() {
19
+ index_1.defaultSSRContextValue.current = 0;
20
+ }
21
+
22
+ exports.resetIdsForTests = resetIdsForTests;
23
+ /**
24
+ * Hook to generate a unique ID.
25
+ *
26
+ * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.
27
+ * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
28
+ * without conditioning the hook call
29
+ * @returns The ID
30
+ */
31
+
32
+ function useId(prefix = 'fui-', providedId) {
33
+ const contextValue = index_1.useSSRContext();
34
+ return React.useMemo(() => {
35
+ if (providedId) {
36
+ return providedId;
37
+ }
38
+
39
+ return `${prefix}${++contextValue.current}`;
40
+ }, [prefix, providedId, contextValue]);
41
+ }
42
+
43
+ exports.useId = useId;
44
+ //# sourceMappingURL=useId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useId.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,OAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AAEA;;;;AAIG;;;AACH,SAAgB,gBAAhB,GAAgC;AAC9B,EAAA,OAAA,CAAA,sBAAA,CAAuB,OAAvB,GAAiC,CAAjC;AACD;;AAFD,OAAA,CAAA,gBAAA,GAAA,gBAAA;AAIA;;;;;;;AAOG;;AACH,SAAgB,KAAhB,CAAsB,MAAA,GAAiB,MAAvC,EAA+C,UAA/C,EAAkE;AAChE,QAAM,YAAY,GAAG,OAAA,CAAA,aAAA,EAArB;AAEA,SAAO,KAAK,CAAC,OAAN,CAAc,MAAK;AACxB,QAAI,UAAJ,EAAgB;AACd,aAAO,UAAP;AACD;;AAED,WAAO,GAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAO,EAAzC;AACD,GANM,EAMJ,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CANI,CAAP;AAOD;;AAVD,OAAA,CAAA,KAAA,GAAA,KAAA","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 *\n * @private\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"],"sourceRoot":"../src/"}
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
4
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
5
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
6
+ * the server.
7
+ *
8
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
9
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
10
+ */
11
+ export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useIsomorphicLayoutEffect = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const index_1 = /*#__PURE__*/require("../ssr/index");
11
+ /**
12
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
13
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
14
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
15
+ * the server.
16
+ *
17
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
18
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
19
+ */
20
+ // eslint-disable-next-line no-restricted-properties
21
+
22
+
23
+ exports.useIsomorphicLayoutEffect = /*#__PURE__*/index_1.canUseDOM() ? React.useLayoutEffect : React.useEffect;
24
+ //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,OAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AAEA;;;;;;;;AAQG;AACH;;;AACa,OAAA,CAAA,yBAAA,GAAoD,aAAA,OAAA,CAAA,SAAA,KAAc,KAAK,CAAC,eAApB,GAAsC,KAAK,CAAC,SAAhG","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"],"sourceRoot":"../src/"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Combine two event callbacks into a single callback function that calls each one in order.
3
+ *
4
+ * This is useful to add an event listener to an existing element without overwriting the current listener, if any.
5
+ *
6
+ * For example:
7
+ * ```ts
8
+ * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
9
+ * // Handle onChange
10
+ * });
11
+ * ```
12
+ *
13
+ * @param callback1 - The first callback to be called
14
+ * @param callback2 - The second callback to be called
15
+ *
16
+ * @returns An event callback that calls the callbacks in order, and is stable between renders
17
+ */
18
+ export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMergedEventCallbacks = void 0;
7
+
8
+ const useEventCallback_1 = /*#__PURE__*/require("./useEventCallback");
9
+ /**
10
+ * Combine two event callbacks into a single callback function that calls each one in order.
11
+ *
12
+ * This is useful to add an event listener to an existing element without overwriting the current listener, if any.
13
+ *
14
+ * For example:
15
+ * ```ts
16
+ * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
17
+ * // Handle onChange
18
+ * });
19
+ * ```
20
+ *
21
+ * @param callback1 - The first callback to be called
22
+ * @param callback2 - The second callback to be called
23
+ *
24
+ * @returns An event callback that calls the callbacks in order, and is stable between renders
25
+ */
26
+
27
+
28
+ function useMergedEventCallbacks(callback1, callback2) {
29
+ return useEventCallback_1.useEventCallback((...args) => {
30
+ callback1 === null || callback1 === void 0 ? void 0 : callback1(...args);
31
+ callback2 === null || callback2 === void 0 ? void 0 : callback2(...args);
32
+ });
33
+ }
34
+
35
+ exports.useMergedEventCallbacks = useMergedEventCallbacks;
36
+ //# sourceMappingURL=useMergedEventCallbacks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useMergedEventCallbacks.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,kBAAA,gBAAA,OAAA,CAAA,oBAAA,CAAA;AAEA;;;;;;;;;;;;;;;;AAgBG;;;AACH,SAAgB,uBAAhB,CACE,SADF,EAEE,SAFF,EAEkD;AAEhD,SAAO,kBAAA,CAAA,gBAAA,CAAiB,CAAC,GAAG,IAAJ,KAAkB;AACxC,IAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;AACA,IAAA,SAAS,KAAA,IAAT,IAAA,SAAS,KAAA,KAAA,CAAT,GAAS,KAAA,CAAT,GAAA,SAAS,CAAG,GAAG,IAAN,CAAT;AACD,GAHM,CAAP;AAID;;AARD,OAAA,CAAA,uBAAA,GAAA,uBAAA","sourcesContent":["import { useEventCallback } from './useEventCallback';\n\n/**\n * Combine two event callbacks into a single callback function that calls each one in order.\n *\n * This is useful to add an event listener to an existing element without overwriting the current listener, if any.\n *\n * For example:\n * ```ts\n * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {\n * // Handle onChange\n * });\n * ```\n *\n * @param callback1 - The first callback to be called\n * @param callback2 - The second callback to be called\n *\n * @returns An event callback that calls the callbacks in order, and is stable between renders\n */\nexport function useMergedEventCallbacks<Args extends unknown[]>(\n callback1: ((...args: Args) => void) | undefined,\n callback2: ((...args: Args) => void) | undefined,\n) {\n return useEventCallback((...args: Args) => {\n callback1?.(...args);\n callback2?.(...args);\n });\n}\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * A Ref function which can be treated like a ref object in that it has an attached
4
+ * current property, which will be updated as the ref is evaluated.
5
+ */
6
+ export declare type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);
7
+ /**
8
+ * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
9
+ * updates all provided refs
10
+ * @param refs - Refs to collectively update with one ref value.
11
+ * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
12
+ */
13
+ export declare function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMergedRefs = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+ /**
10
+ * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
11
+ * updates all provided refs
12
+ * @param refs - Refs to collectively update with one ref value.
13
+ * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
14
+ */
15
+
16
+
17
+ function useMergedRefs(...refs) {
18
+ const mergedCallback = React.useCallback(value => {
19
+ // Update the "current" prop hanging on the function.
20
+ mergedCallback.current = value;
21
+
22
+ for (const ref of refs) {
23
+ if (typeof ref === 'function') {
24
+ ref(value);
25
+ } else if (ref) {
26
+ // work around the immutability of the React.Ref type
27
+ ref.current = value;
28
+ }
29
+ }
30
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive
31
+ [...refs]);
32
+ return mergedCallback;
33
+ }
34
+
35
+ exports.useMergedRefs = useMergedRefs;
36
+ //# sourceMappingURL=useMergedRefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useMergedRefs.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAQA;;;;;AAKG;;;AACH,SAAgB,aAAhB,CAAiC,GAAG,IAApC,EAAsE;AACpE,QAAM,cAAc,GAA0B,KAAK,CAAC,WAAN,CAC3C,KAAD,IAAa;AACX;AACE,IAAA,cAAwD,CAAC,OAAzD,GAAmE,KAAnE;;AAEF,SAAK,MAAM,GAAX,IAAkB,IAAlB,EAAwB;AACtB,UAAI,OAAO,GAAP,KAAe,UAAnB,EAA+B;AAC7B,QAAA,GAAG,CAAC,KAAD,CAAH;AACD,OAFD,MAEO,IAAI,GAAJ,EAAS;AACd;AACE,QAAA,GAA6C,CAAC,OAA9C,GAAwD,KAAxD;AACH;AACF;AACF,GAb2C,EAc5C;AACA,GAAC,GAAG,IAAJ,CAf4C,CAA9C;AAkBA,SAAO,cAAP;AACD;;AApBD,OAAA,CAAA,aAAA,GAAA,aAAA","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"],"sourceRoot":"../src/"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Hook which asynchronously executes a callback once the component has been mounted.
3
+ *
4
+ * @param callback - Function to call before mount.
5
+ */
6
+ export declare const useMount: (callback: () => void) => void;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMount = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+ /**
10
+ * Hook which asynchronously executes a callback once the component has been mounted.
11
+ *
12
+ * @param callback - Function to call before mount.
13
+ */
14
+
15
+
16
+ const useMount = callback => {
17
+ const mountRef = React.useRef(callback);
18
+ mountRef.current = callback;
19
+ React.useEffect(() => {
20
+ var _a;
21
+
22
+ (_a = mountRef.current) === null || _a === void 0 ? void 0 : _a.call(mountRef);
23
+ }, []);
24
+ };
25
+
26
+ exports.useMount = useMount;
27
+ //# sourceMappingURL=useMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useMount.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;AAIG;;;AACI,MAAM,QAAQ,GAAI,QAAD,IAAyB;AAC/C,QAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,QAAb,CAAjB;AACA,EAAA,QAAQ,CAAC,OAAT,GAAmB,QAAnB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;;;AACnB,KAAA,EAAA,GAAA,QAAQ,CAAC,OAAT,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAA,IAAA,CAAhB,QAAgB,CAAhB;AACD,GAFD,EAEG,EAFH;AAGD,CANM;;AAAM,OAAA,CAAA,QAAA,GAAQ,QAAR","sourcesContent":["import * as React from 'react';\n\n/**\n * Hook which asynchronously executes a callback once the component has been mounted.\n *\n * @param callback - Function to call before mount.\n */\nexport const useMount = (callback: () => void) => {\n const mountRef = React.useRef(callback);\n mountRef.current = callback;\n React.useEffect(() => {\n mountRef.current?.();\n }, []);\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ export declare type UseOnClickOrScrollOutsideOptions = {
3
+ /**
4
+ * The element to listen for the click event
5
+ */
6
+ element: Document | undefined;
7
+ /**
8
+ * Refs to elements that check if the click is outside
9
+ */
10
+ refs: React.MutableRefObject<HTMLElement | undefined | null>[];
11
+ /**
12
+ * By default uses element.contains, but custom contain function can be provided
13
+ * @param parentRef - provided parent ref
14
+ * @param child - event target element
15
+ */
16
+ contains?(parent: HTMLElement | null, child: HTMLElement): boolean;
17
+ /**
18
+ * Disables event listeners
19
+ */
20
+ disabled?: boolean;
21
+ /**
22
+ * Called if the click is outside the element refs
23
+ */
24
+ callback: (ev: MouseEvent | TouchEvent) => void;
25
+ };
26
+ /**
27
+ * Utility to perform checks where a click/touch event was made outside a component
28
+ */
29
+ export declare const useOnClickOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useOnClickOutside = 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 useOnClickOutside = options => {
17
+ const {
18
+ refs,
19
+ callback,
20
+ element,
21
+ disabled,
22
+ contains: containsProp
23
+ } = options;
24
+ const timeoutId = React.useRef(undefined);
25
+ useIFrameFocus(!disabled, element, callback);
26
+ const listener = useEventCallback_1.useEventCallback(ev => {
27
+ const contains = containsProp || ((parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
28
+
29
+ const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));
30
+
31
+ if (isOutside && !disabled) {
32
+ callback(ev);
33
+ }
34
+ });
35
+ React.useEffect(() => {
36
+ // Store the current event to avoid triggering handlers immediately
37
+ // Note this depends on a deprecated but extremely well supported quirk of the web platform
38
+ // https://github.com/facebook/react/issues/20074
39
+ let currentEvent = getWindowEvent(window);
40
+
41
+ const conditionalHandler = event => {
42
+ // Skip if this event is the same as the one running when we added the handlers
43
+ if (event === currentEvent) {
44
+ currentEvent = undefined;
45
+ return;
46
+ }
47
+
48
+ listener(event);
49
+ };
50
+
51
+ if (!disabled) {
52
+ // use capture phase because React can update DOM before the event bubbles to the document
53
+ element === null || element === void 0 ? void 0 : element.addEventListener('click', conditionalHandler, true);
54
+ element === null || element === void 0 ? void 0 : element.addEventListener('touchstart', conditionalHandler, true);
55
+ element === null || element === void 0 ? void 0 : element.addEventListener('contextmenu', conditionalHandler, true);
56
+ } // Garbage collect this event after it's no longer useful to avoid memory leaks
57
+
58
+
59
+ timeoutId.current = window.setTimeout(() => {
60
+ currentEvent = undefined;
61
+ }, 1);
62
+ return () => {
63
+ element === null || element === void 0 ? void 0 : element.removeEventListener('click', conditionalHandler, true);
64
+ element === null || element === void 0 ? void 0 : element.removeEventListener('touchstart', conditionalHandler, true);
65
+ element === null || element === void 0 ? void 0 : element.removeEventListener('contextmenu', conditionalHandler, true);
66
+ clearTimeout(timeoutId.current);
67
+ currentEvent = undefined;
68
+ };
69
+ }, [listener, element, disabled]);
70
+ };
71
+
72
+ exports.useOnClickOutside = useOnClickOutside;
73
+
74
+ const getWindowEvent = target => {
75
+ var _a, _b, _c;
76
+
77
+ if (target) {
78
+ if (typeof target.window === 'object' && target.window === target) {
79
+ // eslint-disable-next-line deprecation/deprecation
80
+ return target.event;
81
+ } // eslint-disable-next-line deprecation/deprecation
82
+
83
+
84
+ 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;
85
+ }
86
+
87
+ return undefined;
88
+ };
89
+
90
+ const FUI_FRAME_EVENT = 'fuiframefocus';
91
+ /**
92
+ * Since click events do not propagate past iframes, we use focus to detect if a
93
+ * click has happened inside an iframe, since the only ways of focusing inside an
94
+ * iframe are:
95
+ * - clicking inside
96
+ * - tabbing inside
97
+ *
98
+ * Polls the value of `document.activeElement`. If it is an iframe, then dispatch
99
+ * a custom DOM event. When the custom event is received call the provided callback
100
+ *
101
+ * @param enableFrameFocusDispatch - boolean flag to start dispatching events
102
+ * @param targetDocument - the document to dispatch events and set timeouts
103
+ * @param pollDuration - in milliseconds
104
+ */
105
+
106
+ const useIFrameFocus = (enableFrameFocusDispatch, targetDocument, callback, pollDuration = 1000) => {
107
+ const timeoutRef = React.useRef();
108
+ const listener = useEventCallback_1.useEventCallback(e => {
109
+ if (callback) {
110
+ callback(e);
111
+ }
112
+ }); // Adds listener to the custom iframe focus event
113
+
114
+ React.useEffect(() => {
115
+ if (enableFrameFocusDispatch) {
116
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
117
+ }
118
+
119
+ return () => {
120
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
121
+ };
122
+ }, [targetDocument, enableFrameFocusDispatch, listener]); // Starts polling for the active element
123
+
124
+ React.useEffect(() => {
125
+ var _a;
126
+
127
+ if (enableFrameFocusDispatch) {
128
+ timeoutRef.current = (_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.setInterval(() => {
129
+ const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
130
+
131
+ if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME') {
132
+ const event = new CustomEvent(FUI_FRAME_EVENT, {
133
+ bubbles: true
134
+ });
135
+ activeElement.dispatchEvent(event);
136
+ }
137
+ }, pollDuration);
138
+ }
139
+
140
+ return () => {
141
+ var _a;
142
+
143
+ (_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.clearTimeout(timeoutRef.current);
144
+ };
145
+ }, [targetDocument, enableFrameFocusDispatch, pollDuration]);
146
+ };
147
+ //# sourceMappingURL=useOnClickOutside.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["hooks/useOnClickOutside.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,kBAAA,gBAAA,OAAA,CAAA,oBAAA,CAAA;AA8BA;;AAEG;;;AACI,MAAM,iBAAiB,GAAI,OAAD,IAA8C;AAC7E,QAAM;AAAE,IAAA,IAAF;AAAQ,IAAA,QAAR;AAAkB,IAAA,OAAlB;AAA2B,IAAA,QAA3B;AAAqC,IAAA,QAAQ,EAAE;AAA/C,MAAgE,OAAtE;AACA,QAAM,SAAS,GAAG,KAAK,CAAC,MAAN,CAAiC,SAAjC,CAAlB;AACA,EAAA,cAAc,CAAC,CAAC,QAAF,EAAY,OAAZ,EAAqB,QAArB,CAAd;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,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f,MAA2B,QAA/B,EAAyC;AACvC,gBAAM,KAAK,GAAG,IAAI,WAAJ,CAAgB,eAAhB,EAAiC;AAAE,YAAA,OAAO,EAAE;AAAX,WAAjC,CAAd;AACA,UAAA,aAAa,CAAC,aAAd,CAA4B,KAA5B;AACD;AACF,OAN+C,EAM7C,YAN6C,CAAhD;AAOD;;AACD,WAAO,MAAK;;;AACV,OAAA,EAAA,GAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,MAA2B,IAA3B,IAA2B,EAAA,KAAA,KAAA,CAA3B,GAA2B,KAAA,CAA3B,GAA2B,EAAA,CAAE,YAAF,CAAe,UAAU,CAAC,OAA1B,CAA3B;AACD,KAFD;AAGD,GAbD,EAaG,CAAC,cAAD,EAAiB,wBAAjB,EAA2C,YAA3C,CAbH;AAcD,CAvCD","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\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 * 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') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, enableFrameFocusDispatch, pollDuration]);\n};\n"],"sourceRoot":"../src/"}
@@ -0,0 +1,5 @@
1
+ import type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';
2
+ /**
3
+ * Utility to perform checks where a click/touch event was made outside a component
4
+ */
5
+ export declare const useOnScrollOutside: (options: UseOnClickOrScrollOutsideOptions) => void;