sweetalert2 11.7.12 → 11.7.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.
- package/README.md +2 -1
- package/dist/sweetalert2.all.js +60 -32
- package/dist/sweetalert2.all.min.js +2 -2
- package/dist/sweetalert2.js +60 -32
- package/dist/sweetalert2.min.js +2 -2
- package/package.json +2 -2
- package/src/SweetAlert.js +1 -1
- package/src/utils/dom/domUtils.js +3 -3
- package/src/utils/dom/getters.js +18 -8
- package/src/utils/dom/init.js +5 -5
- package/src/utils/dom/parseHtmlToContainer.js +2 -2
- package/src/utils/dom/renderers/renderActions.js +12 -5
- package/src/utils/dom/renderers/renderContainer.js +6 -5
- package/src/utils/dom/renderers/renderIcon.js +13 -4
- package/sweetalert2.d.ts +1 -0
package/src/utils/dom/init.js
CHANGED
|
@@ -13,19 +13,19 @@ const sweetHTML = `
|
|
|
13
13
|
<img class="${swalClasses.image}" />
|
|
14
14
|
<h2 class="${swalClasses.title}" id="${swalClasses.title}"></h2>
|
|
15
15
|
<div class="${swalClasses['html-container']}" id="${swalClasses['html-container']}"></div>
|
|
16
|
-
<input class="${swalClasses.input}" />
|
|
16
|
+
<input class="${swalClasses.input}" id="${swalClasses.input}" />
|
|
17
17
|
<input type="file" class="${swalClasses.file}" />
|
|
18
18
|
<div class="${swalClasses.range}">
|
|
19
19
|
<input type="range" />
|
|
20
20
|
<output></output>
|
|
21
21
|
</div>
|
|
22
|
-
<select class="${swalClasses.select}"></select>
|
|
22
|
+
<select class="${swalClasses.select}" id="${swalClasses.select}"></select>
|
|
23
23
|
<div class="${swalClasses.radio}"></div>
|
|
24
|
-
<label
|
|
25
|
-
<input type="checkbox" />
|
|
24
|
+
<label class="${swalClasses.checkbox}">
|
|
25
|
+
<input type="checkbox" id="${swalClasses.checkbox}" />
|
|
26
26
|
<span class="${swalClasses.label}"></span>
|
|
27
27
|
</label>
|
|
28
|
-
<textarea class="${swalClasses.textarea}"></textarea>
|
|
28
|
+
<textarea class="${swalClasses.textarea}" id="${swalClasses.textarea}"></textarea>
|
|
29
29
|
<div class="${swalClasses['validation-message']}" id="${swalClasses['validation-message']}"></div>
|
|
30
30
|
<div class="${swalClasses.actions}">
|
|
31
31
|
<div class="${swalClasses.loader}"></div>
|
|
@@ -22,7 +22,7 @@ export const parseHtmlToContainer = (param, target) => {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {any} param
|
|
26
26
|
* @param {HTMLElement} target
|
|
27
27
|
*/
|
|
28
28
|
const handleObject = (param, target) => {
|
|
@@ -39,7 +39,7 @@ const handleObject = (param, target) => {
|
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* @param {HTMLElement} target
|
|
42
|
-
* @param {
|
|
42
|
+
* @param {any} elem
|
|
43
43
|
*/
|
|
44
44
|
const handleJqueryElem = (target, elem) => {
|
|
45
45
|
target.textContent = ''
|
|
@@ -9,6 +9,9 @@ import { capitalizeFirstLetter } from '../../utils.js'
|
|
|
9
9
|
export const renderActions = (instance, params) => {
|
|
10
10
|
const actions = dom.getActions()
|
|
11
11
|
const loader = dom.getLoader()
|
|
12
|
+
if (!actions || !loader) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
12
15
|
|
|
13
16
|
// Actions (buttons) wrapper
|
|
14
17
|
if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) {
|
|
@@ -24,7 +27,7 @@ export const renderActions = (instance, params) => {
|
|
|
24
27
|
renderButtons(actions, loader, params)
|
|
25
28
|
|
|
26
29
|
// Loader
|
|
27
|
-
dom.setInnerHtml(loader, params.loaderHtml)
|
|
30
|
+
dom.setInnerHtml(loader, params.loaderHtml || '')
|
|
28
31
|
dom.applyCustomClass(loader, params, 'loader')
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -37,6 +40,9 @@ function renderButtons(actions, loader, params) {
|
|
|
37
40
|
const confirmButton = dom.getConfirmButton()
|
|
38
41
|
const denyButton = dom.getDenyButton()
|
|
39
42
|
const cancelButton = dom.getCancelButton()
|
|
43
|
+
if (!confirmButton || !denyButton || !cancelButton) {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
40
46
|
|
|
41
47
|
// Render buttons
|
|
42
48
|
renderButton(confirmButton, 'confirm', params)
|
|
@@ -91,12 +97,13 @@ function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
|
|
|
91
97
|
* @param {SweetAlertOptions} params
|
|
92
98
|
*/
|
|
93
99
|
function renderButton(button, buttonType, params) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
const buttonName = /** @type {'Confirm' | 'Deny' | 'Cancel'} */ (capitalizeFirstLetter(buttonType))
|
|
101
|
+
|
|
102
|
+
dom.toggle(button, params[`show${buttonName}Button`], 'inline-block')
|
|
103
|
+
dom.setInnerHtml(button, params[`${buttonType}ButtonText`] || '') // Set caption text
|
|
104
|
+
button.setAttribute('aria-label', params[`${buttonType}ButtonAriaLabel`] || '') // ARIA label
|
|
97
105
|
|
|
98
106
|
// Add buttons custom classes
|
|
99
107
|
button.className = swalClasses[buttonType]
|
|
100
108
|
dom.applyCustomClass(button, params, `${buttonType}Button`)
|
|
101
|
-
dom.addClass(button, params[`${buttonType}ButtonClass`])
|
|
102
109
|
}
|
|
@@ -39,6 +39,9 @@ function handleBackdropParam(container, backdrop) {
|
|
|
39
39
|
* @param {SweetAlertOptions['position']} position
|
|
40
40
|
*/
|
|
41
41
|
function handlePositionParam(container, position) {
|
|
42
|
+
if (!position) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
42
45
|
if (position in swalClasses) {
|
|
43
46
|
dom.addClass(container, swalClasses[position])
|
|
44
47
|
} else {
|
|
@@ -52,10 +55,8 @@ function handlePositionParam(container, position) {
|
|
|
52
55
|
* @param {SweetAlertOptions['grow']} grow
|
|
53
56
|
*/
|
|
54
57
|
function handleGrowParam(container, grow) {
|
|
55
|
-
if (grow
|
|
56
|
-
|
|
57
|
-
if (growClass in swalClasses) {
|
|
58
|
-
dom.addClass(container, swalClasses[growClass])
|
|
59
|
-
}
|
|
58
|
+
if (!grow) {
|
|
59
|
+
return
|
|
60
60
|
}
|
|
61
|
+
dom.addClass(container, swalClasses[`grow-${grow}`])
|
|
61
62
|
}
|
|
@@ -10,6 +10,9 @@ import { error } from '../../utils.js'
|
|
|
10
10
|
export const renderIcon = (instance, params) => {
|
|
11
11
|
const innerParams = privateProps.innerParams.get(instance)
|
|
12
12
|
const icon = dom.getIcon()
|
|
13
|
+
if (!icon) {
|
|
14
|
+
return
|
|
15
|
+
}
|
|
13
16
|
|
|
14
17
|
// if the given icon already rendered, apply the styling without re-rendering the icon
|
|
15
18
|
if (innerParams && params.icon === innerParams.icon) {
|
|
@@ -39,7 +42,7 @@ export const renderIcon = (instance, params) => {
|
|
|
39
42
|
applyStyles(icon, params)
|
|
40
43
|
|
|
41
44
|
// Animate icon
|
|
42
|
-
dom.addClass(icon, params.showClass.icon)
|
|
45
|
+
dom.addClass(icon, params.showClass && params.showClass.icon)
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
/**
|
|
@@ -47,12 +50,12 @@ export const renderIcon = (instance, params) => {
|
|
|
47
50
|
* @param {SweetAlertOptions} params
|
|
48
51
|
*/
|
|
49
52
|
const applyStyles = (icon, params) => {
|
|
50
|
-
for (const iconType
|
|
53
|
+
for (const [iconType, iconClassName] of Object.entries(iconTypes)) {
|
|
51
54
|
if (params.icon !== iconType) {
|
|
52
|
-
dom.removeClass(icon,
|
|
55
|
+
dom.removeClass(icon, iconClassName)
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
|
-
dom.addClass(icon, iconTypes[params.icon])
|
|
58
|
+
dom.addClass(icon, params.icon && iconTypes[params.icon])
|
|
56
59
|
|
|
57
60
|
// Icon color
|
|
58
61
|
setColor(icon, params)
|
|
@@ -67,6 +70,9 @@ const applyStyles = (icon, params) => {
|
|
|
67
70
|
// Adjust success icon background color to match the popup background color
|
|
68
71
|
const adjustSuccessIconBackgroundColor = () => {
|
|
69
72
|
const popup = dom.getPopup()
|
|
73
|
+
if (!popup) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
70
76
|
const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color')
|
|
71
77
|
/** @type {NodeListOf<HTMLElement>} */
|
|
72
78
|
const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix')
|
|
@@ -94,6 +100,9 @@ const errorIconHtml = `
|
|
|
94
100
|
* @param {SweetAlertOptions} params
|
|
95
101
|
*/
|
|
96
102
|
const setContent = (icon, params) => {
|
|
103
|
+
if (!params.icon) {
|
|
104
|
+
return
|
|
105
|
+
}
|
|
97
106
|
let oldContent = icon.innerHTML
|
|
98
107
|
let newContent
|
|
99
108
|
if (params.iconHtml) {
|