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.
Files changed (53) hide show
  1. package/CHANGELOG.md +2264 -0
  2. package/README.md +6 -6
  3. package/dist/sweetalert2.all.js +127 -47
  4. package/dist/sweetalert2.all.min.js +1 -1
  5. package/dist/sweetalert2.js +127 -47
  6. package/dist/sweetalert2.min.js +1 -1
  7. package/package.json +10 -6
  8. package/src/SweetAlert.js +12 -11
  9. package/src/buttons-handlers.js +30 -27
  10. package/src/globalState.js +1 -1
  11. package/src/instanceMethods/_destroy.js +1 -1
  12. package/src/instanceMethods/close.js +25 -23
  13. package/src/instanceMethods/enable-disable-elements.js +7 -7
  14. package/src/instanceMethods/getInput.js +1 -1
  15. package/src/instanceMethods/hideLoading.js +2 -5
  16. package/src/instanceMethods/progress-steps.js +1 -1
  17. package/src/instanceMethods/update.js +20 -13
  18. package/src/instanceMethods/validation-message.js +2 -2
  19. package/src/keydown-handler.js +22 -16
  20. package/src/popup-click-handler.js +3 -1
  21. package/src/privateMethods.js +1 -1
  22. package/src/privateProps.js +1 -1
  23. package/src/staticMethods/argsToParams.js +1 -1
  24. package/src/staticMethods/bindClickHandler.js +1 -1
  25. package/src/staticMethods/dom.js +1 -1
  26. package/src/staticMethods/fire.js +2 -2
  27. package/src/staticMethods/mixin.js +2 -2
  28. package/src/staticMethods/showLoading.js +1 -4
  29. package/src/staticMethods.js +1 -5
  30. package/src/utils/DismissReason.js +1 -1
  31. package/src/utils/Timer.js +6 -6
  32. package/src/utils/aria.js +2 -2
  33. package/src/utils/classes.js +1 -7
  34. package/src/utils/defaultInputValidators.js +1 -1
  35. package/src/utils/dom/animationEndEvent.js +1 -1
  36. package/src/utils/dom/domUtils.js +16 -9
  37. package/src/utils/dom/getters.js +7 -7
  38. package/src/utils/dom/init.js +3 -7
  39. package/src/utils/dom/inputUtils.js +26 -19
  40. package/src/utils/dom/parseHtmlToContainer.js +14 -3
  41. package/src/utils/dom/renderers/renderActions.js +3 -3
  42. package/src/utils/dom/renderers/renderContainer.js +3 -3
  43. package/src/utils/dom/renderers/renderContent.js +4 -2
  44. package/src/utils/dom/renderers/renderIcon.js +24 -15
  45. package/src/utils/dom/renderers/renderInput.js +30 -21
  46. package/src/utils/dom/renderers/renderPopup.js +2 -1
  47. package/src/utils/dom/renderers/renderProgressSteps.js +1 -1
  48. package/src/utils/getTemplateParams.js +36 -5
  49. package/src/utils/iosFix.js +16 -5
  50. package/src/utils/isNodeEnv.js +5 -1
  51. package/src/utils/params.js +2 -2
  52. package/src/utils/setParameters.js +5 -5
  53. package/src/utils/utils.js +5 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sweetalert2",
3
- "version": "11.3.4",
3
+ "version": "11.3.8",
4
4
  "repository": "sweetalert2/sweetalert2",
5
5
  "homepage": "https://sweetalert2.github.io/",
6
6
  "description": "A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes, supported fork of sweetalert",
@@ -8,18 +8,21 @@
8
8
  "browser": "dist/sweetalert2.all.js",
9
9
  "module": "src/sweetalert2.js",
10
10
  "types": "sweetalert2.d.ts",
