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 _assertClassBrand(e, t, n) {
@@ -620,7 +620,7 @@ const toggle = (elem, condition, display = 'flex') => {
620
620
  * @param {HTMLElement | null} elem
621
621
  * @returns {boolean}
622
622
  */
623
- const isVisible$1 = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
623
+ const isVisible$1 = elem => Boolean(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
624
624
 
625
625
  /**
626
626
  * @returns {boolean}
@@ -631,7 +631,7 @@ const allButtonsAreHidden = () => !isVisible$1(getConfirmButton()) && !isVisible
631
631
  * @param {HTMLElement} elem
632
632
  * @returns {boolean}
633
633
  */
634
- const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight);
634
+ const isScrollable = elem => Boolean(elem.scrollHeight > elem.clientHeight);
635
635
 
636
636
  /**
637
637
  * @param {HTMLElement} element
@@ -1263,96 +1263,119 @@ const checkAndSetInputValue = (input, inputValue) => {
1263
1263
  const renderInputType = {};
1264
1264
 
1265
1265
  /**
1266
- * @param {HTMLInputElement} input
1266
+ * @param {Input | HTMLElement} input
1267
1267
  * @param {SweetAlertOptions} params
1268
- * @returns {HTMLInputElement}
1268
+ * @returns {Input}
1269
1269
  */
1270
1270
  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} */
1271
1271
  (input, params) => {
1272
- checkAndSetInputValue(input, params.inputValue);
1273
- setInputLabel(input, input, params);
1274
- setInputPlaceholder(input, params);
1275
- input.type = params.input;
1276
- return input;
1272
+ const inputElement = /** @type {HTMLInputElement} */input;
1273
+ checkAndSetInputValue(inputElement, params.inputValue);
1274
+ setInputLabel(inputElement, inputElement, params);
1275
+ setInputPlaceholder(inputElement, params);
1276
+ inputElement.type = /** @type {string} */params.input;
1277
+ return inputElement;
1277
1278
  };
1278
1279
 
1279
1280
  /**
1280
- * @param {HTMLInputElement} input
1281
+ * @param {Input | HTMLElement} input
1281
1282
  * @param {SweetAlertOptions} params
1282
- * @returns {HTMLInputElement}
1283
+ * @returns {Input}
1283
1284
  */
1284
1285
  renderInputType.file = (input, params) => {
1285
- setInputLabel(input, input, params);
1286
- setInputPlaceholder(input, params);
1287
- return input;
1286
+ const inputElement = /** @type {HTMLInputElement} */input;
1287
+ setInputLabel(inputElement, inputElement, params);
1288
+ setInputPlaceholder(inputElement, params);
1289
+ return inputElement;
1288
1290
  };
1289
1291
 
1290
1292
  /**
1291
- * @param {HTMLInputElement} range
1293
+ * @param {Input | HTMLElement} range
1292
1294
  * @param {SweetAlertOptions} params
1293
- * @returns {HTMLInputElement}
1295
+ * @returns {Input}
1294
1296
  */
1295
1297
  renderInputType.range = (range, params) => {
1296
- const rangeInput = range.querySelector('input');
1297
- const rangeOutput = range.querySelector('output');
1298
- checkAndSetInputValue(rangeInput, params.inputValue);
1299
- rangeInput.type = params.input;
1300
- checkAndSetInputValue(rangeOutput, params.inputValue);
1301
- setInputLabel(rangeInput, range, params);
1302
- return range;
1298
+ const rangeContainer = /** @type {HTMLElement} */range;
1299
+ const rangeInput = rangeContainer.querySelector('input');
1300
+ const rangeOutput = rangeContainer.querySelector('output');
1301
+ if (rangeInput) {
1302
+ checkAndSetInputValue(rangeInput, params.inputValue);
1303
+ rangeInput.type = /** @type {string} */params.input;
1304
+ setInputLabel(rangeInput, /** @type {Input} */range, params);
1305
+ }
1306
+ if (rangeOutput) {
1307
+ checkAndSetInputValue(rangeOutput, params.inputValue);
1308
+ }
1309
+ return /** @type {Input} */range;
1303
1310
  };
1304
1311
 
1305
1312
  /**
1306
- * @param {HTMLSelectElement} select
1313
+ * @param {Input | HTMLElement} select
1307
1314
  * @param {SweetAlertOptions} params
1308
- * @returns {HTMLSelectElement}
1315
+ * @returns {Input}
1309
1316
  */
1310
1317
  renderInputType.select = (select, params) => {
1311
- select.textContent = '';
1318
+ const selectElement = /** @type {HTMLSelectElement} */select;
1319
+ selectElement.textContent = '';
1312
1320
  if (params.inputPlaceholder) {
1313
1321
  const placeholder = document.createElement('option');
1314
1322
  setInnerHtml(placeholder, params.inputPlaceholder);
1315
1323
  placeholder.value = '';
1316
1324
  placeholder.disabled = true;
1317
1325
  placeholder.selected = true;
1318
- select.appendChild(placeholder);
1326
+ selectElement.appendChild(placeholder);
1319
1327
  }
1320
- setInputLabel(select, select, params);
1321
- return select;
1328
+ setInputLabel(selectElement, selectElement, params);
1329
+ return selectElement;
1322
1330
  };
1323
1331
 
1324
1332
  /**
1325
- * @param {HTMLInputElement} radio
1326
- * @returns {HTMLInputElement}
1333
+ * @param {Input | HTMLElement} radio
1334
+ * @returns {Input}
1327
1335
  */
1328
1336
  renderInputType.radio = radio => {
1329
- radio.textContent = '';
1330
- return radio;
1337
+ const radioElement = /** @type {HTMLElement} */radio;
1338
+ radioElement.textContent = '';
1339
+ return /** @type {Input} */radio;
1331
1340
  };
1332
1341
 
1333
1342
  /**
1334
- * @param {HTMLLabelElement} checkboxContainer
1343
+ * @param {Input | HTMLElement} checkboxContainer
1335
1344
  * @param {SweetAlertOptions} params
1336
- * @returns {HTMLInputElement}
1345
+ * @returns {Input}
1337
1346
  */
1338
1347
  renderInputType.checkbox = (checkboxContainer, params) => {
1339
- const checkbox = getInput$1(getPopup(), 'checkbox');
1348
+ const popup = getPopup();
1349
+ if (!popup) {
1350
+ throw new Error('Popup not found');
1351
+ }
1352
+ const checkbox = getInput$1(popup, 'checkbox');
1353
+ if (!checkbox) {
1354
+ throw new Error('Checkbox input not found');
1355
+ }
1340
1356
  checkbox.value = '1';
1341
1357
  checkbox.checked = Boolean(params.inputValue);
1342
- const label = checkboxContainer.querySelector('span');
1343
- setInnerHtml(label, params.inputPlaceholder || params.inputLabel);
1358
+ const containerElement = /** @type {HTMLElement} */checkboxContainer;
1359
+ const label = containerElement.querySelector('span');
1360
+ if (label) {
1361
+ const placeholderOrLabel = params.inputPlaceholder || params.inputLabel;
1362
+ if (placeholderOrLabel) {
1363
+ setInnerHtml(label, placeholderOrLabel);
1364
+ }
1365
+ }
1344
1366
  return checkbox;
1345
1367
  };
1346
1368
 
1347
1369
  /**
1348
- * @param {HTMLTextAreaElement} textarea
1370
+ * @param {Input | HTMLElement} textarea
1349
1371
  * @param {SweetAlertOptions} params
1350
- * @returns {HTMLTextAreaElement}
1372
+ * @returns {Input}
1351
1373
  */
1352
1374
  renderInputType.textarea = (textarea, params) => {
1353
- checkAndSetInputValue(textarea, params.inputValue);
1354
- setInputPlaceholder(textarea, params);
1355
- setInputLabel(textarea, textarea, params);
1375
+ const textareaElement = /** @type {HTMLTextAreaElement} */textarea;
1376
+ checkAndSetInputValue(textareaElement, params.inputValue);
1377
+ setInputPlaceholder(textareaElement, params);
1378
+ setInputLabel(textareaElement, textareaElement, params);
1356
1379
 
1357
1380
  /**
1358
1381
  * @param {HTMLElement} el
@@ -1364,26 +1387,33 @@ renderInputType.textarea = (textarea, params) => {
1364
1387
  setTimeout(() => {
1365
1388
  // https://github.com/sweetalert2/sweetalert2/issues/1699
1366
1389
  if ('MutationObserver' in window) {
1367
- const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
1390
+ const popup = getPopup();
1391
+ if (!popup) {
1392
+ return;
1393
+ }
1394
+ const initialPopupWidth = parseInt(window.getComputedStyle(popup).width);
1368
1395
  const textareaResizeHandler = () => {
1369
1396
  // check if texarea is still in document (i.e. popup wasn't closed in the meantime)
1370
- if (!document.body.contains(textarea)) {
1397
+ if (!document.body.contains(textareaElement)) {
1371
1398
  return;
1372
1399
  }
1373
- const textareaWidth = textarea.offsetWidth + getMargin(textarea);
1374
- if (textareaWidth > initialPopupWidth) {
1375
- getPopup().style.width = `${textareaWidth}px`;
1376
- } else {
1377
- applyNumericalStyle(getPopup(), 'width', params.width);
1400
+ const textareaWidth = textareaElement.offsetWidth + getMargin(textareaElement);
1401
+ const popupElement = getPopup();
1402
+ if (popupElement) {
1403
+ if (textareaWidth > initialPopupWidth) {
1404
+ popupElement.style.width = `${textareaWidth}px`;
1405
+ } else {
1406
+ applyNumericalStyle(popupElement, 'width', params.width);
1407
+ }
1378
1408
  }
1379
1409
  };
1380
- new MutationObserver(textareaResizeHandler).observe(textarea, {
1410
+ new MutationObserver(textareaResizeHandler).observe(textareaElement, {
1381
1411
  attributes: true,
1382
1412
  attributeFilter: ['style']
1383
1413
  });
1384
1414
  }
1385
1415
  });
1386
- return textarea;
1416
+ return textareaElement;
1387
1417
  };
1388
1418
 
1389
1419
  /**
@@ -1647,7 +1677,11 @@ const removeDraggableListeners = popup => {
1647
1677
  */
1648
1678
  const down = event => {
1649
1679
  const popup = getPopup();
1650
- if (event.target === popup || getIcon().contains(/** @type {HTMLElement} */event.target)) {
1680
+ if (!popup) {
1681
+ return;
1682
+ }
1683
+ const icon = getIcon();
1684
+ if (event.target === popup || icon && icon.contains(/** @type {HTMLElement} */event.target)) {
1651
1685
  dragging = true;
1652
1686
  const clientXY = getClientXY(event);
1653
1687
  mousedownX = clientXY.clientX;
@@ -1663,6 +1697,9 @@ const down = event => {
1663
1697
  */
1664
1698
  const move = event => {
1665
1699
  const popup = getPopup();
1700
+ if (!popup) {
1701
+ return;
1702
+ }
1666
1703
  if (dragging) {
1667
1704
  let {
1668
1705
  clientX,
@@ -2164,7 +2201,7 @@ const unsetAriaHidden = () => {
2164
2201
  };
2165
2202
 
2166
2203
  // @ts-ignore
2167
- const isSafariOrIOS = typeof window !== 'undefined' && !!window.GestureEvent; // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394
2204
+ const isSafariOrIOS = typeof window !== 'undefined' && Boolean(window.GestureEvent); // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394
2168
2205
 
2169
2206
  /**
2170
2207
  * Fix iOS scrolling
@@ -2240,11 +2277,13 @@ const shouldPreventTouchMove = event => {
2240
2277
  /**
2241
2278
  * https://github.com/sweetalert2/sweetalert2/issues/1786
2242
2279
  *
2243
- * @param {object} event
2280
+ * @param {TouchEvent} event
2244
2281
  * @returns {boolean}
2245
2282
  */
2246
2283
  const isStylus = event => {
2247
- return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
2284
+ return Boolean(event.touches && event.touches.length &&
2285
+ // @ts-ignore - touchType is not a standard property
2286
+ event.touches[0].touchType === 'stylus');
2248
2287
  };
2249
2288
 
2250
2289
  /**
@@ -2769,7 +2808,7 @@ const formatInputOptions = inputOptions => {
2769
2808
  * @returns {boolean}
2770
2809
  */
2771
2810
  const isSelected = (optionValue, inputValue) => {
2772
- return !!inputValue && inputValue.toString() === optionValue.toString();
2811
+ return Boolean(inputValue) && inputValue.toString() === optionValue.toString();
2773
2812
  };
2774
2813
 
2775
2814
  /**
@@ -3449,7 +3488,7 @@ const handleToastClick = (innerParams, domCache, dismissWith) => {
3449
3488
  * @returns {boolean}
3450
3489
  */
3451
3490
  const isAnyButtonShown = innerParams => {
3452
- return !!(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton);
3491
+ return Boolean(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton);
3453
3492
  };
3454
3493
  let ignoreOutsideClick = false;
3455
3494
 
@@ -3634,7 +3673,7 @@ const increaseTimer = ms => {
3634
3673
  * @returns {boolean}
3635
3674
  */
3636
3675
  const isTimerRunning = () => {
3637
- return !!(globalState.timeout && globalState.timeout.isRunning());
3676
+ return Boolean(globalState.timeout && globalState.timeout.isRunning());
3638
3677
  };
3639
3678
 
3640
3679
  let bodyClickListenerAdded = false;
@@ -3702,10 +3741,11 @@ class EventEmitter {
3702
3741
  */
3703
3742
  once(eventName, eventHandler) {
3704
3743
  /**
3705
- * @param {Array} args
3744
+ * @param {...any} args
3706
3745
  */
3707
3746
  const onceFn = (...args) => {
3708
3747
  this.removeListener(eventName, onceFn);
3748
+ // @ts-ignore
3709
3749
  eventHandler.apply(this, args);
3710
3750
  };
3711
3751
  this.on(eventName, onceFn);
@@ -3713,7 +3753,7 @@ class EventEmitter {
3713
3753
 
3714
3754
  /**
3715
3755
  * @param {string} eventName
3716
- * @param {Array} args
3756
+ * @param {...any} args
3717
3757
  */
3718
3758
  emit(eventName, ...args) {
3719
3759
  this._getHandlersByEventName(eventName).forEach(
@@ -3722,6 +3762,7 @@ class EventEmitter {
3722
3762
  */
3723
3763
  eventHandler => {
3724
3764
  try {
3765
+ // @ts-ignore
3725
3766
  eventHandler.apply(this, args);
3726
3767
  } catch (error) {
3727
3768
  console.error(error);
@@ -4140,12 +4181,16 @@ const SHOW_CLASS_TIMEOUT = 10;
4140
4181
  * @param {SweetAlertOptions} params
4141
4182
  */
4142
4183
  const openPopup = params => {
4184
+ var _globalState$eventEmi, _globalState$eventEmi2;
4143
4185
  const container = getContainer();
4144
4186
  const popup = getPopup();
4187
+ if (!container || !popup) {
4188
+ return;
4189
+ }
4145
4190
  if (typeof params.willOpen === 'function') {
4146
4191
  params.willOpen(popup);
4147
4192
  }
4148
- globalState.eventEmitter.emit('willOpen', popup);
4193
+ (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('willOpen', popup);
4149
4194
  const bodyStyles = window.getComputedStyle(document.body);
4150
4195
  const initialBodyOverflow = bodyStyles.overflowY;
4151
4196
  addClasses(container, popup, params);
@@ -4155,27 +4200,32 @@ const openPopup = params => {
4155
4200
  setScrollingVisibility(container, popup);
4156
4201
  }, SHOW_CLASS_TIMEOUT);
4157
4202
  if (isModal()) {
4158
- fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
4203
+ // Using ternary instead of ?? operator for Webpack 4 compatibility
4204
+ fixScrollContainer(container, params.scrollbarPadding !== undefined ? params.scrollbarPadding : false, initialBodyOverflow);
4159
4205
  setAriaHidden();
4160
4206
  }
4161
4207
  if (!isToast() && !globalState.previousActiveElement) {
4162
4208
  globalState.previousActiveElement = document.activeElement;
4163
4209
  }
4164
4210
  if (typeof params.didOpen === 'function') {
4165
- setTimeout(() => params.didOpen(popup));
4211
+ const didOpen = params.didOpen;
4212
+ setTimeout(() => didOpen(popup));
4166
4213
  }
4167
- globalState.eventEmitter.emit('didOpen', popup);
4214
+ (_globalState$eventEmi2 = globalState.eventEmitter) === null || _globalState$eventEmi2 === void 0 || _globalState$eventEmi2.emit('didOpen', popup);
4168
4215
  };
4169
4216
 
4170
4217
  /**
4171
- * @param {AnimationEvent} event
4218
+ * @param {Event} event
4172
4219
  */
4173
4220
  const swalOpenAnimationFinished = event => {
4174
4221
  const popup = getPopup();
4175
- if (event.target !== popup) {
4222
+ if (!popup || event.target !== popup) {
4176
4223
  return;
4177
4224
  }
4178
4225
  const container = getContainer();
4226
+ if (!container) {
4227
+ return;
4228
+ }
4179
4229
  popup.removeEventListener('animationend', swalOpenAnimationFinished);
4180
4230
  popup.removeEventListener('transitionend', swalOpenAnimationFinished);
4181
4231
  container.style.overflowY = 'auto';
@@ -4221,14 +4271,20 @@ const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) =>
4221
4271
  * @param {SweetAlertOptions} params
4222
4272
  */
4223
4273
  const addClasses = (container, popup, params) => {
4224
- addClass(container, params.showClass.backdrop);
4274
+ var _params$showClass;
4275
+ if ((_params$showClass = params.showClass) !== null && _params$showClass !== void 0 && _params$showClass.backdrop) {
4276
+ addClass(container, params.showClass.backdrop);
4277
+ }
4225
4278
  if (params.animation) {
4226
4279
  // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
4227
4280
  popup.style.setProperty('opacity', '0', 'important');
4228
4281
  show(popup, 'grid');
4229
4282
  setTimeout(() => {
4283
+ var _params$showClass2;
4230
4284
  // Animate popup right after showing it
4231
- addClass(popup, params.showClass.popup);
4285
+ if ((_params$showClass2 = params.showClass) !== null && _params$showClass2 !== void 0 && _params$showClass2.popup) {
4286
+ addClass(popup, params.showClass.popup);
4287
+ }
4232
4288
  // and remove the opacity workaround
4233
4289
  popup.style.removeProperty('opacity');
4234
4290
  }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062
@@ -4605,7 +4661,7 @@ Object.keys(instanceMethods).forEach(key => {
4605
4661
  };
4606
4662
  });
4607
4663
  SweetAlert.DismissReason = DismissReason;
4608
- SweetAlert.version = '11.26.11';
4664
+ SweetAlert.version = '11.26.13';
4609
4665
 
4610
4666
  const Swal = SweetAlert;
4611
4667
  // @ts-ignore