sweetalert2 11.26.14 → 11.26.16

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.14
2
+ * sweetalert2 v11.26.16
3
3
  * Released under the MIT License.
4
4
  */
5
5
  (function (global, factory) {
@@ -550,7 +550,7 @@
550
550
  value = parseInt(value);
551
551
  }
552
552
  if (value || parseInt(`${value}`) === 0) {
553
- elem.style.setProperty(property, typeof value === 'number' ? `${value}px` : value);
553
+ elem.style.setProperty(property, typeof value === 'number' ? `${value}px` : (/** @type {string} */value));
554
554
  } else {
555
555
  elem.style.removeProperty(property);
556
556
  }
@@ -645,7 +645,7 @@
645
645
  * @returns {boolean}
646
646
  */
647
647
  const selfOrParentIsScrollable = (element, stopElement) => {
648
- let parent = element;
648
+ let parent = /** @type {HTMLElement | null} */element;
649
649
  while (parent && parent !== stopElement) {
650
650
  if (isScrollable(parent)) {
651
651
  return true;
@@ -752,50 +752,81 @@
752
752
  return false;
753
753
  }
754
754
  oldContainer.remove();
755
- removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
755
+ removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'],
756
+ // @ts-ignore: 'has-column' is not defined in swalClasses but may be set dynamically
757
+ swalClasses['has-column']]);
756
758
  return true;
757
759
  };
758
760
  const resetValidationMessage$1 = () => {
759
- globalState.currentInstance.resetValidationMessage();
761
+ if (globalState.currentInstance) {
762
+ globalState.currentInstance.resetValidationMessage();
763
+ }
760
764
  };
761
765
  const addInputChangeListeners = () => {
762
766
  const popup = getPopup();
767
+ if (!popup) {
768
+ return;
769
+ }
763
770
  const input = getDirectChildByClass(popup, swalClasses.input);
764
771
  const file = getDirectChildByClass(popup, swalClasses.file);
765
- /** @type {HTMLInputElement} */
772
+ /** @type {HTMLInputElement | null} */
766
773
  const range = popup.querySelector(`.${swalClasses.range} input`);
767
- /** @type {HTMLOutputElement} */
774
+ /** @type {HTMLOutputElement | null} */
768
775
  const rangeOutput = popup.querySelector(`.${swalClasses.range} output`);
769
776
  const select = getDirectChildByClass(popup, swalClasses.select);
770
- /** @type {HTMLInputElement} */
777
+ /** @type {HTMLInputElement | null} */
771
778
  const checkbox = popup.querySelector(`.${swalClasses.checkbox} input`);
772
779
  const textarea = getDirectChildByClass(popup, swalClasses.textarea);
773
- input.oninput = resetValidationMessage$1;
774
- file.onchange = resetValidationMessage$1;
775
- select.onchange = resetValidationMessage$1;
776
- checkbox.onchange = resetValidationMessage$1;
777
- textarea.oninput = resetValidationMessage$1;
778
- range.oninput = () => {
779
- resetValidationMessage$1();
780
- rangeOutput.value = range.value;
781
- };
782
- range.onchange = () => {
783
- resetValidationMessage$1();
784
- rangeOutput.value = range.value;
785
- };
780
+ if (input) {
781
+ input.oninput = resetValidationMessage$1;
782
+ }
783
+ if (file) {
784
+ file.onchange = resetValidationMessage$1;
785
+ }
786
+ if (select) {
787
+ select.onchange = resetValidationMessage$1;
788
+ }
789
+ if (checkbox) {
790
+ checkbox.onchange = resetValidationMessage$1;
791
+ }
792
+ if (textarea) {
793
+ textarea.oninput = resetValidationMessage$1;
794
+ }
795
+ if (range && rangeOutput) {
796
+ range.oninput = () => {
797
+ resetValidationMessage$1();
798
+ rangeOutput.value = range.value;
799
+ };
800
+ range.onchange = () => {
801
+ resetValidationMessage$1();
802
+ rangeOutput.value = range.value;
803
+ };
804
+ }
786
805
  };
787
806
 
788
807
  /**
789
808
  * @param {string | HTMLElement} target
790
809
  * @returns {HTMLElement}
791
810
  */
792
- const getTarget = target => typeof target === 'string' ? document.querySelector(target) : target;
811
+ const getTarget = target => {
812
+ if (typeof target === 'string') {
813
+ const element = document.querySelector(target);
814
+ if (!element) {
815
+ throw new Error(`Target element "${target}" not found`);
816
+ }
817
+ return /** @type {HTMLElement} */element;
818
+ }
819
+ return target;
820
+ };
793
821
 
