@fluentui/react-utilities 9.5.3 → 9.6.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 (95) hide show
  1. package/CHANGELOG.json +53 -1
  2. package/CHANGELOG.md +25 -2
  3. package/dist/index.d.ts +57 -10
  4. package/lib/compose/getSlots.js.map +1 -1
  5. package/lib/compose/isResolvedShorthand.js.map +1 -1
  6. package/lib/compose/resolveShorthand.js.map +1 -1
  7. package/lib/compose/types.js.map +1 -1
  8. package/lib/events/index.js +2 -0
  9. package/lib/events/index.js.map +1 -0
  10. package/lib/events/mouseTouchHelpers.js +38 -0
  11. package/lib/events/mouseTouchHelpers.js.map +1 -0
  12. package/lib/hooks/useControllableState.js.map +1 -1
  13. package/lib/hooks/useEventCallback.js.map +1 -1
  14. package/lib/hooks/useFirstMount.js.map +1 -1
  15. package/lib/hooks/useForceUpdate.js.map +1 -1
  16. package/lib/hooks/useId.js.map +1 -1
  17. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  18. package/lib/hooks/useMergedRefs.js.map +1 -1
  19. package/lib/hooks/useOnClickOutside.js +20 -14
  20. package/lib/hooks/useOnClickOutside.js.map +1 -1
  21. package/lib/hooks/useOnScrollOutside.js.map +1 -1
  22. package/lib/hooks/usePrevious.js.map +1 -1
  23. package/lib/hooks/useScrollbarWidth.js.map +1 -1
  24. package/lib/hooks/useTimeout.js.map +1 -1
  25. package/lib/index.js +2 -1
  26. package/lib/index.js.map +1 -1
  27. package/lib/ssr/SSRContext.js.map +1 -1
  28. package/lib/ssr/canUseDOM.js.map +1 -1
  29. package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
  30. package/lib/trigger/getTriggerChild.js.map +1 -1
  31. package/lib/trigger/isFluentTrigger.js.map +1 -1
  32. package/lib/utils/getNativeElementProps.js.map +1 -1
  33. package/lib/utils/getRTLSafeKey.js.map +1 -1
  34. package/lib/utils/getReactCallbackName.js.map +1 -1
  35. package/lib/utils/isHTMLElement.js.map +1 -1
  36. package/lib/utils/isInteractiveHTMLElement.js.map +1 -1
  37. package/lib/utils/mergeCallbacks.js.map +1 -1
  38. package/lib/utils/omit.js.map +1 -1
  39. package/lib/utils/properties.js.map +1 -1
  40. package/lib-amd/compose/getSlots.js.map +1 -1
  41. package/lib-amd/compose/types.js.map +1 -1
  42. package/lib-amd/events/index.js +6 -0
  43. package/lib-amd/events/index.js.map +1 -0
  44. package/lib-amd/events/mouseTouchHelpers.js +39 -0
  45. package/lib-amd/events/mouseTouchHelpers.js.map +1 -0
  46. package/lib-amd/hooks/useMergedRefs.js.map +1 -1
  47. package/lib-amd/hooks/useOnClickOutside.js +13 -15
  48. package/lib-amd/hooks/useOnClickOutside.js.map +1 -1
  49. package/lib-amd/index.js +6 -2
  50. package/lib-amd/index.js.map +1 -1
  51. package/lib-amd/utils/getNativeElementProps.js.map +1 -1
  52. package/lib-commonjs/compose/getSlots.js.map +1 -1
  53. package/lib-commonjs/compose/index.js.map +1 -1
  54. package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
  55. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  56. package/lib-commonjs/compose/types.js.map +1 -1
  57. package/lib-commonjs/events/index.js +8 -0
  58. package/lib-commonjs/events/index.js.map +1 -0
  59. package/lib-commonjs/events/mouseTouchHelpers.js +47 -0
  60. package/lib-commonjs/events/mouseTouchHelpers.js.map +1 -0
  61. package/lib-commonjs/hooks/index.js.map +1 -1
  62. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  63. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  64. package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
  65. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
  66. package/lib-commonjs/hooks/useId.js.map +1 -1
  67. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  68. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  69. package/lib-commonjs/hooks/useOnClickOutside.js +20 -14
  70. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  71. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  72. package/lib-commonjs/hooks/usePrevious.js.map +1 -1
  73. package/lib-commonjs/hooks/useScrollbarWidth.js.map +1 -1
  74. package/lib-commonjs/hooks/useTimeout.js.map +1 -1
  75. package/lib-commonjs/index.js +26 -1
  76. package/lib-commonjs/index.js.map +1 -1
  77. package/lib-commonjs/ssr/SSRContext.js.map +1 -1
  78. package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
  79. package/lib-commonjs/ssr/index.js.map +1 -1
  80. package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
  81. package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
  82. package/lib-commonjs/trigger/index.js.map +1 -1
  83. package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
  84. package/lib-commonjs/trigger/types.js.map +1 -1
  85. package/lib-commonjs/utils/clamp.js.map +1 -1
  86. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  87. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
  88. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
  89. package/lib-commonjs/utils/index.js.map +1 -1
  90. package/lib-commonjs/utils/isHTMLElement.js.map +1 -1
  91. package/lib-commonjs/utils/isInteractiveHTMLElement.js.map +1 -1
  92. package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
  93. package/lib-commonjs/utils/omit.js.map +1 -1
  94. package/lib-commonjs/utils/properties.js.map +1 -1
  95. package/package.json +1 -1
