@fluentui/react-utilities 9.0.0-nightly.b5b7401007.0 → 9.0.0-rc.3

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 (186) hide show
  1. package/CHANGELOG.json +180 -12
  2. package/CHANGELOG.md +54 -8
  3. package/dist/react-utilities.d.ts +232 -105
  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 -1
  8. package/lib/compose/index.js +0 -1
  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 -35
  14. package/lib/compose/types.js.map +1 -1
  15. package/lib/hooks/index.d.ts +1 -1
  16. package/lib/hooks/index.js +1 -1
  17. package/lib/hooks/index.js.map +1 -1
  18. package/lib/hooks/useBoolean.js +10 -21
  19. package/lib/hooks/useBoolean.js.map +1 -1
  20. package/lib/hooks/useConst.js +1 -1
  21. package/lib/hooks/useConst.js.map +1 -1
  22. package/lib/hooks/useControllableState.d.ts +16 -6
  23. package/lib/hooks/useControllableState.js +26 -25
  24. package/lib/hooks/useControllableState.js.map +1 -1
  25. package/lib/hooks/useEventCallback.js +6 -12
  26. package/lib/hooks/useEventCallback.js.map +1 -1
  27. package/lib/hooks/useFirstMount.js +1 -1
  28. package/lib/hooks/useFirstMount.js.map +1 -1
  29. package/lib/hooks/useForceUpdate.js +1 -3
  30. package/lib/hooks/useForceUpdate.js.map +1 -1
  31. package/lib/hooks/useId.js +2 -4
  32. package/lib/hooks/useId.js.map +1 -1
  33. package/lib/hooks/useIsomorphicLayoutEffect.js +1 -1
  34. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  35. package/lib/hooks/useMergedEventCallbacks.d.ts +18 -0
  36. package/lib/hooks/useMergedEventCallbacks.js +26 -0
  37. package/lib/hooks/useMergedEventCallbacks.js.map +1 -0
  38. package/lib/hooks/useMergedRefs.js +5 -13
  39. package/lib/hooks/useMergedRefs.js.map +1 -1
  40. package/lib/hooks/useMount.js +3 -3
  41. package/lib/hooks/useMount.js.map +1 -1
  42. package/lib/hooks/useOnClickOutside.js +30 -36
  43. package/lib/hooks/useOnClickOutside.js.map +1 -1
  44. package/lib/hooks/useOnScrollOutside.js +13 -15
  45. package/lib/hooks/useOnScrollOutside.js.map +1 -1
  46. package/lib/hooks/usePrevious.js +3 -3
  47. package/lib/hooks/usePrevious.js.map +1 -1
  48. package/lib/hooks/useTimeout.js +13 -17
  49. package/lib/hooks/useTimeout.js.map +1 -1
  50. package/lib/hooks/useUnmount.js +5 -7
  51. package/lib/hooks/useUnmount.js.map +1 -1
  52. package/lib/index.js.map +1 -1
  53. package/lib/ssr/SSRContext.js +9 -15
  54. package/lib/ssr/SSRContext.js.map +1 -1
  55. package/lib/ssr/canUseDOM.js.map +1 -1
  56. package/lib/ssr/index.js.map +1 -1
  57. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  58. package/lib/utils/applyTriggerPropsToChildren.js +24 -4
  59. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  60. package/lib/utils/clamp.js +1 -3
  61. package/lib/utils/clamp.js.map +1 -1
  62. package/lib/utils/getNativeElementProps.d.ts +22 -0
  63. package/lib/utils/getNativeElementProps.js +24 -2
  64. package/lib/utils/getNativeElementProps.js.map +1 -1
  65. package/lib/utils/getRTLSafeKey.js +1 -1
  66. package/lib/utils/getRTLSafeKey.js.map +1 -1
  67. package/lib/utils/getReactCallbackName.d.ts +25 -0
  68. package/lib/utils/getReactCallbackName.js +26 -0
  69. package/lib/utils/getReactCallbackName.js.map +1 -0
  70. package/lib/utils/getTriggerChild.d.ts +22 -0
  71. package/lib/utils/getTriggerChild.js +26 -0
  72. package/lib/utils/getTriggerChild.js.map +1 -0
  73. package/lib/utils/index.d.ts +2 -1
  74. package/lib/utils/index.js +2 -1
  75. package/lib/utils/index.js.map +1 -1
  76. package/lib/utils/isFluentTrigger.d.ts +22 -0
  77. package/lib/utils/isFluentTrigger.js +8 -0
  78. package/lib/utils/isFluentTrigger.js.map +1 -0
  79. package/lib/utils/omit.js +2 -2
  80. package/lib/utils/omit.js.map +1 -1
  81. package/lib/utils/properties.js +55 -44
  82. package/lib/utils/properties.js.map +1 -1
  83. package/lib/utils/shouldPreventDefaultOnKeyDown.js +4 -4
  84. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  85. package/lib-commonjs/compose/getSlots.d.ts +11 -10
  86. package/lib-commonjs/compose/getSlots.js +23 -34
  87. package/lib-commonjs/compose/getSlots.js.map +1 -1
  88. package/lib-commonjs/compose/index.d.ts +0 -1
  89. package/lib-commonjs/compose/index.js +1 -3
  90. package/lib-commonjs/compose/index.js.map +1 -1
  91. package/lib-commonjs/compose/resolveShorthand.d.ts +10 -6
  92. package/lib-commonjs/compose/resolveShorthand.js +14 -14
  93. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  94. package/lib-commonjs/compose/types.d.ts +86 -35
  95. package/lib-commonjs/compose/types.js.map +1 -1
  96. package/lib-commonjs/hooks/index.d.ts +1 -1
  97. package/lib-commonjs/hooks/index.js +3 -3
  98. package/lib-commonjs/hooks/index.js.map +1 -1
  99. package/lib-commonjs/hooks/useBoolean.js +12 -23
  100. package/lib-commonjs/hooks/useBoolean.js.map +1 -1
  101. package/lib-commonjs/hooks/useConst.js +2 -2
  102. package/lib-commonjs/hooks/useConst.js.map +1 -1
  103. package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
  104. package/lib-commonjs/hooks/useControllableState.js +28 -27
  105. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  106. package/lib-commonjs/hooks/useEventCallback.js +8 -14
  107. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  108. package/lib-commonjs/hooks/useFirstMount.js +2 -2
  109. package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
  110. package/lib-commonjs/hooks/useForceUpdate.js +2 -4
  111. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
  112. package/lib-commonjs/hooks/useId.js +4 -6
  113. package/lib-commonjs/hooks/useId.js.map +1 -1
  114. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +2 -2
  115. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  116. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  117. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  118. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  119. package/lib-commonjs/hooks/useMergedRefs.js +6 -15
  120. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  121. package/lib-commonjs/hooks/useMount.js +4 -4
  122. package/lib-commonjs/hooks/useMount.js.map +1 -1
  123. package/lib-commonjs/hooks/useOnClickOutside.js +32 -38
  124. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  125. package/lib-commonjs/hooks/useOnScrollOutside.js +15 -17
  126. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  127. package/lib-commonjs/hooks/usePrevious.js +4 -4
  128. package/lib-commonjs/hooks/usePrevious.js.map +1 -1
  129. package/lib-commonjs/hooks/useTimeout.js +15 -19
  130. package/lib-commonjs/hooks/useTimeout.js.map +1 -1
  131. package/lib-commonjs/hooks/useUnmount.js +6 -8
  132. package/lib-commonjs/hooks/useUnmount.js.map +1 -1
  133. package/lib-commonjs/index.js +1 -1
  134. package/lib-commonjs/index.js.map +1 -1
  135. package/lib-commonjs/ssr/SSRContext.js +9 -15
  136. package/lib-commonjs/ssr/SSRContext.js.map +1 -1
  137. package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
  138. package/lib-commonjs/ssr/index.js +1 -1
  139. package/lib-commonjs/ssr/index.js.map +1 -1
  140. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  141. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +26 -6
  142. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  143. package/lib-commonjs/utils/clamp.js +1 -3
  144. package/lib-commonjs/utils/clamp.js.map +1 -1
  145. package/lib-commonjs/utils/getNativeElementProps.d.ts +22 -0
  146. package/lib-commonjs/utils/getNativeElementProps.js +28 -4
  147. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  148. package/lib-commonjs/utils/getRTLSafeKey.js +1 -1
  149. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
  150. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  151. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  152. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  153. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  154. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  155. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  156. package/lib-commonjs/utils/index.d.ts +2 -1
  157. package/lib-commonjs/utils/index.js +5 -3
  158. package/lib-commonjs/utils/index.js.map +1 -1
  159. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  160. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  161. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  162. package/lib-commonjs/utils/omit.js +2 -2
  163. package/lib-commonjs/utils/omit.js.map +1 -1
  164. package/lib-commonjs/utils/properties.js +50 -39
  165. package/lib-commonjs/utils/properties.js.map +1 -1
  166. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +5 -5
  167. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  168. package/package.json +6 -11
  169. package/lib/compose/nullRender.d.ts +0 -4
  170. package/lib/compose/nullRender.js +0 -7
  171. package/lib/compose/nullRender.js.map +0 -1
  172. package/lib/hooks/useControllableValue.d.ts +0 -20
  173. package/lib/hooks/useControllableValue.js +0 -62
  174. package/lib/hooks/useControllableValue.js.map +0 -1
  175. package/lib/utils/onlyChild.d.ts +0 -5
  176. package/lib/utils/onlyChild.js +0 -13
  177. package/lib/utils/onlyChild.js.map +0 -1
  178. package/lib-commonjs/compose/nullRender.d.ts +0 -4
  179. package/lib-commonjs/compose/nullRender.js +0 -16
  180. package/lib-commonjs/compose/nullRender.js.map +0 -1
  181. package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
  182. package/lib-commonjs/hooks/useControllableValue.js +0 -73
  183. package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
  184. package/lib-commonjs/utils/onlyChild.d.ts +0 -5
  185. package/lib-commonjs/utils/onlyChild.js +0 -23
  186. package/lib-commonjs/utils/onlyChild.js.map +0 -1
