sweetalert2 11.3.6 → 11.3.7

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +2257 -0
  2. package/dist/sweetalert2.all.js +77 -44
  3. package/dist/sweetalert2.all.min.js +1 -1
  4. package/dist/sweetalert2.js +77 -44
  5. package/dist/sweetalert2.min.js +1 -1
  6. package/package.json +5 -2
  7. package/src/SweetAlert.js +12 -11
  8. package/src/buttons-handlers.js +27 -27
  9. package/src/globalState.js +1 -1
  10. package/src/instanceMethods/_destroy.js +1 -1
  11. package/src/instanceMethods/close.js +25 -23
  12. package/src/instanceMethods/enable-disable-elements.js +7 -7
  13. package/src/instanceMethods/getInput.js +1 -1
  14. package/src/instanceMethods/hideLoading.js +2 -5
  15. package/src/instanceMethods/progress-steps.js +1 -1
  16. package/src/instanceMethods/update.js +20 -13
  17. package/src/instanceMethods/validation-message.js +2 -2
  18. package/src/keydown-handler.js +22 -16
  19. package/src/popup-click-handler.js +3 -1
  20. package/src/privateMethods.js +1 -1
  21. package/src/privateProps.js +1 -1
  22. package/src/staticMethods/argsToParams.js +1 -1
  23. package/src/staticMethods/bindClickHandler.js +1 -1
  24. package/src/staticMethods/dom.js +1 -1
  25. package/src/staticMethods/fire.js +2 -2
  26. package/src/staticMethods/mixin.js +2 -2
  27. package/src/staticMethods/showLoading.js +1 -4
  28. package/src/staticMethods.js +1 -5
  29. package/src/utils/DismissReason.js +1 -1
  30. package/src/utils/Timer.js +6 -6
  31. package/src/utils/aria.js +2 -2
  32. package/src/utils/classes.js +1 -7
  33. package/src/utils/defaultInputValidators.js +1 -1
  34. package/src/utils/dom/animationEndEvent.js +1 -1
  35. package/src/utils/dom/domUtils.js +16 -9
  36. package/src/utils/dom/getters.js +7 -7
  37. package/src/utils/dom/init.js +3 -7
  38. package/src/utils/dom/inputUtils.js +26 -19
  39. package/src/utils/dom/parseHtmlToContainer.js +14 -3
  40. package/src/utils/dom/renderers/renderActions.js +3 -3
  41. package/src/utils/dom/renderers/renderContainer.js +3 -3
  42. package/src/utils/dom/renderers/renderContent.js +4 -2
  43. package/src/utils/dom/renderers/renderIcon.js +24 -15
  44. package/src/utils/dom/renderers/renderInput.js +30 -21
  45. package/src/utils/dom/renderers/renderPopup.js +2 -1
  46. package/src/utils/dom/renderers/renderProgressSteps.js +1 -1
  47. package/src/utils/getTemplateParams.js +7 -3
  48. package/src/utils/iosFix.js +16 -5
  49. package/src/utils/params.js +2 -2
  50. package/src/utils/setParameters.js +5 -5
  51. package/src/utils/utils.js +5 -3
