sweetalert2 11.26.15 → 11.26.17

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.15
2
+ * sweetalert2 v11.26.17
3
3
  * Released under the MIT License.
4
4
  */
5
5
  (function (global, factory) {
@@ -1999,8 +1999,9 @@
1999
1999
  * @param {GlobalState} globalState
2000
2000
  */
2001
2001
  const removeKeydownHandler = globalState => {
2002
- if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
2003
- globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
2002
+ if (globalState.keydownTarget && globalState.keydownHandlerAdded && globalState.keydownHandler) {
2003
+ const handler = /** @type {EventListenerOrEventListenerObject} */ /** @type {unknown} */globalState.keydownHandler;
2004
+ globalState.keydownTarget.removeEventListener('keydown', handler, {
2004
2005
  capture: globalState.keydownListenerCapture
2005
2006
  });
2006
2007
  globalState.keydownHandlerAdded = false;
@@ -2015,13 +2016,19 @@
2015
2016
  const addKeydownHandler = (globalState, innerParams, dismissWith) => {
2016
2017
  removeKeydownHandler(globalState);
2017
2018
  if (!innerParams.toast) {
2018
- globalState.keydownHandler = e => keydownHandler(innerParams, e, dismissWith);
2019
- globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
2020
- globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
2021
- globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
2022
- capture: globalState.keydownListenerCapture
2023
- });
2024
- globalState.keydownHandlerAdded = true;
2019
+ /** @type {(this: HTMLElement, event: KeyboardEvent) => void} */
2020
+ const handler = e => keydownHandler(innerParams, e, dismissWith);
2021
+ globalState.keydownHandler = handler;
2022
+ const target = innerParams.keydownListenerCapture ? window : getPopup();
2023
+ if (target) {
2024
+ globalState.keydownTarget = target;
2025
+ globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
2026
+ const eventHandler = /** @type {EventListenerOrEventListenerObject} */ /** @type {unknown} */handler;
2027
+ globalState.keydownTarget.addEventListener('keydown', eventHandler, {
2028
+ capture: globalState.keydownListenerCapture
2029
+ });
2030
+ globalState.keydownHandlerAdded = true;
2031
+ }
2025
2032
  }
2026
2033
  };
2027
2034
 
@@ -2109,7 +2116,11 @@
2109
2116
  if (!callIfFunction(innerParams.allowEnterKey)) {
2110
2117
  return;
2111
2118
  }
2112
- const input = getInput$1(getPopup(), innerParams.input);
2119
+ const popup = getPopup();
2120
+ if (!popup || !innerParams.input) {
2121
+ return;
2122
+ }
2123
+ const input = getInput$1(popup, innerParams.input);
2113
2124
  if (event.target && input && event.target instanceof HTMLElement && event.target.outerHTML === input.outerHTML) {
2114
2125
  if (['textarea', 'file'].includes(innerParams.input)) {
2115
2126
  return; // do not submit
@@ -2390,7 +2401,7 @@
2390
2401
  * @param {SweetAlert} instance
2391
2402
  * @param {HTMLElement} container
2392
2403
  * @param {boolean} returnFocus
2393
- * @param {() => void} didClose
2404
+ * @param {(() => void) | undefined} didClose
2394
2405
  */
2395
2406
  function removePopupAndResetState(instance, container, returnFocus, didClose) {
2396
2407
  if (isToast()) {
@@ -2428,6 +2439,7 @@
2428
2439
  * Instance method to close sweetAlert
2429
2440
  *
2430
2441
  * @param {SweetAlertResult | undefined} resolveValue
2442
+ * @this {SweetAlert}
2431
2443
  */
2432
2444
  function close(resolveValue) {
2433
2445
  resolveValue = prepareResolveValue(resolveValue);
@@ -2444,6 +2456,11 @@
2444
2456
  swalPromiseResolve(resolveValue);
2445
2457
  }
2446
2458
  }
2459
+
2460
+ /**
2461
+ * @param {SweetAlert} instance
2462
+ * @returns {boolean}
2463
+ */
2447
2464
  const triggerClosePopup = instance => {
2448
2465
  const popup = getPopup();
2449
2466
  if (!popup) {
@@ -2464,6 +2481,7 @@
2464
2481
 
2465
2482
  /**
2466
2483
  * @param {Error | string} error
2484
+ * @this {SweetAlert}
2467
2485
  */
2468
2486
  function rejectPromise(error) {
2469
2487
  const rejectPromise = privateMethods.swalPromiseReject.get(this);
@@ -2479,6 +2497,7 @@
2479
2497
  */
2480
2498
  const handleAwaitingPromise = instance => {
2481
2499
  if (instance.isAwaitingPromise) {
2500
+ // @ts-ignore
2482
2501
  delete instance.isAwaitingPromise;
2483
2502
  // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
2484
2503
  if (!privateProps.innerParams.get(instance)) {
@@ -2521,11 +2540,11 @@
2521
2540
  innerParams.willClose(popup);
2522
2541
  }
2523
2542
  (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('willClose', popup);
2524
- if (animationIsSupported) {
2525
- animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
2526
- } else {
2543
+ if (animationIsSupported && container) {
2544
+ animatePopup(instance, popup, container, Boolean(innerParams.returnFocus), innerParams.didClose);
2545
+ } else if (container) {
2527
2546
  // Otherwise, remove immediately
2528
- removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
2547
+ removePopupAndResetState(instance, container, Boolean(innerParams.returnFocus), innerParams.didClose);
2529
2548
  }
2530
2549
  };
2531
2550
 
@@ -2534,7 +2553,7 @@
2534
2553
  * @param {HTMLElement} popup
2535
2554
  * @param {HTMLElement} container
2536
2555
  * @param {boolean} returnFocus
2537
- * @param {() => void} didClose
2556
+ * @param {(() => void) | undefined} didClose
2538
2557
  */
2539
2558
  const animatePopup = (instance, popup, container, returnFocus, didClose) => {
2540
2559
  globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
@@ -2556,7 +2575,7 @@
2556
2575
 
2557
2576
  /**
2558
2577
  * @param {SweetAlert} instance
2559
- * @param {() => void} didClose
2578
+ * @param {(() => void) | undefined} didClose
2560
2579
  */
2561
2580
  const triggerDidCloseAndDispose = (instance, didClose) => {
2562
2581
  setTimeout(() => {
@@ -3010,6 +3029,7 @@
3010
3029
 
3011
3030
  /**
3012
3031
  * Hides loader and shows back the button which was hidden by .showLoading()
3032
+ * @this {SweetAlert}
3013
3033
  */
3014
3034
  function hideLoading() {
3015
3035
  // do nothing if popup is closed
@@ -3033,10 +3053,15 @@
3033
3053
  domCache.denyButton.disabled = false;
3034
3054
  domCache.cancelButton.disabled = false;
3035
3055
  }
3056
+
3057
+ /**
3058
+ * @param {DomCache} domCache
3059
+ */
3036
3060
  const showRelatedButton = domCache => {
3037
- const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
3061
+ const dataButtonToReplace = domCache.loader.getAttribute('data-button-to-replace');
3062
+ const buttonToReplace = dataButtonToReplace ? domCache.popup.getElementsByClassName(dataButtonToReplace) : [];
3038
3063
  if (buttonToReplace.length) {
3039
- show(buttonToReplace[0], 'inline-block');
3064
+ show(/** @type {HTMLElement} */buttonToReplace[0], 'inline-block');
3040
3065
  } else if (allButtonsAreHidden()) {
3041
3066
  hide(domCache.actions);
3042
3067
  }
@@ -3046,6 +3071,7 @@
3046
3071
  * Gets the input DOM node, this method works with input parameter.
3047
3072
  *
3048
3073
  * @returns {HTMLInputElement | null}
3074
+ * @this {SweetAlert}
3049
3075
  */
3050
3076
  function getInput() {
3051
3077
  const innerParams = privateProps.innerParams.get(this);
@@ -3346,6 +3372,7 @@
3346
3372
  /**
3347
3373
  * Updates popup parameters.
3348
3374
  *
3375
+ * @this {any}
3349
3376
  * @param {SweetAlertOptions} params
3350
3377
  */
3351
3378
  function update(params) {
@@ -3359,7 +3386,9 @@
3359
3386
  const validUpdatableParams = filterValidParams(params);
3360
3387
  const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
3361
3388
  showWarningsForParams(updatedParams);
3362
- container.dataset['swal2Theme'] = updatedParams.theme;
3389
+ if (container) {
3390
+ container.dataset['swal2Theme'] = updatedParams.theme;
3391
+ }
3363
3392
  render(this, updatedParams);
3364
3393
  privateProps.innerParams.set(this, updatedParams);
3365
3394
  Object.defineProperties(this, {
@@ -3376,10 +3405,12 @@
3376
3405
  * @returns {SweetAlertOptions}
3377
3406
  */
3378
3407
  const filterValidParams = params => {
3408
+ /** @type {Record<string, any>} */
3379
3409
  const validUpdatableParams = {};
3380
3410
  Object.keys(params).forEach(param => {
3381
3411
  if (isUpdatableParameter(param)) {
3382
- validUpdatableParams[param] = params[param];
3412
+ const typedParams = /** @type {Record<string, any>} */params;
3413
+ validUpdatableParams[param] = typedParams[param];
3383
3414
  } else {
3384
3415
  warn(`Invalid parameter to update: ${param}`);
3385
3416
  }
@@ -3389,8 +3420,10 @@
3389
3420
 
3390
3421
  /**
3391
3422
  * Dispose the current SweetAlert2 instance
3423
+ * @this {SweetAlert}
3392
3424
  */
3393
3425
  function _destroy() {
3426
+ var _globalState$eventEmi;
3394
3427
  const domCache = privateProps.domCache.get(this);
3395
3428
  const innerParams = privateProps.innerParams.get(this);
3396
3429
  if (!innerParams) {
@@ -3406,7 +3439,7 @@
3406
3439
  if (typeof innerParams.didDestroy === 'function') {
3407
3440
  innerParams.didDestroy();
3408
3441
  }
3409
- globalState.eventEmitter.emit('didDestroy');
3442
+ (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('didDestroy');
3410
3443
  disposeSwal(this);
3411
3444
  }
3412
3445
 
@@ -3416,6 +3449,7 @@
3416
3449
  const disposeSwal = instance => {
3417
3450
  disposeWeakMaps(instance);
3418
3451
  // Unset this.params so GC will dispose it (#1569)
3452
+ // @ts-ignore
3419
3453
  delete instance.params;
3420
3454
  // Unset globalState props so GC will dispose globalState (#1569)
3421
3455
  delete globalState.keydownHandler;
@@ -3435,29 +3469,47 @@
3435
3469
  } else {
3436
3470
  unsetWeakMaps(privateMethods, instance);
3437
3471
  unsetWeakMaps(privateProps, instance);
3472
+
3473
+ // @ts-ignore
3438
3474
  delete instance.isAwaitingPromise;
3439
3475
  // Unset instance methods
3476
+ // @ts-ignore
3440
3477
  delete instance.disableButtons;
3478
+ // @ts-ignore
3441
3479
  delete instance.enableButtons;
3480
+ // @ts-ignore
3442
3481
  delete instance.getInput;
3482
+ // @ts-ignore
3443
3483
  delete instance.disableInput;
3484
+ // @ts-ignore
3444
3485
  delete instance.enableInput;
3486
+ // @ts-ignore
3445
3487
  delete instance.hideLoading;
3488
+ // @ts-ignore
3446
3489
  delete instance.disableLoading;
3490
+ // @ts-ignore
3447
3491
  delete instance.showValidationMessage;
3492
+ // @ts-ignore
3448
3493
  delete instance.resetValidationMessage;
3494
+ // @ts-ignore
3449
3495
  delete instance.close;
3496
+ // @ts-ignore
3450
3497
  delete instance.closePopup;
3498
+ // @ts-ignore
3451
3499
  delete instance.closeModal;
3500
+ // @ts-ignore
3452
3501
  delete instance.closeToast;
3502
+ // @ts-ignore
3453
3503
  delete instance.rejectPromise;
3504
+ // @ts-ignore
3454
3505
  delete instance.update;
3506
+ // @ts-ignore
3455
3507
  delete instance._destroy;
3456
3508
  }
3457
3509
  };
3458
3510
 
3459
3511
  /**
3460
- * @param {object} obj
3512
+ * @param {Record<string, WeakMap<any, any>>} obj
3461
3513
  * @param {SweetAlert} instance
3462
3514
  */
3463
3515
  const unsetWeakMaps = (obj, instance) => {
@@ -3582,9 +3634,24 @@
3582
3634
  };
3583
3635
  };
3584
3636
 
3637
+ /**
3638
+ * @param {any} elem
3639
+ * @returns {boolean}
3640
+ */
3585
3641
  const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
3642
+
3643
+ /**
3644
+ * @param {any} elem
3645
+ * @returns {boolean}
3646
+ */
3586
3647
  const isElement = elem => elem instanceof Element || isJqueryElement(elem);
3648
+
3649
+ /**
3650
+ * @param {any[]} args
3651
+ * @returns {SweetAlertOptions}
3652
+ */
3587
3653
  const argsToParams = args => {
3654
+ /** @type {Record<string, any>} */
3588
3655
  const params = {};
3589
3656
  if (typeof args[0] === 'object' && !isElement(args[0])) {
3590
3657
  Object.assign(params, args[0]);
@@ -3604,6 +3671,7 @@
3604
3671
  /**
3605
3672
  * Main method to create a new SweetAlert2 popup
3606
3673
  *
3674
+ * @this {new (...args: any[]) => any}
3607
3675
  * @param {...SweetAlertOptions} args
3608
3676
  * @returns {Promise<SweetAlertResult>}
3609
3677
  */
@@ -3721,9 +3789,11 @@
3721
3789
  };
3722
3790
 
3723
3791
  let bodyClickListenerAdded = false;
3792
+ /** @type {Record<string, any>} */
3724
3793
  const clickHandlers = {};
3725
3794
 
3726
3795
  /**
3796
+ * @this {any}
3727
3797
  * @param {string} attr
3728
3798
  */
3729
3799
  function bindClickHandler(attr = 'data-swal-template') {
@@ -3733,10 +3803,14 @@
3733
3803
  bodyClickListenerAdded = true;
3734
3804
  }
3735
3805
  }
3806
+
3807
+ /**
3808
+ * @param {MouseEvent} event
3809
+ */
3736
3810
  const bodyClickListener = event => {
3737
- for (let el = event.target; el && el !== document; el = el.parentNode) {
3811
+ for (let el = /** @type {any} */event.target; el && el !== document; el = el.parentNode) {
3738
3812
  for (const attr in clickHandlers) {
3739
- const template = el.getAttribute(attr);
3813
+ const template = el.getAttribute && el.getAttribute(attr);
3740
3814
  if (template) {
3741
3815
  clickHandlers[attr].fire({
3742
3816
  template
@@ -3847,7 +3921,9 @@
3847
3921
  * @param {EventHandler} eventHandler
3848
3922
  */
3849
3923
  const on = (eventName, eventHandler) => {
3850
- globalState.eventEmitter.on(eventName, eventHandler);
3924
+ if (globalState.eventEmitter) {
3925
+ globalState.eventEmitter.on(eventName, eventHandler);
3926
+ }
3851
3927
  };
3852
3928
 
3853
3929
  /**
@@ -3855,7 +3931,9 @@
3855
3931
  * @param {EventHandler} eventHandler
3856
3932
  */
3857
3933
  const once = (eventName, eventHandler) => {
3858
- globalState.eventEmitter.once(eventName, eventHandler);
3934
+ if (globalState.eventEmitter) {
3935
+ globalState.eventEmitter.once(eventName, eventHandler);
3936
+ }
3859
3937
  };
3860
3938
 
3861
3939
  /**
@@ -3863,6 +3941,10 @@
3863
3941
  * @param {EventHandler} [eventHandler]
3864
3942
  */
3865
3943
  const off = (eventName, eventHandler) => {
3944
+ if (!globalState.eventEmitter) {
3945
+ return;
3946
+ }
3947
+
3866
3948
  // Remove all handlers for all events
3867
3949
  if (!eventName) {
3868
3950
  globalState.eventEmitter.reset();
@@ -4730,7 +4812,7 @@
4730
4812
  };
4731
4813
  });
4732
4814
  SweetAlert.DismissReason = DismissReason;
4733
- SweetAlert.version = '11.26.15';
4815
+ SweetAlert.version = '11.26.17';
4734
4816
 
4735
4817
  const Swal = SweetAlert;
4736
4818
  // @ts-ignore