@fluentui/react-utilities 9.2.1 → 9.3.0

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 (158) hide show
  1. package/CHANGELOG.json +60 -1
  2. package/CHANGELOG.md +21 -2
  3. package/dist/index.d.ts +17 -8
  4. package/lib/compose/getSlots.js.map +1 -1
  5. package/lib/compose/index.js.map +1 -1
  6. package/lib/compose/isResolvedShorthand.js.map +1 -1
  7. package/lib/compose/resolveShorthand.js.map +1 -1
  8. package/lib/compose/types.js.map +1 -1
  9. package/lib/hooks/index.js.map +1 -1
  10. package/lib/hooks/useControllableState.js.map +1 -1
  11. package/lib/hooks/useEventCallback.js.map +1 -1
  12. package/lib/hooks/useFirstMount.js.map +1 -1
  13. package/lib/hooks/useForceUpdate.js.map +1 -1
  14. package/lib/hooks/useId.js.map +1 -1
  15. package/lib/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  16. package/lib/hooks/useMergedRefs.js.map +1 -1
  17. package/lib/hooks/useOnClickOutside.js.map +1 -1
  18. package/lib/hooks/useOnScrollOutside.js.map +1 -1
  19. package/lib/hooks/usePrevious.js.map +1 -1
  20. package/lib/hooks/useTimeout.js.map +1 -1
  21. package/lib/index.js +1 -1
  22. package/lib/index.js.map +1 -1
  23. package/lib/ssr/SSRContext.js.map +1 -1
  24. package/lib/ssr/canUseDOM.js.map +1 -1
  25. package/lib/ssr/index.js.map +1 -1
  26. package/lib/trigger/applyTriggerPropsToChildren.js.map +1 -1
  27. package/lib/trigger/getTriggerChild.js.map +1 -1
  28. package/lib/trigger/index.js.map +1 -1
  29. package/lib/trigger/isFluentTrigger.js.map +1 -1
  30. package/lib/trigger/types.js.map +1 -1
  31. package/lib/utils/clamp.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/index.js +2 -1
  36. package/lib/utils/index.js.map +1 -1
  37. package/lib/utils/isHTMLElement.js +15 -0
  38. package/lib/utils/isHTMLElement.js.map +1 -0
  39. package/lib/utils/isInteractiveHTMLElement.js +26 -0
  40. package/lib/utils/isInteractiveHTMLElement.js.map +1 -0
  41. package/lib/utils/mergeCallbacks.js.map +1 -1
  42. package/lib/utils/omit.js.map +1 -1
  43. package/lib/utils/properties.js +1 -1
  44. package/lib/utils/properties.js.map +1 -1
  45. package/lib-amd/compose/getSlots.js +58 -0
  46. package/lib-amd/compose/getSlots.js.map +1 -0
  47. package/lib-amd/compose/index.js +9 -0
  48. package/lib-amd/compose/index.js.map +1 -0
  49. package/lib-amd/compose/isResolvedShorthand.js +40 -0
  50. package/lib-amd/compose/isResolvedShorthand.js.map +1 -0
  51. package/lib-amd/compose/resolveShorthand.js +27 -0
  52. package/lib-amd/compose/resolveShorthand.js.map +1 -0
  53. package/lib-amd/compose/types.js +5 -0
  54. package/lib-amd/compose/types.js.map +1 -0
  55. package/lib-amd/hooks/index.js +16 -0
  56. package/lib-amd/hooks/index.js.map +1 -0
  57. package/lib-amd/hooks/useControllableState.js +81 -0
  58. package/lib-amd/hooks/useControllableState.js.map +1 -0
  59. package/lib-amd/hooks/useEventCallback.js +36 -0
  60. package/lib-amd/hooks/useEventCallback.js.map +1 -0
  61. package/lib-amd/hooks/useFirstMount.js +26 -0
  62. package/lib-amd/hooks/useFirstMount.js.map +1 -0
  63. package/lib-amd/hooks/useForceUpdate.js +14 -0
  64. package/lib-amd/hooks/useForceUpdate.js.map +1 -0
  65. package/lib-amd/hooks/useId.js +32 -0
  66. package/lib-amd/hooks/useId.js.map +1 -0
  67. package/lib-amd/hooks/useIsomorphicLayoutEffect.js +17 -0
  68. package/lib-amd/hooks/useIsomorphicLayoutEffect.js.map +1 -0
  69. package/lib-amd/hooks/useMergedRefs.js +34 -0
  70. package/lib-amd/hooks/useMergedRefs.js.map +1 -0
  71. package/lib-amd/hooks/useOnClickOutside.js +116 -0
  72. package/lib-amd/hooks/useOnClickOutside.js.map +1 -0
  73. package/lib-amd/hooks/useOnScrollOutside.js +31 -0
  74. package/lib-amd/hooks/useOnScrollOutside.js.map +1 -0
  75. package/lib-amd/hooks/usePrevious.js +17 -0
  76. package/lib-amd/hooks/usePrevious.js.map +1 -0
  77. package/lib-amd/hooks/useTimeout.js +33 -0
  78. package/lib-amd/hooks/useTimeout.js.map +1 -0
  79. package/lib-amd/index.js +34 -0
  80. package/lib-amd/index.js.map +1 -0
  81. package/lib-amd/ssr/SSRContext.js +69 -0
  82. package/lib-amd/ssr/SSRContext.js.map +1 -0
  83. package/lib-amd/ssr/canUseDOM.js +16 -0
  84. package/lib-amd/ssr/canUseDOM.js.map +1 -0
  85. package/lib-amd/ssr/index.js +7 -0
  86. package/lib-amd/ssr/index.js.map +1 -0
  87. package/lib-amd/trigger/applyTriggerPropsToChildren.js +40 -0
  88. package/lib-amd/trigger/applyTriggerPropsToChildren.js.map +1 -0
  89. package/lib-amd/trigger/getTriggerChild.js +40 -0
  90. package/lib-amd/trigger/getTriggerChild.js.map +1 -0
  91. package/lib-amd/trigger/index.js +9 -0
  92. package/lib-amd/trigger/index.js.map +1 -0
  93. package/lib-amd/trigger/isFluentTrigger.js +15 -0
  94. package/lib-amd/trigger/isFluentTrigger.js.map +1 -0
  95. package/lib-amd/trigger/types.js +5 -0
  96. package/lib-amd/trigger/types.js.map +1 -0
  97. package/lib-amd/utils/clamp.js +16 -0
  98. package/lib-amd/utils/clamp.js.map +1 -0
  99. package/lib-amd/utils/getNativeElementProps.js +64 -0
  100. package/lib-amd/utils/getNativeElementProps.js.map +1 -0
  101. package/lib-amd/utils/getRTLSafeKey.js +24 -0
  102. package/lib-amd/utils/getRTLSafeKey.js.map +1 -0
  103. package/lib-amd/utils/index.js +13 -0
  104. package/lib-amd/utils/index.js.map +1 -0
  105. package/lib-amd/utils/isHTMLElement.js +22 -0
  106. package/lib-amd/utils/isHTMLElement.js.map +1 -0
  107. package/lib-amd/utils/isInteractiveHTMLElement.js +25 -0
  108. package/lib-amd/utils/isInteractiveHTMLElement.js.map +1 -0
  109. package/lib-amd/utils/mergeCallbacks.js +40 -0
  110. package/lib-amd/utils/mergeCallbacks.js.map +1 -0
  111. package/lib-amd/utils/omit.js +31 -0
  112. package/lib-amd/utils/omit.js.map +1 -0
  113. package/lib-amd/utils/properties.js +450 -0
  114. package/lib-amd/utils/properties.js.map +1 -0
  115. package/lib-commonjs/compose/getSlots.js.map +1 -1
  116. package/lib-commonjs/compose/index.js.map +1 -1
  117. package/lib-commonjs/compose/isResolvedShorthand.js.map +1 -1
  118. package/lib-commonjs/compose/resolveShorthand.js.map +1 -1
  119. package/lib-commonjs/hooks/index.js.map +1 -1
  120. package/lib-commonjs/hooks/useControllableState.js.map +1 -1
  121. package/lib-commonjs/hooks/useEventCallback.js.map +1 -1
  122. package/lib-commonjs/hooks/useFirstMount.js.map +1 -1
  123. package/lib-commonjs/hooks/useForceUpdate.js.map +1 -1
  124. package/lib-commonjs/hooks/useId.js.map +1 -1
  125. package/lib-commonjs/hooks/useIsomorphicLayoutEffect.js.map +1 -1
  126. package/lib-commonjs/hooks/useMergedRefs.js.map +1 -1
  127. package/lib-commonjs/hooks/useOnClickOutside.js.map +1 -1
  128. package/lib-commonjs/hooks/useOnScrollOutside.js.map +1 -1
  129. package/lib-commonjs/hooks/usePrevious.js.map +1 -1
  130. package/lib-commonjs/hooks/useTimeout.js.map +1 -1
  131. package/lib-commonjs/index.js +9 -3
  132. package/lib-commonjs/index.js.map +1 -1
  133. package/lib-commonjs/ssr/SSRContext.js.map +1 -1
  134. package/lib-commonjs/ssr/canUseDOM.js.map +1 -1
  135. package/lib-commonjs/ssr/index.js.map +1 -1
  136. package/lib-commonjs/trigger/applyTriggerPropsToChildren.js.map +1 -1
  137. package/lib-commonjs/trigger/getTriggerChild.js.map +1 -1
  138. package/lib-commonjs/trigger/index.js.map +1 -1
  139. package/lib-commonjs/trigger/isFluentTrigger.js.map +1 -1
  140. package/lib-commonjs/utils/clamp.js.map +1 -1
  141. package/lib-commonjs/utils/getNativeElementProps.js.map +1 -1
  142. package/lib-commonjs/utils/getRTLSafeKey.js.map +1 -1
  143. package/lib-commonjs/utils/getReactCallbackName.js.map +1 -1
  144. package/lib-commonjs/utils/index.js +3 -1
  145. package/lib-commonjs/utils/index.js.map +1 -1
  146. package/lib-commonjs/utils/isHTMLElement.js +24 -0
  147. package/lib-commonjs/utils/isHTMLElement.js.map +1 -0
  148. package/lib-commonjs/utils/isInteractiveHTMLElement.js +36 -0
  149. package/lib-commonjs/utils/isInteractiveHTMLElement.js.map +1 -0
  150. package/lib-commonjs/utils/mergeCallbacks.js.map +1 -1
  151. package/lib-commonjs/utils/omit.js.map +1 -1
  152. package/lib-commonjs/utils/properties.js +1 -1
  153. package/lib-commonjs/utils/properties.js.map +1 -1
  154. package/package.json +3 -4
  155. package/lib/utils/shouldPreventDefaultOnKeyDown.js +0 -25
  156. package/lib/utils/shouldPreventDefaultOnKeyDown.js.map +0 -1
  157. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js +0 -35
  158. package/lib-commonjs/utils/shouldPreventDefaultOnKeyDown.js.map +0 -1
