@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,13 +1,20 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var React = require("react");
4
- var index_1 = require("../utils/index");
5
- var nullRender_1 = require("./nullRender");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSlots = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const nullRender_1 = /*#__PURE__*/require("./nullRender");
11
+
12
+ const omit_1 = /*#__PURE__*/require("../utils/omit");
6
13
  /**
7
14
  * Given the state and an array of slot names, will break out `slots` and `slotProps`
8
15
  * collections.
9
16
  *
10
- * The root is always derived from the `as` prop.
17
+ * The root is derived from a mix of `components` props and `as` prop.
11
18
  *
12
19
  * Slots will render as null if they are rendered as primitives with undefined children.
13
20
  *
@@ -19,34 +26,49 @@ var nullRender_1 = require("./nullRender");
19
26
  * @param slotNames - Name of which props are slots
20
27
  * @returns An object containing the `slots` map and `slotProps` map.
21
28
  */
22
- exports.getSlots = function (state, slotNames) {
23
- var slots = {
24
- root: state.as || 'div',
25
- };
26
- var slotProps = {
27
- root: typeof slots.root === 'string' ? index_1.getNativeElementProps(slots.root, state) : index_1.omit(state, ['as']),
28
- };
29
- if (slotNames) {
30
- for (var _i = 0, slotNames_1 = slotNames; _i < slotNames_1.length; _i++) {
31
- var name_1 = slotNames_1[_i];
32
- var slotDefinition = state[name_1] || {};
33
- var _a = slotDefinition.as, slotAs = _a === void 0 ? 'span' : _a, children = slotDefinition.children;
34
- var isSlotPrimitive = typeof slotAs === 'string';
35
- var isSlotEmpty = isSlotPrimitive && slotDefinition.children === undefined;
36
- slots[name_1] = isSlotEmpty ? nullRender_1.nullRender : slotAs;
37
- if (typeof children === 'function') {
38
- slotProps[name_1] = {
39
- children: children(slots[name_1], index_1.omit(slotDefinition, ['as', 'children'])),
40
- };
41
- slots[name_1] = React.Fragment;
42
- }
43
- else if (slots[name_1] !== nullRender_1.nullRender) {
44
- slotProps[name_1] = isSlotPrimitive
45
- ? index_1.getNativeElementProps(slotAs, slotDefinition)
46
- : index_1.omit(slotDefinition, ['as']);
47
- }
48
- }
49
- }
50
- return { slots: slots, slotProps: slotProps };
51
- };
29
+
30
+
31
+ function getSlots(state, slotNames = ['root']) {
32
+ const slots = {};
33
+ const slotProps = {};
34
+
35
+ for (const slotName of slotNames) {
36
+ const [slot, props] = getSlot(state, slotName);
37
+ slots[slotName] = slot;
38
+ slotProps[slotName] = props;
39
+ }
40
+
41
+ return {
42
+ slots,
43
+ slotProps: slotProps
44
+ };
45
+ }
46
+
47
+ exports.getSlots = getSlots;
48
+
49
+ function getSlot(state, slotName) {
50
+ var _a, _b, _c;
51
+
52
+ if (state[slotName] === undefined) {
53
+ return [nullRender_1.nullRender, undefined];
54
+ }
55
+
56
+ const {
57
+ children,
58
+ as: asProp,
59
+ ...rest
60
+ } = state[slotName];
61
+ const slot = ((_a = state.components) === null || _a === void 0 ? void 0 : _a[slotName]) === undefined || typeof state.components[slotName] === 'string' ? asProp || ((_b = state.components) === null || _b === void 0 ? void 0 : _b[slotName]) || 'div' : state.components[slotName];
62
+
63
+ if (typeof children === 'function') {
64
+ const render = children;
65
+ return [React.Fragment, {
66
+ children: render(slot, rest)
67
+ }];
68
+ }
69
+
70
+ const shouldOmitAsProp = typeof slot === 'string' && ((_c = state[slotName]) === null || _c === void 0 ? void 0 : _c.as);
71
+ const slotProps = shouldOmitAsProp ? omit_1.omit(state[slotName], ['as']) : state[slotName];
72
+ return [slot, slotProps];
73
+ }
52
74
  //# sourceMappingURL=getSlots.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSlots.js","sourceRoot":"../src/","sources":["compose/getSlots.ts"],"names":[],"mappings":";;AAAA,6BAA+B;AAE/B,wCAA6D;AAE7D,2CAA0C;AAE1C;;;;;;;;;;;;;;;GAeG;AACU,QAAA,QAAQ,GAAG,UAAC,KAAwB,EAAE,SAAgC;IACjF,IAAM,KAAK,GAAsB;QAC/B,IAAI,EAAE,KAAK,CAAC,EAAE,IAAI,KAAK;KACxB,CAAC;IAEF,IAAM,SAAS,GAAsB;QACnC,IAAI,EAAE,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,6BAAqB,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,YAAI,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,CAAC;KACtG,CAAC;IAEF,IAAI,SAAS,EAAE;QACb,KAAmB,UAAS,EAAT,uBAAS,EAAT,uBAAS,EAAT,IAAS,EAAE;YAAzB,IAAM,MAAI,kBAAA;YACb,IAAM,cAAc,GAAG,KAAK,CAAC,MAAI,CAAC,IAAI,EAAE,CAAC;YACjC,IAAA,sBAAmB,EAAnB,oCAAmB,EAAE,kCAAQ,CAAoB;YACzD,IAAM,eAAe,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC;YACnD,IAAM,WAAW,GAAG,eAAe,IAAI,cAAc,CAAC,QAAQ,KAAK,SAAS,CAAC;YAE7E,KAAK,CAAC,MAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,uBAAU,CAAC,CAAC,CAAC,MAAM,CAAC;YAEhD,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;gBAClC,SAAS,CAAC,MAAI,CAAC,GAAG;oBAChB,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,MAAI,CAAC,EAAE,YAAI,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;iBAC1E,CAAC;gBACF,KAAK,CAAC,MAAI,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC;aAC9B;iBAAM,IAAI,KAAK,CAAC,MAAI,CAAC,KAAK,uBAAU,EAAE;gBACrC,SAAS,CAAC,MAAI,CAAC,GAAG,eAAe;oBAC/B,CAAC,CAAC,6BAAqB,CAAC,MAAM,EAAE,cAAc,CAAC;oBAC/C,CAAC,CAAC,YAAI,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;aAClC;SACF;KACF;IAED,OAAO,EAAE,KAAK,OAAA,EAAE,SAAS,WAAA,EAAE,CAAC;AAC9B,CAAC,CAAC","sourcesContent":["import * as React from 'react';\n\nimport { getNativeElementProps, omit } from '../utils/index';\nimport { GenericDictionary } from './types';\nimport { nullRender } from './nullRender';\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is always derived from the `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according the the slot type. For example, if the\n * slot is rendered `as: 'a'`, the props will be filtered for acceptable anchor props.\n *\n * @param state - State including slot definitions\n * @param slotNames - Name of which props are slots\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport const getSlots = (state: GenericDictionary, slotNames?: string[] | undefined) => {\n const slots: GenericDictionary = {\n root: state.as || 'div',\n };\n\n const slotProps: GenericDictionary = {\n root: typeof slots.root === 'string' ? getNativeElementProps(slots.root, state) : omit(state, ['as']),\n };\n\n if (slotNames) {\n for (const name of slotNames) {\n const slotDefinition = state[name] || {};\n const { as: slotAs = 'span', children } = slotDefinition;\n const isSlotPrimitive = typeof slotAs === 'string';\n const isSlotEmpty = isSlotPrimitive && slotDefinition.children === undefined;\n\n slots[name] = isSlotEmpty ? nullRender : slotAs;\n\n if (typeof children === 'function') {\n slotProps[name] = {\n children: children(slots[name], omit(slotDefinition, ['as', 'children'])),\n };\n slots[name] = React.Fragment;\n } else if (slots[name] !== nullRender) {\n slotProps[name] = isSlotPrimitive\n ? getNativeElementProps(slotAs, slotDefinition)\n : omit(slotDefinition, ['as']);\n }\n }\n }\n\n return { slots, slotProps };\n};\n"]}
