@tamagui/toast 2.7.7 → 3.0.0-beta.637.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ToastComposable.cjs +773 -882
- package/dist/cjs/ToastComposable.native.cjs +924 -0
- package/dist/cjs/ToastComposable.native.js +854 -966
- package/dist/cjs/ToastComposable.native.js.map +1 -1
- package/dist/cjs/ToastItemFrame.cjs +48 -119
- package/dist/cjs/ToastItemFrame.native.cjs +76 -0
- package/dist/cjs/ToastItemFrame.native.js +50 -120
- package/dist/cjs/ToastItemFrame.native.js.map +1 -1
- package/dist/cjs/ToastState.cjs +281 -290
- package/dist/cjs/ToastState.native.cjs +312 -0
- package/dist/cjs/ToastState.native.js +280 -290
- package/dist/cjs/ToastState.native.js.map +1 -1
- package/dist/cjs/createNativeToast.cjs +38 -44
- package/dist/cjs/createNativeToast.native.cjs +54 -0
- package/dist/cjs/createNativeToast.native.js +36 -40
- package/dist/cjs/createNativeToast.native.js.map +1 -1
- package/dist/cjs/dispatchNativeToast.cjs +32 -35
- package/dist/cjs/dispatchNativeToast.native.cjs +48 -0
- package/dist/cjs/dispatchNativeToast.native.js +34 -36
- package/dist/cjs/dispatchNativeToast.native.js.map +1 -1
- package/dist/cjs/index.cjs +25 -12
- package/dist/cjs/index.native.cjs +35 -0
- package/dist/cjs/index.native.js +26 -12
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/types.cjs +10 -11
- package/dist/cjs/types.native.cjs +19 -0
- package/dist/cjs/types.native.js +10 -10
- package/dist/cjs/types.native.js.map +1 -1
- package/dist/cjs/useAnimatedDragGesture.cjs +197 -194
- package/dist/cjs/useAnimatedDragGesture.native.cjs +210 -0
- package/dist/cjs/useAnimatedDragGesture.native.js +179 -191
- package/dist/cjs/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/cjs/useReducedMotion.cjs +47 -55
- package/dist/cjs/useReducedMotion.native.cjs +74 -0
- package/dist/cjs/useReducedMotion.native.js +53 -60
- package/dist/cjs/useReducedMotion.native.js.map +1 -1
- package/dist/cjs/useToastAnimations.cjs +198 -270
- package/dist/cjs/useToastAnimations.native.cjs +229 -0
- package/dist/cjs/useToastAnimations.native.js +205 -276
- package/dist/cjs/useToastAnimations.native.js.map +1 -1
- package/dist/esm/ToastComposable.mjs +752 -854
- package/dist/esm/ToastComposable.mjs.map +1 -1
- package/dist/esm/ToastComposable.native.js +834 -940
- package/dist/esm/ToastComposable.native.js.map +1 -1
- package/dist/esm/ToastItemFrame.mjs +31 -99
- package/dist/esm/ToastItemFrame.mjs.map +1 -1
- package/dist/esm/ToastItemFrame.native.js +34 -102
- package/dist/esm/ToastItemFrame.native.js.map +1 -1
- package/dist/esm/ToastState.mjs +266 -273
- package/dist/esm/ToastState.mjs.map +1 -1
- package/dist/esm/ToastState.native.js +265 -274
- package/dist/esm/ToastState.native.js.map +1 -1
- package/dist/esm/createNativeToast.mjs +22 -26
- package/dist/esm/createNativeToast.mjs.map +1 -1
- package/dist/esm/createNativeToast.native.js +21 -23
- package/dist/esm/createNativeToast.native.js.map +1 -1
- package/dist/esm/dispatchNativeToast.mjs +19 -17
- package/dist/esm/dispatchNativeToast.mjs.map +1 -1
- package/dist/esm/dispatchNativeToast.native.js +21 -19
- package/dist/esm/dispatchNativeToast.native.js.map +1 -1
- package/dist/esm/index.js +5 -2
- package/dist/esm/index.mjs +5 -2
- package/dist/esm/index.native.js +5 -2
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.native.js +0 -2
- package/dist/esm/useAnimatedDragGesture.mjs +181 -168
- package/dist/esm/useAnimatedDragGesture.mjs.map +1 -1
- package/dist/esm/useAnimatedDragGesture.native.js +163 -166
- package/dist/esm/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/esm/useReducedMotion.mjs +31 -29
- package/dist/esm/useReducedMotion.mjs.map +1 -1
- package/dist/esm/useReducedMotion.native.js +37 -35
- package/dist/esm/useReducedMotion.native.js.map +1 -1
- package/dist/esm/useToastAnimations.mjs +183 -245
- package/dist/esm/useToastAnimations.mjs.map +1 -1
- package/dist/esm/useToastAnimations.native.js +190 -252
- package/dist/esm/useToastAnimations.native.js.map +1 -1
- package/dist/jsx/ToastComposable.mjs +752 -854
- package/dist/jsx/ToastComposable.mjs.map +1 -1
- package/dist/jsx/ToastComposable.native.cjs +924 -0
- package/dist/jsx/ToastComposable.native.js +854 -966
- package/dist/jsx/ToastComposable.native.js.map +1 -1
- package/dist/jsx/ToastItemFrame.mjs +31 -99
- package/dist/jsx/ToastItemFrame.mjs.map +1 -1
- package/dist/jsx/ToastItemFrame.native.cjs +76 -0
- package/dist/jsx/ToastItemFrame.native.js +50 -120
- package/dist/jsx/ToastItemFrame.native.js.map +1 -1
- package/dist/jsx/ToastState.mjs +266 -273
- package/dist/jsx/ToastState.mjs.map +1 -1
- package/dist/jsx/ToastState.native.cjs +312 -0
- package/dist/jsx/ToastState.native.js +280 -290
- package/dist/jsx/ToastState.native.js.map +1 -1
- package/dist/jsx/createNativeToast.mjs +22 -26
- package/dist/jsx/createNativeToast.mjs.map +1 -1
- package/dist/jsx/createNativeToast.native.cjs +54 -0
- package/dist/jsx/createNativeToast.native.js +36 -40
- package/dist/jsx/createNativeToast.native.js.map +1 -1
- package/dist/jsx/dispatchNativeToast.mjs +19 -17
- package/dist/jsx/dispatchNativeToast.mjs.map +1 -1
- package/dist/jsx/dispatchNativeToast.native.cjs +48 -0
- package/dist/jsx/dispatchNativeToast.native.js +34 -36
- package/dist/jsx/dispatchNativeToast.native.js.map +1 -1
- package/dist/jsx/index.js +5 -2
- package/dist/jsx/index.mjs +5 -2
- package/dist/jsx/index.native.cjs +35 -0
- package/dist/jsx/index.native.js +26 -12
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.native.cjs +19 -0
- package/dist/jsx/types.native.js +10 -10
- package/dist/jsx/types.native.js.map +1 -1
- package/dist/jsx/useAnimatedDragGesture.mjs +181 -168
- package/dist/jsx/useAnimatedDragGesture.mjs.map +1 -1
- package/dist/jsx/useAnimatedDragGesture.native.cjs +210 -0
- package/dist/jsx/useAnimatedDragGesture.native.js +179 -191
- package/dist/jsx/useAnimatedDragGesture.native.js.map +1 -1
- package/dist/jsx/useReducedMotion.mjs +31 -29
- package/dist/jsx/useReducedMotion.mjs.map +1 -1
- package/dist/jsx/useReducedMotion.native.cjs +74 -0
- package/dist/jsx/useReducedMotion.native.js +53 -60
- package/dist/jsx/useReducedMotion.native.js.map +1 -1
- package/dist/jsx/useToastAnimations.mjs +183 -245
- package/dist/jsx/useToastAnimations.mjs.map +1 -1
- package/dist/jsx/useToastAnimations.native.cjs +229 -0
- package/dist/jsx/useToastAnimations.native.js +205 -276
- package/dist/jsx/useToastAnimations.native.js.map +1 -1
- package/package.json +20 -37
- package/src/ToastComposable.tsx +55 -97
- package/src/ToastItemFrame.tsx +22 -81
- package/src/ToastState.ts +1 -0
- package/src/index.ts +34 -2
- package/src/types.ts +11 -0
- package/src/useAnimatedDragGesture.native.ts +1 -1
- package/src/useAnimatedDragGesture.ts +1 -1
- package/src/useToastAnimations.ts +20 -36
- package/types/ToastComposable.d.ts +124 -47
- package/types/ToastComposable.d.ts.map +1 -1
- package/types/ToastItemFrame.d.ts +52 -21
- package/types/ToastItemFrame.d.ts.map +1 -1
- package/types/ToastState.d.ts +15 -11
- package/types/ToastState.d.ts.map +1 -1
- package/types/index.d.ts +6 -2
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +1 -0
- package/types/types.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.d.ts +1 -1
- package/types/useAnimatedDragGesture.d.ts.map +1 -1
- package/types/useAnimatedDragGesture.native.d.ts +1 -1
- package/types/useAnimatedDragGesture.native.d.ts.map +1 -1
- package/types/useToastAnimations.d.ts +2 -8
- package/types/useToastAnimations.d.ts.map +1 -1
- package/dist/cjs/Toast.cjs +0 -178
- package/dist/cjs/Toast.native.js +0 -181
- package/dist/cjs/Toast.native.js.map +0 -1
- package/dist/cjs/ToastAnnounce.cjs +0 -103
- package/dist/cjs/ToastAnnounce.native.js +0 -111
- package/dist/cjs/ToastAnnounce.native.js.map +0 -1
- package/dist/cjs/ToastImperative.cjs +0 -119
- package/dist/cjs/ToastImperative.native.js +0 -130
- package/dist/cjs/ToastImperative.native.js.map +0 -1
- package/dist/cjs/ToastImpl.cjs +0 -354
- package/dist/cjs/ToastImpl.native.js +0 -364
- package/dist/cjs/ToastImpl.native.js.map +0 -1
- package/dist/cjs/ToastPortal.cjs +0 -49
- package/dist/cjs/ToastPortal.native.js +0 -52
- package/dist/cjs/ToastPortal.native.js.map +0 -1
- package/dist/cjs/ToastProvider.cjs +0 -150
- package/dist/cjs/ToastProvider.native.js +0 -161
- package/dist/cjs/ToastProvider.native.js.map +0 -1
- package/dist/cjs/ToastViewport.cjs +0 -319
- package/dist/cjs/ToastViewport.native.js +0 -343
- package/dist/cjs/ToastViewport.native.js.map +0 -1
- package/dist/cjs/Toaster.cjs +0 -87
- package/dist/cjs/Toaster.native.js +0 -91
- package/dist/cjs/Toaster.native.js.map +0 -1
- package/dist/cjs/constants.cjs +0 -30
- package/dist/cjs/constants.native.js +0 -33
- package/dist/cjs/constants.native.js.map +0 -1
- package/dist/cjs/v2.cjs +0 -36
- package/dist/cjs/v2.native.js +0 -39
- package/dist/cjs/v2.native.js.map +0 -1
- package/dist/esm/Toast.mjs +0 -137
- package/dist/esm/Toast.mjs.map +0 -1
- package/dist/esm/Toast.native.js +0 -137
- package/dist/esm/Toast.native.js.map +0 -1
- package/dist/esm/ToastAnnounce.mjs +0 -66
- package/dist/esm/ToastAnnounce.mjs.map +0 -1
- package/dist/esm/ToastAnnounce.native.js +0 -71
- package/dist/esm/ToastAnnounce.native.js.map +0 -1
- package/dist/esm/ToastImperative.mjs +0 -80
- package/dist/esm/ToastImperative.mjs.map +0 -1
- package/dist/esm/ToastImperative.native.js +0 -88
- package/dist/esm/ToastImperative.native.js.map +0 -1
- package/dist/esm/ToastImpl.mjs +0 -316
- package/dist/esm/ToastImpl.mjs.map +0 -1
- package/dist/esm/ToastImpl.native.js +0 -329
- package/dist/esm/ToastImpl.native.js.map +0 -1
- package/dist/esm/ToastPortal.mjs +0 -24
- package/dist/esm/ToastPortal.mjs.map +0 -1
- package/dist/esm/ToastPortal.native.js +0 -24
- package/dist/esm/ToastPortal.native.js.map +0 -1
- package/dist/esm/ToastProvider.mjs +0 -110
- package/dist/esm/ToastProvider.mjs.map +0 -1
- package/dist/esm/ToastProvider.native.js +0 -118
- package/dist/esm/ToastProvider.native.js.map +0 -1
- package/dist/esm/ToastViewport.mjs +0 -280
- package/dist/esm/ToastViewport.mjs.map +0 -1
- package/dist/esm/ToastViewport.native.js +0 -301
- package/dist/esm/ToastViewport.native.js.map +0 -1
- package/dist/esm/Toaster.mjs +0 -51
- package/dist/esm/Toaster.mjs.map +0 -1
- package/dist/esm/Toaster.native.js +0 -52
- package/dist/esm/Toaster.native.js.map +0 -1
- package/dist/esm/constants.mjs +0 -4
- package/dist/esm/constants.mjs.map +0 -1
- package/dist/esm/constants.native.js +0 -4
- package/dist/esm/constants.native.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/types.native.js.map +0 -1
- package/dist/esm/v2.mjs +0 -6
- package/dist/esm/v2.mjs.map +0 -1
- package/dist/esm/v2.native.js +0 -6
- package/dist/esm/v2.native.js.map +0 -1
- package/dist/jsx/Toast.mjs +0 -137
- package/dist/jsx/Toast.mjs.map +0 -1
- package/dist/jsx/Toast.native.js +0 -181
- package/dist/jsx/Toast.native.js.map +0 -1
- package/dist/jsx/ToastAnnounce.mjs +0 -66
- package/dist/jsx/ToastAnnounce.mjs.map +0 -1
- package/dist/jsx/ToastAnnounce.native.js +0 -111
- package/dist/jsx/ToastAnnounce.native.js.map +0 -1
- package/dist/jsx/ToastImperative.mjs +0 -80
- package/dist/jsx/ToastImperative.mjs.map +0 -1
- package/dist/jsx/ToastImperative.native.js +0 -130
- package/dist/jsx/ToastImperative.native.js.map +0 -1
- package/dist/jsx/ToastImpl.mjs +0 -316
- package/dist/jsx/ToastImpl.mjs.map +0 -1
- package/dist/jsx/ToastImpl.native.js +0 -364
- package/dist/jsx/ToastImpl.native.js.map +0 -1
- package/dist/jsx/ToastPortal.mjs +0 -24
- package/dist/jsx/ToastPortal.mjs.map +0 -1
- package/dist/jsx/ToastPortal.native.js +0 -52
- package/dist/jsx/ToastPortal.native.js.map +0 -1
- package/dist/jsx/ToastProvider.mjs +0 -110
- package/dist/jsx/ToastProvider.mjs.map +0 -1
- package/dist/jsx/ToastProvider.native.js +0 -161
- package/dist/jsx/ToastProvider.native.js.map +0 -1
- package/dist/jsx/ToastViewport.mjs +0 -280
- package/dist/jsx/ToastViewport.mjs.map +0 -1
- package/dist/jsx/ToastViewport.native.js +0 -343
- package/dist/jsx/ToastViewport.native.js.map +0 -1
- package/dist/jsx/Toaster.mjs +0 -51
- package/dist/jsx/Toaster.mjs.map +0 -1
- package/dist/jsx/Toaster.native.js +0 -91
- package/dist/jsx/Toaster.native.js.map +0 -1
- package/dist/jsx/constants.mjs +0 -4
- package/dist/jsx/constants.mjs.map +0 -1
- package/dist/jsx/constants.native.js +0 -33
- package/dist/jsx/constants.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/types.mjs.map +0 -1
- package/dist/jsx/v2.mjs +0 -6
- package/dist/jsx/v2.mjs.map +0 -1
- package/dist/jsx/v2.native.js +0 -39
- package/dist/jsx/v2.native.js.map +0 -1
- package/src/Toast.tsx +0 -219
- package/src/ToastAnnounce.tsx +0 -103
- package/src/ToastImperative.tsx +0 -192
- package/src/ToastImpl.tsx +0 -514
- package/src/ToastPortal.tsx +0 -19
- package/src/ToastProvider.tsx +0 -204
- package/src/ToastViewport.tsx +0 -430
- package/src/Toaster.tsx +0 -181
- package/src/constants.ts +0 -2
- package/src/v2.ts +0 -31
- package/types/Toast.d.ts +0 -84
- package/types/Toast.d.ts.map +0 -1
- package/types/ToastAnnounce.d.ts +0 -18
- package/types/ToastAnnounce.d.ts.map +0 -1
- package/types/ToastImperative.d.ts +0 -95
- package/types/ToastImperative.d.ts.map +0 -1
- package/types/ToastImpl.d.ts +0 -109
- package/types/ToastImpl.d.ts.map +0 -1
- package/types/ToastPortal.d.ts +0 -8
- package/types/ToastPortal.d.ts.map +0 -1
- package/types/ToastProvider.d.ts +0 -92
- package/types/ToastProvider.d.ts.map +0 -1
- package/types/ToastViewport.d.ts +0 -75
- package/types/ToastViewport.d.ts.map +0 -1
- package/types/Toaster.d.ts +0 -112
- package/types/Toaster.d.ts.map +0 -1
- package/types/constants.d.ts +0 -3
- package/types/constants.d.ts.map +0 -1
- package/types/v2.d.ts +0 -10
- package/types/v2.d.ts.map +0 -1
- package/v2/index.cjs +0 -2
- package/v2/index.js +0 -2
- package/v2/index.native.cjs +0 -2
- package/v2/index.native.js +0 -2
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var ToastImperative_exports = {};
|
|
35
|
-
__export(ToastImperative_exports, {
|
|
36
|
-
ToastImperativeProvider: () => ToastImperativeProvider,
|
|
37
|
-
useToast: () => useToast,
|
|
38
|
-
useToastController: () => useToastController,
|
|
39
|
-
useToastState: () => useToastState
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(ToastImperative_exports);
|
|
42
|
-
var import_core = require("@tamagui/core");
|
|
43
|
-
var import_react = __toESM(require("react"), 1);
|
|
44
|
-
var import_createNativeToast = require("./createNativeToast.cjs");
|
|
45
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
-
const ToastContext = import_react.default.createContext({});
|
|
47
|
-
const ToastCurrentContext = import_react.default.createContext(null);
|
|
48
|
-
const useToastController = () => {
|
|
49
|
-
return import_react.default.useContext(ToastContext);
|
|
50
|
-
};
|
|
51
|
-
const useToastState = () => {
|
|
52
|
-
return import_react.default.useContext(ToastCurrentContext);
|
|
53
|
-
};
|
|
54
|
-
const useToast = () => {
|
|
55
|
-
return {
|
|
56
|
-
...useToastController(),
|
|
57
|
-
currentToast: useToastState()
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
const ToastImperativeProvider = ({
|
|
61
|
-
children,
|
|
62
|
-
options
|
|
63
|
-
}) => {
|
|
64
|
-
const counterRef = import_react.default.useRef(0);
|
|
65
|
-
const [toast, setToast] = import_react.default.useState(null);
|
|
66
|
-
const [lastNativeToastRef, setLastNativeToastRef] = import_react.default.useState(null);
|
|
67
|
-
const show = import_react.default.useCallback((title, showOptions) => {
|
|
68
|
-
const native = showOptions?.native ?? options.native;
|
|
69
|
-
const isWebNative = Array.isArray(native) ? native.includes("web") : native === "web";
|
|
70
|
-
const isMobileNative = Array.isArray(native) ? native.includes("mobile") : native === "mobile";
|
|
71
|
-
const isAndroidNative = isMobileNative || (Array.isArray(native) ? native.includes("android") : native === "android");
|
|
72
|
-
const isIosNative = isMobileNative || (Array.isArray(native) ? native.includes("ios") : native === "ios");
|
|
73
|
-
const isHandledNatively = native === true || import_core.isWeb && isWebNative || !import_core.isWeb && isMobileNative || import_core.isAndroid && isAndroidNative || import_core.isIos && isIosNative;
|
|
74
|
-
if (isHandledNatively) {
|
|
75
|
-
const nativeToastResult = (0, import_createNativeToast.createNativeToast)(title, showOptions ?? {});
|
|
76
|
-
if (typeof nativeToastResult === "object" && nativeToastResult.nativeToastRef) {
|
|
77
|
-
setLastNativeToastRef(nativeToastResult.nativeToastRef);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
counterRef.current++;
|
|
81
|
-
setToast({
|
|
82
|
-
...showOptions?.customData,
|
|
83
|
-
...showOptions,
|
|
84
|
-
viewportName: showOptions?.viewportName ?? "default",
|
|
85
|
-
title,
|
|
86
|
-
id: counterRef.current.toString(),
|
|
87
|
-
isHandledNatively
|
|
88
|
-
});
|
|
89
|
-
return true;
|
|
90
|
-
}, [setToast, JSON.stringify(options.native || null)]);
|
|
91
|
-
const hide = import_react.default.useCallback(() => {
|
|
92
|
-
lastNativeToastRef?.close();
|
|
93
|
-
setToast(prev => {
|
|
94
|
-
if (!prev) return null;
|
|
95
|
-
return {
|
|
96
|
-
...prev,
|
|
97
|
-
hide: true
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
setTimeout(() => {
|
|
101
|
-
setToast(null);
|
|
102
|
-
}, 100);
|
|
103
|
-
}, [setToast, lastNativeToastRef]);
|
|
104
|
-
const contextValue = import_react.default.useMemo(() => {
|
|
105
|
-
return {
|
|
106
|
-
show,
|
|
107
|
-
hide,
|
|
108
|
-
nativeToast: lastNativeToastRef,
|
|
109
|
-
options
|
|
110
|
-
};
|
|
111
|
-
}, [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
|
|
112
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
|
|
113
|
-
value: contextValue,
|
|
114
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCurrentContext.Provider, {
|
|
115
|
-
value: toast,
|
|
116
|
-
children
|
|
117
|
-
})
|
|
118
|
-
});
|
|
119
|
-
};
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all) __defProp(target, name, {
|
|
11
|
-
get: all[name],
|
|
12
|
-
enumerable: true
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
-
get: () => from[key],
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
32
|
-
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
36
|
-
var ToastImperative_exports = {};
|
|
37
|
-
__export(ToastImperative_exports, {
|
|
38
|
-
ToastImperativeProvider: () => ToastImperativeProvider,
|
|
39
|
-
useToast: () => useToast,
|
|
40
|
-
useToastController: () => useToastController,
|
|
41
|
-
useToastState: () => useToastState
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(ToastImperative_exports);
|
|
44
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
-
var import_core = require("@tamagui/core");
|
|
46
|
-
var import_react = __toESM(require("react"), 1);
|
|
47
|
-
var import_createNativeToast = require("./createNativeToast.native.js");
|
|
48
|
-
function _type_of(obj) {
|
|
49
|
-
"@swc/helpers - typeof";
|
|
50
|
-
|
|
51
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
52
|
-
}
|
|
53
|
-
var ToastContext = /* @__PURE__ */import_react.default.createContext({});
|
|
54
|
-
var ToastCurrentContext = /* @__PURE__ */import_react.default.createContext(null);
|
|
55
|
-
var useToastController = function () {
|
|
56
|
-
return import_react.default.useContext(ToastContext);
|
|
57
|
-
};
|
|
58
|
-
var useToastState = function () {
|
|
59
|
-
return import_react.default.useContext(ToastCurrentContext);
|
|
60
|
-
};
|
|
61
|
-
var useToast = function () {
|
|
62
|
-
return {
|
|
63
|
-
...useToastController(),
|
|
64
|
-
currentToast: useToastState()
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var ToastImperativeProvider = function (param) {
|
|
68
|
-
var {
|
|
69
|
-
children,
|
|
70
|
-
options
|
|
71
|
-
} = param;
|
|
72
|
-
var counterRef = import_react.default.useRef(0);
|
|
73
|
-
var [toast, setToast] = import_react.default.useState(null);
|
|
74
|
-
var [lastNativeToastRef, setLastNativeToastRef] = import_react.default.useState(null);
|
|
75
|
-
var show = import_react.default.useCallback(function (title, showOptions) {
|
|
76
|
-
var _showOptions_native;
|
|
77
|
-
var native = (_showOptions_native = showOptions === null || showOptions === void 0 ? void 0 : showOptions.native) !== null && _showOptions_native !== void 0 ? _showOptions_native : options.native;
|
|
78
|
-
var isWebNative = Array.isArray(native) ? native.includes("web") : native === "web";
|
|
79
|
-
var isMobileNative = Array.isArray(native) ? native.includes("mobile") : native === "mobile";
|
|
80
|
-
var isAndroidNative = isMobileNative || (Array.isArray(native) ? native.includes("android") : native === "android");
|
|
81
|
-
var isIosNative = isMobileNative || (Array.isArray(native) ? native.includes("ios") : native === "ios");
|
|
82
|
-
var isHandledNatively = native === true || import_core.isWeb && isWebNative || !import_core.isWeb && isMobileNative || import_core.isAndroid && isAndroidNative || import_core.isIos && isIosNative;
|
|
83
|
-
if (isHandledNatively) {
|
|
84
|
-
var nativeToastResult = (0, import_createNativeToast.createNativeToast)(title, showOptions !== null && showOptions !== void 0 ? showOptions : {});
|
|
85
|
-
if ((typeof nativeToastResult === "undefined" ? "undefined" : _type_of(nativeToastResult)) === "object" && nativeToastResult.nativeToastRef) {
|
|
86
|
-
setLastNativeToastRef(nativeToastResult.nativeToastRef);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
counterRef.current++;
|
|
90
|
-
var _showOptions_viewportName;
|
|
91
|
-
setToast({
|
|
92
|
-
...(showOptions === null || showOptions === void 0 ? void 0 : showOptions.customData),
|
|
93
|
-
...showOptions,
|
|
94
|
-
viewportName: (_showOptions_viewportName = showOptions === null || showOptions === void 0 ? void 0 : showOptions.viewportName) !== null && _showOptions_viewportName !== void 0 ? _showOptions_viewportName : "default",
|
|
95
|
-
title,
|
|
96
|
-
id: counterRef.current.toString(),
|
|
97
|
-
isHandledNatively
|
|
98
|
-
});
|
|
99
|
-
return true;
|
|
100
|
-
}, [setToast, JSON.stringify(options.native || null)]);
|
|
101
|
-
var hide = import_react.default.useCallback(function () {
|
|
102
|
-
lastNativeToastRef === null || lastNativeToastRef === void 0 ? void 0 : lastNativeToastRef.close();
|
|
103
|
-
setToast(function (prev) {
|
|
104
|
-
if (!prev) return null;
|
|
105
|
-
return {
|
|
106
|
-
...prev,
|
|
107
|
-
hide: true
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
setTimeout(function () {
|
|
111
|
-
setToast(null);
|
|
112
|
-
}, 100);
|
|
113
|
-
}, [setToast, lastNativeToastRef]);
|
|
114
|
-
var contextValue = import_react.default.useMemo(function () {
|
|
115
|
-
return {
|
|
116
|
-
show,
|
|
117
|
-
hide,
|
|
118
|
-
nativeToast: lastNativeToastRef,
|
|
119
|
-
options
|
|
120
|
-
};
|
|
121
|
-
}, [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
|
|
122
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
|
|
123
|
-
value: contextValue,
|
|
124
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCurrentContext.Provider, {
|
|
125
|
-
value: toast,
|
|
126
|
-
children
|
|
127
|
-
})
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
//# sourceMappingURL=ToastImperative.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","ToastImperative_exports","__export","ToastImperativeProvider","useToast","useToastController","useToastState","module","exports","import_jsx_runtime","require","import_core","import_react","__toESM","import_createNativeToast","_type_of","obj","Symbol","constructor","ToastContext","default","createContext","ToastCurrentContext","useContext","currentToast","param","children","options","counterRef","useRef","toast","setToast","useState","lastNativeToastRef","setLastNativeToastRef","show","useCallback","title","showOptions","_showOptions_native","native","isWebNative","Array","isArray","includes","isMobileNative","isAndroidNative","isIosNative","isHandledNatively","isWeb","isAndroid","isIos","nativeToastResult","createNativeToast","nativeToastRef","current","_showOptions_viewportName","customData","viewportName","id","toString","JSON","stringify","hide","close","prev","setTimeout","contextValue","useMemo"],"sources":["../../src/ToastImperative.tsx"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
|
package/dist/cjs/ToastImpl.cjs
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var ToastImpl_exports = {};
|
|
35
|
-
__export(ToastImpl_exports, {
|
|
36
|
-
ToastImpl: () => ToastImpl,
|
|
37
|
-
ToastImplFrame: () => ToastImplFrame,
|
|
38
|
-
useToastInteractiveContext: () => useToastInteractiveContext
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(ToastImpl_exports);
|
|
41
|
-
var import_animate_presence = require("@tamagui/animate-presence");
|
|
42
|
-
var import_compose_refs = require("@tamagui/compose-refs");
|
|
43
|
-
var import_constants = require("@tamagui/constants");
|
|
44
|
-
var import_core = require("@tamagui/core");
|
|
45
|
-
var import_dismissable = require("@tamagui/dismissable");
|
|
46
|
-
var import_helpers = require("@tamagui/helpers");
|
|
47
|
-
var import_portal = require("@tamagui/portal");
|
|
48
|
-
var import_stacks = require("@tamagui/stacks");
|
|
49
|
-
var React = __toESM(require("react"), 1);
|
|
50
|
-
var import_constants2 = require("./constants.cjs");
|
|
51
|
-
var import_ToastAnnounce = require("./ToastAnnounce.cjs");
|
|
52
|
-
var import_ToastProvider = require("./ToastProvider.cjs");
|
|
53
|
-
var import_ToastViewport = require("./ToastViewport.cjs");
|
|
54
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
55
|
-
const getPanResponder = () => {
|
|
56
|
-
return null;
|
|
57
|
-
};
|
|
58
|
-
const ToastImplFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
59
|
-
name: "ToastImpl",
|
|
60
|
-
tabIndex: 0,
|
|
61
|
-
variants: {
|
|
62
|
-
unstyled: {
|
|
63
|
-
false: {
|
|
64
|
-
focusStyle: {
|
|
65
|
-
outlineStyle: "solid",
|
|
66
|
-
outlineWidth: 2,
|
|
67
|
-
outlineColor: "$outlineColor"
|
|
68
|
-
},
|
|
69
|
-
backgroundColor: "$color6",
|
|
70
|
-
borderRadius: "$4",
|
|
71
|
-
paddingHorizontal: "$4",
|
|
72
|
-
paddingVertical: "$3",
|
|
73
|
-
marginHorizontal: "auto",
|
|
74
|
-
marginVertical: "$1",
|
|
75
|
-
elevation: "$3"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
defaultVariants: {
|
|
80
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const {
|
|
84
|
-
Provider: ToastInteractiveProvider,
|
|
85
|
-
useStyledContext: useToastInteractiveContext
|
|
86
|
-
} = (0, import_core.createStyledContext)({
|
|
87
|
-
onClose() {}
|
|
88
|
-
});
|
|
89
|
-
const ToastImpl = React.forwardRef((props, forwardedRef) => {
|
|
90
|
-
const {
|
|
91
|
-
scope,
|
|
92
|
-
type = "foreground",
|
|
93
|
-
duration: durationProp,
|
|
94
|
-
open,
|
|
95
|
-
onClose,
|
|
96
|
-
onEscapeKeyDown,
|
|
97
|
-
onPause,
|
|
98
|
-
onResume,
|
|
99
|
-
onSwipeStart,
|
|
100
|
-
onSwipeMove,
|
|
101
|
-
onSwipeCancel,
|
|
102
|
-
onSwipeEnd,
|
|
103
|
-
viewportName = "default",
|
|
104
|
-
...toastProps
|
|
105
|
-
} = props;
|
|
106
|
-
const isPresent = (0, import_animate_presence.useIsPresent)();
|
|
107
|
-
const context = (0, import_ToastProvider.useToastProviderContext)(scope);
|
|
108
|
-
const [node, setNode] = React.useState(null);
|
|
109
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setNode);
|
|
110
|
-
const duration = durationProp || context.duration;
|
|
111
|
-
const closeTimerStartTimeRef = React.useRef(0);
|
|
112
|
-
const closeTimerRemainingTimeRef = React.useRef(duration);
|
|
113
|
-
const closeTimerRef = React.useRef(0);
|
|
114
|
-
const {
|
|
115
|
-
onToastAdd,
|
|
116
|
-
onToastRemove
|
|
117
|
-
} = context;
|
|
118
|
-
const viewport = React.useMemo(() => {
|
|
119
|
-
return context.viewports[viewportName];
|
|
120
|
-
}, [context.viewports, viewportName]);
|
|
121
|
-
const handleClose = (0, import_core.useEvent)(() => {
|
|
122
|
-
if (!isPresent) return;
|
|
123
|
-
if (import_constants.isWeb) {
|
|
124
|
-
if (node?.contains(document.activeElement)) viewport?.focus();
|
|
125
|
-
}
|
|
126
|
-
onClose();
|
|
127
|
-
});
|
|
128
|
-
const startTimer = React.useCallback(duration2 => {
|
|
129
|
-
if (!duration2 || duration2 === Number.POSITIVE_INFINITY) return;
|
|
130
|
-
clearTimeout(closeTimerRef.current);
|
|
131
|
-
closeTimerStartTimeRef.current = (/* @__PURE__ */new Date()).getTime();
|
|
132
|
-
closeTimerRef.current = setTimeout(handleClose, duration2);
|
|
133
|
-
}, [handleClose]);
|
|
134
|
-
const handleResume = React.useCallback(() => {
|
|
135
|
-
startTimer(closeTimerRemainingTimeRef.current);
|
|
136
|
-
onResume?.();
|
|
137
|
-
}, [onResume, startTimer]);
|
|
138
|
-
const handlePause = React.useCallback(() => {
|
|
139
|
-
const elapsedTime = (/* @__PURE__ */new Date()).getTime() - closeTimerStartTimeRef.current;
|
|
140
|
-
closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
|
|
141
|
-
window.clearTimeout(closeTimerRef.current);
|
|
142
|
-
onPause?.();
|
|
143
|
-
}, [onPause]);
|
|
144
|
-
React.useEffect(() => {
|
|
145
|
-
if (!import_constants.isWeb) return;
|
|
146
|
-
if (viewport) {
|
|
147
|
-
viewport.addEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause);
|
|
148
|
-
viewport.addEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume);
|
|
149
|
-
return () => {
|
|
150
|
-
viewport.removeEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause);
|
|
151
|
-
viewport.removeEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}, [viewport, duration, onPause, onResume, startTimer]);
|
|
155
|
-
React.useEffect(() => {
|
|
156
|
-
if (open && !context.isClosePausedRef.current) startTimer(duration);
|
|
157
|
-
}, [open, duration, context.isClosePausedRef, startTimer]);
|
|
158
|
-
React.useEffect(() => {
|
|
159
|
-
onToastAdd();
|
|
160
|
-
return () => onToastRemove();
|
|
161
|
-
}, [onToastAdd, onToastRemove]);
|
|
162
|
-
const announceTextContent = React.useMemo(() => {
|
|
163
|
-
if (!import_constants.isWeb) return null;
|
|
164
|
-
return node ? getAnnounceTextContent(node) : null;
|
|
165
|
-
}, [node]);
|
|
166
|
-
const isHorizontalSwipe = ["left", "right", "horizontal"].includes(context.swipeDirection);
|
|
167
|
-
const {
|
|
168
|
-
animationDriver
|
|
169
|
-
} = (0, import_core.useConfiguration)();
|
|
170
|
-
if (!animationDriver) throw new Error("Must set animations in tamagui.config.ts");
|
|
171
|
-
const {
|
|
172
|
-
useAnimatedNumber,
|
|
173
|
-
useAnimatedNumberStyle
|
|
174
|
-
} = animationDriver;
|
|
175
|
-
const animatedNumber = useAnimatedNumber(0);
|
|
176
|
-
const AnimatedView = animationDriver["NumberView"] ?? animationDriver.View ?? import_core.View;
|
|
177
|
-
const animatedStyles = useAnimatedNumberStyle(animatedNumber, val => {
|
|
178
|
-
"worklet";
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
transform: [isHorizontalSwipe ? {
|
|
182
|
-
translateX: val
|
|
183
|
-
} : {
|
|
184
|
-
translateY: val
|
|
185
|
-
}]
|
|
186
|
-
};
|
|
187
|
-
});
|
|
188
|
-
const panResponder = React.useMemo(() => {
|
|
189
|
-
const PanResponder = getPanResponder();
|
|
190
|
-
if (!PanResponder) return null;
|
|
191
|
-
return PanResponder.create({
|
|
192
|
-
onMoveShouldSetPanResponder: (e, gesture) => {
|
|
193
|
-
if (shouldGrantGestureMove(context.swipeDirection, gesture)) {
|
|
194
|
-
onSwipeStart?.(e);
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
return false;
|
|
198
|
-
},
|
|
199
|
-
onPanResponderGrant: e => {
|
|
200
|
-
if (!import_constants.isWeb) handlePause?.();
|
|
201
|
-
},
|
|
202
|
-
onPanResponderMove: (e, gesture) => {
|
|
203
|
-
const {
|
|
204
|
-
x,
|
|
205
|
-
y
|
|
206
|
-
} = getGestureDistance(context.swipeDirection, gesture);
|
|
207
|
-
const delta = {
|
|
208
|
-
x,
|
|
209
|
-
y
|
|
210
|
-
};
|
|
211
|
-
animatedNumber.setValue(isHorizontalSwipe ? x : y, {
|
|
212
|
-
type: "direct"
|
|
213
|
-
});
|
|
214
|
-
if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) onSwipeEnd?.(e);
|
|
215
|
-
onSwipeMove?.(e);
|
|
216
|
-
},
|
|
217
|
-
onPanResponderEnd: (e, {
|
|
218
|
-
dx,
|
|
219
|
-
dy
|
|
220
|
-
}) => {
|
|
221
|
-
if (!isDeltaInDirection({
|
|
222
|
-
x: dx,
|
|
223
|
-
y: dy
|
|
224
|
-
}, context.swipeDirection, context.swipeThreshold)) {
|
|
225
|
-
if (!import_constants.isWeb) handleResume?.();
|
|
226
|
-
onSwipeCancel?.(e);
|
|
227
|
-
animatedNumber.setValue(0, {
|
|
228
|
-
type: "spring"
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}, [handlePause, handleResume]);
|
|
234
|
-
const themeName = (0, import_core.useThemeName)();
|
|
235
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
|
236
|
-
children: [announceTextContent && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounce, {
|
|
237
|
-
scope,
|
|
238
|
-
role: "status",
|
|
239
|
-
"aria-live": type === "foreground" ? "assertive" : "polite",
|
|
240
|
-
"aria-atomic": true,
|
|
241
|
-
children: announceTextContent
|
|
242
|
-
}), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
|
|
243
|
-
hostName: viewportName ?? "default",
|
|
244
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastInteractiveProvider, {
|
|
245
|
-
scope,
|
|
246
|
-
onClose: () => {
|
|
247
|
-
handleClose();
|
|
248
|
-
},
|
|
249
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
|
|
250
|
-
onEscapeKeyDown: (0, import_helpers.composeEventHandlers)(onEscapeKeyDown, () => {
|
|
251
|
-
if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
|
|
252
|
-
context.isFocusedToastEscapeKeyDownRef.current = false;
|
|
253
|
-
}),
|
|
254
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
|
|
255
|
-
contain: true,
|
|
256
|
-
forceClassName: true,
|
|
257
|
-
name: themeName,
|
|
258
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
|
|
259
|
-
...panResponder?.panHandlers,
|
|
260
|
-
style: [{
|
|
261
|
-
margin: "auto"
|
|
262
|
-
}, animatedStyles],
|
|
263
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.ItemSlot, {
|
|
264
|
-
scope: context.toastScope,
|
|
265
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastImplFrame, {
|
|
266
|
-
role: "status",
|
|
267
|
-
"aria-live": "off",
|
|
268
|
-
"aria-atomic": true,
|
|
269
|
-
"data-state": open ? "open" : "closed",
|
|
270
|
-
"data-swipe-direction": context.swipeDirection,
|
|
271
|
-
pointerEvents: "auto",
|
|
272
|
-
"$platform-web": {
|
|
273
|
-
touchAction: "none",
|
|
274
|
-
userSelect: "none"
|
|
275
|
-
},
|
|
276
|
-
...toastProps,
|
|
277
|
-
ref: composedRefs,
|
|
278
|
-
...(import_constants.isWeb && {
|
|
279
|
-
onKeyDown: (0, import_helpers.composeEventHandlers)(props.onKeyDown, event => {
|
|
280
|
-
if (event.key !== "Escape") return;
|
|
281
|
-
onEscapeKeyDown?.(event);
|
|
282
|
-
if (!event.defaultPrevented) {
|
|
283
|
-
context.isFocusedToastEscapeKeyDownRef.current = true;
|
|
284
|
-
handleClose();
|
|
285
|
-
}
|
|
286
|
-
})
|
|
287
|
-
})
|
|
288
|
-
})
|
|
289
|
-
})
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
})
|
|
293
|
-
}, props.id)
|
|
294
|
-
})]
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
ToastImpl.propTypes = {
|
|
298
|
-
type(props) {
|
|
299
|
-
if (props.type && !["foreground", "background"].includes(props.type)) {
|
|
300
|
-
const error = `Invalid prop \`type\` supplied to \`${import_constants2.TOAST_NAME}\`. Expected \`foreground | background\`.`;
|
|
301
|
-
return new Error(error);
|
|
302
|
-
}
|
|
303
|
-
return null;
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
const isDeltaInDirection = (delta, direction, threshold = 0) => {
|
|
307
|
-
const deltaX = Math.abs(delta.x);
|
|
308
|
-
const deltaY = Math.abs(delta.y);
|
|
309
|
-
const isDeltaX = deltaX > deltaY;
|
|
310
|
-
if (direction === "left" || direction === "right" || direction === "horizontal") return isDeltaX && deltaX > threshold;
|
|
311
|
-
return !isDeltaX && deltaY > threshold;
|
|
312
|
-
};
|
|
313
|
-
function getAnnounceTextContent(container) {
|
|
314
|
-
if (!import_constants.isWeb) return "";
|
|
315
|
-
const textContent = [];
|
|
316
|
-
Array.from(container.childNodes).forEach(node => {
|
|
317
|
-
if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
|
|
318
|
-
if (isHTMLElement(node)) {
|
|
319
|
-
const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
|
|
320
|
-
const isExcluded = node.dataset.toastAnnounceExclude === "";
|
|
321
|
-
if (!isHidden) if (isExcluded) {
|
|
322
|
-
const altText = node.dataset.toastAnnounceAlt;
|
|
323
|
-
if (altText) textContent.push(altText);
|
|
324
|
-
} else textContent.push(...getAnnounceTextContent(node));
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
return textContent;
|
|
328
|
-
}
|
|
329
|
-
function isHTMLElement(node) {
|
|
330
|
-
return node.nodeType === node.ELEMENT_NODE;
|
|
331
|
-
}
|
|
332
|
-
const GESTURE_GRANT_THRESHOLD = 10;
|
|
333
|
-
const shouldGrantGestureMove = (dir, {
|
|
334
|
-
dx,
|
|
335
|
-
dy
|
|
336
|
-
}) => {
|
|
337
|
-
if ((dir === "horizontal" || dir === "left") && dx < -GESTURE_GRANT_THRESHOLD) return true;
|
|
338
|
-
if ((dir === "horizontal" || dir === "right") && dx > GESTURE_GRANT_THRESHOLD) return true;
|
|
339
|
-
if ((dir === "vertical" || dir === "up") && dy > -GESTURE_GRANT_THRESHOLD) return true;
|
|
340
|
-
if ((dir === "vertical" || dir === "down") && dy < GESTURE_GRANT_THRESHOLD) return true;
|
|
341
|
-
return false;
|
|
342
|
-
};
|
|
343
|
-
const getGestureDistance = (dir, {
|
|
344
|
-
dx,
|
|
345
|
-
dy
|
|
346
|
-
}) => {
|
|
347
|
-
let y = 0;
|
|
348
|
-
let x = 0;
|
|
349
|
-
if (dir === "horizontal") x = dx;else if (dir === "left") x = Math.min(0, dx);else if (dir === "right") x = Math.max(0, dx);else if (dir === "vertical") y = dy;else if (dir === "up") y = Math.min(0, dy);else if (dir === "down") y = Math.max(0, dy);
|
|
350
|
-
return {
|
|
351
|
-
x,
|
|
352
|
-
y
|
|
353
|
-
};
|
|
354
|
-
};
|