sweetalert2 11.13.1 → 11.13.2
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/sweetalert2.all.js +801 -1083
- package/dist/sweetalert2.all.min.js +2 -2
- package/dist/sweetalert2.esm.all.js +801 -1083
- package/dist/sweetalert2.esm.all.min.js +2 -2
- package/dist/sweetalert2.esm.js +801 -1083
- package/dist/sweetalert2.esm.min.js +2 -2
- package/dist/sweetalert2.js +801 -1083
- package/dist/sweetalert2.min.js +2 -2
- package/package.json +1 -1
- package/src/SweetAlert.js +1 -1
package/dist/sweetalert2.all.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sweetalert2 v11.13.
|
|
2
|
+
* sweetalert2 v11.13.2
|
|
3
3
|
* Released under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -8,34 +8,13 @@
|
|
|
8
8
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Sweetalert2 = factory());
|
|
9
9
|
})(this, (function () { 'use strict';
|
|
10
10
|
|
|
11
|
-
function _arrayLikeToArray(r, a) {
|
|
12
|
-
(null == a || a > r.length) && (a = r.length);
|
|
13
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
14
|
-
return n;
|
|
15
|
-
}
|
|
16
|
-
function _arrayWithHoles(r) {
|
|
17
|
-
if (Array.isArray(r)) return r;
|
|
18
|
-
}
|
|
19
|
-
function _arrayWithoutHoles(r) {
|
|
20
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
21
|
-
}
|
|
22
11
|
function _assertClassBrand(e, t, n) {
|
|
23
12
|
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
24
13
|
throw new TypeError("Private element is not present on this object");
|
|
25
14
|
}
|
|
26
|
-
function _assertThisInitialized(e) {
|
|
27
|
-
if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
28
|
-
return e;
|
|
29
|
-
}
|
|
30
|
-
function _callSuper(t, o, e) {
|
|
31
|
-
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
32
|
-
}
|
|
33
15
|
function _checkPrivateRedeclaration(e, t) {
|
|
34
16
|
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
35
17
|
}
|
|
36
|
-
function _classCallCheck(a, n) {
|
|
37
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
38
|
-
}
|
|
39
18
|
function _classPrivateFieldGet2(s, a) {
|
|
40
19
|
return s.get(_assertClassBrand(s, a));
|
|
41
20
|
}
|
|
@@ -45,201 +24,12 @@
|
|
|
45
24
|
function _classPrivateFieldSet2(s, a, r) {
|
|
46
25
|
return s.set(_assertClassBrand(s, a), r), r;
|
|
47
26
|
}
|
|
48
|
-
function _construct(t, e, r) {
|
|
49
|
-
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
50
|
-
var o = [null];
|
|
51
|
-
o.push.apply(o, e);
|
|
52
|
-
var p = new (t.bind.apply(t, o))();
|
|
53
|
-
return p;
|
|
54
|
-
}
|
|
55
|
-
function _defineProperties(e, r) {
|
|
56
|
-
for (var t = 0; t < r.length; t++) {
|
|
57
|
-
var o = r[t];
|
|
58
|
-
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function _createClass(e, r, t) {
|
|
62
|
-
return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
|
|
63
|
-
writable: !1
|
|
64
|
-
}), e;
|
|
65
|
-
}
|
|
66
|
-
function _createForOfIteratorHelper(r, e) {
|
|
67
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
68
|
-
if (!t) {
|
|
69
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
|
|
70
|
-
t && (r = t);
|
|
71
|
-
var n = 0,
|
|
72
|
-
F = function () {};
|
|
73
|
-
return {
|
|
74
|
-
s: F,
|
|
75
|
-
n: function () {
|
|
76
|
-
return n >= r.length ? {
|
|
77
|
-
done: !0
|
|
78
|
-
} : {
|
|
79
|
-
done: !1,
|
|
80
|
-
value: r[n++]
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
e: function (r) {
|
|
84
|
-
throw r;
|
|
85
|
-
},
|
|
86
|
-
f: F
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
90
|
-
}
|
|
91
|
-
var o,
|
|
92
|
-
a = !0,
|
|
93
|
-
u = !1;
|
|
94
|
-
return {
|
|
95
|
-
s: function () {
|
|
96
|
-
t = t.call(r);
|
|
97
|
-
},
|
|
98
|
-
n: function () {
|
|
99
|
-
var r = t.next();
|
|
100
|
-
return a = r.done, r;
|
|
101
|
-
},
|
|
102
|
-
e: function (r) {
|
|
103
|
-
u = !0, o = r;
|
|
104
|
-
},
|
|
105
|
-
f: function () {
|
|
106
|
-
try {
|
|
107
|
-
a || null == t.return || t.return();
|
|
108
|
-
} finally {
|
|
109
|
-
if (u) throw o;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function _get() {
|
|
115
|
-
return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
|
|
116
|
-
var p = _superPropBase(e, t);
|
|
117
|
-
if (p) {
|
|
118
|
-
var n = Object.getOwnPropertyDescriptor(p, t);
|
|
119
|
-
return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
|
|
120
|
-
}
|
|
121
|
-
}, _get.apply(null, arguments);
|
|
122
|
-
}
|
|
123
|
-
function _getPrototypeOf(t) {
|
|
124
|
-
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
125
|
-
return t.__proto__ || Object.getPrototypeOf(t);
|
|
126
|
-
}, _getPrototypeOf(t);
|
|
127
|
-
}
|
|
128
|
-
function _inherits(t, e) {
|
|
129
|
-
if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
|
|
130
|
-
t.prototype = Object.create(e && e.prototype, {
|
|
131
|
-
constructor: {
|
|
132
|
-
value: t,
|
|
133
|
-
writable: !0,
|
|
134
|
-
configurable: !0
|
|
135
|
-
}
|
|
136
|
-
}), Object.defineProperty(t, "prototype", {
|
|
137
|
-
writable: !1
|
|
138
|
-
}), e && _setPrototypeOf(t, e);
|
|
139
|
-
}
|
|
140
|
-
function _isNativeReflectConstruct() {
|
|
141
|
-
try {
|
|
142
|
-
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
143
|
-
} catch (t) {}
|
|
144
|
-
return (_isNativeReflectConstruct = function () {
|
|
145
|
-
return !!t;
|
|
146
|
-
})();
|
|
147
|
-
}
|
|
148
|
-
function _iterableToArray(r) {
|
|
149
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
150
|
-
}
|
|
151
|
-
function _iterableToArrayLimit(r, l) {
|
|
152
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
153
|
-
if (null != t) {
|
|
154
|
-
var e,
|
|
155
|
-
n,
|
|
156
|
-
i,
|
|
157
|
-
u,
|
|
158
|
-
a = [],
|
|
159
|
-
f = !0,
|
|
160
|
-
o = !1;
|
|
161
|
-
try {
|
|
162
|
-
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
163
|
-
} catch (r) {
|
|
164
|
-
o = !0, n = r;
|
|
165
|
-
} finally {
|
|
166
|
-
try {
|
|
167
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
168
|
-
} finally {
|
|
169
|
-
if (o) throw n;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return a;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function _nonIterableRest() {
|
|
176
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
177
|
-
}
|
|
178
|
-
function _nonIterableSpread() {
|
|
179
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
180
|
-
}
|
|
181
|
-
function _possibleConstructorReturn(t, e) {
|
|
182
|
-
if (e && ("object" == typeof e || "function" == typeof e)) return e;
|
|
183
|
-
if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
|
|
184
|
-
return _assertThisInitialized(t);
|
|
185
|
-
}
|
|
186
|
-
function _setPrototypeOf(t, e) {
|
|
187
|
-
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
188
|
-
return t.__proto__ = e, t;
|
|
189
|
-
}, _setPrototypeOf(t, e);
|
|
190
|
-
}
|
|
191
|
-
function _slicedToArray(r, e) {
|
|
192
|
-
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
193
|
-
}
|
|
194
|
-
function _superPropBase(t, o) {
|
|
195
|
-
for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
|
|
196
|
-
return t;
|
|
197
|
-
}
|
|
198
|
-
function _superPropGet(t, e, o, r) {
|
|
199
|
-
var p = _get(_getPrototypeOf(t.prototype ), e, o);
|
|
200
|
-
return "function" == typeof p ? function (t) {
|
|
201
|
-
return p.apply(o, t);
|
|
202
|
-
} : p;
|
|
203
|
-
}
|
|
204
|
-
function _toConsumableArray(r) {
|
|
205
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
206
|
-
}
|
|
207
|
-
function _toPrimitive(t, r) {
|
|
208
|
-
if ("object" != typeof t || !t) return t;
|
|
209
|
-
var e = t[Symbol.toPrimitive];
|
|
210
|
-
if (void 0 !== e) {
|
|
211
|
-
var i = e.call(t, r);
|
|
212
|
-
if ("object" != typeof i) return i;
|
|
213
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
214
|
-
}
|
|
215
|
-
return (String )(t);
|
|
216
|
-
}
|
|
217
|
-
function _toPropertyKey(t) {
|
|
218
|
-
var i = _toPrimitive(t, "string");
|
|
219
|
-
return "symbol" == typeof i ? i : i + "";
|
|
220
|
-
}
|
|
221
|
-
function _typeof(o) {
|
|
222
|
-
"@babel/helpers - typeof";
|
|
223
|
-
|
|
224
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
225
|
-
return typeof o;
|
|
226
|
-
} : function (o) {
|
|
227
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
228
|
-
}, _typeof(o);
|
|
229
|
-
}
|
|
230
|
-
function _unsupportedIterableToArray(r, a) {
|
|
231
|
-
if (r) {
|
|
232
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
233
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
234
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
27
|
|
|
238
|
-
|
|
28
|
+
const RESTORE_FOCUS_TIMEOUT = 100;
|
|
239
29
|
|
|
240
30
|
/** @type {GlobalState} */
|
|
241
|
-
|
|
242
|
-
|
|
31
|
+
const globalState = {};
|
|
32
|
+
const focusPreviousActiveElement = () => {
|
|
243
33
|
if (globalState.previousActiveElement instanceof HTMLElement) {
|
|
244
34
|
globalState.previousActiveElement.focus();
|
|
245
35
|
globalState.previousActiveElement = null;
|
|
@@ -254,14 +44,14 @@
|
|
|
254
44
|
* @param {boolean} returnFocus
|
|
255
45
|
* @returns {Promise<void>}
|
|
256
46
|
*/
|
|
257
|
-
|
|
258
|
-
return new Promise(
|
|
47
|
+
const restoreActiveElement = returnFocus => {
|
|
48
|
+
return new Promise(resolve => {
|
|
259
49
|
if (!returnFocus) {
|
|
260
50
|
return resolve();
|
|
261
51
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
globalState.restoreFocusTimeout = setTimeout(
|
|
52
|
+
const x = window.scrollX;
|
|
53
|
+
const y = window.scrollY;
|
|
54
|
+
globalState.restoreFocusTimeout = setTimeout(() => {
|
|
265
55
|
focusPreviousActiveElement();
|
|
266
56
|
resolve();
|
|
267
57
|
}, RESTORE_FOCUS_TIMEOUT); // issues/900
|
|
@@ -270,7 +60,7 @@
|
|
|
270
60
|
});
|
|
271
61
|
};
|
|
272
62
|
|
|
273
|
-
|
|
63
|
+
const swalPrefix = 'swal2-';
|
|
274
64
|
|
|
275
65
|
/**
|
|
276
66
|
* @typedef {Record<SwalClass, string>} SwalClasses
|
|
@@ -282,20 +72,20 @@
|
|
|
282
72
|
*/
|
|
283
73
|
|
|
284
74
|
/** @type {SwalClass[]} */
|
|
285
|
-
|
|
286
|
-
|
|
75
|
+
const classNames = ['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'no-transition', 'toast', 'toast-shown', 'show', 'hide', 'close', 'title', 'html-container', 'actions', 'confirm', 'deny', 'cancel', 'default-outline', 'footer', 'icon', 'icon-content', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'input-label', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', 'loader', 'loading', 'styled', 'top', 'top-start', 'top-end', 'top-left', 'top-right', 'center', 'center-start', 'center-end', 'center-left', 'center-right', 'bottom', 'bottom-start', 'bottom-end', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen', 'rtl', 'timer-progress-bar', 'timer-progress-bar-container', 'scrollbar-measure', 'icon-success', 'icon-warning', 'icon-info', 'icon-question', 'icon-error'];
|
|
76
|
+
const swalClasses = classNames.reduce((acc, className) => {
|
|
287
77
|
acc[className] = swalPrefix + className;
|
|
288
78
|
return acc;
|
|
289
79
|
}, /** @type {SwalClasses} */{});
|
|
290
80
|
|
|
291
81
|
/** @type {SwalIcon[]} */
|
|
292
|
-
|
|
293
|
-
|
|
82
|
+
const icons = ['success', 'warning', 'info', 'question', 'error'];
|
|
83
|
+
const iconTypes = icons.reduce((acc, icon) => {
|
|
294
84
|
acc[icon] = swalPrefix + icon;
|
|
295
85
|
return acc;
|
|
296
86
|
}, /** @type {SwalIcons} */{});
|
|
297
87
|
|
|
298
|
-
|
|
88
|
+
const consolePrefix = 'SweetAlert2:';
|
|
299
89
|
|
|
300
90
|
/**
|
|
301
91
|
* Capitalize the first letter of a string
|
|
@@ -303,17 +93,15 @@
|
|
|
303
93
|
* @param {string} str
|
|
304
94
|
* @returns {string}
|
|
305
95
|
*/
|
|
306
|
-
|
|
307
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
308
|
-
};
|
|
96
|
+
const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1);
|
|
309
97
|
|
|
310
98
|
/**
|
|
311
99
|
* Standardize console warnings
|
|
312
100
|
*
|
|
313
101
|
* @param {string | string[]} message
|
|
314
102
|
*/
|
|
315
|
-
|
|
316
|
-
console.warn(
|
|
103
|
+
const warn = message => {
|
|
104
|
+
console.warn(`${consolePrefix} ${typeof message === 'object' ? message.join(' ') : message}`);
|
|
317
105
|
};
|
|
318
106
|
|
|
319
107
|
/**
|
|
@@ -321,8 +109,8 @@
|
|
|
321
109
|
*
|
|
322
110
|
* @param {string} message
|
|
323
111
|
*/
|
|
324
|
-
|
|
325
|
-
console.error(
|
|
112
|
+
const error = message => {
|
|
113
|
+
console.error(`${consolePrefix} ${message}`);
|
|
326
114
|
};
|
|
327
115
|
|
|
328
116
|
/**
|
|
@@ -331,14 +119,14 @@
|
|
|
331
119
|
* @type {string[]}
|
|
332
120
|
* @private
|
|
333
121
|
*/
|
|
334
|
-
|
|
122
|
+
const previousWarnOnceMessages = [];
|
|
335
123
|
|
|
336
124
|
/**
|
|
337
125
|
* Show a console warning, but only if it hasn't already been shown
|
|
338
126
|
*
|
|
339
127
|
* @param {string} message
|
|
340
128
|
*/
|
|
341
|
-
|
|
129
|
+
const warnOnce = message => {
|
|
342
130
|
if (!previousWarnOnceMessages.includes(message)) {
|
|
343
131
|
previousWarnOnceMessages.push(message);
|
|
344
132
|
warn(message);
|
|
@@ -351,9 +139,9 @@
|
|
|
351
139
|
* @param {string} deprecatedParam
|
|
352
140
|
* @param {string?} useInstead
|
|
353
141
|
*/
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
warnOnce("
|
|
142
|
+
const warnAboutDeprecation = function (deprecatedParam) {
|
|
143
|
+
let useInstead = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
144
|
+
warnOnce(`"${deprecatedParam}" is deprecated and will be removed in the next major release.${useInstead ? ` Use "${useInstead}" instead.` : ''}`);
|
|
357
145
|
};
|
|
358
146
|
|
|
359
147
|
/**
|
|
@@ -363,49 +151,39 @@
|
|
|
363
151
|
* @param {Function | any} arg
|
|
364
152
|
* @returns {any}
|
|
365
153
|
*/
|
|
366
|
-
|
|
367
|
-
return typeof arg === 'function' ? arg() : arg;
|
|
368
|
-
};
|
|
154
|
+
const callIfFunction = arg => typeof arg === 'function' ? arg() : arg;
|
|
369
155
|
|
|
370
156
|
/**
|
|
371
157
|
* @param {any} arg
|
|
372
158
|
* @returns {boolean}
|
|
373
159
|
*/
|
|
374
|
-
|
|
375
|
-
return arg && typeof arg.toPromise === 'function';
|
|
376
|
-
};
|
|
160
|
+
const hasToPromiseFn = arg => arg && typeof arg.toPromise === 'function';
|
|
377
161
|
|
|
378
162
|
/**
|
|
379
163
|
* @param {any} arg
|
|
380
164
|
* @returns {Promise<any>}
|
|
381
165
|
*/
|
|
382
|
-
|
|
383
|
-
return hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
|
|
384
|
-
};
|
|
166
|
+
const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
|
|
385
167
|
|
|
386
168
|
/**
|
|
387
169
|
* @param {any} arg
|
|
388
170
|
* @returns {boolean}
|
|
389
171
|
*/
|
|
390
|
-
|
|
391
|
-
return arg && Promise.resolve(arg) === arg;
|
|
392
|
-
};
|
|
172
|
+
const isPromise = arg => arg && Promise.resolve(arg) === arg;
|
|
393
173
|
|
|
394
174
|
/**
|
|
395
175
|
* Gets the popup container which contains the backdrop and the popup itself.
|
|
396
176
|
*
|
|
397
177
|
* @returns {HTMLElement | null}
|
|
398
178
|
*/
|
|
399
|
-
|
|
400
|
-
return document.body.querySelector(".".concat(swalClasses.container));
|
|
401
|
-
};
|
|
179
|
+
const getContainer = () => document.body.querySelector(`.${swalClasses.container}`);
|
|
402
180
|
|
|
403
181
|
/**
|
|
404
182
|
* @param {string} selectorString
|
|
405
183
|
* @returns {HTMLElement | null}
|
|
406
184
|
*/
|
|
407
|
-
|
|
408
|
-
|
|
185
|
+
const elementBySelector = selectorString => {
|
|
186
|
+
const container = getContainer();
|
|
409
187
|
return container ? container.querySelector(selectorString) : null;
|
|
410
188
|
};
|
|
411
189
|
|
|
@@ -413,146 +191,127 @@
|
|
|
413
191
|
* @param {string} className
|
|
414
192
|
* @returns {HTMLElement | null}
|
|
415
193
|
*/
|
|
416
|
-
|
|
417
|
-
return elementBySelector(
|
|
194
|
+
const elementByClass = className => {
|
|
195
|
+
return elementBySelector(`.${className}`);
|
|
418
196
|
};
|
|
419
197
|
|
|
420
198
|
/**
|
|
421
199
|
* @returns {HTMLElement | null}
|
|
422
200
|
*/
|
|
423
|
-
|
|
424
|
-
return elementByClass(swalClasses.popup);
|
|
425
|
-
};
|
|
201
|
+
const getPopup = () => elementByClass(swalClasses.popup);
|
|
426
202
|
|
|
427
203
|
/**
|
|
428
204
|
* @returns {HTMLElement | null}
|
|
429
205
|
*/
|
|
430
|
-
|
|
431
|
-
return elementByClass(swalClasses.icon);
|
|
432
|
-
};
|
|
206
|
+
const getIcon = () => elementByClass(swalClasses.icon);
|
|
433
207
|
|
|
434
208
|
/**
|
|
435
209
|
* @returns {HTMLElement | null}
|
|
436
210
|
*/
|
|
437
|
-
|
|
438
|
-
return elementByClass(swalClasses['icon-content']);
|
|
439
|
-
};
|
|
211
|
+
const getIconContent = () => elementByClass(swalClasses['icon-content']);
|
|
440
212
|
|
|
441
213
|
/**
|
|
442
214
|
* @returns {HTMLElement | null}
|
|
443
215
|
*/
|
|
444
|
-
|
|
445
|
-
return elementByClass(swalClasses.title);
|
|
446
|
-
};
|
|
216
|
+
const getTitle = () => elementByClass(swalClasses.title);
|
|
447
217
|
|
|
448
218
|
/**
|
|
449
219
|
* @returns {HTMLElement | null}
|
|
450
220
|
*/
|
|
451
|
-
|
|
452
|
-
return elementByClass(swalClasses['html-container']);
|
|
453
|
-
};
|
|
221
|
+
const getHtmlContainer = () => elementByClass(swalClasses['html-container']);
|
|
454
222
|
|
|
455
223
|
/**
|
|
456
224
|
* @returns {HTMLElement | null}
|
|
457
225
|
*/
|
|
458
|
-
|
|
459
|
-
return elementByClass(swalClasses.image);
|
|
460
|
-
};
|
|
226
|
+
const getImage = () => elementByClass(swalClasses.image);
|
|
461
227
|
|
|
462
228
|
/**
|
|
463
229
|
* @returns {HTMLElement | null}
|
|
464
230
|
*/
|
|
465
|
-
|
|
466
|
-
return elementByClass(swalClasses['progress-steps']);
|
|
467
|
-
};
|
|
231
|
+
const getProgressSteps = () => elementByClass(swalClasses['progress-steps']);
|
|
468
232
|
|
|
469
233
|
/**
|
|
470
234
|
* @returns {HTMLElement | null}
|
|
471
235
|
*/
|
|
472
|
-
|
|
473
|
-
return elementByClass(swalClasses['validation-message']);
|
|
474
|
-
};
|
|
236
|
+
const getValidationMessage = () => elementByClass(swalClasses['validation-message']);
|
|
475
237
|
|
|
476
238
|
/**
|
|
477
239
|
* @returns {HTMLButtonElement | null}
|
|
478
240
|
*/
|
|
479
|
-
|
|
480
|
-
return /** @type {HTMLButtonElement} */elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.confirm));
|
|
481
|
-
};
|
|
241
|
+
const getConfirmButton = () => (/** @type {HTMLButtonElement} */elementBySelector(`.${swalClasses.actions} .${swalClasses.confirm}`));
|
|
482
242
|
|
|
483
243
|
/**
|
|
484
244
|
* @returns {HTMLButtonElement | null}
|
|
485
245
|
*/
|
|
486
|
-
|
|
487
|
-
return /** @type {HTMLButtonElement} */elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.cancel));
|
|
488
|
-
};
|
|
246
|
+
const getCancelButton = () => (/** @type {HTMLButtonElement} */elementBySelector(`.${swalClasses.actions} .${swalClasses.cancel}`));
|
|
489
247
|
|
|
490
248
|
/**
|
|
491
249
|
* @returns {HTMLButtonElement | null}
|
|
492
250
|
*/
|
|
493
|
-
|
|
494
|
-
return /** @type {HTMLButtonElement} */elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.deny));
|
|
495
|
-
};
|
|
251
|
+
const getDenyButton = () => (/** @type {HTMLButtonElement} */elementBySelector(`.${swalClasses.actions} .${swalClasses.deny}`));
|
|
496
252
|
|
|
497
253
|
/**
|
|
498
254
|
* @returns {HTMLElement | null}
|
|
499
255
|
*/
|
|
500
|
-
|
|
501
|
-
return elementByClass(swalClasses['input-label']);
|
|
502
|
-
};
|
|
256
|
+
const getInputLabel = () => elementByClass(swalClasses['input-label']);
|
|
503
257
|
|
|
504
258
|
/**
|
|
505
259
|
* @returns {HTMLElement | null}
|
|
506
260
|
*/
|
|
507
|
-
|
|
508
|
-
return elementBySelector(".".concat(swalClasses.loader));
|
|
509
|
-
};
|
|
261
|
+
const getLoader = () => elementBySelector(`.${swalClasses.loader}`);
|
|
510
262
|
|
|
511
263
|
/**
|
|
512
264
|
* @returns {HTMLElement | null}
|
|
513
265
|
*/
|
|
514
|
-
|
|
515
|
-
return elementByClass(swalClasses.actions);
|
|
516
|
-
};
|
|
266
|
+
const getActions = () => elementByClass(swalClasses.actions);
|
|
517
267
|
|
|
518
268
|
/**
|
|
519
269
|
* @returns {HTMLElement | null}
|
|
520
270
|
*/
|
|
521
|
-
|
|
522
|
-
return elementByClass(swalClasses.footer);
|
|
523
|
-
};
|
|
271
|
+
const getFooter = () => elementByClass(swalClasses.footer);
|
|
524
272
|
|
|
525
273
|
/**
|
|
526
274
|
* @returns {HTMLElement | null}
|
|
527
275
|
*/
|
|
528
|
-
|
|
529
|
-
return elementByClass(swalClasses['timer-progress-bar']);
|
|
530
|
-
};
|
|
276
|
+
const getTimerProgressBar = () => elementByClass(swalClasses['timer-progress-bar']);
|
|
531
277
|
|
|
532
278
|
/**
|
|
533
279
|
* @returns {HTMLElement | null}
|
|
534
280
|
*/
|
|
535
|
-
|
|
536
|
-
return elementByClass(swalClasses.close);
|
|
537
|
-
};
|
|
281
|
+
const getCloseButton = () => elementByClass(swalClasses.close);
|
|
538
282
|
|
|
539
283
|
// https://github.com/jkup/focusable/blob/master/index.js
|
|
540
|
-
|
|
284
|
+
const focusable = `
|
|
285
|
+
a[href],
|
|
286
|
+
area[href],
|
|
287
|
+
input:not([disabled]),
|
|
288
|
+
select:not([disabled]),
|
|
289
|
+
textarea:not([disabled]),
|
|
290
|
+
button:not([disabled]),
|
|
291
|
+
iframe,
|
|
292
|
+
object,
|
|
293
|
+
embed,
|
|
294
|
+
[tabindex="0"],
|
|
295
|
+
[contenteditable],
|
|
296
|
+
audio[controls],
|
|
297
|
+
video[controls],
|
|
298
|
+
summary
|
|
299
|
+
`;
|
|
541
300
|
/**
|
|
542
301
|
* @returns {HTMLElement[]}
|
|
543
302
|
*/
|
|
544
|
-
|
|
545
|
-
|
|
303
|
+
const getFocusableElements = () => {
|
|
304
|
+
const popup = getPopup();
|
|
546
305
|
if (!popup) {
|
|
547
306
|
return [];
|
|
548
307
|
}
|
|
549
308
|
/** @type {NodeListOf<HTMLElement>} */
|
|
550
|
-
|
|
551
|
-
|
|
309
|
+
const focusableElementsWithTabindex = popup.querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])');
|
|
310
|
+
const focusableElementsWithTabindexSorted = Array.from(focusableElementsWithTabindex)
|
|
552
311
|
// sort according to tabindex
|
|
553
|
-
.sort(
|
|
554
|
-
|
|
555
|
-
|
|
312
|
+
.sort((a, b) => {
|
|
313
|
+
const tabindexA = parseInt(a.getAttribute('tabindex') || '0');
|
|
314
|
+
const tabindexB = parseInt(b.getAttribute('tabindex') || '0');
|
|
556
315
|
if (tabindexA > tabindexB) {
|
|
557
316
|
return 1;
|
|
558
317
|
} else if (tabindexA < tabindexB) {
|
|
@@ -562,27 +321,23 @@
|
|
|
562
321
|
});
|
|
563
322
|
|
|
564
323
|
/** @type {NodeListOf<HTMLElement>} */
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
});
|
|
569
|
-
return _toConsumableArray(new Set(focusableElementsWithTabindexSorted.concat(otherFocusableElementsFiltered))).filter(function (el) {
|
|
570
|
-
return isVisible$1(el);
|
|
571
|
-
});
|
|
324
|
+
const otherFocusableElements = popup.querySelectorAll(focusable);
|
|
325
|
+
const otherFocusableElementsFiltered = Array.from(otherFocusableElements).filter(el => el.getAttribute('tabindex') !== '-1');
|
|
326
|
+
return [...new Set(focusableElementsWithTabindexSorted.concat(otherFocusableElementsFiltered))].filter(el => isVisible$1(el));
|
|
572
327
|
};
|
|
573
328
|
|
|
574
329
|
/**
|
|
575
330
|
* @returns {boolean}
|
|
576
331
|
*/
|
|
577
|
-
|
|
332
|
+
const isModal = () => {
|
|
578
333
|
return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
|
|
579
334
|
};
|
|
580
335
|
|
|
581
336
|
/**
|
|
582
337
|
* @returns {boolean}
|
|
583
338
|
*/
|
|
584
|
-
|
|
585
|
-
|
|
339
|
+
const isToast = () => {
|
|
340
|
+
const popup = getPopup();
|
|
586
341
|
if (!popup) {
|
|
587
342
|
return false;
|
|
588
343
|
}
|
|
@@ -592,8 +347,8 @@
|
|
|
592
347
|
/**
|
|
593
348
|
* @returns {boolean}
|
|
594
349
|
*/
|
|
595
|
-
|
|
596
|
-
|
|
350
|
+
const isLoading = () => {
|
|
351
|
+
const popup = getPopup();
|
|
597
352
|
if (!popup) {
|
|
598
353
|
return false;
|
|
599
354
|
}
|
|
@@ -607,20 +362,20 @@
|
|
|
607
362
|
* @param {HTMLElement} elem
|
|
608
363
|
* @param {string} html
|
|
609
364
|
*/
|
|
610
|
-
|
|
365
|
+
const setInnerHtml = (elem, html) => {
|
|
611
366
|
elem.textContent = '';
|
|
612
367
|
if (html) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
368
|
+
const parser = new DOMParser();
|
|
369
|
+
const parsed = parser.parseFromString(html, `text/html`);
|
|
370
|
+
const head = parsed.querySelector('head');
|
|
616
371
|
if (head) {
|
|
617
|
-
Array.from(head.childNodes).forEach(
|
|
372
|
+
Array.from(head.childNodes).forEach(child => {
|
|
618
373
|
elem.appendChild(child);
|
|
619
374
|
});
|
|
620
375
|
}
|
|
621
|
-
|
|
376
|
+
const body = parsed.querySelector('body');
|
|
622
377
|
if (body) {
|
|
623
|
-
Array.from(body.childNodes).forEach(
|
|
378
|
+
Array.from(body.childNodes).forEach(child => {
|
|
624
379
|
if (child instanceof HTMLVideoElement || child instanceof HTMLAudioElement) {
|
|
625
380
|
elem.appendChild(child.cloneNode(true)); // https://github.com/sweetalert2/sweetalert2/issues/2507
|
|
626
381
|
} else {
|
|
@@ -636,12 +391,12 @@
|
|
|
636
391
|
* @param {string} className
|
|
637
392
|
* @returns {boolean}
|
|
638
393
|
*/
|
|
639
|
-
|
|
394
|
+
const hasClass = (elem, className) => {
|
|
640
395
|
if (!className) {
|
|
641
396
|
return false;
|
|
642
397
|
}
|
|
643
|
-
|
|
644
|
-
for (
|
|
398
|
+
const classList = className.split(/\s+/);
|
|
399
|
+
for (let i = 0; i < classList.length; i++) {
|
|
645
400
|
if (!elem.classList.contains(classList[i])) {
|
|
646
401
|
return false;
|
|
647
402
|
}
|
|
@@ -653,8 +408,8 @@
|
|
|
653
408
|
* @param {HTMLElement} elem
|
|
654
409
|
* @param {SweetAlertOptions} params
|
|
655
410
|
*/
|
|
656
|
-
|
|
657
|
-
Array.from(elem.classList).forEach(
|
|
411
|
+
const removeCustomClasses = (elem, params) => {
|
|
412
|
+
Array.from(elem.classList).forEach(className => {
|
|
658
413
|
if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass || {}).includes(className)) {
|
|
659
414
|
elem.classList.remove(className);
|
|
660
415
|
}
|
|
@@ -666,17 +421,17 @@
|
|
|
666
421
|
* @param {SweetAlertOptions} params
|
|
667
422
|
* @param {string} className
|
|
668
423
|
*/
|
|
669
|
-
|
|
424
|
+
const applyCustomClass = (elem, params, className) => {
|
|
670
425
|
removeCustomClasses(elem, params);
|
|
671
426
|
if (!params.customClass) {
|
|
672
427
|
return;
|
|
673
428
|
}
|
|
674
|
-
|
|
429
|
+
const customClass = params.customClass[(/** @type {keyof SweetAlertCustomClass} */className)];
|
|
675
430
|
if (!customClass) {
|
|
676
431
|
return;
|
|
677
432
|
}
|
|
678
433
|
if (typeof customClass !== 'string' && !customClass.forEach) {
|
|
679
|
-
warn(
|
|
434
|
+
warn(`Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof customClass}"`);
|
|
680
435
|
return;
|
|
681
436
|
}
|
|
682
437
|
addClass(elem, customClass);
|
|
@@ -687,7 +442,7 @@
|
|
|
687
442
|
* @param {import('./renderers/renderInput').InputClass | SweetAlertInput} inputClass
|
|
688
443
|
* @returns {HTMLInputElement | null}
|
|
689
444
|
*/
|
|
690
|
-
|
|
445
|
+
const getInput$1 = (popup, inputClass) => {
|
|
691
446
|
if (!inputClass) {
|
|
692
447
|
return null;
|
|
693
448
|
}
|
|
@@ -695,28 +450,28 @@
|
|
|
695
450
|
case 'select':
|
|
696
451
|
case 'textarea':
|
|
697
452
|
case 'file':
|
|
698
|
-
return popup.querySelector(
|
|
453
|
+
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses[inputClass]}`);
|
|
699
454
|
case 'checkbox':
|
|
700
|
-
return popup.querySelector(
|
|
455
|
+
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.checkbox} input`);
|
|
701
456
|
case 'radio':
|
|
702
|
-
return popup.querySelector(
|
|
457
|
+
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) || popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:first-child`);
|
|
703
458
|
case 'range':
|
|
704
|
-
return popup.querySelector(
|
|
459
|
+
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.range} input`);
|
|
705
460
|
default:
|
|
706
|
-
return popup.querySelector(
|
|
461
|
+
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.input}`);
|
|
707
462
|
}
|
|
708
463
|
};
|
|
709
464
|
|
|
710
465
|
/**
|
|
711
466
|
* @param {HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement} input
|
|
712
467
|
*/
|
|
713
|
-
|
|
468
|
+
const focusInput = input => {
|
|
714
469
|
input.focus();
|
|
715
470
|
|
|
716
471
|
// place cursor at end of text in text input
|
|
717
472
|
if (input.type !== 'file') {
|
|
718
473
|
// http://stackoverflow.com/a/2345915
|
|
719
|
-
|
|
474
|
+
const val = input.value;
|
|
720
475
|
input.value = '';
|
|
721
476
|
input.value = val;
|
|
722
477
|
}
|
|
@@ -727,16 +482,16 @@
|
|
|
727
482
|
* @param {string | string[] | readonly string[] | undefined} classList
|
|
728
483
|
* @param {boolean} condition
|
|
729
484
|
*/
|
|
730
|
-
|
|
485
|
+
const toggleClass = (target, classList, condition) => {
|
|
731
486
|
if (!target || !classList) {
|
|
732
487
|
return;
|
|
733
488
|
}
|
|
734
489
|
if (typeof classList === 'string') {
|
|
735
490
|
classList = classList.split(/\s+/).filter(Boolean);
|
|
736
491
|
}
|
|
737
|
-
classList.forEach(
|
|
492
|
+
classList.forEach(className => {
|
|
738
493
|
if (Array.isArray(target)) {
|
|
739
|
-
target.forEach(
|
|
494
|
+
target.forEach(elem => {
|
|
740
495
|
if (condition) {
|
|
741
496
|
elem.classList.add(className);
|
|
742
497
|
} else {
|
|
@@ -757,7 +512,7 @@
|
|
|
757
512
|
* @param {HTMLElement | HTMLElement[] | null} target
|
|
758
513
|
* @param {string | string[] | readonly string[] | undefined} classList
|
|
759
514
|
*/
|
|
760
|
-
|
|
515
|
+
const addClass = (target, classList) => {
|
|
761
516
|
toggleClass(target, classList, true);
|
|
762
517
|
};
|
|
763
518
|
|
|
@@ -765,7 +520,7 @@
|
|
|
765
520
|
* @param {HTMLElement | HTMLElement[] | null} target
|
|
766
521
|
* @param {string | string[] | readonly string[] | undefined} classList
|
|
767
522
|
*/
|
|
768
|
-
|
|
523
|
+
const removeClass = (target, classList) => {
|
|
769
524
|
toggleClass(target, classList, false);
|
|
770
525
|
};
|
|
771
526
|
|
|
@@ -776,10 +531,10 @@
|
|
|
776
531
|
* @param {string} className
|
|
777
532
|
* @returns {HTMLElement | undefined}
|
|
778
533
|
*/
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
for (
|
|
782
|
-
|
|
534
|
+
const getDirectChildByClass = (elem, className) => {
|
|
535
|
+
const children = Array.from(elem.children);
|
|
536
|
+
for (let i = 0; i < children.length; i++) {
|
|
537
|
+
const child = children[i];
|
|
783
538
|
if (child instanceof HTMLElement && hasClass(child, className)) {
|
|
784
539
|
return child;
|
|
785
540
|
}
|
|
@@ -791,12 +546,12 @@
|
|
|
791
546
|
* @param {string} property
|
|
792
547
|
* @param {*} value
|
|
793
548
|
*/
|
|
794
|
-
|
|
795
|
-
if (value ===
|
|
549
|
+
const applyNumericalStyle = (elem, property, value) => {
|
|
550
|
+
if (value === `${parseInt(value)}`) {
|
|
796
551
|
value = parseInt(value);
|
|
797
552
|
}
|
|
798
553
|
if (value || parseInt(value) === 0) {
|
|
799
|
-
elem.style.setProperty(property, typeof value === 'number' ?
|
|
554
|
+
elem.style.setProperty(property, typeof value === 'number' ? `${value}px` : value);
|
|
800
555
|
} else {
|
|
801
556
|
elem.style.removeProperty(property);
|
|
802
557
|
}
|
|
@@ -806,8 +561,8 @@
|
|
|
806
561
|
* @param {HTMLElement | null} elem
|
|
807
562
|
* @param {string} display
|
|
808
563
|
*/
|
|
809
|
-
|
|
810
|
-
|
|
564
|
+
const show = function (elem) {
|
|
565
|
+
let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
|
|
811
566
|
if (!elem) {
|
|
812
567
|
return;
|
|
813
568
|
}
|
|
@@ -817,7 +572,7 @@
|
|
|
817
572
|
/**
|
|
818
573
|
* @param {HTMLElement | null} elem
|
|
819
574
|
*/
|
|
820
|
-
|
|
575
|
+
const hide = elem => {
|
|
821
576
|
if (!elem) {
|
|
822
577
|
return;
|
|
823
578
|
}
|
|
@@ -828,12 +583,12 @@
|
|
|
828
583
|
* @param {HTMLElement | null} elem
|
|
829
584
|
* @param {string} display
|
|
830
585
|
*/
|
|
831
|
-
|
|
832
|
-
|
|
586
|
+
const showWhenInnerHtmlPresent = function (elem) {
|
|
587
|
+
let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'block';
|
|
833
588
|
if (!elem) {
|
|
834
589
|
return;
|
|
835
590
|
}
|
|
836
|
-
new MutationObserver(
|
|
591
|
+
new MutationObserver(() => {
|
|
837
592
|
toggle(elem, elem.innerHTML, display);
|
|
838
593
|
}).observe(elem, {
|
|
839
594
|
childList: true,
|
|
@@ -847,9 +602,9 @@
|
|
|
847
602
|
* @param {string} property
|
|
848
603
|
* @param {string} value
|
|
849
604
|
*/
|
|
850
|
-
|
|
605
|
+
const setStyle = (parent, selector, property, value) => {
|
|
851
606
|
/** @type {HTMLElement | null} */
|
|
852
|
-
|
|
607
|
+
const el = parent.querySelector(selector);
|
|
853
608
|
if (el) {
|
|
854
609
|
el.style.setProperty(property, value);
|
|
855
610
|
}
|
|
@@ -860,8 +615,8 @@
|
|
|
860
615
|
* @param {any} condition
|
|
861
616
|
* @param {string} display
|
|
862
617
|
*/
|
|
863
|
-
|
|
864
|
-
|
|
618
|
+
const toggle = function (elem, condition) {
|
|
619
|
+
let display = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'flex';
|
|
865
620
|
if (condition) {
|
|
866
621
|
show(elem, display);
|
|
867
622
|
} else {
|
|
@@ -875,24 +630,18 @@
|
|
|
875
630
|
* @param {HTMLElement | null} elem
|
|
876
631
|
* @returns {boolean}
|
|
877
632
|
*/
|
|
878
|
-
|
|
879
|
-
return !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
|
|
880
|
-
};
|
|
633
|
+
const isVisible$1 = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
|
|
881
634
|
|
|
882
635
|
/**
|
|
883
636
|
* @returns {boolean}
|
|
884
637
|
*/
|
|
885
|
-
|
|
886
|
-
return !isVisible$1(getConfirmButton()) && !isVisible$1(getDenyButton()) && !isVisible$1(getCancelButton());
|
|
887
|
-
};
|
|
638
|
+
const allButtonsAreHidden = () => !isVisible$1(getConfirmButton()) && !isVisible$1(getDenyButton()) && !isVisible$1(getCancelButton());
|
|
888
639
|
|
|
889
640
|
/**
|
|
890
641
|
* @param {HTMLElement} elem
|
|
891
642
|
* @returns {boolean}
|
|
892
643
|
*/
|
|
893
|
-
|
|
894
|
-
return !!(elem.scrollHeight > elem.clientHeight);
|
|
895
|
-
};
|
|
644
|
+
const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight);
|
|
896
645
|
|
|
897
646
|
/**
|
|
898
647
|
* borrowed from https://stackoverflow.com/a/46352119
|
|
@@ -900,10 +649,10 @@
|
|
|
900
649
|
* @param {HTMLElement} elem
|
|
901
650
|
* @returns {boolean}
|
|
902
651
|
*/
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
652
|
+
const hasCssAnimation = elem => {
|
|
653
|
+
const style = window.getComputedStyle(elem);
|
|
654
|
+
const animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
|
|
655
|
+
const transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
|
|
907
656
|
return animDuration > 0 || transDuration > 0;
|
|
908
657
|
};
|
|
909
658
|
|
|
@@ -911,9 +660,9 @@
|
|
|
911
660
|
* @param {number} timer
|
|
912
661
|
* @param {boolean} reset
|
|
913
662
|
*/
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
663
|
+
const animateTimerProgressBar = function (timer) {
|
|
664
|
+
let reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
665
|
+
const timerProgressBar = getTimerProgressBar();
|
|
917
666
|
if (!timerProgressBar) {
|
|
918
667
|
return;
|
|
919
668
|
}
|
|
@@ -922,23 +671,23 @@
|
|
|
922
671
|
timerProgressBar.style.transition = 'none';
|
|
923
672
|
timerProgressBar.style.width = '100%';
|
|
924
673
|
}
|
|
925
|
-
setTimeout(
|
|
926
|
-
timerProgressBar.style.transition =
|
|
674
|
+
setTimeout(() => {
|
|
675
|
+
timerProgressBar.style.transition = `width ${timer / 1000}s linear`;
|
|
927
676
|
timerProgressBar.style.width = '0%';
|
|
928
677
|
}, 10);
|
|
929
678
|
}
|
|
930
679
|
};
|
|
931
|
-
|
|
932
|
-
|
|
680
|
+
const stopTimerProgressBar = () => {
|
|
681
|
+
const timerProgressBar = getTimerProgressBar();
|
|
933
682
|
if (!timerProgressBar) {
|
|
934
683
|
return;
|
|
935
684
|
}
|
|
936
|
-
|
|
685
|
+
const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
|
|
937
686
|
timerProgressBar.style.removeProperty('transition');
|
|
938
687
|
timerProgressBar.style.width = '100%';
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
timerProgressBar.style.width =
|
|
688
|
+
const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
|
|
689
|
+
const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100;
|
|
690
|
+
timerProgressBar.style.width = `${timerProgressBarPercent}%`;
|
|
942
691
|
};
|
|
943
692
|
|
|
944
693
|
/**
|
|
@@ -946,17 +695,48 @@
|
|
|
946
695
|
*
|
|
947
696
|
* @returns {boolean}
|
|
948
697
|
*/
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
698
|
+
const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined';
|
|
699
|
+
|
|
700
|
+
const sweetHTML = `
|
|
701
|
+
<div aria-labelledby="${swalClasses.title}" aria-describedby="${swalClasses['html-container']}" class="${swalClasses.popup}" tabindex="-1">
|
|
702
|
+
<button type="button" class="${swalClasses.close}"></button>
|
|
703
|
+
<ul class="${swalClasses['progress-steps']}"></ul>
|
|
704
|
+
<div class="${swalClasses.icon}"></div>
|
|
705
|
+
<img class="${swalClasses.image}" />
|
|
706
|
+
<h2 class="${swalClasses.title}" id="${swalClasses.title}"></h2>
|
|
707
|
+
<div class="${swalClasses['html-container']}" id="${swalClasses['html-container']}"></div>
|
|
708
|
+
<input class="${swalClasses.input}" id="${swalClasses.input}" />
|
|
709
|
+
<input type="file" class="${swalClasses.file}" />
|
|
710
|
+
<div class="${swalClasses.range}">
|
|
711
|
+
<input type="range" />
|
|
712
|
+
<output></output>
|
|
713
|
+
</div>
|
|
714
|
+
<select class="${swalClasses.select}" id="${swalClasses.select}"></select>
|
|
715
|
+
<div class="${swalClasses.radio}"></div>
|
|
716
|
+
<label class="${swalClasses.checkbox}">
|
|
717
|
+
<input type="checkbox" id="${swalClasses.checkbox}" />
|
|
718
|
+
<span class="${swalClasses.label}"></span>
|
|
719
|
+
</label>
|
|
720
|
+
<textarea class="${swalClasses.textarea}" id="${swalClasses.textarea}"></textarea>
|
|
721
|
+
<div class="${swalClasses['validation-message']}" id="${swalClasses['validation-message']}"></div>
|
|
722
|
+
<div class="${swalClasses.actions}">
|
|
723
|
+
<div class="${swalClasses.loader}"></div>
|
|
724
|
+
<button type="button" class="${swalClasses.confirm}"></button>
|
|
725
|
+
<button type="button" class="${swalClasses.deny}"></button>
|
|
726
|
+
<button type="button" class="${swalClasses.cancel}"></button>
|
|
727
|
+
</div>
|
|
728
|
+
<div class="${swalClasses.footer}"></div>
|
|
729
|
+
<div class="${swalClasses['timer-progress-bar-container']}">
|
|
730
|
+
<div class="${swalClasses['timer-progress-bar']}"></div>
|
|
731
|
+
</div>
|
|
732
|
+
</div>
|
|
733
|
+
`.replace(/(^|\n)\s*/g, '');
|
|
954
734
|
|
|
955
735
|
/**
|
|
956
736
|
* @returns {boolean}
|
|
957
737
|
*/
|
|
958
|
-
|
|
959
|
-
|
|
738
|
+
const resetOldContainer = () => {
|
|
739
|
+
const oldContainer = getContainer();
|
|
960
740
|
if (!oldContainer) {
|
|
961
741
|
return false;
|
|
962
742
|
}
|
|
@@ -964,31 +744,31 @@
|
|
|
964
744
|
removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
|
|
965
745
|
return true;
|
|
966
746
|
};
|
|
967
|
-
|
|
747
|
+
const resetValidationMessage$1 = () => {
|
|
968
748
|
globalState.currentInstance.resetValidationMessage();
|
|
969
749
|
};
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
750
|
+
const addInputChangeListeners = () => {
|
|
751
|
+
const popup = getPopup();
|
|
752
|
+
const input = getDirectChildByClass(popup, swalClasses.input);
|
|
753
|
+
const file = getDirectChildByClass(popup, swalClasses.file);
|
|
974
754
|
/** @type {HTMLInputElement} */
|
|
975
|
-
|
|
755
|
+
const range = popup.querySelector(`.${swalClasses.range} input`);
|
|
976
756
|
/** @type {HTMLOutputElement} */
|
|
977
|
-
|
|
978
|
-
|
|
757
|
+
const rangeOutput = popup.querySelector(`.${swalClasses.range} output`);
|
|
758
|
+
const select = getDirectChildByClass(popup, swalClasses.select);
|
|
979
759
|
/** @type {HTMLInputElement} */
|
|
980
|
-
|
|
981
|
-
|
|
760
|
+
const checkbox = popup.querySelector(`.${swalClasses.checkbox} input`);
|
|
761
|
+
const textarea = getDirectChildByClass(popup, swalClasses.textarea);
|
|
982
762
|
input.oninput = resetValidationMessage$1;
|
|
983
763
|
file.onchange = resetValidationMessage$1;
|
|
984
764
|
select.onchange = resetValidationMessage$1;
|
|
985
765
|
checkbox.onchange = resetValidationMessage$1;
|
|
986
766
|
textarea.oninput = resetValidationMessage$1;
|
|
987
|
-
range.oninput =
|
|
767
|
+
range.oninput = () => {
|
|
988
768
|
resetValidationMessage$1();
|
|
989
769
|
rangeOutput.value = range.value;
|
|
990
770
|
};
|
|
991
|
-
range.onchange =
|
|
771
|
+
range.onchange = () => {
|
|
992
772
|
resetValidationMessage$1();
|
|
993
773
|
rangeOutput.value = range.value;
|
|
994
774
|
};
|
|
@@ -998,15 +778,13 @@
|
|
|
998
778
|
* @param {string | HTMLElement} target
|
|
999
779
|
* @returns {HTMLElement}
|
|
1000
780
|
*/
|
|
1001
|
-
|
|
1002
|
-
return typeof target === 'string' ? document.querySelector(target) : target;
|
|
1003
|
-
};
|
|
781
|
+
const getTarget = target => typeof target === 'string' ? document.querySelector(target) : target;
|
|
1004
782
|
|
|
1005
783
|
/**
|
|
1006
784
|
* @param {SweetAlertOptions} params
|
|
1007
785
|
*/
|
|
1008
|
-
|
|
1009
|
-
|
|
786
|
+
const setupAccessibility = params => {
|
|
787
|
+
const popup = getPopup();
|
|
1010
788
|
popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
|
|
1011
789
|
popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
|
|
1012
790
|
if (!params.toast) {
|
|
@@ -1017,7 +795,7 @@
|
|
|
1017
795
|
/**
|
|
1018
796
|
* @param {HTMLElement} targetElement
|
|
1019
797
|
*/
|
|
1020
|
-
|
|
798
|
+
const setupRTL = targetElement => {
|
|
1021
799
|
if (window.getComputedStyle(targetElement).direction === 'rtl') {
|
|
1022
800
|
addClass(getContainer(), swalClasses.rtl);
|
|
1023
801
|
}
|
|
@@ -1028,20 +806,20 @@
|
|
|
1028
806
|
*
|
|
1029
807
|
* @param {SweetAlertOptions} params
|
|
1030
808
|
*/
|
|
1031
|
-
|
|
809
|
+
const init = params => {
|
|
1032
810
|
// Clean up the old popup container if it exists
|
|
1033
|
-
|
|
811
|
+
const oldContainerExisted = resetOldContainer();
|
|
1034
812
|
if (isNodeEnv()) {
|
|
1035
813
|
error('SweetAlert2 requires document to initialize');
|
|
1036
814
|
return;
|
|
1037
815
|
}
|
|
1038
|
-
|
|
816
|
+
const container = document.createElement('div');
|
|
1039
817
|
container.className = swalClasses.container;
|
|
1040
818
|
if (oldContainerExisted) {
|
|
1041
819
|
addClass(container, swalClasses['no-transition']);
|
|
1042
820
|
}
|
|
1043
821
|
setInnerHtml(container, sweetHTML);
|
|
1044
|
-
|
|
822
|
+
const targetElement = getTarget(params.target);
|
|
1045
823
|
targetElement.appendChild(container);
|
|
1046
824
|
setupAccessibility(params);
|
|
1047
825
|
setupRTL(targetElement);
|
|
@@ -1052,14 +830,14 @@
|
|
|
1052
830
|
* @param {HTMLElement | object | string} param
|
|
1053
831
|
* @param {HTMLElement} target
|
|
1054
832
|
*/
|
|
1055
|
-
|
|
833
|
+
const parseHtmlToContainer = (param, target) => {
|
|
1056
834
|
// DOM element
|
|
1057
835
|
if (param instanceof HTMLElement) {
|
|
1058
836
|
target.appendChild(param);
|
|
1059
837
|
}
|
|
1060
838
|
|
|
1061
839
|
// Object
|
|
1062
|
-
else if (
|
|
840
|
+
else if (typeof param === 'object') {
|
|
1063
841
|
handleObject(param, target);
|
|
1064
842
|
}
|
|
1065
843
|
|
|
@@ -1073,7 +851,7 @@
|
|
|
1073
851
|
* @param {any} param
|
|
1074
852
|
* @param {HTMLElement} target
|
|
1075
853
|
*/
|
|
1076
|
-
|
|
854
|
+
const handleObject = (param, target) => {
|
|
1077
855
|
// JQuery element(s)
|
|
1078
856
|
if (param.jquery) {
|
|
1079
857
|
handleJqueryElem(target, param);
|
|
@@ -1089,10 +867,10 @@
|
|
|
1089
867
|
* @param {HTMLElement} target
|
|
1090
868
|
* @param {any} elem
|
|
1091
869
|
*/
|
|
1092
|
-
|
|
870
|
+
const handleJqueryElem = (target, elem) => {
|
|
1093
871
|
target.textContent = '';
|
|
1094
872
|
if (0 in elem) {
|
|
1095
|
-
for (
|
|
873
|
+
for (let i = 0; i in elem; i++) {
|
|
1096
874
|
target.appendChild(elem[i].cloneNode(true));
|
|
1097
875
|
}
|
|
1098
876
|
} else {
|
|
@@ -1103,12 +881,12 @@
|
|
|
1103
881
|
/**
|
|
1104
882
|
* @returns {'webkitAnimationEnd' | 'animationend' | false}
|
|
1105
883
|
*/
|
|
1106
|
-
|
|
884
|
+
const animationEndEvent = (() => {
|
|
1107
885
|
// Prevent run in Node env
|
|
1108
886
|
if (isNodeEnv()) {
|
|
1109
887
|
return false;
|
|
1110
888
|
}
|
|
1111
|
-
|
|
889
|
+
const testEl = document.createElement('div');
|
|
1112
890
|
|
|
1113
891
|
// Chrome, Safari and Opera
|
|
1114
892
|
if (typeof testEl.style.webkitAnimation !== 'undefined') {
|
|
@@ -1120,15 +898,15 @@
|
|
|
1120
898
|
return 'animationend';
|
|
1121
899
|
}
|
|
1122
900
|
return false;
|
|
1123
|
-
}();
|
|
901
|
+
})();
|
|
1124
902
|
|
|
1125
903
|
/**
|
|
1126
904
|
* @param {SweetAlert} instance
|
|
1127
905
|
* @param {SweetAlertOptions} params
|
|
1128
906
|
*/
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
907
|
+
const renderActions = (instance, params) => {
|
|
908
|
+
const actions = getActions();
|
|
909
|
+
const loader = getLoader();
|
|
1132
910
|
if (!actions || !loader) {
|
|
1133
911
|
return;
|
|
1134
912
|
}
|
|
@@ -1157,9 +935,9 @@
|
|
|
1157
935
|
* @param {SweetAlertOptions} params
|
|
1158
936
|
*/
|
|
1159
937
|
function renderButtons(actions, loader, params) {
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
938
|
+
const confirmButton = getConfirmButton();
|
|
939
|
+
const denyButton = getDenyButton();
|
|
940
|
+
const cancelButton = getCancelButton();
|
|
1163
941
|
if (!confirmButton || !denyButton || !cancelButton) {
|
|
1164
942
|
return;
|
|
1165
943
|
}
|
|
@@ -1215,22 +993,22 @@
|
|
|
1215
993
|
* @param {SweetAlertOptions} params
|
|
1216
994
|
*/
|
|
1217
995
|
function renderButton(button, buttonType, params) {
|
|
1218
|
-
|
|
1219
|
-
toggle(button, params[
|
|
1220
|
-
setInnerHtml(button, params[
|
|
1221
|
-
button.setAttribute('aria-label', params[
|
|
996
|
+
const buttonName = /** @type {'Confirm' | 'Deny' | 'Cancel'} */capitalizeFirstLetter(buttonType);
|
|
997
|
+
toggle(button, params[`show${buttonName}Button`], 'inline-block');
|
|
998
|
+
setInnerHtml(button, params[`${buttonType}ButtonText`] || ''); // Set caption text
|
|
999
|
+
button.setAttribute('aria-label', params[`${buttonType}ButtonAriaLabel`] || ''); // ARIA label
|
|
1222
1000
|
|
|
1223
1001
|
// Add buttons custom classes
|
|
1224
1002
|
button.className = swalClasses[buttonType];
|
|
1225
|
-
applyCustomClass(button, params,
|
|
1003
|
+
applyCustomClass(button, params, `${buttonType}Button`);
|
|
1226
1004
|
}
|
|
1227
1005
|
|
|
1228
1006
|
/**
|
|
1229
1007
|
* @param {SweetAlert} instance
|
|
1230
1008
|
* @param {SweetAlertOptions} params
|
|
1231
1009
|
*/
|
|
1232
|
-
|
|
1233
|
-
|
|
1010
|
+
const renderCloseButton = (instance, params) => {
|
|
1011
|
+
const closeButton = getCloseButton();
|
|
1234
1012
|
if (!closeButton) {
|
|
1235
1013
|
return;
|
|
1236
1014
|
}
|
|
@@ -1246,8 +1024,8 @@
|
|
|
1246
1024
|
* @param {SweetAlert} instance
|
|
1247
1025
|
* @param {SweetAlertOptions} params
|
|
1248
1026
|
*/
|
|
1249
|
-
|
|
1250
|
-
|
|
1027
|
+
const renderContainer = (instance, params) => {
|
|
1028
|
+
const container = getContainer();
|
|
1251
1029
|
if (!container) {
|
|
1252
1030
|
return;
|
|
1253
1031
|
}
|
|
@@ -1295,7 +1073,7 @@
|
|
|
1295
1073
|
if (!grow) {
|
|
1296
1074
|
return;
|
|
1297
1075
|
}
|
|
1298
|
-
addClass(container, swalClasses[
|
|
1076
|
+
addClass(container, swalClasses[`grow-${grow}`]);
|
|
1299
1077
|
}
|
|
1300
1078
|
|
|
1301
1079
|
/**
|
|
@@ -1313,22 +1091,25 @@
|
|
|
1313
1091
|
domCache: new WeakMap()
|
|
1314
1092
|
};
|
|
1315
1093
|
|
|
1094
|
+
/// <reference path="../../../../sweetalert2.d.ts"/>
|
|
1095
|
+
|
|
1096
|
+
|
|
1316
1097
|
/** @type {InputClass[]} */
|
|
1317
|
-
|
|
1098
|
+
const inputClasses = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
|
|
1318
1099
|
|
|
1319
1100
|
/**
|
|
1320
1101
|
* @param {SweetAlert} instance
|
|
1321
1102
|
* @param {SweetAlertOptions} params
|
|
1322
1103
|
*/
|
|
1323
|
-
|
|
1324
|
-
|
|
1104
|
+
const renderInput = (instance, params) => {
|
|
1105
|
+
const popup = getPopup();
|
|
1325
1106
|
if (!popup) {
|
|
1326
1107
|
return;
|
|
1327
1108
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
inputClasses.forEach(
|
|
1331
|
-
|
|
1109
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
1110
|
+
const rerender = !innerParams || params.input !== innerParams.input;
|
|
1111
|
+
inputClasses.forEach(inputClass => {
|
|
1112
|
+
const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]);
|
|
1332
1113
|
if (!inputContainer) {
|
|
1333
1114
|
return;
|
|
1334
1115
|
}
|
|
@@ -1354,24 +1135,24 @@
|
|
|
1354
1135
|
/**
|
|
1355
1136
|
* @param {SweetAlertOptions} params
|
|
1356
1137
|
*/
|
|
1357
|
-
|
|
1138
|
+
const showInput = params => {
|
|
1358
1139
|
if (!params.input) {
|
|
1359
1140
|
return;
|
|
1360
1141
|
}
|
|
1361
1142
|
if (!renderInputType[params.input]) {
|
|
1362
|
-
error(
|
|
1143
|
+
error(`Unexpected type of input! Expected ${Object.keys(renderInputType).join(' | ')}, got "${params.input}"`);
|
|
1363
1144
|
return;
|
|
1364
1145
|
}
|
|
1365
|
-
|
|
1146
|
+
const inputContainer = getInputContainer(params.input);
|
|
1366
1147
|
if (!inputContainer) {
|
|
1367
1148
|
return;
|
|
1368
1149
|
}
|
|
1369
|
-
|
|
1150
|
+
const input = renderInputType[params.input](inputContainer, params);
|
|
1370
1151
|
show(inputContainer);
|
|
1371
1152
|
|
|
1372
1153
|
// input autofocus
|
|
1373
1154
|
if (params.inputAutoFocus) {
|
|
1374
|
-
setTimeout(
|
|
1155
|
+
setTimeout(() => {
|
|
1375
1156
|
focusInput(input);
|
|
1376
1157
|
});
|
|
1377
1158
|
}
|
|
@@ -1380,9 +1161,9 @@
|
|
|
1380
1161
|
/**
|
|
1381
1162
|
* @param {HTMLInputElement} input
|
|
1382
1163
|
*/
|
|
1383
|
-
|
|
1384
|
-
for (
|
|
1385
|
-
|
|
1164
|
+
const removeAttributes = input => {
|
|
1165
|
+
for (let i = 0; i < input.attributes.length; i++) {
|
|
1166
|
+
const attrName = input.attributes[i].name;
|
|
1386
1167
|
if (!['id', 'type', 'value', 'style'].includes(attrName)) {
|
|
1387
1168
|
input.removeAttribute(attrName);
|
|
1388
1169
|
}
|
|
@@ -1393,17 +1174,17 @@
|
|
|
1393
1174
|
* @param {InputClass} inputClass
|
|
1394
1175
|
* @param {SweetAlertOptions['inputAttributes']} inputAttributes
|
|
1395
1176
|
*/
|
|
1396
|
-
|
|
1397
|
-
|
|
1177
|
+
const setAttributes = (inputClass, inputAttributes) => {
|
|
1178
|
+
const popup = getPopup();
|
|
1398
1179
|
if (!popup) {
|
|
1399
1180
|
return;
|
|
1400
1181
|
}
|
|
1401
|
-
|
|
1182
|
+
const input = getInput$1(popup, inputClass);
|
|
1402
1183
|
if (!input) {
|
|
1403
1184
|
return;
|
|
1404
1185
|
}
|
|
1405
1186
|
removeAttributes(input);
|
|
1406
|
-
for (
|
|
1187
|
+
for (const attr in inputAttributes) {
|
|
1407
1188
|
input.setAttribute(attr, inputAttributes[attr]);
|
|
1408
1189
|
}
|
|
1409
1190
|
};
|
|
@@ -1411,11 +1192,11 @@
|
|
|
1411
1192
|
/**
|
|
1412
1193
|
* @param {SweetAlertOptions} params
|
|
1413
1194
|
*/
|
|
1414
|
-
|
|
1195
|
+
const setCustomClass = params => {
|
|
1415
1196
|
if (!params.input) {
|
|
1416
1197
|
return;
|
|
1417
1198
|
}
|
|
1418
|
-
|
|
1199
|
+
const inputContainer = getInputContainer(params.input);
|
|
1419
1200
|
if (inputContainer) {
|
|
1420
1201
|
applyCustomClass(inputContainer, params, 'input');
|
|
1421
1202
|
}
|
|
@@ -1425,7 +1206,7 @@
|
|
|
1425
1206
|
* @param {HTMLInputElement | HTMLTextAreaElement} input
|
|
1426
1207
|
* @param {SweetAlertOptions} params
|
|
1427
1208
|
*/
|
|
1428
|
-
|
|
1209
|
+
const setInputPlaceholder = (input, params) => {
|
|
1429
1210
|
if (!input.placeholder && params.inputPlaceholder) {
|
|
1430
1211
|
input.placeholder = params.inputPlaceholder;
|
|
1431
1212
|
}
|
|
@@ -1436,13 +1217,13 @@
|
|
|
1436
1217
|
* @param {Input} prependTo
|
|
1437
1218
|
* @param {SweetAlertOptions} params
|
|
1438
1219
|
*/
|
|
1439
|
-
|
|
1220
|
+
const setInputLabel = (input, prependTo, params) => {
|
|
1440
1221
|
if (params.inputLabel) {
|
|
1441
|
-
|
|
1442
|
-
|
|
1222
|
+
const label = document.createElement('label');
|
|
1223
|
+
const labelClass = swalClasses['input-label'];
|
|
1443
1224
|
label.setAttribute('for', input.id);
|
|
1444
1225
|
label.className = labelClass;
|
|
1445
|
-
if (
|
|
1226
|
+
if (typeof params.customClass === 'object') {
|
|
1446
1227
|
addClass(label, params.customClass.inputLabel);
|
|
1447
1228
|
}
|
|
1448
1229
|
label.innerText = params.inputLabel;
|
|
@@ -1454,8 +1235,8 @@
|
|
|
1454
1235
|
* @param {SweetAlertInput} inputType
|
|
1455
1236
|
* @returns {HTMLElement | undefined}
|
|
1456
1237
|
*/
|
|
1457
|
-
|
|
1458
|
-
|
|
1238
|
+
const getInputContainer = inputType => {
|
|
1239
|
+
const popup = getPopup();
|
|
1459
1240
|
if (!popup) {
|
|
1460
1241
|
return;
|
|
1461
1242
|
}
|
|
@@ -1466,16 +1247,16 @@
|
|
|
1466
1247
|
* @param {HTMLInputElement | HTMLOutputElement | HTMLTextAreaElement} input
|
|
1467
1248
|
* @param {SweetAlertOptions['inputValue']} inputValue
|
|
1468
1249
|
*/
|
|
1469
|
-
|
|
1470
|
-
if (['string', 'number'].includes(
|
|
1471
|
-
input.value =
|
|
1250
|
+
const checkAndSetInputValue = (input, inputValue) => {
|
|
1251
|
+
if (['string', 'number'].includes(typeof inputValue)) {
|
|
1252
|
+
input.value = `${inputValue}`;
|
|
1472
1253
|
} else if (!isPromise(inputValue)) {
|
|
1473
|
-
warn(
|
|
1254
|
+
warn(`Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof inputValue}"`);
|
|
1474
1255
|
}
|
|
1475
1256
|
};
|
|
1476
1257
|
|
|
1477
1258
|
/** @type {Record<SweetAlertInput, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */
|
|
1478
|
-
|
|
1259
|
+
const renderInputType = {};
|
|
1479
1260
|
|
|
1480
1261
|
/**
|
|
1481
1262
|
* @param {HTMLInputElement} input
|
|
@@ -1483,7 +1264,7 @@
|
|
|
1483
1264
|
* @returns {HTMLInputElement}
|
|
1484
1265
|
*/
|
|
1485
1266
|
renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = renderInputType.search = renderInputType.date = renderInputType['datetime-local'] = renderInputType.time = renderInputType.week = renderInputType.month = /** @type {(input: Input | HTMLElement, params: SweetAlertOptions) => Input} */
|
|
1486
|
-
|
|
1267
|
+
(input, params) => {
|
|
1487
1268
|
checkAndSetInputValue(input, params.inputValue);
|
|
1488
1269
|
setInputLabel(input, input, params);
|
|
1489
1270
|
setInputPlaceholder(input, params);
|
|
@@ -1496,7 +1277,7 @@
|
|
|
1496
1277
|
* @param {SweetAlertOptions} params
|
|
1497
1278
|
* @returns {HTMLInputElement}
|
|
1498
1279
|
*/
|
|
1499
|
-
renderInputType.file =
|
|
1280
|
+
renderInputType.file = (input, params) => {
|
|
1500
1281
|
setInputLabel(input, input, params);
|
|
1501
1282
|
setInputPlaceholder(input, params);
|
|
1502
1283
|
return input;
|
|
@@ -1507,9 +1288,9 @@
|
|
|
1507
1288
|
* @param {SweetAlertOptions} params
|
|
1508
1289
|
* @returns {HTMLInputElement}
|
|
1509
1290
|
*/
|
|
1510
|
-
renderInputType.range =
|
|
1511
|
-
|
|
1512
|
-
|
|
1291
|
+
renderInputType.range = (range, params) => {
|
|
1292
|
+
const rangeInput = range.querySelector('input');
|
|
1293
|
+
const rangeOutput = range.querySelector('output');
|
|
1513
1294
|
checkAndSetInputValue(rangeInput, params.inputValue);
|
|
1514
1295
|
rangeInput.type = params.input;
|
|
1515
1296
|
checkAndSetInputValue(rangeOutput, params.inputValue);
|
|
@@ -1522,10 +1303,10 @@
|
|
|
1522
1303
|
* @param {SweetAlertOptions} params
|
|
1523
1304
|
* @returns {HTMLSelectElement}
|
|
1524
1305
|
*/
|
|
1525
|
-
renderInputType.select =
|
|
1306
|
+
renderInputType.select = (select, params) => {
|
|
1526
1307
|
select.textContent = '';
|
|
1527
1308
|
if (params.inputPlaceholder) {
|
|
1528
|
-
|
|
1309
|
+
const placeholder = document.createElement('option');
|
|
1529
1310
|
setInnerHtml(placeholder, params.inputPlaceholder);
|
|
1530
1311
|
placeholder.value = '';
|
|
1531
1312
|
placeholder.disabled = true;
|
|
@@ -1540,7 +1321,7 @@
|
|
|
1540
1321
|
* @param {HTMLInputElement} radio
|
|
1541
1322
|
* @returns {HTMLInputElement}
|
|
1542
1323
|
*/
|
|
1543
|
-
renderInputType.radio =
|
|
1324
|
+
renderInputType.radio = radio => {
|
|
1544
1325
|
radio.textContent = '';
|
|
1545
1326
|
return radio;
|
|
1546
1327
|
};
|
|
@@ -1550,11 +1331,11 @@
|
|
|
1550
1331
|
* @param {SweetAlertOptions} params
|
|
1551
1332
|
* @returns {HTMLInputElement}
|
|
1552
1333
|
*/
|
|
1553
|
-
renderInputType.checkbox =
|
|
1554
|
-
|
|
1334
|
+
renderInputType.checkbox = (checkboxContainer, params) => {
|
|
1335
|
+
const checkbox = getInput$1(getPopup(), 'checkbox');
|
|
1555
1336
|
checkbox.value = '1';
|
|
1556
1337
|
checkbox.checked = Boolean(params.inputValue);
|
|
1557
|
-
|
|
1338
|
+
const label = checkboxContainer.querySelector('span');
|
|
1558
1339
|
setInnerHtml(label, params.inputPlaceholder);
|
|
1559
1340
|
return checkbox;
|
|
1560
1341
|
};
|
|
@@ -1564,7 +1345,7 @@
|
|
|
1564
1345
|
* @param {SweetAlertOptions} params
|
|
1565
1346
|
* @returns {HTMLTextAreaElement}
|
|
1566
1347
|
*/
|
|
1567
|
-
renderInputType.textarea =
|
|
1348
|
+
renderInputType.textarea = (textarea, params) => {
|
|
1568
1349
|
checkAndSetInputValue(textarea, params.inputValue);
|
|
1569
1350
|
setInputPlaceholder(textarea, params);
|
|
1570
1351
|
setInputLabel(textarea, textarea, params);
|
|
@@ -1573,23 +1354,21 @@
|
|
|
1573
1354
|
* @param {HTMLElement} el
|
|
1574
1355
|
* @returns {number}
|
|
1575
1356
|
*/
|
|
1576
|
-
|
|
1577
|
-
return parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight);
|
|
1578
|
-
};
|
|
1357
|
+
const getMargin = el => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight);
|
|
1579
1358
|
|
|
1580
1359
|
// https://github.com/sweetalert2/sweetalert2/issues/2291
|
|
1581
|
-
setTimeout(
|
|
1360
|
+
setTimeout(() => {
|
|
1582
1361
|
// https://github.com/sweetalert2/sweetalert2/issues/1699
|
|
1583
1362
|
if ('MutationObserver' in window) {
|
|
1584
|
-
|
|
1585
|
-
|
|
1363
|
+
const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
|
|
1364
|
+
const textareaResizeHandler = () => {
|
|
1586
1365
|
// check if texarea is still in document (i.e. popup wasn't closed in the meantime)
|
|
1587
1366
|
if (!document.body.contains(textarea)) {
|
|
1588
1367
|
return;
|
|
1589
1368
|
}
|
|
1590
|
-
|
|
1369
|
+
const textareaWidth = textarea.offsetWidth + getMargin(textarea);
|
|
1591
1370
|
if (textareaWidth > initialPopupWidth) {
|
|
1592
|
-
getPopup().style.width =
|
|
1371
|
+
getPopup().style.width = `${textareaWidth}px`;
|
|
1593
1372
|
} else {
|
|
1594
1373
|
applyNumericalStyle(getPopup(), 'width', params.width);
|
|
1595
1374
|
}
|
|
@@ -1607,8 +1386,8 @@
|
|
|
1607
1386
|
* @param {SweetAlert} instance
|
|
1608
1387
|
* @param {SweetAlertOptions} params
|
|
1609
1388
|
*/
|
|
1610
|
-
|
|
1611
|
-
|
|
1389
|
+
const renderContent = (instance, params) => {
|
|
1390
|
+
const htmlContainer = getHtmlContainer();
|
|
1612
1391
|
if (!htmlContainer) {
|
|
1613
1392
|
return;
|
|
1614
1393
|
}
|
|
@@ -1638,8 +1417,8 @@
|
|
|
1638
1417
|
* @param {SweetAlert} instance
|
|
1639
1418
|
* @param {SweetAlertOptions} params
|
|
1640
1419
|
*/
|
|
1641
|
-
|
|
1642
|
-
|
|
1420
|
+
const renderFooter = (instance, params) => {
|
|
1421
|
+
const footer = getFooter();
|
|
1643
1422
|
if (!footer) {
|
|
1644
1423
|
return;
|
|
1645
1424
|
}
|
|
@@ -1657,9 +1436,9 @@
|
|
|
1657
1436
|
* @param {SweetAlert} instance
|
|
1658
1437
|
* @param {SweetAlertOptions} params
|
|
1659
1438
|
*/
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1439
|
+
const renderIcon = (instance, params) => {
|
|
1440
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
1441
|
+
const icon = getIcon();
|
|
1663
1442
|
if (!icon) {
|
|
1664
1443
|
return;
|
|
1665
1444
|
}
|
|
@@ -1676,7 +1455,7 @@
|
|
|
1676
1455
|
return;
|
|
1677
1456
|
}
|
|
1678
1457
|
if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) {
|
|
1679
|
-
error(
|
|
1458
|
+
error(`Unknown icon! Expected "success", "error", "warning", "info" or "question", got "${params.icon}"`);
|
|
1680
1459
|
hide(icon);
|
|
1681
1460
|
return;
|
|
1682
1461
|
}
|
|
@@ -1694,11 +1473,8 @@
|
|
|
1694
1473
|
* @param {HTMLElement} icon
|
|
1695
1474
|
* @param {SweetAlertOptions} params
|
|
1696
1475
|
*/
|
|
1697
|
-
|
|
1698
|
-
for (
|
|
1699
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1700
|
-
iconType = _Object$entries$_i[0],
|
|
1701
|
-
iconClassName = _Object$entries$_i[1];
|
|
1476
|
+
const applyStyles = (icon, params) => {
|
|
1477
|
+
for (const [iconType, iconClassName] of Object.entries(iconTypes)) {
|
|
1702
1478
|
if (params.icon !== iconType) {
|
|
1703
1479
|
removeClass(icon, iconClassName);
|
|
1704
1480
|
}
|
|
@@ -1716,31 +1492,41 @@
|
|
|
1716
1492
|
};
|
|
1717
1493
|
|
|
1718
1494
|
// Adjust success icon background color to match the popup background color
|
|
1719
|
-
|
|
1720
|
-
|
|
1495
|
+
const adjustSuccessIconBackgroundColor = () => {
|
|
1496
|
+
const popup = getPopup();
|
|
1721
1497
|
if (!popup) {
|
|
1722
1498
|
return;
|
|
1723
1499
|
}
|
|
1724
|
-
|
|
1500
|
+
const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
|
|
1725
1501
|
/** @type {NodeListOf<HTMLElement>} */
|
|
1726
|
-
|
|
1727
|
-
for (
|
|
1502
|
+
const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
|
|
1503
|
+
for (let i = 0; i < successIconParts.length; i++) {
|
|
1728
1504
|
successIconParts[i].style.backgroundColor = popupBackgroundColor;
|
|
1729
1505
|
}
|
|
1730
1506
|
};
|
|
1731
|
-
|
|
1732
|
-
|
|
1507
|
+
const successIconHtml = `
|
|
1508
|
+
<div class="swal2-success-circular-line-left"></div>
|
|
1509
|
+
<span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>
|
|
1510
|
+
<div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>
|
|
1511
|
+
<div class="swal2-success-circular-line-right"></div>
|
|
1512
|
+
`;
|
|
1513
|
+
const errorIconHtml = `
|
|
1514
|
+
<span class="swal2-x-mark">
|
|
1515
|
+
<span class="swal2-x-mark-line-left"></span>
|
|
1516
|
+
<span class="swal2-x-mark-line-right"></span>
|
|
1517
|
+
</span>
|
|
1518
|
+
`;
|
|
1733
1519
|
|
|
1734
1520
|
/**
|
|
1735
1521
|
* @param {HTMLElement} icon
|
|
1736
1522
|
* @param {SweetAlertOptions} params
|
|
1737
1523
|
*/
|
|
1738
|
-
|
|
1524
|
+
const setContent = (icon, params) => {
|
|
1739
1525
|
if (!params.icon && !params.iconHtml) {
|
|
1740
1526
|
return;
|
|
1741
1527
|
}
|
|
1742
|
-
|
|
1743
|
-
|
|
1528
|
+
let oldContent = icon.innerHTML;
|
|
1529
|
+
let newContent = '';
|
|
1744
1530
|
if (params.iconHtml) {
|
|
1745
1531
|
newContent = iconContent(params.iconHtml);
|
|
1746
1532
|
} else if (params.icon === 'success') {
|
|
@@ -1749,7 +1535,7 @@
|
|
|
1749
1535
|
} else if (params.icon === 'error') {
|
|
1750
1536
|
newContent = errorIconHtml;
|
|
1751
1537
|
} else if (params.icon) {
|
|
1752
|
-
|
|
1538
|
+
const defaultIconHtml = {
|
|
1753
1539
|
question: '?',
|
|
1754
1540
|
warning: '!',
|
|
1755
1541
|
info: 'i'
|
|
@@ -1765,14 +1551,13 @@
|
|
|
1765
1551
|
* @param {HTMLElement} icon
|
|
1766
1552
|
* @param {SweetAlertOptions} params
|
|
1767
1553
|
*/
|
|
1768
|
-
|
|
1554
|
+
const setColor = (icon, params) => {
|
|
1769
1555
|
if (!params.iconColor) {
|
|
1770
1556
|
return;
|
|
1771
1557
|
}
|
|
1772
1558
|
icon.style.color = params.iconColor;
|
|
1773
1559
|
icon.style.borderColor = params.iconColor;
|
|
1774
|
-
for (
|
|
1775
|
-
var sel = _arr[_i2];
|
|
1560
|
+
for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) {
|
|
1776
1561
|
setStyle(icon, sel, 'background-color', params.iconColor);
|
|
1777
1562
|
}
|
|
1778
1563
|
setStyle(icon, '.swal2-success-ring', 'border-color', params.iconColor);
|
|
@@ -1782,16 +1567,14 @@
|
|
|
1782
1567
|
* @param {string} content
|
|
1783
1568
|
* @returns {string}
|
|
1784
1569
|
*/
|
|
1785
|
-
|
|
1786
|
-
return "<div class=\"".concat(swalClasses['icon-content'], "\">").concat(content, "</div>");
|
|
1787
|
-
};
|
|
1570
|
+
const iconContent = content => `<div class="${swalClasses['icon-content']}">${content}</div>`;
|
|
1788
1571
|
|
|
1789
1572
|
/**
|
|
1790
1573
|
* @param {SweetAlert} instance
|
|
1791
1574
|
* @param {SweetAlertOptions} params
|
|
1792
1575
|
*/
|
|
1793
|
-
|
|
1794
|
-
|
|
1576
|
+
const renderImage = (instance, params) => {
|
|
1577
|
+
const image = getImage();
|
|
1795
1578
|
if (!image) {
|
|
1796
1579
|
return;
|
|
1797
1580
|
}
|
|
@@ -1818,9 +1601,9 @@
|
|
|
1818
1601
|
* @param {SweetAlert} instance
|
|
1819
1602
|
* @param {SweetAlertOptions} params
|
|
1820
1603
|
*/
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1604
|
+
const renderPopup = (instance, params) => {
|
|
1605
|
+
const container = getContainer();
|
|
1606
|
+
const popup = getPopup();
|
|
1824
1607
|
if (!container || !popup) {
|
|
1825
1608
|
return;
|
|
1826
1609
|
}
|
|
@@ -1830,7 +1613,7 @@
|
|
|
1830
1613
|
if (params.toast) {
|
|
1831
1614
|
applyNumericalStyle(container, 'width', params.width);
|
|
1832
1615
|
popup.style.width = '100%';
|
|
1833
|
-
|
|
1616
|
+
const loader = getLoader();
|
|
1834
1617
|
if (loader) {
|
|
1835
1618
|
popup.insertBefore(loader, getIcon());
|
|
1836
1619
|
}
|
|
@@ -1860,10 +1643,10 @@
|
|
|
1860
1643
|
* @param {HTMLElement} popup
|
|
1861
1644
|
* @param {SweetAlertOptions} params
|
|
1862
1645
|
*/
|
|
1863
|
-
|
|
1864
|
-
|
|
1646
|
+
const addClasses$1 = (popup, params) => {
|
|
1647
|
+
const showClass = params.showClass || {};
|
|
1865
1648
|
// Default Class + showClass when updating Swal.update({})
|
|
1866
|
-
popup.className =
|
|
1649
|
+
popup.className = `${swalClasses.popup} ${isVisible$1(popup) ? showClass.popup : ''}`;
|
|
1867
1650
|
if (params.toast) {
|
|
1868
1651
|
addClass([document.documentElement, document.body], swalClasses['toast-shown']);
|
|
1869
1652
|
addClass(popup, swalClasses.toast);
|
|
@@ -1880,7 +1663,7 @@
|
|
|
1880
1663
|
|
|
1881
1664
|
// Icon class (#1842)
|
|
1882
1665
|
if (params.icon) {
|
|
1883
|
-
addClass(popup, swalClasses[
|
|
1666
|
+
addClass(popup, swalClasses[`icon-${params.icon}`]);
|
|
1884
1667
|
}
|
|
1885
1668
|
};
|
|
1886
1669
|
|
|
@@ -1888,13 +1671,15 @@
|
|
|
1888
1671
|
* @param {SweetAlert} instance
|
|
1889
1672
|
* @param {SweetAlertOptions} params
|
|
1890
1673
|
*/
|
|
1891
|
-
|
|
1892
|
-
|
|
1674
|
+
const renderProgressSteps = (instance, params) => {
|
|
1675
|
+
const progressStepsContainer = getProgressSteps();
|
|
1893
1676
|
if (!progressStepsContainer) {
|
|
1894
1677
|
return;
|
|
1895
1678
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1679
|
+
const {
|
|
1680
|
+
progressSteps,
|
|
1681
|
+
currentProgressStep
|
|
1682
|
+
} = params;
|
|
1898
1683
|
if (!progressSteps || progressSteps.length === 0 || currentProgressStep === undefined) {
|
|
1899
1684
|
hide(progressStepsContainer);
|
|
1900
1685
|
return;
|
|
@@ -1904,14 +1689,14 @@
|
|
|
1904
1689
|
if (currentProgressStep >= progressSteps.length) {
|
|
1905
1690
|
warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
|
|
1906
1691
|
}
|
|
1907
|
-
progressSteps.forEach(
|
|
1908
|
-
|
|
1692
|
+
progressSteps.forEach((step, index) => {
|
|
1693
|
+
const stepEl = createStepElement(step);
|
|
1909
1694
|
progressStepsContainer.appendChild(stepEl);
|
|
1910
1695
|
if (index === currentProgressStep) {
|
|
1911
1696
|
addClass(stepEl, swalClasses['active-progress-step']);
|
|
1912
1697
|
}
|
|
1913
1698
|
if (index !== progressSteps.length - 1) {
|
|
1914
|
-
|
|
1699
|
+
const lineEl = createLineElement(params);
|
|
1915
1700
|
progressStepsContainer.appendChild(lineEl);
|
|
1916
1701
|
}
|
|
1917
1702
|
});
|
|
@@ -1921,8 +1706,8 @@
|
|
|
1921
1706
|
* @param {string} step
|
|
1922
1707
|
* @returns {HTMLLIElement}
|
|
1923
1708
|
*/
|
|
1924
|
-
|
|
1925
|
-
|
|
1709
|
+
const createStepElement = step => {
|
|
1710
|
+
const stepEl = document.createElement('li');
|
|
1926
1711
|
addClass(stepEl, swalClasses['progress-step']);
|
|
1927
1712
|
setInnerHtml(stepEl, step);
|
|
1928
1713
|
return stepEl;
|
|
@@ -1932,8 +1717,8 @@
|
|
|
1932
1717
|
* @param {SweetAlertOptions} params
|
|
1933
1718
|
* @returns {HTMLLIElement}
|
|
1934
1719
|
*/
|
|
1935
|
-
|
|
1936
|
-
|
|
1720
|
+
const createLineElement = params => {
|
|
1721
|
+
const lineEl = document.createElement('li');
|
|
1937
1722
|
addClass(lineEl, swalClasses['progress-step-line']);
|
|
1938
1723
|
if (params.progressStepsDistance) {
|
|
1939
1724
|
applyNumericalStyle(lineEl, 'width', params.progressStepsDistance);
|
|
@@ -1945,8 +1730,8 @@
|
|
|
1945
1730
|
* @param {SweetAlert} instance
|
|
1946
1731
|
* @param {SweetAlertOptions} params
|
|
1947
1732
|
*/
|
|
1948
|
-
|
|
1949
|
-
|
|
1733
|
+
const renderTitle = (instance, params) => {
|
|
1734
|
+
const title = getTitle();
|
|
1950
1735
|
if (!title) {
|
|
1951
1736
|
return;
|
|
1952
1737
|
}
|
|
@@ -1967,7 +1752,7 @@
|
|
|
1967
1752
|
* @param {SweetAlert} instance
|
|
1968
1753
|
* @param {SweetAlertOptions} params
|
|
1969
1754
|
*/
|
|
1970
|
-
|
|
1755
|
+
const render = (instance, params) => {
|
|
1971
1756
|
renderPopup(instance, params);
|
|
1972
1757
|
renderContainer(instance, params);
|
|
1973
1758
|
renderProgressSteps(instance, params);
|
|
@@ -1978,7 +1763,7 @@
|
|
|
1978
1763
|
renderContent(instance, params);
|
|
1979
1764
|
renderActions(instance, params);
|
|
1980
1765
|
renderFooter(instance, params);
|
|
1981
|
-
|
|
1766
|
+
const popup = getPopup();
|
|
1982
1767
|
if (typeof params.didRender === 'function' && popup) {
|
|
1983
1768
|
params.didRender(popup);
|
|
1984
1769
|
}
|
|
@@ -1987,14 +1772,14 @@
|
|
|
1987
1772
|
/*
|
|
1988
1773
|
* Global function to determine if SweetAlert2 popup is shown
|
|
1989
1774
|
*/
|
|
1990
|
-
|
|
1775
|
+
const isVisible = () => {
|
|
1991
1776
|
return isVisible$1(getPopup());
|
|
1992
1777
|
};
|
|
1993
1778
|
|
|
1994
1779
|
/*
|
|
1995
1780
|
* Global function to click 'Confirm' button
|
|
1996
1781
|
*/
|
|
1997
|
-
|
|
1782
|
+
const clickConfirm = () => {
|
|
1998
1783
|
var _dom$getConfirmButton;
|
|
1999
1784
|
return (_dom$getConfirmButton = getConfirmButton()) === null || _dom$getConfirmButton === void 0 ? void 0 : _dom$getConfirmButton.click();
|
|
2000
1785
|
};
|
|
@@ -2002,7 +1787,7 @@
|
|
|
2002
1787
|
/*
|
|
2003
1788
|
* Global function to click 'Deny' button
|
|
2004
1789
|
*/
|
|
2005
|
-
|
|
1790
|
+
const clickDeny = () => {
|
|
2006
1791
|
var _dom$getDenyButton;
|
|
2007
1792
|
return (_dom$getDenyButton = getDenyButton()) === null || _dom$getDenyButton === void 0 ? void 0 : _dom$getDenyButton.click();
|
|
2008
1793
|
};
|
|
@@ -2010,7 +1795,7 @@
|
|
|
2010
1795
|
/*
|
|
2011
1796
|
* Global function to click 'Cancel' button
|
|
2012
1797
|
*/
|
|
2013
|
-
|
|
1798
|
+
const clickCancel = () => {
|
|
2014
1799
|
var _dom$getCancelButton;
|
|
2015
1800
|
return (_dom$getCancelButton = getCancelButton()) === null || _dom$getCancelButton === void 0 ? void 0 : _dom$getCancelButton.click();
|
|
2016
1801
|
};
|
|
@@ -2018,7 +1803,7 @@
|
|
|
2018
1803
|
/** @typedef {'cancel' | 'backdrop' | 'close' | 'esc' | 'timer'} DismissReason */
|
|
2019
1804
|
|
|
2020
1805
|
/** @type {Record<DismissReason, DismissReason>} */
|
|
2021
|
-
|
|
1806
|
+
const DismissReason = Object.freeze({
|
|
2022
1807
|
cancel: 'cancel',
|
|
2023
1808
|
backdrop: 'backdrop',
|
|
2024
1809
|
close: 'close',
|
|
@@ -2029,7 +1814,7 @@
|
|
|
2029
1814
|
/**
|
|
2030
1815
|
* @param {GlobalState} globalState
|
|
2031
1816
|
*/
|
|
2032
|
-
|
|
1817
|
+
const removeKeydownHandler = globalState => {
|
|
2033
1818
|
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
|
|
2034
1819
|
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
2035
1820
|
capture: globalState.keydownListenerCapture
|
|
@@ -2043,12 +1828,10 @@
|
|
|
2043
1828
|
* @param {SweetAlertOptions} innerParams
|
|
2044
1829
|
* @param {*} dismissWith
|
|
2045
1830
|
*/
|
|
2046
|
-
|
|
1831
|
+
const addKeydownHandler = (globalState, innerParams, dismissWith) => {
|
|
2047
1832
|
removeKeydownHandler(globalState);
|
|
2048
1833
|
if (!innerParams.toast) {
|
|
2049
|
-
globalState.keydownHandler =
|
|
2050
|
-
return keydownHandler(innerParams, e, dismissWith);
|
|
2051
|
-
};
|
|
1834
|
+
globalState.keydownHandler = e => keydownHandler(innerParams, e, dismissWith);
|
|
2052
1835
|
globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
|
|
2053
1836
|
globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
|
|
2054
1837
|
globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
|
|
@@ -2062,9 +1845,9 @@
|
|
|
2062
1845
|
* @param {number} index
|
|
2063
1846
|
* @param {number} increment
|
|
2064
1847
|
*/
|
|
2065
|
-
|
|
1848
|
+
const setFocus = (index, increment) => {
|
|
2066
1849
|
var _dom$getPopup;
|
|
2067
|
-
|
|
1850
|
+
const focusableElements = getFocusableElements();
|
|
2068
1851
|
// search for visible elements and select the next possible match
|
|
2069
1852
|
if (focusableElements.length) {
|
|
2070
1853
|
index = index + increment;
|
|
@@ -2083,15 +1866,15 @@
|
|
|
2083
1866
|
// no visible focusable elements, focus the popup
|
|
2084
1867
|
(_dom$getPopup = getPopup()) === null || _dom$getPopup === void 0 || _dom$getPopup.focus();
|
|
2085
1868
|
};
|
|
2086
|
-
|
|
2087
|
-
|
|
1869
|
+
const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
|
|
1870
|
+
const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
|
|
2088
1871
|
|
|
2089
1872
|
/**
|
|
2090
1873
|
* @param {SweetAlertOptions} innerParams
|
|
2091
1874
|
* @param {KeyboardEvent} event
|
|
2092
1875
|
* @param {Function} dismissWith
|
|
2093
1876
|
*/
|
|
2094
|
-
|
|
1877
|
+
const keydownHandler = (innerParams, event, dismissWith) => {
|
|
2095
1878
|
if (!innerParams) {
|
|
2096
1879
|
return; // This instance has already been destroyed
|
|
2097
1880
|
}
|
|
@@ -2118,7 +1901,7 @@
|
|
|
2118
1901
|
}
|
|
2119
1902
|
|
|
2120
1903
|
// ARROWS - switch focus between buttons
|
|
2121
|
-
else if ([
|
|
1904
|
+
else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(event.key)) {
|
|
2122
1905
|
handleArrows(event.key);
|
|
2123
1906
|
}
|
|
2124
1907
|
|
|
@@ -2132,12 +1915,12 @@
|
|
|
2132
1915
|
* @param {KeyboardEvent} event
|
|
2133
1916
|
* @param {SweetAlertOptions} innerParams
|
|
2134
1917
|
*/
|
|
2135
|
-
|
|
1918
|
+
const handleEnter = (event, innerParams) => {
|
|
2136
1919
|
// https://github.com/sweetalert2/sweetalert2/issues/2386
|
|
2137
1920
|
if (!callIfFunction(innerParams.allowEnterKey)) {
|
|
2138
1921
|
return;
|
|
2139
1922
|
}
|
|
2140
|
-
|
|
1923
|
+
const input = getInput$1(getPopup(), innerParams.input);
|
|
2141
1924
|
if (event.target && input && event.target instanceof HTMLElement && event.target.outerHTML === input.outerHTML) {
|
|
2142
1925
|
if (['textarea', 'file'].includes(innerParams.input)) {
|
|
2143
1926
|
return; // do not submit
|
|
@@ -2150,11 +1933,11 @@
|
|
|
2150
1933
|
/**
|
|
2151
1934
|
* @param {KeyboardEvent} event
|
|
2152
1935
|
*/
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
for (
|
|
1936
|
+
const handleTab = event => {
|
|
1937
|
+
const targetElement = event.target;
|
|
1938
|
+
const focusableElements = getFocusableElements();
|
|
1939
|
+
let btnIndex = -1;
|
|
1940
|
+
for (let i = 0; i < focusableElements.length; i++) {
|
|
2158
1941
|
if (targetElement === focusableElements[i]) {
|
|
2159
1942
|
btnIndex = i;
|
|
2160
1943
|
break;
|
|
@@ -2177,25 +1960,25 @@
|
|
|
2177
1960
|
/**
|
|
2178
1961
|
* @param {string} key
|
|
2179
1962
|
*/
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
1963
|
+
const handleArrows = key => {
|
|
1964
|
+
const actions = getActions();
|
|
1965
|
+
const confirmButton = getConfirmButton();
|
|
1966
|
+
const denyButton = getDenyButton();
|
|
1967
|
+
const cancelButton = getCancelButton();
|
|
2185
1968
|
if (!actions || !confirmButton || !denyButton || !cancelButton) {
|
|
2186
1969
|
return;
|
|
2187
1970
|
}
|
|
2188
1971
|
/** @type HTMLElement[] */
|
|
2189
|
-
|
|
1972
|
+
const buttons = [confirmButton, denyButton, cancelButton];
|
|
2190
1973
|
if (document.activeElement instanceof HTMLElement && !buttons.includes(document.activeElement)) {
|
|
2191
1974
|
return;
|
|
2192
1975
|
}
|
|
2193
|
-
|
|
2194
|
-
|
|
1976
|
+
const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
|
|
1977
|
+
let buttonToFocus = document.activeElement;
|
|
2195
1978
|
if (!buttonToFocus) {
|
|
2196
1979
|
return;
|
|
2197
1980
|
}
|
|
2198
|
-
for (
|
|
1981
|
+
for (let i = 0; i < actions.children.length; i++) {
|
|
2199
1982
|
buttonToFocus = buttonToFocus[sibling];
|
|
2200
1983
|
if (!buttonToFocus) {
|
|
2201
1984
|
return;
|
|
@@ -2214,7 +1997,7 @@
|
|
|
2214
1997
|
* @param {SweetAlertOptions} innerParams
|
|
2215
1998
|
* @param {Function} dismissWith
|
|
2216
1999
|
*/
|
|
2217
|
-
|
|
2000
|
+
const handleEsc = (event, innerParams, dismissWith) => {
|
|
2218
2001
|
if (callIfFunction(innerParams.allowEscapeKey)) {
|
|
2219
2002
|
event.preventDefault();
|
|
2220
2003
|
dismissWith(DismissReason.esc);
|
|
@@ -2241,10 +2024,10 @@
|
|
|
2241
2024
|
// elements not within the active modal dialog will not be surfaced if a user opens a screen
|
|
2242
2025
|
// reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
|
|
2243
2026
|
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
bodyChildren.forEach(
|
|
2027
|
+
const setAriaHidden = () => {
|
|
2028
|
+
const container = getContainer();
|
|
2029
|
+
const bodyChildren = Array.from(document.body.children);
|
|
2030
|
+
bodyChildren.forEach(el => {
|
|
2248
2031
|
if (el.contains(container)) {
|
|
2249
2032
|
return;
|
|
2250
2033
|
}
|
|
@@ -2254,9 +2037,9 @@
|
|
|
2254
2037
|
el.setAttribute('aria-hidden', 'true');
|
|
2255
2038
|
});
|
|
2256
2039
|
};
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
bodyChildren.forEach(
|
|
2040
|
+
const unsetAriaHidden = () => {
|
|
2041
|
+
const bodyChildren = Array.from(document.body.children);
|
|
2042
|
+
bodyChildren.forEach(el => {
|
|
2260
2043
|
if (el.hasAttribute('data-previous-aria-hidden')) {
|
|
2261
2044
|
el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden') || '');
|
|
2262
2045
|
el.removeAttribute('data-previous-aria-hidden');
|
|
@@ -2267,16 +2050,16 @@
|
|
|
2267
2050
|
};
|
|
2268
2051
|
|
|
2269
2052
|
// @ts-ignore
|
|
2270
|
-
|
|
2053
|
+
const isSafariOrIOS = typeof window !== 'undefined' && !!window.GestureEvent; // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394
|
|
2271
2054
|
|
|
2272
2055
|
/**
|
|
2273
2056
|
* Fix iOS scrolling
|
|
2274
2057
|
* http://stackoverflow.com/q/39626302
|
|
2275
2058
|
*/
|
|
2276
|
-
|
|
2059
|
+
const iOSfix = () => {
|
|
2277
2060
|
if (isSafariOrIOS && !hasClass(document.body, swalClasses.iosfix)) {
|
|
2278
|
-
|
|
2279
|
-
document.body.style.top =
|
|
2061
|
+
const offset = document.body.scrollTop;
|
|
2062
|
+
document.body.style.top = `${offset * -1}px`;
|
|
2280
2063
|
addClass(document.body, swalClasses.iosfix);
|
|
2281
2064
|
lockBodyScroll();
|
|
2282
2065
|
}
|
|
@@ -2285,23 +2068,23 @@
|
|
|
2285
2068
|
/**
|
|
2286
2069
|
* https://github.com/sweetalert2/sweetalert2/issues/1246
|
|
2287
2070
|
*/
|
|
2288
|
-
|
|
2289
|
-
|
|
2071
|
+
const lockBodyScroll = () => {
|
|
2072
|
+
const container = getContainer();
|
|
2290
2073
|
if (!container) {
|
|
2291
2074
|
return;
|
|
2292
2075
|
}
|
|
2293
2076
|
/** @type {boolean} */
|
|
2294
|
-
|
|
2077
|
+
let preventTouchMove;
|
|
2295
2078
|
/**
|
|
2296
2079
|
* @param {TouchEvent} event
|
|
2297
2080
|
*/
|
|
2298
|
-
container.ontouchstart =
|
|
2081
|
+
container.ontouchstart = event => {
|
|
2299
2082
|
preventTouchMove = shouldPreventTouchMove(event);
|
|
2300
2083
|
};
|
|
2301
2084
|
/**
|
|
2302
2085
|
* @param {TouchEvent} event
|
|
2303
2086
|
*/
|
|
2304
|
-
container.ontouchmove =
|
|
2087
|
+
container.ontouchmove = event => {
|
|
2305
2088
|
if (preventTouchMove) {
|
|
2306
2089
|
event.preventDefault();
|
|
2307
2090
|
event.stopPropagation();
|
|
@@ -2313,10 +2096,10 @@
|
|
|
2313
2096
|
* @param {TouchEvent} event
|
|
2314
2097
|
* @returns {boolean}
|
|
2315
2098
|
*/
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2099
|
+
const shouldPreventTouchMove = event => {
|
|
2100
|
+
const target = event.target;
|
|
2101
|
+
const container = getContainer();
|
|
2102
|
+
const htmlContainer = getHtmlContainer();
|
|
2320
2103
|
if (!container || !htmlContainer) {
|
|
2321
2104
|
return false;
|
|
2322
2105
|
}
|
|
@@ -2344,7 +2127,7 @@
|
|
|
2344
2127
|
* @param {*} event
|
|
2345
2128
|
* @returns {boolean}
|
|
2346
2129
|
*/
|
|
2347
|
-
|
|
2130
|
+
const isStylus = event => {
|
|
2348
2131
|
return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
|
|
2349
2132
|
};
|
|
2350
2133
|
|
|
@@ -2354,12 +2137,12 @@
|
|
|
2354
2137
|
* @param {TouchEvent} event
|
|
2355
2138
|
* @returns {boolean}
|
|
2356
2139
|
*/
|
|
2357
|
-
|
|
2140
|
+
const isZoom = event => {
|
|
2358
2141
|
return event.touches && event.touches.length > 1;
|
|
2359
2142
|
};
|
|
2360
|
-
|
|
2143
|
+
const undoIOSfix = () => {
|
|
2361
2144
|
if (hasClass(document.body, swalClasses.iosfix)) {
|
|
2362
|
-
|
|
2145
|
+
const offset = parseInt(document.body.style.top, 10);
|
|
2363
2146
|
removeClass(document.body, swalClasses.iosfix);
|
|
2364
2147
|
document.body.style.top = '';
|
|
2365
2148
|
document.body.scrollTop = offset * -1;
|
|
@@ -2372,11 +2155,11 @@
|
|
|
2372
2155
|
*
|
|
2373
2156
|
* @returns {number}
|
|
2374
2157
|
*/
|
|
2375
|
-
|
|
2376
|
-
|
|
2158
|
+
const measureScrollbar = () => {
|
|
2159
|
+
const scrollDiv = document.createElement('div');
|
|
2377
2160
|
scrollDiv.className = swalClasses['scrollbar-measure'];
|
|
2378
2161
|
document.body.appendChild(scrollDiv);
|
|
2379
|
-
|
|
2162
|
+
const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
|
|
2380
2163
|
document.body.removeChild(scrollDiv);
|
|
2381
2164
|
return scrollbarWidth;
|
|
2382
2165
|
};
|
|
@@ -2385,12 +2168,12 @@
|
|
|
2385
2168
|
* Remember state in cases where opening and handling a modal will fiddle with it.
|
|
2386
2169
|
* @type {number | null}
|
|
2387
2170
|
*/
|
|
2388
|
-
|
|
2171
|
+
let previousBodyPadding = null;
|
|
2389
2172
|
|
|
2390
2173
|
/**
|
|
2391
2174
|
* @param {string} initialBodyOverflow
|
|
2392
2175
|
*/
|
|
2393
|
-
|
|
2176
|
+
const replaceScrollbarWithPadding = initialBodyOverflow => {
|
|
2394
2177
|
// for queues, do not do this more than once
|
|
2395
2178
|
if (previousBodyPadding !== null) {
|
|
2396
2179
|
return;
|
|
@@ -2400,12 +2183,12 @@
|
|
|
2400
2183
|
) {
|
|
2401
2184
|
// add padding so the content doesn't shift after removal of scrollbar
|
|
2402
2185
|
previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
|
|
2403
|
-
document.body.style.paddingRight =
|
|
2186
|
+
document.body.style.paddingRight = `${previousBodyPadding + measureScrollbar()}px`;
|
|
2404
2187
|
}
|
|
2405
2188
|
};
|
|
2406
|
-
|
|
2189
|
+
const undoReplaceScrollbarWithPadding = () => {
|
|
2407
2190
|
if (previousBodyPadding !== null) {
|
|
2408
|
-
document.body.style.paddingRight =
|
|
2191
|
+
document.body.style.paddingRight = `${previousBodyPadding}px`;
|
|
2409
2192
|
previousBodyPadding = null;
|
|
2410
2193
|
}
|
|
2411
2194
|
};
|
|
@@ -2420,9 +2203,7 @@
|
|
|
2420
2203
|
if (isToast()) {
|
|
2421
2204
|
triggerDidCloseAndDispose(instance, didClose);
|
|
2422
2205
|
} else {
|
|
2423
|
-
restoreActiveElement(returnFocus).then(
|
|
2424
|
-
return triggerDidCloseAndDispose(instance, didClose);
|
|
2425
|
-
});
|
|
2206
|
+
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
2426
2207
|
removeKeydownHandler(globalState);
|
|
2427
2208
|
}
|
|
2428
2209
|
|
|
@@ -2457,8 +2238,8 @@
|
|
|
2457
2238
|
*/
|
|
2458
2239
|
function close(resolveValue) {
|
|
2459
2240
|
resolveValue = prepareResolveValue(resolveValue);
|
|
2460
|
-
|
|
2461
|
-
|
|
2241
|
+
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
2242
|
+
const didClose = triggerClosePopup(this);
|
|
2462
2243
|
if (this.isAwaitingPromise) {
|
|
2463
2244
|
// A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
|
|
2464
2245
|
if (!resolveValue.isDismissed) {
|
|
@@ -2470,18 +2251,18 @@
|
|
|
2470
2251
|
swalPromiseResolve(resolveValue);
|
|
2471
2252
|
}
|
|
2472
2253
|
}
|
|
2473
|
-
|
|
2474
|
-
|
|
2254
|
+
const triggerClosePopup = instance => {
|
|
2255
|
+
const popup = getPopup();
|
|
2475
2256
|
if (!popup) {
|
|
2476
2257
|
return false;
|
|
2477
2258
|
}
|
|
2478
|
-
|
|
2259
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2479
2260
|
if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
|
|
2480
2261
|
return false;
|
|
2481
2262
|
}
|
|
2482
2263
|
removeClass(popup, innerParams.showClass.popup);
|
|
2483
2264
|
addClass(popup, innerParams.hideClass.popup);
|
|
2484
|
-
|
|
2265
|
+
const backdrop = getContainer();
|
|
2485
2266
|
removeClass(backdrop, innerParams.showClass.backdrop);
|
|
2486
2267
|
addClass(backdrop, innerParams.hideClass.backdrop);
|
|
2487
2268
|
handlePopupAnimation(instance, popup, innerParams);
|
|
@@ -2492,7 +2273,7 @@
|
|
|
2492
2273
|
* @param {any} error
|
|
2493
2274
|
*/
|
|
2494
2275
|
function rejectPromise(error) {
|
|
2495
|
-
|
|
2276
|
+
const rejectPromise = privateMethods.swalPromiseReject.get(this);
|
|
2496
2277
|
handleAwaitingPromise(this);
|
|
2497
2278
|
if (rejectPromise) {
|
|
2498
2279
|
// Reject Swal promise
|
|
@@ -2503,7 +2284,7 @@
|
|
|
2503
2284
|
/**
|
|
2504
2285
|
* @param {SweetAlert} instance
|
|
2505
2286
|
*/
|
|
2506
|
-
|
|
2287
|
+
const handleAwaitingPromise = instance => {
|
|
2507
2288
|
if (instance.isAwaitingPromise) {
|
|
2508
2289
|
delete instance.isAwaitingPromise;
|
|
2509
2290
|
// The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
|
|
@@ -2517,7 +2298,7 @@
|
|
|
2517
2298
|
* @param {any} resolveValue
|
|
2518
2299
|
* @returns {SweetAlertResult}
|
|
2519
2300
|
*/
|
|
2520
|
-
|
|
2301
|
+
const prepareResolveValue = resolveValue => {
|
|
2521
2302
|
// When user calls Swal.close()
|
|
2522
2303
|
if (typeof resolveValue === 'undefined') {
|
|
2523
2304
|
return {
|
|
@@ -2538,10 +2319,10 @@
|
|
|
2538
2319
|
* @param {HTMLElement} popup
|
|
2539
2320
|
* @param {SweetAlertOptions} innerParams
|
|
2540
2321
|
*/
|
|
2541
|
-
|
|
2542
|
-
|
|
2322
|
+
const handlePopupAnimation = (instance, popup, innerParams) => {
|
|
2323
|
+
const container = getContainer();
|
|
2543
2324
|
// If animation is supported, animate
|
|
2544
|
-
|
|
2325
|
+
const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
|
|
2545
2326
|
if (typeof innerParams.willClose === 'function') {
|
|
2546
2327
|
innerParams.willClose(popup);
|
|
2547
2328
|
}
|
|
@@ -2560,7 +2341,7 @@
|
|
|
2560
2341
|
* @param {boolean} returnFocus
|
|
2561
2342
|
* @param {Function} didClose
|
|
2562
2343
|
*/
|
|
2563
|
-
|
|
2344
|
+
const animatePopup = (instance, popup, container, returnFocus, didClose) => {
|
|
2564
2345
|
if (!animationEndEvent) {
|
|
2565
2346
|
return;
|
|
2566
2347
|
}
|
|
@@ -2577,8 +2358,8 @@
|
|
|
2577
2358
|
* @param {SweetAlert} instance
|
|
2578
2359
|
* @param {Function} didClose
|
|
2579
2360
|
*/
|
|
2580
|
-
|
|
2581
|
-
setTimeout(
|
|
2361
|
+
const triggerDidCloseAndDispose = (instance, didClose) => {
|
|
2362
|
+
setTimeout(() => {
|
|
2582
2363
|
if (typeof didClose === 'function') {
|
|
2583
2364
|
didClose.bind(instance.params)();
|
|
2584
2365
|
}
|
|
@@ -2595,8 +2376,8 @@
|
|
|
2595
2376
|
*
|
|
2596
2377
|
* @param {HTMLButtonElement | null} [buttonToReplace]
|
|
2597
2378
|
*/
|
|
2598
|
-
|
|
2599
|
-
|
|
2379
|
+
const showLoading = buttonToReplace => {
|
|
2380
|
+
let popup = getPopup();
|
|
2600
2381
|
if (!popup) {
|
|
2601
2382
|
new Swal();
|
|
2602
2383
|
}
|
|
@@ -2604,7 +2385,7 @@
|
|
|
2604
2385
|
if (!popup) {
|
|
2605
2386
|
return;
|
|
2606
2387
|
}
|
|
2607
|
-
|
|
2388
|
+
const loader = getLoader();
|
|
2608
2389
|
if (isToast()) {
|
|
2609
2390
|
hide(getIcon());
|
|
2610
2391
|
} else {
|
|
@@ -2620,9 +2401,9 @@
|
|
|
2620
2401
|
* @param {HTMLElement} popup
|
|
2621
2402
|
* @param {HTMLButtonElement | null} [buttonToReplace]
|
|
2622
2403
|
*/
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2404
|
+
const replaceButton = (popup, buttonToReplace) => {
|
|
2405
|
+
const actions = getActions();
|
|
2406
|
+
const loader = getLoader();
|
|
2626
2407
|
if (!actions || !loader) {
|
|
2627
2408
|
return;
|
|
2628
2409
|
}
|
|
@@ -2642,12 +2423,10 @@
|
|
|
2642
2423
|
* @param {SweetAlert} instance
|
|
2643
2424
|
* @param {SweetAlertOptions} params
|
|
2644
2425
|
*/
|
|
2645
|
-
|
|
2426
|
+
const handleInputOptionsAndValue = (instance, params) => {
|
|
2646
2427
|
if (params.input === 'select' || params.input === 'radio') {
|
|
2647
2428
|
handleInputOptions(instance, params);
|
|
2648
|
-
} else if (['text', 'email', 'number', 'tel', 'textarea'].some(
|
|
2649
|
-
return i === params.input;
|
|
2650
|
-
}) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
|
|
2429
|
+
} else if (['text', 'email', 'number', 'tel', 'textarea'].some(i => i === params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
|
|
2651
2430
|
showLoading(getConfirmButton());
|
|
2652
2431
|
handleInputValue(instance, params);
|
|
2653
2432
|
}
|
|
@@ -2658,8 +2437,8 @@
|
|
|
2658
2437
|
* @param {SweetAlertOptions} innerParams
|
|
2659
2438
|
* @returns {SweetAlertInputValue}
|
|
2660
2439
|
*/
|
|
2661
|
-
|
|
2662
|
-
|
|
2440
|
+
const getInputValue = (instance, innerParams) => {
|
|
2441
|
+
const input = instance.getInput();
|
|
2663
2442
|
if (!input) {
|
|
2664
2443
|
return null;
|
|
2665
2444
|
}
|
|
@@ -2679,55 +2458,49 @@
|
|
|
2679
2458
|
* @param {HTMLInputElement} input
|
|
2680
2459
|
* @returns {number}
|
|
2681
2460
|
*/
|
|
2682
|
-
|
|
2683
|
-
return input.checked ? 1 : 0;
|
|
2684
|
-
};
|
|
2461
|
+
const getCheckboxValue = input => input.checked ? 1 : 0;
|
|
2685
2462
|
|
|
2686
2463
|
/**
|
|
2687
2464
|
* @param {HTMLInputElement} input
|
|
2688
2465
|
* @returns {string | null}
|
|
2689
2466
|
*/
|
|
2690
|
-
|
|
2691
|
-
return input.checked ? input.value : null;
|
|
2692
|
-
};
|
|
2467
|
+
const getRadioValue = input => input.checked ? input.value : null;
|
|
2693
2468
|
|
|
2694
2469
|
/**
|
|
2695
2470
|
* @param {HTMLInputElement} input
|
|
2696
2471
|
* @returns {FileList | File | null}
|
|
2697
2472
|
*/
|
|
2698
|
-
|
|
2699
|
-
return input.files && input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
|
|
2700
|
-
};
|
|
2473
|
+
const getFileValue = input => input.files && input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
|
|
2701
2474
|
|
|
2702
2475
|
/**
|
|
2703
2476
|
* @param {SweetAlert} instance
|
|
2704
2477
|
* @param {SweetAlertOptions} params
|
|
2705
2478
|
*/
|
|
2706
|
-
|
|
2707
|
-
|
|
2479
|
+
const handleInputOptions = (instance, params) => {
|
|
2480
|
+
const popup = getPopup();
|
|
2708
2481
|
if (!popup) {
|
|
2709
2482
|
return;
|
|
2710
2483
|
}
|
|
2711
2484
|
/**
|
|
2712
2485
|
* @param {Record<string, any>} inputOptions
|
|
2713
2486
|
*/
|
|
2714
|
-
|
|
2487
|
+
const processInputOptions = inputOptions => {
|
|
2715
2488
|
if (params.input === 'select') {
|
|
2716
|
-
populateSelectOptions(popup,
|
|
2489
|
+
populateSelectOptions(popup, formatInputOptions(inputOptions), params);
|
|
2717
2490
|
} else if (params.input === 'radio') {
|
|
2718
|
-
populateRadioOptions(popup,
|
|
2491
|
+
populateRadioOptions(popup, formatInputOptions(inputOptions), params);
|
|
2719
2492
|
}
|
|
2720
2493
|
};
|
|
2721
2494
|
if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
|
|
2722
2495
|
showLoading(getConfirmButton());
|
|
2723
|
-
asPromise(params.inputOptions).then(
|
|
2496
|
+
asPromise(params.inputOptions).then(inputOptions => {
|
|
2724
2497
|
instance.hideLoading();
|
|
2725
2498
|
processInputOptions(inputOptions);
|
|
2726
2499
|
});
|
|
2727
|
-
} else if (
|
|
2500
|
+
} else if (typeof params.inputOptions === 'object') {
|
|
2728
2501
|
processInputOptions(params.inputOptions);
|
|
2729
2502
|
} else {
|
|
2730
|
-
error(
|
|
2503
|
+
error(`Unexpected type of inputOptions! Expected object, Map or Promise, got ${typeof params.inputOptions}`);
|
|
2731
2504
|
}
|
|
2732
2505
|
};
|
|
2733
2506
|
|
|
@@ -2735,19 +2508,19 @@
|
|
|
2735
2508
|
* @param {SweetAlert} instance
|
|
2736
2509
|
* @param {SweetAlertOptions} params
|
|
2737
2510
|
*/
|
|
2738
|
-
|
|
2739
|
-
|
|
2511
|
+
const handleInputValue = (instance, params) => {
|
|
2512
|
+
const input = instance.getInput();
|
|
2740
2513
|
if (!input) {
|
|
2741
2514
|
return;
|
|
2742
2515
|
}
|
|
2743
2516
|
hide(input);
|
|
2744
|
-
asPromise(params.inputValue).then(
|
|
2745
|
-
input.value = params.input === 'number' ?
|
|
2517
|
+
asPromise(params.inputValue).then(inputValue => {
|
|
2518
|
+
input.value = params.input === 'number' ? `${parseFloat(inputValue) || 0}` : `${inputValue}`;
|
|
2746
2519
|
show(input);
|
|
2747
2520
|
input.focus();
|
|
2748
2521
|
instance.hideLoading();
|
|
2749
|
-
})
|
|
2750
|
-
error(
|
|
2522
|
+
}).catch(err => {
|
|
2523
|
+
error(`Error in inputValue promise: ${err}`);
|
|
2751
2524
|
input.value = '';
|
|
2752
2525
|
show(input);
|
|
2753
2526
|
input.focus();
|
|
@@ -2761,7 +2534,7 @@
|
|
|
2761
2534
|
* @param {SweetAlertOptions} params
|
|
2762
2535
|
*/
|
|
2763
2536
|
function populateSelectOptions(popup, inputOptions, params) {
|
|
2764
|
-
|
|
2537
|
+
const select = getDirectChildByClass(popup, swalClasses.select);
|
|
2765
2538
|
if (!select) {
|
|
2766
2539
|
return;
|
|
2767
2540
|
}
|
|
@@ -2770,29 +2543,27 @@
|
|
|
2770
2543
|
* @param {string} optionLabel
|
|
2771
2544
|
* @param {string} optionValue
|
|
2772
2545
|
*/
|
|
2773
|
-
|
|
2774
|
-
|
|
2546
|
+
const renderOption = (parent, optionLabel, optionValue) => {
|
|
2547
|
+
const option = document.createElement('option');
|
|
2775
2548
|
option.value = optionValue;
|
|
2776
2549
|
setInnerHtml(option, optionLabel);
|
|
2777
2550
|
option.selected = isSelected(optionValue, params.inputValue);
|
|
2778
2551
|
parent.appendChild(option);
|
|
2779
2552
|
};
|
|
2780
|
-
inputOptions.forEach(
|
|
2781
|
-
|
|
2782
|
-
|
|
2553
|
+
inputOptions.forEach(inputOption => {
|
|
2554
|
+
const optionValue = inputOption[0];
|
|
2555
|
+
const optionLabel = inputOption[1];
|
|
2783
2556
|
// <optgroup> spec:
|
|
2784
2557
|
// https://www.w3.org/TR/html401/interact/forms.html#h-17.6
|
|
2785
2558
|
// "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
|
|
2786
2559
|
// check whether this is a <optgroup>
|
|
2787
2560
|
if (Array.isArray(optionLabel)) {
|
|
2788
2561
|
// if it is an array, then it is an <optgroup>
|
|
2789
|
-
|
|
2562
|
+
const optgroup = document.createElement('optgroup');
|
|
2790
2563
|
optgroup.label = optionValue;
|
|
2791
2564
|
optgroup.disabled = false; // not configurable for now
|
|
2792
2565
|
select.appendChild(optgroup);
|
|
2793
|
-
optionLabel.forEach(
|
|
2794
|
-
return renderOption(optgroup, o[1], o[0]);
|
|
2795
|
-
});
|
|
2566
|
+
optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
|
|
2796
2567
|
} else {
|
|
2797
2568
|
// case of <option>
|
|
2798
2569
|
renderOption(select, optionLabel, optionValue);
|
|
@@ -2807,29 +2578,29 @@
|
|
|
2807
2578
|
* @param {SweetAlertOptions} params
|
|
2808
2579
|
*/
|
|
2809
2580
|
function populateRadioOptions(popup, inputOptions, params) {
|
|
2810
|
-
|
|
2581
|
+
const radio = getDirectChildByClass(popup, swalClasses.radio);
|
|
2811
2582
|
if (!radio) {
|
|
2812
2583
|
return;
|
|
2813
2584
|
}
|
|
2814
|
-
inputOptions.forEach(
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2585
|
+
inputOptions.forEach(inputOption => {
|
|
2586
|
+
const radioValue = inputOption[0];
|
|
2587
|
+
const radioLabel = inputOption[1];
|
|
2588
|
+
const radioInput = document.createElement('input');
|
|
2589
|
+
const radioLabelElement = document.createElement('label');
|
|
2819
2590
|
radioInput.type = 'radio';
|
|
2820
2591
|
radioInput.name = swalClasses.radio;
|
|
2821
2592
|
radioInput.value = radioValue;
|
|
2822
2593
|
if (isSelected(radioValue, params.inputValue)) {
|
|
2823
2594
|
radioInput.checked = true;
|
|
2824
2595
|
}
|
|
2825
|
-
|
|
2596
|
+
const label = document.createElement('span');
|
|
2826
2597
|
setInnerHtml(label, radioLabel);
|
|
2827
2598
|
label.className = swalClasses.label;
|
|
2828
2599
|
radioLabelElement.appendChild(radioInput);
|
|
2829
2600
|
radioLabelElement.appendChild(label);
|
|
2830
2601
|
radio.appendChild(radioLabelElement);
|
|
2831
2602
|
});
|
|
2832
|
-
|
|
2603
|
+
const radios = radio.querySelectorAll('input');
|
|
2833
2604
|
if (radios.length) {
|
|
2834
2605
|
radios[0].focus();
|
|
2835
2606
|
}
|
|
@@ -2842,24 +2613,24 @@
|
|
|
2842
2613
|
* @typedef {string[]} InputOptionFlattened
|
|
2843
2614
|
* @returns {InputOptionFlattened[]}
|
|
2844
2615
|
*/
|
|
2845
|
-
|
|
2616
|
+
const formatInputOptions = inputOptions => {
|
|
2846
2617
|
/** @type {InputOptionFlattened[]} */
|
|
2847
|
-
|
|
2618
|
+
const result = [];
|
|
2848
2619
|
if (inputOptions instanceof Map) {
|
|
2849
|
-
inputOptions.forEach(
|
|
2850
|
-
|
|
2851
|
-
if (
|
|
2620
|
+
inputOptions.forEach((value, key) => {
|
|
2621
|
+
let valueFormatted = value;
|
|
2622
|
+
if (typeof valueFormatted === 'object') {
|
|
2852
2623
|
// case of <optgroup>
|
|
2853
|
-
valueFormatted =
|
|
2624
|
+
valueFormatted = formatInputOptions(valueFormatted);
|
|
2854
2625
|
}
|
|
2855
2626
|
result.push([key, valueFormatted]);
|
|
2856
2627
|
});
|
|
2857
2628
|
} else {
|
|
2858
|
-
Object.keys(inputOptions).forEach(
|
|
2859
|
-
|
|
2860
|
-
if (
|
|
2629
|
+
Object.keys(inputOptions).forEach(key => {
|
|
2630
|
+
let valueFormatted = inputOptions[key];
|
|
2631
|
+
if (typeof valueFormatted === 'object') {
|
|
2861
2632
|
// case of <optgroup>
|
|
2862
|
-
valueFormatted =
|
|
2633
|
+
valueFormatted = formatInputOptions(valueFormatted);
|
|
2863
2634
|
}
|
|
2864
2635
|
result.push([key, valueFormatted]);
|
|
2865
2636
|
});
|
|
@@ -2872,17 +2643,15 @@
|
|
|
2872
2643
|
* @param {SweetAlertInputValue} inputValue
|
|
2873
2644
|
* @returns {boolean}
|
|
2874
2645
|
*/
|
|
2875
|
-
|
|
2646
|
+
const isSelected = (optionValue, inputValue) => {
|
|
2876
2647
|
return !!inputValue && inputValue.toString() === optionValue.toString();
|
|
2877
2648
|
};
|
|
2878
2649
|
|
|
2879
|
-
var _this = undefined;
|
|
2880
|
-
|
|
2881
2650
|
/**
|
|
2882
2651
|
* @param {SweetAlert} instance
|
|
2883
2652
|
*/
|
|
2884
|
-
|
|
2885
|
-
|
|
2653
|
+
const handleConfirmButtonClick = instance => {
|
|
2654
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2886
2655
|
instance.disableButtons();
|
|
2887
2656
|
if (innerParams.input) {
|
|
2888
2657
|
handleConfirmOrDenyWithInput(instance, 'confirm');
|
|
@@ -2894,8 +2663,8 @@
|
|
|
2894
2663
|
/**
|
|
2895
2664
|
* @param {SweetAlert} instance
|
|
2896
2665
|
*/
|
|
2897
|
-
|
|
2898
|
-
|
|
2666
|
+
const handleDenyButtonClick = instance => {
|
|
2667
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2899
2668
|
instance.disableButtons();
|
|
2900
2669
|
if (innerParams.returnInputValueOnDeny) {
|
|
2901
2670
|
handleConfirmOrDenyWithInput(instance, 'deny');
|
|
@@ -2908,7 +2677,7 @@
|
|
|
2908
2677
|
* @param {SweetAlert} instance
|
|
2909
2678
|
* @param {Function} dismissWith
|
|
2910
2679
|
*/
|
|
2911
|
-
|
|
2680
|
+
const handleCancelButtonClick = (instance, dismissWith) => {
|
|
2912
2681
|
instance.disableButtons();
|
|
2913
2682
|
dismissWith(DismissReason.cancel);
|
|
2914
2683
|
};
|
|
@@ -2917,14 +2686,14 @@
|
|
|
2917
2686
|
* @param {SweetAlert} instance
|
|
2918
2687
|
* @param {'confirm' | 'deny'} type
|
|
2919
2688
|
*/
|
|
2920
|
-
|
|
2921
|
-
|
|
2689
|
+
const handleConfirmOrDenyWithInput = (instance, type) => {
|
|
2690
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2922
2691
|
if (!innerParams.input) {
|
|
2923
|
-
error(
|
|
2692
|
+
error(`The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`);
|
|
2924
2693
|
return;
|
|
2925
2694
|
}
|
|
2926
|
-
|
|
2927
|
-
|
|
2695
|
+
const input = instance.getInput();
|
|
2696
|
+
const inputValue = getInputValue(instance, innerParams);
|
|
2928
2697
|
if (innerParams.inputValidator) {
|
|
2929
2698
|
handleInputValidator(instance, inputValue, type);
|
|
2930
2699
|
} else if (input && !input.checkValidity()) {
|
|
@@ -2942,13 +2711,11 @@
|
|
|
2942
2711
|
* @param {SweetAlertInputValue} inputValue
|
|
2943
2712
|
* @param {'confirm' | 'deny'} type
|
|
2944
2713
|
*/
|
|
2945
|
-
|
|
2946
|
-
|
|
2714
|
+
const handleInputValidator = (instance, inputValue, type) => {
|
|
2715
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2947
2716
|
instance.disableInput();
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
});
|
|
2951
|
-
validationPromise.then(function (validationMessage) {
|
|
2717
|
+
const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
|
|
2718
|
+
validationPromise.then(validationMessage => {
|
|
2952
2719
|
instance.enableButtons();
|
|
2953
2720
|
instance.enableInput();
|
|
2954
2721
|
if (validationMessage) {
|
|
@@ -2965,17 +2732,15 @@
|
|
|
2965
2732
|
* @param {SweetAlert} instance
|
|
2966
2733
|
* @param {any} value
|
|
2967
2734
|
*/
|
|
2968
|
-
|
|
2969
|
-
|
|
2735
|
+
const deny = (instance, value) => {
|
|
2736
|
+
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
2970
2737
|
if (innerParams.showLoaderOnDeny) {
|
|
2971
2738
|
showLoading(getDenyButton());
|
|
2972
2739
|
}
|
|
2973
2740
|
if (innerParams.preDeny) {
|
|
2974
2741
|
instance.isAwaitingPromise = true; // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preDeny's promise is received
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
});
|
|
2978
|
-
preDenyPromise.then(function (preDenyValue) {
|
|
2742
|
+
const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
|
|
2743
|
+
preDenyPromise.then(preDenyValue => {
|
|
2979
2744
|
if (preDenyValue === false) {
|
|
2980
2745
|
instance.hideLoading();
|
|
2981
2746
|
handleAwaitingPromise(instance);
|
|
@@ -2985,13 +2750,11 @@
|
|
|
2985
2750
|
value: typeof preDenyValue === 'undefined' ? value : preDenyValue
|
|
2986
2751
|
});
|
|
2987
2752
|
}
|
|
2988
|
-
})
|
|
2989
|
-
return rejectWith(instance || _this, error);
|
|
2990
|
-
});
|
|
2753
|
+
}).catch(error => rejectWith(instance || undefined, error));
|
|
2991
2754
|
} else {
|
|
2992
2755
|
instance.close({
|
|
2993
2756
|
isDenied: true,
|
|
2994
|
-
value
|
|
2757
|
+
value
|
|
2995
2758
|
});
|
|
2996
2759
|
}
|
|
2997
2760
|
};
|
|
@@ -3000,10 +2763,10 @@
|
|
|
3000
2763
|
* @param {SweetAlert} instance
|
|
3001
2764
|
* @param {any} value
|
|
3002
2765
|
*/
|
|
3003
|
-
|
|
2766
|
+
const succeedWith = (instance, value) => {
|
|
3004
2767
|
instance.close({
|
|
3005
2768
|
isConfirmed: true,
|
|
3006
|
-
value
|
|
2769
|
+
value
|
|
3007
2770
|
});
|
|
3008
2771
|
};
|
|
3009
2772
|
|
|
@@ -3012,7 +2775,7 @@
|
|
|
3012
2775
|
* @param {SweetAlert} instance
|
|
3013
2776
|
* @param {string} error
|
|
3014
2777
|
*/
|
|
3015
|
-
|
|
2778
|
+
const rejectWith = (instance, error) => {
|
|
3016
2779
|
instance.rejectPromise(error);
|
|
3017
2780
|
};
|
|
3018
2781
|
|
|
@@ -3021,27 +2784,23 @@
|
|
|
3021
2784
|
* @param {SweetAlert} instance
|
|
3022
2785
|
* @param {any} value
|
|
3023
2786
|
*/
|
|
3024
|
-
|
|
3025
|
-
|
|
2787
|
+
const confirm = (instance, value) => {
|
|
2788
|
+
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
3026
2789
|
if (innerParams.showLoaderOnConfirm) {
|
|
3027
2790
|
showLoading();
|
|
3028
2791
|
}
|
|
3029
2792
|
if (innerParams.preConfirm) {
|
|
3030
2793
|
instance.resetValidationMessage();
|
|
3031
2794
|
instance.isAwaitingPromise = true; // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preConfirm's promise is received
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
});
|
|
3035
|
-
preConfirmPromise.then(function (preConfirmValue) {
|
|
2795
|
+
const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
|
|
2796
|
+
preConfirmPromise.then(preConfirmValue => {
|
|
3036
2797
|
if (isVisible$1(getValidationMessage()) || preConfirmValue === false) {
|
|
3037
2798
|
instance.hideLoading();
|
|
3038
2799
|
handleAwaitingPromise(instance);
|
|
3039
2800
|
} else {
|
|
3040
2801
|
succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
|
|
3041
2802
|
}
|
|
3042
|
-
})
|
|
3043
|
-
return rejectWith(instance || _this, error);
|
|
3044
|
-
});
|
|
2803
|
+
}).catch(error => rejectWith(instance || undefined, error));
|
|
3045
2804
|
} else {
|
|
3046
2805
|
succeedWith(instance, value);
|
|
3047
2806
|
}
|
|
@@ -3052,11 +2811,11 @@
|
|
|
3052
2811
|
*/
|
|
3053
2812
|
function hideLoading() {
|
|
3054
2813
|
// do nothing if popup is closed
|
|
3055
|
-
|
|
2814
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
3056
2815
|
if (!innerParams) {
|
|
3057
2816
|
return;
|
|
3058
2817
|
}
|
|
3059
|
-
|
|
2818
|
+
const domCache = privateProps.domCache.get(this);
|
|
3060
2819
|
hide(domCache.loader);
|
|
3061
2820
|
if (isToast()) {
|
|
3062
2821
|
if (innerParams.icon) {
|
|
@@ -3072,8 +2831,8 @@
|
|
|
3072
2831
|
domCache.denyButton.disabled = false;
|
|
3073
2832
|
domCache.cancelButton.disabled = false;
|
|
3074
2833
|
}
|
|
3075
|
-
|
|
3076
|
-
|
|
2834
|
+
const showRelatedButton = domCache => {
|
|
2835
|
+
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
3077
2836
|
if (buttonToReplace.length) {
|
|
3078
2837
|
show(buttonToReplace[0], 'inline-block');
|
|
3079
2838
|
} else if (allButtonsAreHidden()) {
|
|
@@ -3087,8 +2846,8 @@
|
|
|
3087
2846
|
* @returns {HTMLInputElement | null}
|
|
3088
2847
|
*/
|
|
3089
2848
|
function getInput() {
|
|
3090
|
-
|
|
3091
|
-
|
|
2849
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
2850
|
+
const domCache = privateProps.domCache.get(this);
|
|
3092
2851
|
if (!domCache) {
|
|
3093
2852
|
return null;
|
|
3094
2853
|
}
|
|
@@ -3101,8 +2860,8 @@
|
|
|
3101
2860
|
* @param {boolean} disabled
|
|
3102
2861
|
*/
|
|
3103
2862
|
function setButtonsDisabled(instance, buttons, disabled) {
|
|
3104
|
-
|
|
3105
|
-
buttons.forEach(
|
|
2863
|
+
const domCache = privateProps.domCache.get(instance);
|
|
2864
|
+
buttons.forEach(button => {
|
|
3106
2865
|
domCache[button].disabled = disabled;
|
|
3107
2866
|
});
|
|
3108
2867
|
}
|
|
@@ -3112,14 +2871,14 @@
|
|
|
3112
2871
|
* @param {boolean} disabled
|
|
3113
2872
|
*/
|
|
3114
2873
|
function setInputDisabled(input, disabled) {
|
|
3115
|
-
|
|
2874
|
+
const popup = getPopup();
|
|
3116
2875
|
if (!popup || !input) {
|
|
3117
2876
|
return;
|
|
3118
2877
|
}
|
|
3119
2878
|
if (input.type === 'radio') {
|
|
3120
2879
|
/** @type {NodeListOf<HTMLInputElement>} */
|
|
3121
|
-
|
|
3122
|
-
for (
|
|
2880
|
+
const radios = popup.querySelectorAll(`[name="${swalClasses.radio}"]`);
|
|
2881
|
+
for (let i = 0; i < radios.length; i++) {
|
|
3123
2882
|
radios[i].disabled = disabled;
|
|
3124
2883
|
}
|
|
3125
2884
|
} else {
|
|
@@ -3166,15 +2925,15 @@
|
|
|
3166
2925
|
* @this {SweetAlert}
|
|
3167
2926
|
*/
|
|
3168
2927
|
function showValidationMessage(error) {
|
|
3169
|
-
|
|
3170
|
-
|
|
2928
|
+
const domCache = privateProps.domCache.get(this);
|
|
2929
|
+
const params = privateProps.innerParams.get(this);
|
|
3171
2930
|
setInnerHtml(domCache.validationMessage, error);
|
|
3172
2931
|
domCache.validationMessage.className = swalClasses['validation-message'];
|
|
3173
2932
|
if (params.customClass && params.customClass.validationMessage) {
|
|
3174
2933
|
addClass(domCache.validationMessage, params.customClass.validationMessage);
|
|
3175
2934
|
}
|
|
3176
2935
|
show(domCache.validationMessage);
|
|
3177
|
-
|
|
2936
|
+
const input = this.getInput();
|
|
3178
2937
|
if (input) {
|
|
3179
2938
|
input.setAttribute('aria-invalid', 'true');
|
|
3180
2939
|
input.setAttribute('aria-describedby', swalClasses['validation-message']);
|
|
@@ -3189,11 +2948,11 @@
|
|
|
3189
2948
|
* @this {SweetAlert}
|
|
3190
2949
|
*/
|
|
3191
2950
|
function resetValidationMessage() {
|
|
3192
|
-
|
|
2951
|
+
const domCache = privateProps.domCache.get(this);
|
|
3193
2952
|
if (domCache.validationMessage) {
|
|
3194
2953
|
hide(domCache.validationMessage);
|
|
3195
2954
|
}
|
|
3196
|
-
|
|
2955
|
+
const input = this.getInput();
|
|
3197
2956
|
if (input) {
|
|
3198
2957
|
input.removeAttribute('aria-invalid');
|
|
3199
2958
|
input.removeAttribute('aria-describedby');
|
|
@@ -3201,7 +2960,7 @@
|
|
|
3201
2960
|
}
|
|
3202
2961
|
}
|
|
3203
2962
|
|
|
3204
|
-
|
|
2963
|
+
const defaultParams = {
|
|
3205
2964
|
title: '',
|
|
3206
2965
|
titleText: '',
|
|
3207
2966
|
text: '',
|
|
@@ -3292,13 +3051,13 @@
|
|
|
3292
3051
|
didDestroy: undefined,
|
|
3293
3052
|
scrollbarPadding: true
|
|
3294
3053
|
};
|
|
3295
|
-
|
|
3054
|
+
const updatableParams = ['allowEscapeKey', 'allowOutsideClick', 'background', 'buttonsStyling', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonText', 'closeButtonAriaLabel', 'closeButtonHtml', 'color', 'confirmButtonAriaLabel', 'confirmButtonColor', 'confirmButtonText', 'currentProgressStep', 'customClass', 'denyButtonAriaLabel', 'denyButtonColor', 'denyButtonText', 'didClose', 'didDestroy', 'footer', 'hideClass', 'html', 'icon', 'iconColor', 'iconHtml', 'imageAlt', 'imageHeight', 'imageUrl', 'imageWidth', 'preConfirm', 'preDeny', 'progressSteps', 'returnFocus', 'reverseButtons', 'showCancelButton', 'showCloseButton', 'showConfirmButton', 'showDenyButton', 'text', 'title', 'titleText', 'willClose'];
|
|
3296
3055
|
|
|
3297
3056
|
/** @type {Record<string, string | undefined>} */
|
|
3298
|
-
|
|
3057
|
+
const deprecatedParams = {
|
|
3299
3058
|
allowEnterKey: undefined
|
|
3300
3059
|
};
|
|
3301
|
-
|
|
3060
|
+
const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture'];
|
|
3302
3061
|
|
|
3303
3062
|
/**
|
|
3304
3063
|
* Is valid parameter
|
|
@@ -3306,7 +3065,7 @@
|
|
|
3306
3065
|
* @param {string} paramName
|
|
3307
3066
|
* @returns {boolean}
|
|
3308
3067
|
*/
|
|
3309
|
-
|
|
3068
|
+
const isValidParameter = paramName => {
|
|
3310
3069
|
return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
|
|
3311
3070
|
};
|
|
3312
3071
|
|
|
@@ -3316,7 +3075,7 @@
|
|
|
3316
3075
|
* @param {string} paramName
|
|
3317
3076
|
* @returns {boolean}
|
|
3318
3077
|
*/
|
|
3319
|
-
|
|
3078
|
+
const isUpdatableParameter = paramName => {
|
|
3320
3079
|
return updatableParams.indexOf(paramName) !== -1;
|
|
3321
3080
|
};
|
|
3322
3081
|
|
|
@@ -3326,33 +3085,33 @@
|
|
|
3326
3085
|
* @param {string} paramName
|
|
3327
3086
|
* @returns {string | undefined}
|
|
3328
3087
|
*/
|
|
3329
|
-
|
|
3088
|
+
const isDeprecatedParameter = paramName => {
|
|
3330
3089
|
return deprecatedParams[paramName];
|
|
3331
3090
|
};
|
|
3332
3091
|
|
|
3333
3092
|
/**
|
|
3334
3093
|
* @param {string} param
|
|
3335
3094
|
*/
|
|
3336
|
-
|
|
3095
|
+
const checkIfParamIsValid = param => {
|
|
3337
3096
|
if (!isValidParameter(param)) {
|
|
3338
|
-
warn(
|
|
3097
|
+
warn(`Unknown parameter "${param}"`);
|
|
3339
3098
|
}
|
|
3340
3099
|
};
|
|
3341
3100
|
|
|
3342
3101
|
/**
|
|
3343
3102
|
* @param {string} param
|
|
3344
3103
|
*/
|
|
3345
|
-
|
|
3104
|
+
const checkIfToastParamIsValid = param => {
|
|
3346
3105
|
if (toastIncompatibleParams.includes(param)) {
|
|
3347
|
-
warn(
|
|
3106
|
+
warn(`The parameter "${param}" is incompatible with toasts`);
|
|
3348
3107
|
}
|
|
3349
3108
|
};
|
|
3350
3109
|
|
|
3351
3110
|
/**
|
|
3352
3111
|
* @param {string} param
|
|
3353
3112
|
*/
|
|
3354
|
-
|
|
3355
|
-
|
|
3113
|
+
const checkIfParamIsDeprecated = param => {
|
|
3114
|
+
const isDeprecated = isDeprecatedParameter(param);
|
|
3356
3115
|
if (isDeprecated) {
|
|
3357
3116
|
warnAboutDeprecation(param, isDeprecated);
|
|
3358
3117
|
}
|
|
@@ -3363,11 +3122,11 @@
|
|
|
3363
3122
|
*
|
|
3364
3123
|
* @param {SweetAlertOptions} params
|
|
3365
3124
|
*/
|
|
3366
|
-
|
|
3125
|
+
const showWarningsForParams = params => {
|
|
3367
3126
|
if (params.backdrop === false && params.allowOutsideClick) {
|
|
3368
3127
|
warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
|
|
3369
3128
|
}
|
|
3370
|
-
for (
|
|
3129
|
+
for (const param in params) {
|
|
3371
3130
|
checkIfParamIsValid(param);
|
|
3372
3131
|
if (params.toast) {
|
|
3373
3132
|
checkIfToastParamIsValid(param);
|
|
@@ -3382,14 +3141,14 @@
|
|
|
3382
3141
|
* @param {SweetAlertOptions} params
|
|
3383
3142
|
*/
|
|
3384
3143
|
function update(params) {
|
|
3385
|
-
|
|
3386
|
-
|
|
3144
|
+
const popup = getPopup();
|
|
3145
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
3387
3146
|
if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
|
|
3388
|
-
warn(
|
|
3147
|
+
warn(`You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.`);
|
|
3389
3148
|
return;
|
|
3390
3149
|
}
|
|
3391
|
-
|
|
3392
|
-
|
|
3150
|
+
const validUpdatableParams = filterValidParams(params);
|
|
3151
|
+
const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
|
|
3393
3152
|
render(this, updatedParams);
|
|
3394
3153
|
privateProps.innerParams.set(this, updatedParams);
|
|
3395
3154
|
Object.defineProperties(this, {
|
|
@@ -3405,13 +3164,13 @@
|
|
|
3405
3164
|
* @param {SweetAlertOptions} params
|
|
3406
3165
|
* @returns {SweetAlertOptions}
|
|
3407
3166
|
*/
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
Object.keys(params).forEach(
|
|
3167
|
+
const filterValidParams = params => {
|
|
3168
|
+
const validUpdatableParams = {};
|
|
3169
|
+
Object.keys(params).forEach(param => {
|
|
3411
3170
|
if (isUpdatableParameter(param)) {
|
|
3412
3171
|
validUpdatableParams[param] = params[param];
|
|
3413
3172
|
} else {
|
|
3414
|
-
warn(
|
|
3173
|
+
warn(`Invalid parameter to update: ${param}`);
|
|
3415
3174
|
}
|
|
3416
3175
|
});
|
|
3417
3176
|
return validUpdatableParams;
|
|
@@ -3421,8 +3180,8 @@
|
|
|
3421
3180
|
* Dispose the current SweetAlert2 instance
|
|
3422
3181
|
*/
|
|
3423
3182
|
function _destroy() {
|
|
3424
|
-
|
|
3425
|
-
|
|
3183
|
+
const domCache = privateProps.domCache.get(this);
|
|
3184
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
3426
3185
|
if (!innerParams) {
|
|
3427
3186
|
disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
|
|
3428
3187
|
return; // This instance has already been destroyed
|
|
@@ -3442,7 +3201,7 @@
|
|
|
3442
3201
|
/**
|
|
3443
3202
|
* @param {SweetAlert} instance
|
|
3444
3203
|
*/
|
|
3445
|
-
|
|
3204
|
+
const disposeSwal = instance => {
|
|
3446
3205
|
disposeWeakMaps(instance);
|
|
3447
3206
|
// Unset this.params so GC will dispose it (#1569)
|
|
3448
3207
|
delete instance.params;
|
|
@@ -3456,7 +3215,7 @@
|
|
|
3456
3215
|
/**
|
|
3457
3216
|
* @param {SweetAlert} instance
|
|
3458
3217
|
*/
|
|
3459
|
-
|
|
3218
|
+
const disposeWeakMaps = instance => {
|
|
3460
3219
|
// If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
|
|
3461
3220
|
if (instance.isAwaitingPromise) {
|
|
3462
3221
|
unsetWeakMaps(privateProps, instance);
|
|
@@ -3489,9 +3248,9 @@
|
|
|
3489
3248
|
* @param {object} obj
|
|
3490
3249
|
* @param {SweetAlert} instance
|
|
3491
3250
|
*/
|
|
3492
|
-
|
|
3493
|
-
for (
|
|
3494
|
-
obj[i]
|
|
3251
|
+
const unsetWeakMaps = (obj, instance) => {
|
|
3252
|
+
for (const i in obj) {
|
|
3253
|
+
obj[i].delete(instance);
|
|
3495
3254
|
}
|
|
3496
3255
|
};
|
|
3497
3256
|
|
|
@@ -3521,7 +3280,7 @@
|
|
|
3521
3280
|
* @param {DomCache} domCache
|
|
3522
3281
|
* @param {Function} dismissWith
|
|
3523
3282
|
*/
|
|
3524
|
-
|
|
3283
|
+
const handlePopupClick = (innerParams, domCache, dismissWith) => {
|
|
3525
3284
|
if (innerParams.toast) {
|
|
3526
3285
|
handleToastClick(innerParams, domCache, dismissWith);
|
|
3527
3286
|
} else {
|
|
@@ -3540,9 +3299,9 @@
|
|
|
3540
3299
|
* @param {DomCache} domCache
|
|
3541
3300
|
* @param {Function} dismissWith
|
|
3542
3301
|
*/
|
|
3543
|
-
|
|
3302
|
+
const handleToastClick = (innerParams, domCache, dismissWith) => {
|
|
3544
3303
|
// Closing toast by internal click
|
|
3545
|
-
domCache.popup.onclick =
|
|
3304
|
+
domCache.popup.onclick = () => {
|
|
3546
3305
|
if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
|
|
3547
3306
|
return;
|
|
3548
3307
|
}
|
|
@@ -3554,18 +3313,18 @@
|
|
|
3554
3313
|
* @param {SweetAlertOptions} innerParams
|
|
3555
3314
|
* @returns {boolean}
|
|
3556
3315
|
*/
|
|
3557
|
-
|
|
3316
|
+
const isAnyButtonShown = innerParams => {
|
|
3558
3317
|
return !!(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton);
|
|
3559
3318
|
};
|
|
3560
|
-
|
|
3319
|
+
let ignoreOutsideClick = false;
|
|
3561
3320
|
|
|
3562
3321
|
/**
|
|
3563
3322
|
* @param {DomCache} domCache
|
|
3564
3323
|
*/
|
|
3565
|
-
|
|
3566
|
-
domCache.popup.onmousedown =
|
|
3324
|
+
const handleModalMousedown = domCache => {
|
|
3325
|
+
domCache.popup.onmousedown = () => {
|
|
3567
3326
|
domCache.container.onmouseup = function (e) {
|
|
3568
|
-
domCache.container.onmouseup =
|
|
3327
|
+
domCache.container.onmouseup = () => {};
|
|
3569
3328
|
// We only check if the mouseup target is the container because usually it doesn't
|
|
3570
3329
|
// have any other direct children aside of the popup
|
|
3571
3330
|
if (e.target === domCache.container) {
|
|
@@ -3578,14 +3337,14 @@
|
|
|
3578
3337
|
/**
|
|
3579
3338
|
* @param {DomCache} domCache
|
|
3580
3339
|
*/
|
|
3581
|
-
|
|
3582
|
-
domCache.container.onmousedown =
|
|
3340
|
+
const handleContainerMousedown = domCache => {
|
|
3341
|
+
domCache.container.onmousedown = e => {
|
|
3583
3342
|
// prevent the modal text from being selected on double click on the container (allowOutsideClick: false)
|
|
3584
3343
|
if (e.target === domCache.container) {
|
|
3585
3344
|
e.preventDefault();
|
|
3586
3345
|
}
|
|
3587
3346
|
domCache.popup.onmouseup = function (e) {
|
|
3588
|
-
domCache.popup.onmouseup =
|
|
3347
|
+
domCache.popup.onmouseup = () => {};
|
|
3589
3348
|
// We also need to check if the mouseup target is a child of the popup
|
|
3590
3349
|
if (e.target === domCache.popup || e.target instanceof HTMLElement && domCache.popup.contains(e.target)) {
|
|
3591
3350
|
ignoreOutsideClick = true;
|
|
@@ -3599,8 +3358,8 @@
|
|
|
3599
3358
|
* @param {DomCache} domCache
|
|
3600
3359
|
* @param {Function} dismissWith
|
|
3601
3360
|
*/
|
|
3602
|
-
|
|
3603
|
-
domCache.container.onclick =
|
|
3361
|
+
const handleModalClick = (innerParams, domCache, dismissWith) => {
|
|
3362
|
+
domCache.container.onclick = e => {
|
|
3604
3363
|
if (ignoreOutsideClick) {
|
|
3605
3364
|
ignoreOutsideClick = false;
|
|
3606
3365
|
return;
|
|
@@ -3611,23 +3370,19 @@
|
|
|
3611
3370
|
};
|
|
3612
3371
|
};
|
|
3613
3372
|
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
};
|
|
3620
|
-
var argsToParams = function argsToParams(args) {
|
|
3621
|
-
var params = {};
|
|
3622
|
-
if (_typeof(args[0]) === 'object' && !isElement(args[0])) {
|
|
3373
|
+
const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
|
|
3374
|
+
const isElement = elem => elem instanceof Element || isJqueryElement(elem);
|
|
3375
|
+
const argsToParams = args => {
|
|
3376
|
+
const params = {};
|
|
3377
|
+
if (typeof args[0] === 'object' && !isElement(args[0])) {
|
|
3623
3378
|
Object.assign(params, args[0]);
|
|
3624
3379
|
} else {
|
|
3625
|
-
['title', 'html', 'icon'].forEach(
|
|
3626
|
-
|
|
3380
|
+
['title', 'html', 'icon'].forEach((name, index) => {
|
|
3381
|
+
const arg = args[index];
|
|
3627
3382
|
if (typeof arg === 'string' || isElement(arg)) {
|
|
3628
3383
|
params[name] = arg;
|
|
3629
3384
|
} else if (arg !== undefined) {
|
|
3630
|
-
error(
|
|
3385
|
+
error(`Unexpected type of ${name}! Expected "string" or "Element", got ${typeof arg}`);
|
|
3631
3386
|
}
|
|
3632
3387
|
});
|
|
3633
3388
|
}
|
|
@@ -3644,7 +3399,7 @@
|
|
|
3644
3399
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3645
3400
|
args[_key] = arguments[_key];
|
|
3646
3401
|
}
|
|
3647
|
-
return
|
|
3402
|
+
return new this(...args);
|
|
3648
3403
|
}
|
|
3649
3404
|
|
|
3650
3405
|
/**
|
|
@@ -3667,19 +3422,12 @@
|
|
|
3667
3422
|
* @returns {SweetAlert}
|
|
3668
3423
|
*/
|
|
3669
3424
|
function mixin(mixinParams) {
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
return _callSuper(this, MixinSwal, arguments);
|
|
3425
|
+
class MixinSwal extends this {
|
|
3426
|
+
_main(params, priorityMixinParams) {
|
|
3427
|
+
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
3674
3428
|
}
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
key: "_main",
|
|
3678
|
-
value: function _main(params, priorityMixinParams) {
|
|
3679
|
-
return _superPropGet(MixinSwal, "_main", this)([params, Object.assign({}, mixinParams, priorityMixinParams)]);
|
|
3680
|
-
}
|
|
3681
|
-
}]);
|
|
3682
|
-
}(this); // @ts-ignore
|
|
3429
|
+
}
|
|
3430
|
+
// @ts-ignore
|
|
3683
3431
|
return MixinSwal;
|
|
3684
3432
|
}
|
|
3685
3433
|
|
|
@@ -3689,7 +3437,7 @@
|
|
|
3689
3437
|
*
|
|
3690
3438
|
* @returns {number | undefined}
|
|
3691
3439
|
*/
|
|
3692
|
-
|
|
3440
|
+
const getTimerLeft = () => {
|
|
3693
3441
|
return globalState.timeout && globalState.timeout.getTimerLeft();
|
|
3694
3442
|
};
|
|
3695
3443
|
|
|
@@ -3699,7 +3447,7 @@
|
|
|
3699
3447
|
*
|
|
3700
3448
|
* @returns {number | undefined}
|
|
3701
3449
|
*/
|
|
3702
|
-
|
|
3450
|
+
const stopTimer = () => {
|
|
3703
3451
|
if (globalState.timeout) {
|
|
3704
3452
|
stopTimerProgressBar();
|
|
3705
3453
|
return globalState.timeout.stop();
|
|
@@ -3712,9 +3460,9 @@
|
|
|
3712
3460
|
*
|
|
3713
3461
|
* @returns {number | undefined}
|
|
3714
3462
|
*/
|
|
3715
|
-
|
|
3463
|
+
const resumeTimer = () => {
|
|
3716
3464
|
if (globalState.timeout) {
|
|
3717
|
-
|
|
3465
|
+
const remaining = globalState.timeout.start();
|
|
3718
3466
|
animateTimerProgressBar(remaining);
|
|
3719
3467
|
return remaining;
|
|
3720
3468
|
}
|
|
@@ -3726,8 +3474,8 @@
|
|
|
3726
3474
|
*
|
|
3727
3475
|
* @returns {number | undefined}
|
|
3728
3476
|
*/
|
|
3729
|
-
|
|
3730
|
-
|
|
3477
|
+
const toggleTimer = () => {
|
|
3478
|
+
const timer = globalState.timeout;
|
|
3731
3479
|
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
3732
3480
|
};
|
|
3733
3481
|
|
|
@@ -3738,9 +3486,9 @@
|
|
|
3738
3486
|
* @param {number} ms
|
|
3739
3487
|
* @returns {number | undefined}
|
|
3740
3488
|
*/
|
|
3741
|
-
|
|
3489
|
+
const increaseTimer = ms => {
|
|
3742
3490
|
if (globalState.timeout) {
|
|
3743
|
-
|
|
3491
|
+
const remaining = globalState.timeout.increase(ms);
|
|
3744
3492
|
animateTimerProgressBar(remaining, true);
|
|
3745
3493
|
return remaining;
|
|
3746
3494
|
}
|
|
@@ -3753,31 +3501,31 @@
|
|
|
3753
3501
|
*
|
|
3754
3502
|
* @returns {boolean}
|
|
3755
3503
|
*/
|
|
3756
|
-
|
|
3504
|
+
const isTimerRunning = () => {
|
|
3757
3505
|
return !!(globalState.timeout && globalState.timeout.isRunning());
|
|
3758
3506
|
};
|
|
3759
3507
|
|
|
3760
|
-
|
|
3761
|
-
|
|
3508
|
+
let bodyClickListenerAdded = false;
|
|
3509
|
+
const clickHandlers = {};
|
|
3762
3510
|
|
|
3763
3511
|
/**
|
|
3764
3512
|
* @param {string} attr
|
|
3765
3513
|
*/
|
|
3766
3514
|
function bindClickHandler() {
|
|
3767
|
-
|
|
3515
|
+
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
3768
3516
|
clickHandlers[attr] = this;
|
|
3769
3517
|
if (!bodyClickListenerAdded) {
|
|
3770
3518
|
document.body.addEventListener('click', bodyClickListener);
|
|
3771
3519
|
bodyClickListenerAdded = true;
|
|
3772
3520
|
}
|
|
3773
3521
|
}
|
|
3774
|
-
|
|
3775
|
-
for (
|
|
3776
|
-
for (
|
|
3777
|
-
|
|
3522
|
+
const bodyClickListener = event => {
|
|
3523
|
+
for (let el = event.target; el && el !== document; el = el.parentNode) {
|
|
3524
|
+
for (const attr in clickHandlers) {
|
|
3525
|
+
const template = el.getAttribute(attr);
|
|
3778
3526
|
if (template) {
|
|
3779
3527
|
clickHandlers[attr].fire({
|
|
3780
|
-
template
|
|
3528
|
+
template
|
|
3781
3529
|
});
|
|
3782
3530
|
return;
|
|
3783
3531
|
}
|
|
@@ -3828,13 +3576,12 @@
|
|
|
3828
3576
|
toggleTimer: toggleTimer
|
|
3829
3577
|
});
|
|
3830
3578
|
|
|
3831
|
-
|
|
3579
|
+
class Timer {
|
|
3832
3580
|
/**
|
|
3833
3581
|
* @param {Function} callback
|
|
3834
3582
|
* @param {number} delay
|
|
3835
3583
|
*/
|
|
3836
|
-
|
|
3837
|
-
_classCallCheck(this, Timer);
|
|
3584
|
+
constructor(callback, delay) {
|
|
3838
3585
|
this.callback = callback;
|
|
3839
3586
|
this.remaining = delay;
|
|
3840
3587
|
this.running = false;
|
|
@@ -3844,88 +3591,77 @@
|
|
|
3844
3591
|
/**
|
|
3845
3592
|
* @returns {number}
|
|
3846
3593
|
*/
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
this.started = new Date();
|
|
3853
|
-
this.id = setTimeout(this.callback, this.remaining);
|
|
3854
|
-
}
|
|
3855
|
-
return this.remaining;
|
|
3594
|
+
start() {
|
|
3595
|
+
if (!this.running) {
|
|
3596
|
+
this.running = true;
|
|
3597
|
+
this.started = new Date();
|
|
3598
|
+
this.id = setTimeout(this.callback, this.remaining);
|
|
3856
3599
|
}
|
|
3600
|
+
return this.remaining;
|
|
3601
|
+
}
|
|
3857
3602
|
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
clearTimeout(this.id);
|
|
3867
|
-
this.remaining -= new Date().getTime() - this.started.getTime();
|
|
3868
|
-
}
|
|
3869
|
-
return this.remaining;
|
|
3603
|
+
/**
|
|
3604
|
+
* @returns {number}
|
|
3605
|
+
*/
|
|
3606
|
+
stop() {
|
|
3607
|
+
if (this.started && this.running) {
|
|
3608
|
+
this.running = false;
|
|
3609
|
+
clearTimeout(this.id);
|
|
3610
|
+
this.remaining -= new Date().getTime() - this.started.getTime();
|
|
3870
3611
|
}
|
|
3612
|
+
return this.remaining;
|
|
3613
|
+
}
|
|
3871
3614
|
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
if (running) {
|
|
3881
|
-
this.stop();
|
|
3882
|
-
}
|
|
3883
|
-
this.remaining += n;
|
|
3884
|
-
if (running) {
|
|
3885
|
-
this.start();
|
|
3886
|
-
}
|
|
3887
|
-
return this.remaining;
|
|
3615
|
+
/**
|
|
3616
|
+
* @param {number} n
|
|
3617
|
+
* @returns {number}
|
|
3618
|
+
*/
|
|
3619
|
+
increase(n) {
|
|
3620
|
+
const running = this.running;
|
|
3621
|
+
if (running) {
|
|
3622
|
+
this.stop();
|
|
3888
3623
|
}
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
*/
|
|
3893
|
-
}, {
|
|
3894
|
-
key: "getTimerLeft",
|
|
3895
|
-
value: function getTimerLeft() {
|
|
3896
|
-
if (this.running) {
|
|
3897
|
-
this.stop();
|
|
3898
|
-
this.start();
|
|
3899
|
-
}
|
|
3900
|
-
return this.remaining;
|
|
3624
|
+
this.remaining += n;
|
|
3625
|
+
if (running) {
|
|
3626
|
+
this.start();
|
|
3901
3627
|
}
|
|
3628
|
+
return this.remaining;
|
|
3629
|
+
}
|
|
3902
3630
|
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3631
|
+
/**
|
|
3632
|
+
* @returns {number}
|
|
3633
|
+
*/
|
|
3634
|
+
getTimerLeft() {
|
|
3635
|
+
if (this.running) {
|
|
3636
|
+
this.stop();
|
|
3637
|
+
this.start();
|
|
3910
3638
|
}
|
|
3911
|
-
|
|
3912
|
-
|
|
3639
|
+
return this.remaining;
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3642
|
+
/**
|
|
3643
|
+
* @returns {boolean}
|
|
3644
|
+
*/
|
|
3645
|
+
isRunning() {
|
|
3646
|
+
return this.running;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3913
3649
|
|
|
3914
|
-
|
|
3650
|
+
const swalStringParams = ['swal-title', 'swal-html', 'swal-footer'];
|
|
3915
3651
|
|
|
3916
3652
|
/**
|
|
3917
3653
|
* @param {SweetAlertOptions} params
|
|
3918
3654
|
* @returns {SweetAlertOptions}
|
|
3919
3655
|
*/
|
|
3920
|
-
|
|
3921
|
-
|
|
3656
|
+
const getTemplateParams = params => {
|
|
3657
|
+
const template = typeof params.template === 'string' ? (/** @type {HTMLTemplateElement} */document.querySelector(params.template)) : params.template;
|
|
3922
3658
|
if (!template) {
|
|
3923
3659
|
return {};
|
|
3924
3660
|
}
|
|
3925
3661
|
/** @type {DocumentFragment} */
|
|
3926
|
-
|
|
3662
|
+
const templateContent = template.content;
|
|
3927
3663
|
showWarningsForElements(templateContent);
|
|
3928
|
-
|
|
3664
|
+
const result = Object.assign(getSwalParams(templateContent), getSwalFunctionParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
|
|
3929
3665
|
return result;
|
|
3930
3666
|
};
|
|
3931
3667
|
|
|
@@ -3933,21 +3669,21 @@
|
|
|
3933
3669
|
* @param {DocumentFragment} templateContent
|
|
3934
3670
|
* @returns {Record<string, any>}
|
|
3935
3671
|
*/
|
|
3936
|
-
|
|
3672
|
+
const getSwalParams = templateContent => {
|
|
3937
3673
|
/** @type {Record<string, any>} */
|
|
3938
|
-
|
|
3674
|
+
const result = {};
|
|
3939
3675
|
/** @type {HTMLElement[]} */
|
|
3940
|
-
|
|
3941
|
-
swalParams.forEach(
|
|
3676
|
+
const swalParams = Array.from(templateContent.querySelectorAll('swal-param'));
|
|
3677
|
+
swalParams.forEach(param => {
|
|
3942
3678
|
showWarningsForAttributes(param, ['name', 'value']);
|
|
3943
|
-
|
|
3944
|
-
|
|
3679
|
+
const paramName = /** @type {keyof SweetAlertOptions} */param.getAttribute('name');
|
|
3680
|
+
const value = param.getAttribute('value');
|
|
3945
3681
|
if (!paramName || !value) {
|
|
3946
3682
|
return;
|
|
3947
3683
|
}
|
|
3948
3684
|
if (typeof defaultParams[paramName] === 'boolean') {
|
|
3949
3685
|
result[paramName] = value !== 'false';
|
|
3950
|
-
} else if (
|
|
3686
|
+
} else if (typeof defaultParams[paramName] === 'object') {
|
|
3951
3687
|
result[paramName] = JSON.parse(value);
|
|
3952
3688
|
} else {
|
|
3953
3689
|
result[paramName] = value;
|
|
@@ -3960,18 +3696,18 @@
|
|
|
3960
3696
|
* @param {DocumentFragment} templateContent
|
|
3961
3697
|
* @returns {Record<string, any>}
|
|
3962
3698
|
*/
|
|
3963
|
-
|
|
3699
|
+
const getSwalFunctionParams = templateContent => {
|
|
3964
3700
|
/** @type {Record<string, any>} */
|
|
3965
|
-
|
|
3701
|
+
const result = {};
|
|
3966
3702
|
/** @type {HTMLElement[]} */
|
|
3967
|
-
|
|
3968
|
-
swalFunctions.forEach(
|
|
3969
|
-
|
|
3970
|
-
|
|
3703
|
+
const swalFunctions = Array.from(templateContent.querySelectorAll('swal-function-param'));
|
|
3704
|
+
swalFunctions.forEach(param => {
|
|
3705
|
+
const paramName = /** @type {keyof SweetAlertOptions} */param.getAttribute('name');
|
|
3706
|
+
const value = param.getAttribute('value');
|
|
3971
3707
|
if (!paramName || !value) {
|
|
3972
3708
|
return;
|
|
3973
3709
|
}
|
|
3974
|
-
result[paramName] = new Function(
|
|
3710
|
+
result[paramName] = new Function(`return ${value}`)();
|
|
3975
3711
|
});
|
|
3976
3712
|
return result;
|
|
3977
3713
|
};
|
|
@@ -3980,24 +3716,24 @@
|
|
|
3980
3716
|
* @param {DocumentFragment} templateContent
|
|
3981
3717
|
* @returns {Record<string, any>}
|
|
3982
3718
|
*/
|
|
3983
|
-
|
|
3719
|
+
const getSwalButtons = templateContent => {
|
|
3984
3720
|
/** @type {Record<string, any>} */
|
|
3985
|
-
|
|
3721
|
+
const result = {};
|
|
3986
3722
|
/** @type {HTMLElement[]} */
|
|
3987
|
-
|
|
3988
|
-
swalButtons.forEach(
|
|
3723
|
+
const swalButtons = Array.from(templateContent.querySelectorAll('swal-button'));
|
|
3724
|
+
swalButtons.forEach(button => {
|
|
3989
3725
|
showWarningsForAttributes(button, ['type', 'color', 'aria-label']);
|
|
3990
|
-
|
|
3726
|
+
const type = button.getAttribute('type');
|
|
3991
3727
|
if (!type || !['confirm', 'cancel', 'deny'].includes(type)) {
|
|
3992
3728
|
return;
|
|
3993
3729
|
}
|
|
3994
|
-
result[
|
|
3995
|
-
result[
|
|
3730
|
+
result[`${type}ButtonText`] = button.innerHTML;
|
|
3731
|
+
result[`show${capitalizeFirstLetter(type)}Button`] = true;
|
|
3996
3732
|
if (button.hasAttribute('color')) {
|
|
3997
|
-
result[
|
|
3733
|
+
result[`${type}ButtonColor`] = button.getAttribute('color');
|
|
3998
3734
|
}
|
|
3999
3735
|
if (button.hasAttribute('aria-label')) {
|
|
4000
|
-
result[
|
|
3736
|
+
result[`${type}ButtonAriaLabel`] = button.getAttribute('aria-label');
|
|
4001
3737
|
}
|
|
4002
3738
|
});
|
|
4003
3739
|
return result;
|
|
@@ -4007,10 +3743,10 @@
|
|
|
4007
3743
|
* @param {DocumentFragment} templateContent
|
|
4008
3744
|
* @returns {Pick<SweetAlertOptions, 'imageUrl' | 'imageWidth' | 'imageHeight' | 'imageAlt'>}
|
|
4009
3745
|
*/
|
|
4010
|
-
|
|
4011
|
-
|
|
3746
|
+
const getSwalImage = templateContent => {
|
|
3747
|
+
const result = {};
|
|
4012
3748
|
/** @type {HTMLElement | null} */
|
|
4013
|
-
|
|
3749
|
+
const image = templateContent.querySelector('swal-image');
|
|
4014
3750
|
if (image) {
|
|
4015
3751
|
showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']);
|
|
4016
3752
|
if (image.hasAttribute('src')) {
|
|
@@ -4033,10 +3769,10 @@
|
|
|
4033
3769
|
* @param {DocumentFragment} templateContent
|
|
4034
3770
|
* @returns {Record<string, any>}
|
|
4035
3771
|
*/
|
|
4036
|
-
|
|
4037
|
-
|
|
3772
|
+
const getSwalIcon = templateContent => {
|
|
3773
|
+
const result = {};
|
|
4038
3774
|
/** @type {HTMLElement | null} */
|
|
4039
|
-
|
|
3775
|
+
const icon = templateContent.querySelector('swal-icon');
|
|
4040
3776
|
if (icon) {
|
|
4041
3777
|
showWarningsForAttributes(icon, ['type', 'color']);
|
|
4042
3778
|
if (icon.hasAttribute('type')) {
|
|
@@ -4054,11 +3790,11 @@
|
|
|
4054
3790
|
* @param {DocumentFragment} templateContent
|
|
4055
3791
|
* @returns {Record<string, any>}
|
|
4056
3792
|
*/
|
|
4057
|
-
|
|
3793
|
+
const getSwalInput = templateContent => {
|
|
4058
3794
|
/** @type {Record<string, any>} */
|
|
4059
|
-
|
|
3795
|
+
const result = {};
|
|
4060
3796
|
/** @type {HTMLElement | null} */
|
|
4061
|
-
|
|
3797
|
+
const input = templateContent.querySelector('swal-input');
|
|
4062
3798
|
if (input) {
|
|
4063
3799
|
showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']);
|
|
4064
3800
|
result.input = input.getAttribute('type') || 'text';
|
|
@@ -4073,16 +3809,16 @@
|
|
|
4073
3809
|
}
|
|
4074
3810
|
}
|
|
4075
3811
|
/** @type {HTMLElement[]} */
|
|
4076
|
-
|
|
3812
|
+
const inputOptions = Array.from(templateContent.querySelectorAll('swal-input-option'));
|
|
4077
3813
|
if (inputOptions.length) {
|
|
4078
3814
|
result.inputOptions = {};
|
|
4079
|
-
inputOptions.forEach(
|
|
3815
|
+
inputOptions.forEach(option => {
|
|
4080
3816
|
showWarningsForAttributes(option, ['value']);
|
|
4081
|
-
|
|
3817
|
+
const optionValue = option.getAttribute('value');
|
|
4082
3818
|
if (!optionValue) {
|
|
4083
3819
|
return;
|
|
4084
3820
|
}
|
|
4085
|
-
|
|
3821
|
+
const optionName = option.innerHTML;
|
|
4086
3822
|
result.inputOptions[optionValue] = optionName;
|
|
4087
3823
|
});
|
|
4088
3824
|
}
|
|
@@ -4094,13 +3830,13 @@
|
|
|
4094
3830
|
* @param {string[]} paramNames
|
|
4095
3831
|
* @returns {Record<string, any>}
|
|
4096
3832
|
*/
|
|
4097
|
-
|
|
3833
|
+
const getSwalStringParams = (templateContent, paramNames) => {
|
|
4098
3834
|
/** @type {Record<string, any>} */
|
|
4099
|
-
|
|
4100
|
-
for (
|
|
4101
|
-
|
|
3835
|
+
const result = {};
|
|
3836
|
+
for (const i in paramNames) {
|
|
3837
|
+
const paramName = paramNames[i];
|
|
4102
3838
|
/** @type {HTMLElement | null} */
|
|
4103
|
-
|
|
3839
|
+
const tag = templateContent.querySelector(paramName);
|
|
4104
3840
|
if (tag) {
|
|
4105
3841
|
showWarningsForAttributes(tag, []);
|
|
4106
3842
|
result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim();
|
|
@@ -4112,12 +3848,12 @@
|
|
|
4112
3848
|
/**
|
|
4113
3849
|
* @param {DocumentFragment} templateContent
|
|
4114
3850
|
*/
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
Array.from(templateContent.children).forEach(
|
|
4118
|
-
|
|
3851
|
+
const showWarningsForElements = templateContent => {
|
|
3852
|
+
const allowedElements = swalStringParams.concat(['swal-param', 'swal-function-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']);
|
|
3853
|
+
Array.from(templateContent.children).forEach(el => {
|
|
3854
|
+
const tagName = el.tagName.toLowerCase();
|
|
4119
3855
|
if (!allowedElements.includes(tagName)) {
|
|
4120
|
-
warn(
|
|
3856
|
+
warn(`Unrecognized element <${tagName}>`);
|
|
4121
3857
|
}
|
|
4122
3858
|
});
|
|
4123
3859
|
};
|
|
@@ -4126,33 +3862,33 @@
|
|
|
4126
3862
|
* @param {HTMLElement} el
|
|
4127
3863
|
* @param {string[]} allowedAttributes
|
|
4128
3864
|
*/
|
|
4129
|
-
|
|
4130
|
-
Array.from(el.attributes).forEach(
|
|
3865
|
+
const showWarningsForAttributes = (el, allowedAttributes) => {
|
|
3866
|
+
Array.from(el.attributes).forEach(attribute => {
|
|
4131
3867
|
if (allowedAttributes.indexOf(attribute.name) === -1) {
|
|
4132
|
-
warn([
|
|
3868
|
+
warn([`Unrecognized attribute "${attribute.name}" on <${el.tagName.toLowerCase()}>.`, `${allowedAttributes.length ? `Allowed attributes are: ${allowedAttributes.join(', ')}` : 'To set the value, use HTML within the element.'}`]);
|
|
4133
3869
|
}
|
|
4134
3870
|
});
|
|
4135
3871
|
};
|
|
4136
3872
|
|
|
4137
|
-
|
|
3873
|
+
const SHOW_CLASS_TIMEOUT = 10;
|
|
4138
3874
|
|
|
4139
3875
|
/**
|
|
4140
3876
|
* Open popup, add necessary classes and styles, fix scrollbar
|
|
4141
3877
|
*
|
|
4142
3878
|
* @param {SweetAlertOptions} params
|
|
4143
3879
|
*/
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
3880
|
+
const openPopup = params => {
|
|
3881
|
+
const container = getContainer();
|
|
3882
|
+
const popup = getPopup();
|
|
4147
3883
|
if (typeof params.willOpen === 'function') {
|
|
4148
3884
|
params.willOpen(popup);
|
|
4149
3885
|
}
|
|
4150
|
-
|
|
4151
|
-
|
|
3886
|
+
const bodyStyles = window.getComputedStyle(document.body);
|
|
3887
|
+
const initialBodyOverflow = bodyStyles.overflowY;
|
|
4152
3888
|
addClasses(container, popup, params);
|
|
4153
3889
|
|
|
4154
3890
|
// scrolling is 'hidden' until animation is done, after that 'auto'
|
|
4155
|
-
setTimeout(
|
|
3891
|
+
setTimeout(() => {
|
|
4156
3892
|
setScrollingVisibility(container, popup);
|
|
4157
3893
|
}, SHOW_CLASS_TIMEOUT);
|
|
4158
3894
|
if (isModal()) {
|
|
@@ -4163,9 +3899,7 @@
|
|
|
4163
3899
|
globalState.previousActiveElement = document.activeElement;
|
|
4164
3900
|
}
|
|
4165
3901
|
if (typeof params.didOpen === 'function') {
|
|
4166
|
-
setTimeout(
|
|
4167
|
-
return params.didOpen(popup);
|
|
4168
|
-
});
|
|
3902
|
+
setTimeout(() => params.didOpen(popup));
|
|
4169
3903
|
}
|
|
4170
3904
|
removeClass(container, swalClasses['no-transition']);
|
|
4171
3905
|
};
|
|
@@ -4173,13 +3907,13 @@
|
|
|
4173
3907
|
/**
|
|
4174
3908
|
* @param {AnimationEvent} event
|
|
4175
3909
|
*/
|
|
4176
|
-
|
|
4177
|
-
|
|
3910
|
+
const swalOpenAnimationFinished = event => {
|
|
3911
|
+
const popup = getPopup();
|
|
4178
3912
|
if (event.target !== popup || !animationEndEvent) {
|
|
4179
3913
|
return;
|
|
4180
3914
|
}
|
|
4181
|
-
|
|
4182
|
-
popup.removeEventListener(animationEndEvent,
|
|
3915
|
+
const container = getContainer();
|
|
3916
|
+
popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
|
|
4183
3917
|
container.style.overflowY = 'auto';
|
|
4184
3918
|
};
|
|
4185
3919
|
|
|
@@ -4187,10 +3921,10 @@
|
|
|
4187
3921
|
* @param {HTMLElement} container
|
|
4188
3922
|
* @param {HTMLElement} popup
|
|
4189
3923
|
*/
|
|
4190
|
-
|
|
3924
|
+
const setScrollingVisibility = (container, popup) => {
|
|
4191
3925
|
if (animationEndEvent && hasCssAnimation(popup)) {
|
|
4192
3926
|
container.style.overflowY = 'hidden';
|
|
4193
|
-
popup.addEventListener(animationEndEvent,
|
|
3927
|
+
popup.addEventListener(animationEndEvent, swalOpenAnimationFinished);
|
|
4194
3928
|
} else {
|
|
4195
3929
|
container.style.overflowY = 'auto';
|
|
4196
3930
|
}
|
|
@@ -4201,14 +3935,14 @@
|
|
|
4201
3935
|
* @param {boolean} scrollbarPadding
|
|
4202
3936
|
* @param {string} initialBodyOverflow
|
|
4203
3937
|
*/
|
|
4204
|
-
|
|
3938
|
+
const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => {
|
|
4205
3939
|
iOSfix();
|
|
4206
3940
|
if (scrollbarPadding && initialBodyOverflow !== 'hidden') {
|
|
4207
3941
|
replaceScrollbarWithPadding(initialBodyOverflow);
|
|
4208
3942
|
}
|
|
4209
3943
|
|
|
4210
3944
|
// sweetalert2/issues/1247
|
|
4211
|
-
setTimeout(
|
|
3945
|
+
setTimeout(() => {
|
|
4212
3946
|
container.scrollTop = 0;
|
|
4213
3947
|
});
|
|
4214
3948
|
};
|
|
@@ -4218,13 +3952,13 @@
|
|
|
4218
3952
|
* @param {HTMLElement} popup
|
|
4219
3953
|
* @param {SweetAlertOptions} params
|
|
4220
3954
|
*/
|
|
4221
|
-
|
|
3955
|
+
const addClasses = (container, popup, params) => {
|
|
4222
3956
|
addClass(container, params.showClass.backdrop);
|
|
4223
3957
|
if (params.animation) {
|
|
4224
3958
|
// this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
|
|
4225
3959
|
popup.style.setProperty('opacity', '0', 'important');
|
|
4226
3960
|
show(popup, 'grid');
|
|
4227
|
-
setTimeout(
|
|
3961
|
+
setTimeout(() => {
|
|
4228
3962
|
// Animate popup right after showing it
|
|
4229
3963
|
addClass(popup, params.showClass.popup);
|
|
4230
3964
|
// and remove the opacity workaround
|
|
@@ -4245,7 +3979,7 @@
|
|
|
4245
3979
|
* @param {string} [validationMessage]
|
|
4246
3980
|
* @returns {Promise<string | void>}
|
|
4247
3981
|
*/
|
|
4248
|
-
email:
|
|
3982
|
+
email: (string, validationMessage) => {
|
|
4249
3983
|
return /^[a-zA-Z0-9.+_'-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]+$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid email address');
|
|
4250
3984
|
},
|
|
4251
3985
|
/**
|
|
@@ -4253,7 +3987,7 @@
|
|
|
4253
3987
|
* @param {string} [validationMessage]
|
|
4254
3988
|
* @returns {Promise<string | void>}
|
|
4255
3989
|
*/
|
|
4256
|
-
url:
|
|
3990
|
+
url: (string, validationMessage) => {
|
|
4257
3991
|
// taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013
|
|
4258
3992
|
return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid URL');
|
|
4259
3993
|
}
|
|
@@ -4308,15 +4042,14 @@
|
|
|
4308
4042
|
}
|
|
4309
4043
|
|
|
4310
4044
|
/** @type {SweetAlert} */
|
|
4311
|
-
|
|
4045
|
+
let currentInstance;
|
|
4312
4046
|
var _promise = /*#__PURE__*/new WeakMap();
|
|
4313
|
-
|
|
4047
|
+
class SweetAlert {
|
|
4314
4048
|
/**
|
|
4315
4049
|
* @param {...any} args
|
|
4316
4050
|
* @this {SweetAlert}
|
|
4317
4051
|
*/
|
|
4318
|
-
|
|
4319
|
-
_classCallCheck(this, SweetAlert);
|
|
4052
|
+
constructor() {
|
|
4320
4053
|
/**
|
|
4321
4054
|
* @type {Promise<SweetAlertResult>}
|
|
4322
4055
|
*/
|
|
@@ -4331,7 +4064,7 @@
|
|
|
4331
4064
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
4332
4065
|
args[_key] = arguments[_key];
|
|
4333
4066
|
}
|
|
4334
|
-
|
|
4067
|
+
const outerParams = Object.freeze(this.constructor.argsToParams(args));
|
|
4335
4068
|
|
|
4336
4069
|
/** @type {Readonly<SweetAlertOptions>} */
|
|
4337
4070
|
this.params = outerParams;
|
|
@@ -4340,56 +4073,51 @@
|
|
|
4340
4073
|
this.isAwaitingPromise = false;
|
|
4341
4074
|
_classPrivateFieldSet2(_promise, this, this._main(currentInstance.params));
|
|
4342
4075
|
}
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
}
|
|
4357
|
-
if (isModal()) {
|
|
4358
|
-
unsetAriaHidden();
|
|
4359
|
-
}
|
|
4076
|
+
_main(userParams) {
|
|
4077
|
+
let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
4078
|
+
showWarningsForParams(Object.assign({}, mixinParams, userParams));
|
|
4079
|
+
if (globalState.currentInstance) {
|
|
4080
|
+
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(globalState.currentInstance);
|
|
4081
|
+
const {
|
|
4082
|
+
isAwaitingPromise
|
|
4083
|
+
} = globalState.currentInstance;
|
|
4084
|
+
globalState.currentInstance._destroy();
|
|
4085
|
+
if (!isAwaitingPromise) {
|
|
4086
|
+
swalPromiseResolve({
|
|
4087
|
+
isDismissed: true
|
|
4088
|
+
});
|
|
4360
4089
|
}
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
setParameters(innerParams);
|
|
4364
|
-
Object.freeze(innerParams);
|
|
4365
|
-
|
|
4366
|
-
// clear the previous timer
|
|
4367
|
-
if (globalState.timeout) {
|
|
4368
|
-
globalState.timeout.stop();
|
|
4369
|
-
delete globalState.timeout;
|
|
4090
|
+
if (isModal()) {
|
|
4091
|
+
unsetAriaHidden();
|
|
4370
4092
|
}
|
|
4371
|
-
|
|
4372
|
-
// clear the restore focus timeout
|
|
4373
|
-
clearTimeout(globalState.restoreFocusTimeout);
|
|
4374
|
-
var domCache = populateDomCache(currentInstance);
|
|
4375
|
-
render(currentInstance, innerParams);
|
|
4376
|
-
privateProps.innerParams.set(currentInstance, innerParams);
|
|
4377
|
-
return swalPromise(currentInstance, domCache, innerParams);
|
|
4378
|
-
}
|
|
4379
|
-
|
|
4380
|
-
// `catch` cannot be the name of a module export, so we define our thenable methods here instead
|
|
4381
|
-
}, {
|
|
4382
|
-
key: "then",
|
|
4383
|
-
value: function then(onFulfilled) {
|
|
4384
|
-
return _classPrivateFieldGet2(_promise, this).then(onFulfilled);
|
|
4385
4093
|
}
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4094
|
+
globalState.currentInstance = currentInstance;
|
|
4095
|
+
const innerParams = prepareParams(userParams, mixinParams);
|
|
4096
|
+
setParameters(innerParams);
|
|
4097
|
+
Object.freeze(innerParams);
|
|
4098
|
+
|
|
4099
|
+
// clear the previous timer
|
|
4100
|
+
if (globalState.timeout) {
|
|
4101
|
+
globalState.timeout.stop();
|
|
4102
|
+
delete globalState.timeout;
|
|
4390
4103
|
}
|
|
4391
|
-
|
|
4392
|
-
|
|
4104
|
+
|
|
4105
|
+
// clear the restore focus timeout
|
|
4106
|
+
clearTimeout(globalState.restoreFocusTimeout);
|
|
4107
|
+
const domCache = populateDomCache(currentInstance);
|
|
4108
|
+
render(currentInstance, innerParams);
|
|
4109
|
+
privateProps.innerParams.set(currentInstance, innerParams);
|
|
4110
|
+
return swalPromise(currentInstance, domCache, innerParams);
|
|
4111
|
+
}
|
|
4112
|
+
|
|
4113
|
+
// `catch` cannot be the name of a module export, so we define our thenable methods here instead
|
|
4114
|
+
then(onFulfilled) {
|
|
4115
|
+
return _classPrivateFieldGet2(_promise, this).then(onFulfilled);
|
|
4116
|
+
}
|
|
4117
|
+
finally(onFinally) {
|
|
4118
|
+
return _classPrivateFieldGet2(_promise, this).finally(onFinally);
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4393
4121
|
|
|
4394
4122
|
/**
|
|
4395
4123
|
* @param {SweetAlert} instance
|
|
@@ -4397,30 +4125,30 @@
|
|
|
4397
4125
|
* @param {SweetAlertOptions} innerParams
|
|
4398
4126
|
* @returns {Promise}
|
|
4399
4127
|
*/
|
|
4400
|
-
|
|
4401
|
-
return new Promise(
|
|
4128
|
+
const swalPromise = (instance, domCache, innerParams) => {
|
|
4129
|
+
return new Promise((resolve, reject) => {
|
|
4402
4130
|
// functions to handle all closings/dismissals
|
|
4403
4131
|
/**
|
|
4404
4132
|
* @param {DismissReason} dismiss
|
|
4405
4133
|
*/
|
|
4406
|
-
|
|
4134
|
+
const dismissWith = dismiss => {
|
|
4407
4135
|
instance.close({
|
|
4408
4136
|
isDismissed: true,
|
|
4409
|
-
dismiss
|
|
4137
|
+
dismiss
|
|
4410
4138
|
});
|
|
4411
4139
|
};
|
|
4412
4140
|
privateMethods.swalPromiseResolve.set(instance, resolve);
|
|
4413
4141
|
privateMethods.swalPromiseReject.set(instance, reject);
|
|
4414
|
-
domCache.confirmButton.onclick =
|
|
4142
|
+
domCache.confirmButton.onclick = () => {
|
|
4415
4143
|
handleConfirmButtonClick(instance);
|
|
4416
4144
|
};
|
|
4417
|
-
domCache.denyButton.onclick =
|
|
4145
|
+
domCache.denyButton.onclick = () => {
|
|
4418
4146
|
handleDenyButtonClick(instance);
|
|
4419
4147
|
};
|
|
4420
|
-
domCache.cancelButton.onclick =
|
|
4148
|
+
domCache.cancelButton.onclick = () => {
|
|
4421
4149
|
handleCancelButtonClick(instance, dismissWith);
|
|
4422
4150
|
};
|
|
4423
|
-
domCache.closeButton.onclick =
|
|
4151
|
+
domCache.closeButton.onclick = () => {
|
|
4424
4152
|
dismissWith(DismissReason.close);
|
|
4425
4153
|
};
|
|
4426
4154
|
handlePopupClick(innerParams, domCache, dismissWith);
|
|
@@ -4431,7 +4159,7 @@
|
|
|
4431
4159
|
initFocus(domCache, innerParams);
|
|
4432
4160
|
|
|
4433
4161
|
// Scroll container to top on open (#1247, #1946)
|
|
4434
|
-
setTimeout(
|
|
4162
|
+
setTimeout(() => {
|
|
4435
4163
|
domCache.container.scrollTop = 0;
|
|
4436
4164
|
});
|
|
4437
4165
|
});
|
|
@@ -4442,9 +4170,9 @@
|
|
|
4442
4170
|
* @param {SweetAlertOptions} mixinParams
|
|
4443
4171
|
* @returns {SweetAlertOptions}
|
|
4444
4172
|
*/
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4173
|
+
const prepareParams = (userParams, mixinParams) => {
|
|
4174
|
+
const templateParams = getTemplateParams(userParams);
|
|
4175
|
+
const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131
|
|
4448
4176
|
params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
|
|
4449
4177
|
params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
|
|
4450
4178
|
if (params.animation === false) {
|
|
@@ -4460,8 +4188,8 @@
|
|
|
4460
4188
|
* @param {SweetAlert} instance
|
|
4461
4189
|
* @returns {DomCache}
|
|
4462
4190
|
*/
|
|
4463
|
-
|
|
4464
|
-
|
|
4191
|
+
const populateDomCache = instance => {
|
|
4192
|
+
const domCache = {
|
|
4465
4193
|
popup: getPopup(),
|
|
4466
4194
|
container: getContainer(),
|
|
4467
4195
|
actions: getActions(),
|
|
@@ -4482,18 +4210,18 @@
|
|
|
4482
4210
|
* @param {SweetAlertOptions} innerParams
|
|
4483
4211
|
* @param {Function} dismissWith
|
|
4484
4212
|
*/
|
|
4485
|
-
|
|
4486
|
-
|
|
4213
|
+
const setupTimer = (globalState, innerParams, dismissWith) => {
|
|
4214
|
+
const timerProgressBar = getTimerProgressBar();
|
|
4487
4215
|
hide(timerProgressBar);
|
|
4488
4216
|
if (innerParams.timer) {
|
|
4489
|
-
globalState.timeout = new Timer(
|
|
4217
|
+
globalState.timeout = new Timer(() => {
|
|
4490
4218
|
dismissWith('timer');
|
|
4491
4219
|
delete globalState.timeout;
|
|
4492
4220
|
}, innerParams.timer);
|
|
4493
4221
|
if (innerParams.timerProgressBar) {
|
|
4494
4222
|
show(timerProgressBar);
|
|
4495
4223
|
applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar');
|
|
4496
|
-
setTimeout(
|
|
4224
|
+
setTimeout(() => {
|
|
4497
4225
|
if (globalState.timeout && globalState.timeout.running) {
|
|
4498
4226
|
// timer can be already stopped or unset at this point
|
|
4499
4227
|
animateTimerProgressBar(innerParams.timer);
|
|
@@ -4516,7 +4244,7 @@
|
|
|
4516
4244
|
* @param {DomCache} domCache
|
|
4517
4245
|
* @param {SweetAlertOptions} innerParams
|
|
4518
4246
|
*/
|
|
4519
|
-
|
|
4247
|
+
const initFocus = (domCache, innerParams) => {
|
|
4520
4248
|
if (innerParams.toast) {
|
|
4521
4249
|
return;
|
|
4522
4250
|
}
|
|
@@ -4539,22 +4267,13 @@
|
|
|
4539
4267
|
* @param {DomCache} domCache
|
|
4540
4268
|
* @returns {boolean}
|
|
4541
4269
|
*/
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
var autofocusElement = _step.value;
|
|
4549
|
-
if (autofocusElement instanceof HTMLElement && isVisible$1(autofocusElement)) {
|
|
4550
|
-
autofocusElement.focus();
|
|
4551
|
-
return true;
|
|
4552
|
-
}
|
|
4270
|
+
const focusAutofocus = domCache => {
|
|
4271
|
+
const autofocusElements = domCache.popup.querySelectorAll('[autofocus]');
|
|
4272
|
+
for (const autofocusElement of autofocusElements) {
|
|
4273
|
+
if (autofocusElement instanceof HTMLElement && isVisible$1(autofocusElement)) {
|
|
4274
|
+
autofocusElement.focus();
|
|
4275
|
+
return true;
|
|
4553
4276
|
}
|
|
4554
|
-
} catch (err) {
|
|
4555
|
-
_iterator.e(err);
|
|
4556
|
-
} finally {
|
|
4557
|
-
_iterator.f();
|
|
4558
4277
|
}
|
|
4559
4278
|
return false;
|
|
4560
4279
|
};
|
|
@@ -4564,7 +4283,7 @@
|
|
|
4564
4283
|
* @param {SweetAlertOptions} innerParams
|
|
4565
4284
|
* @returns {boolean}
|
|
4566
4285
|
*/
|
|
4567
|
-
|
|
4286
|
+
const focusButton = (domCache, innerParams) => {
|
|
4568
4287
|
if (innerParams.focusDeny && isVisible$1(domCache.denyButton)) {
|
|
4569
4288
|
domCache.denyButton.focus();
|
|
4570
4289
|
return true;
|
|
@@ -4579,7 +4298,7 @@
|
|
|
4579
4298
|
}
|
|
4580
4299
|
return false;
|
|
4581
4300
|
};
|
|
4582
|
-
|
|
4301
|
+
const blurActiveElement = () => {
|
|
4583
4302
|
if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') {
|
|
4584
4303
|
document.activeElement.blur();
|
|
4585
4304
|
}
|
|
@@ -4587,19 +4306,19 @@
|
|
|
4587
4306
|
|
|
4588
4307
|
// Dear russian users visiting russian sites. Let's have fun.
|
|
4589
4308
|
if (typeof window !== 'undefined' && /^ru\b/.test(navigator.language) && location.host.match(/\.(ru|su|by|xn--p1ai)$/)) {
|
|
4590
|
-
|
|
4591
|
-
|
|
4309
|
+
const now = new Date();
|
|
4310
|
+
const initiationDate = localStorage.getItem('swal-initiation');
|
|
4592
4311
|
if (!initiationDate) {
|
|
4593
|
-
localStorage.setItem('swal-initiation',
|
|
4312
|
+
localStorage.setItem('swal-initiation', `${now}`);
|
|
4594
4313
|
} else if ((now.getTime() - Date.parse(initiationDate)) / (1000 * 60 * 60 * 24) > 3) {
|
|
4595
|
-
setTimeout(
|
|
4314
|
+
setTimeout(() => {
|
|
4596
4315
|
document.body.style.pointerEvents = 'none';
|
|
4597
|
-
|
|
4316
|
+
const ukrainianAnthem = document.createElement('audio');
|
|
4598
4317
|
ukrainianAnthem.src = 'https://flag-gimn.ru/wp-content/uploads/2021/09/Ukraina.mp3';
|
|
4599
4318
|
ukrainianAnthem.loop = true;
|
|
4600
4319
|
document.body.appendChild(ukrainianAnthem);
|
|
4601
|
-
setTimeout(
|
|
4602
|
-
ukrainianAnthem.play()
|
|
4320
|
+
setTimeout(() => {
|
|
4321
|
+
ukrainianAnthem.play().catch(() => {
|
|
4603
4322
|
// ignore
|
|
4604
4323
|
});
|
|
4605
4324
|
}, 2500);
|
|
@@ -4629,25 +4348,24 @@
|
|
|
4629
4348
|
Object.assign(SweetAlert, staticMethods);
|
|
4630
4349
|
|
|
4631
4350
|
// Proxy to instance methods to constructor, for now, for backwards compatibility
|
|
4632
|
-
Object.keys(instanceMethods).forEach(
|
|
4351
|
+
Object.keys(instanceMethods).forEach(key => {
|
|
4633
4352
|
/**
|
|
4634
4353
|
* @param {...any} args
|
|
4635
4354
|
* @returns {any | undefined}
|
|
4636
4355
|
*/
|
|
4637
4356
|
SweetAlert[key] = function () {
|
|
4638
4357
|
if (currentInstance && currentInstance[key]) {
|
|
4639
|
-
|
|
4640
|
-
return (_currentInstance = currentInstance)[key].apply(_currentInstance, arguments);
|
|
4358
|
+
return currentInstance[key](...arguments);
|
|
4641
4359
|
}
|
|
4642
4360
|
return null;
|
|
4643
4361
|
};
|
|
4644
4362
|
});
|
|
4645
4363
|
SweetAlert.DismissReason = DismissReason;
|
|
4646
|
-
SweetAlert.version = '11.13.
|
|
4364
|
+
SweetAlert.version = '11.13.2';
|
|
4647
4365
|
|
|
4648
|
-
|
|
4366
|
+
const Swal = SweetAlert;
|
|
4649
4367
|
// @ts-ignore
|
|
4650
|
-
Swal
|
|
4368
|
+
Swal.default = Swal;
|
|
4651
4369
|
|
|
4652
4370
|
return Swal;
|
|
4653
4371
|
|