1
+ {"version":3,"sources":["../../src/compose/getSlots.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AAUA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,MAAA,gBAAA,OAAA,CAAA,eAAA,CAAA;AAqBA;;;;;;;;;;;;;;;AAeG;;;AACH,SAAgB,QAAhB,CACE,KADF,EAEE,SAAA,GAAyB,CAAC,MAAD,CAF3B,EAEmC;AAKjC,QAAM,KAAK,GAAG,EAAd;AACA,QAAM,SAAS,GAAG,EAAlB;;AAEA,OAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;AAChC,UAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;AACA,IAAA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;AACA,IAAA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;AACD;;AACD,SAAO;AAAE,IAAA,KAAF;AAAS,IAAA,SAAS,EAAG;AAArB,GAAP;AACD;;AAhBD,OAAA,CAAA,QAAA,GAAA,QAAA;;AAkBA,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;AAEX,MAAI,KAAK,CAAC,QAAD,CAAL,KAAoB,SAAxB,EAAmC;AACjC,WAAO,CAAC,YAAA,CAAA,UAAD,EAAa,SAAb,CAAP;AACD;;AACD,QAAM;AAAE,IAAA,QAAF;AAAY,IAAA,EAAE,EAAE,MAAhB;AAAwB,OAAG;AAA3B,MAAoC,KAAK,CAAC,QAAD,CAA/C;AAEA,QAAM,IAAI,GAAI,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,UAAN,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,KAAA,CAAhB,GAAgB,EAAA,CAAG,QAAH,CAAhB,MAAiC,SAAjC,IAA8C,OAAO,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAAP,KAAsC,QAApF,GACV,MAAM,KAAA,CAAA,EAAA,GAAI,KAAK,CAAC,UAAV,MAAoB,IAApB,IAAoB,EAAA,KAAA,KAAA,CAApB,GAAoB,KAAA,CAApB,GAAoB,EAAA,CAAG,QAAH,CAApB,CAAN,IAA0C,KADhC,GAEV,KAAK,CAAC,UAAN,CAAiB,QAAjB,CAFJ;;AAIA,MAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;AAClC,UAAM,MAAM,GAAG,QAAf;AACA,WAAO,CACL,KAAK,CAAC,QADD,EAEJ;AACC,MAAA,QAAQ,EAAE,MAAM,CAAC,IAAD,EAAO,IAAP;AADjB,KAFI,CAAP;AAMD;;AAED,QAAM,gBAAgB,GAAG,OAAO,IAAP,KAAgB,QAAhB,KAAwB,CAAA,EAAA,GAAI,KAAK,CAAC,QAAD,CAAT,MAAmB,IAAnB,IAAmB,EAAA,KAAA,KAAA,CAAnB,GAAmB,KAAA,CAAnB,GAAmB,EAAA,CAAE,EAA7C,CAAzB;AACA,QAAM,SAAS,GAAI,gBAAgB,GAAG,MAAA,CAAA,IAAA,CAAK,KAAK,CAAC,QAAD,CAAV,EAAuB,CAAC,IAAD,CAAvB,CAAH,GAAoC,KAAK,CAAC,QAAD,CAA5E;AAEA,SAAO,CAAC,IAAD,EAAO,SAAP,CAAP;AACD","sourceRoot":""}
@@ -1,5 +1,4 @@
1
1
  export * from './getSlots';
2
- export * from './makeMergeProps';
3
2
  export * from './nullRender';
4
- export * from './resolveShorthandProps';
3
+ export * from './resolveShorthand';
5
4
  export * from './types';
@@ -1,8 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ const tslib_1 = /*#__PURE__*/require("tslib");
8
+
4
9
  tslib_1.__exportStar(require("./getSlots"), exports);
5
- tslib_1.__exportStar(require("./makeMergeProps"), exports);
10
+
6
11
  tslib_1.__exportStar(require("./nullRender"), exports);
7
- tslib_1.__exportStar(require("./resolveShorthandProps"), exports);
12
+
13
+ tslib_1.__exportStar(require("./resolveShorthand"), exports);
14
+
15
+ tslib_1.__exportStar(require("./types"), exports);
8
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["compose/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,2DAAiC;AACjC,uDAA6B;AAC7B,kEAAwC","sourcesContent":["export * from './getSlots';\nexport * from './makeMergeProps';\nexport * from './nullRender';\nexport * from './resolveShorthandProps';\nexport * from './types';\n"]}
1
+ {"version":3,"sources":["../../src/compose/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA","sourceRoot":""}
@@ -1,7 +1,14 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.nullRender = void 0;
3
7
  /**
4
8
  * Simple constant function for returning null, used to render empty templates in JSX.
5
9
  */
6
- exports.nullRender = function () { return null; };
10
+
11
+ const nullRender = () => null;
12
+
13
+ exports.nullRender = nullRender;
7
14
  //# sourceMappingURL=nullRender.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nullRender.js","sourceRoot":"../src/","sources":["compose/nullRender.tsx"],"names":[],"mappings":";;AAAA;;GAEG;AACU,QAAA,UAAU,GAAG,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC","sourcesContent":["/**\n * Simple constant function for returning null, used to render empty templates in JSX.\n */\nexport const nullRender = () => null;\n"]}
1
+ {"version":3,"sources":["../../src/compose/nullRender.tsx"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACI,MAAM,UAAU,GAAG,MAAM,IAAzB;;AAAM,OAAA,CAAA,UAAA,GAAU,UAAV","sourceRoot":""}
@@ -0,0 +1,12 @@
1
+ import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
2
+ export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
3
+ required?: Required;
4
+ defaultProps?: Props;
5
+ };
6
+ /**
7
+ * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
8
+ * being passed down to getSlots method
9
+ * @param value - the base ShorthandProps
10
+ * @param options - options to resolve ShorthandProps
11
+ */
12
+ export declare function resolveShorthand<Props extends DefaultObjectShorthandProps, Required extends boolean = false>(value: ShorthandProps<Props>, options?: ResolveShorthandOptions<Props, Required>): Required extends false ? Props | undefined : Props;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveShorthand = void 0;
7
+
8
+ const react_1 = /*#__PURE__*/require("react");
9
+ /**
10
+ * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
11
+ * being passed down to getSlots method
12
+ * @param value - the base ShorthandProps
13
+ * @param options - options to resolve ShorthandProps
14
+ */
15
+
16
+
17
+ function resolveShorthand(value, options) {
18
+ const {
19
+ required = false,
20
+ defaultProps
21
+ } = options || {};
22
+
23
+ if (value === null || value === undefined && !required) {
24
+ return undefined;
25
+ }
26
+
27
+ let resolvedShorthand = {};
28
+
29
+ if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || react_1.isValidElement(value)) {
30
+ resolvedShorthand.children = value;
31
+ } else if (typeof value === 'object') {
32
+ resolvedShorthand = value;
33
+ }
34
+
35
+ return defaultProps ? { ...defaultProps,
36
+ ...resolvedShorthand
37
+ } : resolvedShorthand;
38
+ }
39
+
40
+ exports.resolveShorthand = resolveShorthand;
41
+ //# sourceMappingURL=resolveShorthand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AASA;;;;;AAKG;;;AACH,SAAgB,gBAAhB,CACE,KADF,EAEE,OAFF,EAEoD;AAElD,QAAM;AAAE,IAAA,QAAQ,GAAG,KAAb;AAAoB,IAAA;AAApB,MAAqC,OAAO,IAAI,EAAtD;;AACA,MAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;AACxD,WAAO,SAAP;AACD;;AAED,MAAI,iBAAiB,GAAG,EAAxB;;AAEA,MAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,IAAkF,OAAA,CAAA,cAAA,CAAe,KAAf,CAAtF,EAA6G;AAC3G,IAAA,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;AACD,GAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AACpC,IAAA,iBAAiB,GAAG,KAApB;AACD;;AAED,SAAQ,YAAY,GAAG,EAAE,GAAG,YAAL;AAAmB,OAAG;AAAtB,GAAH,GAA+C,iBAAnE;AAGD;;AApBD,OAAA,CAAA,gBAAA,GAAA,gBAAA","sourceRoot":""}
@@ -1,29 +1,103 @@
1
1
  import * as React from 'react';
2
+ export declare type ShorthandRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
3
+ export declare type ObjectShorthandPropsRecord = Record<string, DefaultObjectShorthandProps | undefined>;
4
+ export declare type ShorthandProps<Props extends DefaultObjectShorthandProps> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | Props;
2
5
  /**
3
- * Generic name to any dictionary.
6
+ * Matches any shorthand props type.
7
+ *
8
+ * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
9
+ * it shouldn't be used as the type of a slot.
4
10
  */
5
- export declare type GenericDictionary = Record<string, any>;
11
+ export declare type DefaultObjectShorthandProps = ObjectShorthandProps<Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
12
+ as?: keyof JSX.IntrinsicElements;
13
+ }>;
6
14
  /**
7
- * Class dictionary.
15
+ * Defines the slot props for a slot that supports a Component type.
16
+ *
17
+ * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
8
18
  */
9
- export declare type ClassDictionary = Record<string, string>;
10
- export interface ComponentProps {
11
- as?: React.ElementType;
12
- className?: string;
19
+ export declare type ObjectShorthandProps<Props extends {
13
20
  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
+ } = {}> = Props & {
22
+ children?: Props['children'] | ShorthandRenderFunction<Props>;
21
23
  };
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;
24
+ /**
25
+ * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
26
+ * For slots that support custom components, use {@link ObjectShorthandProps} instead.
27
+ *
28
+ * The first param is the slot's default type if no `as` prop is specified.
29
+ * The second param is an optional union of alternative types that can be specified for the `as` prop.
30
+ *
31
+ * ```
32
+ * IntrinsicShorthandProps<'div'> // Slot is always div
33
+ * IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
34
+ * IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
35
+ * ```
36
+ */
37
+ export declare type IntrinsicShorthandProps<DefaultAs extends keyof JSX.IntrinsicElements, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<DefaultAs> extends false ? 'Error: first parameter to IntrinsicShorthandProps must be a single element type, not a union of types' : ({
38
+ as?: DefaultAs;
39
+ } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
40
+ [As in AlternateAs]: {
41
+ as: As;
42
+ } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
43
+ }[AlternateAs];
44
+ /**
45
+ * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
46
+ *
47
+ * ```
48
+ * IsSingleton<'a'> // true
49
+ * IsSingleton<'a' | 'b' | 'c'> // false
50
+ * ```
51
+ */
52
+ export declare type IsSingleton<T extends string> = {
53
+ [K in T]: Exclude<T, K> extends never ? true : false;
54
+ }[T];
55
+ /**
56
+ * Helper type for inferring the type of the as prop from a Props type.
57
+ *
58
+ * For example:
59
+ * ```
60
+ * type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;
61
+ * ```
62
+ */
63
+ export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = {
64
+ as?: As;
29
65
  };
66
+ /**
67
+ * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)
68
+ */
69
+ export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
70
+ /**
71
+ * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
72
+ * IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
73
+ *
74
+ * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
75
+ * types, to prevent unions from being expanded.
76
+ */
77
+ export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
78
+ export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
79
+ [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
80
+ }, Primary & 'root'> & PropsWithoutRef<Shorthands[Primary]>;
81
+ export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
82
+ components?: {
83
+ [Key in keyof Shorthands]-?: React.ComponentType<NonNullable<Shorthands[Key]> extends ObjectShorthandProps<infer P> ? P : NonNullable<Shorthands[Key]>> | (NonNullable<Shorthands[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
84
+ };
85
+ } & Shorthands;
86
+ /**
87
+ * This is part of a hack to infer the element type from a native element *props* type.
88
+ * The only place the original element is found in a native props type (at least that's workable
89
+ * for inference) is in the event handlers, so some of the helper types use this event handler
90
+ * name to infer the original element type.
91
+ *
92
+ * Notes:
93
+ * - Using an extremely obscure event handler reduces the likelihood that its signature will be
94
+ * modified in any component's props.
95
+ * - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be
96
+ * less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.
97
+ */
98
+ declare type ObscureEventName = 'onLostPointerCaptureCapture';
99
+ /**
100
+ * Return type for `React.forwardRef`, including inference of the proper typing for the ref.
101
+ */
102
+ export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof Props ? Required<Props>[ObscureEventName] extends React.PointerEventHandler<infer Element> ? React.ForwardRefExoticComponent<Props & React.RefAttributes<Element>> : never : never;
103
+ export {};
@@ -1,3 +1,10 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ }); // A definition like this would also work, but typescript is more likely to unnecessarily expand
6
+ // the props type with this version (and it's likely much more expensive to evaluate)
7
+ // export type ForwardRefComponent<Props> = Props extends React.DOMAttributes<infer Element>
8
+ // ? React.ForwardRefExoticComponent<Props> & React.RefAttributes<Element>
9
+ // : never;
3
10
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
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
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IAgJA;AACA;AACA;AACA;AACA","sourceRoot":""}
@@ -1,8 +1,16 @@
1
+ export * from './useControllableState';
1
2
  export * from './useBoolean';
2
3
  export * from './useConst';
3
4
  export * from './useControllableValue';
4
5
  export * from './useEventCallback';
5
- export { useId } from './useId';
6
+ export * from './useFirstMount';
7
+ export * from './useId';
6
8
  export * from './useIsomorphicLayoutEffect';
7
9
  export * from './useMergedRefs';
10
+ export * from './useMount';
8
11
  export * from './useOnClickOutside';
12
+ export * from './useOnScrollOutside';
13
+ export * from './usePrevious';
14
+ export * from './useTimeout';
15
+ export * from './useUnmount';
16
+ export * from './useForceUpdate';
@@ -1,13 +1,40 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ const tslib_1 = /*#__PURE__*/require("tslib");
8
+
9
+ tslib_1.__exportStar(require("./useControllableState"), exports);
10
+
4
11
  tslib_1.__exportStar(require("./useBoolean"), exports);
12
+
5
13
  tslib_1.__exportStar(require("./useConst"), exports);
14
+
6
15
  tslib_1.__exportStar(require("./useControllableValue"), exports);
16
+
7
17
  tslib_1.__exportStar(require("./useEventCallback"), exports);
8
- var useId_1 = require("./useId");
9
- exports.useId = useId_1.useId;
18
+
19
+ tslib_1.__exportStar(require("./useFirstMount"), exports);
20
+
21
+ tslib_1.__exportStar(require("./useId"), exports);
22
+
10
23
  tslib_1.__exportStar(require("./useIsomorphicLayoutEffect"), exports);
24
+
11
25
  tslib_1.__exportStar(require("./useMergedRefs"), exports);
26
+
27
+ tslib_1.__exportStar(require("./useMount"), exports);
28
+
12
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);
13
40
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,qDAA2B;AAC3B,iEAAuC;AACvC,6DAAmC;AACnC,iCAAgC;AAAvB,wBAAA,KAAK,CAAA;AACd,sEAA4C;AAC5C,0DAAgC;AAChC,8DAAoC","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
+ {"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":""}
@@ -1,12 +1,12 @@
1
1
  /** Updater callbacks returned by `useBoolean`. */
