@react-aria/utils 3.31.0 → 3.32.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 (60) hide show
  1. package/dist/filterDOMProps.main.js +1 -1
  2. package/dist/filterDOMProps.main.js.map +1 -1
  3. package/dist/filterDOMProps.mjs +1 -1
  4. package/dist/filterDOMProps.module.js +1 -1
  5. package/dist/filterDOMProps.module.js.map +1 -1
  6. package/dist/mergeProps.main.js.map +1 -1
  7. package/dist/mergeProps.module.js.map +1 -1
  8. package/dist/openLink.main.js +1 -0
  9. package/dist/openLink.main.js.map +1 -1
  10. package/dist/openLink.mjs +1 -0
  11. package/dist/openLink.module.js +1 -0
  12. package/dist/openLink.module.js.map +1 -1
  13. package/dist/scrollIntoView.main.js +10 -37
  14. package/dist/scrollIntoView.main.js.map +1 -1
  15. package/dist/scrollIntoView.mjs +10 -37
  16. package/dist/scrollIntoView.module.js +10 -37
  17. package/dist/scrollIntoView.module.js.map +1 -1
  18. package/dist/types.d.ts +3 -4
  19. package/dist/types.d.ts.map +1 -1
  20. package/dist/useEvent.main.js +1 -2
  21. package/dist/useEvent.main.js.map +1 -1
  22. package/dist/useEvent.mjs +1 -2
  23. package/dist/useEvent.module.js +1 -2
  24. package/dist/useEvent.module.js.map +1 -1
  25. package/dist/useFormReset.main.js +1 -2
  26. package/dist/useFormReset.main.js.map +1 -1
  27. package/dist/useFormReset.mjs +1 -2
  28. package/dist/useFormReset.module.js +1 -2
  29. package/dist/useFormReset.module.js.map +1 -1
  30. package/dist/useLoadMoreSentinel.main.js +0 -1
  31. package/dist/useLoadMoreSentinel.main.js.map +1 -1
  32. package/dist/useLoadMoreSentinel.mjs +0 -1
  33. package/dist/useLoadMoreSentinel.module.js +0 -1
  34. package/dist/useLoadMoreSentinel.module.js.map +1 -1
  35. package/dist/useResizeObserver.main.js +8 -4
  36. package/dist/useResizeObserver.main.js.map +1 -1
  37. package/dist/useResizeObserver.mjs +8 -4
  38. package/dist/useResizeObserver.module.js +8 -4
  39. package/dist/useResizeObserver.module.js.map +1 -1
  40. package/dist/useUpdateEffect.main.js +5 -2
  41. package/dist/useUpdateEffect.main.js.map +1 -1
  42. package/dist/useUpdateEffect.mjs +5 -2
  43. package/dist/useUpdateEffect.module.js +5 -2
  44. package/dist/useUpdateEffect.module.js.map +1 -1
  45. package/dist/useValueEffect.main.js +13 -8
  46. package/dist/useValueEffect.main.js.map +1 -1
  47. package/dist/useValueEffect.mjs +14 -9
  48. package/dist/useValueEffect.module.js +14 -9
  49. package/dist/useValueEffect.module.js.map +1 -1
  50. package/package.json +3 -3
  51. package/src/filterDOMProps.ts +1 -1
  52. package/src/mergeProps.ts +1 -2
  53. package/src/openLink.tsx +1 -1
  54. package/src/scrollIntoView.ts +16 -47
  55. package/src/useEvent.ts +1 -1
  56. package/src/useFormReset.ts +1 -1
  57. package/src/useLoadMoreSentinel.ts +1 -1
  58. package/src/useResizeObserver.ts +8 -4
  59. package/src/useUpdateEffect.ts +5 -3
  60. package/src/useValueEffect.ts +15 -11
@@ -1,3 +1,4 @@
1
+ var $1254e5bb94ac8761$exports = require("./useEffectEvent.main.js");
1
2
  var $cagC1$react = require("react");
2
3
 
3
4
 