package/CHANGELOG.json CHANGED
@@ -2,7 +2,59 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Mon, 13 Feb 2023 23:40:49 GMT",
5
+ "date": "Wed, 08 Mar 2023 17:39:17 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.6.1",
7
+ "version": "9.6.1",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "author": "martinhochel@microsoft.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "677a67b551966986db34a6fac608cb89ee150471",
14
+ "comment": "style: apply prettier 2.3-2.8 formatting on whole codebase"
15
+ }
16
+ ],
17
+ "patch": [
18
+ {
19
+ "author": "bernardo.sunderhus@gmail.com",
20
+ "package": "@fluentui/react-utilities",
21
+ "commit": "b38973143b00f399373027454844ef695fc0091b",
22
+ "comment": "fix: adjust IntrinsicElementProps type to properly support void elements"
23
+ },
24
+ {
25
+ "author": "martinhochel@microsoft.com",
26
+ "package": "@fluentui/react-utilities",
27
+ "commit": "dd0f5b76fc8905c067cc58556ec1f9626dcfc640",
28
+ "comment": "fix: export omit function"
29
+ }
30
+ ]
31
+ }
32
+ },
33
+ {
34
+ "date": "Wed, 15 Feb 2023 11:44:51 GMT",
35
+ "tag": "@fluentui/react-utilities_v9.6.0",
36
+ "version": "9.6.0",
37
+ "comments": {
38
+ "minor": [
39
+ {
40
+ "author": "jirivyhnalek@microsoft.com",
41
+ "package": "@fluentui/react-utilities",
42
+ "commit": "4e349194f193d7371de6040c7c69cf071b87be56",
43
+ "comment": "feat: Add event helpers to ease working with mouse and touch"
44
+ }
45
+ ],
46
+ "patch": [
47
+ {
48
+ "author": "lingfangao@hotmail.com",
49
+ "package": "@fluentui/react-utilities",
50
+ "commit": "087d981aab96bef2e332a373069a19bc702a7ca2",
51
+ "comment": "fix(useOnClickOutside): iframe focus detection uses `contains`"
52
+ }
53
+ ]
54
+ }
55
+ },
56
+ {
57
+ "date": "Mon, 13 Feb 2023 23:43:13 GMT",
6
58
  "tag": "@fluentui/react-utilities_v9.5.3",
7
59
  "version": "9.5.3",
8
60
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,35 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Mon, 13 Feb 2023 23:40:49 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 08 Mar 2023 17:39:17 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.6.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.6.1)
8
+
9
+ Wed, 08 Mar 2023 17:39:17 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.6.0..@fluentui/react-utilities_v9.6.1)
11
+
12
+ ### Patches
13
+
14
+ - fix: adjust IntrinsicElementProps type to properly support void elements ([PR #27095](https://github.com/microsoft/fluentui/pull/27095) by bernardo.sunderhus@gmail.com)
15
+ - fix: export omit function ([PR #26958](https://github.com/microsoft/fluentui/pull/26958) by martinhochel@microsoft.com)
16
+
17
+ ## [9.6.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.6.0)
18
+
19
+ Wed, 15 Feb 2023 11:44:51 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.5.3..@fluentui/react-utilities_v9.6.0)
21
+
22
+ ### Minor changes
23
+
24
+ - feat: Add event helpers to ease working with mouse and touch ([PR #26784](https://github.com/microsoft/fluentui/pull/26784) by jirivyhnalek@microsoft.com)
25
+
26
+ ### Patches
27
+
28
+ - fix(useOnClickOutside): iframe focus detection uses `contains` ([PR #26845](https://github.com/microsoft/fluentui/pull/26845) by lingfangao@hotmail.com)
29
+
7
30
  ## [9.5.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.5.3)
8
31
 
9
- Mon, 13 Feb 2023 23:40:49 GMT
32
+ Mon, 13 Feb 2023 23:43:13 GMT
10
33
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.5.2..@fluentui/react-utilities_v9.5.3)
11
34
 
12
35
  ### Patches
package/dist/index.d.ts CHANGED
@@ -56,7 +56,7 @@ export declare type ComponentState<Slots extends SlotPropsRecord> = {
56
56
  *
57
57
  * Reference: https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
58
58
  */
59
- declare type EmptyIntrisicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
59
+ declare type EmptyIntrinsicElements = 'area' | 'base' | 'br' | 'col' | 'embed' | 'hr' | 'img' | 'input' | 'link' | 'meta' | 'param' | 'source' | 'track' | 'wbr';
60
60
 
61
61
  /**
62
62
  * Removes SlotShorthandValue and null from the slot type, extracting just the slot's Props object.
@@ -86,6 +86,15 @@ export declare type FluentTriggerComponent = {
86
86
  */
87
87
  export declare type ForwardRefComponent<Props> = ObscureEventName extends keyof Props ? Required<Props>[ObscureEventName] extends React_2.PointerEventHandler<infer Element> ? React_2.ForwardRefExoticComponent<Props & React_2.RefAttributes<Element>> : never : never;
88
88
 
89
+ /**
90
+ * Returns an object with clientX, clientY for TouchOrMouseEvent.
91
+ * Returns zeros in case the event is not a mouse or a touch event.
92
+ */
93
+ export declare function getEventClientCoords(event: TouchOrMouseEvent): {
94
+ clientX: number;
95
+ clientY: number;
96
+ };
97
+
89
98
  /**
90
99
  * Given an element tagname and user props, filters the props to only allowed props for the given
91
100
  * element type.
@@ -183,9 +192,7 @@ export declare const IdPrefixProvider: React_2.Provider<string | undefined>;
183
192
  * * Removes legacy string ref.
184
193
  * * Disallows children for empty tags like 'img'.
185
194
  */
186
- declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = React_2.PropsWithRef<JSX.IntrinsicElements[Type]> & (Type extends EmptyIntrisicElements ? {
187
- children?: never;
188
- } : {});
195
+ declare type IntrinsicElementProps<Type extends keyof JSX.IntrinsicElements> = Type extends EmptyIntrinsicElements ? PropsWithoutChildren<React_2.PropsWithRef<JSX.IntrinsicElements[Type]>> : React_2.PropsWithRef<JSX.IntrinsicElements[Type]>;
189
196
 
190
197
  /**
191
198
  * @internal
@@ -211,6 +218,11 @@ export declare function isHTMLElement(element?: unknown): element is HTMLElement
211
218
  */
212
219
  export declare function isInteractiveHTMLElement(element: unknown): boolean;
213
220
 
221
+ /**
222
+ * Returns true if event is a mouse event. Useful when sharing logic between touch and mouse interactions.
223
+ */
224
+ export declare function isMouseEvent(event: TouchOrMouseEvent): event is MouseEvent | React_2.MouseEvent;
225
+
214
226
  /**
215
227
  * Guard method that validates if a shorthand is a slot
216
228
  * can be used to extends properties provided by a slot
@@ -255,6 +267,11 @@ declare type IsSingleton<T extends string> = {
255
267
  [K in T]: Exclude<T, K> extends never ? true : false;
256
268
  }[T];
257
269
 
270
+ /**
271
+ * Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.
272
+ */
273
+ export declare function isTouchEvent(event: TouchOrMouseEvent): event is TouchEvent | React_2.TouchEvent;
274
+
258
275
  /**
259
276
  * @internal
260
277
  * Combine two event callbacks into a single callback function that calls each one in order.
@@ -280,6 +297,8 @@ declare type IsSingleton<T extends string> = {
280
297
  */
281
298
  export declare function mergeCallbacks<Args extends unknown[]>(callback1: ((...args: Args) => void) | undefined, callback2: ((...args: Args) => void) | undefined): (...args: Args) => void;
282
299
 
300
+ export declare type NativeTouchOrMouseEvent = MouseEvent | TouchEvent;
301
+
283
302
  declare type ObjectSlotProps<S extends SlotPropsRecord> = {
284
303
  [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As> ? UnionToIntersection<JSX.IntrinsicElements[As]> : ExtractSlotProps<S[K]> extends React_2.ComponentType<infer P> ? P : never;
285
304
  };
@@ -298,6 +317,30 @@ declare type ObjectSlotProps<S extends SlotPropsRecord> = {
298
317
  */
299
318
  declare type ObscureEventName = 'onLostPointerCaptureCapture';
300
319
 
320
+ /**
321
+ * Tiny helper to do the minimal amount of work in duplicating an object but omitting some
322
+ * props. This ends up faster than using object ...rest or reduce to filter.
323
+ *
324
+ * This behaves very much like filteredAssign, but does not merge many objects together,
325
+ * uses an exclusion object map, and avoids spreads all for optimal performance.
326
+ *
327
+ * See perf test for background:
328
+ * https://jsperf.com/omit-vs-rest-vs-reduce/1
329
+ *
330
+ * @param obj - The object to clone
331
+ * @param exclusions - The array of keys to exclude
332
+ */
333
+ export declare function omit<TObj extends Record<string, any>, Exclusions extends (keyof TObj)[]>(obj: TObj, exclusions: Exclusions): Omit<TObj, Exclusions[number]>;
334
+
335
+ /**
336
+ * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
337
+ * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
338
+ *
339
+ * The conditional "extends unknown" (always true) exploits a quirk in the way TypeScript handles conditional
340
+ * types, to prevent unions from being expanded.
341
+ */
342
+ declare type PropsWithoutChildren<P> = 'children' extends keyof P ? (P extends unknown ? Omit<P, 'children'> : P) : P;
343
+
301
344
  /**
302
345
  * Removes the 'ref' prop from the given Props type, leaving unions intact (such as the discriminated union created by
303
346
  * IntrinsicSlotProps). This allows IntrinsicSlotProps to be used with React.forwardRef.
@@ -307,6 +350,8 @@ declare type ObscureEventName = 'onLostPointerCaptureCapture';
307
350
  */
308
351
  declare type PropsWithoutRef<P> = 'ref' extends keyof P ? (P extends unknown ? Omit<P, 'ref'> : P) : P;
309
352
 
353
+ export declare type ReactTouchOrMouseEvent = React_2.MouseEvent | React_2.TouchEvent;
354
+
310
355
  /**
311
356
  * A Ref function which can be treated like a ref object in that it has an attached
312
357
  * current property, which will be updated as the ref is evaluated.
@@ -365,10 +410,10 @@ export declare type ResolveShorthandOptions<Props, Required extends boolean = fa
365
410
  */
366
411
  export declare type Slot<Type extends keyof JSX.IntrinsicElements | React_2.ComponentType | React_2.VoidFunctionComponent | UnknownSlotProps, AlternateAs extends keyof JSX.IntrinsicElements = never> = IsSingleton<Extract<Type, string>> extends true ? WithSlotShorthandValue<Type extends keyof JSX.IntrinsicElements ? {
367
412
  as?: Type;
368
- } & WithSlotRenderFunction<IntrisicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
413
+ } & WithSlotRenderFunction<IntrinsicElementProps<Type>> : Type extends React_2.ComponentType<infer Props> ? WithSlotRenderFunction<Props> : Type> | {
369
414
  [As in AlternateAs]: {
370
415
  as: As;
371
- } & WithSlotRenderFunction<IntrisicElementProps<As>>;
416
+ } & WithSlotRenderFunction<IntrinsicElementProps<As>>;
372
417
  }[AlternateAs] | null : 'Error: First parameter to Slot must not be not a union of types. See documentation of Slot type.';
373
418
 
374
419
  /**
@@ -407,6 +452,8 @@ export declare const SSRProvider: React_2.FC<{
407
452
  children: React_2.ReactNode;
408
453
  }>;
409
454
 
455
+ export declare type TouchOrMouseEvent = NativeTouchOrMouseEvent | ReactTouchOrMouseEvent;
456
+
410
457
  /**
411
458
  * A trigger may have a children that could be either:
412
459
  * 1. A single element
@@ -613,10 +660,10 @@ export declare function useTimeout(): readonly [(fn: () => void, delay: number)
613
660
  * Helper type for {@link Slot}. Takes the props we want to support for a slot and adds the ability for `children`
614
661
  * to be a render function that takes those props.
615
662
  */
616
- declare type WithSlotRenderFunction<Props extends {
617
- children?: unknown;
618
- }> = Props & {
619
- children?: Props['children'] | SlotRenderFunction<Props>;
663
+ declare type WithSlotRenderFunction<Props> = Props & {
664
+ children?: (Props extends {
665
+ children?: unknown;
666
+ } ? Props['children'] : never) | SlotRenderFunction<Props>;
620
667
  };
621
668
 
622
669
  /**
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,IAAI,QAAQ,eAAe;AA6BpC;;;;;;;;;;;;;;;;;AAiBA,OAAM,SAAUC,QAAQ,CACtBC,KAAwB;EAKxB,MAAMC,KAAK,GAAG,EAAc;EAC5B,MAAMC,SAAS,GAAG,EAAO;EAEzB,MAAMC,SAAS,GAAgBC,MAAM,CAACC,IAAI,CAACL,KAAK,CAACM,UAAU,CAAC;EAC5D,KAAK,MAAMC,QAAQ,IAAIJ,SAAS,EAAE;IAChC,MAAM,CAACK,IAAI,EAAEC,KAAK,CAAC,GAAGC,OAAO,CAACV,KAAK,EAAEO,QAAQ,CAAC;IAC9CN,KAAK,CAACM,QAAQ,CAAC,GAAGC,IAAiC;IACnDN,SAAS,CAACK,QAAQ,CAAC,GAAGE,KAAK;;EAE7B,OAAO;IAAER,KAAK;IAAEC,SAAS,EAAGA;EAA2C,CAAE;AAC3E;AAEA,SAASQ,OAAO,CACdV,KAAwB,EACxBO,QAAW;;EAEX,IAAIP,KAAK,CAACO,QAAQ,CAAC,KAAKI,SAAS,EAAE;IACjC,OAAO,CAAC,IAAI,EAAEA,SAAiB,CAAC;;EAElC,MAAM;IAAEC,QAAQ;IAAEC,EAAE,EAAEC,MAAM;IAAE,GAAGC;EAAI,CAAE,GAAGf,KAAK,CAACO,QAAQ,CAAE;EAE1D,MAAMC,IAAI,GAAI,YAAK,CAACF,UAAU,0CAAGC,QAAQ,CAAC,MAAKI,SAAS,IAAI,OAAOX,KAAK,CAACM,UAAU,CAACC,QAAQ,CAAC,KAAK,QAAQ,GACtGO,MAAM,KAAI,WAAK,CAACR,UAAU,0CAAGC,QAAQ,CAAC,KAAI,KAAK,GAC/CP,KAAK,CAACM,UAAU,CAACC,QAAQ,CAA6B;EAE1D,IAAI,OAAOK,QAAQ,KAAK,UAAU,EAAE;IAClC,MAAMI,MAAM,GAAGJ,QAAoC;IACnD,OAAO,CACLf,KAAK,CAACoB,QAAQ,EACb;MACCL,QAAQ,EAAEI,MAAM,CAACR,IAAI,EAAEO,IAAqC;KACzC,CACtB;;EAGH,MAAMG,gBAAgB,GAAG,OAAOV,IAAI,KAAK,QAAQ,KAAI,WAAK,CAACD,QAAQ,CAAC,0CAAEM,EAAE;EACxE,MAAMX,SAAS,GAAIgB,gBAAgB,GAAGpB,IAAI,CAACE,KAAK,CAACO,QAAQ,CAAE,EAAE,CAAC,IAAI,CAAC,CAAC,GAAGP,KAAK,CAACO,QAAQ,CAAU;EAE/F,OAAO,CAACC,IAAI,EAAEN,SAAS,CAAC;AAC1B","names":["React","omit","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","undefined","children","as","asProp","rest","render","Fragment","shouldOmitAsProp"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/compose/getSlots.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\ntype ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: (slotProps as unknown) as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n ({\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown) as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"]}
1
+ {"version":3,"names":["React","omit","getSlots","state","slots","slotProps","slotNames","Object","keys","components","slotName","slot","props","getSlot","undefined","children","as","asProp","rest","_a","_b","render","Fragment","shouldOmitAsProp","_c"],"sources":["../src/packages/react-components/react-utilities/src/compose/getSlots.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { omit } from '../utils/omit';\nimport type {\n AsIntrinsicElement,\n ComponentState,\n ExtractSlotProps,\n SlotPropsRecord,\n SlotRenderFunction,\n UnionToIntersection,\n} from './types';\n\nexport type Slots<S extends SlotPropsRecord> = {\n [K in keyof S]: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // for slots with an `as` prop, the slot will be any one of the possible values of `as`\n As\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? React.ElementType<NonNullable<P>>\n : React.ElementType<ExtractSlotProps<S[K]>>;\n};\n\ntype ObjectSlotProps<S extends SlotPropsRecord> = {\n [K in keyof S]-?: ExtractSlotProps<S[K]> extends AsIntrinsicElement<infer As>\n ? // For intrinsic element types, return the intersection of all possible\n // element's props, to be compatible with the As type returned by Slots<>\n UnionToIntersection<JSX.IntrinsicElements[As]>\n : ExtractSlotProps<S[K]> extends React.ComponentType<infer P>\n ? P\n : never;\n};\n\n/**\n * Given the state and an array of slot names, will break out `slots` and `slotProps`\n * collections.\n *\n * The root is derived from a mix of `components` props and `as` prop.\n *\n * Slots will render as null if they are rendered as primitives with undefined children.\n *\n * The slotProps will always omit the `as` prop within them, and for slots that are string\n * primitives, the props will be filtered according to the slot type by the type system.\n * For example, if the slot is rendered `as: 'a'`, the props will be filtered for acceptable\n * anchor props. Note that this is only enforced at build time by Typescript -- there is no\n * runtime code filtering props in this function.\n *\n * @param state - State including slot definitions\n * @returns An object containing the `slots` map and `slotProps` map.\n */\nexport function getSlots<R extends SlotPropsRecord>(\n state: ComponentState<R>,\n): {\n slots: Slots<R>;\n slotProps: ObjectSlotProps<R>;\n} {\n const slots = {} as Slots<R>;\n const slotProps = {} as R;\n\n const slotNames: (keyof R)[] = Object.keys(state.components);\n for (const slotName of slotNames) {\n const [slot, props] = getSlot(state, slotName);\n slots[slotName] = slot as Slots<R>[typeof slotName];\n slotProps[slotName] = props;\n }\n return { slots, slotProps: slotProps as unknown as ObjectSlotProps<R> };\n}\n\nfunction getSlot<R extends SlotPropsRecord, K extends keyof R>(\n state: ComponentState<R>,\n slotName: K,\n): readonly [React.ElementType<R[K]> | null, R[K]] {\n if (state[slotName] === undefined) {\n return [null, undefined as R[K]];\n }\n const { children, as: asProp, ...rest } = state[slotName]!;\n\n const slot = (\n state.components?.[slotName] === undefined || typeof state.components[slotName] === 'string'\n ? asProp || state.components?.[slotName] || 'div'\n : state.components[slotName]\n ) as React.ElementType<R[K]>;\n\n if (typeof children === 'function') {\n const render = children as SlotRenderFunction<R[K]>;\n return [\n React.Fragment,\n {\n children: render(slot, rest as Omit<R[K], 'children' | 'as'>),\n } as unknown as R[K],\n ];\n }\n\n const shouldOmitAsProp = typeof slot === 'string' && state[slotName]?.as;\n const slotProps = (shouldOmitAsProp ? omit(state[slotName]!, ['as']) : state[slotName]) as R[K];\n\n return [slot, slotProps];\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAASC,IAAI,QAAQ,eAAe;AA6BpC;;;;;;;;;;;;;;;;;AAiBA,OAAM,SAAUC,QAAQA,CACtBC,KAAwB;EAKxB,MAAMC,KAAK,GAAG,EAAc;EAC5B,MAAMC,SAAS,GAAG,EAAO;EAEzB,MAAMC,SAAS,GAAgBC,MAAM,CAACC,IAAI,CAACL,KAAK,CAACM,UAAU,CAAC;EAC5D,KAAK,MAAMC,QAAQ,IAAIJ,SAAS,EAAE;IAChC,MAAM,CAACK,IAAI,EAAEC,KAAK,CAAC,GAAGC,OAAO,CAACV,KAAK,EAAEO,QAAQ,CAAC;IAC9CN,KAAK,CAACM,QAAQ,CAAC,GAAGC,IAAiC;IACnDN,SAAS,CAACK,QAAQ,CAAC,GAAGE,KAAK;;EAE7B,OAAO;IAAER,KAAK;IAAEC,SAAS,EAAEA;EAA0C,CAAE;AACzE;AAEA,SAASQ,OAAOA,CACdV,KAAwB,EACxBO,QAAW;;EAEX,IAAIP,KAAK,CAACO,QAAQ,CAAC,KAAKI,SAAS,EAAE;IACjC,OAAO,CAAC,IAAI,EAAEA,SAAiB,CAAC;;EAElC,MAAM;IAAEC,QAAQ;IAAEC,EAAE,EAAEC,MAAM;IAAE,GAAGC;EAAI,CAAE,GAAGf,KAAK,CAACO,QAAQ,CAAE;EAE1D,MAAMC,IAAI,GACR,EAAAQ,EAAA,GAAAhB,KAAK,CAACM,UAAU,cAAAU,EAAA,uBAAAA,EAAA,CAAGT,QAAQ,CAAC,MAAKI,SAAS,IAAI,OAAOX,KAAK,CAACM,UAAU,CAACC,QAAQ,CAAC,KAAK,QAAQ,GACxFO,MAAM,KAAI,CAAAG,EAAA,GAAAjB,KAAK,CAACM,UAAU,cAAAW,EAAA,uBAAAA,EAAA,CAAGV,QAAQ,CAAC,KAAI,KAAK,GAC/CP,KAAK,CAACM,UAAU,CAACC,QAAQ,CACH;EAE5B,IAAI,OAAOK,QAAQ,KAAK,UAAU,EAAE;IAClC,MAAMM,MAAM,GAAGN,QAAoC;IACnD,OAAO,CACLf,KAAK,CAACsB,QAAQ,EACd;MACEP,QAAQ,EAAEM,MAAM,CAACV,IAAI,EAAEO,IAAqC;KAC1C,CACrB;;EAGH,MAAMK,gBAAgB,GAAG,OAAOZ,IAAI,KAAK,QAAQ,KAAI,CAAAa,EAAA,GAAArB,KAAK,CAACO,QAAQ,CAAC,cAAAc,EAAA,uBAAAA,EAAA,CAAER,EAAE;EACxE,MAAMX,SAAS,GAAIkB,gBAAgB,GAAGtB,IAAI,CAACE,KAAK,CAACO,QAAQ,CAAE,EAAE,CAAC,IAAI,CAAC,CAAC,GAAGP,KAAK,CAACO,QAAQ,CAAU;EAE/F,OAAO,CAACC,IAAI,EAAEN,SAAS,CAAC;AAC1B"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,SAASA,cAAc,QAAQ,OAAO;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,OAAM,SAAUC,mBAAmB,CACjCC,SAAqB;EAErB,OAAOA,SAAS,KAAK,IAAI,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,IAAI,eAACF,cAAc,CAACE,SAAS,CAAC;AACvH","names":["isValidElement","isResolvedShorthand","shorthand","Array","isArray"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/compose/isResolvedShorthand.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !isValidElement(shorthand);\n}\n"]}
1
+ {"version":3,"names":["isValidElement","isResolvedShorthand","shorthand","Array","isArray"],"sources":["../src/packages/react-components/react-utilities/src/compose/isResolvedShorthand.ts"],"sourcesContent":["import { isValidElement } from 'react';\nimport type { ExtractSlotProps, Slot, UnknownSlotProps } from './types';\n\n/**\n * Guard method that validates if a shorthand is a slot\n * can be used to extends properties provided by a slot\n *\n * @example\n * ```\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(event => {\n * if (isResolvedShorthand(backdrop)) {\n * backdrop.onClick?.(event)\n * }\n * // do something after passing click down the line\n * }),\n * },\n * })\n * ```\n * @example\n * ```\n * const handleBackDropClick = (event) => {\n * // do your thing\n * }\n * const backdropSlot = resolveShorthand(backdrop, {\n * defaultProps: {\n * onClick: useEventCallback(\n * mergeCallbacks(isResolvedShorthand(backdrop) ? backdrop.onClick : undefined, handleBackdropClick)\n * )\n * })\n * ```\n */\nexport function isResolvedShorthand<Shorthand extends Slot<UnknownSlotProps>>(\n shorthand?: Shorthand,\n): shorthand is ExtractSlotProps<Shorthand> {\n return shorthand !== null && typeof shorthand === 'object' && !Array.isArray(shorthand) && !isValidElement(shorthand);\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,OAAO;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,OAAM,SAAUC,mBAAmBA,CACjCC,SAAqB;EAErB,OAAOA,SAAS,KAAK,IAAI,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,IAAI,eAACF,cAAc,CAACE,SAAS,CAAC;AACvH"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,SAASA,cAAc,QAAQ,OAAO;AAkBtC;;;;;;AAMA,OAAO,MAAMC,gBAAgB,GAA6B,CAACC,KAAK,EAAEC,OAAO,KAAI;EAC3E,MAAM;IAAEC,QAAQ,GAAG,KAAK;IAAEC;EAAY,CAAE,GAAGF,OAAO,IAAI,EAAE;EACxD,IAAID,KAAK,KAAK,IAAI,IAAKA,KAAK,KAAKI,SAAS,IAAI,CAACF,QAAS,EAAE;IACxD,OAAOE,SAAS;;EAGlB,IAAIC,iBAAiB,GAAG,EAAsB;EAE9C,IAAI,OAAOL,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIM,KAAK,CAACC,OAAO,CAACP,KAAK,CAAC,iBAAIF,cAAc,CAACE,KAAK,CAAC,EAAE;IAC3GK,iBAAiB,CAACG,QAAQ,GAAGR,KAAK;GACnC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IACpCK,iBAAiB,GAAG;MAAE,GAAGL;IAAK,CAAE;;EAGlC,OAAOG,YAAY,GAAG;IAAE,GAAGA,YAAY;IAAE,GAAGE;EAAiB,CAAE,GAAGA,iBAAiB;AACrF,CAAC","names":["isValidElement","resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","children"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/compose/resolveShorthand.ts"],"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"]}
1
+ {"version":3,"names":["isValidElement","resolveShorthand","value","options","required","defaultProps","undefined","resolvedShorthand","Array","isArray","children"],"sources":["../src/packages/react-components/react-utilities/src/compose/resolveShorthand.ts"],"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"],"mappings":"AAAA,SAASA,cAAc,QAAQ,OAAO;AAkBtC;;;;;;AAMA,OAAO,MAAMC,gBAAgB,GAA6BA,CAACC,KAAK,EAAEC,OAAO,KAAI;EAC3E,MAAM;IAAEC,QAAQ,GAAG,KAAK;IAAEC;EAAY,CAAE,GAAGF,OAAO,IAAI,EAAE;EACxD,IAAID,KAAK,KAAK,IAAI,IAAKA,KAAK,KAAKI,SAAS,IAAI,CAACF,QAAS,EAAE;IACxD,OAAOE,SAAS;;EAGlB,IAAIC,iBAAiB,GAAG,EAAsB;EAE9C,IAAI,OAAOL,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAIM,KAAK,CAACC,OAAO,CAACP,KAAK,CAAC,iBAAIF,cAAc,CAACE,KAAK,CAAC,EAAE;IAC3GK,iBAAiB,CAACG,QAAQ,GAAGR,KAAK;GACnC,MAAM,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IACpCK,iBAAiB,GAAG;MAAE,GAAGL;IAAK,CAAE;;EAGlC,OAAOG,YAAY,GAAG;IAAE,GAAGA,YAAY;IAAE,GAAGE;EAAiB,CAAE,GAAGA,iBAAiB;AACrF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/compose/types.ts"],"names":[],"mappings":"","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.ReactNode[] | 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 | React.VoidFunctionComponent | 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\n/**\n * Helper type to correctly define the slot class names object.\n */\nexport type SlotClassNames<Slots> = {\n [SlotName in keyof Slots]-?: string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/compose/types.ts"],"names":[],"mappings":"","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.ReactNode[] | 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> = Props & {\n children?: (Props extends { children?: unknown } ? Props['children'] : never) | 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 EmptyIntrinsicElements =\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 IntrinsicElementProps<Type extends keyof JSX.IntrinsicElements> = Type extends EmptyIntrinsicElements\n ? PropsWithoutChildren<React.PropsWithRef<JSX.IntrinsicElements[Type]>>\n : React.PropsWithRef<JSX.IntrinsicElements[Type]>;\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 | React.VoidFunctionComponent | 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<IntrinsicElementProps<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<IntrinsicElementProps<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 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 PropsWithoutChildren<P> = 'children' extends keyof P ? (P extends unknown ? Omit<P, 'children'> : 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\n/**\n * Helper type to correctly define the slot class names object.\n */\nexport type SlotClassNames<Slots> = {\n [SlotName in keyof Slots]-?: string;\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './mouseTouchHelpers';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/events/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC","sourcesContent":["export * from './mouseTouchHelpers';\n"]}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.
3
+ */
4
+ export function isTouchEvent(event) {
5
+ return event.type.startsWith('touch');
6
+ }
7
+ /**
8
+ * Returns true if event is a mouse event. Useful when sharing logic between touch and mouse interactions.
9
+ */
10
+ export function isMouseEvent(event) {
11
+ return event.type.startsWith('mouse') || ['click', 'contextmenu', 'dblclick'].indexOf(event.type) > -1;
12
+ }
13
+ /**
14
+ * Returns an object with clientX, clientY for TouchOrMouseEvent.
15
+ * Returns zeros in case the event is not a mouse or a touch event.
16
+ */
17
+ export function getEventClientCoords(event) {
18
+ if (isMouseEvent(event)) {
19
+ return {
20
+ clientX: event.clientX,
21
+ clientY: event.clientY
22
+ };
23
+ } else if (isTouchEvent(event)) {
24
+ return {
25
+ clientX: event.touches[0].clientX,
26
+ clientY: event.touches[0].clientY
27
+ };
28
+ } else {
29
+ if (process.env.NODE_ENV !== 'production') {
30
+ throw new Error('@fluentui/react-utilities]: Unable to get clientX. Unknown event type.');
31
+ }
32
+ return {
33
+ clientX: 0,
34
+ clientY: 0
35
+ };
36
+ }
37
+ }
38
+ //# sourceMappingURL=mouseTouchHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isTouchEvent","event","type","startsWith","isMouseEvent","indexOf","getEventClientCoords","clientX","clientY","touches","process","env","NODE_ENV","Error"],"sources":["../src/packages/react-components/react-utilities/src/events/mouseTouchHelpers.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type NativeTouchOrMouseEvent = MouseEvent | TouchEvent;\n\nexport type ReactTouchOrMouseEvent = React.MouseEvent | React.TouchEvent;\n\nexport type TouchOrMouseEvent = NativeTouchOrMouseEvent | ReactTouchOrMouseEvent;\n\n/**\n * Returns true if event is a touch event. Useful when sharing logic between touch and mouse interactions.\n */\nexport function isTouchEvent(event: TouchOrMouseEvent): event is TouchEvent | React.TouchEvent {\n return event.type.startsWith('touch');\n}\n\n/**\n * Returns true if event is a mouse event. Useful when sharing logic between touch and mouse interactions.\n */\nexport function isMouseEvent(event: TouchOrMouseEvent): event is MouseEvent | React.MouseEvent {\n return event.type.startsWith('mouse') || ['click', 'contextmenu', 'dblclick'].indexOf(event.type) > -1;\n}\n\n/**\n * Returns an object with clientX, clientY for TouchOrMouseEvent.\n * Returns zeros in case the event is not a mouse or a touch event.\n */\nexport function getEventClientCoords(event: TouchOrMouseEvent): { clientX: number; clientY: number } {\n if (isMouseEvent(event)) {\n return { clientX: event.clientX, clientY: event.clientY };\n } else if (isTouchEvent(event)) {\n return { clientX: event.touches[0].clientX, clientY: event.touches[0].clientY };\n } else {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('@fluentui/react-utilities]: Unable to get clientX. Unknown event type.');\n }\n return { clientX: 0, clientY: 0 };\n }\n}\n"],"mappings":"AAQA;;;AAGA,OAAM,SAAUA,YAAYA,CAACC,KAAwB;EACnD,OAAOA,KAAK,CAACC,IAAI,CAACC,UAAU,CAAC,OAAO,CAAC;AACvC;AAEA;;;AAGA,OAAM,SAAUC,YAAYA,CAACH,KAAwB;EACnD,OAAOA,KAAK,CAACC,IAAI,CAACC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC,CAACE,OAAO,CAACJ,KAAK,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxG;AAEA;;;;AAIA,OAAM,SAAUI,oBAAoBA,CAACL,KAAwB;EAC3D,IAAIG,YAAY,CAACH,KAAK,CAAC,EAAE;IACvB,OAAO;MAAEM,OAAO,EAAEN,KAAK,CAACM,OAAO;MAAEC,OAAO,EAAEP,KAAK,CAACO;IAAO,CAAE;GAC1D,MAAM,IAAIR,YAAY,CAACC,KAAK,CAAC,EAAE;IAC9B,OAAO;MAAEM,OAAO,EAAEN,KAAK,CAACQ,OAAO,CAAC,CAAC,CAAC,CAACF,OAAO;MAAEC,OAAO,EAAEP,KAAK,CAACQ,OAAO,CAAC,CAAC,CAAC,CAACD;IAAO,CAAE;GAChF,MAAM;IACL,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;MACzC,MAAM,IAAIC,KAAK,CAAC,wEAAwE,CAAC;;IAE3F,OAAO;MAAEN,OAAO,EAAE,CAAC;MAAEC,OAAO,EAAE;IAAC,CAAE;;AAErC"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAqB9B,SAASC,iBAAiB,CAAQC,QAAqC;EACrE,OAAO,OAAOA,QAAQ,KAAK,UAAU;AACvC;AAEA;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMC,oBAAoB,GAC/BC,OAA2C,IACa;EACxD,MAAMC,YAAY,GAAGC,eAAe,CAACF,OAAO,CAACG,KAAK,CAAC;EACnD,MAAMC,YAAY,GAAG,OAAOJ,OAAO,CAACK,YAAY,KAAK,WAAW,GAAGL,OAAO,CAACI,YAAY,GAAGJ,OAAO,CAACK,YAAY;EAC9G,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGX,KAAK,CAACY,QAAQ,CAAQJ,YAAY,CAAC;EAE7E,MAAMD,KAAK,GAAGF,YAAY,GAAID,OAAO,CAACG,KAAe,GAAGG,aAAa;EAErE,MAAMG,QAAQ,GAAGb,KAAK,CAACc,MAAM,CAACP,KAAK,CAAC;EACpCP,KAAK,CAACe,SAAS,CAAC,MAAK;IACnBF,QAAQ,CAACG,OAAO,GAAGT,KAAK;EAC1B,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX;EACA;EACA,MAAMU,QAAQ,GAAGjB,KAAK,CAACkB,WAAW,CAAEhB,QAAqC,IAAI;IAC3E;IACA;IACA,IAAID,iBAAiB,CAACC,QAAQ,CAAC,EAAE;MAC/BW,QAAQ,CAACG,OAAO,GAAGd,QAAQ,CAACW,QAAQ,CAACG,OAAO,CAAC;KAC9C,MAAM;MACLH,QAAQ,CAACG,OAAO,GAAGd,QAAQ;;IAG7BS,gBAAgB,CAACE,QAAQ,CAACG,OAAO,CAAC;EACpC,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,CAACT,KAAK,EAAEU,QAAQ,CAAC;AAC1B,CAAC;AAED;;;;;AAKA,MAAMX,eAAe,GAAIa,eAAwB,IAAI;EACnD,MAAM,CAACd,YAAY,CAAC,GAAGL,KAAK,CAACY,QAAQ,CAAU,MAAMO,eAAe,KAAKC,SAAS,CAAC;EAEnF,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC;IACA;IACAvB,KAAK,CAACe,SAAS,CAAC,MAAK;MACnB,IAAIV,YAAY,MAAMc,eAAe,KAAKC,SAAS,CAAC,EAAE;QACpD,MAAMI,KAAK,GAAG,IAAIC,KAAK,EAAE;QAEzB,MAAMC,cAAc,GAAGrB,YAAY,GAC/B,uCAAuC,GACvC,wCAAwC;QAE5C,MAAMsB,gBAAgB,GAAGtB,YAAY,GAAG,yBAAyB,GAAG,wBAAwB;QAE5F;QACAuB,OAAO,CAACJ,KAAK,CACX;QACE;QACA,0BAA0B,GAAGE,cAAc,GAAG,sCAAsC,EACpF,gBAAgB,GAAGC,gBAAgB,GAAG,kCAAkC,EACxE,oGAAoG,EACpG,2DAA2D,EAC3DH,KAAK,CAACK,KAAK,CACZ,CAACC,IAAI,CAAC,GAAG,CAAC,CACZ;;IAEL,CAAC,EAAE,CAACzB,YAAY,EAAEc,eAAe,CAAC,CAAC;;EAGrC,OAAOd,YAAY;AACrB,CAAC","names":["React","isFactoryDispatch","newState","useControllableState","options","isControlled","useIsControlled","state","initialState","defaultState","internalState","setInternalState","useState","stateRef","useRef","useEffect","current","setState","useCallback","controlledValue","undefined","process","env","NODE_ENV","error","Error","controlWarning","undefinedWarning","console","stack","join"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\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 * @internal\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] = React.useState<boolean>(() => controlledValue !== undefined);\n\n if (process.env.NODE_ENV !== 'production') {\n // We don't want these warnings in production even though it is against native behaviour\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (isControlled !== (controlledValue !== undefined)) {\n const error = new Error();\n\n const controlWarning = isControlled\n ? 'a controlled value to be uncontrolled'\n : 'an uncontrolled value to be controlled';\n\n const undefinedWarning = isControlled ? 'defined to an undefined' : 'undefined to a defined';\n\n // eslint-disable-next-line no-console\n console.error(\n [\n // Default react error\n 'A component is changing ' + controlWarning + '. This is likely caused by the value',\n 'changing from ' + undefinedWarning + ' value, which should not happen.',\n 'Decide between using a controlled or uncontrolled input element for the lifetime of the component.',\n 'More info: https://reactjs.org/link/controlled-components',\n error.stack,\n ].join(' '),\n );\n }\n }, [isControlled, controlledValue]);\n }\n\n return isControlled;\n};\n"]}
1
+ {"version":3,"names":["React","isFactoryDispatch","newState","useControllableState","options","isControlled","useIsControlled","state","initialState","defaultState","internalState","setInternalState","useState","stateRef","useRef","useEffect","current","setState","useCallback","controlledValue","undefined","process","env","NODE_ENV","error","Error","controlWarning","undefinedWarning","console","stack","join"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useControllableState.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\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 * @internal\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] = React.useState<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"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAqB9B,SAASC,iBAAiBA,CAAQC,QAAqC;EACrE,OAAO,OAAOA,QAAQ,KAAK,UAAU;AACvC;AAEA;;;;;;;;;;;;;;;;AAgBA,OAAO,MAAMC,oBAAoB,GAC/BC,OAA2C,IACa;EACxD,MAAMC,YAAY,GAAGC,eAAe,CAACF,OAAO,CAACG,KAAK,CAAC;EACnD,MAAMC,YAAY,GAAG,OAAOJ,OAAO,CAACK,YAAY,KAAK,WAAW,GAAGL,OAAO,CAACI,YAAY,GAAGJ,OAAO,CAACK,YAAY;EAC9G,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGX,KAAK,CAACY,QAAQ,CAAQJ,YAAY,CAAC;EAE7E,MAAMD,KAAK,GAAGF,YAAY,GAAID,OAAO,CAACG,KAAe,GAAGG,aAAa;EAErE,MAAMG,QAAQ,GAAGb,KAAK,CAACc,MAAM,CAACP,KAAK,CAAC;EACpCP,KAAK,CAACe,SAAS,CAAC,MAAK;IACnBF,QAAQ,CAACG,OAAO,GAAGT,KAAK;EAC1B,CAAC,EAAE,CAACA,KAAK,CAAC,CAAC;EAEX;EACA;EACA,MAAMU,QAAQ,GAAGjB,KAAK,CAACkB,WAAW,CAAEhB,QAAqC,IAAI;IAC3E;IACA;IACA,IAAID,iBAAiB,CAACC,QAAQ,CAAC,EAAE;MAC/BW,QAAQ,CAACG,OAAO,GAAGd,QAAQ,CAACW,QAAQ,CAACG,OAAO,CAAC;KAC9C,MAAM;MACLH,QAAQ,CAACG,OAAO,GAAGd,QAAQ;;IAG7BS,gBAAgB,CAACE,QAAQ,CAACG,OAAO,CAAC;EACpC,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,CAACT,KAAK,EAAEU,QAAQ,CAAC;AAC1B,CAAC;AAED;;;;;AAKA,MAAMX,eAAe,GAAIa,eAAwB,IAAI;EACnD,MAAM,CAACd,YAAY,CAAC,GAAGL,KAAK,CAACY,QAAQ,CAAU,MAAMO,eAAe,KAAKC,SAAS,CAAC;EAEnF,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC;IACA;IACAvB,KAAK,CAACe,SAAS,CAAC,MAAK;MACnB,IAAIV,YAAY,MAAMc,eAAe,KAAKC,SAAS,CAAC,EAAE;QACpD,MAAMI,KAAK,GAAG,IAAIC,KAAK,EAAE;QAEzB,MAAMC,cAAc,GAAGrB,YAAY,GAC/B,uCAAuC,GACvC,wCAAwC;QAE5C,MAAMsB,gBAAgB,GAAGtB,YAAY,GAAG,yBAAyB,GAAG,wBAAwB;QAE5F;QACAuB,OAAO,CAACJ,KAAK,CACX;QACE;QACA,0BAA0B,GAAGE,cAAc,GAAG,sCAAsC,EACpF,gBAAgB,GAAGC,gBAAgB,GAAG,kCAAkC,EACxE,oGAAoG,EACpG,2DAA2D,EAC3DH,KAAK,CAACK,KAAK,CACZ,CAACC,IAAI,CAAC,GAAG,CAAC,CACZ;;IAEL,CAAC,EAAE,CAACzB,YAAY,EAAEc,eAAe,CAAC,CAAC;;EAGrC,OAAOd,YAAY;AACrB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,yBAAyB,QAAQ,6BAA6B;AAEvE;;;;;;;;;;;;;AAaA,OAAO,MAAMC,gBAAgB,GAAoCC,EAA6B,IAAI;EAChG,MAAMC,WAAW,GAAGJ,KAAK,CAACK,MAAM,CAAY,MAAK;IAC/C,MAAM,IAAIC,KAAK,CAAC,8CAA8C,CAAC;EACjE,CAAC,CAAC;EAEFL,yBAAyB,CAAC,MAAK;IAC7BG,WAAW,CAACG,OAAO,GAAGJ,EAAE;EAC1B,CAAC,EAAE,CAACA,EAAE,CAAC,CAAC;EAER,OAAOH,KAAK,CAACQ,WAAW,CACtB,CAAC,GAAGC,IAAU,KAAI;IAChB,MAAMC,QAAQ,GAAGN,WAAW,CAACG,OAAO;IACpC,OAAOG,QAAQ,CAAC,GAAGD,IAAI,CAAC;EAC1B,CAAC,EACD,CAACL,WAAW,CAAC,CACd;AACH,CAAC","names":["React","useIsomorphicLayoutEffect","useEventCallback","fn","callbackRef","useRef","Error","current","useCallback","args","callback"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useEventCallback.ts"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\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"]}
1
+ {"version":3,"names":["React","useIsomorphicLayoutEffect","useEventCallback","fn","callbackRef","useRef","Error","current","useCallback","args","callback"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useEventCallback.ts"],"sourcesContent":["import * as React from 'react';\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';\n\n/**\n * @internal\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"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,yBAAyB,QAAQ,6BAA6B;AAEvE;;;;;;;;;;;;;AAaA,OAAO,MAAMC,gBAAgB,GAAoCC,EAA6B,IAAI;EAChG,MAAMC,WAAW,GAAGJ,KAAK,CAACK,MAAM,CAAY,MAAK;IAC/C,MAAM,IAAIC,KAAK,CAAC,8CAA8C,CAAC;EACjE,CAAC,CAAC;EAEFL,yBAAyB,CAAC,MAAK;IAC7BG,WAAW,CAACG,OAAO,GAAGJ,EAAE;EAC1B,CAAC,EAAE,CAACA,EAAE,CAAC,CAAC;EAER,OAAOH,KAAK,CAACQ,WAAW,CACtB,CAAC,GAAGC,IAAU,KAAI;IAChB,MAAMC,QAAQ,GAAGN,WAAW,CAACG,OAAO;IACpC,OAAOG,QAAQ,CAAC,GAAGD,IAAI,CAAC;EAC1B,CAAC,EACD,CAACL,WAAW,CAAC,CACd;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B;;;;;;;;;;;AAWA,OAAM,SAAUC,aAAa;EAC3B,MAAMC,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,IAAI,CAAC;EAElC,IAAID,OAAO,CAACE,OAAO,EAAE;IACnBF,OAAO,CAACE,OAAO,GAAG,KAAK;IACvB,OAAO,IAAI;;EAGb,OAAOF,OAAO,CAACE,OAAO;AACxB","names":["React","useFirstMount","isFirst","useRef","current"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useFirstMount.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\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"]}
1
+ {"version":3,"names":["React","useFirstMount","isFirst","useRef","current"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useFirstMount.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\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"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B;;;;;;;;;;;AAWA,OAAM,SAAUC,aAAaA,CAAA;EAC3B,MAAMC,OAAO,GAAGF,KAAK,CAACG,MAAM,CAAC,IAAI,CAAC;EAElC,IAAID,OAAO,CAACE,OAAO,EAAE;IACnBF,OAAO,CAACE,OAAO,GAAG,KAAK;IACvB,OAAO,IAAI;;EAGb,OAAOF,OAAO,CAACE,OAAO;AACxB"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC;;;;AAIA,OAAM,SAAUC,cAAc;EAC5B,OAAOD,UAAU,CAACE,CAAC,IAAIA,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC","names":["useReducer","useForceUpdate","x"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useForceUpdate.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/**\n * @internal\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"]}
1
+ {"version":3,"names":["useReducer","useForceUpdate","x"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useForceUpdate.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/**\n * @internal\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"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC;;;;AAIA,OAAM,SAAUC,cAAcA,CAAA;EAC5B,OAAOD,UAAU,CAACE,CAAC,IAAIA,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,sBAAsB,EAAEC,aAAa,QAAQ,cAAc;AAEpE,MAAMC,eAAe,gBAAGH,KAAK,CAACI,aAAa,CAAqBC,SAAS,CAAC;AAE1E;;;;AAIA,OAAO,MAAMC,gBAAgB,GAAGH,eAAe,CAACI,QAAQ;AAExD,SAASC,WAAW;EAClB,OAAOR,KAAK,CAACS,UAAU,CAACN,eAAe,CAAC,IAAI,EAAE;AAChD;AAEA;;;AAGA,OAAM,SAAUO,gBAAgB;EAC9BT,sBAAsB,CAACU,OAAO,GAAG,CAAC;AACpC;AAEA;;;;;;;;AAQA,OAAM,SAAUC,KAAK,CAACC,SAAiB,MAAM,EAAEC,UAAmB;EAChE,MAAMC,YAAY,GAAGb,aAAa,EAAE;EACpC,MAAMc,QAAQ,GAAGR,WAAW,EAAE;EAE9B;EACA;EACA,MAAMS,MAAM,GAAIjB,KAAe,CAAC,KAAK,GAAG,IAAI,CAA+B;EAE3E,IAAIiB,MAAM,EAAE;IACV,MAAMC,WAAW,GAAGD,MAAM,EAAE;IAE5B;IACA,MAAME,SAAS,GAAGnB,KAAK,CAACoB,OAAO,CAAC,MAAMF,WAAW,CAACG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAACH,WAAW,CAAC,CAAC;IAEnF,OAAOJ,UAAU,IAAI,GAAGE,QAAQ,GAAGH,MAAM,GAAGM,SAAS,EAAE;;EAGzD;EACA;EACA;EACA,OAAOnB,KAAK,CAACoB,OAAO,CAAC,MAAK;IACxB,IAAIN,UAAU,EAAE;MACd,OAAOA,UAAU;;IAGnB,OAAO,GAAGE,QAAQ,GAAGH,MAAM,GAAG,EAAEE,YAAY,CAACJ,OAAO,EAAE;EACxD,CAAC,EAAE,CAACK,QAAQ,EAAEH,MAAM,EAAEC,UAAU,EAAEC,YAAY,CAAC,CAAC;AAClD","names":["React","defaultSSRContextValue","useSSRContext","IdPrefixContext","createContext","undefined","IdPrefixProvider","Provider","useIdPrefix","useContext","resetIdsForTests","current","useId","prefix","providedId","contextValue","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"]}
1
+ {"version":3,"names":["React","defaultSSRContextValue","useSSRContext","IdPrefixContext","createContext","undefined","IdPrefixProvider","Provider","useIdPrefix","useContext","resetIdsForTests","current","useId","prefix","providedId","contextValue","idPrefix","_useId","generatedId","escapedId","useMemo","replace"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useId.ts"],"sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\n\nconst IdPrefixContext = React.createContext<string | undefined>(undefined);\n\n/**\n * Allows to define a prefix that will be used for all IDs generated by useId() hook. It's useful to avoid collisions\n * between different bundles.\n */\nexport const IdPrefixProvider = IdPrefixContext.Provider;\n\nfunction useIdPrefix(): string {\n return React.useContext(IdPrefixContext) || '';\n}\n\n/**\n * Resets generated IDs, should be used only in tests.\n */\nexport function resetIdsForTests(): void {\n defaultSSRContextValue.current = 0;\n}\n\n/**\n * Hook to generate a unique ID.\n *\n * @param prefix - Optional prefix for the ID. Defaults to 'fui-'.\n * @param providedId - Optional id provided by a parent component. Defaults to the provided value if present,\n * without conditioning the hook call\n * @returns The ID\n */\nexport function useId(prefix: string = 'fui-', providedId?: string): string {\n const contextValue = useSSRContext();\n const idPrefix = useIdPrefix();\n\n // Checking if useId is available on React, if it is, we use it to generate the id. String concatenation is used to\n // prevent bundlers from complaining with older versions of React.\n const _useId = (React as never)['use' + 'Id'] as (() => string) | undefined;\n\n if (_useId) {\n const generatedId = _useId();\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const escapedId = React.useMemo(() => generatedId.replace(/:/g, ''), [generatedId]);\n\n return providedId || `${idPrefix}${prefix}${escapedId}`;\n }\n\n // Hooks appear to be running conditionally, but they will always run in the same order since it's based on\n // the version of React being used. This is safe to ignore.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${idPrefix}${prefix}${++contextValue.current}`;\n }, [idPrefix, prefix, providedId, contextValue]);\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,sBAAsB,EAAEC,aAAa,QAAQ,cAAc;AAEpE,MAAMC,eAAe,gBAAGH,KAAK,CAACI,aAAa,CAAqBC,SAAS,CAAC;AAE1E;;;;AAIA,OAAO,MAAMC,gBAAgB,GAAGH,eAAe,CAACI,QAAQ;AAExD,SAASC,WAAWA,CAAA;EAClB,OAAOR,KAAK,CAACS,UAAU,CAACN,eAAe,CAAC,IAAI,EAAE;AAChD;AAEA;;;AAGA,OAAM,SAAUO,gBAAgBA,CAAA;EAC9BT,sBAAsB,CAACU,OAAO,GAAG,CAAC;AACpC;AAEA;;;;;;;;AAQA,OAAM,SAAUC,KAAKA,CAACC,MAAA,GAAiB,MAAM,EAAEC,UAAmB;EAChE,MAAMC,YAAY,GAAGb,aAAa,EAAE;EACpC,MAAMc,QAAQ,GAAGR,WAAW,EAAE;EAE9B;EACA;EACA,MAAMS,MAAM,GAAIjB,KAAe,CAAC,KAAK,GAAG,IAAI,CAA+B;EAE3E,IAAIiB,MAAM,EAAE;IACV,MAAMC,WAAW,GAAGD,MAAM,EAAE;IAE5B;IACA,MAAME,SAAS,GAAGnB,KAAK,CAACoB,OAAO,CAAC,MAAMF,WAAW,CAACG,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAACH,WAAW,CAAC,CAAC;IAEnF,OAAOJ,UAAU,IAAI,GAAGE,QAAQ,GAAGH,MAAM,GAAGM,SAAS,EAAE;;EAGzD;EACA;EACA;EACA,OAAOnB,KAAK,CAACoB,OAAO,CAAC,MAAK;IACxB,IAAIN,UAAU,EAAE;MACd,OAAOA,UAAU;;IAGnB,OAAO,GAAGE,QAAQ,GAAGH,MAAM,GAAG,EAAEE,YAAY,CAACJ,OAAO,EAAE;EACxD,CAAC,EAAE,CAACK,QAAQ,EAAEH,MAAM,EAAEC,UAAU,EAAEC,YAAY,CAAC,CAAC;AAClD"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,QAAQ,cAAc;AAExC;;;;;;;;;AASA;AACA,OAAO,MAAMC,yBAAyB,GAA2B,sBAAS,EAAE,GAAGF,KAAK,CAACG,eAAe,GAAGH,KAAK,CAACI,SAAS","names":["React","canUseDOM","useIsomorphicLayoutEffect","useLayoutEffect","useEffect"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useIsomorphicLayoutEffect.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"]}
1
+ {"version":3,"names":["React","canUseDOM","useIsomorphicLayoutEffect","useLayoutEffect","useEffect"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useIsomorphicLayoutEffect.ts"],"sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from '../ssr/index';\n\n/**\n * React currently throws a warning when using useLayoutEffect on the server. To get around it, we can conditionally\n * useEffect on the server (no-op) and useLayoutEffect in the browser. We occasionally need useLayoutEffect to\n * ensure we don't get a render flash for certain operations, but we may also need affected components to render on\n * the server.\n *\n * https://gist.github.com/gaearon/e7d97cdf38a2907924ea12e4ebdf3c85\n * https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js\n */\n// eslint-disable-next-line no-restricted-properties\nexport const useIsomorphicLayoutEffect: typeof React.useEffect = canUseDOM() ? React.useLayoutEffect : React.useEffect;\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,SAAS,QAAQ,cAAc;AAExC;;;;;;;;;AASA;AACA,OAAO,MAAMC,yBAAyB,GAA2B,aAAAD,SAAS,EAAE,GAAGD,KAAK,CAACG,eAAe,GAAGH,KAAK,CAACI,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAQ9B;;;;;;AAMA,OAAM,SAAUC,aAAa,CAAI,GAAGC,IAAkC;EACpE,MAAMC,cAAc,GAA0BH,KAAK,CAACI,WAAW,CAC5DC,KAAQ,IAAI;IACX;IACEF,cAAwD,CAACG,OAAO,GAAGD,KAAK;IAE1E,KAAK,MAAME,GAAG,IAAIL,IAAI,EAAE;MACtB,IAAI,OAAOK,GAAG,KAAK,UAAU,EAAE;QAC7BA,GAAG,CAACF,KAAK,CAAC;OACX,MAAM,IAAIE,GAAG,EAAE;QACd;QACEA,GAA6C,CAACD,OAAO,GAAGD,KAAK;;;EAGrE,CAAC;EACD;EACA,CAAC,GAAGH,IAAI,CAAC,CAC0B;EAErC,OAAOC,cAAc;AACvB","names":["React","useMergedRefs","refs","mergedCallback","useCallback","value","current","ref"],"sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = (React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n ((mergedCallback as unknown) as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n ((ref as unknown) as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown) as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"]}
1
+ {"version":3,"names":["React","useMergedRefs","refs","mergedCallback","useCallback","value","current","ref"],"sources":["../src/packages/react-components/react-utilities/src/hooks/useMergedRefs.ts"],"sourcesContent":["import * as React from 'react';\n\n/**\n * A Ref function which can be treated like a ref object in that it has an attached\n * current property, which will be updated as the ref is evaluated.\n */\nexport type RefObjectFunction<T> = React.RefObject<T> & ((value: T) => void);\n\n/**\n * React hook to merge multiple React refs (either MutableRefObjects or ref callbacks) into a single ref callback that\n * updates all provided refs\n * @param refs - Refs to collectively update with one ref value.\n * @returns A function with an attached \"current\" prop, so that it can be treated like a RefObject.\n */\nexport function useMergedRefs<T>(...refs: (React.Ref<T> | undefined)[]): RefObjectFunction<T> {\n const mergedCallback: RefObjectFunction<T> = React.useCallback(\n (value: T) => {\n // Update the \"current\" prop hanging on the function.\n (mergedCallback as unknown as React.MutableRefObject<T>).current = value;\n\n for (const ref of refs) {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref) {\n // work around the immutability of the React.Ref type\n (ref as unknown as React.MutableRefObject<T>).current = value;\n }\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps -- already exhaustive\n [...refs],\n ) as unknown as RefObjectFunction<T>;\n\n return mergedCallback;\n}\n"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAQ9B;;;;;;AAMA,OAAM,SAAUC,aAAaA,CAAI,GAAGC,IAAkC;EACpE,MAAMC,cAAc,GAAyBH,KAAK,CAACI,WAAW,CAC3DC,KAAQ,IAAI;IACX;IACCF,cAAuD,CAACG,OAAO,GAAGD,KAAK;IAExE,KAAK,MAAME,GAAG,IAAIL,IAAI,EAAE;MACtB,IAAI,OAAOK,GAAG,KAAK,UAAU,EAAE;QAC7BA,GAAG,CAACF,KAAK,CAAC;OACX,MAAM,IAAIE,GAAG,EAAE;QACd;QACCA,GAA4C,CAACD,OAAO,GAAGD,KAAK;;;EAGnE,CAAC;EACD;EACA,CAAC,GAAGH,IAAI,CAAC,CACyB;EAEpC,OAAOC,cAAc;AACvB"}
@@ -13,7 +13,7 @@ export const useOnClickOutside = options => {
13
13
  contains: containsProp
14
14
  } = options;
15
15
  const timeoutId = React.useRef(undefined);
16
- useIFrameFocus(!disabled, element, callback);
16
+ useIFrameFocus(options);
17
17
  const listener = useEventCallback(ev => {
18
18
  const contains = containsProp || ((parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
19
19
  const isOutside = refs.every(ref => !contains(ref.current || null, ev.target));
@@ -75,31 +75,37 @@ const FUI_FRAME_EVENT = 'fuiframefocus';
75
75
  *
76
76
  * Polls the value of `document.activeElement`. If it is an iframe, then dispatch
77
77
  * a custom DOM event. When the custom event is received call the provided callback
78
- *
79
- * @param enableFrameFocusDispatch - boolean flag to start dispatching events
80
- * @param targetDocument - the document to dispatch events and set timeouts
81
- * @param pollDuration - in milliseconds
82
78
  */
83
- const useIFrameFocus = (enableFrameFocusDispatch, targetDocument, callback, pollDuration = 1000) => {
79
+ const useIFrameFocus = options => {
80
+ const {
81
+ disabled,
82
+ element: targetDocument,
83
+ callback,
84
+ contains: containsProp = (parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)),
85
+ pollDuration = 1000,
86
+ refs
87
+ } = options;
84
88
  const timeoutRef = React.useRef();
85
89
  const listener = useEventCallback(e => {
86
- if (callback) {
90
+ const contains = containsProp || ((parent, child) => !!(parent === null || parent === void 0 ? void 0 : parent.contains(child)));
91
+ const isOutside = refs.every(ref => !contains(ref.current || null, e.target));
92
+ if (isOutside && !disabled) {
87
93
  callback(e);
88
94
  }
89
95
  });
90
96
  // Adds listener to the custom iframe focus event
91
97
  React.useEffect(() => {
92
- if (enableFrameFocusDispatch) {
98
+ if (!disabled) {
93
99
  targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener(FUI_FRAME_EVENT, listener, true);
100
+ return () => {
101
+ targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
102
+ };
94
103
  }
95
- return () => {
96
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener(FUI_FRAME_EVENT, listener, true);
97
- };
98
- }, [targetDocument, enableFrameFocusDispatch, listener]);
104
+ }, [targetDocument, disabled, listener]);
99
105
  // Starts polling for the active element
100
106
  React.useEffect(() => {
101
107
  var _a;
102
- if (enableFrameFocusDispatch) {
108
+ if (!disabled) {
103
109
  timeoutRef.current = (_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.setInterval(() => {
104
110
  const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
105
111
  if ((activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'IFRAME' || (activeElement === null || activeElement === void 0 ? void 0 : activeElement.tagName) === 'WEBVIEW') {
@@ -114,6 +120,6 @@ const useIFrameFocus = (enableFrameFocusDispatch, targetDocument, callback, poll
114
120
  var _a;
115
121
  (_a = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView) === null || _a === void 0 ? void 0 : _a.clearTimeout(timeoutRef.current);
116
122
  };
117
- }, [targetDocument, enableFrameFocusDispatch, pollDuration]);
123
+ }, [targetDocument, disabled, pollDuration]);
118
124
  };
119
125
  //# sourceMappingURL=useOnClickOutside.js.map