2
- export interface UseBooleanCallbacks {
2
+ export declare type UseBooleanCallbacks = {
3
3
  /** Set the value to true. Always has the same identity. */
4
4
  setTrue: () => void;
5
5
  /** Set the value to false. Always has the same identity. */
6
6
  setFalse: () => void;
7
7
  /** Toggle the value. Always has the same identity. */
8
8
  toggle: () => void;
9
- }
9
+ };
10
10
  /**
11
11
  * Hook to store a value and generate callbacks for setting the value to true or false.
12
12
  * The identity of the callbacks will always stay the same.
@@ -1,7 +1,13 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var React = require("react");
4
- var useConst_1 = require("./useConst");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBoolean = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
9
+
10
+ const useConst_1 = /*#__PURE__*/require("./useConst");
5
11
  /**
6
12
  * Hook to store a value and generate callbacks for setting the value to true or false.
7
13
  * The identity of the callbacks will always stay the same.
@@ -9,18 +15,25 @@ var useConst_1 = require("./useConst");
9
15
  * @param initialState - Initial value
10
16
  * @returns Array with the current value and an object containing the updater callbacks.
11
17
  */
18
+
19
+
12
20
  function useBoolean(initialState) {
13
- var _a = React.useState(initialState), value = _a[0], setValue = _a[1];
14
- var setTrue = useConst_1.useConst(function () { return function () {
15
- setValue(true);
16
- }; });
17
- var setFalse = useConst_1.useConst(function () { return function () {
18
- setValue(false);
19
- }; });
20
- var toggle = useConst_1.useConst(function () { return function () {
21
- setValue(function (currentValue) { return !currentValue; });
22
- }; });
23
- return [value, { setTrue: setTrue, setFalse: setFalse, toggle: toggle }];
21
+ const [value, setValue] = React.useState(initialState);
22
+ const setTrue = useConst_1.useConst(() => () => {
23
+ setValue(true);
24
+ });
25
+ const setFalse = useConst_1.useConst(() => () => {
26
+ setValue(false);
27
+ });
28
+ const toggle = useConst_1.useConst(() => () => {
29
+ setValue(currentValue => !currentValue);
30
+ });
31
+ return [value, {
32
+ setTrue,
33
+ setFalse,
34
+ toggle
35
+ }];
24
36
  }
