@react-aria/utils 3.26.0 → 3.28.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/DOMFunctions.main.js +44 -0
- package/dist/DOMFunctions.main.js.map +1 -0
- package/dist/DOMFunctions.mjs +37 -0
- package/dist/DOMFunctions.module.js +37 -0
- package/dist/DOMFunctions.module.js.map +1 -0
- package/dist/ShadowTreeWalker.main.js +200 -0
- package/dist/ShadowTreeWalker.main.js.map +1 -0
- package/dist/ShadowTreeWalker.mjs +194 -0
- package/dist/ShadowTreeWalker.module.js +194 -0
- package/dist/ShadowTreeWalker.module.js.map +1 -0
- package/dist/animation.main.js +97 -0
- package/dist/animation.main.js.map +1 -0
- package/dist/animation.mjs +91 -0
- package/dist/animation.module.js +91 -0
- package/dist/animation.module.js.map +1 -0
- package/dist/constants.main.js +23 -0
- package/dist/constants.main.js.map +1 -0
- package/dist/constants.mjs +17 -0
- package/dist/constants.module.js +17 -0
- package/dist/constants.module.js.map +1 -0
- package/dist/domHelpers.main.js +9 -0
- package/dist/domHelpers.main.js.map +1 -1
- package/dist/domHelpers.mjs +9 -1
- package/dist/domHelpers.module.js +9 -1
- package/dist/domHelpers.module.js.map +1 -1
- package/dist/import.mjs +18 -2
- package/dist/inertValue.main.js +19 -0
- package/dist/inertValue.main.js.map +1 -0
- package/dist/inertValue.mjs +14 -0
- package/dist/inertValue.module.js +14 -0
- package/dist/inertValue.module.js.map +1 -0
- package/dist/isFocusable.main.js +34 -0
- package/dist/isFocusable.main.js.map +1 -0
- package/dist/isFocusable.mjs +28 -0
- package/dist/isFocusable.module.js +28 -0
- package/dist/isFocusable.module.js.map +1 -0
- package/dist/keyboard.main.js +26 -0
- package/dist/keyboard.main.js.map +1 -0
- package/dist/keyboard.mjs +21 -0
- package/dist/keyboard.module.js +21 -0
- package/dist/keyboard.module.js.map +1 -0
- package/dist/main.js +31 -0
- package/dist/main.js.map +1 -1
- package/dist/mergeProps.main.js.map +1 -1
- package/dist/mergeProps.module.js.map +1 -1
- package/dist/module.js +18 -2
- package/dist/module.js.map +1 -1
- package/dist/scrollIntoView.main.js +14 -8
- package/dist/scrollIntoView.main.js.map +1 -1
- package/dist/scrollIntoView.mjs +14 -8
- package/dist/scrollIntoView.module.js +14 -8
- package/dist/scrollIntoView.module.js.map +1 -1
- package/dist/types.d.ts +61 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useGlobalListeners.main.js +1 -1
- package/dist/useGlobalListeners.main.js.map +1 -1
- package/dist/useGlobalListeners.mjs +1 -1
- package/dist/useGlobalListeners.module.js +1 -1
- package/dist/useGlobalListeners.module.js.map +1 -1
- package/dist/useId.main.js +26 -21
- package/dist/useId.main.js.map +1 -1
- package/dist/useId.mjs +28 -23
- package/dist/useId.module.js +28 -23
- package/dist/useId.module.js.map +1 -1
- package/dist/useUpdateEffect.main.js +2 -1
- package/dist/useUpdateEffect.main.js.map +1 -1
- package/dist/useUpdateEffect.mjs +2 -1
- package/dist/useUpdateEffect.module.js +2 -1
- package/dist/useUpdateEffect.module.js.map +1 -1
- package/dist/useUpdateLayoutEffect.main.js +40 -0
- package/dist/useUpdateLayoutEffect.main.js.map +1 -0
- package/dist/useUpdateLayoutEffect.mjs +35 -0
- package/dist/useUpdateLayoutEffect.module.js +35 -0
- package/dist/useUpdateLayoutEffect.module.js.map +1 -0
- package/package.json +6 -4
- package/src/animation.ts +103 -0
- package/src/constants.ts +15 -0
- package/src/domHelpers.ts +19 -0
- package/src/index.ts +9 -1
- package/src/inertValue.ts +11 -0
- package/src/isFocusable.ts +28 -0
- package/src/keyboard.tsx +27 -0
- package/src/mergeProps.ts +1 -1
- package/src/scrollIntoView.ts +28 -12
- package/src/shadowdom/DOMFunctions.ts +70 -0
- package/src/shadowdom/ShadowTreeWalker.ts +319 -0
- package/src/useGlobalListeners.ts +2 -1
- package/src/useId.ts +24 -15
- package/src/useUpdateEffect.ts +3 -2
- package/src/useUpdateLayoutEffect.ts +37 -0
package/dist/useId.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.mjs";
|
|
2
2
|
import {useValueEffect as $1dbecbe27a04f9af$export$14d238f342723f25} from "./useValueEffect.mjs";
|
|
3
|
-
import {useState as $eKkEp$useState, useRef as $eKkEp$useRef,
|
|
3
|
+
import {useState as $eKkEp$useState, useRef as $eKkEp$useRef, useEffect as $eKkEp$useEffect, useCallback as $eKkEp$useCallback} from "react";
|
|
4
4
|
import {useSSRSafeId as $eKkEp$useSSRSafeId} from "@react-aria/ssr";
|
|
5
5
|
|
|
6
6
|
/*
|
|
@@ -19,53 +19,58 @@ import {useSSRSafeId as $eKkEp$useSSRSafeId} from "@react-aria/ssr";
|
|
|
19
19
|
|
|
20
20
|
// copied from SSRProvider.tsx to reduce exports, if needed again, consider sharing
|
|
21
21
|
let $bdb11010cef70236$var$canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
22
|
-
let $bdb11010cef70236$
|
|
22
|
+
let $bdb11010cef70236$export$d41a04c74483c6ef = new Map();
|
|
23
|
+
// This allows us to clean up the idsUpdaterMap when the id is no longer used.
|
|
24
|
+
// Map is a strong reference, so unused ids wouldn't be cleaned up otherwise.
|
|
25
|
+
// This can happen in suspended components where mount/unmount is not called.
|
|
26
|
+
let $bdb11010cef70236$var$registry = new FinalizationRegistry((heldValue)=>{
|
|
27
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(heldValue);
|
|
28
|
+
});
|
|
23
29
|
function $bdb11010cef70236$export$f680877a34711e37(defaultId) {
|
|
24
30
|
let [value, setValue] = (0, $eKkEp$useState)(defaultId);
|
|
25
31
|
let nextId = (0, $eKkEp$useRef)(null);
|
|
26
32
|
let res = (0, $eKkEp$useSSRSafeId)(value);
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
}, []);
|
|
33
|
+
let cleanupRef = (0, $eKkEp$useRef)(null);
|
|
34
|
+
$bdb11010cef70236$var$registry.register(cleanupRef, res);
|
|
30
35
|
if ($bdb11010cef70236$var$canUseDOM) {
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]);
|
|
36
|
-
else $bdb11010cef70236$var$idsUpdaterMap.set(res, [
|
|
37
|
-
updateValue
|
|
36
|
+
const cacheIdRef = $bdb11010cef70236$export$d41a04c74483c6ef.get(res);
|
|
37
|
+
if (cacheIdRef && !cacheIdRef.includes(nextId)) cacheIdRef.push(nextId);
|
|
38
|
+
else $bdb11010cef70236$export$d41a04c74483c6ef.set(res, [
|
|
39
|
+
nextId
|
|
38
40
|
]);
|
|
39
41
|
}
|
|
40
42
|
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
41
43
|
let r = res;
|
|
42
44
|
return ()=>{
|
|
43
|
-
|
|
45
|
+
// In Suspense, the cleanup function may be not called
|
|
46
|
+
// when it is though, also remove it from the finalization registry.
|
|
47
|
+
$bdb11010cef70236$var$registry.unregister(cleanupRef);
|
|
48
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(r);
|
|
44
49
|
};
|
|
45
50
|
}, [
|
|
46
51
|
res
|
|
47
52
|
]);
|
|
48
|
-
// This cannot cause an infinite loop because the ref is
|
|
53
|
+
// This cannot cause an infinite loop because the ref is always cleaned up.
|
|
49
54
|
// eslint-disable-next-line
|
|
50
55
|
(0, $eKkEp$useEffect)(()=>{
|
|
51
56
|
let newId = nextId.current;
|
|
52
|
-
if (newId)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
57
|
+
if (newId) setValue(newId);
|
|
58
|
+
return ()=>{
|
|
59
|
+
if (newId) nextId.current = null;
|
|
60
|
+
};
|
|
56
61
|
});
|
|
57
62
|
return res;
|
|
58
63
|
}
|
|
59
64
|
function $bdb11010cef70236$export$cd8c9cb68f842629(idA, idB) {
|
|
60
65
|
if (idA === idB) return idA;
|
|
61
|
-
let setIdsA = $bdb11010cef70236$
|
|
66
|
+
let setIdsA = $bdb11010cef70236$export$d41a04c74483c6ef.get(idA);
|
|
62
67
|
if (setIdsA) {
|
|
63
|
-
setIdsA.forEach((
|
|
68
|
+
setIdsA.forEach((ref)=>ref.current = idB);
|
|
64
69
|
return idB;
|
|
65
70
|
}
|
|
66
|
-
let setIdsB = $bdb11010cef70236$
|
|
71
|
+
let setIdsB = $bdb11010cef70236$export$d41a04c74483c6ef.get(idB);
|
|
67
72
|
if (setIdsB) {
|
|
68
|
-
setIdsB.forEach((
|
|
73
|
+
setIdsB.forEach((ref)=>ref.current = idA);
|
|
69
74
|
return idA;
|
|
70
75
|
}
|
|
71
76
|
return idB;
|
|
@@ -91,5 +96,5 @@ function $bdb11010cef70236$export$b4cc09c592e8fdb8(depArray = []) {
|
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
|
|
94
|
-
export {$bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
99
|
+
export {$bdb11010cef70236$export$d41a04c74483c6ef as idsUpdaterMap, $bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
95
100
|
//# sourceMappingURL=useId.module.js.map
|
package/dist/useId.module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.module.js";
|
|
2
2
|
import {useValueEffect as $1dbecbe27a04f9af$export$14d238f342723f25} from "./useValueEffect.module.js";
|
|
3
|
-
import {useState as $eKkEp$useState, useRef as $eKkEp$useRef,
|
|
3
|
+
import {useState as $eKkEp$useState, useRef as $eKkEp$useRef, useEffect as $eKkEp$useEffect, useCallback as $eKkEp$useCallback} from "react";
|
|
4
4
|
import {useSSRSafeId as $eKkEp$useSSRSafeId} from "@react-aria/ssr";
|
|
5
5
|
|
|
6
6
|
/*
|
|
@@ -19,53 +19,58 @@ import {useSSRSafeId as $eKkEp$useSSRSafeId} from "@react-aria/ssr";
|
|
|
19
19
|
|
|
20
20
|
// copied from SSRProvider.tsx to reduce exports, if needed again, consider sharing
|
|
21
21
|
let $bdb11010cef70236$var$canUseDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
22
|
-
let $bdb11010cef70236$
|
|
22
|
+
let $bdb11010cef70236$export$d41a04c74483c6ef = new Map();
|
|
23
|
+
// This allows us to clean up the idsUpdaterMap when the id is no longer used.
|
|
24
|
+
// Map is a strong reference, so unused ids wouldn't be cleaned up otherwise.
|
|
25
|
+
// This can happen in suspended components where mount/unmount is not called.
|
|
26
|
+
let $bdb11010cef70236$var$registry = new FinalizationRegistry((heldValue)=>{
|
|
27
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(heldValue);
|
|
28
|
+
});
|
|
23
29
|
function $bdb11010cef70236$export$f680877a34711e37(defaultId) {
|
|
24
30
|
let [value, setValue] = (0, $eKkEp$useState)(defaultId);
|
|
25
31
|
let nextId = (0, $eKkEp$useRef)(null);
|
|
26
32
|
let res = (0, $eKkEp$useSSRSafeId)(value);
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
}, []);
|
|
33
|
+
let cleanupRef = (0, $eKkEp$useRef)(null);
|
|
34
|
+
$bdb11010cef70236$var$registry.register(cleanupRef, res);
|
|
30
35
|
if ($bdb11010cef70236$var$canUseDOM) {
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]);
|
|
36
|
-
else $bdb11010cef70236$var$idsUpdaterMap.set(res, [
|
|
37
|
-
updateValue
|
|
36
|
+
const cacheIdRef = $bdb11010cef70236$export$d41a04c74483c6ef.get(res);
|
|
37
|
+
if (cacheIdRef && !cacheIdRef.includes(nextId)) cacheIdRef.push(nextId);
|
|
38
|
+
else $bdb11010cef70236$export$d41a04c74483c6ef.set(res, [
|
|
39
|
+
nextId
|
|
38
40
|
]);
|
|
39
41
|
}
|
|
40
42
|
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
41
43
|
let r = res;
|
|
42
44
|
return ()=>{
|
|
43
|
-
|
|
45
|
+
// In Suspense, the cleanup function may be not called
|
|
46
|
+
// when it is though, also remove it from the finalization registry.
|
|
47
|
+
$bdb11010cef70236$var$registry.unregister(cleanupRef);
|
|
48
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(r);
|
|
44
49
|
};
|
|
45
50
|
}, [
|
|
46
51
|
res
|
|
47
52
|
]);
|
|
48
|
-
// This cannot cause an infinite loop because the ref is
|
|
53
|
+
// This cannot cause an infinite loop because the ref is always cleaned up.
|
|
49
54
|
// eslint-disable-next-line
|
|
50
55
|
(0, $eKkEp$useEffect)(()=>{
|
|
51
56
|
let newId = nextId.current;
|
|
52
|
-
if (newId)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
57
|
+
if (newId) setValue(newId);
|
|
58
|
+
return ()=>{
|
|
59
|
+
if (newId) nextId.current = null;
|
|
60
|
+
};
|
|
56
61
|
});
|
|
57
62
|
return res;
|
|
58
63
|
}
|
|
59
64
|
function $bdb11010cef70236$export$cd8c9cb68f842629(idA, idB) {
|
|
60
65
|
if (idA === idB) return idA;
|
|
61
|
-
let setIdsA = $bdb11010cef70236$
|
|
66
|
+
let setIdsA = $bdb11010cef70236$export$d41a04c74483c6ef.get(idA);
|
|
62
67
|
if (setIdsA) {
|
|
63
|
-
setIdsA.forEach((
|
|
68
|
+
setIdsA.forEach((ref)=>ref.current = idB);
|
|
64
69
|
return idB;
|
|
65
70
|
}
|
|
66
|
-
let setIdsB = $bdb11010cef70236$
|
|
71
|
+
let setIdsB = $bdb11010cef70236$export$d41a04c74483c6ef.get(idB);
|
|
67
72
|
if (setIdsB) {
|
|
68
|
-
setIdsB.forEach((
|
|
73
|
+
setIdsB.forEach((ref)=>ref.current = idA);
|
|
69
74
|
return idA;
|
|
70
75
|
}
|
|
71
76
|
return idB;
|
|
@@ -91,5 +96,5 @@ function $bdb11010cef70236$export$b4cc09c592e8fdb8(depArray = []) {
|
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
|
|
94
|
-
export {$bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
99
|
+
export {$bdb11010cef70236$export$d41a04c74483c6ef as idsUpdaterMap, $bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
95
100
|
//# sourceMappingURL=useId.module.js.map
|
package/dist/useId.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAOD,mFAAmF;AACnF,IAAI,kCAAY,QACd,OAAO,WAAW,eAClB,OAAO,QAAQ,IACf,OAAO,QAAQ,CAAC,aAAa;
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAOD,mFAAmF;AACnF,IAAI,kCAAY,QACd,OAAO,WAAW,eAClB,OAAO,QAAQ,IACf,OAAO,QAAQ,CAAC,aAAa;AAGxB,IAAI,4CAA2D,IAAI;AAC1E,8EAA8E;AAC9E,6EAA6E;AAC7E,6EAA6E;AAC7E,IAAI,iCAAW,IAAI,qBAA6B,CAAC;IAC/C,0CAAc,MAAM,CAAC;AACvB;AAMO,SAAS,0CAAM,SAAkB;IACtC,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;IACjC,IAAI,SAAS,CAAA,GAAA,aAAK,EAAE;IAEpB,IAAI,MAAM,CAAA,GAAA,mBAAW,EAAE;IACvB,IAAI,aAAa,CAAA,GAAA,aAAK,EAAE;IAExB,+BAAS,QAAQ,CAAC,YAAY;IAE9B,IAAI,iCAAW;QACb,MAAM,aAAa,0CAAc,GAAG,CAAC;QACrC,IAAI,cAAc,CAAC,WAAW,QAAQ,CAAC,SACrC,WAAW,IAAI,CAAC;aAEhB,0CAAc,GAAG,CAAC,KAAK;YAAC;SAAO;IAEnC;IAEA,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,IAAI;QACR,OAAO;YACL,sDAAsD;YACtD,oEAAoE;YACpE,+BAAS,UAAU,CAAC;YACpB,0CAAc,MAAM,CAAC;QACvB;IACF,GAAG;QAAC;KAAI;IAER,2EAA2E;IAC3E,2BAA2B;IAC3B,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,QAAQ,OAAO,OAAO;QAC1B,IAAI,OAAS,SAAS;QAEtB,OAAO;YACL,IAAI,OAAS,OAAO,OAAO,GAAG;QAChC;IACF;IAEA,OAAO;AACT;AAMO,SAAS,0CAAS,GAAW,EAAE,GAAW;IAC/C,IAAI,QAAQ,KACV,OAAO;IAGT,IAAI,UAAU,0CAAc,GAAG,CAAC;IAChC,IAAI,SAAS;QACX,QAAQ,OAAO,CAAC,CAAA,MAAQ,IAAI,OAAO,GAAG;QACtC,OAAO;IACT;IAEA,IAAI,UAAU,0CAAc,GAAG,CAAC;IAChC,IAAI,SAAS;QACX,QAAQ,OAAO,CAAC,CAAC,MAAS,IAAI,OAAO,GAAG;QACxC,OAAO;IACT;IAEA,OAAO;AACT;AAOO,SAAS,0CAAU,WAA+B,EAAE;IACzD,IAAI,KAAK;IACT,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,yCAAa,EAAE;IACjD,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QACzB,cAAc;YACZ,MAAM;YAEN,MAAM,SAAS,cAAc,CAAC,MAAM,KAAK;QAC3C;IACF,GAAG;QAAC;QAAI;KAAc;IAEtB,CAAA,GAAA,yCAAc,EAAE,UAAU;QAAC;QAAI;WAAa;KAAS;IAErD,OAAO;AACT","sources":["packages/@react-aria/utils/src/useId.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 {useCallback, useEffect, useRef, useState} from 'react';\nimport {useLayoutEffect} from './useLayoutEffect';\nimport {useSSRSafeId} from '@react-aria/ssr';\nimport {useValueEffect} from './';\n\n// copied from SSRProvider.tsx to reduce exports, if needed again, consider sharing\nlet canUseDOM = Boolean(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n);\n\nexport let idsUpdaterMap: Map<string, { current: string | null }[]> = new Map();\n// This allows us to clean up the idsUpdaterMap when the id is no longer used.\n// Map is a strong reference, so unused ids wouldn't be cleaned up otherwise.\n// This can happen in suspended components where mount/unmount is not called.\nlet registry = new FinalizationRegistry<string>((heldValue) => {\n idsUpdaterMap.delete(heldValue);\n});\n\n/**\n * If a default is not provided, generate an id.\n * @param defaultId - Default component id.\n */\nexport function useId(defaultId?: string): string {\n let [value, setValue] = useState(defaultId);\n let nextId = useRef(null);\n\n let res = useSSRSafeId(value);\n let cleanupRef = useRef(null);\n\n registry.register(cleanupRef, res);\n\n if (canUseDOM) {\n const cacheIdRef = idsUpdaterMap.get(res);\n if (cacheIdRef && !cacheIdRef.includes(nextId)) {\n cacheIdRef.push(nextId);\n } else {\n idsUpdaterMap.set(res, [nextId]);\n }\n }\n\n useLayoutEffect(() => {\n let r = res;\n return () => {\n // In Suspense, the cleanup function may be not called\n // when it is though, also remove it from the finalization registry.\n registry.unregister(cleanupRef);\n idsUpdaterMap.delete(r);\n };\n }, [res]);\n\n // This cannot cause an infinite loop because the ref is always cleaned up.\n // eslint-disable-next-line\n useEffect(() => {\n let newId = nextId.current;\n if (newId) { setValue(newId); }\n\n return () => {\n if (newId) { nextId.current = null; }\n };\n });\n\n return res;\n}\n\n/**\n * Merges two ids.\n * Different ids will trigger a side-effect and re-render components hooked up with `useId`.\n */\nexport function mergeIds(idA: string, idB: string): string {\n if (idA === idB) {\n return idA;\n }\n\n let setIdsA = idsUpdaterMap.get(idA);\n if (setIdsA) {\n setIdsA.forEach(ref => (ref.current = idB));\n return idB;\n }\n\n let setIdsB = idsUpdaterMap.get(idB);\n if (setIdsB) {\n setIdsB.forEach((ref) => (ref.current = idA));\n return idA;\n }\n\n return idB;\n}\n\n/**\n * Used to generate an id, and after render, check if that id is rendered so we know\n * if we can use it in places such as labelledby.\n * @param depArray - When to recalculate if the id is in the DOM.\n */\nexport function useSlotId(depArray: ReadonlyArray<any> = []): string {\n let id = useId();\n let [resolvedId, setResolvedId] = useValueEffect(id);\n let updateId = useCallback(() => {\n setResolvedId(function *() {\n yield id;\n\n yield document.getElementById(id) ? id : undefined;\n });\n }, [id, setResolvedId]);\n\n useLayoutEffect(updateId, [id, updateId, ...depArray]);\n\n return resolvedId;\n}\n"],"names":[],"version":3,"file":"useId.module.js.map"}
|
|
@@ -27,8 +27,9 @@ function $29293a6f5c75b37e$export$496315a1608d9602(effect, dependencies) {
|
|
|
27
27
|
};
|
|
28
28
|
}, []);
|
|
29
29
|
(0, $cagC1$react.useEffect)(()=>{
|
|
30
|
+
let prevDeps = lastDeps.current;
|
|
30
31
|
if (isInitialMount.current) isInitialMount.current = false;
|
|
31
|
-
else if (!
|
|
32
|
+
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) effect();
|
|
32
33
|
lastDeps.current = dependencies;
|
|
33
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
35
|
}, 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,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,
|
|
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"}
|
package/dist/useUpdateEffect.mjs
CHANGED
|
@@ -21,8 +21,9 @@ function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
|
|
|
21
21
|
};
|
|
22
22
|
}, []);
|
|
23
23
|
(0, $9vW05$useEffect)(()=>{
|
|
24
|
+
let prevDeps = lastDeps.current;
|
|
24
25
|
if (isInitialMount.current) isInitialMount.current = false;
|
|
25
|
-
else if (!
|
|
26
|
+
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) effect();
|
|
26
27
|
lastDeps.current = dependencies;
|
|
27
28
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
29
|
}, dependencies);
|
|
@@ -21,8 +21,9 @@ function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
|
|
|
21
21
|
};
|
|
22
22
|
}, []);
|
|
23
23
|
(0, $9vW05$useEffect)(()=>{
|
|
24
|
+
let prevDeps = lastDeps.current;
|
|
24
25
|
if (isInitialMount.current) isInitialMount.current = false;
|
|
25
|
-
else if (!
|
|
26
|
+
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) effect();
|
|
26
27
|
lastDeps.current = dependencies;
|
|
27
28
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
29
|
}, 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,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,
|
|
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"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var $78605a5d7424e31b$exports = require("./useLayoutEffect.main.js");
|
|
2
|
+
var $ah9Dz$react = require("react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useUpdateLayoutEffect", () => $0fa310503218f75f$export$72ef708ab07251f1);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function $0fa310503218f75f$export$72ef708ab07251f1(effect, dependencies) {
|
|
23
|
+
const isInitialMount = (0, $ah9Dz$react.useRef)(true);
|
|
24
|
+
const lastDeps = (0, $ah9Dz$react.useRef)(null);
|
|
25
|
+
(0, $78605a5d7424e31b$exports.useLayoutEffect)(()=>{
|
|
26
|
+
isInitialMount.current = true;
|
|
27
|
+
return ()=>{
|
|
28
|
+
isInitialMount.current = false;
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
(0, $78605a5d7424e31b$exports.useLayoutEffect)(()=>{
|
|
32
|
+
if (isInitialMount.current) isInitialMount.current = false;
|
|
33
|
+
else if (!lastDeps.current || dependencies.some((dep, i)=>!Object.is(dep, lastDeps[i]))) effect();
|
|
34
|
+
lastDeps.current = dependencies;
|
|
35
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
+
}, dependencies);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=useUpdateLayoutEffect.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAMM,SAAS,0CAAsB,MAAsB,EAAE,YAAmB;IAC/E,MAAM,iBAAiB,CAAA,GAAA,mBAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,mBAAK,EAAgB;IAEtC,CAAA,GAAA,yCAAc,EAAE;QACd,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,SAAS,OAAO,IAAI,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IACvF;QAEF,SAAS,OAAO,GAAG;IACnB,uDAAuD;IACzD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateLayoutEffect.ts"],"sourcesContent":["/*\n * Copyright 2024 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, useRef} from 'react';\nimport {useLayoutEffect} from './useLayoutEffect';\n\n// Like useLayoutEffect, but only called for updates after the initial render.\nexport function useUpdateLayoutEffect(effect: EffectCallback, dependencies: any[]) {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n\n useLayoutEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!lastDeps.current || dependencies.some((dep, i) => !Object.is(dep, lastDeps[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":"useUpdateLayoutEffect.main.js.map"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.mjs";
|
|
2
|
+
import {useRef as $azsE2$useRef} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $ca9b37712f007381$export$72ef708ab07251f1(effect, dependencies) {
|
|
17
|
+
const isInitialMount = (0, $azsE2$useRef)(true);
|
|
18
|
+
const lastDeps = (0, $azsE2$useRef)(null);
|
|
19
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
20
|
+
isInitialMount.current = true;
|
|
21
|
+
return ()=>{
|
|
22
|
+
isInitialMount.current = false;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
26
|
+
if (isInitialMount.current) isInitialMount.current = false;
|
|
27
|
+
else if (!lastDeps.current || dependencies.some((dep, i)=>!Object.is(dep, lastDeps[i]))) effect();
|
|
28
|
+
lastDeps.current = dependencies;
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, dependencies);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export {$ca9b37712f007381$export$72ef708ab07251f1 as useUpdateLayoutEffect};
|
|
35
|
+
//# sourceMappingURL=useUpdateLayoutEffect.module.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.module.js";
|
|
2
|
+
import {useRef as $azsE2$useRef} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $ca9b37712f007381$export$72ef708ab07251f1(effect, dependencies) {
|
|
17
|
+
const isInitialMount = (0, $azsE2$useRef)(true);
|
|
18
|
+
const lastDeps = (0, $azsE2$useRef)(null);
|
|
19
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
20
|
+
isInitialMount.current = true;
|
|
21
|
+
return ()=>{
|
|
22
|
+
isInitialMount.current = false;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
26
|
+
if (isInitialMount.current) isInitialMount.current = false;
|
|
27
|
+
else if (!lastDeps.current || dependencies.some((dep, i)=>!Object.is(dep, lastDeps[i]))) effect();
|
|
28
|
+
lastDeps.current = dependencies;
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
}, dependencies);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export {$ca9b37712f007381$export$72ef708ab07251f1 as useUpdateLayoutEffect};
|
|
35
|
+
//# sourceMappingURL=useUpdateLayoutEffect.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAMM,SAAS,0CAAsB,MAAsB,EAAE,YAAmB;IAC/E,MAAM,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,aAAK,EAAgB;IAEtC,CAAA,GAAA,yCAAc,EAAE;QACd,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,SAAS,OAAO,IAAI,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IACvF;QAEF,SAAS,OAAO,GAAG;IACnB,uDAAuD;IACzD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateLayoutEffect.ts"],"sourcesContent":["/*\n * Copyright 2024 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, useRef} from 'react';\nimport {useLayoutEffect} from './useLayoutEffect';\n\n// Like useLayoutEffect, but only called for updates after the initial render.\nexport function useUpdateLayoutEffect(effect: EffectCallback, dependencies: any[]) {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n\n useLayoutEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useLayoutEffect(() => {\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!lastDeps.current || dependencies.some((dep, i) => !Object.is(dep, lastDeps[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":"useUpdateLayoutEffect.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.28.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -23,16 +23,18 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@react-aria/ssr": "^3.9.7",
|
|
26
|
+
"@react-stately/flags": "^3.1.0",
|
|
26
27
|
"@react-stately/utils": "^3.10.5",
|
|
27
|
-
"@react-types/shared": "^3.
|
|
28
|
+
"@react-types/shared": "^3.28.0",
|
|
28
29
|
"@swc/helpers": "^0.5.0",
|
|
29
30
|
"clsx": "^2.0.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
33
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
34
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
33
35
|
},
|
|
34
36
|
"publishConfig": {
|
|
35
37
|
"access": "public"
|
|
36
38
|
},
|
|
37
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "4d3c72c94eea2d72eb3a0e7d56000c6ef7e39726"
|
|
38
40
|
}
|
package/src/animation.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {flushSync} from 'react-dom';
|
|
14
|
+
import {RefObject, useCallback, useState} from 'react';
|
|
15
|
+
import {useLayoutEffect} from './useLayoutEffect';
|
|
16
|
+
|
|
17
|
+
export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: boolean = true) {
|
|
18
|
+
let [isEntering, setEntering] = useState(true);
|
|
19
|
+
let isAnimationReady = isEntering && isReady;
|
|
20
|
+
|
|
21
|
+
// There are two cases for entry animations:
|
|
22
|
+
// 1. CSS @keyframes. The `animation` property is set during the isEntering state, and it is removed after the animation finishes.
|
|
23
|
+
// 2. CSS transitions. The initial styles are applied during the isEntering state, and removed immediately, causing the transition to occur.
|
|
24
|
+
//
|
|
25
|
+
// In the second case, cancel any transitions that were triggered prior to the isEntering = false state (when the transition is supposed to start).
|
|
26
|
+
// This can happen when isReady starts as false (e.g. popovers prior to placement calculation).
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
if (isAnimationReady && ref.current && 'getAnimations' in ref.current) {
|
|
29
|
+
for (let animation of ref.current.getAnimations()) {
|
|
30
|
+
if (animation instanceof CSSTransition) {
|
|
31
|
+
animation.cancel();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, [ref, isAnimationReady]);
|
|
36
|
+
|
|
37
|
+
useAnimation(ref, isAnimationReady, useCallback(() => setEntering(false), []));
|
|
38
|
+
return isAnimationReady;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean) {
|
|
42
|
+
let [exitState, setExitState] = useState<'closed' | 'open' | 'exiting'>(isOpen ? 'open' : 'closed');
|
|
43
|
+
|
|
44
|
+
switch (exitState) {
|
|
45
|
+
case 'open':
|
|
46
|
+
// If isOpen becomes false, set the state to exiting.
|
|
47
|
+
if (!isOpen) {
|
|
48
|
+
setExitState('exiting');
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
case 'closed':
|
|
52
|
+
case 'exiting':
|
|
53
|
+
// If we are exiting and isOpen becomes true, the animation was interrupted.
|
|
54
|
+
// Reset the state to open.
|
|
55
|
+
if (isOpen) {
|
|
56
|
+
setExitState('open');
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let isExiting = exitState === 'exiting';
|
|
62
|
+
useAnimation(
|
|
63
|
+
ref,
|
|
64
|
+
isExiting,
|
|
65
|
+
useCallback(() => {
|
|
66
|
+
// Set the state to closed, which will cause the element to be unmounted.
|
|
67
|
+
setExitState(state => state === 'exiting' ? 'closed' : state);
|
|
68
|
+
}, [])
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return isExiting;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onEnd: () => void) {
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
if (isActive && ref.current) {
|
|
77
|
+
if (!('getAnimations' in ref.current)) {
|
|
78
|
+
// JSDOM
|
|
79
|
+
onEnd();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let animations = ref.current.getAnimations();
|
|
84
|
+
if (animations.length === 0) {
|
|
85
|
+
onEnd();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let canceled = false;
|
|
90
|
+
Promise.all(animations.map(a => a.finished)).then(() => {
|
|
91
|
+
if (!canceled) {
|
|
92
|
+
flushSync(() => {
|
|
93
|
+
onEnd();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}).catch(() => {});
|
|
97
|
+
|
|
98
|
+
return () => {
|
|
99
|
+
canceled = true;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}, [ref, isActive, onEnd]);
|
|
103
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Custom event names for updating the autocomplete's aria-activedecendant.
|
|
14
|
+
export const CLEAR_FOCUS_EVENT = 'react-aria-clear-focus';
|
|
15
|
+
export const FOCUS_EVENT = 'react-aria-focus';
|
package/src/domHelpers.ts
CHANGED
|
@@ -12,3 +12,22 @@ export const getOwnerWindow = (
|
|
|
12
12
|
const doc = getOwnerDocument(el as Element | null | undefined);
|
|
13
13
|
return doc.defaultView || window;
|
|
14
14
|
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Type guard that checks if a value is a Node. Verifies the presence and type of the nodeType property.
|
|
18
|
+
*/
|
|
19
|
+
function isNode(value: unknown): value is Node {
|
|
20
|
+
return value !== null &&
|
|
21
|
+
typeof value === 'object' &&
|
|
22
|
+
'nodeType' in value &&
|
|
23
|
+
typeof (value as Node).nodeType === 'number';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Type guard that checks if a node is a ShadowRoot. Uses nodeType and host property checks to
|
|
27
|
+
* distinguish ShadowRoot from other DocumentFragments.
|
|
28
|
+
*/
|
|
29
|
+
export function isShadowRoot(node: Node | null): node is ShadowRoot {
|
|
30
|
+
return isNode(node) &&
|
|
31
|
+
node.nodeType === Node.DOCUMENT_FRAGMENT_NODE &&
|
|
32
|
+
'host' in node;
|
|
33
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export {useId, mergeIds, useSlotId} from './useId';
|
|
13
13
|
export {chain} from './chain';
|
|
14
|
-
export {
|
|
14
|
+
export {createShadowTreeWalker, ShadowTreeWalker} from './shadowdom/ShadowTreeWalker';
|
|
15
|
+
export {getActiveElement, getEventTarget, nodeContains} from './shadowdom/DOMFunctions';
|
|
16
|
+
export {getOwnerDocument, getOwnerWindow, isShadowRoot} from './domHelpers';
|
|
15
17
|
export {mergeProps} from './mergeProps';
|
|
16
18
|
export {mergeRefs} from './mergeRefs';
|
|
17
19
|
export {filterDOMProps} from './filterDOMProps';
|
|
@@ -24,6 +26,7 @@ export {useGlobalListeners} from './useGlobalListeners';
|
|
|
24
26
|
export {useLabels} from './useLabels';
|
|
25
27
|
export {useObjectRef} from './useObjectRef';
|
|
26
28
|
export {useUpdateEffect} from './useUpdateEffect';
|
|
29
|
+
export {useUpdateLayoutEffect} from './useUpdateLayoutEffect';
|
|
27
30
|
export {useLayoutEffect} from './useLayoutEffect';
|
|
28
31
|
export {useResizeObserver} from './useResizeObserver';
|
|
29
32
|
export {useSyncRef} from './useSyncRef';
|
|
@@ -42,3 +45,8 @@ export {useEffectEvent} from './useEffectEvent';
|
|
|
42
45
|
export {useDeepMemo} from './useDeepMemo';
|
|
43
46
|
export {useFormReset} from './useFormReset';
|
|
44
47
|
export {useLoadMore} from './useLoadMore';
|
|
48
|
+
export {inertValue} from './inertValue';
|
|
49
|
+
export {CLEAR_FOCUS_EVENT, FOCUS_EVENT} from './constants';
|
|
50
|
+
export {isCtrlKeyPressed} from './keyboard';
|
|
51
|
+
export {useEnterAnimation, useExitAnimation} from './animation';
|
|
52
|
+
export {isFocusable, isTabbable} from './isFocusable';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {version} from 'react';
|
|
2
|
+
|
|
3
|
+
export function inertValue(value?: boolean) {
|
|
4
|
+
const pieces = version.split('.');
|
|
5
|
+
const major = parseInt(pieces[0], 10);
|
|
6
|
+
if (major >= 19) {
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
// compatibility with React < 19
|
|
10
|
+
return value ? 'true' : undefined;
|
|
11
|
+
}
|