@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,60 +1,57 @@
1
1
  import * as React from 'react';
2
2
  import { useConst } from './useConst';
3
3
  export function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
4
- var _a = React.useState(defaultUncontrolledValue), value = _a[0], setValue = _a[1];
5
- var isControlled = useIsControlled(controlledValue);
6
- var currentValue = isControlled ? controlledValue : value;
7
- // Duplicate the current value and onChange in refs so they're accessible from
8
- // setValueOrCallOnChange without creating a new callback every time
9
- var valueRef = React.useRef(currentValue);
10
- var onChangeRef = React.useRef(onChange);
11
- React.useEffect(function () {
12
- valueRef.current = currentValue;
13
- onChangeRef.current = onChange;
14
- });
15
- // To match the behavior of the setter returned by React.useState, this callback's identity
16
- // should never change. This means it MUST NOT directly reference variables that can change.
17
- var setValueOrCallOnChange = useConst(function () { return function (update, ev) {
18
- // Assuming here that TValue is not a function, because a controllable value will typically
19
- // be something a user can enter as input
20
- var newValue = typeof update === 'function' ? update(valueRef.current) : update;
21
- if (onChangeRef.current) {
22
- onChangeRef.current(ev, newValue);
23
- }
24
- if (!isControlled) {
25
- setValue(newValue);
26
- }
27
- }; });
28
- return [currentValue, setValueOrCallOnChange];
4
+ const [value, setValue] = React.useState(defaultUncontrolledValue);
5
+ const isControlled = useIsControlled(controlledValue);
6
+ const currentValue = isControlled ? controlledValue : value; // Duplicate the current value and onChange in refs so they're accessible from
7
+ // setValueOrCallOnChange without creating a new callback every time
8
+
9
+ const valueRef = React.useRef(currentValue);
10
+ const onChangeRef = React.useRef(onChange);
11
+ React.useEffect(() => {
12
+ valueRef.current = currentValue;
13
+ onChangeRef.current = onChange;
14
+ }); // To match the behavior of the setter returned by React.useState, this callback's identity
15
+ // should never change. This means it MUST NOT directly reference variables that can change.
16
+
17
+ const setValueOrCallOnChange = useConst(() => (update, ev) => {
18
+ // Assuming here that TValue is not a function, because a controllable value will typically
19
+ // be something a user can enter as input
20
+ const newValue = typeof update === 'function' ? update(valueRef.current) : update;
21
+
22
+ if (onChangeRef.current) {
23
+ onChangeRef.current(ev, newValue);
24
+ }
25
+
26
+ if (!isControlled) {
27
+ setValue(newValue);
28
+ }
29
+ });
30
+ return [currentValue, setValueOrCallOnChange];
29
31
  }
30
32
  /**
31
33
  * Helper hook to handle previous comparison of controlled/uncontrolled
32
34
  * Prints an error when isControlled value switches between subsequent renders
33
35
  */
