@fluentui/react-utilities 9.0.0-alpha.9 → 9.0.0-beta.4

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 (283) hide show
  1. package/CHANGELOG.json +1132 -1
  2. package/CHANGELOG.md +492 -2
  3. package/dist/react-utilities.d.ts +335 -67
  4. package/lib/compose/getSlots.d.ts +13 -4
  5. package/lib/compose/getSlots.js +44 -32
  6. package/lib/compose/getSlots.js.map +1 -1
  7. package/lib/compose/index.d.ts +1 -2
  8. package/lib/compose/index.js +2 -2
  9. package/lib/compose/index.js.map +1 -1
  10. package/lib/compose/nullRender.js +1 -1
  11. package/lib/compose/nullRender.js.map +1 -1
  12. package/lib/compose/resolveShorthand.d.ts +12 -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 +95 -21
  16. package/lib/compose/types.js +5 -0
  17. package/lib/compose/types.js.map +1 -1
  18. package/lib/hooks/index.d.ts +9 -1
  19. package/lib/hooks/index.js +9 -1
  20. package/lib/hooks/index.js.map +1 -1
  21. package/lib/hooks/useBoolean.d.ts +2 -2
  22. package/lib/hooks/useBoolean.js +16 -11
  23. package/lib/hooks/useBoolean.js.map +1 -1
  24. package/lib/hooks/useConst.js +15 -12
  25. package/lib/hooks/useConst.js.map +1 -1
  26. package/lib/hooks/useControllableState.d.ts +21 -0
  27. package/lib/hooks/useControllableState.js +68 -0
  28. package/lib/hooks/useControllableState.js.map +1 -0
  29. package/lib/hooks/useControllableValue.js +47 -50
  30. package/lib/hooks/useControllableValue.js.map +1 -1
  31. package/lib/hooks/useEventCallback.d.ts +2 -2
  32. package/lib/hooks/useEventCallback.js +14 -17
  33. package/lib/hooks/useEventCallback.js.map +1 -1
  34. package/lib/hooks/useFirstMount.d.ts +11 -0
  35. package/lib/hooks/useFirstMount.js +23 -0
  36. package/lib/hooks/useFirstMount.js.map +1 -0
  37. package/lib/hooks/useForceUpdate.d.ts +4 -0
  38. package/lib/hooks/useForceUpdate.js +9 -0
  39. package/lib/hooks/useForceUpdate.js.map +1 -0
  40. package/lib/hooks/useId.d.ts +7 -3
  41. package/lib/hooks/useId.js +13 -17
  42. package/lib/hooks/useId.js.map +1 -1
  43. package/lib/hooks/useIsomorphicLayoutEffect.d.ts +9 -0
  44. package/lib/hooks/useIsomorphicLayoutEffect.js +13 -4
  45. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  46. package/lib/hooks/useMergedRefs.js +16 -20
  47. package/lib/hooks/useMergedRefs.js.map +1 -1
  48. package/lib/hooks/useMount.d.ts +6 -0
  49. package/lib/hooks/useMount.js +17 -0
  50. package/lib/hooks/useMount.js.map +1 -0
  51. package/lib/hooks/useOnClickOutside.d.ts +14 -4
  52. package/lib/hooks/useOnClickOutside.js +129 -18
  53. package/lib/hooks/useOnClickOutside.js.map +1 -1
  54. package/lib/hooks/useOnScrollOutside.d.ts +5 -0
  55. package/lib/hooks/useOnScrollOutside.js +36 -0
  56. package/lib/hooks/useOnScrollOutside.js.map +1 -0
  57. package/lib/hooks/usePrevious.d.ts +1 -0
  58. package/lib/hooks/usePrevious.js +9 -0
  59. package/lib/hooks/usePrevious.js.map +1 -0
  60. package/lib/hooks/useTimeout.d.ts +8 -0
  61. package/lib/hooks/useTimeout.js +29 -0
  62. package/lib/hooks/useTimeout.js.map +1 -0
  63. package/lib/hooks/useUnmount.d.ts +6 -0
  64. package/lib/hooks/useUnmount.js +17 -0
  65. package/lib/hooks/useUnmount.js.map +1 -0
  66. package/lib/index.d.ts +1 -0
  67. package/lib/index.js +1 -0
  68. package/lib/index.js.map +1 -1
  69. package/lib/ssr/SSRContext.d.ts +33 -0
  70. package/lib/ssr/SSRContext.js +65 -0
  71. package/lib/ssr/SSRContext.js.map +1 -0
  72. package/lib/ssr/canUseDOM.d.ts +4 -0
  73. package/lib/ssr/canUseDOM.js +8 -0
  74. package/lib/ssr/canUseDOM.js.map +1 -0
  75. package/lib/ssr/index.d.ts +2 -0
  76. package/lib/ssr/index.js +3 -0
  77. package/lib/ssr/index.js.map +1 -0
  78. package/lib/tsdoc-metadata.json +1 -1
  79. package/lib/utils/applyTriggerPropsToChildren.d.ts +5 -0
  80. package/lib/utils/applyTriggerPropsToChildren.js +16 -0
  81. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -0
  82. package/lib/utils/clamp.d.ts +8 -0
  83. package/lib/utils/clamp.js +9 -0
  84. package/lib/utils/clamp.js.map +1 -0
  85. package/lib/utils/getNativeElementProps.d.ts +22 -0
  86. package/lib/utils/getNativeElementProps.js +48 -24
  87. package/lib/utils/getNativeElementProps.js.map +1 -1
  88. package/lib/utils/getRTLSafeKey.d.ts +4 -0
  89. package/lib/utils/getRTLSafeKey.js +21 -0
  90. package/lib/utils/getRTLSafeKey.js.map +1 -0
  91. package/lib/utils/index.d.ts +5 -0
  92. package/lib/utils/index.js +5 -0
  93. package/lib/utils/index.js.map +1 -1
  94. package/lib/utils/omit.d.ts +1 -1
  95. package/lib/utils/omit.js +9 -7
  96. package/lib/utils/omit.js.map +1 -1
  97. package/lib/utils/onlyChild.d.ts +5 -0
  98. package/lib/utils/onlyChild.js +13 -0
  99. package/lib/utils/onlyChild.js.map +1 -0
  100. package/lib/utils/properties.js +80 -282
  101. package/lib/utils/properties.js.map +1 -1
  102. package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  103. package/lib/utils/shouldPreventDefaultOnKeyDown.js +20 -0
  104. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  105. package/lib-commonjs/compose/getSlots.d.ts +13 -4
  106. package/lib-commonjs/compose/getSlots.js +57 -35
  107. package/lib-commonjs/compose/getSlots.js.map +1 -1
  108. package/lib-commonjs/compose/index.d.ts +1 -2
  109. package/lib-commonjs/compose/index.js +12 -4
  110. package/lib-commonjs/compose/index.js.map +1 -1
  111. package/lib-commonjs/compose/nullRender.js +9 -2
  112. package/lib-commonjs/compose/nullRender.js.map +1 -1
  113. package/lib-commonjs/compose/resolveShorthand.d.ts +12 -0
  114. package/lib-commonjs/compose/resolveShorthand.js +41 -0
  115. package/lib-commonjs/compose/resolveShorthand.js.map +1 -0
  116. package/lib-commonjs/compose/types.d.ts +95 -21
  117. package/lib-commonjs/compose/types.js +8 -1
  118. package/lib-commonjs/compose/types.js.map +1 -1
  119. package/lib-commonjs/hooks/index.d.ts +9 -1
  120. package/lib-commonjs/hooks/index.js +31 -4
  121. package/lib-commonjs/hooks/index.js.map +1 -1
  122. package/lib-commonjs/hooks/useBoolean.d.ts +2 -2
  123. package/lib-commonjs/hooks/useBoolean.js +27 -14
  124. package/lib-commonjs/hooks/useBoolean.js.map +1 -1
  125. package/lib-commonjs/hooks/useConst.js +24 -14
  126. package/lib-commonjs/hooks/useConst.js.map +1 -1
  127. package/lib-commonjs/hooks/useControllableState.d.ts +21 -0
  128. package/lib-commonjs/hooks/useControllableState.js +78 -0
  129. package/lib-commonjs/hooks/useControllableState.js.map +1 -0
  130. package/lib-commonjs/hooks/useControllableValue.js +58 -53
  131. package/lib-commonjs/hooks/useControllableValue.js.map +1 -1
  132. package/lib-commonjs/hooks/useEventCallback.d.ts +2 -2
  133. package/lib-commonjs/hooks/useEventCallback.js +26 -20
  134. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  135. package/lib-commonjs/hooks/useFirstMount.d.ts +11 -0
  136. package/lib-commonjs/hooks/useFirstMount.js +33 -0
  137. package/lib-commonjs/hooks/useFirstMount.js.map +1 -0
  138. package/lib-commonjs/hooks/useForceUpdate.d.ts +4 -0
  139. package/lib-commonjs/hooks/useForceUpdate.js +19 -0
  140. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -0
  141. package/lib-commonjs/hooks/useId.d.ts +7 -3
  142. package/lib-commonjs/hooks/useId.js +25 -21
  143. package/lib-commonjs/hooks/useId.js.map +1 -1
  144. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +9 -0
  145. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +22 -6
  146. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  147. package/lib-commonjs/hooks/useMergedRefs.js +25 -22
  148. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  149. package/lib-commonjs/hooks/useMount.d.ts +6 -0
  150. package/lib-commonjs/hooks/useMount.js +27 -0
  151. package/lib-commonjs/hooks/useMount.js.map +1 -0
  152. package/lib-commonjs/hooks/useOnClickOutside.d.ts +14 -4
  153. package/lib-commonjs/hooks/useOnClickOutside.js +141 -21
  154. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  155. package/lib-commonjs/hooks/useOnScrollOutside.d.ts +5 -0
  156. package/lib-commonjs/hooks/useOnScrollOutside.js +47 -0
  157. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -0
  158. package/lib-commonjs/hooks/usePrevious.d.ts +1 -0
  159. package/lib-commonjs/hooks/usePrevious.js +19 -0
  160. package/lib-commonjs/hooks/usePrevious.js.map +1 -0
  161. package/lib-commonjs/hooks/useTimeout.d.ts +8 -0
  162. package/lib-commonjs/hooks/useTimeout.js +40 -0
  163. package/lib-commonjs/hooks/useTimeout.js.map +1 -0
  164. package/lib-commonjs/hooks/useUnmount.d.ts +6 -0
  165. package/lib-commonjs/hooks/useUnmount.js +27 -0
  166. package/lib-commonjs/hooks/useUnmount.js.map +1 -0
  167. package/lib-commonjs/index.d.ts +1 -0
  168. package/lib-commonjs/index.js +11 -2
  169. package/lib-commonjs/index.js.map +1 -1
  170. package/lib-commonjs/ssr/SSRContext.d.ts +33 -0
  171. package/lib-commonjs/ssr/SSRContext.js +80 -0
  172. package/lib-commonjs/ssr/SSRContext.js.map +1 -0
  173. package/lib-commonjs/ssr/canUseDOM.d.ts +4 -0
  174. package/lib-commonjs/ssr/canUseDOM.js +17 -0
  175. package/lib-commonjs/ssr/canUseDOM.js.map +1 -0
  176. package/lib-commonjs/ssr/index.d.ts +2 -0
  177. package/lib-commonjs/ssr/index.js +12 -0
  178. package/lib-commonjs/ssr/index.js.map +1 -0
  179. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +5 -0
  180. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +27 -0
  181. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -0
  182. package/lib-commonjs/utils/clamp.d.ts +8 -0
  183. package/lib-commonjs/utils/clamp.js +18 -0
  184. package/lib-commonjs/utils/clamp.js.map +1 -0
  185. package/lib-commonjs/utils/getNativeElementProps.d.ts +22 -0
  186. package/lib-commonjs/utils/getNativeElementProps.js +58 -25
  187. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  188. package/lib-commonjs/utils/getRTLSafeKey.d.ts +4 -0
  189. package/lib-commonjs/utils/getRTLSafeKey.js +30 -0
  190. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -0
  191. package/lib-commonjs/utils/index.d.ts +5 -0
  192. package/lib-commonjs/utils/index.js +19 -2
  193. package/lib-commonjs/utils/index.js.map +1 -1
  194. package/lib-commonjs/utils/omit.d.ts +1 -1
  195. package/lib-commonjs/utils/omit.js +16 -8
  196. package/lib-commonjs/utils/omit.js.map +1 -1
  197. package/lib-commonjs/utils/onlyChild.d.ts +5 -0
  198. package/lib-commonjs/utils/onlyChild.js +23 -0
  199. package/lib-commonjs/utils/onlyChild.js.map +1 -0
  200. package/lib-commonjs/utils/properties.js +84 -280
  201. package/lib-commonjs/utils/properties.js.map +1 -1
  202. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  203. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +30 -0
  204. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  205. package/package.json +11 -9
  206. package/NOTICE.txt +0 -0
  207. package/config/api-extractor.json +0 -3
  208. package/config/tests.js +0 -7
  209. package/etc/react-utilities.api.md +0 -207
  210. package/just.config.ts +0 -3
  211. package/lib/compose/makeMergeProps.d.ts +0 -15
  212. package/lib/compose/makeMergeProps.js +0 -96
  213. package/lib/compose/makeMergeProps.js.map +0 -1
  214. package/lib/compose/resolveShorthandProps.d.ts +0 -7
  215. package/lib/compose/resolveShorthandProps.js +0 -27
  216. package/lib/compose/resolveShorthandProps.js.map +0 -1
  217. package/lib-amd/compose/getSlots.d.ts +0 -20
  218. package/lib-amd/compose/getSlots.js +0 -51
  219. package/lib-amd/compose/getSlots.js.map +0 -1
  220. package/lib-amd/compose/index.d.ts +0 -5
  221. package/lib-amd/compose/index.js +0 -9
  222. package/lib-amd/compose/index.js.map +0 -1
  223. package/lib-amd/compose/makeMergeProps.d.ts +0 -15
  224. package/lib-amd/compose/makeMergeProps.js +0 -98
  225. package/lib-amd/compose/makeMergeProps.js.map +0 -1
  226. package/lib-amd/compose/nullRender.d.ts +0 -4
  227. package/lib-amd/compose/nullRender.js +0 -9
  228. package/lib-amd/compose/nullRender.js.map +0 -1
  229. package/lib-amd/compose/resolveShorthandProps.d.ts +0 -7
  230. package/lib-amd/compose/resolveShorthandProps.js +0 -29
  231. package/lib-amd/compose/resolveShorthandProps.js.map +0 -1
  232. package/lib-amd/compose/types.d.ts +0 -29
  233. package/lib-amd/compose/types.js +0 -5
  234. package/lib-amd/compose/types.js.map +0 -1
  235. package/lib-amd/hooks/index.d.ts +0 -8
  236. package/lib-amd/hooks/index.js +0 -13
  237. package/lib-amd/hooks/index.js.map +0 -1
  238. package/lib-amd/hooks/useBoolean.d.ts +0 -17
  239. package/lib-amd/hooks/useBoolean.js +0 -26
  240. package/lib-amd/hooks/useBoolean.js.map +0 -1
  241. package/lib-amd/hooks/useConst.d.ts +0 -12
  242. package/lib-amd/hooks/useConst.js +0 -31
  243. package/lib-amd/hooks/useConst.js.map +0 -1
  244. package/lib-amd/hooks/useControllableValue.d.ts +0 -20
  245. package/lib-amd/hooks/useControllableValue.js +0 -42
  246. package/lib-amd/hooks/useControllableValue.js.map +0 -1
  247. package/lib-amd/hooks/useEventCallback.d.ts +0 -13
  248. package/lib-amd/hooks/useEventCallback.js +0 -33
  249. package/lib-amd/hooks/useEventCallback.js.map +0 -1
  250. package/lib-amd/hooks/useId.d.ts +0 -11
  251. package/lib-amd/hooks/useId.js +0 -35
  252. package/lib-amd/hooks/useId.js.map +0 -1
  253. package/lib-amd/hooks/useIsomorphicLayoutEffect.d.ts +0 -2
  254. package/lib-amd/hooks/useIsomorphicLayoutEffect.js +0 -9
  255. package/lib-amd/hooks/useIsomorphicLayoutEffect.js.map +0 -1
  256. package/lib-amd/hooks/useMergedRefs.d.ts +0 -13
  257. package/lib-amd/hooks/useMergedRefs.js +0 -33
  258. package/lib-amd/hooks/useMergedRefs.js.map +0 -1
  259. package/lib-amd/hooks/useOnClickOutside.d.ts +0 -19
  260. package/lib-amd/hooks/useOnClickOutside.js +0 -27
  261. package/lib-amd/hooks/useOnClickOutside.js.map +0 -1
  262. package/lib-amd/index.d.ts +0 -3
  263. package/lib-amd/index.js +0 -8
  264. package/lib-amd/index.js.map +0 -1
  265. package/lib-amd/utils/getNativeElementProps.d.ts +0 -9
  266. package/lib-amd/utils/getNativeElementProps.js +0 -40
  267. package/lib-amd/utils/getNativeElementProps.js.map +0 -1
  268. package/lib-amd/utils/index.d.ts +0 -3
  269. package/lib-amd/utils/index.js +0 -8
  270. package/lib-amd/utils/index.js.map +0 -1
  271. package/lib-amd/utils/omit.d.ts +0 -14
  272. package/lib-amd/utils/omit.js +0 -30
  273. package/lib-amd/utils/omit.js.map +0 -1
  274. package/lib-amd/utils/properties.d.ts +0 -148
  275. package/lib-amd/utils/properties.js +0 -416
  276. package/lib-amd/utils/properties.js.map +0 -1
  277. package/lib-commonjs/compose/makeMergeProps.d.ts +0 -15
  278. package/lib-commonjs/compose/makeMergeProps.js +0 -98
  279. package/lib-commonjs/compose/makeMergeProps.js.map +0 -1
  280. package/lib-commonjs/compose/resolveShorthandProps.d.ts +0 -7
  281. package/lib-commonjs/compose/resolveShorthandProps.js +0 -29
  282. package/lib-commonjs/compose/resolveShorthandProps.js.map +0 -1
  283. package/src/compose/README.md +0 -279
