sweetalert2 11.3.4 → 11.3.8
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/CHANGELOG.md +2264 -0
- package/README.md +6 -6
- package/dist/sweetalert2.all.js +127 -47
- package/dist/sweetalert2.all.min.js +1 -1
- package/dist/sweetalert2.js +127 -47
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +10 -6
- package/src/SweetAlert.js +12 -11
- package/src/buttons-handlers.js +30 -27
- package/src/globalState.js +1 -1
- package/src/instanceMethods/_destroy.js +1 -1
- package/src/instanceMethods/close.js +25 -23
- package/src/instanceMethods/enable-disable-elements.js +7 -7
- package/src/instanceMethods/getInput.js +1 -1
- package/src/instanceMethods/hideLoading.js +2 -5
- package/src/instanceMethods/progress-steps.js +1 -1
- package/src/instanceMethods/update.js +20 -13
- package/src/instanceMethods/validation-message.js +2 -2
- package/src/keydown-handler.js +22 -16
- package/src/popup-click-handler.js +3 -1
- package/src/privateMethods.js +1 -1
- package/src/privateProps.js +1 -1
- package/src/staticMethods/argsToParams.js +1 -1
- package/src/staticMethods/bindClickHandler.js +1 -1
- package/src/staticMethods/dom.js +1 -1
- package/src/staticMethods/fire.js +2 -2
- package/src/staticMethods/mixin.js +2 -2
- package/src/staticMethods/showLoading.js +1 -4
- package/src/staticMethods.js +1 -5
- package/src/utils/DismissReason.js +1 -1
- package/src/utils/Timer.js +6 -6
- package/src/utils/aria.js +2 -2
- package/src/utils/classes.js +1 -7
- package/src/utils/defaultInputValidators.js +1 -1
- package/src/utils/dom/animationEndEvent.js +1 -1
- package/src/utils/dom/domUtils.js +16 -9
- package/src/utils/dom/getters.js +7 -7
- package/src/utils/dom/init.js +3 -7
- package/src/utils/dom/inputUtils.js +26 -19
- package/src/utils/dom/parseHtmlToContainer.js +14 -3
- package/src/utils/dom/renderers/renderActions.js +3 -3
- package/src/utils/dom/renderers/renderContainer.js +3 -3
- package/src/utils/dom/renderers/renderContent.js +4 -2
- package/src/utils/dom/renderers/renderIcon.js +24 -15
- package/src/utils/dom/renderers/renderInput.js +30 -21
- package/src/utils/dom/renderers/renderPopup.js +2 -1
- package/src/utils/dom/renderers/renderProgressSteps.js +1 -1
- package/src/utils/getTemplateParams.js +36 -5
- package/src/utils/iosFix.js +16 -5
- package/src/utils/isNodeEnv.js +5 -1
- package/src/utils/params.js +2 -2
- package/src/utils/setParameters.js +5 -5
- package/src/utils/utils.js +5 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { swalClasses } from '../../classes.js'
|
|
2
|
-
import {
|
|
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(
|
|
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 =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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) =>
|
|
180
|
+
const getMargin = (el) =>
|
|
181
|
+
parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight)
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
2
|
+
import { capitalizeFirstLetter, toArray, warn } from './utils.js'
|
|
3
3
|
|
|
4
4
|
const swalStringParams = ['swal-title', 'swal-html', 'swal-footer']
|
|
5
5
|
|
|
@@ -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)
|
|
@@ -18,11 +19,14 @@ export const getTemplateParams = (params) => {
|
|
|
18
19
|
getSwalImage(templateContent),
|
|
19
20
|
getSwalIcon(templateContent),
|
|
20
21
|
getSwalInput(templateContent),
|
|
21
|
-
getSwalStringParams(templateContent, swalStringParams)
|
|
22
|
+
getSwalStringParams(templateContent, swalStringParams)
|
|
22
23
|
)
|
|
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) => {
|
|
@@ -39,6 +43,9 @@ const getSwalParams = (templateContent) => {
|
|
|
39
43
|
return result
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @param {DocumentFragment} templateContent
|
|
48
|
+
*/
|
|
42
49
|
const getSwalButtons = (templateContent) => {
|
|
43
50
|
const result = {}
|
|
44
51
|
toArray(templateContent.querySelectorAll('swal-button')).forEach((button) => {
|
|
@@ -56,8 +63,12 @@ const getSwalButtons = (templateContent) => {
|
|
|
56
63
|
return result
|
|
57
64
|
}
|
|
58
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @param {DocumentFragment} templateContent
|
|
68
|
+
*/
|
|
59
69
|
const getSwalImage = (templateContent) => {
|
|
60
70
|
const result = {}
|
|
71
|
+
/** @type {HTMLElement} */
|
|
61
72
|
const image = templateContent.querySelector('swal-image')
|
|
62
73
|
if (image) {
|
|
63
74
|
showWarningsForAttributes(image, ['src', 'width', 'height', 'alt'])
|
|
@@ -77,8 +88,12 @@ const getSwalImage = (templateContent) => {
|
|
|
77
88
|
return result
|
|
78
89
|
}
|
|
79
90
|
|
|
91
|
+
/**
|
|
92
|
+
* @param {DocumentFragment} templateContent
|
|
93
|
+
*/
|
|
80
94
|
const getSwalIcon = (templateContent) => {
|
|
81
95
|
const result = {}
|
|
96
|
+
/** @type {HTMLElement} */
|
|
82
97
|
const icon = templateContent.querySelector('swal-icon')
|
|
83
98
|
if (icon) {
|
|
84
99
|
showWarningsForAttributes(icon, ['type', 'color'])
|
|
@@ -93,8 +108,12 @@ const getSwalIcon = (templateContent) => {
|
|
|
93
108
|
return result
|
|
94
109
|
}
|
|
95
110
|
|
|
111
|
+
/**
|
|
112
|
+
* @param {DocumentFragment} templateContent
|
|
113
|
+
*/
|
|
96
114
|
const getSwalInput = (templateContent) => {
|
|
97
115
|
const result = {}
|
|
116
|
+
/** @type {HTMLElement} */
|
|
98
117
|
const input = templateContent.querySelector('swal-input')
|
|
99
118
|
if (input) {
|
|
100
119
|
showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value'])
|
|
@@ -122,10 +141,15 @@ const getSwalInput = (templateContent) => {
|
|
|
122
141
|
return result
|
|
123
142
|
}
|
|
124
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @param {DocumentFragment} templateContent
|
|
146
|
+
* @param {string[]} paramNames
|
|
147
|
+
*/
|
|
125
148
|
const getSwalStringParams = (templateContent, paramNames) => {
|
|
126
149
|
const result = {}
|
|
127
150
|
for (const i in paramNames) {
|
|
128
151
|
const paramName = paramNames[i]
|
|
152
|
+
/** @type {HTMLElement} */
|
|
129
153
|
const tag = templateContent.querySelector(paramName)
|
|
130
154
|
if (tag) {
|
|
131
155
|
showWarningsForAttributes(tag, [])
|
|
@@ -135,7 +159,10 @@ const getSwalStringParams = (templateContent, paramNames) => {
|
|
|
135
159
|
return result
|
|
136
160
|
}
|
|
137
161
|
|
|
138
|
-
|
|
162
|
+
/**
|
|
163
|
+
* @param {DocumentFragment} templateContent
|
|
164
|
+
*/
|
|
165
|
+
const showWarningsForElements = (templateContent) => {
|
|
139
166
|
const allowedElements = swalStringParams.concat([
|
|
140
167
|
'swal-param',
|
|
141
168
|
'swal-button',
|
|
@@ -144,7 +171,7 @@ const showWarningsForElements = (template) => {
|
|
|
144
171
|
'swal-input',
|
|
145
172
|
'swal-input-option',
|
|
146
173
|
])
|
|
147
|
-
toArray(
|
|
174
|
+
toArray(templateContent.children).forEach((el) => {
|
|
148
175
|
const tagName = el.tagName.toLowerCase()
|
|
149
176
|
if (allowedElements.indexOf(tagName) === -1) {
|
|
150
177
|
warn(`Unrecognized element <${tagName}>`)
|
|
@@ -161,7 +188,11 @@ const showWarningsForAttributes = (el, allowedAttributes) => {
|
|
|
161
188
|
if (allowedAttributes.indexOf(attribute.name) === -1) {
|
|
162
189
|
warn([
|
|
163
190
|
`Unrecognized attribute "${attribute.name}" on <${el.tagName.toLowerCase()}>.`,
|
|
164
|
-
`${
|
|
191
|
+
`${
|
|
192
|
+
allowedAttributes.length
|
|
193
|
+
? `Allowed attributes are: ${allowedAttributes.join(', ')}`
|
|
194
|
+
: 'To set the value, use HTML within the element.'
|
|
195
|
+
}`,
|
|
165
196
|
])
|
|
166
197
|
}
|
|
167
198
|
})
|
package/src/utils/iosFix.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
102
|
+
document.body.scrollTop = offset * -1
|
|
92
103
|
}
|
|
93
104
|
}
|
package/src/utils/isNodeEnv.js
CHANGED
package/src/utils/params.js
CHANGED
|
@@ -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
|
/**
|
|
@@ -2,7 +2,7 @@ import { warn } from './utils.js'
|
|
|
2
2
|
import * as dom from './dom/index.js'
|
|
3
3
|
import defaultInputValidators from './defaultInputValidators.js'
|
|
4
4
|
|
|
5
|
-
function setDefaultInputValidators
|
|
5
|
+
function setDefaultInputValidators(params) {
|
|
6
6
|
// Use default `inputValidator` for supported input types if not provided
|
|
7
7
|
if (!params.inputValidator) {
|
|
8
8
|
Object.keys(defaultInputValidators).forEach((key) => {
|
|
@@ -13,7 +13,7 @@ function setDefaultInputValidators (params) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function validateCustomTargetElement
|
|
16
|
+
function validateCustomTargetElement(params) {
|
|
17
17
|
// Determine if the custom target element is valid
|
|
18
18
|
if (
|
|
19
19
|
!params.target ||
|
|
@@ -30,15 +30,15 @@ function validateCustomTargetElement (params) {
|
|
|
30
30
|
*
|
|
31
31
|
* @param params
|
|
32
32
|
*/
|
|
33
|
-
export default function setParameters
|
|
33
|
+
export default function setParameters(params) {
|
|
34
34
|
setDefaultInputValidators(params)
|
|
35
35
|
|
|
36
36
|
// showLoaderOnConfirm && preConfirm
|
|
37
37
|
if (params.showLoaderOnConfirm && !params.preConfirm) {
|
|
38
38
|
warn(
|
|
39
39
|
'showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' +
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' +
|
|
41
|
+
'https://sweetalert2.github.io/#ajax-request'
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
|
package/src/utils/utils.js
CHANGED
|
@@ -65,7 +65,9 @@ export const warnOnce = (message) => {
|
|
|
65
65
|
* Show a one-time console warning about deprecated params/methods
|
|
66
66
|
*/
|
|
67
67
|
export const warnAboutDeprecation = (deprecatedParam, useInstead) => {
|
|
68
|
-
warnOnce(
|
|
68
|
+
warnOnce(
|
|
69
|
+
`"${deprecatedParam}" is deprecated and will be removed in the next major release. Please use "${useInstead}" instead.`
|
|
70
|
+
)
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
@@ -73,10 +75,10 @@ export const warnAboutDeprecation = (deprecatedParam, useInstead) => {
|
|
|
73
75
|
* Otherwise, just pass the value through
|
|
74
76
|
* @param arg
|
|
75
77
|
*/
|
|
76
|
-
export const callIfFunction = (arg) => typeof arg === 'function' ? arg() : arg
|
|
78
|
+
export const callIfFunction = (arg) => (typeof arg === 'function' ? arg() : arg)
|
|
77
79
|
|
|
78
80
|
export const hasToPromiseFn = (arg) => arg && typeof arg.toPromise === 'function'
|
|
79
81
|
|
|
80
|
-
export const asPromise = (arg) => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg)
|
|
82
|
+
export const asPromise = (arg) => (hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg))
|
|
81
83
|
|
|
82
84
|
export const isPromise = (arg) => arg && Promise.resolve(arg) === arg
|