@react-aria/utils 3.15.0 → 3.17.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.
package/dist/import.mjs CHANGED
@@ -55,34 +55,45 @@ function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
55
55
  let [value, setValue] = (0, $12uGp$useState)(defaultValue);
56
56
  let valueRef = (0, $12uGp$useRef)(value);
57
57
  let effect = (0, $12uGp$useRef)(null);
58
- valueRef.current = value;
59
- // Store the function in a ref so we can always access the current version
60
- // which has the proper `value` in scope.
61
- let nextRef = (0, $12uGp$useRef)(null);
62
- nextRef.current = ()=>{
58
+ // Must be stable so that `queue` is stable.
59
+ let nextIter = (0, $12uGp$useCallback)(()=>{
63
60
  // Run the generator to the next yield.
64
61
  let newValue = effect.current.next();
62
+ while(!newValue.done && valueRef.current === newValue.value)// If the value is the same as the current value,
63
+ // then continue to the next yield. Otherwise,
64
+ // set the value in state and wait for the next layout effect.
65
+ newValue = effect.current.next();
65
66
  // If the generator is done, reset the effect.
66
67
  if (newValue.done) {
67
68
  effect.current = null;
68
69
  return;
69
70
  }
70
- // If the value is the same as the current value,
71
- // then continue to the next yield. Otherwise,
72
- // set the value in state and wait for the next layout effect.
73
- if (value === newValue.value) nextRef.current();
74
- else setValue(newValue.value);
75
- };
71
+ // Always update valueRef when setting the state.
72
+ // This is needed because the function is not regenerated with the new state value since
73
+ // they must be stable across renders. Instead, it gets carried in the ref, but the setState
74
+ // is also needed in order to cause a rerender.
75
+ setValue(newValue.value);
76
+ valueRef.current = newValue.value;
77
+ // this list of dependencies is stable, setState and refs never change after first render.
78
+ }, [
79
+ setValue,
80
+ valueRef,
81
+ effect
82
+ ]);
76
83
  (0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
77
84
  // If there is an effect currently running, continue to the next yield.
78
- if (effect.current) nextRef.current();
85
+ if (effect.current) nextIter();
79
86
  });
87
+ // queue must be a stable function, much like setState.
80
88
  let queue = (0, $12uGp$useCallback)((fn)=>{
81
89
  effect.current = fn(valueRef.current);
82
- nextRef.current();
90
+ nextIter();
91
+ // this list of dependencies is stable, setState and refs never change after first render.
92
+ // in addition, nextIter is stable as outlined above
83
93
  }, [
94
+ nextIter,
84
95
  effect,
85
- nextRef
96
+ valueRef
86
97
  ]);
