sweetalert2 11.26.11 → 11.26.13

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sweetalert2 v11.26.11
2
+ * sweetalert2 v11.26.13
3
3
  * Released under the MIT License.
4
4
  */
5
5
  (function (global, factory) {
@@ -626,7 +626,7 @@
626
626
  * @param {HTMLElement | null} elem
627
627
  * @returns {boolean}
628
628
  */
629
- const isVisible$1 = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
629
+ const isVisible$1 = elem => Boolean(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
630
630
 
631
631
  /**
632
632
  * @returns {boolean}
@@ -637,7 +637,7 @@
637
637
  * @param {HTMLElement} elem
638
638
  * @returns {boolean}
639
639
  */
640
- const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight);
640
+ const isScrollable = elem => Boolean(elem.scrollHeight > elem.clientHeight);
641
641
 
642
642
  /**
643
643
  * @param {HTMLElement} element
@@ -1269,96 +1269,119 @@
1269
1269
  const renderInputType = {};
1270
1270
 
1271
1271
  /**
1272
- * @param {HTMLInputElement} input
1272
+ * @param {Input | HTMLElement} input
1273
1273
  * @param {SweetAlertOptions} params
1274
- * @returns {HTMLInputElement}
1274
+ * @returns {Input}
1275
1275
  */
1276
1276
  renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = renderInputType.search = renderInputType.date = renderInputType['datetime-local'] = renderInputType.time = renderInputType.week = renderInputType.month = /** @type {(input: Input | HTMLElement, params: SweetAlertOptions) => Input} */
1277
1277
  (input, params) => {
1278
- checkAndSetInputValue(input, params.inputValue);
1279
- setInputLabel(input, input, params);
1280
- setInputPlaceholder(input, params);
1281
- input.type = params.input;
1282
- return input;
1278
+ const inputElement = /** @type {HTMLInputElement} */input;
1279
+ checkAndSetInputValue(inputElement, params.inputValue);
1280
+ setInputLabel(inputElement, inputElement, params);
1281
+ setInputPlaceholder(inputElement, params);
1282
+ inputElement.type = /** @type {string} */params.input;
1283
+ return inputElement;
1283
1284
  };
1284
1285
 
1285
1286
  /**
1286
- * @param {HTMLInputElement} input
1287
+ * @param {Input | HTMLElement} input
1287
1288
  * @param {SweetAlertOptions} params
1288
- * @returns {HTMLInputElement}
1289
+ * @returns {Input}
1289
1290
  */
1290
1291
  renderInputType.file = (input, params) => {
1291
- setInputLabel(input, input, params);
1292
- setInputPlaceholder(input, params);
1293
- return input;
1292
+ const inputElement = /** @type {HTMLInputElement} */input;
1293
+ setInputLabel(inputElement, inputElement, params);
1294
+ setInputPlaceholder(inputElement, params);
1295
+ return inputElement;
1294
1296
  };
1295
1297
 
1296
1298
  /**
1297
- * @param {HTMLInputElement} range
1299
+ * @param {Input | HTMLElement} range
1298
1300
  * @param {SweetAlertOptions} params
1299
- * @returns {HTMLInputElement}
1301
+ * @returns {Input}
1300
1302
  */
1301
1303
  renderInputType.range = (range, params) => {
1302
- const rangeInput = range.querySelector('input');
1303
- const rangeOutput = range.querySelector('output');
1304
- checkAndSetInputValue(rangeInput, params.inputValue);
1305
- rangeInput.type = params.input;
1306
- checkAndSetInputValue(rangeOutput, params.inputValue);
1307
- setInputLabel(rangeInput, range, params);
1308
- return range;
1304
+ const rangeContainer = /** @type {HTMLElement} */range;
1305
+ const rangeInput = rangeContainer.querySelector('input');
1306
+ const rangeOutput = rangeContainer.querySelector('output');
1307
+ if (rangeInput) {
1308
+ checkAndSetInputValue(rangeInput, params.inputValue);
1309
+ rangeInput.type = /** @type {string} */params.input;
1310
+ setInputLabel(rangeInput, /** @type {Input} */range, params);
1311
+ }
1312
+ if (rangeOutput) {
1313
+ checkAndSetInputValue(rangeOutput, params.inputValue);
1314
+ }
1315
+ return /** @type {Input} */range;
1309
1316
  };
1310
1317
 
1311
1318
  /**
1312
- * @param {HTMLSelectElement} select
1319
+ * @param {Input | HTMLElement} select
1313
1320
  * @param {SweetAlertOptions} params
1314
- * @returns {HTMLSelectElement}
1321
+ * @returns {Input}
1315
1322
  */
1316
1323
  renderInputType.select = (select, params) => {
1317
- select.textContent = '';
1324
+ const selectElement = /** @type {HTMLSelectElement} */select;
1325
+ selectElement.textContent = '';
1318
1326
  if (params.inputPlaceholder) {
1319
1327
  const placeholder = document.createElement('option');
1320
1328
  setInnerHtml(placeholder, params.inputPlaceholder);
1321
1329
  placeholder.value = '';
1322
1330
  placeholder.disabled = true;
1323
1331
  placeholder.selected = true;
1324
- select.appendChild(placeholder);
1332
+ selectElement.appendChild(placeholder);
1325
1333
  }
1326
- setInputLabel(select, select, params);
1327
- return select;
1334
+ setInputLabel(selectElement, selectElement, params);
1335
+ return selectElement;
1328
1336
  };
1329
1337
 
1330
1338
  /**
1331
- * @param {HTMLInputElement} radio
1332
- * @returns {HTMLInputElement}
1339
+ * @param {Input | HTMLElement} radio
1340
+ * @returns {Input}
1333
1341
  */
1334
1342
  renderInputType.radio = radio => {
1335
- radio.textContent = '';
1336
- return radio;
1343
+ const radioElement = /** @type {HTMLElement} */radio;
1344
+ radioElement.textContent = '';
1345
+ return /** @type {Input} */radio;
1337
1346
  };
1338
1347
 
1339
1348
  /**
1340
- * @param {HTMLLabelElement} checkboxContainer
1349
+ * @param {Input | HTMLElement} checkboxContainer
1341
1350
  * @param {SweetAlertOptions} params
1342
- * @returns {HTMLInputElement}
1351
+ * @returns {Input}
1343
1352
  */
1344
1353
  renderInputType.checkbox = (checkboxContainer, params) => {
1345
- const checkbox = getInput$1(getPopup(), 'checkbox');
1354
+ const popup = getPopup();
1355
+ if (!popup) {
1356
+ throw new Error('Popup not found');
1357
+ }
1358
+ const checkbox = getInput$1(popup, 'checkbox');
1359
+ if (!checkbox) {
1360
+ throw new Error('Checkbox input not found');
1361
+ }
1346
1362
  checkbox.value = '1';
1347
1363
  checkbox.checked = Boolean(params.inputValue);
1348
- const label = checkboxContainer.querySelector('span');
1349
- setInnerHtml(label, params.inputPlaceholder || params.inputLabel);
1364
+ const containerElement = /** @type {HTMLElement} */checkboxContainer;
1365
+ const label = containerElement.querySelector('span');
1366
+ if (label) {
1367
+ const placeholderOrLabel = params.inputPlaceholder || params.inputLabel;
1368
+ if (placeholderOrLabel) {
1369
+ setInnerHtml(label, placeholderOrLabel);
1370
+ }
1371
+ }
1350
1372
  return checkbox;
1351
1373
  };
1352
1374
 
1353
1375
  /**
1354
- * @param {HTMLTextAreaElement} textarea
1376
+ * @param {Input | HTMLElement} textarea
1355
1377
  * @param {SweetAlertOptions} params
1356
- * @returns {HTMLTextAreaElement}
1378
+ * @returns {Input}
1357
1379
  */
1358
1380
  renderInputType.textarea = (textarea, params) => {
1359
- checkAndSetInputValue(textarea, params.inputValue);
1360
- setInputPlaceholder(textarea, params);
1361
- setInputLabel(textarea, textarea, params);
1381
+ const textareaElement = /** @type {HTMLTextAreaElement} */textarea;
1382
+ checkAndSetInputValue(textareaElement, params.inputValue);
1383
+ setInputPlaceholder(textareaElement, params);
1384
+ setInputLabel(textareaElement, textareaElement, params);
1362
1385
 
1363
1386
  /**
1364
1387
  * @param {HTMLElement} el
@@ -1370,26 +1393,33 @@
1370
1393
  setTimeout(() => {
1371
1394
  // https://github.com/sweetalert2/sweetalert2/issues/1699
1372
1395
  if ('MutationObserver' in window) {
1373
- const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
1396
+ const popup = getPopup();
1397
+ if (!popup) {
1398
+ return;
1399
+ }
1400
+ const initialPopupWidth = parseInt(window.getComputedStyle(popup).width);
1374
1401
  const textareaResizeHandler = () => {
1375
1402
  // check if texarea is still in document (i.e. popup wasn't closed in the meantime)
1376
- if (!document.body.contains(textarea)) {
1403
+ if (!document.body.contains(textareaElement)) {
1377
1404
  return;
1378
1405
  }
1379
- const textareaWidth = textarea.offsetWidth + getMargin(textarea);
1380
- if (textareaWidth > initialPopupWidth) {
1381
- getPopup().style.width = `${textareaWidth}px`;
1382
- } else {
1383
- applyNumericalStyle(getPopup(), 'width', params.width);
1406
+ const textareaWidth = textareaElement.offsetWidth + getMargin(textareaElement);
1407
+ const popupElement = getPopup();
1408
+ if (popupElement) {
1409
+ if (textareaWidth > initialPopupWidth) {
1410
+ popupElement.style.width = `${textareaWidth}px`;
1411
+ } else {
1412
+ applyNumericalStyle(popupElement, 'width', params.width);
1413
+ }
1384
1414
  }
1385
1415
  };
1386
- new MutationObserver(textareaResizeHandler).observe(textarea, {
1416
+ new MutationObserver(textareaResizeHandler).observe(textareaElement, {
1387
1417
  attributes: true,
1388
1418
  attributeFilter: ['style']
1389
1419
  });
1390
1420
  }
1391
1421
  });
1392
- return textarea;
1422
+ return textareaElement;
1393
1423
  };
1394
1424
 
1395
1425
  /**
@@ -1653,7 +1683,11 @@
1653
1683
  */
1654
1684
  const down = event => {
1655
1685
  const popup = getPopup();
1656
- if (event.target === popup || getIcon().contains(/** @type {HTMLElement} */event.target)) {
1686
+ if (!popup) {
1687
+ return;
1688
+ }
1689
+ const icon = getIcon();
1690
+ if (event.target === popup || icon && icon.contains(/** @type {HTMLElement} */event.target)) {
1657
1691
  dragging = true;
1658
1692
  const clientXY = getClientXY(event);
1659
1693
  mousedownX = clientXY.clientX;
@@ -1669,6 +1703,9 @@
1669
1703
  */
1670
1704
  const move = event => {
1671
1705
  const popup = getPopup();
1706
+ if (!popup) {
1707
+ return;
1708
+ }
1672
1709
  if (dragging) {
1673
1710
  let {
1674
1711
  clientX,
@@ -2170,7 +2207,7 @@
2170
2207
  };
2171
2208
 
2172
2209
  // @ts-ignore
2173
- const isSafariOrIOS = typeof window !== 'undefined' && !!window.GestureEvent; // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394
2210
+ const isSafariOrIOS = typeof window !== 'undefined' && Boolean(window.GestureEvent); // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394
2174
2211
 
2175
2212
  /**
2176
2213
  * Fix iOS scrolling
@@ -2246,11 +2283,13 @@
2246
2283
  /**
2247
2284
  * https://github.com/sweetalert2/sweetalert2/issues/1786
2248
2285
  *
2249
- * @param {object} event
2286
+ * @param {TouchEvent} event
2250
2287
  * @returns {boolean}
2251
2288
  */
2252
2289
  const isStylus = event => {
2253
- return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
2290
+ return Boolean(event.touches && event.touches.length &&
2291
+ // @ts-ignore - touchType is not a standard property
2292
+ event.touches[0].touchType === 'stylus');
2254
2293
  };
2255
2294
 
2256
2295
  /**
@@ -2775,7 +2814,7 @@
2775
2814
  * @returns {boolean}
2776
2815
  */
2777
2816
  const isSelected = (optionValue, inputValue) => {
2778
- return !!inputValue && inputValue.toString() === optionValue.toString();
2817
+ return Boolean(inputValue) && inputValue.toString() === optionValue.toString();
2779
2818
  };
2780
2819
 
2781
2820
  /**
@@ -3455,7 +3494,7 @@
3455
3494
  * @returns {boolean}
3456
3495
  */
3457
3496
  const isAnyButtonShown = innerParams => {
3458
- return !!(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton);
3497
+ return Boolean(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton);
3459
3498
  };
3460
3499
  let ignoreOutsideClick = false;
3461
3500
 
@@ -3640,7 +3679,7 @@
3640
3679
  * @returns {boolean}
3641
3680
  */
3642
3681
  const isTimerRunning = () => {
3643
- return !!(globalState.timeout && globalState.timeout.isRunning());
3682
+ return Boolean(globalState.timeout && globalState.timeout.isRunning());
3644
3683
  };
3645
3684
 
3646
3685
  let bodyClickListenerAdded = false;
@@ -3708,10 +3747,11 @@
3708
3747
  */
3709
3748
  once(eventName, eventHandler) {
3710
3749
  /**
3711
- * @param {Array} args
3750
+ * @param {...any} args
3712
3751
  */
3713
3752
  const onceFn = (...args) => {
3714
3753
  this.removeListener(eventName, onceFn);
3754
+ // @ts-ignore
3715
3755
  eventHandler.apply(this, args);
3716
3756
  };
3717
3757
  this.on(eventName, onceFn);
@@ -3719,7 +3759,7 @@
3719
3759
 
3720
3760
  /**
3721
3761
  * @param {string} eventName
3722
- * @param {Array} args
3762
+ * @param {...any} args
3723
3763
  */
3724
3764
  emit(eventName, ...args) {
3725
3765
  this._getHandlersByEventName(eventName).forEach(
@@ -3728,6 +3768,7 @@
3728
3768
  */
3729
3769
  eventHandler => {
3730
3770
  try {
3771
+ // @ts-ignore
3731
3772
  eventHandler.apply(this, args);
3732
3773
  } catch (error) {
3733
3774
  console.error(error);
@@ -4146,12 +4187,16 @@
4146
4187
  * @param {SweetAlertOptions} params
4147
4188
  */
4148
4189
  const openPopup = params => {
4190
+ var _globalState$eventEmi, _globalState$eventEmi2;
4149
4191
  const container = getContainer();
4150
4192
  const popup = getPopup();
4193
+ if (!container || !popup) {
4194
+ return;
4195
+ }
4151
4196
  if (typeof params.willOpen === 'function') {
4152
4197
  params.willOpen(popup);
4153
4198
  }
4154
- globalState.eventEmitter.emit('willOpen', popup);
4199
+ (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('willOpen', popup);
4155
4200
  const bodyStyles = window.getComputedStyle(document.body);
4156
4201
  const initialBodyOverflow = bodyStyles.overflowY;
4157
4202
  addClasses(container, popup, params);
@@ -4161,27 +4206,32 @@
4161
4206
  setScrollingVisibility(container, popup);
4162
4207
  }, SHOW_CLASS_TIMEOUT);
4163
4208
  if (isModal()) {
4164
- fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
4209
+ // Using ternary instead of ?? operator for Webpack 4 compatibility
4210
+ fixScrollContainer(container, params.scrollbarPadding !== undefined ? params.scrollbarPadding : false, initialBodyOverflow);
4165
4211
  setAriaHidden();
4166
4212
  }
4167
4213
  if (!isToast() && !globalState.previousActiveElement) {
4168
4214
  globalState.previousActiveElement = document.activeElement;
4169
4215
  }
4170
4216
  if (typeof params.didOpen === 'function') {
4171
- setTimeout(() => params.didOpen(popup));
4217
+ const didOpen = params.didOpen;
4218
+ setTimeout(() => didOpen(popup));
4172
4219
  }
4173
- globalState.eventEmitter.emit('didOpen', popup);
4220
+ (_globalState$eventEmi2 = globalState.eventEmitter) === null || _globalState$eventEmi2 === void 0 || _globalState$eventEmi2.emit('didOpen', popup);
4174
4221
  };
4175
4222
 
4176
4223
  /**
4177
- * @param {AnimationEvent} event
4224
+ * @param {Event} event
4178
4225
  */
4179
4226
  const swalOpenAnimationFinished = event => {
4180
4227
  const popup = getPopup();
4181
- if (event.target !== popup) {
4228
+ if (!popup || event.target !== popup) {
4182
4229
  return;
4183
4230
  }
4184
4231
  const container = getContainer();
4232
+ if (!container) {
4233
+ return;
4234
+ }
4185
4235
  popup.removeEventListener('animationend', swalOpenAnimationFinished);
4186
4236
  popup.removeEventListener('transitionend', swalOpenAnimationFinished);
4187
4237
  container.style.overflowY = 'auto';
@@ -4227,14 +4277,20 @@
4227
4277
  * @param {SweetAlertOptions} params
4228
4278
  */
4229
4279
  const addClasses = (container, popup, params) => {
4230
- addClass(container, params.showClass.backdrop);
4280
+ var _params$showClass;
4281
+ if ((_params$showClass = params.showClass) !== null && _params$showClass !== void 0 && _params$showClass.backdrop) {
4282
+ addClass(container, params.showClass.backdrop);
4283
+ }
4231
4284
  if (params.animation) {
4232
4285
  // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
4233
4286
  popup.style.setProperty('opacity', '0', 'important');
4234
4287
  show(popup, 'grid');
4235
4288
  setTimeout(() => {
4289
+ var _params$showClass2;
4236
4290
  // Animate popup right after showing it
4237
- addClass(popup, params.showClass.popup);
4291
+ if ((_params$showClass2 = params.showClass) !== null && _params$showClass2 !== void 0 && _params$showClass2.popup) {
4292
+ addClass(popup, params.showClass.popup);
4293
+ }
4238
4294
  // and remove the opacity workaround
4239
4295
  popup.style.removeProperty('opacity');
4240
4296
  }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062
@@ -4611,7 +4667,7 @@
4611
4667
  };
4612
4668
  });
4613
4669
  SweetAlert.DismissReason = DismissReason;
4614
- SweetAlert.version = '11.26.11';
4670
+ SweetAlert.version = '11.26.13';
4615
4671
 
4616
4672
  const Swal = SweetAlert;
4617
4673
  // @ts-ignore