@fluentui/react-utilities 0.0.0-nightly050f89bf0020211102.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/CHANGELOG.json +1637 -0
  2. package/CHANGELOG.md +677 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/dist/react-utilities.d.ts +648 -0
  6. package/lib/compose/getSlots.d.ts +29 -0
  7. package/lib/compose/getSlots.js +72 -0
  8. package/lib/compose/getSlots.js.map +1 -0
  9. package/lib/compose/index.d.ts +4 -0
  10. package/lib/compose/index.js +5 -0
  11. package/lib/compose/index.js.map +1 -0
  12. package/lib/compose/nullRender.d.ts +4 -0
  13. package/lib/compose/nullRender.js +7 -0
  14. package/lib/compose/nullRender.js.map +1 -0
  15. package/lib/compose/resolveShorthand.d.ts +12 -0
  16. package/lib/compose/resolveShorthand.js +30 -0
  17. package/lib/compose/resolveShorthand.js.map +1 -0
  18. package/lib/compose/types.d.ts +104 -0
  19. package/lib/compose/types.js +6 -0
  20. package/lib/compose/types.js.map +1 -0
  21. package/lib/hooks/index.d.ts +16 -0
  22. package/lib/hooks/index.js +17 -0
  23. package/lib/hooks/index.js.map +1 -0
  24. package/lib/hooks/useBoolean.d.ts +17 -0
  25. package/lib/hooks/useBoolean.js +39 -0
  26. package/lib/hooks/useBoolean.js.map +1 -0
  27. package/lib/hooks/useConst.d.ts +12 -0
  28. package/lib/hooks/useConst.js +30 -0
  29. package/lib/hooks/useConst.js.map +1 -0
  30. package/lib/hooks/useControllableState.d.ts +21 -0
  31. package/lib/hooks/useControllableState.js +72 -0
  32. package/lib/hooks/useControllableState.js.map +1 -0
  33. package/lib/hooks/useControllableValue.d.ts +20 -0
  34. package/lib/hooks/useControllableValue.js +62 -0
  35. package/lib/hooks/useControllableValue.js.map +1 -0
  36. package/lib/hooks/useEventCallback.d.ts +13 -0
  37. package/lib/hooks/useEventCallback.js +34 -0
  38. package/lib/hooks/useEventCallback.js.map +1 -0
  39. package/lib/hooks/useFirstMount.d.ts +11 -0
  40. package/lib/hooks/useFirstMount.js +23 -0
  41. package/lib/hooks/useFirstMount.js.map +1 -0
  42. package/lib/hooks/useForceUpdate.d.ts +4 -0
  43. package/lib/hooks/useForceUpdate.js +11 -0
  44. package/lib/hooks/useForceUpdate.js.map +1 -0
  45. package/lib/hooks/useId.d.ts +15 -0
  46. package/lib/hooks/useId.js +27 -0
  47. package/lib/hooks/useId.js.map +1 -0
  48. package/lib/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  49. package/lib/hooks/useIsomorphicLayoutEffect.js +15 -0
  50. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  51. package/lib/hooks/useMergedRefs.d.ts +13 -0
  52. package/lib/hooks/useMergedRefs.js +34 -0
  53. package/lib/hooks/useMergedRefs.js.map +1 -0
  54. package/lib/hooks/useMount.d.ts +6 -0
  55. package/lib/hooks/useMount.js +17 -0
  56. package/lib/hooks/useMount.js.map +1 -0
  57. package/lib/hooks/useOnClickOutside.d.ts +29 -0
  58. package/lib/hooks/useOnClickOutside.js +142 -0
  59. package/lib/hooks/useOnClickOutside.js.map +1 -0
  60. package/lib/hooks/useOnScrollOutside.d.ts +5 -0
  61. package/lib/hooks/useOnScrollOutside.js +38 -0
  62. package/lib/hooks/useOnScrollOutside.js.map +1 -0
  63. package/lib/hooks/usePrevious.d.ts +1 -0
  64. package/lib/hooks/usePrevious.js +9 -0
  65. package/lib/hooks/usePrevious.js.map +1 -0
  66. package/lib/hooks/useTimeout.d.ts +8 -0
  67. package/lib/hooks/useTimeout.js +33 -0
  68. package/lib/hooks/useTimeout.js.map +1 -0
  69. package/lib/hooks/useUnmount.d.ts +6 -0
  70. package/lib/hooks/useUnmount.js +19 -0
  71. package/lib/hooks/useUnmount.js.map +1 -0
  72. package/lib/index.d.ts +4 -0
  73. package/lib/index.js +5 -0
  74. package/lib/index.js.map +1 -0
  75. package/lib/ssr/SSRContext.d.ts +33 -0
  76. package/lib/ssr/SSRContext.js +71 -0
  77. package/lib/ssr/SSRContext.js.map +1 -0
  78. package/lib/ssr/canUseDOM.d.ts +4 -0
  79. package/lib/ssr/canUseDOM.js +8 -0
  80. package/lib/ssr/canUseDOM.js.map +1 -0
  81. package/lib/ssr/index.d.ts +2 -0
  82. package/lib/ssr/index.js +3 -0
  83. package/lib/ssr/index.js.map +1 -0
  84. package/lib/tsdoc-metadata.json +11 -0
  85. package/lib/utils/applyTriggerPropsToChildren.d.ts +5 -0
  86. package/lib/utils/applyTriggerPropsToChildren.js +16 -0
  87. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -0
  88. package/lib/utils/clamp.d.ts +8 -0
  89. package/lib/utils/clamp.js +11 -0
  90. package/lib/utils/clamp.js.map +1 -0
  91. package/lib/utils/getNativeElementProps.d.ts +9 -0
  92. package/lib/utils/getNativeElementProps.js +38 -0
  93. package/lib/utils/getNativeElementProps.js.map +1 -0
  94. package/lib/utils/getRTLSafeKey.d.ts +4 -0
  95. package/lib/utils/getRTLSafeKey.js +21 -0
  96. package/lib/utils/getRTLSafeKey.js.map +1 -0
  97. package/lib/utils/index.d.ts +8 -0
  98. package/lib/utils/index.js +9 -0
  99. package/lib/utils/index.js.map +1 -0
  100. package/lib/utils/omit.d.ts +14 -0
  101. package/lib/utils/omit.js +27 -0
  102. package/lib/utils/omit.js.map +1 -0
  103. package/lib/utils/onlyChild.d.ts +5 -0
  104. package/lib/utils/onlyChild.js +13 -0
  105. package/lib/utils/onlyChild.js.map +1 -0
  106. package/lib/utils/properties.d.ts +148 -0
  107. package/lib/utils/properties.js +218 -0
  108. package/lib/utils/properties.js.map +1 -0
  109. package/lib/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  110. package/lib/utils/shouldPreventDefaultOnKeyDown.js +20 -0
  111. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  112. package/lib-commonjs/compose/getSlots.d.ts +29 -0
  113. package/lib-commonjs/compose/getSlots.js +85 -0
  114. package/lib-commonjs/compose/getSlots.js.map +1 -0
  115. package/lib-commonjs/compose/index.d.ts +4 -0
  116. package/lib-commonjs/compose/index.js +16 -0
  117. package/lib-commonjs/compose/index.js.map +1 -0
  118. package/lib-commonjs/compose/nullRender.d.ts +4 -0
  119. package/lib-commonjs/compose/nullRender.js +16 -0
  120. package/lib-commonjs/compose/nullRender.js.map +1 -0
  121. package/lib-commonjs/compose/resolveShorthand.d.ts +12 -0
  122. package/lib-commonjs/compose/resolveShorthand.js +41 -0
  123. package/lib-commonjs/compose/resolveShorthand.js.map +1 -0
  124. package/lib-commonjs/compose/types.d.ts +104 -0
  125. package/lib-commonjs/compose/types.js +10 -0
  126. package/lib-commonjs/compose/types.js.map +1 -0
  127. package/lib-commonjs/hooks/index.d.ts +16 -0
  128. package/lib-commonjs/hooks/index.js +40 -0
  129. package/lib-commonjs/hooks/index.js.map +1 -0
  130. package/lib-commonjs/hooks/useBoolean.d.ts +17 -0
  131. package/lib-commonjs/hooks/useBoolean.js +50 -0
  132. package/lib-commonjs/hooks/useBoolean.js.map +1 -0
  133. package/lib-commonjs/hooks/useConst.d.ts +12 -0
  134. package/lib-commonjs/hooks/useConst.js +40 -0
  135. package/lib-commonjs/hooks/useConst.js.map +1 -0
  136. package/lib-commonjs/hooks/useControllableState.d.ts +21 -0
  137. package/lib-commonjs/hooks/useControllableState.js +82 -0
  138. package/lib-commonjs/hooks/useControllableState.js.map +1 -0
  139. package/lib-commonjs/hooks/useControllableValue.d.ts +20 -0
  140. package/lib-commonjs/hooks/useControllableValue.js +73 -0
  141. package/lib-commonjs/hooks/useControllableValue.js.map +1 -0
  142. package/lib-commonjs/hooks/useEventCallback.d.ts +13 -0
  143. package/lib-commonjs/hooks/useEventCallback.js +45 -0
  144. package/lib-commonjs/hooks/useEventCallback.js.map +1 -0
  145. package/lib-commonjs/hooks/useFirstMount.d.ts +11 -0
  146. package/lib-commonjs/hooks/useFirstMount.js +33 -0
  147. package/lib-commonjs/hooks/useFirstMount.js.map +1 -0
  148. package/lib-commonjs/hooks/useForceUpdate.d.ts +4 -0
  149. package/lib-commonjs/hooks/useForceUpdate.js +21 -0
  150. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -0
  151. package/lib-commonjs/hooks/useId.d.ts +15 -0
  152. package/lib-commonjs/hooks/useId.js +40 -0
  153. package/lib-commonjs/hooks/useId.js.map +1 -0
  154. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.d.ts +11 -0
  155. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +24 -0
  156. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  157. package/lib-commonjs/hooks/useMergedRefs.d.ts +13 -0
  158. package/lib-commonjs/hooks/useMergedRefs.js +45 -0
  159. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -0
  160. package/lib-commonjs/hooks/useMount.d.ts +6 -0
  161. package/lib-commonjs/hooks/useMount.js +27 -0
  162. package/lib-commonjs/hooks/useMount.js.map +1 -0
  163. package/lib-commonjs/hooks/useOnClickOutside.d.ts +29 -0
  164. package/lib-commonjs/hooks/useOnClickOutside.js +153 -0
  165. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -0
  166. package/lib-commonjs/hooks/useOnScrollOutside.d.ts +5 -0
  167. package/lib-commonjs/hooks/useOnScrollOutside.js +49 -0
  168. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -0
  169. package/lib-commonjs/hooks/usePrevious.d.ts +1 -0
  170. package/lib-commonjs/hooks/usePrevious.js +19 -0
  171. package/lib-commonjs/hooks/usePrevious.js.map +1 -0
  172. package/lib-commonjs/hooks/useTimeout.d.ts +8 -0
  173. package/lib-commonjs/hooks/useTimeout.js +44 -0
  174. package/lib-commonjs/hooks/useTimeout.js.map +1 -0
  175. package/lib-commonjs/hooks/useUnmount.d.ts +6 -0
  176. package/lib-commonjs/hooks/useUnmount.js +29 -0
  177. package/lib-commonjs/hooks/useUnmount.js.map +1 -0
  178. package/lib-commonjs/index.d.ts +4 -0
  179. package/lib-commonjs/index.js +16 -0
  180. package/lib-commonjs/index.js.map +1 -0
  181. package/lib-commonjs/ssr/SSRContext.d.ts +33 -0
  182. package/lib-commonjs/ssr/SSRContext.js +86 -0
  183. package/lib-commonjs/ssr/SSRContext.js.map +1 -0
  184. package/lib-commonjs/ssr/canUseDOM.d.ts +4 -0
  185. package/lib-commonjs/ssr/canUseDOM.js +17 -0
  186. package/lib-commonjs/ssr/canUseDOM.js.map +1 -0
  187. package/lib-commonjs/ssr/index.d.ts +2 -0
  188. package/lib-commonjs/ssr/index.js +12 -0
  189. package/lib-commonjs/ssr/index.js.map +1 -0
  190. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +5 -0
  191. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +27 -0
  192. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -0
  193. package/lib-commonjs/utils/clamp.d.ts +8 -0
  194. package/lib-commonjs/utils/clamp.js +20 -0
  195. package/lib-commonjs/utils/clamp.js.map +1 -0
  196. package/lib-commonjs/utils/getNativeElementProps.d.ts +9 -0
  197. package/lib-commonjs/utils/getNativeElementProps.js +48 -0
  198. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -0
  199. package/lib-commonjs/utils/getRTLSafeKey.d.ts +4 -0
  200. package/lib-commonjs/utils/getRTLSafeKey.js +30 -0
  201. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -0
  202. package/lib-commonjs/utils/index.d.ts +8 -0
  203. package/lib-commonjs/utils/index.js +24 -0
  204. package/lib-commonjs/utils/index.js.map +1 -0
  205. package/lib-commonjs/utils/omit.d.ts +14 -0
  206. package/lib-commonjs/utils/omit.js +36 -0
  207. package/lib-commonjs/utils/omit.js.map +1 -0
  208. package/lib-commonjs/utils/onlyChild.d.ts +5 -0
  209. package/lib-commonjs/utils/onlyChild.js +23 -0
  210. package/lib-commonjs/utils/onlyChild.js.map +1 -0
  211. package/lib-commonjs/utils/properties.d.ts +148 -0
  212. package/lib-commonjs/utils/properties.js +227 -0
  213. package/lib-commonjs/utils/properties.js.map +1 -0
  214. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.d.ts +7 -0
  215. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +30 -0
  216. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -0
  217. package/package.json +55 -0
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var tslib_1 = /*#__PURE__*/require("tslib");
8
+
9
+ tslib_1.__exportStar(require("./useControllableState"), exports);
10
+
11
+ tslib_1.__exportStar(require("./useBoolean"), exports);
12
+
13
+ tslib_1.__exportStar(require("./useConst"), exports);
14
+
15
+ tslib_1.__exportStar(require("./useControllableValue"), exports);
16
+
17
+ tslib_1.__exportStar(require("./useEventCallback"), exports);
18
+
19
+ tslib_1.__exportStar(require("./useFirstMount"), exports);
20
+
21
+ tslib_1.__exportStar(require("./useId"), exports);
22
+
23
+ tslib_1.__exportStar(require("./useIsomorphicLayoutEffect"), exports);
24
+
25
+ tslib_1.__exportStar(require("./useMergedRefs"), exports);
26
+
27
+ tslib_1.__exportStar(require("./useMount"), exports);
28
+
29
+ tslib_1.__exportStar(require("./useOnClickOutside"), exports);
30
+
31
+ tslib_1.__exportStar(require("./useOnScrollOutside"), exports);
32
+
33
+ tslib_1.__exportStar(require("./usePrevious"), exports);
34
+
35
+ tslib_1.__exportStar(require("./useTimeout"), exports);
36
+
37
+ tslib_1.__exportStar(require("./useUnmount"), exports);
38
+
39
+ tslib_1.__exportStar(require("./useForceUpdate"), exports);
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
@@ -0,0 +1,17 @@
1
+ /** Updater callbacks returned by `useBoolean`. */
2
+ export declare type UseBooleanCallbacks = {
3
+ /** Set the value to true. Always has the same identity. */
4
+ setTrue: () => void;
5
+ /** Set the value to false. Always has the same identity. */
6
+ setFalse: () => void;
7
+ /** Toggle the value. Always has the same identity. */
8
+ toggle: () => void;
9
+ };
10
+ /**
11
+ * Hook to store a value and generate callbacks for setting the value to true or false.
12
+ * The identity of the callbacks will always stay the same.
13
+ *
14
+ * @param initialState - Initial value
15
+ * @returns Array with the current value and an object containing the updater callbacks.
16
+ */
17
+ export declare function useBoolean(initialState: boolean): [boolean, UseBooleanCallbacks];
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBoolean = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+
10
+ var useConst_1 = /*#__PURE__*/require("./useConst");
11
+ /**
12
+ * Hook to store a value and generate callbacks for setting the value to true or false.
13
+ * The identity of the callbacks will always stay the same.
14
+ *
15
+ * @param initialState - Initial value
16
+ * @returns Array with the current value and an object containing the updater callbacks.
17
+ */
18
+
19
+
20
+ function useBoolean(initialState) {
21
+ var _a = React.useState(initialState),
22
+ value = _a[0],
23
+ setValue = _a[1];
24
+
25
+ var setTrue = useConst_1.useConst(function () {
26
+ return function () {
27
+ setValue(true);
28
+ };
29
+ });
30
+ var setFalse = useConst_1.useConst(function () {
31
+ return function () {
32
+ setValue(false);
33
+ };
34
+ });
35
+ var toggle = useConst_1.useConst(function () {
36
+ return function () {
37
+ setValue(function (currentValue) {
38
+ return !currentValue;
39
+ });
40
+ };
41
+ });
42
+ return [value, {
43
+ setTrue: setTrue,
44
+ setFalse: setFalse,
45
+ toggle: toggle
46
+ }];
47
+ }
48
+
49
+ exports.useBoolean = useBoolean;
50
+ //# sourceMappingURL=useBoolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;AAYA;;;;;;AAMG;;;AACH,SAAgB,UAAhB,CAA2B,YAA3B,EAAgD;AACxC,MAAA,EAAA,GAAoB,KAAK,CAAC,QAAN,CAAe,YAAf,CAApB;AAAA,MAAC,KAAK,GAAA,EAAA,CAAA,CAAA,CAAN;AAAA,MAAQ,QAAQ,GAAA,EAAA,CAAA,CAAA,CAAhB;;AAEN,MAAM,OAAO,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,YAAA;AAC7B,MAAA,QAAQ,CAAC,IAAD,CAAR;AAD6B,KAAA;AAE9B,GAFe,CAAhB;AAGA,MAAM,QAAQ,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,YAAA;AAC9B,MAAA,QAAQ,CAAC,KAAD,CAAR;AAD8B,KAAA;AAE/B,GAFgB,CAAjB;AAGA,MAAM,MAAM,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,YAAA;AAC5B,MAAA,QAAQ,CAAC,UAAA,YAAA,EAAY;AAAI,eAAA,CAAA,YAAA;AAAa,OAA9B,CAAR;AAD4B,KAAA;AAE7B,GAFc,CAAf;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAO,EAAA,OAAT;AAAW,IAAA,QAAQ,EAAA,QAAnB;AAAqB,IAAA,MAAM,EAAA;AAA3B,GAAR,CAAP;AACD;;AAdD,OAAA,CAAA,UAAA,GAAA,UAAA","sourceRoot":""}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
3
+ * always return the same value (and if the initializer is a function, only call it once).
4
+ * This is similar to setting a private member in a class constructor.
5
+ *
6
+ * If the value should ever change based on dependencies, use `React.useMemo` instead.
7
+ *
8
+ * @param initialValue - Initial value, or function to get the initial value. Similar to `useState`,
9
+ * only the value/function passed in the first time this is called is respected.
10
+ * @returns The value. The identity of this value will always be the same.
11
+ */
12
+ export declare function useConst<T>(initialValue: T | (() => T)): T;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useConst = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+ /**
10
+ * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
11
+ * always return the same value (and if the initializer is a function, only call it once).
12
+ * This is similar to setting a private member in a class constructor.
13
+ *
14
+ * If the value should ever change based on dependencies, use `React.useMemo` instead.
15
+ *
16
+ * @param initialValue - Initial value, or function to get the initial value. Similar to `useState`,
17
+ * only the value/function passed in the first time this is called is respected.
18
+ * @returns The value. The identity of this value will always be the same.
19
+ */
20
+
21
+
22
+ function useConst(initialValue) {
23
+ // Use useRef to store the value because it's the least expensive built-in hook that works here
24
+ // (we could also use `const [value] = React.useState(initialValue)` but that's more expensive
25
+ // internally due to reducer handling which we don't need)
26
+ var ref = React.useRef();
27
+
28
+ if (ref.current === undefined) {
29
+ // Box the value in an object so we can tell if it's initialized even if the initializer
30
+ // returns/is undefined
31
+ ref.current = {
32
+ value: typeof initialValue === 'function' ? initialValue() : initialValue
33
+ };
34
+ }
35
+
36
+ return ref.current.value;
37
+ }
38
+
39
+ exports.useConst = useConst;
40
+ //# sourceMappingURL=useConst.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useConst.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;;AAUG;;;AACH,SAAgB,QAAhB,CAA4B,YAA5B,EAAuD;AACrD;AACA;AACA;AACA,MAAM,GAAG,GAAG,KAAK,CAAC,MAAN,EAAZ;;AACA,MAAI,GAAG,CAAC,OAAJ,KAAgB,SAApB,EAA+B;AAC7B;AACA;AACA,IAAA,GAAG,CAAC,OAAJ,GAAc;AACZ,MAAA,KAAK,EAAE,OAAO,YAAP,KAAwB,UAAxB,GAAsC,YAAyB,EAA/D,GAAoE;AAD/D,KAAd;AAGD;;AACD,SAAO,GAAG,CAAC,OAAJ,CAAY,KAAnB;AACD;;AAbD,OAAA,CAAA,QAAA,GAAA,QAAA","sourceRoot":""}
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ export declare type UseControllableStateOptions<State> = {
3
+ /**
4
+ * User provided default state or factory initializer
5
+ */
6
+ defaultState?: State | (() => State);
7
+ /**
8
+ * User provided controllable state, undefined state means internal state will be used
9
+ */
10
+ state: State | undefined;
11
+ /**
12
+ * Used to initialize state if all user provided states are undefined
13
+ */
14
+ initialState: State;
15
+ };
16
+ /**
17
+ * A useState 'like' hook that allows optional user control
18
+ * Useful for components which allow uncontrolled and controlled behaviour for users
19
+ * @returns - https://reactjs.org/docs/hooks-state.html
20
+ */
21
+ export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React.Dispatch<React.SetStateAction<State>>];
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useControllableState = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+
10
+ var useConst_1 = /*#__PURE__*/require("./useConst");
11
+
12
+ function isUndefined(state) {
13
+ return typeof state === 'undefined';
14
+ }
15
+
16
+ function isFactoryDispatch(newState) {
17
+ return typeof newState === 'function';
18
+ }
19
+ /**
20
+ * A useState 'like' hook that allows optional user control
21
+ * Useful for components which allow uncontrolled and controlled behaviour for users
22
+ * @returns - https://reactjs.org/docs/hooks-state.html
23
+ */
24
+
25
+
26
+ var useControllableState = function (options) {
27
+ var isControlled = useIsControlled(options.state);
28
+ var initialState = isUndefined(options.defaultState) ? options.initialState : options.defaultState;
29
+
30
+ var _a = React.useState(initialState),
31
+ internalState = _a[0],
32
+ setInternalState = _a[1];
33
+
34
+ var state = isControlled ? options.state : internalState;
35
+ var stateRef = React.useRef(state);
36
+ React.useEffect(function () {
37
+ stateRef.current = state;
38
+ }, [state]); // To match the behavior of the setter returned by React.useState, this callback's identity
39
+ // should never change. This means it MUST NOT directly reference variables that can change.
40
+
41
+ var setState = React.useCallback(function (newState) {
42
+ // React dispatch can use a factory
43
+ // https://reactjs.org/docs/hooks-reference.html#functional-updates
44
+ if (isFactoryDispatch(newState)) {
45
+ stateRef.current = newState(stateRef.current);
46
+ } else {
47
+ stateRef.current = newState;
48
+ }
49
+
50
+ setInternalState(stateRef.current);
51
+ }, []);
52
+ return [state, setState];
53
+ };
54
+
55
+ exports.useControllableState = useControllableState;
56
+ /**
57
+ * Helper hook to handle previous comparison of controlled/uncontrolled
58
+ * Prints an error when isControlled value switches between subsequent renders
59
+ * @returns - whether the value is controlled
60
+ */
61
+
62
+ var useIsControlled = function (controlledValue) {
63
+ var isControlled = useConst_1.useConst(controlledValue !== undefined);
64
+
65
+ if (process.env.NODE_ENV !== 'production') {
66
+ // We don't want these warnings in production even though it is against native behaviour
67
+ // eslint-disable-next-line react-hooks/rules-of-hooks
68
+ React.useEffect(function () {
69
+ if (isControlled !== (controlledValue !== undefined)) {
70
+ var error = new Error();
71
+ var controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
72
+ var undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
73
+
74
+ console.error([// Default react error
75
+ '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(' '));
76
+ }
77
+ }, [isControlled, controlledValue]);
78
+ }
79
+
80
+ return isControlled;
81
+ };
82
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AAiBA,SAAS,WAAT,CAAqB,KAArB,EAAmC;AACjC,SAAO,OAAO,KAAP,KAAiB,WAAxB;AACD;;AAED,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;AAIG;;;AACI,IAAM,oBAAoB,GAAG,UAClC,OADkC,EACS;AAE3C,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;AACA,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,YAAT,CAAX,GAAoC,OAAO,CAAC,YAA5C,GAA2D,OAAO,CAAC,YAAxF;;AACM,MAAA,EAAA,GAAoC,KAAK,CAAC,QAAN,CAAsB,YAAtB,CAApC;AAAA,MAAC,aAAa,GAAA,EAAA,CAAA,CAAA,CAAd;AAAA,MAAgB,gBAAgB,GAAA,EAAA,CAAA,CAAA,CAAhC;;AAEN,MAAM,KAAK,GAAG,YAAY,GAAI,OAAO,CAAC,KAAZ,GAA8B,aAAxD;AAEA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,KAAb,CAAjB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,YAAA;AACd,IAAA,QAAQ,CAAC,OAAT,GAAmB,KAAnB;AACD,GAFD,EAEG,CAAC,KAAD,CAFH,EAT2C,CAa3C;AACA;;AACA,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAN,CAAkB,UAAC,QAAD,EAAsC;AACvE;AACA;AACA,QAAI,iBAAiB,CAAC,QAAD,CAArB,EAAiC;AAC/B,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAQ,CAAC,QAAQ,CAAC,OAAV,CAA3B;AACD,KAFD,MAEO;AACL,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAnB;AACD;;AAED,IAAA,gBAAgB,CAAC,QAAQ,CAAC,OAAV,CAAhB;AACD,GAVgB,EAUd,EAVc,CAAjB;AAYA,SAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;AACD,CA7BM;;AAAM,OAAA,CAAA,oBAAA,GAAoB,oBAApB;AA+Bb;;;;AAIG;;AACH,IAAM,eAAe,GAAG,UAAC,eAAD,EAAyB;AAC/C,MAAM,YAAY,GAAG,UAAA,CAAA,QAAA,CAAkB,eAAe,KAAK,SAAtC,CAArB;;AAEA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA;AACA,IAAA,KAAK,CAAC,SAAN,CAAgB,YAAA;AACd,UAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;AACpD,YAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;AAEA,YAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;AAIA,YAAM,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":""}
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ export declare type ChangeCallback<TElement extends HTMLElement, TValue, TEvent extends React.SyntheticEvent<TElement> | undefined> = (ev: TEvent, newValue: TValue | undefined) => void;
3
+ /**
4
+ * Default value can be a value or an initializer
5
+ */
6
+ declare type DefaultValue<TValue> = TValue | (() => TValue);
7
+ /**
8
+ * Hook to manage a value that could be either controlled or uncontrolled, such as a checked state or
9
+ * text box string.
10
+ * @param controlledValue - The controlled value passed in the props. This value will always be used if provided,
11
+ * and the internal state will be updated to reflect it.
12
+ * @param defaultUncontrolledValue - Initial value for the internal state in the uncontrolled case.
13
+ * @returns An array of the current value and an updater callback. Like `React.useState`, the updater
14
+ * callback always has the same identity, and it can take either a new value, or a function which
15
+ * is passed the previous value and returns the new value.
16
+ * @see https://reactjs.org/docs/uncontrolled-components.html
17
+ */
18
+ export declare function useControllableValue<TValue, TElement extends HTMLElement>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>): Readonly<[TValue, (update: React.SetStateAction<TValue>) => void]>;
19
+ export declare function useControllableValue<TValue, TElement extends HTMLElement, TEvent extends React.SyntheticEvent<TElement> | undefined>(controlledValue: TValue, defaultUncontrolledValue: DefaultValue<TValue>, onChange: ChangeCallback<TElement, TValue, TEvent>): Readonly<[TValue, (update: React.SetStateAction<TValue>, ev?: React.FormEvent<TElement>) => void]>;
20
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useControllableValue = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+
10
+ var useConst_1 = /*#__PURE__*/require("./useConst");
11
+
12
+ function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
13
+ var _a = React.useState(defaultUncontrolledValue),
14
+ value = _a[0],
15
+ setValue = _a[1];
16
+
17
+ var isControlled = useIsControlled(controlledValue);
18
+ var currentValue = isControlled ? controlledValue : value; // Duplicate the current value and onChange in refs so they're accessible from
19
+ // setValueOrCallOnChange without creating a new callback every time
20
+
21
+ var valueRef = React.useRef(currentValue);
22
+ var onChangeRef = React.useRef(onChange);
23
+ React.useEffect(function () {
24
+ valueRef.current = currentValue;
25
+ onChangeRef.current = onChange;
26
+ }); // To match the behavior of the setter returned by React.useState, this callback's identity
27
+ // should never change. This means it MUST NOT directly reference variables that can change.
28
+
29
+ var setValueOrCallOnChange = useConst_1.useConst(function () {
30
+ return function (update, ev) {
31
+ // Assuming here that TValue is not a function, because a controllable value will typically
32
+ // be something a user can enter as input
33
+ var newValue = typeof update === 'function' ? update(valueRef.current) : update;
34
+
35
+ if (onChangeRef.current) {
36
+ onChangeRef.current(ev, newValue);
37
+ }
38
+
39
+ if (!isControlled) {
40
+ setValue(newValue);
41
+ }
42
+ };
43
+ });
44
+ return [currentValue, setValueOrCallOnChange];
45
+ }
46
+
47
+ exports.useControllableValue = useControllableValue;
48
+ /**
49
+ * Helper hook to handle previous comparison of controlled/uncontrolled
50
+ * Prints an error when isControlled value switches between subsequent renders
51
+ */
52
+
53
+ var useIsControlled = function (controlledValue) {
54
+ var isControlled = useConst_1.useConst(controlledValue !== undefined);
55
+
56
+ if (process.env.NODE_ENV !== 'production') {
57
+ // We don't want these warnings in production even though it is against native behaviour
58
+ // eslint-disable-next-line react-hooks/rules-of-hooks
59
+ React.useEffect(function () {
60
+ if (isControlled !== (controlledValue !== undefined)) {
61
+ var error = new Error();
62
+ var controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
63
+ var undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
64
+
65
+ console.error([// Default react error
66
+ '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(' '));
67
+ }
68
+ }, [isControlled, controlledValue]);
69
+ }
70
+
71
+ return isControlled;
72
+ };
73
+ //# sourceMappingURL=useControllableValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useControllableValue.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AAqCA,SAAgB,oBAAhB,CAKE,eALF,EAME,wBANF,EAOE,QAPF,EAOqD;AAE7C,MAAA,EAAA,GAAoB,KAAK,CAAC,QAAN,CAAmC,wBAAnC,CAApB;AAAA,MAAC,KAAK,GAAA,EAAA,CAAA,CAAA,CAAN;AAAA,MAAQ,QAAQ,GAAA,EAAA,CAAA,CAAA,CAAhB;;AACN,MAAM,YAAY,GAAG,eAAe,CAAC,eAAD,CAApC;AACA,MAAM,YAAY,GAAG,YAAY,GAAG,eAAH,GAAqB,KAAtD,CAJmD,CAMnD;AACA;;AACA,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAN,CAAa,YAAb,CAAjB;AACA,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAa,QAAb,CAApB;AACA,EAAA,KAAK,CAAC,SAAN,CAAgB,YAAA;AACd,IAAA,QAAQ,CAAC,OAAT,GAAmB,YAAnB;AACA,IAAA,WAAW,CAAC,OAAZ,GAAsB,QAAtB;AACD,GAHD,EAVmD,CAenD;AACA;;AACA,MAAM,sBAAsB,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,UAAC,MAAD,EAAmD,EAAnD,EAA8D;AAC1G;AACA;AACA,UAAM,QAAQ,GAAG,OAAO,MAAP,KAAkB,UAAlB,GAAgC,MAAmB,CAAC,QAAQ,CAAC,OAAV,CAAnD,GAAwE,MAAzF;;AAEA,UAAI,WAAW,CAAC,OAAhB,EAAyB;AACvB,QAAA,WAAW,CAAC,OAAZ,CAAoB,EAApB,EAAyB,QAAzB;AACD;;AAED,UAAI,CAAC,YAAL,EAAmB;AACjB,QAAA,QAAQ,CAAC,QAAD,CAAR;AACD;AAX2C,KAAA;AAY7C,GAZ8B,CAA/B;AAcA,SAAO,CAAC,YAAD,EAAe,sBAAf,CAAP;AACD;;AAvCD,OAAA,CAAA,oBAAA,GAAA,oBAAA;AAyCA;;;AAGG;;AACH,IAAM,eAAe,GAAG,UAAS,eAAT,EAAgC;AACtD,MAAM,YAAY,GAAG,UAAA,CAAA,QAAA,CAAkB,eAAe,KAAK,SAAtC,CAArB;;AAEA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA;AACA,IAAA,KAAK,CAAC,SAAN,CAAgB,YAAA;AACd,UAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;AACpD,YAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;AAEA,YAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;AAIA,YAAM,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":""}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
3
+ *
4
+ * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
5
+ * e.g. user props are dependencies which could change on every render
6
+ * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
7
+ *
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 re-renders
10
+ *
11
+ * @param fn - The callback function that will be used
12
+ */
13
+ export declare const useEventCallback: <Args extends unknown[], Return>(fn: (...args: Args) => Return) => (...args: Args) => Return;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useEventCallback = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+
10
+ var useIsomorphicLayoutEffect_1 = /*#__PURE__*/require("./useIsomorphicLayoutEffect");
11
+ /**
12
+ * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
13
+ *
14
+ * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
15
+ * e.g. user props are dependencies which could change on every render
16
+ * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
17
+ *
18
+ * This should not be used often, but can be a useful re-render optimization since the callback is a ref and
19
+ * will not be invalidated between re-renders
20
+ *
21
+ * @param fn - The callback function that will be used
22
+ */
23
+
24
+
25
+ var useEventCallback = function (fn) {
26
+ var callbackRef = React.useRef(function () {
27
+ throw new Error('Cannot call an event handler while rendering');
28
+ });
29
+ useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(function () {
30
+ callbackRef.current = fn;
31
+ }, [fn]);
32
+ return React.useCallback(function () {
33
+ var args = [];
34
+
35
+ for (var _i = 0; _i < arguments.length; _i++) {
36
+ args[_i] = arguments[_i];
37
+ }
38
+
39
+ var callback = callbackRef.current;
40
+ return callback.apply(void 0, args);
41
+ }, [callbackRef]);
42
+ };
43
+
44
+ exports.useEventCallback = useEventCallback;
45
+ //# sourceMappingURL=useEventCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useEventCallback.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,2BAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;AAEA;;;;;;;;;;;AAWG;;;AACI,IAAM,gBAAgB,GAAG,UAAiC,EAAjC,EAA8D;AAC5F,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,YAAA;AAC1C,UAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;AACD,GAFmB,CAApB;AAIA,EAAA,2BAAA,CAAA,yBAAA,CAA0B,YAAA;AACxB,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFD,EAEG,CAAC,EAAD,CAFH;AAIA,SAAO,KAAK,CAAC,WAAN,CACL,YAAA;AAAC,QAAA,IAAA,GAAA,EAAA;;SAAA,IAAA,EAAA,GAAA,C,EAAA,EAAA,GAAA,SAAA,CAAA,M,EAAA,EAAA,E,EAAa;AAAb,MAAA,IAAA,CAAA,EAAA,CAAA,GAAA,SAAA,CAAA,EAAA,CAAA;;;AACC,QAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;AACA,WAAO,QAAQ,CAAA,KAAR,CAAQ,KAAA,CAAR,EAAY,IAAZ,CAAP;AACD,GAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","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,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useFirstMount = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+ /**
10
+ * Checks if components was mounted the first time.
11
+ * Since concurrent mode will be released in the future this needs to be verified
12
+ * Currently (React 17) will always render the initial mount once
13
+ * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx
14
+ * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx
15
+ *
16
+ * @example
17
+ * const isFirstMount = useFirstMount();
18
+ */
19
+
20
+
21
+ function useFirstMount() {
22
+ var isFirst = React.useRef(true);
23
+
24
+ if (isFirst.current) {
25
+ isFirst.current = false;
26
+ return true;
27
+ }
28
+
29
+ return isFirst.current;
30
+ }
31
+
32
+ exports.useFirstMount = useFirstMount;
33
+ //# sourceMappingURL=useFirstMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useFirstMount.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;AASG;;;AACH,SAAgB,aAAhB,GAA6B;AAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;AAEA,MAAI,OAAO,CAAC,OAAZ,EAAqB;AACnB,IAAA,OAAO,CAAC,OAAR,GAAkB,KAAlB;AACA,WAAO,IAAP;AACD;;AAED,SAAO,OAAO,CAAC,OAAf;AACD;;AATD,OAAA,CAAA,aAAA,GAAA,aAAA","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,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useForceUpdate = void 0;
7
+
8
+ var react_1 = /*#__PURE__*/require("react");
9
+ /**
10
+ * Forces a re-render, similar to `forceUpdate` in class components.
11
+ */
12
+
13
+
14
+ function useForceUpdate() {
15
+ return react_1.useReducer(function (x) {
16
+ return x + 1;
17
+ }, 0)[1];
18
+ }
19
+
20
+ exports.useForceUpdate = useForceUpdate;
21
+ //# sourceMappingURL=useForceUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useForceUpdate.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;AAEG;;;AACH,SAAgB,cAAhB,GAA8B;AAC5B,SAAO,OAAA,CAAA,UAAA,CAAW,UAAA,CAAA,EAAC;AAAI,WAAA,CAAC,GAAD,CAAA;AAAK,GAArB,EAAuB,CAAvB,EAA0B,CAA1B,CAAP;AACD;;AAFD,OAAA,CAAA,cAAA,GAAA,cAAA","sourceRoot":""}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Resets generated IDs, should be used only in tests.
3
+ *
4
+ * @private
5
+ */
6
+ export declare function resetIdsForTests(): void;
7
+ /**
8
+ * Hook to generate a unique ID.
9
+ *
10
+ * @param prefix - Optional prefix for the ID
11
+ * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
12
+ * without conditioning the hook call
13
+ * @returns The ID
14
+ */
15
+ export declare function useId(prefix?: string, providedId?: string): string;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useId = exports.resetIdsForTests = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+
10
+ var index_1 = /*#__PURE__*/require("../ssr/index");
11
+ /**
12
+ * Resets generated IDs, should be used only in tests.
13
+ *
14
+ * @private
15
+ */
16
+
17
+
18
+ function resetIdsForTests() {
19
+ index_1.defaultSSRContextValue.current = 0;
20
+ }
21
+
22
+ exports.resetIdsForTests = resetIdsForTests;
23
+ /**
24
+ * Hook to generate a unique ID.
25
+ *
26
+ * @param prefix - Optional prefix for the ID
27
+ * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
28
+ * without conditioning the hook call
29
+ * @returns The ID
30
+ */
31
+
32
+ function useId(prefix, providedId) {
33
+ var contextValue = index_1.useSSRContext();
34
+ return React.useMemo(function () {
35
+ return providedId || "" + prefix + ++contextValue.current;
36
+ }, [prefix, providedId, contextValue]);
37
+ }
38
+
39
+ exports.useId = useId;
40
+ //# sourceMappingURL=useId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useId.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,OAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AAEA;;;;AAIG;;;AACH,SAAgB,gBAAhB,GAAgC;AAC9B,EAAA,OAAA,CAAA,sBAAA,CAAuB,OAAvB,GAAiC,CAAjC;AACD;;AAFD,OAAA,CAAA,gBAAA,GAAA,gBAAA;AAIA;;;;;;;AAOG;;AACH,SAAgB,KAAhB,CAAsB,MAAtB,EAAuC,UAAvC,EAA0D;AACxD,MAAM,YAAY,GAAG,OAAA,CAAA,aAAA,EAArB;AAEA,SAAO,KAAK,CAAC,OAAN,CAAc,YAAA;AAAM,WAAA,UAAU,IAAI,KAAG,MAAH,GAAY,EAAE,YAAY,CAAxC,OAAA;AAAkD,GAAtE,EAAwE,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CAAxE,CAAP;AACD;;AAJD,OAAA,CAAA,KAAA,GAAA,KAAA","sourceRoot":""}
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
4
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
5
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
6
+ * the server.
7
+ *
8
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
9
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
10
+ */
11
+ export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useIsomorphicLayoutEffect = void 0;
7
+
8
+ var React = /*#__PURE__*/require("react");
9
+
10
+ var index_1 = /*#__PURE__*/require("../ssr/index");
11
+ /**
12
+ * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally
13
+ * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to
14
+ * ensure we don't get a render flash for certain operations, but we may also need affected components to render on
15
+ * the server.
16
+ *
17
+ * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85
18
+ * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js
19
+ */
20
+ // eslint-disable-next-line no-restricted-properties
21
+
22
+
23
+ exports.useIsomorphicLayoutEffect = /*#__PURE__*/index_1.canUseDOM() ? React.useLayoutEffect : React.useEffect;
24
+ //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,OAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;AAEA;;;;;;;;AAQG;AACH;;;AACa,OAAA,CAAA,yBAAA,GAAoD,aAAA,OAAA,CAAA,SAAA,KAAc,KAAK,CAAC,eAApB,GAAsC,KAAK,CAAC,SAAhG","sourceRoot":""}