@@ -1,33 +1,36 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var React = require("react");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useMergedRefs = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
5
9
  /**
6
10
  * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
7
11
  * updates all provided refs
8
12
  * @param refs - Refs to collectively update with one ref value.
9
13
  * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
10
14
  */
11
- function useMergedRefs() {
12
- var refs = [];
13
- for (var _i = 0; _i < arguments.length; _i++) {
14
- refs[_i] = arguments[_i];
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
+ }
15
29
  }
16
- var mergedCallback = React.useCallback(function (value) {
17
- // Update the "current" prop hanging on the function.
18
- mergedCallback.current = value;
19
- for (var _i = 0, refs_1 = refs; _i < refs_1.length; _i++) {
20
- var ref = refs_1[_i];
21
- if (typeof ref === 'function') {
22
- ref(value);
23
- }
24
- else if (ref) {
25
- // work around the immutability of the React.Ref type
26
- ref.current = value;
27
- }
28
- }
29
- }, tslib_1.__spreadArrays(refs));
30
- return mergedCallback;
30
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive
31
+ [...refs]);
32
+ return mergedCallback;
31
33
  }
34
+
32
35
  exports.useMergedRefs = useMergedRefs;
33
36
  //# sourceMappingURL=useMergedRefs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMergedRefs.js","sourceRoot":"../src/","sources":["hooks/useMergedRefs.ts"],"names":[],"mappings":";;;AAAA,6BAA+B;AAQ/B;;;;;GAKG;AACH,SAAgB,aAAa;IAAI,cAAqC;SAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;QAArC,yBAAqC;;IACpE,IAAM,cAAc,GAA0B,KAAK,CAAC,WAAW,CAC7D,UAAC,KAAQ;QACP,qDAAqD;QACnD,cAAwD,CAAC,OAAO,GAAG,KAAK,CAAC;QAE3E,KAAkB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE;YAAnB,IAAM,GAAG,aAAA;YACZ,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC7B,GAAG,CAAC,KAAK,CAAC,CAAC;aACZ;iBAAM,IAAI,GAAG,EAAE;gBACd,qDAAqD;gBACnD,GAA6C,CAAC,OAAO,GAAG,KAAK,CAAC;aACjE;SACF;IACH,CAAC,yBAEG,IAAI,EAC2B,CAAC;IAEtC,OAAO,cAAc,CAAC;AACxB,CAAC;AApBD,sCAoBC","sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = (React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n ((mergedCallback as unknown) as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n ((ref as unknown) as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown) as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"]}