794
822
  /**
795
823
  * @param {SweetAlertOptions} params
796
824
  */
797
825
  const setupAccessibility = params => {
798
826
  const popup = getPopup();
827
+ if (!popup) {
828
+ return;
829
+ }
799
830
  popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
800
831
  popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
801
832
  if (!params.toast) {
@@ -832,7 +863,7 @@
832
863
  }
833
864
  setInnerHtml(container, sweetHTML);
834
865
  container.dataset['swal2Theme'] = params.theme;
835
- const targetElement = getTarget(params.target);
866
+ const targetElement = getTarget(params.target || 'body');
836
867
  targetElement.appendChild(container);
837
868
  if (params.topLayer) {
838
869
  container.setAttribute('popover', '');
@@ -1968,8 +1999,9 @@
1968
1999
  * @param {GlobalState} globalState
1969
2000
  */
1970
2001
  const removeKeydownHandler = globalState => {
1971
- if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
1972
- 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, {
1973
2005
  capture: globalState.keydownListenerCapture
1974
2006
  });
1975
2007
  globalState.keydownHandlerAdded = false;
@@ -1984,13 +2016,19 @@
1984
2016
  const addKeydownHandler = (globalState, innerParams, dismissWith) => {
1985
2017
  removeKeydownHandler(globalState);
1986
2018
  if (!innerParams.toast) {
1987
- globalState.keydownHandler = e => keydownHandler(innerParams, e, dismissWith);
1988
- globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
1989
- globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
1990
- globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
1991
- capture: globalState.keydownListenerCapture
1992
- });
1993
- 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
+ }
1994
2032
  }
1995
2033
  };
1996
2034
 
@@ -2078,7 +2116,11 @@
2078
2116
  if (!callIfFunction(innerParams.allowEnterKey)) {
2079
2117
  return;
2080
2118
  }
