@fluentui/react-utilities 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.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 (216) hide show
  1. package/CHANGELOG.json +209 -8
  2. package/CHANGELOG.md +64 -6
  3. package/dist/react-utilities.d.ts +225 -198
  4. package/lib/compose/getSlots.d.ts +11 -10
  5. package/lib/compose/getSlots.js +21 -30
  6. package/lib/compose/getSlots.js.map +1 -1
  7. package/lib/compose/index.d.ts +0 -5
  8. package/lib/compose/index.js +0 -5
  9. package/lib/compose/index.js.map +1 -1
  10. package/lib/compose/resolveShorthand.d.ts +10 -6
  11. package/lib/compose/resolveShorthand.js +13 -12
  12. package/lib/compose/resolveShorthand.js.map +1 -1
  13. package/lib/compose/types.d.ts +86 -76
  14. package/lib/compose/types.js +5 -1
  15. package/lib/compose/types.js.map +1 -1
  16. package/lib/hooks/index.d.ts +1 -1
  17. package/lib/hooks/index.js +1 -1
  18. package/lib/hooks/index.js.map +1 -1
  19. package/lib/hooks/useBoolean.js +10 -21
  20. package/lib/hooks/useBoolean.js.map +1 -1
  21. package/lib/hooks/useConst.js +1 -1
  22. package/lib/hooks/useConst.js.map +1 -1
  23. package/lib/hooks/useControllableState.d.ts +16 -6
  24. package/lib/hooks/useControllableState.js +26 -25
  25. package/lib/hooks/useControllableState.js.map +1 -1
  26. package/lib/hooks/useEventCallback.js +6 -12
  27. package/lib/hooks/useEventCallback.js.map +1 -1
  28. package/lib/hooks/useFirstMount.js +1 -1
  29. package/lib/hooks/useFirstMount.js.map +1 -1
  30. package/lib/hooks/useForceUpdate.js +1 -3
  31. package/lib/hooks/useForceUpdate.js.map +1 -1
  32. package/lib/hooks/useId.d.ts +1 -1
  33. package/lib/hooks/useId.js +9 -5
  34. package/lib/hooks/useId.js.map +1 -1
  35. package/lib/hooks/useIsomorphicLayoutEffect.js +1 -1
  36. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  37. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  38. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  39. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  40. package/lib/hooks/useMergedRefs.js +5 -13
  41. package/lib/hooks/useMergedRefs.js.map +1 -1
  42. package/lib/hooks/useMount.js +3 -3
  43. package/lib/hooks/useMount.js.map +1 -1
  44. package/lib/hooks/useOnClickOutside.js +30 -36
  45. package/lib/hooks/useOnClickOutside.js.map +1 -1
  46. package/lib/hooks/useOnScrollOutside.js +13 -15
  47. package/lib/hooks/useOnScrollOutside.js.map +1 -1
  48. package/lib/hooks/usePrevious.js +3 -3
  49. package/lib/hooks/usePrevious.js.map +1 -1
  50. package/lib/hooks/useTimeout.js +13 -17
  51. package/lib/hooks/useTimeout.js.map +1 -1
  52. package/lib/hooks/useUnmount.js +5 -7
  53. package/lib/hooks/useUnmount.js.map +1 -1
  54. package/lib/index.js.map +1 -1
  55. package/lib/ssr/SSRContext.js +9 -15
  56. package/lib/ssr/SSRContext.js.map +1 -1
  57. package/lib/ssr/canUseDOM.js.map +1 -1
  58. package/lib/ssr/index.js.map +1 -1
  59. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  60. package/lib/utils/applyTriggerPropsToChildren.js +24 -4
  61. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  62. package/lib/utils/clamp.js +1 -3
  63. package/lib/utils/clamp.js.map +1 -1
  64. package/lib/utils/getNativeElementProps.d.ts +22 -0
  65. package/lib/utils/getNativeElementProps.js +26 -3
  66. package/lib/utils/getNativeElementProps.js.map +1 -1
  67. package/lib/utils/getRTLSafeKey.js +1 -1
  68. package/lib/utils/getRTLSafeKey.js.map +1 -1
  69. package/lib/utils/getReactCallbackName.d.ts +25 -0
  70. package/lib/utils/getReactCallbackName.js +26 -0
  71. package/lib/utils/getReactCallbackName.js.map +1 -0
  72. package/lib/utils/getTriggerChild.d.ts +22 -0
  73. package/lib/utils/getTriggerChild.js +26 -0
  74. package/lib/utils/getTriggerChild.js.map +1 -0
  75. package/lib/utils/index.d.ts +2 -1
  76. package/lib/utils/index.js +2 -1
  77. package/lib/utils/index.js.map +1 -1
  78. package/lib/utils/isFluentTrigger.d.ts +22 -0
  79. package/lib/utils/isFluentTrigger.js +8 -0
  80. package/lib/utils/isFluentTrigger.js.map +1 -0
  81. package/lib/utils/omit.js +2 -2
  82. package/lib/utils/omit.js.map +1 -1
  83. package/lib/utils/properties.d.ts +6 -0
  84. package/lib/utils/properties.js +63 -44
  85. package/lib/utils/properties.js.map +1 -1
  86. package/lib/utils/shouldPreventDefaultOnKeyDown.js +4 -4
  87. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  88. package/lib-commonjs/compose/getSlots.d.ts +11 -10
  89. package/lib-commonjs/compose/getSlots.js +23 -34
  90. package/lib-commonjs/compose/getSlots.js.map +1 -1
  91. package/lib-commonjs/compose/index.d.ts +0 -5
  92. package/lib-commonjs/compose/index.js +1 -11
  93. package/lib-commonjs/compose/index.js.map +1 -1
  94. package/lib-commonjs/compose/resolveShorthand.d.ts +10 -6
  95. package/lib-commonjs/compose/resolveShorthand.js +14 -14
  96. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  97. package/lib-commonjs/compose/types.d.ts +86 -76
  98. package/lib-commonjs/compose/types.js +5 -1
  99. package/lib-commonjs/compose/types.js.map +1 -1
  100. package/lib-commonjs/hooks/index.d.ts +1 -1
  101. package/lib-commonjs/hooks/index.js +3 -3
  102. package/lib-commonjs/hooks/index.js.map +1 -1
  103. package/lib-commonjs/hooks/useBoolean.js +12 -23
  104. package/lib-commonjs/hooks/useBoolean.js.map +1 -1
  105. package/lib-commonjs/hooks/useConst.js +2 -2
  106. package/lib-commonjs/hooks/useConst.js.map +1 -1
  107. package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
  108. package/lib-commonjs/hooks/useControllableState.js +28 -27
  109. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  110. package/lib-commonjs/hooks/useEventCallback.js +8 -14
  111. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  112. package/lib-commonjs/hooks/useFirstMount.js +2 -2
  113. package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
  114. package/lib-commonjs/hooks/useForceUpdate.js +2 -4
  115. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
  116. package/lib-commonjs/hooks/useId.d.ts +1 -1
  117. package/lib-commonjs/hooks/useId.js +11 -7
  118. package/lib-commonjs/hooks/useId.js.map +1 -1
  119. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +2 -2
  120. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  121. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  122. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  123. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  124. package/lib-commonjs/hooks/useMergedRefs.js +6 -15
  125. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  126. package/lib-commonjs/hooks/useMount.js +4 -4
  127. package/lib-commonjs/hooks/useMount.js.map +1 -1
  128. package/lib-commonjs/hooks/useOnClickOutside.js +32 -38
  129. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  130. package/lib-commonjs/hooks/useOnScrollOutside.js +15 -17
  131. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  132. package/lib-commonjs/hooks/usePrevious.js +4 -4
  133. package/lib-commonjs/hooks/usePrevious.js.map +1 -1
  134. package/lib-commonjs/hooks/useTimeout.js +15 -19
  135. package/lib-commonjs/hooks/useTimeout.js.map +1 -1
  136. package/lib-commonjs/hooks/useUnmount.js +6 -8
  137. package/lib-commonjs/hooks/useUnmount.js.map +1 -1
  138. package/lib-commonjs/index.js +1 -1
  139. package/lib-commonjs/index.js.map +1 -1
  140. package/lib-commonjs/ssr/SSRContext.js +9 -15
  141. package/lib-commonjs/ssr/SSRContext.js.map +1 -1
  142. package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
  143. package/lib-commonjs/ssr/index.js +1 -1
  144. package/lib-commonjs/ssr/index.js.map +1 -1
  145. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  146. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +26 -6
  147. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  148. package/lib-commonjs/utils/clamp.js +1 -3
  149. package/lib-commonjs/utils/clamp.js.map +1 -1
  150. package/lib-commonjs/utils/getNativeElementProps.d.ts +22 -0
  151. package/lib-commonjs/utils/getNativeElementProps.js +29 -4
  152. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  153. package/lib-commonjs/utils/getRTLSafeKey.js +1 -1
  154. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
  155. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  156. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  157. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  158. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  159. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  160. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  161. package/lib-commonjs/utils/index.d.ts +2 -1
  162. package/lib-commonjs/utils/index.js +5 -3
  163. package/lib-commonjs/utils/index.js.map +1 -1
  164. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  165. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  166. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  167. package/lib-commonjs/utils/omit.js +2 -2
  168. package/lib-commonjs/utils/omit.js.map +1 -1
  169. package/lib-commonjs/utils/properties.d.ts +6 -0
  170. package/lib-commonjs/utils/properties.js +60 -41
  171. package/lib-commonjs/utils/properties.js.map +1 -1
  172. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +5 -5
  173. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  174. package/package.json +6 -11
  175. package/lib/compose/getSlotsCompat.d.ts +0 -22
  176. package/lib/compose/getSlotsCompat.js +0 -56
  177. package/lib/compose/getSlotsCompat.js.map +0 -1
  178. package/lib/compose/makeMergeProps.d.ts +0 -15
  179. package/lib/compose/makeMergeProps.js +0 -106
  180. package/lib/compose/makeMergeProps.js.map +0 -1
  181. package/lib/compose/makeMergePropsCompat.d.ts +0 -9
  182. package/lib/compose/makeMergePropsCompat.js +0 -9
  183. package/lib/compose/makeMergePropsCompat.js.map +0 -1
  184. package/lib/compose/nullRender.d.ts +0 -4
  185. package/lib/compose/nullRender.js +0 -7
  186. package/lib/compose/nullRender.js.map +0 -1
  187. package/lib/compose/resolveShorthandProps.d.ts +0 -8
  188. package/lib/compose/resolveShorthandProps.js +0 -30
  189. package/lib/compose/resolveShorthandProps.js.map +0 -1
  190. package/lib/hooks/useControllableValue.d.ts +0 -20
  191. package/lib/hooks/useControllableValue.js +0 -62
  192. package/lib/hooks/useControllableValue.js.map +0 -1
  193. package/lib/utils/onlyChild.d.ts +0 -5
  194. package/lib/utils/onlyChild.js +0 -13
  195. package/lib/utils/onlyChild.js.map +0 -1
  196. package/lib-commonjs/compose/getSlotsCompat.d.ts +0 -22
  197. package/lib-commonjs/compose/getSlotsCompat.js +0 -68
  198. package/lib-commonjs/compose/getSlotsCompat.js.map +0 -1
  199. package/lib-commonjs/compose/makeMergeProps.d.ts +0 -15
  200. package/lib-commonjs/compose/makeMergeProps.js +0 -117
  201. package/lib-commonjs/compose/makeMergeProps.js.map +0 -1
  202. package/lib-commonjs/compose/makeMergePropsCompat.d.ts +0 -9
  203. package/lib-commonjs/compose/makeMergePropsCompat.js +0 -17
  204. package/lib-commonjs/compose/makeMergePropsCompat.js.map +0 -1
  205. package/lib-commonjs/compose/nullRender.d.ts +0 -4
  206. package/lib-commonjs/compose/nullRender.js +0 -16
  207. package/lib-commonjs/compose/nullRender.js.map +0 -1
  208. package/lib-commonjs/compose/resolveShorthandProps.d.ts +0 -8
  209. package/lib-commonjs/compose/resolveShorthandProps.js +0 -41
  210. package/lib-commonjs/compose/resolveShorthandProps.js.map +0 -1
  211. package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
  212. package/lib-commonjs/hooks/useControllableValue.js +0 -73
  213. package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
  214. package/lib-commonjs/utils/onlyChild.d.ts +0 -5
  215. package/lib-commonjs/utils/onlyChild.js +0 -23
  216. package/lib-commonjs/utils/onlyChild.js.map +0 -1
