@react-aria/utils 3.31.0 → 3.33.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 (84) hide show
  1. package/dist/DOMFunctions.main.js +1 -1
  2. package/dist/DOMFunctions.main.js.map +1 -1
  3. package/dist/DOMFunctions.mjs +1 -1
  4. package/dist/DOMFunctions.module.js +1 -1
  5. package/dist/DOMFunctions.module.js.map +1 -1
  6. package/dist/domHelpers.main.js.map +1 -1
  7. package/dist/domHelpers.module.js.map +1 -1
  8. package/dist/filterDOMProps.main.js +1 -1
  9. package/dist/filterDOMProps.main.js.map +1 -1
  10. package/dist/filterDOMProps.mjs +1 -1
  11. package/dist/filterDOMProps.module.js +1 -1
  12. package/dist/filterDOMProps.module.js.map +1 -1
  13. package/dist/mergeProps.main.js +3 -0
  14. package/dist/mergeProps.main.js.map +1 -1
  15. package/dist/mergeProps.mjs +3 -0
  16. package/dist/mergeProps.module.js +3 -0
  17. package/dist/mergeProps.module.js.map +1 -1
  18. package/dist/openLink.main.js +1 -0
  19. package/dist/openLink.main.js.map +1 -1
  20. package/dist/openLink.mjs +1 -0
  21. package/dist/openLink.module.js +1 -0
  22. package/dist/openLink.module.js.map +1 -1
  23. package/dist/scrollIntoView.main.js +13 -38
  24. package/dist/scrollIntoView.main.js.map +1 -1
  25. package/dist/scrollIntoView.mjs +13 -38
  26. package/dist/scrollIntoView.module.js +13 -38
  27. package/dist/scrollIntoView.module.js.map +1 -1
  28. package/dist/types.d.ts +8 -9
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/useDrag1D.main.js +3 -1
  31. package/dist/useDrag1D.main.js.map +1 -1
  32. package/dist/useDrag1D.mjs +3 -1
  33. package/dist/useDrag1D.module.js +3 -1
  34. package/dist/useDrag1D.module.js.map +1 -1
  35. package/dist/useEvent.main.js +1 -2
  36. package/dist/useEvent.main.js.map +1 -1
  37. package/dist/useEvent.mjs +1 -2
  38. package/dist/useEvent.module.js +1 -2
  39. package/dist/useEvent.module.js.map +1 -1
  40. package/dist/useFormReset.main.js +1 -2
  41. package/dist/useFormReset.main.js.map +1 -1
  42. package/dist/useFormReset.mjs +1 -2
  43. package/dist/useFormReset.module.js +1 -2
  44. package/dist/useFormReset.module.js.map +1 -1
  45. package/dist/useLoadMoreSentinel.main.js +0 -1
  46. package/dist/useLoadMoreSentinel.main.js.map +1 -1
  47. package/dist/useLoadMoreSentinel.mjs +0 -1
  48. package/dist/useLoadMoreSentinel.module.js +0 -1
  49. package/dist/useLoadMoreSentinel.module.js.map +1 -1
  50. package/dist/useResizeObserver.main.js +8 -4
  51. package/dist/useResizeObserver.main.js.map +1 -1
  52. package/dist/useResizeObserver.mjs +8 -4
  53. package/dist/useResizeObserver.module.js +8 -4
  54. package/dist/useResizeObserver.module.js.map +1 -1
  55. package/dist/useUpdateEffect.main.js +5 -2
  56. package/dist/useUpdateEffect.main.js.map +1 -1
  57. package/dist/useUpdateEffect.mjs +5 -2
  58. package/dist/useUpdateEffect.module.js +5 -2
  59. package/dist/useUpdateEffect.module.js.map +1 -1
  60. package/dist/useValueEffect.main.js +13 -8
  61. package/dist/useValueEffect.main.js.map +1 -1
  62. package/dist/useValueEffect.mjs +14 -9
  63. package/dist/useValueEffect.module.js +14 -9
  64. package/dist/useValueEffect.module.js.map +1 -1
  65. package/dist/useViewportSize.main.js +13 -14
  66. package/dist/useViewportSize.main.js.map +1 -1
  67. package/dist/useViewportSize.mjs +13 -14
  68. package/dist/useViewportSize.module.js +13 -14
  69. package/dist/useViewportSize.module.js.map +1 -1
  70. package/package.json +4 -4
  71. package/src/domHelpers.ts +2 -2
  72. package/src/filterDOMProps.ts +1 -1
  73. package/src/mergeProps.ts +4 -2
  74. package/src/openLink.tsx +1 -1
  75. package/src/scrollIntoView.ts +19 -49
  76. package/src/shadowdom/DOMFunctions.ts +1 -0
  77. package/src/useDrag1D.ts +2 -1
  78. package/src/useEvent.ts +1 -1
  79. package/src/useFormReset.ts +1 -1
  80. package/src/useLoadMoreSentinel.ts +1 -1
  81. package/src/useResizeObserver.ts +8 -4
  82. package/src/useUpdateEffect.ts +5 -3
  83. package/src/useValueEffect.ts +15 -11
  84. package/src/useViewportSize.ts +15 -16
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAkB,YAA2B;IAC3D,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;IACjC,IAAI,SAAgD,CAAA,GAAA,aAAK,EAAuB;IAEhF,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,UAAU,CAAA,GAAA,yCAAa,EAAE;QAC3B,IAAI,CAAC,OAAO,OAAO,EACjB;QAEF,uCAAuC;QACvC,IAAI,WAAW,OAAO,OAAO,CAAC,IAAI;QAElC,8CAA8C;QAC9C,IAAI,SAAS,IAAI,EAAE;YACjB,OAAO,OAAO,GAAG;YACjB;QACF;QAEA,iDAAiD;QACjD,8CAA8C;QAC9C,8DAA8D;QAC9D,IAAI,UAAU,SAAS,KAAK,EAC1B;aAEA,SAAS,SAAS,KAAK;IAE3B;IAEA,CAAA,GAAA,yCAAc,EAAE;QACd,uEAAuE;QACvE,IAAI,OAAO,OAAO,EAChB;IAEJ;IAEA,IAAI,QAAQ,CAAA,GAAA,yCAAa,EAAE,CAAA;QACzB,OAAO,OAAO,GAAG,GAAG;QACpB;IACF;IAEA,OAAO;QAAC;QAAO;KAAM;AACvB","sources":["packages/@react-aria/utils/src/useValueEffect.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 {Dispatch, MutableRefObject, useRef, useState} from 'react';\nimport {useEffectEvent, useLayoutEffect} from './';\n\ntype SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;\n\n// This hook works like `useState`, but when setting the value, you pass a generator function\n// that can yield multiple values. Each yielded value updates the state and waits for the next\n// layout effect, then continues the generator. This allows sequential updates to state to be\n// written linearly.\nexport function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>] {\n let [value, setValue] = useState(defaultValue);\n let effect: MutableRefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);\n\n // Store the function in a ref so we can always access the current version\n // which has the proper `value` in scope.\n let nextRef = useEffectEvent(() => {\n if (!effect.current) {\n return;\n }\n // Run the generator to the next yield.\n let newValue = effect.current.next();\n\n // If the generator is done, reset the effect.\n if (newValue.done) {\n effect.current = null;\n return;\n }\n\n // If the value is the same as the current value,\n // then continue to the next yield. Otherwise,\n // set the value in state and wait for the next layout effect.\n if (value === newValue.value) {\n nextRef();\n } else {\n setValue(newValue.value);\n }\n });\n\n useLayoutEffect(() => {\n // If there is an effect currently running, continue to the next yield.\n if (effect.current) {\n nextRef();\n }\n });\n\n let queue = useEffectEvent(fn => {\n effect.current = fn(value);\n nextRef();\n });\n\n return [value, queue];\n}\n"],"names":[],"version":3,"file":"useValueEffect.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAkB,YAA2B;IAC3D,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;IACjC,iGAAiG;IACjG,sDAAsD;IACtD,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,SAAyC,CAAA,GAAA,aAAK,EAAuB;IAEzE,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE;QACnB,IAAI,CAAC,OAAO,OAAO,EACjB;QAEF,uCAAuC;QACvC,IAAI,WAAW,OAAO,OAAO,CAAC,IAAI;QAElC,8CAA8C;QAC9C,IAAI,SAAS,IAAI,EAAE;YACjB,OAAO,OAAO,GAAG;YACjB;QACF;QAEA,iDAAiD;QACjD,8CAA8C;QAC9C,8DAA8D;QAC9D,IAAI,UAAU,OAAO,KAAK,SAAS,KAAK,EACtC,QAAQ,OAAO;aAEf,SAAS,SAAS,KAAK;IAE3B;IAEA,CAAA,GAAA,yCAAc,EAAE;QACd,UAAU,OAAO,GAAG;QACpB,uEAAuE;QACvE,IAAI,OAAO,OAAO,EAChB,QAAQ,OAAO;IAEnB;IAEA,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE,CAAA;QACtB,OAAO,OAAO,GAAG,GAAG,UAAU,OAAO;QACrC,QAAQ,OAAO;IACjB,GAAG;QAAC;KAAQ;IAEZ,OAAO;QAAC;QAAO;KAAM;AACvB","sources":["packages/@react-aria/utils/src/useValueEffect.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 {Dispatch, RefObject, useCallback, useRef, useState} from 'react';\nimport {useLayoutEffect} from './';\n\ntype SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;\n\n// This hook works like `useState`, but when setting the value, you pass a generator function\n// that can yield multiple values. Each yielded value updates the state and waits for the next\n// layout effect, then continues the generator. This allows sequential updates to state to be\n// written linearly.\nexport function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>] {\n let [value, setValue] = useState(defaultValue);\n // Keep an up to date copy of value in a ref so we can access the current value in the generator.\n // This allows us to maintain a stable queue function.\n let currValue = useRef(value);\n let effect: RefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);\n\n // Store the function in a ref so we can always access the current version\n // which has the proper `value` in scope.\n let nextRef = useRef(() => {\n if (!effect.current) {\n return;\n }\n // Run the generator to the next yield.\n let newValue = effect.current.next();\n\n // If the generator is done, reset the effect.\n if (newValue.done) {\n effect.current = null;\n return;\n }\n\n // If the value is the same as the current value,\n // then continue to the next yield. Otherwise,\n // set the value in state and wait for the next layout effect.\n if (currValue.current === newValue.value) {\n nextRef.current();\n } else {\n setValue(newValue.value);\n }\n });\n\n useLayoutEffect(() => {\n currValue.current = value;\n // If there is an effect currently running, continue to the next yield.\n if (effect.current) {\n nextRef.current();\n }\n });\n\n let queue = useCallback(fn => {\n effect.current = fn(currValue.current);\n nextRef.current();\n }, [nextRef]);\n\n return [value, queue];\n}\n"],"names":[],"version":3,"file":"useValueEffect.module.js.map"}
@@ -29,16 +29,18 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
29
29
  height: 0
