@react-aria/utils 3.28.1 → 3.29.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.map +1 -1
- package/dist/DOMFunctions.module.js.map +1 -1
- package/dist/ShadowTreeWalker.main.js.map +1 -1
- package/dist/ShadowTreeWalker.module.js.map +1 -1
- package/dist/animation.main.js.map +1 -1
- package/dist/animation.module.js.map +1 -1
- package/dist/focusWithoutScrolling.main.js.map +1 -1
- package/dist/focusWithoutScrolling.module.js.map +1 -1
- package/dist/getOffset.main.js.map +1 -1
- package/dist/getOffset.module.js.map +1 -1
- package/dist/import.mjs +3 -1
- package/dist/inertValue.main.js.map +1 -1
- package/dist/inertValue.module.js.map +1 -1
- package/dist/isFocusable.main.js.map +1 -1
- package/dist/isFocusable.module.js.map +1 -1
- package/dist/isVirtualEvent.main.js.map +1 -1
- package/dist/isVirtualEvent.module.js.map +1 -1
- package/dist/keyboard.main.js.map +1 -1
- package/dist/keyboard.module.js.map +1 -1
- package/dist/main.js +3 -0
- package/dist/main.js.map +1 -1
- package/dist/mergeRefs.main.js +16 -4
- package/dist/mergeRefs.main.js.map +1 -1
- package/dist/mergeRefs.mjs +16 -4
- package/dist/mergeRefs.module.js +16 -4
- package/dist/mergeRefs.module.js.map +1 -1
- package/dist/module.js +3 -1
- package/dist/module.js.map +1 -1
- package/dist/openLink.main.js +1 -1
- package/dist/openLink.main.js.map +1 -1
- package/dist/openLink.mjs +1 -1
- package/dist/openLink.module.js +1 -1
- package/dist/openLink.module.js.map +1 -1
- package/dist/platform.main.js +1 -0
- package/dist/platform.main.js.map +1 -1
- package/dist/platform.mjs +1 -0
- package/dist/platform.module.js +1 -0
- package/dist/platform.module.js.map +1 -1
- package/dist/runAfterTransition.main.js +10 -0
- package/dist/runAfterTransition.main.js.map +1 -1
- package/dist/runAfterTransition.mjs +10 -0
- package/dist/runAfterTransition.module.js +10 -0
- package/dist/runAfterTransition.module.js.map +1 -1
- package/dist/scrollIntoView.main.js.map +1 -1
- package/dist/scrollIntoView.module.js.map +1 -1
- package/dist/types.d.ts +25 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/useEvent.main.js.map +1 -1
- package/dist/useEvent.module.js.map +1 -1
- package/dist/useFormReset.main.js.map +1 -1
- package/dist/useFormReset.module.js.map +1 -1
- package/dist/useLoadMore.main.js.map +1 -1
- package/dist/useLoadMore.module.js.map +1 -1
- package/dist/useLoadMoreSentinel.main.js +59 -0
- package/dist/useLoadMoreSentinel.main.js.map +1 -0
- package/dist/useLoadMoreSentinel.mjs +54 -0
- package/dist/useLoadMoreSentinel.module.js +54 -0
- package/dist/useLoadMoreSentinel.module.js.map +1 -0
- package/dist/useObjectRef.main.js +25 -4
- package/dist/useObjectRef.main.js.map +1 -1
- package/dist/useObjectRef.mjs +26 -5
- package/dist/useObjectRef.module.js +26 -5
- package/dist/useObjectRef.module.js.map +1 -1
- package/dist/useResizeObserver.main.js.map +1 -1
- package/dist/useResizeObserver.module.js.map +1 -1
- package/dist/useSyncRef.main.js.map +1 -1
- package/dist/useSyncRef.module.js.map +1 -1
- package/dist/useUpdateLayoutEffect.main.js.map +1 -1
- package/dist/useUpdateLayoutEffect.module.js.map +1 -1
- package/package.json +6 -6
- package/src/animation.ts +6 -6
- package/src/focusWithoutScrolling.ts +1 -1
- package/src/getOffset.ts +3 -1
- package/src/index.ts +3 -0
- package/src/inertValue.ts +1 -1
- package/src/isFocusable.ts +2 -2
- package/src/isVirtualEvent.ts +1 -1
- package/src/keyboard.tsx +1 -1
- package/src/mergeRefs.ts +28 -8
- package/src/openLink.tsx +9 -9
- package/src/runAfterTransition.ts +17 -1
- package/src/scrollIntoView.ts +2 -2
- package/src/shadowdom/DOMFunctions.ts +5 -5
- package/src/shadowdom/ShadowTreeWalker.ts +1 -1
- package/src/useEvent.ts +1 -1
- package/src/useFormReset.ts +1 -1
- package/src/useLoadMore.ts +2 -2
- package/src/useLoadMoreSentinel.ts +63 -0
- package/src/useObjectRef.ts +45 -15
- package/src/useResizeObserver.ts +1 -1
- package/src/useSyncRef.ts +1 -1
- package/src/useUpdateLayoutEffect.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useRef as $gbmns$useRef, useMemo as $gbmns$useMemo} from "react";
|
|
1
|
+
import {useRef as $gbmns$useRef, useCallback as $gbmns$useCallback, useMemo as $gbmns$useMemo} from "react";
|
|
2
2
|
|
|
3
3
|
/*
|
|
4
4
|
* Copyright 2021 Adobe. All rights reserved.
|
|
@@ -11,19 +11,40 @@ import {useRef as $gbmns$useRef, useMemo as $gbmns$useMemo} from "react";
|
|
|
11
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
|
-
function $df56164dff5785e2$export$4338b53315abf666(
|
|
14
|
+
function $df56164dff5785e2$export$4338b53315abf666(ref) {
|
|
15
15
|
const objRef = (0, $gbmns$useRef)(null);
|
|
16
|
+
const cleanupRef = (0, $gbmns$useRef)(undefined);
|
|
17
|
+
const refEffect = (0, $gbmns$useCallback)((instance)=>{
|
|
18
|
+
if (typeof ref === 'function') {
|
|
19
|
+
const refCallback = ref;
|
|
20
|
+
const refCleanup = refCallback(instance);
|
|
21
|
+
return ()=>{
|
|
22
|
+
if (typeof refCleanup === 'function') refCleanup();
|
|
23
|
+
else refCallback(null);
|
|
24
|
+
};
|
|
25
|
+
} else if (ref) {
|
|
26
|
+
ref.current = instance;
|
|
27
|
+
return ()=>{
|
|
28
|
+
ref.current = null;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}, [
|
|
32
|
+
ref
|
|
33
|
+
]);
|
|
16
34
|
return (0, $gbmns$useMemo)(()=>({
|
|
17
35
|
get current () {
|
|
18
36
|
return objRef.current;
|
|
19
37
|
},
|
|
20
38
|
set current (value){
|
|
21
39
|
objRef.current = value;
|
|
22
|
-
if (
|
|
23
|
-
|
|
40
|
+
if (cleanupRef.current) {
|
|
41
|
+
cleanupRef.current();
|
|
42
|
+
cleanupRef.current = undefined;
|
|
43
|
+
}
|
|
44
|
+
if (value != null) cleanupRef.current = refEffect(value);
|
|
24
45
|
}
|
|
25
46
|
}), [
|
|
26
|
-
|
|
47
|
+
refEffect
|
|
27
48
|
]);
|
|
28
49
|
}
|
|
29
50
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAaM,SAAS,0CAAgB,
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAaM,SAAS,0CAAgB,GAAuF;IACrH,MAAM,SAAqC,CAAA,GAAA,aAAK,EAAK;IACrD,MAAM,aAAoD,CAAA,GAAA,aAAK,EAAE;IAEjE,MAAM,YAAY,CAAA,GAAA,kBAAU,EAC1B,CAAC;QACC,IAAI,OAAO,QAAQ,YAAY;YAC7B,MAAM,cAAc;YACpB,MAAM,aAAa,YAAY;YAC/B,OAAO;gBACL,IAAI,OAAO,eAAe,YACxB;qBAEA,YAAY;YAEhB;QACF,OAAO,IAAI,KAAK;YACd,IAAI,OAAO,GAAG;YACd,OAAO;gBACL,IAAI,OAAO,GAAG;YAChB;QACF;IACF,GACA;QAAC;KAAI;IAGP,OAAO,CAAA,GAAA,cAAM,EACX,IAAO,CAAA;YACL,IAAI,WAAU;gBACZ,OAAO,OAAO,OAAO;YACvB;YACA,IAAI,SAAQ,MAAO;gBACjB,OAAO,OAAO,GAAG;gBACjB,IAAI,WAAW,OAAO,EAAE;oBACtB,WAAW,OAAO;oBAClB,WAAW,OAAO,GAAG;gBACvB;gBAEA,IAAI,SAAS,MACX,WAAW,OAAO,GAAG,UAAU;YAEnC;QACF,CAAA,GACA;QAAC;KAAU;AAEf","sources":["packages/@react-aria/utils/src/useObjectRef.ts"],"sourcesContent":["/*\n * Copyright 2021 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 {MutableRefObject, useCallback, useMemo, useRef} from 'react';\n\n/**\n * Offers an object ref for a given callback ref or an object ref. Especially\n * helfpul when passing forwarded refs (created using `React.forwardRef`) to\n * React Aria hooks.\n *\n * @param ref The original ref intended to be used.\n * @returns An object ref that updates the given ref.\n * @see https://react.dev/reference/react/forwardRef\n */\nexport function useObjectRef<T>(ref?: ((instance: T | null) => (() => void) | void) | MutableRefObject<T | null> | null): MutableRefObject<T | null> {\n const objRef: MutableRefObject<T | null> = useRef<T>(null);\n const cleanupRef: MutableRefObject<(() => void) | void> = useRef(undefined);\n\n const refEffect = useCallback(\n (instance: T | null) => {\n if (typeof ref === 'function') {\n const refCallback = ref;\n const refCleanup = refCallback(instance);\n return () => {\n if (typeof refCleanup === 'function') {\n refCleanup();\n } else {\n refCallback(null);\n }\n };\n } else if (ref) {\n ref.current = instance;\n return () => {\n ref.current = null;\n };\n }\n },\n [ref]\n );\n\n return useMemo(\n () => ({\n get current() {\n return objRef.current;\n },\n set current(value) {\n objRef.current = value;\n if (cleanupRef.current) {\n cleanupRef.current();\n cleanupRef.current = undefined;\n }\n\n if (value != null) {\n cleanupRef.current = refEffect(value);\n }\n }\n }),\n [refEffect]\n );\n}\n"],"names":[],"version":3,"file":"useObjectRef.module.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAIA,SAAS;IACP,OAAO,OAAO,OAAO,cAAc,KAAK;AAC1C;AAQO,SAAS,0CAAqC,OAAwC;IAC3F,MAAM,OAAC,GAAG,OAAE,GAAG,YAAE,QAAQ,EAAC,GAAG;IAE7B,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,UAAU,gBAAA,0BAAA,IAAK,OAAO;QAC1B,IAAI,CAAC,SACH;QAGF,IAAI,CAAC,2CAAqB;YACxB,OAAO,gBAAgB,CAAC,UAAU,UAAU;YAC5C,OAAO;gBACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;YACjD;QACF,OAAO;YAEL,MAAM,yBAAyB,IAAI,OAAO,cAAc,CAAC,CAAC;gBACxD,IAAI,CAAC,QAAQ,MAAM,EACjB;gBAGF;YACF;YACA,uBAAuB,OAAO,CAAC,SAAS;qBAAC;YAAG;YAE5C,OAAO;gBACL,IAAI,SACF,uBAAuB,SAAS,CAAC;YAErC;QACF;IAEF,GAAG;QAAC;QAAU;QAAK;KAAI;AACzB","sources":["packages/@react-aria/utils/src/useResizeObserver.ts"],"sourcesContent":["\nimport {RefObject} from '@react-types/shared';\nimport {useEffect} from 'react';\n\nfunction hasResizeObserver() {\n return typeof window.ResizeObserver !== 'undefined';\n}\n\ntype useResizeObserverOptionsType<T> = {\n ref: RefObject<T | undefined | null> | undefined,\n box?: ResizeObserverBoxOptions,\n onResize: () => void\n}\n\nexport function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>) {\n const {ref, box, onResize} = options;\n\n useEffect(() => {\n let element = ref?.current;\n if (!element) {\n return;\n }\n\n if (!hasResizeObserver()) {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n } else {\n\n const resizeObserverInstance = new window.ResizeObserver((entries) => {\n if (!entries.length) {\n return;\n }\n\n onResize();\n });\n resizeObserverInstance.observe(element, {box});\n\n return () => {\n if (element) {\n resizeObserverInstance.unobserve(element);\n }\n };\n }\n\n }, [onResize, ref, box]);\n}\n"],"names":[],"version":3,"file":"useResizeObserver.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAIA,SAAS;IACP,OAAO,OAAO,OAAO,cAAc,KAAK;AAC1C;AAQO,SAAS,0CAAqC,OAAwC;IAC3F,MAAM,OAAC,GAAG,OAAE,GAAG,YAAE,QAAQ,EAAC,GAAG;IAE7B,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,UAAU,gBAAA,0BAAA,IAAK,OAAO;QAC1B,IAAI,CAAC,SACH;QAGF,IAAI,CAAC,2CAAqB;YACxB,OAAO,gBAAgB,CAAC,UAAU,UAAU;YAC5C,OAAO;gBACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;YACjD;QACF,OAAO;YAEL,MAAM,yBAAyB,IAAI,OAAO,cAAc,CAAC,CAAC;gBACxD,IAAI,CAAC,QAAQ,MAAM,EACjB;gBAGF;YACF;YACA,uBAAuB,OAAO,CAAC,SAAS;qBAAC;YAAG;YAE5C,OAAO;gBACL,IAAI,SACF,uBAAuB,SAAS,CAAC;YAErC;QACF;IAEF,GAAG;QAAC;QAAU;QAAK;KAAI;AACzB","sources":["packages/@react-aria/utils/src/useResizeObserver.ts"],"sourcesContent":["\nimport {RefObject} from '@react-types/shared';\nimport {useEffect} from 'react';\n\nfunction hasResizeObserver() {\n return typeof window.ResizeObserver !== 'undefined';\n}\n\ntype useResizeObserverOptionsType<T> = {\n ref: RefObject<T | undefined | null> | undefined,\n box?: ResizeObserverBoxOptions,\n onResize: () => void\n}\n\nexport function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>): void {\n const {ref, box, onResize} = options;\n\n useEffect(() => {\n let element = ref?.current;\n if (!element) {\n return;\n }\n\n if (!hasResizeObserver()) {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n } else {\n\n const resizeObserverInstance = new window.ResizeObserver((entries) => {\n if (!entries.length) {\n return;\n }\n\n onResize();\n });\n resizeObserverInstance.observe(element, {box});\n\n return () => {\n if (element) {\n resizeObserverInstance.unobserve(element);\n }\n };\n }\n\n }, [onResize, ref, box]);\n}\n"],"names":[],"version":3,"file":"useResizeObserver.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;AAIA,SAAS;IACP,OAAO,OAAO,OAAO,cAAc,KAAK;AAC1C;AAQO,SAAS,0CAAqC,OAAwC;IAC3F,MAAM,OAAC,GAAG,OAAE,GAAG,YAAE,QAAQ,EAAC,GAAG;IAE7B,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,UAAU,gBAAA,0BAAA,IAAK,OAAO;QAC1B,IAAI,CAAC,SACH;QAGF,IAAI,CAAC,2CAAqB;YACxB,OAAO,gBAAgB,CAAC,UAAU,UAAU;YAC5C,OAAO;gBACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;YACjD;QACF,OAAO;YAEL,MAAM,yBAAyB,IAAI,OAAO,cAAc,CAAC,CAAC;gBACxD,IAAI,CAAC,QAAQ,MAAM,EACjB;gBAGF;YACF;YACA,uBAAuB,OAAO,CAAC,SAAS;qBAAC;YAAG;YAE5C,OAAO;gBACL,IAAI,SACF,uBAAuB,SAAS,CAAC;YAErC;QACF;IAEF,GAAG;QAAC;QAAU;QAAK;KAAI;AACzB","sources":["packages/@react-aria/utils/src/useResizeObserver.ts"],"sourcesContent":["\nimport {RefObject} from '@react-types/shared';\nimport {useEffect} from 'react';\n\nfunction hasResizeObserver() {\n return typeof window.ResizeObserver !== 'undefined';\n}\n\ntype useResizeObserverOptionsType<T> = {\n ref: RefObject<T | undefined | null> | undefined,\n box?: ResizeObserverBoxOptions,\n onResize: () => void\n}\n\nexport function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>) {\n const {ref, box, onResize} = options;\n\n useEffect(() => {\n let element = ref?.current;\n if (!element) {\n return;\n }\n\n if (!hasResizeObserver()) {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n } else {\n\n const resizeObserverInstance = new window.ResizeObserver((entries) => {\n if (!entries.length) {\n return;\n }\n\n onResize();\n });\n resizeObserverInstance.observe(element, {box});\n\n return () => {\n if (element) {\n resizeObserverInstance.unobserve(element);\n }\n };\n }\n\n }, [onResize, ref, box]);\n}\n"],"names":[],"version":3,"file":"useResizeObserver.module.js.map"}
|
|
1
|
+
{"mappings":";;;AAIA,SAAS;IACP,OAAO,OAAO,OAAO,cAAc,KAAK;AAC1C;AAQO,SAAS,0CAAqC,OAAwC;IAC3F,MAAM,OAAC,GAAG,OAAE,GAAG,YAAE,QAAQ,EAAC,GAAG;IAE7B,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,UAAU,gBAAA,0BAAA,IAAK,OAAO;QAC1B,IAAI,CAAC,SACH;QAGF,IAAI,CAAC,2CAAqB;YACxB,OAAO,gBAAgB,CAAC,UAAU,UAAU;YAC5C,OAAO;gBACL,OAAO,mBAAmB,CAAC,UAAU,UAAU;YACjD;QACF,OAAO;YAEL,MAAM,yBAAyB,IAAI,OAAO,cAAc,CAAC,CAAC;gBACxD,IAAI,CAAC,QAAQ,MAAM,EACjB;gBAGF;YACF;YACA,uBAAuB,OAAO,CAAC,SAAS;qBAAC;YAAG;YAE5C,OAAO;gBACL,IAAI,SACF,uBAAuB,SAAS,CAAC;YAErC;QACF;IAEF,GAAG;QAAC;QAAU;QAAK;KAAI;AACzB","sources":["packages/@react-aria/utils/src/useResizeObserver.ts"],"sourcesContent":["\nimport {RefObject} from '@react-types/shared';\nimport {useEffect} from 'react';\n\nfunction hasResizeObserver() {\n return typeof window.ResizeObserver !== 'undefined';\n}\n\ntype useResizeObserverOptionsType<T> = {\n ref: RefObject<T | undefined | null> | undefined,\n box?: ResizeObserverBoxOptions,\n onResize: () => void\n}\n\nexport function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>): void {\n const {ref, box, onResize} = options;\n\n useEffect(() => {\n let element = ref?.current;\n if (!element) {\n return;\n }\n\n if (!hasResizeObserver()) {\n window.addEventListener('resize', onResize, false);\n return () => {\n window.removeEventListener('resize', onResize, false);\n };\n } else {\n\n const resizeObserverInstance = new window.ResizeObserver((entries) => {\n if (!entries.length) {\n return;\n }\n\n onResize();\n });\n resizeObserverInstance.observe(element, {box});\n\n return () => {\n if (element) {\n resizeObserverInstance.unobserve(element);\n }\n };\n }\n\n }, [onResize, ref, box]);\n}\n"],"names":[],"version":3,"file":"useResizeObserver.module.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAWM,SAAS,0CAAc,OAAgC,EAAE,GAAyB;IACvF,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,WAAW,QAAQ,GAAG,IAAI,KAAK;YACjC,QAAQ,GAAG,CAAC,OAAO,GAAG,IAAI,OAAO;YACjC,OAAO;gBACL,IAAI,QAAQ,GAAG,EACb,QAAQ,GAAG,CAAC,OAAO,GAAG;YAE1B;QACF;IACF;AACF","sources":["packages/@react-aria/utils/src/useSyncRef.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 {MutableRefObject} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {useLayoutEffect} from './';\n\ninterface ContextValue<T> {\n ref?: MutableRefObject<T | null>\n}\n\n// Syncs ref from context with ref passed to hook\nexport function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>) {\n useLayoutEffect(() => {\n if (context && context.ref && ref) {\n context.ref.current = ref.current;\n return () => {\n if (context.ref) {\n context.ref.current = null;\n }\n };\n }\n });\n}\n"],"names":[],"version":3,"file":"useSyncRef.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAWM,SAAS,0CAAc,OAAgC,EAAE,GAAyB;IACvF,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,WAAW,QAAQ,GAAG,IAAI,KAAK;YACjC,QAAQ,GAAG,CAAC,OAAO,GAAG,IAAI,OAAO;YACjC,OAAO;gBACL,IAAI,QAAQ,GAAG,EACb,QAAQ,GAAG,CAAC,OAAO,GAAG;YAE1B;QACF;IACF;AACF","sources":["packages/@react-aria/utils/src/useSyncRef.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 {MutableRefObject} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {useLayoutEffect} from './';\n\ninterface ContextValue<T> {\n ref?: MutableRefObject<T | null>\n}\n\n// Syncs ref from context with ref passed to hook\nexport function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>): void {\n useLayoutEffect(() => {\n if (context && context.ref && ref) {\n context.ref.current = ref.current;\n return () => {\n if (context.ref) {\n context.ref.current = null;\n }\n };\n }\n });\n}\n"],"names":[],"version":3,"file":"useSyncRef.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAWM,SAAS,0CAAc,OAAgC,EAAE,GAAyB;IACvF,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,WAAW,QAAQ,GAAG,IAAI,KAAK;YACjC,QAAQ,GAAG,CAAC,OAAO,GAAG,IAAI,OAAO;YACjC,OAAO;gBACL,IAAI,QAAQ,GAAG,EACb,QAAQ,GAAG,CAAC,OAAO,GAAG;YAE1B;QACF;IACF;AACF","sources":["packages/@react-aria/utils/src/useSyncRef.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 {MutableRefObject} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {useLayoutEffect} from './';\n\ninterface ContextValue<T> {\n ref?: MutableRefObject<T | null>\n}\n\n// Syncs ref from context with ref passed to hook\nexport function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>) {\n useLayoutEffect(() => {\n if (context && context.ref && ref) {\n context.ref.current = ref.current;\n return () => {\n if (context.ref) {\n context.ref.current = null;\n }\n };\n }\n });\n}\n"],"names":[],"version":3,"file":"useSyncRef.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAWM,SAAS,0CAAc,OAAgC,EAAE,GAAyB;IACvF,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,WAAW,QAAQ,GAAG,IAAI,KAAK;YACjC,QAAQ,GAAG,CAAC,OAAO,GAAG,IAAI,OAAO;YACjC,OAAO;gBACL,IAAI,QAAQ,GAAG,EACb,QAAQ,GAAG,CAAC,OAAO,GAAG;YAE1B;QACF;IACF;AACF","sources":["packages/@react-aria/utils/src/useSyncRef.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 {MutableRefObject} from 'react';\nimport {RefObject} from '@react-types/shared';\nimport {useLayoutEffect} from './';\n\ninterface ContextValue<T> {\n ref?: MutableRefObject<T | null>\n}\n\n// Syncs ref from context with ref passed to hook\nexport function useSyncRef<T>(context?: ContextValue<T> | null, ref?: RefObject<T | null>): void {\n useLayoutEffect(() => {\n if (context && context.ref && ref) {\n context.ref.current = ref.current;\n return () => {\n if (context.ref) {\n context.ref.current = null;\n }\n };\n }\n });\n}\n"],"names":[],"version":3,"file":"useSyncRef.module.js.map"}
|
|
@@ -1 +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"}
|
|
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[]): void {\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"}
|
|
@@ -1 +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"}
|
|
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[]): void {\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.29.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/ssr": "^3.9.
|
|
26
|
-
"@react-stately/flags": "^3.1.
|
|
27
|
-
"@react-stately/utils": "^3.10.
|
|
28
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/ssr": "^3.9.8",
|
|
26
|
+
"@react-stately/flags": "^3.1.1",
|
|
27
|
+
"@react-stately/utils": "^3.10.6",
|
|
28
|
+
"@react-types/shared": "^3.29.1",
|
|
29
29
|
"@swc/helpers": "^0.5.0",
|
|
30
30
|
"clsx": "^2.0.0"
|
|
31
31
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "9c77d4e8267ed39469c65f65da94ece7be509874"
|
|
40
40
|
}
|
package/src/animation.ts
CHANGED
|
@@ -14,10 +14,10 @@ import {flushSync} from 'react-dom';
|
|
|
14
14
|
import {RefObject, useCallback, useState} from 'react';
|
|
15
15
|
import {useLayoutEffect} from './useLayoutEffect';
|
|
16
16
|
|
|
17
|
-
export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: boolean = true) {
|
|
17
|
+
export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: boolean = true): boolean {
|
|
18
18
|
let [isEntering, setEntering] = useState(true);
|
|
19
19
|
let isAnimationReady = isEntering && isReady;
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
// There are two cases for entry animations:
|
|
22
22
|
// 1. CSS @keyframes. The `animation` property is set during the isEntering state, and it is removed after the animation finishes.
|
|
23
23
|
// 2. CSS transitions. The initial styles are applied during the isEntering state, and removed immediately, causing the transition to occur.
|
|
@@ -38,7 +38,7 @@ export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: b
|
|
|
38
38
|
return isAnimationReady;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean) {
|
|
41
|
+
export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean): boolean {
|
|
42
42
|
let [exitState, setExitState] = useState<'closed' | 'open' | 'exiting'>(isOpen ? 'open' : 'closed');
|
|
43
43
|
|
|
44
44
|
switch (exitState) {
|
|
@@ -71,7 +71,7 @@ export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boo
|
|
|
71
71
|
return isExiting;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onEnd: () => void) {
|
|
74
|
+
function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onEnd: () => void): void {
|
|
75
75
|
useLayoutEffect(() => {
|
|
76
76
|
if (isActive && ref.current) {
|
|
77
77
|
if (!('getAnimations' in ref.current)) {
|
|
@@ -79,7 +79,7 @@ function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onE
|
|
|
79
79
|
onEnd();
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
let animations = ref.current.getAnimations();
|
|
84
84
|
if (animations.length === 0) {
|
|
85
85
|
onEnd();
|
|
@@ -94,7 +94,7 @@ function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onE
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
}).catch(() => {});
|
|
97
|
-
|
|
97
|
+
|
|
98
98
|
return () => {
|
|
99
99
|
canceled = true;
|
|
100
100
|
};
|
|
@@ -28,7 +28,7 @@ interface ScrollableElement {
|
|
|
28
28
|
scrollLeft: number
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function focusWithoutScrolling(element: FocusableElement) {
|
|
31
|
+
export function focusWithoutScrolling(element: FocusableElement): void {
|
|
32
32
|
if (supportsPreventScroll()) {
|
|
33
33
|
element.focus({preventScroll: true});
|
|
34
34
|
} else {
|
package/src/getOffset.ts
CHANGED
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
import {Orientation} from '@react-types/shared';
|
|
14
|
+
|
|
15
|
+
export function getOffset(element: HTMLElement, reverse?: boolean, orientation: Orientation = 'horizontal'): number {
|
|
14
16
|
let rect = element.getBoundingClientRect();
|
|
15
17
|
if (reverse) {
|
|
16
18
|
return orientation === 'horizontal' ? rect.right : rect.bottom;
|
package/src/index.ts
CHANGED
|
@@ -45,8 +45,11 @@ export {useEffectEvent} from './useEffectEvent';
|
|
|
45
45
|
export {useDeepMemo} from './useDeepMemo';
|
|
46
46
|
export {useFormReset} from './useFormReset';
|
|
47
47
|
export {useLoadMore} from './useLoadMore';
|
|
48
|
+
export {UNSTABLE_useLoadMoreSentinel} from './useLoadMoreSentinel';
|
|
48
49
|
export {inertValue} from './inertValue';
|
|
49
50
|
export {CLEAR_FOCUS_EVENT, FOCUS_EVENT} from './constants';
|
|
50
51
|
export {isCtrlKeyPressed} from './keyboard';
|
|
51
52
|
export {useEnterAnimation, useExitAnimation} from './animation';
|
|
52
53
|
export {isFocusable, isTabbable} from './isFocusable';
|
|
54
|
+
|
|
55
|
+
export type {LoadMoreSentinelProps} from './useLoadMoreSentinel';
|
package/src/inertValue.ts
CHANGED
package/src/isFocusable.ts
CHANGED
|
@@ -19,10 +19,10 @@ const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + '
|
|
|
19
19
|
focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
|
|
20
20
|
const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
|
|
21
21
|
|
|
22
|
-
export function isFocusable(element: Element) {
|
|
22
|
+
export function isFocusable(element: Element): boolean {
|
|
23
23
|
return element.matches(FOCUSABLE_ELEMENT_SELECTOR);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export function isTabbable(element: Element) {
|
|
26
|
+
export function isTabbable(element: Element): boolean {
|
|
27
27
|
return element.matches(TABBABLE_ELEMENT_SELECTOR);
|
|
28
28
|
}
|
package/src/isVirtualEvent.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function isVirtualClick(event: MouseEvent | PointerEvent): boolean {
|
|
|
39
39
|
return event.detail === 0 && !(event as PointerEvent).pointerType;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function isVirtualPointerEvent(event: PointerEvent) {
|
|
42
|
+
export function isVirtualPointerEvent(event: PointerEvent): boolean {
|
|
43
43
|
// If the pointer size is zero, then we assume it's from a screen reader.
|
|
44
44
|
// Android TalkBack double tap will sometimes return a event with width and height of 1
|
|
45
45
|
// and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
|
package/src/keyboard.tsx
CHANGED
package/src/mergeRefs.ts
CHANGED
|
@@ -10,23 +10,43 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {MutableRefObject, Ref} from 'react';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Merges multiple refs into one. Works with either callback or object refs.
|
|
17
17
|
*/
|
|
18
|
-
export function mergeRefs<T>(...refs: Array<
|
|
18
|
+
export function mergeRefs<T>(...refs: Array<Ref<T> | MutableRefObject<T> | null | undefined>): Ref<T> {
|
|
19
19
|
if (refs.length === 1 && refs[0]) {
|
|
20
20
|
return refs[0];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
return (value: T | null) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
let hasCleanup = false;
|
|
25
|
+
|
|
26
|
+
const cleanups = refs.map(ref => {
|
|
27
|
+
const cleanup = setRef(ref, value);
|
|
28
|
+
hasCleanup ||= typeof cleanup == 'function';
|
|
29
|
+
return cleanup;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (hasCleanup) {
|
|
33
|
+
return () => {
|
|
34
|
+
cleanups.forEach((cleanup, i) => {
|
|
35
|
+
if (typeof cleanup === 'function') {
|
|
36
|
+
cleanup();
|
|
37
|
+
} else {
|
|
38
|
+
setRef(refs[i], null);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
30
42
|
}
|
|
31
43
|
};
|
|
32
44
|
}
|
|
45
|
+
|
|
46
|
+
function setRef<T>(ref: Ref<T> | MutableRefObject<T> | null | undefined, value: T) {
|
|
47
|
+
if (typeof ref === 'function') {
|
|
48
|
+
return ref(value);
|
|
49
|
+
} else if (ref != null) {
|
|
50
|
+
ref.current = value;
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/openLink.tsx
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import {focusWithoutScrolling, isMac, isWebKit} from './index';
|
|
14
14
|
import {Href, LinkDOMProps, RouterOptions} from '@react-types/shared';
|
|
15
15
|
import {isFirefox, isIPad} from './platform';
|
|
16
|
-
import React, {createContext, ReactNode, useContext, useMemo} from 'react';
|
|
16
|
+
import React, {createContext, DOMAttributes, JSX, ReactNode, useContext, useMemo} from 'react';
|
|
17
17
|
|
|
18
18
|
interface Router {
|
|
19
19
|
isNative: boolean,
|
|
@@ -37,7 +37,7 @@ interface RouterProviderProps {
|
|
|
37
37
|
* A RouterProvider accepts a `navigate` function from a framework or client side router,
|
|
38
38
|
* and provides it to all nested React Aria links to enable client side navigation.
|
|
39
39
|
*/
|
|
40
|
-
export function RouterProvider(props: RouterProviderProps) {
|
|
40
|
+
export function RouterProvider(props: RouterProviderProps): JSX.Element {
|
|
41
41
|
let {children, navigate, useHref} = props;
|
|
42
42
|
|
|
43
43
|
let ctx = useMemo(() => ({
|
|
@@ -72,7 +72,7 @@ interface Modifiers {
|
|
|
72
72
|
shiftKey?: boolean
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export function shouldClientNavigate(link: HTMLAnchorElement, modifiers: Modifiers) {
|
|
75
|
+
export function shouldClientNavigate(link: HTMLAnchorElement, modifiers: Modifiers): boolean {
|
|
76
76
|
// Use getAttribute here instead of link.target. Firefox will default link.target to "_parent" when inside an iframe.
|
|
77
77
|
let target = link.getAttribute('target');
|
|
78
78
|
return (
|
|
@@ -86,7 +86,7 @@ export function shouldClientNavigate(link: HTMLAnchorElement, modifiers: Modifie
|
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpening = true) {
|
|
89
|
+
export function openLink(target: HTMLAnchorElement, modifiers: Modifiers, setOpening = true): void {
|
|
90
90
|
let {metaKey, ctrlKey, altKey, shiftKey} = modifiers;
|
|
91
91
|
|
|
92
92
|
// Firefox does not recognize keyboard events as a user action by default, and the popup blocker
|
|
@@ -146,7 +146,7 @@ function openSyntheticLink(target: Element, modifiers: Modifiers) {
|
|
|
146
146
|
getSyntheticLink(target, link => openLink(link, modifiers));
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
export function useSyntheticLinkProps(props: LinkDOMProps) {
|
|
149
|
+
export function useSyntheticLinkProps(props: LinkDOMProps): DOMAttributes<HTMLElement> {
|
|
150
150
|
let router = useRouter();
|
|
151
151
|
const href = router.useHref(props.href ?? '');
|
|
152
152
|
return {
|
|
@@ -156,11 +156,11 @@ export function useSyntheticLinkProps(props: LinkDOMProps) {
|
|
|
156
156
|
'data-download': props.download,
|
|
157
157
|
'data-ping': props.ping,
|
|
158
158
|
'data-referrer-policy': props.referrerPolicy
|
|
159
|
-
}
|
|
159
|
+
} as DOMAttributes<HTMLElement>;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
/** @deprecated - For backward compatibility. */
|
|
163
|
-
export function getSyntheticLinkProps(props: LinkDOMProps) {
|
|
163
|
+
export function getSyntheticLinkProps(props: LinkDOMProps): DOMAttributes<HTMLElement> {
|
|
164
164
|
return {
|
|
165
165
|
'data-href': props.href,
|
|
166
166
|
'data-target': props.target,
|
|
@@ -168,10 +168,10 @@ export function getSyntheticLinkProps(props: LinkDOMProps) {
|
|
|
168
168
|
'data-download': props.download,
|
|
169
169
|
'data-ping': props.ping,
|
|
170
170
|
'data-referrer-policy': props.referrerPolicy
|
|
171
|
-
}
|
|
171
|
+
} as DOMAttributes<HTMLElement>;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
export function useLinkProps(props?: LinkDOMProps) {
|
|
174
|
+
export function useLinkProps(props?: LinkDOMProps): LinkDOMProps {
|
|
175
175
|
let router = useRouter();
|
|
176
176
|
const href = router.useHref(props?.href ?? '');
|
|
177
177
|
return {
|
|
@@ -91,9 +91,25 @@ if (typeof document !== 'undefined') {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Cleans up any elements that are no longer in the document.
|
|
96
|
+
* This is necessary because we can't rely on transitionend events to fire
|
|
97
|
+
* for elements that are removed from the document while transitioning.
|
|
98
|
+
*/
|
|
99
|
+
function cleanupDetachedElements() {
|
|
100
|
+
for (const [eventTarget] of transitionsByElement) {
|
|
101
|
+
// Similar to `eventTarget instanceof Element && !eventTarget.isConnected`, but avoids
|
|
102
|
+
// the explicit instanceof check, since it may be different in different contexts.
|
|
103
|
+
if ('isConnected' in eventTarget && !eventTarget.isConnected) {
|
|
104
|
+
transitionsByElement.delete(eventTarget);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function runAfterTransition(fn: () => void): void {
|
|
95
110
|
// Wait one frame to see if an animation starts, e.g. a transition on mount.
|
|
96
111
|
requestAnimationFrame(() => {
|
|
112
|
+
cleanupDetachedElements();
|
|
97
113
|
// If no transitions are running, call the function immediately.
|
|
98
114
|
// Otherwise, add it to a list of callbacks to run at the end of the animation.
|
|
99
115
|
if (transitionsByElement.size === 0) {
|
package/src/scrollIntoView.ts
CHANGED
|
@@ -22,7 +22,7 @@ interface ScrollIntoViewportOpts {
|
|
|
22
22
|
* Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),
|
|
23
23
|
* but doesn't affect parents above `scrollView`.
|
|
24
24
|
*/
|
|
25
|
-
export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement) {
|
|
25
|
+
export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement): void {
|
|
26
26
|
let offsetX = relativeOffset(scrollView, element, 'left');
|
|
27
27
|
let offsetY = relativeOffset(scrollView, element, 'top');
|
|
28
28
|
let width = element.offsetWidth;
|
|
@@ -97,7 +97,7 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
|
|
|
97
97
|
* that will be centered in the viewport prior to scrolling the targetElement into view. If scrolling is prevented on
|
|
98
98
|
* the body (e.g. targetElement is in a popover), this will only scroll the scroll parents of the targetElement up to but not including the body itself.
|
|
99
99
|
*/
|
|
100
|
-
export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts) {
|
|
100
|
+
export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts): void {
|
|
101
101
|
if (targetElement && document.contains(targetElement)) {
|
|
102
102
|
let root = document.scrollingElement || document.documentElement;
|
|
103
103
|
let isScrollPrevented = window.getComputedStyle(root).overflow === 'hidden';
|
|
@@ -43,7 +43,7 @@ export function nodeContains(
|
|
|
43
43
|
/**
|
|
44
44
|
* ShadowDOM safe version of document.activeElement.
|
|
45
45
|
*/
|
|
46
|
-
export const getActiveElement = (doc: Document = document) => {
|
|
46
|
+
export const getActiveElement = (doc: Document = document): Element | null => {
|
|
47
47
|
if (!shadowDOM()) {
|
|
48
48
|
return doc.activeElement;
|
|
49
49
|
}
|
|
@@ -60,11 +60,11 @@ export const getActiveElement = (doc: Document = document) => {
|
|
|
60
60
|
/**
|
|
61
61
|
* ShadowDOM safe version of event.target.
|
|
62
62
|
*/
|
|
63
|
-
export function getEventTarget(event): Element {
|
|
64
|
-
if (shadowDOM() && event.target.shadowRoot) {
|
|
63
|
+
export function getEventTarget<T extends Event>(event: T): Element {
|
|
64
|
+
if (shadowDOM() && (event.target as HTMLElement).shadowRoot) {
|
|
65
65
|
if (event.composedPath) {
|
|
66
|
-
return event.composedPath()[0];
|
|
66
|
+
return event.composedPath()[0] as Element;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
return event.target;
|
|
69
|
+
return event.target as Element;
|
|
70
70
|
}
|
package/src/useEvent.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function useEvent<K extends keyof GlobalEventHandlersEventMap>(
|
|
|
19
19
|
event: K | (string & {}),
|
|
20
20
|
handler?: (this: Document, ev: GlobalEventHandlersEventMap[K]) => any,
|
|
21
21
|
options?: boolean | AddEventListenerOptions
|
|
22
|
-
) {
|
|
22
|
+
): void {
|
|
23
23
|
let handleEvent = useEffectEvent(handler);
|
|
24
24
|
let isDisabled = handler == null;
|
|
25
25
|
|
package/src/useFormReset.ts
CHANGED
|
@@ -18,7 +18,7 @@ export function useFormReset<T>(
|
|
|
18
18
|
ref: RefObject<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null> | undefined,
|
|
19
19
|
initialValue: T,
|
|
20
20
|
onReset: (value: T) => void
|
|
21
|
-
) {
|
|
21
|
+
): void {
|
|
22
22
|
let resetValue = useRef(initialValue);
|
|
23
23
|
let handleReset = useEffectEvent(() => {
|
|
24
24
|
if (onReset) {
|
package/src/useLoadMore.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {RefObject, useCallback, useRef} from 'react';
|
|
14
14
|
import {useEvent} from './useEvent';
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
import {useLayoutEffect} from './useLayoutEffect';
|
|
17
17
|
|
|
18
18
|
export interface LoadMoreProps {
|
|
@@ -32,7 +32,7 @@ export interface LoadMoreProps {
|
|
|
32
32
|
items?: any
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export function useLoadMore(props: LoadMoreProps, ref: RefObject<HTMLElement | null>) {
|
|
35
|
+
export function useLoadMore(props: LoadMoreProps, ref: RefObject<HTMLElement | null>): void {
|
|
36
36
|
let {isLoading, onLoadMore, scrollOffset = 1, items} = props;
|
|
37
37
|
|
|
38
38
|
// Handle scrolling, and call onLoadMore when nearing the bottom.
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import type {AsyncLoadable, Collection, Node} from '@react-types/shared';
|
|
14
|
+
import {getScrollParent} from './getScrollParent';
|
|
15
|
+
import {RefObject, useRef} from 'react';
|
|
16
|
+
import {useEffectEvent} from './useEffectEvent';
|
|
17
|
+
import {useLayoutEffect} from './useLayoutEffect';
|
|
18
|
+
|
|
19
|
+
export interface LoadMoreSentinelProps extends Omit<AsyncLoadable, 'isLoading'> {
|
|
20
|
+
collection: Collection<Node<unknown>>,
|
|
21
|
+
/**
|
|
22
|
+
* The amount of offset from the bottom of your scrollable region that should trigger load more.
|
|
23
|
+
* Uses a percentage value relative to the scroll body's client height. Load more is then triggered
|
|
24
|
+
* when your current scroll position's distance from the bottom of the currently loaded list of items is less than
|
|
25
|
+
* or equal to the provided value. (e.g. 1 = 100% of the scroll region's height).
|
|
26
|
+
* @default 1
|
|
27
|
+
*/
|
|
28
|
+
scrollOffset?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function UNSTABLE_useLoadMoreSentinel(props: LoadMoreSentinelProps, ref: RefObject<HTMLElement | null>): void {
|
|
32
|
+
let {collection, onLoadMore, scrollOffset = 1} = props;
|
|
33
|
+
|
|
34
|
+
let sentinelObserver = useRef<IntersectionObserver>(null);
|
|
35
|
+
|
|
36
|
+
let triggerLoadMore = useEffectEvent((entries: IntersectionObserverEntry[]) => {
|
|
37
|
+
// Use "isIntersecting" over an equality check of 0 since it seems like there is cases where
|
|
38
|
+
// a intersection ratio of 0 can be reported when isIntersecting is actually true
|
|
39
|
+
for (let entry of entries) {
|
|
40
|
+
// Note that this will be called if the collection changes, even if onLoadMore was already called and is being processed.
|
|
41
|
+
// Up to user discretion as to how to handle these multiple onLoadMore calls
|
|
42
|
+
if (entry.isIntersecting && onLoadMore) {
|
|
43
|
+
onLoadMore();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
if (ref.current) {
|
|
50
|
+
// Tear down and set up a new IntersectionObserver when the collection changes so that we can properly trigger additional loadMores if there is room for more items
|
|
51
|
+
// Need to do this tear down and set up since using a large rootMargin will mean the observer's callback isn't called even when scrolling the item into view beause its visibility hasn't actually changed
|
|
52
|
+
// https://codesandbox.io/p/sandbox/magical-swanson-dhgp89?file=%2Fsrc%2FApp.js%3A21%2C21
|
|
53
|
+
sentinelObserver.current = new IntersectionObserver(triggerLoadMore, {root: getScrollParent(ref?.current) as HTMLElement, rootMargin: `0px ${100 * scrollOffset}% ${100 * scrollOffset}% ${100 * scrollOffset}%`});
|
|
54
|
+
sentinelObserver.current.observe(ref.current);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return () => {
|
|
58
|
+
if (sentinelObserver.current) {
|
|
59
|
+
sentinelObserver.current.disconnect();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, [collection, triggerLoadMore, ref, scrollOffset]);
|
|
63
|
+
}
|