@react-aria/overlays 3.21.0 → 3.22.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 (253) hide show
  1. package/dist/DismissButton.main.js +51 -0
  2. package/dist/DismissButton.main.js.map +1 -0
  3. package/dist/DismissButton.mjs +46 -0
  4. package/dist/DismissButton.module.js +46 -0
  5. package/dist/DismissButton.module.js.map +1 -0
  6. package/dist/Overlay.main.js +73 -0
  7. package/dist/Overlay.main.js.map +1 -0
  8. package/dist/Overlay.mjs +63 -0
  9. package/dist/Overlay.module.js +63 -0
  10. package/dist/Overlay.module.js.map +1 -0
  11. package/dist/PortalProvider.main.js +41 -0
  12. package/dist/PortalProvider.main.js.map +1 -0
  13. package/dist/PortalProvider.mjs +31 -0
  14. package/dist/PortalProvider.module.js +31 -0
  15. package/dist/PortalProvider.module.js.map +1 -0
  16. package/dist/ar-AE.main.js +6 -0
  17. package/dist/ar-AE.main.js.map +1 -0
  18. package/dist/ar-AE.mjs +8 -0
  19. package/dist/ar-AE.module.js +8 -0
  20. package/dist/ar-AE.module.js.map +1 -0
  21. package/dist/ariaHideOutside.main.js +121 -0
  22. package/dist/ariaHideOutside.main.js.map +1 -0
  23. package/dist/ariaHideOutside.mjs +116 -0
  24. package/dist/ariaHideOutside.module.js +116 -0
  25. package/dist/ariaHideOutside.module.js.map +1 -0
  26. package/dist/bg-BG.main.js +6 -0
  27. package/dist/bg-BG.main.js.map +1 -0
  28. package/dist/bg-BG.mjs +8 -0
  29. package/dist/bg-BG.module.js +8 -0
  30. package/dist/bg-BG.module.js.map +1 -0
  31. package/dist/calculatePosition.main.js +355 -0
  32. package/dist/calculatePosition.main.js.map +1 -0
  33. package/dist/calculatePosition.mjs +350 -0
  34. package/dist/calculatePosition.module.js +350 -0
  35. package/dist/calculatePosition.module.js.map +1 -0
  36. package/dist/cs-CZ.main.js +6 -0
  37. package/dist/cs-CZ.main.js.map +1 -0
  38. package/dist/cs-CZ.mjs +8 -0
  39. package/dist/cs-CZ.module.js +8 -0
  40. package/dist/cs-CZ.module.js.map +1 -0
  41. package/dist/da-DK.main.js +6 -0
  42. package/dist/da-DK.main.js.map +1 -0
  43. package/dist/da-DK.mjs +8 -0
  44. package/dist/da-DK.module.js +8 -0
  45. package/dist/da-DK.module.js.map +1 -0
  46. package/dist/de-DE.main.js +6 -0
  47. package/dist/de-DE.main.js.map +1 -0
  48. package/dist/de-DE.mjs +8 -0
  49. package/dist/de-DE.module.js +8 -0
  50. package/dist/de-DE.module.js.map +1 -0
  51. package/dist/el-GR.main.js +6 -0
  52. package/dist/el-GR.main.js.map +1 -0
  53. package/dist/el-GR.mjs +8 -0
  54. package/dist/el-GR.module.js +8 -0
  55. package/dist/el-GR.module.js.map +1 -0
  56. package/dist/en-US.main.js +6 -0
  57. package/dist/en-US.main.js.map +1 -0
  58. package/dist/en-US.mjs +8 -0
  59. package/dist/en-US.module.js +8 -0
  60. package/dist/en-US.module.js.map +1 -0
  61. package/dist/es-ES.main.js +6 -0
  62. package/dist/es-ES.main.js.map +1 -0
  63. package/dist/es-ES.mjs +8 -0
  64. package/dist/es-ES.module.js +8 -0
  65. package/dist/es-ES.module.js.map +1 -0
  66. package/dist/et-EE.main.js +6 -0
  67. package/dist/et-EE.main.js.map +1 -0
  68. package/dist/et-EE.mjs +8 -0
  69. package/dist/et-EE.module.js +8 -0
  70. package/dist/et-EE.module.js.map +1 -0
  71. package/dist/fi-FI.main.js +6 -0
  72. package/dist/fi-FI.main.js.map +1 -0
  73. package/dist/fi-FI.mjs +8 -0
  74. package/dist/fi-FI.module.js +8 -0
  75. package/dist/fi-FI.module.js.map +1 -0
  76. package/dist/fr-FR.main.js +6 -0
  77. package/dist/fr-FR.main.js.map +1 -0
  78. package/dist/fr-FR.mjs +8 -0
  79. package/dist/fr-FR.module.js +8 -0
  80. package/dist/fr-FR.module.js.map +1 -0
  81. package/dist/he-IL.main.js +6 -0
  82. package/dist/he-IL.main.js.map +1 -0
  83. package/dist/he-IL.mjs +8 -0
  84. package/dist/he-IL.module.js +8 -0
  85. package/dist/he-IL.module.js.map +1 -0
  86. package/dist/hr-HR.main.js +6 -0
  87. package/dist/hr-HR.main.js.map +1 -0
  88. package/dist/hr-HR.mjs +8 -0
  89. package/dist/hr-HR.module.js +8 -0
  90. package/dist/hr-HR.module.js.map +1 -0
  91. package/dist/hu-HU.main.js +6 -0
  92. package/dist/hu-HU.main.js.map +1 -0
  93. package/dist/hu-HU.mjs +8 -0
  94. package/dist/hu-HU.module.js +8 -0
  95. package/dist/hu-HU.module.js.map +1 -0
  96. package/dist/import.mjs +12 -1533
  97. package/dist/intlStrings.main.js +108 -0
  98. package/dist/intlStrings.main.js.map +1 -0
  99. package/dist/intlStrings.mjs +110 -0
  100. package/dist/intlStrings.module.js +110 -0
  101. package/dist/intlStrings.module.js.map +1 -0
  102. package/dist/it-IT.main.js +6 -0
  103. package/dist/it-IT.main.js.map +1 -0
  104. package/dist/it-IT.mjs +8 -0
  105. package/dist/it-IT.module.js +8 -0
  106. package/dist/it-IT.module.js.map +1 -0
  107. package/dist/ja-JP.main.js +6 -0
  108. package/dist/ja-JP.main.js.map +1 -0
  109. package/dist/ja-JP.mjs +8 -0
  110. package/dist/ja-JP.module.js +8 -0
  111. package/dist/ja-JP.module.js.map +1 -0
  112. package/dist/ko-KR.main.js +6 -0
  113. package/dist/ko-KR.main.js.map +1 -0
  114. package/dist/ko-KR.mjs +8 -0
  115. package/dist/ko-KR.module.js +8 -0
  116. package/dist/ko-KR.module.js.map +1 -0
  117. package/dist/lt-LT.main.js +6 -0
  118. package/dist/lt-LT.main.js.map +1 -0
  119. package/dist/lt-LT.mjs +8 -0
  120. package/dist/lt-LT.module.js +8 -0
  121. package/dist/lt-LT.module.js.map +1 -0
  122. package/dist/lv-LV.main.js +6 -0
  123. package/dist/lv-LV.main.js.map +1 -0
  124. package/dist/lv-LV.mjs +8 -0
  125. package/dist/lv-LV.module.js +8 -0
  126. package/dist/lv-LV.module.js.map +1 -0
  127. package/dist/main.js +28 -1547
  128. package/dist/main.js.map +1 -1
  129. package/dist/module.js +12 -1533
  130. package/dist/module.js.map +1 -1
  131. package/dist/nb-NO.main.js +6 -0
  132. package/dist/nb-NO.main.js.map +1 -0
  133. package/dist/nb-NO.mjs +8 -0
  134. package/dist/nb-NO.module.js +8 -0
  135. package/dist/nb-NO.module.js.map +1 -0
  136. package/dist/nl-NL.main.js +6 -0
  137. package/dist/nl-NL.main.js.map +1 -0
  138. package/dist/nl-NL.mjs +8 -0
  139. package/dist/nl-NL.module.js +8 -0
  140. package/dist/nl-NL.module.js.map +1 -0
  141. package/dist/pl-PL.main.js +6 -0
  142. package/dist/pl-PL.main.js.map +1 -0
  143. package/dist/pl-PL.mjs +8 -0
  144. package/dist/pl-PL.module.js +8 -0
  145. package/dist/pl-PL.module.js.map +1 -0
  146. package/dist/pt-BR.main.js +6 -0
  147. package/dist/pt-BR.main.js.map +1 -0
  148. package/dist/pt-BR.mjs +8 -0
  149. package/dist/pt-BR.module.js +8 -0
  150. package/dist/pt-BR.module.js.map +1 -0
  151. package/dist/pt-PT.main.js +6 -0
  152. package/dist/pt-PT.main.js.map +1 -0
  153. package/dist/pt-PT.mjs +8 -0
  154. package/dist/pt-PT.module.js +8 -0
  155. package/dist/pt-PT.module.js.map +1 -0
  156. package/dist/ro-RO.main.js +6 -0
  157. package/dist/ro-RO.main.js.map +1 -0
  158. package/dist/ro-RO.mjs +8 -0
  159. package/dist/ro-RO.module.js +8 -0
  160. package/dist/ro-RO.module.js.map +1 -0
  161. package/dist/ru-RU.main.js +6 -0
  162. package/dist/ru-RU.main.js.map +1 -0
  163. package/dist/ru-RU.mjs +8 -0
  164. package/dist/ru-RU.module.js +8 -0
  165. package/dist/ru-RU.module.js.map +1 -0
  166. package/dist/sk-SK.main.js +6 -0
  167. package/dist/sk-SK.main.js.map +1 -0
  168. package/dist/sk-SK.mjs +8 -0
  169. package/dist/sk-SK.module.js +8 -0
  170. package/dist/sk-SK.module.js.map +1 -0
  171. package/dist/sl-SI.main.js +6 -0
  172. package/dist/sl-SI.main.js.map +1 -0
  173. package/dist/sl-SI.mjs +8 -0
  174. package/dist/sl-SI.module.js +8 -0
  175. package/dist/sl-SI.module.js.map +1 -0
  176. package/dist/sr-SP.main.js +6 -0
  177. package/dist/sr-SP.main.js.map +1 -0
  178. package/dist/sr-SP.mjs +8 -0
  179. package/dist/sr-SP.module.js +8 -0
  180. package/dist/sr-SP.module.js.map +1 -0
  181. package/dist/sv-SE.main.js +6 -0
  182. package/dist/sv-SE.main.js.map +1 -0
  183. package/dist/sv-SE.mjs +8 -0
  184. package/dist/sv-SE.module.js +8 -0
  185. package/dist/sv-SE.module.js.map +1 -0
  186. package/dist/tr-TR.main.js +6 -0
  187. package/dist/tr-TR.main.js.map +1 -0
  188. package/dist/tr-TR.mjs +8 -0
  189. package/dist/tr-TR.module.js +8 -0
  190. package/dist/tr-TR.module.js.map +1 -0
  191. package/dist/types.d.ts +8 -1
  192. package/dist/types.d.ts.map +1 -1
  193. package/dist/uk-UA.main.js +6 -0
  194. package/dist/uk-UA.main.js.map +1 -0
  195. package/dist/uk-UA.mjs +8 -0
  196. package/dist/uk-UA.module.js +8 -0
  197. package/dist/uk-UA.module.js.map +1 -0
  198. package/dist/useCloseOnScroll.main.js +46 -0
  199. package/dist/useCloseOnScroll.main.js.map +1 -0
  200. package/dist/useCloseOnScroll.mjs +40 -0
  201. package/dist/useCloseOnScroll.module.js +40 -0
  202. package/dist/useCloseOnScroll.module.js.map +1 -0
  203. package/dist/useModal.main.js +114 -0
  204. package/dist/useModal.main.js.map +1 -0
  205. package/dist/useModal.mjs +101 -0
  206. package/dist/useModal.module.js +101 -0
  207. package/dist/useModal.module.js.map +1 -0
  208. package/dist/useModalOverlay.main.js +55 -0
  209. package/dist/useModalOverlay.main.js.map +1 -0
  210. package/dist/useModalOverlay.mjs +50 -0
  211. package/dist/useModalOverlay.module.js +50 -0
  212. package/dist/useModalOverlay.module.js.map +1 -0
  213. package/dist/useOverlay.main.js +105 -0
  214. package/dist/useOverlay.main.js.map +1 -0
  215. package/dist/useOverlay.mjs +100 -0
  216. package/dist/useOverlay.module.js +100 -0
  217. package/dist/useOverlay.module.js.map +1 -0
  218. package/dist/useOverlayPosition.main.js +181 -0
  219. package/dist/useOverlayPosition.main.js.map +1 -0
  220. package/dist/useOverlayPosition.mjs +176 -0
  221. package/dist/useOverlayPosition.module.js +176 -0
  222. package/dist/useOverlayPosition.module.js.map +1 -0
  223. package/dist/useOverlayTrigger.main.js +54 -0
  224. package/dist/useOverlayTrigger.main.js.map +1 -0
  225. package/dist/useOverlayTrigger.mjs +49 -0
  226. package/dist/useOverlayTrigger.module.js +49 -0
  227. package/dist/useOverlayTrigger.module.js.map +1 -0
  228. package/dist/usePopover.main.js +66 -0
  229. package/dist/usePopover.main.js.map +1 -0
  230. package/dist/usePopover.mjs +61 -0
  231. package/dist/usePopover.module.js +61 -0
  232. package/dist/usePopover.module.js.map +1 -0
  233. package/dist/usePreventScroll.main.js +226 -0
  234. package/dist/usePreventScroll.main.js.map +1 -0
  235. package/dist/usePreventScroll.mjs +221 -0
  236. package/dist/usePreventScroll.module.js +221 -0
  237. package/dist/usePreventScroll.module.js.map +1 -0
  238. package/dist/zh-CN.main.js +6 -0
  239. package/dist/zh-CN.main.js.map +1 -0
  240. package/dist/zh-CN.mjs +8 -0
  241. package/dist/zh-CN.module.js +8 -0
  242. package/dist/zh-CN.module.js.map +1 -0
  243. package/dist/zh-TW.main.js +6 -0
  244. package/dist/zh-TW.main.js.map +1 -0
  245. package/dist/zh-TW.mjs +8 -0
  246. package/dist/zh-TW.module.js +8 -0
  247. package/dist/zh-TW.module.js.map +1 -0
  248. package/package.json +12 -12
  249. package/src/Overlay.tsx +6 -0
  250. package/src/PortalProvider.tsx +34 -0
  251. package/src/index.ts +1 -0
  252. package/src/useModalOverlay.ts +2 -2
  253. package/src/useOverlay.ts +1 -1
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAwB;IAChH,IAAI,QAAC,IAAI,EAAC,GAAG;IACb,IAAI,UAAC,MAAM,EAAC,GAAG;IAEf,uGAAuG;IACvG,yCAAyC;IACzC,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,OAAO,IAAI,OAAO,EACpB,CAAA,GAAA,oCAAS,EAAE,GAAG,CAAC,IAAI,OAAO,EAAE,MAAM,KAAK;IAE3C;IAEA,6EAA6E;IAC7E,oDAAoD;IACpD,yEAAyE;IACzE,+CAA+C;IAC/C,IAAI,eAAe;IACnB,IAAI,SAAS,QACX,eAAe;SACV,IAAI,SAAS,WAClB,eAAe;IAGjB,IAAI,YAAY,CAAA,GAAA,2BAAI;IACpB,OAAO;QACL,cAAc;YACZ,iBAAiB;YACjB,iBAAiB;YACjB,iBAAiB,SAAS,YAAY;YACtC,SAAS,MAAM,MAAM;QACvB;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/overlays/src/useOverlayTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMProps} from '@react-types/shared';\nimport {onCloseMap} from './useCloseOnScroll';\nimport {OverlayTriggerState} from '@react-stately/overlays';\nimport {RefObject, useEffect} from 'react';\nimport {useId} from '@react-aria/utils';\n\nexport interface OverlayTriggerProps {\n /** Type of overlay that is opened by the trigger. */\n type: 'dialog' | 'menu' | 'listbox' | 'tree' | 'grid'\n}\n\nexport interface OverlayTriggerAria {\n /** Props for the trigger element. */\n triggerProps: AriaButtonProps,\n\n /** Props for the overlay container element. */\n overlayProps: DOMProps\n}\n\n/**\n * Handles the behavior and accessibility for an overlay trigger, e.g. a button\n * that opens a popover, menu, or other overlay that is positioned relative to the trigger.\n */\nexport function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref?: RefObject<Element>): OverlayTriggerAria {\n let {type} = props;\n let {isOpen} = state;\n\n // Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll\n // without forcing users to pass onClose.\n useEffect(() => {\n if (ref && ref.current) {\n onCloseMap.set(ref.current, state.close);\n }\n });\n\n // Aria 1.1 supports multiple values for aria-haspopup other than just menus.\n // https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup\n // However, we only add it for menus for now because screen readers often\n // announce it as a menu even for other values.\n let ariaHasPopup = undefined;\n if (type === 'menu') {\n ariaHasPopup = true;\n } else if (type === 'listbox') {\n ariaHasPopup = 'listbox';\n }\n\n let overlayId = useId();\n return {\n triggerProps: {\n 'aria-haspopup': ariaHasPopup,\n 'aria-expanded': isOpen,\n 'aria-controls': isOpen ? overlayId : null,\n onPress: state.toggle\n },\n overlayProps: {\n id: overlayId\n }\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTrigger.main.js.map"}
@@ -0,0 +1,49 @@
1
+ import {onCloseMap as $dd149f63282afbbf$export$f6211563215e3b37} from "./useCloseOnScroll.mjs";
2
+ import {useEffect as $gMvIk$useEffect} from "react";
3
+ import {useId as $gMvIk$useId} from "@react-aria/utils";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $628037886ba31236$export$f9d5c8beee7d008d(props, state, ref) {
19
+ let { type: type } = props;
20
+ let { isOpen: isOpen } = state;
21
+ // Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll
22
+ // without forcing users to pass onClose.
23
+ (0, $gMvIk$useEffect)(()=>{
24
+ if (ref && ref.current) (0, $dd149f63282afbbf$export$f6211563215e3b37).set(ref.current, state.close);
25
+ });
26
+ // Aria 1.1 supports multiple values for aria-haspopup other than just menus.
27
+ // https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup
28
+ // However, we only add it for menus for now because screen readers often
29
+ // announce it as a menu even for other values.
30
+ let ariaHasPopup = undefined;
31
+ if (type === "menu") ariaHasPopup = true;
32
+ else if (type === "listbox") ariaHasPopup = "listbox";
33
+ let overlayId = (0, $gMvIk$useId)();
34
+ return {
35
+ triggerProps: {
36
+ "aria-haspopup": ariaHasPopup,
37
+ "aria-expanded": isOpen,
38
+ "aria-controls": isOpen ? overlayId : null,
39
+ onPress: state.toggle
40
+ },
41
+ overlayProps: {
42
+ id: overlayId
43
+ }
44
+ };
45
+ }
46
+
47
+
48
+ export {$628037886ba31236$export$f9d5c8beee7d008d as useOverlayTrigger};
49
+ //# sourceMappingURL=useOverlayTrigger.mjs.map
@@ -0,0 +1,49 @@
1
+ import {onCloseMap as $dd149f63282afbbf$export$f6211563215e3b37} from "./useCloseOnScroll.module.js";
2
+ import {useEffect as $gMvIk$useEffect} from "react";
3
+ import {useId as $gMvIk$useId} from "@react-aria/utils";
4
+
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+
17
+
18
+ function $628037886ba31236$export$f9d5c8beee7d008d(props, state, ref) {
19
+ let { type: type } = props;
20
+ let { isOpen: isOpen } = state;
21
+ // Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll
22
+ // without forcing users to pass onClose.
23
+ (0, $gMvIk$useEffect)(()=>{
24
+ if (ref && ref.current) (0, $dd149f63282afbbf$export$f6211563215e3b37).set(ref.current, state.close);
25
+ });
26
+ // Aria 1.1 supports multiple values for aria-haspopup other than just menus.
27
+ // https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup
28
+ // However, we only add it for menus for now because screen readers often
29
+ // announce it as a menu even for other values.
30
+ let ariaHasPopup = undefined;
31
+ if (type === "menu") ariaHasPopup = true;
32
+ else if (type === "listbox") ariaHasPopup = "listbox";
33
+ let overlayId = (0, $gMvIk$useId)();
34
+ return {
35
+ triggerProps: {
36
+ "aria-haspopup": ariaHasPopup,
37
+ "aria-expanded": isOpen,
38
+ "aria-controls": isOpen ? overlayId : null,
39
+ onPress: state.toggle
40
+ },
41
+ overlayProps: {
42
+ id: overlayId
43
+ }
44
+ };
45
+ }
46
+
47
+
48
+ export {$628037886ba31236$export$f9d5c8beee7d008d as useOverlayTrigger};
49
+ //# sourceMappingURL=useOverlayTrigger.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA0BM,SAAS,0CAAkB,KAA0B,EAAE,KAA0B,EAAE,GAAwB;IAChH,IAAI,QAAC,IAAI,EAAC,GAAG;IACb,IAAI,UAAC,MAAM,EAAC,GAAG;IAEf,uGAAuG;IACvG,yCAAyC;IACzC,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,OAAO,IAAI,OAAO,EACpB,CAAA,GAAA,yCAAS,EAAE,GAAG,CAAC,IAAI,OAAO,EAAE,MAAM,KAAK;IAE3C;IAEA,6EAA6E;IAC7E,oDAAoD;IACpD,yEAAyE;IACzE,+CAA+C;IAC/C,IAAI,eAAe;IACnB,IAAI,SAAS,QACX,eAAe;SACV,IAAI,SAAS,WAClB,eAAe;IAGjB,IAAI,YAAY,CAAA,GAAA,YAAI;IACpB,OAAO;QACL,cAAc;YACZ,iBAAiB;YACjB,iBAAiB;YACjB,iBAAiB,SAAS,YAAY;YACtC,SAAS,MAAM,MAAM;QACvB;QACA,cAAc;YACZ,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/overlays/src/useOverlayTrigger.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMProps} from '@react-types/shared';\nimport {onCloseMap} from './useCloseOnScroll';\nimport {OverlayTriggerState} from '@react-stately/overlays';\nimport {RefObject, useEffect} from 'react';\nimport {useId} from '@react-aria/utils';\n\nexport interface OverlayTriggerProps {\n /** Type of overlay that is opened by the trigger. */\n type: 'dialog' | 'menu' | 'listbox' | 'tree' | 'grid'\n}\n\nexport interface OverlayTriggerAria {\n /** Props for the trigger element. */\n triggerProps: AriaButtonProps,\n\n /** Props for the overlay container element. */\n overlayProps: DOMProps\n}\n\n/**\n * Handles the behavior and accessibility for an overlay trigger, e.g. a button\n * that opens a popover, menu, or other overlay that is positioned relative to the trigger.\n */\nexport function useOverlayTrigger(props: OverlayTriggerProps, state: OverlayTriggerState, ref?: RefObject<Element>): OverlayTriggerAria {\n let {type} = props;\n let {isOpen} = state;\n\n // Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll\n // without forcing users to pass onClose.\n useEffect(() => {\n if (ref && ref.current) {\n onCloseMap.set(ref.current, state.close);\n }\n });\n\n // Aria 1.1 supports multiple values for aria-haspopup other than just menus.\n // https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup\n // However, we only add it for menus for now because screen readers often\n // announce it as a menu even for other values.\n let ariaHasPopup = undefined;\n if (type === 'menu') {\n ariaHasPopup = true;\n } else if (type === 'listbox') {\n ariaHasPopup = 'listbox';\n }\n\n let overlayId = useId();\n return {\n triggerProps: {\n 'aria-haspopup': ariaHasPopup,\n 'aria-expanded': isOpen,\n 'aria-controls': isOpen ? overlayId : null,\n onPress: state.toggle\n },\n overlayProps: {\n id: overlayId\n }\n };\n}\n"],"names":[],"version":3,"file":"useOverlayTrigger.module.js.map"}
@@ -0,0 +1,66 @@
1
+ var $08ef1685902b6011$exports = require("./ariaHideOutside.main.js");
2
+ var $cd94b4896dd97759$exports = require("./useOverlayPosition.main.js");
3
+ var $82711f9cb668ecdb$exports = require("./useOverlay.main.js");
4
+ var $5c2f5cd01815d369$exports = require("./usePreventScroll.main.js");
5
+ var $jkVOI$reactariautils = require("@react-aria/utils");
6
+
7
+
8
+ function $parcel$export(e, n, v, s) {
9
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
10
+ }
11
+
12
+ $parcel$export(module.exports, "usePopover", () => $6c2dfcdee3e15e20$export$542a6fd13ac93354);
13
+ /*
14
+ * Copyright 2022 Adobe. All rights reserved.
15
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License. You may obtain a copy
17
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software distributed under
20
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
21
+ * OF ANY KIND, either express or implied. See the License for the specific language
22
+ * governing permissions and limitations under the License.
23
+ */
24
+
25
+
26
+
27
+
28
+ function $6c2dfcdee3e15e20$export$542a6fd13ac93354(props, state) {
29
+ let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside, ...otherProps } = props;
30
+ let { overlayProps: overlayProps, underlayProps: underlayProps } = (0, $82711f9cb668ecdb$exports.useOverlay)({
31
+ isOpen: state.isOpen,
32
+ onClose: state.close,
33
+ shouldCloseOnBlur: true,
34
+ isDismissable: !isNonModal,
35
+ isKeyboardDismissDisabled: isKeyboardDismissDisabled,
36
+ shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
37
+ }, popoverRef);
38
+ let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $cd94b4896dd97759$exports.useOverlayPosition)({
39
+ ...otherProps,
40
+ targetRef: triggerRef,
41
+ overlayRef: popoverRef,
42
+ isOpen: state.isOpen,
43
+ onClose: isNonModal ? state.close : null
44
+ });
45
+ (0, $5c2f5cd01815d369$exports.usePreventScroll)({
46
+ isDisabled: isNonModal || !state.isOpen
47
+ });
48
+ (0, $jkVOI$reactariautils.useLayoutEffect)(()=>{
49
+ if (state.isOpen && !isNonModal && popoverRef.current) return (0, $08ef1685902b6011$exports.ariaHideOutside)([
50
+ popoverRef.current
51
+ ]);
52
+ }, [
53
+ isNonModal,
54
+ state.isOpen,
55
+ popoverRef
56
+ ]);
57
+ return {
58
+ popoverProps: (0, $jkVOI$reactariautils.mergeProps)(overlayProps, positionProps),
59
+ arrowProps: arrowProps,
60
+ underlayProps: underlayProps,
61
+ placement: placement
62
+ };
63
+ }
64
+
65
+
66
+ //# sourceMappingURL=usePopover.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+DM,SAAS,0CAAW,KAAuB,EAAE,KAA0B;IAC5E,IAAI,cACF,UAAU,cACV,UAAU,cACV,UAAU,6BACV,yBAAyB,gCACzB,4BAA4B,EAC5B,GAAG,YACJ,GAAG;IAEJ,IAAI,gBAAC,YAAY,iBAAE,aAAa,EAAC,GAAG,CAAA,GAAA,oCAAS,EAC3C;QACE,QAAQ,MAAM,MAAM;QACpB,SAAS,MAAM,KAAK;QACpB,mBAAmB;QACnB,eAAe,CAAC;mCAChB;sCACA;IACF,GACA;IAGF,IAAI,EAAC,cAAc,aAAa,cAAE,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,4CAAiB,EAAE;QAC5E,GAAG,UAAU;QACb,WAAW;QACX,YAAY;QACZ,QAAQ,MAAM,MAAM;QACpB,SAAS,aAAa,MAAM,KAAK,GAAG;IACtC;IAEA,CAAA,GAAA,0CAAe,EAAE;QACf,YAAY,cAAc,CAAC,MAAM,MAAM;IACzC;IAEA,CAAA,GAAA,qCAAc,EAAE;QACd,IAAI,MAAM,MAAM,IAAI,CAAC,cAAc,WAAW,OAAO,EACnD,OAAO,CAAA,GAAA,yCAAc,EAAE;YAAC,WAAW,OAAO;SAAC;IAE/C,GAAG;QAAC;QAAY,MAAM,MAAM;QAAE;KAAW;IAEzC,OAAO;QACL,cAAc,CAAA,GAAA,gCAAS,EAAE,cAAc;oBACvC;uBACA;mBACA;IACF;AACF","sources":["packages/@react-aria/overlays/src/usePopover.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ariaHideOutside} from './ariaHideOutside';\nimport {AriaPositionProps, useOverlayPosition} from './useOverlayPosition';\nimport {DOMAttributes} from '@react-types/shared';\nimport {mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport {OverlayTriggerState} from '@react-stately/overlays';\nimport {PlacementAxis} from '@react-types/overlays';\nimport {RefObject} from 'react';\nimport {useOverlay} from './useOverlay';\nimport {usePreventScroll} from './usePreventScroll';\n\nexport interface AriaPopoverProps extends Omit<AriaPositionProps, 'isOpen' | 'onClose' | 'targetRef' | 'overlayRef'> {\n /**\n * The ref for the element which the popover positions itself with respect to.\n */\n triggerRef: RefObject<Element>,\n /**\n * The ref for the popover element.\n */\n popoverRef: RefObject<Element>,\n /**\n * Whether the popover is non-modal, i.e. elements outside the popover may be\n * interacted with by assistive technologies.\n *\n * Most popovers should not use this option as it may negatively impact the screen\n * reader experience. Only use with components such as combobox, which are designed\n * to handle this situation carefully.\n */\n isNonModal?: boolean,\n /**\n * Whether pressing the escape key to close the popover should be disabled.\n *\n * Most popovers should not use this option. When set to true, an alternative\n * way to close the popover with a keyboard must be provided.\n *\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n /**\n * When user interacts with the argument element outside of the popover ref,\n * return true if onClose should be called. This gives you a chance to filter\n * out interaction with elements that should not dismiss the popover.\n * By default, onClose will always be called on interaction outside the popover ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface PopoverAria {\n /** Props for the popover element. */\n popoverProps: DOMAttributes,\n /** Props for the popover tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes,\n /** Placement of the popover with respect to the trigger. */\n placement: PlacementAxis\n}\n\n/**\n * Provides the behavior and accessibility implementation for a popover component.\n * A popover is an overlay element positioned relative to a trigger.\n */\nexport function usePopover(props: AriaPopoverProps, state: OverlayTriggerState): PopoverAria {\n let {\n triggerRef,\n popoverRef,\n isNonModal,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside,\n ...otherProps\n } = props;\n\n let {overlayProps, underlayProps} = useOverlay(\n {\n isOpen: state.isOpen,\n onClose: state.close,\n shouldCloseOnBlur: true,\n isDismissable: !isNonModal,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside\n },\n popoverRef\n );\n\n let {overlayProps: positionProps, arrowProps, placement} = useOverlayPosition({\n ...otherProps,\n targetRef: triggerRef,\n overlayRef: popoverRef,\n isOpen: state.isOpen,\n onClose: isNonModal ? state.close : null\n });\n\n usePreventScroll({\n isDisabled: isNonModal || !state.isOpen\n });\n\n useLayoutEffect(() => {\n if (state.isOpen && !isNonModal && popoverRef.current) {\n return ariaHideOutside([popoverRef.current]);\n }\n }, [isNonModal, state.isOpen, popoverRef]);\n\n return {\n popoverProps: mergeProps(overlayProps, positionProps),\n arrowProps,\n underlayProps,\n placement\n };\n}\n"],"names":[],"version":3,"file":"usePopover.main.js.map"}
@@ -0,0 +1,61 @@
1
+ import {ariaHideOutside as $5e3802645cc19319$export$1c3ebcada18427bf} from "./ariaHideOutside.mjs";
2
+ import {useOverlayPosition as $2a41e45df1593e64$export$d39e1813b3bdd0e1} from "./useOverlayPosition.mjs";
3
+ import {useOverlay as $a11501f3d1d39e6c$export$ea8f71083e90600f} from "./useOverlay.mjs";
4
+ import {usePreventScroll as $49c51c25361d4cd2$export$ee0f7cc6afcd1c18} from "./usePreventScroll.mjs";
5
+ import {useLayoutEffect as $m0yab$useLayoutEffect, mergeProps as $m0yab$mergeProps} from "@react-aria/utils";
6
+
7
+ /*
8
+ * Copyright 2022 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */
18
+
19
+
20
+
21
+
22
+ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
23
+ let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside, ...otherProps } = props;
24
+ let { overlayProps: overlayProps, underlayProps: underlayProps } = (0, $a11501f3d1d39e6c$export$ea8f71083e90600f)({
25
+ isOpen: state.isOpen,
26
+ onClose: state.close,
27
+ shouldCloseOnBlur: true,
28
+ isDismissable: !isNonModal,
29
+ isKeyboardDismissDisabled: isKeyboardDismissDisabled,
30
+ shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
31
+ }, popoverRef);
32
+ let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
33
+ ...otherProps,
34
+ targetRef: triggerRef,
35
+ overlayRef: popoverRef,
36
+ isOpen: state.isOpen,
37
+ onClose: isNonModal ? state.close : null
38
+ });
39
+ (0, $49c51c25361d4cd2$export$ee0f7cc6afcd1c18)({
40
+ isDisabled: isNonModal || !state.isOpen
41
+ });
42
+ (0, $m0yab$useLayoutEffect)(()=>{
43
+ if (state.isOpen && !isNonModal && popoverRef.current) return (0, $5e3802645cc19319$export$1c3ebcada18427bf)([
44
+ popoverRef.current
45
+ ]);
46
+ }, [
47
+ isNonModal,
48
+ state.isOpen,
49
+ popoverRef
50
+ ]);
51
+ return {
52
+ popoverProps: (0, $m0yab$mergeProps)(overlayProps, positionProps),
53
+ arrowProps: arrowProps,
54
+ underlayProps: underlayProps,
55
+ placement: placement
56
+ };
57
+ }
58
+
59
+
60
+ export {$f2f8a6077418541e$export$542a6fd13ac93354 as usePopover};
61
+ //# sourceMappingURL=usePopover.mjs.map
@@ -0,0 +1,61 @@
1
+ import {ariaHideOutside as $5e3802645cc19319$export$1c3ebcada18427bf} from "./ariaHideOutside.module.js";
2
+ import {useOverlayPosition as $2a41e45df1593e64$export$d39e1813b3bdd0e1} from "./useOverlayPosition.module.js";
3
+ import {useOverlay as $a11501f3d1d39e6c$export$ea8f71083e90600f} from "./useOverlay.module.js";
4
+ import {usePreventScroll as $49c51c25361d4cd2$export$ee0f7cc6afcd1c18} from "./usePreventScroll.module.js";
5
+ import {useLayoutEffect as $m0yab$useLayoutEffect, mergeProps as $m0yab$mergeProps} from "@react-aria/utils";
6
+
7
+ /*
8
+ * Copyright 2022 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */
18
+
19
+
20
+
21
+
22
+ function $f2f8a6077418541e$export$542a6fd13ac93354(props, state) {
23
+ let { triggerRef: triggerRef, popoverRef: popoverRef, isNonModal: isNonModal, isKeyboardDismissDisabled: isKeyboardDismissDisabled, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside, ...otherProps } = props;
24
+ let { overlayProps: overlayProps, underlayProps: underlayProps } = (0, $a11501f3d1d39e6c$export$ea8f71083e90600f)({
25
+ isOpen: state.isOpen,
26
+ onClose: state.close,
27
+ shouldCloseOnBlur: true,
28
+ isDismissable: !isNonModal,
29
+ isKeyboardDismissDisabled: isKeyboardDismissDisabled,
30
+ shouldCloseOnInteractOutside: shouldCloseOnInteractOutside
31
+ }, popoverRef);
32
+ let { overlayProps: positionProps, arrowProps: arrowProps, placement: placement } = (0, $2a41e45df1593e64$export$d39e1813b3bdd0e1)({
33
+ ...otherProps,
34
+ targetRef: triggerRef,
35
+ overlayRef: popoverRef,
36
+ isOpen: state.isOpen,
37
+ onClose: isNonModal ? state.close : null
38
+ });
39
+ (0, $49c51c25361d4cd2$export$ee0f7cc6afcd1c18)({
40
+ isDisabled: isNonModal || !state.isOpen
41
+ });
42
+ (0, $m0yab$useLayoutEffect)(()=>{
43
+ if (state.isOpen && !isNonModal && popoverRef.current) return (0, $5e3802645cc19319$export$1c3ebcada18427bf)([
44
+ popoverRef.current
45
+ ]);
46
+ }, [
47
+ isNonModal,
48
+ state.isOpen,
49
+ popoverRef
50
+ ]);
51
+ return {
52
+ popoverProps: (0, $m0yab$mergeProps)(overlayProps, positionProps),
53
+ arrowProps: arrowProps,
54
+ underlayProps: underlayProps,
55
+ placement: placement
56
+ };
57
+ }
58
+
59
+
60
+ export {$f2f8a6077418541e$export$542a6fd13ac93354 as usePopover};
61
+ //# sourceMappingURL=usePopover.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA+DM,SAAS,0CAAW,KAAuB,EAAE,KAA0B;IAC5E,IAAI,cACF,UAAU,cACV,UAAU,cACV,UAAU,6BACV,yBAAyB,gCACzB,4BAA4B,EAC5B,GAAG,YACJ,GAAG;IAEJ,IAAI,gBAAC,YAAY,iBAAE,aAAa,EAAC,GAAG,CAAA,GAAA,yCAAS,EAC3C;QACE,QAAQ,MAAM,MAAM;QACpB,SAAS,MAAM,KAAK;QACpB,mBAAmB;QACnB,eAAe,CAAC;mCAChB;sCACA;IACF,GACA;IAGF,IAAI,EAAC,cAAc,aAAa,cAAE,UAAU,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,yCAAiB,EAAE;QAC5E,GAAG,UAAU;QACb,WAAW;QACX,YAAY;QACZ,QAAQ,MAAM,MAAM;QACpB,SAAS,aAAa,MAAM,KAAK,GAAG;IACtC;IAEA,CAAA,GAAA,yCAAe,EAAE;QACf,YAAY,cAAc,CAAC,MAAM,MAAM;IACzC;IAEA,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,MAAM,MAAM,IAAI,CAAC,cAAc,WAAW,OAAO,EACnD,OAAO,CAAA,GAAA,yCAAc,EAAE;YAAC,WAAW,OAAO;SAAC;IAE/C,GAAG;QAAC;QAAY,MAAM,MAAM;QAAE;KAAW;IAEzC,OAAO;QACL,cAAc,CAAA,GAAA,iBAAS,EAAE,cAAc;oBACvC;uBACA;mBACA;IACF;AACF","sources":["packages/@react-aria/overlays/src/usePopover.ts"],"sourcesContent":["/*\n * Copyright 2022 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {ariaHideOutside} from './ariaHideOutside';\nimport {AriaPositionProps, useOverlayPosition} from './useOverlayPosition';\nimport {DOMAttributes} from '@react-types/shared';\nimport {mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport {OverlayTriggerState} from '@react-stately/overlays';\nimport {PlacementAxis} from '@react-types/overlays';\nimport {RefObject} from 'react';\nimport {useOverlay} from './useOverlay';\nimport {usePreventScroll} from './usePreventScroll';\n\nexport interface AriaPopoverProps extends Omit<AriaPositionProps, 'isOpen' | 'onClose' | 'targetRef' | 'overlayRef'> {\n /**\n * The ref for the element which the popover positions itself with respect to.\n */\n triggerRef: RefObject<Element>,\n /**\n * The ref for the popover element.\n */\n popoverRef: RefObject<Element>,\n /**\n * Whether the popover is non-modal, i.e. elements outside the popover may be\n * interacted with by assistive technologies.\n *\n * Most popovers should not use this option as it may negatively impact the screen\n * reader experience. Only use with components such as combobox, which are designed\n * to handle this situation carefully.\n */\n isNonModal?: boolean,\n /**\n * Whether pressing the escape key to close the popover should be disabled.\n *\n * Most popovers should not use this option. When set to true, an alternative\n * way to close the popover with a keyboard must be provided.\n *\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n /**\n * When user interacts with the argument element outside of the popover ref,\n * return true if onClose should be called. This gives you a chance to filter\n * out interaction with elements that should not dismiss the popover.\n * By default, onClose will always be called on interaction outside the popover ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface PopoverAria {\n /** Props for the popover element. */\n popoverProps: DOMAttributes,\n /** Props for the popover tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes,\n /** Placement of the popover with respect to the trigger. */\n placement: PlacementAxis\n}\n\n/**\n * Provides the behavior and accessibility implementation for a popover component.\n * A popover is an overlay element positioned relative to a trigger.\n */\nexport function usePopover(props: AriaPopoverProps, state: OverlayTriggerState): PopoverAria {\n let {\n triggerRef,\n popoverRef,\n isNonModal,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside,\n ...otherProps\n } = props;\n\n let {overlayProps, underlayProps} = useOverlay(\n {\n isOpen: state.isOpen,\n onClose: state.close,\n shouldCloseOnBlur: true,\n isDismissable: !isNonModal,\n isKeyboardDismissDisabled,\n shouldCloseOnInteractOutside\n },\n popoverRef\n );\n\n let {overlayProps: positionProps, arrowProps, placement} = useOverlayPosition({\n ...otherProps,\n targetRef: triggerRef,\n overlayRef: popoverRef,\n isOpen: state.isOpen,\n onClose: isNonModal ? state.close : null\n });\n\n usePreventScroll({\n isDisabled: isNonModal || !state.isOpen\n });\n\n useLayoutEffect(() => {\n if (state.isOpen && !isNonModal && popoverRef.current) {\n return ariaHideOutside([popoverRef.current]);\n }\n }, [isNonModal, state.isOpen, popoverRef]);\n\n return {\n popoverProps: mergeProps(overlayProps, positionProps),\n arrowProps,\n underlayProps,\n placement\n };\n}\n"],"names":[],"version":3,"file":"usePopover.module.js.map"}
@@ -0,0 +1,226 @@
1
+ var $59kHH$reactariautils = require("@react-aria/utils");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "usePreventScroll", () => $5c2f5cd01815d369$export$ee0f7cc6afcd1c18);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+ // @ts-ignore
21
+ const $5c2f5cd01815d369$var$visualViewport = typeof document !== "undefined" && window.visualViewport;
22
+ // HTML input types that do not cause the software keyboard to appear.
23
+ const $5c2f5cd01815d369$var$nonTextInputTypes = new Set([
24
+ "checkbox",
25
+ "radio",
26
+ "range",
27
+ "color",
28
+ "file",
29
+ "image",
30
+ "button",
31
+ "submit",
32
+ "reset"
33
+ ]);
34
+ // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
35
+ let $5c2f5cd01815d369$var$preventScrollCount = 0;
36
+ let $5c2f5cd01815d369$var$restore;
37
+ function $5c2f5cd01815d369$export$ee0f7cc6afcd1c18(options = {}) {
38
+ let { isDisabled: isDisabled } = options;
39
+ (0, $59kHH$reactariautils.useLayoutEffect)(()=>{
40
+ if (isDisabled) return;
41
+ $5c2f5cd01815d369$var$preventScrollCount++;
42
+ if ($5c2f5cd01815d369$var$preventScrollCount === 1) {
43
+ if ((0, $59kHH$reactariautils.isIOS)()) $5c2f5cd01815d369$var$restore = $5c2f5cd01815d369$var$preventScrollMobileSafari();
44
+ else $5c2f5cd01815d369$var$restore = $5c2f5cd01815d369$var$preventScrollStandard();
45
+ }
46
+ return ()=>{
47
+ $5c2f5cd01815d369$var$preventScrollCount--;
48
+ if ($5c2f5cd01815d369$var$preventScrollCount === 0) $5c2f5cd01815d369$var$restore();
49
+ };
50
+ }, [
51
+ isDisabled
52
+ ]);
53
+ }
54
+ // For most browsers, all we need to do is set `overflow: hidden` on the root element, and
55
+ // add some padding to prevent the page from shifting when the scrollbar is hidden.
56
+ function $5c2f5cd01815d369$var$preventScrollStandard() {
57
+ return (0, $59kHH$reactariautils.chain)($5c2f5cd01815d369$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $5c2f5cd01815d369$var$setStyle(document.documentElement, "overflow", "hidden"));
58
+ }
59
+ // Mobile Safari is a whole different beast. Even with overflow: hidden,
60
+ // it still scrolls the page in many situations:
61
+ //
62
+ // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
63
+ // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
64
+ // it, so it becomes scrollable.
65
+ // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
66
+ // This may cause even fixed position elements to scroll off the screen.
67
+ // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
68
+ // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
69
+ //
70
+ // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
71
+ //
72
+ // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
73
+ // on the window.
74
+ // 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
75
+ // the top or bottom. Work around a bug where this does not work when the element does not actually overflow
76
+ // by preventing default in a `touchmove` event.
77
+ // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
78
+ // 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
79
+ // of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
80
+ // into view ourselves, without scrolling the whole page.
81
+ // 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
82
+ // same visually, but makes the actual scroll position always zero. This is required to make all of the
83
+ // above work or Safari will still try to scroll the page when focusing an input.
84
+ // 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
85
+ // to navigate to an input with the next/previous buttons that's outside a modal.
86
+ function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
87
+ let scrollable;
88
+ let restoreScrollableStyles;
89
+ let onTouchStart = (e)=>{
90
+ // Store the nearest scrollable parent element from the element that the user touched.
91
+ scrollable = (0, $59kHH$reactariautils.getScrollParent)(e.target, true);
92
+ if (scrollable === document.documentElement && scrollable === document.body) return;
93
+ // Prevent scrolling up when at the top and scrolling down when at the bottom
94
+ // of a nested scrollable area, otherwise mobile Safari will start scrolling
95
+ // the window instead.
96
+ if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === "auto") restoreScrollableStyles = $5c2f5cd01815d369$var$setStyle(scrollable, "overscrollBehavior", "contain");
97
+ };
98
+ let onTouchMove = (e)=>{
99
+ // Prevent scrolling the window.
100
+ if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
101
+ e.preventDefault();
102
+ return;
103
+ }
104
+ // overscroll-behavior should prevent scroll chaining, but currently does not
105
+ // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
106
+ // This checks that both the width and height do not overflow, otherwise we might
107
+ // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
108
+ // the element will prevent vertical page scrolling. We can't add that automatically
109
+ // because it must be set before the touchstart event.
110
+ if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
111
+ };
112
+ let onTouchEnd = (e)=>{
113
+ let target = e.target;
114
+ // Apply this change if we're not already focused on the target element
115
+ if ($5c2f5cd01815d369$var$willOpenKeyboard(target) && target !== document.activeElement) {
116
+ e.preventDefault();
117
+ setupStyles();
118
+ // Apply a transform to trick Safari into thinking the input is at the top of the page
119
+ // so it doesn't try to scroll it into view. When tapping on an input, this needs to
120
+ // be done before the "focus" event, so we have to focus the element ourselves.
121
+ target.style.transform = "translateY(-2000px)";
122
+ target.focus();
123
+ requestAnimationFrame(()=>{
124
+ target.style.transform = "";
125
+ });
126
+ }
127
+ if (restoreScrollableStyles) restoreScrollableStyles();
128
+ };
129
+ let onFocus = (e)=>{
130
+ let target = e.target;
131
+ if ($5c2f5cd01815d369$var$willOpenKeyboard(target)) {
132
+ setupStyles();
133
+ // Transform also needs to be applied in the focus event in cases where focus moves
134
+ // other than tapping on an input directly, e.g. the next/previous buttons in the
135
+ // software keyboard. In these cases, it seems applying the transform in the focus event
136
+ // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
137
+ target.style.transform = "translateY(-2000px)";
138
+ requestAnimationFrame(()=>{
139
+ target.style.transform = "";
140
+ // This will have prevented the browser from scrolling the focused element into view,
141
+ // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
142
+ if ($5c2f5cd01815d369$var$visualViewport) {
143
+ if ($5c2f5cd01815d369$var$visualViewport.height < window.innerHeight) // If the keyboard is already visible, do this after one additional frame
144
+ // to wait for the transform to be removed.
145
+ requestAnimationFrame(()=>{
146
+ $5c2f5cd01815d369$var$scrollIntoView(target);
147
+ });
148
+ else // Otherwise, wait for the visual viewport to resize before scrolling so we can
149
+ // measure the correct position to scroll to.
150
+ $5c2f5cd01815d369$var$visualViewport.addEventListener("resize", ()=>$5c2f5cd01815d369$var$scrollIntoView(target), {
151
+ once: true
152
+ });
153
+ }
154
+ });
155
+ }
156
+ };
157
+ let restoreStyles = null;
158
+ let setupStyles = ()=>{
159
+ if (restoreStyles) return;
160
+ let onWindowScroll = ()=>{
161
+ // Last resort. If the window scrolled, scroll it back to the top.
162
+ // It should always be at the top because the body will have a negative margin (see below).
163
+ window.scrollTo(0, 0);
164
+ };
165
+ // Record the original scroll position so we can restore it.
166
+ // Then apply a negative margin to the body to offset it by the scroll position. This will
167
+ // enable us to scroll the window to the top, which is required for the rest of this to work.
168
+ let scrollX = window.pageXOffset;
169
+ let scrollY = window.pageYOffset;
170
+ restoreStyles = (0, $59kHH$reactariautils.chain)($5c2f5cd01815d369$var$addEvent(window, "scroll", onWindowScroll), $5c2f5cd01815d369$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $5c2f5cd01815d369$var$setStyle(document.documentElement, "overflow", "hidden"), $5c2f5cd01815d369$var$setStyle(document.body, "marginTop", `-${scrollY}px`), ()=>{
171
+ window.scrollTo(scrollX, scrollY);
172
+ });
173
+ // Scroll to the top. The negative margin on the body will make this appear the same.
174
+ window.scrollTo(0, 0);
175
+ };
176
+ let removeEvents = (0, $59kHH$reactariautils.chain)($5c2f5cd01815d369$var$addEvent(document, "touchstart", onTouchStart, {
177
+ passive: false,
178
+ capture: true
179
+ }), $5c2f5cd01815d369$var$addEvent(document, "touchmove", onTouchMove, {
180
+ passive: false,
181
+ capture: true
182
+ }), $5c2f5cd01815d369$var$addEvent(document, "touchend", onTouchEnd, {
183
+ passive: false,
184
+ capture: true
185
+ }), $5c2f5cd01815d369$var$addEvent(document, "focus", onFocus, true));
186
+ return ()=>{
187
+ // Restore styles and scroll the page back to where it was.
188
+ restoreScrollableStyles === null || restoreScrollableStyles === void 0 ? void 0 : restoreScrollableStyles();
189
+ restoreStyles === null || restoreStyles === void 0 ? void 0 : restoreStyles();
190
+ removeEvents();
191
+ };
192
+ }
193
+ // Sets a CSS property on an element, and returns a function to revert it to the previous value.
194
+ function $5c2f5cd01815d369$var$setStyle(element, style, value) {
195
+ let cur = element.style[style];
196
+ element.style[style] = value;
197
+ return ()=>{
198
+ element.style[style] = cur;
199
+ };
200
+ }
201
+ // Adds an event listener to an element, and returns a function to remove it.
202
+ function $5c2f5cd01815d369$var$addEvent(target, event, handler, options) {
203
+ target.addEventListener(event, handler, options);
204
+ return ()=>{
205
+ target.removeEventListener(event, handler, options);
206
+ };
207
+ }
208
+ function $5c2f5cd01815d369$var$scrollIntoView(target) {
209
+ let root = document.scrollingElement || document.documentElement;
210
+ while(target && target !== root){
211
+ // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
212
+ let scrollable = (0, $59kHH$reactariautils.getScrollParent)(target);
213
+ if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
214
+ let scrollableTop = scrollable.getBoundingClientRect().top;
215
+ let targetTop = target.getBoundingClientRect().top;
216
+ if (targetTop > scrollableTop + target.clientHeight) scrollable.scrollTop += targetTop - scrollableTop;
217
+ }
218
+ target = scrollable.parentElement;
219
+ }
220
+ }
221
+ function $5c2f5cd01815d369$var$willOpenKeyboard(target) {
222
+ return target instanceof HTMLInputElement && !$5c2f5cd01815d369$var$nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
223
+ }
224
+
225
+
226
+ //# sourceMappingURL=usePreventScroll.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","sources":["packages/@react-aria/overlays/src/usePreventScroll.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, getScrollParent, isIOS, useLayoutEffect} from '@react-aria/utils';\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean\n}\n\n// @ts-ignore\nconst visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}) {\n let {isDisabled} = options;\n\n useLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n return chain(\n setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),\n setStyle(document.documentElement, 'overflow', 'hidden')\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let restoreScrollableStyles;\n let onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element, true);\n if (scrollable === document.documentElement && scrollable === document.body) {\n return;\n }\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === 'auto') {\n restoreScrollableStyles = setStyle(scrollable, 'overscrollBehavior', 'contain');\n }\n };\n\n let onTouchMove = (e: TouchEvent) => {\n // Prevent scrolling the window.\n if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {\n e.preventDefault();\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) {\n e.preventDefault();\n }\n };\n\n let onTouchEnd = (e: TouchEvent) => {\n let target = e.target as HTMLElement;\n\n // Apply this change if we're not already focused on the target element\n if (willOpenKeyboard(target) && target !== document.activeElement) {\n e.preventDefault();\n setupStyles();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view. When tapping on an input, this needs to\n // be done before the \"focus\" event, so we have to focus the element ourselves.\n target.style.transform = 'translateY(-2000px)';\n target.focus();\n requestAnimationFrame(() => {\n target.style.transform = '';\n });\n }\n\n if (restoreScrollableStyles) {\n restoreScrollableStyles();\n }\n };\n\n let onFocus = (e: FocusEvent) => {\n let target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n setupStyles();\n\n // Transform also needs to be applied in the focus event in cases where focus moves\n // other than tapping on an input directly, e.g. the next/previous buttons in the\n // software keyboard. In these cases, it seems applying the transform in the focus event\n // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️\n target.style.transform = 'translateY(-2000px)';\n requestAnimationFrame(() => {\n target.style.transform = '';\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener('resize', () => scrollIntoView(target), {once: true});\n }\n }\n });\n }\n };\n\n let restoreStyles = null;\n let setupStyles = () => {\n if (restoreStyles) {\n return;\n }\n\n let onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n let scrollX = window.pageXOffset;\n let scrollY = window.pageYOffset;\n\n restoreStyles = chain(\n addEvent(window, 'scroll', onWindowScroll),\n setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),\n setStyle(document.documentElement, 'overflow', 'hidden'),\n setStyle(document.body, 'marginTop', `-${scrollY}px`),\n () => {\n window.scrollTo(scrollX, scrollY);\n }\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n };\n\n let removeEvents = chain(\n addEvent(document, 'touchstart', onTouchStart, {passive: false, capture: true}),\n addEvent(document, 'touchmove', onTouchMove, {passive: false, capture: true}),\n addEvent(document, 'touchend', onTouchEnd, {passive: false, capture: true}),\n addEvent(document, 'focus', onFocus, true)\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreScrollableStyles?.();\n restoreStyles?.();\n removeEvents();\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: HTMLElement, style: string, value: string) {\n let cur = element.style[style];\n element.style[style] = value;\n\n return () => {\n element.style[style] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: EventTarget,\n event: K,\n handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n target.addEventListener(event, handler, options);\n return () => {\n target.removeEventListener(event, handler, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n let root = document.scrollingElement || document.documentElement;\n while (target && target !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(target);\n if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {\n let scrollableTop = scrollable.getBoundingClientRect().top;\n let targetTop = target.getBoundingClientRect().top;\n if (targetTop > scrollableTop + target.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n target = scrollable.parentElement;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n"],"names":[],"version":3,"file":"usePreventScroll.main.js.map"}