sweetalert2 11.7.20 → 11.7.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sweetalert2.all.js +122 -86
- package/dist/sweetalert2.all.min.js +2 -2
- package/dist/sweetalert2.js +122 -86
- package/dist/sweetalert2.min.js +2 -2
- package/package.json +3 -3
- package/src/SweetAlert.js +1 -1
- package/src/buttons-handlers.js +2 -1
- package/src/instanceMethods/enable-disable-elements.js +11 -4
- package/src/staticMethods/showLoading.js +9 -3
- package/src/utils/dom/domUtils.js +7 -1
- package/src/utils/dom/inputUtils.js +90 -74
- package/sweetalert2.d.ts +1 -1
package/dist/sweetalert2.all.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sweetalert2 v11.7.
|
|
2
|
+
* sweetalert2 v11.7.21
|
|
3
3
|
* Released under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
(function (global, factory) {
|
|
@@ -652,7 +652,7 @@
|
|
|
652
652
|
/**
|
|
653
653
|
* borrowed from jquery $(elem).is(':visible') implementation
|
|
654
654
|
*
|
|
655
|
-
* @param {HTMLElement} elem
|
|
655
|
+
* @param {HTMLElement | null} elem
|
|
656
656
|
* @returns {boolean}
|
|
657
657
|
*/
|
|
658
658
|
const isVisible$1 = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
|
|
@@ -688,6 +688,9 @@
|
|
|
688
688
|
const animateTimerProgressBar = function (timer) {
|
|
689
689
|
let reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
690
690
|
const timerProgressBar = getTimerProgressBar();
|
|
691
|
+
if (!timerProgressBar) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
691
694
|
if (isVisible$1(timerProgressBar)) {
|
|
692
695
|
if (reset) {
|
|
693
696
|
timerProgressBar.style.transition = 'none';
|
|
@@ -701,6 +704,9 @@
|
|
|
701
704
|
};
|
|
702
705
|
const stopTimerProgressBar = () => {
|
|
703
706
|
const timerProgressBar = getTimerProgressBar();
|
|
707
|
+
if (!timerProgressBar) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
704
710
|
const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
|
|
705
711
|
timerProgressBar.style.removeProperty('transition');
|
|
706
712
|
timerProgressBar.style.width = '100%';
|
|
@@ -2321,7 +2327,7 @@
|
|
|
2321
2327
|
* Shows loader (spinner), this is useful with AJAX requests.
|
|
2322
2328
|
* By default the loader be shown instead of the "Confirm" button.
|
|
2323
2329
|
*
|
|
2324
|
-
* @param {HTMLButtonElement} [buttonToReplace]
|
|
2330
|
+
* @param {HTMLButtonElement | null} [buttonToReplace]
|
|
2325
2331
|
*/
|
|
2326
2332
|
const showLoading = buttonToReplace => {
|
|
2327
2333
|
let popup = getPopup();
|
|
@@ -2330,6 +2336,9 @@
|
|
|
2330
2336
|
}
|
|
2331
2337
|
|
|
2332
2338
|
popup = getPopup();
|
|
2339
|
+
if (!popup) {
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2333
2342
|
const loader = getLoader();
|
|
2334
2343
|
if (isToast()) {
|
|
2335
2344
|
hide(getIcon());
|
|
@@ -2344,11 +2353,14 @@
|
|
|
2344
2353
|
|
|
2345
2354
|
/**
|
|
2346
2355
|
* @param {HTMLElement} popup
|
|
2347
|
-
* @param {HTMLButtonElement} [buttonToReplace]
|
|
2356
|
+
* @param {HTMLButtonElement | null} [buttonToReplace]
|
|
2348
2357
|
*/
|
|
2349
2358
|
const replaceButton = (popup, buttonToReplace) => {
|
|
2350
2359
|
const actions = getActions();
|
|
2351
2360
|
const loader = getLoader();
|
|
2361
|
+
if (!actions || !loader) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2352
2364
|
if (!buttonToReplace && isVisible$1(getConfirmButton())) {
|
|
2353
2365
|
buttonToReplace = getConfirmButton();
|
|
2354
2366
|
}
|
|
@@ -2356,13 +2368,13 @@
|
|
|
2356
2368
|
if (buttonToReplace) {
|
|
2357
2369
|
hide(buttonToReplace);
|
|
2358
2370
|
loader.setAttribute('data-button-to-replace', buttonToReplace.className);
|
|
2371
|
+
actions.insertBefore(loader, buttonToReplace);
|
|
2359
2372
|
}
|
|
2360
|
-
loader.parentNode.insertBefore(loader, buttonToReplace);
|
|
2361
2373
|
addClass([popup, actions], swalClasses.loading);
|
|
2362
2374
|
};
|
|
2363
2375
|
|
|
2364
2376
|
/**
|
|
2365
|
-
* @typedef { string | number | boolean } InputValue
|
|
2377
|
+
* @typedef { string | number | boolean | undefined } InputValue
|
|
2366
2378
|
*/
|
|
2367
2379
|
|
|
2368
2380
|
/**
|
|
@@ -2372,7 +2384,7 @@
|
|
|
2372
2384
|
const handleInputOptionsAndValue = (instance, params) => {
|
|
2373
2385
|
if (params.input === 'select' || params.input === 'radio') {
|
|
2374
2386
|
handleInputOptions(instance, params);
|
|
2375
|
-
} else if (['text', 'email', 'number', 'tel', 'textarea'].
|
|
2387
|
+
} else if (['text', 'email', 'number', 'tel', 'textarea'].some(i => i === params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
|
|
2376
2388
|
showLoading(getConfirmButton());
|
|
2377
2389
|
handleInputValue(instance, params);
|
|
2378
2390
|
}
|
|
@@ -2416,7 +2428,7 @@
|
|
|
2416
2428
|
* @param {HTMLInputElement} input
|
|
2417
2429
|
* @returns {FileList | File | null}
|
|
2418
2430
|
*/
|
|
2419
|
-
const getFileValue = input => input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
|
|
2431
|
+
const getFileValue = input => input.files && input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
|
|
2420
2432
|
|
|
2421
2433
|
/**
|
|
2422
2434
|
* @param {SweetAlert} instance
|
|
@@ -2424,11 +2436,18 @@
|
|
|
2424
2436
|
*/
|
|
2425
2437
|
const handleInputOptions = (instance, params) => {
|
|
2426
2438
|
const popup = getPopup();
|
|
2439
|
+
if (!popup) {
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2427
2442
|
/**
|
|
2428
2443
|
* @param {Record<string, any>} inputOptions
|
|
2429
2444
|
*/
|
|
2430
2445
|
const processInputOptions = inputOptions => {
|
|
2431
|
-
|
|
2446
|
+
if (params.input === 'select') {
|
|
2447
|
+
populateSelectOptions(popup, formatInputOptions(inputOptions), params);
|
|
2448
|
+
} else if (params.input === 'radio') {
|
|
2449
|
+
populateRadioOptions(popup, formatInputOptions(inputOptions), params);
|
|
2450
|
+
}
|
|
2432
2451
|
};
|
|
2433
2452
|
if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
|
|
2434
2453
|
showLoading(getConfirmButton());
|
|
@@ -2449,6 +2468,9 @@
|
|
|
2449
2468
|
*/
|
|
2450
2469
|
const handleInputValue = (instance, params) => {
|
|
2451
2470
|
const input = instance.getInput();
|
|
2471
|
+
if (!input) {
|
|
2472
|
+
return;
|
|
2473
|
+
}
|
|
2452
2474
|
hide(input);
|
|
2453
2475
|
asPromise(params.inputValue).then(inputValue => {
|
|
2454
2476
|
input.value = params.input === 'number' ? `${parseFloat(inputValue) || 0}` : `${inputValue}`;
|
|
@@ -2463,88 +2485,96 @@
|
|
|
2463
2485
|
instance.hideLoading();
|
|
2464
2486
|
});
|
|
2465
2487
|
};
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
* @param {string} optionValue
|
|
2478
|
-
*/
|
|
2479
|
-
const renderOption = (parent, optionLabel, optionValue) => {
|
|
2480
|
-
const option = document.createElement('option');
|
|
2481
|
-
option.value = optionValue;
|
|
2482
|
-
setInnerHtml(option, optionLabel);
|
|
2483
|
-
option.selected = isSelected(optionValue, params.inputValue);
|
|
2484
|
-
parent.appendChild(option);
|
|
2485
|
-
};
|
|
2486
|
-
inputOptions.forEach(inputOption => {
|
|
2487
|
-
const optionValue = inputOption[0];
|
|
2488
|
-
const optionLabel = inputOption[1];
|
|
2489
|
-
// <optgroup> spec:
|
|
2490
|
-
// https://www.w3.org/TR/html401/interact/forms.html#h-17.6
|
|
2491
|
-
// "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
|
|
2492
|
-
// check whether this is a <optgroup>
|
|
2493
|
-
if (Array.isArray(optionLabel)) {
|
|
2494
|
-
// if it is an array, then it is an <optgroup>
|
|
2495
|
-
const optgroup = document.createElement('optgroup');
|
|
2496
|
-
optgroup.label = optionValue;
|
|
2497
|
-
optgroup.disabled = false; // not configurable for now
|
|
2498
|
-
select.appendChild(optgroup);
|
|
2499
|
-
optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
|
|
2500
|
-
} else {
|
|
2501
|
-
// case of <option>
|
|
2502
|
-
renderOption(select, optionLabel, optionValue);
|
|
2503
|
-
}
|
|
2504
|
-
});
|
|
2505
|
-
select.focus();
|
|
2506
|
-
},
|
|
2488
|
+
|
|
2489
|
+
/**
|
|
2490
|
+
* @param {HTMLElement} popup
|
|
2491
|
+
* @param {InputOptionFlattened[]} inputOptions
|
|
2492
|
+
* @param {SweetAlertOptions} params
|
|
2493
|
+
*/
|
|
2494
|
+
function populateSelectOptions(popup, inputOptions, params) {
|
|
2495
|
+
const select = getDirectChildByClass(popup, swalClasses.select);
|
|
2496
|
+
if (!select) {
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2507
2499
|
/**
|
|
2508
|
-
* @param {HTMLElement}
|
|
2509
|
-
* @param {
|
|
2510
|
-
* @param {
|
|
2500
|
+
* @param {HTMLElement} parent
|
|
2501
|
+
* @param {string} optionLabel
|
|
2502
|
+
* @param {string} optionValue
|
|
2511
2503
|
*/
|
|
2512
|
-
|
|
2513
|
-
const
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2504
|
+
const renderOption = (parent, optionLabel, optionValue) => {
|
|
2505
|
+
const option = document.createElement('option');
|
|
2506
|
+
option.value = optionValue;
|
|
2507
|
+
setInnerHtml(option, optionLabel);
|
|
2508
|
+
option.selected = isSelected(optionValue, params.inputValue);
|
|
2509
|
+
parent.appendChild(option);
|
|
2510
|
+
};
|
|
2511
|
+
inputOptions.forEach(inputOption => {
|
|
2512
|
+
const optionValue = inputOption[0];
|
|
2513
|
+
const optionLabel = inputOption[1];
|
|
2514
|
+
// <optgroup> spec:
|
|
2515
|
+
// https://www.w3.org/TR/html401/interact/forms.html#h-17.6
|
|
2516
|
+
// "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
|
|
2517
|
+
// check whether this is a <optgroup>
|
|
2518
|
+
if (Array.isArray(optionLabel)) {
|
|
2519
|
+
// if it is an array, then it is an <optgroup>
|
|
2520
|
+
const optgroup = document.createElement('optgroup');
|
|
2521
|
+
optgroup.label = optionValue;
|
|
2522
|
+
optgroup.disabled = false; // not configurable for now
|
|
2523
|
+
select.appendChild(optgroup);
|
|
2524
|
+
optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
|
|
2525
|
+
} else {
|
|
2526
|
+
// case of <option>
|
|
2527
|
+
renderOption(select, optionLabel, optionValue);
|
|
2535
2528
|
}
|
|
2529
|
+
});
|
|
2530
|
+
select.focus();
|
|
2531
|
+
}
|
|
2532
|
+
|
|
2533
|
+
/**
|
|
2534
|
+
* @param {HTMLElement} popup
|
|
2535
|
+
* @param {InputOptionFlattened[]} inputOptions
|
|
2536
|
+
* @param {SweetAlertOptions} params
|
|
2537
|
+
*/
|
|
2538
|
+
function populateRadioOptions(popup, inputOptions, params) {
|
|
2539
|
+
const radio = getDirectChildByClass(popup, swalClasses.radio);
|
|
2540
|
+
if (!radio) {
|
|
2541
|
+
return;
|
|
2536
2542
|
}
|
|
2537
|
-
|
|
2543
|
+
inputOptions.forEach(inputOption => {
|
|
2544
|
+
const radioValue = inputOption[0];
|
|
2545
|
+
const radioLabel = inputOption[1];
|
|
2546
|
+
const radioInput = document.createElement('input');
|
|
2547
|
+
const radioLabelElement = document.createElement('label');
|
|
2548
|
+
radioInput.type = 'radio';
|
|
2549
|
+
radioInput.name = swalClasses.radio;
|
|
2550
|
+
radioInput.value = radioValue;
|
|
2551
|
+
if (isSelected(radioValue, params.inputValue)) {
|
|
2552
|
+
radioInput.checked = true;
|
|
2553
|
+
}
|
|
2554
|
+
const label = document.createElement('span');
|
|
2555
|
+
setInnerHtml(label, radioLabel);
|
|
2556
|
+
label.className = swalClasses.label;
|
|
2557
|
+
radioLabelElement.appendChild(radioInput);
|
|
2558
|
+
radioLabelElement.appendChild(label);
|
|
2559
|
+
radio.appendChild(radioLabelElement);
|
|
2560
|
+
});
|
|
2561
|
+
const radios = radio.querySelectorAll('input');
|
|
2562
|
+
if (radios.length) {
|
|
2563
|
+
radios[0].focus();
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2538
2566
|
|
|
2539
2567
|
/**
|
|
2540
2568
|
* Converts `inputOptions` into an array of `[value, label]`s
|
|
2541
2569
|
*
|
|
2542
2570
|
* @param {Record<string, any>} inputOptions
|
|
2543
|
-
* @
|
|
2571
|
+
* @typedef {string[]} InputOptionFlattened
|
|
2572
|
+
* @returns {InputOptionFlattened[]}
|
|
2544
2573
|
*/
|
|
2545
2574
|
const formatInputOptions = inputOptions => {
|
|
2575
|
+
/** @type {InputOptionFlattened[]} */
|
|
2546
2576
|
const result = [];
|
|
2547
|
-
if (
|
|
2577
|
+
if (inputOptions instanceof Map) {
|
|
2548
2578
|
inputOptions.forEach((value, key) => {
|
|
2549
2579
|
let valueFormatted = value;
|
|
2550
2580
|
if (typeof valueFormatted === 'object') {
|
|
@@ -2572,7 +2602,7 @@
|
|
|
2572
2602
|
* @returns {boolean}
|
|
2573
2603
|
*/
|
|
2574
2604
|
const isSelected = (optionValue, inputValue) => {
|
|
2575
|
-
return inputValue && inputValue.toString() === optionValue.toString();
|
|
2605
|
+
return !!inputValue && inputValue.toString() === optionValue.toString();
|
|
2576
2606
|
};
|
|
2577
2607
|
|
|
2578
2608
|
/**
|
|
@@ -2620,10 +2650,11 @@
|
|
|
2620
2650
|
error(`The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`);
|
|
2621
2651
|
return;
|
|
2622
2652
|
}
|
|
2653
|
+
const input = instance.getInput();
|
|
2623
2654
|
const inputValue = getInputValue(instance, innerParams);
|
|
2624
2655
|
if (innerParams.inputValidator) {
|
|
2625
2656
|
handleInputValidator(instance, inputValue, type);
|
|
2626
|
-
} else if (!
|
|
2657
|
+
} else if (input && !input.checkValidity()) {
|
|
2627
2658
|
instance.enableButtons();
|
|
2628
2659
|
instance.showValidationMessage(innerParams.validationMessage);
|
|
2629
2660
|
} else if (type === 'deny') {
|
|
@@ -2794,16 +2825,17 @@
|
|
|
2794
2825
|
}
|
|
2795
2826
|
|
|
2796
2827
|
/**
|
|
2797
|
-
* @param {HTMLInputElement} input
|
|
2828
|
+
* @param {HTMLInputElement | null} input
|
|
2798
2829
|
* @param {boolean} disabled
|
|
2799
2830
|
*/
|
|
2800
2831
|
function setInputDisabled(input, disabled) {
|
|
2801
|
-
|
|
2832
|
+
const popup = getPopup();
|
|
2833
|
+
if (!popup || !input) {
|
|
2802
2834
|
return;
|
|
2803
2835
|
}
|
|
2804
2836
|
if (input.type === 'radio') {
|
|
2805
|
-
|
|
2806
|
-
const radios =
|
|
2837
|
+
/** @type {NodeListOf<HTMLInputElement>} */
|
|
2838
|
+
const radios = popup.querySelectorAll(`[name="${swalClasses.radio}"]`);
|
|
2807
2839
|
for (let i = 0; i < radios.length; i++) {
|
|
2808
2840
|
radios[i].disabled = disabled;
|
|
2809
2841
|
}
|
|
@@ -2814,6 +2846,7 @@
|
|
|
2814
2846
|
|
|
2815
2847
|
/**
|
|
2816
2848
|
* Enable all the buttons
|
|
2849
|
+
* @this {SweetAlert}
|
|
2817
2850
|
*/
|
|
2818
2851
|
function enableButtons() {
|
|
2819
2852
|
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
|
|
@@ -2821,6 +2854,7 @@
|
|
|
2821
2854
|
|
|
2822
2855
|
/**
|
|
2823
2856
|
* Disable all the buttons
|
|
2857
|
+
* @this {SweetAlert}
|
|
2824
2858
|
*/
|
|
2825
2859
|
function disableButtons() {
|
|
2826
2860
|
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
|
|
@@ -2828,6 +2862,7 @@
|
|
|
2828
2862
|
|
|
2829
2863
|
/**
|
|
2830
2864
|
* Enable the input field
|
|
2865
|
+
* @this {SweetAlert}
|
|
2831
2866
|
*/
|
|
2832
2867
|
function enableInput() {
|
|
2833
2868
|
setInputDisabled(this.getInput(), false);
|
|
@@ -2835,6 +2870,7 @@
|
|
|
2835
2870
|
|
|
2836
2871
|
/**
|
|
2837
2872
|
* Disable the input field
|
|
2873
|
+
* @this {SweetAlert}
|
|
2838
2874
|
*/
|
|
2839
2875
|
function disableInput() {
|
|
2840
2876
|
setInputDisabled(this.getInput(), true);
|
|
@@ -4190,7 +4226,7 @@
|
|
|
4190
4226
|
};
|
|
4191
4227
|
});
|
|
4192
4228
|
SweetAlert.DismissReason = DismissReason;
|
|
4193
|
-
SweetAlert.version = '11.7.
|
|
4229
|
+
SweetAlert.version = '11.7.21';
|
|
4194
4230
|
|
|
4195
4231
|
const Swal = SweetAlert;
|
|
4196
4232
|
// @ts-ignore
|