@react-aria/overlays 3.21.1 → 3.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/DismissButton.main.js +51 -0
  2. package/dist/DismissButton.main.js.map +1 -0
  3. package/dist/DismissButton.mjs +46 -0
  4. package/dist/DismissButton.module.js +46 -0
  5. package/dist/DismissButton.module.js.map +1 -0
  6. package/dist/Overlay.main.js +73 -0
  7. package/dist/Overlay.main.js.map +1 -0
  8. package/dist/Overlay.mjs +63 -0
  9. package/dist/Overlay.module.js +63 -0
  10. package/dist/Overlay.module.js.map +1 -0
  11. package/dist/PortalProvider.main.js +41 -0
  12. package/dist/PortalProvider.main.js.map +1 -0
  13. package/dist/PortalProvider.mjs +31 -0
  14. package/dist/PortalProvider.module.js +31 -0
  15. package/dist/PortalProvider.module.js.map +1 -0
  16. package/dist/ar-AE.mjs +1 -1
  17. package/dist/ariaHideOutside.main.js +121 -0
  18. package/dist/ariaHideOutside.main.js.map +1 -0
  19. package/dist/ariaHideOutside.mjs +116 -0
  20. package/dist/ariaHideOutside.module.js +116 -0
  21. package/dist/ariaHideOutside.module.js.map +1 -0
  22. package/dist/bg-BG.mjs +1 -1
  23. package/dist/calculatePosition.main.js +355 -0
  24. package/dist/calculatePosition.main.js.map +1 -0
  25. package/dist/calculatePosition.mjs +350 -0
  26. package/dist/calculatePosition.module.js +350 -0
  27. package/dist/calculatePosition.module.js.map +1 -0
  28. package/dist/cs-CZ.mjs +1 -1
  29. package/dist/da-DK.mjs +1 -1
  30. package/dist/de-DE.mjs +1 -1
  31. package/dist/el-GR.mjs +1 -1
  32. package/dist/en-US.mjs +1 -1
  33. package/dist/es-ES.mjs +1 -1
  34. package/dist/et-EE.mjs +1 -1
  35. package/dist/fi-FI.mjs +1 -1
  36. package/dist/fr-FR.mjs +1 -1
  37. package/dist/he-IL.mjs +1 -1
  38. package/dist/hr-HR.mjs +1 -1
  39. package/dist/hu-HU.mjs +1 -1
  40. package/dist/import.mjs +12 -1397
  41. package/dist/intlStrings.main.js +108 -0
  42. package/dist/intlStrings.main.js.map +1 -0
  43. package/dist/intlStrings.mjs +110 -0
  44. package/dist/intlStrings.module.js +110 -0
  45. package/dist/intlStrings.module.js.map +1 -0
  46. package/dist/it-IT.mjs +1 -1
  47. package/dist/ja-JP.mjs +1 -1
  48. package/dist/ko-KR.mjs +1 -1
  49. package/dist/lt-LT.mjs +1 -1
  50. package/dist/lv-LV.mjs +1 -1
  51. package/dist/main.js +28 -1411
  52. package/dist/main.js.map +1 -1
  53. package/dist/module.js +12 -1397
  54. package/dist/module.js.map +1 -1
  55. package/dist/nb-NO.mjs +1 -1
  56. package/dist/nl-NL.mjs +1 -1
  57. package/dist/pl-PL.mjs +1 -1
  58. package/dist/pt-BR.mjs +1 -1
  59. package/dist/pt-PT.mjs +1 -1
  60. package/dist/ro-RO.mjs +1 -1
  61. package/dist/ru-RU.mjs +1 -1
  62. package/dist/sk-SK.mjs +1 -1
  63. package/dist/sl-SI.mjs +1 -1
  64. package/dist/sr-SP.mjs +1 -1
  65. package/dist/sv-SE.mjs +1 -1
  66. package/dist/tr-TR.mjs +1 -1
  67. package/dist/types.d.ts +8 -1
  68. package/dist/types.d.ts.map +1 -1
  69. package/dist/uk-UA.mjs +1 -1
  70. package/dist/useCloseOnScroll.main.js +46 -0
  71. package/dist/useCloseOnScroll.main.js.map +1 -0
  72. package/dist/useCloseOnScroll.mjs +40 -0
  73. package/dist/useCloseOnScroll.module.js +40 -0
  74. package/dist/useCloseOnScroll.module.js.map +1 -0
  75. package/dist/useModal.main.js +114 -0
  76. package/dist/useModal.main.js.map +1 -0
  77. package/dist/useModal.mjs +101 -0
  78. package/dist/useModal.module.js +101 -0
  79. package/dist/useModal.module.js.map +1 -0
  80. package/dist/useModalOverlay.main.js +55 -0
  81. package/dist/useModalOverlay.main.js.map +1 -0
  82. package/dist/useModalOverlay.mjs +50 -0
  83. package/dist/useModalOverlay.module.js +50 -0
  84. package/dist/useModalOverlay.module.js.map +1 -0
  85. package/dist/useOverlay.main.js +105 -0
  86. package/dist/useOverlay.main.js.map +1 -0
  87. package/dist/useOverlay.mjs +100 -0
  88. package/dist/useOverlay.module.js +100 -0
  89. package/dist/useOverlay.module.js.map +1 -0
  90. package/dist/useOverlayPosition.main.js +181 -0
  91. package/dist/useOverlayPosition.main.js.map +1 -0
  92. package/dist/useOverlayPosition.mjs +176 -0
  93. package/dist/useOverlayPosition.module.js +176 -0
  94. package/dist/useOverlayPosition.module.js.map +1 -0
  95. package/dist/useOverlayTrigger.main.js +54 -0
  96. package/dist/useOverlayTrigger.main.js.map +1 -0
  97. package/dist/useOverlayTrigger.mjs +49 -0
  98. package/dist/useOverlayTrigger.module.js +49 -0
  99. package/dist/useOverlayTrigger.module.js.map +1 -0
  100. package/dist/usePopover.main.js +66 -0
  101. package/dist/usePopover.main.js.map +1 -0
  102. package/dist/usePopover.mjs +61 -0
  103. package/dist/usePopover.module.js +61 -0
  104. package/dist/usePopover.module.js.map +1 -0
  105. package/dist/usePreventScroll.main.js +226 -0
  106. package/dist/usePreventScroll.main.js.map +1 -0
  107. package/dist/usePreventScroll.mjs +221 -0
  108. package/dist/usePreventScroll.module.js +221 -0
  109. package/dist/usePreventScroll.module.js.map +1 -0
  110. package/dist/zh-CN.mjs +1 -1
  111. package/dist/zh-TW.mjs +1 -1
  112. package/package.json +12 -12
  113. package/src/Overlay.tsx +6 -0
  114. package/src/PortalProvider.tsx +34 -0
  115. package/src/index.ts +1 -0
  116. package/src/useModalOverlay.ts +2 -2
  117. package/src/useOverlay.ts +1 -1
