sweetalert2 11.4.32 → 11.4.34

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.
@@ -4,6 +4,14 @@ import { asPromise, error, hasToPromiseFn, isPromise } from '../utils.js'
4
4
  import { getDirectChildByClass } from './domUtils.js'
5
5
  import * as dom from './index.js'
6
6
 
7
+ /**
8
+ * @typedef { string | number | boolean } InputValue
9
+ */
10
+
11
+ /**
12
+ * @param {SweetAlert2} instance
13
+ * @param {SweetAlertOptions} params
14
+ */
7
15
  export const handleInputOptionsAndValue = (instance, params) => {
8
16
  if (params.input === 'select' || params.input === 'radio') {
9
17
  handleInputOptions(instance, params)
@@ -16,6 +24,11 @@ export const handleInputOptionsAndValue = (instance, params) => {
16
24
  }
17
25
  }
18
26
 
27
+ /**
28
+ * @param {SweetAlert2} instance
29
+ * @param {SweetAlertOptions} innerParams
30
+ * @returns {string | number | File | FileList | null}
31
+ */
19
32
  export const getInputValue = (instance, innerParams) => {
20
33
  const input = instance.getInput()
21
34
  if (!input) {
@@ -33,17 +46,37 @@ export const getInputValue = (instance, innerParams) => {
33
46
  }
34
47
  }
35
48
 
49
+ /**
50
+ * @param {HTMLInputElement} input
51
+ * @returns {number}
52
+ */
36
53
  const getCheckboxValue = (input) => (input.checked ? 1 : 0)
37
54
 
55
+ /**
56
+ * @param {HTMLInputElement} input
57
+ * @returns {string | null}
58
+ */
38
59
  const getRadioValue = (input) => (input.checked ? input.value : null)
39
60
 
61
+ /**
62
+ * @param {HTMLInputElement} input
63
+ * @returns {FileList | File | null}
64
+ */
40
65
  const getFileValue = (input) =>
41
66
  input.files.length ? (input.getAttribute('multiple') !== null ? input.files : input.files[0]) : null
42
67
 
68
+ /**
69
+ * @param {SweetAlert2} instance
70
+ * @param {SweetAlertOptions} params
71
+ */
43
72
  const handleInputOptions = (instance, params) => {
44
73
  const popup = dom.getPopup()
45
- const processInputOptions = (inputOptions) =>
74
+ /**
75
+ * @param {Record<string, any>} inputOptions
76
+ */
77
+ const processInputOptions = (inputOptions) => {
46
78
  populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params)
79
+ }
47
80
  if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
48
81
  showLoading(dom.getConfirmButton())
49
82
  asPromise(params.inputOptions).then((inputOptions) => {
@@ -57,12 +90,16 @@ const handleInputOptions = (instance, params) => {
57
90
  }
58
91
  }
59
92
 
93
+ /**
94
+ * @param {SweetAlert2} instance
95
+ * @param {SweetAlertOptions} params
96
+ */
60
97
  const handleInputValue = (instance, params) => {
61
98
  const input = instance.getInput()
62
99
  dom.hide(input)
63
100
  asPromise(params.inputValue)
64
101
  .then((inputValue) => {
65
- input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : `${inputValue}`
102
+ input.value = params.input === 'number' ? `${parseFloat(inputValue) || 0}` : `${inputValue}`
66
103
  dom.show(input)
67
104
  input.focus()
68
105
  instance.hideLoading()
@@ -77,8 +114,18 @@ const handleInputValue = (instance, params) => {
77
114
  }
78
115
 
79
116
  const populateInputOptions = {
117
+ /**
118
+ * @param {HTMLElement} popup
119
+ * @param {Record<string, any>} inputOptions
120
+ * @param {SweetAlertOptions} params
121
+ */
80
122
  select: (popup, inputOptions, params) => {
81
123
  const select = getDirectChildByClass(popup, swalClasses.select)
124
+ /**
125
+ * @param {HTMLElement} parent
126
+ * @param {string} optionLabel
127
+ * @param {string} optionValue
128
+ */
82
129
  const renderOption = (parent, optionLabel, optionValue) => {
83
130
  const option = document.createElement('option')
84
131
  option.value = optionValue
@@ -108,6 +155,11 @@ const populateInputOptions = {
108
155
  select.focus()
109
156
  },
110
157
 
158
+ /**
159
+ * @param {HTMLElement} popup
160
+ * @param {Record<string, any>} inputOptions
161
+ * @param {SweetAlertOptions} params
162
+ */
111
163
  radio: (popup, inputOptions, params) => {
112
164
  const radio = getDirectChildByClass(popup, swalClasses.radio)
113
165
  inputOptions.forEach((inputOption) => {
@@ -137,7 +189,9 @@ const populateInputOptions = {
137
189
 
138
190
  /**
139
191
  * Converts `inputOptions` into an array of `[value, label]`s
140
- * @param inputOptions
192
+ *
193
+ * @param {Record<string, any>} inputOptions
194
+ * @returns {Array<Array<string>>}
141
195
  */
142
196
  const formatInputOptions = (inputOptions) => {
143
197
  const result = []
@@ -163,6 +217,11 @@ const formatInputOptions = (inputOptions) => {
163
217
  return result
164
218
  }
165
219
 
220
+ /**
221
+ * @param {string} optionValue
222
+ * @param {InputValue | Promise<InputValue> | { toPromise: () => InputValue }} inputValue
223
+ * @returns {boolean}
224
+ */
166
225
  const isSelected = (optionValue, inputValue) => {
167
226
  return inputValue && inputValue.toString() === optionValue.toString()
168
227
  }