@radix-ui/react-toast 0.1.2-rc.8 → 1.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/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +718 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +697 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +16 -16
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,698 @@
|
|
|
1
|
-
import
|
|
1
|
+
import $eyrYI$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import {useState as $eyrYI$useState, useRef as $eyrYI$useRef, createElement as $eyrYI$createElement, useCallback as $eyrYI$useCallback, forwardRef as $eyrYI$forwardRef, useEffect as $eyrYI$useEffect, Fragment as $eyrYI$Fragment, useMemo as $eyrYI$useMemo} from "react";
|
|
3
|
+
import {createPortal as $eyrYI$createPortal} from "react-dom";
|
|
4
|
+
import {composeEventHandlers as $eyrYI$composeEventHandlers} from "@radix-ui/primitive";
|
|
5
|
+
import {useComposedRefs as $eyrYI$useComposedRefs} from "@radix-ui/react-compose-refs";
|
|
6
|
+
import {createCollection as $eyrYI$createCollection} from "@radix-ui/react-collection";
|
|
7
|
+
import {createContextScope as $eyrYI$createContextScope} from "@radix-ui/react-context";
|
|
8
|
+
import {Branch as $eyrYI$Branch, Root as $eyrYI$Root} from "@radix-ui/react-dismissable-layer";
|
|
9
|
+
import {Portal as $eyrYI$Portal} from "@radix-ui/react-portal";
|
|
10
|
+
import {Presence as $eyrYI$Presence} from "@radix-ui/react-presence";
|
|
11
|
+
import {Primitive as $eyrYI$Primitive, dispatchDiscreteCustomEvent as $eyrYI$dispatchDiscreteCustomEvent} from "@radix-ui/react-primitive";
|
|
12
|
+
import {useCallbackRef as $eyrYI$useCallbackRef} from "@radix-ui/react-use-callback-ref";
|
|
13
|
+
import {useControllableState as $eyrYI$useControllableState} from "@radix-ui/react-use-controllable-state";
|
|
14
|
+
import {useLayoutEffect as $eyrYI$useLayoutEffect} from "@radix-ui/react-use-layout-effect";
|
|
15
|
+
import {VisuallyHidden as $eyrYI$VisuallyHidden} from "@radix-ui/react-visually-hidden";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/* -------------------------------------------------------------------------------------------------
|
|
33
|
+
* ToastProvider
|
|
34
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$PROVIDER_NAME = 'ToastProvider';
|
|
35
|
+
const [$054eb8030ebde76e$var$Collection, $054eb8030ebde76e$var$useCollection, $054eb8030ebde76e$var$createCollectionScope] = $eyrYI$createCollection('Toast');
|
|
36
|
+
const [$054eb8030ebde76e$var$createToastContext, $054eb8030ebde76e$export$8a359da18fbc9073] = $eyrYI$createContextScope('Toast', [
|
|
37
|
+
$054eb8030ebde76e$var$createCollectionScope
|
|
38
|
+
]);
|
|
39
|
+
const [$054eb8030ebde76e$var$ToastProviderProvider, $054eb8030ebde76e$var$useToastProviderContext] = $054eb8030ebde76e$var$createToastContext($054eb8030ebde76e$var$PROVIDER_NAME);
|
|
40
|
+
const $054eb8030ebde76e$export$f5d03d415824e0e = (props)=>{
|
|
41
|
+
const { __scopeToast: __scopeToast , label: label = 'Notification' , duration: duration = 5000 , swipeDirection: swipeDirection = 'right' , swipeThreshold: swipeThreshold = 50 , children: children } = props;
|
|
42
|
+
const [viewport, setViewport] = $eyrYI$useState(null);
|
|
43
|
+
const [toastCount, setToastCount] = $eyrYI$useState(0);
|
|
44
|
+
const isFocusedToastEscapeKeyDownRef = $eyrYI$useRef(false);
|
|
45
|
+
const isClosePausedRef = $eyrYI$useRef(false);
|
|
46
|
+
return /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$Collection.Provider, {
|
|
47
|
+
scope: __scopeToast
|
|
48
|
+
}, /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastProviderProvider, {
|
|
49
|
+
scope: __scopeToast,
|
|
50
|
+
label: label,
|
|
51
|
+
duration: duration,
|
|
52
|
+
swipeDirection: swipeDirection,
|
|
53
|
+
swipeThreshold: swipeThreshold,
|
|
54
|
+
toastCount: toastCount,
|
|
55
|
+
viewport: viewport,
|
|
56
|
+
onViewportChange: setViewport,
|
|
57
|
+
onToastAdd: $eyrYI$useCallback(()=>setToastCount((prevCount)=>prevCount + 1
|
|
58
|
+
)
|
|
59
|
+
, []),
|
|
60
|
+
onToastRemove: $eyrYI$useCallback(()=>setToastCount((prevCount)=>prevCount - 1
|
|
61
|
+
)
|
|
62
|
+
, []),
|
|
63
|
+
isFocusedToastEscapeKeyDownRef: isFocusedToastEscapeKeyDownRef,
|
|
64
|
+
isClosePausedRef: isClosePausedRef
|
|
65
|
+
}, children));
|
|
66
|
+
};
|
|
67
|
+
$054eb8030ebde76e$export$f5d03d415824e0e.propTypes = {
|
|
68
|
+
label (props) {
|
|
69
|
+
if (props.label && typeof props.label === 'string' && !props.label.trim()) {
|
|
70
|
+
const error = `Invalid prop \`label\` supplied to \`${$054eb8030ebde76e$var$PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
|
|
71
|
+
return new Error(error);
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$f5d03d415824e0e, {
|
|
77
|
+
displayName: $054eb8030ebde76e$var$PROVIDER_NAME
|
|
78
|
+
});
|
|
79
|
+
/* -------------------------------------------------------------------------------------------------
|
|
80
|
+
* ToastViewport
|
|
81
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$VIEWPORT_NAME = 'ToastViewport';
|
|
82
|
+
const $054eb8030ebde76e$var$VIEWPORT_DEFAULT_HOTKEY = [
|
|
83
|
+
'F8'
|
|
84
|
+
];
|
|
85
|
+
const $054eb8030ebde76e$var$VIEWPORT_PAUSE = 'toast.viewportPause';
|
|
86
|
+
const $054eb8030ebde76e$var$VIEWPORT_RESUME = 'toast.viewportResume';
|
|
87
|
+
const $054eb8030ebde76e$export$6192c2425ecfd989 = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
88
|
+
const { __scopeToast: __scopeToast , hotkey: hotkey = $054eb8030ebde76e$var$VIEWPORT_DEFAULT_HOTKEY , label: label = 'Notifications ({hotkey})' , ...viewportProps } = props;
|
|
89
|
+
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$VIEWPORT_NAME, __scopeToast);
|
|
90
|
+
const getItems = $054eb8030ebde76e$var$useCollection(__scopeToast);
|
|
91
|
+
const wrapperRef = $eyrYI$useRef(null);
|
|
92
|
+
const headFocusProxyRef = $eyrYI$useRef(null);
|
|
93
|
+
const tailFocusProxyRef = $eyrYI$useRef(null);
|
|
94
|
+
const ref = $eyrYI$useRef(null);
|
|
95
|
+
const composedRefs = $eyrYI$useComposedRefs(forwardedRef, ref, context.onViewportChange);
|
|
96
|
+
const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
|
|
97
|
+
const hasToasts = context.toastCount > 0;
|
|
98
|
+
$eyrYI$useEffect(()=>{
|
|
99
|
+
const handleKeyDown = (event)=>{
|
|
100
|
+
var _ref$current;
|
|
101
|
+
// we use `event.code` as it is consistent regardless of meta keys that were pressed.
|
|
102
|
+
// for example, `event.key` for `Control+Alt+t` is `†` and `t !== †`
|
|
103
|
+
const isHotkeyPressed = hotkey.every((key)=>event[key] || event.code === key
|
|
104
|
+
);
|
|
105
|
+
if (isHotkeyPressed) (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.focus();
|
|
106
|
+
};
|
|
107
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
108
|
+
return ()=>document.removeEventListener('keydown', handleKeyDown)
|
|
109
|
+
;
|
|
110
|
+
}, [
|
|
111
|
+
hotkey
|
|
112
|
+
]);
|
|
113
|
+
$eyrYI$useEffect(()=>{
|
|
114
|
+
const wrapper = wrapperRef.current;
|
|
115
|
+
const viewport = ref.current;
|
|
116
|
+
if (wrapper && viewport) {
|
|
117
|
+
const handlePause = ()=>{
|
|
118
|
+
const pauseEvent = new CustomEvent($054eb8030ebde76e$var$VIEWPORT_PAUSE);
|
|
119
|
+
viewport.dispatchEvent(pauseEvent);
|
|
120
|
+
context.isClosePausedRef.current = true;
|
|
121
|
+
};
|
|
122
|
+
const handleResume = ()=>{
|
|
123
|
+
const resumeEvent = new CustomEvent($054eb8030ebde76e$var$VIEWPORT_RESUME);
|
|
124
|
+
viewport.dispatchEvent(resumeEvent);
|
|
125
|
+
context.isClosePausedRef.current = false;
|
|
126
|
+
}; // Toasts are not in the viewport React tree so we need to bind DOM events
|
|
127
|
+
wrapper.addEventListener('focusin', handlePause);
|
|
128
|
+
wrapper.addEventListener('focusout', handleResume);
|
|
129
|
+
wrapper.addEventListener('pointerenter', handlePause);
|
|
130
|
+
wrapper.addEventListener('pointerleave', handleResume);
|
|
131
|
+
window.addEventListener('blur', handlePause);
|
|
132
|
+
window.addEventListener('focus', handleResume);
|
|
133
|
+
return ()=>{
|
|
134
|
+
wrapper.removeEventListener('focusin', handlePause);
|
|
135
|
+
wrapper.removeEventListener('focusout', handleResume);
|
|
136
|
+
wrapper.removeEventListener('pointerenter', handlePause);
|
|
137
|
+
wrapper.removeEventListener('pointerleave', handleResume);
|
|
138
|
+
window.removeEventListener('blur', handlePause);
|
|
139
|
+
window.removeEventListener('focus', handleResume);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}, [
|
|
143
|
+
context.isClosePausedRef
|
|
144
|
+
]);
|
|
145
|
+
const getSortedTabbableCandidates = $eyrYI$useCallback(({ tabbingDirection: tabbingDirection })=>{
|
|
146
|
+
const toastItems = getItems();
|
|
147
|
+
const tabbableCandidates = toastItems.map((toastItem)=>{
|
|
148
|
+
const toastNode = toastItem.ref.current;
|
|
149
|
+
const toastTabbableCandidates = [
|
|
150
|
+
toastNode,
|
|
151
|
+
...$054eb8030ebde76e$var$getTabbableCandidates(toastNode)
|
|
152
|
+
];
|
|
153
|
+
return tabbingDirection === 'forwards' ? toastTabbableCandidates : toastTabbableCandidates.reverse();
|
|
154
|
+
});
|
|
155
|
+
return (tabbingDirection === 'forwards' ? tabbableCandidates.reverse() : tabbableCandidates).flat();
|
|
156
|
+
}, [
|
|
157
|
+
getItems
|
|
158
|
+
]);
|
|
159
|
+
$eyrYI$useEffect(()=>{
|
|
160
|
+
const viewport = ref.current; // We programmatically manage tabbing as we are unable to influence
|
|
161
|
+
// the source order with portals, this allows us to reverse the
|
|
162
|
+
// tab order so that it runs from most recent toast to least
|
|
163
|
+
if (viewport) {
|
|
164
|
+
const handleKeyDown = (event)=>{
|
|
165
|
+
const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
|
|
166
|
+
const isTabKey = event.key === 'Tab' && !isMetaKey;
|
|
167
|
+
if (isTabKey) {
|
|
168
|
+
const focusedElement = document.activeElement;
|
|
169
|
+
const isTabbingBackwards = event.shiftKey;
|
|
170
|
+
const targetIsViewport = event.target === viewport; // If we're back tabbing after jumping to the viewport then we simply
|
|
171
|
+
// proxy focus out to the preceding document
|
|
172
|
+
if (targetIsViewport && isTabbingBackwards) {
|
|
173
|
+
var _headFocusProxyRef$cu;
|
|
174
|
+
(_headFocusProxyRef$cu = headFocusProxyRef.current) === null || _headFocusProxyRef$cu === void 0 || _headFocusProxyRef$cu.focus();
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards';
|
|
178
|
+
const sortedCandidates = getSortedTabbableCandidates({
|
|
179
|
+
tabbingDirection: tabbingDirection
|
|
180
|
+
});
|
|
181
|
+
const index = sortedCandidates.findIndex((candidate)=>candidate === focusedElement
|
|
182
|
+
);
|
|
183
|
+
if ($054eb8030ebde76e$var$focusFirst(sortedCandidates.slice(index + 1))) event.preventDefault();
|
|
184
|
+
else {
|
|
185
|
+
var _headFocusProxyRef$cu2, _tailFocusProxyRef$cu;
|
|
186
|
+
// If we can't focus that means we're at the edges so we
|
|
187
|
+
// proxy to the corresponding exit point and let the browser handle
|
|
188
|
+
// tab/shift+tab keypress and implicitly pass focus to the next valid element in the document
|
|
189
|
+
isTabbingBackwards ? (_headFocusProxyRef$cu2 = headFocusProxyRef.current) === null || _headFocusProxyRef$cu2 === void 0 || _headFocusProxyRef$cu2.focus() : (_tailFocusProxyRef$cu = tailFocusProxyRef.current) === null || _tailFocusProxyRef$cu === void 0 || _tailFocusProxyRef$cu.focus();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}; // Toasts are not in the viewport React tree so we need to bind DOM events
|
|
193
|
+
viewport.addEventListener('keydown', handleKeyDown);
|
|
194
|
+
return ()=>viewport.removeEventListener('keydown', handleKeyDown)
|
|
195
|
+
;
|
|
196
|
+
}
|
|
197
|
+
}, [
|
|
198
|
+
getItems,
|
|
199
|
+
getSortedTabbableCandidates
|
|
200
|
+
]);
|
|
201
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Branch, {
|
|
202
|
+
ref: wrapperRef,
|
|
203
|
+
role: "region",
|
|
204
|
+
"aria-label": label.replace('{hotkey}', hotkeyLabel) // Ensure virtual cursor from landmarks menus triggers focus/blur for pause/resume
|
|
205
|
+
,
|
|
206
|
+
tabIndex: -1 // incase list has size when empty (e.g. padding), we remove pointer events so
|
|
207
|
+
,
|
|
208
|
+
style: {
|
|
209
|
+
pointerEvents: hasToasts ? undefined : 'none'
|
|
210
|
+
}
|
|
211
|
+
}, hasToasts && /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$FocusProxy, {
|
|
212
|
+
ref: headFocusProxyRef,
|
|
213
|
+
onFocusFromOutsideViewport: ()=>{
|
|
214
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
215
|
+
tabbingDirection: 'forwards'
|
|
216
|
+
});
|
|
217
|
+
$054eb8030ebde76e$var$focusFirst(tabbableCandidates);
|
|
218
|
+
}
|
|
219
|
+
}), /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$Collection.Slot, {
|
|
220
|
+
scope: __scopeToast
|
|
221
|
+
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.ol, $eyrYI$babelruntimehelpersesmextends({
|
|
222
|
+
tabIndex: -1
|
|
223
|
+
}, viewportProps, {
|
|
224
|
+
ref: composedRefs
|
|
225
|
+
}))), hasToasts && /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$FocusProxy, {
|
|
226
|
+
ref: tailFocusProxyRef,
|
|
227
|
+
onFocusFromOutsideViewport: ()=>{
|
|
228
|
+
const tabbableCandidates = getSortedTabbableCandidates({
|
|
229
|
+
tabbingDirection: 'backwards'
|
|
230
|
+
});
|
|
231
|
+
$054eb8030ebde76e$var$focusFirst(tabbableCandidates);
|
|
232
|
+
}
|
|
233
|
+
}));
|
|
234
|
+
});
|
|
235
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$6192c2425ecfd989, {
|
|
236
|
+
displayName: $054eb8030ebde76e$var$VIEWPORT_NAME
|
|
237
|
+
});
|
|
238
|
+
/* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$FOCUS_PROXY_NAME = 'ToastFocusProxy';
|
|
239
|
+
const $054eb8030ebde76e$var$FocusProxy = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
240
|
+
const { __scopeToast: __scopeToast , onFocusFromOutsideViewport: onFocusFromOutsideViewport , ...proxyProps } = props;
|
|
241
|
+
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$FOCUS_PROXY_NAME, __scopeToast);
|
|
242
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$VisuallyHidden, $eyrYI$babelruntimehelpersesmextends({
|
|
243
|
+
"aria-hidden": true,
|
|
244
|
+
tabIndex: 0
|
|
245
|
+
}, proxyProps, {
|
|
246
|
+
ref: forwardedRef // Avoid page scrolling when focus is on the focus proxy
|
|
247
|
+
,
|
|
248
|
+
style: {
|
|
249
|
+
position: 'fixed'
|
|
250
|
+
},
|
|
251
|
+
onFocus: (event)=>{
|
|
252
|
+
var _context$viewport;
|
|
253
|
+
const prevFocusedElement = event.relatedTarget;
|
|
254
|
+
const isFocusFromOutsideViewport = !((_context$viewport = context.viewport) !== null && _context$viewport !== void 0 && _context$viewport.contains(prevFocusedElement));
|
|
255
|
+
if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
|
|
256
|
+
}
|
|
257
|
+
}));
|
|
258
|
+
});
|
|
259
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$var$FocusProxy, {
|
|
260
|
+
displayName: $054eb8030ebde76e$var$FOCUS_PROXY_NAME
|
|
261
|
+
});
|
|
262
|
+
/* -------------------------------------------------------------------------------------------------
|
|
263
|
+
* Toast
|
|
264
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$TOAST_NAME = 'Toast';
|
|
265
|
+
const $054eb8030ebde76e$var$TOAST_SWIPE_START = 'toast.swipeStart';
|
|
266
|
+
const $054eb8030ebde76e$var$TOAST_SWIPE_MOVE = 'toast.swipeMove';
|
|
267
|
+
const $054eb8030ebde76e$var$TOAST_SWIPE_CANCEL = 'toast.swipeCancel';
|
|
268
|
+
const $054eb8030ebde76e$var$TOAST_SWIPE_END = 'toast.swipeEnd';
|
|
269
|
+
const $054eb8030ebde76e$export$8d8dc7d5f743331b = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
270
|
+
const { forceMount: forceMount , open: openProp , defaultOpen: defaultOpen , onOpenChange: onOpenChange , ...toastProps } = props;
|
|
271
|
+
const [open = true, setOpen] = $eyrYI$useControllableState({
|
|
272
|
+
prop: openProp,
|
|
273
|
+
defaultProp: defaultOpen,
|
|
274
|
+
onChange: onOpenChange
|
|
275
|
+
});
|
|
276
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Presence, {
|
|
277
|
+
present: forceMount || open
|
|
278
|
+
}, /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastImpl, $eyrYI$babelruntimehelpersesmextends({
|
|
279
|
+
open: open
|
|
280
|
+
}, toastProps, {
|
|
281
|
+
ref: forwardedRef,
|
|
282
|
+
onClose: ()=>setOpen(false)
|
|
283
|
+
,
|
|
284
|
+
onSwipeStart: $eyrYI$composeEventHandlers(props.onSwipeStart, (event)=>{
|
|
285
|
+
event.currentTarget.setAttribute('data-swipe', 'start');
|
|
286
|
+
}),
|
|
287
|
+
onSwipeMove: $eyrYI$composeEventHandlers(props.onSwipeMove, (event)=>{
|
|
288
|
+
const { x: x , y: y } = event.detail.delta;
|
|
289
|
+
event.currentTarget.setAttribute('data-swipe', 'move');
|
|
290
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-move-x', `${x}px`);
|
|
291
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-move-y', `${y}px`);
|
|
292
|
+
}),
|
|
293
|
+
onSwipeCancel: $eyrYI$composeEventHandlers(props.onSwipeCancel, (event)=>{
|
|
294
|
+
event.currentTarget.setAttribute('data-swipe', 'cancel');
|
|
295
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-x');
|
|
296
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-y');
|
|
297
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-end-x');
|
|
298
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-end-y');
|
|
299
|
+
}),
|
|
300
|
+
onSwipeEnd: $eyrYI$composeEventHandlers(props.onSwipeEnd, (event)=>{
|
|
301
|
+
const { x: x , y: y } = event.detail.delta;
|
|
302
|
+
event.currentTarget.setAttribute('data-swipe', 'end');
|
|
303
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-x');
|
|
304
|
+
event.currentTarget.style.removeProperty('--radix-toast-swipe-move-y');
|
|
305
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-end-x', `${x}px`);
|
|
306
|
+
event.currentTarget.style.setProperty('--radix-toast-swipe-end-y', `${y}px`);
|
|
307
|
+
setOpen(false);
|
|
308
|
+
})
|
|
309
|
+
})));
|
|
310
|
+
});
|
|
311
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$8d8dc7d5f743331b, {
|
|
312
|
+
displayName: $054eb8030ebde76e$var$TOAST_NAME
|
|
313
|
+
});
|
|
314
|
+
/* -----------------------------------------------------------------------------------------------*/ const [$054eb8030ebde76e$var$ToastInteractiveProvider, $054eb8030ebde76e$var$useToastInteractiveContext] = $054eb8030ebde76e$var$createToastContext($054eb8030ebde76e$var$TOAST_NAME, {
|
|
315
|
+
isInteractive: false,
|
|
316
|
+
onClose () {}
|
|
317
|
+
});
|
|
318
|
+
const $054eb8030ebde76e$var$ToastImpl = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
319
|
+
const { __scopeToast: __scopeToast , type: type = 'foreground' , duration: durationProp , open: open , onClose: onClose , onEscapeKeyDown: onEscapeKeyDown , onSwipeStart: onSwipeStart , onSwipeMove: onSwipeMove , onSwipeCancel: onSwipeCancel , onSwipeEnd: onSwipeEnd , ...toastProps } = props;
|
|
320
|
+
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$TOAST_NAME, __scopeToast);
|
|
321
|
+
const ref = $eyrYI$useRef(null);
|
|
322
|
+
const composedRefs = $eyrYI$useComposedRefs(forwardedRef, ref);
|
|
323
|
+
const pointerStartRef = $eyrYI$useRef(null);
|
|
324
|
+
const swipeDeltaRef = $eyrYI$useRef(null);
|
|
325
|
+
const duration1 = durationProp || context.duration;
|
|
326
|
+
const closeTimerStartTimeRef = $eyrYI$useRef(0);
|
|
327
|
+
const closeTimerRemainingTimeRef = $eyrYI$useRef(duration1);
|
|
328
|
+
const closeTimerRef = $eyrYI$useRef(0);
|
|
329
|
+
const { onToastAdd: onToastAdd , onToastRemove: onToastRemove } = context;
|
|
330
|
+
const handleClose = $eyrYI$useCallbackRef(()=>{
|
|
331
|
+
var _ref$current2, _context$viewport2;
|
|
332
|
+
// focus viewport if focus is within toast to read the remaining toast
|
|
333
|
+
// count to SR users and ensure focus isn't lost
|
|
334
|
+
const isFocusInToast = (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.contains(document.activeElement);
|
|
335
|
+
if (isFocusInToast) (_context$viewport2 = context.viewport) === null || _context$viewport2 === void 0 || _context$viewport2.focus();
|
|
336
|
+
onClose();
|
|
337
|
+
});
|
|
338
|
+
const startTimer = $eyrYI$useCallback((duration)=>{
|
|
339
|
+
if (!duration || duration === Infinity) return;
|
|
340
|
+
window.clearTimeout(closeTimerRef.current);
|
|
341
|
+
closeTimerStartTimeRef.current = new Date().getTime();
|
|
342
|
+
closeTimerRef.current = window.setTimeout(handleClose, duration);
|
|
343
|
+
}, [
|
|
344
|
+
handleClose
|
|
345
|
+
]);
|
|
346
|
+
$eyrYI$useEffect(()=>{
|
|
347
|
+
const viewport = context.viewport;
|
|
348
|
+
if (viewport) {
|
|
349
|
+
const handleResume = ()=>{
|
|
350
|
+
startTimer(closeTimerRemainingTimeRef.current);
|
|
351
|
+
};
|
|
352
|
+
const handlePause = ()=>{
|
|
353
|
+
const elapsedTime = new Date().getTime() - closeTimerStartTimeRef.current;
|
|
354
|
+
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
355
|
+
window.clearTimeout(closeTimerRef.current);
|
|
356
|
+
};
|
|
357
|
+
viewport.addEventListener($054eb8030ebde76e$var$VIEWPORT_PAUSE, handlePause);
|
|
358
|
+
viewport.addEventListener($054eb8030ebde76e$var$VIEWPORT_RESUME, handleResume);
|
|
359
|
+
return ()=>{
|
|
360
|
+
viewport.removeEventListener($054eb8030ebde76e$var$VIEWPORT_PAUSE, handlePause);
|
|
361
|
+
viewport.removeEventListener($054eb8030ebde76e$var$VIEWPORT_RESUME, handleResume);
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}, [
|
|
365
|
+
context.viewport,
|
|
366
|
+
duration1,
|
|
367
|
+
startTimer
|
|
368
|
+
]); // start timer when toast opens or duration changes.
|
|
369
|
+
// we include `open` in deps because closed !== unmounted when animating
|
|
370
|
+
// so it could reopen before being completely unmounted
|
|
371
|
+
$eyrYI$useEffect(()=>{
|
|
372
|
+
if (open && !context.isClosePausedRef.current) startTimer(duration1);
|
|
373
|
+
}, [
|
|
374
|
+
open,
|
|
375
|
+
duration1,
|
|
376
|
+
context.isClosePausedRef,
|
|
377
|
+
startTimer
|
|
378
|
+
]);
|
|
379
|
+
$eyrYI$useEffect(()=>{
|
|
380
|
+
onToastAdd();
|
|
381
|
+
return ()=>onToastRemove()
|
|
382
|
+
;
|
|
383
|
+
}, [
|
|
384
|
+
onToastAdd,
|
|
385
|
+
onToastRemove
|
|
386
|
+
]);
|
|
387
|
+
if (!context.viewport) return null;
|
|
388
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Fragment, null, /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastAnnounce, {
|
|
389
|
+
__scopeToast: __scopeToast // Toasts are always role=status to avoid stuttering issues with role=alert in SRs.
|
|
390
|
+
,
|
|
391
|
+
role: "status",
|
|
392
|
+
"aria-live": type === 'foreground' ? 'assertive' : 'polite',
|
|
393
|
+
"aria-atomic": true
|
|
394
|
+
}, props.children), /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$ToastInteractiveProvider, {
|
|
395
|
+
scope: __scopeToast,
|
|
396
|
+
isInteractive: true,
|
|
397
|
+
onClose: handleClose
|
|
398
|
+
}, /*#__PURE__*/ $eyrYI$createPortal(/*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$var$Collection.ItemSlot, {
|
|
399
|
+
scope: __scopeToast
|
|
400
|
+
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$Root, {
|
|
401
|
+
asChild: true,
|
|
402
|
+
onEscapeKeyDown: $eyrYI$composeEventHandlers(onEscapeKeyDown, ()=>{
|
|
403
|
+
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
|
|
404
|
+
context.isFocusedToastEscapeKeyDownRef.current = false;
|
|
405
|
+
})
|
|
406
|
+
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.li, $eyrYI$babelruntimehelpersesmextends({
|
|
407
|
+
tabIndex: 0,
|
|
408
|
+
"data-state": open ? 'open' : 'closed',
|
|
409
|
+
"data-swipe-direction": context.swipeDirection
|
|
410
|
+
}, toastProps, {
|
|
411
|
+
ref: composedRefs,
|
|
412
|
+
style: {
|
|
413
|
+
userSelect: 'none',
|
|
414
|
+
touchAction: 'none',
|
|
415
|
+
...props.style
|
|
416
|
+
},
|
|
417
|
+
onKeyDown: $eyrYI$composeEventHandlers(props.onKeyDown, (event)=>{
|
|
418
|
+
if (event.key !== 'Escape') return;
|
|
419
|
+
onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event.nativeEvent);
|
|
420
|
+
if (!event.nativeEvent.defaultPrevented) {
|
|
421
|
+
context.isFocusedToastEscapeKeyDownRef.current = true;
|
|
422
|
+
handleClose();
|
|
423
|
+
}
|
|
424
|
+
}),
|
|
425
|
+
onPointerDown: $eyrYI$composeEventHandlers(props.onPointerDown, (event)=>{
|
|
426
|
+
if (event.button !== 0) return;
|
|
427
|
+
pointerStartRef.current = {
|
|
428
|
+
x: event.clientX,
|
|
429
|
+
y: event.clientY
|
|
430
|
+
};
|
|
431
|
+
}),
|
|
432
|
+
onPointerMove: $eyrYI$composeEventHandlers(props.onPointerMove, (event)=>{
|
|
433
|
+
if (!pointerStartRef.current) return;
|
|
434
|
+
const x = event.clientX - pointerStartRef.current.x;
|
|
435
|
+
const y = event.clientY - pointerStartRef.current.y;
|
|
436
|
+
const hasSwipeMoveStarted = Boolean(swipeDeltaRef.current);
|
|
437
|
+
const isHorizontalSwipe = [
|
|
438
|
+
'left',
|
|
439
|
+
'right'
|
|
440
|
+
].includes(context.swipeDirection);
|
|
441
|
+
const clamp = [
|
|
442
|
+
'left',
|
|
443
|
+
'up'
|
|
444
|
+
].includes(context.swipeDirection) ? Math.min : Math.max;
|
|
445
|
+
const clampedX = isHorizontalSwipe ? clamp(0, x) : 0;
|
|
446
|
+
const clampedY = !isHorizontalSwipe ? clamp(0, y) : 0;
|
|
447
|
+
const moveStartBuffer = event.pointerType === 'touch' ? 10 : 2;
|
|
448
|
+
const delta = {
|
|
449
|
+
x: clampedX,
|
|
450
|
+
y: clampedY
|
|
451
|
+
};
|
|
452
|
+
const eventDetail = {
|
|
453
|
+
originalEvent: event,
|
|
454
|
+
delta: delta
|
|
455
|
+
};
|
|
456
|
+
if (hasSwipeMoveStarted) {
|
|
457
|
+
swipeDeltaRef.current = delta;
|
|
458
|
+
$054eb8030ebde76e$var$handleAndDispatchCustomEvent($054eb8030ebde76e$var$TOAST_SWIPE_MOVE, onSwipeMove, eventDetail, {
|
|
459
|
+
discrete: false
|
|
460
|
+
});
|
|
461
|
+
} else if ($054eb8030ebde76e$var$isDeltaInDirection(delta, context.swipeDirection, moveStartBuffer)) {
|
|
462
|
+
swipeDeltaRef.current = delta;
|
|
463
|
+
$054eb8030ebde76e$var$handleAndDispatchCustomEvent($054eb8030ebde76e$var$TOAST_SWIPE_START, onSwipeStart, eventDetail, {
|
|
464
|
+
discrete: false
|
|
465
|
+
});
|
|
466
|
+
event.target.setPointerCapture(event.pointerId);
|
|
467
|
+
} else if (Math.abs(x) > moveStartBuffer || Math.abs(y) > moveStartBuffer) // User is swiping in wrong direction so we disable swipe gesture
|
|
468
|
+
// for the current pointer down interaction
|
|
469
|
+
pointerStartRef.current = null;
|
|
470
|
+
}),
|
|
471
|
+
onPointerUp: $eyrYI$composeEventHandlers(props.onPointerUp, (event1)=>{
|
|
472
|
+
const delta = swipeDeltaRef.current;
|
|
473
|
+
event1.target.releasePointerCapture(event1.pointerId);
|
|
474
|
+
swipeDeltaRef.current = null;
|
|
475
|
+
pointerStartRef.current = null;
|
|
476
|
+
if (delta) {
|
|
477
|
+
const toast = event1.currentTarget;
|
|
478
|
+
const eventDetail = {
|
|
479
|
+
originalEvent: event1,
|
|
480
|
+
delta: delta
|
|
481
|
+
};
|
|
482
|
+
if ($054eb8030ebde76e$var$isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) $054eb8030ebde76e$var$handleAndDispatchCustomEvent($054eb8030ebde76e$var$TOAST_SWIPE_END, onSwipeEnd, eventDetail, {
|
|
483
|
+
discrete: true
|
|
484
|
+
});
|
|
485
|
+
else $054eb8030ebde76e$var$handleAndDispatchCustomEvent($054eb8030ebde76e$var$TOAST_SWIPE_CANCEL, onSwipeCancel, eventDetail, {
|
|
486
|
+
discrete: true
|
|
487
|
+
});
|
|
488
|
+
// Prevent click event from triggering on items within the toast when
|
|
489
|
+
// pointer up is part of a swipe gesture
|
|
490
|
+
toast.addEventListener('click', (event)=>event.preventDefault()
|
|
491
|
+
, {
|
|
492
|
+
once: true
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
})
|
|
496
|
+
})))), context.viewport)));
|
|
497
|
+
});
|
|
498
|
+
$054eb8030ebde76e$var$ToastImpl.propTypes = {
|
|
499
|
+
type (props) {
|
|
500
|
+
if (props.type && ![
|
|
501
|
+
'foreground',
|
|
502
|
+
'background'
|
|
503
|
+
].includes(props.type)) {
|
|
504
|
+
const error = `Invalid prop \`type\` supplied to \`${$054eb8030ebde76e$var$TOAST_NAME}\`. Expected \`foreground | background\`.`;
|
|
505
|
+
return new Error(error);
|
|
506
|
+
}
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
/* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$ToastAnnounce = (props)=>{
|
|
511
|
+
const { __scopeToast: __scopeToast , children: children , ...announceProps } = props;
|
|
512
|
+
const context = $054eb8030ebde76e$var$useToastProviderContext($054eb8030ebde76e$var$TOAST_NAME, __scopeToast);
|
|
513
|
+
const [renderAnnounceText, setRenderAnnounceText] = $eyrYI$useState(false);
|
|
514
|
+
const [isAnnounced, setIsAnnounced] = $eyrYI$useState(false);
|
|
515
|
+
const [fragment, setFragment] = $eyrYI$useState();
|
|
516
|
+
const [rootFragmentNode, setRootFragmentNode] = $eyrYI$useState(null); // We portal children into a document fragment so that we can extract the bare text nodes
|
|
517
|
+
// before rendering to the DOM. This avoids issues with duplicate `children`
|
|
518
|
+
// and animation libraries when composing via `asChild`.
|
|
519
|
+
const announceTextContent = $eyrYI$useMemo(()=>{
|
|
520
|
+
return rootFragmentNode ? $054eb8030ebde76e$var$getAnnounceTextContent(rootFragmentNode) : null;
|
|
521
|
+
}, [
|
|
522
|
+
rootFragmentNode
|
|
523
|
+
]); // setting the fragment in `useLayoutEffect` as `DocumentFragment` doesn't exist on the server
|
|
524
|
+
$eyrYI$useLayoutEffect(()=>{
|
|
525
|
+
setFragment(new DocumentFragment());
|
|
526
|
+
}, []); // render text content in the next frame to ensure toast is announced in NVDA
|
|
527
|
+
$054eb8030ebde76e$var$useNextFrame(()=>setRenderAnnounceText(true)
|
|
528
|
+
);
|
|
529
|
+
$eyrYI$useEffect(()=>{
|
|
530
|
+
const timer = window.setTimeout(()=>setIsAnnounced(true)
|
|
531
|
+
, 1000);
|
|
532
|
+
return ()=>window.clearTimeout(timer)
|
|
533
|
+
;
|
|
534
|
+
}, []);
|
|
535
|
+
return isAnnounced ? null : /*#__PURE__*/ $eyrYI$createElement($eyrYI$Fragment, null, fragment && /*#__PURE__*/ $eyrYI$createElement($eyrYI$Portal, {
|
|
536
|
+
container: fragment,
|
|
537
|
+
ref: setRootFragmentNode
|
|
538
|
+
}, context.label, " ", children), /*#__PURE__*/ $eyrYI$createElement($eyrYI$Portal, {
|
|
539
|
+
asChild: true
|
|
540
|
+
}, /*#__PURE__*/ $eyrYI$createElement($eyrYI$VisuallyHidden, announceProps, renderAnnounceText && announceTextContent)));
|
|
541
|
+
};
|
|
542
|
+
/* -------------------------------------------------------------------------------------------------
|
|
543
|
+
* ToastTitle
|
|
544
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$TITLE_NAME = 'ToastTitle';
|
|
545
|
+
const $054eb8030ebde76e$export$16d42d7c29b95a4 = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
546
|
+
const { __scopeToast: __scopeToast , ...titleProps } = props;
|
|
547
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.div, $eyrYI$babelruntimehelpersesmextends({}, titleProps, {
|
|
548
|
+
ref: forwardedRef
|
|
549
|
+
}));
|
|
550
|
+
});
|
|
551
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$16d42d7c29b95a4, {
|
|
552
|
+
displayName: $054eb8030ebde76e$var$TITLE_NAME
|
|
553
|
+
});
|
|
554
|
+
/* -------------------------------------------------------------------------------------------------
|
|
555
|
+
* ToastDescription
|
|
556
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$DESCRIPTION_NAME = 'ToastDescription';
|
|
557
|
+
const $054eb8030ebde76e$export$ecddd96c53621d9a = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
558
|
+
const { __scopeToast: __scopeToast , ...descriptionProps } = props;
|
|
559
|
+
return /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.div, $eyrYI$babelruntimehelpersesmextends({}, descriptionProps, {
|
|
560
|
+
ref: forwardedRef
|
|
561
|
+
}));
|
|
562
|
+
});
|
|
563
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$ecddd96c53621d9a, {
|
|
564
|
+
displayName: $054eb8030ebde76e$var$DESCRIPTION_NAME
|
|
565
|
+
});
|
|
566
|
+
/* -------------------------------------------------------------------------------------------------
|
|
567
|
+
* ToastAction
|
|
568
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$ACTION_NAME = 'ToastAction';
|
|
569
|
+
const $054eb8030ebde76e$export$3019feecfda683d2 = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
570
|
+
const { altText: altText , ...actionProps } = props;
|
|
571
|
+
const context = $054eb8030ebde76e$var$useToastInteractiveContext($054eb8030ebde76e$var$ACTION_NAME, props.__scopeToast);
|
|
572
|
+
if (!altText) return null;
|
|
573
|
+
return context.isInteractive ? /*#__PURE__*/ $eyrYI$createElement($054eb8030ebde76e$export$811e70f61c205839, $eyrYI$babelruntimehelpersesmextends({}, actionProps, {
|
|
574
|
+
ref: forwardedRef
|
|
575
|
+
})) : /*#__PURE__*/ $eyrYI$createElement("span", null, altText);
|
|
576
|
+
});
|
|
577
|
+
$054eb8030ebde76e$export$3019feecfda683d2.propTypes = {
|
|
578
|
+
altText (props) {
|
|
579
|
+
if (!props.altText) return new Error(`Missing prop \`altText\` expected on \`${$054eb8030ebde76e$var$ACTION_NAME}\``);
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$3019feecfda683d2, {
|
|
584
|
+
displayName: $054eb8030ebde76e$var$ACTION_NAME
|
|
585
|
+
});
|
|
586
|
+
/* -------------------------------------------------------------------------------------------------
|
|
587
|
+
* ToastClose
|
|
588
|
+
* -----------------------------------------------------------------------------------------------*/ const $054eb8030ebde76e$var$CLOSE_NAME = 'ToastClose';
|
|
589
|
+
const $054eb8030ebde76e$export$811e70f61c205839 = /*#__PURE__*/ $eyrYI$forwardRef((props, forwardedRef)=>{
|
|
590
|
+
const { __scopeToast: __scopeToast , ...closeProps } = props;
|
|
591
|
+
const interactiveContext = $054eb8030ebde76e$var$useToastInteractiveContext($054eb8030ebde76e$var$CLOSE_NAME, __scopeToast);
|
|
592
|
+
return interactiveContext.isInteractive ? /*#__PURE__*/ $eyrYI$createElement($eyrYI$Primitive.button, $eyrYI$babelruntimehelpersesmextends({
|
|
593
|
+
type: "button"
|
|
594
|
+
}, closeProps, {
|
|
595
|
+
ref: forwardedRef,
|
|
596
|
+
onClick: $eyrYI$composeEventHandlers(props.onClick, interactiveContext.onClose)
|
|
597
|
+
})) : null;
|
|
598
|
+
});
|
|
599
|
+
/*#__PURE__*/ Object.assign($054eb8030ebde76e$export$811e70f61c205839, {
|
|
600
|
+
displayName: $054eb8030ebde76e$var$CLOSE_NAME
|
|
601
|
+
});
|
|
602
|
+
/* ---------------------------------------------------------------------------------------------- */ function $054eb8030ebde76e$var$handleAndDispatchCustomEvent(name, handler, detail, { discrete: discrete }) {
|
|
603
|
+
const currentTarget = detail.originalEvent.currentTarget;
|
|
604
|
+
const event = new CustomEvent(name, {
|
|
605
|
+
bubbles: true,
|
|
606
|
+
cancelable: true,
|
|
607
|
+
detail: detail
|
|
608
|
+
});
|
|
609
|
+
if (handler) currentTarget.addEventListener(name, handler, {
|
|
610
|
+
once: true
|
|
611
|
+
});
|
|
612
|
+
if (discrete) $eyrYI$dispatchDiscreteCustomEvent(currentTarget, event);
|
|
613
|
+
else currentTarget.dispatchEvent(event);
|
|
614
|
+
}
|
|
615
|
+
const $054eb8030ebde76e$var$isDeltaInDirection = (delta, direction, threshold = 0)=>{
|
|
616
|
+
const deltaX = Math.abs(delta.x);
|
|
617
|
+
const deltaY = Math.abs(delta.y);
|
|
618
|
+
const isDeltaX = deltaX > deltaY;
|
|
619
|
+
if (direction === 'left' || direction === 'right') return isDeltaX && deltaX > threshold;
|
|
620
|
+
else return !isDeltaX && deltaY > threshold;
|
|
621
|
+
};
|
|
622
|
+
function $054eb8030ebde76e$var$useNextFrame(callback = ()=>{}) {
|
|
623
|
+
const fn = $eyrYI$useCallbackRef(callback);
|
|
624
|
+
$eyrYI$useLayoutEffect(()=>{
|
|
625
|
+
let raf1 = 0;
|
|
626
|
+
let raf2 = 0;
|
|
627
|
+
raf1 = window.requestAnimationFrame(()=>raf2 = window.requestAnimationFrame(fn)
|
|
628
|
+
);
|
|
629
|
+
return ()=>{
|
|
630
|
+
window.cancelAnimationFrame(raf1);
|
|
631
|
+
window.cancelAnimationFrame(raf2);
|
|
632
|
+
};
|
|
633
|
+
}, [
|
|
634
|
+
fn
|
|
635
|
+
]);
|
|
636
|
+
}
|
|
637
|
+
function $054eb8030ebde76e$var$getAnnounceTextContent(container) {
|
|
638
|
+
const textContent = [];
|
|
639
|
+
const childNodes = Array.from(container.childNodes);
|
|
640
|
+
childNodes.forEach((node)=>{
|
|
641
|
+
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
|
|
642
|
+
if ($054eb8030ebde76e$var$isHTMLElement(node)) {
|
|
643
|
+
const isHidden = node.ariaHidden || node.hidden || node.style.display === 'none';
|
|
644
|
+
if (!isHidden) textContent.push(...$054eb8030ebde76e$var$getAnnounceTextContent(node));
|
|
645
|
+
}
|
|
646
|
+
}); // We return a collection of text rather than a single concatenated string.
|
|
647
|
+
// This allows SR VO to naturally pause break between nodes while announcing.
|
|
648
|
+
return textContent;
|
|
649
|
+
}
|
|
650
|
+
function $054eb8030ebde76e$var$isHTMLElement(node) {
|
|
651
|
+
return node.nodeType === node.ELEMENT_NODE;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Returns a list of potential tabbable candidates.
|
|
655
|
+
*
|
|
656
|
+
* NOTE: This is only a close approximation. For example it doesn't take into account cases like when
|
|
657
|
+
* elements are not visible. This cannot be worked out easily by just reading a property, but rather
|
|
658
|
+
* necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
|
|
659
|
+
*
|
|
660
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
|
|
661
|
+
* Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
|
|
662
|
+
*/ function $054eb8030ebde76e$var$getTabbableCandidates(container) {
|
|
663
|
+
const nodes = [];
|
|
664
|
+
const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
665
|
+
acceptNode: (node)=>{
|
|
666
|
+
const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
|
|
667
|
+
if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP; // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
|
|
668
|
+
// runtime's understanding of tabbability, so this automatically accounts
|
|
669
|
+
// for any kind of element that could be tabbed to.
|
|
670
|
+
return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
while(walker.nextNode())nodes.push(walker.currentNode); // we do not take into account the order of nodes with positive `tabIndex` as it
|
|
674
|
+
// hinders accessibility to have tab order different from visual order.
|
|
675
|
+
return nodes;
|
|
676
|
+
}
|
|
677
|
+
function $054eb8030ebde76e$var$focusFirst(candidates) {
|
|
678
|
+
const previouslyFocusedElement = document.activeElement;
|
|
679
|
+
return candidates.some((candidate)=>{
|
|
680
|
+
// if focus is already where we want to go, we don't want to keep going through the candidates
|
|
681
|
+
if (candidate === previouslyFocusedElement) return true;
|
|
682
|
+
candidate.focus();
|
|
683
|
+
return document.activeElement !== previouslyFocusedElement;
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
const $054eb8030ebde76e$export$2881499e37b75b9a = $054eb8030ebde76e$export$f5d03d415824e0e;
|
|
687
|
+
const $054eb8030ebde76e$export$d5c6c08dc2d3ca7 = $054eb8030ebde76e$export$6192c2425ecfd989;
|
|
688
|
+
const $054eb8030ebde76e$export$be92b6f5f03c0fe9 = $054eb8030ebde76e$export$8d8dc7d5f743331b;
|
|
689
|
+
const $054eb8030ebde76e$export$f99233281efd08a0 = $054eb8030ebde76e$export$16d42d7c29b95a4;
|
|
690
|
+
const $054eb8030ebde76e$export$393edc798c47379d = $054eb8030ebde76e$export$ecddd96c53621d9a;
|
|
691
|
+
const $054eb8030ebde76e$export$e19cd5f9376f8cee = $054eb8030ebde76e$export$3019feecfda683d2;
|
|
692
|
+
const $054eb8030ebde76e$export$f39c2d165cd861fe = $054eb8030ebde76e$export$811e70f61c205839;
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
export {$054eb8030ebde76e$export$8a359da18fbc9073 as createToastScope, $054eb8030ebde76e$export$f5d03d415824e0e as ToastProvider, $054eb8030ebde76e$export$6192c2425ecfd989 as ToastViewport, $054eb8030ebde76e$export$8d8dc7d5f743331b as Toast, $054eb8030ebde76e$export$16d42d7c29b95a4 as ToastTitle, $054eb8030ebde76e$export$ecddd96c53621d9a as ToastDescription, $054eb8030ebde76e$export$3019feecfda683d2 as ToastAction, $054eb8030ebde76e$export$811e70f61c205839 as ToastClose, $054eb8030ebde76e$export$2881499e37b75b9a as Provider, $054eb8030ebde76e$export$d5c6c08dc2d3ca7 as Viewport, $054eb8030ebde76e$export$be92b6f5f03c0fe9 as Root, $054eb8030ebde76e$export$f99233281efd08a0 as Title, $054eb8030ebde76e$export$393edc798c47379d as Description, $054eb8030ebde76e$export$e19cd5f9376f8cee as Action, $054eb8030ebde76e$export$f39c2d165cd861fe as Close};
|
|
2
698
|
//# sourceMappingURL=index.module.js.map
|