11
+ "type": "module",
11
12
  "devDependencies": {
12
13
  "@babel/core": "^7.16.7",
13
14
  "@babel/preset-env": "^7.16.7",
14
15
  "@rollup/plugin-json": "^4.0.2",
15
16
  "@sweetalert2/eslint-config": "^1.0.11",
16
17
  "@sweetalert2/execute": "^1.0.0",
18
+ "@sweetalert2/prettier-config": "^1.0.0",
17
19
  "@sweetalert2/stylelint-config": "^2.0.6",
18
20
  "browser-sync": "^2.27.7",
19
- "cspell": "^5.14.0",
21
+ "cspell": "^5.15.1",
20
22
  "cypress": "^9.2.0",
21
- "eslint": "^8.6.0",
23
+ "eslint": "^8.7.0",
22
24
  "eslint-plugin-cypress": "^2.12.1",
25
+ "eslint-plugin-import": "^2.25.4",
23
26
  "eslint-plugin-no-unsanitized": "^4.0.1",
24
27
  "gulp": "^4.0.0",
25
28
  "gulp-autoprefixer": "^8.0.0",
@@ -33,10 +36,11 @@
33
36
  "jquery": "^3.6.0",
34
37
  "merge2": "^1.2.3",
35
38
  "postcss-scss": "^4.0.2",
39
+ "prettier": "^2.5.1",
36
40
  "replace-in-file": "^6.3.2",
37
- "rollup": "^2.62.0",
41
+ "rollup": "^2.64.0",
38
42
  "rollup-plugin-babel": "^4.3.2",
39
- "sass": "^1.45.2",
43
+ "sass": "^1.47.0",
40
44
  "sinon": "^12.0.1",
41
45
  "stylelint": "^14.2.0",
42
46
  "typescript": "^4.5.4"
@@ -76,7 +80,7 @@
76
80
  ],
