sweetalert2 11.7.20 → 11.7.22

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/README.md CHANGED
@@ -61,24 +61,25 @@ NSFW Sponsors
61
61
  <table>
62
62
  <tr>
63
63
  <td align="center"><a href="SPONSORS.md#sponsors"><img src="https://sweetalert2.github.io/images/plus.png" width="80"><br>Become a NSFW sponsor</a></td>
64
+ <td align="center"><a href="https://sexsitoys.com/lovense-games/"><img src="https://sweetalert2.github.io/images/sponsors/sexsitoys.jpg" width="80"><br>Sexsi Toys</a></td>
64
65
  <td align="center"><a href="https://www.cheapestsexdolls.com"><img src="https://sweetalert2.github.io/images/sponsors/cheapestsexdolls.png" width="80"><br>CheapestSexDolls</a></td>
65
66
  <td align="center"><a href="https://www.sexysexdoll.com/"><img src="https://sweetalert2.github.io/images/sponsors/sexysexdoll.png" width="80"><br>Sexy Sex Doll</a></td>
66
67
  <td align="center"><a href="https://www.bestblowjobmachines.com/"><img src="https://sweetalert2.github.io/images/sponsors/best-blowjob-machines.jpg" width="80"><br>Best Blowjob Machines</a></td>
67
- <td align="center"><a href="https://celebexposed.com/"><img src="https://sweetalert2.github.io/images/sponsors/celebexposed.jpg" width="80"><br>CelebExposed</a></td>
68
68
  </tr>
69
69
  </table>
70
70
  <table>
71
71
  <tr>
72
+ <td align="center"><a href="https://celebexposed.com/"><img src="https://sweetalert2.github.io/images/sponsors/celebexposed.jpg" width="80"><br>CelebExposed</a></td>
72
73
  <td align="center"><a href="https://escortsear.ch/"><img src="https://sweetalert2.github.io/images/sponsors/escortsearch.jpg" width="80"><br>EscortSearch</a></td>
73
74
  <td align="center"><a href="https://nakedoll.com/"><img src="https://sweetalert2.github.io/images/sponsors/nakedoll.png" width="80"><br>NakeDoll</a></td>
74
75
  <td align="center"><a href="https://readysetcam.com/"><img src="https://sweetalert2.github.io/images/sponsors/readysetcam.png" width="80"><br>Ready Set Cam</a></td>
75
76
  <td align="center"><a href="https://www.onahole.com/"><img src="https://sweetalert2.github.io/images/sponsors/onahole.png" width="80"><br>hentai sex toys</a></td>
76
77
  <td align="center"><a href="https://blowupdollshop.com/inflatable-sex-doll/"><img src="https://sweetalert2.github.io/images/sponsors/blowupdollshop.png" width="80"><br>Inflatable sex doll</a></td>
77
- <td align="center"><a href="https://sextoystop.com/"><img src="https://sweetalert2.github.io/images/sponsors/sextoystop.png" width="80"><br>Sex Doll Torso</a></td>
78
78
  </tr>
79
79
  </table>
80
80
  <table>
81
81
  <tr>
82
+ <td align="center"><a href="https://sextoystop.com/"><img src="https://sweetalert2.github.io/images/sponsors/sextoystop.png" width="80"><br>Sex Doll Torso</a></td>
82
83
  <td align="center"><a href="https://sexydollies.com/"><img src="https://sweetalert2.github.io/images/sponsors/sexydollies.png" width="80"><br>porn sexdoll</a></td>
83
84
  <td align="center"><a href="https://bululusexdoll.com/"><img src="https://sweetalert2.github.io/images/sponsors/bululusexdoll.png" width="80"><br>cheap sex doll</a></td>
84
85
  <td align="center"><a href="https://bululu.shop/"><img src="https://sweetalert2.github.io/images/sponsors/bululu.png" width="80"><br>BULULU</a></td>
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sweetalert2 v11.7.20
2
+ * sweetalert2 v11.7.22
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%';
@@ -1111,10 +1117,16 @@
1111
1117
  */