2081
- 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);
2082
2124
  if (event.target && input && event.target instanceof HTMLElement && event.target.outerHTML === input.outerHTML) {
2083
2125
  if (['textarea', 'file'].includes(innerParams.input)) {
2084
2126
  return; // do not submit
@@ -3315,6 +3357,7 @@
3315
3357
  /**
3316
3358
  * Updates popup parameters.
3317
3359
  *
3360
+ * @this {any}
3318
3361
  * @param {SweetAlertOptions} params
3319
3362
  */
3320
3363
  function update(params) {
@@ -3328,7 +3371,9 @@
3328
3371
  const validUpdatableParams = filterValidParams(params);
3329
3372
  const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
3330
3373
  showWarningsForParams(updatedParams);
3331
- container.dataset['swal2Theme'] = updatedParams.theme;
3374
+ if (container) {
3375
+ container.dataset['swal2Theme'] = updatedParams.theme;
3376
+ }
3332
3377
  render(this, updatedParams);
3333
3378
  privateProps.innerParams.set(this, updatedParams);
3334
3379
  Object.defineProperties(this, {
@@ -3345,10 +3390,12 @@
3345
3390
  * @returns {SweetAlertOptions}
3346
3391
  */
3347
3392
  const filterValidParams = params => {
3393
+ /** @type {Record<string, any>} */
3348
3394
  const validUpdatableParams = {};
3349
3395
  Object.keys(params).forEach(param => {
3350
3396
  if (isUpdatableParameter(param)) {
3351
- validUpdatableParams[param] = params[param];
3397
+ const typedParams = /** @type {Record<string, any>} */params;
3398
+ validUpdatableParams[param] = typedParams[param];
3352
3399
  } else {
3353
3400
  warn(`Invalid parameter to update: ${param}`);
3354
3401
  }
@@ -3551,9 +3598,24 @@
3551
3598
  };
3552
3599
  };
3553
3600
 
3601
+ /**
3602
+ * @param {any} elem
3603
+ * @returns {boolean}
3604
+ */
3554
3605
  const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
3606
+
3607
+ /**
3608
+ * @param {any} elem
3609
+ * @returns {boolean}
3610
+ */
3555
3611
  const isElement = elem => elem instanceof Element || isJqueryElement(elem);
3612
+
3613
+ /**
3614
+ * @param {any[]} args
3615
+ * @returns {SweetAlertOptions}
3616
+ */
3556
3617
  const argsToParams = args => {
3618
+ /** @type {Record<string, any>} */
3557
3619
  const params = {};
3558
3620
  if (typeof args[0] === 'object' && !isElement(args[0])) {
3559
3621
  Object.assign(params, args[0]);
@@ -3573,6 +3635,7 @@
3573
3635
  /**
3574
3636
  * Main method to create a new SweetAlert2 popup
3575
3637
  *
3638
+ * @this {new (...args: any[]) => any}
3576
3639
  * @param {...SweetAlertOptions} args
3577
3640
  * @returns {Promise<SweetAlertResult>}
3578
3641
  */
@@ -3598,9 +3661,15 @@
3598
3661
  *
3599
3662
  * @param {SweetAlertOptions} mixinParams
3600
3663
  * @returns {SweetAlert}
3664
+ * @this {typeof import('../SweetAlert.js').SweetAlert}
3601
3665
  */
3602
3666
  function mixin(mixinParams) {
3667
+ // @ts-ignore: 'this' refers to the SweetAlert constructor
3603
3668
  class MixinSwal extends this {
3669
+ /**
3670
+ * @param {any} params
3671
+ * @param {any} priorityMixinParams
3672
+ */
3604
3673
  _main(params, priorityMixinParams) {
3605
3674
  return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
3606
3675
  }
@@ -3684,9 +3753,11 @@
3684
3753
  };
3685
3754
 
3686
3755
  let bodyClickListenerAdded = false;
3756
+ /** @type {Record<string, any>} */
3687
3757
  const clickHandlers = {};
3688
3758
 
3689
3759
  /**
3760
+ * @this {any}
3690
3761
  * @param {string} attr
3691
3762
  */
3692
3763
  function bindClickHandler(attr = 'data-swal-template') {
@@ -3696,10 +3767,14 @@
3696
3767
  bodyClickListenerAdded = true;
3697
3768
  }
3698
3769
  }
3770
+
3771
+ /**
3772
+ * @param {MouseEvent} event
3773
+ */
3699
3774
  const bodyClickListener = event => {
3700
- for (let el = event.target; el && el !== document; el = el.parentNode) {
3775
+ for (let el = /** @type {any} */event.target; el && el !== document; el = el.parentNode) {
3701
3776
  for (const attr in clickHandlers) {
3702
- const template = el.getAttribute(attr);
3777
+ const template = el.getAttribute && el.getAttribute(attr);
3703
3778
  if (template) {
3704
3779
  clickHandlers[attr].fire({
3705
3780
  template
@@ -3810,7 +3885,9 @@
3810
3885
  * @param {EventHandler} eventHandler
3811
3886
  */
3812
3887
  const on = (eventName, eventHandler) => {
3813
- globalState.eventEmitter.on(eventName, eventHandler);
3888
+ if (globalState.eventEmitter) {
3889
+ globalState.eventEmitter.on(eventName, eventHandler);
3890
+ }
3814
3891
  };
3815
3892
 
3816
3893
  /**
@@ -3818,7 +3895,9 @@
3818
3895
  * @param {EventHandler} eventHandler
3819
3896
  */
3820
3897
  const once = (eventName, eventHandler) => {
3821
- globalState.eventEmitter.once(eventName, eventHandler);
3898
+ if (globalState.eventEmitter) {
3899
+ globalState.eventEmitter.once(eventName, eventHandler);
3900
+ }
3822
3901
  };
3823
3902
 
3824
3903
  /**
@@ -3826,6 +3905,10 @@
3826
3905
  * @param {EventHandler} [eventHandler]
3827
3906
  */
3828
3907
  const off = (eventName, eventHandler) => {
3908
+ if (!globalState.eventEmitter) {
3909
+ return;
3910
+ }
3911
+
3829
3912
  // Remove all handlers for all events
3830
3913
  if (!eventName) {
3831
3914
  globalState.eventEmitter.reset();
@@ -4390,7 +4473,11 @@
4390
4473
  /**
4391
4474
  * @type {Promise<SweetAlertResult>}
4392
4475
  */
4393
- _classPrivateFieldInitSpec(this, _promise, void 0);
4476
+ _classPrivateFieldInitSpec(this, _promise, /** @type {Promise<SweetAlertResult>} */Promise.resolve({
4477
+ isConfirmed: false,
4478
+ isDenied: false,
4479
+ isDismissed: true
4480
+ }));
4394
4481
  // Prevent run in Node env
4395
4482
  if (typeof window === 'undefined') {
4396
4483
  return;
@@ -4407,6 +4494,11 @@
4407
4494
  this.isAwaitingPromise = false;
4408
4495
  _classPrivateFieldSet2(_promise, this, this._main(currentInstance.params));
4409
4496
  }
4497
+
4498
+ /**
4499
+ * @param {any} userParams
4500
+ * @param {any} mixinParams
4501
+ */
4410
4502
  _main(userParams, mixinParams = {}) {
4411
4503
  showWarningsForParams(Object.assign({}, mixinParams, userParams));
4412
4504
  if (globalState.currentInstance) {
@@ -4444,9 +4536,16 @@
4444
4536
  }
4445
4537
 
4446
4538
  // `catch` cannot be the name of a module export, so we define our thenable methods here instead
4539
+ /**
4540
+ * @param {any} onFulfilled
4541
+ */
4447
4542
  then(onFulfilled) {
4448
4543
  return _classPrivateFieldGet2(_promise, this).then(onFulfilled);
4449
4544
  }
4545
+
4546
+ /**
4547
+ * @param {any} onFinally
4548
+ */
4450
4549
  finally(onFinally) {
4451
4550
  return _classPrivateFieldGet2(_promise, this).finally(onFinally);
4452
4551
  }
@@ -4456,7 +4555,7 @@
4456
4555
  * @param {SweetAlert} instance
4457
4556
  * @param {DomCache} domCache
4458
4557
  * @param {SweetAlertOptions} innerParams
4459
- * @returns {Promise}
4558
+ * @returns {Promise<SweetAlertResult>}
4460
4559
  */
4461
4560
  const swalPromise = (instance, domCache, innerParams) => {
4462
4561
  return new Promise((resolve, reject) => {
@@ -4524,17 +4623,17 @@
4524
4623
  * @returns {DomCache}
4525
4624
  */
4526
4625
  const populateDomCache = instance => {
4527
- const domCache = {
4528
- popup: getPopup(),
4529
- container: getContainer(),
4530
- actions: getActions(),
4531
- confirmButton: getConfirmButton(),
4532
- denyButton: getDenyButton(),
4533
- cancelButton: getCancelButton(),
4534
- loader: getLoader(),
4535
- closeButton: getCloseButton(),
4536
- validationMessage: getValidationMessage(),
4537
- progressSteps: getProgressSteps()
4626
+ const domCache = /** @type {DomCache} */{
4627
+ popup: (/** @type {HTMLElement} */getPopup()),
4628
+ container: (/** @type {HTMLElement} */getContainer()),
4629
+ actions: (/** @type {HTMLElement} */getActions()),
4630
+ confirmButton: (/** @type {HTMLElement} */getConfirmButton()),
4631
+ denyButton: (/** @type {HTMLElement} */getDenyButton()),
4632
+ cancelButton: (/** @type {HTMLElement} */getCancelButton()),
4633
+ loader: (/** @type {HTMLElement} */getLoader()),
4634
+ closeButton: (/** @type {HTMLElement} */getCloseButton()),
4635
+ validationMessage: (/** @type {HTMLElement} */getValidationMessage()),
4636
+ progressSteps: (/** @type {HTMLElement} */getProgressSteps())
4538
4637
  };
4539
4638
  privateProps.domCache.set(instance, domCache);
4540
4639
  return domCache;
@@ -4553,13 +4652,13 @@
4553
4652
  dismissWith('timer');
4554
4653
  delete globalState.timeout;
4555
4654
  }, innerParams.timer);
4556
- if (innerParams.timerProgressBar) {
4655
+ if (innerParams.timerProgressBar && timerProgressBar) {
4557
4656
  show(timerProgressBar);
4558
4657
  applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar');
4559
4658
  setTimeout(() => {
4560
4659
  if (globalState.timeout && globalState.timeout.running) {
4561
4660
  // timer can be already stopped or unset at this point
4562
- animateTimerProgressBar(innerParams.timer);
4661
+ animateTimerProgressBar(/** @type {number} */innerParams.timer);
4563
4662
  }
4564
4663
  });
4565
4664
  }
@@ -4666,15 +4765,18 @@
4666
4765
  * @param {...(SweetAlertOptions | string | undefined)} args
4667
4766
  * @returns {SweetAlertResult | Promise<SweetAlertResult> | undefined}
4668
4767
  */
4768
+ // @ts-ignore: Dynamic property assignment for backwards compatibility
4669
4769
  SweetAlert[key] = function (...args) {
4770
+ // @ts-ignore
4670
4771
  if (currentInstance && currentInstance[key]) {
4772
+ // @ts-ignore
4671
4773
  return currentInstance[key](...args);
4672
4774
  }
4673
- return null;
4775
+ return undefined;
4674
4776
  };
4675
4777
  });
4676
4778
  SweetAlert.DismissReason = DismissReason;
4677
- SweetAlert.version = '11.26.14';
4779
+ SweetAlert.version = '11.26.16';
4678
4780
 
4679
4781
  const Swal = SweetAlert;
4680
4782
  // @ts-ignore