@@ -1,12 +1,16 @@
1
- import type { DefaultObjectShorthandProps, ShorthandProps } from './types';
2
- export declare type ResolveShorthandOptions<Props extends Record<string, any>, Required extends boolean = false> = {
1
+ import type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';
2
+ export declare type ResolveShorthandOptions<Props, Required extends boolean = false> = {
3
3
  required?: Required;
4
4
  defaultProps?: Props;
5
5
  };
6
+ export declare type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {
7
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, true>): ReplaceNullWithUndefined<P>;
8
+ <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>): ReplaceNullWithUndefined<P> | undefined;
9
+ };
6
10
  /**
7
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
11
+ * Resolves shorthands into slot props, to ensure normalization of the signature
8
12
  * being passed down to getSlots method
9
- * @param value - the base ShorthandProps
10
- * @param options - options to resolve ShorthandProps
13
+ * @param value - the base shorthand props
14
+ * @param options - options to resolve shorthand props
11
15
  */
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;
16
+ export declare const resolveShorthand: ResolveShorthandFunction;
@@ -5,28 +5,26 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.resolveShorthand = void 0;
7
7
 
8
- var tslib_1 = /*#__PURE__*/require("tslib");
9
-
10
- var react_1 = /*#__PURE__*/require("react");
8
+ const react_1 = /*#__PURE__*/require("react");
11
9
  /**
12
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
10
+ * Resolves shorthands into slot props, to ensure normalization of the signature
13
11
  * being passed down to getSlots method
14
- * @param value - the base ShorthandProps
15
- * @param options - options to resolve ShorthandProps
12
+ * @param value - the base shorthand props
13
+ * @param options - options to resolve shorthand props
16
14
  */
