@fluentui/react-utilities 9.0.0-nightly.46b9ea7036.0 → 9.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/CHANGELOG.json +163 -10
  2. package/CHANGELOG.md +44 -7
  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/ssr/SSRContext.js +9 -15
  53. package/lib/ssr/SSRContext.js.map +1 -1
  54. package/lib/utils/applyTriggerPropsToChildren.d.ts +1 -1
  55. package/lib/utils/applyTriggerPropsToChildren.js +24 -4
  56. package/lib/utils/applyTriggerPropsToChildren.js.map +1 -1
  57. package/lib/utils/clamp.js +1 -3
  58. package/lib/utils/clamp.js.map +1 -1
  59. package/lib/utils/getNativeElementProps.d.ts +22 -0
  60. package/lib/utils/getNativeElementProps.js +24 -2
  61. package/lib/utils/getNativeElementProps.js.map +1 -1
  62. package/lib/utils/getRTLSafeKey.js +1 -1
  63. package/lib/utils/getRTLSafeKey.js.map +1 -1
  64. package/lib/utils/getReactCallbackName.d.ts +25 -0
  65. package/lib/utils/getReactCallbackName.js +26 -0
  66. package/lib/utils/getReactCallbackName.js.map +1 -0
  67. package/lib/utils/getTriggerChild.d.ts +22 -0
  68. package/lib/utils/getTriggerChild.js +26 -0
  69. package/lib/utils/getTriggerChild.js.map +1 -0
  70. package/lib/utils/index.d.ts +2 -1
  71. package/lib/utils/index.js +2 -1
  72. package/lib/utils/index.js.map +1 -1
  73. package/lib/utils/isFluentTrigger.d.ts +22 -0
  74. package/lib/utils/isFluentTrigger.js +8 -0
  75. package/lib/utils/isFluentTrigger.js.map +1 -0
  76. package/lib/utils/omit.js +2 -2
  77. package/lib/utils/omit.js.map +1 -1
  78. package/lib/utils/properties.js +55 -44
  79. package/lib/utils/properties.js.map +1 -1
  80. package/lib/utils/shouldPreventDefaultOnKeyDown.js +4 -4
  81. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  82. package/lib-commonjs/compose/getSlots.d.ts +11 -10
  83. package/lib-commonjs/compose/getSlots.js +23 -34
  84. package/lib-commonjs/compose/getSlots.js.map +1 -1
  85. package/lib-commonjs/compose/index.d.ts +0 -1
  86. package/lib-commonjs/compose/index.js +1 -3
  87. package/lib-commonjs/compose/index.js.map +1 -1
  88. package/lib-commonjs/compose/resolveShorthand.d.ts +10 -6
  89. package/lib-commonjs/compose/resolveShorthand.js +14 -14
  90. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  91. package/lib-commonjs/compose/types.d.ts +86 -35
  92. package/lib-commonjs/compose/types.js.map +1 -1
  93. package/lib-commonjs/hooks/index.d.ts +1 -1
  94. package/lib-commonjs/hooks/index.js +3 -3
  95. package/lib-commonjs/hooks/index.js.map +1 -1
  96. package/lib-commonjs/hooks/useBoolean.js +12 -23
  97. package/lib-commonjs/hooks/useBoolean.js.map +1 -1
  98. package/lib-commonjs/hooks/useConst.js +2 -2
  99. package/lib-commonjs/hooks/useConst.js.map +1 -1
  100. package/lib-commonjs/hooks/useControllableState.d.ts +16 -6
  101. package/lib-commonjs/hooks/useControllableState.js +28 -27
  102. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  103. package/lib-commonjs/hooks/useEventCallback.js +8 -14
  104. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  105. package/lib-commonjs/hooks/useFirstMount.js +2 -2
  106. package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
  107. package/lib-commonjs/hooks/useForceUpdate.js +2 -4
  108. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
  109. package/lib-commonjs/hooks/useId.js +4 -6
  110. package/lib-commonjs/hooks/useId.js.map +1 -1
  111. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js +2 -2
  112. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  113. package/lib-commonjs/hooks/useMergedEventCallbacks.d.ts +18 -0
  114. package/lib-commonjs/hooks/useMergedEventCallbacks.js +36 -0
  115. package/lib-commonjs/hooks/useMergedEventCallbacks.js.map +1 -0
  116. package/lib-commonjs/hooks/useMergedRefs.js +6 -15
  117. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  118. package/lib-commonjs/hooks/useMount.js +4 -4
  119. package/lib-commonjs/hooks/useMount.js.map +1 -1
  120. package/lib-commonjs/hooks/useOnClickOutside.js +32 -38
  121. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  122. package/lib-commonjs/hooks/useOnScrollOutside.js +15 -17
  123. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  124. package/lib-commonjs/hooks/usePrevious.js +4 -4
  125. package/lib-commonjs/hooks/usePrevious.js.map +1 -1
  126. package/lib-commonjs/hooks/useTimeout.js +15 -19
  127. package/lib-commonjs/hooks/useTimeout.js.map +1 -1
  128. package/lib-commonjs/hooks/useUnmount.js +6 -8
  129. package/lib-commonjs/hooks/useUnmount.js.map +1 -1
  130. package/lib-commonjs/index.js +1 -1
  131. package/lib-commonjs/ssr/SSRContext.js +9 -15
  132. package/lib-commonjs/ssr/SSRContext.js.map +1 -1
  133. package/lib-commonjs/ssr/index.js +1 -1
  134. package/lib-commonjs/utils/applyTriggerPropsToChildren.d.ts +1 -1
  135. package/lib-commonjs/utils/applyTriggerPropsToChildren.js +26 -6
  136. package/lib-commonjs/utils/applyTriggerPropsToChildren.js.map +1 -1
  137. package/lib-commonjs/utils/clamp.js +1 -3
  138. package/lib-commonjs/utils/clamp.js.map +1 -1
  139. package/lib-commonjs/utils/getNativeElementProps.d.ts +22 -0
  140. package/lib-commonjs/utils/getNativeElementProps.js +28 -4
  141. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  142. package/lib-commonjs/utils/getRTLSafeKey.js +1 -1
  143. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
  144. package/lib-commonjs/utils/getReactCallbackName.d.ts +25 -0
  145. package/lib-commonjs/utils/getReactCallbackName.js +35 -0
  146. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -0
  147. package/lib-commonjs/utils/getTriggerChild.d.ts +22 -0
  148. package/lib-commonjs/utils/getTriggerChild.js +37 -0
  149. package/lib-commonjs/utils/getTriggerChild.js.map +1 -0
  150. package/lib-commonjs/utils/index.d.ts +2 -1
  151. package/lib-commonjs/utils/index.js +5 -3
  152. package/lib-commonjs/utils/index.js.map +1 -1
  153. package/lib-commonjs/utils/isFluentTrigger.d.ts +22 -0
  154. package/lib-commonjs/utils/isFluentTrigger.js +17 -0
  155. package/lib-commonjs/utils/isFluentTrigger.js.map +1 -0
  156. package/lib-commonjs/utils/omit.js +2 -2
  157. package/lib-commonjs/utils/omit.js.map +1 -1
  158. package/lib-commonjs/utils/properties.js +51 -40
  159. package/lib-commonjs/utils/properties.js.map +1 -1
  160. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +5 -5
  161. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +1 -1
  162. package/package.json +6 -11
  163. package/lib/compose/nullRender.d.ts +0 -4
  164. package/lib/compose/nullRender.js +0 -7
  165. package/lib/compose/nullRender.js.map +0 -1
  166. package/lib/hooks/useControllableValue.d.ts +0 -20
  167. package/lib/hooks/useControllableValue.js +0 -62
  168. package/lib/hooks/useControllableValue.js.map +0 -1
  169. package/lib/utils/onlyChild.d.ts +0 -5
  170. package/lib/utils/onlyChild.js +0 -13
  171. package/lib/utils/onlyChild.js.map +0 -1
  172. package/lib-commonjs/compose/nullRender.d.ts +0 -4
  173. package/lib-commonjs/compose/nullRender.js +0 -16
  174. package/lib-commonjs/compose/nullRender.js.map +0 -1
  175. package/lib-commonjs/hooks/useControllableValue.d.ts +0 -20
  176. package/lib-commonjs/hooks/useControllableValue.js +0 -73
  177. package/lib-commonjs/hooks/useControllableValue.js.map +0 -1
  178. package/lib-commonjs/utils/onlyChild.d.ts +0 -5
  179. package/lib-commonjs/utils/onlyChild.js +0 -23
  180. package/lib-commonjs/utils/onlyChild.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC"}
