@react-spectrum/menu 3.22.7 → 3.22.9

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 (77) hide show
  1. package/dist/Menu.main.js +1 -1
  2. package/dist/Menu.main.js.map +1 -1
  3. package/dist/Menu.mjs +2 -2
  4. package/dist/Menu.module.js +2 -2
  5. package/dist/Menu.module.js.map +1 -1
  6. package/dist/MenuItem.main.js +2 -1
  7. package/dist/MenuItem.main.js.map +1 -1
  8. package/dist/MenuItem.mjs +2 -1
  9. package/dist/MenuItem.module.js +2 -1
  10. package/dist/MenuItem.module.js.map +1 -1
  11. package/dist/Popover.main.js +196 -0
  12. package/dist/Popover.main.js.map +1 -0
  13. package/dist/Popover.mjs +191 -0
  14. package/dist/Popover.module.js +191 -0
  15. package/dist/Popover.module.js.map +1 -0
  16. package/dist/SubmenuTrigger.main.js +2 -2
  17. package/dist/SubmenuTrigger.main.js.map +1 -1
  18. package/dist/SubmenuTrigger.mjs +2 -2
  19. package/dist/SubmenuTrigger.module.js +2 -2
  20. package/dist/SubmenuTrigger.module.js.map +1 -1
  21. package/dist/Underlay.main.js +54 -0
  22. package/dist/Underlay.main.js.map +1 -0
  23. package/dist/Underlay.mjs +49 -0
  24. package/dist/Underlay.module.js +49 -0
  25. package/dist/Underlay.module.js.map +1 -0
  26. package/dist/calculatePosition.main.js +392 -0
  27. package/dist/calculatePosition.main.js.map +1 -0
  28. package/dist/calculatePosition.mjs +386 -0
  29. package/dist/calculatePosition.module.js +386 -0
  30. package/dist/calculatePosition.module.js.map +1 -0
  31. package/dist/menu.2259a533.css +210 -0
  32. package/dist/menu.2259a533.css.map +1 -0
  33. package/dist/menu.359a0c0a.css +131 -0
  34. package/dist/menu.359a0c0a.css.map +1 -0
  35. package/dist/menu.57b3a408.css +12 -0
  36. package/dist/menu.57b3a408.css.map +1 -0
  37. package/dist/overlays_css.main.js +35 -0
  38. package/dist/overlays_css.main.js.map +1 -0
  39. package/dist/overlays_css.mjs +37 -0
  40. package/dist/overlays_css.module.js +37 -0
  41. package/dist/overlays_css.module.js.map +1 -0
  42. package/dist/popover_vars_css.main.js +83 -0
  43. package/dist/popover_vars_css.main.js.map +1 -0
  44. package/dist/popover_vars_css.mjs +85 -0
  45. package/dist/popover_vars_css.module.js +85 -0
  46. package/dist/popover_vars_css.module.js.map +1 -0
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/underlay_vars_css.main.js +50 -0
  49. package/dist/underlay_vars_css.main.js.map +1 -0
  50. package/dist/underlay_vars_css.mjs +52 -0
  51. package/dist/underlay_vars_css.module.js +52 -0
  52. package/dist/underlay_vars_css.module.js.map +1 -0
  53. package/dist/useCloseOnScroll.main.js +49 -0
  54. package/dist/useCloseOnScroll.main.js.map +1 -0
  55. package/dist/useCloseOnScroll.mjs +44 -0
  56. package/dist/useCloseOnScroll.module.js +44 -0
  57. package/dist/useCloseOnScroll.module.js.map +1 -0
  58. package/dist/useOverlayPosition.main.js +225 -0
  59. package/dist/useOverlayPosition.main.js.map +1 -0
  60. package/dist/useOverlayPosition.mjs +220 -0
  61. package/dist/useOverlayPosition.module.js +220 -0
  62. package/dist/useOverlayPosition.module.js.map +1 -0
  63. package/dist/usePopover.main.js +73 -0
  64. package/dist/usePopover.main.js.map +1 -0
  65. package/dist/usePopover.mjs +68 -0
  66. package/dist/usePopover.module.js +68 -0
  67. package/dist/usePopover.module.js.map +1 -0
  68. package/package.json +23 -23
  69. package/src/Menu.tsx +2 -1
  70. package/src/MenuItem.tsx +5 -1
  71. package/src/Popover.tsx +240 -0
  72. package/src/SubmenuTrigger.tsx +1 -1
  73. package/src/Underlay.tsx +43 -0
  74. package/src/calculatePosition.ts +627 -0
  75. package/src/useCloseOnScroll.ts +64 -0
  76. package/src/useOverlayPosition.ts +327 -0
  77. package/src/usePopover.ts +136 -0