37
+
25
38
  exports.useBoolean = useBoolean;
26
39
  //# sourceMappingURL=useBoolean.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBoolean.js","sourceRoot":"../src/","sources":["hooks/useBoolean.ts"],"names":[],"mappings":";;AAAA,6BAA+B;AAC/B,uCAAsC;AAYtC;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,YAAqB;IACxC,IAAA,iCAAgD,EAA/C,aAAK,EAAE,gBAAwC,CAAC;IAEvD,IAAM,OAAO,GAAG,mBAAQ,CAAC,cAAM,OAAA;QAC7B,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,EAF8B,CAE9B,CAAC,CAAC;IACH,IAAM,QAAQ,GAAG,mBAAQ,CAAC,cAAM,OAAA;QAC9B,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,EAF+B,CAE/B,CAAC,CAAC;IACH,IAAM,MAAM,GAAG,mBAAQ,CAAC,cAAM,OAAA;QAC5B,QAAQ,CAAC,UAAA,YAAY,IAAI,OAAA,CAAC,YAAY,EAAb,CAAa,CAAC,CAAC;IAC1C,CAAC,EAF6B,CAE7B,CAAC,CAAC;IAEH,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,SAAA,EAAE,QAAQ,UAAA,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;AAChD,CAAC;AAdD,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