17
15
 
18
16
 
19
- function resolveShorthand(value, options) {
20
- var _a = options || {},
21
- _b = _a.required,
22
- required = _b === void 0 ? false : _b,
23
- defaultProps = _a.defaultProps;
17
+ const resolveShorthand = (value, options) => {
18
+ const {
19
+ required = false,
20
+ defaultProps
21
+ } = options || {};
24
22
 
25
23
  if (value === null || value === undefined && !required) {
26
24
  return undefined;
27
25
  }
28
26
 
29
- var resolvedShorthand = {};
27
+ let resolvedShorthand = {};
30
28
 
31
29
  if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || react_1.isValidElement(value)) {
32
30
  resolvedShorthand.children = value;
@@ -34,8 +32,10 @@ function resolveShorthand(value, options) {
34
32
  resolvedShorthand = value;
35
33
  }
36
34
 
37
- return defaultProps ? tslib_1.__assign(tslib_1.__assign({}, defaultProps), resolvedShorthand) : resolvedShorthand;
38
- }
35
+ return defaultProps ? { ...defaultProps,
36
+ ...resolvedShorthand
37
+ } : resolvedShorthand;
38
+ };
39
39
 
40
40
  exports.resolveShorthand = resolveShorthand;
41
41
  //# sourceMappingURL=resolveShorthand.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AASA;;;;;AAKG;;;AACH,SAAgB,gBAAhB,CACE,KADF,EAEE,OAFF,EAEoD;AAE5C,MAAA,EAAA,GAAqC,OAAO,IAAI,EAAhD;AAAA,MAAE,EAAA,GAAA,EAAA,CAAA,QAAF;AAAA,MAAE,QAAQ,GAAA,EAAA,KAAA,KAAA,CAAA,GAAG,KAAH,GAAQ,EAAlB;AAAA,MAAoB,YAAY,GAAA,EAAA,CAAA,YAAhC;;AACN,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,GAAE,OAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,EAAA,EAAM,YAAN,CAAA,EAAuB,iBAAvB,CAAF,GAA+C,iBAAnE;AAGD;;AApBD,OAAA,CAAA,gBAAA,GAAA,gBAAA","sourceRoot":""}
1
+ {"version":3,"sources":["compose/resolveShorthand.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAkBA;;;;;AAKG;;;AACI,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;AAC3E,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,SAAO,YAAY,GAAG,EAAE,GAAG,YAAL;AAAmB,OAAG;AAAtB,GAAH,GAA+C,iBAAlE;AACD,CAfM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import { isValidElement } from 'react';\nimport type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = {\n required?: Required;\n defaultProps?: Props;\n};\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props | null>(\n value: P | SlotShorthandValue | undefined,\n options?: ResolveShorthandOptions<P, true>,\n ): ReplaceNullWithUndefined<P>;\n <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | ReplaceNullWithUndefined<P>\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand = {} as UnknownSlotProps;\n\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n return defaultProps ? { ...defaultProps, ...resolvedShorthand } : resolvedShorthand;\n};\n"],"sourceRoot":"../src/"}
@@ -1,47 +1,83 @@
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
+ export declare type SlotRenderFunction<Props> = (Component: React.ElementType<Props>, props: Omit<Props, 'children' | 'as'>) => React.ReactNode;
5
3
  /**
6
- * Matches any shorthand props type.
4
+ * Matches any component's Slots type (such as ButtonSlots).
7
5
  *
8
- * This should ONLY be used in type templates as in `extends DefaultObjectShorthandProps`;
6
+ * This should ONLY be used in type templates as in `extends SlotPropsRecord`;
7
+ * it shouldn't be used as a component's Slots type.
8
+ */
9
+ export declare type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;
10
+ /**
11
+ * The shorthand value of a slot allows specifying its child
12
+ */
13
+ export declare type SlotShorthandValue = React.ReactChild | React.ReactNodeArray | React.ReactPortal;
14
+ /**
15
+ * Matches any slot props type.
16
+ *
17
+ * This should ONLY be used in type templates as in `extends UnknownSlotProps`;
9
18
  * it shouldn't be used as the type of a slot.
10
19
  */