@@ -0,0 +1,225 @@
1
+ var $404994fca17f0d46$exports = require("./calculatePosition.main.js");
2
+ var $acb28858babbe848$exports = require("./useCloseOnScroll.main.js");
3
+ var $jkbw0$react = require("react");
4
+ var $jkbw0$reactariautils = require("@react-aria/utils");
5
+ var $jkbw0$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", () => $29af923830236f61$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
+ let $29af923830236f61$var$visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;
29
+ function $29af923830236f61$export$d39e1813b3bdd0e1(props) {
30
+ let { direction: direction } = (0, $jkbw0$reactariai18n.useLocale)();
31
+ let { arrowSize: arrowSize, targetRef: targetRef, overlayRef: overlayRef, arrowRef: arrowRef, 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;
32
+ let [position, setPosition] = (0, $jkbw0$react.useState)(null);
33
+ let deps = [
34
+ shouldUpdatePosition,
35
+ placement,
36
+ overlayRef.current,
37
+ targetRef.current,
38
+ arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.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, $jkbw0$react.useRef)($29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.scale);
55
+ (0, $jkbw0$react.useEffect)(()=>{
56
+ if (isOpen) lastScale.current = $29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.scale;
57
+ }, [
58
+ isOpen
59
+ ]);
60
+ let updatePosition = (0, $jkbw0$react.useCallback)(()=>{
61
+ if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
62
+ if (($29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.scale) !== lastScale.current) return;
63
+ // Determine a scroll anchor based on the focused element.
64
+ // This stores the offset of the anchor element from the scroll container
65
+ // so it can be restored after repositioning. This way if the overlay height
66
+ // changes, the focused element appears to stay in the same position.
67
+ let anchor = null;
68
+ if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {
69
+ var _document_activeElement;
70
+ let anchorRect = (_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.getBoundingClientRect();
71
+ let scrollRect = scrollRef.current.getBoundingClientRect();
72
+ var _anchorRect_top;
73
+ // Anchor from the top if the offset is in the top half of the scrollable element,
74
+ // otherwise anchor from the bottom.
75
+ anchor = {
76
+ type: 'top',
77
+ offset: ((_anchorRect_top = anchorRect === null || anchorRect === void 0 ? void 0 : anchorRect.top) !== null && _anchorRect_top !== void 0 ? _anchorRect_top : 0) - scrollRect.top
78
+ };
79
+ if (anchor.offset > scrollRect.height / 2) {
80
+ anchor.type = 'bottom';
81
+ var _anchorRect_bottom;
82
+ anchor.offset = ((_anchorRect_bottom = anchorRect === null || anchorRect === void 0 ? void 0 : anchorRect.bottom) !== null && _anchorRect_bottom !== void 0 ? _anchorRect_bottom : 0) - scrollRect.bottom;
83
+ }
84
+ }
85
+ // Always reset the overlay's previous max height if not defined by the user so that we can compensate for
86
+ // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
87
+ let overlay = overlayRef.current;
88
+ if (!maxHeight && overlayRef.current) {
89
+ var _window_visualViewport;
90
+ overlay.style.top = '0px';
91
+ overlay.style.bottom = '';
92
+ var _window_visualViewport_height;
93
+ overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
94
+ }
95
+ let position = (0, $404994fca17f0d46$exports.calculatePosition)({
96
+ placement: $29af923830236f61$var$translateRTL(placement, direction),
97
+ overlayNode: overlayRef.current,
98
+ targetNode: targetRef.current,
99
+ scrollNode: scrollRef.current || overlayRef.current,
100
+ padding: containerPadding,
101
+ shouldFlip: shouldFlip,
102
+ boundaryElement: boundaryElement,
103
+ offset: offset,
104
+ crossOffset: crossOffset,
105
+ maxHeight: maxHeight,
106
+ arrowSize: arrowSize !== null && arrowSize !== void 0 ? arrowSize : (arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current) ? (0, $404994fca17f0d46$exports.getRect)(arrowRef.current, true).width : 0,
107
+ arrowBoundaryOffset: arrowBoundaryOffset
108
+ });
109
+ if (!position.position) return;
110
+ // Modify overlay styles directly so positioning happens immediately without the need of a second render
111
+ // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
112
+ overlay.style.top = '';
113
+ overlay.style.bottom = '';
114
+ overlay.style.left = '';
115
+ overlay.style.right = '';
116
+ Object.keys(position.position).forEach((key)=>overlay.style[key] = position.position[key] + 'px');
117
+ overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';
118
+ // Restore scroll position relative to anchor element.
119
+ if (anchor && document.activeElement && scrollRef.current) {
120
+ let anchorRect = document.activeElement.getBoundingClientRect();
121
+ let scrollRect = scrollRef.current.getBoundingClientRect();
122
+ let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];
123
+ scrollRef.current.scrollTop += newOffset - anchor.offset;
124
+ }
125
+ // Trigger a set state for a second render anyway for arrow positioning
126
+ setPosition(position);
127
+ // eslint-disable-next-line react-hooks/exhaustive-deps
128
+ }, deps);
129
+ // Update position when anything changes
130
+ // eslint-disable-next-line react-hooks/exhaustive-deps
131
+ (0, $jkbw0$reactariautils.useLayoutEffect)(updatePosition, deps);
132
+ // Update position on window resize
133
+ $29af923830236f61$var$useResize(updatePosition);
134
+ // Update position when the overlay changes size (might need to flip).
135
+ (0, $jkbw0$reactariautils.useResizeObserver)({
136
+ ref: overlayRef,
137
+ onResize: updatePosition
138
+ });
139
+ // Update position when the target changes size (might need to flip).
140
+ (0, $jkbw0$reactariautils.useResizeObserver)({
141
+ ref: targetRef,
142
+ onResize: updatePosition
143
+ });
144
+ // Reposition the overlay and do not close on scroll while the visual viewport is resizing.
145
+ // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
146
+ let isResizing = (0, $jkbw0$react.useRef)(false);
147
+ (0, $jkbw0$reactariautils.useLayoutEffect)(()=>{
148
+ let timeout;
149
+ let onResize = ()=>{
150
+ isResizing.current = true;
151
+ clearTimeout(timeout);
152
+ timeout = setTimeout(()=>{
153
+ isResizing.current = false;
154
+ }, 500);
155
+ updatePosition();
156
+ };
157
+ // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
158
+ // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
159
+ let onScroll = ()=>{
160
+ if (isResizing.current) onResize();
161
+ };
162
+ $29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.addEventListener('resize', onResize);
163
+ $29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.addEventListener('scroll', onScroll);
164
+ return ()=>{
165
+ $29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.removeEventListener('resize', onResize);
166
+ $29af923830236f61$var$visualViewport === null || $29af923830236f61$var$visualViewport === void 0 ? void 0 : $29af923830236f61$var$visualViewport.removeEventListener('scroll', onScroll);
167
+ };
168
+ }, [
169
+ updatePosition
170
+ ]);
171
+ let close = (0, $jkbw0$react.useCallback)(()=>{
172
+ if (!isResizing.current) onClose === null || onClose === void 0 ? void 0 : onClose();
173
+ }, [
174
+ onClose,
175
+ isResizing
176
+ ]);
177
+ // When scrolling a parent scrollable region of the trigger (other than the body),
178
+ // we hide the popover. Otherwise, its position would be incorrect.
179
+ (0, $acb28858babbe848$exports.useCloseOnScroll)({
180
+ triggerRef: targetRef,
181
+ isOpen: isOpen,
182
+ onClose: onClose && close
183
+ });
184
+ var _position_maxHeight, _position_placement, _position_triggerAnchorPoint;
185
+ return {
186
+ overlayProps: {
187
+ style: {
188
+ position: position ? 'absolute' : 'fixed',
189
+ top: !position ? 0 : undefined,
190
+ left: !position ? 0 : undefined,
191
+ zIndex: 100000,
192
+ ...position === null || position === void 0 ? void 0 : position.position,
193
+ maxHeight: (_position_maxHeight = position === null || position === void 0 ? void 0 : position.maxHeight) !== null && _position_maxHeight !== void 0 ? _position_maxHeight : '100vh'
194
+ }
195
+ },
196
+ placement: (_position_placement = position === null || position === void 0 ? void 0 : position.placement) !== null && _position_placement !== void 0 ? _position_placement : null,
197
+ triggerAnchorPoint: (_position_triggerAnchorPoint = position === null || position === void 0 ? void 0 : position.triggerAnchorPoint) !== null && _position_triggerAnchorPoint !== void 0 ? _position_triggerAnchorPoint : null,
198
+ arrowProps: {
199
+ 'aria-hidden': 'true',
200
+ role: 'presentation',
201
+ style: {
202
+ left: position === null || position === void 0 ? void 0 : position.arrowOffsetLeft,
203
+ top: position === null || position === void 0 ? void 0 : position.arrowOffsetTop
204
+ }
205
+ },
206
+ updatePosition: updatePosition
207
+ };
208
+ }
209
+ function $29af923830236f61$var$useResize(onResize) {
210
+ (0, $jkbw0$reactariautils.useLayoutEffect)(()=>{
211
+ window.addEventListener('resize', onResize, false);
212
+ return ()=>{
213
+ window.removeEventListener('resize', onResize, false);
214
+ };
215
+ }, [
216
+ onResize
217
+ ]);
218
+ }
219
+ function $29af923830236f61$var$translateRTL(position, direction) {
220
+ if (direction === 'rtl') return position.replace('start', 'right').replace('end', 'left');
221
+ return position.replace('start', 'left').replace('end', 'right');
222
+ }
223
+
224
+
225
+ //# sourceMappingURL=useOverlayPosition.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA2ED,IAAI,uCAAiB,OAAO,aAAa,cAAc,OAAO,cAAc,GAAG;AAMxE,SAAS,0CAAmB,KAAwB;IACzD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,aACF,SAAS,aACT,SAAS,cACT,UAAU,YACV,QAAQ,aACR,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,EAAyB;IAE9D,IAAI,OAAO;QACT;QACA;QACA,WAAW,OAAO;QAClB,UAAU,OAAO;QACjB,qBAAA,+BAAA,SAAU,OAAO;QACjB,UAAU,OAAO;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;QACf,YAAY;gBACZ;QACA,SAAS,WAAW;IACtB;QAUiB,qBAGJ,qBACS;IAZtB,OAAO;QACL,cAAc;YACZ,OAAO;gBACL,UAAU,WAAW,aAAa;gBAClC,KAAK,CAAC,WAAW,IAAI;gBACrB,MAAM,CAAC,WAAW,IAAI;gBACtB,QAAQ;mBACL,qBAAA,+BAAA,SAAU,QAAQ,AAArB;gBACA,WAAW,CAAA,sBAAA,qBAAA,+BAAA,SAAU,SAAS,cAAnB,iCAAA,sBAAuB;YACpC;QACF;QACA,WAAW,CAAA,sBAAA,qBAAA,+BAAA,SAAU,SAAS,cAAnB,iCAAA,sBAAuB;QAClC,oBAAoB,CAAA,+BAAA,qBAAA,+BAAA,SAAU,kBAAkB,cAA5B,0CAAA,+BAAgC;QACpD,YAAY;YACV,eAAe;YACf,MAAM;YACN,OAAO;gBACL,IAAI,EAAE,qBAAA,+BAAA,SAAU,eAAe;gBAC/B,GAAG,EAAE,qBAAA,+BAAA,SAAU,cAAc;YAC/B;QACF;wBACA;IACF;AACF;AAEA,SAAS,gCAAU,QAAQ;IACzB,CAAA,GAAA,qCAAc,EAAE;QACd,OAAO,gBAAgB,CAAC,UAAU,UAAU;QAC5C,OAAO;YACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;QACjD;IACF,GAAG;QAAC;KAAS;AACf;AAEA,SAAS,mCAAa,QAAQ,EAAE,SAAS;IACvC,IAAI,cAAc,OAChB,OAAO,SAAS,OAAO,CAAC,SAAS,SAAS,OAAO,CAAC,OAAO;IAE3D,OAAO,SAAS,OAAO,CAAC,SAAS,QAAQ,OAAO,CAAC,OAAO;AAC1D","sources":["packages/@react-spectrum/menu/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, getRect, PositionResult} from './calculatePosition';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {Placement, PlacementAxis, PositionProps} from '@react-types/overlays';\nimport {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 | null>,\n /**\n * The ref for the overlay element.\n */\n overlayRef: RefObject<Element | null>,\n /**\n * The ref for the arrow element.\n */\n arrowRef?: RefObject<Element | null>,\n /**\n * A ref for the scrollable region within the overlay.\n * @default overlayRef\n */\n scrollRef?: RefObject<Element | null>,\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) | null,\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 | null,\n /** The origin of the target in the overlay's coordinate system. Useful for animations. */\n triggerAnchorPoint: {x: number, y: number} | null,\n /** Updates the position of the overlay. */\n updatePosition(): void\n}\n\ninterface ScrollAnchor {\n type: 'top' | 'bottom',\n offset: number\n}\n\nlet visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;\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,\n targetRef,\n overlayRef,\n arrowRef,\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 | null>(null);\n\n let deps = [\n shouldUpdatePosition,\n placement,\n overlayRef.current,\n targetRef.current,\n arrowRef?.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 || !boundaryElement) {\n return;\n }\n\n if (visualViewport?.scale !== lastScale.current) {\n return;\n }\n\n // Determine a scroll anchor based on the focused element.\n // This stores the offset of the anchor element from the scroll container\n // so it can be restored after repositioning. This way if the overlay height\n // changes, the focused element appears to stay in the same position.\n let anchor: ScrollAnchor | null = null;\n if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {\n let anchorRect = document.activeElement?.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n // Anchor from the top if the offset is in the top half of the scrollable element,\n // otherwise anchor from the bottom.\n anchor = {\n type: 'top',\n offset: (anchorRect?.top ?? 0) - scrollRect.top\n };\n if (anchor.offset > scrollRect.height / 2) {\n anchor.type = 'bottom';\n anchor.offset = (anchorRect?.bottom ?? 0) - scrollRect.bottom;\n }\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 let overlay = (overlayRef.current as HTMLElement);\n if (!maxHeight && overlayRef.current) {\n overlay.style.top = '0px';\n overlay.style.bottom = '';\n overlay.style.maxHeight = (window.visualViewport?.height ?? window.innerHeight) + 'px';\n }\n\n let position = calculatePosition({\n placement: translateRTL(placement, direction),\n overlayNode: overlayRef.current,\n targetNode: targetRef.current,\n scrollNode: scrollRef.current || overlayRef.current,\n padding: containerPadding,\n shouldFlip,\n boundaryElement,\n offset,\n crossOffset,\n maxHeight,\n arrowSize: arrowSize ?? (arrowRef?.current ? getRect(arrowRef.current, true).width : 0),\n arrowBoundaryOffset\n });\n\n if (!position.position) {\n return;\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 overlay.style.top = '';\n overlay.style.bottom = '';\n overlay.style.left = '';\n overlay.style.right = '';\n\n Object.keys(position.position).forEach(key => overlay.style[key] = (position.position!)[key] + 'px');\n overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';\n\n // Restore scroll position relative to anchor element.\n if (anchor && document.activeElement && scrollRef.current) {\n let anchorRect = document.activeElement.getBoundingClientRect();\n let scrollRect = scrollRef.current.getBoundingClientRect();\n let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];\n scrollRef.current.scrollTop += newOffset - anchor.offset;\n }\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 // Update position when the target changes size (might need to flip).\n useResizeObserver({\n ref: targetRef,\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: position ? 'absolute' : 'fixed',\n top: !position ? 0 : undefined,\n left: !position ? 0 : undefined,\n zIndex: 100000, // should match the z-index in ModalTrigger\n ...position?.position,\n maxHeight: position?.maxHeight ?? '100vh'\n }\n },\n placement: position?.placement ?? null,\n triggerAnchorPoint: position?.triggerAnchorPoint ?? null,\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,220 @@
1
+ import {calculatePosition as $74be59a24b8d2173$export$b3ceb0cbf1056d98, getRect as $74be59a24b8d2173$export$4b834cebd9e5cebe} from "./calculatePosition.mjs";
2
+ import {useCloseOnScroll as $ca3b77875a5017bc$export$18fc8428861184da} from "./useCloseOnScroll.mjs";
3
+ import {useState as $db9yU$useState, useRef as $db9yU$useRef, useEffect as $db9yU$useEffect, useCallback as $db9yU$useCallback} from "react";
4
+ import {useLayoutEffect as $db9yU$useLayoutEffect, useResizeObserver as $db9yU$useResizeObserver} from "@react-aria/utils";
5
+ import {useLocale as $db9yU$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
+ let $e235061053e33ff6$var$visualViewport = typeof document !== 'undefined' ? window.visualViewport : null;
23
+ function $e235061053e33ff6$export$d39e1813b3bdd0e1(props) {
24
+ let { direction: direction } = (0, $db9yU$useLocale)();
25
+ let { arrowSize: arrowSize, targetRef: targetRef, overlayRef: overlayRef, arrowRef: arrowRef, 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;
26
+ let [position, setPosition] = (0, $db9yU$useState)(null);
27
+ let deps = [
28
+ shouldUpdatePosition,
29
+ placement,
30
+ overlayRef.current,
31
+ targetRef.current,
32
+ arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current,
33
+ scrollRef.current,
34
+ containerPadding,
35
+ shouldFlip,
36
+ boundaryElement,
37
+ offset,
38
+ crossOffset,
39
+ isOpen,
40
+ direction,
41
+ maxHeight,
42
+ arrowBoundaryOffset,
43
+ arrowSize
44
+ ];
45
+ // Note, the position freezing breaks if body sizes itself dynamicly with the visual viewport but that might
46
+ // just be a non-realistic use case
47
+ // Upon opening a overlay, record the current visual viewport scale so we can freeze the overlay styles
48
+ let lastScale = (0, $db9yU$useRef)($e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.scale);
49
+ (0, $db9yU$useEffect)(()=>{
50
+ if (isOpen) lastScale.current = $e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.scale;
51
+ }, [
52
+ isOpen
53
+ ]);
54
+ let updatePosition = (0, $db9yU$useCallback)(()=>{
55
+ if (shouldUpdatePosition === false || !isOpen || !overlayRef.current || !targetRef.current || !boundaryElement) return;
56
+ if (($e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.scale) !== lastScale.current) return;
57
+ // Determine a scroll anchor based on the focused element.
58
+ // This stores the offset of the anchor element from the scroll container
59
+ // so it can be restored after repositioning. This way if the overlay height
60
+ // changes, the focused element appears to stay in the same position.
61
+ let anchor = null;
62
+ if (scrollRef.current && scrollRef.current.contains(document.activeElement)) {
63
+ var _document_activeElement;
64
+ let anchorRect = (_document_activeElement = document.activeElement) === null || _document_activeElement === void 0 ? void 0 : _document_activeElement.getBoundingClientRect();
65
+ let scrollRect = scrollRef.current.getBoundingClientRect();
66
+ var _anchorRect_top;
67
+ // Anchor from the top if the offset is in the top half of the scrollable element,
68
+ // otherwise anchor from the bottom.
69
+ anchor = {
70
+ type: 'top',
71
+ offset: ((_anchorRect_top = anchorRect === null || anchorRect === void 0 ? void 0 : anchorRect.top) !== null && _anchorRect_top !== void 0 ? _anchorRect_top : 0) - scrollRect.top
72
+ };
73
+ if (anchor.offset > scrollRect.height / 2) {
74
+ anchor.type = 'bottom';
75
+ var _anchorRect_bottom;
76
+ anchor.offset = ((_anchorRect_bottom = anchorRect === null || anchorRect === void 0 ? void 0 : anchorRect.bottom) !== null && _anchorRect_bottom !== void 0 ? _anchorRect_bottom : 0) - scrollRect.bottom;
77
+ }
78
+ }
79
+ // Always reset the overlay's previous max height if not defined by the user so that we can compensate for
80
+ // RAC collections populating after a second render and properly set a correct max height + positioning when it populates.
81
+ let overlay = overlayRef.current;
82
+ if (!maxHeight && overlayRef.current) {
83
+ var _window_visualViewport;
84
+ overlay.style.top = '0px';
85
+ overlay.style.bottom = '';
86
+ var _window_visualViewport_height;
87
+ overlay.style.maxHeight = ((_window_visualViewport_height = (_window_visualViewport = window.visualViewport) === null || _window_visualViewport === void 0 ? void 0 : _window_visualViewport.height) !== null && _window_visualViewport_height !== void 0 ? _window_visualViewport_height : window.innerHeight) + 'px';
88
+ }
89
+ let position = (0, $74be59a24b8d2173$export$b3ceb0cbf1056d98)({
90
+ placement: $e235061053e33ff6$var$translateRTL(placement, direction),
91
+ overlayNode: overlayRef.current,
92
+ targetNode: targetRef.current,
93
+ scrollNode: scrollRef.current || overlayRef.current,
94
+ padding: containerPadding,
95
+ shouldFlip: shouldFlip,
96
+ boundaryElement: boundaryElement,
97
+ offset: offset,
98
+ crossOffset: crossOffset,
99
+ maxHeight: maxHeight,
100
+ arrowSize: arrowSize !== null && arrowSize !== void 0 ? arrowSize : (arrowRef === null || arrowRef === void 0 ? void 0 : arrowRef.current) ? (0, $74be59a24b8d2173$export$4b834cebd9e5cebe)(arrowRef.current, true).width : 0,
101
+ arrowBoundaryOffset: arrowBoundaryOffset
102
+ });
103
+ if (!position.position) return;
104
+ // Modify overlay styles directly so positioning happens immediately without the need of a second render
105
+ // This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
106
+ overlay.style.top = '';
107
+ overlay.style.bottom = '';
108
+ overlay.style.left = '';
109
+ overlay.style.right = '';
110
+ Object.keys(position.position).forEach((key)=>overlay.style[key] = position.position[key] + 'px');
111
+ overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : '';
112
+ // Restore scroll position relative to anchor element.
113
+ if (anchor && document.activeElement && scrollRef.current) {
114
+ let anchorRect = document.activeElement.getBoundingClientRect();
115
+ let scrollRect = scrollRef.current.getBoundingClientRect();
116
+ let newOffset = anchorRect[anchor.type] - scrollRect[anchor.type];
117
+ scrollRef.current.scrollTop += newOffset - anchor.offset;
118
+ }
119
+ // Trigger a set state for a second render anyway for arrow positioning
120
+ setPosition(position);
121
+ // eslint-disable-next-line react-hooks/exhaustive-deps
122
+ }, deps);
123
+ // Update position when anything changes
124
+ // eslint-disable-next-line react-hooks/exhaustive-deps
125
+ (0, $db9yU$useLayoutEffect)(updatePosition, deps);
126
+ // Update position on window resize
127
+ $e235061053e33ff6$var$useResize(updatePosition);
128
+ // Update position when the overlay changes size (might need to flip).
129
+ (0, $db9yU$useResizeObserver)({
130
+ ref: overlayRef,
131
+ onResize: updatePosition
132
+ });
133
+ // Update position when the target changes size (might need to flip).
134
+ (0, $db9yU$useResizeObserver)({
135
+ ref: targetRef,
136
+ onResize: updatePosition
137
+ });
138
+ // Reposition the overlay and do not close on scroll while the visual viewport is resizing.
139
+ // This will ensure that overlays adjust their positioning when the iOS virtual keyboard appears.
140
+ let isResizing = (0, $db9yU$useRef)(false);
141
+ (0, $db9yU$useLayoutEffect)(()=>{
142
+ let timeout;
143
+ let onResize = ()=>{
144
+ isResizing.current = true;
145
+ clearTimeout(timeout);
146
+ timeout = setTimeout(()=>{
147
+ isResizing.current = false;
148
+ }, 500);
149
+ updatePosition();
150
+ };
151
+ // Only reposition the overlay if a scroll event happens immediately as a result of resize (aka the virtual keyboard has appears)
152
+ // We don't want to reposition the overlay if the user has pinch zoomed in and is scrolling the viewport around.
153
+ let onScroll = ()=>{
154
+ if (isResizing.current) onResize();
155
+ };
156
+ $e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.addEventListener('resize', onResize);
157
+ $e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.addEventListener('scroll', onScroll);
158
+ return ()=>{
159
+ $e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.removeEventListener('resize', onResize);
160
+ $e235061053e33ff6$var$visualViewport === null || $e235061053e33ff6$var$visualViewport === void 0 ? void 0 : $e235061053e33ff6$var$visualViewport.removeEventListener('scroll', onScroll);
161
+ };
162
+ }, [
163
+ updatePosition
164
+ ]);
165
+ let close = (0, $db9yU$useCallback)(()=>{
166
+ if (!isResizing.current) onClose === null || onClose === void 0 ? void 0 : onClose();
167
+ }, [
168
+ onClose,
169
+ isResizing
170
+ ]);
171
+ // When scrolling a parent scrollable region of the trigger (other than the body),
172
+ // we hide the popover. Otherwise, its position would be incorrect.
173
+ (0, $ca3b77875a5017bc$export$18fc8428861184da)({
174
+ triggerRef: targetRef,
175
+ isOpen: isOpen,
176
+ onClose: onClose && close
177
+ });
178
+ var _position_maxHeight, _position_placement, _position_triggerAnchorPoint;
179
+ return {
180
+ overlayProps: {
181
+ style: {
182
+ position: position ? 'absolute' : 'fixed',
183
+ top: !position ? 0 : undefined,
184
+ left: !position ? 0 : undefined,
185
+ zIndex: 100000,
186
+ ...position === null || position === void 0 ? void 0 : position.position,
187
+ maxHeight: (_position_maxHeight = position === null || position === void 0 ? void 0 : position.maxHeight) !== null && _position_maxHeight !== void 0 ? _position_maxHeight : '100vh'
188
+ }
189
+ },
190
+ placement: (_position_placement = position === null || position === void 0 ? void 0 : position.placement) !== null && _position_placement !== void 0 ? _position_placement : null,
191
+ triggerAnchorPoint: (_position_triggerAnchorPoint = position === null || position === void 0 ? void 0 : position.triggerAnchorPoint) !== null && _position_triggerAnchorPoint !== void 0 ? _position_triggerAnchorPoint : null,
192
+ arrowProps: {
193
+ 'aria-hidden': 'true',
194
+ role: 'presentation',
195
+ style: {
196
+ left: position === null || position === void 0 ? void 0 : position.arrowOffsetLeft,
197
+ top: position === null || position === void 0 ? void 0 : position.arrowOffsetTop
198
+ }
199
+ },
200
+ updatePosition: updatePosition
201
+ };
202
+ }
203
+ function $e235061053e33ff6$var$useResize(onResize) {
204
+ (0, $db9yU$useLayoutEffect)(()=>{
205
+ window.addEventListener('resize', onResize, false);
206
+ return ()=>{
207
+ window.removeEventListener('resize', onResize, false);
208
+ };
209
+ }, [
210
+ onResize
211
+ ]);
212
+ }
213
+ function $e235061053e33ff6$var$translateRTL(position, direction) {
214
+ if (direction === 'rtl') return position.replace('start', 'right').replace('end', 'left');
215
+ return position.replace('start', 'left').replace('end', 'right');
216
+ }
217
+
218
+
219
+ export {$e235061053e33ff6$export$d39e1813b3bdd0e1 as useOverlayPosition};
220
+ //# sourceMappingURL=useOverlayPosition.module.js.map