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.
@@ -16,10 +16,14 @@ export const openPopup = (params) => {
16
16
  const container = dom.getContainer()
17
17
  const popup = dom.getPopup()
18
18
 
19
+ if (!container || !popup) {
20
+ return
21
+ }
22
+
19
23
  if (typeof params.willOpen === 'function') {
20
24
  params.willOpen(popup)
21
25
  }
22
- globalState.eventEmitter.emit('willOpen', popup)
26
+ globalState.eventEmitter?.emit('willOpen', popup)
23
27
 
24
28
  const bodyStyles = window.getComputedStyle(document.body)
25
29
  const initialBodyOverflow = bodyStyles.overflowY
@@ -31,7 +35,12 @@ export const openPopup = (params) => {
31
35
  }, SHOW_CLASS_TIMEOUT)
32
36
 
33
37
  if (dom.isModal()) {
34
- fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow)
38
+ // Using ternary instead of ?? operator for Webpack 4 compatibility
39
+ fixScrollContainer(
40
+ container,
41
+ params.scrollbarPadding !== undefined ? params.scrollbarPadding : false,
42
+ initialBodyOverflow
43
+ )
35
44
  setAriaHidden()
36
45
  }
37
46
 
@@ -40,20 +49,24 @@ export const openPopup = (params) => {
40
49
  }
41
50
 
42
51
  if (typeof params.didOpen === 'function') {
43
- setTimeout(() => params.didOpen(popup))
52
+ const didOpen = params.didOpen
53
+ setTimeout(() => didOpen(popup))
44
54
  }
45
- globalState.eventEmitter.emit('didOpen', popup)
55
+ globalState.eventEmitter?.emit('didOpen', popup)
46
56
  }
47
57
 
48
58
  /**
49
- * @param {AnimationEvent} event
59
+ * @param {Event} event
50
60
  */
51
61
  const swalOpenAnimationFinished = (event) => {
52
62
  const popup = dom.getPopup()
53
- if (event.target !== popup) {
63
+ if (!popup || event.target !== popup) {
54
64
  return
55
65
  }
56
66
  const container = dom.getContainer()
67
+ if (!container) {
68
+ return
69
+ }
57
70
  popup.removeEventListener('animationend', swalOpenAnimationFinished)
58
71
  popup.removeEventListener('transitionend', swalOpenAnimationFinished)
59
72
  container.style.overflowY = 'auto'
@@ -100,14 +113,18 @@ const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) =>
100
113
  * @param {SweetAlertOptions} params
101
114
  */
102
115
  const addClasses = (container, popup, params) => {
103
- dom.addClass(container, params.showClass.backdrop)
116
+ if (params.showClass?.backdrop) {
117
+ dom.addClass(container, params.showClass.backdrop)
118
+ }
104
119
  if (params.animation) {
105
120
  // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
106
121
  popup.style.setProperty('opacity', '0', 'important')
107
122
  dom.show(popup, 'grid')
108
123
  setTimeout(() => {
109
124
  // Animate popup right after showing it
110
- dom.addClass(popup, params.showClass.popup)
125
+ if (params.showClass?.popup) {
126
+ dom.addClass(popup, params.showClass.popup)
127
+ }
111
128
  // and remove the opacity workaround
112
129
  popup.style.removeProperty('opacity')
113
130
  }, SHOW_CLASS_TIMEOUT) // 10ms in order to fix #2062