@@ -0,0 +1,226 @@
1
+ var $59kHH$reactariautils = require("@react-aria/utils");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "usePreventScroll", () => $5c2f5cd01815d369$export$ee0f7cc6afcd1c18);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+ // @ts-ignore
21
+ const $5c2f5cd01815d369$var$visualViewport = typeof document !== "undefined" && window.visualViewport;
22
+ // HTML input types that do not cause the software keyboard to appear.
23
+ const $5c2f5cd01815d369$var$nonTextInputTypes = new Set([
24
+ "checkbox",
25
+ "radio",
26
+ "range",
27
+ "color",
28
+ "file",
29
+ "image",
30
+ "button",
31
+ "submit",
32
+ "reset"
33
+ ]);
34
+ // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
35
+ let $5c2f5cd01815d369$var$preventScrollCount = 0;
36
+ let $5c2f5cd01815d369$var$restore;
37
+ function $5c2f5cd01815d369$export$ee0f7cc6afcd1c18(options = {}) {
38
+ let { isDisabled: isDisabled } = options;
39
+ (0, $59kHH$reactariautils.useLayoutEffect)(()=>{
40
+ if (isDisabled) return;
41
+ $5c2f5cd01815d369$var$preventScrollCount++;
42
+ if ($5c2f5cd01815d369$var$preventScrollCount === 1) {
43
+ if ((0, $59kHH$reactariautils.isIOS)()) $5c2f5cd01815d369$var$restore = $5c2f5cd01815d369$var$preventScrollMobileSafari();
44
+ else $5c2f5cd01815d369$var$restore = $5c2f5cd01815d369$var$preventScrollStandard();
45
+ }
46
+ return ()=>{
47
+ $5c2f5cd01815d369$var$preventScrollCount--;
48
+ if ($5c2f5cd01815d369$var$preventScrollCount === 0) $5c2f5cd01815d369$var$restore();
49
+ };
50
+ }, [
51
+ isDisabled
52
+ ]);
53
+ }
54
+ // For most browsers, all we need to do is set `overflow: hidden` on the root element, and
55
+ // add some padding to prevent the page from shifting when the scrollbar is hidden.
56
+ function $5c2f5cd01815d369$var$preventScrollStandard() {
57
+ return (0, $59kHH$reactariautils.chain)($5c2f5cd01815d369$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $5c2f5cd01815d369$var$setStyle(document.documentElement, "overflow", "hidden"));
58
+ }
59
+ // Mobile Safari is a whole different beast. Even with overflow: hidden,
60
+ // it still scrolls the page in many situations:
61
+ //
62
+ // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
63
+ // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
64
+ // it, so it becomes scrollable.
65
+ // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
66
+ // This may cause even fixed position elements to scroll off the screen.
67
+ // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
68
+ // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
69
+ //
70
+ // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
71
+ //
72
+ // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
73
+ // on the window.
74
+ // 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
75
+ // the top or bottom. Work around a bug where this does not work when the element does not actually overflow
76
+ // by preventing default in a `touchmove` event.
77
+ // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
78
+ // 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
79
+ // of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
80
+ // into view ourselves, without scrolling the whole page.
81
+ // 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
82
+ // same visually, but makes the actual scroll position always zero. This is required to make all of the
83
+ // above work or Safari will still try to scroll the page when focusing an input.
84
+ // 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
85
+ // to navigate to an input with the next/previous buttons that's outside a modal.
86
+ function $5c2f5cd01815d369$var$preventScrollMobileSafari() {
87
+ let scrollable;
88
+ let restoreScrollableStyles;
89
+ let onTouchStart = (e)=>{
90
+ // Store the nearest scrollable parent element from the element that the user touched.
91
+ scrollable = (0, $59kHH$reactariautils.getScrollParent)(e.target, true);
92
+ if (scrollable === document.documentElement && scrollable === document.body) return;
93
+ // Prevent scrolling up when at the top and scrolling down when at the bottom
94
+ // of a nested scrollable area, otherwise mobile Safari will start scrolling
95
+ // the window instead.
96
+ if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === "auto") restoreScrollableStyles = $5c2f5cd01815d369$var$setStyle(scrollable, "overscrollBehavior", "contain");
97
+ };
98
+ let onTouchMove = (e)=>{
99
+ // Prevent scrolling the window.
100
+ if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
101
+ e.preventDefault();
102
+ return;
103
+ }
104
+ // overscroll-behavior should prevent scroll chaining, but currently does not
105
+ // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
106
+ // This checks that both the width and height do not overflow, otherwise we might
107
+ // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
108
+ // the element will prevent vertical page scrolling. We can't add that automatically
109
+ // because it must be set before the touchstart event.
110
+ if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
111
+ };
112
+ let onTouchEnd = (e)=>{
113
+ let target = e.target;
114
+ // Apply this change if we're not already focused on the target element
115
+ if ($5c2f5cd01815d369$var$willOpenKeyboard(target) && target !== document.activeElement) {
116
+ e.preventDefault();
117
+ setupStyles();
118
+ // Apply a transform to trick Safari into thinking the input is at the top of the page
119
+ // so it doesn't try to scroll it into view. When tapping on an input, this needs to
120
+ // be done before the "focus" event, so we have to focus the element ourselves.
121
+ target.style.transform = "translateY(-2000px)";
122
+ target.focus();
123
+ requestAnimationFrame(()=>{
124
+ target.style.transform = "";
125
+ });
126
+ }
127
+ if (restoreScrollableStyles) restoreScrollableStyles();
128
+ };
129
+ let onFocus = (e)=>{
130
+ let target = e.target;
131
+ if ($5c2f5cd01815d369$var$willOpenKeyboard(target)) {
132
+ setupStyles();
133
+ // Transform also needs to be applied in the focus event in cases where focus moves
134
+ // other than tapping on an input directly, e.g. the next/previous buttons in the
135
+ // software keyboard. In these cases, it seems applying the transform in the focus event
136
+ // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
137
+ target.style.transform = "translateY(-2000px)";
138
+ requestAnimationFrame(()=>{
139
+ target.style.transform = "";
140
+ // This will have prevented the browser from scrolling the focused element into view,
141
+ // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
142
+ if ($5c2f5cd01815d369$var$visualViewport) {
143
+ if ($5c2f5cd01815d369$var$visualViewport.height < window.innerHeight) // If the keyboard is already visible, do this after one additional frame
144
+ // to wait for the transform to be removed.
145
+ requestAnimationFrame(()=>{
146
+ $5c2f5cd01815d369$var$scrollIntoView(target);
147
+ });
148
+ else // Otherwise, wait for the visual viewport to resize before scrolling so we can
149
+ // measure the correct position to scroll to.
150
+ $5c2f5cd01815d369$var$visualViewport.addEventListener("resize", ()=>$5c2f5cd01815d369$var$scrollIntoView(target), {
151
+ once: true
152
+ });
153
+ }
154
+ });
155
+ }
156
+ };
157
+ let restoreStyles = null;
158
+ let setupStyles = ()=>{
159
+ if (restoreStyles) return;
160
+ let onWindowScroll = ()=>{
161
+ // Last resort. If the window scrolled, scroll it back to the top.
162
+ // It should always be at the top because the body will have a negative margin (see below).
163
+ window.scrollTo(0, 0);
164
+ };
165
+ // Record the original scroll position so we can restore it.
166
+ // Then apply a negative margin to the body to offset it by the scroll position. This will
167
+ // enable us to scroll the window to the top, which is required for the rest of this to work.
168
+ let scrollX = window.pageXOffset;
169
+ let scrollY = window.pageYOffset;
170
+ restoreStyles = (0, $59kHH$reactariautils.chain)($5c2f5cd01815d369$var$addEvent(window, "scroll", onWindowScroll), $5c2f5cd01815d369$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $5c2f5cd01815d369$var$setStyle(document.documentElement, "overflow", "hidden"), $5c2f5cd01815d369$var$setStyle(document.body, "marginTop", `-${scrollY}px`), ()=>{
171
+ window.scrollTo(scrollX, scrollY);
172
+ });
173
+ // Scroll to the top. The negative margin on the body will make this appear the same.
174
+ window.scrollTo(0, 0);
175
+ };
176
+ let removeEvents = (0, $59kHH$reactariautils.chain)($5c2f5cd01815d369$var$addEvent(document, "touchstart", onTouchStart, {
177
+ passive: false,
178
+ capture: true
179
+ }), $5c2f5cd01815d369$var$addEvent(document, "touchmove", onTouchMove, {
180
+ passive: false,
181
+ capture: true
182
+ }), $5c2f5cd01815d369$var$addEvent(document, "touchend", onTouchEnd, {
183
+ passive: false,
184
+ capture: true
185
+ }), $5c2f5cd01815d369$var$addEvent(document, "focus", onFocus, true));
186
+ return ()=>{
187
+ // Restore styles and scroll the page back to where it was.
188
+ restoreScrollableStyles === null || restoreScrollableStyles === void 0 ? void 0 : restoreScrollableStyles();
189
+ restoreStyles === null || restoreStyles === void 0 ? void 0 : restoreStyles();
190
+ removeEvents();
191
+ };
192
+ }
193
+ // Sets a CSS property on an element, and returns a function to revert it to the previous value.
194
+ function $5c2f5cd01815d369$var$setStyle(element, style, value) {
195
+ let cur = element.style[style];
196
+ element.style[style] = value;
197
+ return ()=>{
198
+ element.style[style] = cur;
199
+ };
200
+ }
201
+ // Adds an event listener to an element, and returns a function to remove it.
202
+ function $5c2f5cd01815d369$var$addEvent(target, event, handler, options) {
203
+ target.addEventListener(event, handler, options);
204
+ return ()=>{
205
+ target.removeEventListener(event, handler, options);
206
+ };
207
+ }
208
+ function $5c2f5cd01815d369$var$scrollIntoView(target) {
209
+ let root = document.scrollingElement || document.documentElement;
210
+ while(target && target !== root){
211
+ // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
212
+ let scrollable = (0, $59kHH$reactariautils.getScrollParent)(target);
213
+ if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
214
+ let scrollableTop = scrollable.getBoundingClientRect().top;
215
+ let targetTop = target.getBoundingClientRect().top;
216
+ if (targetTop > scrollableTop + target.clientHeight) scrollable.scrollTop += targetTop - scrollableTop;
217
+ }
218
+ target = scrollable.parentElement;
219
+ }
220
+ }
221
+ function $5c2f5cd01815d369$var$willOpenKeyboard(target) {
222
+ return target instanceof HTMLInputElement && !$5c2f5cd01815d369$var$nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
223
+ }
224
+
225
+
226
+ //# sourceMappingURL=usePreventScroll.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AASD,aAAa;AACb,MAAM,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAE/E,sEAAsE;AACtE,MAAM,0CAAoB,IAAI,IAAI;IAChC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,mIAAmI;AACnI,IAAI,2CAAqB;AACzB,IAAI;AAOG,SAAS,0CAAiB,UAAgC,CAAC,CAAC;IACjE,IAAI,cAAC,UAAU,EAAC,GAAG;IAEnB,CAAA,GAAA,qCAAc,EAAE;QACd,IAAI,YACF;QAGF;QACA,IAAI,6CAAuB;YACzB,IAAI,CAAA,GAAA,2BAAI,KACN,gCAAU;iBAEV,gCAAU;;QAId,OAAO;YACL;YACA,IAAI,6CAAuB,GACzB;QAEJ;IACF,GAAG;QAAC;KAAW;AACjB;AAEA,0FAA0F;AAC1F,mFAAmF;AACnF,SAAS;IACP,OAAO,CAAA,GAAA,2BAAI,EACT,+BAAS,SAAS,eAAe,EAAE,gBAAgB,CAAC,EAAE,OAAO,UAAU,GAAG,SAAS,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC,GAClH,+BAAS,SAAS,eAAe,EAAE,YAAY;AAEnD;AAEA,wEAAwE;AACxE,gDAAgD;AAChD,EAAE;AACF,8FAA8F;AAC9F,sGAAsG;AACtG,mCAAmC;AACnC,6GAA6G;AAC7G,2EAA2E;AAC3E,4GAA4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kBAAkB,uBACjB,kBAAkB,eAAe,OAAO,iBAAiB;AAE9D","sources":["packages/@react-aria/overlays/src/usePreventScroll.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, getScrollParent, isIOS, useLayoutEffect} from '@react-aria/utils';\n\ninterface PreventScrollOptions {\n /** Whether the scroll lock is disabled. */\n isDisabled?: boolean\n}\n\n// @ts-ignore\nconst visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\n// HTML input types that do not cause the software keyboard to appear.\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n// The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position\nlet preventScrollCount = 0;\nlet restore;\n\n/**\n * Prevents scrolling on the document body on mount, and\n * restores it on unmount. Also ensures that content does not\n * shift due to the scrollbars disappearing.\n */\nexport function usePreventScroll(options: PreventScrollOptions = {}) {\n let {isDisabled} = options;\n\n useLayoutEffect(() => {\n if (isDisabled) {\n return;\n }\n\n preventScrollCount++;\n if (preventScrollCount === 1) {\n if (isIOS()) {\n restore = preventScrollMobileSafari();\n } else {\n restore = preventScrollStandard();\n }\n }\n\n return () => {\n preventScrollCount--;\n if (preventScrollCount === 0) {\n restore();\n }\n };\n }, [isDisabled]);\n}\n\n// For most browsers, all we need to do is set `overflow: hidden` on the root element, and\n// add some padding to prevent the page from shifting when the scrollbar is hidden.\nfunction preventScrollStandard() {\n return chain(\n setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),\n setStyle(document.documentElement, 'overflow', 'hidden')\n );\n}\n\n// Mobile Safari is a whole different beast. Even with overflow: hidden,\n// it still scrolls the page in many situations:\n//\n// 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.\n// 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of\n// it, so it becomes scrollable.\n// 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.\n// This may cause even fixed position elements to scroll off the screen.\n// 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always\n// scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.\n//\n// In order to work around these cases, and prevent scrolling without jankiness, we do a few things:\n//\n// 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling\n// on the window.\n// 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at\n// the top or bottom. Work around a bug where this does not work when the element does not actually overflow\n// by preventing default in a `touchmove` event.\n// 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.\n// 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top\n// of the page, which prevents it from scrolling the page. After the input is focused, scroll the element\n// into view ourselves, without scrolling the whole page.\n// 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the\n// same visually, but makes the actual scroll position always zero. This is required to make all of the\n// above work or Safari will still try to scroll the page when focusing an input.\n// 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting\n// to navigate to an input with the next/previous buttons that's outside a modal.\nfunction preventScrollMobileSafari() {\n let scrollable: Element;\n let restoreScrollableStyles;\n let onTouchStart = (e: TouchEvent) => {\n // Store the nearest scrollable parent element from the element that the user touched.\n scrollable = getScrollParent(e.target as Element, true);\n if (scrollable === document.documentElement && scrollable === document.body) {\n return;\n }\n\n // Prevent scrolling up when at the top and scrolling down when at the bottom\n // of a nested scrollable area, otherwise mobile Safari will start scrolling\n // the window instead.\n if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === 'auto') {\n restoreScrollableStyles = setStyle(scrollable, 'overscrollBehavior', 'contain');\n }\n };\n\n let onTouchMove = (e: TouchEvent) => {\n // Prevent scrolling the window.\n if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {\n e.preventDefault();\n return;\n }\n\n // overscroll-behavior should prevent scroll chaining, but currently does not\n // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452\n // This checks that both the width and height do not overflow, otherwise we might\n // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to\n // the element will prevent vertical page scrolling. We can't add that automatically\n // because it must be set before the touchstart event.\n if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) {\n e.preventDefault();\n }\n };\n\n let onTouchEnd = (e: TouchEvent) => {\n let target = e.target as HTMLElement;\n\n // Apply this change if we're not already focused on the target element\n if (willOpenKeyboard(target) && target !== document.activeElement) {\n e.preventDefault();\n setupStyles();\n\n // Apply a transform to trick Safari into thinking the input is at the top of the page\n // so it doesn't try to scroll it into view. When tapping on an input, this needs to\n // be done before the \"focus\" event, so we have to focus the element ourselves.\n target.style.transform = 'translateY(-2000px)';\n target.focus();\n requestAnimationFrame(() => {\n target.style.transform = '';\n });\n }\n\n if (restoreScrollableStyles) {\n restoreScrollableStyles();\n }\n };\n\n let onFocus = (e: FocusEvent) => {\n let target = e.target as HTMLElement;\n if (willOpenKeyboard(target)) {\n setupStyles();\n\n // Transform also needs to be applied in the focus event in cases where focus moves\n // other than tapping on an input directly, e.g. the next/previous buttons in the\n // software keyboard. In these cases, it seems applying the transform in the focus event\n // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️\n target.style.transform = 'translateY(-2000px)';\n requestAnimationFrame(() => {\n target.style.transform = '';\n\n // This will have prevented the browser from scrolling the focused element into view,\n // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.\n if (visualViewport) {\n if (visualViewport.height < window.innerHeight) {\n // If the keyboard is already visible, do this after one additional frame\n // to wait for the transform to be removed.\n requestAnimationFrame(() => {\n scrollIntoView(target);\n });\n } else {\n // Otherwise, wait for the visual viewport to resize before scrolling so we can\n // measure the correct position to scroll to.\n visualViewport.addEventListener('resize', () => scrollIntoView(target), {once: true});\n }\n }\n });\n }\n };\n\n let restoreStyles = null;\n let setupStyles = () => {\n if (restoreStyles) {\n return;\n }\n\n let onWindowScroll = () => {\n // Last resort. If the window scrolled, scroll it back to the top.\n // It should always be at the top because the body will have a negative margin (see below).\n window.scrollTo(0, 0);\n };\n\n // Record the original scroll position so we can restore it.\n // Then apply a negative margin to the body to offset it by the scroll position. This will\n // enable us to scroll the window to the top, which is required for the rest of this to work.\n let scrollX = window.pageXOffset;\n let scrollY = window.pageYOffset;\n\n restoreStyles = chain(\n addEvent(window, 'scroll', onWindowScroll),\n setStyle(document.documentElement, 'paddingRight', `${window.innerWidth - document.documentElement.clientWidth}px`),\n setStyle(document.documentElement, 'overflow', 'hidden'),\n setStyle(document.body, 'marginTop', `-${scrollY}px`),\n () => {\n window.scrollTo(scrollX, scrollY);\n }\n );\n\n // Scroll to the top. The negative margin on the body will make this appear the same.\n window.scrollTo(0, 0);\n };\n\n let removeEvents = chain(\n addEvent(document, 'touchstart', onTouchStart, {passive: false, capture: true}),\n addEvent(document, 'touchmove', onTouchMove, {passive: false, capture: true}),\n addEvent(document, 'touchend', onTouchEnd, {passive: false, capture: true}),\n addEvent(document, 'focus', onFocus, true)\n );\n\n return () => {\n // Restore styles and scroll the page back to where it was.\n restoreScrollableStyles?.();\n restoreStyles?.();\n removeEvents();\n };\n}\n\n// Sets a CSS property on an element, and returns a function to revert it to the previous value.\nfunction setStyle(element: HTMLElement, style: string, value: string) {\n let cur = element.style[style];\n element.style[style] = value;\n\n return () => {\n element.style[style] = cur;\n };\n}\n\n// Adds an event listener to an element, and returns a function to remove it.\nfunction addEvent<K extends keyof GlobalEventHandlersEventMap>(\n target: EventTarget,\n event: K,\n handler: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,\n options?: boolean | AddEventListenerOptions\n) {\n target.addEventListener(event, handler, options);\n return () => {\n target.removeEventListener(event, handler, options);\n };\n}\n\nfunction scrollIntoView(target: Element) {\n let root = document.scrollingElement || document.documentElement;\n while (target && target !== root) {\n // Find the parent scrollable element and adjust the scroll position if the target is not already in view.\n let scrollable = getScrollParent(target);\n if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {\n let scrollableTop = scrollable.getBoundingClientRect().top;\n let targetTop = target.getBoundingClientRect().top;\n if (targetTop > scrollableTop + target.clientHeight) {\n scrollable.scrollTop += targetTop - scrollableTop;\n }\n }\n\n target = scrollable.parentElement;\n }\n}\n\nfunction willOpenKeyboard(target: Element) {\n return (\n (target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||\n target instanceof HTMLTextAreaElement ||\n (target instanceof HTMLElement && target.isContentEditable)\n );\n}\n"],"names":[],"version":3,"file":"usePreventScroll.main.js.map"}
@@ -0,0 +1,221 @@
1
+ import {useLayoutEffect as $7mMvr$useLayoutEffect, isIOS as $7mMvr$isIOS, chain as $7mMvr$chain, getScrollParent as $7mMvr$getScrollParent} from "@react-aria/utils";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ // @ts-ignore
15
+ const $49c51c25361d4cd2$var$visualViewport = typeof document !== "undefined" && window.visualViewport;
16
+ // HTML input types that do not cause the software keyboard to appear.
17
+ const $49c51c25361d4cd2$var$nonTextInputTypes = new Set([
18
+ "checkbox",
19
+ "radio",
20
+ "range",
21
+ "color",
22
+ "file",
23
+ "image",
24
+ "button",
25
+ "submit",
26
+ "reset"
27
+ ]);
28
+ // The number of active usePreventScroll calls. Used to determine whether to revert back to the original page style/scroll position
29
+ let $49c51c25361d4cd2$var$preventScrollCount = 0;
30
+ let $49c51c25361d4cd2$var$restore;
31
+ function $49c51c25361d4cd2$export$ee0f7cc6afcd1c18(options = {}) {
32
+ let { isDisabled: isDisabled } = options;
33
+ (0, $7mMvr$useLayoutEffect)(()=>{
34
+ if (isDisabled) return;
35
+ $49c51c25361d4cd2$var$preventScrollCount++;
36
+ if ($49c51c25361d4cd2$var$preventScrollCount === 1) {
37
+ if ((0, $7mMvr$isIOS)()) $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollMobileSafari();
38
+ else $49c51c25361d4cd2$var$restore = $49c51c25361d4cd2$var$preventScrollStandard();
39
+ }
40
+ return ()=>{
41
+ $49c51c25361d4cd2$var$preventScrollCount--;
42
+ if ($49c51c25361d4cd2$var$preventScrollCount === 0) $49c51c25361d4cd2$var$restore();
43
+ };
44
+ }, [
45
+ isDisabled
46
+ ]);
47
+ }
48
+ // For most browsers, all we need to do is set `overflow: hidden` on the root element, and
49
+ // add some padding to prevent the page from shifting when the scrollbar is hidden.
50
+ function $49c51c25361d4cd2$var$preventScrollStandard() {
51
+ return (0, $7mMvr$chain)($49c51c25361d4cd2$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $49c51c25361d4cd2$var$setStyle(document.documentElement, "overflow", "hidden"));
52
+ }
53
+ // Mobile Safari is a whole different beast. Even with overflow: hidden,
54
+ // it still scrolls the page in many situations:
55
+ //
56
+ // 1. When the bottom toolbar and address bar are collapsed, page scrolling is always allowed.
57
+ // 2. When the keyboard is visible, the viewport does not resize. Instead, the keyboard covers part of
58
+ // it, so it becomes scrollable.
59
+ // 3. When tapping on an input, the page always scrolls so that the input is centered in the visual viewport.
60
+ // This may cause even fixed position elements to scroll off the screen.
61
+ // 4. When using the next/previous buttons in the keyboard to navigate between inputs, the whole page always
62
+ // scrolls, even if the input is inside a nested scrollable element that could be scrolled instead.
63
+ //
64
+ // In order to work around these cases, and prevent scrolling without jankiness, we do a few things:
65
+ //
66
+ // 1. Prevent default on `touchmove` events that are not in a scrollable element. This prevents touch scrolling
67
+ // on the window.
68
+ // 2. Set `overscroll-behavior: contain` on nested scrollable regions so they do not scroll the page when at
69
+ // the top or bottom. Work around a bug where this does not work when the element does not actually overflow
70
+ // by preventing default in a `touchmove` event.
71
+ // 3. Prevent default on `touchend` events on input elements and handle focusing the element ourselves.
72
+ // 4. When focusing an input, apply a transform to trick Safari into thinking the input is at the top
73
+ // of the page, which prevents it from scrolling the page. After the input is focused, scroll the element
74
+ // into view ourselves, without scrolling the whole page.
75
+ // 5. Offset the body by the scroll position using a negative margin and scroll to the top. This should appear the
76
+ // same visually, but makes the actual scroll position always zero. This is required to make all of the
77
+ // above work or Safari will still try to scroll the page when focusing an input.
78
+ // 6. As a last resort, handle window scroll events, and scroll back to the top. This can happen when attempting
79
+ // to navigate to an input with the next/previous buttons that's outside a modal.
80
+ function $49c51c25361d4cd2$var$preventScrollMobileSafari() {
81
+ let scrollable;
82
+ let restoreScrollableStyles;
83
+ let onTouchStart = (e)=>{
84
+ // Store the nearest scrollable parent element from the element that the user touched.
85
+ scrollable = (0, $7mMvr$getScrollParent)(e.target, true);
86
+ if (scrollable === document.documentElement && scrollable === document.body) return;
87
+ // Prevent scrolling up when at the top and scrolling down when at the bottom
88
+ // of a nested scrollable area, otherwise mobile Safari will start scrolling
89
+ // the window instead.
90
+ if (scrollable instanceof HTMLElement && window.getComputedStyle(scrollable).overscrollBehavior === "auto") restoreScrollableStyles = $49c51c25361d4cd2$var$setStyle(scrollable, "overscrollBehavior", "contain");
91
+ };
92
+ let onTouchMove = (e)=>{
93
+ // Prevent scrolling the window.
94
+ if (!scrollable || scrollable === document.documentElement || scrollable === document.body) {
95
+ e.preventDefault();
96
+ return;
97
+ }
98
+ // overscroll-behavior should prevent scroll chaining, but currently does not
99
+ // if the element doesn't actually overflow. https://bugs.webkit.org/show_bug.cgi?id=243452
100
+ // This checks that both the width and height do not overflow, otherwise we might
101
+ // block horizontal scrolling too. In that case, adding `touch-action: pan-x` to
102
+ // the element will prevent vertical page scrolling. We can't add that automatically
103
+ // because it must be set before the touchstart event.
104
+ if (scrollable.scrollHeight === scrollable.clientHeight && scrollable.scrollWidth === scrollable.clientWidth) e.preventDefault();
105
+ };
106
+ let onTouchEnd = (e)=>{
107
+ let target = e.target;
108
+ // Apply this change if we're not already focused on the target element
109
+ if ($49c51c25361d4cd2$var$willOpenKeyboard(target) && target !== document.activeElement) {
110
+ e.preventDefault();
111
+ setupStyles();
112
+ // Apply a transform to trick Safari into thinking the input is at the top of the page
113
+ // so it doesn't try to scroll it into view. When tapping on an input, this needs to
114
+ // be done before the "focus" event, so we have to focus the element ourselves.
115
+ target.style.transform = "translateY(-2000px)";
116
+ target.focus();
117
+ requestAnimationFrame(()=>{
118
+ target.style.transform = "";
119
+ });
120
+ }
121
+ if (restoreScrollableStyles) restoreScrollableStyles();
122
+ };
123
+ let onFocus = (e)=>{
124
+ let target = e.target;
125
+ if ($49c51c25361d4cd2$var$willOpenKeyboard(target)) {
126
+ setupStyles();
127
+ // Transform also needs to be applied in the focus event in cases where focus moves
128
+ // other than tapping on an input directly, e.g. the next/previous buttons in the
129
+ // software keyboard. In these cases, it seems applying the transform in the focus event
130
+ // is good enough, whereas when tapping an input, it must be done before the focus event. 🤷‍♂️
131
+ target.style.transform = "translateY(-2000px)";
132
+ requestAnimationFrame(()=>{
133
+ target.style.transform = "";
134
+ // This will have prevented the browser from scrolling the focused element into view,
135
+ // so we need to do this ourselves in a way that doesn't cause the whole page to scroll.
136
+ if ($49c51c25361d4cd2$var$visualViewport) {
137
+ if ($49c51c25361d4cd2$var$visualViewport.height < window.innerHeight) // If the keyboard is already visible, do this after one additional frame
138
+ // to wait for the transform to be removed.
139
+ requestAnimationFrame(()=>{
140
+ $49c51c25361d4cd2$var$scrollIntoView(target);
141
+ });
142
+ else // Otherwise, wait for the visual viewport to resize before scrolling so we can
143
+ // measure the correct position to scroll to.
144
+ $49c51c25361d4cd2$var$visualViewport.addEventListener("resize", ()=>$49c51c25361d4cd2$var$scrollIntoView(target), {
145
+ once: true
146
+ });
147
+ }
148
+ });
149
+ }
150
+ };
151
+ let restoreStyles = null;
152
+ let setupStyles = ()=>{
153
+ if (restoreStyles) return;
154
+ let onWindowScroll = ()=>{
155
+ // Last resort. If the window scrolled, scroll it back to the top.
156
+ // It should always be at the top because the body will have a negative margin (see below).
157
+ window.scrollTo(0, 0);
158
+ };
159
+ // Record the original scroll position so we can restore it.
160
+ // Then apply a negative margin to the body to offset it by the scroll position. This will
161
+ // enable us to scroll the window to the top, which is required for the rest of this to work.
162
+ let scrollX = window.pageXOffset;
163
+ let scrollY = window.pageYOffset;
164
+ restoreStyles = (0, $7mMvr$chain)($49c51c25361d4cd2$var$addEvent(window, "scroll", onWindowScroll), $49c51c25361d4cd2$var$setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`), $49c51c25361d4cd2$var$setStyle(document.documentElement, "overflow", "hidden"), $49c51c25361d4cd2$var$setStyle(document.body, "marginTop", `-${scrollY}px`), ()=>{
165
+ window.scrollTo(scrollX, scrollY);
166
+ });
167
+ // Scroll to the top. The negative margin on the body will make this appear the same.
168
+ window.scrollTo(0, 0);
169
+ };
170
+ let removeEvents = (0, $7mMvr$chain)($49c51c25361d4cd2$var$addEvent(document, "touchstart", onTouchStart, {
171
+ passive: false,
172
+ capture: true
173
+ }), $49c51c25361d4cd2$var$addEvent(document, "touchmove", onTouchMove, {
174
+ passive: false,
175
+ capture: true
176
+ }), $49c51c25361d4cd2$var$addEvent(document, "touchend", onTouchEnd, {
177
+ passive: false,
178
+ capture: true
179
+ }), $49c51c25361d4cd2$var$addEvent(document, "focus", onFocus, true));
180
+ return ()=>{
181
+ // Restore styles and scroll the page back to where it was.
182
+ restoreScrollableStyles === null || restoreScrollableStyles === void 0 ? void 0 : restoreScrollableStyles();
183
+ restoreStyles === null || restoreStyles === void 0 ? void 0 : restoreStyles();
184
+ removeEvents();
185
+ };
186
+ }
187
+ // Sets a CSS property on an element, and returns a function to revert it to the previous value.
188
+ function $49c51c25361d4cd2$var$setStyle(element, style, value) {
189
+ let cur = element.style[style];
190
+ element.style[style] = value;
191
+ return ()=>{
192
+ element.style[style] = cur;
193
+ };
194
+ }
195
+ // Adds an event listener to an element, and returns a function to remove it.
196
+ function $49c51c25361d4cd2$var$addEvent(target, event, handler, options) {
197
+ target.addEventListener(event, handler, options);
198
+ return ()=>{
199
+ target.removeEventListener(event, handler, options);
200
+ };
201
+ }
202
+ function $49c51c25361d4cd2$var$scrollIntoView(target) {
203
+ let root = document.scrollingElement || document.documentElement;
204
+ while(target && target !== root){
205
+ // Find the parent scrollable element and adjust the scroll position if the target is not already in view.
206
+ let scrollable = (0, $7mMvr$getScrollParent)(target);
207
+ if (scrollable !== document.documentElement && scrollable !== document.body && scrollable !== target) {
208
+ let scrollableTop = scrollable.getBoundingClientRect().top;
209
+ let targetTop = target.getBoundingClientRect().top;
210
+ if (targetTop > scrollableTop + target.clientHeight) scrollable.scrollTop += targetTop - scrollableTop;
211
+ }
212
+ target = scrollable.parentElement;
213
+ }
214
+ }
215
+ function $49c51c25361d4cd2$var$willOpenKeyboard(target) {
216
+ return target instanceof HTMLInputElement && !$49c51c25361d4cd2$var$nonTextInputTypes.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLElement && target.isContentEditable;
217
+ }
218
+
219
+
220
+ export {$49c51c25361d4cd2$export$ee0f7cc6afcd1c18 as usePreventScroll};
221
+ //# sourceMappingURL=usePreventScroll.mjs.map