sweetalert2 11.3.2 → 11.3.6
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.
- package/README.md +8 -10
- package/dist/sweetalert2.all.js +117 -51
- package/dist/sweetalert2.all.min.js +2 -2
- package/dist/sweetalert2.css +2 -2
- package/dist/sweetalert2.js +116 -50
- package/dist/sweetalert2.min.css +1 -1
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +9 -8
- package/src/SweetAlert.js +1 -1
- package/src/buttons-handlers.js +6 -3
- package/src/instanceMethods/_destroy.js +1 -1
- package/src/utils/dom/animationEndEvent.js +2 -3
- package/src/utils/dom/domUtils.js +9 -7
- package/src/utils/dom/getters.js +4 -4
- package/src/utils/dom/init.js +5 -5
- package/src/utils/dom/inputUtils.js +3 -3
- package/src/utils/dom/renderers/renderIcon.js +2 -2
- package/src/utils/dom/renderers/renderInput.js +2 -2
- package/src/utils/getTemplateParams.js +36 -6
- package/src/utils/iosFix.js +17 -5
- package/src/utils/isNodeEnv.js +5 -1
- package/src/utils/openPopup.js +1 -1
- package/src/utils/utils.js +9 -8
- package/src/variables.scss +1 -1
|
@@ -8,6 +8,7 @@ export const getTemplateParams = (params) => {
|
|
|
8
8
|
if (!template) {
|
|
9
9
|
return {}
|
|
10
10
|
}
|
|
11
|
+
/** @type {DocumentFragment} */
|
|
11
12
|
const templateContent = template.content
|
|
12
13
|
|
|
13
14
|
showWarningsForElements(templateContent)
|
|
@@ -23,23 +24,28 @@ export const getTemplateParams = (params) => {
|
|
|
23
24
|
return result
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @param {DocumentFragment} templateContent
|
|
29
|
+
*/
|
|
26
30
|
const getSwalParams = (templateContent) => {
|
|
27
31
|
const result = {}
|
|
28
32
|
toArray(templateContent.querySelectorAll('swal-param')).forEach((param) => {
|
|
29
33
|
showWarningsForAttributes(param, ['name', 'value'])
|
|
30
34
|
const paramName = param.getAttribute('name')
|
|
31
|
-
|
|
35
|
+
const value = param.getAttribute('value')
|
|
32
36
|
if (typeof defaultParams[paramName] === 'boolean' && value === 'false') {
|
|
33
|
-
|
|
37
|
+
result[paramName] = false
|
|
34
38
|
}
|
|
35
39
|
if (typeof defaultParams[paramName] === 'object') {
|
|
36
|
-
|
|
40
|
+
result[paramName] = JSON.parse(value)
|
|
37
41
|
}
|
|
38
|
-
result[paramName] = value
|
|
39
42
|
})
|
|
40
43
|
return result
|
|
41
44
|
}
|
|
42
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @param {DocumentFragment} templateContent
|
|
48
|
+
*/
|
|
43
49
|
const getSwalButtons = (templateContent) => {
|
|
44
50
|
const result = {}
|
|
45
51
|
toArray(templateContent.querySelectorAll('swal-button')).forEach((button) => {
|
|
@@ -57,8 +63,12 @@ const getSwalButtons = (templateContent) => {
|
|
|
57
63
|
return result
|
|
58
64
|
}
|
|
59
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @param {DocumentFragment} templateContent
|
|
68
|
+
*/
|
|
60
69
|
const getSwalImage = (templateContent) => {
|
|
61
70
|
const result = {}
|
|
71
|
+
/** @type {HTMLElement} */
|
|
62
72
|
const image = templateContent.querySelector('swal-image')
|
|
63
73
|
if (image) {
|
|
64
74
|
showWarningsForAttributes(image, ['src', 'width', 'height', 'alt'])
|
|
@@ -78,8 +88,12 @@ const getSwalImage = (templateContent) => {
|
|
|
78
88
|
return result
|
|
79
89
|
}
|
|
80
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @param {DocumentFragment} templateContent
|
|
93
|
+
*/
|
|
81
94
|
const getSwalIcon = (templateContent) => {
|
|
82
95
|
const result = {}
|
|
96
|
+
/** @type {HTMLElement} */
|
|
83
97
|
const icon = templateContent.querySelector('swal-icon')
|
|
84
98
|
if (icon) {
|
|
85
99
|
showWarningsForAttributes(icon, ['type', 'color'])
|
|
@@ -94,8 +108,12 @@ const getSwalIcon = (templateContent) => {
|
|
|
94
108
|
return result
|
|
95
109
|
}
|
|
96
110
|
|
|
111
|
+
/**
|
|
112
|
+
* @param {DocumentFragment} templateContent
|
|
113
|
+
*/
|
|
97
114
|
const getSwalInput = (templateContent) => {
|
|
98
115
|
const result = {}
|
|
116
|
+
/** @type {HTMLElement} */
|
|
99
117
|
const input = templateContent.querySelector('swal-input')
|
|
100
118
|
if (input) {
|
|
101
119
|
showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value'])
|
|
@@ -123,10 +141,15 @@ const getSwalInput = (templateContent) => {
|
|
|
123
141
|
return result
|
|
124
142
|
}
|
|
125
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @param {DocumentFragment} templateContent
|
|
146
|
+
* @param {string[]} paramNames
|
|
147
|
+
*/
|
|
126
148
|
const getSwalStringParams = (templateContent, paramNames) => {
|
|
127
149
|
const result = {}
|
|
128
150
|
for (const i in paramNames) {
|
|
129
151
|
const paramName = paramNames[i]
|
|
152
|
+
/** @type {HTMLElement} */
|
|
130
153
|
const tag = templateContent.querySelector(paramName)
|
|
131
154
|
if (tag) {
|
|
132
155
|
showWarningsForAttributes(tag, [])
|
|
@@ -136,7 +159,10 @@ const getSwalStringParams = (templateContent, paramNames) => {
|
|
|
136
159
|
return result
|
|
137
160
|
}
|
|
138
161
|
|
|
139
|
-
|
|
162
|
+
/**
|
|
163
|
+
* @param {DocumentFragment} templateContent
|
|
164
|
+
*/
|
|
165
|
+
const showWarningsForElements = (templateContent) => {
|
|
140
166
|
const allowedElements = swalStringParams.concat([
|
|
141
167
|
'swal-param',
|
|
142
168
|
'swal-button',
|
|
@@ -145,7 +171,7 @@ const showWarningsForElements = (template) => {
|
|
|
145
171
|
'swal-input',
|
|
146
172
|
'swal-input-option',
|
|
147
173
|
])
|
|
148
|
-
toArray(
|
|
174
|
+
toArray(templateContent.children).forEach((el) => {
|
|
149
175
|
const tagName = el.tagName.toLowerCase()
|
|
150
176
|
if (allowedElements.indexOf(tagName) === -1) {
|
|
151
177
|
warn(`Unrecognized element <${tagName}>`)
|
|
@@ -153,6 +179,10 @@ const showWarningsForElements = (template) => {
|
|
|
153
179
|
})
|
|
154
180
|
}
|
|
155
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @param {HTMLElement} el
|
|
184
|
+
* @param {string[]} allowedAttributes
|
|
185
|
+
*/
|
|
156
186
|
const showWarningsForAttributes = (el, allowedAttributes) => {
|
|
157
187
|
toArray(el.attributes).forEach((attribute) => {
|
|
158
188
|
if (allowedAttributes.indexOf(attribute.name) === -1) {
|
package/src/utils/iosFix.js
CHANGED
|
@@ -12,13 +12,19 @@ export const iOSfix = () => {
|
|
|
12
12
|
document.body.style.top = `${offset * -1}px`
|
|
13
13
|
dom.addClass(document.body, swalClasses.iosfix)
|
|
14
14
|
lockBodyScroll()
|
|
15
|
-
addBottomPaddingForTallPopups()
|
|
15
|
+
addBottomPaddingForTallPopups()
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* https://github.com/sweetalert2/sweetalert2/issues/1948
|
|
21
|
+
*/
|
|
19
22
|
const addBottomPaddingForTallPopups = () => {
|
|
20
|
-
const
|
|
21
|
-
|
|
23
|
+
const ua = navigator.userAgent
|
|
24
|
+
const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i)
|
|
25
|
+
const webkit = !!ua.match(/WebKit/i)
|
|
26
|
+
const iOSSafari = iOS && webkit && !ua.match(/CriOS/i)
|
|
27
|
+
if (iOSSafari) {
|
|
22
28
|
const bottomPanelHeight = 44
|
|
23
29
|
if (dom.getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
|
|
24
30
|
dom.getContainer().style.paddingBottom = `${bottomPanelHeight}px`
|
|
@@ -43,7 +49,7 @@ const lockBodyScroll = () => { // #1246
|
|
|
43
49
|
const shouldPreventTouchMove = (event) => {
|
|
44
50
|
const target = event.target
|
|
45
51
|
const container = dom.getContainer()
|
|
46
|
-
if (
|
|
52
|
+
if (isStylus(event) || isZoom(event)) {
|
|
47
53
|
return false
|
|
48
54
|
}
|
|
49
55
|
if (target === container) {
|
|
@@ -63,7 +69,13 @@ const shouldPreventTouchMove = (event) => {
|
|
|
63
69
|
return false
|
|
64
70
|
}
|
|
65
71
|
|
|
66
|
-
|
|
72
|
+
/**
|
|
73
|
+
* https://github.com/sweetalert2/sweetalert2/issues/1786
|
|
74
|
+
*
|
|
75
|
+
* @param {*} event
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
const isStylus = (event) => {
|
|
67
79
|
return event.touches && event.touches.length && event.touches[0].touchType === 'stylus'
|
|
68
80
|
}
|
|
69
81
|
|
package/src/utils/isNodeEnv.js
CHANGED
package/src/utils/openPopup.js
CHANGED
|
@@ -79,7 +79,7 @@ const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) =>
|
|
|
79
79
|
|
|
80
80
|
const addClasses = (container, popup, params) => {
|
|
81
81
|
dom.addClass(container, params.showClass.backdrop)
|
|
82
|
-
//
|
|
82
|
+
// this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
|
|
83
83
|
popup.style.setProperty('opacity', '0', 'important')
|
|
84
84
|
dom.show(popup, 'grid')
|
|
85
85
|
setTimeout(() => {
|
package/src/utils/utils.js
CHANGED
|
@@ -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
|
-
*
|
|
25
|
-
* @
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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)) {
|
package/src/variables.scss
CHANGED
|
@@ -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
|
|
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;
|