@react-aria/utils 3.27.0 → 3.28.1
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/constants.main.js +0 -2
- package/dist/constants.main.js.map +1 -1
- package/dist/constants.mjs +1 -2
- package/dist/constants.module.js +1 -2
- package/dist/constants.module.js.map +1 -1
- 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 +11 -3
- 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/main.js +17 -1
- 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 +11 -3
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +50 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useGlobalListeners.main.js.map +1 -1
- package/dist/useGlobalListeners.module.js.map +1 -1
- package/dist/useId.main.js +27 -21
- package/dist/useId.main.js.map +1 -1
- package/dist/useId.mjs +29 -23
- package/dist/useId.module.js +29 -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/package.json +4 -3
- package/src/constants.ts +0 -1
- package/src/domHelpers.ts +19 -0
- package/src/index.ts +6 -2
- package/src/inertValue.ts +11 -0
- package/src/isFocusable.ts +28 -0
- package/src/mergeProps.ts +1 -1
- package/src/shadowdom/DOMFunctions.ts +70 -0
- package/src/shadowdom/ShadowTreeWalker.ts +319 -0
- package/src/useGlobalListeners.ts +1 -0
- package/src/useId.ts +31 -15
- package/src/useUpdateEffect.ts +3 -2
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,59 @@ 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;
|
|
27
|
+
if (typeof FinalizationRegistry !== 'undefined') $bdb11010cef70236$var$registry = new FinalizationRegistry((heldValue)=>{
|
|
28
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(heldValue);
|
|
29
|
+
});
|
|
23
30
|
function $bdb11010cef70236$export$f680877a34711e37(defaultId) {
|
|
24
31
|
let [value, setValue] = (0, $eKkEp$useState)(defaultId);
|
|
25
32
|
let nextId = (0, $eKkEp$useRef)(null);
|
|
26
33
|
let res = (0, $eKkEp$useSSRSafeId)(value);
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
}, []);
|
|
34
|
+
let cleanupRef = (0, $eKkEp$useRef)(null);
|
|
35
|
+
if ($bdb11010cef70236$var$registry) $bdb11010cef70236$var$registry.register(cleanupRef, res);
|
|
30
36
|
if ($bdb11010cef70236$var$canUseDOM) {
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]);
|
|
36
|
-
else $bdb11010cef70236$var$idsUpdaterMap.set(res, [
|
|
37
|
-
updateValue
|
|
37
|
+
const cacheIdRef = $bdb11010cef70236$export$d41a04c74483c6ef.get(res);
|
|
38
|
+
if (cacheIdRef && !cacheIdRef.includes(nextId)) cacheIdRef.push(nextId);
|
|
39
|
+
else $bdb11010cef70236$export$d41a04c74483c6ef.set(res, [
|
|
40
|
+
nextId
|
|
38
41
|
]);
|
|
39
42
|
}
|
|
40
43
|
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
41
44
|
let r = res;
|
|
42
45
|
return ()=>{
|
|
43
|
-
|
|
46
|
+
// In Suspense, the cleanup function may be not called
|
|
47
|
+
// when it is though, also remove it from the finalization registry.
|
|
48
|
+
if ($bdb11010cef70236$var$registry) $bdb11010cef70236$var$registry.unregister(cleanupRef);
|
|
49
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(r);
|
|
44
50
|
};
|
|
45
51
|
}, [
|
|
46
52
|
res
|
|
47
53
|
]);
|
|
48
|
-
// This cannot cause an infinite loop because the ref is
|
|
54
|
+
// This cannot cause an infinite loop because the ref is always cleaned up.
|
|
49
55
|
// eslint-disable-next-line
|
|
50
56
|
(0, $eKkEp$useEffect)(()=>{
|
|
51
57
|
let newId = nextId.current;
|
|
52
|
-
if (newId)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
58
|
+
if (newId) setValue(newId);
|
|
59
|
+
return ()=>{
|
|
60
|
+
if (newId) nextId.current = null;
|
|
61
|
+
};
|
|
56
62
|
});
|
|
57
63
|
return res;
|
|
58
64
|
}
|
|
59
65
|
function $bdb11010cef70236$export$cd8c9cb68f842629(idA, idB) {
|
|
60
66
|
if (idA === idB) return idA;
|
|
61
|
-
let setIdsA = $bdb11010cef70236$
|
|
67
|
+
let setIdsA = $bdb11010cef70236$export$d41a04c74483c6ef.get(idA);
|
|
62
68
|
if (setIdsA) {
|
|
63
|
-
setIdsA.forEach((
|
|
69
|
+
setIdsA.forEach((ref)=>ref.current = idB);
|
|
64
70
|
return idB;
|
|
65
71
|
}
|
|
66
|
-
let setIdsB = $bdb11010cef70236$
|
|
72
|
+
let setIdsB = $bdb11010cef70236$export$d41a04c74483c6ef.get(idB);
|
|
67
73
|
if (setIdsB) {
|
|
68
|
-
setIdsB.forEach((
|
|
74
|
+
setIdsB.forEach((ref)=>ref.current = idA);
|
|
69
75
|
return idA;
|
|
70
76
|
}
|
|
71
77
|
return idB;
|
|
@@ -91,5 +97,5 @@ function $bdb11010cef70236$export$b4cc09c592e8fdb8(depArray = []) {
|
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
|
|
94
|
-
export {$bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
100
|
+
export {$bdb11010cef70236$export$d41a04c74483c6ef as idsUpdaterMap, $bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
95
101
|
//# 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,59 @@ 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;
|
|
27
|
+
if (typeof FinalizationRegistry !== 'undefined') $bdb11010cef70236$var$registry = new FinalizationRegistry((heldValue)=>{
|
|
28
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(heldValue);
|
|
29
|
+
});
|
|
23
30
|
function $bdb11010cef70236$export$f680877a34711e37(defaultId) {
|
|
24
31
|
let [value, setValue] = (0, $eKkEp$useState)(defaultId);
|
|
25
32
|
let nextId = (0, $eKkEp$useRef)(null);
|
|
26
33
|
let res = (0, $eKkEp$useSSRSafeId)(value);
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
}, []);
|
|
34
|
+
let cleanupRef = (0, $eKkEp$useRef)(null);
|
|
35
|
+
if ($bdb11010cef70236$var$registry) $bdb11010cef70236$var$registry.register(cleanupRef, res);
|
|
30
36
|
if ($bdb11010cef70236$var$canUseDOM) {
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
]);
|
|
36
|
-
else $bdb11010cef70236$var$idsUpdaterMap.set(res, [
|
|
37
|
-
updateValue
|
|
37
|
+
const cacheIdRef = $bdb11010cef70236$export$d41a04c74483c6ef.get(res);
|
|
38
|
+
if (cacheIdRef && !cacheIdRef.includes(nextId)) cacheIdRef.push(nextId);
|
|
39
|
+
else $bdb11010cef70236$export$d41a04c74483c6ef.set(res, [
|
|
40
|
+
nextId
|
|
38
41
|
]);
|
|
39
42
|
}
|
|
40
43
|
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
41
44
|
let r = res;
|
|
42
45
|
return ()=>{
|
|
43
|
-
|
|
46
|
+
// In Suspense, the cleanup function may be not called
|
|
47
|
+
// when it is though, also remove it from the finalization registry.
|
|
48
|
+
if ($bdb11010cef70236$var$registry) $bdb11010cef70236$var$registry.unregister(cleanupRef);
|
|
49
|
+
$bdb11010cef70236$export$d41a04c74483c6ef.delete(r);
|
|
44
50
|
};
|
|
45
51
|
}, [
|
|
46
52
|
res
|
|
47
53
|
]);
|
|
48
|
-
// This cannot cause an infinite loop because the ref is
|
|
54
|
+
// This cannot cause an infinite loop because the ref is always cleaned up.
|
|
49
55
|
// eslint-disable-next-line
|
|
50
56
|
(0, $eKkEp$useEffect)(()=>{
|
|
51
57
|
let newId = nextId.current;
|
|
52
|
-
if (newId)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
58
|
+
if (newId) setValue(newId);
|
|
59
|
+
return ()=>{
|
|
60
|
+
if (newId) nextId.current = null;
|
|
61
|
+
};
|
|
56
62
|
});
|
|
57
63
|
return res;
|
|
58
64
|
}
|
|
59
65
|
function $bdb11010cef70236$export$cd8c9cb68f842629(idA, idB) {
|
|
60
66
|
if (idA === idB) return idA;
|
|
61
|
-
let setIdsA = $bdb11010cef70236$
|
|
67
|
+
let setIdsA = $bdb11010cef70236$export$d41a04c74483c6ef.get(idA);
|
|
62
68
|
if (setIdsA) {
|
|
63
|
-
setIdsA.forEach((
|
|
69
|
+
setIdsA.forEach((ref)=>ref.current = idB);
|
|
64
70
|
return idB;
|
|
65
71
|
}
|
|
66
|
-
let setIdsB = $bdb11010cef70236$
|
|
72
|
+
let setIdsB = $bdb11010cef70236$export$d41a04c74483c6ef.get(idB);
|
|
67
73
|
if (setIdsB) {
|
|
68
|
-
setIdsB.forEach((
|
|
74
|
+
setIdsB.forEach((ref)=>ref.current = idA);
|
|
69
75
|
return idA;
|
|
70
76
|
}
|
|
71
77
|
return idB;
|
|
@@ -91,5 +97,5 @@ function $bdb11010cef70236$export$b4cc09c592e8fdb8(depArray = []) {
|
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
|
|
94
|
-
export {$bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
100
|
+
export {$bdb11010cef70236$export$d41a04c74483c6ef as idsUpdaterMap, $bdb11010cef70236$export$f680877a34711e37 as useId, $bdb11010cef70236$export$cd8c9cb68f842629 as mergeIds, $bdb11010cef70236$export$b4cc09c592e8fdb8 as useSlotId};
|
|
95
101
|
//# 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;AACJ,IAAI,OAAO,yBAAyB,aAClC,iCAAW,IAAI,qBAA6B,CAAC;IAC3C,0CAAc,MAAM,CAAC;AACvB;AAOK,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,IAAI,gCACF,+BAAS,QAAQ,CAAC,YAAY;IAGhC,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,IAAI,gCACF,+BAAS,UAAU,CAAC;YAEtB,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;\nif (typeof FinalizationRegistry !== 'undefined') {\n registry = new FinalizationRegistry<string>((heldValue) => {\n idsUpdaterMap.delete(heldValue);\n });\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 if (registry) {\n registry.register(cleanupRef, res);\n }\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 if (registry) {\n registry.unregister(cleanupRef);\n }\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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.28.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -23,8 +23,9 @@
|
|
|
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
|
},
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "9c4ebbc0c1972cc880febc29de995ca58caa3ba4"
|
|
39
40
|
}
|
package/src/constants.ts
CHANGED
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';
|
|
@@ -43,6 +45,8 @@ export {useEffectEvent} from './useEffectEvent';
|
|
|
43
45
|
export {useDeepMemo} from './useDeepMemo';
|
|
44
46
|
export {useFormReset} from './useFormReset';
|
|
45
47
|
export {useLoadMore} from './useLoadMore';
|
|
46
|
-
export {
|
|
48
|
+
export {inertValue} from './inertValue';
|
|
49
|
+
export {CLEAR_FOCUS_EVENT, FOCUS_EVENT} from './constants';
|
|
47
50
|
export {isCtrlKeyPressed} from './keyboard';
|
|
48
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
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const focusableElements = [
|
|
2
|
+
'input:not([disabled]):not([type=hidden])',
|
|
3
|
+
'select:not([disabled])',
|
|
4
|
+
'textarea:not([disabled])',
|
|
5
|
+
'button:not([disabled])',
|
|
6
|
+
'a[href]',
|
|
7
|
+
'area[href]',
|
|
8
|
+
'summary',
|
|
9
|
+
'iframe',
|
|
10
|
+
'object',
|
|
11
|
+
'embed',
|
|
12
|
+
'audio[controls]',
|
|
13
|
+
'video[controls]',
|
|
14
|
+
'[contenteditable]:not([contenteditable^="false"])'
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
|
|
18
|
+
|
|
19
|
+
focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
|
|
20
|
+
const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
|
|
21
|
+
|
|
22
|
+
export function isFocusable(element: Element) {
|
|
23
|
+
return element.matches(FOCUSABLE_ELEMENT_SELECTOR);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isTabbable(element: Element) {
|
|
27
|
+
return element.matches(TABBABLE_ELEMENT_SELECTOR);
|
|
28
|
+
}
|
package/src/mergeProps.ts
CHANGED
|
@@ -23,7 +23,7 @@ type PropsArg = Props | null | undefined;
|
|
|
23
23
|
// taken from: https://stackoverflow.com/questions/51603250/typescript-3-parameter-list-intersection-type/51604379#51604379
|
|
24
24
|
type TupleTypes<T> = { [P in keyof T]: T[P] } extends { [key: number]: infer V } ? NullToObject<V> : never;
|
|
25
25
|
type NullToObject<T> = T extends (null | undefined) ? {} : T;
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Source: https://github.com/microsoft/tabster/blob/a89fc5d7e332d48f68d03b1ca6e344489d1c3898/src/Shadowdomize/DOMFunctions.ts#L16
|
|
2
|
+
|
|
3
|
+
import {isShadowRoot} from '../domHelpers';
|
|
4
|
+
import {shadowDOM} from '@react-stately/flags';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ShadowDOM safe version of Node.contains.
|
|
8
|
+
*/
|
|
9
|
+
export function nodeContains(
|
|
10
|
+
node: Node | null | undefined,
|
|
11
|
+
otherNode: Node | null | undefined
|
|
12
|
+
): boolean {
|
|
13
|
+
if (!shadowDOM()) {
|
|
14
|
+
return otherNode && node ? node.contains(otherNode) : false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!node || !otherNode) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let currentNode: HTMLElement | Node | null | undefined = otherNode;
|
|
22
|
+
|
|
23
|
+
while (currentNode !== null) {
|
|
24
|
+
if (currentNode === node) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if ((currentNode as HTMLSlotElement).tagName === 'SLOT' &&
|
|
29
|
+
(currentNode as HTMLSlotElement).assignedSlot) {
|
|
30
|
+
// Element is slotted
|
|
31
|
+
currentNode = (currentNode as HTMLSlotElement).assignedSlot!.parentNode;
|
|
32
|
+
} else if (isShadowRoot(currentNode)) {
|
|
33
|
+
// Element is in shadow root
|
|
34
|
+
currentNode = currentNode.host;
|
|
35
|
+
} else {
|
|
36
|
+
currentNode = currentNode.parentNode;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* ShadowDOM safe version of document.activeElement.
|
|
45
|
+
*/
|
|
46
|
+
export const getActiveElement = (doc: Document = document) => {
|
|
47
|
+
if (!shadowDOM()) {
|
|
48
|
+
return doc.activeElement;
|
|
49
|
+
}
|
|
50
|
+
let activeElement: Element | null = doc.activeElement;
|
|
51
|
+
|
|
52
|
+
while (activeElement && 'shadowRoot' in activeElement &&
|
|
53
|
+
activeElement.shadowRoot?.activeElement) {
|
|
54
|
+
activeElement = activeElement.shadowRoot.activeElement;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return activeElement;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* ShadowDOM safe version of event.target.
|
|
62
|
+
*/
|
|
63
|
+
export function getEventTarget(event): Element {
|
|
64
|
+
if (shadowDOM() && event.target.shadowRoot) {
|
|
65
|
+
if (event.composedPath) {
|
|
66
|
+
return event.composedPath()[0];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return event.target;
|
|
70
|
+
}
|