1
+ {"version":3,"sources":["../../src/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","sourceRoot":""}
@@ -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":["../../src/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","sourceRoot":""}
@@ -1,19 +1,29 @@
1
1
  import * as React from 'react';
2
- export declare type UseOnClickOutsideOptions = {
2
+ export declare type UseOnClickOrScrollOutsideOptions = {
3
3
  /**
4
4
  * The element to listen for the click event
5
5
  */
6
- element?: Document;
6
+ element: Document | undefined;
7
7
  /**
8
8
  * Refs to elements that check if the click is outside
9
9
  */
10
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;
11
21
  /**
12
22
  * Called if the click is outside the element refs
13
23
  */
14
24
  callback: (ev: MouseEvent | TouchEvent) => void;
15
25
  };
16
26
  /**
17
- * Utility to perform checks where a click/touch event was made outside a compoent
27
+ * Utility to perform checks where a click/touch event was made outside a component
18
28
  */
19
- export declare const useOnClickOutside: (options: UseOnClickOutsideOptions) => void;
29
+ export declare const useOnClickOutside: (options: UseOnClickOrScrollOutsideOptions) => void;
@@ -1,27 +1,147 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var React = require("react");
4
- var useEventCallback_1 = require("./useEventCallback");
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");
5
11
  /**
6
- * Utility to perform checks where a click/touch event was made outside a compoent
12
+ * Utility to perform checks where a click/touch event was made outside a component
7
13
  */
8
- exports.useOnClickOutside = function (options) {
9
- var refs = options.refs, callback = options.callback, _a = options.element, element = _a === void 0 ? document : _a;
10
- var listener = useEventCallback_1.useEventCallback(function (ev) {
11
- var isOutside = refs.every(function (ref) { var _a; return !((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(ev.target)); });
12
- if (isOutside) {
13
- callback(ev);
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);
14
136
  }
15
- });
16
- React.useEffect(function () {
17
- var _a, _b;
18
- (_a = element) === null || _a === void 0 ? void 0 : _a.addEventListener('click', listener);
19
- (_b = element) === null || _b === void 0 ? void 0 : _b.addEventListener('touchstart', listener);
20
- return function () {
21
- var _a, _b;
22
- (_a = element) === null || _a === void 0 ? void 0 : _a.removeEventListener('click', listener);
23
- (_b = element) === null || _b === void 0 ? void 0 : _b.removeEventListener('touchstart', listener);
24
- };
25
- }, [listener, element]);
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]);
26
146
  };