30
30
  } : $8b24bab62f5c65ad$var$getViewportSize());
31
31
  (0, $4gIVO$react.useEffect)(()=>{
32
- // Use visualViewport api to track available height even on iOS virtual keyboard opening
33
- let onResize = ()=>{
34
- // Ignore updates when zoomed.
35
- if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
32
+ let updateSize = (newSize)=>{
36
33
  setSize((size)=>{
37
- let newSize = $8b24bab62f5c65ad$var$getViewportSize();
38
34
  if (newSize.width === size.width && newSize.height === size.height) return size;
39
35
  return newSize;
40
36
  });
41
37
  };
38
+ // Use visualViewport api to track available height even on iOS virtual keyboard opening
39
+ let onResize = ()=>{
40
+ // Ignore updates when zoomed.
41
+ if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
42
+ updateSize($8b24bab62f5c65ad$var$getViewportSize());
43
+ };
42
44
  // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
43
45
  // We can anticipate this and resize early by handling the blur event and using the layout size.
44
46
  let frame;
@@ -46,16 +48,13 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
46
48
  if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
47
49
  if ((0, $2308dc377e184bb0$exports.willOpenKeyboard)(e.target)) // Wait one frame to see if a new element gets focused.
48
50
  frame = requestAnimationFrame(()=>{
49
- if (!document.activeElement || !(0, $2308dc377e184bb0$exports.willOpenKeyboard)(document.activeElement)) setSize((size)=>{
50
- let newSize = {
51
- width: window.innerWidth,
52
- height: window.innerHeight
53
- };
54
- if (newSize.width === size.width && newSize.height === size.height) return size;
55
- return newSize;
51
+ if (!document.activeElement || !(0, $2308dc377e184bb0$exports.willOpenKeyboard)(document.activeElement)) updateSize({
52
+ width: document.documentElement.clientWidth,
53
+ height: document.documentElement.clientHeight
56
54
  });
57
55
  });
58
56
  };
57
+ updateSize($8b24bab62f5c65ad$var$getViewportSize());
59
58
  window.addEventListener('blur', onBlur, true);
60
59
  if (!$8b24bab62f5c65ad$var$visualViewport) window.addEventListener('resize', onResize);
61
60
  else $8b24bab62f5c65ad$var$visualViewport.addEventListener('resize', onResize);
@@ -71,8 +70,8 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
71
70
  function $8b24bab62f5c65ad$var$getViewportSize() {
72
71
  return {
73
72
  // Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
74
- width: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.width * $8b24bab62f5c65ad$var$visualViewport.scale : window.innerWidth,
75
- height: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.height * $8b24bab62f5c65ad$var$visualViewport.scale : window.innerHeight
73
+ width: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.width * $8b24bab62f5c65ad$var$visualViewport.scale : document.documentElement.clientWidth,
74
+ height: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.height * $8b24bab62f5c65ad$var$visualViewport.scale : document.documentElement.clientHeight
76
75
  };
77
76
  }
78
77
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAWD,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,qBAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,sBAAQ,EAAE;QACR,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,QAAQ,CAAA;gBACN,IAAI,UAAU;gBACd,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,0CAAe,EAAE,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,0CAAe,EAAE,SAAS,aAAa,GACrE,QAAQ,CAAA;oBACN,IAAI,UAAU;wBAAC,OAAO,OAAO,UAAU;wBAAE,QAAQ,OAAO,WAAW;oBAAA;oBACnE,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;oBAET,OAAO;gBACT;YAEJ;QAEJ;QAEA,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAExC,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAC3C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAAiB,qCAAe,KAAK,GAAG,qCAAe,KAAK,GAAG,OAAO,UAAU;QACvF,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,OAAO,WAAW;IAC5F;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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 {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n // Ignore updates when zoomed.\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n setSize(size => {\n let newSize = getViewportSize();\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n // We can anticipate this and resize early by handling the blur event and using the layout size.\n let frame: number;\n let onBlur = (e: FocusEvent) => {\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n if (willOpenKeyboard(e.target as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n if (!document.activeElement || !willOpenKeyboard(document.activeElement)) {\n setSize(size => {\n let newSize = {width: window.innerWidth, height: window.innerHeight};\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n }\n });\n }\n };\n\n window.addEventListener('blur', onBlur, true);\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('blur', onBlur, true);\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n width: visualViewport ? visualViewport.width * visualViewport.scale : window.innerWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : window.innerHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAWD,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,qBAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,aAAa,CAAC;YAChB,QAAQ,CAAA;gBACN,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,WAAW;QACb;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,0CAAe,EAAE,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,0CAAe,EAAE,SAAS,aAAa,GACrE,WAAW;oBAAC,OAAO,SAAS,eAAe,CAAC,WAAW;oBAAE,QAAQ,SAAS,eAAe,CAAC,YAAY;gBAAA;YAE1G;QAEJ;QAEA,WAAW;QAEX,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAExC,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAC3C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAAiB,qCAAe,KAAK,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,WAAW;QAC1G,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,YAAY;IAC/G;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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 {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n let updateSize = (newSize: ViewportSize) => {\n setSize(size => {\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n // Ignore updates when zoomed.\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n updateSize(getViewportSize());\n };\n\n // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n // We can anticipate this and resize early by handling the blur event and using the layout size.\n let frame: number;\n let onBlur = (e: FocusEvent) => {\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n if (willOpenKeyboard(e.target as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n if (!document.activeElement || !willOpenKeyboard(document.activeElement)) {\n updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n }\n });\n }\n };\n\n updateSize(getViewportSize());\n\n window.addEventListener('blur', onBlur, true);\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('blur', onBlur, true);\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n width: visualViewport ? visualViewport.width * visualViewport.scale : document.documentElement.clientWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : document.documentElement.clientHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.main.js.map"}
@@ -23,16 +23,18 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
23
23
  height: 0
24
24
  } : $5df64b3807dc15ee$var$getViewportSize());
25
25
  (0, $fuDHA$useEffect)(()=>{
26
- // Use visualViewport api to track available height even on iOS virtual keyboard opening
27
- let onResize = ()=>{
28
- // Ignore updates when zoomed.
29
- if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
26
+ let updateSize = (newSize)=>{
30
27
  setSize((size)=>{
31
- let newSize = $5df64b3807dc15ee$var$getViewportSize();
32
28
  if (newSize.width === size.width && newSize.height === size.height) return size;
33
29
  return newSize;
34
30
  });
35
31
  };
32
+ // Use visualViewport api to track available height even on iOS virtual keyboard opening
33
+ let onResize = ()=>{
34
+ // Ignore updates when zoomed.
35
+ if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
36
+ updateSize($5df64b3807dc15ee$var$getViewportSize());
37
+ };
36
38
  // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
37
39
  // We can anticipate this and resize early by handling the blur event and using the layout size.
38
40
  let frame;
@@ -40,16 +42,13 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
40
42
  if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
41
43
  if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e.target)) // Wait one frame to see if a new element gets focused.
42
44
  frame = requestAnimationFrame(()=>{
43
- if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) setSize((size)=>{
44
- let newSize = {
45
- width: window.innerWidth,
46
- height: window.innerHeight
47
- };
48
- if (newSize.width === size.width && newSize.height === size.height) return size;
49
- return newSize;
45
+ if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) updateSize({
46
+ width: document.documentElement.clientWidth,
47
+ height: document.documentElement.clientHeight
50
48
  });
51
49
  });
52
50
  };
51
+ updateSize($5df64b3807dc15ee$var$getViewportSize());
53
52
  window.addEventListener('blur', onBlur, true);
54
53
  if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
55
54
  else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
@@ -65,8 +64,8 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
65
64
  function $5df64b3807dc15ee$var$getViewportSize() {
66
65
  return {
67
66
  // Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
68
- width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : window.innerWidth,
69
- height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : window.innerHeight
67
+ width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientWidth,
68
+ height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientHeight
70
69
  };
71
70
  }
72
71
 
@@ -23,16 +23,18 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
23
23
  height: 0
24
24
  } : $5df64b3807dc15ee$var$getViewportSize());
25
25
  (0, $fuDHA$useEffect)(()=>{
26
- // Use visualViewport api to track available height even on iOS virtual keyboard opening
27
- let onResize = ()=>{
28
- // Ignore updates when zoomed.
29
- if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
26
+ let updateSize = (newSize)=>{
30
27
  setSize((size)=>{
31
- let newSize = $5df64b3807dc15ee$var$getViewportSize();
32
28
  if (newSize.width === size.width && newSize.height === size.height) return size;
33
29
  return newSize;
34
30
  });
35
31
  };
32
+ // Use visualViewport api to track available height even on iOS virtual keyboard opening
33
+ let onResize = ()=>{
34
+ // Ignore updates when zoomed.
35
+ if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
36
+ updateSize($5df64b3807dc15ee$var$getViewportSize());
37
+ };
36
38
  // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
37
39
  // We can anticipate this and resize early by handling the blur event and using the layout size.
38
40
  let frame;
@@ -40,16 +42,13 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
40
42
  if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
41
43
  if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e.target)) // Wait one frame to see if a new element gets focused.
42
44
  frame = requestAnimationFrame(()=>{
43
- if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) setSize((size)=>{
44
- let newSize = {
45
- width: window.innerWidth,
46
- height: window.innerHeight
47
- };
48
- if (newSize.width === size.width && newSize.height === size.height) return size;
49
- return newSize;
45
+ if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) updateSize({
46
+ width: document.documentElement.clientWidth,
47
+ height: document.documentElement.clientHeight
50
48
  });
51
49
  });
52
50
  };
51
+ updateSize($5df64b3807dc15ee$var$getViewportSize());
53
52
  window.addEventListener('blur', onBlur, true);
54
53
  if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
55
54
  else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
@@ -65,8 +64,8 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
65
64
  function $5df64b3807dc15ee$var$getViewportSize() {
66
65
  return {
67
66
  // Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
68
- width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : window.innerWidth,
69
- height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : window.innerHeight
67
+ width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientWidth,
68
+ height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientHeight
70
69
  };
71
70
  }
72
71
 
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAWD,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,eAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,gBAAQ,EAAE;QACR,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,QAAQ,CAAA;gBACN,IAAI,UAAU;gBACd,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,yCAAe,EAAE,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,yCAAe,EAAE,SAAS,aAAa,GACrE,QAAQ,CAAA;oBACN,IAAI,UAAU;wBAAC,OAAO,OAAO,UAAU;wBAAE,QAAQ,OAAO,WAAW;oBAAA;oBACnE,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;oBAET,OAAO;gBACT;YAEJ;QAEJ;QAEA,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAExC,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAC3C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAAiB,qCAAe,KAAK,GAAG,qCAAe,KAAK,GAAG,OAAO,UAAU;QACvF,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,OAAO,WAAW;IAC5F;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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 {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n // Ignore updates when zoomed.\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n setSize(size => {\n let newSize = getViewportSize();\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n // We can anticipate this and resize early by handling the blur event and using the layout size.\n let frame: number;\n let onBlur = (e: FocusEvent) => {\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n if (willOpenKeyboard(e.target as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n if (!document.activeElement || !willOpenKeyboard(document.activeElement)) {\n setSize(size => {\n let newSize = {width: window.innerWidth, height: window.innerHeight};\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n }\n });\n }\n };\n\n window.addEventListener('blur', onBlur, true);\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('blur', onBlur, true);\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n width: visualViewport ? visualViewport.width * visualViewport.scale : window.innerWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : window.innerHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAWD,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,eAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,aAAa,CAAC;YAChB,QAAQ,CAAA;gBACN,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,WAAW;QACb;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,yCAAe,EAAE,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,yCAAe,EAAE,SAAS,aAAa,GACrE,WAAW;oBAAC,OAAO,SAAS,eAAe,CAAC,WAAW;oBAAE,QAAQ,SAAS,eAAe,CAAC,YAAY;gBAAA;YAE1G;QAEJ;QAEA,WAAW;QAEX,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAExC,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAC3C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAAiB,qCAAe,KAAK,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,WAAW;QAC1G,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,YAAY;IAC/G;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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 {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n let updateSize = (newSize: ViewportSize) => {\n setSize(size => {\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n // Ignore updates when zoomed.\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n updateSize(getViewportSize());\n };\n\n // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n // We can anticipate this and resize early by handling the blur event and using the layout size.\n let frame: number;\n let onBlur = (e: FocusEvent) => {\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n if (willOpenKeyboard(e.target as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n if (!document.activeElement || !willOpenKeyboard(document.activeElement)) {\n updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n }\n });\n }\n };\n\n updateSize(getViewportSize());\n\n window.addEventListener('blur', onBlur, true);\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('blur', onBlur, true);\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n width: visualViewport ? visualViewport.width * visualViewport.scale : document.documentElement.clientWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : document.documentElement.clientHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/utils",
3
- "version": "3.31.0",
3
+ "version": "3.33.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -28,8 +28,8 @@
28
28
  "dependencies": {
29
29
  "@react-aria/ssr": "^3.9.10",
30
30
  "@react-stately/flags": "^3.1.2",
31
- "@react-stately/utils": "^3.10.8",
32
- "@react-types/shared": "^3.32.1",
31
+ "@react-stately/utils": "^3.11.0",
32
+ "@react-types/shared": "^3.33.0",
33
33
  "@swc/helpers": "^0.5.0",
34
34
  "clsx": "^2.0.0"
35
35
  },
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
43
+ "gitHead": "66e51757606b43a89ed02c574ca24517323a2ab9"
44
44
  }
package/src/domHelpers.ts CHANGED
@@ -3,8 +3,8 @@ export const getOwnerDocument = (el: Element | null | undefined): Document => {
3
3
  };
4
4
 
5
5
  export const getOwnerWindow = (
6
- el: (Window & typeof global) | Element | null | undefined
7
- ): Window & typeof global => {
6
+ el: (Window & typeof globalThis) | Element | null | undefined
7
+ ): Window & typeof globalThis => {
8
8
  if (el && 'window' in el && el.window === el) {
9
9
  return el;
10
10
  }
@@ -114,7 +114,7 @@ export function filterDOMProps(props: DOMProps & AriaLabelingProps & LinkDOMProp
114
114
  (labelable && labelablePropNames.has(prop)) ||
115
115
  (isLink && linkPropNames.has(prop)) ||
116
116
  (global && globalAttrs.has(prop)) ||
117
- (events && globalEvents.has(prop) || (prop.endsWith('Capture') && globalEvents.has(prop.slice(0, -7)))) ||
117
+ (events && (globalEvents.has(prop) || (prop.endsWith('Capture') && globalEvents.has(prop.slice(0, -7))))) ||
118
118
  propNames?.has(prop) ||
119
119
  propRe.test(prop)
120
120
  )
package/src/mergeProps.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  import {chain} from './chain';
14
14
  import clsx from 'clsx';
15
15
  import {mergeIds} from './useId';
16
+ import {mergeRefs} from './mergeRefs';
16
17
 
17
18
  interface Props {
18
19
  [key: string]: any
@@ -28,8 +29,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
28
29
 
29
30
  /**
30
31
  * Merges multiple props objects together. Event handlers are chained,
31
- * classNames are combined, and ids are deduplicated - different ids
32
- * will trigger a side-effect and re-render components hooked up with `useId`.
32
+ * classNames are combined, ids are deduplicated, and refs are merged.
33
33
  * For all other props, the last prop object overrides all previous ones.
34
34
  * @param args - Multiple sets of props to merge together.
35
35
  */
@@ -64,6 +64,8 @@ export function mergeProps<T extends PropsArg[]>(...args: T): UnionToIntersectio
64
64
  result[key] = clsx(a, b);
65
65
  } else if (key === 'id' && a && b) {
66
66
  result.id = mergeIds(a, b);
67
+ } else if (key === 'ref' && a && b) {
68
+ result.ref = mergeRefs(a, b);
67
69
  // Override others
68
70
  } else {
69
71
  result[key] = b !== undefined ? b : a;
package/src/openLink.tsx CHANGED
@@ -106,7 +106,7 @@ export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpe
106
106
  let event = isWebKit() && isMac() && !isIPad() && process.env.NODE_ENV !== 'test'
107
107
  // @ts-ignore - keyIdentifier is a non-standard property, but it's what webkit expects
108
108
  ? new KeyboardEvent('keydown', {keyIdentifier: 'Enter', metaKey, ctrlKey, altKey, shiftKey})
109
- : new MouseEvent('click', {metaKey, ctrlKey, altKey, shiftKey, bubbles: true, cancelable: true});
109
+ : new MouseEvent('click', {metaKey, ctrlKey, altKey, shiftKey, detail: 1, bubbles: true, cancelable: true});
110
110
  (openLink as any).isOpening = setOpening;
111
111
  focusWithoutScrolling(target);
112
112
  target.dispatchEvent(event);
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {getScrollParents} from './getScrollParents';
14
- import {isChrome} from './platform';
14
+ import {nodeContains} from './shadowdom/DOMFunctions';
15
15
 
16
16
  interface ScrollIntoViewportOpts {
17
17
  /** The optional containing element of the target to be centered in the viewport. */
@@ -41,64 +41,32 @@ export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement): v
41
41
  scrollPaddingLeft
42
42
  } = getComputedStyle(scrollView);
43
43
 
44
- // Account for scroll margin of the element
45
- let {
46
- scrollMarginTop,
47
- scrollMarginRight,
48
- scrollMarginBottom,
49
- scrollMarginLeft
50
- } = getComputedStyle(element);
51
-
52
44
  let borderAdjustedX = x + parseInt(borderLeftWidth, 10);
53
45
  let borderAdjustedY = y + parseInt(borderTopWidth, 10);
54
46
  // Ignore end/bottom border via clientHeight/Width instead of offsetHeight/Width
55
47
  let maxX = borderAdjustedX + scrollView.clientWidth;
56
48
  let maxY = borderAdjustedY + scrollView.clientHeight;
57
49
 
58
- // Get scroll padding / margin values as pixels - defaults to 0 if no scroll padding / margin
50
+ // Get scroll padding values as pixels - defaults to 0 if no scroll padding
59
51
  // is used.
60
52
  let scrollPaddingTopNumber = parseInt(scrollPaddingTop, 10) || 0;
61
53
  let scrollPaddingBottomNumber = parseInt(scrollPaddingBottom, 10) || 0;
62
54
  let scrollPaddingRightNumber = parseInt(scrollPaddingRight, 10) || 0;
63
55
  let scrollPaddingLeftNumber = parseInt(scrollPaddingLeft, 10) || 0;
64
- let scrollMarginTopNumber = parseInt(scrollMarginTop, 10) || 0;
65
- let scrollMarginBottomNumber = parseInt(scrollMarginBottom, 10) || 0;
66
- let scrollMarginRightNumber = parseInt(scrollMarginRight, 10) || 0;
67
- let scrollMarginLeftNumber = parseInt(scrollMarginLeft, 10) || 0;
68
-
69
- let targetLeft = offsetX - scrollMarginLeftNumber;
70
- let targetRight = offsetX + width + scrollMarginRightNumber;
71
- let targetTop = offsetY - scrollMarginTopNumber;
72
- let targetBottom = offsetY + height + scrollMarginBottomNumber;
73
-
74
- let scrollPortLeft = x + parseInt(borderLeftWidth, 10) + scrollPaddingLeftNumber;
75
- let scrollPortRight = maxX - scrollPaddingRightNumber;
76
- let scrollPortTop = y + parseInt(borderTopWidth, 10) + scrollPaddingTopNumber;
77
- let scrollPortBottom = maxY - scrollPaddingBottomNumber;
78
-
79
- if (targetLeft > scrollPortLeft || targetRight < scrollPortRight) {
80
- if (targetLeft <= x + scrollPaddingLeftNumber) {
81
- x = targetLeft - parseInt(borderLeftWidth, 10) - scrollPaddingLeftNumber;
82
- } else if (targetRight > maxX - scrollPaddingRightNumber) {
83
- x += targetRight - maxX + scrollPaddingRightNumber;
84
- }
85
- }
86
56
 
87
- if (targetTop > scrollPortTop || targetBottom < scrollPortBottom) {
88
- if (targetTop <= borderAdjustedY + scrollPaddingTopNumber) {
89
- y = targetTop - parseInt(borderTopWidth, 10) - scrollPaddingTopNumber;
90
- } else if (targetBottom > maxY - scrollPaddingBottomNumber) {
91
- y += targetBottom - maxY + scrollPaddingBottomNumber;
92
- }
57
+ if (offsetX <= x + scrollPaddingLeftNumber) {
58
+ x = offsetX - parseInt(borderLeftWidth, 10) - scrollPaddingLeftNumber;
59
+ } else if (offsetX + width > maxX - scrollPaddingRightNumber) {
60
+ x += offsetX + width - maxX + scrollPaddingRightNumber;
93
61
  }
94
-
95
- if (process.env.NODE_ENV === 'test') {
96
- scrollView.scrollLeft = x;
97
- scrollView.scrollTop = y;
98
- return;
62
+ if (offsetY <= borderAdjustedY + scrollPaddingTopNumber) {
63
+ y = offsetY - parseInt(borderTopWidth, 10) - scrollPaddingTopNumber;
64
+ } else if (offsetY + height > maxY - scrollPaddingBottomNumber) {
65
+ y += offsetY + height - maxY + scrollPaddingBottomNumber;
99
66
  }
100
67
 
101
- scrollView.scrollTo({left: x, top: y});
68
+ scrollView.scrollLeft = x;
69
+ scrollView.scrollTop = y;
102
70
  }
103
71
 
104
72
  /**
@@ -113,7 +81,7 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
113
81
  if (child.offsetParent === ancestor) {
114
82
  // Stop once we have found the ancestor we are interested in.
115
83
  break;
116
- } else if (child.offsetParent.contains(ancestor)) {
84
+ } else if (nodeContains(child.offsetParent, ancestor)) {
117
85
  // If the ancestor is not `position:relative`, then we stop at
118
86
  // _its_ offset parent, and we subtract off _its_ offset, so that
119
87
  // we end up with the proper offset from child to ancestor.
@@ -131,12 +99,11 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
131
99
  * the body (e.g. targetElement is in a popover), this will only scroll the scroll parents of the targetElement up to but not including the body itself.
132
100
  */
133
101
  export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts): void {
134
- if (targetElement && document.contains(targetElement)) {
102
+ if (targetElement && nodeContains(document, targetElement)) {
135
103
  let root = document.scrollingElement || document.documentElement;
136
104
  let isScrollPrevented = window.getComputedStyle(root).overflow === 'hidden';
137
- // If scrolling is not currently prevented then we aren't in a overlay nor is a overlay open, just use element.scrollIntoView to bring the element into view
138
- // Also ignore in chrome because of this bug: https://issues.chromium.org/issues/40074749
139
- if (!isScrollPrevented && !isChrome()) {
105
+ // If scrolling is not currently prevented then we arent in a overlay nor is a overlay open, just use element.scrollIntoView to bring the element into view
106
+ if (!isScrollPrevented) {
140
107
  let {left: originalLeft, top: originalTop} = targetElement.getBoundingClientRect();
141
108
 
142
109
  // use scrollIntoView({block: 'nearest'}) instead of .focus to check if the element is fully in view or not since .focus()
@@ -151,6 +118,9 @@ export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollI
151
118
  } else {
152
119
  let scrollParents = getScrollParents(targetElement);
153
120
  // If scrolling is prevented, we don't want to scroll the body since it might move the overlay partially offscreen and the user can't scroll it back into view.
121
+ if (!isScrollPrevented) {
122
+ scrollParents.push(root);
123
+ }
154
124
  for (let scrollParent of scrollParents) {
155
125
  scrollIntoView(scrollParent as HTMLElement, targetElement as HTMLElement);
156
126
  }
@@ -1,4 +1,5 @@
1
1
  // Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16
2
+ /* eslint-disable rsp-rules/no-non-shadow-contains */
2
3
 
3
4
  import {isShadowRoot} from '../domHelpers';
4
5
  import {shadowDOM} from '@react-stately/flags';
package/src/useDrag1D.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  /* eslint-disable rulesdir/pure-render */
14
14
 
15
15
  import {getOffset} from './getOffset';
16
+ import {nodeContains} from './shadowdom/DOMFunctions';
16
17
  import {Orientation} from '@react-types/shared';
17
18
  import React, {HTMLAttributes, MutableRefObject, useRef} from 'react';
18
19
 
@@ -99,7 +100,7 @@ export function useDrag1D(props: UseDrag1DProps): HTMLAttributes<HTMLElement> {
99
100
  const target = e.currentTarget;
100
101
  // If we're already handling dragging on a descendant with useDrag1D, then
101
102
  // we don't want to handle the drag motion on this target as well.
102
- if (draggingElements.some(elt => target.contains(elt))) {
103
+ if (draggingElements.some(elt => nodeContains(target, elt))) {
103
104
  return;
104
105
  }
105
106
  draggingElements.push(target);
package/src/useEvent.ts CHANGED
@@ -33,5 +33,5 @@ export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
33
33
  return () => {
34
34
  element.removeEventListener(event, handleEvent as EventListener, options);
35
35
  };
36
- }, [ref, event, options, isDisabled, handleEvent]);
36
+ }, [ref, event, options, isDisabled]);
37
37
  }
@@ -32,5 +32,5 @@ export function useFormReset<T>(
32
32
  return () => {
33
33
  form?.removeEventListener('reset', handleReset);
34
34
  };
35
- }, [ref, handleReset]);
35
+ }, [ref]);
36
36
  }