1112
1118
  const renderInput = (instance, params) => {
1113
1119
  const popup = getPopup();
1120
+ if (!popup) {
1121
+ return;
1122
+ }
1114
1123
  const innerParams = privateProps.innerParams.get(instance);
1115
1124
  const rerender = !innerParams || params.input !== innerParams.input;
1116
1125
  inputClasses.forEach(inputClass => {
1117
1126
  const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]);
1127
+ if (!inputContainer) {
1128
+ return;
1129
+ }
1118
1130
 
1119
1131
  // set attributes
1120
1132
  setAttributes(inputClass, params.inputAttributes);
@@ -1138,6 +1150,9 @@
1138
1150
  * @param {SweetAlertOptions} params
1139
1151
  */
1140
1152
  const showInput = params => {
1153
+ if (!params.input) {
1154
+ return;
1155
+ }
1141
1156
  if (!renderInputType[params.input]) {
1142
1157
  error(`Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "${params.input}"`);
1143
1158
  return;
@@ -1240,7 +1255,7 @@
1240
1255
  }
1241
1256
  };
1242
1257
 
1243
- /** @type {Record<string, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */
1258
+ /** @type {Record<SweetAlertInput, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */
1244
1259
  const renderInputType = {};
1245
1260
 
1246
1261
  /**
@@ -2321,7 +2336,7 @@
2321
2336
  * Shows loader (spinner), this is useful with AJAX requests.
2322
2337
  * By default the loader be shown instead of the "Confirm" button.
2323
2338
  *
2324
- * @param {HTMLButtonElement} [buttonToReplace]
2339
+ * @param {HTMLButtonElement | null} [buttonToReplace]
2325
2340
  */
2326
2341
  const showLoading = buttonToReplace => {
2327
2342
  let popup = getPopup();
@@ -2330,6 +2345,9 @@
2330
2345
  }
2331
2346
 
2332
2347
  popup = getPopup();
2348
+ if (!popup) {
2349
+ return;
2350
+ }
2333
2351
  const loader = getLoader();
2334
2352
  if (isToast()) {
2335
2353
  hide(getIcon());
@@ -2344,11 +2362,14 @@
2344
2362
 
2345
2363
  /**
2346
2364
  * @param {HTMLElement} popup
2347
- * @param {HTMLButtonElement} [buttonToReplace]
2365
+ * @param {HTMLButtonElement | null} [buttonToReplace]
2348
2366
  */
2349
2367
  const replaceButton = (popup, buttonToReplace) => {
2350
2368
  const actions = getActions();
2351
2369
  const loader = getLoader();
2370
+ if (!actions || !loader) {
2371
+ return;
2372
+ }
2352
2373
  if (!buttonToReplace && isVisible$1(getConfirmButton())) {
2353
2374
  buttonToReplace = getConfirmButton();
2354
2375
  }
@@ -2356,13 +2377,13 @@
2356
2377
  if (buttonToReplace) {
2357
2378
  hide(buttonToReplace);
2358
2379
  loader.setAttribute('data-button-to-replace', buttonToReplace.className);
2380
+ actions.insertBefore(loader, buttonToReplace);
2359
2381
  }
2360
- loader.parentNode.insertBefore(loader, buttonToReplace);
2361
2382
  addClass([popup, actions], swalClasses.loading);
2362
2383
  };
2363
2384
 
2364
2385
  /**
2365
- * @typedef { string | number | boolean } InputValue
2386
+ * @typedef { string | number | boolean | undefined } InputValue
2366
2387
  */
2367
2388
 
2368
2389
  /**
@@ -2372,7 +2393,7 @@
2372
2393
  const handleInputOptionsAndValue = (instance, params) => {
2373
2394
  if (params.input === 'select' || params.input === 'radio') {
2374
2395
  handleInputOptions(instance, params);
2375
- } else if (['text', 'email', 'number', 'tel', 'textarea'].includes(params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
2396
+ } else if (['text', 'email', 'number', 'tel', 'textarea'].some(i => i === params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
2376
2397
  showLoading(getConfirmButton());
2377
2398
  handleInputValue(instance, params);
2378
2399
  }
@@ -2416,7 +2437,7 @@
2416
2437
  * @param {HTMLInputElement} input
2417
2438
  * @returns {FileList | File | null}
2418
2439
  */
2419
- const getFileValue = input => input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
2440
+ const getFileValue = input => input.files && input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
2420
2441
 
2421
2442
  /**
2422
2443
  * @param {SweetAlert} instance
@@ -2424,11 +2445,18 @@
2424
2445
  */
2425
2446
  const handleInputOptions = (instance, params) => {
2426
2447
  const popup = getPopup();
2448
+ if (!popup) {
2449
+ return;
2450
+ }
2427
2451
  /**
2428
2452
  * @param {Record<string, any>} inputOptions
2429
2453
  */
2430
2454
  const processInputOptions = inputOptions => {
2431
- populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params);
2455
+ if (params.input === 'select') {
2456
+ populateSelectOptions(popup, formatInputOptions(inputOptions), params);
2457
+ } else if (params.input === 'radio') {
2458
+ populateRadioOptions(popup, formatInputOptions(inputOptions), params);
2459
+ }
2432
2460
  };
2433
2461
  if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
2434
2462
  showLoading(getConfirmButton());
@@ -2449,6 +2477,9 @@
2449
2477
  */
2450
2478
  const handleInputValue = (instance, params) => {
2451
2479
  const input = instance.getInput();
2480
+ if (!input) {
2481
+ return;
2482
+ }
2452
2483
  hide(input);
2453
2484
  asPromise(params.inputValue).then(inputValue => {
2454
2485
  input.value = params.input === 'number' ? `${parseFloat(inputValue) || 0}` : `${inputValue}`;
@@ -2463,88 +2494,96 @@
2463
2494
  instance.hideLoading();
2464
2495
  });
2465
2496
  };
2466
- const populateInputOptions = {
2467
- /**
2468
- * @param {HTMLElement} popup
2469
- * @param {Record<string, any>} inputOptions
2470
- * @param {SweetAlertOptions} params
2471
- */
2472
- select: (popup, inputOptions, params) => {
2473
- const select = getDirectChildByClass(popup, swalClasses.select);
2474
- /**
2475
- * @param {HTMLElement} parent
2476
- * @param {string} optionLabel
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
- },
2497
+
2498
+ /**
2499
+ * @param {HTMLElement} popup
2500
+ * @param {InputOptionFlattened[]} inputOptions
2501
+ * @param {SweetAlertOptions} params
2502
+ */
2503
+ function populateSelectOptions(popup, inputOptions, params) {
2504
+ const select = getDirectChildByClass(popup, swalClasses.select);
2505
+ if (!select) {
2506
+ return;
2507
+ }
2507
2508
  /**
2508
- * @param {HTMLElement} popup
2509
- * @param {Record<string, any>} inputOptions
2510
- * @param {SweetAlertOptions} params
2509
+ * @param {HTMLElement} parent
2510
+ * @param {string} optionLabel
2511
+ * @param {string} optionValue
2511
2512
  */
2512
- radio: (popup, inputOptions, params) => {
2513
- const radio = getDirectChildByClass(popup, swalClasses.radio);
2514
- inputOptions.forEach(inputOption => {
2515
- const radioValue = inputOption[0];
2516
- const radioLabel = inputOption[1];
2517
- const radioInput = document.createElement('input');
2518
- const radioLabelElement = document.createElement('label');
2519
- radioInput.type = 'radio';
2520
- radioInput.name = swalClasses.radio;
2521
- radioInput.value = radioValue;
2522
- if (isSelected(radioValue, params.inputValue)) {
2523
- radioInput.checked = true;
2524
- }
2525
- const label = document.createElement('span');
2526
- setInnerHtml(label, radioLabel);
2527
- label.className = swalClasses.label;
2528
- radioLabelElement.appendChild(radioInput);
2529
- radioLabelElement.appendChild(label);
2530
- radio.appendChild(radioLabelElement);
2531
- });
2532
- const radios = radio.querySelectorAll('input');
2533
- if (radios.length) {
2534
- radios[0].focus();
2513
+ const renderOption = (parent, optionLabel, optionValue) => {
2514
+ const option = document.createElement('option');
2515
+ option.value = optionValue;
2516
+ setInnerHtml(option, optionLabel);
2517
+ option.selected = isSelected(optionValue, params.inputValue);
2518
+ parent.appendChild(option);
2519
+ };
2520
+ inputOptions.forEach(inputOption => {
2521
+ const optionValue = inputOption[0];
2522
+ const optionLabel = inputOption[1];
2523
+ // <optgroup> spec:
2524
+ // https://www.w3.org/TR/html401/interact/forms.html#h-17.6
2525
+ // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
2526
+ // check whether this is a <optgroup>
2527
+ if (Array.isArray(optionLabel)) {
2528
+ // if it is an array, then it is an <optgroup>
2529
+ const optgroup = document.createElement('optgroup');
2530
+ optgroup.label = optionValue;
2531
+ optgroup.disabled = false; // not configurable for now
2532
+ select.appendChild(optgroup);
2533
+ optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
2534
+ } else {
2535
+ // case of <option>
2536
+ renderOption(select, optionLabel, optionValue);
2535
2537
  }
2538
+ });
2539
+ select.focus();
2540
+ }
2541
+
2542
+ /**
2543
+ * @param {HTMLElement} popup
2544
+ * @param {InputOptionFlattened[]} inputOptions
2545
+ * @param {SweetAlertOptions} params
2546
+ */
2547
+ function populateRadioOptions(popup, inputOptions, params) {
2548
+ const radio = getDirectChildByClass(popup, swalClasses.radio);
2549
+ if (!radio) {
2550
+ return;
2536
2551
  }
2537
- };
2552
+ inputOptions.forEach(inputOption => {
2553
+ const radioValue = inputOption[0];
2554
+ const radioLabel = inputOption[1];
2555
+ const radioInput = document.createElement('input');
2556
+ const radioLabelElement = document.createElement('label');
2557
+ radioInput.type = 'radio';
2558
+ radioInput.name = swalClasses.radio;
2559
+ radioInput.value = radioValue;
2560
+ if (isSelected(radioValue, params.inputValue)) {
2561
+ radioInput.checked = true;
2562
+ }
2563
+ const label = document.createElement('span');
2564
+ setInnerHtml(label, radioLabel);
2565
+ label.className = swalClasses.label;
2566
+ radioLabelElement.appendChild(radioInput);
2567
+ radioLabelElement.appendChild(label);
2568
+ radio.appendChild(radioLabelElement);
2569
+ });
2570
+ const radios = radio.querySelectorAll('input');
2571
+ if (radios.length) {
2572
+ radios[0].focus();
2573
+ }
2574
+ }
2538
2575
 
2539
2576
  /**
2540
2577
  * Converts `inputOptions` into an array of `[value, label]`s
2541
2578
  *
2542
2579
  * @param {Record<string, any>} inputOptions
2543
- * @returns {Array<Array<string>>}
2580
+ * @typedef {string[]} InputOptionFlattened
2581
+ * @returns {InputOptionFlattened[]}
2544
2582
  */
2545
2583
  const formatInputOptions = inputOptions => {
2584
+ /** @type {InputOptionFlattened[]} */
2546
2585
  const result = [];
2547
- if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
2586
+ if (inputOptions instanceof Map) {
2548
2587
  inputOptions.forEach((value, key) => {
2549
2588
  let valueFormatted = value;
2550
2589
  if (typeof valueFormatted === 'object') {
@@ -2572,7 +2611,7 @@
2572
2611
  * @returns {boolean}
2573
2612
  */
2574
2613
  const isSelected = (optionValue, inputValue) => {
2575
- return inputValue && inputValue.toString() === optionValue.toString();
2614
+ return !!inputValue && inputValue.toString() === optionValue.toString();
2576
2615
  };
2577
2616
 
2578
2617
  /**
@@ -2620,10 +2659,11 @@
2620
2659
  error(`The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`);
2621
2660
  return;
2622
2661
  }
2662
+ const input = instance.getInput();
2623
2663
  const inputValue = getInputValue(instance, innerParams);
2624
2664
  if (innerParams.inputValidator) {
2625
2665
  handleInputValidator(instance, inputValue, type);
2626
- } else if (!instance.getInput().checkValidity()) {
2666
+ } else if (input && !input.checkValidity()) {
2627
2667
  instance.enableButtons();
2628
2668
  instance.showValidationMessage(innerParams.validationMessage);
2629
2669
  } else if (type === 'deny') {
@@ -2794,16 +2834,17 @@
2794
2834
  }
2795
2835
 
2796
2836
  /**
2797
- * @param {HTMLInputElement} input
2837
+ * @param {HTMLInputElement | null} input
2798
2838
  * @param {boolean} disabled
2799
2839
  */
2800
2840
  function setInputDisabled(input, disabled) {
2801
- if (!input) {
2841
+ const popup = getPopup();
2842
+ if (!popup || !input) {
2802
2843
  return;
2803
2844
  }
2804
2845
  if (input.type === 'radio') {
2805
- const radiosContainer = input.parentNode.parentNode;
2806
- const radios = radiosContainer.querySelectorAll('input');
2846
+ /** @type {NodeListOf<HTMLInputElement>} */
2847
+ const radios = popup.querySelectorAll(`[name="${swalClasses.radio}"]`);
2807
2848
  for (let i = 0; i < radios.length; i++) {
2808
2849
  radios[i].disabled = disabled;
2809
2850
  }
@@ -2814,6 +2855,7 @@
2814
2855
 
2815
2856
  /**
2816
2857
  * Enable all the buttons
2858
+ * @this {SweetAlert}
2817
2859
  */
2818
2860
  function enableButtons() {
2819
2861
  setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
@@ -2821,6 +2863,7 @@
2821
2863
 
2822
2864
  /**
2823
2865
  * Disable all the buttons
2866
+ * @this {SweetAlert}
2824
2867
  */
2825
2868
  function disableButtons() {
2826
2869
  setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
@@ -2828,6 +2871,7 @@
2828
2871
 
2829
2872
  /**
2830
2873
  * Enable the input field
2874
+ * @this {SweetAlert}
2831
2875
  */
2832
2876
  function enableInput() {
2833
2877
  setInputDisabled(this.getInput(), false);
@@ -2835,6 +2879,7 @@
2835
2879
 
2836
2880
  /**
2837
2881
  * Disable the input field
2882
+ * @this {SweetAlert}
2838
2883
  */
2839
2884
  function disableInput() {
2840
2885
  setInputDisabled(this.getInput(), true);
@@ -4190,7 +4235,7 @@
4190
4235
  };
4191
4236
  });
4192
4237
  SweetAlert.DismissReason = DismissReason;
4193
- SweetAlert.version = '11.7.20';
4238
+ SweetAlert.version = '11.7.22';
4194
4239
 
4195
4240
  const Swal = SweetAlert;
4196
4241
  // @ts-ignore