@@ -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;
@@ -1,23 +1,22 @@
1
- import { __assign } from "tslib";
2
1
  import { isValidElement } from 'react';
3
2
  /**
4
- * Resolves ShorthandProps into ObjectShorthandProps, to ensure normalization of the signature
3
+ * Resolves shorthands into slot props, to ensure normalization of the signature
5
4
  * being passed down to getSlots method
6
- * @param value - the base ShorthandProps
7
- * @param options - options to resolve ShorthandProps
5
+ * @param value - the base shorthand props
6
+ * @param options - options to resolve shorthand props
8
7
  */
9
8
 
10
- export function resolveShorthand(value, options) {
11
- var _a = options || {},
12
- _b = _a.required,
13
- required = _b === void 0 ? false : _b,
14
- defaultProps = _a.defaultProps;
9
+ export const resolveShorthand = (value, options) => {
10
+ const {
11
+ required = false,
12
+ defaultProps
13
+ } = options || {};
15
14
 
16
15
  if (value === null || value === undefined && !required) {
17
16
  return undefined;
18
17
  }
19
18
 
20
- var resolvedShorthand = {};
19
+ let resolvedShorthand = {};
21
20
 
22
21
  if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || /*#__PURE__*/isValidElement(value)) {
23
22
  resolvedShorthand.children = value;
@@ -25,6 +24,8 @@ export function resolveShorthand(value, options) {
25
24
  resolvedShorthand = value;
26
25
  }
27
26
 
28
- return defaultProps ? __assign(__assign({}, defaultProps), resolvedShorthand) : resolvedShorthand;
29
- }
27
+ return defaultProps ? { ...defaultProps,
28
+ ...resolvedShorthand
29
+ } : resolvedShorthand;
30
+ };
30
31
  //# sourceMappingURL=resolveShorthand.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compose/resolveShorthand.ts"],"names":[],"mappings":";AAAA,SAAS,cAAT,QAA+B,OAA/B;AASA;;;;;AA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AxB;;AAEA,MAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,iBAAkF,cAAc,CAAC,KAAD,CAApG,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","sourceRoot":""}