11
- export declare type DefaultObjectShorthandProps = ObjectShorthandProps<{
12
- children?: React.ReactNode;
20
+ export declare type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {
13
21
  as?: keyof JSX.IntrinsicElements;
14
- }>;
22
+ };
15
23
  /**
16
- * Defines the slot props for a slot that supports a Component type.
17
- *
18
- * For intrinsic elements like 'div', use {@link IntrinsicShorthandProps} instead.
24
+ * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.
19
25
  */
20
- export declare type ObjectShorthandProps<Props extends {
21
- children?: React.ReactNode;
22
- } = {}> = Props & {
23
- children?: Props['children'] | ShorthandRenderFunction<Props>;
26
+ declare type WithSlotShorthandValue<Props extends {
27
+ children?: unknown;
28
+ }> = Props | Extract<SlotShorthandValue, Props['children']>;
29
+ /**
30
+ * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
31
+ * to be a render function that takes those props.
32
+ */
33
+ declare type WithSlotRenderFunction<Props extends {
34
+ children?: unknown;
35
+ }> = Props & {
36
+ children?: Props['children'] | SlotRenderFunction<Props>;
24
37
  };
25
38
  /**
26
- * Define the slot arguments for a slot that supports one or more intrinsic element types, such as 'div'.
27
- * For slots that support custom components, use {@link ObjectShorthandProps} instead.
39
+ * HTML element types that are not allowed to have children.
40
+ *
41
+ * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
42
+ */
43
+ declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
44
+ /**
45
+ * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:
46
+ * * Removes legacy string ref.
47
+ * * Disallows children for empty tags like 'img'.
48
+ */
49
+ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
50
+ children?: never;
51
+ } : {});
52
+ /**
53
+ * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
54
+ * or a component like `typeof Button`.
55
+ *
56
+ * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
28
57
  *
29
- * The first param is the slot's default type if no `as` prop is specified.
30
- * The second param is an optional union of alternative types that can be specified for the `as` prop.
58
+ * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,
59
+ * wrap with `NonNullable` (see examples below).
31
60
  *
61
+ * @example
32
62
  * ```
33
- * IntrinsicShorthandProps<'div'> // Slot is always div
34
- * IntrinsicShorthandProps<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
35
- * IntrinsicShorthandProps<'label', 'span' | 'div'>; // Defaults to label, but allows as="span" or as="div"
63
+ * // Intrinsic element examples:
64
+ * Slot<'div'> // Slot is always div
65
+ * Slot<'button', 'a'> // Defaults to button, but allows as="a" with anchor-specific props
66
+ * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as="div" or as="pre"
67
+ * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)
68
+ *
69
+ * // Component examples:
70
+ * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props
71
+ * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)
36
72
  * ```
37
73
  */