87
98
  return [
88
99
  value,
@@ -220,6 +231,7 @@ function $3ef42575df84b30b$export$9d1611c77c2fe928(...args) {
220
231
  * OF ANY KIND, either express or implied. See the License for the specific language
221
232
  * governing permissions and limitations under the License.
222
233
  */ function $5dc95899b306f630$export$c9058316764c140e(...refs) {
234
+ if (refs.length === 1) return refs[0];
223
235
  return (value)=>{
224
236
  for (let ref of refs){
225
237
  if (typeof ref === "function") ref(value);
@@ -647,6 +659,10 @@ function $df56164dff5785e2$export$4338b53315abf666(forwardedRef) {
647
659
  if (!forwardedRef) return;
648
660
  if (typeof forwardedRef === "function") forwardedRef(objRef.current);
649
661
  else forwardedRef.current = objRef.current;
662
+ return ()=>{
663
+ if (typeof forwardedRef === "function") forwardedRef(null);
664
+ else forwardedRef.current = null;
665
+ };
650
666
  }, [
651
667
  forwardedRef
652
668
  ]);
@@ -1045,7 +1061,33 @@ function $6a7db85432448f7f$export$29bf1b5f2c56cf63(event) {
1045
1061
  }
1046
1062
 
1047
1063
 
1064
+ /*
1065
+ * Copyright 2023 Adobe. All rights reserved.
1066
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1067
+ * you may not use this file except in compliance with the License. You may obtain a copy
1068
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1069
+ *
1070
+ * Unless required by applicable law or agreed to in writing, software distributed under
1071
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1072
+ * OF ANY KIND, either express or implied. See the License for the specific language
1073
+ * governing permissions and limitations under the License.
1074
+ */
1075
+
1076
+ function $8ae05eaa5c114e9c$export$7f54fc3180508a52(fn) {
1077
+ const ref = (0, $12uGp$useRef)(null);
1078
+ (0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
1079
+ ref.current = fn;
1080
+ }, [
1081
+ fn
1082
+ ]);
1083
+ return (0, $12uGp$useCallback)((...args)=>{
1084
+ const f = ref.current;
1085
+ return f(...args);
1086
+ }, []);
1087
+ }
1088
+
1089
+
1048
1090
 
1049
1091
 
1050
- export {$bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId, $ff5963eb1fccf552$export$e08e3b67e392101e as chain, $3ef42575df84b30b$export$9d1611c77c2fe928 as mergeProps, $5dc95899b306f630$export$c9058316764c140e as mergeRefs, $65484d02dcb7eb3e$export$457c3d6518dd4c6f as filterDOMProps, $7215afc6de606d6b$export$de79e2c695e052f3 as focusWithoutScrolling, $ab71dadb03a6fb2e$export$622cea445a1c5b7d as getOffset, $bbed8b41f857bcc0$export$24490316f764c430 as runAfterTransition, $9cc09df9fd7676be$export$7bbed75feba39706 as useDrag1D, $03deb23ff14920c4$export$4eaf04e54aa8eed6 as useGlobalListeners, $313b98861ee5dd6c$export$d6875122194c7b44 as useLabels, $df56164dff5785e2$export$4338b53315abf666 as useObjectRef, $4f58c5f72bcf79f7$export$496315a1608d9602 as useUpdateEffect, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c as useLayoutEffect, $9daab02d461809db$export$683480f191c0e3ea as useResizeObserver, $e7801be82b4b2a53$export$4debdb1a3f0fa79e as useSyncRef, $62d8ded9296f3872$export$cfa2225e87938781 as getScrollParent, $62d8ded9296f3872$export$2bb74740c4e19def as isScrollable, $5df64b3807dc15ee$export$d699905dd57c73ca as useViewportSize, $ef06256079686ba0$export$f8aeda7b10753fa1 as useDescription, $c87311424ea30a05$export$9ac100e40613ea10 as isMac, $c87311424ea30a05$export$186c6964ca17d99 as isIPhone, $c87311424ea30a05$export$7bef049ce92e4224 as isIPad, $c87311424ea30a05$export$fedb369cb70207f1 as isIOS, $c87311424ea30a05$export$e1865c3bedcd822b as isAppleDevice, $c87311424ea30a05$export$78551043582a6a98 as isWebKit, $c87311424ea30a05$export$6446a186d09e379e as isChrome, $c87311424ea30a05$export$a11b0059900ceec8 as isAndroid, $e9faafb641e167db$export$90fc3a17d93f704c as useEvent, $1dbecbe27a04f9af$export$14d238f342723f25 as useValueEffect, $2f04cbc44ee30ce0$export$53a0910f038337bd as scrollIntoView, $2f04cbc44ee30ce0$export$c826860796309d1b as scrollIntoViewport, $4507461a1b870123$re_export$clamp as clamp, $4507461a1b870123$re_export$snapValueToStep as snapValueToStep, $6a7db85432448f7f$export$60278871457622de as isVirtualClick, $6a7db85432448f7f$export$29bf1b5f2c56cf63 as isVirtualPointerEvent};
1092
+ export {$bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId, $ff5963eb1fccf552$export$e08e3b67e392101e as chain, $3ef42575df84b30b$export$9d1611c77c2fe928 as mergeProps, $5dc95899b306f630$export$c9058316764c140e as mergeRefs, $65484d02dcb7eb3e$export$457c3d6518dd4c6f as filterDOMProps, $7215afc6de606d6b$export$de79e2c695e052f3 as focusWithoutScrolling, $ab71dadb03a6fb2e$export$622cea445a1c5b7d as getOffset, $bbed8b41f857bcc0$export$24490316f764c430 as runAfterTransition, $9cc09df9fd7676be$export$7bbed75feba39706 as useDrag1D, $03deb23ff14920c4$export$4eaf04e54aa8eed6 as useGlobalListeners, $313b98861ee5dd6c$export$d6875122194c7b44 as useLabels, $df56164dff5785e2$export$4338b53315abf666 as useObjectRef, $4f58c5f72bcf79f7$export$496315a1608d9602 as useUpdateEffect, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c as useLayoutEffect, $9daab02d461809db$export$683480f191c0e3ea as useResizeObserver, $e7801be82b4b2a53$export$4debdb1a3f0fa79e as useSyncRef, $62d8ded9296f3872$export$cfa2225e87938781 as getScrollParent, $62d8ded9296f3872$export$2bb74740c4e19def as isScrollable, $5df64b3807dc15ee$export$d699905dd57c73ca as useViewportSize, $ef06256079686ba0$export$f8aeda7b10753fa1 as useDescription, $c87311424ea30a05$export$9ac100e40613ea10 as isMac, $c87311424ea30a05$export$186c6964ca17d99 as isIPhone, $c87311424ea30a05$export$7bef049ce92e4224 as isIPad, $c87311424ea30a05$export$fedb369cb70207f1 as isIOS, $c87311424ea30a05$export$e1865c3bedcd822b as isAppleDevice, $c87311424ea30a05$export$78551043582a6a98 as isWebKit, $c87311424ea30a05$export$6446a186d09e379e as isChrome, $c87311424ea30a05$export$a11b0059900ceec8 as isAndroid, $e9faafb641e167db$export$90fc3a17d93f704c as useEvent, $1dbecbe27a04f9af$export$14d238f342723f25 as useValueEffect, $2f04cbc44ee30ce0$export$53a0910f038337bd as scrollIntoView, $2f04cbc44ee30ce0$export$c826860796309d1b as scrollIntoViewport, $4507461a1b870123$re_export$clamp as clamp, $4507461a1b870123$re_export$snapValueToStep as snapValueToStep, $6a7db85432448f7f$export$60278871457622de as isVirtualClick, $6a7db85432448f7f$export$29bf1b5f2c56cf63 as isVirtualPointerEvent, $8ae05eaa5c114e9c$export$7f54fc3180508a52 as useEffectEvent};
1051
1093
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -48,6 +48,7 @@ $parcel$export(module.exports, "clamp", () => $1Yh1N$reactstatelyutils.clamp);
48
48
  $parcel$export(module.exports, "snapValueToStep", () => $1Yh1N$reactstatelyutils.snapValueToStep);
49
49
  $parcel$export(module.exports, "isVirtualClick", () => $577e795361f19be9$export$60278871457622de);
50
50
  $parcel$export(module.exports, "isVirtualPointerEvent", () => $577e795361f19be9$export$29bf1b5f2c56cf63);
51
+ $parcel$export(module.exports, "useEffectEvent", () => $1254e5bb94ac8761$export$7f54fc3180508a52);
51
52
  /*
52
53
  * Copyright 2020 Adobe. All rights reserved.
53
54
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -100,34 +101,45 @@ function $19a2307bfabafaf1$export$14d238f342723f25(defaultValue) {
100
101
  let [value, setValue] = (0, $1Yh1N$react.useState)(defaultValue);
101
102
  let valueRef = (0, $1Yh1N$react.useRef)(value);
102
103
  let effect = (0, $1Yh1N$react.useRef)(null);
103
- valueRef.current = value;
104
- // Store the function in a ref so we can always access the current version
105
- // which has the proper `value` in scope.
106
- let nextRef = (0, $1Yh1N$react.useRef)(null);
107
- nextRef.current = ()=>{
104
+ // Must be stable so that `queue` is stable.
105
+ let nextIter = (0, $1Yh1N$react.useCallback)(()=>{
108
106
  // Run the generator to the next yield.
109
107
  let newValue = effect.current.next();
108
+ while(!newValue.done && valueRef.current === newValue.value)// If the value is the same as the current value,
109
+ // then continue to the next yield. Otherwise,
110
+ // set the value in state and wait for the next layout effect.
111
+ newValue = effect.current.next();
110
112
  // If the generator is done, reset the effect.
111
113
  if (newValue.done) {
112
114
  effect.current = null;
113
115
  return;
114
116
  }
115
- // If the value is the same as the current value,
116
- // then continue to the next yield. Otherwise,
117
- // set the value in state and wait for the next layout effect.
118
- if (value === newValue.value) nextRef.current();
119
- else setValue(newValue.value);
120
- };
117
+ // Always update valueRef when setting the state.
118
+ // This is needed because the function is not regenerated with the new state value since
119
+ // they must be stable across renders. Instead, it gets carried in the ref, but the setState
120
+ // is also needed in order to cause a rerender.
121
+ setValue(newValue.value);
122
+ valueRef.current = newValue.value;
123
+ // this list of dependencies is stable, setState and refs never change after first render.
124
+ }, [
125
+ setValue,
126
+ valueRef,
127
+ effect
128
+ ]);
121
129
  (0, $78605a5d7424e31b$export$e5c5a5f917a5871c)(()=>{
122
130
  // If there is an effect currently running, continue to the next yield.
123
- if (effect.current) nextRef.current();
131
+ if (effect.current) nextIter();
124
132
  });
133
+ // queue must be a stable function, much like setState.
125
134
  let queue = (0, $1Yh1N$react.useCallback)((fn)=>{
126
135
  effect.current = fn(valueRef.current);
127
- nextRef.current();
136
+ nextIter();
137
+ // this list of dependencies is stable, setState and refs never change after first render.
138
+ // in addition, nextIter is stable as outlined above
128
139
  }, [
140
+ nextIter,
129
141
  effect,
130
- nextRef
142
+ valueRef
131
143
  ]);
132
144
  return [
133
145
  value,
@@ -265,6 +277,7 @@ function $f847cd1382ea7cd4$export$9d1611c77c2fe928(...args) {
265
277
  * OF ANY KIND, either express or implied. See the License for the specific language
266
278
  * governing permissions and limitations under the License.
267
279
  */ function $f05dc24eafaeb7e2$export$c9058316764c140e(...refs) {
280
+ if (refs.length === 1) return refs[0];
268
281
  return (value)=>{
269
282
  for (let ref of refs){
270
283
  if (typeof ref === "function") ref(value);
@@ -692,6 +705,10 @@ function $475b35fe72ba49b3$export$4338b53315abf666(forwardedRef) {
692
705
  if (!forwardedRef) return;
693
706
  if (typeof forwardedRef === "function") forwardedRef(objRef.current);
694
707
  else forwardedRef.current = objRef.current;
708
+ return ()=>{
709
+ if (typeof forwardedRef === "function") forwardedRef(null);
710
+ else forwardedRef.current = null;
711
+ };
695
712
  }, [
696
713
  forwardedRef
697
714
  ]);
@@ -1090,6 +1107,32 @@ function $577e795361f19be9$export$29bf1b5f2c56cf63(event) {
1090
1107
  }
1091
1108
 
1092
1109
 
1110
+ /*
1111
+ * Copyright 2023 Adobe. All rights reserved.
1112
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1113
+ * you may not use this file except in compliance with the License. You may obtain a copy
1114
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1115
+ *
1116
+ * Unless required by applicable law or agreed to in writing, software distributed under
1117
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1118
+ * OF ANY KIND, either express or implied. See the License for the specific language
1119
+ * governing permissions and limitations under the License.
1120
+ */
1121
+
1122
+ function $1254e5bb94ac8761$export$7f54fc3180508a52(fn) {
1123
+ const ref = (0, $1Yh1N$react.useRef)(null);
1124
+ (0, $78605a5d7424e31b$export$e5c5a5f917a5871c)(()=>{
1125
+ ref.current = fn;
1126
+ }, [
1127
+ fn
1128
+ ]);
1129
+ return (0, $1Yh1N$react.useCallback)((...args)=>{
1130
+ const f = ref.current;
1131
+ return f(...args);
1132
+ }, []);
1133
+ }
1134
+
1135
+
1093
1136
 
1094
1137
 
1095
1138
  //# sourceMappingURL=main.js.map