77
81
  "scripts": {
78
82
  "start": "gulp develop --continue-on-error --skip-minification --skip-standalone",
79
- "lint": "stylelint src/**/*.scss && eslint src test cypress tools *.js *.ts && cspell lint 'src/**/*.js' --no-progress --no-summary",
83
+ "lint": "stylelint src/**/*.scss && eslint src test cypress tools *.js *.ts && prettier --check src/**/*.js cypress/**/*.js test/**/*.{js,ts} tools/**/*.js *.js && cspell lint 'src/**/*.js' --no-progress --no-summary",
80
84
  "build": "gulp build",
81
85
  "test": "cypress run --headless",
82
86
  "check-types": "tsc --noEmit -p jsconfig.json",
package/src/SweetAlert.js CHANGED
@@ -8,7 +8,7 @@ import setParameters from './utils/setParameters.js'
8
8
  import Timer from './utils/Timer.js'
9
9
  import { openPopup } from './utils/openPopup.js'
10
10
  import { handleInputOptionsAndValue } from './utils/dom/inputUtils.js'
11
- import { handleConfirmButtonClick, handleDenyButtonClick, handleCancelButtonClick } from './buttons-handlers.js'
11
+ import { handleCancelButtonClick, handleConfirmButtonClick, handleDenyButtonClick } from './buttons-handlers.js'
12
12
  import { handlePopupClick } from './popup-click-handler.js'
13
13
  import { addKeydownHandler, setFocus } from './keydown-handler.js'
14
14
  import * as staticMethods from './staticMethods.js'
@@ -20,7 +20,7 @@ import globalState from './globalState.js'
20
20
  let currentInstance
21
21
 
22
22
  class SweetAlert {
23
- constructor (...args) {
23
+ constructor(...args) {
24
24
  // Prevent run in Node env
25
25
  if (typeof window === 'undefined') {
26
26
  return
@@ -36,8 +36,8 @@ class SweetAlert {
36
36
  value: outerParams,
37
37
  writable: false,
38
38
  enumerable: true,
39
- configurable: true
40
- }
39
+ configurable: true,
40
+ },
41
41
  })
42
42
 
43
43
  // @ts-ignore
@@ -45,7 +45,7 @@ class SweetAlert {
45
45
  privateProps.promise.set(this, promise)
46
46
  }
47
47
 
48
- _main (userParams, mixinParams = {}) {
48
+ _main(userParams, mixinParams = {}) {
49
49
  showWarningsForParams(Object.assign({}, mixinParams, userParams))
50
50
 
51
51
  if (globalState.currentInstance) {
@@ -79,12 +79,12 @@ class SweetAlert {
79
79
  }
80
80
 
81
81
  // `catch` cannot be the name of a module export, so we define our thenable methods here instead
82
- then (onFulfilled) {
82
+ then(onFulfilled) {
83
83
  const promise = privateProps.promise.get(this)
84
84
  return promise.then(onFulfilled)
85
85
  }
86
86
 
87
- finally (onFinally) {
87
+ finally(onFinally) {
88
88
  const promise = privateProps.promise.get(this)
89
89
  return promise.finally(onFinally)
90
90
  }
@@ -144,7 +144,7 @@ const populateDomCache = (instance) => {
144
144
  loader: dom.getLoader(),
145
145
  closeButton: dom.getCloseButton(),
146
146
  validationMessage: dom.getValidationMessage(),
147
- progressSteps: dom.getProgressSteps()
147
+ progressSteps: dom.getProgressSteps(),
148
148
  }
149
149
  privateProps.domCache.set(instance, domCache)
150
150
 
@@ -162,7 +162,8 @@ const setupTimer = (globalState, innerParams, dismissWith) => {
162
162
  if (innerParams.timerProgressBar) {
163
163
  dom.show(timerProgressBar)
164
164
  setTimeout(() => {
165
- if (globalState.timeout && globalState.timeout.running) { // timer can be already stopped or unset at this point
165
+ if (globalState.timeout && globalState.timeout.running) {
166
+ // timer can be already stopped or unset at this point
166
167
  dom.animateTimerProgressBar(innerParams.timer)
167
168
  }
168
169
  })
@@ -216,7 +217,7 @@ Object.assign(SweetAlert.prototype, instanceMethods)
216
217
  Object.assign(SweetAlert, staticMethods)
217
218
 
218
219
  // Proxy to instance methods to constructor, for now, for backwards compatibility
219
- Object.keys(instanceMethods).forEach(key => {
220
+ Object.keys(instanceMethods).forEach((key) => {
220
221
  SweetAlert[key] = function (...args) {
221
222
  if (currentInstance) {
222
223
  return currentInstance[key](...args)
@@ -226,6 +227,6 @@ Object.keys(instanceMethods).forEach(key => {
226
227
 
227
228
  SweetAlert.DismissReason = DismissReason
228
229
 
229
- SweetAlert.version = '11.3.4'
230
+ SweetAlert.version = '11.3.8'
230
231
 
231
232
  export default SweetAlert
@@ -1,7 +1,7 @@
1
1
  import { isVisible } from './utils/dom/domUtils.js'
2
2
  import { getInputValue } from './utils/dom/inputUtils.js'
3
3
  import { getDenyButton, getValidationMessage } from './utils/dom/getters.js'
4
- import { asPromise } from './utils/utils.js'
4
+ import { asPromise, capitalizeFirstLetter, error } from './utils/utils.js'
5
5
  import { showLoading } from './staticMethods/showLoading.js'
6
6
  import { DismissReason } from './utils/DismissReason.js'
7
7
  import privateProps from './privateProps.js'
@@ -33,6 +33,11 @@ export const handleCancelButtonClick = (instance, dismissWith) => {
33
33
 
34
34
  const handleConfirmOrDenyWithInput = (instance, type /* 'confirm' | 'deny' */) => {
35
35
  const innerParams = privateProps.innerParams.get(instance)
36
+ if (!innerParams.input) {
37
+ return error(
38
+ `The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`
39
+ )
40
+ }
36
41
  const inputValue = getInputValue(instance, innerParams)
37
42
  if (innerParams.inputValidator) {
38
43
  handleInputValidator(instance, inputValue, type)
@@ -49,22 +54,20 @@ const handleConfirmOrDenyWithInput = (instance, type /* 'confirm' | 'deny' */) =
49
54
  const handleInputValidator = (instance, inputValue, type /* 'confirm' | 'deny' */) => {
50
55
  const innerParams = privateProps.innerParams.get(instance)
51
56
  instance.disableInput()
52
- const validationPromise = Promise.resolve().then(() => asPromise(
53
- innerParams.inputValidator(inputValue, innerParams.validationMessage))
57
+ const validationPromise = Promise.resolve().then(() =>
58
+ asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage))
54
59
  )
55
- validationPromise.then(
56
- (validationMessage) => {
57
- instance.enableButtons()
58
- instance.enableInput()
59
- if (validationMessage) {
60
- instance.showValidationMessage(validationMessage)
61
- } else if (type === 'deny') {
62
- deny(instance, inputValue)
63
- } else {
64
- confirm(instance, inputValue)
65
- }
60
+ validationPromise.then((validationMessage) => {
61
+ instance.enableButtons()
62
+ instance.enableInput()
63
+ if (validationMessage) {
64
+ instance.showValidationMessage(validationMessage)
65
+ } else if (type === 'deny') {
66
+ deny(instance, inputValue)
67
+ } else {
68
+ confirm(instance, inputValue)
66
69
  }
67
- )
70
+ })
68
71
  }
69
72
 
70
73
  const deny = (instance, value) => {
@@ -76,18 +79,18 @@ const deny = (instance, value) => {
76
79
 
77
80
  if (innerParams.preDeny) {
78
81
  privateProps.awaitingPromise.set(instance || this, true) // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preDeny's promise is received
79
- const preDenyPromise = Promise.resolve().then(() => asPromise(
80
- innerParams.preDeny(value, innerParams.validationMessage))
82
+ const preDenyPromise = Promise.resolve().then(() =>
83
+ asPromise(innerParams.preDeny(value, innerParams.validationMessage))
81
84
  )
82
- preDenyPromise.then(
83
- (preDenyValue) => {
85
+ preDenyPromise
86
+ .then((preDenyValue) => {
84
87
  if (preDenyValue === false) {
85
88
  instance.hideLoading()
86
89
  } else {
87
90
  instance.closePopup({ isDenied: true, value: typeof preDenyValue === 'undefined' ? value : preDenyValue })
88
91
  }
89
- }
90
- ).catch((error) => rejectWith(instance || this, error))
92
+ })
93
+ .catch((error) => rejectWith(instance || this, error))
91
94
  } else {
92
95
  instance.closePopup({ isDenied: true, value })
93
96
  }
@@ -111,18 +114,18 @@ const confirm = (instance, value) => {
111
114
  if (innerParams.preConfirm) {
112
115
  instance.resetValidationMessage()
113
116
  privateProps.awaitingPromise.set(instance || this, true) // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preConfirm's promise is received
114
- const preConfirmPromise = Promise.resolve().then(() => asPromise(
115
- innerParams.preConfirm(value, innerParams.validationMessage))
117
+ const preConfirmPromise = Promise.resolve().then(() =>
118
+ asPromise(innerParams.preConfirm(value, innerParams.validationMessage))
116
119
  )
117
- preConfirmPromise.then(
118
- (preConfirmValue) => {
120
+ preConfirmPromise
121
+ .then((preConfirmValue) => {
119
122
  if (isVisible(getValidationMessage()) || preConfirmValue === false) {
120
123
  instance.hideLoading()
121
124
  } else {
122
125
  succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue)
123
126
  }
124
- }
125
- ).catch((error) => rejectWith(instance || this, error))
127
+ })
128
+ .catch((error) => rejectWith(instance || this, error))
126
129
  } else {
127
130
  succeedWith(instance, value)
128
131
  }
@@ -15,7 +15,7 @@ const focusPreviousActiveElement = () => {
15
15
 
16
16
  // Restore previous active (focused) element
17
17
  export const restoreActiveElement = (returnFocus) => {
18
- return new Promise(resolve => {
18
+ return new Promise((resolve) => {
19
19
  if (!returnFocus) {
20
20
  return resolve()
21
21
  }
@@ -2,7 +2,7 @@ import globalState from '../globalState.js'
2
2
  import privateProps from '../privateProps.js'
3
3
  import privateMethods from '../privateMethods.js'
4
4
 
5
- export function _destroy () {
5
+ export function _destroy() {
6
6
  const domCache = privateProps.domCache.get(this)
7
7
  const innerParams = privateProps.innerParams.get(this)
8
8
 
@@ -11,12 +11,14 @@ import privateMethods from '../privateMethods.js'
11
11
  * Instance method to close sweetAlert
12
12
  */
13
13
 
14
- function removePopupAndResetState (instance, container, returnFocus, didClose) {
14
+ function removePopupAndResetState(instance, container, returnFocus, didClose) {
15
15
  if (dom.isToast()) {
16
16
  triggerDidCloseAndDispose(instance, didClose)
17
17
  } else {
18
18
  restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose))
19
- globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { capture: globalState.keydownListenerCapture })
19
+ globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
20
+ capture: globalState.keydownListenerCapture,
21
+ })
20
22
  globalState.keydownHandlerAdded = false
21
23
  }
22
24
 
@@ -40,19 +42,14 @@ function removePopupAndResetState (instance, container, returnFocus, didClose) {
40
42
  removeBodyClasses()
41
43
  }
42
44
 
43
- function removeBodyClasses () {
45
+ function removeBodyClasses() {
44
46
  dom.removeClass(
45
47
  [document.documentElement, document.body],
46
- [
47
- swalClasses.shown,
48
- swalClasses['height-auto'],
49
- swalClasses['no-backdrop'],
50
- swalClasses['toast-shown'],
51
- ]
48
+ [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]
52
49
  )
53
50
  }
54
51
 
55
- export function close (resolveValue) {
52
+ export function close(resolveValue) {
56
53
  resolveValue = prepareResolveValue(resolveValue)
57
54
 
58
55
  const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this)
@@ -71,7 +68,7 @@ export function close (resolveValue) {
71
68
  }
72
69
  }
73
70
 
74
- export function isAwaitingPromise () {
71
+ export function isAwaitingPromise() {
75
72
  return !!privateProps.awaitingPromise.get(this)
76
73
  }
77
74
 
@@ -99,7 +96,7 @@ const triggerClosePopup = (instance) => {
99
96
  return true
100
97
  }
101
98
 
102
- export function rejectPromise (error) {
99
+ export function rejectPromise(error) {
103
100
  const rejectPromise = privateMethods.swalPromiseReject.get(this)
104
101
  handleAwaitingPromise(this)
105
102
  if (rejectPromise) {
@@ -128,11 +125,14 @@ const prepareResolveValue = (resolveValue) => {
128
125
  }
129
126
  }
130
127
 
131
- return Object.assign({
132
- isConfirmed: false,
133
- isDenied: false,
134
- isDismissed: false,
135
- }, resolveValue)
128
+ return Object.assign(
129
+ {
130
+ isConfirmed: false,
131
+ isDenied: false,
132
+ isDismissed: false,
133
+ },
134
+ resolveValue
135
+ )
136
136
  }
137
137
 
138
138
  const handlePopupAnimation = (instance, popup, innerParams) => {
@@ -153,7 +153,13 @@ const handlePopupAnimation = (instance, popup, innerParams) => {
153
153
  }
154
154
 
155
155
  const animatePopup = (instance, popup, container, returnFocus, didClose) => {
156
- globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose)
156
+ globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(
157
+ null,
158
+ instance,
159
+ container,
160
+ returnFocus,
161
+ didClose
162
+ )
157
163
  popup.addEventListener(dom.animationEndEvent, function (e) {
158
164
  if (e.target === popup) {
159
165
  globalState.swalCloseEventFinishedCallback()
@@ -171,8 +177,4 @@ const triggerDidCloseAndDispose = (instance, didClose) => {
171
177
  })
172
178
  }
173
179
 
174
- export {
175
- close as closePopup,
176
- close as closeModal,
177
- close as closeToast
178
- }
180
+ export { close as closePopup, close as closeModal, close as closeToast }
@@ -1,13 +1,13 @@
1
1
  import privateProps from '../privateProps.js'
2
2
 
3
- function setButtonsDisabled (instance, buttons, disabled) {
3
+ function setButtonsDisabled(instance, buttons, disabled) {
4
4
  const domCache = privateProps.domCache.get(instance)
5
- buttons.forEach(button => {
5
+ buttons.forEach((button) => {
6
6
  domCache[button].disabled = disabled
7
7
  })
8
8
  }
9
9
 
10
- function setInputDisabled (input, disabled) {
10
+ function setInputDisabled(input, disabled) {
11
11
  if (!input) {
12
12
  return false
13
13
  }
@@ -22,18 +22,18 @@ function setInputDisabled (input, disabled) {
22
22
  }
23
23
  }
24
24
 
25
- export function enableButtons () {
25
+ export function enableButtons() {
26
26
  setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false)
27
27
  }
28
28
 
29
- export function disableButtons () {
29
+ export function disableButtons() {
30
30
  setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true)
31
31
  }
32
32
 
33
- export function enableInput () {
33
+ export function enableInput() {
34
34
  return setInputDisabled(this.getInput(), false)
35
35
  }
36
36
 
37
- export function disableInput () {
37
+ export function disableInput() {
38
38
  return setInputDisabled(this.getInput(), true)
39
39
  }
@@ -5,7 +5,7 @@ import privateProps from '../privateProps.js'
5
5
  * Gets the input DOM node, this method works with input parameter.
6
6
  * @returns {HTMLElement | null}
7
7
  */
8
- export function getInput (instance) {
8
+ export function getInput(instance) {
9
9
  const innerParams = privateProps.innerParams.get(instance || this)
10
10
  const domCache = privateProps.domCache.get(instance || this)
11
11
  if (!domCache) {
@@ -5,7 +5,7 @@ import privateProps from '../privateProps.js'
5
5
  /**
6
6
  * Hides loader and shows back the button which was hidden by .showLoading()
7
7
  */
8
- function hideLoading () {
8
+ function hideLoading() {
9
9
  // do nothing if popup is closed
10
10
  const innerParams = privateProps.innerParams.get(this)
11
11
  if (!innerParams) {
@@ -37,7 +37,4 @@ const showRelatedButton = (domCache) => {
37
37
  }
38
38
  }
39
39
 
40
- export {
41
- hideLoading,
42
- hideLoading as disableLoading
43
- }
40
+ export { hideLoading, hideLoading as disableLoading }
@@ -1,6 +1,6 @@
1
1
  import privateProps from '../privateProps.js'
2
2
 
3
- export function getProgressSteps () {
3
+ export function getProgressSteps() {
4
4
  const domCache = privateProps.domCache.get(this)
5
5
  return domCache.progressSteps
6
6
  }
@@ -6,24 +6,17 @@ import { isUpdatableParameter } from '../../src/utils/params.js'
6
6
  /**
7
7
  * Updates popup parameters.
8
8
  */
9
- export function update (params) {
9
+ export function update(params) {
10
10
  const popup = dom.getPopup()
11
11
  const innerParams = privateProps.innerParams.get(this)
12
12
 
13
13
  if (!popup || dom.hasClass(popup, innerParams.hideClass.popup)) {
14
- return warn(`You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.`)
14
+ return warn(
15
+ `You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.`
16
+ )
15
17
  }
16
18
 
17
- const validUpdatableParams = {}
18
-
19
- // assign valid params from `params` to `defaults`
20
- Object.keys(params).forEach(param => {
21
- if (isUpdatableParameter(param)) {
22
- validUpdatableParams[param] = params[param]
23
- } else {
24
- warn(`Invalid parameter to update: "${param}". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md`)
25
- }
26
- })
19
+ const validUpdatableParams = filterValidParams(params)
27
20
 
28
21
  const updatedParams = Object.assign({}, innerParams, validUpdatableParams)
29
22
 
@@ -34,7 +27,21 @@ export function update (params) {
34
27
  params: {
35
28
  value: Object.assign({}, this.params, params),
36
29
  writable: false,
37
- enumerable: true
30
+ enumerable: true,
31
+ },
32
+ })
33
+ }
34
+
35
+ const filterValidParams = (params) => {
36
+ const validUpdatableParams = {}
37
+ Object.keys(params).forEach((param) => {
38
+ if (isUpdatableParameter(param)) {
39
+ validUpdatableParams[param] = params[param]
40
+ } else {
41
+ warn(
42
+ `Invalid parameter to update: "${param}". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md`
43
+ )
38
44
  }
39
45
  })
46
+ return validUpdatableParams
40
47
  }
@@ -3,7 +3,7 @@ import { swalClasses } from '../utils/classes.js'
3
3
  import privateProps from '../privateProps.js'
4
4
 
5
5
  // Show block with validation message
6
- export function showValidationMessage (error) {
6
+ export function showValidationMessage(error) {
7
7
  const domCache = privateProps.domCache.get(this)
8
8
  const params = privateProps.innerParams.get(this)
9
9
  dom.setInnerHtml(domCache.validationMessage, error)
@@ -23,7 +23,7 @@ export function showValidationMessage (error) {
23
23
  }
24
24
 
25
25
  // Hide block with validation message
26
- export function resetValidationMessage () {
26
+ export function resetValidationMessage() {
27
27
  const domCache = privateProps.domCache.get(this)
28
28
  if (domCache.validationMessage) {
29
29
  dom.hide(domCache.validationMessage)
@@ -6,7 +6,9 @@ import privateProps from './privateProps.js'
6
6
 
7
7
  export const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
8
8
  if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
9
- globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { capture: globalState.keydownListenerCapture })
9
+ globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
10
+ capture: globalState.keydownListenerCapture,
11
+ })
10
12
  globalState.keydownHandlerAdded = false
11
13
  }
12
14
 
@@ -14,7 +16,9 @@ export const addKeydownHandler = (instance, globalState, innerParams, dismissWit
14
16
  globalState.keydownHandler = (e) => keydownHandler(instance, e, dismissWith)
15
17
  globalState.keydownTarget = innerParams.keydownListenerCapture ? window : dom.getPopup()
16
18
  globalState.keydownListenerCapture = innerParams.keydownListenerCapture
17
- globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, { capture: globalState.keydownListenerCapture })
19
+ globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
20
+ capture: globalState.keydownListenerCapture,
21
+ })
18
22
  globalState.keydownHandlerAdded = true
19
23
  }
20
24
  }
@@ -41,13 +45,9 @@ export const setFocus = (innerParams, index, increment) => {
41
45
  dom.getPopup().focus()
42
46
  }
43
47
 
44
- const arrowKeysNextButton = [
45
- 'ArrowRight', 'ArrowDown',
46
- ]
48
+ const arrowKeysNextButton = ['ArrowRight', 'ArrowDown']
47
49
 
48
- const arrowKeysPreviousButton = [
49
- 'ArrowLeft', 'ArrowUp',
50
- ]
50
+ const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp']
51
51
 
52
52
  const keydownHandler = (instance, e, dismissWith) => {
53
53
  const innerParams = privateProps.innerParams.get(instance)
@@ -63,24 +63,27 @@ const keydownHandler = (instance, e, dismissWith) => {
63
63
  // ENTER
64
64
  if (e.key === 'Enter') {
65
65
  handleEnter(instance, e, innerParams)
66
+ }
66
67
 
67
68
  // TAB
68
- } else if (e.key === 'Tab') {
69
+ else if (e.key === 'Tab') {
69
70
  handleTab(e, innerParams)
71
+ }
70
72
 
71
73
  // ARROWS - switch focus between buttons
72
- } else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
74
+ else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
73
75
  handleArrows(e.key)
76
+ }
74
77
 
75
78
  // ESC
76
- } else if (e.key === 'Escape') {
79
+ else if (e.key === 'Escape') {
77
80
  handleEsc(e, innerParams, dismissWith)
78
81
  }
79
82
  }
80
83
 
81
84
  const handleEnter = (instance, e, innerParams) => {
82
- // #720 #721
83
- if (e.isComposing) {
85
+ // #2386 #720 #721
86
+ if (!callIfFunction(innerParams.allowEnterKey) || e.isComposing) {
84
87
  return
85
88
  }
86
89
 
@@ -106,13 +109,16 @@ const handleTab = (e, innerParams) => {
106
109
  }
107
110
  }
108
111
 
112
+ // Cycle to the next button
109
113
  if (!e.shiftKey) {
110
- // Cycle to the next button
111
114
  setFocus(innerParams, btnIndex, 1)
112
- } else {
113
- // Cycle to the prev button
115
+ }
116
+
117
+ // Cycle to the prev button
118
+ else {
114
119
  setFocus(innerParams, btnIndex, -1)
115
120
  }
121
+
116
122
  e.stopPropagation()
117
123
  e.preventDefault()
118
124
  }
@@ -34,10 +34,12 @@ const handleToastClick = (instance, domCache, dismissWith) => {
34
34
  * @returns {boolean}
35
35
  */
36
36
  const isAnyButtonShown = (innerParams) => {
37
- return innerParams.showConfirmButton ||
37
+ return (
38
+ innerParams.showConfirmButton ||
38
39
  innerParams.showDenyButton ||
39
40
  innerParams.showCancelButton ||
40
41
  innerParams.showCloseButton
42
+ )
41
43
  }
42
44
 
43
45
  let ignoreOutsideClick = false
@@ -10,5 +10,5 @@
10
10
 
11
11
  export default {
12
12
  swalPromiseResolve: new WeakMap(),
13
- swalPromiseReject: new WeakMap()
13
+ swalPromiseReject: new WeakMap(),
14
14
  }
@@ -12,5 +12,5 @@ export default {
12
12
  awaitingPromise: new WeakMap(),
13
13
  promise: new WeakMap(),
14
14
  innerParams: new WeakMap(),
15
- domCache: new WeakMap()
15
+ domCache: new WeakMap(),
16
16
  }
@@ -8,7 +8,7 @@ export const argsToParams = (args) => {
8
8
  if (typeof args[0] === 'object' && !isElement(args[0])) {
9
9
  Object.assign(params, args[0])
10
10
  } else {
11
- ['title', 'html', 'icon'].forEach((name, index) => {
11
+ ;['title', 'html', 'icon'].forEach((name, index) => {
12
12
  const arg = args[index]
13
13
  if (typeof arg === 'string' || isElement(arg)) {
14
14
  params[name] = arg
@@ -1,7 +1,7 @@
1
1
  let bodyClickListenerAdded = false
2
2
  const clickHandlers = {}
3
3
 
4
- export function bindClickHandler (attr = 'data-swal-template') {
4
+ export function bindClickHandler(attr = 'data-swal-template') {
5
5
  clickHandlers[attr] = this
6
6
 
7
7
  if (!bodyClickListenerAdded) {
@@ -19,7 +19,7 @@ export {
19
19
  getTimerProgressBar,
20
20
  getFocusableElements,
21
21
  getValidationMessage,
22
- isLoading
22
+ isLoading,
23
23
  } from '../utils/dom/index.js'
24
24
 
25
25
  /*