sweetalert2 11.4.3 → 11.4.4
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/CHANGELOG.md +7 -0
- package/dist/sweetalert2.all.js +780 -778
- package/dist/sweetalert2.all.min.js +1 -1
- package/dist/sweetalert2.js +780 -778
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +1 -1
- package/src/SweetAlert.js +1 -1
- package/src/buttons-handlers.js +3 -0
- package/src/instanceMethods/close.js +1 -1
package/dist/sweetalert2.all.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sweetalert2 v11.4.
|
|
2
|
+
* sweetalert2 v11.4.4
|
|
3
3
|
* Released under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -2190,1005 +2190,1007 @@
|
|
|
2190
2190
|
return inputValue && inputValue.toString() === optionValue.toString();
|
|
2191
2191
|
};
|
|
2192
2192
|
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2193
|
+
/**
|
|
2194
|
+
* Hides loader and shows back the button which was hidden by .showLoading()
|
|
2195
|
+
*/
|
|
2196
2196
|
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2197
|
+
function hideLoading() {
|
|
2198
|
+
// do nothing if popup is closed
|
|
2199
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
2200
|
+
|
|
2201
|
+
if (!innerParams) {
|
|
2202
|
+
return;
|
|
2201
2203
|
}
|
|
2202
|
-
};
|
|
2203
|
-
const handleDenyButtonClick = instance => {
|
|
2204
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
2205
|
-
instance.disableButtons();
|
|
2206
2204
|
|
|
2207
|
-
|
|
2208
|
-
|
|
2205
|
+
const domCache = privateProps.domCache.get(this);
|
|
2206
|
+
hide(domCache.loader);
|
|
2207
|
+
|
|
2208
|
+
if (isToast()) {
|
|
2209
|
+
if (innerParams.icon) {
|
|
2210
|
+
show(getIcon());
|
|
2211
|
+
}
|
|
2209
2212
|
} else {
|
|
2210
|
-
|
|
2213
|
+
showRelatedButton(domCache);
|
|
2211
2214
|
}
|
|
2212
|
-
};
|
|
2213
|
-
const handleCancelButtonClick = (instance, dismissWith) => {
|
|
2214
|
-
instance.disableButtons();
|
|
2215
|
-
dismissWith(DismissReason.cancel);
|
|
2216
|
-
};
|
|
2217
2215
|
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2216
|
+
removeClass([domCache.popup, domCache.actions], swalClasses.loading);
|
|
2217
|
+
domCache.popup.removeAttribute('aria-busy');
|
|
2218
|
+
domCache.popup.removeAttribute('data-loading');
|
|
2219
|
+
domCache.confirmButton.disabled = false;
|
|
2220
|
+
domCache.denyButton.disabled = false;
|
|
2221
|
+
domCache.cancelButton.disabled = false;
|
|
2222
|
+
}
|
|
2222
2223
|
|
|
2223
|
-
|
|
2224
|
-
|
|
2224
|
+
const showRelatedButton = domCache => {
|
|
2225
|
+
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
2226
|
+
|
|
2227
|
+
if (buttonToReplace.length) {
|
|
2228
|
+
show(buttonToReplace[0], 'inline-block');
|
|
2229
|
+
} else if (allButtonsAreHidden()) {
|
|
2230
|
+
hide(domCache.actions);
|
|
2225
2231
|
}
|
|
2232
|
+
};
|
|
2226
2233
|
|
|
2227
|
-
|
|
2234
|
+
/**
|
|
2235
|
+
* Gets the input DOM node, this method works with input parameter.
|
|
2236
|
+
* @returns {HTMLElement | null}
|
|
2237
|
+
*/
|
|
2228
2238
|
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
deny(instance, inputValue);
|
|
2236
|
-
} else {
|
|
2237
|
-
confirm(instance, inputValue);
|
|
2239
|
+
function getInput$1(instance) {
|
|
2240
|
+
const innerParams = privateProps.innerParams.get(instance || this);
|
|
2241
|
+
const domCache = privateProps.domCache.get(instance || this);
|
|
2242
|
+
|
|
2243
|
+
if (!domCache) {
|
|
2244
|
+
return null;
|
|
2238
2245
|
}
|
|
2239
|
-
};
|
|
2240
2246
|
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
) => {
|
|
2244
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
2245
|
-
instance.disableInput();
|
|
2246
|
-
const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
|
|
2247
|
-
validationPromise.then(validationMessage => {
|
|
2248
|
-
instance.enableButtons();
|
|
2249
|
-
instance.enableInput();
|
|
2247
|
+
return getInput(domCache.popup, innerParams.input);
|
|
2248
|
+
}
|
|
2250
2249
|
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2250
|
+
/**
|
|
2251
|
+
* This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
|
|
2252
|
+
* For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
|
|
2253
|
+
* This is the approach that Babel will probably take to implement private methods/fields
|
|
2254
|
+
* https://github.com/tc39/proposal-private-methods
|
|
2255
|
+
* https://github.com/babel/babel/pull/7555
|
|
2256
|
+
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
2257
|
+
* then we can use that language feature.
|
|
2258
|
+
*/
|
|
2259
|
+
var privateMethods = {
|
|
2260
|
+
swalPromiseResolve: new WeakMap(),
|
|
2261
|
+
swalPromiseReject: new WeakMap()
|
|
2259
2262
|
};
|
|
2260
2263
|
|
|
2261
|
-
|
|
2262
|
-
|
|
2264
|
+
/*
|
|
2265
|
+
* Instance method to close sweetAlert
|
|
2266
|
+
*/
|
|
2263
2267
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2268
|
+
function removePopupAndResetState(instance, container, returnFocus, didClose) {
|
|
2269
|
+
if (isToast()) {
|
|
2270
|
+
triggerDidCloseAndDispose(instance, didClose);
|
|
2271
|
+
} else {
|
|
2272
|
+
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
2273
|
+
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
2274
|
+
capture: globalState.keydownListenerCapture
|
|
2275
|
+
});
|
|
2276
|
+
globalState.keydownHandlerAdded = false;
|
|
2266
2277
|
}
|
|
2267
2278
|
|
|
2268
|
-
|
|
2269
|
-
|
|
2279
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // workaround for #2088
|
|
2280
|
+
// for some reason removing the container in Safari will scroll the document to bottom
|
|
2270
2281
|
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
} else {
|
|
2276
|
-
instance.closePopup({
|
|
2277
|
-
isDenied: true,
|
|
2278
|
-
value: typeof preDenyValue === 'undefined' ? value : preDenyValue
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
|
-
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2282
|
+
if (isSafari) {
|
|
2283
|
+
container.setAttribute('style', 'display:none !important');
|
|
2284
|
+
container.removeAttribute('class');
|
|
2285
|
+
container.innerHTML = '';
|
|
2282
2286
|
} else {
|
|
2283
|
-
|
|
2284
|
-
isDenied: true,
|
|
2285
|
-
value
|
|
2286
|
-
});
|
|
2287
|
+
container.remove();
|
|
2287
2288
|
}
|
|
2288
|
-
};
|
|
2289
2289
|
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
}
|
|
2295
|
-
};
|
|
2290
|
+
if (isModal()) {
|
|
2291
|
+
undoScrollbar();
|
|
2292
|
+
undoIOSfix();
|
|
2293
|
+
unsetAriaHidden();
|
|
2294
|
+
}
|
|
2296
2295
|
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
};
|
|
2296
|
+
removeBodyClasses();
|
|
2297
|
+
}
|
|
2300
2298
|
|
|
2301
|
-
|
|
2302
|
-
|
|
2299
|
+
function removeBodyClasses() {
|
|
2300
|
+
removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
|
|
2301
|
+
}
|
|
2303
2302
|
|
|
2304
|
-
|
|
2305
|
-
|
|
2303
|
+
function close(resolveValue) {
|
|
2304
|
+
resolveValue = prepareResolveValue(resolveValue);
|
|
2305
|
+
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
2306
|
+
const didClose = triggerClosePopup(this);
|
|
2307
|
+
|
|
2308
|
+
if (this.isAwaitingPromise()) {
|
|
2309
|
+
// A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
|
|
2310
|
+
if (!resolveValue.isDismissed) {
|
|
2311
|
+
handleAwaitingPromise(this);
|
|
2312
|
+
swalPromiseResolve(resolveValue);
|
|
2313
|
+
}
|
|
2314
|
+
} else if (didClose) {
|
|
2315
|
+
// Resolve Swal promise
|
|
2316
|
+
swalPromiseResolve(resolveValue);
|
|
2306
2317
|
}
|
|
2318
|
+
}
|
|
2319
|
+
function isAwaitingPromise() {
|
|
2320
|
+
return !!privateProps.awaitingPromise.get(this);
|
|
2321
|
+
}
|
|
2307
2322
|
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
privateProps.awaitingPromise.set(instance || undefined, 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
|
|
2323
|
+
const triggerClosePopup = instance => {
|
|
2324
|
+
const popup = getPopup();
|
|
2311
2325
|
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
if (isVisible(getValidationMessage()) || preConfirmValue === false) {
|
|
2315
|
-
instance.hideLoading();
|
|
2316
|
-
} else {
|
|
2317
|
-
succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
|
|
2318
|
-
}
|
|
2319
|
-
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2320
|
-
} else {
|
|
2321
|
-
succeedWith(instance, value);
|
|
2326
|
+
if (!popup) {
|
|
2327
|
+
return false;
|
|
2322
2328
|
}
|
|
2323
|
-
};
|
|
2324
2329
|
|
|
2325
|
-
const handlePopupClick = (instance, domCache, dismissWith) => {
|
|
2326
2330
|
const innerParams = privateProps.innerParams.get(instance);
|
|
2327
2331
|
|
|
2328
|
-
if (innerParams.
|
|
2329
|
-
|
|
2330
|
-
} else {
|
|
2331
|
-
// Ignore click events that had mousedown on the popup but mouseup on the container
|
|
2332
|
-
// This can happen when the user drags a slider
|
|
2333
|
-
handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
|
|
2334
|
-
|
|
2335
|
-
handleContainerMousedown(domCache);
|
|
2336
|
-
handleModalClick(instance, domCache, dismissWith);
|
|
2332
|
+
if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
|
|
2333
|
+
return false;
|
|
2337
2334
|
}
|
|
2335
|
+
|
|
2336
|
+
removeClass(popup, innerParams.showClass.popup);
|
|
2337
|
+
addClass(popup, innerParams.hideClass.popup);
|
|
2338
|
+
const backdrop = getContainer();
|
|
2339
|
+
removeClass(backdrop, innerParams.showClass.backdrop);
|
|
2340
|
+
addClass(backdrop, innerParams.hideClass.backdrop);
|
|
2341
|
+
handlePopupAnimation(instance, popup, innerParams);
|
|
2342
|
+
return true;
|
|
2338
2343
|
};
|
|
2339
2344
|
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
2345
|
+
function rejectPromise(error) {
|
|
2346
|
+
const rejectPromise = privateMethods.swalPromiseReject.get(this);
|
|
2347
|
+
handleAwaitingPromise(this);
|
|
2344
2348
|
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2349
|
+
if (rejectPromise) {
|
|
2350
|
+
// Reject Swal promise
|
|
2351
|
+
rejectPromise(error);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
const handleAwaitingPromise = instance => {
|
|
2355
|
+
if (instance.isAwaitingPromise()) {
|
|
2356
|
+
privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
|
|
2348
2357
|
|
|
2349
|
-
|
|
2350
|
-
|
|
2358
|
+
if (!privateProps.innerParams.get(instance)) {
|
|
2359
|
+
instance._destroy();
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2351
2362
|
};
|
|
2352
|
-
/**
|
|
2353
|
-
* @param {*} innerParams
|
|
2354
|
-
* @returns {boolean}
|
|
2355
|
-
*/
|
|
2356
2363
|
|
|
2364
|
+
const prepareResolveValue = resolveValue => {
|
|
2365
|
+
// When user calls Swal.close()
|
|
2366
|
+
if (typeof resolveValue === 'undefined') {
|
|
2367
|
+
return {
|
|
2368
|
+
isConfirmed: false,
|
|
2369
|
+
isDenied: false,
|
|
2370
|
+
isDismissed: true
|
|
2371
|
+
};
|
|
2372
|
+
}
|
|
2357
2373
|
|
|
2358
|
-
|
|
2359
|
-
|
|
2374
|
+
return Object.assign({
|
|
2375
|
+
isConfirmed: false,
|
|
2376
|
+
isDenied: false,
|
|
2377
|
+
isDismissed: false
|
|
2378
|
+
}, resolveValue);
|
|
2360
2379
|
};
|
|
2361
2380
|
|
|
2362
|
-
|
|
2381
|
+
const handlePopupAnimation = (instance, popup, innerParams) => {
|
|
2382
|
+
const container = getContainer(); // If animation is supported, animate
|
|
2363
2383
|
|
|
2364
|
-
|
|
2365
|
-
domCache.popup.onmousedown = () => {
|
|
2366
|
-
domCache.container.onmouseup = function (e) {
|
|
2367
|
-
domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
|
|
2368
|
-
// have any other direct children aside of the popup
|
|
2384
|
+
const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
|
|
2369
2385
|
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2386
|
+
if (typeof innerParams.willClose === 'function') {
|
|
2387
|
+
innerParams.willClose(popup);
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
if (animationIsSupported) {
|
|
2391
|
+
animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
|
|
2392
|
+
} else {
|
|
2393
|
+
// Otherwise, remove immediately
|
|
2394
|
+
removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
|
|
2395
|
+
}
|
|
2375
2396
|
};
|
|
2376
2397
|
|
|
2377
|
-
const
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2398
|
+
const animatePopup = (instance, popup, container, returnFocus, didClose) => {
|
|
2399
|
+
globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
|
|
2400
|
+
popup.addEventListener(animationEndEvent, function (e) {
|
|
2401
|
+
if (e.target === popup) {
|
|
2402
|
+
globalState.swalCloseEventFinishedCallback();
|
|
2403
|
+
delete globalState.swalCloseEventFinishedCallback;
|
|
2404
|
+
}
|
|
2405
|
+
});
|
|
2406
|
+
};
|
|
2381
2407
|
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2408
|
+
const triggerDidCloseAndDispose = (instance, didClose) => {
|
|
2409
|
+
setTimeout(() => {
|
|
2410
|
+
if (typeof didClose === 'function') {
|
|
2411
|
+
didClose.bind(instance.params)();
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
instance._destroy();
|
|
2415
|
+
});
|
|
2387
2416
|
};
|
|
2388
2417
|
|
|
2389
|
-
|
|
2390
|
-
domCache
|
|
2391
|
-
|
|
2418
|
+
function setButtonsDisabled(instance, buttons, disabled) {
|
|
2419
|
+
const domCache = privateProps.domCache.get(instance);
|
|
2420
|
+
buttons.forEach(button => {
|
|
2421
|
+
domCache[button].disabled = disabled;
|
|
2422
|
+
});
|
|
2423
|
+
}
|
|
2392
2424
|
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2425
|
+
function setInputDisabled(input, disabled) {
|
|
2426
|
+
if (!input) {
|
|
2427
|
+
return false;
|
|
2428
|
+
}
|
|
2397
2429
|
|
|
2398
|
-
|
|
2399
|
-
|
|
2430
|
+
if (input.type === 'radio') {
|
|
2431
|
+
const radiosContainer = input.parentNode.parentNode;
|
|
2432
|
+
const radios = radiosContainer.querySelectorAll('input');
|
|
2433
|
+
|
|
2434
|
+
for (let i = 0; i < radios.length; i++) {
|
|
2435
|
+
radios[i].disabled = disabled;
|
|
2400
2436
|
}
|
|
2401
|
-
}
|
|
2402
|
-
|
|
2437
|
+
} else {
|
|
2438
|
+
input.disabled = disabled;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2403
2441
|
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2442
|
+
function enableButtons() {
|
|
2443
|
+
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
|
|
2444
|
+
}
|
|
2445
|
+
function disableButtons() {
|
|
2446
|
+
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
|
|
2447
|
+
}
|
|
2448
|
+
function enableInput() {
|
|
2449
|
+
return setInputDisabled(this.getInput(), false);
|
|
2450
|
+
}
|
|
2451
|
+
function disableInput() {
|
|
2452
|
+
return setInputDisabled(this.getInput(), true);
|
|
2453
|
+
}
|
|
2407
2454
|
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
*/
|
|
2455
|
+
function showValidationMessage(error) {
|
|
2456
|
+
const domCache = privateProps.domCache.get(this);
|
|
2457
|
+
const params = privateProps.innerParams.get(this);
|
|
2458
|
+
setInnerHtml(domCache.validationMessage, error);
|
|
2459
|
+
domCache.validationMessage.className = swalClasses['validation-message'];
|
|
2414
2460
|
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
*/
|
|
2461
|
+
if (params.customClass && params.customClass.validationMessage) {
|
|
2462
|
+
addClass(domCache.validationMessage, params.customClass.validationMessage);
|
|
2463
|
+
}
|
|
2419
2464
|
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
* Global function to click 'Cancel' button
|
|
2423
|
-
*/
|
|
2465
|
+
show(domCache.validationMessage);
|
|
2466
|
+
const input = this.getInput();
|
|
2424
2467
|
|
|
2425
|
-
|
|
2468
|
+
if (input) {
|
|
2469
|
+
input.setAttribute('aria-invalid', true);
|
|
2470
|
+
input.setAttribute('aria-describedby', swalClasses['validation-message']);
|
|
2471
|
+
focusInput(input);
|
|
2472
|
+
addClass(input, swalClasses.inputerror);
|
|
2473
|
+
}
|
|
2474
|
+
} // Hide block with validation message
|
|
2426
2475
|
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
globalState.keydownHandlerAdded = false;
|
|
2476
|
+
function resetValidationMessage$1() {
|
|
2477
|
+
const domCache = privateProps.domCache.get(this);
|
|
2478
|
+
|
|
2479
|
+
if (domCache.validationMessage) {
|
|
2480
|
+
hide(domCache.validationMessage);
|
|
2433
2481
|
}
|
|
2434
2482
|
|
|
2435
|
-
|
|
2436
|
-
globalState.keydownHandler = e => keydownHandler(instance, e, dismissWith);
|
|
2483
|
+
const input = this.getInput();
|
|
2437
2484
|
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
});
|
|
2443
|
-
globalState.keydownHandlerAdded = true;
|
|
2485
|
+
if (input) {
|
|
2486
|
+
input.removeAttribute('aria-invalid');
|
|
2487
|
+
input.removeAttribute('aria-describedby');
|
|
2488
|
+
removeClass(input, swalClasses.inputerror);
|
|
2444
2489
|
}
|
|
2445
|
-
}
|
|
2490
|
+
}
|
|
2446
2491
|
|
|
2447
|
-
|
|
2448
|
-
const
|
|
2492
|
+
function getProgressSteps$1() {
|
|
2493
|
+
const domCache = privateProps.domCache.get(this);
|
|
2494
|
+
return domCache.progressSteps;
|
|
2495
|
+
}
|
|
2449
2496
|
|
|
2450
|
-
|
|
2451
|
-
|
|
2497
|
+
/**
|
|
2498
|
+
* Updates popup parameters.
|
|
2499
|
+
*/
|
|
2452
2500
|
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
index = focusableElements.length - 1;
|
|
2457
|
-
}
|
|
2501
|
+
function update(params) {
|
|
2502
|
+
const popup = getPopup();
|
|
2503
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
2458
2504
|
|
|
2459
|
-
|
|
2460
|
-
|
|
2505
|
+
if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
|
|
2506
|
+
return 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.");
|
|
2507
|
+
}
|
|
2461
2508
|
|
|
2509
|
+
const validUpdatableParams = filterValidParams(params);
|
|
2510
|
+
const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
|
|
2511
|
+
render(this, updatedParams);
|
|
2512
|
+
privateProps.innerParams.set(this, updatedParams);
|
|
2513
|
+
Object.defineProperties(this, {
|
|
2514
|
+
params: {
|
|
2515
|
+
value: Object.assign({}, this.params, params),
|
|
2516
|
+
writable: false,
|
|
2517
|
+
enumerable: true
|
|
2518
|
+
}
|
|
2519
|
+
});
|
|
2520
|
+
}
|
|
2462
2521
|
|
|
2463
|
-
|
|
2522
|
+
const filterValidParams = params => {
|
|
2523
|
+
const validUpdatableParams = {};
|
|
2524
|
+
Object.keys(params).forEach(param => {
|
|
2525
|
+
if (isUpdatableParameter(param)) {
|
|
2526
|
+
validUpdatableParams[param] = params[param];
|
|
2527
|
+
} else {
|
|
2528
|
+
warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md"));
|
|
2529
|
+
}
|
|
2530
|
+
});
|
|
2531
|
+
return validUpdatableParams;
|
|
2464
2532
|
};
|
|
2465
|
-
const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
|
|
2466
|
-
const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
|
|
2467
2533
|
|
|
2468
|
-
|
|
2469
|
-
const
|
|
2534
|
+
function _destroy() {
|
|
2535
|
+
const domCache = privateProps.domCache.get(this);
|
|
2536
|
+
const innerParams = privateProps.innerParams.get(this);
|
|
2470
2537
|
|
|
2471
2538
|
if (!innerParams) {
|
|
2539
|
+
disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
|
|
2540
|
+
|
|
2472
2541
|
return; // This instance has already been destroyed
|
|
2473
|
-
} //
|
|
2474
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition
|
|
2475
|
-
// https://github.com/sweetalert2/sweetalert2/issues/720
|
|
2476
|
-
// https://github.com/sweetalert2/sweetalert2/issues/2406
|
|
2542
|
+
} // Check if there is another Swal closing
|
|
2477
2543
|
|
|
2478
2544
|
|
|
2479
|
-
if (
|
|
2480
|
-
|
|
2545
|
+
if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
|
|
2546
|
+
globalState.swalCloseEventFinishedCallback();
|
|
2547
|
+
delete globalState.swalCloseEventFinishedCallback;
|
|
2548
|
+
} // Check if there is a swal disposal defer timer
|
|
2549
|
+
|
|
2550
|
+
|
|
2551
|
+
if (globalState.deferDisposalTimer) {
|
|
2552
|
+
clearTimeout(globalState.deferDisposalTimer);
|
|
2553
|
+
delete globalState.deferDisposalTimer;
|
|
2481
2554
|
}
|
|
2482
2555
|
|
|
2483
|
-
if (innerParams.
|
|
2484
|
-
|
|
2485
|
-
}
|
|
2556
|
+
if (typeof innerParams.didDestroy === 'function') {
|
|
2557
|
+
innerParams.didDestroy();
|
|
2558
|
+
}
|
|
2486
2559
|
|
|
2560
|
+
disposeSwal(this);
|
|
2561
|
+
}
|
|
2487
2562
|
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
else if (e.key === 'Escape') {
|
|
2498
|
-
handleEsc(e, innerParams, dismissWith);
|
|
2499
|
-
}
|
|
2563
|
+
const disposeSwal = instance => {
|
|
2564
|
+
disposeWeakMaps(instance); // Unset this.params so GC will dispose it (#1569)
|
|
2565
|
+
|
|
2566
|
+
delete instance.params; // Unset globalState props so GC will dispose globalState (#1569)
|
|
2567
|
+
|
|
2568
|
+
delete globalState.keydownHandler;
|
|
2569
|
+
delete globalState.keydownTarget; // Unset currentInstance
|
|
2570
|
+
|
|
2571
|
+
delete globalState.currentInstance;
|
|
2500
2572
|
};
|
|
2501
2573
|
|
|
2502
|
-
const
|
|
2503
|
-
//
|
|
2504
|
-
if (
|
|
2505
|
-
|
|
2574
|
+
const disposeWeakMaps = instance => {
|
|
2575
|
+
// If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
|
|
2576
|
+
if (instance.isAwaitingPromise()) {
|
|
2577
|
+
unsetWeakMaps(privateProps, instance);
|
|
2578
|
+
privateProps.awaitingPromise.set(instance, true);
|
|
2579
|
+
} else {
|
|
2580
|
+
unsetWeakMaps(privateMethods, instance);
|
|
2581
|
+
unsetWeakMaps(privateProps, instance);
|
|
2506
2582
|
}
|
|
2583
|
+
};
|
|
2507
2584
|
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
clickConfirm();
|
|
2514
|
-
e.preventDefault();
|
|
2585
|
+
const unsetWeakMaps = (obj, instance) => {
|
|
2586
|
+
for (const i in obj) {
|
|
2587
|
+
obj[i].delete(instance);
|
|
2515
2588
|
}
|
|
2516
2589
|
};
|
|
2517
2590
|
|
|
2518
|
-
const handleTab = (e, innerParams) => {
|
|
2519
|
-
const targetElement = e.target;
|
|
2520
|
-
const focusableElements = getFocusableElements();
|
|
2521
|
-
let btnIndex = -1;
|
|
2522
2591
|
|
|
2523
|
-
for (let i = 0; i < focusableElements.length; i++) {
|
|
2524
|
-
if (targetElement === focusableElements[i]) {
|
|
2525
|
-
btnIndex = i;
|
|
2526
|
-
break;
|
|
2527
|
-
}
|
|
2528
|
-
} // Cycle to the next button
|
|
2529
2592
|
|
|
2593
|
+
var instanceMethods = /*#__PURE__*/Object.freeze({
|
|
2594
|
+
hideLoading: hideLoading,
|
|
2595
|
+
disableLoading: hideLoading,
|
|
2596
|
+
getInput: getInput$1,
|
|
2597
|
+
close: close,
|
|
2598
|
+
isAwaitingPromise: isAwaitingPromise,
|
|
2599
|
+
rejectPromise: rejectPromise,
|
|
2600
|
+
handleAwaitingPromise: handleAwaitingPromise,
|
|
2601
|
+
closePopup: close,
|
|
2602
|
+
closeModal: close,
|
|
2603
|
+
closeToast: close,
|
|
2604
|
+
enableButtons: enableButtons,
|
|
2605
|
+
disableButtons: disableButtons,
|
|
2606
|
+
enableInput: enableInput,
|
|
2607
|
+
disableInput: disableInput,
|
|
2608
|
+
showValidationMessage: showValidationMessage,
|
|
2609
|
+
resetValidationMessage: resetValidationMessage$1,
|
|
2610
|
+
getProgressSteps: getProgressSteps$1,
|
|
2611
|
+
update: update,
|
|
2612
|
+
_destroy: _destroy
|
|
2613
|
+
});
|
|
2614
|
+
|
|
2615
|
+
const handleConfirmButtonClick = instance => {
|
|
2616
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2617
|
+
instance.disableButtons();
|
|
2530
2618
|
|
|
2531
|
-
if (
|
|
2532
|
-
|
|
2533
|
-
}
|
|
2534
|
-
|
|
2535
|
-
setFocus(innerParams, btnIndex, -1);
|
|
2619
|
+
if (innerParams.input) {
|
|
2620
|
+
handleConfirmOrDenyWithInput(instance, 'confirm');
|
|
2621
|
+
} else {
|
|
2622
|
+
confirm(instance, true);
|
|
2536
2623
|
}
|
|
2624
|
+
};
|
|
2625
|
+
const handleDenyButtonClick = instance => {
|
|
2626
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2627
|
+
instance.disableButtons();
|
|
2537
2628
|
|
|
2538
|
-
|
|
2539
|
-
|
|
2629
|
+
if (innerParams.returnInputValueOnDeny) {
|
|
2630
|
+
handleConfirmOrDenyWithInput(instance, 'deny');
|
|
2631
|
+
} else {
|
|
2632
|
+
deny(instance, false);
|
|
2633
|
+
}
|
|
2634
|
+
};
|
|
2635
|
+
const handleCancelButtonClick = (instance, dismissWith) => {
|
|
2636
|
+
instance.disableButtons();
|
|
2637
|
+
dismissWith(DismissReason.cancel);
|
|
2540
2638
|
};
|
|
2541
2639
|
|
|
2542
|
-
const
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
const
|
|
2640
|
+
const handleConfirmOrDenyWithInput = (instance, type
|
|
2641
|
+
/* 'confirm' | 'deny' */
|
|
2642
|
+
) => {
|
|
2643
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2546
2644
|
|
|
2547
|
-
if (!
|
|
2548
|
-
return;
|
|
2645
|
+
if (!innerParams.input) {
|
|
2646
|
+
return error("The \"input\" parameter is needed to be set when using returnInputValueOn".concat(capitalizeFirstLetter(type)));
|
|
2549
2647
|
}
|
|
2550
2648
|
|
|
2551
|
-
const
|
|
2552
|
-
let buttonToFocus = document.activeElement;
|
|
2649
|
+
const inputValue = getInputValue(instance, innerParams);
|
|
2553
2650
|
|
|
2554
|
-
|
|
2555
|
-
|
|
2651
|
+
if (innerParams.inputValidator) {
|
|
2652
|
+
handleInputValidator(instance, inputValue, type);
|
|
2653
|
+
} else if (!instance.getInput().checkValidity()) {
|
|
2654
|
+
instance.enableButtons();
|
|
2655
|
+
instance.showValidationMessage(innerParams.validationMessage);
|
|
2656
|
+
} else if (type === 'deny') {
|
|
2657
|
+
deny(instance, inputValue);
|
|
2658
|
+
} else {
|
|
2659
|
+
confirm(instance, inputValue);
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2556
2662
|
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2663
|
+
const handleInputValidator = (instance, inputValue, type
|
|
2664
|
+
/* 'confirm' | 'deny' */
|
|
2665
|
+
) => {
|
|
2666
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2667
|
+
instance.disableInput();
|
|
2668
|
+
const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
|
|
2669
|
+
validationPromise.then(validationMessage => {
|
|
2670
|
+
instance.enableButtons();
|
|
2671
|
+
instance.enableInput();
|
|
2560
2672
|
|
|
2561
|
-
if (
|
|
2562
|
-
|
|
2673
|
+
if (validationMessage) {
|
|
2674
|
+
instance.showValidationMessage(validationMessage);
|
|
2675
|
+
} else if (type === 'deny') {
|
|
2676
|
+
deny(instance, inputValue);
|
|
2677
|
+
} else {
|
|
2678
|
+
confirm(instance, inputValue);
|
|
2563
2679
|
}
|
|
2680
|
+
});
|
|
2681
|
+
};
|
|
2682
|
+
|
|
2683
|
+
const deny = (instance, value) => {
|
|
2684
|
+
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
2685
|
+
|
|
2686
|
+
if (innerParams.showLoaderOnDeny) {
|
|
2687
|
+
showLoading(getDenyButton());
|
|
2564
2688
|
}
|
|
2565
2689
|
|
|
2566
|
-
if (
|
|
2567
|
-
|
|
2690
|
+
if (innerParams.preDeny) {
|
|
2691
|
+
privateProps.awaitingPromise.set(instance || undefined, 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
|
|
2692
|
+
|
|
2693
|
+
const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
|
|
2694
|
+
preDenyPromise.then(preDenyValue => {
|
|
2695
|
+
if (preDenyValue === false) {
|
|
2696
|
+
instance.hideLoading();
|
|
2697
|
+
handleAwaitingPromise(instance);
|
|
2698
|
+
} else {
|
|
2699
|
+
instance.closePopup({
|
|
2700
|
+
isDenied: true,
|
|
2701
|
+
value: typeof preDenyValue === 'undefined' ? value : preDenyValue
|
|
2702
|
+
});
|
|
2703
|
+
}
|
|
2704
|
+
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2705
|
+
} else {
|
|
2706
|
+
instance.closePopup({
|
|
2707
|
+
isDenied: true,
|
|
2708
|
+
value
|
|
2709
|
+
});
|
|
2568
2710
|
}
|
|
2569
2711
|
};
|
|
2570
2712
|
|
|
2571
|
-
const
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
}
|
|
2713
|
+
const succeedWith = (instance, value) => {
|
|
2714
|
+
instance.closePopup({
|
|
2715
|
+
isConfirmed: true,
|
|
2716
|
+
value
|
|
2717
|
+
});
|
|
2576
2718
|
};
|
|
2577
2719
|
|
|
2578
|
-
const
|
|
2720
|
+
const rejectWith = (instance, error$$1) => {
|
|
2721
|
+
instance.rejectPromise(error$$1);
|
|
2722
|
+
};
|
|
2579
2723
|
|
|
2580
|
-
const
|
|
2724
|
+
const confirm = (instance, value) => {
|
|
2725
|
+
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
2581
2726
|
|
|
2582
|
-
|
|
2583
|
-
|
|
2727
|
+
if (innerParams.showLoaderOnConfirm) {
|
|
2728
|
+
showLoading();
|
|
2729
|
+
}
|
|
2584
2730
|
|
|
2585
|
-
if (
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
['title', 'html', 'icon'].forEach((name, index) => {
|
|
2589
|
-
const arg = args[index];
|
|
2731
|
+
if (innerParams.preConfirm) {
|
|
2732
|
+
instance.resetValidationMessage();
|
|
2733
|
+
privateProps.awaitingPromise.set(instance || undefined, 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
|
|
2590
2734
|
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2735
|
+
const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
|
|
2736
|
+
preConfirmPromise.then(preConfirmValue => {
|
|
2737
|
+
if (isVisible(getValidationMessage()) || preConfirmValue === false) {
|
|
2738
|
+
instance.hideLoading();
|
|
2739
|
+
handleAwaitingPromise(instance);
|
|
2740
|
+
} else {
|
|
2741
|
+
succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
|
|
2595
2742
|
}
|
|
2596
|
-
});
|
|
2743
|
+
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2744
|
+
} else {
|
|
2745
|
+
succeedWith(instance, value);
|
|
2597
2746
|
}
|
|
2598
|
-
|
|
2599
|
-
return params;
|
|
2600
2747
|
};
|
|
2601
2748
|
|
|
2602
|
-
|
|
2603
|
-
const
|
|
2749
|
+
const handlePopupClick = (instance, domCache, dismissWith) => {
|
|
2750
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2604
2751
|
|
|
2605
|
-
|
|
2606
|
-
|
|
2752
|
+
if (innerParams.toast) {
|
|
2753
|
+
handleToastClick(instance, domCache, dismissWith);
|
|
2754
|
+
} else {
|
|
2755
|
+
// Ignore click events that had mousedown on the popup but mouseup on the container
|
|
2756
|
+
// This can happen when the user drags a slider
|
|
2757
|
+
handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
|
|
2758
|
+
|
|
2759
|
+
handleContainerMousedown(domCache);
|
|
2760
|
+
handleModalClick(instance, domCache, dismissWith);
|
|
2607
2761
|
}
|
|
2762
|
+
};
|
|
2608
2763
|
|
|
2609
|
-
|
|
2610
|
-
|
|
2764
|
+
const handleToastClick = (instance, domCache, dismissWith) => {
|
|
2765
|
+
// Closing toast by internal click
|
|
2766
|
+
domCache.popup.onclick = () => {
|
|
2767
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2768
|
+
|
|
2769
|
+
if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2611
2772
|
|
|
2773
|
+
dismissWith(DismissReason.close);
|
|
2774
|
+
};
|
|
2775
|
+
};
|
|
2612
2776
|
/**
|
|
2613
|
-
*
|
|
2614
|
-
*
|
|
2615
|
-
*
|
|
2616
|
-
* For example:
|
|
2617
|
-
*
|
|
2618
|
-
* Before:
|
|
2619
|
-
* const textPromptOptions = { input: 'text', showCancelButton: true }
|
|
2620
|
-
* const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
|
|
2621
|
-
* const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
|
|
2622
|
-
*
|
|
2623
|
-
* After:
|
|
2624
|
-
* const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
|
|
2625
|
-
* const {value: firstName} = await TextPrompt('What is your first name?')
|
|
2626
|
-
* const {value: lastName} = await TextPrompt('What is your last name?')
|
|
2627
|
-
*
|
|
2628
|
-
* @param mixinParams
|
|
2777
|
+
* @param {*} innerParams
|
|
2778
|
+
* @returns {boolean}
|
|
2629
2779
|
*/
|
|
2630
|
-
function mixin(mixinParams) {
|
|
2631
|
-
class MixinSwal extends this {
|
|
2632
|
-
_main(params, priorityMixinParams) {
|
|
2633
|
-
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
2634
|
-
}
|
|
2635
2780
|
|
|
2636
|
-
}
|
|
2637
2781
|
|
|
2638
|
-
|
|
2639
|
-
|
|
2782
|
+
const isAnyButtonShown = innerParams => {
|
|
2783
|
+
return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
|
|
2784
|
+
};
|
|
2640
2785
|
|
|
2641
|
-
|
|
2642
|
-
* If `timer` parameter is set, returns number of milliseconds of timer remained.
|
|
2643
|
-
* Otherwise, returns undefined.
|
|
2644
|
-
*/
|
|
2786
|
+
let ignoreOutsideClick = false;
|
|
2645
2787
|
|
|
2646
|
-
const
|
|
2647
|
-
|
|
2788
|
+
const handleModalMousedown = domCache => {
|
|
2789
|
+
domCache.popup.onmousedown = () => {
|
|
2790
|
+
domCache.container.onmouseup = function (e) {
|
|
2791
|
+
domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
|
|
2792
|
+
// have any other direct children aside of the popup
|
|
2793
|
+
|
|
2794
|
+
if (e.target === domCache.container) {
|
|
2795
|
+
ignoreOutsideClick = true;
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
};
|
|
2648
2799
|
};
|
|
2649
|
-
/**
|
|
2650
|
-
* Stop timer. Returns number of milliseconds of timer remained.
|
|
2651
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
2652
|
-
*/
|
|
2653
2800
|
|
|
2654
|
-
const
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2801
|
+
const handleContainerMousedown = domCache => {
|
|
2802
|
+
domCache.container.onmousedown = () => {
|
|
2803
|
+
domCache.popup.onmouseup = function (e) {
|
|
2804
|
+
domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
|
|
2805
|
+
|
|
2806
|
+
if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
|
|
2807
|
+
ignoreOutsideClick = true;
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2810
|
+
};
|
|
2659
2811
|
};
|
|
2660
|
-
/**
|
|
2661
|
-
* Resume timer. Returns number of milliseconds of timer remained.
|
|
2662
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
2663
|
-
*/
|
|
2664
2812
|
|
|
2665
|
-
const
|
|
2666
|
-
|
|
2667
|
-
const
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2813
|
+
const handleModalClick = (instance, domCache, dismissWith) => {
|
|
2814
|
+
domCache.container.onclick = e => {
|
|
2815
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2816
|
+
|
|
2817
|
+
if (ignoreOutsideClick) {
|
|
2818
|
+
ignoreOutsideClick = false;
|
|
2819
|
+
return;
|
|
2820
|
+
}
|
|
2821
|
+
|
|
2822
|
+
if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
|
|
2823
|
+
dismissWith(DismissReason.backdrop);
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2671
2826
|
};
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
*
|
|
2827
|
+
|
|
2828
|
+
/*
|
|
2829
|
+
* Global function to determine if SweetAlert2 popup is shown
|
|
2675
2830
|
*/
|
|
2676
2831
|
|
|
2677
|
-
const
|
|
2678
|
-
|
|
2679
|
-
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
2832
|
+
const isVisible$1 = () => {
|
|
2833
|
+
return isVisible(getPopup());
|
|
2680
2834
|
};
|
|
2681
|
-
|
|
2682
|
-
*
|
|
2683
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
2835
|
+
/*
|
|
2836
|
+
* Global function to click 'Confirm' button
|
|
2684
2837
|
*/
|
|
2685
2838
|
|
|
2686
|
-
const
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
animateTimerProgressBar(remaining, true);
|
|
2690
|
-
return remaining;
|
|
2691
|
-
}
|
|
2692
|
-
};
|
|
2693
|
-
/**
|
|
2694
|
-
* Check if timer is running. Returns true if timer is running
|
|
2695
|
-
* or false if timer is paused or stopped.
|
|
2696
|
-
* If `timer` parameter isn't set, returns undefined
|
|
2839
|
+
const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
|
|
2840
|
+
/*
|
|
2841
|
+
* Global function to click 'Deny' button
|
|
2697
2842
|
*/
|
|
2698
2843
|
|
|
2699
|
-
const
|
|
2700
|
-
|
|
2701
|
-
|
|
2844
|
+
const clickDeny = () => getDenyButton() && getDenyButton().click();
|
|
2845
|
+
/*
|
|
2846
|
+
* Global function to click 'Cancel' button
|
|
2847
|
+
*/
|
|
2702
2848
|
|
|
2703
|
-
|
|
2704
|
-
const clickHandlers = {};
|
|
2705
|
-
function bindClickHandler() {
|
|
2706
|
-
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
2707
|
-
clickHandlers[attr] = this;
|
|
2849
|
+
const clickCancel = () => getCancelButton() && getCancelButton().click();
|
|
2708
2850
|
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2851
|
+
const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
|
|
2852
|
+
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
|
|
2853
|
+
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
2854
|
+
capture: globalState.keydownListenerCapture
|
|
2855
|
+
});
|
|
2856
|
+
globalState.keydownHandlerAdded = false;
|
|
2712
2857
|
}
|
|
2713
|
-
}
|
|
2714
2858
|
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
for (const attr in clickHandlers) {
|
|
2718
|
-
const template = el.getAttribute(attr);
|
|
2859
|
+
if (!innerParams.toast) {
|
|
2860
|
+
globalState.keydownHandler = e => keydownHandler(instance, e, dismissWith);
|
|
2719
2861
|
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
}
|
|
2862
|
+
globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
|
|
2863
|
+
globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
|
|
2864
|
+
globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
|
|
2865
|
+
capture: globalState.keydownListenerCapture
|
|
2866
|
+
});
|
|
2867
|
+
globalState.keydownHandlerAdded = true;
|
|
2727
2868
|
}
|
|
2728
|
-
};
|
|
2869
|
+
}; // Focus handling
|
|
2729
2870
|
|
|
2871
|
+
const setFocus = (innerParams, index, increment) => {
|
|
2872
|
+
const focusableElements = getFocusableElements(); // search for visible elements and select the next possible match
|
|
2730
2873
|
|
|
2874
|
+
if (focusableElements.length) {
|
|
2875
|
+
index = index + increment; // rollover to first item
|
|
2731
2876
|
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
isVisible: isVisible$1,
|
|
2738
|
-
clickConfirm: clickConfirm,
|
|
2739
|
-
clickDeny: clickDeny,
|
|
2740
|
-
clickCancel: clickCancel,
|
|
2741
|
-
getContainer: getContainer,
|
|
2742
|
-
getPopup: getPopup,
|
|
2743
|
-
getTitle: getTitle,
|
|
2744
|
-
getHtmlContainer: getHtmlContainer,
|
|
2745
|
-
getImage: getImage,
|
|
2746
|
-
getIcon: getIcon,
|
|
2747
|
-
getInputLabel: getInputLabel,
|
|
2748
|
-
getCloseButton: getCloseButton,
|
|
2749
|
-
getActions: getActions,
|
|
2750
|
-
getConfirmButton: getConfirmButton,
|
|
2751
|
-
getDenyButton: getDenyButton,
|
|
2752
|
-
getCancelButton: getCancelButton,
|
|
2753
|
-
getLoader: getLoader,
|
|
2754
|
-
getFooter: getFooter,
|
|
2755
|
-
getTimerProgressBar: getTimerProgressBar,
|
|
2756
|
-
getFocusableElements: getFocusableElements,
|
|
2757
|
-
getValidationMessage: getValidationMessage,
|
|
2758
|
-
isLoading: isLoading,
|
|
2759
|
-
fire: fire,
|
|
2760
|
-
mixin: mixin,
|
|
2761
|
-
showLoading: showLoading,
|
|
2762
|
-
enableLoading: showLoading,
|
|
2763
|
-
getTimerLeft: getTimerLeft,
|
|
2764
|
-
stopTimer: stopTimer,
|
|
2765
|
-
resumeTimer: resumeTimer,
|
|
2766
|
-
toggleTimer: toggleTimer,
|
|
2767
|
-
increaseTimer: increaseTimer,
|
|
2768
|
-
isTimerRunning: isTimerRunning,
|
|
2769
|
-
bindClickHandler: bindClickHandler
|
|
2770
|
-
});
|
|
2877
|
+
if (index === focusableElements.length) {
|
|
2878
|
+
index = 0; // go to last item
|
|
2879
|
+
} else if (index === -1) {
|
|
2880
|
+
index = focusableElements.length - 1;
|
|
2881
|
+
}
|
|
2771
2882
|
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
*/
|
|
2883
|
+
return focusableElements[index].focus();
|
|
2884
|
+
} // no visible focusable elements, focus the popup
|
|
2775
2885
|
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2886
|
+
|
|
2887
|
+
getPopup().focus();
|
|
2888
|
+
};
|
|
2889
|
+
const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
|
|
2890
|
+
const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
|
|
2891
|
+
|
|
2892
|
+
const keydownHandler = (instance, e, dismissWith) => {
|
|
2893
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2779
2894
|
|
|
2780
2895
|
if (!innerParams) {
|
|
2781
|
-
return;
|
|
2782
|
-
}
|
|
2896
|
+
return; // This instance has already been destroyed
|
|
2897
|
+
} // Ignore keydown during IME composition
|
|
2898
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition
|
|
2899
|
+
// https://github.com/sweetalert2/sweetalert2/issues/720
|
|
2900
|
+
// https://github.com/sweetalert2/sweetalert2/issues/2406
|
|
2783
2901
|
|
|
2784
|
-
const domCache = privateProps.domCache.get(this);
|
|
2785
|
-
hide(domCache.loader);
|
|
2786
2902
|
|
|
2787
|
-
if (
|
|
2788
|
-
|
|
2789
|
-
show(getIcon());
|
|
2790
|
-
}
|
|
2791
|
-
} else {
|
|
2792
|
-
showRelatedButton(domCache);
|
|
2903
|
+
if (e.isComposing || e.keyCode === 229) {
|
|
2904
|
+
return;
|
|
2793
2905
|
}
|
|
2794
2906
|
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
domCache.confirmButton.disabled = false;
|
|
2799
|
-
domCache.denyButton.disabled = false;
|
|
2800
|
-
domCache.cancelButton.disabled = false;
|
|
2801
|
-
}
|
|
2802
|
-
|
|
2803
|
-
const showRelatedButton = domCache => {
|
|
2804
|
-
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
2907
|
+
if (innerParams.stopKeydownPropagation) {
|
|
2908
|
+
e.stopPropagation();
|
|
2909
|
+
} // ENTER
|
|
2805
2910
|
|
|
2806
|
-
if (buttonToReplace.length) {
|
|
2807
|
-
show(buttonToReplace[0], 'inline-block');
|
|
2808
|
-
} else if (allButtonsAreHidden()) {
|
|
2809
|
-
hide(domCache.actions);
|
|
2810
|
-
}
|
|
2811
|
-
};
|
|
2812
2911
|
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
if (
|
|
2823
|
-
|
|
2912
|
+
if (e.key === 'Enter') {
|
|
2913
|
+
handleEnter(instance, e, innerParams);
|
|
2914
|
+
} // TAB
|
|
2915
|
+
else if (e.key === 'Tab') {
|
|
2916
|
+
handleTab(e, innerParams);
|
|
2917
|
+
} // ARROWS - switch focus between buttons
|
|
2918
|
+
else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
|
|
2919
|
+
handleArrows(e.key);
|
|
2920
|
+
} // ESC
|
|
2921
|
+
else if (e.key === 'Escape') {
|
|
2922
|
+
handleEsc(e, innerParams, dismissWith);
|
|
2824
2923
|
}
|
|
2825
|
-
|
|
2826
|
-
return getInput(domCache.popup, innerParams.input);
|
|
2827
|
-
}
|
|
2828
|
-
|
|
2829
|
-
/**
|
|
2830
|
-
* This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
|
|
2831
|
-
* For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
|
|
2832
|
-
* This is the approach that Babel will probably take to implement private methods/fields
|
|
2833
|
-
* https://github.com/tc39/proposal-private-methods
|
|
2834
|
-
* https://github.com/babel/babel/pull/7555
|
|
2835
|
-
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
2836
|
-
* then we can use that language feature.
|
|
2837
|
-
*/
|
|
2838
|
-
var privateMethods = {
|
|
2839
|
-
swalPromiseResolve: new WeakMap(),
|
|
2840
|
-
swalPromiseReject: new WeakMap()
|
|
2841
2924
|
};
|
|
2842
2925
|
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
function removePopupAndResetState(instance, container, returnFocus, didClose) {
|
|
2848
|
-
if (isToast()) {
|
|
2849
|
-
triggerDidCloseAndDispose(instance, didClose);
|
|
2850
|
-
} else {
|
|
2851
|
-
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
2852
|
-
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
2853
|
-
capture: globalState.keydownListenerCapture
|
|
2854
|
-
});
|
|
2855
|
-
globalState.keydownHandlerAdded = false;
|
|
2926
|
+
const handleEnter = (instance, e, innerParams) => {
|
|
2927
|
+
// https://github.com/sweetalert2/sweetalert2/issues/2386
|
|
2928
|
+
if (!callIfFunction(innerParams.allowEnterKey)) {
|
|
2929
|
+
return;
|
|
2856
2930
|
}
|
|
2857
2931
|
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
container.setAttribute('style', 'display:none !important');
|
|
2863
|
-
container.removeAttribute('class');
|
|
2864
|
-
container.innerHTML = '';
|
|
2865
|
-
} else {
|
|
2866
|
-
container.remove();
|
|
2867
|
-
}
|
|
2932
|
+
if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) {
|
|
2933
|
+
if (['textarea', 'file'].includes(innerParams.input)) {
|
|
2934
|
+
return; // do not submit
|
|
2935
|
+
}
|
|
2868
2936
|
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
undoIOSfix();
|
|
2872
|
-
unsetAriaHidden();
|
|
2937
|
+
clickConfirm();
|
|
2938
|
+
e.preventDefault();
|
|
2873
2939
|
}
|
|
2940
|
+
};
|
|
2874
2941
|
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
function close(resolveValue) {
|
|
2883
|
-
resolveValue = prepareResolveValue(resolveValue);
|
|
2884
|
-
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
2885
|
-
const didClose = triggerClosePopup(this);
|
|
2942
|
+
const handleTab = (e, innerParams) => {
|
|
2943
|
+
const targetElement = e.target;
|
|
2944
|
+
const focusableElements = getFocusableElements();
|
|
2945
|
+
let btnIndex = -1;
|
|
2886
2946
|
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
swalPromiseResolve(resolveValue);
|
|
2947
|
+
for (let i = 0; i < focusableElements.length; i++) {
|
|
2948
|
+
if (targetElement === focusableElements[i]) {
|
|
2949
|
+
btnIndex = i;
|
|
2950
|
+
break;
|
|
2892
2951
|
}
|
|
2893
|
-
}
|
|
2894
|
-
// Resolve Swal promise
|
|
2895
|
-
swalPromiseResolve(resolveValue);
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
function isAwaitingPromise() {
|
|
2899
|
-
return !!privateProps.awaitingPromise.get(this);
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
const triggerClosePopup = instance => {
|
|
2903
|
-
const popup = getPopup();
|
|
2904
|
-
|
|
2905
|
-
if (!popup) {
|
|
2906
|
-
return false;
|
|
2907
|
-
}
|
|
2952
|
+
} // Cycle to the next button
|
|
2908
2953
|
|
|
2909
|
-
const innerParams = privateProps.innerParams.get(instance);
|
|
2910
2954
|
|
|
2911
|
-
if (!
|
|
2912
|
-
|
|
2955
|
+
if (!e.shiftKey) {
|
|
2956
|
+
setFocus(innerParams, btnIndex, 1);
|
|
2957
|
+
} // Cycle to the prev button
|
|
2958
|
+
else {
|
|
2959
|
+
setFocus(innerParams, btnIndex, -1);
|
|
2913
2960
|
}
|
|
2914
2961
|
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
const backdrop = getContainer();
|
|
2918
|
-
removeClass(backdrop, innerParams.showClass.backdrop);
|
|
2919
|
-
addClass(backdrop, innerParams.hideClass.backdrop);
|
|
2920
|
-
handlePopupAnimation(instance, popup, innerParams);
|
|
2921
|
-
return true;
|
|
2962
|
+
e.stopPropagation();
|
|
2963
|
+
e.preventDefault();
|
|
2922
2964
|
};
|
|
2923
2965
|
|
|
2924
|
-
|
|
2925
|
-
const
|
|
2926
|
-
|
|
2966
|
+
const handleArrows = key => {
|
|
2967
|
+
const confirmButton = getConfirmButton();
|
|
2968
|
+
const denyButton = getDenyButton();
|
|
2969
|
+
const cancelButton = getCancelButton();
|
|
2927
2970
|
|
|
2928
|
-
if (
|
|
2929
|
-
|
|
2930
|
-
rejectPromise(error);
|
|
2971
|
+
if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
|
|
2972
|
+
return;
|
|
2931
2973
|
}
|
|
2932
|
-
}
|
|
2933
2974
|
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
|
|
2975
|
+
const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
|
|
2976
|
+
let buttonToFocus = document.activeElement;
|
|
2937
2977
|
|
|
2938
|
-
|
|
2939
|
-
|
|
2978
|
+
for (let i = 0; i < getActions().children.length; i++) {
|
|
2979
|
+
buttonToFocus = buttonToFocus[sibling];
|
|
2980
|
+
|
|
2981
|
+
if (!buttonToFocus) {
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
if (isVisible(buttonToFocus) && buttonToFocus instanceof HTMLButtonElement) {
|
|
2986
|
+
break;
|
|
2940
2987
|
}
|
|
2941
2988
|
}
|
|
2942
|
-
};
|
|
2943
2989
|
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
if (typeof resolveValue === 'undefined') {
|
|
2947
|
-
return {
|
|
2948
|
-
isConfirmed: false,
|
|
2949
|
-
isDenied: false,
|
|
2950
|
-
isDismissed: true
|
|
2951
|
-
};
|
|
2990
|
+
if (buttonToFocus instanceof HTMLButtonElement) {
|
|
2991
|
+
buttonToFocus.focus();
|
|
2952
2992
|
}
|
|
2993
|
+
};
|
|
2953
2994
|
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
}
|
|
2995
|
+
const handleEsc = (e, innerParams, dismissWith) => {
|
|
2996
|
+
if (callIfFunction(innerParams.allowEscapeKey)) {
|
|
2997
|
+
e.preventDefault();
|
|
2998
|
+
dismissWith(DismissReason.esc);
|
|
2999
|
+
}
|
|
2959
3000
|
};
|
|
2960
3001
|
|
|
2961
|
-
const
|
|
2962
|
-
const container = getContainer(); // If animation is supported, animate
|
|
3002
|
+
const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
|
|
2963
3003
|
|
|
2964
|
-
|
|
3004
|
+
const isElement = elem => elem instanceof Element || isJqueryElement(elem);
|
|
2965
3005
|
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
}
|
|
3006
|
+
const argsToParams = args => {
|
|
3007
|
+
const params = {};
|
|
2969
3008
|
|
|
2970
|
-
if (
|
|
2971
|
-
|
|
3009
|
+
if (typeof args[0] === 'object' && !isElement(args[0])) {
|
|
3010
|
+
Object.assign(params, args[0]);
|
|
2972
3011
|
} else {
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
}
|
|
2976
|
-
};
|
|
2977
|
-
|
|
2978
|
-
const animatePopup = (instance, popup, container, returnFocus, didClose) => {
|
|
2979
|
-
globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
|
|
2980
|
-
popup.addEventListener(animationEndEvent, function (e) {
|
|
2981
|
-
if (e.target === popup) {
|
|
2982
|
-
globalState.swalCloseEventFinishedCallback();
|
|
2983
|
-
delete globalState.swalCloseEventFinishedCallback;
|
|
2984
|
-
}
|
|
2985
|
-
});
|
|
2986
|
-
};
|
|
3012
|
+
['title', 'html', 'icon'].forEach((name, index) => {
|
|
3013
|
+
const arg = args[index];
|
|
2987
3014
|
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3015
|
+
if (typeof arg === 'string' || isElement(arg)) {
|
|
3016
|
+
params[name] = arg;
|
|
3017
|
+
} else if (arg !== undefined) {
|
|
3018
|
+
error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg));
|
|
3019
|
+
}
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
2993
3022
|
|
|
2994
|
-
|
|
2995
|
-
});
|
|
3023
|
+
return params;
|
|
2996
3024
|
};
|
|
2997
3025
|
|
|
2998
|
-
function
|
|
2999
|
-
const
|
|
3000
|
-
buttons.forEach(button => {
|
|
3001
|
-
domCache[button].disabled = disabled;
|
|
3002
|
-
});
|
|
3003
|
-
}
|
|
3026
|
+
function fire() {
|
|
3027
|
+
const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
3004
3028
|
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
return false;
|
|
3029
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3030
|
+
args[_key] = arguments[_key];
|
|
3008
3031
|
}
|
|
3009
3032
|
|
|
3010
|
-
|
|
3011
|
-
const radiosContainer = input.parentNode.parentNode;
|
|
3012
|
-
const radios = radiosContainer.querySelectorAll('input');
|
|
3013
|
-
|
|
3014
|
-
for (let i = 0; i < radios.length; i++) {
|
|
3015
|
-
radios[i].disabled = disabled;
|
|
3016
|
-
}
|
|
3017
|
-
} else {
|
|
3018
|
-
input.disabled = disabled;
|
|
3019
|
-
}
|
|
3033
|
+
return new Swal(...args);
|
|
3020
3034
|
}
|
|
3021
3035
|
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3036
|
+
/**
|
|
3037
|
+
* Returns an extended version of `Swal` containing `params` as defaults.
|
|
3038
|
+
* Useful for reusing Swal configuration.
|
|
3039
|
+
*
|
|
3040
|
+
* For example:
|
|
3041
|
+
*
|
|
3042
|
+
* Before:
|
|
3043
|
+
* const textPromptOptions = { input: 'text', showCancelButton: true }
|
|
3044
|
+
* const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
|
|
3045
|
+
* const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
|
|
3046
|
+
*
|
|
3047
|
+
* After:
|
|
3048
|
+
* const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
|
|
3049
|
+
* const {value: firstName} = await TextPrompt('What is your first name?')
|
|
3050
|
+
* const {value: lastName} = await TextPrompt('What is your last name?')
|
|
3051
|
+
*
|
|
3052
|
+
* @param mixinParams
|
|
3053
|
+
*/
|
|
3054
|
+
function mixin(mixinParams) {
|
|
3055
|
+
class MixinSwal extends this {
|
|
3056
|
+
_main(params, priorityMixinParams) {
|
|
3057
|
+
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
3058
|
+
}
|
|
3040
3059
|
|
|
3041
|
-
if (params.customClass && params.customClass.validationMessage) {
|
|
3042
|
-
addClass(domCache.validationMessage, params.customClass.validationMessage);
|
|
3043
3060
|
}
|
|
3044
3061
|
|
|
3045
|
-
|
|
3046
|
-
|
|
3062
|
+
return MixinSwal;
|
|
3063
|
+
}
|
|
3047
3064
|
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
addClass(input, swalClasses.inputerror);
|
|
3053
|
-
}
|
|
3054
|
-
} // Hide block with validation message
|
|
3065
|
+
/**
|
|
3066
|
+
* If `timer` parameter is set, returns number of milliseconds of timer remained.
|
|
3067
|
+
* Otherwise, returns undefined.
|
|
3068
|
+
*/
|
|
3055
3069
|
|
|
3056
|
-
|
|
3057
|
-
|
|
3070
|
+
const getTimerLeft = () => {
|
|
3071
|
+
return globalState.timeout && globalState.timeout.getTimerLeft();
|
|
3072
|
+
};
|
|
3073
|
+
/**
|
|
3074
|
+
* Stop timer. Returns number of milliseconds of timer remained.
|
|
3075
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
3076
|
+
*/
|
|
3058
3077
|
|
|
3059
|
-
|
|
3060
|
-
|
|
3078
|
+
const stopTimer = () => {
|
|
3079
|
+
if (globalState.timeout) {
|
|
3080
|
+
stopTimerProgressBar();
|
|
3081
|
+
return globalState.timeout.stop();
|
|
3061
3082
|
}
|
|
3083
|
+
};
|
|
3084
|
+
/**
|
|
3085
|
+
* Resume timer. Returns number of milliseconds of timer remained.
|
|
3086
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
3087
|
+
*/
|
|
3062
3088
|
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
removeClass(input, swalClasses.inputerror);
|
|
3089
|
+
const resumeTimer = () => {
|
|
3090
|
+
if (globalState.timeout) {
|
|
3091
|
+
const remaining = globalState.timeout.start();
|
|
3092
|
+
animateTimerProgressBar(remaining);
|
|
3093
|
+
return remaining;
|
|
3069
3094
|
}
|
|
3070
|
-
}
|
|
3071
|
-
|
|
3072
|
-
function getProgressSteps$1() {
|
|
3073
|
-
const domCache = privateProps.domCache.get(this);
|
|
3074
|
-
return domCache.progressSteps;
|
|
3075
|
-
}
|
|
3076
|
-
|
|
3095
|
+
};
|
|
3077
3096
|
/**
|
|
3078
|
-
*
|
|
3097
|
+
* Resume timer. Returns number of milliseconds of timer remained.
|
|
3098
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
3079
3099
|
*/
|
|
3080
3100
|
|
|
3081
|
-
|
|
3082
|
-
const
|
|
3083
|
-
|
|
3101
|
+
const toggleTimer = () => {
|
|
3102
|
+
const timer = globalState.timeout;
|
|
3103
|
+
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
3104
|
+
};
|
|
3105
|
+
/**
|
|
3106
|
+
* Increase timer. Returns number of milliseconds of an updated timer.
|
|
3107
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
3108
|
+
*/
|
|
3084
3109
|
|
|
3085
|
-
|
|
3086
|
-
|
|
3110
|
+
const increaseTimer = n => {
|
|
3111
|
+
if (globalState.timeout) {
|
|
3112
|
+
const remaining = globalState.timeout.increase(n);
|
|
3113
|
+
animateTimerProgressBar(remaining, true);
|
|
3114
|
+
return remaining;
|
|
3087
3115
|
}
|
|
3088
|
-
|
|
3089
|
-
const validUpdatableParams = filterValidParams(params);
|
|
3090
|
-
const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
|
|
3091
|
-
render(this, updatedParams);
|
|
3092
|
-
privateProps.innerParams.set(this, updatedParams);
|
|
3093
|
-
Object.defineProperties(this, {
|
|
3094
|
-
params: {
|
|
3095
|
-
value: Object.assign({}, this.params, params),
|
|
3096
|
-
writable: false,
|
|
3097
|
-
enumerable: true
|
|
3098
|
-
}
|
|
3099
|
-
});
|
|
3100
|
-
}
|
|
3101
|
-
|
|
3102
|
-
const filterValidParams = params => {
|
|
3103
|
-
const validUpdatableParams = {};
|
|
3104
|
-
Object.keys(params).forEach(param => {
|
|
3105
|
-
if (isUpdatableParameter(param)) {
|
|
3106
|
-
validUpdatableParams[param] = params[param];
|
|
3107
|
-
} else {
|
|
3108
|
-
warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md"));
|
|
3109
|
-
}
|
|
3110
|
-
});
|
|
3111
|
-
return validUpdatableParams;
|
|
3112
3116
|
};
|
|
3117
|
+
/**
|
|
3118
|
+
* Check if timer is running. Returns true if timer is running
|
|
3119
|
+
* or false if timer is paused or stopped.
|
|
3120
|
+
* If `timer` parameter isn't set, returns undefined
|
|
3121
|
+
*/
|
|
3113
3122
|
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
if (!innerParams) {
|
|
3119
|
-
disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
|
|
3120
|
-
|
|
3121
|
-
return; // This instance has already been destroyed
|
|
3122
|
-
} // Check if there is another Swal closing
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
|
|
3126
|
-
globalState.swalCloseEventFinishedCallback();
|
|
3127
|
-
delete globalState.swalCloseEventFinishedCallback;
|
|
3128
|
-
} // Check if there is a swal disposal defer timer
|
|
3129
|
-
|
|
3123
|
+
const isTimerRunning = () => {
|
|
3124
|
+
return globalState.timeout && globalState.timeout.isRunning();
|
|
3125
|
+
};
|
|
3130
3126
|
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3127
|
+
let bodyClickListenerAdded = false;
|
|
3128
|
+
const clickHandlers = {};
|
|
3129
|
+
function bindClickHandler() {
|
|
3130
|
+
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
3131
|
+
clickHandlers[attr] = this;
|
|
3135
3132
|
|
|
3136
|
-
if (
|
|
3137
|
-
|
|
3133
|
+
if (!bodyClickListenerAdded) {
|
|
3134
|
+
document.body.addEventListener('click', bodyClickListener);
|
|
3135
|
+
bodyClickListenerAdded = true;
|
|
3138
3136
|
}
|
|
3139
|
-
|
|
3140
|
-
disposeSwal(this);
|
|
3141
3137
|
}
|
|
3142
3138
|
|
|
3143
|
-
const
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
delete globalState.keydownHandler;
|
|
3149
|
-
delete globalState.keydownTarget; // Unset currentInstance
|
|
3150
|
-
|
|
3151
|
-
delete globalState.currentInstance;
|
|
3152
|
-
};
|
|
3153
|
-
|
|
3154
|
-
const disposeWeakMaps = instance => {
|
|
3155
|
-
// If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
|
|
3156
|
-
if (instance.isAwaitingPromise()) {
|
|
3157
|
-
unsetWeakMaps(privateProps, instance);
|
|
3158
|
-
privateProps.awaitingPromise.set(instance, true);
|
|
3159
|
-
} else {
|
|
3160
|
-
unsetWeakMaps(privateMethods, instance);
|
|
3161
|
-
unsetWeakMaps(privateProps, instance);
|
|
3162
|
-
}
|
|
3163
|
-
};
|
|
3139
|
+
const bodyClickListener = event => {
|
|
3140
|
+
for (let el = event.target; el && el !== document; el = el.parentNode) {
|
|
3141
|
+
for (const attr in clickHandlers) {
|
|
3142
|
+
const template = el.getAttribute(attr);
|
|
3164
3143
|
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3144
|
+
if (template) {
|
|
3145
|
+
clickHandlers[attr].fire({
|
|
3146
|
+
template
|
|
3147
|
+
});
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3168
3151
|
}
|
|
3169
3152
|
};
|
|
3170
3153
|
|
|
3171
3154
|
|
|
3172
3155
|
|
|
3173
|
-
var
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3156
|
+
var staticMethods = /*#__PURE__*/Object.freeze({
|
|
3157
|
+
isValidParameter: isValidParameter,
|
|
3158
|
+
isUpdatableParameter: isUpdatableParameter,
|
|
3159
|
+
isDeprecatedParameter: isDeprecatedParameter,
|
|
3160
|
+
argsToParams: argsToParams,
|
|
3161
|
+
isVisible: isVisible$1,
|
|
3162
|
+
clickConfirm: clickConfirm,
|
|
3163
|
+
clickDeny: clickDeny,
|
|
3164
|
+
clickCancel: clickCancel,
|
|
3165
|
+
getContainer: getContainer,
|
|
3166
|
+
getPopup: getPopup,
|
|
3167
|
+
getTitle: getTitle,
|
|
3168
|
+
getHtmlContainer: getHtmlContainer,
|
|
3169
|
+
getImage: getImage,
|
|
3170
|
+
getIcon: getIcon,
|
|
3171
|
+
getInputLabel: getInputLabel,
|
|
3172
|
+
getCloseButton: getCloseButton,
|
|
3173
|
+
getActions: getActions,
|
|
3174
|
+
getConfirmButton: getConfirmButton,
|
|
3175
|
+
getDenyButton: getDenyButton,
|
|
3176
|
+
getCancelButton: getCancelButton,
|
|
3177
|
+
getLoader: getLoader,
|
|
3178
|
+
getFooter: getFooter,
|
|
3179
|
+
getTimerProgressBar: getTimerProgressBar,
|
|
3180
|
+
getFocusableElements: getFocusableElements,
|
|
3181
|
+
getValidationMessage: getValidationMessage,
|
|
3182
|
+
isLoading: isLoading,
|
|
3183
|
+
fire: fire,
|
|
3184
|
+
mixin: mixin,
|
|
3185
|
+
showLoading: showLoading,
|
|
3186
|
+
enableLoading: showLoading,
|
|
3187
|
+
getTimerLeft: getTimerLeft,
|
|
3188
|
+
stopTimer: stopTimer,
|
|
3189
|
+
resumeTimer: resumeTimer,
|
|
3190
|
+
toggleTimer: toggleTimer,
|
|
3191
|
+
increaseTimer: increaseTimer,
|
|
3192
|
+
isTimerRunning: isTimerRunning,
|
|
3193
|
+
bindClickHandler: bindClickHandler
|
|
3192
3194
|
});
|
|
3193
3195
|
|
|
3194
3196
|
let currentInstance;
|
|
@@ -3399,7 +3401,7 @@
|
|
|
3399
3401
|
};
|
|
3400
3402
|
});
|
|
3401
3403
|
SweetAlert.DismissReason = DismissReason;
|
|
3402
|
-
SweetAlert.version = '11.4.
|
|
3404
|
+
SweetAlert.version = '11.4.4';
|
|
3403
3405
|
|
|
3404
3406
|
const Swal = SweetAlert; // @ts-ignore
|
|
3405
3407
|
|