sweetalert2 11.3.0 → 11.3.1

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.
@@ -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
- }