27
147
  //# sourceMappingURL=useOnClickOutside.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOnClickOutside.js","sourceRoot":"../src/","sources":["hooks/useOnClickOutside.ts"],"names":[],"mappings":";;AAAA,6BAA+B;AAC/B,uDAAsD;AAiBtD;;GAEG;AACU,QAAA,iBAAiB,GAAG,UAAC,OAAiC;IACzD,IAAA,mBAAI,EAAE,2BAAQ,EAAE,oBAAkB,EAAlB,uCAAkB,CAAa;IACvD,IAAM,QAAQ,GAAG,mCAAgB,CAAC,UAAC,EAA2B;QAC5D,IAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAA,GAAG,YAAI,OAAA,QAAC,GAAG,CAAC,OAAO,0CAAE,QAAQ,CAAC,EAAE,CAAC,MAAqB,EAAC,CAAA,EAAA,CAAC,CAAC;QACtF,IAAI,SAAS,EAAE;YACb,QAAQ,CAAC,EAAE,CAAC,CAAC;SACd;IACH,CAAC,CAAC,CAAC;IAEH,KAAK,CAAC,SAAS,CAAC;;QACd,MAAA,OAAO,0CAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE;QAC7C,MAAA,OAAO,0CAAE,gBAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE;QAElD,OAAO;;YACL,MAAA,OAAO,0CAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE;YAChD,MAAA,OAAO,0CAAE,mBAAmB,CAAC,YAAY,EAAE,QAAQ,EAAE;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1B,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\nexport type UseOnClickOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element?: Document;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\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 compoent\n */\nexport const useOnClickOutside = (options: UseOnClickOutsideOptions) => {\n const { refs, callback, element = document } = options;\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const isOutside = refs.every(ref => !ref.current?.contains(ev.target as HTMLElement));\n if (isOutside) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n element?.addEventListener('click', listener);\n element?.addEventListener('touchstart', listener);\n\n return () => {\n element?.removeEventListener('click', listener);\n element?.removeEventListener('touchstart', listener);\n };\n }, [listener, element]);\n};\n"]}
