@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,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":"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","sources":["packages/@react-aria/overlays/src/useOverlayPosition.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 {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
@@ -0,0 +1,176 @@
1
+ import {calculatePosition as $edcf132a9284368a$export$b3ceb0cbf1056d98} from "./calculatePosition.module.js";
2
+ import {useCloseOnScroll as $dd149f63282afbbf$export$18fc8428861184da} from "./useCloseOnScroll.module.js";
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.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"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","sources":["packages/@react-aria/overlays/src/useOverlayPosition.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 {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.module.js.map"}
@@ -0,0 +1,54 @@
1
+ var $9a8aa1b0b336ea3a$exports = require("./useCloseOnScroll.main.js");
2
+ var $3l9xr$react = require("react");
3
+ var $3l9xr$reactariautils = require("@react-aria/utils");
4
+
5
+
6
+ function $parcel$export(e, n, v, s) {
7
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
+ }
9
+
10
+ $parcel$export(module.exports, "useOverlayTrigger", () => $b4878eb6316f670a$export$f9d5c8beee7d008d);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+ function $b4878eb6316f670a$export$f9d5c8beee7d008d(props, state, ref) {
25
+ let { type: type } = props;
26
+ let { isOpen: isOpen } = state;
27
+ // Backward compatibility. Share state close function with useOverlayPosition so it can close on scroll
28
+ // without forcing users to pass onClose.
29
+ (0, $3l9xr$react.useEffect)(()=>{
30
+ if (ref && ref.current) (0, $9a8aa1b0b336ea3a$exports.onCloseMap).set(ref.current, state.close);
31
+ });
32
+ // Aria 1.1 supports multiple values for aria-haspopup other than just menus.
33
+ // https://www.w3.org/TR/wai-aria-1.1/#aria-haspopup
34
+ // However, we only add it for menus for now because screen readers often
35
+ // announce it as a menu even for other values.
36
+ let ariaHasPopup = undefined;
37
+ if (type === "menu") ariaHasPopup = true;
38
+ else if (type === "listbox") ariaHasPopup = "listbox";
39
+ let overlayId = (0, $3l9xr$reactariautils.useId)();
40
+ return {
41
+ triggerProps: {
42
+ "aria-haspopup": ariaHasPopup,
43
+ "aria-expanded": isOpen,
44
+ "aria-controls": isOpen ? overlayId : null,
45
+ onPress: state.toggle
46
+ },
47
+ overlayProps: {
48
+ id: overlayId
49
+ }
50
+ };
51
+ }
52
+
53
+
54
+ //# sourceMappingURL=useOverlayTrigger.main.js.map