toastify-all 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/LICENSE +1 -0
- package/README.md +311 -0
- package/dist/angular/angular/index.d.ts +29 -0
- package/dist/angular/angular/public-api.d.ts +1 -0
- package/dist/angular/core/AlertService.d.ts +39 -0
- package/dist/angular/core/NotificationCore.d.ts +51 -0
- package/dist/angular/index.d.ts +30 -0
- package/dist/angular/index.esm.js +949 -0
- package/dist/angular/index.esm.js.map +1 -0
- package/dist/angular/index.js +957 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/index.esm.js +824 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +831 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +837 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/react/index.d.ts +15 -0
- package/dist/react/index.esm.js +916 -0
- package/dist/react/index.esm.js.map +1 -0
- package/dist/react/index.js +925 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react-native/index.d.ts +17 -0
- package/dist/react-native/index.esm.js +146 -0
- package/dist/react-native/index.esm.js.map +1 -0
- package/dist/react-native/index.js +153 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/types/index.d.ts +95 -0
- package/dist/vue/index.d.ts +19 -0
- package/dist/vue/index.esm.js +845 -0
- package/dist/vue/index.esm.js.map +1 -0
- package/dist/vue/index.js +857 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +160 -0
|
@@ -0,0 +1,925 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
function _classCallCheck(a, n) {
|
|
10
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(e, r) {
|
|
13
|
+
for (var t = 0; t < r.length; t++) {
|
|
14
|
+
var o = r[t];
|
|
15
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function _createClass(e, r, t) {
|
|
19
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
20
|
+
writable: !1
|
|
21
|
+
}), e;
|
|
22
|
+
}
|
|
23
|
+
function _defineProperty(e, r, t) {
|
|
24
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
25
|
+
value: t,
|
|
26
|
+
enumerable: !0,
|
|
27
|
+
configurable: !0,
|
|
28
|
+
writable: !0
|
|
29
|
+
}) : e[r] = t, e;
|
|
30
|
+
}
|
|
31
|
+
function ownKeys(e, r) {
|
|
32
|
+
var t = Object.keys(e);
|
|
33
|
+
if (Object.getOwnPropertySymbols) {
|
|
34
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
35
|
+
r && (o = o.filter(function (r) {
|
|
36
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
37
|
+
})), t.push.apply(t, o);
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
}
|
|
41
|
+
function _objectSpread2(e) {
|
|
42
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
43
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
44
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
45
|
+
_defineProperty(e, r, t[r]);
|
|
46
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
47
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return e;
|
|
51
|
+
}
|
|
52
|
+
function _objectWithoutProperties(e, t) {
|
|
53
|
+
if (null == e) return {};
|
|
54
|
+
var o,
|
|
55
|
+
r,
|
|
56
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
57
|
+
if (Object.getOwnPropertySymbols) {
|
|
58
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
59
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
60
|
+
}
|
|
61
|
+
return i;
|
|
62
|
+
}
|
|
63
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
64
|
+
if (null == r) return {};
|
|
65
|
+
var t = {};
|
|
66
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
67
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
68
|
+
t[n] = r[n];
|
|
69
|
+
}
|
|
70
|
+
return t;
|
|
71
|
+
}
|
|
72
|
+
function _toPrimitive(t, r) {
|
|
73
|
+
if ("object" != typeof t || !t) return t;
|
|
74
|
+
var e = t[Symbol.toPrimitive];
|
|
75
|
+
if (void 0 !== e) {
|
|
76
|
+
var i = e.call(t, r || "default");
|
|
77
|
+
if ("object" != typeof i) return i;
|
|
78
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
79
|
+
}
|
|
80
|
+
return ("string" === r ? String : Number)(t);
|
|
81
|
+
}
|
|
82
|
+
function _toPropertyKey(t) {
|
|
83
|
+
var i = _toPrimitive(t, "string");
|
|
84
|
+
return "symbol" == typeof i ? i : i + "";
|
|
85
|
+
}
|
|
86
|
+
function _typeof(o) {
|
|
87
|
+
"@babel/helpers - typeof";
|
|
88
|
+
|
|
89
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
90
|
+
return typeof o;
|
|
91
|
+
} : function (o) {
|
|
92
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
93
|
+
}, _typeof(o);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var NotificationCore = /*#__PURE__*/function () {
|
|
97
|
+
function NotificationCore() {
|
|
98
|
+
var _this = this;
|
|
99
|
+
_classCallCheck(this, NotificationCore);
|
|
100
|
+
this.notifications = new Map();
|
|
101
|
+
this.counter = 0;
|
|
102
|
+
this.config = {
|
|
103
|
+
position: 'top-right',
|
|
104
|
+
autoClose: 5000,
|
|
105
|
+
hideProgressBar: false,
|
|
106
|
+
closeOnClick: true,
|
|
107
|
+
pauseOnHover: true,
|
|
108
|
+
pauseOnFocusLoss: true,
|
|
109
|
+
draggable: true,
|
|
110
|
+
draggablePercent: 80,
|
|
111
|
+
theme: 'light',
|
|
112
|
+
// 'light' | 'dark' | 'colored' | 'system'
|
|
113
|
+
transition: 'bounce',
|
|
114
|
+
// 'bounce' | 'slide' | 'zoom' | 'flip'
|
|
115
|
+
limit: null,
|
|
116
|
+
newestOnTop: true,
|
|
117
|
+
closeButton: true,
|
|
118
|
+
sound: false
|
|
119
|
+
};
|
|
120
|
+
this.containers = new Map();
|
|
121
|
+
this.initialized = false;
|
|
122
|
+
this.isWindowFocused = true;
|
|
123
|
+
if (typeof window !== 'undefined') {
|
|
124
|
+
window.addEventListener('focus', function () {
|
|
125
|
+
_this.isWindowFocused = true;
|
|
126
|
+
_this.resumeAll();
|
|
127
|
+
});
|
|
128
|
+
window.addEventListener('blur', function () {
|
|
129
|
+
_this.isWindowFocused = false;
|
|
130
|
+
_this.pauseAll();
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
var darkQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
134
|
+
darkQuery.addEventListener('change', function () {
|
|
135
|
+
if (_this.config.theme === 'system') {
|
|
136
|
+
_this.refreshSystemTheme();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
} catch (e) {}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return _createClass(NotificationCore, [{
|
|
143
|
+
key: "getEffectiveTheme",
|
|
144
|
+
value: function getEffectiveTheme() {
|
|
145
|
+
var theme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.theme;
|
|
146
|
+
if (theme === 'system') {
|
|
147
|
+
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
148
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
149
|
+
}
|
|
150
|
+
return 'light';
|
|
151
|
+
}
|
|
152
|
+
return theme;
|
|
153
|
+
}
|
|
154
|
+
}, {
|
|
155
|
+
key: "refreshSystemTheme",
|
|
156
|
+
value: function refreshSystemTheme() {
|
|
157
|
+
if (typeof document === 'undefined') return;
|
|
158
|
+
var effectiveTheme = this.getEffectiveTheme('system');
|
|
159
|
+
var position = this.config.position;
|
|
160
|
+
this.containers.forEach(function (container) {
|
|
161
|
+
container.className = "notification-container toastify-all-container omnitoast-container ".concat(position, " ").concat(effectiveTheme, " Toastify__toast-container Toastify__toast-container--").concat(position, " theme-").concat(effectiveTheme);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "configure",
|
|
166
|
+
value: function configure() {
|
|
167
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
|
+
this.config = _objectSpread2(_objectSpread2({}, this.config), options);
|
|
169
|
+
if (typeof document !== 'undefined') {
|
|
170
|
+
var effectiveTheme = this.getEffectiveTheme(this.config.theme);
|
|
171
|
+
var position = this.config.position;
|
|
172
|
+
this.containers.forEach(function (container) {
|
|
173
|
+
container.className = "notification-container toastify-all-container omnitoast-container ".concat(position, " ").concat(effectiveTheme, " Toastify__toast-container Toastify__toast-container--").concat(position, " theme-").concat(effectiveTheme);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "init",
|
|
179
|
+
value: function init() {
|
|
180
|
+
if (typeof document === 'undefined') return;
|
|
181
|
+
this.injectStyles();
|
|
182
|
+
this.initialized = true;
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
key: "getContainer",
|
|
186
|
+
value: function getContainer() {
|
|
187
|
+
var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.config.position;
|
|
188
|
+
if (typeof document === 'undefined') return null;
|
|
189
|
+
this.init();
|
|
190
|
+
var effectiveTheme = this.getEffectiveTheme(this.config.theme);
|
|
191
|
+
var key = position;
|
|
192
|
+
if (this.containers.has(key)) {
|
|
193
|
+
var existing = this.containers.get(key);
|
|
194
|
+
if (existing && document.body.contains(existing)) {
|
|
195
|
+
return existing;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
var container = document.createElement('div');
|
|
199
|
+
container.className = "notification-container toastify-all-container omnitoast-container ".concat(position, " ").concat(effectiveTheme, " Toastify__toast-container Toastify__toast-container--").concat(position, " theme-").concat(effectiveTheme);
|
|
200
|
+
container.setAttribute('aria-live', 'polite');
|
|
201
|
+
document.body.appendChild(container);
|
|
202
|
+
this.containers.set(key, container);
|
|
203
|
+
return container;
|
|
204
|
+
}
|
|
205
|
+
}, {
|
|
206
|
+
key: "playChime",
|
|
207
|
+
value: function playChime(type) {
|
|
208
|
+
if (typeof window === 'undefined') return;
|
|
209
|
+
try {
|
|
210
|
+
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
|
211
|
+
if (!AudioContext) return;
|
|
212
|
+
var ctx = new AudioContext();
|
|
213
|
+
var osc = ctx.createOscillator();
|
|
214
|
+
var gain = ctx.createGain();
|
|
215
|
+
osc.connect(gain);
|
|
216
|
+
gain.connect(ctx.destination);
|
|
217
|
+
var now = ctx.currentTime;
|
|
218
|
+
gain.gain.setValueAtTime(0.04, now);
|
|
219
|
+
gain.gain.exponentialRampToValueAtTime(0.0001, now + 0.16);
|
|
220
|
+
if (type === 'error') {
|
|
221
|
+
osc.frequency.setValueAtTime(220, now);
|
|
222
|
+
osc.frequency.setValueAtTime(180, now + 0.08);
|
|
223
|
+
} else if (type === 'success') {
|
|
224
|
+
osc.frequency.setValueAtTime(523.25, now);
|
|
225
|
+
osc.frequency.setValueAtTime(659.25, now + 0.08);
|
|
226
|
+
} else {
|
|
227
|
+
osc.frequency.setValueAtTime(440, now);
|
|
228
|
+
}
|
|
229
|
+
osc.start(now);
|
|
230
|
+
osc.stop(now + 0.16);
|
|
231
|
+
} catch (e) {}
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "injectStyles",
|
|
235
|
+
value: function injectStyles() {
|
|
236
|
+
if (typeof document === 'undefined' || document.getElementById('omnitoast-styles')) return;
|
|
237
|
+
var style = document.createElement('style');
|
|
238
|
+
style.id = 'omnitoast-styles';
|
|
239
|
+
style.textContent = "\n :root {\n --omnitoast-color-light: #ffffff;\n --omnitoast-color-dark: #18181b;\n --omnitoast-color-info: #3b82f6;\n --omnitoast-color-success: #10b981;\n --omnitoast-color-warning: #f59e0b;\n --omnitoast-color-error: #ef4444;\n\n --omnitoast-width: 350px;\n --omnitoast-font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", sans-serif;\n --omnitoast-z-index: 999999;\n --omnitoast-radius: 10px;\n }\n\n .notification-container,\n .toastify-all-container,\n .omnitoast-container,\n .Toastify__toast-container {\n z-index: var(--omnitoast-z-index);\n position: fixed;\n padding: 12px;\n width: var(--omnitoast-width);\n max-width: 100vw;\n box-sizing: border-box;\n pointer-events: none;\n display: flex;\n flex-direction: column;\n gap: 10px;\n }\n\n .Toastify__toast-container--top-left, .notification-container.top-left { top: 10px; left: 10px; }\n .Toastify__toast-container--top-center, .notification-container.top-center { top: 10px; left: 50%; transform: translateX(-50%); }\n .Toastify__toast-container--top-right, .notification-container.top-right { top: 10px; right: 10px; }\n .Toastify__toast-container--bottom-left, .notification-container.bottom-left { bottom: 10px; left: 10px; }\n .Toastify__toast-container--bottom-center, .notification-container.bottom-center { bottom: 10px; left: 50%; transform: translateX(-50%); }\n .Toastify__toast-container--bottom-right, .notification-container.bottom-right { bottom: 10px; right: 10px; }\n\n @media only screen and (max-width: 480px) {\n .notification-container,\n .toastify-all-container,\n .omnitoast-container,\n .Toastify__toast-container {\n width: 100vw;\n padding: 8px;\n left: 0 !important;\n margin: 0;\n transform: none !important;\n }\n }\n\n .notification-toast,\n .toastify-all-toast,\n .omnitoast-toast,\n .Toastify__toast {\n position: relative;\n box-sizing: border-box;\n padding: 12px 14px;\n border-radius: var(--omnitoast-radius);\n box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);\n display: flex;\n justify-content: space-between;\n align-items: flex-start;\n overflow: hidden;\n font-family: var(--omnitoast-font-family);\n cursor: default;\n pointer-events: auto;\n user-select: none;\n line-height: 1.45;\n backdrop-filter: blur(12px);\n -webkit-backdrop-filter: blur(12px);\n border: 1px solid rgba(0, 0, 0, 0.08);\n transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s;\n }\n\n .Toastify__toast--theme-light {\n background: rgba(255, 255, 255, 0.96);\n color: #1f2937;\n border: 1px solid rgba(0, 0, 0, 0.06);\n }\n\n .Toastify__toast--theme-dark {\n background: rgba(24, 24, 27, 0.95);\n color: #f4f4f5;\n border: 1px solid rgba(255, 255, 255, 0.12);\n box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.6);\n }\n\n .Toastify__toast--theme-colored.Toastify__toast--info {\n color: #fff;\n background: var(--omnitoast-color-info);\n border-color: transparent;\n }\n .Toastify__toast--theme-colored.Toastify__toast--success {\n color: #fff;\n background: var(--omnitoast-color-success);\n border-color: transparent;\n }\n .Toastify__toast--theme-colored.Toastify__toast--warning {\n color: #1f2937;\n background: var(--omnitoast-color-warning);\n border-color: transparent;\n }\n .Toastify__toast--theme-colored.Toastify__toast--error {\n color: #fff;\n background: var(--omnitoast-color-error);\n border-color: transparent;\n }\n\n .Toastify__toast-body {\n flex: 1 1 auto;\n display: flex;\n align-items: flex-start;\n gap: 10px;\n min-width: 0;\n }\n\n .Toastify__toast-icon {\n flex-shrink: 0;\n width: 20px;\n height: 20px;\n margin-top: 1px;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n .Toastify__toast-icon svg {\n width: 100%;\n height: 100%;\n }\n\n .omnitoast-text-container {\n flex: 1;\n min-width: 0;\n }\n\n .omnitoast-title {\n font-weight: 600;\n font-size: 13.5px;\n line-height: 1.35;\n margin-bottom: 2px;\n }\n\n .omnitoast-content {\n font-size: 13px;\n line-height: 1.45;\n word-break: break-word;\n opacity: 0.92;\n }\n\n .Toastify__close-button {\n color: #9ca3af;\n background: transparent;\n outline: none;\n border: none;\n padding: 2px;\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.15s ease, color 0.15s ease;\n align-self: flex-start;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 16px;\n line-height: 1;\n margin-left: 8px;\n border-radius: 4px;\n }\n .Toastify__close-button:hover {\n opacity: 1;\n color: inherit;\n background: rgba(0, 0, 0, 0.05);\n }\n\n .Toastify__action-btn {\n margin-top: 6px;\n padding: 5px 12px;\n border: 1px solid rgba(0, 0, 0, 0.15);\n background: rgba(0, 0, 0, 0.05);\n color: inherit;\n border-radius: 6px;\n font-weight: 600;\n font-size: 12px;\n cursor: pointer;\n transition: background 0.15s, border-color 0.15s;\n display: inline-block;\n }\n\n .Toastify__progress-bar {\n position: absolute;\n bottom: 0;\n left: 0;\n width: 100%;\n height: 3px;\n opacity: 0.45;\n transform-origin: left;\n }\n .Toastify__progress-bar--animated {\n animation: Toastify__trackProgress linear 1 forwards;\n }\n .Toastify__progress-bar--info { background: var(--omnitoast-color-info); }\n .Toastify__progress-bar--success { background: var(--omnitoast-color-success); }\n .Toastify__progress-bar--warning { background: var(--omnitoast-color-warning); }\n .Toastify__progress-bar--error { background: var(--omnitoast-color-error); }\n\n @keyframes Toastify__trackProgress {\n 0% { transform: scaleX(1); }\n 100% { transform: scaleX(0); }\n }\n\n @keyframes Toastify__bounceInRight {\n from { opacity: 0; transform: translate3d(200px, 0, 0) scale(0.9); }\n to { transform: none; }\n }\n @keyframes Toastify__bounceOutRight {\n to { opacity: 0; transform: translate3d(250px, 0, 0) scale(0.85); }\n }\n @keyframes Toastify__bounceInLeft {\n from { opacity: 0; transform: translate3d(-200px, 0, 0) scale(0.9); }\n to { transform: none; }\n }\n @keyframes Toastify__bounceOutLeft {\n to { opacity: 0; transform: translate3d(-250px, 0, 0) scale(0.85); }\n }\n @keyframes Toastify__bounceInDown {\n from { opacity: 0; transform: translate3d(0, -50px, 0) scale(0.9); }\n to { transform: none; }\n }\n @keyframes Toastify__bounceOutUp {\n to { opacity: 0; transform: translate3d(0, -60px, 0) scale(0.85); }\n }\n\n @keyframes Toastify__slideInRight {\n from { transform: translate3d(100%, 0, 0); opacity: 0; }\n to { transform: translate3d(0, 0, 0); opacity: 1; }\n }\n @keyframes Toastify__slideOutRight {\n to { transform: translate3d(100%, 0, 0); opacity: 0; }\n }\n @keyframes Toastify__slideInLeft {\n from { transform: translate3d(-100%, 0, 0); opacity: 0; }\n to { transform: translate3d(0, 0, 0); opacity: 1; }\n }\n @keyframes Toastify__slideOutLeft {\n to { transform: translate3d(-100%, 0, 0); opacity: 0; }\n }\n\n @keyframes Toastify__zoomIn {\n from { opacity: 0; transform: scale3d(0.5, 0.5, 0.5); }\n to { opacity: 1; transform: scale3d(1, 1, 1); }\n }\n @keyframes Toastify__zoomOut {\n to { opacity: 0; transform: scale3d(0.5, 0.5, 0.5); }\n }\n\n @keyframes Toastify__flipIn {\n from { transform: perspective(400px) rotate3d(1, 0, 0, 90deg); opacity: 0; }\n to { transform: perspective(400px); opacity: 1; }\n }\n @keyframes Toastify__flipOut {\n to { transform: perspective(400px) rotate3d(1, 0, 0, 90deg); opacity: 0; }\n }\n\n @keyframes Toastify__spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n .Toastify__spinner {\n width: 18px;\n height: 18px;\n box-sizing: border-box;\n border: 2px solid currentColor;\n border-radius: 50%;\n border-right-color: transparent;\n animation: Toastify__spin 0.75s linear infinite;\n }\n ";
|
|
240
|
+
document.head.appendChild(style);
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
key: "getDefaultIcon",
|
|
244
|
+
value: function getDefaultIcon(type) {
|
|
245
|
+
switch (type) {
|
|
246
|
+
case 'success':
|
|
247
|
+
return '<svg viewBox="0 0 20 20" fill="#10b981"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/></svg>';
|
|
248
|
+
case 'error':
|
|
249
|
+
return '<svg viewBox="0 0 20 20" fill="#ef4444"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/></svg>';
|
|
250
|
+
case 'warning':
|
|
251
|
+
return '<svg viewBox="0 0 20 20" fill="#f59e0b"><path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd"/></svg>';
|
|
252
|
+
case 'info':
|
|
253
|
+
return '<svg viewBox="0 0 20 20" fill="#3b82f6"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"/></svg>';
|
|
254
|
+
case 'loading':
|
|
255
|
+
return '<div class="Toastify__spinner"></div>';
|
|
256
|
+
default:
|
|
257
|
+
return '';
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}, {
|
|
261
|
+
key: "getAnimationNames",
|
|
262
|
+
value: function getAnimationNames(transition, position) {
|
|
263
|
+
var isLeft = position.includes('left');
|
|
264
|
+
var isCenter = position.includes('center');
|
|
265
|
+
switch (transition) {
|
|
266
|
+
case 'slide':
|
|
267
|
+
return {
|
|
268
|
+
enter: isLeft ? 'Toastify__slideInLeft 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards' : 'Toastify__slideInRight 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards',
|
|
269
|
+
exit: isLeft ? 'Toastify__slideOutLeft 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards' : 'Toastify__slideOutRight 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards'
|
|
270
|
+
};
|
|
271
|
+
case 'zoom':
|
|
272
|
+
return {
|
|
273
|
+
enter: 'Toastify__zoomIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards',
|
|
274
|
+
exit: 'Toastify__zoomOut 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards'
|
|
275
|
+
};
|
|
276
|
+
case 'flip':
|
|
277
|
+
return {
|
|
278
|
+
enter: 'Toastify__flipIn 0.35s ease forwards',
|
|
279
|
+
exit: 'Toastify__flipOut 0.3s ease forwards'
|
|
280
|
+
};
|
|
281
|
+
case 'bounce':
|
|
282
|
+
default:
|
|
283
|
+
if (isCenter) {
|
|
284
|
+
return {
|
|
285
|
+
enter: 'Toastify__bounceInDown 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards',
|
|
286
|
+
exit: 'Toastify__bounceOutUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards'
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
enter: isLeft ? 'Toastify__bounceInLeft 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards' : 'Toastify__bounceInRight 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards',
|
|
291
|
+
exit: isLeft ? 'Toastify__bounceOutLeft 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards' : 'Toastify__bounceOutRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards'
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, {
|
|
296
|
+
key: "show",
|
|
297
|
+
value: function show() {
|
|
298
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'default';
|
|
299
|
+
var message = arguments.length > 1 ? arguments[1] : undefined;
|
|
300
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
301
|
+
if (typeof document === 'undefined') return 0;
|
|
302
|
+
this.init();
|
|
303
|
+
var id = options.toastId || ++this.counter;
|
|
304
|
+
if (this.notifications.has(id)) {
|
|
305
|
+
this.update(id, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
306
|
+
message: message,
|
|
307
|
+
type: type
|
|
308
|
+
}));
|
|
309
|
+
return id;
|
|
310
|
+
}
|
|
311
|
+
var config = _objectSpread2(_objectSpread2({}, this.config), options);
|
|
312
|
+
var position = config.position || this.config.position;
|
|
313
|
+
var container = this.getContainer(position);
|
|
314
|
+
if (!container) return id;
|
|
315
|
+
|
|
316
|
+
// Waiting queue limit
|
|
317
|
+
if (config.limit && container.children.length >= config.limit) {
|
|
318
|
+
var firstChild = container.firstElementChild;
|
|
319
|
+
var oldestId = firstChild ? Number(firstChild.getAttribute('data-toast-id')) : null;
|
|
320
|
+
if (oldestId) {
|
|
321
|
+
this.dismiss(oldestId);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
var toast = this.createToast(id, type, message, config, position);
|
|
325
|
+
if (config.newestOnTop) {
|
|
326
|
+
container.insertBefore(toast, container.firstChild);
|
|
327
|
+
} else {
|
|
328
|
+
container.appendChild(toast);
|
|
329
|
+
}
|
|
330
|
+
var entry = {
|
|
331
|
+
id: id,
|
|
332
|
+
toast: toast,
|
|
333
|
+
type: type,
|
|
334
|
+
message: message,
|
|
335
|
+
config: config,
|
|
336
|
+
position: position,
|
|
337
|
+
timer: null,
|
|
338
|
+
remainingTime: config.autoClose,
|
|
339
|
+
startTime: Date.now(),
|
|
340
|
+
isPaused: false
|
|
341
|
+
};
|
|
342
|
+
this.notifications.set(id, entry);
|
|
343
|
+
if (config.autoClose !== false) {
|
|
344
|
+
this.setupAutoClose(entry);
|
|
345
|
+
}
|
|
346
|
+
if (config.sound) {
|
|
347
|
+
this.playChime(type);
|
|
348
|
+
}
|
|
349
|
+
if (typeof config.onOpen === 'function') {
|
|
350
|
+
config.onOpen(id);
|
|
351
|
+
}
|
|
352
|
+
return id;
|
|
353
|
+
}
|
|
354
|
+
}, {
|
|
355
|
+
key: "createToast",
|
|
356
|
+
value: function createToast(id, type, message, config, position) {
|
|
357
|
+
var _this2 = this;
|
|
358
|
+
var effectiveTheme = this.getEffectiveTheme(config.theme);
|
|
359
|
+
var transition = config.transition || this.config.transition;
|
|
360
|
+
var animations = this.getAnimationNames(transition, position);
|
|
361
|
+
var toast = document.createElement('div');
|
|
362
|
+
toast.className = "notification-toast toastify-all-toast omnitoast-toast ".concat(type, " Toastify__toast Toastify__toast--").concat(type, " Toastify__toast--theme-").concat(effectiveTheme, " ").concat(config.className || '').trim();
|
|
363
|
+
toast.setAttribute('data-toast-id', id);
|
|
364
|
+
toast.setAttribute('role', type === 'error' ? 'alert' : 'status');
|
|
365
|
+
toast.style.animation = animations.enter;
|
|
366
|
+
if (config.style && _typeof(config.style) === 'object') {
|
|
367
|
+
Object.assign(toast.style, config.style);
|
|
368
|
+
}
|
|
369
|
+
var body = document.createElement('div');
|
|
370
|
+
body.className = "Toastify__toast-body ".concat(config.bodyClassName || '').trim();
|
|
371
|
+
if (config.bodyStyle) Object.assign(body.style, config.bodyStyle);
|
|
372
|
+
if (config.icon !== false) {
|
|
373
|
+
var iconWrapper = document.createElement('div');
|
|
374
|
+
iconWrapper.className = 'Toastify__toast-icon';
|
|
375
|
+
if (typeof config.icon === 'string') {
|
|
376
|
+
iconWrapper.innerHTML = config.icon;
|
|
377
|
+
} else if (config.icon instanceof Node) {
|
|
378
|
+
iconWrapper.appendChild(config.icon);
|
|
379
|
+
} else {
|
|
380
|
+
iconWrapper.innerHTML = this.getDefaultIcon(type);
|
|
381
|
+
}
|
|
382
|
+
body.appendChild(iconWrapper);
|
|
383
|
+
}
|
|
384
|
+
var textWrapper = document.createElement('div');
|
|
385
|
+
textWrapper.className = 'omnitoast-text-container';
|
|
386
|
+
if (config.title) {
|
|
387
|
+
var titleEl = document.createElement('div');
|
|
388
|
+
titleEl.className = 'omnitoast-title';
|
|
389
|
+
titleEl.textContent = config.title;
|
|
390
|
+
textWrapper.appendChild(titleEl);
|
|
391
|
+
}
|
|
392
|
+
var contentEl = document.createElement('div');
|
|
393
|
+
contentEl.className = 'omnitoast-content';
|
|
394
|
+
if (message instanceof Node) {
|
|
395
|
+
contentEl.appendChild(message);
|
|
396
|
+
} else if (typeof message === 'string') {
|
|
397
|
+
contentEl.textContent = message;
|
|
398
|
+
} else {
|
|
399
|
+
contentEl.textContent = String(message);
|
|
400
|
+
}
|
|
401
|
+
textWrapper.appendChild(contentEl);
|
|
402
|
+
if (config.action && config.action.label) {
|
|
403
|
+
var actionBtn = document.createElement('button');
|
|
404
|
+
actionBtn.type = 'button';
|
|
405
|
+
actionBtn.className = 'Toastify__action-btn';
|
|
406
|
+
actionBtn.textContent = config.action.label;
|
|
407
|
+
actionBtn.onclick = function (e) {
|
|
408
|
+
e.stopPropagation();
|
|
409
|
+
if (typeof config.action.onClick === 'function') {
|
|
410
|
+
config.action.onClick(id);
|
|
411
|
+
}
|
|
412
|
+
if (config.action.autoDismiss !== false) {
|
|
413
|
+
_this2.dismiss(id);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
textWrapper.appendChild(actionBtn);
|
|
417
|
+
}
|
|
418
|
+
body.appendChild(textWrapper);
|
|
419
|
+
toast.appendChild(body);
|
|
420
|
+
if (config.closeButton !== false) {
|
|
421
|
+
var closeBtn = document.createElement('button');
|
|
422
|
+
closeBtn.type = 'button';
|
|
423
|
+
closeBtn.className = 'Toastify__close-button';
|
|
424
|
+
closeBtn.setAttribute('aria-label', 'Close');
|
|
425
|
+
closeBtn.innerHTML = '×';
|
|
426
|
+
closeBtn.onclick = function (e) {
|
|
427
|
+
e.stopPropagation();
|
|
428
|
+
_this2.dismiss(id);
|
|
429
|
+
};
|
|
430
|
+
toast.appendChild(closeBtn);
|
|
431
|
+
}
|
|
432
|
+
if (!config.hideProgressBar && config.autoClose !== false) {
|
|
433
|
+
var progress = document.createElement('div');
|
|
434
|
+
progress.className = "Toastify__progress-bar Toastify__progress-bar--animated Toastify__progress-bar--".concat(type, " ").concat(config.progressClassName || '').trim();
|
|
435
|
+
progress.style.animationDuration = "".concat(config.autoClose, "ms");
|
|
436
|
+
if (config.progressStyle) Object.assign(progress.style, config.progressStyle);
|
|
437
|
+
toast.appendChild(progress);
|
|
438
|
+
}
|
|
439
|
+
if (config.closeOnClick !== false) {
|
|
440
|
+
toast.style.cursor = 'pointer';
|
|
441
|
+
toast.onclick = function (e) {
|
|
442
|
+
if (e.target.tagName !== 'BUTTON') {
|
|
443
|
+
_this2.dismiss(id);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
if (config.draggable !== false) {
|
|
448
|
+
this.makeDraggable(toast, id, config);
|
|
449
|
+
}
|
|
450
|
+
if (config.pauseOnHover !== false) {
|
|
451
|
+
this.setupHoverPause(toast, id);
|
|
452
|
+
}
|
|
453
|
+
return toast;
|
|
454
|
+
}
|
|
455
|
+
}, {
|
|
456
|
+
key: "setupAutoClose",
|
|
457
|
+
value: function setupAutoClose(entry) {
|
|
458
|
+
var _this3 = this;
|
|
459
|
+
var delay = entry.remainingTime;
|
|
460
|
+
entry.startTime = Date.now();
|
|
461
|
+
entry.timer = setTimeout(function () {
|
|
462
|
+
_this3.dismiss(entry.id);
|
|
463
|
+
}, delay);
|
|
464
|
+
}
|
|
465
|
+
}, {
|
|
466
|
+
key: "setupHoverPause",
|
|
467
|
+
value: function setupHoverPause(toast, id) {
|
|
468
|
+
var _this4 = this;
|
|
469
|
+
toast.addEventListener('mouseenter', function () {
|
|
470
|
+
_this4.pauseToast(id);
|
|
471
|
+
});
|
|
472
|
+
toast.addEventListener('mouseleave', function () {
|
|
473
|
+
_this4.resumeToast(id);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}, {
|
|
477
|
+
key: "pauseToast",
|
|
478
|
+
value: function pauseToast(id) {
|
|
479
|
+
var entry = this.notifications.get(id);
|
|
480
|
+
if (!entry || entry.isPaused || !entry.timer) return;
|
|
481
|
+
clearTimeout(entry.timer);
|
|
482
|
+
entry.timer = null;
|
|
483
|
+
entry.isPaused = true;
|
|
484
|
+
var elapsed = Date.now() - entry.startTime;
|
|
485
|
+
entry.remainingTime = Math.max(0, entry.remainingTime - elapsed);
|
|
486
|
+
var progress = entry.toast.querySelector('.Toastify__progress-bar');
|
|
487
|
+
if (progress) {
|
|
488
|
+
progress.style.animationPlayState = 'paused';
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}, {
|
|
492
|
+
key: "resumeToast",
|
|
493
|
+
value: function resumeToast(id) {
|
|
494
|
+
var entry = this.notifications.get(id);
|
|
495
|
+
if (!entry || !entry.isPaused || entry.remainingTime <= 0) return;
|
|
496
|
+
entry.isPaused = false;
|
|
497
|
+
var progress = entry.toast.querySelector('.Toastify__progress-bar');
|
|
498
|
+
if (progress) {
|
|
499
|
+
progress.style.animationPlayState = 'running';
|
|
500
|
+
}
|
|
501
|
+
this.setupAutoClose(entry);
|
|
502
|
+
}
|
|
503
|
+
}, {
|
|
504
|
+
key: "pauseAll",
|
|
505
|
+
value: function pauseAll() {
|
|
506
|
+
var _this5 = this;
|
|
507
|
+
this.notifications.forEach(function (_, id) {
|
|
508
|
+
return _this5.pauseToast(id);
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
}, {
|
|
512
|
+
key: "resumeAll",
|
|
513
|
+
value: function resumeAll() {
|
|
514
|
+
var _this6 = this;
|
|
515
|
+
this.notifications.forEach(function (_, id) {
|
|
516
|
+
return _this6.resumeToast(id);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}, {
|
|
520
|
+
key: "makeDraggable",
|
|
521
|
+
value: function makeDraggable(toast, id, config) {
|
|
522
|
+
var _this7 = this;
|
|
523
|
+
var startX = null;
|
|
524
|
+
var currentX = null;
|
|
525
|
+
var handleStart = function handleStart(e) {
|
|
526
|
+
startX = e.type === 'mousedown' ? e.clientX : e.touches && e.touches[0] ? e.touches[0].clientX : null;
|
|
527
|
+
currentX = startX;
|
|
528
|
+
toast.style.transition = 'none';
|
|
529
|
+
};
|
|
530
|
+
var handleMove = function handleMove(e) {
|
|
531
|
+
if (startX === null) return;
|
|
532
|
+
currentX = e.type === 'mousemove' ? e.clientX : e.touches && e.touches[0] ? e.touches[0].clientX : null;
|
|
533
|
+
if (currentX === null) return;
|
|
534
|
+
var deltaX = currentX - startX;
|
|
535
|
+
toast.style.transform = "translate3d(".concat(deltaX, "px, 0, 0)");
|
|
536
|
+
toast.style.opacity = "".concat(1 - Math.abs(deltaX) / (toast.offsetWidth * 1.5));
|
|
537
|
+
};
|
|
538
|
+
var handleEnd = function handleEnd() {
|
|
539
|
+
if (startX === null || currentX === null) return;
|
|
540
|
+
var deltaX = currentX - startX;
|
|
541
|
+
toast.style.transition = 'all 0.25s ease';
|
|
542
|
+
var threshold = toast.offsetWidth * (config.draggablePercent || 80) / 100;
|
|
543
|
+
if (Math.abs(deltaX) > threshold) {
|
|
544
|
+
_this7.dismiss(id);
|
|
545
|
+
} else {
|
|
546
|
+
toast.style.transform = 'translate3d(0, 0, 0)';
|
|
547
|
+
toast.style.opacity = '1';
|
|
548
|
+
}
|
|
549
|
+
startX = null;
|
|
550
|
+
currentX = null;
|
|
551
|
+
};
|
|
552
|
+
toast.addEventListener('mousedown', handleStart);
|
|
553
|
+
toast.addEventListener('touchstart', handleStart, {
|
|
554
|
+
passive: true
|
|
555
|
+
});
|
|
556
|
+
window.addEventListener('mousemove', handleMove);
|
|
557
|
+
window.addEventListener('touchmove', handleMove, {
|
|
558
|
+
passive: true
|
|
559
|
+
});
|
|
560
|
+
window.addEventListener('mouseup', handleEnd);
|
|
561
|
+
window.addEventListener('touchend', handleEnd);
|
|
562
|
+
}
|
|
563
|
+
}, {
|
|
564
|
+
key: "update",
|
|
565
|
+
value: function update(id) {
|
|
566
|
+
var newState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
567
|
+
var entry = this.notifications.get(id);
|
|
568
|
+
if (!entry) return;
|
|
569
|
+
var toast = entry.toast;
|
|
570
|
+
var content = toast.querySelector('.omnitoast-content') || toast.querySelector('.Toastify__toast-body');
|
|
571
|
+
var iconWrapper = toast.querySelector('.Toastify__toast-icon');
|
|
572
|
+
if (newState.render) {
|
|
573
|
+
newState.message = newState.render;
|
|
574
|
+
}
|
|
575
|
+
if (newState.message !== undefined && content) {
|
|
576
|
+
content.textContent = '';
|
|
577
|
+
if (newState.message instanceof Node) {
|
|
578
|
+
content.appendChild(newState.message);
|
|
579
|
+
} else {
|
|
580
|
+
content.textContent = String(newState.message);
|
|
581
|
+
}
|
|
582
|
+
entry.message = newState.message;
|
|
583
|
+
}
|
|
584
|
+
if (newState.type && newState.type !== entry.type) {
|
|
585
|
+
toast.className = toast.className.replace(entry.type, newState.type);
|
|
586
|
+
toast.className = toast.className.replace("Toastify__toast--".concat(entry.type), "Toastify__toast--".concat(newState.type));
|
|
587
|
+
entry.type = newState.type;
|
|
588
|
+
if (iconWrapper) {
|
|
589
|
+
iconWrapper.innerHTML = this.getDefaultIcon(newState.type);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (newState.autoClose !== undefined) {
|
|
593
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
594
|
+
if (newState.autoClose !== false) {
|
|
595
|
+
entry.remainingTime = newState.autoClose;
|
|
596
|
+
var progress = toast.querySelector('.Toastify__progress-bar');
|
|
597
|
+
if (progress) {
|
|
598
|
+
progress.style.animationDuration = "".concat(newState.autoClose, "ms");
|
|
599
|
+
}
|
|
600
|
+
this.setupAutoClose(entry);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}, {
|
|
605
|
+
key: "dismiss",
|
|
606
|
+
value: function dismiss(id) {
|
|
607
|
+
var _this8 = this;
|
|
608
|
+
if (id === undefined) {
|
|
609
|
+
this.clearAll();
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
var entry = this.notifications.get(id);
|
|
613
|
+
if (!entry) return;
|
|
614
|
+
var toast = entry.toast,
|
|
615
|
+
config = entry.config,
|
|
616
|
+
position = entry.position;
|
|
617
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
618
|
+
var transition = config.transition || this.config.transition;
|
|
619
|
+
var animations = this.getAnimationNames(transition, position);
|
|
620
|
+
toast.style.animation = animations.exit;
|
|
621
|
+
if (typeof config.onClose === 'function') {
|
|
622
|
+
config.onClose(id);
|
|
623
|
+
}
|
|
624
|
+
setTimeout(function () {
|
|
625
|
+
if (toast.parentNode) {
|
|
626
|
+
toast.parentNode.removeChild(toast);
|
|
627
|
+
}
|
|
628
|
+
_this8.notifications.delete(id);
|
|
629
|
+
}, 280);
|
|
630
|
+
}
|
|
631
|
+
}, {
|
|
632
|
+
key: "isActive",
|
|
633
|
+
value: function isActive(id) {
|
|
634
|
+
return this.notifications.has(id);
|
|
635
|
+
}
|
|
636
|
+
}, {
|
|
637
|
+
key: "clearWaitingQueue",
|
|
638
|
+
value: function clearWaitingQueue() {
|
|
639
|
+
var _this9 = this;
|
|
640
|
+
this.containers.forEach(function (container) {
|
|
641
|
+
var toasts = Array.from(container.children);
|
|
642
|
+
toasts.slice(_this9.config.limit || 5).forEach(function (toast) {
|
|
643
|
+
var id = Number(toast.getAttribute('data-toast-id'));
|
|
644
|
+
if (id) _this9.dismiss(id);
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}, {
|
|
649
|
+
key: "clearAll",
|
|
650
|
+
value: function clearAll() {
|
|
651
|
+
var _this0 = this;
|
|
652
|
+
this.notifications.forEach(function (_, id) {
|
|
653
|
+
_this0.dismiss(id);
|
|
654
|
+
});
|
|
655
|
+
this.containers.forEach(function (container) {
|
|
656
|
+
if (container.parentNode) {
|
|
657
|
+
container.parentNode.removeChild(container);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
this.containers.clear();
|
|
661
|
+
}
|
|
662
|
+
}, {
|
|
663
|
+
key: "promise",
|
|
664
|
+
value: function promise(promiseOrFn) {
|
|
665
|
+
var _this1 = this;
|
|
666
|
+
var states = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
667
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
668
|
+
var p = typeof promiseOrFn === 'function' ? promiseOrFn() : promiseOrFn;
|
|
669
|
+
var pendingMsg = states.pending || states.loading || 'Loading...';
|
|
670
|
+
var id = this.show('loading', pendingMsg, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
671
|
+
autoClose: false
|
|
672
|
+
}));
|
|
673
|
+
return p.then(function (data) {
|
|
674
|
+
var successMsg = typeof states.success === 'function' ? states.success(data) : states.success || 'Success!';
|
|
675
|
+
_this1.update(id, {
|
|
676
|
+
type: 'success',
|
|
677
|
+
render: successMsg,
|
|
678
|
+
autoClose: options.autoClose !== undefined ? options.autoClose : 5000
|
|
679
|
+
});
|
|
680
|
+
if (options.sound || _this1.config.sound) {
|
|
681
|
+
_this1.playChime('success');
|
|
682
|
+
}
|
|
683
|
+
return data;
|
|
684
|
+
}).catch(function (err) {
|
|
685
|
+
var errorMsg = typeof states.error === 'function' ? states.error(err) : states.error || err && err.message || 'Error occurred';
|
|
686
|
+
_this1.update(id, {
|
|
687
|
+
type: 'error',
|
|
688
|
+
render: errorMsg,
|
|
689
|
+
autoClose: options.autoClose !== undefined ? options.autoClose : 5000
|
|
690
|
+
});
|
|
691
|
+
if (options.sound || _this1.config.sound) {
|
|
692
|
+
_this1.playChime('error');
|
|
693
|
+
}
|
|
694
|
+
throw err;
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}]);
|
|
698
|
+
}();
|
|
699
|
+
|
|
700
|
+
var AlertService = /*#__PURE__*/function () {
|
|
701
|
+
function AlertService() {
|
|
702
|
+
_classCallCheck(this, AlertService);
|
|
703
|
+
this.core = new NotificationCore();
|
|
704
|
+
}
|
|
705
|
+
return _createClass(AlertService, [{
|
|
706
|
+
key: "configure",
|
|
707
|
+
value: function configure(options) {
|
|
708
|
+
this.core.configure(options);
|
|
709
|
+
}
|
|
710
|
+
}, {
|
|
711
|
+
key: "show",
|
|
712
|
+
value: function show(type, message, options) {
|
|
713
|
+
return this.core.show(type, message, options);
|
|
714
|
+
}
|
|
715
|
+
}, {
|
|
716
|
+
key: "success",
|
|
717
|
+
value: function success(message, options) {
|
|
718
|
+
return this.core.show('success', message, options);
|
|
719
|
+
}
|
|
720
|
+
}, {
|
|
721
|
+
key: "error",
|
|
722
|
+
value: function error(message, options) {
|
|
723
|
+
return this.core.show('error', message, options);
|
|
724
|
+
}
|
|
725
|
+
}, {
|
|
726
|
+
key: "info",
|
|
727
|
+
value: function info(message, options) {
|
|
728
|
+
return this.core.show('info', message, options);
|
|
729
|
+
}
|
|
730
|
+
}, {
|
|
731
|
+
key: "warn",
|
|
732
|
+
value: function warn(message, options) {
|
|
733
|
+
return this.core.show('warning', message, options);
|
|
734
|
+
}
|
|
735
|
+
}, {
|
|
736
|
+
key: "warning",
|
|
737
|
+
value: function warning(message, options) {
|
|
738
|
+
return this.core.show('warning', message, options);
|
|
739
|
+
}
|
|
740
|
+
}, {
|
|
741
|
+
key: "loading",
|
|
742
|
+
value: function loading(message, options) {
|
|
743
|
+
return this.core.show('loading', message, _objectSpread2(_objectSpread2({}, options), {}, {
|
|
744
|
+
autoClose: false
|
|
745
|
+
}));
|
|
746
|
+
}
|
|
747
|
+
}, {
|
|
748
|
+
key: "custom",
|
|
749
|
+
value: function custom(content, options) {
|
|
750
|
+
return this.core.show('custom', content, options);
|
|
751
|
+
}
|
|
752
|
+
}, {
|
|
753
|
+
key: "promise",
|
|
754
|
+
value: function promise(promiseOrFn, states, options) {
|
|
755
|
+
return this.core.promise(promiseOrFn, states, options);
|
|
756
|
+
}
|
|
757
|
+
}, {
|
|
758
|
+
key: "update",
|
|
759
|
+
value: function update(id, newState) {
|
|
760
|
+
this.core.update(id, newState);
|
|
761
|
+
}
|
|
762
|
+
}, {
|
|
763
|
+
key: "dismiss",
|
|
764
|
+
value: function dismiss(id) {
|
|
765
|
+
if (id !== undefined) {
|
|
766
|
+
this.core.dismiss(id);
|
|
767
|
+
} else {
|
|
768
|
+
this.core.clearAll();
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}, {
|
|
772
|
+
key: "isActive",
|
|
773
|
+
value: function isActive(id) {
|
|
774
|
+
return this.core.isActive(id);
|
|
775
|
+
}
|
|
776
|
+
}, {
|
|
777
|
+
key: "clearWaitingQueue",
|
|
778
|
+
value: function clearWaitingQueue() {
|
|
779
|
+
this.core.clearWaitingQueue();
|
|
780
|
+
}
|
|
781
|
+
}, {
|
|
782
|
+
key: "clearAll",
|
|
783
|
+
value: function clearAll() {
|
|
784
|
+
this.core.clearAll();
|
|
785
|
+
}
|
|
786
|
+
}]);
|
|
787
|
+
}(); // Create singleton instance
|
|
788
|
+
var alertService = new AlertService();
|
|
789
|
+
|
|
790
|
+
// Create callable toast function like react-toastify: toast("msg") or toast.success("msg")
|
|
791
|
+
function createCallableToast(service) {
|
|
792
|
+
var toast = function toast(content) {
|
|
793
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
794
|
+
return service.core.show('default', content, options);
|
|
795
|
+
};
|
|
796
|
+
toast.configure = function (options) {
|
|
797
|
+
return service.configure(options);
|
|
798
|
+
};
|
|
799
|
+
toast.success = function (content, options) {
|
|
800
|
+
return service.success(content, options);
|
|
801
|
+
};
|
|
802
|
+
toast.error = function (content, options) {
|
|
803
|
+
return service.error(content, options);
|
|
804
|
+
};
|
|
805
|
+
toast.info = function (content, options) {
|
|
806
|
+
return service.info(content, options);
|
|
807
|
+
};
|
|
808
|
+
toast.warning = function (content, options) {
|
|
809
|
+
return service.warning(content, options);
|
|
810
|
+
};
|
|
811
|
+
toast.warn = function (content, options) {
|
|
812
|
+
return service.warn(content, options);
|
|
813
|
+
};
|
|
814
|
+
toast.loading = function (content, options) {
|
|
815
|
+
return service.loading(content, options);
|
|
816
|
+
};
|
|
817
|
+
toast.custom = function (content, options) {
|
|
818
|
+
return service.custom(content, options);
|
|
819
|
+
};
|
|
820
|
+
toast.promise = function (promiseOrFn, states, options) {
|
|
821
|
+
return service.promise(promiseOrFn, states, options);
|
|
822
|
+
};
|
|
823
|
+
toast.update = function (id, newState) {
|
|
824
|
+
return service.update(id, newState);
|
|
825
|
+
};
|
|
826
|
+
toast.dismiss = function (id) {
|
|
827
|
+
return service.dismiss(id);
|
|
828
|
+
};
|
|
829
|
+
toast.isActive = function (id) {
|
|
830
|
+
return service.isActive(id);
|
|
831
|
+
};
|
|
832
|
+
toast.clearWaitingQueue = function () {
|
|
833
|
+
return service.clearWaitingQueue();
|
|
834
|
+
};
|
|
835
|
+
toast.clearAll = function () {
|
|
836
|
+
return service.clearAll();
|
|
837
|
+
};
|
|
838
|
+
toast.core = service.core;
|
|
839
|
+
return toast;
|
|
840
|
+
}
|
|
841
|
+
var toast = createCallableToast(alertService);
|
|
842
|
+
if (typeof window !== 'undefined') {
|
|
843
|
+
window.ToastifyAll = window.ToastifyAll || {
|
|
844
|
+
toast: toast,
|
|
845
|
+
alertService: alertService,
|
|
846
|
+
AlertService: AlertService
|
|
847
|
+
};
|
|
848
|
+
window.OmniToast = window.OmniToast || window.ToastifyAll;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
var _excluded = ["position", "autoClose", "hideProgressBar", "newestOnTop", "closeOnClick", "pauseOnHover", "pauseOnFocusLoss", "draggable", "theme", "transition", "limit", "className", "style"];
|
|
852
|
+
var ToastContext = /*#__PURE__*/react.createContext(toast);
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* ToastContainer component like react-toastify
|
|
856
|
+
* Can be placed once at the root of the app.
|
|
857
|
+
*/
|
|
858
|
+
var ToastContainer = function ToastContainer() {
|
|
859
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
860
|
+
var position = props.position,
|
|
861
|
+
autoClose = props.autoClose,
|
|
862
|
+
hideProgressBar = props.hideProgressBar,
|
|
863
|
+
newestOnTop = props.newestOnTop,
|
|
864
|
+
closeOnClick = props.closeOnClick,
|
|
865
|
+
pauseOnHover = props.pauseOnHover,
|
|
866
|
+
pauseOnFocusLoss = props.pauseOnFocusLoss,
|
|
867
|
+
draggable = props.draggable,
|
|
868
|
+
theme = props.theme,
|
|
869
|
+
transition = props.transition,
|
|
870
|
+
limit = props.limit,
|
|
871
|
+
className = props.className,
|
|
872
|
+
style = props.style,
|
|
873
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
874
|
+
react.useEffect(function () {
|
|
875
|
+
var config = {};
|
|
876
|
+
if (position !== undefined) config.position = position;
|
|
877
|
+
if (autoClose !== undefined) {
|
|
878
|
+
config.autoClose = autoClose === false || autoClose === 'false' ? false : !isNaN(Number(autoClose)) ? Number(autoClose) : autoClose;
|
|
879
|
+
}
|
|
880
|
+
if (hideProgressBar !== undefined) config.hideProgressBar = Boolean(hideProgressBar);
|
|
881
|
+
if (newestOnTop !== undefined) config.newestOnTop = Boolean(newestOnTop);
|
|
882
|
+
if (closeOnClick !== undefined) config.closeOnClick = Boolean(closeOnClick);
|
|
883
|
+
if (pauseOnHover !== undefined) config.pauseOnHover = Boolean(pauseOnHover);
|
|
884
|
+
if (pauseOnFocusLoss !== undefined) config.pauseOnFocusLoss = Boolean(pauseOnFocusLoss);
|
|
885
|
+
if (draggable !== undefined) config.draggable = Boolean(draggable);
|
|
886
|
+
if (theme !== undefined) config.theme = theme;
|
|
887
|
+
if (transition !== undefined) config.transition = transition;
|
|
888
|
+
if (limit !== undefined) config.limit = limit;
|
|
889
|
+
if (className !== undefined) config.className = className;
|
|
890
|
+
if (style !== undefined) config.style = style;
|
|
891
|
+
Object.assign(config, rest);
|
|
892
|
+
toast.configure(config);
|
|
893
|
+
}, [position, autoClose, hideProgressBar, newestOnTop, closeOnClick, pauseOnHover, pauseOnFocusLoss, draggable, theme, transition, limit, className, style, JSON.stringify(rest)]);
|
|
894
|
+
return null;
|
|
895
|
+
};
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* NotificationProvider for React Context users
|
|
899
|
+
*/
|
|
900
|
+
var NotificationProvider = function NotificationProvider(_ref) {
|
|
901
|
+
var children = _ref.children,
|
|
902
|
+
_ref$options = _ref.options,
|
|
903
|
+
options = _ref$options === void 0 ? {} : _ref$options;
|
|
904
|
+
react.useEffect(function () {
|
|
905
|
+
if (options && Object.keys(options).length > 0) {
|
|
906
|
+
toast.configure(options);
|
|
907
|
+
}
|
|
908
|
+
}, [options]);
|
|
909
|
+
return /*#__PURE__*/jsxRuntime.jsx(ToastContext.Provider, {
|
|
910
|
+
value: toast,
|
|
911
|
+
children: children
|
|
912
|
+
});
|
|
913
|
+
};
|
|
914
|
+
var useToast = function useToast() {
|
|
915
|
+
var context = react.useContext(ToastContext);
|
|
916
|
+
return context || toast;
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
exports.NotificationProvider = NotificationProvider;
|
|
920
|
+
exports.ToastContainer = ToastContainer;
|
|
921
|
+
exports.alertService = alertService;
|
|
922
|
+
exports.default = toast;
|
|
923
|
+
exports.toast = toast;
|
|
924
|
+
exports.useToast = useToast;
|
|
925
|
+
//# sourceMappingURL=index.js.map
|