package/CHANGELOG.json CHANGED
@@ -2,7 +2,66 @@
2
2
  "name": "@fluentui/react-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 11 Nov 2022 14:53:36 GMT",
5
+ "date": "Tue, 20 Dec 2022 14:55:58 GMT",
6
+ "tag": "@fluentui/react-utilities_v9.3.0",
7
+ "version": "9.3.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "bernardo.sunderhus@gmail.com",
12
+ "package": "@fluentui/react-utilities",
13
+ "commit": "f3e6e65b7f6435dc6b09bfd626e99921a10983d8",
14
+ "comment": "feat: isHTMLElement helper function"
15
+ },
16
+ {
17
+ "author": "lingfangao@hotmail.com",
18
+ "package": "@fluentui/react-utilities",
19
+ "commit": "dc96e9c54ac445396cd5e74812fd2ac1acdd15eb",
20
+ "comment": "feat: replace shouldPreventKeydown with isInteractiveHTMLElement"
21
+ }
22
+ ]
23
+ }
24
+ },
25
+ {
26
+ "date": "Mon, 05 Dec 2022 18:29:39 GMT",
27
+ "tag": "@fluentui/react-utilities_v9.2.2",
28
+ "version": "9.2.2",
29
+ "comments": {
30
+ "none": [
31
+ {
32
+ "author": "tristan.watanabe@gmail.com",
33
+ "package": "@fluentui/react-utilities",
34
+ "commit": "109f6e6966ce703169c98134f1aedbaec17d6f93",
35
+ "comment": "chore: Migrate to new package structure."
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ {
41
+ "date": "Thu, 17 Nov 2022 23:05:30 GMT",
42
+ "tag": "@fluentui/react-utilities_v9.2.2",
43
+ "version": "9.2.2",
44
+ "comments": {
45
+ "none": [
46
+ {
47
+ "author": "martinhochel@microsoft.com",
48
+ "package": "@fluentui/react-utilities",
49
+ "commit": "ea768501802d65d63ddc63fff3816fb6b5008ae4",
50
+ "comment": "chore: update package scaffold"
51
+ }
52
+ ],
53
+ "patch": [
54
+ {
55
+ "author": "bernardo.sunderhus@gmail.com",
56
+ "package": "@fluentui/react-utilities",
57
+ "commit": "5ca29f62f68fdce6e127f6ef61ecf36416a68478",
58
+ "comment": "fix: supports colSpan property for th"
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ {
64
+ "date": "Fri, 11 Nov 2022 14:57:49 GMT",
6
65
  "tag": "@fluentui/react-utilities_v9.2.1",
7
66
  "version": "9.2.1",
8
67
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,31 @@
1
1
  # Change Log - @fluentui/react-utilities
2
2
 
3
- This log was last generated on Fri, 11 Nov 2022 14:53:36 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 20 Dec 2022 14:55:58 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.3.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.3.0)
8
+
9
+ Tue, 20 Dec 2022 14:55:58 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.2.2..@fluentui/react-utilities_v9.3.0)
11
+
12
+ ### Minor changes
13
+
14
+ - feat: isHTMLElement helper function ([PR #25891](https://github.com/microsoft/fluentui/pull/25891) by bernardo.sunderhus@gmail.com)
15
+ - feat: replace shouldPreventKeydown with isInteractiveHTMLElement ([PR #25942](https://github.com/microsoft/fluentui/pull/25942) by lingfangao@hotmail.com)
16
+
17
+ ## [9.2.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.2.2)
18
+
19
+ Thu, 17 Nov 2022 23:05:30 GMT
20
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.2.1..@fluentui/react-utilities_v9.2.2)
21
+
22
+ ### Patches
23
+
24
+ - fix: supports colSpan property for th ([PR #25613](https://github.com/microsoft/fluentui/pull/25613) by bernardo.sunderhus@gmail.com)
25
+
7
26
  ## [9.2.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-utilities_v9.2.1)
8
27
 
9
- Fri, 11 Nov 2022 14:53:36 GMT
28
+ Fri, 11 Nov 2022 14:57:49 GMT
10
29
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-utilities_v9.2.0..@fluentui/react-utilities_v9.2.1)
11
30
 
12
31
  ### Patches
package/dist/index.d.ts CHANGED
@@ -188,6 +188,23 @@ declare type IntrisicElementProps<Type extends keyof JSX.IntrinsicElements> = Re
188
188
  */
189
189
  export declare function isFluentTrigger(element: React_2.ReactElement): element is React_2.ReactElement<TriggerProps>;
190
190
 
191
+ /**
192
+ * @internal
193
+ * Verifies if a given node is an HTMLElement,
194
+ * this method works seamlessly with frames and elements from different documents
195
+ *
196
+ * This is required as simply using `instanceof`
197
+ * might be problematic while operating with [multiple realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms)
198
+ *
199
+ */
200
+ export declare function isHTMLElement(element?: Node | null | undefined): element is HTMLElement;
201
+
202
+ /**
203
+ * @internal
204
+ * Checks that the element has default behaviour from user input on click or 'Enter'/'Space' keys
205
+ */
206
+ export declare function isInteractiveHTMLElement(element: Node | null | undefined): boolean;
207
+
191
208
  /**
192
209
  * Guard method that validates if a shorthand is a slot
193
210
  * can be used to extends properties provided by a slot
@@ -318,14 +335,6 @@ export declare type ResolveShorthandOptions<Props, Required extends boolean = fa
318
335
  defaultProps?: Props;
319
336
  };
320
337
 
321
- /**
322
- * @internal
323
- * Checks if the keyboard event should preventDefault() for Enter and Spacebar keys
324
- *
325
- * Useful for situations where a keydown needs to be transformed to a click event
326
- */
327
- export declare function shouldPreventDefaultOnKeyDown(e: KeyboardEvent | React_2.KeyboardEvent): boolean;
328
-
329
338
  /**
330
339
  * The props type and shorthand value for a slot. Type is either a single intrinsic element like `'div'`,
331
340
  * or a component like `typeof Button`.
@@ -1 +1 @@
1
- {"version":3,"sources":["compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,IAAT,QAAqB,eAArB;AA6BA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EACoB;EAKxB,MAAM,KAAK,GAAG,EAAd;EACA,MAAM,SAAS,GAAG,EAAlB;EAEA,MAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;EACA,KAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;IAChC,MAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;IACA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;IACA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;EACD;;EACD,OAAO;IAAE,KAAF;IAAS,SAAS,EAAG;EAArB,CAAP;AACD;;AAED,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;EAEX,IAAI,KAAK,CAAC,QAAD,CAAL,KAAoB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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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/compose/getSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA,SAAS,IAAT,QAAqB,eAArB;AA6BA;;;;;;;;;;;;;;;;AAgBG;;AACH,OAAM,SAAU,QAAV,CACJ,KADI,EACoB;EAKxB,MAAM,KAAK,GAAG,EAAd;EACA,MAAM,SAAS,GAAG,EAAlB;EAEA,MAAM,SAAS,GAAgB,MAAM,CAAC,IAAP,CAAY,KAAK,CAAC,UAAlB,CAA/B;;EACA,KAAK,MAAM,QAAX,IAAuB,SAAvB,EAAkC;IAChC,MAAM,CAAC,IAAD,EAAO,KAAP,IAAgB,OAAO,CAAC,KAAD,EAAQ,QAAR,CAA7B;IACA,KAAK,CAAC,QAAD,CAAL,GAAkB,IAAlB;IACA,SAAS,CAAC,QAAD,CAAT,GAAsB,KAAtB;EACD;;EACD,OAAO;IAAE,KAAF;IAAS,SAAS,EAAG;EAArB,CAAP;AACD;;AAED,SAAS,OAAT,CACE,KADF,EAEE,QAFF,EAEa;;;EAEX,IAAI,KAAK,CAAC,QAAD,CAA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{ 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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/compose/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC","sourcesContent":["export * from './getSlots';\nexport * from './resolveShorthand';\nexport * from './types';\nexport * from './isResolvedShorthand';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["compose/isResolvedShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;;AACH,OAAM,SAAU,mBAAV,CACJ,SADI,EACiB;EAErB,OAAO,SAAS,KAAK,IAAd,IAAsB,OAAO,SAAP,KAAqB,QAA3C,IAAuD,CAAC,KAAK,CAAC,OAAN,CAAc,SAAd,CAAxD,IAAoF,eAAC,cAAc,CAAC,SAAD,CAA1G;AACD","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/compose/isResolvedShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;;AACH,OAAM,SAAU,mBAAV,CACJ,SADI,EACiB;EAErB,OAAO,SAAS,KAAK,IAAd,IAAsB,OAAO,SAAP,KAAqB,QAA3C,IAAuD,CAAC,KAAK,CAAC,OAAN,CAAc,SAAd,CAAxD,IAAoF,eAAC,cAAc,CAAC,SAAD,CAA1G;AACD","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["compose/resolveShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAkBA;;;;;AAKG;;AACH,OAAO,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;EAC3E,MAAM;IAAE,QAAQ,GAAG,KAAb;IAAoB;EAApB,IAAqC,OAAO,IAAI,EAAtD;;EACA,IAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;IACxD,OAAO,SAAP;EACD;;EAED,IAAI,iBAAiB,GAAG,EAAxB;;EAEA,IAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,iBAAkF,cAAc,CAAC,KAAD,CAApG,EAA6G;IAC3G,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;EACD,CAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;IACpC,iBAAiB,GAAG,KAApB;EACD;;EAED,OAAO,YAAY,GAAG,EAAE,GAAG,YAAL;IAAmB,GAAG;EAAtB,CAAH,GAA+C,iBAAlE;AACD,CAfM","sourcesContent":["import { isValidElement } from 'react';\nimport type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = {\n required?: Required;\n defaultProps?: Props;\n};\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props | null>(\n value: P | SlotShorthandValue | undefined,\n options?: ResolveShorthandOptions<P, true>,\n ): ReplaceNullWithUndefined<P>;\n <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | ReplaceNullWithUndefined<P>\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand = {} as UnknownSlotProps;\n\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n return defaultProps ? { ...defaultProps, ...resolvedShorthand } : resolvedShorthand;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/compose/resolveShorthand.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAA+B,OAA/B;AAkBA;;;;;AAKG;;AACH,OAAO,MAAM,gBAAgB,GAA6B,CAAC,KAAD,EAAQ,OAAR,KAAmB;EAC3E,MAAM;IAAE,QAAQ,GAAG,KAAb;IAAoB;EAApB,IAAqC,OAAO,IAAI,EAAtD;;EACA,IAAI,KAAK,KAAK,IAAV,IAAmB,KAAK,KAAK,SAAV,IAAuB,CAAC,QAA/C,EAA0D;IACxD,OAAO,SAAP;EACD;;EAED,IAAI,iBAAiB,GAAG,EAAxB;;EAEA,IAAI,OAAO,KAAP,KAAiB,QAAjB,IAA6B,OAAO,KAAP,KAAiB,QAA9C,IAA0D,KAAK,CAAC,OAAN,CAAc,KAAd,CAA1D,iBAAkF,cAAc,CAAC,KAAD,CAApG,EAA6G;IAC3G,iBAAiB,CAAC,QAAlB,GAA6B,KAA7B;EACD,CAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;IACpC,iBAAiB,GAAG,KAApB;EACD;;EAED,OAAO,YAAY,GAAG,EAAE,GAAG,YAAL;IAAmB,GAAG;EAAtB,CAAH,GAA+C,iBAAlE;AACD,CAfM","sourcesContent":["import { isValidElement } from 'react';\nimport type { ReplaceNullWithUndefined, SlotShorthandValue, UnknownSlotProps } from './types';\n\nexport type ResolveShorthandOptions<Props, Required extends boolean = false> = {\n required?: Required;\n defaultProps?: Props;\n};\n\nexport type ResolveShorthandFunction<Props extends UnknownSlotProps = UnknownSlotProps> = {\n <P extends Props | null>(\n value: P | SlotShorthandValue | undefined,\n options?: ResolveShorthandOptions<P, true>,\n ): ReplaceNullWithUndefined<P>;\n <P extends Props | null>(value: P | SlotShorthandValue | undefined, options?: ResolveShorthandOptions<P, boolean>):\n | ReplaceNullWithUndefined<P>\n | undefined;\n};\n\n/**\n * Resolves shorthands into slot props, to ensure normalization of the signature\n * being passed down to getSlots method\n * @param value - the base shorthand props\n * @param options - options to resolve shorthand props\n */\nexport const resolveShorthand: ResolveShorthandFunction = (value, options) => {\n const { required = false, defaultProps } = options || {};\n if (value === null || (value === undefined && !required)) {\n return undefined;\n }\n\n let resolvedShorthand = {} as UnknownSlotProps;\n\n if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value) || isValidElement(value)) {\n resolvedShorthand.children = value;\n } else if (typeof value === 'object') {\n resolvedShorthand = value;\n }\n\n return defaultProps ? { ...defaultProps, ...resolvedShorthand } : resolvedShorthand;\n};\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["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 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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC","sourcesContent":["export * from './useControllableState';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useForceUpdate';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC","sourcesContent":["export * from './useControllableState';\nexport * from './useEventCallback';\nexport * from './useFirstMount';\nexport * from './useForceUpdate';\nexport * from './useId';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMergedRefs';\nexport * from './useOnClickOutside';\nexport * from './useOnScrollOutside';\nexport * from './usePrevious';\nexport * from './useTimeout';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;;AAqBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;EACrE,OAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;;;;;;;;;;;;AAeG;;;AACH,OAAO,MAAM,oBAAoB,GAC/B,OADkC,IAEsB;EACxD,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,KAAT,CAApC;EACA,MAAM,YAAY,GAAG,OAAO,OAAO,CAAC,YAAf,KAAgC,WAAhC,GAA8C,OAAO,CAAC,YAAtD,GAAqE,OAAO,CAAC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D;;QACA,OAAO,CAAC,KAAR,CACE,CACE;QACA,6BAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;MAUD;IACF,CAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;EAuBD;;EAED,OAAO,YAAP;AACD,CAhCD","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useControllableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;;AAqBA,SAAS,iBAAT,CAAkC,QAAlC,EAAuE;EACrE,OAAO,OAAO,QAAP,KAAoB,UAA3B;AACD;AAED;;;;;;;;;;;;;;;AAeG;;;AACH,OAAO,MAAM,oBAAoB,GAC/B,OADkC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ACpD,MAAM,KAAK,GAAG,IAAI,KAAJ,EAAd;QAEA,MAAM,cAAc,GAAG,YAAY,GAC/B,uCAD+B,GAE/B,wCAFJ;QAIA,MAAM,gBAAgB,GAAG,YAAY,GAAG,yBAAH,GAA+B,wBAApE,CAPoD,CASpD;;QACA,OAAO,CAAC,KAAR,CACE,CACE;QACA,6BAA6B,cAA7B,GAA8C,sCAFhD,EAGE,mBAAmB,gBAAnB,GAAsC,kCAHxC,EAIE,oGAJF,EAKE,2DALF,EAME,KAAK,CAAC,KANR,EAOE,IAPF,CAOO,GAPP,CADF;MAUD;IACF,CAtBD,EAsBG,CAAC,YAAD,EAAe,eAAf,CAtBH;EAuBD;;EAED,OAAO,YAAP;AACD,CAhCD","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;;;;;;;;;;;AAYG;;AACH,OAAO,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;EAChG,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;IAC/C,MAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;EACD,CAFmB,CAApB;EAIA,yBAAyB,CAAC,MAAK;IAC7B,WAAW,CAAC,OAAZ,GAAsB,EAAtB;EACD,CAFwB,EAEtB,CAAC,EAAD,CAFsB,CAAzB;EAIA,OAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;IAChB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;IACA,OAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;EACD,CAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useEventCallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,yBAAT,QAA0C,6BAA1C;AAEA;;;;;;;;;;;;AAYG;;AACH,OAAO,MAAM,gBAAgB,GAAoC,EAAjC,IAAkE;EAChG,MAAM,WAAW,GAAG,KAAK,CAAC,MAAN,CAAwB,MAAK;IAC/C,MAAM,IAAI,KAAJ,CAAU,8CAAV,CAAN;EACD,CAFmB,CAApB;EAIA,yBAAyB,CAAC,MAAK;IAC7B,WAAW,CAAC,OAAZ,GAAsB,EAAtB;EACD,CAFwB,EAEtB,CAAC,EAAD,CAFsB,CAAzB;EAIA,OAAO,KAAK,CAAC,WAAN,CACL,CAAC,GAAG,IAAJ,KAAkB;IAChB,MAAM,QAAQ,GAAG,WAAW,CAAC,OAA7B;IACA,OAAO,QAAQ,CAAC,GAAG,IAAJ,CAAf;EACD,CAJI,EAKL,CAAC,WAAD,CALK,CAAP;AAOD,CAhBM","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useFirstMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;;AAUG;;AACH,OAAM,SAAU,aAAV,GAAuB;EAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;EAEA,IAAI,OAAO,CAAC,OAAZ,EAAqB;IACnB,OAAO,CAAC,OAAR,GAAkB,KAAlB;IACA,OAAO,IAAP;EACD;;EAED,OAAO,OAAO,CAAC,OAAf;AACD","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useFirstMount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;;;;AAUG;;AACH,OAAM,SAAU,aAAV,GAAuB;EAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAN,CAAa,IAAb,CAAhB;;EAEA,IAAI,OAAO,CAAC,OAAZ,EAAqB;IACnB,OAAO,CAAC,OAAR,GAAkB,KAAlB;IACA,OAAO,IAAP;EACD;;EAED,OAAO,OAAO,CAAC,OAAf;AACD","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useForceUpdate.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,OAA3B;AAEA;;;AAGG;;AACH,OAAM,SAAU,cAAV,GAAwB;EAC5B,OAAO,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAV,EAAa,CAAb,CAAV,CAA0B,CAA1B,CAAP;AACD","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useForceUpdate.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,OAA3B;AAEA;;;AAGG;;AACH,OAAM,SAAU,cAAV,GAAwB;EAC5B,OAAO,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAV,EAAa,CAAb,CAAV,CAA0B,CAA1B,CAAP;AACD","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,sBAAT,EAAiC,aAAjC,QAAsD,cAAtD;AAEA;;AAEG;;AACH,OAAM,SAAU,gBAAV,GAA0B;EAC9B,sBAAsB,CAAC,OAAvB,GAAiC,CAAjC;AACD;AAED;;;;;;;AAOG;;AACH,OAAM,SAAU,KAAV,CAAgB,MAAA,GAAiB,MAAjC,EAAyC,UAAzC,EAA4D;EAChE,MAAM,YAAY,GAAG,aAAa,EAAlC;EAEA,OAAO,KAAK,CAAC,OAAN,CAAc,MAAK;IACxB,IAAI,UAAJ,EAAgB;MACd,OAAO,UAAP;IACD;;IAED,OAAO,GAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAO,EAAzC;EACD,CANM,EAMJ,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CANI,CAAP;AAOD","sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\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\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${prefix}${++contextValue.current}`;\n }, [prefix, providedId, contextValue]);\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useId.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,sBAAT,EAAiC,aAAjC,QAAsD,cAAtD;AAEA;;AAEG;;AACH,OAAM,SAAU,gBAAV,GAA0B;EAC9B,sBAAsB,CAAC,OAAvB,GAAiC,CAAjC;AACD;AAED;;;;;;;AAOG;;AACH,OAAM,SAAU,KAAV,CAAgB,MAAA,GAAiB,MAAjC,EAAyC,UAAzC,EAA4D;EAChE,MAAM,YAAY,GAAG,aAAa,EAAlC;EAEA,OAAO,KAAK,CAAC,OAAN,CAAc,MAAK;IACxB,IAAI,UAAJ,EAAgB;MACd,OAAO,UAAP;IACD;;IAED,OAAO,GAAG,MAAM,GAAG,EAAE,YAAY,CAAC,OAAO,EAAzC;EACD,CANM,EAMJ,CAAC,MAAD,EAAS,UAAT,EAAqB,YAArB,CANI,CAAP;AAOD","sourcesContent":["import * as React from 'react';\nimport { defaultSSRContextValue, useSSRContext } from '../ssr/index';\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\n return React.useMemo(() => {\n if (providedId) {\n return providedId;\n }\n\n return `${prefix}${++contextValue.current}`;\n }, [prefix, providedId, contextValue]);\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,cAA1B;AAEA;;;;;;;;AAQG;AACH;;AACA,OAAO,MAAM,yBAAyB,GAA2B,aAAA,SAAS,KAAK,KAAK,CAAC,eAAX,GAA6B,KAAK,CAAC,SAAtG","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useIsomorphicLayoutEffect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,cAA1B;AAEA;;;;;;;;AAQG;AACH;;AACA,OAAO,MAAM,yBAAyB,GAA2B,aAAA,SAAS,KAAK,KAAK,CAAC,eAAX,GAA6B,KAAK,CAAC,SAAtG","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useMergedRefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAQA;;;;;AAKG;;AACH,OAAM,SAAU,aAAV,CAA2B,GAAG,IAA9B,EAAgE;EACpE,MAAM,cAAc,GAA0B,KAAK,CAAC,WAAN,CAC3C,KAAD,IAAa;IACX;IACE,cAAwD,CAAC,OAAzD,GAAmE,KAAnE;;IAEF,KAAK,MAAM,GAAX,IAAkB,IAAlB,EAAwB;MACtB,IAAI,OAAO,GAAP,KAAe,UAAnB,EAA+B;QAC7B,GAAG,CAAC,KAAD,CAAH;MACD,CAFD,MAEO,IAAI,GAAJ,EAAS;QACd;QACE,GAA6C,CAAC,OAA9C,GAAwD,KAAxD;MACH;IACF;EACF,CAb2C,EAc5C;EACA,CAAC,GAAG,IAAJ,CAf4C,CAA9C;EAkBA,OAAO,cAAP;AACD","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"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useMergedRefs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAQA;;;;;AAKG;;AACH,OAAM,SAAU,aAAV,CAA2B,GAAG,IAA9B,EAAgE;EACpE,MAAM,cAAc,GAA0B,KAAK,CAAC,WAAN,CAC3C,KAAD,IAAa;IACX;IACE,cAAwD,CAAC,OAAzD,GAAmE,KAAnE;;IAEF,KAAK,MAAM,GAAX,IAAkB,IAAlB,EAAwB;MACtB,IAAI,OAAO,GAAP,KAAe,UAAnB,EAA+B;QAC7B,GAAG,CAAC,KAAD,CAAH;MACD,CAFD,MAEO,IAAI,GAAJ,EAAS;QACd;QACE,GAA6C,CAAC,OAA9C,GAAwD,KAAxD;MACH;IACF;EACF,CAb2C,EAc5C;EACA,CAAC,GAAG,IAAJ,CAf4C,CAA9C;EAkBA,OAAO,cAAP;AACD","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"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useOnClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AAiCA;;;AAGG;;AACH,OAAO,MAAM,iBAAiB,GAAI,OAAD,IAA8C;EAC7E,MAAM;IAAE,IAAF;IAAQ,QAAR;IAAkB,OAAlB;IAA2B,QAA3B;IAAqC,QAAQ,EAAE;EAA/C,IAAgE,OAAtE;EACA,MAAM,SAAS,GAAG,KAAK,CAAC,MAAN,CAAiC,SAAjC,CAAlB;EACA,cAAc,CAAC,CAAC,QAAF,EAAY,OAAZ,EAAqB,QAArB,CAAd;EAEA,MAAM,QAAQ,GAAG,gBAAgB,CAAE,EAAD,IAAgC;IAChE,MAAM,QAAQ,GACZ,YAAY,KAAK,CAAC,MAAD,EAAS,KAAT,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,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,aAAtC;;QACA,IAAI,CAAA,aAAa,KAAA,IAAb,IAAA,aAAa,KAAA,KAAA,CAAb,GAAa,KAAA,CAAb,GAAA,aAAa,CAAE,OAAf,MAA2B,QAA3B,IAAuC,CAAA,aAAa,KAAA,IAAb,IAAA,aAAa,KAAA,KAAA,CAAb,GAAa,KAAA,CAAb,GAAA,aAAa,CAAE,OAAf,MAA2B,SAAtE,EAAiF;UAC/E,MAAM,KAAK,GAAG,IAAI,WAAJ,CAAgB,eAAhB,EAAiC;YAAE,OAAO,EAAE;UAAX,CAAjC,CAAd;UACA,aAAa,CAAC,aAAd,CAA4B,KAA5B;QACD;MACF,CAN+C,EAM7C,YAN6C,CAAhD;IAOD;;IACD,OAAO,MAAK;;;MACV,CAAA,EAAA,GAAA,cAAc,KAAA,IAAd,IAAA,cAAc,KAAA,KAAA,CAAd,GAAc,KAAA,CAAd,GAAA,cAAc,CAAE,WAAhB,MAA2B,IAA3B,IAA2B,EAAA,KAAA,KAAA,CAA3B,GAA2B,KAAA,CAA3B,GAA2B,EAAA,CAAE,YAAF,CAAe,UAAU,CAAC,OAA1B,CAA3B;IACD,CAFD;EAGD,CAbD,EAaG,CAAC,cAAD,EAAiB,wBAAjB,EAA2C,YAA3C,CAbH;AAcD,CAvCD","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\n\n/**\n * @internal\n */\nexport type UseOnClickOrScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n * @param parentRef - provided parent ref\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n useIFrameFocus(!disabled, element, callback as (e: Event) => void);\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n if (!disabled) {\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n }\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\n\nconst getWindowEvent = (target: Node | Window): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n *\n * @param enableFrameFocusDispatch - boolean flag to start dispatching events\n * @param targetDocument - the document to dispatch events and set timeouts\n * @param pollDuration - in milliseconds\n */\nconst useIFrameFocus = (\n enableFrameFocusDispatch: boolean,\n targetDocument: Document | undefined,\n callback: (e: Event) => void,\n pollDuration: number = 1000,\n) => {\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n if (callback) {\n callback(e);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n }\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, enableFrameFocusDispatch, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, enableFrameFocusDispatch, pollDuration]);\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useOnClickOutside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AAiCA;;;AAGG;;AACH,OAAO,MAAM,iBAAiB,GAAI,OAAD,IAA8C;EAC7E,MAAM;IAA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ScrollOutsideOptions = {\n /**\n * The element to listen for the click event\n */\n element: Document | undefined;\n /**\n * Refs to elements that check if the click is outside\n */\n refs: React.MutableRefObject<HTMLElement | undefined | null>[];\n\n /**\n * By default uses element.contains, but custom contain function can be provided\n * @param parentRef - provided parent ref\n * @param child - event target element\n */\n contains?(parent: HTMLElement | null, child: HTMLElement): boolean;\n\n /**\n * Disables event listeners\n */\n disabled?: boolean;\n\n /**\n * Called if the click is outside the element refs\n */\n callback: (ev: MouseEvent | TouchEvent) => void;\n};\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnClickOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n const timeoutId = React.useRef<number | undefined>(undefined);\n useIFrameFocus(!disabled, element, callback as (e: Event) => void);\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n // Store the current event to avoid triggering handlers immediately\n // Note this depends on a deprecated but extremely well supported quirk of the web platform\n // https://github.com/facebook/react/issues/20074\n let currentEvent = getWindowEvent(window);\n\n const conditionalHandler = (event: MouseEvent | TouchEvent) => {\n // Skip if this event is the same as the one running when we added the handlers\n if (event === currentEvent) {\n currentEvent = undefined;\n return;\n }\n\n listener(event);\n };\n\n if (!disabled) {\n // use capture phase because React can update DOM before the event bubbles to the document\n element?.addEventListener('click', conditionalHandler, true);\n element?.addEventListener('touchstart', conditionalHandler, true);\n element?.addEventListener('contextmenu', conditionalHandler, true);\n }\n\n // Garbage collect this event after it's no longer useful to avoid memory leaks\n timeoutId.current = window.setTimeout(() => {\n currentEvent = undefined;\n }, 1);\n\n return () => {\n element?.removeEventListener('click', conditionalHandler, true);\n element?.removeEventListener('touchstart', conditionalHandler, true);\n element?.removeEventListener('contextmenu', conditionalHandler, true);\n\n clearTimeout(timeoutId.current);\n currentEvent = undefined;\n };\n }, [listener, element, disabled]);\n};\n\nconst getWindowEvent = (target: Node | Window): Event | undefined => {\n if (target) {\n if (typeof (target as Window).window === 'object' && (target as Window).window === target) {\n // eslint-disable-next-line deprecation/deprecation\n return target.event;\n }\n\n // eslint-disable-next-line deprecation/deprecation\n return (target as Node).ownerDocument?.defaultView?.event ?? undefined;\n }\n\n return undefined;\n};\n\nconst FUI_FRAME_EVENT = 'fuiframefocus';\n\n/**\n * Since click events do not propagate past iframes, we use focus to detect if a\n * click has happened inside an iframe, since the only ways of focusing inside an\n * iframe are:\n * - clicking inside\n * - tabbing inside\n *\n * Polls the value of `document.activeElement`. If it is an iframe, then dispatch\n * a custom DOM event. When the custom event is received call the provided callback\n *\n * @param enableFrameFocusDispatch - boolean flag to start dispatching events\n * @param targetDocument - the document to dispatch events and set timeouts\n * @param pollDuration - in milliseconds\n */\nconst useIFrameFocus = (\n enableFrameFocusDispatch: boolean,\n targetDocument: Document | undefined,\n callback: (e: Event) => void,\n pollDuration: number = 1000,\n) => {\n const timeoutRef = React.useRef<number>();\n\n const listener = useEventCallback((e: Event) => {\n if (callback) {\n callback(e);\n }\n });\n\n // Adds listener to the custom iframe focus event\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n targetDocument?.addEventListener(FUI_FRAME_EVENT, listener, true);\n }\n return () => {\n targetDocument?.removeEventListener(FUI_FRAME_EVENT, listener, true);\n };\n }, [targetDocument, enableFrameFocusDispatch, listener]);\n\n // Starts polling for the active element\n React.useEffect(() => {\n if (enableFrameFocusDispatch) {\n timeoutRef.current = targetDocument?.defaultView?.setInterval(() => {\n const activeElement = targetDocument?.activeElement;\n if (activeElement?.tagName === 'IFRAME' || activeElement?.tagName === 'WEBVIEW') {\n const event = new CustomEvent(FUI_FRAME_EVENT, { bubbles: true });\n activeElement.dispatchEvent(event);\n }\n }, pollDuration);\n }\n return () => {\n targetDocument?.defaultView?.clearTimeout(timeoutRef.current);\n };\n }, [targetDocument, enableFrameFocusDispatch, pollDuration]);\n};\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useOnScrollOutside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AAGA;;;AAGG;;AACH,OAAO,MAAM,kBAAkB,GAAI,OAAD,IAA8C;EAC9E,MAAM;IAAE,IAAF;IAAQ,QAAR;IAAkB,OAAlB;IAA2B,QAA3B;IAAqC,QAAQ,EAAE;EAA/C,IAAgE,OAAtE;EAEA,MAAM,QAAQ,GAAG,gBAAgB,CAAE,EAAD,IAAgC;IAChE,MAAM,QAAQ,GACZ,YAAY,KAAK,CAAC,MAAD,EAAS,KAAT,KAAmB,CAAC,EAAC,MAAM,KAAA,IAAN,IAAA,MAAM,KAAA,KAAA,CAAN,GAAM,KAAA,CAAN,GAAA,MAAM,CAAE,QAAR,CAAiB,KAAjB,CAAD,CAAzB,CADd;;IAGA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAL,CAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAJ,IAAe,IAAhB,EAAsB,EAAE,CAAC,MAAzB,CAA3B,CAAlB;;IACA,IAAI,SAAS,IAAI,CAAC,QAAlB,EAA4B;MAC1B,QAAQ,CAAC,EAAD,CAAR;IACD;EACF,CARgC,CAAjC;EAUA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,IAAI,CAAC,QAAL,EAAe;MACb,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,gBAAT,CAA0B,OAA1B,EAAmC,QAAnC,CAAA;MACA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,gBAAT,CAA0B,WAA1B,EAAuC,QAAvC,CAAA;IACD;;IAED,OAAO,MAAK;MACV,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,mBAAT,CAA6B,OAA7B,EAAsC,QAAtC,CAAA;MACA,OAAO,KAAA,IAAP,IAAA,OAAO,KAAA,KAAA,CAAP,GAAO,KAAA,CAAP,GAAA,OAAO,CAAE,mBAAT,CAA6B,WAA7B,EAA0C,QAA1C,CAAA;IACD,CAHD;EAID,CAVD,EAUG,CAAC,QAAD,EAAW,OAAX,EAAoB,QAApB,CAVH;AAWD,CAxBM","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (!disabled) {\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n }\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useOnScrollOutside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AAGA;;;AAGG;;AACH,OAAO,MAAM,kBAAkB,GAAI,OAAD,IAA8C;EAC9E,MAAM;IAAE,IAAF;IAAQ,QAAR;IAA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EAAW,OAAX,EAAoB,QAApB,CAVH;AAWD,CAxBM","sourcesContent":["import * as React from 'react';\nimport { useEventCallback } from './useEventCallback';\nimport type { UseOnClickOrScrollOutsideOptions } from './useOnClickOutside';\n\n/**\n * @internal\n * Utility to perform checks where a click/touch event was made outside a component\n */\nexport const useOnScrollOutside = (options: UseOnClickOrScrollOutsideOptions) => {\n const { refs, callback, element, disabled, contains: containsProp } = options;\n\n const listener = useEventCallback((ev: MouseEvent | TouchEvent) => {\n const contains: UseOnClickOrScrollOutsideOptions['contains'] =\n containsProp || ((parent, child) => !!parent?.contains(child));\n\n const isOutside = refs.every(ref => !contains(ref.current || null, ev.target as HTMLElement));\n if (isOutside && !disabled) {\n callback(ev);\n }\n });\n\n React.useEffect(() => {\n if (!disabled) {\n element?.addEventListener('wheel', listener);\n element?.addEventListener('touchmove', listener);\n }\n\n return () => {\n element?.removeEventListener('wheel', listener);\n element?.removeEventListener('touchmove', listener);\n };\n }, [listener, element, disabled]);\n};\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/usePrevious.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;AAEG;;AACH,OAAO,MAAM,WAAW,GAAyB,KAAtB,IAA0C;EACnE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAN,CAA+B,IAA/B,CAAZ;EACA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,GAAG,CAAC,OAAJ,GAAc,KAAd;EACD,CAFD,EAEG,CAAC,KAAD,CAFH;EAGA,OAAO,GAAG,CAAC,OAAX;AACD,CANM","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport const usePrevious = <ValueType = unknown>(value: ValueType) => {\n const ref = React.useRef<ValueType | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/usePrevious.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;AAEG;;AACH,OAAO,MAAM,WAAW,GAAyB,KAAtB,IAA0C;EACnE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAN,CAA+B,IAA/B,CAAZ;EACA,KAAK,CAAC,SAAN,CAAgB,MAAK;IACnB,GAAG,CAAC,OAAJ,GAAc,KAAd;EACD,CAFD,EAEG,CAAC,KAAD,CAFH;EAGA,OAAO,GAAG,CAAC,OAAX;AACD,CANM","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n */\nexport const usePrevious = <ValueType = unknown>(value: ValueType) => {\n const ref = React.useRef<ValueType | null>(null);\n React.useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref.current;\n};\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["hooks/useTimeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;AAOG;;AACH,OAAM,SAAU,UAAV,GAAoB;EACxB,MAAM,CAAC,OAAD,IAAY,KAAK,CAAC,QAAN,CAAe,OAAO;IACtC,EAAE,EAAE,SADkC;IAEtC,GAAG,EAAE,CAAC,EAAD,EAAiB,KAAjB,KAAkC;MACrC,OAAO,CAAC,KAAR;MACA,OAAO,CAAC,EAAR,GAAa,UAAU,CAAC,EAAD,EAAK,KAAL,CAAvB;IACD,CALqC;IAMtC,KAAK,EAAE,MAAK;MACV,IAAI,OAAO,CAAC,EAAR,KAAe,SAAnB,EAA8B;QAC5B,YAAY,CAAC,OAAO,CAAC,EAAT,CAAZ;QACA,OAAO,CAAC,EAAR,GAAa,SAAb;MACD;IACF;EAXqC,CAAP,CAAf,CAAlB,CADwB,CAexB;;EACA,KAAK,CAAC,SAAN,CAAgB,MAAM,OAAO,CAAC,KAA9B,EAAqC,CAAC,OAAD,CAArC;EAEA,OAAO,CAAC,OAAO,CAAC,GAAT,EAAc,OAAO,CAAC,KAAtB,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once,\n * and is cleaned up when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const [timeout] = React.useState(() => ({\n id: undefined as ReturnType<typeof setTimeout> | undefined,\n set: (fn: () => void, delay: number) => {\n timeout.clear();\n timeout.id = setTimeout(fn, delay);\n },\n clear: () => {\n if (timeout.id !== undefined) {\n clearTimeout(timeout.id);\n timeout.id = undefined;\n }\n },\n }));\n\n // Clean up the timeout when the component is unloaded\n React.useEffect(() => timeout.clear, [timeout]);\n\n return [timeout.set, timeout.clear] as const;\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/hooks/useTimeout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AAEA;;;;;;;AAOG;;AACH,OAAM,SAAU,UAAV,GAAoB;EACxB,MAAM,CAAC,OAAD,IAAY,KAAK,CAAC,QAAN,CAAe,OAAO;IACtC,EAAE,EAAE,SADkC;IAEtC,GAAG,EAAE,CAAC,EAAD,EAAiB,KAAjB,KAAkC;MACrC,OAAO,CAAC,KAAR;MACA,OAAO,CAAC,EAAR,GAAa,UAAU,CAAC,EAAD,EAAK,KAAL,CAAvB;IACD,CALqC;IAMtC,KAAK,EAAE,MAAK;MACV,IAAI,OAAO,CAAC,EAAR,KAAe,SAAnB,EAA8B;QAC5B,YAAY,CAAC,OAAO,CAAC,EAAT,CAAZ;QACA,OAAO,CAAC,EAAR,GAAa,SAAb;MACD;IACF;EAXqC,CAAP,CAAf,CAAlB,CADwB,CAexB;;EACA,KAAK,CAAC,SAAN,CAAgB,MAAM,OAAO,CAAC,KAA9B,EAAqC,CAAC,OAAD,CAArC;EAEA,OAAO,CAAC,OAAO,CAAC,GAAT,EAAc,OAAO,CAAC,KAAtB,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Helper to manage a browser timeout.\n * Ensures that the timeout isn't set multiple times at once,\n * and is cleaned up when the component is unloaded.\n *\n * @returns A pair of [setTimeout, clearTimeout] that are stable between renders.\n */\nexport function useTimeout() {\n const [timeout] = React.useState(() => ({\n id: undefined as ReturnType<typeof setTimeout> | undefined,\n set: (fn: () => void, delay: number) => {\n timeout.clear();\n timeout.id = setTimeout(fn, delay);\n },\n clear: () => {\n if (timeout.id !== undefined) {\n clearTimeout(timeout.id);\n timeout.id = undefined;\n }\n },\n }));\n\n // Clean up the timeout when the component is unloaded\n React.useEffect(() => timeout.clear, [timeout]);\n\n return [timeout.set, timeout.clear] as const;\n}\n"],"sourceRoot":"../src/"}
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';
2
2
  export { resetIdsForTests, useControllableState, useEventCallback, useFirstMount, useForceUpdate, useId, useIsomorphicLayoutEffect, useMergedRefs, useOnClickOutside, useOnScrollOutside, usePrevious, useTimeout } from './hooks/index';
3
3
  export { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';
4
- export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, shouldPreventDefaultOnKeyDown } from './utils/index';
4
+ export { clamp, getNativeElementProps, getPartitionedNativeProps, getRTLSafeKey, mergeCallbacks, isHTMLElement, isInteractiveHTMLElement } from './utils/index';
5
5
  export { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';
6
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,gBAAnB,EAAqC,mBAArC,QAAgE,iBAAhE;AAgBA,SACE,gBADF,EAEE,oBAFF,EAGE,gBAHF,EAIE,aAJF,EAKE,cALF,EAME,KANF,EAOE,yBAPF,EAQE,aARF,EASE,iBATF,EAUE,kBAVF,EAWE,WAXF,EAYE,UAZF,QAaO,eAbP;AAgBA,SAAS,SAAT,EAAoB,QAApB,EAA8B,WAA9B,QAAiD,aAAjD;AAEA,SACE,KADF,EAEE,qBAFF,EAGE,yBAHF,EAIE,aAJF,EAKE,cALF,EAME,6BANF,QAOO,eAPP;AASA,SAAS,2BAAT,EAAsC,eAAtC,EAAuD,eAAvD,QAA8E,iBAA9E","sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n shouldPreventDefaultOnKeyDown,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,gBAAnB,EAAqC,mBAArC,QAAgE,iBAAhE;AAgBA,SACE,gBADF,EAEE,oBAFF,EAGE,gBAHF,EAIE,aAJF,EAKE,cALF,EAME,KANF,EAOE,yBAPF,EAQE,aARF,EASE,iBATF,EAUE,kBAVF,EAWE,WAXF,EAYE,UAZF,QAaO,eAbP;AAgBA,SAAS,SAAT,EAAoB,QAApB,EAA8B,WAA9B,QAAiD,aAAjD;AAEA,SACE,KADF,EAEE,qBAFF,EAGE,yBAHF,EAIE,aAJF,EAKE,cALF,EAME,aANF,EAOE,wBAPF,QAQO,eARP;AAUA,SAAS,2BAAT,EAAsC,eAAtC,EAAuD,eAAvD,QAA8E,iBAA9E","sourcesContent":["export { getSlots, resolveShorthand, isResolvedShorthand } from './compose/index';\nexport type {\n ExtractSlotProps,\n ComponentProps,\n ComponentState,\n ForwardRefComponent,\n ResolveShorthandFunction,\n ResolveShorthandOptions,\n Slot,\n Slots,\n SlotClassNames,\n SlotPropsRecord,\n SlotRenderFunction,\n SlotShorthandValue,\n} from './compose/index';\n\nexport {\n resetIdsForTests,\n useControllableState,\n useEventCallback,\n useFirstMount,\n useForceUpdate,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n useOnClickOutside,\n useOnScrollOutside,\n usePrevious,\n useTimeout,\n} from './hooks/index';\nexport type { RefObjectFunction, UseControllableStateOptions, UseOnClickOrScrollOutsideOptions } from './hooks/index';\n\nexport { canUseDOM, useIsSSR, SSRProvider } from './ssr/index';\n\nexport {\n clamp,\n getNativeElementProps,\n getPartitionedNativeProps,\n getRTLSafeKey,\n mergeCallbacks,\n isHTMLElement,\n isInteractiveHTMLElement,\n} from './utils/index';\n\nexport { applyTriggerPropsToChildren, getTriggerChild, isFluentTrigger } from './trigger/index';\n\nexport type { FluentTriggerComponent, TriggerProps } from './trigger/index';\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["ssr/SSRContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,SAAT,QAA0B,aAA1B;AAYA;;;;AAIG;;AACH,OAAO,MAAM,sBAAsB,GAAoB;EACrD,OAAO,EAAE;AAD4C,CAAhD;AAIP,OAAO,MAAM,UAAU,gBAAG,KAAK,CAAC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support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request\n * to ensure the client and server are consistent.\n *\n * @internal\n */\nexport type SSRContextValue = {\n current: number;\n};\n\n/**\n * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.\n *\n * @internal\n */\nexport const defaultSSRContextValue: SSRContextValue = {\n current: 0,\n};\n\nexport const SSRContext = React.createContext<SSRContextValue | undefined>(undefined) as React.Context<SSRContextValue>;\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext) ?? defaultSSRContextValue;\n}\n\n/**\n * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids\n * are consistent between the client and server.\n *\n * @public\n */\nexport const SSRProvider: React.FC = props => {\n const [value] = React.useState<SSRContextValue>(() => ({ current: 0 }));\n\n return <SSRContext.Provider value={value}>{props.children}</SSRContext.Provider>;\n};\n\n/**\n * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay\n * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.\n */\nexport function useIsSSR(): boolean {\n const isInSSRContext = useSSRContext() !== defaultSSRContextValue;\n const [isSSR, setIsSSR] = React.useState(isInSSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the\n // developer to add one.\n if (process.env.NODE_ENV !== 'production') {\n if (!isInSSRContext && !canUseDOM()) {\n // eslint-disable-next-line no-console\n console.error(\n [\n '@fluentui/react-components: ',\n 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' +\n 'generated between the client and server.',\n '\\n',\n '\\n',\n 'Check documentation at https://aka.ms/fluentui-ssr',\n ].join(''),\n );\n }\n }\n\n // If on the client, and the component was initially server rendered, then schedule a layout effect to update the\n // component after hydration.\n if (canUseDOM() && isInSSRContext) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line\n React.useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return isSSR;\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,IAPF,CAOO,EAPP,CADF;IAUD;EACF,CApBqB,CAsBtB;EACA;;;EACA,IAAI,SAAS,MAAM,cAAnB,EAAmC;IACjC;IACA;IACA;IACA,KAAK,CAAC,eAAN,CAAsB,MAAK;MACzB,QAAQ,CAAC,KAAD,CAAR;IACD,CAFD,EAEG,EAFH;EAGD;;EAED,OAAO,KAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { canUseDOM } from './canUseDOM';\n\n/**\n * To support SSR, the auto incrementing id counter is stored in a context. This allows it to be reset on every request\n * to ensure the client and server are consistent.\n *\n * @internal\n */\nexport type SSRContextValue = {\n current: number;\n};\n\n/**\n * Default context value to use in case there is no SSRProvider. This is fine for client-only apps.\n *\n * @internal\n */\nexport const defaultSSRContextValue: SSRContextValue = {\n current: 0,\n};\n\nexport const SSRContext = React.createContext<SSRContextValue | undefined>(undefined) as React.Context<SSRContextValue>;\n\n/**\n * @internal\n */\nexport function useSSRContext(): SSRContextValue {\n return React.useContext(SSRContext) ?? defaultSSRContextValue;\n}\n\n/**\n * When using SSR with Fluent UI, applications must be wrapped in an SSRProvider. This ensures that auto generated ids\n * are consistent between the client and server.\n *\n * @public\n */\nexport const SSRProvider: React.FC = props => {\n const [value] = React.useState<SSRContextValue>(() => ({ current: 0 }));\n\n return <SSRContext.Provider value={value}>{props.children}</SSRContext.Provider>;\n};\n\n/**\n * Returns whether the component is currently being server side rendered or hydrated on the client. Can be used to delay\n * browser-specific rendering until after hydration. May cause re-renders on a client when is used within SSRProvider.\n */\nexport function useIsSSR(): boolean {\n const isInSSRContext = useSSRContext() !== defaultSSRContextValue;\n const [isSSR, setIsSSR] = React.useState(isInSSRContext);\n\n // If we are rendering in a non-DOM environment, and there's no SSRProvider, provide a warning to hint to the\n // developer to add one.\n if (process.env.NODE_ENV !== 'production') {\n if (!isInSSRContext && !canUseDOM()) {\n // eslint-disable-next-line no-console\n console.error(\n [\n '@fluentui/react-components: ',\n 'When server rendering, you must wrap your application in an <SSRProvider> to ensure consistent ids are ' +\n 'generated between the client and server.',\n '\\n',\n '\\n',\n 'Check documentation at https://aka.ms/fluentui-ssr',\n ].join(''),\n );\n }\n }\n\n // If on the client, and the component was initially server rendered, then schedule a layout effect to update the\n // component after hydration.\n if (canUseDOM() && isInSSRContext) {\n // This if statement technically breaks the rules of hooks, but is safe because the condition never changes after\n // mounting.\n // eslint-disable-next-line\n React.useLayoutEffect(() => {\n setIsSSR(false);\n }, []);\n }\n\n return isSSR;\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["ssr/canUseDOM.ts"],"names":[],"mappings":"AAAA;;AAEG;AACH,OAAM,SAAU,SAAV,GAAmB;EACvB,OACE,OAAO,MAAP,KAAkB,WAAlB,IACA,CAAC,EACC,MAAM,CAAC,QAAP,IACA;EACA,MAAM,CAAC,QAAP,CAAgB,aAHjB,CAFH;AAQD","sourcesContent":["/**\n * Verifies if an application can use DOM.\n */\nexport function canUseDOM(): boolean {\n return (\n typeof window !== 'undefined' &&\n !!(\n window.document &&\n // eslint-disable-next-line deprecation/deprecation\n window.document.createElement\n )\n );\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/ssr/canUseDOM.ts"],"names":[],"mappings":"AAAA;;AAEG;AACH,OAAM,SAAU,SAAV,GAAmB;EACvB,OACE,OAAO,MAAP,KAAkB,WAAlB,IACA,CAAC,EACC,MAAM,CAAC,QAAP,IACA;EACA,MAAM,CAAC,QAAP,CAAgB,aAHjB,CAFH;AAQD","sourcesContent":["/**\n * Verifies if an application can use DOM.\n */\nexport function canUseDOM(): boolean {\n return (\n typeof window !== 'undefined' &&\n !!(\n window.document &&\n // eslint-disable-next-line deprecation/deprecation\n window.document.createElement\n )\n );\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC","sourcesContent":["export * from './canUseDOM';\nexport * from './SSRContext';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/ssr/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC","sourcesContent":["export * from './canUseDOM';\nexport * from './SSRContext';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;;AAGG;;AACH,OAAM,SAAU,2BAAV,CACJ,QADI,EAEJ,iBAFI,EAEgC;EAEpC,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,OAAO,QAAQ,CAAC,iBAAD,CAAf;EACD,CAFD,MAEO,IAAI,QAAJ,EAAc;IACnB,OAAO,gBAAgB,CAAC,QAAD,EAAW,iBAAX,CAAvB;EACD,CANmC,CAQpC;EACA;EACA;;;EACA,OAAO,QAAQ,IAAI,IAAnB;AACD;AAED;;;AAGG;;AACH,SAAS,gBAAT,CACE,KADF,EAEE,YAFF,EAEiC;EAE/B,IAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;IACjE,MAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;EAID;;EAED,IAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;IAC1B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;IACA,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;EACD,CAHD,MAGO;IACL,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;EACD;AACF","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport function applyTriggerPropsToChildren<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n triggerChildProps: TriggerChildProps,\n): React.ReactElement | null {\n if (typeof children === 'function') {\n return children(triggerChildProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerChildProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n}\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nfunction cloneTriggerTree<TriggerChildProps>(\n child: React.ReactNode,\n triggerProps: TriggerChildProps,\n): React.ReactElement {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps as TriggerChildProps & React.Attributes);\n }\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/trigger/applyTriggerPropsToChildren.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;;AAGG;;AACH,OAAM,SAAU,2BAAV,CACJ,QADI,EAEJ,iBAFI,EAEgC;EAEpC,IAAI,OAAO,QAAP,KAAoB,UAAxB,EAAoC;IAClC,OAAO,QAAQ,CAAC,iBAAD,CAAf;EACD,CAFD,MAEO,IAAI,QAAJ,EAAc;IACnB,OAAO,gBAAgB,CAAC,QAAD,EAAW,iBAAX,CAAvB;EACD,CANmC,CAQpC;EACA;EACA;;;EACA,OAAO,QAAQ,IAAI,IAAnB;AACD;AAED;;;AAGG;;AACH,SAAS,gBAAT,CACE,KADF,EAEE,YAFF,EAEiC;EAE/B,IAAI,eAAC,KAAK,CAAC,cAAN,CAAqB,KAArB,CAAD,IAAgC,KAAK,CAAC,IAAN,KAAe,KAAK,CAAC,QAAzD,EAAmE;IACjE,MAAM,IAAI,KAAJ,CACJ,oEACE,sDAFE,CAAN;EAID;;EAED,IAAI,eAAe,CAAC,KAAD,CAAnB,EAA4B;IAC1B,MAAM,UAAU,GAAG,gBAAgB,CAAC,KAAK,CAAC,KAAN,CAAY,QAAb,EAAuB,YAAvB,CAAnC;IACA,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,SAA1B,EAAqC,UAArC,CAAP;EACD,CAHD,MAGO;IACL,oBAAO,KAAK,CAAC,YAAN,CAAmB,KAAnB,EAA0B,YAA1B,CAAP;EACD;AACF","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * resolve the trigger props to the children, either by calling the render function, or cloning with the new props.\n */\nexport function applyTriggerPropsToChildren<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n triggerChildProps: TriggerChildProps,\n): React.ReactElement | null {\n if (typeof children === 'function') {\n return children(triggerChildProps);\n } else if (children) {\n return cloneTriggerTree(children, triggerChildProps);\n }\n\n // Components in React should return either JSX elements or \"null\", otherwise React will throw:\n // Nothing was returned from render.\n // This usually means a return statement is missing. Or, to render nothing, return null.\n return children || null;\n}\n\n/**\n * Clones a React element tree, and applies the given props to the first grandchild that is not\n * a FluentTriggerComponent or React Fragment (the same element returned by {@link getTriggerChild}).\n */\nfunction cloneTriggerTree<TriggerChildProps>(\n child: React.ReactNode,\n triggerProps: TriggerChildProps,\n): React.ReactElement {\n if (!React.isValidElement(child) || child.type === React.Fragment) {\n throw new Error(\n 'A trigger element must be a single element for this component. ' +\n \"Please ensure that you're not using React Fragments.\",\n );\n }\n\n if (isFluentTrigger(child)) {\n const grandchild = cloneTriggerTree(child.props.children, triggerProps);\n return React.cloneElement(child, undefined, grandchild);\n } else {\n return React.cloneElement(child, triggerProps as TriggerChildProps & React.Attributes);\n }\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/getTriggerChild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;;;;;;;;;;;;;;;;;;;;AAqBG;;AACH,OAAM,SAAU,eAAV,CACJ,QADI,EACiD;EAGrD,IAAI,eAAC,KAAK,CAAC,cAAN,CAAwC,QAAxC,CAAL,EAAwD;IACtD,OAAO,IAAP;EACD;;EACD,OAAO,eAAe,CAAC,QAAD,CAAf,GACH,eAAe,EACb;EACA;EACC,QAAQ,CAAC,KAAT,CAAgC,QAHpB,CADZ,GAMH,QANJ;AAOD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n *\n * In the case where the immediate child is not a valid element,\n * null is returned\n */\nexport function getTriggerChild<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (React.ReactElement<Partial<TriggerChildProps>> & { ref?: React.Ref<any> }) | null {\n if (!React.isValidElement<TriggerChildProps>(children)) {\n return null;\n }\n return isFluentTrigger(children)\n ? getTriggerChild(\n // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,\n // but for some reason it's failing on build\n (children.props as TriggerProps).children,\n )\n : children;\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/trigger/getTriggerChild.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,eAAT,QAAgC,mBAAhC;AAGA;;;;;;;;;;;;;;;;;;;;;AAqBG;;AACH,OAAM,SAAU,eAAV,CACJ,QADI,EACiD;EAGrD,IAAI,eAAC,KAAK,CAAC,cAAN,CAAwC,QAAxC,CAAL,EAAwD;IACtD,OAAO,IAAP;EACD;;EACD,OAAO,eAAe,CAAC,QAAD,CAAf,GACH,eAAe,EACb;EACA;EACC,QAAQ,CAAC,KAAT,CAAgC,QAHpB,CADZ,GAMH,QANJ;AAOD","sourcesContent":["import * as React from 'react';\nimport { isFluentTrigger } from './isFluentTrigger';\nimport type { TriggerProps } from './types';\n\n/**\n * @internal\n * Gets the trigger element of a FluentTriggerComponent (such as Tooltip or MenuTrigger).\n *\n * In the case where the immediate child is itself a FluentTriggerComponent and/or React Fragment,\n * it returns the first descendant that is _not_ a FluentTriggerComponent or Fragment.\n * This allows multiple triggers to be stacked, and still apply their props to the actual trigger element.\n *\n * For example, the following returns `<div id=\"child\" />`:\n * ```jsx\n * getTriggerChild(\n * <Tooltip>\n * <MenuTrigger>\n * <div id=\"child\" />\n * </MenuTrigger>\n * </Tooltip>\n * );\n * ```\n *\n * In the case where the immediate child is not a valid element,\n * null is returned\n */\nexport function getTriggerChild<TriggerChildProps>(\n children: TriggerProps<TriggerChildProps>['children'],\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): (React.ReactElement<Partial<TriggerChildProps>> & { ref?: React.Ref<any> }) | null {\n if (!React.isValidElement<TriggerChildProps>(children)) {\n return null;\n }\n return isFluentTrigger(children)\n ? getTriggerChild(\n // FIXME: This casting should be unnecessary as isFluentTrigger is a guard type method,\n // but for some reason it's failing on build\n (children.props as TriggerProps).children,\n )\n : children;\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["trigger/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC","sourcesContent":["export * from './applyTriggerPropsToChildren';\nexport * from './getTriggerChild';\nexport * from './isFluentTrigger';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/trigger/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC","sourcesContent":["export * from './applyTriggerPropsToChildren';\nexport * from './getTriggerChild';\nexport * from './isFluentTrigger';\nexport * from './types';\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["trigger/isFluentTrigger.ts"],"names":[],"mappings":"AAGA;;;;AAIG;AACH,OAAM,SAAU,eAAV,CAA0B,OAA1B,EAAqD;EACzD,OAAO,OAAO,CAAE,OAAO,CAAC,IAAR,CAAwC,wBAA1C,CAAd;AACD","sourcesContent":["import * as React from 'react';\nimport type { FluentTriggerComponent, TriggerProps } from './types';\n\n/**\n * @internal\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport function isFluentTrigger(element: React.ReactElement): element is React.ReactElement<TriggerProps> {\n return Boolean((element.type as FluentTriggerComponent).isFluentTriggerComponent);\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["packages/react-components/react-utilities/src/trigger/isFluentTrigger.ts"],"names":[],"mappings":"AAGA;;;;AAIG;AACH,OAAM,SAAU,eAAV,CAA0B,OAA1B,EAAqD;EACzD,OAAO,OAAO,CAAE,OAAO,CAAC,IAAR,CAAwC,wBAA1C,CAAd;AACD","sourcesContent":["import * as React from 'react';\nimport type { FluentTriggerComponent, TriggerProps } from './types';\n\n/**\n * @internal\n * Checks if a given element is a FluentUI trigger (e.g. `MenuTrigger` or `Tooltip`).\n * See the {@link FluentTriggerComponent} type for more info.\n */\nexport function isFluentTrigger(element: React.ReactElement): element is React.ReactElement<TriggerProps> {\n return Boolean((element.type as FluentTriggerComponent).isFluentTriggerComponent);\n}\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["trigger/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Allows a component to be tagged as a FluentUI trigger component.\n *\n * Triggers are special-case components: they attach event listeners and other props on their child,\n * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.\n *\n * A component can be tagged as a trigger as follows:\n * ```ts\n * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;\n *\n * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true\n * ```\n */\nexport type FluentTriggerComponent = {\n isFluentTriggerComponent?: boolean;\n};\n\n/**\n * A trigger may have a children that could be either:\n * 1. A single element\n * 2. A render function that will receive properties and must return a valid element or null\n * 3. null or undefined\n */\nexport type TriggerProps<TriggerChildProps = unknown> = {\n children?: React.ReactElement | ((props: TriggerChildProps) => React.ReactElement | null) | null;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/trigger/types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\n/**\n * @internal\n * Allows a component to be tagged as a FluentUI trigger component.\n *\n * Triggers are special-case components: they attach event listeners and other props on their child,\n * and use them to trigger another component to show. Examples include `MenuTrigger` and `Tooltip`.\n *\n * A component can be tagged as a trigger as follows:\n * ```ts\n * const MyComponent: React.FC<MyComponentProps> & FluentTriggerComponent = ...;\n *\n * MyComponent.isFluentTriggerComponent = true; // MUST also set this to true\n * ```\n */\nexport type FluentTriggerComponent = {\n isFluentTriggerComponent?: boolean;\n};\n\n/**\n * A trigger may have a children that could be either:\n * 1. A single element\n * 2. A render function that will receive properties and must return a valid element or null\n * 3. null or undefined\n */\nexport type TriggerProps<TriggerChildProps = unknown> = {\n children?: React.ReactElement | ((props: TriggerChildProps) => React.ReactElement | null) | null;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clamp.js","sourceRoot":"../src/","sources":["utils/clamp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC","sourcesContent":["/**\n * @internal\n * Clamps `value` to a number between the min and max.\n *\n * @param value - the value to be clamped\n * @param min - the lowest valid value\n * @param max - the highest valid value\n */\nexport const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(max, value || 0));\n"]}
1
+ {"version":3,"file":"clamp.js","sourceRoot":"../src/","sources":["packages/react-components/react-utilities/src/utils/clamp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC","sourcesContent":["/**\n * @internal\n * Clamps `value` to a number between the min and max.\n *\n * @param value - the value to be clamped\n * @param min - the lowest valid value\n * @param max - the highest valid value\n */\nexport const clamp = (value: number, min: number, max: number): number => Math.max(min, Math.min(max, value || 0));\n"]}