+ {"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;AAYA;;;;;;AAMG;;;AACH,SAAgB,UAAhB,CAA2B,YAA3B,EAAgD;AAC9C,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,YAAf,CAA1B;AAEA,QAAM,OAAO,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AAClC,IAAA,QAAQ,CAAC,IAAD,CAAR;AACD,GAFe,CAAhB;AAGA,QAAM,QAAQ,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AACnC,IAAA,QAAQ,CAAC,KAAD,CAAR;AACD,GAFgB,CAAjB;AAGA,QAAM,MAAM,GAAG,UAAA,CAAA,QAAA,CAAS,MAAM,MAAK;AACjC,IAAA,QAAQ,CAAC,YAAY,IAAI,CAAC,YAAlB,CAAR;AACD,GAFc,CAAf;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAF;AAAW,IAAA,QAAX;AAAqB,IAAA;AAArB,GAAR,CAAP;AACD;;AAdD,OAAA,CAAA,UAAA,GAAA,UAAA","sourceRoot":""}
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var React = require("react");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useConst = void 0;
7
+
8
+ const React = /*#__PURE__*/require("react");
4
9
  /**
5
10
  * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
6
11
  * always return the same value (and if the initializer is a function, only call it once).
@@ -12,19 +17,24 @@ var React = require("react");
12
17
  * only the value/function passed in the first time this is called is respected.
13
18
  * @returns The value. The identity of this value will always be the same.
14
19
  */
20
+
21
+
15
22
  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;
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
+ const 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;
28
37
  }
38
+
29
39
  exports.useConst = useConst;
30
40
  //# sourceMappingURL=useConst.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useConst.js","sourceRoot":"../src/","sources":["hooks/useConst.ts"],"names":[],"mappings":";;AAAA,6BAA+B;AAE/B;;;;;;;;;;GAUG;AACH,SAAgB,QAAQ,CAAI,YAA2B;IACrD,+FAA+F;IAC/F,8FAA8F;IAC9F,0DAA0D;IAC1D,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,EAAgB,CAAC;IACzC,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE;QAC7B,wFAAwF;QACxF,uBAAuB;QACvB,GAAG,CAAC,OAAO,GAAG;YACZ,KAAK,EAAE,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAE,YAAyB,EAAE,CAAC,CAAC,CAAC,YAAY;SACxF,CAAC;KACH;IACD,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;AAC3B,CAAC;AAbD,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
+ {"version":3,"sources":["../../src/hooks/useConst.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;;AAUG;;;AACH,SAAgB,QAAhB,CAA4B,YAA5B,EAAuD;AACrD;AACA;AACA;AACA,QAAM,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":""}