@@ -17,9 +18,11 @@ $parcel$export(module.exports, "useUpdateEffect", () => $29293a6f5c75b37e$export
17
18
  * OF ANY KIND, either express or implied. See the License for the specific language
18
19
  * governing permissions and limitations under the License.
19
20
  */
20
- function $29293a6f5c75b37e$export$496315a1608d9602(effect, dependencies) {
21
+
22
+ function $29293a6f5c75b37e$export$496315a1608d9602(cb, dependencies) {
21
23
  const isInitialMount = (0, $cagC1$react.useRef)(true);
22
24
  const lastDeps = (0, $cagC1$react.useRef)(null);
25
+ let cbEvent = (0, $1254e5bb94ac8761$exports.useEffectEvent)(cb);
23
26
  (0, $cagC1$react.useEffect)(()=>{
24
27
  isInitialMount.current = true;
25
28
  return ()=>{
@@ -29,7 +32,7 @@ function $29293a6f5c75b37e$export$496315a1608d9602(effect, dependencies) {
29
32
  (0, $cagC1$react.useEffect)(()=>{
30
33
  let prevDeps = lastDeps.current;
31
34
  if (isInitialMount.current) isInitialMount.current = false;
32
- else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) effect();
35
+ else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) cbEvent();
33
36
  lastDeps.current = dependencies;
34
37
  // eslint-disable-next-line react-hooks/exhaustive-deps
35
38
  }, dependencies);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAKM,SAAS,0CAAgB,MAAsB,EAAE,YAAmB;IACzE,MAAM,iBAAiB,CAAA,GAAA,mBAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,mBAAK,EAAgB;IAEtC,CAAA,GAAA,sBAAQ,EAAE;QACR,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,WAAW,SAAS,OAAO;QAC/B,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IAC/E;QAEF,SAAS,OAAO,GAAG;IACnB,uDAAuD;IACzD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateEffect.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 {EffectCallback, useEffect, useRef} from 'react';\n\n// Like useEffect, but only called for updates after the initial render.\nexport function useUpdateEffect(effect: EffectCallback, dependencies: any[]): void {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n\n useEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useEffect(() => {\n let prevDeps = lastDeps.current;\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {\n effect();\n }\n lastDeps.current = dependencies;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n"],"names":[],"version":3,"file":"useUpdateEffect.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAMM,SAAS,0CAAgB,EAAkB,EAAE,YAAmB;IACrE,MAAM,iBAAiB,CAAA,GAAA,mBAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,mBAAK,EAAgB;IACtC,IAAI,UAAU,CAAA,GAAA,wCAAa,EAAE;IAE7B,CAAA,GAAA,sBAAQ,EAAE;QACR,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,WAAW,SAAS,OAAO;QAC/B,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IAC/E;QAEF,SAAS,OAAO,GAAG;IACrB,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateEffect.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 {EffectCallback, useEffect, useRef} from 'react';\nimport {useEffectEvent} from './useEffectEvent';\n\n// Like useEffect, but only called for updates after the initial render.\nexport function useUpdateEffect(cb: EffectCallback, dependencies: any[]): void {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n let cbEvent = useEffectEvent(cb);\n\n useEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useEffect(() => {\n let prevDeps = lastDeps.current;\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {\n cbEvent();\n }\n lastDeps.current = dependencies;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n"],"names":[],"version":3,"file":"useUpdateEffect.main.js.map"}
@@ -1,3 +1,4 @@
1
+ import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.mjs";
1
2
  import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
2
3
 
3
4
  /*
@@ -11,9 +12,11 @@ import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
11
12
  * OF ANY KIND, either express or implied. See the License for the specific language
12
13
  * governing permissions and limitations under the License.
13
14
  */
14
- function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
15
+
16
+ function $4f58c5f72bcf79f7$export$496315a1608d9602(cb, dependencies) {
15
17
  const isInitialMount = (0, $9vW05$useRef)(true);
16
18
  const lastDeps = (0, $9vW05$useRef)(null);
19
+ let cbEvent = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(cb);
17
20
  (0, $9vW05$useEffect)(()=>{
18
21
  isInitialMount.current = true;
19
22
  return ()=>{
@@ -23,7 +26,7 @@ function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
23
26
  (0, $9vW05$useEffect)(()=>{
24
27
  let prevDeps = lastDeps.current;
25
28
  if (isInitialMount.current) isInitialMount.current = false;
26
- else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) effect();
29
+ else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) cbEvent();
27
30
  lastDeps.current = dependencies;
28
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
29
32
  }, dependencies);
@@ -1,3 +1,4 @@
1
+ import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.module.js";
1
2
  import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
2
3
 
3
4
  /*
@@ -11,9 +12,11 @@ import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
11
12
  * OF ANY KIND, either express or implied. See the License for the specific language
12
13
  * governing permissions and limitations under the License.
13
14
  */
14
- function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
15
+
16
+ function $4f58c5f72bcf79f7$export$496315a1608d9602(cb, dependencies) {
15
17
  const isInitialMount = (0, $9vW05$useRef)(true);
16
18
  const lastDeps = (0, $9vW05$useRef)(null);
19
+ let cbEvent = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(cb);
17
20
  (0, $9vW05$useEffect)(()=>{
18
21
  isInitialMount.current = true;
19
22
  return ()=>{
@@ -23,7 +26,7 @@ function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
23
26
  (0, $9vW05$useEffect)(()=>{
24
27
  let prevDeps = lastDeps.current;
25
28
  if (isInitialMount.current) isInitialMount.current = false;
26
- else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) effect();
29
+ else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) cbEvent();
27
30
  lastDeps.current = dependencies;
28
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
29
32
  }, dependencies);
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAKM,SAAS,0CAAgB,MAAsB,EAAE,YAAmB;IACzE,MAAM,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,aAAK,EAAgB;IAEtC,CAAA,GAAA,gBAAQ,EAAE;QACR,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,WAAW,SAAS,OAAO;QAC/B,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IAC/E;QAEF,SAAS,OAAO,GAAG;IACnB,uDAAuD;IACzD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateEffect.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 {EffectCallback, useEffect, useRef} from 'react';\n\n// Like useEffect, but only called for updates after the initial render.\nexport function useUpdateEffect(effect: EffectCallback, dependencies: any[]): void {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n\n useEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useEffect(() => {\n let prevDeps = lastDeps.current;\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {\n effect();\n }\n lastDeps.current = dependencies;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n"],"names":[],"version":3,"file":"useUpdateEffect.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAMM,SAAS,0CAAgB,EAAkB,EAAE,YAAmB;IACrE,MAAM,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,aAAK,EAAgB;IACtC,IAAI,UAAU,CAAA,GAAA,yCAAa,EAAE;IAE7B,CAAA,GAAA,gBAAQ,EAAE;QACR,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,WAAW,SAAS,OAAO;QAC/B,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IAC/E;QAEF,SAAS,OAAO,GAAG;IACrB,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateEffect.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 {EffectCallback, useEffect, useRef} from 'react';\nimport {useEffectEvent} from './useEffectEvent';\n\n// Like useEffect, but only called for updates after the initial render.\nexport function useUpdateEffect(cb: EffectCallback, dependencies: any[]): void {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n let cbEvent = useEffectEvent(cb);\n\n useEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useEffect(() => {\n let prevDeps = lastDeps.current;\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {\n cbEvent();\n }\n lastDeps.current = dependencies;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n"],"names":[],"version":3,"file":"useUpdateEffect.module.js.map"}
@@ -1,4 +1,3 @@
1
- var $1254e5bb94ac8761$exports = require("./useEffectEvent.main.js");
2
1
  var $78605a5d7424e31b$exports = require("./useLayoutEffect.main.js");
3
2
  var $fymK9$react = require("react");
4
3
 
@@ -22,10 +21,13 @@ $parcel$export(module.exports, "useValueEffect", () => $19a2307bfabafaf1$export$
22
21
 
23
22
  function $19a2307bfabafaf1$export$14d238f342723f25(defaultValue) {
24
23
  let [value, setValue] = (0, $fymK9$react.useState)(defaultValue);
24
+ // Keep an up to date copy of value in a ref so we can access the current value in the generator.
25
+ // This allows us to maintain a stable queue function.
26
+ let currValue = (0, $fymK9$react.useRef)(value);
25
27
  let effect = (0, $fymK9$react.useRef)(null);
26
28
  // Store the function in a ref so we can always access the current version
27
29
  // which has the proper `value` in scope.
28
- let nextRef = (0, $1254e5bb94ac8761$exports.useEffectEvent)(()=>{
30
+ let nextRef = (0, $fymK9$react.useRef)(()=>{
29
31
  if (!effect.current) return;
30
32
  // Run the generator to the next yield.
31
33
  let newValue = effect.current.next();
@@ -37,17 +39,20 @@ function $19a2307bfabafaf1$export$14d238f342723f25(defaultValue) {
37
39
  // If the value is the same as the current value,
38
40
  // then continue to the next yield. Otherwise,
39
41
  // set the value in state and wait for the next layout effect.
40
- if (value === newValue.value) nextRef();
42
+ if (currValue.current === newValue.value) nextRef.current();
41
43
  else setValue(newValue.value);
42
44
  });
43
45
  (0, $78605a5d7424e31b$exports.useLayoutEffect)(()=>{
46
+ currValue.current = value;
44
47
  // If there is an effect currently running, continue to the next yield.
45
- if (effect.current) nextRef();
46
- });
47
- let queue = (0, $1254e5bb94ac8761$exports.useEffectEvent)((fn)=>{
48
- effect.current = fn(value);
49
- nextRef();
48
+ if (effect.current) nextRef.current();
50
49
  });
50
+ let queue = (0, $fymK9$react.useCallback)((fn)=>{
51
+ effect.current = fn(currValue.current);
52
+ nextRef.current();
53
+ }, [
54
+ nextRef
55
+ ]);
51
56
  return [
52
57
  value,
53
58
  queue
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAkB,YAA2B;IAC3D,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAO,EAAE;IACjC,IAAI,SAAgD,CAAA,GAAA,mBAAK,EAAuB;IAEhF,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,UAAU,CAAA,GAAA,wCAAa,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,wCAAa,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.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAkB,YAA2B;IAC3D,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAO,EAAE;IACjC,iGAAiG;IACjG,sDAAsD;IACtD,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,SAAyC,CAAA,GAAA,mBAAK,EAAuB;IAEzE,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,UAAU,CAAA,GAAA,mBAAK,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,wBAAU,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.main.js.map"}
@@ -1,6 +1,5 @@
1
- import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.mjs";
2
1
  import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.mjs";
3
- import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
2
+ import {useState as $fCAlL$useState, useRef as $fCAlL$useRef, useCallback as $fCAlL$useCallback} from "react";
4
3
 
5
4
  /*
6
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -16,10 +15,13 @@ import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
16
15
 
17
16
  function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
18
17
  let [value, setValue] = (0, $fCAlL$useState)(defaultValue);
18
+ // Keep an up to date copy of value in a ref so we can access the current value in the generator.
19
+ // This allows us to maintain a stable queue function.
20
+ let currValue = (0, $fCAlL$useRef)(value);
19
21
  let effect = (0, $fCAlL$useRef)(null);
20
22
  // Store the function in a ref so we can always access the current version
21
23
  // which has the proper `value` in scope.
22
- let nextRef = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(()=>{
24
+ let nextRef = (0, $fCAlL$useRef)(()=>{
23
25
  if (!effect.current) return;
24
26
  // Run the generator to the next yield.
25
27
  let newValue = effect.current.next();
@@ -31,17 +33,20 @@ function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
31
33
  // If the value is the same as the current value,
32
34
  // then continue to the next yield. Otherwise,
33
35
  // set the value in state and wait for the next layout effect.
34
- if (value === newValue.value) nextRef();
36
+ if (currValue.current === newValue.value) nextRef.current();
35
37
  else setValue(newValue.value);
36
38
  });
37
39
  (0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
40
+ currValue.current = value;
38
41
  // If there is an effect currently running, continue to the next yield.
39
- if (effect.current) nextRef();
40
- });
41
- let queue = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)((fn)=>{
42
- effect.current = fn(value);
43
- nextRef();
42
+ if (effect.current) nextRef.current();
44
43
  });
44
+ let queue = (0, $fCAlL$useCallback)((fn)=>{
45
+ effect.current = fn(currValue.current);
46
+ nextRef.current();
47
+ }, [
48
+ nextRef
49
+ ]);
45
50
  return [
46
51
  value,
47
52
  queue
@@ -1,6 +1,5 @@
1
- import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.module.js";
2
1
  import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.module.js";
3
- import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
2
+ import {useState as $fCAlL$useState, useRef as $fCAlL$useRef, useCallback as $fCAlL$useCallback} from "react";
4
3
 
5
4
  /*
6
5
  * Copyright 2020 Adobe. All rights reserved.
@@ -16,10 +15,13 @@ import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
16
15
 
17
16
  function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
18
17
  let [value, setValue] = (0, $fCAlL$useState)(defaultValue);
18
+ // Keep an up to date copy of value in a ref so we can access the current value in the generator.
19
+ // This allows us to maintain a stable queue function.
20
+ let currValue = (0, $fCAlL$useRef)(value);
19
21
  let effect = (0, $fCAlL$useRef)(null);
20
22
  // Store the function in a ref so we can always access the current version
21
23
  // which has the proper `value` in scope.
22
- let nextRef = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(()=>{
24
+ let nextRef = (0, $fCAlL$useRef)(()=>{
23
25
  if (!effect.current) return;
24
26
  // Run the generator to the next yield.
25
27
  let newValue = effect.current.next();
@@ -31,17 +33,20 @@ function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
31
33
  // If the value is the same as the current value,
32
34
  // then continue to the next yield. Otherwise,
33
35
  // set the value in state and wait for the next layout effect.
34
- if (value === newValue.value) nextRef();
36
+ if (currValue.current === newValue.value) nextRef.current();
35
37
  else setValue(newValue.value);
36
38
  });
37
39
  (0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
40
+ currValue.current = value;
38
41
  // If there is an effect currently running, continue to the next yield.
39
- if (effect.current) nextRef();
40
- });
41
- let queue = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)((fn)=>{
42
- effect.current = fn(value);
43
- nextRef();
42
+ if (effect.current) nextRef.current();
44
43
  });
44
+ let queue = (0, $fCAlL$useCallback)((fn)=>{
45
+ effect.current = fn(currValue.current);
46
+ nextRef.current();
47
+ }, [
48
+ nextRef
49
+ ]);
45
50
  return [
46
51
  value,
47
52
  queue
@@ -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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/utils",
3
- "version": "3.31.0",
3
+ "version": "3.32.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -28,7 +28,7 @@
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",
31
+ "@react-stately/utils": "^3.11.0",
32
32
  "@react-types/shared": "^3.32.1",
33
33
  "@swc/helpers": "^0.5.0",
34
34
  "clsx": "^2.0.0"
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
43
+ "gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
44
44
  }
@@ -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
@@ -28,8 +28,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
28
28
 
29
29
  /**
30
30
  * 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`.
31
+ * classNames are combined, and ids are deduplicated.
33
32
  * For all other props, the last prop object overrides all previous ones.
34
33
  * @param args - Multiple sets of props to merge together.
35
34
  */
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,6 @@
11
11
  */
12
12
 
13
13
  import {getScrollParents} from './getScrollParents';
14
- import {isChrome} from './platform';
15
14
 
16
15
  interface ScrollIntoViewportOpts {
17
16
  /** The optional containing element of the target to be centered in the viewport. */
@@ -41,64 +40,32 @@ export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement): v
41
40
  scrollPaddingLeft
42
41
  } = getComputedStyle(scrollView);
43
42
 
44
- // Account for scroll margin of the element
45
- let {
46
- scrollMarginTop,
47
- scrollMarginRight,
48
- scrollMarginBottom,
49
- scrollMarginLeft
50
- } = getComputedStyle(element);
51
-
52
43
  let borderAdjustedX = x + parseInt(borderLeftWidth, 10);
53
44
  let borderAdjustedY = y + parseInt(borderTopWidth, 10);
54
45
  // Ignore end/bottom border via clientHeight/Width instead of offsetHeight/Width
55
46
  let maxX = borderAdjustedX + scrollView.clientWidth;
56
47
  let maxY = borderAdjustedY + scrollView.clientHeight;
57
48
 
58
- // Get scroll padding / margin values as pixels - defaults to 0 if no scroll padding / margin
49
+ // Get scroll padding values as pixels - defaults to 0 if no scroll padding
59
50
  // is used.
60
51
  let scrollPaddingTopNumber = parseInt(scrollPaddingTop, 10) || 0;
61
52
  let scrollPaddingBottomNumber = parseInt(scrollPaddingBottom, 10) || 0;
62
53
  let scrollPaddingRightNumber = parseInt(scrollPaddingRight, 10) || 0;
63
54
  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
55
 
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
- }
56
+ if (offsetX <= x + scrollPaddingLeftNumber) {
57
+ x = offsetX - parseInt(borderLeftWidth, 10) - scrollPaddingLeftNumber;
58
+ } else if (offsetX + width > maxX - scrollPaddingRightNumber) {
59
+ x += offsetX + width - maxX + scrollPaddingRightNumber;
93
60
  }
94
-
95
- if (process.env.NODE_ENV === 'test') {
96
- scrollView.scrollLeft = x;
97
- scrollView.scrollTop = y;
98
- return;
61
+ if (offsetY <= borderAdjustedY + scrollPaddingTopNumber) {
62
+ y = offsetY - parseInt(borderTopWidth, 10) - scrollPaddingTopNumber;
63
+ } else if (offsetY + height > maxY - scrollPaddingBottomNumber) {
64
+ y += offsetY + height - maxY + scrollPaddingBottomNumber;
99
65
  }
100
66
 
101
- scrollView.scrollTo({left: x, top: y});
67
+ scrollView.scrollLeft = x;
68
+ scrollView.scrollTop = y;
102
69
  }
103
70
 
104
71
  /**
@@ -134,9 +101,8 @@ export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollI
134
101
  if (targetElement && document.contains(targetElement)) {
135
102
  let root = document.scrollingElement || document.documentElement;
136
103
  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()) {
104
+ // 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
105
+ if (!isScrollPrevented) {
140
106
  let {left: originalLeft, top: originalTop} = targetElement.getBoundingClientRect();
141
107
 
142
108
  // use scrollIntoView({block: 'nearest'}) instead of .focus to check if the element is fully in view or not since .focus()
@@ -151,6 +117,9 @@ export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollI
151
117
  } else {
152
118
  let scrollParents = getScrollParents(targetElement);
153
119
  // 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.
120
+ if (!isScrollPrevented) {
121
+ scrollParents.push(root);
122
+ }
154
123
  for (let scrollParent of scrollParents) {
155
124
  scrollIntoView(scrollParent as HTMLElement, targetElement as HTMLElement);
156
125
  }
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
  }
@@ -10,8 +10,8 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {Dispatch, MutableRefObject, useRef, useState} from 'react';
14
- import {useEffectEvent, useLayoutEffect} from './';
13
+ import {Dispatch, RefObject, useCallback, useRef, useState} from 'react';
14
+ import {useLayoutEffect} from './';
15
15
 
16
16
  type SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;
17
17
 
@@ -21,11 +21,14 @@ type SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;
21
21
  // written linearly.
22
22
  export function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>] {
23
23
  let [value, setValue] = useState(defaultValue);
24
- let effect: MutableRefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);
24
+ // Keep an up to date copy of value in a ref so we can access the current value in the generator.
25
+ // This allows us to maintain a stable queue function.
26
+ let currValue = useRef(value);
27
+ let effect: RefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);
25
28
 
26
29
  // Store the function in a ref so we can always access the current version
27
30
  // which has the proper `value` in scope.
28
- let nextRef = useEffectEvent(() => {
31
+ let nextRef = useRef(() => {
29
32
  if (!effect.current) {
30
33
  return;
31
34
  }
@@ -41,24 +44,25 @@ export function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<Set
41
44
  // If the value is the same as the current value,
42
45
  // then continue to the next yield. Otherwise,
43
46
  // set the value in state and wait for the next layout effect.
44
- if (value === newValue.value) {
45
- nextRef();
47
+ if (currValue.current === newValue.value) {
48
+ nextRef.current();
46
49
  } else {
47
50
  setValue(newValue.value);
48
51
  }
49
52
  });
50
53
 
51
54
  useLayoutEffect(() => {
55
+ currValue.current = value;
52
56
  // If there is an effect currently running, continue to the next yield.
53
57
  if (effect.current) {
54
- nextRef();
58
+ nextRef.current();
55
59
  }
56
60
  });
57
61
 
58
- let queue = useEffectEvent(fn => {
59
- effect.current = fn(value);
60
- nextRef();
61
- });
62
+ let queue = useCallback(fn => {
63
+ effect.current = fn(currValue.current);
64
+ nextRef.current();
65
+ }, [nextRef]);
62
66
 
63
67
  return [value, queue];
64
68
  }