@@ -10,7 +10,7 @@ export const animationEndEvent = (() => {
10
10
  const testEl = document.createElement('div')
11
11
  const transEndEventNames = {
12
12
  WebkitAnimation: 'webkitAnimationEnd', // Chrome, Safari and Opera
13
- animation: 'animationend' // Standard syntax
13
+ animation: 'animationend', // Standard syntax
14
14
  }
15
15
  for (const i in transEndEventNames) {
16
16
  if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') {
@@ -1,10 +1,10 @@
1
- import { getTimerProgressBar, getConfirmButton, getDenyButton, getCancelButton } from './getters.js'
2
- import { swalClasses, iconTypes } from '../classes.js'
1
+ import { getCancelButton, getConfirmButton, getDenyButton, getTimerProgressBar } from './getters.js'
2
+ import { iconTypes, swalClasses } from '../classes.js'
3
3
  import { toArray, warn } from '../utils.js'
4
4
 
5
5
  // Remember state in cases where opening and handling a modal will fiddle with it.
6
6
  export const states = {
7
- previousBodyPadding: null
7
+ previousBodyPadding: null,
8
8
  }
9
9
 
10
10
  /**
@@ -47,7 +47,7 @@ export const hasClass = (elem, className) => {
47
47
  }
48
48
 
49
49
  const removeCustomClasses = (elem, params) => {
50
- toArray(elem.classList).forEach(className => {
50
+ toArray(elem.classList).forEach((className) => {
51
51
  if (
52
52
  !Object.values(swalClasses).includes(className) &&
53
53
  !Object.values(iconTypes).includes(className) &&
@@ -63,7 +63,11 @@ export const applyCustomClass = (elem, params, className) => {
63
63
 
64
64
  if (params.customClass && params.customClass[className]) {
65
65
  if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) {
66
- return warn(`Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof params.customClass[className]}"`)
66
+ return warn(
67
+ `Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof params.customClass[
68
+ className
69
+ ]}"`
70
+ )
67
71
  }
68
72
 
69
73
  addClass(elem, params.customClass[className])
@@ -87,8 +91,10 @@ export const getInput = (popup, inputType) => {
87
91
  case 'checkbox':
88
92
  return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.checkbox} input`)
89
93
  case 'radio':
90
- return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) ||
94
+ return (
95
+ popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) ||
91
96
  popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:first-child`)
97
+ )
92
98
  case 'range':
93
99
  return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.range} input`)
94
100
  default:
@@ -176,7 +182,7 @@ export const applyNumericalStyle = (elem, property, value) => {
176
182
  value = parseInt(value)
177
183
  }
178
184
  if (value || parseInt(value) === 0) {
179
- elem.style[property] = (typeof value === 'number') ? `${value}px` : value
185
+ elem.style[property] = typeof value === 'number' ? `${value}px` : value
180
186
  } else {
181
187
  elem.style.removeProperty(property)
182
188
  }
@@ -211,7 +217,8 @@ export const toggle = (elem, condition, display) => {
211
217
  // borrowed from jquery $(elem).is(':visible') implementation
212
218
  export const isVisible = (elem) => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length))
213
219
 
214
- export const allButtonsAreHidden = () => !isVisible(getConfirmButton()) && !isVisible(getDenyButton()) && !isVisible(getCancelButton())
220
+ export const allButtonsAreHidden = () =>
221
+ !isVisible(getConfirmButton()) && !isVisible(getDenyButton()) && !isVisible(getCancelButton())
215
222
 
216
223
  export const isScrollable = (elem) => !!(elem.scrollHeight > elem.clientHeight)
217
224
 
@@ -245,7 +252,7 @@ export const stopTimerProgressBar = () => {
245
252
  timerProgressBar.style.removeProperty('transition')
246
253
  timerProgressBar.style.width = '100%'
247
254
  const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width)
248
- const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100
255
+ const timerProgressBarPercent = (timerProgressBarWidth / timerProgressBarFullWidth) * 100
249
256
  timerProgressBar.style.removeProperty('transition')
250
257
  timerProgressBar.style.width = `${timerProgressBarPercent}%`
251
258
  }
@@ -1,6 +1,6 @@
1
1
  import { swalClasses } from '../classes.js'
2
- import { uniqueArray, toArray } from '../utils.js'
3
- import { isVisible, hasClass } from './domUtils.js'
2
+ import { toArray, uniqueArray } from '../utils.js'
3
+ import { hasClass, isVisible } from './domUtils.js'
4
4
 
5
5
  /**
6
6
  * Gets the popup container which contains the backdrop and the popup itself.
@@ -72,7 +72,7 @@ export const getFocusableElements = () => {
72
72
  const focusableElementsWithTabindex = toArray(
73
73
  getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')
74
74
  )
75
- // sort according to tabindex
75
+ // sort according to tabindex
76
76
  .sort((a, b) => {
77
77
  const tabindexA = parseInt(a.getAttribute('tabindex'))
78
78
  const tabindexB = parseInt(b.getAttribute('tabindex'))
@@ -84,11 +84,11 @@ export const getFocusableElements = () => {
84
84
  return 0
85
85
  })
86
86
 
87
- const otherFocusableElements = toArray(
88
- getPopup().querySelectorAll(focusable)
89
- ).filter(el => el.getAttribute('tabindex') !== '-1')
87
+ const otherFocusableElements = toArray(getPopup().querySelectorAll(focusable)).filter(
88
+ (el) => el.getAttribute('tabindex') !== '-1'
89
+ )
90
90
 
91
- return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el))
91
+ return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter((el) => isVisible(el))
92
92
  }
93
93
 
94
94
  export const isModal = () => {
@@ -1,6 +1,6 @@
1
1
  import { swalClasses } from '../classes.js'
2
2
  import { getContainer, getPopup } from './getters.js'
3
- import { addClass, removeClass, getDirectChildByClass, setInnerHtml } from './domUtils.js'
3
+ import { addClass, getDirectChildByClass, removeClass, setInnerHtml } from './domUtils.js'
4
4
  import { isNodeEnv } from '../isNodeEnv.js'
5
5
  import { error } from '../utils.js'
6
6
  import globalState from '../../globalState.js'
@@ -49,11 +49,7 @@ const resetOldContainer = () => {
49
49
  oldContainer.remove()
50
50
  removeClass(
51
51
  [document.documentElement, document.body],
52
- [
53
- swalClasses['no-backdrop'],
54
- swalClasses['toast-shown'],
55
- swalClasses['has-column']
56
- ]
52
+ [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]
57
53
  )
58
54
 
59
55
  return true
@@ -91,7 +87,7 @@ const addInputChangeListeners = () => {
91
87
  }
92
88
  }
93
89
 
94
- const getTarget = (target) => typeof target === 'string' ? document.querySelector(target) : target
90
+ const getTarget = (target) => (typeof target === 'string' ? document.querySelector(target) : target)
95
91
 
96
92
  const setupAccessibility = (params) => {
97
93
  const popup = getPopup()
@@ -33,15 +33,17 @@ export const getInputValue = (instance, innerParams) => {
33
33
  }
34
34
  }
35
35
 
36
- const getCheckboxValue = (input) => input.checked ? 1 : 0
36
+ const getCheckboxValue = (input) => (input.checked ? 1 : 0)
37
37
 
38
- const getRadioValue = (input) => input.checked ? input.value : null
38
+ const getRadioValue = (input) => (input.checked ? input.value : null)
39
39
 
40
- const getFileValue = (input) => input.files.length ? (input.getAttribute('multiple') !== null ? input.files : input.files[0]) : null
40
+ const getFileValue = (input) =>
41
+ input.files.length ? (input.getAttribute('multiple') !== null ? input.files : input.files[0]) : null
41
42
 
42
43
  const handleInputOptions = (instance, params) => {
43
44
  const popup = dom.getPopup()
44
- const processInputOptions = (inputOptions) => populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params)
45
+ const processInputOptions = (inputOptions) =>
46
+ populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params)
45
47
  if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
46
48
  showLoading(dom.getConfirmButton())
47
49
  asPromise(params.inputOptions).then((inputOptions) => {
@@ -58,12 +60,13 @@ const handleInputOptions = (instance, params) => {
58
60
  const handleInputValue = (instance, params) => {
59
61
  const input = instance.getInput()
60
62
  dom.hide(input)
61
- asPromise(params.inputValue).then((inputValue) => {
62
- input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : `${inputValue}`
63
- dom.show(input)
64
- input.focus()
65
- instance.hideLoading()
66
- })
63
+ asPromise(params.inputValue)
64
+ .then((inputValue) => {
65
+ input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : `${inputValue}`
66
+ dom.show(input)
67
+ input.focus()
68
+ instance.hideLoading()
69
+ })
67
70
  .catch((err) => {
68
71
  error(`Error in inputValue promise: ${err}`)
69
72
  input.value = ''
@@ -83,20 +86,22 @@ const populateInputOptions = {
83
86
  option.selected = isSelected(optionValue, params.inputValue)
84
87
  parent.appendChild(option)
85
88
  }
86
- inputOptions.forEach(inputOption => {
89
+ inputOptions.forEach((inputOption) => {
87
90
  const optionValue = inputOption[0]
88
91
  const optionLabel = inputOption[1]
89
92
  // <optgroup> spec:
90
93
  // https://www.w3.org/TR/html401/interact/forms.html#h-17.6
91
94
  // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
92
95
  // check whether this is a <optgroup>
93
- if (Array.isArray(optionLabel)) { // if it is an array, then it is an <optgroup>
96
+ if (Array.isArray(optionLabel)) {
97
+ // if it is an array, then it is an <optgroup>
94
98
  const optgroup = document.createElement('optgroup')
95
99
  optgroup.label = optionValue
96
100
  optgroup.disabled = false // not configurable for now
97
101
  select.appendChild(optgroup)
98
- optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]))
99
- } else { // case of <option>
102
+ optionLabel.forEach((o) => renderOption(optgroup, o[1], o[0]))
103
+ } else {
104
+ // case of <option>
100
105
  renderOption(select, optionLabel, optionValue)
101
106
  }
102
107
  })
@@ -105,7 +110,7 @@ const populateInputOptions = {
105
110
 
106
111
  radio: (popup, inputOptions, params) => {
107
112
  const radio = getDirectChildByClass(popup, swalClasses.radio)
108
- inputOptions.forEach(inputOption => {
113
+ inputOptions.forEach((inputOption) => {
109
114
  const radioValue = inputOption[0]
110
115
  const radioLabel = inputOption[1]
111
116
  const radioInput = document.createElement('input')
@@ -127,7 +132,7 @@ const populateInputOptions = {
127
132
  if (radios.length) {
128
133
  radios[0].focus()
129
134
  }
130
- }
135
+ },
131
136
  }
132
137
 
133
138
  /**
@@ -139,15 +144,17 @@ const formatInputOptions = (inputOptions) => {
139
144
  if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
140
145
  inputOptions.forEach((value, key) => {
141
146
  let valueFormatted = value
142
- if (typeof valueFormatted === 'object') { // case of <optgroup>
147
+ if (typeof valueFormatted === 'object') {
148
+ // case of <optgroup>
143
149
  valueFormatted = formatInputOptions(valueFormatted)
144
150
  }
145
151
  result.push([key, valueFormatted])
146
152
  })
147
153
  } else {
148
- Object.keys(inputOptions).forEach(key => {
154
+ Object.keys(inputOptions).forEach((key) => {
149
155
  let valueFormatted = inputOptions[key]
150
- if (typeof valueFormatted === 'object') { // case of <optgroup>
156
+ if (typeof valueFormatted === 'object') {
157
+ // case of <optgroup>
151
158
  valueFormatted = formatInputOptions(valueFormatted)
152
159
  }
153
160
  result.push([key, valueFormatted])
@@ -1,27 +1,38 @@
1
1
  import { setInnerHtml } from './domUtils.js'
2
2
 
3
+ /**
4
+ * @param {HTMLElement | object | string} param
5
+ * @param {HTMLElement} target
6
+ */
3
7
  export const parseHtmlToContainer = (param, target) => {
4
8
  // DOM element
5
9
  if (param instanceof HTMLElement) {
6
10
  target.appendChild(param)
11
+ }
7
12
 
8
13
  // Object
9
- } else if (typeof param === 'object') {
14
+ else if (typeof param === 'object') {
10
15
  handleObject(param, target)
16
+ }
11
17
 
12
18
  // Plain string
13
- } else if (param) {
19
+ else if (param) {
14
20
  setInnerHtml(target, param)
15
21
  }
16
22
  }
17
23
 
24
+ /**
25
+ * @param {object} param
26
+ * @param {HTMLElement} target
27
+ */
18
28
  const handleObject = (param, target) => {
19
29
  // JQuery element(s)
20
30
  if (param.jquery) {
21
31
  handleJqueryElem(target, param)
32
+ }
22
33
 
23
34
  // For other objects use their string representation
24
- } else {
35
+ else {
25
36
  setInnerHtml(target, param.toString())
26
37
  }
27
38
  }
@@ -24,7 +24,7 @@ export const renderActions = (instance, params) => {
24
24
  dom.applyCustomClass(loader, params, 'loader')
25
25
  }
26
26
 
27
- function renderButtons (actions, loader, params) {
27
+ function renderButtons(actions, loader, params) {
28
28
  const confirmButton = dom.getConfirmButton()
29
29
  const denyButton = dom.getDenyButton()
30
30
  const cancelButton = dom.getCancelButton()
@@ -47,7 +47,7 @@ function renderButtons (actions, loader, params) {
47
47
  }
48
48
  }
49
49
 
50
- function handleButtonsStyling (confirmButton, denyButton, cancelButton, params) {
50
+ function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
51
51
  if (!params.buttonsStyling) {
52
52
  return dom.removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled)
53
53
  }
@@ -69,7 +69,7 @@ function handleButtonsStyling (confirmButton, denyButton, cancelButton, params)
69
69
  }
70
70
  }
71
71
 
72
- function renderButton (button, buttonType, params) {
72
+ function renderButton(button, buttonType, params) {
73
73
  dom.toggle(button, params[`show${capitalizeFirstLetter(buttonType)}Button`], 'inline-block')
74
74
  dom.setInnerHtml(button, params[`${buttonType}ButtonText`]) // Set caption text
75
75
  button.setAttribute('aria-label', params[`${buttonType}ButtonAriaLabel`]) // ARIA label
@@ -2,7 +2,7 @@ import { swalClasses } from '../../classes.js'
2
2
  import { warn } from '../../utils.js'
3
3
  import * as dom from '../../dom/index.js'
4
4
 
5
- function handleBackdropParam (container, backdrop) {
5
+ function handleBackdropParam(container, backdrop) {
6
6
  if (typeof backdrop === 'string') {
7
7
  container.style.background = backdrop
8
8
  } else if (!backdrop) {
@@ -10,7 +10,7 @@ function handleBackdropParam (container, backdrop) {
10
10
  }
11
11
  }
12
12
 
13
- function handlePositionParam (container, position) {
13
+ function handlePositionParam(container, position) {
14
14
  if (position in swalClasses) {
15
15
  dom.addClass(container, swalClasses[position])
16
16
  } else {
@@ -19,7 +19,7 @@ function handlePositionParam (container, position) {
19
19
  }
20
20
  }
21
21
 
22
- function handleGrowParam (container, grow) {
22
+ function handleGrowParam(container, grow) {
23
23
  if (grow && typeof grow === 'string') {
24
24
  const growClass = `grow-${grow}`
25
25
  if (growClass in swalClasses) {
@@ -10,14 +10,16 @@ export const renderContent = (instance, params) => {
10
10
  if (params.html) {
11
11
  dom.parseHtmlToContainer(params.html, htmlContainer)
12
12
  dom.show(htmlContainer, 'block')
13
+ }
13
14
 
14
15
  // Content as plain text
15
- } else if (params.text) {
16
+ else if (params.text) {
16
17
  htmlContainer.textContent = params.text
17
18
  dom.show(htmlContainer, 'block')
19
+ }
18
20
 
19
21
  // No content
20
- } else {
22
+ else {
21
23
  dom.hide(htmlContainer)
22
24
  }
23
25
 
@@ -1,4 +1,4 @@
1
- import { swalClasses, iconTypes } from '../../classes.js'
1
+ import { iconTypes, swalClasses } from '../../classes.js'
2
2
  import { error } from '../../utils.js'
3
3
  import * as dom from '../../dom/index.js'
4
4
  import privateProps from '../../../privateProps.js'
@@ -64,30 +64,34 @@ const adjustSuccessIconBackgroundColor = () => {
64
64
  }
65
65
  }
66
66
 
67
+ const successIconHtml = `
68
+ <div class="swal2-success-circular-line-left"></div>
69
+ <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>
70
+ <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>
71
+ <div class="swal2-success-circular-line-right"></div>
72
+ `
73
+
74
+ const errorIconHtml = `
75
+ <span class="swal2-x-mark">
76
+ <span class="swal2-x-mark-line-left"></span>
77
+ <span class="swal2-x-mark-line-right"></span>
78
+ </span>
79
+ `
80
+
67
81
  const setContent = (icon, params) => {
68
82
  icon.textContent = ''
69
83
 
70
84
  if (params.iconHtml) {
71
85
  dom.setInnerHtml(icon, iconContent(params.iconHtml))
72
86
  } else if (params.icon === 'success') {
73
- dom.setInnerHtml(icon, `
74
- <div class="swal2-success-circular-line-left"></div>
75
- <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>
76
- <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>
77
- <div class="swal2-success-circular-line-right"></div>
78
- `)
87
+ dom.setInnerHtml(icon, successIconHtml)
79
88
  } else if (params.icon === 'error') {
80
- dom.setInnerHtml(icon, `
81
- <span class="swal2-x-mark">
82
- <span class="swal2-x-mark-line-left"></span>
83
- <span class="swal2-x-mark-line-right"></span>
84
- </span>
85
- `)
89
+ dom.setInnerHtml(icon, errorIconHtml)
86
90
  } else {
87
91
  const defaultIconHtml = {
88
92
  question: '?',
89
93
  warning: '!',
90
- info: 'i'
94
+ info: 'i',
91
95
  }
92
96
  dom.setInnerHtml(icon, iconContent(defaultIconHtml[params.icon]))
93
97
  }
@@ -99,7 +103,12 @@ const setColor = (icon, params) => {
99
103
  }
100
104
  icon.style.color = params.iconColor
101
105
  icon.style.borderColor = params.iconColor
102
- for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) {
106
+ for (const sel of [
107
+ '.swal2-success-line-tip',
108
+ '.swal2-success-line-long',
109
+ '.swal2-x-mark-line-left',
110
+ '.swal2-x-mark-line-right',
111
+ ]) {
103
112
  dom.setStyle(icon, sel, 'backgroundColor', params.iconColor)
104
113
  }
105
114
  dom.setStyle(icon, '.swal2-success-ring', 'borderColor', params.iconColor)
@@ -1,5 +1,5 @@
1
1
  import { swalClasses } from '../../classes.js'
2
- import { warn, error, isPromise } from '../../utils.js'
2
+ import { error, isPromise, warn } from '../../utils.js'
3
3
  import * as dom from '../../dom/index.js'
4
4
  import privateProps from '../../../privateProps.js'
5
5
 
@@ -36,7 +36,9 @@ export const renderInput = (instance, params) => {
36
36
 
37
37
  const showInput = (params) => {
38
38
  if (!renderInputType[params.input]) {
39
- return error(`Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "${params.input}"`)
39
+ return error(
40
+ `Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "${params.input}"`
41
+ )
40
42
  }
41
43
 
42
44
  const inputContainer = getInputContainer(params.input)
@@ -105,21 +107,24 @@ const getInputContainer = (inputType) => {
105
107
  const renderInputType = {}
106
108
 
107
109
  renderInputType.text =
108
- renderInputType.email =
109
- renderInputType.password =
110
- renderInputType.number =
111
- renderInputType.tel =
112
- renderInputType.url = (input, params) => {
113
- if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
114
- input.value = params.inputValue
115
- } else if (!isPromise(params.inputValue)) {
116
- warn(`Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof params.inputValue}"`)
117
- }
118
- setInputLabel(input, input, params)
119
- setInputPlaceholder(input, params)
120
- input.type = params.input
121
- return input
122
- }
110
+ renderInputType.email =
111
+ renderInputType.password =
112
+ renderInputType.number =
113
+ renderInputType.tel =
114
+ renderInputType.url =
115
+ (input, params) => {
116
+ if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
117
+ input.value = params.inputValue
118
+ } else if (!isPromise(params.inputValue)) {
119
+ warn(
120
+ `Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof params.inputValue}"`
121
+ )
122
+ }
123
+ setInputLabel(input, input, params)
124
+ setInputPlaceholder(input, params)
125
+ input.type = params.input
126
+ return input
127
+ }
123
128
 
124
129
  renderInputType.file = (input, params) => {
125
130
  setInputLabel(input, input, params)
@@ -172,10 +177,13 @@ renderInputType.textarea = (textarea, params) => {
172
177
  setInputPlaceholder(textarea, params)
173
178
  setInputLabel(textarea, textarea, params)
174
179
 
175
- const getMargin = (el) => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight)
180
+ const getMargin = (el) =>
181
+ parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight)
176
182
 
177
- setTimeout(() => { // #2291
178
- if ('MutationObserver' in window) { // #1699
183
+ // https://github.com/sweetalert2/sweetalert2/issues/2291
184
+ setTimeout(() => {
185
+ // https://github.com/sweetalert2/sweetalert2/issues/1699
186
+ if ('MutationObserver' in window) {
179
187
  const initialPopupWidth = parseInt(window.getComputedStyle(dom.getPopup()).width)
180
188
  const textareaResizeHandler = () => {
181
189
  const textareaWidth = textarea.offsetWidth + getMargin(textarea)
@@ -186,7 +194,8 @@ renderInputType.textarea = (textarea, params) => {
186
194
  }
187
195
  }
188
196
  new MutationObserver(textareaResizeHandler).observe(textarea, {
189
- attributes: true, attributeFilter: ['style']
197
+ attributes: true,
198
+ attributeFilter: ['style'],
190
199
  })
191
200
  }
192
201
  })
@@ -6,7 +6,8 @@ export const renderPopup = (instance, params) => {
6
6
  const popup = dom.getPopup()
7
7
 
8
8
  // Width
9
- if (params.toast) { // #2170
9
+ // https://github.com/sweetalert2/sweetalert2/issues/2170
10
+ if (params.toast) {
10
11
  dom.applyNumericalStyle(container, 'width', params.width)
11
12
  popup.style.width = '100%'
12
13
  popup.insertBefore(dom.getLoader(), dom.getIcon())
@@ -29,7 +29,7 @@ export const renderProgressSteps = (instance, params) => {
29
29
  if (params.currentProgressStep >= params.progressSteps.length) {
30
30
  warn(
31
31
  'Invalid currentProgressStep parameter, it should be less than progressSteps.length ' +
32
- '(currentProgressStep like JS arrays starts from 0)'
32
+ '(currentProgressStep like JS arrays starts from 0)'
33
33
  )
34
34
  }
35
35
 
@@ -1,5 +1,5 @@
1
1
  import defaultParams from './params.js'
2
- import { toArray, capitalizeFirstLetter, warn } from './utils.js'
2
+ import { capitalizeFirstLetter, toArray, warn } from './utils.js'
3
3
 
4
4
  const swalStringParams = ['swal-title', 'swal-html', 'swal-footer']
5
5
 
@@ -19,7 +19,7 @@ export const getTemplateParams = (params) => {
19
19
  getSwalImage(templateContent),
20
20
  getSwalIcon(templateContent),
21
21
  getSwalInput(templateContent),
22
- getSwalStringParams(templateContent, swalStringParams),
22
+ getSwalStringParams(templateContent, swalStringParams)
23
23
  )
24
24
  return result
25
25
  }
@@ -188,7 +188,11 @@ const showWarningsForAttributes = (el, allowedAttributes) => {
188
188
  if (allowedAttributes.indexOf(attribute.name) === -1) {
189
189
  warn([
190
190
  `Unrecognized attribute "${attribute.name}" on <${el.tagName.toLowerCase()}>.`,
191
- `${allowedAttributes.length ? `Allowed attributes are: ${allowedAttributes.join(', ')}` : 'To set the value, use HTML within the element.'}`
191
+ `${
192
+ allowedAttributes.length
193
+ ? `Allowed attributes are: ${allowedAttributes.join(', ')}`
194
+ : 'To set the value, use HTML within the element.'
195
+ }`,
192
196
  ])
193
197
  }
194
198
  })
@@ -5,8 +5,10 @@ import { swalClasses } from '../utils/classes.js'
5
5
  // Fix iOS scrolling http://stackoverflow.com/q/39626302
6
6
 
7
7
  export const iOSfix = () => {
8
- // @ts-ignore
9
- const iOS = (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
8
+ const iOS =
9
+ // @ts-ignore
10
+ (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) ||
11
+ (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)
10
12
  if (iOS && !dom.hasClass(document.body, swalClasses.iosfix)) {
11
13
  const offset = document.body.scrollTop
12
14
  document.body.style.top = `${offset * -1}px`
@@ -32,7 +34,10 @@ const addBottomPaddingForTallPopups = () => {
32
34
  }
33
35
  }
34
36
 
35
- const lockBodyScroll = () => { // #1246
37
+ /**
38
+ * https://github.com/sweetalert2/sweetalert2/issues/1246
39
+ */
40
+ const lockBodyScroll = () => {
36
41
  const container = dom.getContainer()
37
42
  let preventTouchMove
38
43
  container.ontouchstart = (e) => {
@@ -79,7 +84,13 @@ const isStylus = (event) => {
79
84
  return event.touches && event.touches.length && event.touches[0].touchType === 'stylus'
80
85
  }
81
86
 
82
- const isZoom = (event) => { // #1891
87
+ /**
88
+ * https://github.com/sweetalert2/sweetalert2/issues/1891
89
+ *
90
+ * @param {TouchEvent} event
91
+ * @returns {boolean}
92
+ */
93
+ const isZoom = (event) => {
83
94
  return event.touches && event.touches.length > 1
84
95
  }
85
96
 
@@ -88,6 +99,6 @@ export const undoIOSfix = () => {
88
99
  const offset = parseInt(document.body.style.top, 10)
89
100
  dom.removeClass(document.body, swalClasses.iosfix)
90
101
  document.body.style.top = ''
91
- document.body.scrollTop = (offset * -1)
102
+ document.body.scrollTop = offset * -1
92
103
  }
93
104
  }
@@ -87,7 +87,7 @@ export const defaultParams = {
87
87
  willClose: undefined,
88
88
  didClose: undefined,
89
89
  didDestroy: undefined,
90
- scrollbarPadding: true
90
+ scrollbarPadding: true,
91
91
  }
92
92
 
93
93
  export const updatableParams = [
@@ -147,7 +147,7 @@ const toastIncompatibleParams = [
147
147
  'focusCancel',
148
148
  'returnFocus',
149
149
  'heightAuto',
150
- 'keydownListenerCapture'
150
+ 'keydownListenerCapture',
151
151
  ]
152
152
 
153
153
  /**