sweetalert2 11.26.12 → 11.26.14

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.12
2
+ * sweetalert2 v11.26.14
3
3
  * Released under the MIT License.
4
4
  */
5
5
  (function (global, factory) {
@@ -870,7 +870,7 @@
870
870
  */
871
871
  const handleObject = (param, target) => {
872
872
  // JQuery element(s)
873
- if (param.jquery) {
873
+ if ('jquery' in param) {
874
874
  handleJqueryElem(target, param);
875
875
  }
876
876
 
@@ -882,7 +882,7 @@
882
882
 
883
883
  /**
884
884
  * @param {HTMLElement} target
885
- * @param {object} elem
885
+ * @param {any} elem
886
886
  */
887
887
  const handleJqueryElem = (target, elem) => {
888
888
  target.textContent = '';
@@ -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
  /**
@@ -1876,6 +1906,7 @@
1876
1906
  * @param {SweetAlertOptions} params
1877
1907
  */
1878
1908
  const render = (instance, params) => {
1909
+ var _globalState$eventEmi;
1879
1910
  renderPopup(instance, params);
1880
1911
  renderContainer(instance, params);
1881
1912
  renderProgressSteps(instance, params);
@@ -1890,7 +1921,7 @@
1890
1921
  if (typeof params.didRender === 'function' && popup) {
1891
1922
  params.didRender(popup);
1892
1923
  }
1893
- globalState.eventEmitter.emit('didRender', popup);
1924
+ (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('didRender', popup);
1894
1925
  };
1895
1926
 
1896
1927
  /*
@@ -2784,7 +2815,7 @@
2784
2815
  * @returns {boolean}
2785
2816
  */
2786
2817
  const isSelected = (optionValue, inputValue) => {
2787
- return Boolean(inputValue) && inputValue.toString() === optionValue.toString();
2818
+ return Boolean(inputValue) && inputValue !== null && inputValue !== undefined && inputValue.toString() === optionValue.toString();
2788
2819
  };
2789
2820
 
2790
2821
  /**
@@ -3960,9 +3991,9 @@
3960
3991
  if (!paramName || !value) {
3961
3992
  return;
3962
3993
  }
3963
- if (typeof defaultParams[paramName] === 'boolean') {
3994
+ if (paramName in defaultParams && typeof defaultParams[(/** @type {keyof typeof defaultParams} */paramName)] === 'boolean') {
3964
3995
  result[paramName] = value !== 'false';
3965
- } else if (typeof defaultParams[paramName] === 'object') {
3996
+ } else if (paramName in defaultParams && typeof defaultParams[(/** @type {keyof typeof defaultParams} */paramName)] === 'object') {
3966
3997
  result[paramName] = JSON.parse(value);
3967
3998
  } else {
3968
3999
  result[paramName] = value;
@@ -4009,10 +4040,16 @@
4009
4040
  result[`${type}ButtonText`] = button.innerHTML;
4010
4041
  result[`show${capitalizeFirstLetter(type)}Button`] = true;
4011
4042
  if (button.hasAttribute('color')) {
4012
- result[`${type}ButtonColor`] = button.getAttribute('color');
4043
+ const color = button.getAttribute('color');
4044
+ if (color !== null) {
4045
+ result[`${type}ButtonColor`] = color;
4046
+ }
4013
4047
  }
4014
4048
  if (button.hasAttribute('aria-label')) {
4015
- result[`${type}ButtonAriaLabel`] = button.getAttribute('aria-label');
4049
+ const ariaLabel = button.getAttribute('aria-label');
4050
+ if (ariaLabel !== null) {
4051
+ result[`${type}ButtonAriaLabel`] = ariaLabel;
4052
+ }
4016
4053
  }
4017
4054
  });
4018
4055
  return result;
@@ -4070,7 +4107,7 @@
4070
4107
  * @returns {object}
4071
4108
  */
4072
4109
  const getSwalInput = templateContent => {
4073
- /** @type {object} */
4110
+ /** @type {Record<string, any>} */
4074
4111
  const result = {};
4075
4112
  /** @type {HTMLElement | null} */
4076
4113
  const input = templateContent.querySelector('swal-input');
@@ -4637,7 +4674,7 @@
4637
4674
  };
4638
4675
  });
4639
4676
  SweetAlert.DismissReason = DismissReason;
4640
- SweetAlert.version = '11.26.12';
4677
+ SweetAlert.version = '11.26.14';
4641
4678
 
4642
4679
  const Swal = SweetAlert;
4643
4680
  // @ts-ignore