@react-aria/overlays 3.21.1 → 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 (117) 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.mjs +1 -1
  17. package/dist/ariaHideOutside.main.js +121 -0
  18. package/dist/ariaHideOutside.main.js.map +1 -0
  19. package/dist/ariaHideOutside.mjs +116 -0
  20. package/dist/ariaHideOutside.module.js +116 -0
  21. package/dist/ariaHideOutside.module.js.map +1 -0
  22. package/dist/bg-BG.mjs +1 -1
  23. package/dist/calculatePosition.main.js +355 -0
  24. package/dist/calculatePosition.main.js.map +1 -0
  25. package/dist/calculatePosition.mjs +350 -0
  26. package/dist/calculatePosition.module.js +350 -0
  27. package/dist/calculatePosition.module.js.map +1 -0
  28. package/dist/cs-CZ.mjs +1 -1
  29. package/dist/da-DK.mjs +1 -1
  30. package/dist/de-DE.mjs +1 -1
  31. package/dist/el-GR.mjs +1 -1
  32. package/dist/en-US.mjs +1 -1
  33. package/dist/es-ES.mjs +1 -1
  34. package/dist/et-EE.mjs +1 -1
  35. package/dist/fi-FI.mjs +1 -1
  36. package/dist/fr-FR.mjs +1 -1
  37. package/dist/he-IL.mjs +1 -1
  38. package/dist/hr-HR.mjs +1 -1
  39. package/dist/hu-HU.mjs +1 -1
  40. package/dist/import.mjs +12 -1397
  41. package/dist/intlStrings.main.js +108 -0
  42. package/dist/intlStrings.main.js.map +1 -0
  43. package/dist/intlStrings.mjs +110 -0
  44. package/dist/intlStrings.module.js +110 -0
  45. package/dist/intlStrings.module.js.map +1 -0
  46. package/dist/it-IT.mjs +1 -1
  47. package/dist/ja-JP.mjs +1 -1
  48. package/dist/ko-KR.mjs +1 -1
  49. package/dist/lt-LT.mjs +1 -1
  50. package/dist/lv-LV.mjs +1 -1
  51. package/dist/main.js +28 -1411
  52. package/dist/main.js.map +1 -1
  53. package/dist/module.js +12 -1397
  54. package/dist/module.js.map +1 -1
  55. package/dist/nb-NO.mjs +1 -1
  56. package/dist/nl-NL.mjs +1 -1
  57. package/dist/pl-PL.mjs +1 -1
  58. package/dist/pt-BR.mjs +1 -1
  59. package/dist/pt-PT.mjs +1 -1
  60. package/dist/ro-RO.mjs +1 -1
  61. package/dist/ru-RU.mjs +1 -1
  62. package/dist/sk-SK.mjs +1 -1
  63. package/dist/sl-SI.mjs +1 -1
  64. package/dist/sr-SP.mjs +1 -1
  65. package/dist/sv-SE.mjs +1 -1
  66. package/dist/tr-TR.mjs +1 -1
  67. package/dist/types.d.ts +8 -1
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/uk-UA.mjs +1 -1
  70. package/dist/useCloseOnScroll.main.js +46 -0
  71. package/dist/useCloseOnScroll.main.js.map +1 -0
  72. package/dist/useCloseOnScroll.mjs +40 -0
  73. package/dist/useCloseOnScroll.module.js +40 -0
  74. package/dist/useCloseOnScroll.module.js.map +1 -0
  75. package/dist/useModal.main.js +114 -0
  76. package/dist/useModal.main.js.map +1 -0
  77. package/dist/useModal.mjs +101 -0
  78. package/dist/useModal.module.js +101 -0
  79. package/dist/useModal.module.js.map +1 -0
  80. package/dist/useModalOverlay.main.js +55 -0
  81. package/dist/useModalOverlay.main.js.map +1 -0
  82. package/dist/useModalOverlay.mjs +50 -0
  83. package/dist/useModalOverlay.module.js +50 -0
  84. package/dist/useModalOverlay.module.js.map +1 -0
  85. package/dist/useOverlay.main.js +105 -0
  86. package/dist/useOverlay.main.js.map +1 -0
  87. package/dist/useOverlay.mjs +100 -0
  88. package/dist/useOverlay.module.js +100 -0
  89. package/dist/useOverlay.module.js.map +1 -0
  90. package/dist/useOverlayPosition.main.js +181 -0
  91. package/dist/useOverlayPosition.main.js.map +1 -0
  92. package/dist/useOverlayPosition.mjs +176 -0
  93. package/dist/useOverlayPosition.module.js +176 -0
  94. package/dist/useOverlayPosition.module.js.map +1 -0
  95. package/dist/useOverlayTrigger.main.js +54 -0
  96. package/dist/useOverlayTrigger.main.js.map +1 -0
  97. package/dist/useOverlayTrigger.mjs +49 -0
  98. package/dist/useOverlayTrigger.module.js +49 -0
  99. package/dist/useOverlayTrigger.module.js.map +1 -0
  100. package/dist/usePopover.main.js +66 -0
  101. package/dist/usePopover.main.js.map +1 -0
  102. package/dist/usePopover.mjs +61 -0
  103. package/dist/usePopover.module.js +61 -0
  104. package/dist/usePopover.module.js.map +1 -0
  105. package/dist/usePreventScroll.main.js +226 -0
  106. package/dist/usePreventScroll.main.js.map +1 -0
  107. package/dist/usePreventScroll.mjs +221 -0
  108. package/dist/usePreventScroll.module.js +221 -0
  109. package/dist/usePreventScroll.module.js.map +1 -0
  110. package/dist/zh-CN.mjs +1 -1
  111. package/dist/zh-TW.mjs +1 -1
  112. package/package.json +12 -12
  113. package/src/Overlay.tsx +6 -0
  114. package/src/PortalProvider.tsx +34 -0
  115. package/src/index.ts +1 -0
  116. package/src/useModalOverlay.ts +2 -2
  117. package/src/useOverlay.ts +1 -1
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AA6CD,MAAM,wCAAwC,EAAE;AAOzC,SAAS,0CAAW,KAAuB,EAAE,GAAuB;IACzE,IAAI,WACF,OAAO,qBACP,iBAAiB,UACjB,MAAM,iBACN,gBAAgB,kCAChB,4BAA4B,qCAC5B,4BAA4B,E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3E,yEAAyE;YACzE,kEAAkE;YAClE,IAAI,CAAC,EAAE,aAAa,IAAI,CAAA,GAAA,mDAA4B,EAAE,EAAE,aAAa,GACnE;YAGF,IAAI,CAAC,gCAAgC,6BAA6B,EAAE,aAAa,GAC/E;QAEJ;IACF;IAEA,IAAI,wBAAwB,CAAA;QAC1B,wGAAwG;QACxG,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAC9B,EAAE,cAAc;IAEpB;IAEA,OAAO;QACL,cAAc;uBACZ;YACA,GAAG,gBAAgB;QACrB;QACA,eAAe;YACb,eAAe;QACjB;IACF;AACF","sources":["packages/@react-aria/overlays/src/useOverlay.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 {DOMAttributes} from '@react-types/shared';\nimport {isElementInChildOfActiveScope} from '@react-aria/focus';\nimport {RefObject, useEffect} from 'react';\nimport {useFocusWithin, useInteractOutside} from '@react-aria/interactions';\n\nexport interface AriaOverlayProps {\n /** Whether the overlay is currently open. */\n isOpen?: boolean,\n\n /** Handler that is called when the overlay should close. */\n onClose?: () => void,\n\n /**\n * Whether to close the overlay when the user interacts outside it.\n * @default false\n */\n isDismissable?: boolean,\n\n /** Whether the overlay should close when focus is lost or moves outside it. */\n shouldCloseOnBlur?: boolean,\n\n /**\n * Whether pressing the escape key to close the overlay should be disabled.\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n\n /**\n * When user interacts with the argument element outside of the overlay 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 overlay.\n * By default, onClose will always be called on interaction outside the overlay ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface OverlayAria {\n /** Props to apply to the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes\n}\n\nconst visibleOverlays: RefObject<Element>[] = [];\n\n/**\n * Provides the behavior for overlays such as dialogs, popovers, and menus.\n * Hides the overlay when the user interacts outside it, when the Escape key is pressed,\n * or optionally, on blur. Only the top-most overlay will close at once.\n */\nexport function useOverlay(props: AriaOverlayProps, ref: RefObject<Element>): OverlayAria {\n let {\n onClose,\n shouldCloseOnBlur,\n isOpen,\n isDismissable = false,\n isKeyboardDismissDisabled = false,\n shouldCloseOnInteractOutside\n } = props;\n\n // Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.\n useEffect(() => {\n if (isOpen) {\n visibleOverlays.push(ref);\n }\n\n return () => {\n let index = visibleOverlays.indexOf(ref);\n if (index >= 0) {\n visibleOverlays.splice(index, 1);\n }\n };\n }, [isOpen, ref]);\n\n // Only hide the overlay when it is the topmost visible overlay in the stack\n let onHide = () => {\n if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {\n onClose();\n }\n };\n\n let onInteractOutsideStart = (e: PointerEvent) => {\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {\n if (visibleOverlays[visibleOverlays.length - 1] === ref) {\n e.stopPropagation();\n e.preventDefault();\n }\n }\n };\n\n let onInteractOutside = (e: PointerEvent) => {\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {\n if (visibleOverlays[visibleOverlays.length - 1] === ref) {\n e.stopPropagation();\n e.preventDefault();\n }\n onHide();\n }\n };\n\n // Handle the escape key\n let onKeyDown = (e) => {\n if (e.key === 'Escape' && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {\n e.stopPropagation();\n e.preventDefault();\n onHide();\n }\n };\n\n // Handle clicking outside the overlay to close it\n useInteractOutside({ref, onInteractOutside: isDismissable && isOpen ? onInteractOutside : null, onInteractOutsideStart});\n\n let {focusWithinProps} = useFocusWithin({\n isDisabled: !shouldCloseOnBlur,\n onBlurWithin: (e) => {\n // Do not close if relatedTarget is null, which means focus is lost to the body.\n // That can happen when switching tabs, or due to a VoiceOver/Chrome bug with Control+Option+Arrow navigation.\n // Clicking on the body to close the overlay should already be handled by useInteractOutside.\n // https://github.com/adobe/react-spectrum/issues/4130\n // https://github.com/adobe/react-spectrum/issues/4922\n //\n // If focus is moving into a child focus scope (e.g. menu inside a dialog),\n // do not close the outer overlay. At this point, the active scope should\n // still be the outer overlay, since blur events run before focus.\n if (!e.relatedTarget || isElementInChildOfActiveScope(e.relatedTarget)) {\n return;\n }\n\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget as Element)) {\n onClose();\n }\n }\n });\n\n let onPointerDownUnderlay = e => {\n // fixes a firefox issue that starts text selection https://bugzilla.mozilla.org/show_bug.cgi?id=1675846\n if (e.target === e.currentTarget) {\n e.preventDefault();\n }\n };\n\n return {\n overlayProps: {\n onKeyDown,\n ...focusWithinProps\n },\n underlayProps: {\n onPointerDown: onPointerDownUnderlay\n }\n };\n}\n"],"names":[],"version":3,"file":"useOverlay.main.js.map"}
@@ -0,0 +1,100 @@
1
+ import {isElementInChildOfActiveScope as $jtpZv$isElementInChildOfActiveScope} from "@react-aria/focus";
2
+ import {useEffect as $jtpZv$useEffect} from "react";
3
+ import {useInteractOutside as $jtpZv$useInteractOutside, useFocusWithin as $jtpZv$useFocusWithin} from "@react-aria/interactions";
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
+ const $a11501f3d1d39e6c$var$visibleOverlays = [];
19
+ function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
20
+ let { onClose: onClose, shouldCloseOnBlur: shouldCloseOnBlur, isOpen: isOpen, isDismissable: isDismissable = false, isKeyboardDismissDisabled: isKeyboardDismissDisabled = false, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside } = props;
21
+ // Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.
22
+ (0, $jtpZv$useEffect)(()=>{
23
+ if (isOpen) $a11501f3d1d39e6c$var$visibleOverlays.push(ref);
24
+ return ()=>{
25
+ let index = $a11501f3d1d39e6c$var$visibleOverlays.indexOf(ref);
26
+ if (index >= 0) $a11501f3d1d39e6c$var$visibleOverlays.splice(index, 1);
27
+ };
28
+ }, [
29
+ isOpen,
30
+ ref
31
+ ]);
32
+ // Only hide the overlay when it is the topmost visible overlay in the stack
33
+ let onHide = ()=>{
34
+ if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref && onClose) onClose();
35
+ };
36
+ let onInteractOutsideStart = (e)=>{
37
+ if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
38
+ if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref) {
39
+ e.stopPropagation();
40
+ e.preventDefault();
41
+ }
42
+ }
43
+ };
44
+ let onInteractOutside = (e)=>{
45
+ if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
46
+ if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref) {
47
+ e.stopPropagation();
48
+ e.preventDefault();
49
+ }
50
+ onHide();
51
+ }
52
+ };
53
+ // Handle the escape key
54
+ let onKeyDown = (e)=>{
55
+ if (e.key === "Escape" && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {
56
+ e.stopPropagation();
57
+ e.preventDefault();
58
+ onHide();
59
+ }
60
+ };
61
+ // Handle clicking outside the overlay to close it
62
+ (0, $jtpZv$useInteractOutside)({
63
+ ref: ref,
64
+ onInteractOutside: isDismissable && isOpen ? onInteractOutside : null,
65
+ onInteractOutsideStart: onInteractOutsideStart
66
+ });
67
+ let { focusWithinProps: focusWithinProps } = (0, $jtpZv$useFocusWithin)({
68
+ isDisabled: !shouldCloseOnBlur,
69
+ onBlurWithin: (e)=>{
70
+ // Do not close if relatedTarget is null, which means focus is lost to the body.
71
+ // That can happen when switching tabs, or due to a VoiceOver/Chrome bug with Control+Option+Arrow navigation.
72
+ // Clicking on the body to close the overlay should already be handled by useInteractOutside.
73
+ // https://github.com/adobe/react-spectrum/issues/4130
74
+ // https://github.com/adobe/react-spectrum/issues/4922
75
+ //
76
+ // If focus is moving into a child focus scope (e.g. menu inside a dialog),
77
+ // do not close the outer overlay. At this point, the active scope should
78
+ // still be the outer overlay, since blur events run before focus.
79
+ if (!e.relatedTarget || (0, $jtpZv$isElementInChildOfActiveScope)(e.relatedTarget)) return;
80
+ if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) onClose();
81
+ }
82
+ });
83
+ let onPointerDownUnderlay = (e)=>{
84
+ // fixes a firefox issue that starts text selection https://bugzilla.mozilla.org/show_bug.cgi?id=1675846
85
+ if (e.target === e.currentTarget) e.preventDefault();
86
+ };
87
+ return {
88
+ overlayProps: {
89
+ onKeyDown: onKeyDown,
90
+ ...focusWithinProps
91
+ },
92
+ underlayProps: {
93
+ onPointerDown: onPointerDownUnderlay
94
+ }
95
+ };
96
+ }
97
+
98
+
99
+ export {$a11501f3d1d39e6c$export$ea8f71083e90600f as useOverlay};
100
+ //# sourceMappingURL=useOverlay.mjs.map
@@ -0,0 +1,100 @@
1
+ import {isElementInChildOfActiveScope as $jtpZv$isElementInChildOfActiveScope} from "@react-aria/focus";
2
+ import {useEffect as $jtpZv$useEffect} from "react";
3
+ import {useInteractOutside as $jtpZv$useInteractOutside, useFocusWithin as $jtpZv$useFocusWithin} from "@react-aria/interactions";
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
+ const $a11501f3d1d39e6c$var$visibleOverlays = [];
19
+ function $a11501f3d1d39e6c$export$ea8f71083e90600f(props, ref) {
20
+ let { onClose: onClose, shouldCloseOnBlur: shouldCloseOnBlur, isOpen: isOpen, isDismissable: isDismissable = false, isKeyboardDismissDisabled: isKeyboardDismissDisabled = false, shouldCloseOnInteractOutside: shouldCloseOnInteractOutside } = props;
21
+ // Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.
22
+ (0, $jtpZv$useEffect)(()=>{
23
+ if (isOpen) $a11501f3d1d39e6c$var$visibleOverlays.push(ref);
24
+ return ()=>{
25
+ let index = $a11501f3d1d39e6c$var$visibleOverlays.indexOf(ref);
26
+ if (index >= 0) $a11501f3d1d39e6c$var$visibleOverlays.splice(index, 1);
27
+ };
28
+ }, [
29
+ isOpen,
30
+ ref
31
+ ]);
32
+ // Only hide the overlay when it is the topmost visible overlay in the stack
33
+ let onHide = ()=>{
34
+ if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref && onClose) onClose();
35
+ };
36
+ let onInteractOutsideStart = (e)=>{
37
+ if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
38
+ if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref) {
39
+ e.stopPropagation();
40
+ e.preventDefault();
41
+ }
42
+ }
43
+ };
44
+ let onInteractOutside = (e)=>{
45
+ if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target)) {
46
+ if ($a11501f3d1d39e6c$var$visibleOverlays[$a11501f3d1d39e6c$var$visibleOverlays.length - 1] === ref) {
47
+ e.stopPropagation();
48
+ e.preventDefault();
49
+ }
50
+ onHide();
51
+ }
52
+ };
53
+ // Handle the escape key
54
+ let onKeyDown = (e)=>{
55
+ if (e.key === "Escape" && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {
56
+ e.stopPropagation();
57
+ e.preventDefault();
58
+ onHide();
59
+ }
60
+ };
61
+ // Handle clicking outside the overlay to close it
62
+ (0, $jtpZv$useInteractOutside)({
63
+ ref: ref,
64
+ onInteractOutside: isDismissable && isOpen ? onInteractOutside : null,
65
+ onInteractOutsideStart: onInteractOutsideStart
66
+ });
67
+ let { focusWithinProps: focusWithinProps } = (0, $jtpZv$useFocusWithin)({
68
+ isDisabled: !shouldCloseOnBlur,
69
+ onBlurWithin: (e)=>{
70
+ // Do not close if relatedTarget is null, which means focus is lost to the body.
71
+ // That can happen when switching tabs, or due to a VoiceOver/Chrome bug with Control+Option+Arrow navigation.
72
+ // Clicking on the body to close the overlay should already be handled by useInteractOutside.
73
+ // https://github.com/adobe/react-spectrum/issues/4130
74
+ // https://github.com/adobe/react-spectrum/issues/4922
75
+ //
76
+ // If focus is moving into a child focus scope (e.g. menu inside a dialog),
77
+ // do not close the outer overlay. At this point, the active scope should
78
+ // still be the outer overlay, since blur events run before focus.
79
+ if (!e.relatedTarget || (0, $jtpZv$isElementInChildOfActiveScope)(e.relatedTarget)) return;
80
+ if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget)) onClose();
81
+ }
82
+ });
83
+ let onPointerDownUnderlay = (e)=>{
84
+ // fixes a firefox issue that starts text selection https://bugzilla.mozilla.org/show_bug.cgi?id=1675846
85
+ if (e.target === e.currentTarget) e.preventDefault();
86
+ };
87
+ return {
88
+ overlayProps: {
89
+ onKeyDown: onKeyDown,
90
+ ...focusWithinProps
91
+ },
92
+ underlayProps: {
93
+ onPointerDown: onPointerDownUnderlay
94
+ }
95
+ };
96
+ }
97
+
98
+
99
+ export {$a11501f3d1d39e6c$export$ea8f71083e90600f as useOverlay};
100
+ //# sourceMappingURL=useOverlay.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AA6CD,MAAM,wCAAwC,EAAE;AAOzC,SAAS,0CAAW,KAAuB,EAAE,GAAuB;IACzE,IAAI,WACF,OAAO,qBACP,iBAAiB,UACjB,MAAM,iBACN,gBAAgB,kCAChB,4BAA4B,qCAC5B,4BAA4B,EAC7B,GAAG;IAEJ,wFAAwF;IACxF,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,QACF,sCAAgB,IAAI,CAAC;QAGvB,OAAO;YACL,IAAI,QAAQ,sCAAgB,OAAO,CAAC;YACpC,IAAI,SAAS,GACX,sCAAgB,MAAM,CAAC,OAAO;QAElC;IACF,GAAG;QAAC;QAAQ;KAAI;IAEhB,4EAA4E;IAC5E,IAAI,SAAS;QACX,IAAI,qCAAe,CAAC,sCAAgB,MAAM,GAAG,EAAE,KAAK,OAAO,SACzD;IAEJ;IAEA,IAAI,yBAAyB,CAAC;QAC5B,IAAI,CAAC,gCAAgC,6BAA6B,EAAE,MAAM,GACxE;YAAA,IAAI,qCAAe,CAAC,sCAAgB,MAAM,GAAG,EAAE,KAAK,KAAK;gBACvD,EAAE,eAAe;gBACjB,EAAE,cAAc;YAClB;QAAA;IAEJ;IAEA,IAAI,oBAAoB,CAAC;QACvB,IAAI,CAAC,gCAAgC,6BAA6B,EAAE,MAAM,GAAc;YACtF,IAAI,qCAAe,CAAC,sCAAgB,MAAM,GAAG,EAAE,KAAK,KAAK;gBACvD,EAAE,eAAe;gBACjB,EAAE,cAAc;YAClB;YACA;QACF;IACF;IAEA,wBAAwB;IACxB,IAAI,YAAY,CAAC;QACf,IAAI,EAAE,GAAG,KAAK,YAAY,CAAC,6BAA6B,CAAC,EAAE,WAAW,CAAC,WAAW,EAAE;YAClF,EAAE,eAAe;YACjB,EAAE,cAAc;YAChB;QACF;IACF;IAEA,kDAAkD;IAClD,CAAA,GAAA,yBAAiB,EAAE;aAAC;QAAK,mBAAmB,iBAAiB,SAAS,oBAAoB;gCAAM;IAAsB;IAEtH,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QACtC,YAAY,CAAC;QACb,cAAc,CAAC;YACb,gFAAgF;YAChF,8GAA8G;YAC9G,6FAA6F;YAC7F,sDAAsD;YACtD,sDAAsD;YACtD,EAAE;YACF,2EAA2E;YAC3E,yEAAyE;YACzE,kEAAkE;YAClE,IAAI,CAAC,EAAE,aAAa,IAAI,CAAA,GAAA,oCAA4B,EAAE,EAAE,aAAa,GACnE;YAGF,IAAI,CAAC,gCAAgC,6BAA6B,EAAE,aAAa,GAC/E;QAEJ;IACF;IAEA,IAAI,wBAAwB,CAAA;QAC1B,wGAAwG;QACxG,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAC9B,EAAE,cAAc;IAEpB;IAEA,OAAO;QACL,cAAc;uBACZ;YACA,GAAG,gBAAgB;QACrB;QACA,eAAe;YACb,eAAe;QACjB;IACF;AACF","sources":["packages/@react-aria/overlays/src/useOverlay.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 {DOMAttributes} from '@react-types/shared';\nimport {isElementInChildOfActiveScope} from '@react-aria/focus';\nimport {RefObject, useEffect} from 'react';\nimport {useFocusWithin, useInteractOutside} from '@react-aria/interactions';\n\nexport interface AriaOverlayProps {\n /** Whether the overlay is currently open. */\n isOpen?: boolean,\n\n /** Handler that is called when the overlay should close. */\n onClose?: () => void,\n\n /**\n * Whether to close the overlay when the user interacts outside it.\n * @default false\n */\n isDismissable?: boolean,\n\n /** Whether the overlay should close when focus is lost or moves outside it. */\n shouldCloseOnBlur?: boolean,\n\n /**\n * Whether pressing the escape key to close the overlay should be disabled.\n * @default false\n */\n isKeyboardDismissDisabled?: boolean,\n\n /**\n * When user interacts with the argument element outside of the overlay 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 overlay.\n * By default, onClose will always be called on interaction outside the overlay ref.\n */\n shouldCloseOnInteractOutside?: (element: Element) => boolean\n}\n\nexport interface OverlayAria {\n /** Props to apply to the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props to apply to the underlay element, if any. */\n underlayProps: DOMAttributes\n}\n\nconst visibleOverlays: RefObject<Element>[] = [];\n\n/**\n * Provides the behavior for overlays such as dialogs, popovers, and menus.\n * Hides the overlay when the user interacts outside it, when the Escape key is pressed,\n * or optionally, on blur. Only the top-most overlay will close at once.\n */\nexport function useOverlay(props: AriaOverlayProps, ref: RefObject<Element>): OverlayAria {\n let {\n onClose,\n shouldCloseOnBlur,\n isOpen,\n isDismissable = false,\n isKeyboardDismissDisabled = false,\n shouldCloseOnInteractOutside\n } = props;\n\n // Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.\n useEffect(() => {\n if (isOpen) {\n visibleOverlays.push(ref);\n }\n\n return () => {\n let index = visibleOverlays.indexOf(ref);\n if (index >= 0) {\n visibleOverlays.splice(index, 1);\n }\n };\n }, [isOpen, ref]);\n\n // Only hide the overlay when it is the topmost visible overlay in the stack\n let onHide = () => {\n if (visibleOverlays[visibleOverlays.length - 1] === ref && onClose) {\n onClose();\n }\n };\n\n let onInteractOutsideStart = (e: PointerEvent) => {\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {\n if (visibleOverlays[visibleOverlays.length - 1] === ref) {\n e.stopPropagation();\n e.preventDefault();\n }\n }\n };\n\n let onInteractOutside = (e: PointerEvent) => {\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {\n if (visibleOverlays[visibleOverlays.length - 1] === ref) {\n e.stopPropagation();\n e.preventDefault();\n }\n onHide();\n }\n };\n\n // Handle the escape key\n let onKeyDown = (e) => {\n if (e.key === 'Escape' && !isKeyboardDismissDisabled && !e.nativeEvent.isComposing) {\n e.stopPropagation();\n e.preventDefault();\n onHide();\n }\n };\n\n // Handle clicking outside the overlay to close it\n useInteractOutside({ref, onInteractOutside: isDismissable && isOpen ? onInteractOutside : null, onInteractOutsideStart});\n\n let {focusWithinProps} = useFocusWithin({\n isDisabled: !shouldCloseOnBlur,\n onBlurWithin: (e) => {\n // Do not close if relatedTarget is null, which means focus is lost to the body.\n // That can happen when switching tabs, or due to a VoiceOver/Chrome bug with Control+Option+Arrow navigation.\n // Clicking on the body to close the overlay should already be handled by useInteractOutside.\n // https://github.com/adobe/react-spectrum/issues/4130\n // https://github.com/adobe/react-spectrum/issues/4922\n //\n // If focus is moving into a child focus scope (e.g. menu inside a dialog),\n // do not close the outer overlay. At this point, the active scope should\n // still be the outer overlay, since blur events run before focus.\n if (!e.relatedTarget || isElementInChildOfActiveScope(e.relatedTarget)) {\n return;\n }\n\n if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.relatedTarget as Element)) {\n onClose();\n }\n }\n });\n\n let onPointerDownUnderlay = e => {\n // fixes a firefox issue that starts text selection https://bugzilla.mozilla.org/show_bug.cgi?id=1675846\n if (e.target === e.currentTarget) {\n e.preventDefault();\n }\n };\n\n return {\n overlayProps: {\n onKeyDown,\n ...focusWithinProps\n },\n underlayProps: {\n onPointerDown: onPointerDownUnderlay\n }\n };\n}\n"],"names":[],"version":3,"file":"useOverlay.module.js.map"}
@@ -0,0 +1,181 @@
1
+ var $5935ba4d7da2c103$exports = require("./calculatePosition.main.js");
2
+ var $9a8aa1b0b336ea3a$exports = require("./useCloseOnScroll.main.js");
3
+ var $6TXnl$react = require("react");
4
+ var $6TXnl$reactariautils = require("@react-aria/utils");
5
+ var $6TXnl$reactariai18n = require("@react-aria/i18n");
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, "useOverlayPosition", () => $cd94b4896dd97759$export$d39e1813b3bdd0e1);
13
+ /*
14
+ * Copyright 2020 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
+ // @ts-ignore
29
+ let $cd94b4896dd97759$var$visualViewport = typeof document !== "undefined" && window.visualViewport;
30
+ function $cd94b4896dd97759$export$d39e1813b3bdd0e1(props) {
31
+ let { direction: direction } = (0, $6TXnl$reactariai18n.useLocale)();
32
+ let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement = "bottom", containerPadding: containerPadding = 12, shouldFlip: shouldFlip = true, boundaryElement: boundaryElement = typeof document !== "undefined" ? document.body : null, offset: offset = 0, crossOffset: crossOffset = 0, shouldUpdatePosition: shouldUpdatePosition = true, isOpen: isOpen = true, onClose: onClose, maxHeight: maxHeight, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = props;
33
+ let [position, setPosition] = (0, $6TXnl$react.useState)({
34
+ position: {},
35
+ arrowOffsetLeft: undefined,
36
+ arrowOffsetTop: undefined,
37
+ maxHeight: undefined,
38
+ placement: undefined
39
+ });
40
+ let deps = [
41
+ shouldUpdatePosition,
42
+ placement,
43
+ overlayRef.current,
44
+ targetRef.current,
45
+ scrollRef.current,
46
+ containerPadding,
47
+ shouldFlip,
48
+ boundaryElement,
49
+ offset,
50
+ crossOffset,
51
+ isOpen,
52
+ direction,
53
+ maxHeight,
54
+ arrowBoundaryOffset,
55
+ arrowSize
56
+ ];
57
+ // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might
58
+ // just be a non-realistic use case
59
+ // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles
60
+ let lastScale = (0, $6TXnl$react.useRef)($cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale);
61
+ (0, $6TXnl$react.useEffect)(()=>{
62
+ if (isOpen) lastScale.current = $cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale;
63
+ }, [
64
+ isOpen
65
+ ]);
66
+ let updatePosition = (0, $6TXnl$react.useCallback)(()=>{
67
+ if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) return;
68
+ if (($cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.scale) !== lastScale.current) return;
69
+ // Always reset the overlay's previous max height if not defined by the user so that we can compensate for
70
+ // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
71
+ if (!maxHeight && overlayRef.current) overlayRef.current.style.maxHeight = "none";
72
+ let position = (0, $5935ba4d7da2c103$exports.calculatePosition)({
73
+ placement: $cd94b4896dd97759$var$translateRTL(placement, direction),
74
+ overlayNode: overlayRef.current,
75
+ targetNode: targetRef.current,
76
+ scrollNode: scrollRef.current,
77
+ padding: containerPadding,
78
+ shouldFlip: shouldFlip,
79
+ boundaryElement: boundaryElement,
80
+ offset: offset,
81
+ crossOffset: crossOffset,
82
+ maxHeight: maxHeight,
83
+ arrowSize: arrowSize,
84
+ arrowBoundaryOffset: arrowBoundaryOffset
85
+ });
86
+ // Modify overlay styles directly so positioning happens immediately without the need of a second render
87
+ // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
88
+ Object.keys(position.position).forEach((key)=>overlayRef.current.style[key] = position.position[key] + "px");
89
+ overlayRef.current.style.maxHeight = position.maxHeight != null ? position.maxHeight + "px" : undefined;
90
+ // Trigger a set state for a second render anyway for arrow positioning
91
+ setPosition(position);
92
+ // eslint-disable-next-line react-hooks/exhaustive-deps
93
+ }, deps);
94
+ // Update position when anything changes
95
+ // eslint-disable-next-line react-hooks/exhaustive-deps
96
+ (0, $6TXnl$reactariautils.useLayoutEffect)(updatePosition, deps);
97
+ // Update position on window resize
98
+ $cd94b4896dd97759$var$useResize(updatePosition);
99
+ // Update position when the overlay changes size (might need to flip).
100
+ (0, $6TXnl$reactariautils.useResizeObserver)({
101
+ ref: overlayRef,
102
+ onResize: updatePosition
103
+ });
104
+ // Reposition the overlay and do not close on scroll while the visual viewport is resizing.
105
+ // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
106
+ let isResizing = (0, $6TXnl$react.useRef)(false);
107
+ (0, $6TXnl$reactariautils.useLayoutEffect)(()=>{
108
+ let timeout;
109
+ let onResize = ()=>{
110
+ isResizing.current = true;
111
+ clearTimeout(timeout);
112
+ timeout = setTimeout(()=>{
113
+ isResizing.current = false;
114
+ }, 500);
115
+ updatePosition();
116
+ };
117
+ // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
118
+ // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
119
+ let onScroll = ()=>{
120
+ if (isResizing.current) onResize();
121
+ };
122
+ $cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener("resize", onResize);
123
+ $cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.addEventListener("scroll", onScroll);
124
+ return ()=>{
125
+ $cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener("resize", onResize);
126
+ $cd94b4896dd97759$var$visualViewport === null || $cd94b4896dd97759$var$visualViewport === void 0 ? void 0 : $cd94b4896dd97759$var$visualViewport.removeEventListener("scroll", onScroll);
127
+ };
128
+ }, [
129
+ updatePosition
130
+ ]);
131
+ let close = (0, $6TXnl$react.useCallback)(()=>{
132
+ if (!isResizing.current) onClose();
133
+ }, [
134
+ onClose,
135
+ isResizing
136
+ ]);
137
+ // When scrolling a parent scrollable region of the trigger (other than the body),
138
+ // we hide the popover. Otherwise, its position would be incorrect.
139
+ (0, $9a8aa1b0b336ea3a$exports.useCloseOnScroll)({
140
+ triggerRef: targetRef,
141
+ isOpen: isOpen,
142
+ onClose: onClose && close
143
+ });
144
+ return {
145
+ overlayProps: {
146
+ style: {
147
+ position: "absolute",
148
+ zIndex: 100000,
149
+ ...position.position,
150
+ maxHeight: position.maxHeight
151
+ }
152
+ },
153
+ placement: position.placement,
154
+ arrowProps: {
155
+ "aria-hidden": "true",
156
+ role: "presentation",
157
+ style: {
158
+ left: position.arrowOffsetLeft,
159
+ top: position.arrowOffsetTop
160
+ }
161
+ },
162
+ updatePosition: updatePosition
163
+ };
164
+ }
165
+ function $cd94b4896dd97759$var$useResize(onResize) {
166
+ (0, $6TXnl$reactariautils.useLayoutEffect)(()=>{
167
+ window.addEventListener("resize", onResize, false);
168
+ return ()=>{
169
+ window.removeEventListener("resize", onResize, false);
170
+ };
171
+ }, [
172
+ onResize
173
+ ]);
174
+ }
175
+ function $cd94b4896dd97759$var$translateRTL(position, direction) {
176
+ if (direction === "rtl") return position.replace("start", "right").replace("end", "left");
177
+ return position.replace("start", "left").replace("end", "right");
178
+ }
179
+
180
+
181
+ //# sourceMappingURL=useOverlayPosition.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgED,aAAa;AACb,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAMtE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,aACF,YAAY,cACZ,SAAS,cACT,UAAU,aACV,YAAY,uBACZ,YAAY,4BACZ,mBAAmB,gBACnB,aAAa,uBACb,kBAAkB,OAAO,aAAa,cAAc,SAAS,IAAI,GAAG,cACpE,SAAS,gBACT,cAAc,yBACd,uBAAuB,cACvB,SAAS,eACT,OAAO,aACP,SAAS,uBACT,sBAAsB,GACvB,GAAG;IACJ,IAAI,CAAC,UAAU,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAkB;QACrD,UAAU,CAAC;QACX,iBAAiB;QACjB,gBAAgB;QAChB,WAAW;QACX,WAAW;IACb;IAEA,IAAI,OAAO;QACT;QACA;QACA,WAAW,OAAO;QAClB,UAAU,OAAO;QACjB,UAAU,OAAO;QACjB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,4GAA4G;IAC5G,mCAAmC;IACnC,uGAAuG;IACvG,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,iDAAA,2DAAA,qCAAgB,KAAK;IAC5C,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,QACF,UAAU,OAAO,GAAG,iDAAA,2DAAA,qCAAgB,KAAK;IAE7C,GAAG;QAAC;KAAO;IAEX,IAAI,iBAAiB,CAAA,GAAA,wBAAU,EAAE;QAC/B,IAAI,yBAAyB,SAAS,CAAC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 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 {calculatePosition, PositionResult} from './calculatePosition';\nimport {DOMAttributes} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {RefObject, useCallback, useEffect, useRef, useState} from 'react';\nimport {useCloseOnScroll} from './useCloseOnScroll';\nimport {useLayoutEffect, useResizeObserver} from '@react-aria/utils';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface AriaPositionProps extends PositionProps {\n /**\n * Cross size of the overlay arrow in pixels.\n * @default 0\n */\n arrowSize?: number,\n /**\n * Element that that serves as the positioning boundary.\n * @default document.body\n */\n boundaryElement?: Element,\n /**\n * The ref for the element which the overlay positions itself with respect to.\n */\n targetRef: RefObject<Element>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element>,\n /**\n * Whether the overlay should update its position automatically.\n * @default true\n */\n shouldUpdatePosition?: boolean,\n /** Handler that is called when the overlay should close. */\n onClose?: () => void,\n /**\n * The maxHeight specified for the overlay element.\n * By default, it will take all space up to the current viewport height.\n */\n maxHeight?: number,\n /**\n * The minimum distance the arrow's edge should be from the edge of the overlay element.\n * @default 0\n */\n arrowBoundaryOffset?: number\n}\n\nexport interface PositionAria {\n /** Props for the overlay container element. */\n overlayProps: DOMAttributes,\n /** Props for the overlay tip arrow if any. */\n arrowProps: DOMAttributes,\n /** Placement of the overlay with respect to the overlay trigger. */\n placement: PlacementAxis,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\n// @ts-ignore\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n/**\n * Handles positioning overlays like popovers and menus relative to a trigger\n * element, and updating the position when the window resizes.\n */\nexport function useOverlayPosition(props: AriaPositionProps): PositionAria {\n let {direction} = useLocale();\n let {\n arrowSize = 0,\n targetRef,\n overlayRef,\n scrollRef = overlayRef,\n placement = 'bottom' as Placement,\n containerPadding = 12,\n shouldFlip = true,\n boundaryElement = typeof document !== 'undefined' ? document.body : null,\n offset = 0,\n crossOffset = 0,\n shouldUpdatePosition = true,\n isOpen = true,\n onClose,\n maxHeight,\n arrowBoundaryOffset = 0\n } = props;\n let [position, setPosition] = useState<PositionResult>({\n position: {},\n arrowOffsetLeft: undefined,\n arrowOffsetTop: undefined,\n maxHeight: undefined,\n placement: undefined\n });\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n scrollRef.current,\n containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n isOpen,\n direction,\n maxHeight,\n arrowBoundaryOffset,\n arrowSize\n ];\n\n // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might\n // just be a non-realistic use case\n // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles\n let lastScale = useRef(visualViewport?.scale);\n useEffect(() => {\n if (isOpen) {\n lastScale.current = visualViewport?.scale;\n }\n }, [isOpen]);\n\n let updatePosition = useCallback(() => {\n if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Always reset the overlay's previous max height if not defined by the user so that we can compensate for\n // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.\n if (!maxHeight && overlayRef.current) {\n (overlayRef.current as HTMLElement).style.maxHeight = 'none';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize,\n arrowBoundaryOffset\n });\n\n // Modify overlay styles directly so positioning happens immediately without the need of a second render\n // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers\n Object.keys(position.position).forEach(key => (overlayRef.current as HTMLElement).style[key] = position.position[key] + 'px');\n (overlayRef.current as HTMLElement).style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;\n\n // Trigger a set state for a second render anyway for arrow positioning\n setPosition(position);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n // Update position when anything changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(updatePosition, deps);\n\n // Update position on window resize\n useResize(updatePosition);\n\n // Update position when the overlay changes size (might need to flip).\n useResizeObserver({\n ref: overlayRef,\n onResize: updatePosition\n });\n\n // Reposition the overlay and do not close on scroll while the visual viewport is resizing.\n // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.\n let isResizing = useRef(false);\n useLayoutEffect(() => {\n let timeout: ReturnType<typeof setTimeout>;\n let onResize = () => {\n isResizing.current = true;\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n isResizing.current = false;\n }, 500);\n\n updatePosition();\n };\n\n // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)\n // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.\n let onScroll = () => {\n if (isResizing.current) {\n onResize();\n }\n };\n\n visualViewport?.addEventListener('resize', onResize);\n visualViewport?.addEventListener('scroll', onScroll);\n return () => {\n visualViewport?.removeEventListener('resize', onResize);\n visualViewport?.removeEventListener('scroll', onScroll);\n };\n }, [updatePosition]);\n\n let close = useCallback(() => {\n if (!isResizing.current) {\n onClose();\n }\n }, [onClose, isResizing]);\n\n // When scrolling a parent scrollable region of the trigger (other than the body),\n // we hide the popover. Otherwise, its position would be incorrect.\n useCloseOnScroll({\n triggerRef: targetRef,\n isOpen,\n onClose: onClose && close\n });\n\n return {\n overlayProps: {\n style: {\n position: 'absolute',\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position.position,\n maxHeight: position.maxHeight\n }\n },\n placement: position.placement,\n arrowProps: {\n 'aria-hidden': 'true',\n role: 'presentation',\n style: {\n left: position.arrowOffsetLeft,\n top: position.arrowOffsetTop\n }\n },\n updatePosition\n };\n}\n\nfunction useResize(onResize) {\n useLayoutEffect(() => {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n }, [onResize]);\n}\n\nfunction translateRTL(position, direction) {\n if (direction === 'rtl') {\n return position.replace('start', 'right').replace('end', 'left');\n }\n return position.replace('start', 'left').replace('end', 'right');\n}\n"],"names":[],"version":3,"file":"useOverlayPosition.main.js.map"}
@@ -0,0 +1,176 @@
1
+ import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98} from "./calculatePosition.mjs";
2
+ import {useCloseOnScroll as $dd149f63282afbbf$export$18fc8428861184da} from "./useCloseOnScroll.mjs";
3
+ import {useState as $39EOa$useState, useRef as $39EOa$useRef, useEffect as $39EOa$useEffect, useCallback as $39EOa$useCallback} from "react";
4
+ import {useLayoutEffect as $39EOa$useLayoutEffect, useResizeObserver as $39EOa$useResizeObserver} from "@react-aria/utils";
5
+ import {useLocale as $39EOa$useLocale} from "@react-aria/i18n";
6
+
7
+ /*
8
+ * Copyright 2020 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
+ // @ts-ignore
23
+ let $2a41e45df1593e64$var$visualViewport = typeof document !== "undefined" && window.visualViewport;
24
+ function $2a41e45df1593e64$export$d39e1813b3bdd0e1(props) {
25
+ let { direction: direction } = (0, $39EOa$useLocale)();
26
+ let { arrowSize: arrowSize = 0, targetRef: targetRef, overlayRef: overlayRef, scrollRef: scrollRef = overlayRef, placement: placement = "bottom", containerPadding: containerPadding = 12, shouldFlip: shouldFlip = true, boundaryElement: boundaryElement = typeof document !== "undefined" ? document.body : null, offset: offset = 0, crossOffset: crossOffset = 0, shouldUpdatePosition: shouldUpdatePosition = true, isOpen: isOpen = true, onClose: onClose, maxHeight: maxHeight, arrowBoundaryOffset: arrowBoundaryOffset = 0 } = props;
27
+ let [position, setPosition] = (0, $39EOa$useState)({
28
+ position: {},
29
+ arrowOffsetLeft: undefined,
30
+ arrowOffsetTop: undefined,
31
+ maxHeight: undefined,
32
+ placement: undefined
33
+ });
34
+ let deps = [
35
+ shouldUpdatePosition,
36
+ placement,
37
+ overlayRef.current,
38
+ targetRef.current,
39
+ scrollRef.current,
40
+ containerPadding,
41
+ shouldFlip,
42
+ boundaryElement,
43
+ offset,
44
+ crossOffset,
45
+ isOpen,
46
+ direction,
47
+ maxHeight,
48
+ arrowBoundaryOffset,
49
+ arrowSize
50
+ ];
51
+ // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might
52
+ // just be a non-realistic use case
53
+ // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles
54
+ let lastScale = (0, $39EOa$useRef)($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale);
55
+ (0, $39EOa$useEffect)(()=>{
56
+ if (isOpen) lastScale.current = $2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale;
57
+ }, [
58
+ isOpen
59
+ ]);
60
+ let updatePosition = (0, $39EOa$useCallback)(()=>{
61
+ if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !scrollRef.current || !boundaryElement) return;
62
+ if (($2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.scale) !== lastScale.current) return;
63
+ // Always reset the overlay's previous max height if not defined by the user so that we can compensate for
64
+ // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
65
+ if (!maxHeight && overlayRef.current) overlayRef.current.style.maxHeight = "none";
66
+ let position = (0, $edcf132a9284368a$export$b3ceb0cbf1056d98)({
67
+ placement: $2a41e45df1593e64$var$translateRTL(placement, direction),
68
+ overlayNode: overlayRef.current,
69
+ targetNode: targetRef.current,
70
+ scrollNode: scrollRef.current,
71
+ padding: containerPadding,
72
+ shouldFlip: shouldFlip,
73
+ boundaryElement: boundaryElement,
74
+ offset: offset,
75
+ crossOffset: crossOffset,
76
+ maxHeight: maxHeight,
77
+ arrowSize: arrowSize,
78
+ arrowBoundaryOffset: arrowBoundaryOffset
79
+ });
80
+ // Modify overlay styles directly so positioning happens immediately without the need of a second render
81
+ // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
82
+ Object.keys(position.position).forEach((key)=>overlayRef.current.style[key] = position.position[key] + "px");
83
+ overlayRef.current.style.maxHeight = position.maxHeight != null ? position.maxHeight + "px" : undefined;
84
+ // Trigger a set state for a second render anyway for arrow positioning
85
+ setPosition(position);
86
+ // eslint-disable-next-line react-hooks/exhaustive-deps
87
+ }, deps);
88
+ // Update position when anything changes
89
+ // eslint-disable-next-line react-hooks/exhaustive-deps
90
+ (0, $39EOa$useLayoutEffect)(updatePosition, deps);
91
+ // Update position on window resize
92
+ $2a41e45df1593e64$var$useResize(updatePosition);
93
+ // Update position when the overlay changes size (might need to flip).
94
+ (0, $39EOa$useResizeObserver)({
95
+ ref: overlayRef,
96
+ onResize: updatePosition
97
+ });
98
+ // Reposition the overlay and do not close on scroll while the visual viewport is resizing.
99
+ // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
100
+ let isResizing = (0, $39EOa$useRef)(false);
101
+ (0, $39EOa$useLayoutEffect)(()=>{
102
+ let timeout;
103
+ let onResize = ()=>{
104
+ isResizing.current = true;
105
+ clearTimeout(timeout);
106
+ timeout = setTimeout(()=>{
107
+ isResizing.current = false;
108
+ }, 500);
109
+ updatePosition();
110
+ };
111
+ // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
112
+ // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
113
+ let onScroll = ()=>{
114
+ if (isResizing.current) onResize();
115
+ };
116
+ $2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener("resize", onResize);
117
+ $2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.addEventListener("scroll", onScroll);
118
+ return ()=>{
119
+ $2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener("resize", onResize);
120
+ $2a41e45df1593e64$var$visualViewport === null || $2a41e45df1593e64$var$visualViewport === void 0 ? void 0 : $2a41e45df1593e64$var$visualViewport.removeEventListener("scroll", onScroll);
121
+ };
122
+ }, [
123
+ updatePosition
124
+ ]);
125
+ let close = (0, $39EOa$useCallback)(()=>{
126
+ if (!isResizing.current) onClose();
127
+ }, [
128
+ onClose,
129
+ isResizing
130
+ ]);
131
+ // When scrolling a parent scrollable region of the trigger (other than the body),
132
+ // we hide the popover. Otherwise, its position would be incorrect.
133
+ (0, $dd149f63282afbbf$export$18fc8428861184da)({
134
+ triggerRef: targetRef,
135
+ isOpen: isOpen,
136
+ onClose: onClose && close
137
+ });
138
+ return {
139
+ overlayProps: {
140
+ style: {
141
+ position: "absolute",
142
+ zIndex: 100000,
143
+ ...position.position,
144
+ maxHeight: position.maxHeight
145
+ }
146
+ },
147
+ placement: position.placement,
148
+ arrowProps: {
149
+ "aria-hidden": "true",
150
+ role: "presentation",
151
+ style: {
152
+ left: position.arrowOffsetLeft,
153
+ top: position.arrowOffsetTop
154
+ }
155
+ },
156
+ updatePosition: updatePosition
157
+ };
158
+ }
159
+ function $2a41e45df1593e64$var$useResize(onResize) {
160
+ (0, $39EOa$useLayoutEffect)(()=>{
161
+ window.addEventListener("resize", onResize, false);
162
+ return ()=>{
163
+ window.removeEventListener("resize", onResize, false);
164
+ };
165
+ }, [
166
+ onResize
167
+ ]);
168
+ }
169
+ function $2a41e45df1593e64$var$translateRTL(position, direction) {
170
+ if (direction === "rtl") return position.replace("start", "right").replace("end", "left");
171
+ return position.replace("start", "left").replace("end", "right");
172
+ }
173
+
174
+
175
+ export {$2a41e45df1593e64$export$d39e1813b3bdd0e1 as useOverlayPosition};
176
+ //# sourceMappingURL=useOverlayPosition.mjs.map