34
- var useIsControlled = function (controlledValue) {
35
- var isControlled = useConst(controlledValue !== undefined);
36
- if (process.env.NODE_ENV !== 'production') {
37
- // We don't want these warnings in production even though it is against native behaviour
38
- // eslint-disable-next-line react-hooks/rules-of-hooks
39
- React.useEffect(function () {
40
- if (isControlled !== (controlledValue !== undefined)) {
41
- var error = new Error();
42
- var controlWarning = isControlled
43
- ? 'a controlled value to be uncontrolled'
44
- : 'an uncontrolled value to be controlled';
45
- var undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';
46
- // eslint-disable-next-line no-console
47
- console.error([
48
- // Default react error
49
- 'A component is changing ' + controlWarning + '. This is likely caused by the value',
50
- 'changing from ' + undefinedWarning + ' value, which should not happen.',
51
- 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',
52
- 'More info: https://reactjs.org/link/controlled-components',
53
- error.stack,
54
- ].join(' '));
55
- }
56
- }, [isControlled, controlledValue]);
57
- }
58
- return isControlled;
36
+
37
+ const useIsControlled = controlledValue => {
38
+ const isControlled = useConst(controlledValue !== undefined);
39
+
40
+ if (process.env.NODE_ENV !== 'production') {
41
+ // We don't want these warnings in production even though it is against native behaviour
42
+ // eslint-disable-next-line react-hooks/rules-of-hooks
43
+ React.useEffect(() => {
44
+ if (isControlled !== (controlledValue !== undefined)) {
45
+ const error = new Error();
46
+ const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
47
+ const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
48
+
49
+ console.error([// Default react error
50
+ 'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));
51
+ }
52
+ }, [isControlled, controlledValue]);
53
+ }
54
+
55
+ return isControlled;
59
56
  };
60
57
  //# sourceMappingURL=useControllableValue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useControllableValue.js","sourceRoot":"../src/","sources":["hooks/useControllableValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqCtC,MAAM,UAAU,oBAAoB,CAKlC,eAAuB,EACvB,wBAA8C,EAC9C,QAAmD;IAE7C,IAAA,6CAAgF,EAA/E,aAAK,EAAE,gBAAwE,CAAC;IACvF,IAAM,YAAY,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;IACtD,IAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;IAE5D,8EAA8E;IAC9E,oEAAoE;IACpE,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3C,KAAK,CAAC,SAAS,CAAC;QACd,QAAQ,CAAC,OAAO,GAAG,YAAY,CAAC;QAChC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,2FAA2F;IAC3F,4FAA4F;IAC5F,IAAM,sBAAsB,GAAG,QAAQ,CAAC,cAAM,OAAA,UAAC,MAAgD,EAAE,EAAW;QAC1G,2FAA2F;QAC3F,yCAAyC;QACzC,IAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAE,MAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAEhG,IAAI,WAAW,CAAC,OAAO,EAAE;YACvB,WAAW,CAAC,OAAO,CAAC,EAAG,EAAE,QAAQ,CAAC,CAAC;SACpC;QAED,IAAI,CAAC,YAAY,EAAE;YACjB,QAAQ,CAAC,QAAQ,CAAC,CAAC;SACpB;IACH,CAAC,EAZ6C,CAY7C,CAAC,CAAC;IAEH,OAAO,CAAC,YAAY,EAAE,sBAAsB,CAAU,CAAC;AACzD,CAAC;AAED;;;GAGG;AACH,IAAM,eAAe,GAAG,UAAS,eAAuB;IACtD,IAAM,YAAY,GAAG,QAAQ,CAAU,eAAe,KAAK,SAAS,CAAC,CAAC;IAEtE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;QACzC,wFAAwF;QACxF,sDAAsD;QACtD,KAAK,CAAC,SAAS,CAAC;YACd,IAAI,YAAY,KAAK,CAAC,eAAe,KAAK,SAAS,CAAC,EAAE;gBACpD,IAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;gBAE1B,IAAM,cAAc,GAAG,YAAY;oBACjC,CAAC,CAAC,uCAAuC;oBACzC,CAAC,CAAC,wCAAwC,CAAC;gBAE7C,IAAM,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,wBAAwB,CAAC;gBAE7F,sCAAsC;gBACtC,OAAO,CAAC,KAAK,CACX;oBACE,sBAAsB;oBACtB,0BAA0B,GAAG,cAAc,GAAG,sCAAsC;oBACpF,gBAAgB,GAAG,gBAAgB,GAAG,kCAAkC;oBACxE,oGAAoG;oBACpG,2DAA2D;oBAC3D,KAAK,CAAC,KAAK;iBACZ,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;aACH;QACH,CAAC,EAAE,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;KACrC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { useConst } from './useConst';\n\nexport type ChangeCallback<\n TElement extends HTMLElement,\n TValue,\n TEvent extends React.SyntheticEvent<TElement> | undefined\n> = (ev: TEvent, newValue: TValue | undefined) => void;\n\n/**\n * Default value can be a value or an initializer\n */\ntype DefaultValue<TValue> = TValue | (() => TValue);\n\n/**\n * Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or\n * text box string.\n * @param controlledValue - The controlled value passed in the props. This value will always be used if provided,\n * and the internal state will be updated to reflect it.\n * @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.\n * @returns An array of the current value and an updater callback. Like `React.useState`, the updater\n * callback always has the same identity, and it can take either a new value, or a function which\n * is passed the previous value and returns the new value.\n * @see https://reactjs.org/docs/uncontrolled-components.html\n */\nexport function useControllableValue<TValue, TElement extends HTMLElement>(\n controlledValue: TValue,\n defaultUncontrolledValue: DefaultValue<TValue>,\n): Readonly<[TValue, (update: React.SetStateAction<TValue>) => void]>;\nexport function useControllableValue<\n TValue,\n TElement extends HTMLElement,\n TEvent extends React.SyntheticEvent<TElement> | undefined\n>(\n controlledValue: TValue,\n defaultUncontrolledValue: DefaultValue<TValue>,\n onChange: ChangeCallback<TElement, TValue, TEvent>,\n): Readonly<[TValue, (update: React.SetStateAction<TValue>, ev?: React.FormEvent<TElement>) => void]>;\nexport function useControllableValue<\n TValue,\n TElement extends HTMLElement,\n TEvent extends React.SyntheticEvent<TElement> | undefined\n>(\n controlledValue: TValue,\n defaultUncontrolledValue: DefaultValue<TValue>,\n onChange?: ChangeCallback<TElement, TValue, TEvent>,\n) {\n const [value, setValue] = React.useState<TValue | undefined>(defaultUncontrolledValue);\n const isControlled = useIsControlled(controlledValue);\n const currentValue = isControlled ? controlledValue : value;\n\n // Duplicate the current value and onChange in refs so they're accessible from\n // setValueOrCallOnChange without creating a new callback every time\n const valueRef = React.useRef(currentValue);\n const onChangeRef = React.useRef(onChange);\n React.useEffect(() => {\n valueRef.current = currentValue;\n onChangeRef.current = onChange;\n });\n\n // To match the behavior of the setter returned by React.useState, this callback's identity\n // should never change. This means it MUST NOT directly reference variables that can change.\n const setValueOrCallOnChange = useConst(() => (update: React.SetStateAction<TValue | undefined>, ev?: TEvent) => {\n // Assuming here that TValue is not a function, because a controllable value will typically\n // be something a user can enter as input\n const newValue = typeof update === 'function' ? (update as Function)(valueRef.current) : update;\n\n if (onChangeRef.current) {\n onChangeRef.current(ev!, newValue);\n }\n\n if (!isControlled) {\n setValue(newValue);\n }\n });\n\n return [currentValue, setValueOrCallOnChange] as const;\n}\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n */\nconst useIsControlled = <TValue>(controlledValue: TValue) => {\n const isControlled = useConst<boolean>(controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"]}
1
+ {"version":3,"sources":["../../src/hooks/useControllableValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;AAqCA,OAAM,SAAU,oBAAV,CAKJ,eALI,EAMJ,wBANI,EAOJ,QAPI,EAO+C;AAEnD,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAmC,wBAAnC,CAA1B;AACA,QAAM,YAAY,GAAG,eAAe,CAAC,eAAD,CAApC;AACA,QAAM,YAAY,GAAG,YAAY,GAAG,eAAH,GAAqB,KAAtD,CAJmD,CAMnD;AACA;;AACA,QAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,YAAb,CAAjB;AACA,QAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAa,QAAb,CAApB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,IAAA,QAAQ,CAAC,OAAT,GAAmB,YAAnB;AACA,IAAA,WAAW,CAAC,OAAZ,GAAsB,QAAtB;AACD,GAHD,EAVmD,CAenD;AACA;;AACA,QAAM,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAD,EAAmD,EAAnD,KAAkE;AAC9G;AACA;AACA,UAAM,QAAQ,GAAG,OAAO,MAAP,KAAkB,UAAlB,GAAgC,MAAmB,CAAC,QAAQ,CAAC,OAAV,CAAnD,GAAwE,MAAzF;;AAEA,QAAI,WAAW,CAAC,OAAhB,EAAyB;AACvB,MAAA,WAAW,CAAC,OAAZ,CAAoB,EAApB,EAAyB,QAAzB;AACD;;AAED,QAAI,CAAC,YAAL,EAAmB;AACjB,MAAA,QAAQ,CAAC,QAAD,CAAR;AACD;AACF,GAZsC,CAAvC;AAcA,SAAO,CAAC,YAAD,EAAe,sBAAf,CAAP;AACD;AAED;;;AAGG;;AACH,MAAM,eAAe,GAAY,eAAT,IAAoC;AAC1D,QAAM,YAAY,GAAG,QAAQ,CAAU,eAAe,KAAK,SAA9B,CAA7B;;AAEA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA;AACA,IAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,UAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;AACpD,cAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;AAEA,cAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;AAIA,cAAM,gBAAgB,GAAG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;AACA,QAAA,OAAO,CAAC,KAAR,CACE,CACE;AACA,qCAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;AAUD;AACF,KAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;AAuBD;;AAED,SAAO,YAAP;AACD,CAhCD","sourceRoot":""}
@@ -2,11 +2,11 @@
2
2
  * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
3
3
  *
4
4
  * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
5
- * e.g. user props are depedencies which could change on every render
5
+ * e.g. user props are dependencies which could change on every render
6
6
  * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
7
7
  *
8
8
  * This should not be used often, but can be a useful re-render optimization since the callback is a ref and
9
- * will not be invalidated between rerenders
9
+ * will not be invalidated between re-renders
10
10
  *
11
11
  * @param fn - The callback function that will be used
12
12
  */
@@ -4,28 +4,25 @@ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
4
4
  * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
5
5
  *
6
6
  * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
7
- * e.g. user props are depedencies which could change on every render
7
+ * e.g. user props are dependencies which could change on every render
8
8
  * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
9
9
  *
10
10
  * This should not be used often, but can be a useful re-render optimization since the callback is a ref and
11
- * will not be invalidated between rerenders
11
+ * will not be invalidated between re-renders
12
12
  *
13
13
  * @param fn - The callback function that will be used
14
14
  */
15
- export var useEventCallback = function (fn) {
16
- var callbackRef = React.useRef(function () {
17
- throw new Error('Cannot call an event handler while rendering');
18
- });
19
- useIsomorphicLayoutEffect(function () {
20
- callbackRef.current = fn;
21
- }, [fn]);
22
- return React.useCallback(function () {
23
- var args = [];
24
- for (var _i = 0; _i < arguments.length; _i++) {
25
- args[_i] = arguments[_i];
26
- }
27
- var callback = callbackRef.current;
28
- return callback.apply(void 0, args);
29
- }, [callbackRef]);
15
+
16
+ export const useEventCallback = fn => {
17
+ const callbackRef = React.useRef(() => {
18
+ throw new Error('Cannot call an event handler while rendering');
19
+ });
20
+ useIsomorphicLayoutEffect(() => {
21
+ callbackRef.current = fn;
22
+ }, [fn]);
23
+ return React.useCallback((...args) => {
24
+ const callback = callbackRef.current;
25
+ return callback(...args);
26
+ }, [callbackRef]);
30
27
  };
31
28
  //# sourceMappingURL=useEventCallback.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEventCallback.js","sourceRoot":"../src/","sources":["hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAiC,EAA6B;IAC5F,IAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAY;QAC1C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,yBAAyB,CAAC;QACxB,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;IAC3B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAET,OAAO,KAAK,CAAC,WAAW,CACtB;QAAC,cAAa;aAAb,UAAa,EAAb,qBAAa,EAAb,IAAa;YAAb,yBAAa;;QACZ,IAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;QACrC,OAAO,QAAQ,eAAI,IAAI,EAAE;IAC3B,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CAAC;AACJ,CAAC,CAAC","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 depedencies 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 rerenders\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"]}
1
+ {"version":3,"sources":["../../src/hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;;;;;;;;;;AAWG;;AACH,OAAO,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,yBAAyB,CAAC,MAAK;AAC7B,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFwB,EAEtB,CAAC,EAAD,CAFsB,CAAzB;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","sourceRoot":""}
@@ -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,23 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Checks if components was mounted the first time.
4
+ * Since concurrent mode will be released in the future this needs to be verified
5
+ * Currently (React 17) will always render the initial mount once
6
+ * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
7
+ * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
8
+ *
9
+ * @example
10
+ * const isFirstMount = useFirstMount();
11
+ */
12
+
13
+ export function useFirstMount() {
14
+ const isFirst = React.useRef(true);
15
+
16
+ if (isFirst.current) {
17
+ isFirst.current = false;
18
+ return true;
19
+ }
20
+
21
+ return isFirst.current;
22
+ }
23
+ //# sourceMappingURL=useFirstMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useFirstMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;AASG;;AACH,OAAM,SAAU,aAAV,GAAuB;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","sourceRoot":""}
@@ -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,9 @@
1
+ import { useReducer } from 'react';
2
+ /**
3
+ * Forces a re-render, similar to `forceUpdate` in class components.
4
+ */
5
+
6
+ export function useForceUpdate() {
7
+ return useReducer(x => x + 1, 0)[1];
8
+ }
9
+ //# sourceMappingURL=useForceUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useForceUpdate.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,OAA3B;AAEA;;AAEG;;AACH,OAAM,SAAU,cAAV,GAAwB;AAC5B,SAAO,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAV,EAAa,CAAb,CAAV,CAA0B,CAA1B,CAAP;AACD","sourceRoot":""}
@@ -1,7 +1,11 @@
1
- export declare function getId(prefix?: string): string;
2
- export declare function resetIds(): void;
3
1
  /**
4
- * Hook to generate a unique ID in the global scope (spanning across duplicate copies of the same library).
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.
5
9
  *
6
10
  * @param prefix - Optional prefix for the ID
7
11
  * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
@@ -1,29 +1,25 @@
1
1
  import * as React from 'react';
2
- // TODO
3
- // getId() is a temporary approach, useId() should be reimplemented to properly support SSR & scenarios with
4
- // different globals (document, window)
5
- var id = 0;
6
- export function getId(prefix) {
7
- return (prefix || '') + id++;
8
- }
9
- export function resetIds() {
10
- id = 0;
2
+ import { defaultSSRContextValue, useSSRContext } from '../ssr/index';
3
+ /**
4
+ * Resets generated IDs, should be used only in tests.
5
+ *
6
+ * @private
7
+ */
8
+
9
+ export function resetIdsForTests() {
10
+ defaultSSRContextValue.current = 0;
11
11
  }
12
12
  /**
13
- * Hook to generate a unique ID in the global scope (spanning across duplicate copies of the same library).
13
+ * Hook to generate a unique ID.
14
14
  *
15
15
  * @param prefix - Optional prefix for the ID
16
16
  * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
17
17
  * without conditioning the hook call
18
18
  * @returns The ID
19
19
  */
20
+
20
21
  export function useId(prefix, providedId) {
21
- // getId should only be called once since it updates the global constant for the next ID value.
22
- // (While an extra update isn't likely to cause problems in practice, it's better to avoid it.)
23
- var ref = React.useRef(providedId);
24
- if (!ref.current) {
25
- ref.current = getId(prefix);
26
- }
27
- return ref.current;
22
+ const contextValue = useSSRContext();
23
+ return React.useMemo(() => providedId || `${prefix}${++contextValue.current}`, [prefix, providedId, contextValue]);
28
24
  }
29
25
  //# sourceMappingURL=useId.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useId.js","sourceRoot":"../src/","sources":["hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO;AACP,4GAA4G;AAC5G,uCAAuC;AACvC,IAAI,EAAE,GAAG,CAAC,CAAC;AAEX,MAAM,UAAU,KAAK,CAAC,MAAe;IACnC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,QAAQ;IACtB,EAAE,GAAG,CAAC,CAAC;AACT,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CAAC,MAAe,EAAE,UAAmB;IACxD,+FAA+F;IAC/F,+FAA+F;IAC/F,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAqB,UAAU,CAAC,CAAC;IACzD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;QAChB,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;KAC7B;IACD,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC","sourcesContent":["import * as React from 'react';\n// TODO\n// getId() is a temporary approach, useId() should be reimplemented to properly support SSR & scenarios with\n// different globals (document, window)\nlet id = 0;\n\nexport function getId(prefix?: string): string {\n return (prefix || '') + id++;\n}\n\nexport function resetIds(): void {\n id = 0;\n}\n\n/**\n * Hook to generate a unique ID in the global scope (spanning across duplicate copies of the same library).\n *\n * @param prefix - Optional prefix for the ID\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, providedId?: string): string {\n // getId should only be called once since it updates the global constant for the next ID value.\n // (While an extra update isn't likely to cause problems in practice, it's better to avoid it.)\n const ref = React.useRef<string | undefined>(providedId);\n if (!ref.current) {\n ref.current = getId(prefix);\n }\n return ref.current;\n}\n"]}
1
+ {"version":3,"sources":["../../src/hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,sBAAT,EAAiC,aAAjC,QAAsD,cAAtD;AAEA;;;;AAIG;;AACH,OAAM,SAAU,gBAAV,GAA0B;AAC9B,EAAA,sBAAsB,CAAC,OAAvB,GAAiC,CAAjC;AACD;AAED;;;;;;;AAOG;;AACH,OAAM,SAAU,KAAV,CAAgB,MAAhB,EAAiC,UAAjC,EAAoD;AACxD,QAAM,YAAY,GAAG,aAAa,EAAlC;AAEA,SAAO,KAAK,CAAC,OAAN,CAAc,MAAM,UAAU,IAAI,GAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAO,EAApE,EAAwE,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CAAxE,CAAP;AACD","sourceRoot":""}
@@ -1,2 +1,11 @@
1
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
+ */
2
11
  export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
@@ -1,6 +1,15 @@
1
1
  import * as React from 'react';
2
- var isSSR = typeof window === 'undefined' || /ServerSideRendering/.test(window.navigator && window.navigator.userAgent);
3
- // useLayoutEffect() produces a warning with SSR rendering
4
- // https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
5
- export var useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect;
2
+ import { canUseDOM } from '../ssr/index';
3
+ /**
4
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
5
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
6
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
7
+ * the server.
8
+ *
9
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
10
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
11
+ */
12
+ // eslint-disable-next-line no-restricted-properties
13
+
14
+ export const useIsomorphicLayoutEffect = /*#__PURE__*/canUseDOM() ? React.useLayoutEffect : React.useEffect;
6
15
  //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"../src/","sources":["hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,IAAM,KAAK,GACT,OAAO,MAAM,KAAK,WAAW,IAAI,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;AAE9G,0DAA0D;AAC1D,2EAA2E;AAC3E,MAAM,CAAC,IAAM,yBAAyB,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC","sourcesContent":["import * as React from 'react';\n\nconst isSSR =\n typeof window === 'undefined' || /ServerSideRendering/.test(window.navigator && window.navigator.userAgent);\n\n// useLayoutEffect() produces a warning with SSR rendering\n// https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a\nexport const useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect;\n"]}
1
+ {"version":3,"sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,cAA1B;AAEA;;;;;;;;AAQG;AACH;;AACA,OAAO,MAAM,yBAAyB,GAA2B,aAAA,SAAS,KAAK,KAAK,CAAC,eAAX,GAA6B,KAAK,CAAC,SAAtG","sourceRoot":""}
@@ -1,4 +1,3 @@
1
- import { __spreadArrays } from "tslib";
2
1
  import * as React from 'react';
3
2
  /**
4
3
  * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
@@ -6,25 +5,22 @@ import * as React from 'react';
6
5
  * @param refs - Refs to collectively update with one ref value.
7
6
  * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
8
7
  */
9
- export function useMergedRefs() {
10
- var refs = [];
11
- for (var _i = 0; _i < arguments.length; _i++) {
12
- refs[_i] = arguments[_i];
8
+
9
+ export function useMergedRefs(...refs) {
10
+ const mergedCallback = React.useCallback(value => {
11
+ // Update the "current" prop hanging on the function.
12
+ mergedCallback.current = value;
13
+
14
+ for (const ref of refs) {
15
+ if (typeof ref === 'function') {
16
+ ref(value);
17
+ } else if (ref) {
18
+ // work around the immutability of the React.Ref type
19
+ ref.current = value;
20
+ }
13
21
  }
14
- var mergedCallback = React.useCallback(function (value) {
15
- // Update the "current" prop hanging on the function.
16
- mergedCallback.current = value;
17
- for (var _i = 0, refs_1 = refs; _i < refs_1.length; _i++) {
18
- var ref = refs_1[_i];
19
- if (typeof ref === 'function') {
20
- ref(value);
21
- }
22
- else if (ref) {
23
- // work around the immutability of the React.Ref type
24
- ref.current = value;
25
- }
26
- }
27
- }, __spreadArrays(refs));
28
- return mergedCallback;
22
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive
23
+ [...refs]);
24
+ return mergedCallback;
29
25
  }
30
26
  //# sourceMappingURL=useMergedRefs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMergedRefs.js","sourceRoot":"../src/","sources":["hooks/useMergedRefs.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B;;;;;GAKG;AACH,MAAM,UAAU,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,iBAEG,IAAI,EAC2B,CAAC;IAEtC,OAAO,cAAc,CAAC;AACxB,CAAC","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,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAQA;;;;;AAKG;;AACH,OAAM,SAAU,aAAV,CAA2B,GAAG,IAA9B,EAAgE;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","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,17 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * Hook which asynchronously executes a callback once the component has been mounted.
4
+ *
5
+ * @param callback - Function to call before mount.
6
+ */
7
+
8
+ export const useMount = callback => {
9
+ const mountRef = React.useRef(callback);
10
+ mountRef.current = callback;
11
+ React.useEffect(() => {
12
+ var _a;
13
+
14
+ (_a = mountRef.current) === null || _a === void 0 ? void 0 : _a.call(mountRef);
15
+ }, []);
16
+ };
17
+ //# sourceMappingURL=useMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;AAIG;;AACH,OAAO,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","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;