sweetalert2 11.4.0 → 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 +28 -0
- package/README.md +6 -6
- package/dist/sweetalert2.all.js +775 -753
- package/dist/sweetalert2.all.min.js +1 -1
- package/dist/sweetalert2.js +775 -753
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +6 -7
- package/src/SweetAlert.js +1 -1
- package/src/buttons-handlers.js +3 -0
- package/src/instanceMethods/close.js +1 -1
- package/src/keydown-handler.js +21 -4
- package/src/utils/dom/getters.js +5 -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) {
|
|
@@ -312,7 +312,7 @@
|
|
|
312
312
|
return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el));
|
|
313
313
|
};
|
|
314
314
|
const isModal = () => {
|
|
315
|
-
return !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
|
|
315
|
+
return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
|
|
316
316
|
};
|
|
317
317
|
const isToast = () => {
|
|
318
318
|
return getPopup() && hasClass(getPopup(), swalClasses.toast);
|
|
@@ -2190,985 +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
|
-
}
|
|
2542
|
+
} // Check if there is another Swal closing
|
|
2474
2543
|
|
|
2475
|
-
if (innerParams.stopKeydownPropagation) {
|
|
2476
|
-
e.stopPropagation();
|
|
2477
|
-
} // ENTER
|
|
2478
2544
|
|
|
2545
|
+
if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
|
|
2546
|
+
globalState.swalCloseEventFinishedCallback();
|
|
2547
|
+
delete globalState.swalCloseEventFinishedCallback;
|
|
2548
|
+
} // Check if there is a swal disposal defer timer
|
|
2479
2549
|
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
handleTab(e, innerParams);
|
|
2485
|
-
} // ARROWS - switch focus between buttons
|
|
2486
|
-
else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
|
|
2487
|
-
handleArrows(e.key);
|
|
2488
|
-
} // ESC
|
|
2489
|
-
else if (e.key === 'Escape') {
|
|
2490
|
-
handleEsc(e, innerParams, dismissWith);
|
|
2550
|
+
|
|
2551
|
+
if (globalState.deferDisposalTimer) {
|
|
2552
|
+
clearTimeout(globalState.deferDisposalTimer);
|
|
2553
|
+
delete globalState.deferDisposalTimer;
|
|
2491
2554
|
}
|
|
2492
|
-
};
|
|
2493
2555
|
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
if (!callIfFunction(innerParams.allowEnterKey) || e.isComposing) {
|
|
2497
|
-
return;
|
|
2556
|
+
if (typeof innerParams.didDestroy === 'function') {
|
|
2557
|
+
innerParams.didDestroy();
|
|
2498
2558
|
}
|
|
2499
2559
|
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
return; // do not submit
|
|
2503
|
-
}
|
|
2560
|
+
disposeSwal(this);
|
|
2561
|
+
}
|
|
2504
2562
|
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
}
|
|
2508
|
-
};
|
|
2563
|
+
const disposeSwal = instance => {
|
|
2564
|
+
disposeWeakMaps(instance); // Unset this.params so GC will dispose it (#1569)
|
|
2509
2565
|
|
|
2510
|
-
|
|
2511
|
-
const targetElement = e.target;
|
|
2512
|
-
const focusableElements = getFocusableElements();
|
|
2513
|
-
let btnIndex = -1;
|
|
2566
|
+
delete instance.params; // Unset globalState props so GC will dispose globalState (#1569)
|
|
2514
2567
|
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
btnIndex = i;
|
|
2518
|
-
break;
|
|
2519
|
-
}
|
|
2520
|
-
} // Cycle to the next button
|
|
2568
|
+
delete globalState.keydownHandler;
|
|
2569
|
+
delete globalState.keydownTarget; // Unset currentInstance
|
|
2521
2570
|
|
|
2571
|
+
delete globalState.currentInstance;
|
|
2572
|
+
};
|
|
2522
2573
|
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
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);
|
|
2528
2582
|
}
|
|
2583
|
+
};
|
|
2529
2584
|
|
|
2530
|
-
|
|
2531
|
-
|
|
2585
|
+
const unsetWeakMaps = (obj, instance) => {
|
|
2586
|
+
for (const i in obj) {
|
|
2587
|
+
obj[i].delete(instance);
|
|
2588
|
+
}
|
|
2532
2589
|
};
|
|
2533
2590
|
|
|
2534
|
-
const handleArrows = key => {
|
|
2535
|
-
const confirmButton = getConfirmButton();
|
|
2536
|
-
const denyButton = getDenyButton();
|
|
2537
|
-
const cancelButton = getCancelButton();
|
|
2538
2591
|
|
|
2539
|
-
if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
|
|
2540
|
-
return;
|
|
2541
|
-
}
|
|
2542
2592
|
|
|
2543
|
-
|
|
2544
|
-
|
|
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
|
+
});
|
|
2545
2614
|
|
|
2546
|
-
|
|
2547
|
-
|
|
2615
|
+
const handleConfirmButtonClick = instance => {
|
|
2616
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2617
|
+
instance.disableButtons();
|
|
2618
|
+
|
|
2619
|
+
if (innerParams.input) {
|
|
2620
|
+
handleConfirmOrDenyWithInput(instance, 'confirm');
|
|
2621
|
+
} else {
|
|
2622
|
+
confirm(instance, true);
|
|
2548
2623
|
}
|
|
2549
2624
|
};
|
|
2625
|
+
const handleDenyButtonClick = instance => {
|
|
2626
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2627
|
+
instance.disableButtons();
|
|
2550
2628
|
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2629
|
+
if (innerParams.returnInputValueOnDeny) {
|
|
2630
|
+
handleConfirmOrDenyWithInput(instance, 'deny');
|
|
2631
|
+
} else {
|
|
2632
|
+
deny(instance, false);
|
|
2555
2633
|
}
|
|
2556
2634
|
};
|
|
2635
|
+
const handleCancelButtonClick = (instance, dismissWith) => {
|
|
2636
|
+
instance.disableButtons();
|
|
2637
|
+
dismissWith(DismissReason.cancel);
|
|
2638
|
+
};
|
|
2557
2639
|
|
|
2558
|
-
const
|
|
2640
|
+
const handleConfirmOrDenyWithInput = (instance, type
|
|
2641
|
+
/* 'confirm' | 'deny' */
|
|
2642
|
+
) => {
|
|
2643
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2559
2644
|
|
|
2560
|
-
|
|
2645
|
+
if (!innerParams.input) {
|
|
2646
|
+
return error("The \"input\" parameter is needed to be set when using returnInputValueOn".concat(capitalizeFirstLetter(type)));
|
|
2647
|
+
}
|
|
2561
2648
|
|
|
2562
|
-
|
|
2563
|
-
const params = {};
|
|
2649
|
+
const inputValue = getInputValue(instance, innerParams);
|
|
2564
2650
|
|
|
2565
|
-
if (
|
|
2566
|
-
|
|
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);
|
|
2567
2658
|
} else {
|
|
2568
|
-
|
|
2569
|
-
|
|
2659
|
+
confirm(instance, inputValue);
|
|
2660
|
+
}
|
|
2661
|
+
};
|
|
2570
2662
|
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
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();
|
|
2672
|
+
|
|
2673
|
+
if (validationMessage) {
|
|
2674
|
+
instance.showValidationMessage(validationMessage);
|
|
2675
|
+
} else if (type === 'deny') {
|
|
2676
|
+
deny(instance, inputValue);
|
|
2677
|
+
} else {
|
|
2678
|
+
confirm(instance, inputValue);
|
|
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());
|
|
2688
|
+
}
|
|
2689
|
+
|
|
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
|
+
});
|
|
2575
2703
|
}
|
|
2704
|
+
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2705
|
+
} else {
|
|
2706
|
+
instance.closePopup({
|
|
2707
|
+
isDenied: true,
|
|
2708
|
+
value
|
|
2576
2709
|
});
|
|
2577
2710
|
}
|
|
2711
|
+
};
|
|
2578
2712
|
|
|
2579
|
-
|
|
2713
|
+
const succeedWith = (instance, value) => {
|
|
2714
|
+
instance.closePopup({
|
|
2715
|
+
isConfirmed: true,
|
|
2716
|
+
value
|
|
2717
|
+
});
|
|
2580
2718
|
};
|
|
2581
2719
|
|
|
2582
|
-
|
|
2583
|
-
|
|
2720
|
+
const rejectWith = (instance, error$$1) => {
|
|
2721
|
+
instance.rejectPromise(error$$1);
|
|
2722
|
+
};
|
|
2584
2723
|
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
}
|
|
2724
|
+
const confirm = (instance, value) => {
|
|
2725
|
+
const innerParams = privateProps.innerParams.get(instance || undefined);
|
|
2588
2726
|
|
|
2589
|
-
|
|
2590
|
-
|
|
2727
|
+
if (innerParams.showLoaderOnConfirm) {
|
|
2728
|
+
showLoading();
|
|
2729
|
+
}
|
|
2591
2730
|
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
*
|
|
2596
|
-
* For example:
|
|
2597
|
-
*
|
|
2598
|
-
* Before:
|
|
2599
|
-
* const textPromptOptions = { input: 'text', showCancelButton: true }
|
|
2600
|
-
* const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
|
|
2601
|
-
* const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
|
|
2602
|
-
*
|
|
2603
|
-
* After:
|
|
2604
|
-
* const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
|
|
2605
|
-
* const {value: firstName} = await TextPrompt('What is your first name?')
|
|
2606
|
-
* const {value: lastName} = await TextPrompt('What is your last name?')
|
|
2607
|
-
*
|
|
2608
|
-
* @param mixinParams
|
|
2609
|
-
*/
|
|
2610
|
-
function mixin(mixinParams) {
|
|
2611
|
-
class MixinSwal extends this {
|
|
2612
|
-
_main(params, priorityMixinParams) {
|
|
2613
|
-
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
2614
|
-
}
|
|
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
|
|
2615
2734
|
|
|
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);
|
|
2742
|
+
}
|
|
2743
|
+
}).catch(error$$1 => rejectWith(instance || undefined, error$$1));
|
|
2744
|
+
} else {
|
|
2745
|
+
succeedWith(instance, value);
|
|
2616
2746
|
}
|
|
2747
|
+
};
|
|
2617
2748
|
|
|
2618
|
-
|
|
2619
|
-
|
|
2749
|
+
const handlePopupClick = (instance, domCache, dismissWith) => {
|
|
2750
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2620
2751
|
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
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
|
|
2625
2758
|
|
|
2626
|
-
|
|
2627
|
-
|
|
2759
|
+
handleContainerMousedown(domCache);
|
|
2760
|
+
handleModalClick(instance, domCache, dismissWith);
|
|
2761
|
+
}
|
|
2628
2762
|
};
|
|
2629
|
-
/**
|
|
2630
|
-
* Stop timer. Returns number of milliseconds of timer remained.
|
|
2631
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
2632
|
-
*/
|
|
2633
2763
|
|
|
2634
|
-
const
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
}
|
|
2639
|
-
};
|
|
2640
|
-
/**
|
|
2641
|
-
* Resume timer. Returns number of milliseconds of timer remained.
|
|
2642
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
2643
|
-
*/
|
|
2764
|
+
const handleToastClick = (instance, domCache, dismissWith) => {
|
|
2765
|
+
// Closing toast by internal click
|
|
2766
|
+
domCache.popup.onclick = () => {
|
|
2767
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2644
2768
|
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
animateTimerProgressBar(remaining);
|
|
2649
|
-
return remaining;
|
|
2650
|
-
}
|
|
2651
|
-
};
|
|
2652
|
-
/**
|
|
2653
|
-
* Resume timer. Returns number of milliseconds of timer remained.
|
|
2654
|
-
* If `timer` parameter isn't set, returns undefined.
|
|
2655
|
-
*/
|
|
2769
|
+
if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
|
|
2770
|
+
return;
|
|
2771
|
+
}
|
|
2656
2772
|
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
return timer && (timer.running ? stopTimer() : resumeTimer());
|
|
2773
|
+
dismissWith(DismissReason.close);
|
|
2774
|
+
};
|
|
2660
2775
|
};
|
|
2661
2776
|
/**
|
|
2662
|
-
*
|
|
2663
|
-
*
|
|
2777
|
+
* @param {*} innerParams
|
|
2778
|
+
* @returns {boolean}
|
|
2664
2779
|
*/
|
|
2665
2780
|
|
|
2666
|
-
const increaseTimer = n => {
|
|
2667
|
-
if (globalState.timeout) {
|
|
2668
|
-
const remaining = globalState.timeout.increase(n);
|
|
2669
|
-
animateTimerProgressBar(remaining, true);
|
|
2670
|
-
return remaining;
|
|
2671
|
-
}
|
|
2672
|
-
};
|
|
2673
|
-
/**
|
|
2674
|
-
* Check if timer is running. Returns true if timer is running
|
|
2675
|
-
* or false if timer is paused or stopped.
|
|
2676
|
-
* If `timer` parameter isn't set, returns undefined
|
|
2677
|
-
*/
|
|
2678
2781
|
|
|
2679
|
-
const
|
|
2680
|
-
return
|
|
2782
|
+
const isAnyButtonShown = innerParams => {
|
|
2783
|
+
return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
|
|
2681
2784
|
};
|
|
2682
2785
|
|
|
2683
|
-
let
|
|
2684
|
-
const clickHandlers = {};
|
|
2685
|
-
function bindClickHandler() {
|
|
2686
|
-
let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
|
|
2687
|
-
clickHandlers[attr] = this;
|
|
2688
|
-
|
|
2689
|
-
if (!bodyClickListenerAdded) {
|
|
2690
|
-
document.body.addEventListener('click', bodyClickListener);
|
|
2691
|
-
bodyClickListenerAdded = true;
|
|
2692
|
-
}
|
|
2693
|
-
}
|
|
2786
|
+
let ignoreOutsideClick = false;
|
|
2694
2787
|
|
|
2695
|
-
const
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
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
|
|
2699
2793
|
|
|
2700
|
-
if (
|
|
2701
|
-
|
|
2702
|
-
template
|
|
2703
|
-
});
|
|
2704
|
-
return;
|
|
2794
|
+
if (e.target === domCache.container) {
|
|
2795
|
+
ignoreOutsideClick = true;
|
|
2705
2796
|
}
|
|
2706
|
-
}
|
|
2707
|
-
}
|
|
2797
|
+
};
|
|
2798
|
+
};
|
|
2708
2799
|
};
|
|
2709
2800
|
|
|
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
|
|
2710
2805
|
|
|
2806
|
+
if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
|
|
2807
|
+
ignoreOutsideClick = true;
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2810
|
+
};
|
|
2811
|
+
};
|
|
2711
2812
|
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
isDeprecatedParameter: isDeprecatedParameter,
|
|
2716
|
-
argsToParams: argsToParams,
|
|
2717
|
-
isVisible: isVisible$1,
|
|
2718
|
-
clickConfirm: clickConfirm,
|
|
2719
|
-
clickDeny: clickDeny,
|
|
2720
|
-
clickCancel: clickCancel,
|
|
2721
|
-
getContainer: getContainer,
|
|
2722
|
-
getPopup: getPopup,
|
|
2723
|
-
getTitle: getTitle,
|
|
2724
|
-
getHtmlContainer: getHtmlContainer,
|
|
2725
|
-
getImage: getImage,
|
|
2726
|
-
getIcon: getIcon,
|
|
2727
|
-
getInputLabel: getInputLabel,
|
|
2728
|
-
getCloseButton: getCloseButton,
|
|
2729
|
-
getActions: getActions,
|
|
2730
|
-
getConfirmButton: getConfirmButton,
|
|
2731
|
-
getDenyButton: getDenyButton,
|
|
2732
|
-
getCancelButton: getCancelButton,
|
|
2733
|
-
getLoader: getLoader,
|
|
2734
|
-
getFooter: getFooter,
|
|
2735
|
-
getTimerProgressBar: getTimerProgressBar,
|
|
2736
|
-
getFocusableElements: getFocusableElements,
|
|
2737
|
-
getValidationMessage: getValidationMessage,
|
|
2738
|
-
isLoading: isLoading,
|
|
2739
|
-
fire: fire,
|
|
2740
|
-
mixin: mixin,
|
|
2741
|
-
showLoading: showLoading,
|
|
2742
|
-
enableLoading: showLoading,
|
|
2743
|
-
getTimerLeft: getTimerLeft,
|
|
2744
|
-
stopTimer: stopTimer,
|
|
2745
|
-
resumeTimer: resumeTimer,
|
|
2746
|
-
toggleTimer: toggleTimer,
|
|
2747
|
-
increaseTimer: increaseTimer,
|
|
2748
|
-
isTimerRunning: isTimerRunning,
|
|
2749
|
-
bindClickHandler: bindClickHandler
|
|
2750
|
-
});
|
|
2751
|
-
|
|
2752
|
-
/**
|
|
2753
|
-
* Hides loader and shows back the button which was hidden by .showLoading()
|
|
2754
|
-
*/
|
|
2755
|
-
|
|
2756
|
-
function hideLoading() {
|
|
2757
|
-
// do nothing if popup is closed
|
|
2758
|
-
const innerParams = privateProps.innerParams.get(this);
|
|
2759
|
-
|
|
2760
|
-
if (!innerParams) {
|
|
2761
|
-
return;
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2764
|
-
const domCache = privateProps.domCache.get(this);
|
|
2765
|
-
hide(domCache.loader);
|
|
2813
|
+
const handleModalClick = (instance, domCache, dismissWith) => {
|
|
2814
|
+
domCache.container.onclick = e => {
|
|
2815
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2766
2816
|
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2817
|
+
if (ignoreOutsideClick) {
|
|
2818
|
+
ignoreOutsideClick = false;
|
|
2819
|
+
return;
|
|
2770
2820
|
}
|
|
2771
|
-
} else {
|
|
2772
|
-
showRelatedButton(domCache);
|
|
2773
|
-
}
|
|
2774
2821
|
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
domCache.denyButton.disabled = false;
|
|
2780
|
-
domCache.cancelButton.disabled = false;
|
|
2781
|
-
}
|
|
2782
|
-
|
|
2783
|
-
const showRelatedButton = domCache => {
|
|
2784
|
-
const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
|
|
2785
|
-
|
|
2786
|
-
if (buttonToReplace.length) {
|
|
2787
|
-
show(buttonToReplace[0], 'inline-block');
|
|
2788
|
-
} else if (allButtonsAreHidden()) {
|
|
2789
|
-
hide(domCache.actions);
|
|
2790
|
-
}
|
|
2822
|
+
if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
|
|
2823
|
+
dismissWith(DismissReason.backdrop);
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2791
2826
|
};
|
|
2792
2827
|
|
|
2793
|
-
|
|
2794
|
-
*
|
|
2795
|
-
* @returns {HTMLElement | null}
|
|
2828
|
+
/*
|
|
2829
|
+
* Global function to determine if SweetAlert2 popup is shown
|
|
2796
2830
|
*/
|
|
2797
2831
|
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
}
|
|
2805
|
-
|
|
2806
|
-
return getInput(domCache.popup, innerParams.input);
|
|
2807
|
-
}
|
|
2832
|
+
const isVisible$1 = () => {
|
|
2833
|
+
return isVisible(getPopup());
|
|
2834
|
+
};
|
|
2835
|
+
/*
|
|
2836
|
+
* Global function to click 'Confirm' button
|
|
2837
|
+
*/
|
|
2808
2838
|
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
*
|
|
2812
|
-
* This is the approach that Babel will probably take to implement private methods/fields
|
|
2813
|
-
* https://github.com/tc39/proposal-private-methods
|
|
2814
|
-
* https://github.com/babel/babel/pull/7555
|
|
2815
|
-
* Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
|
|
2816
|
-
* then we can use that language feature.
|
|
2839
|
+
const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
|
|
2840
|
+
/*
|
|
2841
|
+
* Global function to click 'Deny' button
|
|
2817
2842
|
*/
|
|
2818
|
-
var privateMethods = {
|
|
2819
|
-
swalPromiseResolve: new WeakMap(),
|
|
2820
|
-
swalPromiseReject: new WeakMap()
|
|
2821
|
-
};
|
|
2822
2843
|
|
|
2844
|
+
const clickDeny = () => getDenyButton() && getDenyButton().click();
|
|
2823
2845
|
/*
|
|
2824
|
-
*
|
|
2846
|
+
* Global function to click 'Cancel' button
|
|
2825
2847
|
*/
|
|
2826
2848
|
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
|
|
2849
|
+
const clickCancel = () => getCancelButton() && getCancelButton().click();
|
|
2850
|
+
|
|
2851
|
+
const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
|
|
2852
|
+
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
|
|
2832
2853
|
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
2833
2854
|
capture: globalState.keydownListenerCapture
|
|
2834
2855
|
});
|
|
2835
2856
|
globalState.keydownHandlerAdded = false;
|
|
2836
2857
|
}
|
|
2837
2858
|
|
|
2838
|
-
|
|
2839
|
-
|
|
2859
|
+
if (!innerParams.toast) {
|
|
2860
|
+
globalState.keydownHandler = e => keydownHandler(instance, e, dismissWith);
|
|
2840
2861
|
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
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;
|
|
2847
2868
|
}
|
|
2869
|
+
}; // Focus handling
|
|
2848
2870
|
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
undoIOSfix();
|
|
2852
|
-
unsetAriaHidden();
|
|
2853
|
-
}
|
|
2871
|
+
const setFocus = (innerParams, index, increment) => {
|
|
2872
|
+
const focusableElements = getFocusableElements(); // search for visible elements and select the next possible match
|
|
2854
2873
|
|
|
2855
|
-
|
|
2856
|
-
|
|
2874
|
+
if (focusableElements.length) {
|
|
2875
|
+
index = index + increment; // rollover to first item
|
|
2857
2876
|
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
function close(resolveValue) {
|
|
2863
|
-
resolveValue = prepareResolveValue(resolveValue);
|
|
2864
|
-
const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
|
|
2865
|
-
const didClose = triggerClosePopup(this);
|
|
2866
|
-
|
|
2867
|
-
if (this.isAwaitingPromise()) {
|
|
2868
|
-
// A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
|
|
2869
|
-
if (!resolveValue.isDismissed) {
|
|
2870
|
-
handleAwaitingPromise(this);
|
|
2871
|
-
swalPromiseResolve(resolveValue);
|
|
2877
|
+
if (index === focusableElements.length) {
|
|
2878
|
+
index = 0; // go to last item
|
|
2879
|
+
} else if (index === -1) {
|
|
2880
|
+
index = focusableElements.length - 1;
|
|
2872
2881
|
}
|
|
2873
|
-
} else if (didClose) {
|
|
2874
|
-
// Resolve Swal promise
|
|
2875
|
-
swalPromiseResolve(resolveValue);
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
function isAwaitingPromise() {
|
|
2879
|
-
return !!privateProps.awaitingPromise.get(this);
|
|
2880
|
-
}
|
|
2881
2882
|
|
|
2882
|
-
|
|
2883
|
-
|
|
2883
|
+
return focusableElements[index].focus();
|
|
2884
|
+
} // no visible focusable elements, focus the popup
|
|
2884
2885
|
|
|
2885
|
-
if (!popup) {
|
|
2886
|
-
return false;
|
|
2887
|
-
}
|
|
2888
2886
|
|
|
2889
|
-
|
|
2887
|
+
getPopup().focus();
|
|
2888
|
+
};
|
|
2889
|
+
const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
|
|
2890
|
+
const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
|
|
2890
2891
|
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
}
|
|
2892
|
+
const keydownHandler = (instance, e, dismissWith) => {
|
|
2893
|
+
const innerParams = privateProps.innerParams.get(instance);
|
|
2894
2894
|
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
return true;
|
|
2902
|
-
};
|
|
2895
|
+
if (!innerParams) {
|
|
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
|
|
2903
2901
|
|
|
2904
|
-
function rejectPromise(error) {
|
|
2905
|
-
const rejectPromise = privateMethods.swalPromiseReject.get(this);
|
|
2906
|
-
handleAwaitingPromise(this);
|
|
2907
2902
|
|
|
2908
|
-
if (
|
|
2909
|
-
|
|
2910
|
-
rejectPromise(error);
|
|
2903
|
+
if (e.isComposing || e.keyCode === 229) {
|
|
2904
|
+
return;
|
|
2911
2905
|
}
|
|
2912
|
-
}
|
|
2913
2906
|
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2907
|
+
if (innerParams.stopKeydownPropagation) {
|
|
2908
|
+
e.stopPropagation();
|
|
2909
|
+
} // ENTER
|
|
2917
2910
|
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2911
|
+
|
|
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);
|
|
2921
2923
|
}
|
|
2922
2924
|
};
|
|
2923
2925
|
|
|
2924
|
-
const
|
|
2925
|
-
//
|
|
2926
|
-
if (
|
|
2927
|
-
return
|
|
2928
|
-
isConfirmed: false,
|
|
2929
|
-
isDenied: false,
|
|
2930
|
-
isDismissed: true
|
|
2931
|
-
};
|
|
2926
|
+
const handleEnter = (instance, e, innerParams) => {
|
|
2927
|
+
// https://github.com/sweetalert2/sweetalert2/issues/2386
|
|
2928
|
+
if (!callIfFunction(innerParams.allowEnterKey)) {
|
|
2929
|
+
return;
|
|
2932
2930
|
}
|
|
2933
2931
|
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
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
|
+
}
|
|
2936
|
+
|
|
2937
|
+
clickConfirm();
|
|
2938
|
+
e.preventDefault();
|
|
2939
|
+
}
|
|
2939
2940
|
};
|
|
2940
2941
|
|
|
2941
|
-
const
|
|
2942
|
-
const
|
|
2942
|
+
const handleTab = (e, innerParams) => {
|
|
2943
|
+
const targetElement = e.target;
|
|
2944
|
+
const focusableElements = getFocusableElements();
|
|
2945
|
+
let btnIndex = -1;
|
|
2943
2946
|
|
|
2944
|
-
|
|
2947
|
+
for (let i = 0; i < focusableElements.length; i++) {
|
|
2948
|
+
if (targetElement === focusableElements[i]) {
|
|
2949
|
+
btnIndex = i;
|
|
2950
|
+
break;
|
|
2951
|
+
}
|
|
2952
|
+
} // Cycle to the next button
|
|
2945
2953
|
|
|
2946
|
-
if (typeof innerParams.willClose === 'function') {
|
|
2947
|
-
innerParams.willClose(popup);
|
|
2948
|
-
}
|
|
2949
2954
|
|
|
2950
|
-
if (
|
|
2951
|
-
|
|
2952
|
-
}
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
+
if (!e.shiftKey) {
|
|
2956
|
+
setFocus(innerParams, btnIndex, 1);
|
|
2957
|
+
} // Cycle to the prev button
|
|
2958
|
+
else {
|
|
2959
|
+
setFocus(innerParams, btnIndex, -1);
|
|
2955
2960
|
}
|
|
2956
|
-
};
|
|
2957
2961
|
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
popup.addEventListener(animationEndEvent, function (e) {
|
|
2961
|
-
if (e.target === popup) {
|
|
2962
|
-
globalState.swalCloseEventFinishedCallback();
|
|
2963
|
-
delete globalState.swalCloseEventFinishedCallback;
|
|
2964
|
-
}
|
|
2965
|
-
});
|
|
2962
|
+
e.stopPropagation();
|
|
2963
|
+
e.preventDefault();
|
|
2966
2964
|
};
|
|
2967
2965
|
|
|
2968
|
-
const
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
}
|
|
2966
|
+
const handleArrows = key => {
|
|
2967
|
+
const confirmButton = getConfirmButton();
|
|
2968
|
+
const denyButton = getDenyButton();
|
|
2969
|
+
const cancelButton = getCancelButton();
|
|
2973
2970
|
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2971
|
+
if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
|
|
2972
|
+
return;
|
|
2973
|
+
}
|
|
2977
2974
|
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
buttons.forEach(button => {
|
|
2981
|
-
domCache[button].disabled = disabled;
|
|
2982
|
-
});
|
|
2983
|
-
}
|
|
2975
|
+
const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
|
|
2976
|
+
let buttonToFocus = document.activeElement;
|
|
2984
2977
|
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
return false;
|
|
2988
|
-
}
|
|
2978
|
+
for (let i = 0; i < getActions().children.length; i++) {
|
|
2979
|
+
buttonToFocus = buttonToFocus[sibling];
|
|
2989
2980
|
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2981
|
+
if (!buttonToFocus) {
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2993
2984
|
|
|
2994
|
-
|
|
2995
|
-
|
|
2985
|
+
if (isVisible(buttonToFocus) && buttonToFocus instanceof HTMLButtonElement) {
|
|
2986
|
+
break;
|
|
2996
2987
|
}
|
|
2997
|
-
} else {
|
|
2998
|
-
input.disabled = disabled;
|
|
2999
2988
|
}
|
|
3000
|
-
}
|
|
3001
2989
|
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
|
|
3007
|
-
}
|
|
3008
|
-
function enableInput() {
|
|
3009
|
-
return setInputDisabled(this.getInput(), false);
|
|
3010
|
-
}
|
|
3011
|
-
function disableInput() {
|
|
3012
|
-
return setInputDisabled(this.getInput(), true);
|
|
3013
|
-
}
|
|
3014
|
-
|
|
3015
|
-
function showValidationMessage(error) {
|
|
3016
|
-
const domCache = privateProps.domCache.get(this);
|
|
3017
|
-
const params = privateProps.innerParams.get(this);
|
|
3018
|
-
setInnerHtml(domCache.validationMessage, error);
|
|
3019
|
-
domCache.validationMessage.className = swalClasses['validation-message'];
|
|
2990
|
+
if (buttonToFocus instanceof HTMLButtonElement) {
|
|
2991
|
+
buttonToFocus.focus();
|
|
2992
|
+
}
|
|
2993
|
+
};
|
|
3020
2994
|
|
|
3021
|
-
|
|
3022
|
-
|
|
2995
|
+
const handleEsc = (e, innerParams, dismissWith) => {
|
|
2996
|
+
if (callIfFunction(innerParams.allowEscapeKey)) {
|
|
2997
|
+
e.preventDefault();
|
|
2998
|
+
dismissWith(DismissReason.esc);
|
|
3023
2999
|
}
|
|
3000
|
+
};
|
|
3024
3001
|
|
|
3025
|
-
|
|
3026
|
-
const input = this.getInput();
|
|
3002
|
+
const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
|
|
3027
3003
|
|
|
3028
|
-
|
|
3029
|
-
input.setAttribute('aria-invalid', true);
|
|
3030
|
-
input.setAttribute('aria-describedby', swalClasses['validation-message']);
|
|
3031
|
-
focusInput(input);
|
|
3032
|
-
addClass(input, swalClasses.inputerror);
|
|
3033
|
-
}
|
|
3034
|
-
} // Hide block with validation message
|
|
3004
|
+
const isElement = elem => elem instanceof Element || isJqueryElement(elem);
|
|
3035
3005
|
|
|
3036
|
-
|
|
3037
|
-
const
|
|
3006
|
+
const argsToParams = args => {
|
|
3007
|
+
const params = {};
|
|
3038
3008
|
|
|
3039
|
-
if (
|
|
3040
|
-
|
|
3009
|
+
if (typeof args[0] === 'object' && !isElement(args[0])) {
|
|
3010
|
+
Object.assign(params, args[0]);
|
|
3011
|
+
} else {
|
|
3012
|
+
['title', 'html', 'icon'].forEach((name, index) => {
|
|
3013
|
+
const arg = args[index];
|
|
3014
|
+
|
|
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
|
+
});
|
|
3041
3021
|
}
|
|
3042
3022
|
|
|
3043
|
-
|
|
3023
|
+
return params;
|
|
3024
|
+
};
|
|
3044
3025
|
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3026
|
+
function fire() {
|
|
3027
|
+
const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
3028
|
+
|
|
3029
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3030
|
+
args[_key] = arguments[_key];
|
|
3049
3031
|
}
|
|
3050
|
-
}
|
|
3051
3032
|
|
|
3052
|
-
|
|
3053
|
-
const domCache = privateProps.domCache.get(this);
|
|
3054
|
-
return domCache.progressSteps;
|
|
3033
|
+
return new Swal(...args);
|
|
3055
3034
|
}
|
|
3056
3035
|
|
|
3057
3036
|
/**
|
|
3058
|
-
*
|
|
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
|
|
3059
3053
|
*/
|
|
3054
|
+
function mixin(mixinParams) {
|
|
3055
|
+
class MixinSwal extends this {
|
|
3056
|
+
_main(params, priorityMixinParams) {
|
|
3057
|
+
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
|
|
3058
|
+
}
|
|
3060
3059
|
|
|
3061
|
-
function update(params) {
|
|
3062
|
-
const popup = getPopup();
|
|
3063
|
-
const innerParams = privateProps.innerParams.get(this);
|
|
3064
|
-
|
|
3065
|
-
if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
|
|
3066
|
-
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.");
|
|
3067
3060
|
}
|
|
3068
3061
|
|
|
3069
|
-
|
|
3070
|
-
const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
|
|
3071
|
-
render(this, updatedParams);
|
|
3072
|
-
privateProps.innerParams.set(this, updatedParams);
|
|
3073
|
-
Object.defineProperties(this, {
|
|
3074
|
-
params: {
|
|
3075
|
-
value: Object.assign({}, this.params, params),
|
|
3076
|
-
writable: false,
|
|
3077
|
-
enumerable: true
|
|
3078
|
-
}
|
|
3079
|
-
});
|
|
3062
|
+
return MixinSwal;
|
|
3080
3063
|
}
|
|
3081
3064
|
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
validUpdatableParams[param] = params[param];
|
|
3087
|
-
} else {
|
|
3088
|
-
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"));
|
|
3089
|
-
}
|
|
3090
|
-
});
|
|
3091
|
-
return validUpdatableParams;
|
|
3092
|
-
};
|
|
3093
|
-
|
|
3094
|
-
function _destroy() {
|
|
3095
|
-
const domCache = privateProps.domCache.get(this);
|
|
3096
|
-
const innerParams = privateProps.innerParams.get(this);
|
|
3097
|
-
|
|
3098
|
-
if (!innerParams) {
|
|
3099
|
-
disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
|
|
3100
|
-
|
|
3101
|
-
return; // This instance has already been destroyed
|
|
3102
|
-
} // Check if there is another Swal closing
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
|
|
3106
|
-
globalState.swalCloseEventFinishedCallback();
|
|
3107
|
-
delete globalState.swalCloseEventFinishedCallback;
|
|
3108
|
-
} // Check if there is a swal disposal defer timer
|
|
3065
|
+
/**
|
|
3066
|
+
* If `timer` parameter is set, returns number of milliseconds of timer remained.
|
|
3067
|
+
* Otherwise, returns undefined.
|
|
3068
|
+
*/
|
|
3109
3069
|
|
|
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
|
+
*/
|
|
3110
3077
|
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3078
|
+
const stopTimer = () => {
|
|
3079
|
+
if (globalState.timeout) {
|
|
3080
|
+
stopTimerProgressBar();
|
|
3081
|
+
return globalState.timeout.stop();
|
|
3114
3082
|
}
|
|
3083
|
+
};
|
|
3084
|
+
/**
|
|
3085
|
+
* Resume timer. Returns number of milliseconds of timer remained.
|
|
3086
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
3087
|
+
*/
|
|
3115
3088
|
|
|
3116
|
-
|
|
3117
|
-
|
|
3089
|
+
const resumeTimer = () => {
|
|
3090
|
+
if (globalState.timeout) {
|
|
3091
|
+
const remaining = globalState.timeout.start();
|
|
3092
|
+
animateTimerProgressBar(remaining);
|
|
3093
|
+
return remaining;
|
|
3118
3094
|
}
|
|
3095
|
+
};
|
|
3096
|
+
/**
|
|
3097
|
+
* Resume timer. Returns number of milliseconds of timer remained.
|
|
3098
|
+
* If `timer` parameter isn't set, returns undefined.
|
|
3099
|
+
*/
|
|
3119
3100
|
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
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
|
+
*/
|
|
3127
3109
|
|
|
3128
|
-
|
|
3129
|
-
|
|
3110
|
+
const increaseTimer = n => {
|
|
3111
|
+
if (globalState.timeout) {
|
|
3112
|
+
const remaining = globalState.timeout.increase(n);
|
|
3113
|
+
animateTimerProgressBar(remaining, true);
|
|
3114
|
+
return remaining;
|
|
3115
|
+
}
|
|
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
|
+
*/
|
|
3130
3122
|
|
|
3131
|
-
|
|
3123
|
+
const isTimerRunning = () => {
|
|
3124
|
+
return globalState.timeout && globalState.timeout.isRunning();
|
|
3132
3125
|
};
|
|
3133
3126
|
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
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;
|
|
3132
|
+
|
|
3133
|
+
if (!bodyClickListenerAdded) {
|
|
3134
|
+
document.body.addEventListener('click', bodyClickListener);
|
|
3135
|
+
bodyClickListenerAdded = true;
|
|
3142
3136
|
}
|
|
3143
|
-
}
|
|
3137
|
+
}
|
|
3144
3138
|
|
|
3145
|
-
const
|
|
3146
|
-
for (
|
|
3147
|
-
|
|
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);
|
|
3143
|
+
|
|
3144
|
+
if (template) {
|
|
3145
|
+
clickHandlers[attr].fire({
|
|
3146
|
+
template
|
|
3147
|
+
});
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3148
3151
|
}
|
|
3149
3152
|
};
|
|
3150
3153
|
|
|
3151
3154
|
|
|
3152
3155
|
|
|
3153
|
-
var
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
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
|
|
3172
3194
|
});
|
|
3173
3195
|
|
|
3174
3196
|
let currentInstance;
|
|
@@ -3379,7 +3401,7 @@
|
|
|
3379
3401
|
};
|
|
3380
3402
|
});
|
|
3381
3403
|
SweetAlert.DismissReason = DismissReason;
|
|
3382
|
-
SweetAlert.version = '11.4.
|
|
3404
|
+
SweetAlert.version = '11.4.4';
|
|
3383
3405
|
|
|
3384
3406
|
const Swal = SweetAlert; // @ts-ignore
|
|
3385
3407
|
|