38
- 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' : ({
39
- as?: DefaultAs;
40
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[DefaultAs]>>) | {
74
+ export declare type Slot<Type extends keyof JSX.IntrinsicElements | React.ComponentType | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
75
+ as?: Type;
76
+ } & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
41
77
  [As in AlternateAs]: {
42
78
  as: As;
43
- } & ObjectShorthandProps<React.PropsWithRef<JSX.IntrinsicElements[As]>>;
44
- }[AlternateAs];
79
+ } & WithSlotRenderFunction<IntrisicElementProps<As>>;
80
+ }[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
45
81
  /**
46
82
  * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.
47
83
  *
@@ -70,20 +106,35 @@ export declare type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> =
70
106
  export declare type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;
71
107
  /**
72
108
  * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
73
- * IntrinsicShorthandProps). This allows IntrinsicShorthandProps to be used with React.forwardRef.
109
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
74
110
  *
75
111
  * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
76
112
  * types, to prevent unions from being expanded.
77
113
  */
78
114
  export declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
79
- export declare type ComponentProps<Shorthands extends ObjectShorthandPropsRecord, Primary extends keyof Shorthands = 'root'> = Omit<{
80
- [Key in keyof Shorthands]?: ShorthandProps<NonNullable<Shorthands[Key]>>;
81
- }, Primary> & PropsWithoutRef<Shorthands[Primary]>;
82
- export declare type ComponentState<Shorthands extends ObjectShorthandPropsRecord> = {
83
- components?: {
84
- [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);
115
+ /**
116
+ * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
117
+ */
118
+ export declare type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;
119
+ /**
120
+ * Defines the Props type for a component given its slots and the definition of which one is the primary slot,
121
+ * defaulting to root if one is not provided.
122
+ */
123
+ export declare type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> = Omit<Slots, Primary & 'root'> & PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;
124
+ /**
125
+ * If type T includes `null`, remove it and add `undefined` instead.
126
+ */
127
+ export declare type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;
128
+ /**
129
+ * Defines the State object of a component given its slots.
130
+ */
131
+ export declare type ComponentState<Slots extends SlotPropsRecord> = {
132
+ components: {
133
+ [Key in keyof Slots]-?: React.ComponentType<ExtractSlotProps<Slots[Key]>> | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);
85
134
  };
86
- } & Shorthands;
135
+ } & {
136
+ [Key in keyof Slots]: ReplaceNullWithUndefined<Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>>;
137
+ };
87
138
  /**
88
139
  * This is part of a hack to infer the element type from a native element *props* type.
89
140
  * The only place the original element is found in a native props type (at least that's workable
@@ -101,45 +152,4 @@ declare type ObscureEventName = 'onLostPointerCaptureCapture';
101
152
  * Return type for `React.forwardRef`, including inference of the proper typing for the ref.
102
153
  */
103
154
  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;
104
- export declare type ComponentPropsCompat = {
105
- as?: React.ElementType;
106
- className?: string;
107
- children?: React.ReactNode;
108
- };
109
- export declare type ShorthandRenderFunctionCompat<TProps> = (Component: React.ElementType<TProps>, props: TProps) => React.ReactNode;
110
- export declare type ShorthandPropsCompat<TProps extends ComponentPropsCompat = {}> = React.ReactChild | React.ReactNodeArray | React.ReactPortal | number | null | undefined | ObjectShorthandPropsCompat<TProps>;
111
- export declare type ObjectShorthandPropsCompat<TProps extends ComponentPropsCompat = {}> = TProps & Omit<ComponentPropsCompat, 'children'> & {
112
- children?: TProps['children'] | ShorthandRenderFunctionCompat<TProps>;
113
- };
114
- export declare type BaseSlotsCompat = {
115
- root: React.ElementType;
116
- };
117
- export declare type SlotPropsCompat<TSlots extends BaseSlotsCompat, TProps, TRootProps extends React.HTMLAttributes<HTMLElement>> = {
118
- [key in keyof Omit<TSlots, 'root'>]: key extends keyof TProps ? TProps[key] : any;
119
- } & {
120
- root: TRootProps;
121
- };
122
- /**
123
- * Helper type to convert the given props of type ShorthandProps into ObjectShorthandProps
124
- */
125
- export declare type ResolvedShorthandPropsCompat<T, K extends keyof T> = Omit<T, K> & {
126
- [P in K]: T[P] extends ShorthandPropsCompat<infer U> ? ObjectShorthandPropsCompat<U> : T[P];
127
- };
128
- /**
129
- * Helper type to mark the given props as required.
130
- * Similar to Required<T> except it only requires a subset of the props.
131
- */
132
- export declare type RequiredPropsCompat<T, K extends keyof T> = Omit<T, K> & {
133
- [P in K]-?: T[P];
134
- };
135
- /**
136
- * Converts a components Props type to a State type:
137
- * * Ensures the specified ShorthandProps are of type ObjectShorthandProps<T>
138
- * * Marks the given defaulted props as required (-?)
139
- *
140
- * @template Props - The component's Props type
141
- * @template ShorthandPropNames - The keys of Props that correspond to ShorthandProps
142
- * @template DefaultedPropNames - The keys of Props that will always have a default value provided
143
- */
144
- export declare type ComponentStateCompat<Props, ShorthandPropNames extends keyof Props = never, DefaultedPropNames extends keyof ResolvedShorthandPropsCompat<Props, ShorthandPropNames> = never> = RequiredPropsCompat<ResolvedShorthandPropsCompat<Props, ShorthandPropNames>, DefaultedPropNames>;
145
155
  export {};
@@ -2,5 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
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;
6
10
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":""}
1
+ {"version":3,"sources":["compose/types.ts"],"names":[],"mappings":";;;;IAqNA;AACA;AACA;AACA;AACA","sourcesContent":["import * as React from 'react';\n\nexport type SlotRenderFunction<Props> = (\n Component: React.ElementType<Props>,\n props: Omit<Props, 'children' | 'as'>,\n) => React.ReactNode;\n\n/**\n * Matches any component's Slots type (such as ButtonSlots).\n *\n * This should ONLY be used in type templates as in `extends SlotPropsRecord`;\n * it shouldn't be used as a component's Slots type.\n */\nexport type SlotPropsRecord = Record<string, UnknownSlotProps | SlotShorthandValue | null | undefined>;\n\n/**\n * The shorthand value of a slot allows specifying its child\n */\nexport type SlotShorthandValue = React.ReactChild | React.ReactNodeArray | React.ReactPortal;\n\n/**\n * Matches any slot props type.\n *\n * This should ONLY be used in type templates as in `extends UnknownSlotProps`;\n * it shouldn't be used as the type of a slot.\n */\nexport type UnknownSlotProps = Pick<React.HTMLAttributes<HTMLElement>, 'children' | 'className' | 'style'> & {\n as?: keyof JSX.IntrinsicElements;\n};\n\n/**\n * Helper type for {@link Slot}. Adds shorthand types that are assignable to the slot's `children`.\n */\ntype WithSlotShorthandValue<Props extends { children?: unknown }> =\n | Props\n | Extract<SlotShorthandValue, Props['children']>;\n\n/**\n * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`\n * to be a render function that takes those props.\n */\ntype WithSlotRenderFunction<Props extends { children?: unknown }> = Props & {\n children?: Props['children'] | SlotRenderFunction<Props>;\n};\n\n/**\n * HTML element types that are not allowed to have children.\n *\n * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element\n */\ntype EmptyIntrisicElements =\n | 'area'\n | 'base'\n | 'br'\n | 'col'\n | 'embed'\n | 'hr'\n | 'img'\n | 'input'\n | 'link'\n | 'meta'\n | 'param'\n | 'source'\n | 'track'\n | 'wbr';\n\n/**\n * Helper type for {@link Slot}. Modifies `JSX.IntrinsicElements[Type]`:\n * * Removes legacy string ref.\n * * Disallows children for empty tags like 'img'.\n */\ntype IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React.PropsWithRef<JSX.IntrinsicElements[Type]> &\n (Type extends EmptyIntrisicElements ? { children?: never } : {});\n\n/**\n * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,\n * or a component like `typeof Button`.\n *\n * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).\n *\n * By default, slots can be set to `null` to prevent them from being rendered. If a slot must always be rendered,\n * wrap with `NonNullable` (see examples below).\n *\n * @example\n * ```\n * // Intrinsic element examples:\n * Slot<'div'> // Slot is always div\n * Slot<'button', 'a'> // Defaults to button, but allows as=\"a\" with anchor-specific props\n * Slot<'span', 'div' | 'pre'> // Defaults to span, but allows as=\"div\" or as=\"pre\"\n * NonNullable<Slot<'div'>> // Slot that will always be rendered (can't be set to null by the user)\n *\n * // Component examples:\n * Slot<typeof Button> // Slot is always a Button, and accepts all of Button's Props\n * NonNullable<Slot<typeof Label>> // Slot is a Label and will always be rendered (can't be set to null by the user)\n * ```\n */\nexport type Slot<\n Type extends keyof JSX.IntrinsicElements | React.ComponentType | UnknownSlotProps,\n AlternateAs extends keyof JSX.IntrinsicElements = never\n> = IsSingleton<Extract<Type, string>> extends true\n ?\n | WithSlotShorthandValue<\n Type extends keyof JSX.IntrinsicElements // Intrinsic elements like `div`\n ? { as?: Type } & WithSlotRenderFunction<IntrisicElementProps<Type>>\n : Type extends React.ComponentType<infer Props> // Component types like `typeof Button`\n ? WithSlotRenderFunction<Props>\n : Type // Props types like `ButtonProps`\n >\n | {\n [As in AlternateAs]: { as: As } & WithSlotRenderFunction<IntrisicElementProps<As>>;\n }[AlternateAs]\n | null\n : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';\n\n/**\n * Evaluates to true if the given type contains exactly one string, or false if it is a union of strings.\n *\n * ```\n * IsSingleton<'a'> // true\n * IsSingleton<'a' | 'b' | 'c'> // false\n * ```\n */\nexport type IsSingleton<T extends string> = { [K in T]: Exclude<T, K> extends never ? true : false }[T];\n\n/**\n * Helper type for inferring the type of the as prop from a Props type.\n *\n * For example:\n * ```\n * type Example<T> = T extends AsIntrinsicElement<infer As> ? As : never;\n * ```\n */\nexport type AsIntrinsicElement<As extends keyof JSX.IntrinsicElements> = { as?: As };\n\n/**\n * Converts a union type (`A | B | C`) to an intersection type (`A & B & C`)\n */\nexport type UnionToIntersection<U> = (U extends unknown ? (x: U) => U : never) extends (x: infer I) => U ? I : never;\n\n/**\n * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by\n * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.\n *\n * The conditional \"extends unknown\" (always true) exploits a quirk in the way TypeScript handles conditional\n * types, to prevent unions from being expanded.\n */\nexport type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;\n\n/**\n * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.\n */\nexport type ExtractSlotProps<S> = Exclude<S, SlotShorthandValue | null | undefined>;\n\n/**\n * Defines the Props type for a component given its slots and the definition of which one is the primary slot,\n * defaulting to root if one is not provided.\n */\nexport type ComponentProps<Slots extends SlotPropsRecord, Primary extends keyof Slots = 'root'> =\n // Include a prop for each slot (see note below about the Omit)\n Omit<Slots, Primary & 'root'> &\n // Include all of the props of the primary slot inline in the component's props\n PropsWithoutRef<ExtractSlotProps<Slots[Primary]>>;\n\n// Note: the `Omit<Slots, Primary & 'root'>` above is a little tricky. Here's what it's doing:\n// * If the Primary slot is 'root', then omit the `root` slot prop.\n// * Otherwise, don't omit any props: include *both* the Primary and `root` props.\n// We need both props to allow the user to specify native props for either slot because the `root` slot is\n// special and always gets className and style props, per RFC https://github.com/microsoft/fluentui/pull/18983\n\n/**\n * If type T includes `null`, remove it and add `undefined` instead.\n */\nexport type ReplaceNullWithUndefined<T> = T extends null ? Exclude<T, null> | undefined : T;\n\n/**\n * Defines the State object of a component given its slots.\n */\nexport type ComponentState<Slots extends SlotPropsRecord> = {\n components: {\n [Key in keyof Slots]-?:\n | React.ComponentType<ExtractSlotProps<Slots[Key]>>\n | (ExtractSlotProps<Slots[Key]> extends AsIntrinsicElement<infer As> ? As : keyof JSX.IntrinsicElements);\n };\n} & {\n // Include a prop for each slot, with the shorthand resolved to a props object\n // The root slot can never be null, so also exclude null from it\n [Key in keyof Slots]: ReplaceNullWithUndefined<\n Exclude<Slots[Key], SlotShorthandValue | (Key extends 'root' ? null : never)>\n >;\n};\n\n/**\n * This is part of a hack to infer the element type from a native element *props* type.\n * The only place the original element is found in a native props type (at least that's workable\n * for inference) is in the event handlers, so some of the helper types use this event handler\n * name to infer the original element type.\n *\n * Notes:\n * - Using an extremely obscure event handler reduces the likelihood that its signature will be\n * modified in any component's props.\n * - Inferring based on a single prop name instead of a larger type like `DOMAttributes<T>` should be\n * less expensive for typescript to evaluate and is less likely to result in type expansion in .d.ts.\n */\ntype ObscureEventName = 'onLostPointerCaptureCapture';\n\n/**\n * Return type for `React.forwardRef`, including inference of the proper typing for the ref.\n */\nexport type ForwardRefComponent<Props> = ObscureEventName extends keyof Props\n ? Required<Props>[ObscureEventName] extends React.PointerEventHandler<infer Element>\n ? React.ForwardRefExoticComponent<Props & React.RefAttributes<Element>>\n : never\n : never;\n// A definition like this would also work, but typescript is more likely to unnecessarily expand\n// the props type with this version (and it's likely much more expensive to evaluate)\n// export type ForwardRefComponent<Props> = Props extends React.DOMAttributes<infer Element>\n// ? React.ForwardRefExoticComponent<Props> & React.RefAttributes<Element>\n// : never;\n"],"sourceRoot":"../src/"}
@@ -1,11 +1,11 @@
1
1
  export * from './useControllableState';
2
2
  export * from './useBoolean';
3
3
  export * from './useConst';
4
- export * from './useControllableValue';
5
4
  export * from './useEventCallback';
6
5
  export * from './useFirstMount';
7
6
  export * from './useId';
8
7
  export * from './useIsomorphicLayoutEffect';
8
+ export * from './useMergedEventCallbacks';
9
9
  export * from './useMergedRefs';
10
10
  export * from './useMount';
11
11
  export * from './useOnClickOutside';
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
 
7
- var tslib_1 = /*#__PURE__*/require("tslib");
7
+ const tslib_1 = /*#__PURE__*/require("tslib");
8
8
 
9
9
  tslib_1.__exportStar(require("./useControllableState"), exports);
10
10
 
@@ -12,8 +12,6 @@ tslib_1.__exportStar(require("./useBoolean"), exports);
12
12
 
13
13
  tslib_1.__exportStar(require("./useConst"), exports);
14
14
 
15
- tslib_1.__exportStar(require("./useControllableValue"), exports);
16
-
17
15
  tslib_1.__exportStar(require("./useEventCallback"), exports);
18
16
 
19
17
  tslib_1.__exportStar(require("./useFirstMount"), exports);
@@ -22,6 +20,8 @@ tslib_1.__exportStar(require("./useId"), exports);
22
20
 
23
21
  tslib_1.__exportStar(require("./useIsomorphicLayoutEffect"), exports);
24
22
 
23
+ tslib_1.__exportStar(require("./useMergedEventCallbacks"), exports);
24
+
25
25
  tslib_1.__exportStar(require("./useMergedRefs"), exports);
26
26
 
27
27
  tslib_1.__exportStar(require("./useMount"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,wBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,SAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,6BAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,YAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,qBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,sBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,eAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,kBAAA,CAAA,EAAA,OAAA","sourceRoot":""}
1
+ {"version":3,"sources":["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,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,2BAAA,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","sourcesContent":["export * from './useControllableState';\nexport * from './useBoolean';\nexport * from './useConst';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedEventCallbacks';\nexport * from './useMergedRefs';\nexport * from './useMount';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\nexport * from './useUnmount';\nexport * from './useForceUpdate';\n"],"sourceRoot":"../src/"}
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useBoolean = void 0;
7
7
 
8
- var React = /*#__PURE__*/require("react");
8
+ const React = /*#__PURE__*/require("react");
9
9
 
10
- var useConst_1 = /*#__PURE__*/require("./useConst");
10
+ const useConst_1 = /*#__PURE__*/require("./useConst");
11
11
  /**
12
12
  * Hook to store a value and generate callbacks for setting the value to true or false.
13
13
  * The identity of the callbacks will always stay the same.
@@ -18,31 +18,20 @@ var useConst_1 = /*#__PURE__*/require("./useConst");
18
18
 
19
19
 
20
20
  function useBoolean(initialState) {
21
- var _a = React.useState(initialState),
22
- value = _a[0],
23
- setValue = _a[1];
24
-
25
- var setTrue = useConst_1.useConst(function () {
26
- return function () {
27
- setValue(true);
28
- };
21
+ const [value, setValue] = React.useState(initialState);
22
+ const setTrue = useConst_1.useConst(() => () => {
23
+ setValue(true);
29
24
  });
30
- var setFalse = useConst_1.useConst(function () {
31
- return function () {
32
- setValue(false);
33
- };
25
+ const setFalse = useConst_1.useConst(() => () => {
26
+ setValue(false);
34
27
  });
35
- var toggle = useConst_1.useConst(function () {
36
- return function () {
37
- setValue(function (currentValue) {
38
- return !currentValue;
39
- });
40
- };
28
+ const toggle = useConst_1.useConst(() => () => {
29
+ setValue(currentValue => !currentValue);
41
30
  });
42
31
  return [value, {
43
- setTrue: setTrue,
44
- setFalse: setFalse,
45
- toggle: toggle
32
+ setTrue,
33
+ setFalse,
34
+ toggle
46
35
  }];
47
36
  }
48
37
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;AAYA;;;;;;AAMG;;;AACH,SAAgB,UAAhB,CAA2B,YAA3B,EAAgD;AACxC,MAAA,EAAA,GAAoB,KAAK,CAAC,QAAN,CAAe,YAAf,CAApB;AAAA,MAAC,KAAK,GAAA,EAAA,CAAA,CAAA,CAAN;AAAA,MAAQ,QAAQ,GAAA,EAAA,CAAA,CAAA,CAAhB;;AAEN,MAAM,OAAO,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,YAAA;AAC7B,MAAA,QAAQ,CAAC,IAAD,CAAR;AAD6B,KAAA;AAE9B,GAFe,CAAhB;AAGA,MAAM,QAAQ,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,YAAA;AAC9B,MAAA,QAAQ,CAAC,KAAD,CAAR;AAD8B,KAAA;AAE/B,GAFgB,CAAjB;AAGA,MAAM,MAAM,GAAG,UAAA,CAAA,QAAA,CAAS,YAAA;AAAM,WAAA,YAAA;AAC5B,MAAA,QAAQ,CAAC,UAAA,YAAA,EAAY;AAAI,eAAA,CAAA,YAAA;AAAa,OAA9B,CAAR;AAD4B,KAAA;AAE7B,GAFc,CAAf;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAO,EAAA,OAAT;AAAW,IAAA,QAAQ,EAAA,QAAnB;AAAqB,IAAA,MAAM,EAAA;AAA3B,GAAR,CAAP;AACD;;AAdD,OAAA,CAAA,UAAA,GAAA,UAAA","sourceRoot":""}
1
+ {"version":3,"sources":["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","sourcesContent":["import * as React from 'react';\nimport { useConst } from './useConst';\n\n/** Updater callbacks returned by `useBoolean`. */\nexport type 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"],"sourceRoot":"../src/"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useConst = void 0;
7
7
 
8
- var React = /*#__PURE__*/require("react");
8
+ const React = /*#__PURE__*/require("react");
9
9
  /**
10
10
  * Hook to initialize and return a constant value. Unlike `React.useMemo`, this is guaranteed to
11
11
  * always return the same value (and if the initializer is a function, only call it once).
@@ -23,7 +23,7 @@ function useConst(initialValue) {
23
23
  // Use useRef to store the value because it's the least expensive built-in hook that works here
24
24
  // (we could also use `const [value] = React.useState(initialValue)` but that's more expensive
25
25
  // internally due to reducer handling which we don't need)
26
- var ref = React.useRef();
26
+ const ref = React.useRef();
27
27
 
28
28
  if (ref.current === undefined) {
29
29
  // Box the value in an object so we can tell if it's initialized even if the initializer
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useConst.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;;AAUG;;;AACH,SAAgB,QAAhB,CAA4B,YAA5B,EAAuD;AACrD;AACA;AACA;AACA,MAAM,GAAG,GAAG,KAAK,CAAC,MAAN,EAAZ;;AACA,MAAI,GAAG,CAAC,OAAJ,KAAgB,SAApB,EAA+B;AAC7B;AACA;AACA,IAAA,GAAG,CAAC,OAAJ,GAAc;AACZ,MAAA,KAAK,EAAE,OAAO,YAAP,KAAwB,UAAxB,GAAsC,YAAyB,EAA/D,GAAoE;AAD/D,KAAd;AAGD;;AACD,SAAO,GAAG,CAAC,OAAJ,CAAY,KAAnB;AACD;;AAbD,OAAA,CAAA,QAAA,GAAA,QAAA","sourceRoot":""}
1
+ {"version":3,"sources":["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","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"],"sourceRoot":"../src/"}
@@ -1,21 +1,31 @@
1
1
  import * as React from 'react';
2
2
  export declare type UseControllableStateOptions<State> = {
3
3
  /**
4
- * User provided default state or factory initializer
4
+ * User-provided default state or initializer, for uncontrolled usage.
5
5
  */
6
6
  defaultState?: State | (() => State);
7
7
  /**
8
- * User provided controllable state, undefined state means internal state will be used
8
+ * User-provided controlled state. `undefined` means internal state will be used.
9
9
  */
10
10
  state: State | undefined;
11
11
  /**
12
- * Used to initialize state if all user provided states are undefined
12
+ * Used as the initial state if `state` and `defaultState` are both `undefined`.
13
+ * If `undefined` is the correct initial state, pass that here.
13
14
  */
14
15
  initialState: State;
15
16
  };
16
17
  /**
17
- * A useState 'like' hook that allows optional user control
18
- * Useful for components which allow uncontrolled and controlled behaviour for users
19
- * @returns - https://reactjs.org/docs/hooks-state.html
18
+ * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
19
+ * such as a checked state or text input string.
20
+ *
21
+ * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
22
+ * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
23
+ *
24
+ * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
25
+ * of the current value and an updater (dispatch) function. The updater function is referentially
26
+ * stable (won't change during the component's lifecycle). It can take either a new value, or a
27
+ * function which is passed the previous value and returns the new value. Unlike `setState`, calls
28
+ * to the updater function will only be respected if the component is uncontrolled.
29
+ * @see https://reactjs.org/docs/uncontrolled-components.html
20
30
  */
21
31
  export declare const useControllableState: <State>(options: UseControllableStateOptions<State>) => [State, React.Dispatch<React.SetStateAction<State>>];
@@ -5,40 +5,41 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useControllableState = void 0;
7
7
 
8
- var React = /*#__PURE__*/require("react");
8
+ const React = /*#__PURE__*/require("react");
9
9
 
10
- var useConst_1 = /*#__PURE__*/require("./useConst");
11
-
12
- function isUndefined(state) {
13
- return typeof state === 'undefined';
14
- }
10
+ const useConst_1 = /*#__PURE__*/require("./useConst");
15
11
 
16
12
  function isFactoryDispatch(newState) {
17
13
  return typeof newState === 'function';
18
14
  }
19
15
  /**
20
- * A useState 'like' hook that allows optional user control
21
- * Useful for components which allow uncontrolled and controlled behaviour for users
22
- * @returns - https://reactjs.org/docs/hooks-state.html
16
+ * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
17
+ * such as a checked state or text input string.
18
+ *
19
+ * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
20
+ * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
21
+ *
22
+ * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
23
+ * of the current value and an updater (dispatch) function. The updater function is referentially
24
+ * stable (won't change during the component's lifecycle). It can take either a new value, or a
25
+ * function which is passed the previous value and returns the new value. Unlike `setState`, calls
26
+ * to the updater function will only be respected if the component is uncontrolled.
27
+ * @see https://reactjs.org/docs/uncontrolled-components.html
23
28
  */
24
29
 
25
30
 
26
- var useControllableState = function (options) {
27
- var isControlled = useIsControlled(options.state);
28
- var initialState = isUndefined(options.defaultState) ? options.initialState : options.defaultState;
29
-
30
- var _a = React.useState(initialState),
31
- internalState = _a[0],
32
- setInternalState = _a[1];
33
-
34
- var state = isControlled ? options.state : internalState;
35
- var stateRef = React.useRef(state);
36
- React.useEffect(function () {
31
+ const useControllableState = options => {
32
+ const isControlled = useIsControlled(options.state);
33
+ const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
34
+ const [internalState, setInternalState] = React.useState(initialState);
35
+ const state = isControlled ? options.state : internalState;
36
+ const stateRef = React.useRef(state);
37
+ React.useEffect(() => {
37
38
  stateRef.current = state;
38
39
  }, [state]); // To match the behavior of the setter returned by React.useState, this callback's identity
39
40
  // should never change. This means it MUST NOT directly reference variables that can change.
40
41
 
41
- var setState = React.useCallback(function (newState) {
42
+ const setState = React.useCallback(newState => {
42
43
  // React dispatch can use a factory
43
44
  // https://reactjs.org/docs/hooks-reference.html#functional-updates
44
45
  if (isFactoryDispatch(newState)) {
@@ -59,17 +60,17 @@ exports.useControllableState = useControllableState;
59
60
  * @returns - whether the value is controlled
60
61
  */
61
62
 
62
- var useIsControlled = function (controlledValue) {
63
- var isControlled = useConst_1.useConst(controlledValue !== undefined);
63
+ const useIsControlled = controlledValue => {
64
+ const isControlled = useConst_1.useConst(controlledValue !== undefined);
64
65
 
65
66
  if (process.env.NODE_ENV !== 'production') {
66
67
  // We don't want these warnings in production even though it is against native behaviour
67
68
  // eslint-disable-next-line react-hooks/rules-of-hooks
68
- React.useEffect(function () {
69
+ React.useEffect(() => {
69
70
  if (isControlled !== (controlledValue !== undefined)) {
70
- var error = new Error();
71
- var controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
72
- var undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
71
+ const error = new Error();
72
+ const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
73
+ const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
73
74
 
74
75
  console.error([// Default react error
75
76
  'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));