1
+ {"version":3,"sources":["../../src/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,M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c,MAAK;AACjE,cAAM,aAAa,GAAG,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,aAAtC;;AACA,YAAI,CAAA,aAAa,KAAA,IAAb,IAAA,aAAa,KAAA,KAAA,CAAb,GAAa,KAAA,CAAb,GAAA,aAAa,CAAE,OAAf,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","sourceRoot":""}
@@ -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;
@@ -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":["../../src/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","sourceRoot":""}
@@ -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":["../../src/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","sourceRoot":""}
@@ -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":["../../src/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","sourceRoot":""}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Hook which synchronously executes a callback when the component is about to unmount.
3
+ *
4
+ * @param callback - Function to call during unmount.
5
+ */
6
+ export declare const useUnmount: (callback: () => void) => void;
@@ -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":["../../src/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","sourceRoot":""}
@@ -1,3 +1,4 @@
1
1
  export * from './compose/index';
2
2
  export * from './hooks/index';
3
+ export * from './ssr/index';
3
4
  export * from './utils/index';
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ const tslib_1 = /*#__PURE__*/require("tslib");
8
+
4
9
  tslib_1.__exportStar(require("./compose/index"), exports);
10
+
5
11
  tslib_1.__exportStar(require("./hooks/index"), exports);
12
+
13
+ tslib_1.__exportStar(require("./ssr/index"), exports);
14
+
6
15
  tslib_1.__exportStar(require("./utils/index"), exports);
7
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,wDAA8B;AAC9B,wDAA8B","sourcesContent":["export * from './compose/index';\nexport * from './hooks/index';\nexport * from './utils/index';\n"]}
1
+ {"version":3,"sources":["../src/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","sourceRoot":""}
@@ -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;