@@ -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.
28
40
  *
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.
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`.
31
55
  *
56
+ * If a slot needs to support multiple intrinsic element types, use the `AlternateAs` param (see examples below).
57
+ *
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).
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
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":";;;;IA2IA;AACA;AACA;AACA;AACA","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,iB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A,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(' '));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AAiBA,SAAS,WAAT,CAAqB,KAArB,EAAmC;AACjC,SAAO,OAAO,KAAP,KAAiB,WAAxB;AACD;;AAED,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;AACrE,SAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;AAIG;;;AACI,IAAM,oBA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CAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;AAUD;AACF,KAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;AAuBD;;AAED,SAAO,YAAP;AACD,CAhCD","sourcesContent":["import * as React from 'react';\nimport { useConst } from './useConst';\n\nexport type UseControllableStateOptions<State> = {\n /**\n * User-provided default state or initializer, for uncontrolled usage.\n */\n defaultState?: State | (() => State);\n /**\n * User-provided controlled state. `undefined` means internal state will be used.\n */\n state: State | undefined;\n /**\n * Used as the initial state if `state` and `defaultState` are both `undefined`.\n * If `undefined` is the correct initial state, pass that here.\n */\n initialState: State;\n};\n\nfunction isFactoryDispatch<State>(newState: React.SetStateAction<State>): newState is (prevState: State) => State {\n return typeof newState === 'function';\n}\n\n/**\n * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,\n * such as a checked state or text input string.\n *\n * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a\n * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.\n *\n * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array\n * of the current value and an updater (dispatch) function. The updater function is referentially\n * stable (won't change during the component's lifecycle). It can take either a new value, or a\n * function which is passed the previous value and returns the new value. Unlike `setState`, calls\n * to the updater function will only be respected if the component is uncontrolled.\n * @see https://reactjs.org/docs/uncontrolled-components.html\n */\nexport const useControllableState = <State>(\n options: UseControllableStateOptions<State>,\n): [State, React.Dispatch<React.SetStateAction<State>>] => {\n const isControlled = useIsControlled(options.state);\n const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;\n const [internalState, setInternalState] = React.useState<State>(initialState);\n\n const state = isControlled ? (options.state as State) : internalState;\n\n const stateRef = React.useRef(state);\n React.useEffect(() => {\n stateRef.current = state;\n }, [state]);\n\n // To match the behavior of the setter returned by React.useState, this callback's identity\n // should never change. This means it MUST NOT directly reference variables that can change.\n const setState = React.useCallback((newState: React.SetStateAction<State>) => {\n // React dispatch can use a factory\n // https://reactjs.org/docs/hooks-reference.html#functional-updates\n if (isFactoryDispatch(newState)) {\n stateRef.current = newState(stateRef.current);\n } else {\n stateRef.current = newState;\n }\n\n setInternalState(stateRef.current);\n }, []);\n\n return [state, setState];\n};\n\n/**\n * Helper hook to handle previous comparison of controlled/uncontrolled\n * Prints an error when isControlled value switches between subsequent renders\n * @returns - whether the value is controlled\n */\nconst useIsControlled = (controlledValue: unknown) => {\n const isControlled = useConst<boolean>(controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"],"sourceRoot":"../src/"}
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useEventCallback = void 0;
7
7
 
8
- var React = /*#__PURE__*/require("react");
8
+ const React = /*#__PURE__*/require("react");
9
9
 
10
- var useIsomorphicLayoutEffect_1 = /*#__PURE__*/require("./useIsomorphicLayoutEffect");
10
+ const useIsomorphicLayoutEffect_1 = /*#__PURE__*/require("./useIsomorphicLayoutEffect");
11
11
  /**
12
12
  * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback
13
13
  *
@@ -22,22 +22,16 @@ var useIsomorphicLayoutEffect_1 = /*#__PURE__*/require("./useIsomorphicLayoutEff
22
22
  */
23
23
 
24
24
 
25
- var useEventCallback = function (fn) {
26
- var callbackRef = React.useRef(function () {
25
+ const useEventCallback = fn => {
26
+ const callbackRef = React.useRef(() => {
27
27
  throw new Error('Cannot call an event handler while rendering');
28
28
  });
29
- useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(function () {
29
+ useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(() => {
30
30
  callbackRef.current = fn;
31
31
  }, [fn]);
32
- return React.useCallback(function () {
33
- var args = [];
34
-
35
- for (var _i = 0; _i < arguments.length; _i++) {
36
- args[_i] = arguments[_i];
37
- }
38
-
39
- var callback = callbackRef.current;
40
- return callback.apply(void 0, args);
32
+ return React.useCallback((...args) => {
33
+ const callback = callbackRef.current;
34
+ return callback(...args);
41
35
  }, [callbackRef]);
42
36
  };
43
37
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useEventCallback.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,IAAA,2BAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;AAEA;;;;;;;;;;;AAWG;;;AACI,IAAM,gBAAgB,GAAG,UAAiC,EAAjC,EAA8D;AAC5F,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,YAAA;AAC1C,UAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;AACD,GAFmB,CAApB;AAIA,EAAA,2BAAA,CAAA,yBAAA,CAA0B,YAAA;AACxB,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFD,EAEG,CAAC,EAAD,CAFH;AAIA,SAAO,KAAK,CAAC,WAAN,CACL,YAAA;AAAC,QAAA,IAAA,GAAA,EAAA;;SAAA,IAAA,EAAA,GAAA,C,EAAA,EAAA,GAAA,SAAA,CAAA,M,EAAA,EAAA,E,EAAa;AAAb,MAAA,IAAA,CAAA,EAAA,CAAA,GAAA,SAAA,CAAA,EAAA,CAAA;;;AACC,QAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;AACA,WAAO,QAAQ,CAAA,KAAR,CAAQ,KAAA,CAAR,EAAY,IAAZ,CAAP;AACD,GAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourceRoot":""}
1
+ {"version":3,"sources":["hooks/useEventCallback.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,2BAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;AAEA;;;;;;;;;;;AAWG;;;AACI,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;AAChG,QAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;AAC/C,UAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;AACD,GAFmB,CAApB;AAIA,EAAA,2BAAA,CAAA,yBAAA,CAA0B,MAAK;AAC7B,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFD,EAEG,CAAC,EAAD,CAFH;AAIA,SAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;AAChB,UAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;AACA,WAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;AACD,GAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM;;AAAM,OAAA,CAAA,gBAAA,GAAgB,gBAAhB","sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * https://reactjs.org/docs/hooks-faq.html#how-to-read-an-often-changing-value-from-usecallback\n *\n * Modified `useCallback` that can be used when dependencies change too frequently. Can occur when\n * e.g. user props are dependencies which could change on every render\n * e.g. volatile values (i.e. useState/useDispatch) are dependencies which could change frequently\n *\n * This should not be used often, but can be a useful re-render optimization since the callback is a ref and\n * will not be invalidated between re-renders\n *\n * @param fn - The callback function that will be used\n */\nexport const useEventCallback = <Args extends unknown[], Return>(fn: (...args: Args) => Return) => {\n const callbackRef = React.useRef<typeof fn>(() => {\n throw new Error('Cannot call an event handler while rendering');\n });\n\n useIsomorphicLayoutEffect(() => {\n callbackRef.current = fn;\n }, [fn]);\n\n return React.useCallback(\n (...args: Args) => {\n const callback = callbackRef.current;\n return callback(...args);\n },\n [callbackRef],\n );\n};\n"],"sourceRoot":"../src/"}
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useFirstMount = void 0;
7
7
 
8
- var React = /*#__PURE__*/require("react");
8
+ const React = /*#__PURE__*/require("react");
9
9
  /**
10
10
  * Checks if components was mounted the first time.
11
11
  * Since concurrent mode will be released in the future this needs to be verified
@@ -19,7 +19,7 @@ var React = /*#__PURE__*/require("react");
19
19
 
20
20
 
21
21
  function useFirstMount() {
22
- var isFirst = React.useRef(true);
22
+ const isFirst = React.useRef(true);
23
23
 
24
24
  if (isFirst.current) {
25
25
  isFirst.current = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useFirstMount.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;AASG;;;AACH,SAAgB,aAAhB,GAA6B;AAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;AAEA,MAAI,OAAO,CAAC,OAAZ,EAAqB;AACnB,IAAA,OAAO,CAAC,OAAR,GAAkB,KAAlB;AACA,WAAO,IAAP;AACD;;AAED,SAAO,OAAO,CAAC,OAAf;AACD;;AATD,OAAA,CAAA,aAAA,GAAA,aAAA","sourceRoot":""}
1
+ {"version":3,"sources":["hooks/useFirstMount.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;;;;;;;;AASG;;;AACH,SAAgB,aAAhB,GAA6B;AAC3B,QAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;AAEA,MAAI,OAAO,CAAC,OAAZ,EAAqB;AACnB,IAAA,OAAO,CAAC,OAAR,GAAkB,KAAlB;AACA,WAAO,IAAP;AACD;;AAED,SAAO,OAAO,CAAC,OAAf;AACD;;AATD,OAAA,CAAA,aAAA,GAAA,aAAA","sourcesContent":["import * as React from 'react';\n\n/**\n * Checks if components was mounted the first time.\n * Since concurrent mode will be released in the future this needs to be verified\n * Currently (React 17) will always render the initial mount once\n * https://codesandbox.io/s/heuristic-brook-s4w0q?file=/src/App.jsx\n * https://codesandbox.io/s/holy-grass-8nieu?file=/src/App.jsx\n *\n * @example\n * const isFirstMount = useFirstMount();\n */\nexport function useFirstMount(): boolean {\n const isFirst = React.useRef(true);\n\n if (isFirst.current) {\n isFirst.current = false;\n return true;\n }\n\n return isFirst.current;\n}\n"],"sourceRoot":"../src/"}
@@ -5,16 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useForceUpdate = void 0;
7
7
 
8
- var react_1 = /*#__PURE__*/require("react");
8
+ const react_1 = /*#__PURE__*/require("react");
9
9
  /**
10
10
  * Forces a re-render, similar to `forceUpdate` in class components.
11
11
  */
12
12
 
13
13
 
14
14
  function useForceUpdate() {
15
- return react_1.useReducer(function (x) {
16
- return x + 1;
17
- }, 0)[1];
15
+ return react_1.useReducer(x => x + 1, 0)[1];
18
16
  }
19
17
 
20
18
  exports.useForceUpdate = useForceUpdate;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useForceUpdate.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;AAEG;;;AACH,SAAgB,cAAhB,GAA8B;AAC5B,SAAO,OAAA,CAAA,UAAA,CAAW,UAAA,CAAA,EAAC;AAAI,WAAA,CAAC,GAAD,CAAA;AAAK,GAArB,EAAuB,CAAvB,EAA0B,CAA1B,CAAP;AACD;;AAFD,OAAA,CAAA,cAAA,GAAA,cAAA","sourceRoot":""}
1
+ {"version":3,"sources":["hooks/useForceUpdate.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,OAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;AAEA;;AAEG;;;AACH,SAAgB,cAAhB,GAA8B;AAC5B,SAAO,OAAA,CAAA,UAAA,CAAW,CAAC,IAAI,CAAC,GAAG,CAApB,EAAuB,CAAvB,EAA0B,CAA1B,CAAP;AACD;;AAFD,OAAA,CAAA,cAAA,GAAA,cAAA","sourcesContent":["import { useReducer } from 'react';\n\n/**\n * Forces a re-render, similar to `forceUpdate` in class components.\n */\nexport function useForceUpdate() {\n return useReducer(x => x + 1, 0)[1];\n}\n"],"sourceRoot":"../src/"}