sweetalert2 11.3.0 → 11.3.4

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 (35) hide show
  1. package/README.md +13 -11
  2. package/dist/sweetalert2.all.js +1334 -1234
  3. package/dist/sweetalert2.all.min.js +2 -2
  4. package/dist/sweetalert2.css +2 -2
  5. package/dist/sweetalert2.js +1333 -1233
  6. package/dist/sweetalert2.min.css +1 -1
  7. package/dist/sweetalert2.min.js +1 -1
  8. package/package.json +15 -13
  9. package/src/SweetAlert.js +169 -1
  10. package/src/{instanceMethods/buttons-handlers.js → buttons-handlers.js} +9 -9
  11. package/src/instanceMethods/_destroy.js +1 -1
  12. package/src/instanceMethods/getInput.js +4 -1
  13. package/src/instanceMethods/update.js +2 -2
  14. package/src/instanceMethods.js +0 -1
  15. package/src/{instanceMethods/keydown-handler.js → keydown-handler.js} +6 -6
  16. package/src/{instanceMethods/popup-click-handler.js → popup-click-handler.js} +15 -11
  17. package/src/staticMethods/showLoading.js +1 -1
  18. package/src/sweetalert2.js +1 -0
  19. package/src/utils/Timer.js +1 -1
  20. package/src/utils/dom/animationEndEvent.js +2 -3
  21. package/src/utils/dom/domUtils.js +66 -13
  22. package/src/utils/dom/getters.js +9 -4
  23. package/src/utils/dom/init.js +7 -9
  24. package/src/utils/dom/inputUtils.js +3 -3
  25. package/src/utils/dom/renderers/renderIcon.js +2 -2
  26. package/src/utils/dom/renderers/renderInput.js +4 -3
  27. package/src/utils/getTemplateParams.js +7 -4
  28. package/src/utils/iosFix.js +18 -5
  29. package/src/utils/openPopup.js +1 -1
  30. package/src/utils/params.js +3 -3
  31. package/src/utils/setParameters.js +0 -1
  32. package/src/utils/utils.js +9 -8
  33. package/src/variables.scss +1 -1
  34. package/sweetalert2.d.ts +2 -2
  35. package/src/instanceMethods/_main.js +0 -168
@@ -16,27 +16,28 @@ export const uniqueArray = (arr) => {
16
16
 
17
17
  /**
18
18
  * Capitalize the first letter of a string
19
- * @param str
19
+ * @param {string} str
20
+ * @returns {string}
20
21
  */
21
22
  export const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1)
22
23
 
23
24
  /**
24
- * Convert NodeList to Array
25
- * @param nodeList
25
+ * @param {NodeList | HTMLCollection | NamedNodeMap} nodeList
26
+ * @returns {array}
26
27
  */
27
28
  export const toArray = (nodeList) => Array.prototype.slice.call(nodeList)
28
29
 
29
30
  /**
30
- * Standardise console warnings
31
- * @param message
31
+ * Standardize console warnings
32
+ * @param {string | array} message
32
33
  */
33
34
  export const warn = (message) => {
34
35
  console.warn(`${consolePrefix} ${typeof message === 'object' ? message.join(' ') : message}`)
35
36
  }
36
37
 
37
38
  /**
38
- * Standardise console errors
39
- * @param message
39
+ * Standardize console errors
40
+ * @param {string} message
40
41
  */