@@ -59,5 +59,5 @@ export function useLoadMoreSentinel(props: LoadMoreSentinelProps, ref: RefObject
59
59
  sentinelObserver.current.disconnect();
60
60
  }
61
61
  };
62
- }, [collection, triggerLoadMore, ref, scrollOffset]);
62
+ }, [collection, ref, scrollOffset]);
63
63
  }
@@ -1,6 +1,7 @@
1
1
 
2
2
  import {RefObject} from '@react-types/shared';
3
3
  import {useEffect} from 'react';
4
+ import {useEffectEvent} from './useEffectEvent';
4
5
 
5
6
  function hasResizeObserver() {
6
7
  return typeof window.ResizeObserver !== 'undefined';
@@ -13,7 +14,10 @@ type useResizeObserverOptionsType<T> = {
13
14
  }
14
15
 
15
16
  export function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>): void {
17
+ // Only call onResize from inside the effect, otherwise we'll void our assumption that
18
+ // useEffectEvents are safe to pass in.
16
19
  const {ref, box, onResize} = options;
20
+ let onResizeEvent = useEffectEvent(onResize);
17
21
 
18
22
  useEffect(() => {
19
23
  let element = ref?.current;
@@ -22,9 +26,9 @@ export function useResizeObserver<T extends Element>(options: useResizeObserverO
22
26
  }
23
27
 
24
28
  if (!hasResizeObserver()) {
25
- window.addEventListener('resize', onResize, false);
29
+ window.addEventListener('resize', onResizeEvent, false);
26
30
  return () => {
27
- window.removeEventListener('resize', onResize, false);
31
+ window.removeEventListener('resize', onResizeEvent, false);
28
32
  };
29
33
  } else {
30
34
 
@@ -33,7 +37,7 @@ export function useResizeObserver<T extends Element>(options: useResizeObserverO
33
37
  return;
34
38
  }
35
39
 
36
- onResize();
40
+ onResizeEvent();
37
41
  });
38
42
  resizeObserverInstance.observe(element, {box});
39
43
 
@@ -44,5 +48,5 @@ export function useResizeObserver<T extends Element>(options: useResizeObserverO
44
48
  };
45
49
  }
46
50
 
47
- }, [onResize, ref, box]);
51
+ }, [ref, box]);
48
52
  }
@@ -11,11 +11,13 @@
11
11
  */
12
12
 
13
13
  import {EffectCallback, useEffect, useRef} from 'react';
14
+ import {useEffectEvent} from './useEffectEvent';
14
15
 
15
16
  // Like useEffect, but only called for updates after the initial render.
16
- export function useUpdateEffect(effect: EffectCallback, dependencies: any[]): void {
17
+ export function useUpdateEffect(cb: EffectCallback, dependencies: any[]): void {
17
18
  const isInitialMount = useRef(true);
18
19
  const lastDeps = useRef<any[] | null>(null);
20
+ let cbEvent = useEffectEvent(cb);
19
21
 
20
22
  useEffect(() => {
21
23
  isInitialMount.current = true;
@@ -29,9 +31,9 @@ export function useUpdateEffect(effect: EffectCallback, dependencies: any[]): vo
29
31
  if (isInitialMount.current) {
30
32
  isInitialMount.current = false;
31
33
  } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {
32
- effect();
34
+ cbEvent();
33
35
  }
34
36
  lastDeps.current = dependencies;
35
- // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
38
  }, dependencies);
37
39
  }