sweetalert2 11.26.12 → 11.26.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/dist/sweetalert2.all.js +82 -52
- package/dist/sweetalert2.all.min.js +2 -2
- package/dist/sweetalert2.esm.all.js +82 -52
- package/dist/sweetalert2.esm.all.min.js +2 -2
- package/dist/sweetalert2.esm.js +82 -52
- package/dist/sweetalert2.esm.min.js +2 -2
- package/dist/sweetalert2.js +82 -52
- package/dist/sweetalert2.min.js +2 -2
- package/package.json +1 -1
- package/src/SweetAlert.js +1 -1
- package/src/utils/dom/renderers/renderInput.js +80 -50
|
@@ -185,9 +185,9 @@ const checkAndSetInputValue = (input, inputValue) => {
|
|
|
185
185
|
const renderInputType = {}
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
|
-
* @param {
|
|
188
|
+
* @param {Input | HTMLElement} input
|
|
189
189
|
* @param {SweetAlertOptions} params
|
|
190
|
-
* @returns {
|
|
190
|
+
* @returns {Input}
|
|
191
191
|
*/
|
|
192
192
|
renderInputType.text =
|
|
193
193
|
renderInputType.email =
|
|
@@ -203,90 +203,113 @@ renderInputType.text =
|
|
|
203
203
|
renderInputType.month =
|
|
204
204
|
/** @type {(input: Input | HTMLElement, params: SweetAlertOptions) => Input} */
|
|
205
205
|
(input, params) => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
const inputElement = /** @type {HTMLInputElement} */ (input)
|
|
207
|
+
checkAndSetInputValue(inputElement, params.inputValue)
|
|
208
|
+
setInputLabel(inputElement, inputElement, params)
|
|
209
|
+
setInputPlaceholder(inputElement, params)
|
|
210
|
+
inputElement.type = /** @type {string} */ (params.input)
|
|
211
|
+
return inputElement
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
/**
|
|
214
|
-
* @param {
|
|
215
|
+
* @param {Input | HTMLElement} input
|
|
215
216
|
* @param {SweetAlertOptions} params
|
|
216
|
-
* @returns {
|
|
217
|
+
* @returns {Input}
|
|
217
218
|
*/
|
|
218
219
|
renderInputType.file = (input, params) => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
const inputElement = /** @type {HTMLInputElement} */ (input)
|
|
221
|
+
setInputLabel(inputElement, inputElement, params)
|
|
222
|
+
setInputPlaceholder(inputElement, params)
|
|
223
|
+
return inputElement
|
|
222
224
|
}
|
|
223
225
|
|
|
224
226
|
/**
|
|
225
|
-
* @param {
|
|
227
|
+
* @param {Input | HTMLElement} range
|
|
226
228
|
* @param {SweetAlertOptions} params
|
|
227
|
-
* @returns {
|
|
229
|
+
* @returns {Input}
|
|
228
230
|
*/
|
|
229
231
|
renderInputType.range = (range, params) => {
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
rangeInput
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
const rangeContainer = /** @type {HTMLElement} */ (range)
|
|
233
|
+
const rangeInput = rangeContainer.querySelector('input')
|
|
234
|
+
const rangeOutput = rangeContainer.querySelector('output')
|
|
235
|
+
if (rangeInput) {
|
|
236
|
+
checkAndSetInputValue(rangeInput, params.inputValue)
|
|
237
|
+
rangeInput.type = /** @type {string} */ (params.input)
|
|
238
|
+
setInputLabel(rangeInput, /** @type {Input} */ (range), params)
|
|
239
|
+
}
|
|
240
|
+
if (rangeOutput) {
|
|
241
|
+
checkAndSetInputValue(rangeOutput, params.inputValue)
|
|
242
|
+
}
|
|
243
|
+
return /** @type {Input} */ (range)
|
|
237
244
|
}
|
|
238
245
|
|
|
239
246
|
/**
|
|
240
|
-
* @param {
|
|
247
|
+
* @param {Input | HTMLElement} select
|
|
241
248
|
* @param {SweetAlertOptions} params
|
|
242
|
-
* @returns {
|
|
249
|
+
* @returns {Input}
|
|
243
250
|
*/
|
|
244
251
|
renderInputType.select = (select, params) => {
|
|
245
|
-
|
|
252
|
+
const selectElement = /** @type {HTMLSelectElement} */ (select)
|
|
253
|
+
selectElement.textContent = ''
|
|
246
254
|
if (params.inputPlaceholder) {
|
|
247
255
|
const placeholder = document.createElement('option')
|
|
248
256
|
dom.setInnerHtml(placeholder, params.inputPlaceholder)
|
|
249
257
|
placeholder.value = ''
|
|
250
258
|
placeholder.disabled = true
|
|
251
259
|
placeholder.selected = true
|
|
252
|
-
|
|
260
|
+
selectElement.appendChild(placeholder)
|
|
253
261
|
}
|
|
254
|
-
setInputLabel(
|
|
255
|
-
return
|
|
262
|
+
setInputLabel(selectElement, selectElement, params)
|
|
263
|
+
return selectElement
|
|
256
264
|
}
|
|
257
265
|
|
|
258
266
|
/**
|
|
259
|
-
* @param {
|
|
260
|
-
* @returns {
|
|
267
|
+
* @param {Input | HTMLElement} radio
|
|
268
|
+
* @returns {Input}
|
|
261
269
|
*/
|
|
262
270
|
renderInputType.radio = (radio) => {
|
|
263
|
-
|
|
264
|
-
|
|
271
|
+
const radioElement = /** @type {HTMLElement} */ (radio)
|
|
272
|
+
radioElement.textContent = ''
|
|
273
|
+
return /** @type {Input} */ (radio)
|
|
265
274
|
}
|
|
266
275
|
|
|
267
276
|
/**
|
|
268
|
-
* @param {
|
|
277
|
+
* @param {Input | HTMLElement} checkboxContainer
|
|
269
278
|
* @param {SweetAlertOptions} params
|
|
270
|
-
* @returns {
|
|
279
|
+
* @returns {Input}
|
|
271
280
|
*/
|
|
272
281
|
renderInputType.checkbox = (checkboxContainer, params) => {
|
|
273
|
-
const
|
|
282
|
+
const popup = dom.getPopup()
|
|
283
|
+
if (!popup) {
|
|
284
|
+
throw new Error('Popup not found')
|
|
285
|
+
}
|
|
286
|
+
const checkbox = dom.getInput(popup, 'checkbox')
|
|
287
|
+
if (!checkbox) {
|
|
288
|
+
throw new Error('Checkbox input not found')
|
|
289
|
+
}
|
|
274
290
|
checkbox.value = '1'
|
|
275
291
|
checkbox.checked = Boolean(params.inputValue)
|
|
276
|
-
const
|
|
277
|
-
|
|
292
|
+
const containerElement = /** @type {HTMLElement} */ (checkboxContainer)
|
|
293
|
+
const label = containerElement.querySelector('span')
|
|
294
|
+
if (label) {
|
|
295
|
+
const placeholderOrLabel = params.inputPlaceholder || params.inputLabel
|
|
296
|
+
if (placeholderOrLabel) {
|
|
297
|
+
dom.setInnerHtml(label, placeholderOrLabel)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
278
300
|
return checkbox
|
|
279
301
|
}
|
|
280
302
|
|
|
281
303
|
/**
|
|
282
|
-
* @param {
|
|
304
|
+
* @param {Input | HTMLElement} textarea
|
|
283
305
|
* @param {SweetAlertOptions} params
|
|
284
|
-
* @returns {
|
|
306
|
+
* @returns {Input}
|
|
285
307
|
*/
|
|
286
308
|
renderInputType.textarea = (textarea, params) => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
309
|
+
const textareaElement = /** @type {HTMLTextAreaElement} */ (textarea)
|
|
310
|
+
checkAndSetInputValue(textareaElement, params.inputValue)
|
|
311
|
+
setInputPlaceholder(textareaElement, params)
|
|
312
|
+
setInputLabel(textareaElement, textareaElement, params)
|
|
290
313
|
|
|
291
314
|
/**
|
|
292
315
|
* @param {HTMLElement} el
|
|
@@ -299,25 +322,32 @@ renderInputType.textarea = (textarea, params) => {
|
|
|
299
322
|
setTimeout(() => {
|
|
300
323
|
// https://github.com/sweetalert2/sweetalert2/issues/1699
|
|
301
324
|
if ('MutationObserver' in window) {
|
|
302
|
-
const
|
|
325
|
+
const popup = dom.getPopup()
|
|
326
|
+
if (!popup) {
|
|
327
|
+
return
|
|
328
|
+
}
|
|
329
|
+
const initialPopupWidth = parseInt(window.getComputedStyle(popup).width)
|
|
303
330
|
const textareaResizeHandler = () => {
|
|
304
331
|
// check if texarea is still in document (i.e. popup wasn't closed in the meantime)
|
|
305
|
-
if (!document.body.contains(
|
|
332
|
+
if (!document.body.contains(textareaElement)) {
|
|
306
333
|
return
|
|
307
334
|
}
|
|
308
|
-
const textareaWidth =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
335
|
+
const textareaWidth = textareaElement.offsetWidth + getMargin(textareaElement)
|
|
336
|
+
const popupElement = dom.getPopup()
|
|
337
|
+
if (popupElement) {
|
|
338
|
+
if (textareaWidth > initialPopupWidth) {
|
|
339
|
+
popupElement.style.width = `${textareaWidth}px`
|
|
340
|
+
} else {
|
|
341
|
+
dom.applyNumericalStyle(popupElement, 'width', params.width)
|
|
342
|
+
}
|
|
313
343
|
}
|
|
314
344
|
}
|
|
315
|
-
new MutationObserver(textareaResizeHandler).observe(
|
|
345
|
+
new MutationObserver(textareaResizeHandler).observe(textareaElement, {
|
|
316
346
|
attributes: true,
|
|
317
347
|
attributeFilter: ['style'],
|
|
318
348
|
})
|
|
319
349
|
}
|
|
320
350
|
})
|
|
321
351
|
|
|
322
|
-
return
|
|
352
|
+
return textareaElement
|
|
323
353
|
}
|