41
42
  export const error = (message) => {
42
43
  console.error(`${consolePrefix} ${message}`)
@@ -51,7 +52,7 @@ const previousWarnOnceMessages = []
51
52
 
52
53
  /**
53
54
  * Show a console warning, but only if it hasn't already been shown
54
- * @param message
55
+ * @param {string} message
55
56
  */
56
57
  export const warnOnce = (message) => {
57
58
  if (!previousWarnOnceMessages.includes(message)) {
@@ -70,7 +70,7 @@ $swal2-html-container-word-wrap: break-word !default;
70
70
  $swal2-html-container-word-break: break-word !default;
71
71
 
72
72
  // INPUT
73
- $swal2-input-margin: 1em 2em 0 !default;
73
+ $swal2-input-margin: 1em 2em 3px !default;
74
74
  $swal2-input-width: auto !default;
75
75
  $swal2-input-height: 2.625em !default;
76
76
  $swal2-input-padding: 0 .75em !default;
package/sweetalert2.d.ts CHANGED
@@ -580,14 +580,14 @@ declare module 'sweetalert2' {
580
580
  padding?: number | string;
581
581
 
582
582
  /**
583
- * Popup color for title, content and footer (CSS `color` property).
583
+ * Color for title, content and footer (CSS `color` property). The default color is `#545454`.
584
584
  *
585
585
  * @default undefined
586
586
  */
587
587
  color?: string;
588
588
 
589
589
  /**
590
- * Popup background (CSS `background` property).
590
+ * Popup background (CSS `background` property). The default background is `#fff`.
591
591
  *
592
592
  * @default undefined
593
593
  */
@@ -1,168 +0,0 @@
1
- import defaultParams, { showWarningsForParams } from '../utils/params.js'
2
- import * as dom from '../utils/dom/index.js'
3
- import Timer from '../utils/Timer.js'
4
- import { callIfFunction } from '../utils/utils.js'
5
- import setParameters from '../utils/setParameters.js'
6
- import { getTemplateParams } from '../utils/getTemplateParams.js'
7
- import globalState from '../globalState.js'
8
- import { openPopup } from '../utils/openPopup.js'
9
- import privateProps from '../privateProps.js'
10
- import privateMethods from '../privateMethods.js'
11
- import { handleInputOptionsAndValue } from '../utils/dom/inputUtils.js'
12
- import { handleConfirmButtonClick, handleDenyButtonClick, handleCancelButtonClick } from './buttons-handlers.js'
13
- import { addKeydownHandler, setFocus } from './keydown-handler.js'
14
- import { handlePopupClick } from './popup-click-handler.js'
15
- import { DismissReason } from '../utils/DismissReason.js'
16
- import { unsetAriaHidden } from '../utils/aria.js'
17
-
18
- export function _main (userParams, mixinParams = {}) {
19
- showWarningsForParams(Object.assign({}, mixinParams, userParams))
20
-
21
- if (globalState.currentInstance) {
22
- globalState.currentInstance._destroy()
23
- if (dom.isModal()) {
24
- unsetAriaHidden()
25
- }
26
- }
27
- globalState.currentInstance = this
28
-
29
- const innerParams = prepareParams(userParams, mixinParams)
30
- setParameters(innerParams)
31
- Object.freeze(innerParams)
32
-
33
- // clear the previous timer
34
- if (globalState.timeout) {
35
- globalState.timeout.stop()
36
- delete globalState.timeout
37
- }
38
-
39
- // clear the restore focus timeout
40
- clearTimeout(globalState.restoreFocusTimeout)
41
-
42
- const domCache = populateDomCache(this)
43
-
44
- dom.render(this, innerParams)
45
-
46
- privateProps.innerParams.set(this, innerParams)
47
-
48
- return swalPromise(this, domCache, innerParams)
49
- }
50
-
51
- const prepareParams = (userParams, mixinParams) => {
52
- const templateParams = getTemplateParams(userParams)
53
- const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams) // precedence is described in #2131
54
- params.showClass = Object.assign({}, defaultParams.showClass, params.showClass)
55
- params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass)
56
- return params
57
- }
58
-
59
- const swalPromise = (instance, domCache, innerParams) => {
60
- return new Promise((resolve, reject) => {
61
- // functions to handle all closings/dismissals
62
- const dismissWith = (dismiss) => {
63
- instance.closePopup({ isDismissed: true, dismiss })
64
- }
65
-
66
- privateMethods.swalPromiseResolve.set(instance, resolve)
67
- privateMethods.swalPromiseReject.set(instance, reject)
68
-
69
- domCache.confirmButton.onclick = () => handleConfirmButtonClick(instance)
70
- domCache.denyButton.onclick = () => handleDenyButtonClick(instance)
71
- domCache.cancelButton.onclick = () => handleCancelButtonClick(instance, dismissWith)
72
-
73
- domCache.closeButton.onclick = () => dismissWith(DismissReason.close)
74
-
75
- handlePopupClick(instance, domCache, dismissWith)
76
-
77
- addKeydownHandler(instance, globalState, innerParams, dismissWith)
78
-
79
- handleInputOptionsAndValue(instance, innerParams)
80
-
81
- openPopup(innerParams)
82
-
83
- setupTimer(globalState, innerParams, dismissWith)
84
-
85
- initFocus(domCache, innerParams)
86
-
87
- // Scroll container to top on open (#1247, #1946)
88
- setTimeout(() => {
89
- domCache.container.scrollTop = 0
90
- })
91
- })
92
- }
93
-
94
- const populateDomCache = (instance) => {
95
- const domCache = {
96
- popup: dom.getPopup(),
97
- container: dom.getContainer(),
98
- actions: dom.getActions(),
99
- confirmButton: dom.getConfirmButton(),
100
- denyButton: dom.getDenyButton(),
101
- cancelButton: dom.getCancelButton(),
102
- loader: dom.getLoader(),
103
- closeButton: dom.getCloseButton(),
104
- validationMessage: dom.getValidationMessage(),
105
- progressSteps: dom.getProgressSteps()
106
- }
107
- privateProps.domCache.set(instance, domCache)
108
-
109
- return domCache
110
- }
111
-
112
- const setupTimer = (globalState, innerParams, dismissWith) => {
113
- const timerProgressBar = dom.getTimerProgressBar()
114
- dom.hide(timerProgressBar)
115
- if (innerParams.timer) {
116
- globalState.timeout = new Timer(() => {
117
- dismissWith('timer')
118
- delete globalState.timeout
119
- }, innerParams.timer)
120
- if (innerParams.timerProgressBar) {
121
- dom.show(timerProgressBar)
122
- setTimeout(() => {
123
- if (globalState.timeout && globalState.timeout.running) { // timer can be already stopped or unset at this point
124
- dom.animateTimerProgressBar(innerParams.timer)
125
- }
126
- })
127
- }
128
- }
129
- }
130
-
131
- const initFocus = (domCache, innerParams) => {
132
- if (innerParams.toast) {
133
- return
134
- }
135
-
136
- if (!callIfFunction(innerParams.allowEnterKey)) {
137
- return blurActiveElement()
138
- }
139
-
140
- if (!focusButton(domCache, innerParams)) {
141
- setFocus(innerParams, -1, 1)
142
- }
143
- }
144
-
145
- const focusButton = (domCache, innerParams) => {
146
- if (innerParams.focusDeny && dom.isVisible(domCache.denyButton)) {
147
- domCache.denyButton.focus()
148
- return true
149
- }
150
-
151
- if (innerParams.focusCancel && dom.isVisible(domCache.cancelButton)) {
152
- domCache.cancelButton.focus()
153
- return true
154
- }
155
-
156
- if (innerParams.focusConfirm && dom.isVisible(domCache.confirmButton)) {
157
- domCache.confirmButton.focus()
158
- return true
159
- }
160
-
161
- return false
162
- }
163
-
164
- const blurActiveElement = () => {
165
- if (document.activeElement && typeof document.activeElement.blur === 'function') {
166
- document.activeElement.blur()
167
- }
168
- }