@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,7 +0,0 @@
1
- /**
2
- * Ensures that the given slots are represented using object syntax. This ensures that
3
- * the object can be merged along with other objects.
4
- * @param props - The incoming props
5
- * @param shorthandPropNames - An array of prop names to apply simplification to
6
- */
7
- export declare const resolveShorthandProps: <TProps>(props: TProps, shorthandPropNames: string[]) => TProps;
@@ -1,29 +0,0 @@
1
- define(["require", "exports", "tslib", "react"], function (require, exports, tslib_1, React) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * Ensures that the given slots are represented using object syntax. This ensures that
6
- * the object can be merged along with other objects.
7
- * @param props - The incoming props
8
- * @param shorthandPropNames - An array of prop names to apply simplification to
9
- */
10
- exports.resolveShorthandProps = function (props, shorthandPropNames) {
11
- var newProps = props;
12
- if (shorthandPropNames && shorthandPropNames.length) {
13
- newProps = tslib_1.__assign({}, props);
14
- for (var _i = 0, shorthandPropNames_1 = shorthandPropNames; _i < shorthandPropNames_1.length; _i++) {
15
- var propName = shorthandPropNames_1[_i];
16
- // TODO find clean way of guaranteeing only shorthand props are typechecked
17
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18
- // @ts-ignore
19
- var propValue = props[propName];
20
- if (propValue !== undefined && (typeof propValue !== 'object' || React.isValidElement(propValue))) {
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- newProps[propName] = { children: propValue };
23
- }
24
- }
25
- }
26
- return newProps;
27
- };
28
- });
29
- //# sourceMappingURL=resolveShorthandProps.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolveShorthandProps.js","sourceRoot":"../src/","sources":["compose/resolveShorthandProps.tsx"],"names":[],"mappings":";;;IAEA;;;;;OAKG;IACU,QAAA,qBAAqB,GAAG,UAAU,KAAa,EAAE,kBAA4B;QACxF,IAAI,QAAQ,GAAG,KAAK,CAAC;QAErB,IAAI,kBAAkB,IAAI,kBAAkB,CAAC,MAAM,EAAE;YACnD,QAAQ,wBACH,KAAK,CACT,CAAC;YACF,KAAuB,UAAkB,EAAlB,yCAAkB,EAAlB,gCAAkB,EAAlB,IAAkB,EAAE;gBAAtC,IAAM,QAAQ,2BAAA;gBACjB,2EAA2E;gBAC3E,6DAA6D;gBAC7D,aAAa;gBACb,IAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAElC,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,OAAO,SAAS,KAAK,QAAQ,IAAI,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE;oBACjG,8DAA8D;oBAC7D,QAAgB,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;iBACvD;aACF;SACF;QAED,OAAO,QAAkB,CAAC;IAC5B,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\n/**\n * Ensures that the given slots are represented using object syntax. This ensures that\n * the object can be merged along with other objects.\n * @param props - The incoming props\n * @param shorthandPropNames - An array of prop names to apply simplification to\n */\nexport const resolveShorthandProps = <TProps,>(props: TProps, shorthandPropNames: string[]) => {\n let newProps = props;\n\n if (shorthandPropNames && shorthandPropNames.length) {\n newProps = {\n ...props,\n };\n for (const propName of shorthandPropNames) {\n // TODO find clean way of guaranteeing only shorthand props are typechecked\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const propValue = props[propName];\n\n if (propValue !== undefined && (typeof propValue !== 'object' || React.isValidElement(propValue))) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (newProps as any)[propName] = { children: propValue };\n }\n }\n }\n\n return newProps as TProps;\n};\n"]}
@@ -1,29 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Generic name to any dictionary.
4
- */
5
- export declare type GenericDictionary = Record<string, any>;
6
- /**
7
- * Class dictionary.
8
- */
9
- export declare type ClassDictionary = Record<string, string>;
10
- export interface ComponentProps {
11
- as?: React.ElementType;
12
- className?: string;
13
- children?: React.ReactNode;
14
- }
15
- export declare type ShorthandRenderFunction<TProps> = (Component: React.ElementType<TProps>, props: TProps) => React.ReactNode;
16
- export declare type ShorthandProps<TProps extends ComponentProps = {}> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | boolean | number | null | undefined | (TProps & ComponentProps & {
17
- children?: TProps['children'] | ShorthandRenderFunction<TProps>;
18
- });
19
- export declare type ObjectShorthandProps<TProps extends ComponentProps = {}> = TProps & {
20
- children?: TProps['children'] | ShorthandRenderFunction<TProps>;
21
- };
22
- export interface BaseSlots {
23
- root: React.ElementType;
24
- }
25
- export declare type SlotProps<TSlots extends BaseSlots, TProps, TRootProps extends React.HTMLAttributes<HTMLElement>> = {
26
- [key in keyof Omit<TSlots, 'root'>]: key extends keyof TProps ? TProps[key] : any;
27
- } & {
28
- root: TRootProps;
29
- };
@@ -1,5 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- });
5
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["compose/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\n/**\n * Generic name to any dictionary.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type GenericDictionary = Record<string, any>;\n\n/**\n * Class dictionary.\n */\nexport type ClassDictionary = Record<string, string>;\n\nexport interface ComponentProps {\n as?: React.ElementType;\n className?: string;\n children?: React.ReactNode;\n}\n\n// Shorthand types\n\nexport type ShorthandRenderFunction<TProps> = (Component: React.ElementType<TProps>, props: TProps) => React.ReactNode;\n\nexport type ShorthandProps<TProps extends ComponentProps = {}> =\n | React.ReactChild\n | React.ReactNodeArray\n | React.ReactPortal\n | boolean\n | number\n | null\n | undefined\n | (TProps &\n ComponentProps & {\n children?: TProps['children'] | ShorthandRenderFunction<TProps>;\n });\n\nexport type ObjectShorthandProps<TProps extends ComponentProps = {}> = TProps & {\n children?: TProps['children'] | ShorthandRenderFunction<TProps>;\n};\n\nexport interface BaseSlots {\n root: React.ElementType;\n}\n\nexport type SlotProps<TSlots extends BaseSlots, TProps, TRootProps extends React.HTMLAttributes<HTMLElement>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [key in keyof Omit<TSlots, 'root'>]: key extends keyof TProps ? TProps[key] : any;\n} & {\n root: TRootProps;\n};\n"]}
@@ -1,8 +0,0 @@
1
- export * from './useBoolean';
2
- export * from './useConst';
3
- export * from './useControllableValue';
4
- export * from './useEventCallback';
5
- export { useId } from './useId';
6
- export * from './useIsomorphicLayoutEffect';
7
- export * from './useMergedRefs';
8
- export * from './useOnClickOutside';
@@ -1,13 +0,0 @@
1
- define(["require", "exports", "tslib", "./useBoolean", "./useConst", "./useControllableValue", "./useEventCallback", "./useId", "./useIsomorphicLayoutEffect", "./useMergedRefs", "./useOnClickOutside"], function (require, exports, tslib_1, useBoolean_1, useConst_1, useControllableValue_1, useEventCallback_1, useId_1, useIsomorphicLayoutEffect_1, useMergedRefs_1, useOnClickOutside_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- tslib_1.__exportStar(useBoolean_1, exports);
5
- tslib_1.__exportStar(useConst_1, exports);
6
- tslib_1.__exportStar(useControllableValue_1, exports);
7
- tslib_1.__exportStar(useEventCallback_1, exports);
8
- exports.useId = useId_1.useId;
9
- tslib_1.__exportStar(useIsomorphicLayoutEffect_1, exports);
10
- tslib_1.__exportStar(useMergedRefs_1, exports);
11
- tslib_1.__exportStar(useOnClickOutside_1, exports);
12
- });
13
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":";;;IAAA,4CAA6B;IAC7B,0CAA2B;IAC3B,sDAAuC;IACvC,kDAAmC;IAC1B,wBAAA,KAAK,CAAA;IACd,2DAA4C;IAC5C,+CAAgC;IAChC,mDAAoC","sourcesContent":["export * from './useBoolean';\nexport * from './useConst';\nexport * from './useControllableValue';\nexport * from './useEventCallback';\nexport { useId } from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\n"]}
@@ -1,17 +0,0 @@
1
- /** Updater callbacks returned by `useBoolean`. */
2
- export interface 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];
@@ -1,26 +0,0 @@
1
- define(["require", "exports", "react", "./useConst"], function (require, exports, React, useConst_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * Hook to store a value and generate callbacks for setting the value to true or false.
6
- * The identity of the callbacks will always stay the same.
7
- *
8
- * @param initialState - Initial value
9
- * @returns Array with the current value and an object containing the updater callbacks.
10
- */
11
- function useBoolean(initialState) {
12
- var _a = React.useState(initialState), value = _a[0], setValue = _a[1];
13
- var setTrue = useConst_1.useConst(function () { return function () {
14
- setValue(true);
15
- }; });
16
- var setFalse = useConst_1.useConst(function () { return function () {
17
- setValue(false);
18
- }; });
19
- var toggle = useConst_1.useConst(function () { return function () {
20
- setValue(function (currentValue) { return !currentValue; });
21
- }; });
22
- return [value, { setTrue: setTrue, setFalse: setFalse, toggle: toggle }];
23
- }
24
- exports.useBoolean = useBoolean;
25
- });
26
- //# sourceMappingURL=useBoolean.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useBoolean.js","sourceRoot":"../src/","sources":["hooks/useBoolean.ts"],"names":[],"mappings":";;;IAaA;;;;;;OAMG;IACH,SAAgB,UAAU,CAAC,YAAqB;QACxC,IAAA,iCAAgD,EAA/C,aAAK,EAAE,gBAAwC,CAAC;QAEvD,IAAM,OAAO,GAAG,mBAAQ,CAAC,cAAM,OAAA;YAC7B,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC,EAF8B,CAE9B,CAAC,CAAC;QACH,IAAM,QAAQ,GAAG,mBAAQ,CAAC,cAAM,OAAA;YAC9B,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,EAF+B,CAE/B,CAAC,CAAC;QACH,IAAM,MAAM,GAAG,mBAAQ,CAAC,cAAM,OAAA;YAC5B,QAAQ,CAAC,UAAA,YAAY,IAAI,OAAA,CAAC,YAAY,EAAb,CAAa,CAAC,CAAC;QAC1C,CAAC,EAF6B,CAE7B,CAAC,CAAC;QAEH,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,SAAA,EAAE,QAAQ,UAAA,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IAChD,CAAC;IAdD,gCAcC","sourcesContent":["import * as React from 'react';\nimport { useConst } from './useConst';\n\n/** Updater callbacks returned by `useBoolean`. */\nexport interface UseBooleanCallbacks {\n /** Set the value to true. Always has the same identity. */\n setTrue: () => void;\n /** Set the value to false. Always has the same identity. */\n setFalse: () => void;\n /** Toggle the value. Always has the same identity. */\n toggle: () => void;\n}\n\n/**\n * Hook to store a value and generate callbacks for setting the value to true or false.\n * The identity of the callbacks will always stay the same.\n *\n * @param initialState - Initial value\n * @returns Array with the current value and an object containing the updater callbacks.\n */\nexport function useBoolean(initialState: boolean): [boolean, UseBooleanCallbacks] {\n const [value, setValue] = React.useState(initialState);\n\n const setTrue = useConst(() => () => {\n setValue(true);\n });\n const setFalse = useConst(() => () => {\n setValue(false);\n });\n const toggle = useConst(() => () => {\n setValue(currentValue => !currentValue);\n });\n\n return [value, { setTrue, setFalse, toggle }];\n}\n"]}
@@ -1,12 +0,0 @@
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;
@@ -1,31 +0,0 @@
1
- define(["require", "exports", "react"], function (require, exports, React) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
6
- * always return the same value (and if the initializer is a function, only call it once).
7
- * This is similar to setting a private member in a class constructor.
8
- *
9
- * If the value should ever change based on dependencies, use `React.useMemo` instead.
10
- *
11
- * @param initialValue - Initial value, or function to get the initial value. Similar to `useState`,
12
- * only the value/function passed in the first time this is called is respected.
13
- * @returns The value. The identity of this value will always be the same.
14
- */
15
- function useConst(initialValue) {
16
- // Use useRef to store the value because it's the least expensive built-in hook that works here
17
- // (we could also use `const [value] = React.useState(initialValue)` but that's more expensive
18
- // internally due to reducer handling which we don't need)
19
- var ref = React.useRef();
20
- if (ref.current === undefined) {
21
- // Box the value in an object so we can tell if it's initialized even if the initializer
22
- // returns/is undefined
23
- ref.current = {
24
- value: typeof initialValue === 'function' ? initialValue() : initialValue,
25
- };
26
- }
27
- return ref.current.value;
28
- }
29
- exports.useConst = useConst;
30
- });
31
- //# sourceMappingURL=useConst.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useConst.js","sourceRoot":"../src/","sources":["hooks/useConst.ts"],"names":[],"mappings":";;;IAEA;;;;;;;;;;OAUG;IACH,SAAgB,QAAQ,CAAI,YAA2B;QACrD,+FAA+F;QAC/F,8FAA8F;QAC9F,0DAA0D;QAC1D,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAgB,CAAC;QACzC,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE;YAC7B,wFAAwF;YACxF,uBAAuB;YACvB,GAAG,CAAC,OAAO,GAAG;gBACZ,KAAK,EAAE,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAE,YAAyB,EAAE,CAAC,CAAC,CAAC,YAAY;aACxF,CAAC;SACH;QACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;IAC3B,CAAC;IAbD,4BAaC","sourcesContent":["import * as React from 'react';\n\n/**\n * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to\n * always return the same value (and if the initializer is a function, only call it once).\n * This is similar to setting a private member in a class constructor.\n *\n * If the value should ever change based on dependencies, use `React.useMemo` instead.\n *\n * @param initialValue - Initial value, or function to get the initial value. Similar to `useState`,\n * only the value/function passed in the first time this is called is respected.\n * @returns The value. The identity of this value will always be the same.\n */\nexport function useConst<T>(initialValue: T | (() => T)): T {\n // Use useRef to store the value because it's the least expensive built-in hook that works here\n // (we could also use `const [value] = React.useState(initialValue)` but that's more expensive\n // internally due to reducer handling which we don't need)\n const ref = React.useRef<{ value: T }>();\n if (ref.current === undefined) {\n // Box the value in an object so we can tell if it's initialized even if the initializer\n // returns/is undefined\n ref.current = {\n value: typeof initialValue === 'function' ? (initialValue as Function)() : initialValue,\n };\n }\n return ref.current.value;\n}\n"]}
@@ -1,20 +0,0 @@
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 {};
@@ -1,42 +0,0 @@
1
- define(["require", "exports", "react", "./useConst"], function (require, exports, React, useConst_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- function useControllableValue(controlledValue, defaultUncontrolledValue, onChange) {
5
- var _a = React.useState(defaultUncontrolledValue), value = _a[0], setValue = _a[1];
6
- var isControlled = useIsControlled(controlledValue);
7
- var currentValue = isControlled ? controlledValue : value;
8
- // Duplicate the current value and onChange in refs so they're accessible from
9
- // setValueOrCallOnChange without creating a new callback every time
10
- var valueRef = React.useRef(currentValue);
11
- var onChangeRef = React.useRef(onChange);
12
- React.useEffect(function () {
13
- valueRef.current = currentValue;
14
- onChangeRef.current = onChange;
15
- });
16
- // To match the behavior of the setter returned by React.useState, this callback's identity
17
- // should never change. This means it MUST NOT directly reference variables that can change.
18
- var setValueOrCallOnChange = useConst_1.useConst(function () { return function (update, ev) {
19
- // Assuming here that TValue is not a function, because a controllable value will typically
20
- // be something a user can enter as input
21
- var newValue = typeof update === 'function' ? update(valueRef.current) : update;
22
- if (onChangeRef.current) {
23
- onChangeRef.current(ev, newValue);
24
- }
25
- if (!isControlled) {
26
- setValue(newValue);
27
- }
28
- }; });
29
- return [currentValue, setValueOrCallOnChange];
30
- }
31
- exports.useControllableValue = useControllableValue;
32
- /**
33
- * Helper hook to handle previous comparison of controlled/uncontrolled
34
- * Prints an error when isControlled value switches between subsequent renders
35
- */
36
- var useIsControlled = function (controlledValue) {
37
- var isControlled = useConst_1.useConst(controlledValue !== undefined);
38
-
39
- return isControlled;
40
- };
41
- });
42
- //# sourceMappingURL=useControllableValue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useControllableValue.js","sourceRoot":"../src/","sources":["hooks/useControllableValue.ts"],"names":[],"mappings":";;;IAsCA,SAAgB,oBAAoB,CAKlC,eAAuB,EACvB,wBAA8C,EAC9C,QAAmD;QAE7C,IAAA,6CAAgF,EAA/E,aAAK,EAAE,gBAAwE,CAAC;QACvF,IAAM,YAAY,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC;QACtD,IAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;QAE5D,8EAA8E;QAC9E,oEAAoE;QACpE,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC5C,IAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC3C,KAAK,CAAC,SAAS,CAAC;YACd,QAAQ,CAAC,OAAO,GAAG,YAAY,CAAC;YAChC,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;QACjC,CAAC,CAAC,CAAC;QAEH,2FAA2F;QAC3F,4FAA4F;QAC5F,IAAM,sBAAsB,GAAG,mBAAQ,CAAC,cAAM,OAAA,UAAC,MAAgD,EAAE,EAAW;YAC1G,2FAA2F;YAC3F,yCAAyC;YACzC,IAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAE,MAAmB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAEhG,IAAI,WAAW,CAAC,OAAO,EAAE;gBACvB,WAAW,CAAC,OAAO,CAAC,EAAG,EAAE,QAAQ,CAAC,CAAC;aACpC;YAED,IAAI,CAAC,YAAY,EAAE;gBACjB,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACpB;QACH,CAAC,EAZ6C,CAY7C,CAAC,CAAC;QAEH,OAAO,CAAC,YAAY,EAAE,sBAAsB,CAAU,CAAC;IACzD,CAAC;IAvCD,oDAuCC;IAED;;;OAGG;IACH,IAAM,eAAe,GAAG,UAAS,eAAuB;QACtD,IAAM,YAAY,GAAG,mBAAQ,CAAU,eAAe,KAAK,SAAS,CAAC,CAAC;QAEtE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE;YACzC,wFAAwF;YACxF,sDAAsD;YACtD,KAAK,CAAC,SAAS,CAAC;gBACd,IAAI,YAAY,KAAK,CAAC,eAAe,KAAK,SAAS,CAAC,EAAE;oBACpD,IAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;oBAE1B,IAAM,cAAc,GAAG,YAAY;wBACjC,CAAC,CAAC,uCAAuC;wBACzC,CAAC,CAAC,wCAAwC,CAAC;oBAE7C,IAAM,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,wBAAwB,CAAC;oBAE7F,sCAAsC;oBACtC,OAAO,CAAC,KAAK,CACX;wBACE,sBAAsB;wBACtB,0BAA0B,GAAG,cAAc,GAAG,sCAAsC;wBACpF,gBAAgB,GAAG,gBAAgB,GAAG,kCAAkC;wBACxE,oGAAoG;wBACpG,2DAA2D;wBAC3D,KAAK,CAAC,KAAK;qBACZ,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;iBACH;YACH,CAAC,EAAE,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAC;SACrC;QAED,OAAO,YAAY,CAAC;IACtB,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,13 +0,0 @@
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 depedencies 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 rerenders
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;
@@ -1,33 +0,0 @@
1
- define(["require", "exports", "react", "./useIsomorphicLayoutEffect"], function (require, exports, React, useIsomorphicLayoutEffect_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
6
- *
7
- * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when
8
- * e.g. user props are depedencies which could change on every render
9
- * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently
10
- *
11
- * This should not be used often, but can be a useful re-render optimization since the callback is a ref and
12
- * will not be invalidated between rerenders
13
- *
14
- * @param fn - The callback function that will be used
15
- */
16
- exports.useEventCallback = function (fn) {
17
- var callbackRef = React.useRef(function () {
18
- throw new Error('Cannot call an event handler while rendering');
19
- });
20
- useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(function () {
21
- callbackRef.current = fn;
22
- }, [fn]);
23
- return React.useCallback(function () {
24
- var args = [];
25
- for (var _i = 0; _i < arguments.length; _i++) {
26
- args[_i] = arguments[_i];
27
- }
28
- var callback = callbackRef.current;
29
- return callback.apply(void 0, args);
30
- }, [callbackRef]);
31
- };
32
- });
33
- //# sourceMappingURL=useEventCallback.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEventCallback.js","sourceRoot":"../src/","sources":["hooks/useEventCallback.ts"],"names":[],"mappings":";;;IAGA;;;;;;;;;;;OAWG;IACU,QAAA,gBAAgB,GAAG,UAAiC,EAA6B;QAC5F,IAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAY;YAC1C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC,CAAC,CAAC;QAEH,qDAAyB,CAAC;YACxB,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;QAC3B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAET,OAAO,KAAK,CAAC,WAAW,CACtB;YAAC,cAAa;iBAAb,UAAa,EAAb,qBAAa,EAAb,IAAa;gBAAb,yBAAa;;YACZ,IAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC;YACrC,OAAO,QAAQ,eAAI,IAAI,EAAE;QAC3B,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CAAC;IACJ,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,11 +0,0 @@
1
- export declare function getId(prefix?: string): string;
2
- export declare function resetIds(): void;
3
- /**
4
- * Hook to generate a unique ID in the global scope (spanning across duplicate copies of the same library).
5
- *
6
- * @param prefix - Optional prefix for the ID
7
- * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
8
- * without conditioning the hook call
9
- * @returns The ID
10
- */
11
- export declare function useId(prefix?: string, providedId?: string): string;
@@ -1,35 +0,0 @@
1
- define(["require", "exports", "react"], function (require, exports, React) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- // TODO
5
- // getId() is a temporary approach, useId() should be reimplemented to properly support SSR & scenarios with
6
- // different globals (document, window)
7
- var id = 0;
8
- function getId(prefix) {
9
- return (prefix || '') + id++;
10
- }
11
- exports.getId = getId;
12
- function resetIds() {
13
- id = 0;
14
- }
15
- exports.resetIds = resetIds;
16
- /**
17
- * Hook to generate a unique ID in the global scope (spanning across duplicate copies of the same library).
18
- *
19
- * @param prefix - Optional prefix for the ID
20
- * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,
21
- * without conditioning the hook call
22
- * @returns The ID
23
- */
24
- function useId(prefix, providedId) {
25
- // getId should only be called once since it updates the global constant for the next ID value.
26
- // (While an extra update isn't likely to cause problems in practice, it's better to avoid it.)
27
- var ref = React.useRef(providedId);
28
- if (!ref.current) {
29
- ref.current = getId(prefix);
30
- }
31
- return ref.current;
32
- }
33
- exports.useId = useId;
34
- });
35
- //# sourceMappingURL=useId.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useId.js","sourceRoot":"../src/","sources":["hooks/useId.ts"],"names":[],"mappings":";;;IACA,OAAO;IACP,4GAA4G;IAC5G,uCAAuC;IACvC,IAAI,EAAE,GAAG,CAAC,CAAC;IAEX,SAAgB,KAAK,CAAC,MAAe;QACnC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC;IAC/B,CAAC;IAFD,sBAEC;IAED,SAAgB,QAAQ;QACtB,EAAE,GAAG,CAAC,CAAC;IACT,CAAC;IAFD,4BAEC;IAED;;;;;;;OAOG;IACH,SAAgB,KAAK,CAAC,MAAe,EAAE,UAAmB;QACxD,+FAA+F;QAC/F,+FAA+F;QAC/F,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAqB,UAAU,CAAC,CAAC;QACzD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE;YAChB,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;SAC7B;QACD,OAAO,GAAG,CAAC,OAAO,CAAC;IACrB,CAAC;IARD,sBAQC","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,2 +0,0 @@
1
- import * as React from 'react';
2
- export declare const useIsomorphicLayoutEffect: typeof React.useEffect;
@@ -1,9 +0,0 @@
1
- define(["require", "exports", "react"], function (require, exports, React) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- var isSSR = typeof window === 'undefined' || /ServerSideRendering/.test(window.navigator && window.navigator.userAgent);
5
- // useLayoutEffect() produces a warning with SSR rendering
6
- // https://medium.com/@alexandereardon/uselayouteffect-and-ssr-192986cdcf7a
7
- exports.useIsomorphicLayoutEffect = isSSR ? React.useEffect : React.useLayoutEffect;
8
- });
9
- //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useIsomorphicLayoutEffect.js","sourceRoot":"../src/","sources":["hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":";;;IAEA,IAAM,KAAK,GACT,OAAO,MAAM,KAAK,WAAW,IAAI,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAE9G,0DAA0D;IAC1D,2EAA2E;IAC9D,QAAA,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,13 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * A Ref function which can be treated like a ref object in that it has an attached
4
- * current property, which will be updated as the ref is evaluated.
5
- */
6
- export declare type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);
7
- /**
8
- * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
9
- * updates all provided refs
10
- * @param refs - Refs to collectively update with one ref value.
11
- * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
12
- */
13
- export declare function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T>;
@@ -1,33 +0,0 @@
1
- define(["require", "exports", "tslib", "react"], function (require, exports, tslib_1, React) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that
6
- * updates all provided refs
7
- * @param refs - Refs to collectively update with one ref value.
8
- * @returns A function with an attached "current" prop, so that it can be treated like a RefObject.
9
- */
10
- function useMergedRefs() {
11
- var refs = [];
12
- for (var _i = 0; _i < arguments.length; _i++) {
13
- refs[_i] = arguments[_i];
14
- }
15
- var mergedCallback = React.useCallback(function (value) {
16
- // Update the "current" prop hanging on the function.
17
- mergedCallback.current = value;
18
- for (var _i = 0, refs_1 = refs; _i < refs_1.length; _i++) {
19
- var ref = refs_1[_i];
20
- if (typeof ref === 'function') {
21
- ref(value);
22
- }
23
- else if (ref) {
24
- // work around the immutability of the React.Ref type
25
- ref.current = value;
26
- }
27
- }
28
- }, tslib_1.__spreadArrays(refs));
29
- return mergedCallback;
30
- }
31
- exports.useMergedRefs = useMergedRefs;
32
- });
33
- //# sourceMappingURL=useMergedRefs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useMergedRefs.js","sourceRoot":"../src/","sources":["hooks/useMergedRefs.ts"],"names":[],"mappings":";;;IAQA;;;;;OAKG;IACH,SAAgB,aAAa;QAAI,cAAqC;aAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;YAArC,yBAAqC;;QACpE,IAAM,cAAc,GAA0B,KAAK,CAAC,WAAW,CAC7D,UAAC,KAAQ;YACP,qDAAqD;YACnD,cAAwD,CAAC,OAAO,GAAG,KAAK,CAAC;YAE3E,KAAkB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE;gBAAnB,IAAM,GAAG,aAAA;gBACZ,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;oBAC7B,GAAG,CAAC,KAAK,CAAC,CAAC;iBACZ;qBAAM,IAAI,GAAG,EAAE;oBACd,qDAAqD;oBACnD,GAA6C,CAAC,OAAO,GAAG,KAAK,CAAC;iBACjE;aACF;QACH,CAAC,yBAEG,IAAI,EAC2B,CAAC;QAEtC,OAAO,cAAc,CAAC;IACxB,CAAC;IApBD,sCAoBC","sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = (React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n ((mergedCallback as unknown) as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n ((ref as unknown) as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown) as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"]}
@@ -1,19 +0,0 @@
1
- import * as React from 'react';
2
- export declare type UseOnClickOutsideOptions = {
3
- /**
4
- * The element to listen for the click event
5
- */
6
- element?: Document;
7
- /**
8
- * Refs to elements that check if the click is outside
9
- */
10
- refs: React.MutableRefObject<HTMLElement | undefined | null>[];
11
- /**
12
- * Called if the click is outside the element refs
13
- */
14
- callback: (ev: MouseEvent | TouchEvent) => void;
15
- };
16
- /**
17
- * Utility to perform checks where a click/touch event was made outside a compoent
18
- */
19
- export declare const useOnClickOutside: (options: UseOnClickOutsideOptions) => void;
@@ -1,27 +0,0 @@
1
- define(["require", "exports", "react", "./useEventCallback"], function (require, exports, React, useEventCallback_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /**
5
- * Utility to perform checks where a click/touch event was made outside a compoent
6
- */
7
- exports.useOnClickOutside = function (options) {
8
- var refs = options.refs, callback = options.callback, _a = options.element, element = _a === void 0 ? document : _a;
9
- var listener = useEventCallback_1.useEventCallback(function (ev) {
10
- var isOutside = refs.every(function (ref) { var _a; return !((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(ev.target)); });
11
- if (isOutside) {
12
- callback(ev);
13
- }
14
- });
15
- React.useEffect(function () {
16
- var _a, _b;
17
- (_a = element) === null || _a === void 0 ? void 0 : _a.addEventListener('click', listener);
18
- (_b = element) === null || _b === void 0 ? void 0 : _b.addEventListener('touchstart', listener);
19
- return function () {
20
- var _a, _b;
21
- (_a = element) === null || _a === void 0 ? void 0 : _a.removeEventListener('click', listener);
22
- (_b = element) === null || _b === void 0 ? void 0 : _b.removeEventListener('touchstart', listener);
23
- };
24
- }, [listener, element]);
25
- };
26
- });
27
- //# sourceMappingURL=useOnClickOutside.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useOnClickOutside.js","sourceRoot":"../src/","sources":["hooks/useOnClickOutside.ts"],"names":[],"mappings":";;;IAkBA;;OAEG;IACU,QAAA,iBAAiB,GAAG,UAAC,OAAiC;QACzD,IAAA,mBAAI,EAAE,2BAAQ,EAAE,oBAAkB,EAAlB,uCAAkB,CAAa;QACvD,IAAM,QAAQ,GAAG,mCAAgB,CAAC,UAAC,EAA2B;YAC5D,IAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAA,GAAG,YAAI,OAAA,QAAC,GAAG,CAAC,OAAO,0CAAE,QAAQ,CAAC,EAAE,CAAC,MAAqB,EAAC,CAAA,EAAA,CAAC,CAAC;YACtF,IAAI,SAAS,EAAE;gBACb,QAAQ,CAAC,EAAE,CAAC,CAAC;aACd;QACH,CAAC,CAAC,CAAC;QAEH,KAAK,CAAC,SAAS,CAAC;;YACd,MAAA,OAAO,0CAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE;YAC7C,MAAA,OAAO,0CAAE,gBAAgB,CAAC,YAAY,EAAE,QAAQ,EAAE;YAElD,OAAO;;gBACL,MAAA,OAAO,0CAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE;gBAChD,MAAA,OAAO,0CAAE,mBAAmB,CAAC,YAAY,EAAE,QAAQ,EAAE;YACvD,CAAC,CAAC;QACJ,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1B,CAAC,CAAC","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\nexport type UseOnClickOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element?: Document;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * Utility to perform checks where a click/touch event was made outside a compoent\n */\nexport const useOnClickOutside = (options: UseOnClickOutsideOptions) => {\n const { refs, callback, element = document } = options;\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const isOutside = refs.every(ref => !ref.current?.contains(ev.target as HTMLElement));\n if (isOutside) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n element?.addEventListener('click', listener);\n element?.addEventListener('touchstart', listener);\n\n return () => {\n element?.removeEventListener('click', listener);\n element?.removeEventListener('touchstart', listener);\n };\n }, [listener, element]);\n};\n"]}
@@ -1,3 +0,0 @@
1
- export * from './compose/index';
2
- export * from './hooks/index';
3
- export * from './utils/index';
package/lib-amd/index.js DELETED
@@ -1,8 +0,0 @@
1
- define(["require", "exports", "tslib", "./compose/index", "./hooks/index", "./utils/index"], function (require, exports, tslib_1, index_1, index_2, index_3) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- tslib_1.__exportStar(index_1, exports);
5
- tslib_1.__exportStar(index_2, exports);
6
- tslib_1.__exportStar(index_3, exports);
7
- });
8
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":";;;IAAA,uCAAgC;IAChC,uCAA8B;IAC9B,uCAA8B","sourcesContent":["export * from './compose/index';\nexport * from './hooks/index';\nexport * from './utils/index';\n"]}
@@ -1,9 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Given an element tagname and user props, filters the props to only allowed props for the given
4
- * element type.
5
- * @param tagName - Tag name (e.g. "div")
6
- * @param props - Props object
7
- * @param excludedPropNames - List of props to disallow
8
- */
9
- export declare function getNativeElementProps<TAttributes extends React.HTMLAttributes<any>>(tagName: string, props: {}, excludedPropNames?: string[]): TAttributes;