@react-aria/toast 3.0.0-nightly.3114 → 3.0.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/ar-AE.main.js.map +1 -1
- package/dist/ar-AE.module.js.map +1 -1
- package/dist/bg-BG.main.js.map +1 -1
- package/dist/bg-BG.module.js.map +1 -1
- package/dist/cs-CZ.main.js.map +1 -1
- package/dist/cs-CZ.module.js.map +1 -1
- package/dist/da-DK.main.js.map +1 -1
- package/dist/da-DK.module.js.map +1 -1
- package/dist/de-DE.main.js.map +1 -1
- package/dist/de-DE.module.js.map +1 -1
- package/dist/el-GR.main.js.map +1 -1
- package/dist/el-GR.module.js.map +1 -1
- package/dist/en-US.main.js.map +1 -1
- package/dist/en-US.module.js.map +1 -1
- package/dist/es-ES.main.js.map +1 -1
- package/dist/es-ES.module.js.map +1 -1
- package/dist/et-EE.main.js.map +1 -1
- package/dist/et-EE.module.js.map +1 -1
- package/dist/fi-FI.main.js.map +1 -1
- package/dist/fi-FI.module.js.map +1 -1
- package/dist/fr-FR.main.js.map +1 -1
- package/dist/fr-FR.module.js.map +1 -1
- package/dist/he-IL.main.js.map +1 -1
- package/dist/he-IL.module.js.map +1 -1
- package/dist/hr-HR.main.js.map +1 -1
- package/dist/hr-HR.module.js.map +1 -1
- package/dist/hu-HU.main.js.map +1 -1
- package/dist/hu-HU.module.js.map +1 -1
- package/dist/it-IT.main.js.map +1 -1
- package/dist/it-IT.module.js.map +1 -1
- package/dist/ja-JP.main.js.map +1 -1
- package/dist/ja-JP.module.js.map +1 -1
- package/dist/ko-KR.main.js.map +1 -1
- package/dist/ko-KR.module.js.map +1 -1
- package/dist/lt-LT.main.js.map +1 -1
- package/dist/lt-LT.module.js.map +1 -1
- package/dist/lv-LV.main.js.map +1 -1
- package/dist/lv-LV.module.js.map +1 -1
- package/dist/nb-NO.main.js.map +1 -1
- package/dist/nb-NO.module.js.map +1 -1
- package/dist/nl-NL.main.js.map +1 -1
- package/dist/nl-NL.module.js.map +1 -1
- package/dist/pl-PL.main.js.map +1 -1
- package/dist/pl-PL.module.js.map +1 -1
- package/dist/pt-BR.main.js.map +1 -1
- package/dist/pt-BR.module.js.map +1 -1
- package/dist/pt-PT.main.js.map +1 -1
- package/dist/pt-PT.module.js.map +1 -1
- package/dist/ro-RO.main.js.map +1 -1
- package/dist/ro-RO.module.js.map +1 -1
- package/dist/ru-RU.main.js.map +1 -1
- package/dist/ru-RU.module.js.map +1 -1
- package/dist/sk-SK.main.js.map +1 -1
- package/dist/sk-SK.module.js.map +1 -1
- package/dist/sl-SI.main.js.map +1 -1
- package/dist/sl-SI.module.js.map +1 -1
- package/dist/sr-SP.main.js.map +1 -1
- package/dist/sr-SP.module.js.map +1 -1
- package/dist/sv-SE.main.js.map +1 -1
- package/dist/sv-SE.module.js.map +1 -1
- package/dist/tr-TR.main.js.map +1 -1
- package/dist/tr-TR.module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js.map +1 -1
- package/dist/uk-UA.module.js.map +1 -1
- package/dist/useToast.main.js +10 -13
- package/dist/useToast.main.js.map +1 -1
- package/dist/useToast.mjs +11 -14
- package/dist/useToast.module.js +11 -14
- package/dist/useToast.module.js.map +1 -1
- package/dist/useToastRegion.main.js +60 -29
- package/dist/useToastRegion.main.js.map +1 -1
- package/dist/useToastRegion.mjs +62 -31
- package/dist/useToastRegion.module.js +62 -31
- package/dist/useToastRegion.module.js.map +1 -1
- package/dist/zh-CN.main.js.map +1 -1
- package/dist/zh-CN.module.js.map +1 -1
- package/dist/zh-TW.main.js.map +1 -1
- package/dist/zh-TW.module.js.map +1 -1
- package/package.json +11 -10
- package/src/useToast.ts +12 -16
- package/src/useToastRegion.ts +75 -41
package/dist/useToast.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $7WpW4$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
-
import $7WpW4$
|
|
2
|
+
import {useEffect as $7WpW4$useEffect, useState as $7WpW4$useState} from "react";
|
|
3
3
|
import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId} from "@react-aria/utils";
|
|
4
4
|
import {useLocalizedStringFormatter as $7WpW4$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
5
5
|
|
|
@@ -22,9 +22,9 @@ function $parcel$interopDefault(a) {
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
25
|
-
let { key: key, timer: timer, timeout: timeout
|
|
25
|
+
let { key: key, timer: timer, timeout: timeout } = props.toast;
|
|
26
26
|
(0, $7WpW4$useEffect)(()=>{
|
|
27
|
-
if (
|
|
27
|
+
if (timer == null || timeout == null) return;
|
|
28
28
|
timer.reset(timeout);
|
|
29
29
|
return ()=>{
|
|
30
30
|
timer.pause();
|
|
@@ -33,15 +33,16 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
|
33
33
|
timer,
|
|
34
34
|
timeout
|
|
35
35
|
]);
|
|
36
|
-
let [isEntered, setIsEntered] = (0, $7WpW4$react).useState(false);
|
|
37
|
-
(0, $7WpW4$useEffect)(()=>{
|
|
38
|
-
if (animation === 'entering' || animation === 'queued') setIsEntered(true);
|
|
39
|
-
}, [
|
|
40
|
-
animation
|
|
41
|
-
]);
|
|
42
36
|
let titleId = (0, $7WpW4$useId)();
|
|
43
37
|
let descriptionId = (0, $7WpW4$useSlotId)();
|
|
44
38
|
let stringFormatter = (0, $7WpW4$useLocalizedStringFormatter)((0, ($parcel$interopDefault($7WpW4$intlStringsmodulejs))), '@react-aria/toast');
|
|
39
|
+
// This is required for NVDA announcements, without it NVDA will NOT announce the toast when it appears.
|
|
40
|
+
// Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5
|
|
41
|
+
// but toasts don't always have animations.
|
|
42
|
+
let [isVisible, setIsVisible] = (0, $7WpW4$useState)(false);
|
|
43
|
+
(0, $7WpW4$useEffect)(()=>{
|
|
44
|
+
setIsVisible(true);
|
|
45
|
+
}, []);
|
|
45
46
|
return {
|
|
46
47
|
toastProps: {
|
|
47
48
|
role: 'alertdialog',
|
|
@@ -50,16 +51,12 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
|
50
51
|
'aria-labelledby': props['aria-labelledby'] || titleId,
|
|
51
52
|
'aria-describedby': props['aria-describedby'] || descriptionId,
|
|
52
53
|
'aria-details': props['aria-details'],
|
|
53
|
-
// Hide toasts that are animating out so VoiceOver doesn't announce them.
|
|
54
|
-
'aria-hidden': animation === 'exiting' ? 'true' : undefined,
|
|
55
54
|
tabIndex: 0
|
|
56
55
|
},
|
|
57
56
|
contentProps: {
|
|
58
57
|
role: 'alert',
|
|
59
58
|
'aria-atomic': 'true',
|
|
60
|
-
|
|
61
|
-
visibility: isEntered || animation === null ? 'visible' : 'hidden'
|
|
62
|
-
}
|
|
59
|
+
'aria-hidden': isVisible ? undefined : 'true'
|
|
63
60
|
},
|
|
64
61
|
titleProps: {
|
|
65
62
|
id: titleId
|
package/dist/useToast.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $7WpW4$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
-
import $7WpW4$
|
|
2
|
+
import {useEffect as $7WpW4$useEffect, useState as $7WpW4$useState} from "react";
|
|
3
3
|
import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId} from "@react-aria/utils";
|
|
4
4
|
import {useLocalizedStringFormatter as $7WpW4$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
5
5
|
|
|
@@ -22,9 +22,9 @@ function $parcel$interopDefault(a) {
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
25
|
-
let { key: key, timer: timer, timeout: timeout
|
|
25
|
+
let { key: key, timer: timer, timeout: timeout } = props.toast;
|
|
26
26
|
(0, $7WpW4$useEffect)(()=>{
|
|
27
|
-
if (
|
|
27
|
+
if (timer == null || timeout == null) return;
|
|
28
28
|
timer.reset(timeout);
|
|
29
29
|
return ()=>{
|
|
30
30
|
timer.pause();
|
|
@@ -33,15 +33,16 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
|
33
33
|
timer,
|
|
34
34
|
timeout
|
|
35
35
|
]);
|
|
36
|
-
let [isEntered, setIsEntered] = (0, $7WpW4$react).useState(false);
|
|
37
|
-
(0, $7WpW4$useEffect)(()=>{
|
|
38
|
-
if (animation === 'entering' || animation === 'queued') setIsEntered(true);
|
|
39
|
-
}, [
|
|
40
|
-
animation
|
|
41
|
-
]);
|
|
42
36
|
let titleId = (0, $7WpW4$useId)();
|
|
43
37
|
let descriptionId = (0, $7WpW4$useSlotId)();
|
|
44
38
|
let stringFormatter = (0, $7WpW4$useLocalizedStringFormatter)((0, ($parcel$interopDefault($7WpW4$intlStringsmodulejs))), '@react-aria/toast');
|
|
39
|
+
// This is required for NVDA announcements, without it NVDA will NOT announce the toast when it appears.
|
|
40
|
+
// Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5
|
|
41
|
+
// but toasts don't always have animations.
|
|
42
|
+
let [isVisible, setIsVisible] = (0, $7WpW4$useState)(false);
|
|
43
|
+
(0, $7WpW4$useEffect)(()=>{
|
|
44
|
+
setIsVisible(true);
|
|
45
|
+
}, []);
|
|
45
46
|
return {
|
|
46
47
|
toastProps: {
|
|
47
48
|
role: 'alertdialog',
|
|
@@ -50,16 +51,12 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
|
50
51
|
'aria-labelledby': props['aria-labelledby'] || titleId,
|
|
51
52
|
'aria-describedby': props['aria-describedby'] || descriptionId,
|
|
52
53
|
'aria-details': props['aria-details'],
|
|
53
|
-
// Hide toasts that are animating out so VoiceOver doesn't announce them.
|
|
54
|
-
'aria-hidden': animation === 'exiting' ? 'true' : undefined,
|
|
55
54
|
tabIndex: 0
|
|
56
55
|
},
|
|
57
56
|
contentProps: {
|
|
58
57
|
role: 'alert',
|
|
59
58
|
'aria-atomic': 'true',
|
|
60
|
-
|
|
61
|
-
visibility: isEntered || animation === null ? 'visible' : 'hidden'
|
|
62
|
-
}
|
|
59
|
+
'aria-hidden': isVisible ? undefined : 'true'
|
|
63
60
|
},
|
|
64
61
|
titleProps: {
|
|
65
62
|
id: titleId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAkCM,SAAS,0CAAY,KAAwB,EAAE,KAAoB,EAAE,GAAuC;IACjH,IAAI,OACF,GAAG,SACH,KAAK,WACL,OAAO,
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAkCM,SAAS,0CAAY,KAAwB,EAAE,KAAoB,EAAE,GAAuC;IACjH,IAAI,OACF,GAAG,SACH,KAAK,WACL,OAAO,EACR,GAAG,MAAM,KAAK;IAEf,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,SAAS,QAAQ,WAAW,MAC9B;QAGF,MAAM,KAAK,CAAC;QACZ,OAAO;YACL,MAAM,KAAK;QACb;IACF,GAAG;QAAC;QAAO;KAAQ;IAEnB,IAAI,UAAU,CAAA,GAAA,YAAI;IAClB,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAC5B,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAEhE,wGAAwG;IACxG,mJAAmJ;IACnJ,2CAA2C;IAC3C,IAAI,CAAC,WAAW,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IACzC,CAAA,GAAA,gBAAQ,EAAE;QACR,aAAa;IACf,GAAG,EAAE;IAEL,OAAO;QACL,YAAY;YACV,MAAM;YACN,cAAc;YACd,cAAc,KAAK,CAAC,aAAa;YACjC,mBAAmB,KAAK,CAAC,kBAAkB,IAAI;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB,IAAI;YACjD,gBAAgB,KAAK,CAAC,eAAe;YACrC,UAAU;QACZ;QACA,cAAc;YACZ,MAAM;YACN,eAAe;YACf,eAAe,YAAY,YAAY;QACzC;QACA,YAAY;YACV,IAAI;QACN;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,kBAAkB;YAChB,cAAc,gBAAgB,MAAM,CAAC;YACrC,SAAS,IAAM,MAAM,KAAK,CAAC;QAC7B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToast.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport {useEffect, useState} from 'react';\nimport {useId, useSlotId} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastProps<T> extends AriaLabelingProps {\n /** The toast object. */\n toast: QueuedToast<T>\n}\n\nexport interface ToastAria {\n /** Props for the toast container, non-modal dialog element. */\n toastProps: DOMAttributes,\n /** Props for the toast content alert message. */\n contentProps: DOMAttributes,\n /** Props for the toast title element. */\n titleProps: DOMAttributes,\n /** Props for the toast description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the toast close button. */\n closeButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast component.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement | null>): ToastAria {\n let {\n key,\n timer,\n timeout\n } = props.toast;\n\n useEffect(() => {\n if (timer == null || timeout == null) {\n return;\n }\n\n timer.reset(timeout);\n return () => {\n timer.pause();\n };\n }, [timer, timeout]);\n\n let titleId = useId();\n let descriptionId = useSlotId();\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n\n // This is required for NVDA announcements, without it NVDA will NOT announce the toast when it appears.\n // Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5\n // but toasts don't always have animations.\n let [isVisible, setIsVisible] = useState(false);\n useEffect(() => {\n setIsVisible(true);\n }, []);\n\n return {\n toastProps: {\n role: 'alertdialog',\n 'aria-modal': 'false',\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n 'aria-describedby': props['aria-describedby'] || descriptionId,\n 'aria-details': props['aria-details'],\n tabIndex: 0\n },\n contentProps: {\n role: 'alert',\n 'aria-atomic': 'true',\n 'aria-hidden': isVisible ? undefined : 'true'\n },\n titleProps: {\n id: titleId\n },\n descriptionProps: {\n id: descriptionId\n },\n closeButtonProps: {\n 'aria-label': stringFormatter.format('close'),\n onPress: () => state.close(key)\n }\n };\n}\n"],"names":[],"version":3,"file":"useToast.module.js.map"}
|
|
@@ -15,7 +15,17 @@ function $parcel$export(e, n, v, s) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
$parcel$export(module.exports, "useToastRegion", () => $eda7c6204a682dd4$export$b8cbbb20a51697de);
|
|
18
|
-
|
|
18
|
+
/*
|
|
19
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
20
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
22
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
23
|
+
*
|
|
24
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
25
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
26
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
27
|
+
* governing permissions and limitations under the License.
|
|
28
|
+
*/
|
|
19
29
|
|
|
20
30
|
|
|
21
31
|
|
|
@@ -29,20 +39,30 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
29
39
|
count: state.visibleToasts.length
|
|
30
40
|
})
|
|
31
41
|
}, ref);
|
|
42
|
+
let isHovered = (0, $eO7VF$react.useRef)(false);
|
|
43
|
+
let isFocused = (0, $eO7VF$react.useRef)(false);
|
|
44
|
+
let updateTimers = (0, $eO7VF$reactariautils.useEffectEvent)(()=>{
|
|
45
|
+
if (isHovered.current || isFocused.current) state.pauseAll();
|
|
46
|
+
else state.resumeAll();
|
|
47
|
+
});
|
|
32
48
|
let { hoverProps: hoverProps } = (0, $eO7VF$reactariainteractions.useHover)({
|
|
33
|
-
onHoverStart:
|
|
34
|
-
|
|
49
|
+
onHoverStart: ()=>{
|
|
50
|
+
isHovered.current = true;
|
|
51
|
+
updateTimers();
|
|
52
|
+
},
|
|
53
|
+
onHoverEnd: ()=>{
|
|
54
|
+
isHovered.current = false;
|
|
55
|
+
updateTimers();
|
|
56
|
+
}
|
|
35
57
|
});
|
|
36
58
|
// Manage focus within the toast region.
|
|
37
59
|
// If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.
|
|
38
|
-
// We might be making an assumption with how this works if someone implements the priority queue differently, or
|
|
39
|
-
// if they only show one toast at a time.
|
|
40
60
|
let toasts = (0, $eO7VF$react.useRef)([]);
|
|
41
61
|
let prevVisibleToasts = (0, $eO7VF$react.useRef)(state.visibleToasts);
|
|
42
62
|
let focusedToast = (0, $eO7VF$react.useRef)(null);
|
|
43
63
|
(0, $eO7VF$reactariautils.useLayoutEffect)(()=>{
|
|
44
64
|
// If no toast has focus, then don't do anything.
|
|
45
|
-
if (focusedToast.current === -1 || state.visibleToasts.length === 0) {
|
|
65
|
+
if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {
|
|
46
66
|
toasts.current = [];
|
|
47
67
|
prevVisibleToasts.current = state.visibleToasts;
|
|
48
68
|
return;
|
|
@@ -61,43 +81,52 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
61
81
|
i: i,
|
|
62
82
|
isRemoved: !state.visibleToasts.some((t2)=>t.key === t2.key)
|
|
63
83
|
}));
|
|
64
|
-
let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current);
|
|
84
|
+
let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current && t.isRemoved);
|
|
65
85
|
// If the focused toast was removed, focus the next or previous toast.
|
|
66
86
|
if (removedFocusedToastIndex > -1) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
i
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
87
|
+
var _lastFocused_current;
|
|
88
|
+
// In pointer modality, move focus out of the toast region.
|
|
89
|
+
// Otherwise auto-dismiss timers will appear "stuck".
|
|
90
|
+
if ((0, $eO7VF$reactariainteractions.getInteractionModality)() === 'pointer' && ((_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.isConnected)) (0, $eO7VF$reactariautils.focusWithoutScrolling)(lastFocused.current);
|
|
91
|
+
else {
|
|
92
|
+
let i = 0;
|
|
93
|
+
let nextToast;
|
|
94
|
+
let prevToast;
|
|
95
|
+
while(i <= removedFocusedToastIndex){
|
|
96
|
+
if (!allToasts[i].isRemoved) prevToast = Math.max(0, i - 1);
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
while(i < allToasts.length){
|
|
100
|
+
if (!allToasts[i].isRemoved) {
|
|
101
|
+
nextToast = i - 1;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
i++;
|
|
78
105
|
}
|
|
79
|
-
|
|
106
|
+
// in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
|
|
107
|
+
if (prevToast === undefined && nextToast === undefined) prevToast = 0;
|
|
108
|
+
// prioritize going to newer toasts
|
|
109
|
+
if (prevToast >= 0 && prevToast < toasts.current.length) (0, $eO7VF$reactariautils.focusWithoutScrolling)(toasts.current[prevToast]);
|
|
110
|
+
else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $eO7VF$reactariautils.focusWithoutScrolling)(toasts.current[nextToast]);
|
|
80
111
|
}
|
|
81
|
-
// in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
|
|
82
|
-
if (prevToast === undefined && nextToast === undefined) prevToast = 0;
|
|
83
|
-
// prioritize going to newer toasts
|
|
84
|
-
if (prevToast >= 0 && prevToast < toasts.current.length) (0, $eO7VF$reactariautils.focusWithoutScrolling)(toasts.current[prevToast]);
|
|
85
|
-
else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $eO7VF$reactariautils.focusWithoutScrolling)(toasts.current[nextToast]);
|
|
86
112
|
}
|
|
87
113
|
prevVisibleToasts.current = state.visibleToasts;
|
|
88
114
|
}, [
|
|
89
115
|
state.visibleToasts,
|
|
90
|
-
ref
|
|
116
|
+
ref,
|
|
117
|
+
updateTimers
|
|
91
118
|
]);
|
|
92
119
|
let lastFocused = (0, $eO7VF$react.useRef)(null);
|
|
93
120
|
let { focusWithinProps: focusWithinProps } = (0, $eO7VF$reactariainteractions.useFocusWithin)({
|
|
94
121
|
onFocusWithin: (e)=>{
|
|
95
|
-
|
|
122
|
+
isFocused.current = true;
|
|
96
123
|
lastFocused.current = e.relatedTarget;
|
|
124
|
+
updateTimers();
|
|
97
125
|
},
|
|
98
126
|
onBlurWithin: ()=>{
|
|
99
|
-
|
|
127
|
+
isFocused.current = false;
|
|
100
128
|
lastFocused.current = null;
|
|
129
|
+
updateTimers();
|
|
101
130
|
}
|
|
102
131
|
});
|
|
103
132
|
// When the number of visible toasts becomes 0 or the region unmounts,
|
|
@@ -106,7 +135,8 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
106
135
|
// moves in, it only happens once, so we correct it.
|
|
107
136
|
// Because we're in a hook, we can't control if the user unmounts or not.
|
|
108
137
|
(0, $eO7VF$react.useEffect)(()=>{
|
|
109
|
-
|
|
138
|
+
var _lastFocused_current;
|
|
139
|
+
if (state.visibleToasts.length === 0 && ((_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.isConnected)) {
|
|
110
140
|
if ((0, $eO7VF$reactariainteractions.getInteractionModality)() === 'pointer') (0, $eO7VF$reactariautils.focusWithoutScrolling)(lastFocused.current);
|
|
111
141
|
else lastFocused.current.focus();
|
|
112
142
|
lastFocused.current = null;
|
|
@@ -117,7 +147,8 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
117
147
|
]);
|
|
118
148
|
(0, $eO7VF$react.useEffect)(()=>{
|
|
119
149
|
return ()=>{
|
|
120
|
-
|
|
150
|
+
var _lastFocused_current;
|
|
151
|
+
if ((_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.isConnected) {
|
|
121
152
|
if ((0, $eO7VF$reactariainteractions.getInteractionModality)() === 'pointer') (0, $eO7VF$reactariautils.focusWithoutScrolling)(lastFocused.current);
|
|
122
153
|
else lastFocused.current.focus();
|
|
123
154
|
lastFocused.current = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BO,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAAkC;IACrH,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;I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KAAK,KAAK,YAAY,OAAO,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,YAAY,OAAO,GAAG;YAC1G,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,CAAA,GAAA,2CAAoB,EAAE,YAAY,OAAO;iBAEzC,YAAY,OAAO,CAAC,KAAK;YAE3B,YAAY,OAAO,GAAG;QACxB;IACF,GAAG;QAAC;QAAK,MAAM,aAAa,CAAC,MAAM;KAAC;IAEpC,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,YAAY,OAAO,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,YAAY,OAAO,GAAG;gBACtE,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,CAAA,GAAA,2CAAoB,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;gBAE3B,YAAY,OAAO,GAAG;YACxB;QACF;IACF,GAAG;QAAC;KAAI;IAER,OAAO;QACL,aAAa,CAAA,GAAA,gCAAS,EAAE,eAAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B;YAC7B,oFAAoF;YACpF,0CAA0C;YAC1C,SAAS,CAAC;gBACR,IAAI,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC;gBAC9B,aAAa,OAAO,GAAG,OAAO,OAAO,CAAC,SAAS,CAAC,CAAA,IAAK,MAAM;YAC7D;YACA,QAAQ;gBACN,aAAa,OAAO,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/@react-aria/toast/src/useToastRegion.ts"],"sourcesContent":["import {AriaLabelingProps, DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ToastState} from '@react-stately/toast';\nimport {useEffect, useRef} from 'react';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement | null>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {count: state.visibleToasts.length})\n }, ref);\n\n let {hoverProps} = useHover({\n onHoverStart: state.pauseAll,\n onHoverEnd: state.resumeAll\n });\n\n // Manage focus within the toast region.\n // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.\n // We might be making an assumption with how this works if someone implements the priority queue differently, or\n // if they only show one toast at a time.\n let toasts = useRef([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')];\n // If the visible toasts haven't changed, we don't need to do anything.\n if (prevVisibleToasts.current.length === state.visibleToasts.length\n && state.visibleToasts.every((t, i) => t.key === prevVisibleToasts.current[i].key)) {\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n // Get a list of all toasts by index and add info if they are removed.\n let allToasts = prevVisibleToasts.current\n .map((t, i) => ({\n ...t,\n i,\n isRemoved: !state.visibleToasts.some(t2 => t.key === t2.key)\n }));\n\n let removedFocusedToastIndex = allToasts.findIndex(t => t.i === focusedToast.current);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n let i = 0;\n let nextToast;\n let prevToast;\n while (i <= removedFocusedToastIndex) {\n if (!allToasts[i].isRemoved) {\n prevToast = Math.max(0, i - 1);\n }\n i++;\n }\n while (i < allToasts.length) {\n if (!allToasts[i].isRemoved) {\n nextToast = i - 1;\n break;\n }\n i++;\n }\n\n // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0\n if (prevToast === undefined && nextToast === undefined) {\n prevToast = 0;\n }\n\n // prioritize going to newer toasts\n if (prevToast >= 0 && prevToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[prevToast]);\n } else if (nextToast >= 0 && nextToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[nextToast]);\n }\n }\n\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n state.pauseAll();\n lastFocused.current = e.relatedTarget;\n },\n onBlurWithin: () => {\n state.resumeAll();\n lastFocused.current = null;\n }\n });\n\n // When the number of visible toasts becomes 0 or the region unmounts,\n // restore focus to the last element that had focus before the user moved focus\n // into the region. FocusScope restore focus doesn't update whenever the focus\n // moves in, it only happens once, so we correct it.\n // Because we're in a hook, we can't control if the user unmounts or not.\n useEffect(() => {\n if (state.visibleToasts.length === 0 && lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n }, [ref, state.visibleToasts.length]);\n\n useEffect(() => {\n return () => {\n if (lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true,\n // listen to focus events separate from focuswithin because that will only fire once\n // and we need to follow all focus changes\n onFocus: (e) => {\n let target = e.target.closest('[role=\"alertdialog\"]');\n focusedToast.current = toasts.current.findIndex(t => t === target);\n },\n onBlur: () => {\n focusedToast.current = -1;\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useToastRegion.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAAkC;IACrH,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,oCAAU,EAAE;QAChC,MAAM;QACN,cAAc,KAAK,CAAC,aAAa,IAAI,gBAAgB,MAAM,CAAC,iBAAiB;YAAC,OAAO,MAAM,aAAa,CAAC,MAAM;QAAA;IACjH,GAAG;IAEH,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,eAAe,CAAA,GAAA,oCAAa,EAAE;QAChC,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,QAAQ;aAEd,MAAM,SAAS;IAEnB;IAEA,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QAC1B,cAAc;YACZ,UAAU,OAAO,GAAG;YACpB;QACF;QACA,YAAY;YACV,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,wCAAwC;IACxC,2HAA2H;IAC3H,IAAI,SAAS,CAAA,GAAA,mBAAK,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B,EAAE,YAAY,OAAO;iBAEzC,YAAY,OAAO,CAAC,KAAK;YAE3B,YAAY,OAAO,GAAG;QACxB;IACF,GAAG;QAAC;QAAK,MAAM,aAAa,CAAC,MAAM;KAAC;IAEpC,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;gBACD;YAAJ,KAAI,uBAAA,YAAY,OAAO,cAAnB,2CAAA,qBAAqB,WAAW,EAAE;gBACpC,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,CAAA,GAAA,2CAAoB,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;gBAE3B,YAAY,OAAO,GAAG;YACxB;QACF;IACF,GAAG;QAAC;KAAI;IAER,OAAO;QACL,aAAa,CAAA,GAAA,gCAAS,EAAE,eAAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B;YAC7B,oFAAoF;YACpF,0CAA0C;YAC1C,SAAS,CAAC;gBACR,IAAI,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC;gBAC9B,aAAa,OAAO,GAAG,OAAO,OAAO,CAAC,SAAS,CAAC,CAAA,IAAK,MAAM;YAC7D;YACA,QAAQ;gBACN,aAAa,OAAO,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/@react-aria/toast/src/useToastRegion.ts"],"sourcesContent":["/*\n * Copyright 2025 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 {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useEffectEvent, useLayoutEffect} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ToastState} from '@react-stately/toast';\nimport {useEffect, useRef} from 'react';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement | null>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {count: state.visibleToasts.length})\n }, ref);\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useEffectEvent(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n });\n\n let {hoverProps} = useHover({\n onHoverStart: () => {\n isHovered.current = true;\n updateTimers();\n },\n onHoverEnd: () => {\n isHovered.current = false;\n updateTimers();\n }\n });\n\n // Manage focus within the toast region.\n // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.\n let toasts = useRef<FocusableElement[]>([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef<number | null>(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')] as FocusableElement[];\n // If the visible toasts haven't changed, we don't need to do anything.\n if (prevVisibleToasts.current.length === state.visibleToasts.length\n && state.visibleToasts.every((t, i) => t.key === prevVisibleToasts.current[i].key)) {\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n // Get a list of all toasts by index and add info if they are removed.\n let allToasts = prevVisibleToasts.current\n .map((t, i) => ({\n ...t,\n i,\n isRemoved: !state.visibleToasts.some(t2 => t.key === t2.key)\n }));\n\n let removedFocusedToastIndex = allToasts.findIndex(t => t.i === focusedToast.current && t.isRemoved);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n // In pointer modality, move focus out of the toast region.\n // Otherwise auto-dismiss timers will appear \"stuck\".\n if (getInteractionModality() === 'pointer' && lastFocused.current?.isConnected) {\n focusWithoutScrolling(lastFocused.current);\n } else {\n let i = 0;\n let nextToast;\n let prevToast;\n while (i <= removedFocusedToastIndex) {\n if (!allToasts[i].isRemoved) {\n prevToast = Math.max(0, i - 1);\n }\n i++;\n }\n while (i < allToasts.length) {\n if (!allToasts[i].isRemoved) {\n nextToast = i - 1;\n break;\n }\n i++;\n }\n\n // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0\n if (prevToast === undefined && nextToast === undefined) {\n prevToast = 0;\n }\n\n // prioritize going to newer toasts\n if (prevToast >= 0 && prevToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[prevToast]);\n } else if (nextToast >= 0 && nextToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[nextToast]);\n }\n }\n }\n\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref, updateTimers]);\n\n let lastFocused = useRef<FocusableElement | null>(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n isFocused.current = true;\n lastFocused.current = e.relatedTarget as FocusableElement;\n updateTimers();\n },\n onBlurWithin: () => {\n isFocused.current = false;\n lastFocused.current = null;\n updateTimers();\n }\n });\n\n // When the number of visible toasts becomes 0 or the region unmounts,\n // restore focus to the last element that had focus before the user moved focus\n // into the region. FocusScope restore focus doesn't update whenever the focus\n // moves in, it only happens once, so we correct it.\n // Because we're in a hook, we can't control if the user unmounts or not.\n useEffect(() => {\n if (state.visibleToasts.length === 0 && lastFocused.current?.isConnected) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n }, [ref, state.visibleToasts.length]);\n\n useEffect(() => {\n return () => {\n if (lastFocused.current?.isConnected) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true,\n // listen to focus events separate from focuswithin because that will only fire once\n // and we need to follow all focus changes\n onFocus: (e) => {\n let target = e.target.closest('[role=\"alertdialog\"]');\n focusedToast.current = toasts.current.findIndex(t => t === target);\n },\n onBlur: () => {\n focusedToast.current = -1;\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useToastRegion.main.js.map"}
|
package/dist/useToastRegion.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import $ckyCP$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
-
import {useLayoutEffect as $ckyCP$useLayoutEffect, focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
|
|
3
|
-
import {useHover as $ckyCP$useHover,
|
|
2
|
+
import {useEffectEvent as $ckyCP$useEffectEvent, useLayoutEffect as $ckyCP$useLayoutEffect, focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
|
|
3
|
+
import {useHover as $ckyCP$useHover, getInteractionModality as $ckyCP$getInteractionModality, useFocusWithin as $ckyCP$useFocusWithin} from "@react-aria/interactions";
|
|
4
4
|
import {useRef as $ckyCP$useRef, useEffect as $ckyCP$useEffect} from "react";
|
|
5
5
|
import {useLandmark as $ckyCP$useLandmark} from "@react-aria/landmark";
|
|
6
6
|
import {useLocalizedStringFormatter as $ckyCP$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
@@ -9,7 +9,17 @@ import {useLocalizedStringFormatter as $ckyCP$useLocalizedStringFormatter} from
|
|
|
9
9
|
function $parcel$interopDefault(a) {
|
|
10
10
|
return a && a.__esModule ? a.default : a;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
13
23
|
|
|
14
24
|
|
|
15
25
|
|
|
@@ -23,20 +33,30 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
23
33
|
count: state.visibleToasts.length
|
|
24
34
|
})
|
|
25
35
|
}, ref);
|
|
36
|
+
let isHovered = (0, $ckyCP$useRef)(false);
|
|
37
|
+
let isFocused = (0, $ckyCP$useRef)(false);
|
|
38
|
+
let updateTimers = (0, $ckyCP$useEffectEvent)(()=>{
|
|
39
|
+
if (isHovered.current || isFocused.current) state.pauseAll();
|
|
40
|
+
else state.resumeAll();
|
|
41
|
+
});
|
|
26
42
|
let { hoverProps: hoverProps } = (0, $ckyCP$useHover)({
|
|
27
|
-
onHoverStart:
|
|
28
|
-
|
|
43
|
+
onHoverStart: ()=>{
|
|
44
|
+
isHovered.current = true;
|
|
45
|
+
updateTimers();
|
|
46
|
+
},
|
|
47
|
+
onHoverEnd: ()=>{
|
|
48
|
+
isHovered.current = false;
|
|
49
|
+
updateTimers();
|
|
50
|
+
}
|
|
29
51
|
});
|
|
30
52
|
// Manage focus within the toast region.
|
|
31
53
|
// If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.
|
|
32
|
-
// We might be making an assumption with how this works if someone implements the priority queue differently, or
|
|
33
|
-
// if they only show one toast at a time.
|
|
34
54
|
let toasts = (0, $ckyCP$useRef)([]);
|
|
35
55
|
let prevVisibleToasts = (0, $ckyCP$useRef)(state.visibleToasts);
|
|
36
56
|
let focusedToast = (0, $ckyCP$useRef)(null);
|
|
37
57
|
(0, $ckyCP$useLayoutEffect)(()=>{
|
|
38
58
|
// If no toast has focus, then don't do anything.
|
|
39
|
-
if (focusedToast.current === -1 || state.visibleToasts.length === 0) {
|
|
59
|
+
if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {
|
|
40
60
|
toasts.current = [];
|
|
41
61
|
prevVisibleToasts.current = state.visibleToasts;
|
|
42
62
|
return;
|
|
@@ -55,43 +75,52 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
55
75
|
i: i,
|
|
56
76
|
isRemoved: !state.visibleToasts.some((t2)=>t.key === t2.key)
|
|
57
77
|
}));
|
|
58
|
-
let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current);
|
|
78
|
+
let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current && t.isRemoved);
|
|
59
79
|
// If the focused toast was removed, focus the next or previous toast.
|
|
60
80
|
if (removedFocusedToastIndex > -1) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
i
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
81
|
+
var _lastFocused_current;
|
|
82
|
+
// In pointer modality, move focus out of the toast region.
|
|
83
|
+
// Otherwise auto-dismiss timers will appear "stuck".
|
|
84
|
+
if ((0, $ckyCP$getInteractionModality)() === 'pointer' && ((_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.isConnected)) (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
|
|
85
|
+
else {
|
|
86
|
+
let i = 0;
|
|
87
|
+
let nextToast;
|
|
88
|
+
let prevToast;
|
|
89
|
+
while(i <= removedFocusedToastIndex){
|
|
90
|
+
if (!allToasts[i].isRemoved) prevToast = Math.max(0, i - 1);
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
while(i < allToasts.length){
|
|
94
|
+
if (!allToasts[i].isRemoved) {
|
|
95
|
+
nextToast = i - 1;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
i++;
|
|
72
99
|
}
|
|
73
|
-
|
|
100
|
+
// in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
|
|
101
|
+
if (prevToast === undefined && nextToast === undefined) prevToast = 0;
|
|
102
|
+
// prioritize going to newer toasts
|
|
103
|
+
if (prevToast >= 0 && prevToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[prevToast]);
|
|
104
|
+
else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[nextToast]);
|
|
74
105
|
}
|
|
75
|
-
// in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
|
|
76
|
-
if (prevToast === undefined && nextToast === undefined) prevToast = 0;
|
|
77
|
-
// prioritize going to newer toasts
|
|
78
|
-
if (prevToast >= 0 && prevToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[prevToast]);
|
|
79
|
-
else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[nextToast]);
|
|
80
106
|
}
|
|
81
107
|
prevVisibleToasts.current = state.visibleToasts;
|
|
82
108
|
}, [
|
|
83
109
|
state.visibleToasts,
|
|
84
|
-
ref
|
|
110
|
+
ref,
|
|
111
|
+
updateTimers
|
|
85
112
|
]);
|
|
86
113
|
let lastFocused = (0, $ckyCP$useRef)(null);
|
|
87
114
|
let { focusWithinProps: focusWithinProps } = (0, $ckyCP$useFocusWithin)({
|
|
88
115
|
onFocusWithin: (e)=>{
|
|
89
|
-
|
|
116
|
+
isFocused.current = true;
|
|
90
117
|
lastFocused.current = e.relatedTarget;
|
|
118
|
+
updateTimers();
|
|
91
119
|
},
|
|
92
120
|
onBlurWithin: ()=>{
|
|
93
|
-
|
|
121
|
+
isFocused.current = false;
|
|
94
122
|
lastFocused.current = null;
|
|
123
|
+
updateTimers();
|
|
95
124
|
}
|
|
96
125
|
});
|
|
97
126
|
// When the number of visible toasts becomes 0 or the region unmounts,
|
|
@@ -100,7 +129,8 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
100
129
|
// moves in, it only happens once, so we correct it.
|
|
101
130
|
// Because we're in a hook, we can't control if the user unmounts or not.
|
|
102
131
|
(0, $ckyCP$useEffect)(()=>{
|
|
103
|
-
|
|
132
|
+
var _lastFocused_current;
|
|
133
|
+
if (state.visibleToasts.length === 0 && ((_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.isConnected)) {
|
|
104
134
|
if ((0, $ckyCP$getInteractionModality)() === 'pointer') (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
|
|
105
135
|
else lastFocused.current.focus();
|
|
106
136
|
lastFocused.current = null;
|
|
@@ -111,7 +141,8 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
111
141
|
]);
|
|
112
142
|
(0, $ckyCP$useEffect)(()=>{
|
|
113
143
|
return ()=>{
|
|
114
|
-
|
|
144
|
+
var _lastFocused_current;
|
|
145
|
+
if ((_lastFocused_current = lastFocused.current) === null || _lastFocused_current === void 0 ? void 0 : _lastFocused_current.isConnected) {
|
|
115
146
|
if ((0, $ckyCP$getInteractionModality)() === 'pointer') (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
|
|
116
147
|
else lastFocused.current.focus();
|
|
117
148
|
lastFocused.current = null;
|