@@ -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":"WA2IA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/compose/types.ts"],"names":[],"mappings":"WAqNA;AACA;AACA;AACA;AACA","sourceRoot":""}
@@ -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';
@@ -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';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
@@ -9,31 +9,20 @@ import { useConst } from './useConst';
9
9
  */
10
10
 
11
11
  export function useBoolean(initialState) {
12
- var _a = React.useState(initialState),
13
- value = _a[0],
14
- setValue = _a[1];
15
-
16
- var setTrue = useConst(function () {
17
- return function () {
18
- setValue(true);
19
- };
12
+ const [value, setValue] = React.useState(initialState);
13
+ const setTrue = useConst(() => () => {
14
+ setValue(true);
20
15
  });
21
- var setFalse = useConst(function () {
22
- return function () {
23
- setValue(false);
24
- };
16
+ const setFalse = useConst(() => () => {
17
+ setValue(false);
25
18
  });
26
- var toggle = useConst(function () {
27
- return function () {
28
- setValue(function (currentValue) {
29
- return !currentValue;
30
- });
31
- };
19
+ const toggle = useConst(() => () => {
20
+ setValue(currentValue => !currentValue);
32
21
  });
33
22
  return [value, {
34
- setTrue: setTrue,
35
- setFalse: setFalse,
36
- toggle: toggle
23
+ setTrue,
24
+ setFalse,
25
+ toggle
37
26
  }];
38
27
  }
39
28
  //# sourceMappingURL=useBoolean.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;AAYA;;;;;;AAMG;;AACH,OAAM,SAAU,UAAV,CAAqB,YAArB,EAA0C;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,QAAQ,CAAC,YAAA;AAAM,WAAA,YAAA;AAC7B,MAAA,QAAQ,CAAC,IAAD,CAAR;AAD6B,KAAA;AAE9B,GAFuB,CAAxB;AAGA,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAA;AAAM,WAAA,YAAA;AAC9B,MAAA,QAAQ,CAAC,KAAD,CAAR;AAD8B,KAAA;AAE/B,GAFwB,CAAzB;AAGA,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAA;AAAM,WAAA,YAAA;AAC5B,MAAA,QAAQ,CAAC,UAAA,YAAA,EAAY;AAAI,eAAA,CAAA,YAAA;AAAa,OAA9B,CAAR;AAD4B,KAAA;AAE7B,GAFsB,CAAvB;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAO,EAAA,OAAT;AAAW,IAAA,QAAQ,EAAA,QAAnB;AAAqB,IAAA,MAAM,EAAA;AAA3B,GAAR,CAAP;AACD","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useBoolean.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;AAYA;;;;;;AAMG;;AACH,OAAM,SAAU,UAAV,CAAqB,YAArB,EAA0C;AAC9C,QAAM,CAAC,KAAD,EAAQ,QAAR,IAAoB,KAAK,CAAC,QAAN,CAAe,YAAf,CAA1B;AAEA,QAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,MAAK;AAClC,IAAA,QAAQ,CAAC,IAAD,CAAR;AACD,GAFuB,CAAxB;AAGA,QAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,MAAK;AACnC,IAAA,QAAQ,CAAC,KAAD,CAAR;AACD,GAFwB,CAAzB;AAGA,QAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,MAAK;AACjC,IAAA,QAAQ,CAAC,YAAY,IAAI,CAAC,YAAlB,CAAR;AACD,GAFsB,CAAvB;AAIA,SAAO,CAAC,KAAD,EAAQ;AAAE,IAAA,OAAF;AAAW,IAAA,QAAX;AAAqB,IAAA;AAArB,GAAR,CAAP;AACD","sourceRoot":""}
@@ -15,7 +15,7 @@ export function useConst(initialValue) {
15
15
  // Use useRef to store the value because it's the least expensive built-in hook that works here
16
16
  // (we could also use `const [value] = React.useState(initialValue)` but that's more expensive
17
17
  // internally due to reducer handling which we don't need)
18
- var ref = React.useRef();
18
+ const ref = React.useRef();
19
19
 
20
20
  if (ref.current === undefined) {
21
21
  // 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,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;;AAUG;;AACH,OAAM,SAAU,QAAV,CAAsB,YAAtB,EAAiD;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","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useConst.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;;AAUG;;AACH,OAAM,SAAU,QAAV,CAAsB,YAAtB,EAAiD;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","sourceRoot":""}
@@ -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>>];
@@ -1,36 +1,37 @@
1
1
  import * as React from 'react';
2
2
  import { useConst } from './useConst';
3
3
 
4
- function isUndefined(state) {
5
- return typeof state === 'undefined';
6
- }
7
-
8
4
  function isFactoryDispatch(newState) {
9
5
  return typeof newState === 'function';
10
6
  }
11
7
  /**
12
- * A useState 'like' hook that allows optional user control
13
- * Useful for components which allow uncontrolled and controlled behaviour for users
14
- * @returns - https://reactjs.org/docs/hooks-state.html
8
+ * A `useState`-like hook to manage a value that could be either controlled or uncontrolled,
9
+ * such as a checked state or text input string.
10
+ *
11
+ * Unlike `setState`, it's okay to call the returned updater (dispatch) function for either a
12
+ * controlled or uncontrolled component. Calls will only be respected if the component is uncontrolled.
13
+ *
14
+ * @returns Same as [`useState`](https://reactjs.org/docs/hooks-reference.html#usestate): an array
15
+ * of the current value and an updater (dispatch) function. The updater function is referentially
16
+ * stable (won't change during the component's lifecycle). It can take either a new value, or a
17
+ * function which is passed the previous value and returns the new value. Unlike `setState`, calls
18
+ * to the updater function will only be respected if the component is uncontrolled.
19
+ * @see https://reactjs.org/docs/uncontrolled-components.html
15
20
  */
16
21
 
17
22
 
18
- export var useControllableState = function (options) {
19
- var isControlled = useIsControlled(options.state);
20
- var initialState = isUndefined(options.defaultState) ? options.initialState : options.defaultState;
21
-
22
- var _a = React.useState(initialState),
23
- internalState = _a[0],
24
- setInternalState = _a[1];
25
-
26
- var state = isControlled ? options.state : internalState;
27
- var stateRef = React.useRef(state);
28
- React.useEffect(function () {
23
+ export const useControllableState = options => {
24
+ const isControlled = useIsControlled(options.state);
25
+ const initialState = typeof options.defaultState === 'undefined' ? options.initialState : options.defaultState;
26
+ const [internalState, setInternalState] = React.useState(initialState);
27
+ const state = isControlled ? options.state : internalState;
28
+ const stateRef = React.useRef(state);
29
+ React.useEffect(() => {
29
30
  stateRef.current = state;
30
31
  }, [state]); // To match the behavior of the setter returned by React.useState, this callback's identity
31
32
  // should never change. This means it MUST NOT directly reference variables that can change.
32
33
 
33
- var setState = React.useCallback(function (newState) {
34
+ const setState = React.useCallback(newState => {
34
35
  // React dispatch can use a factory
35
36
  // https://reactjs.org/docs/hooks-reference.html#functional-updates
36
37
  if (isFactoryDispatch(newState)) {
@@ -49,17 +50,17 @@ export var useControllableState = function (options) {
49
50
  * @returns - whether the value is controlled
50
51
  */
51
52
 
52
- var useIsControlled = function (controlledValue) {
53
- var isControlled = useConst(controlledValue !== undefined);
53
+ const useIsControlled = controlledValue => {
54
+ const isControlled = useConst(controlledValue !== undefined);
54
55
 
55
56
  if (process.env.NODE_ENV !== 'production') {
56
57
  // We don't want these warnings in production even though it is against native behaviour
57
58
  // eslint-disable-next-line react-hooks/rules-of-hooks
58
- React.useEffect(function () {
59
+ React.useEffect(() => {
59
60
  if (isControlled !== (controlledValue !== undefined)) {
60
- var error = new Error();
61
- var controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
62
- var undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
61
+ const error = new Error();
62
+ const controlWarning = isControlled ? 'a controlled value to be uncontrolled' : 'an uncontrolled value to be controlled';
63
+ const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined'; // eslint-disable-next-line no-console
63
64
 
64
65
  console.error([// Default react error
65
66
  'A component is changing ' + controlWarning + '. This is likely caused by the value', 'changing from ' + undefinedWarning + ' value, which should not happen.', 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.', 'More info: https://reactjs.org/link/controlled-components', error.stack].join(' '));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,YAAzB;;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;;;AACH,OAAO,IAAM,oBAAoB,GAAG,UAClC,OADkC,EACS;AAE3C,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;AACA,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,CAAC,YAAT,CAAX,GAAoC,OAAO,CAAC,YAA5C,GAA2D,OAAO,CAAC,YAAxF;;AACM,MAAA,EAAA,GAAoC,KAAK,CAAC,QAAN,CAAsB,YAAtB,CAApC;AAAA,MAAC,aAAa,GAAA,EAAA,CAAA,CAAA,CAAd;AAAA,MAAgB,gBAAgB,G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B,QAAQ,CAAC,QAAQ,CAAC,OAAV,CAA3B;AACD,KAFD,MAEO;AACL,MAAA,QAAQ,CAAC,OAAT,GAAmB,QAAnB;AACD;;AAED,IAAA,gBAAgB,CAAC,QAAQ,CAAC,OAAV,CAAhB;AACD,GAVgB,EAUd,EAVc,CAAjB;AAYA,SAAO,CAAC,KAAD,EAAQ,QAAR,CAAP;AACD,CA7BM;AA+BP;;;;AAIG;;AACH,MAAM,eAAe,GAAI,eAAD,IAA6B;AACnD,QAAM,YAAY,GAAG,QAAQ,CAAU,eAAe,KAAK,SAA9B,CAA7B;;AAEA,MAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;AACA;AACA,IAAA,KAAK,CAAC,SAAN,CAAgB,MAAK;AACnB,UAAI,YAAY,MAAM,eAAe,KAAK,SAA1B,CAAhB,EAAsD;AACpD,cAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;AAEA,cAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;AAIA,cAAM,gBAAgB,GAAG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;AACA,QAAA,OAAO,CAAC,KAAR,CACE,CACE;AACA,qCAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;AAUD;AACF,KAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;AAuBD;;AAED,SAAO,YAAP;AACD,CAhCD","sourceRoot":""}
@@ -13,22 +13,16 @@ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
13
13
  * @param fn - The callback function that will be used
14
14
  */
15
15
 
16
- export var useEventCallback = function (fn) {
17
- var callbackRef = React.useRef(function () {
16
+ export const useEventCallback = fn => {
17
+ const callbackRef = React.useRef(() => {
18
18
  throw new Error('Cannot call an event handler while rendering');
19
19
  });
20
- useIsomorphicLayoutEffect(function () {
20
+ useIsomorphicLayoutEffect(() => {
21
21
  callbackRef.current = fn;
22
22
  }, [fn]);
23
- return React.useCallback(function () {
24
- var args = [];
25
-
26
- for (var _i = 0; _i < arguments.length; _i++) {
27
- args[_i] = arguments[_i];
28
- }
29
-
30
- var callback = callbackRef.current;
31
- return callback.apply(void 0, args);
23
+ return React.useCallback((...args) => {
24
+ const callback = callbackRef.current;
25
+ return callback(...args);
32
26
  }, [callbackRef]);
33
27
  };
34
28
  //# sourceMappingURL=useEventCallback.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;;;;;;;;;;AAWG;;AACH,OAAO,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,yBAAyB,CAAC,YAAA;AACxB,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFwB,EAEtB,CAAC,EAAD,CAFsB,CAAzB;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","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;;;;;;;;;;AAWG;;AACH,OAAO,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,yBAAyB,CAAC,MAAK;AAC7B,IAAA,WAAW,CAAC,OAAZ,GAAsB,EAAtB;AACD,GAFwB,EAEtB,CAAC,EAAD,CAFsB,CAAzB;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","sourceRoot":""}
@@ -11,7 +11,7 @@ import * as React from 'react';
11
11
  */
12
12
 
13
13
  export function useFirstMount() {
14
- var isFirst = React.useRef(true);
14
+ const isFirst = React.useRef(true);
15
15
 
16
16
  if (isFirst.current) {
17
17
  isFirst.current = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useFirstMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;AASG;;AACH,OAAM,SAAU,aAAV,GAAuB;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","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useFirstMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;AASG;;AACH,OAAM,SAAU,aAAV,GAAuB;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","sourceRoot":""}
@@ -4,8 +4,6 @@ import { useReducer } from 'react';
4
4
  */
5
5
 
6
6
  export function useForceUpdate() {
7
- return useReducer(function (x) {
8
- return x + 1;
9
- }, 0)[1];
7
+ return useReducer(x => x + 1, 0)[1];
10
8
  }
11
9
  //# sourceMappingURL=useForceUpdate.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useForceUpdate.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,OAA3B;AAEA;;AAEG;;AACH,OAAM,SAAU,cAAV,GAAwB;AAC5B,SAAO,UAAU,CAAC,UAAA,CAAA,EAAC;AAAI,WAAA,CAAC,GAAD,CAAA;AAAK,GAAX,EAAa,CAAb,CAAV,CAA0B,CAA1B,CAAP;AACD","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useForceUpdate.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,OAA3B;AAEA;;AAEG;;AACH,OAAM,SAAU,cAAV,GAAwB;AAC5B,SAAO,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAV,EAAa,CAAb,CAAV,CAA0B,CAA1B,CAAP;AACD","sourceRoot":""}
@@ -19,9 +19,7 @@ export function resetIdsForTests() {
19
19
  */
20
20
 
21
21
  export function useId(prefix, providedId) {
22
- var contextValue = useSSRContext();
23
- return React.useMemo(function () {
24
- return providedId || "" + prefix + ++contextValue.current;
25
- }, [prefix, providedId, contextValue]);
22
+ const contextValue = useSSRContext();
23
+ return React.useMemo(() => providedId || `${prefix}${++contextValue.current}`, [prefix, providedId, contextValue]);
26
24
  }
27
25
  //# sourceMappingURL=useId.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,sBAAT,EAAiC,aAAjC,QAAsD,cAAtD;AAEA;;;;AAIG;;AACH,OAAM,SAAU,gBAAV,GAA0B;AAC9B,EAAA,sBAAsB,CAAC,OAAvB,GAAiC,CAAjC;AACD;AAED;;;;;;;AAOG;;AACH,OAAM,SAAU,KAAV,CAAgB,MAAhB,EAAiC,UAAjC,EAAoD;AACxD,MAAM,YAAY,GAAG,aAAa,EAAlC;AAEA,SAAO,KAAK,CAAC,OAAN,CAAc,YAAA;AAAM,WAAA,UAAU,IAAI,KAAG,MAAH,GAAY,EAAE,YAAY,CAAxC,OAAA;AAAkD,GAAtE,EAAwE,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CAAxE,CAAP;AACD","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,sBAAT,EAAiC,aAAjC,QAAsD,cAAtD;AAEA;;;;AAIG;;AACH,OAAM,SAAU,gBAAV,GAA0B;AAC9B,EAAA,sBAAsB,CAAC,OAAvB,GAAiC,CAAjC;AACD;AAED;;;;;;;AAOG;;AACH,OAAM,SAAU,KAAV,CAAgB,MAAhB,EAAiC,UAAjC,EAAoD;AACxD,QAAM,YAAY,GAAG,aAAa,EAAlC;AAEA,SAAO,KAAK,CAAC,OAAN,CAAc,MAAM,UAAU,IAAI,GAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAO,EAApE,EAAwE,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CAAxE,CAAP;AACD","sourceRoot":""}
@@ -11,5 +11,5 @@ import { canUseDOM } from '../ssr/index';
11
11
  */
12
12
  // eslint-disable-next-line no-restricted-properties
13
13
 
14
- export var useIsomorphicLayoutEffect = /*#__PURE__*/canUseDOM() ? React.useLayoutEffect : React.useEffect;
14
+ export const useIsomorphicLayoutEffect = /*#__PURE__*/canUseDOM() ? React.useLayoutEffect : React.useEffect;
15
15
  //# sourceMappingURL=useIsomorphicLayoutEffect.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,cAA1B;AAEA;;;;;;;;AAQG;AACH;;AACA,OAAO,IAAM,yBAAyB,GAA2B,aAAA,SAAS,KAAK,KAAK,CAAC,eAAX,GAA6B,KAAK,CAAC,SAAtG","sourceRoot":""}
1
+ {"version":3,"sources":["../../src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,cAA1B;AAEA;;;;;;;;AAQG;AACH;;AACA,OAAO,MAAM,yBAAyB,GAA2B,aAAA,SAAS,KAAK,KAAK,CAAC,eAAX,GAA6B,KAAK,CAAC,SAAtG","sourceRoot":""}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Combine two event callbacks into a single callback function that calls each one in order.
3
+ *
4
+ * This is useful to add an event listener to an existing element without overwriting the current listener, if any.
5
+ *
6
+ * For example:
7
+ * ```ts
8
+ * state.slot.onChange = useMergedCallbacks(state.slot.onChange, ev => {
9
+ * // Handle onChange
10
+ * });
11
+ * ```
12
+ *
13
+ * @param callback1 - The first callback to be called
14
+ * @param callback2 - The second callback to be called
15
+ *
16
+ * @returns An event callback that calls the callbacks in order, and is stable between renders
17
+ */
18
+ export declare function useMergedEventCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;