| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | /******/ (() => { // webpackBootstrap |
| 2 | -/******/ "use strict"; | |
| 3 | 2 | /******/ var __webpack_modules__ = ({ |
| 4 | 3 | |
| 5 | 4 | /***/ "./assets/src/js/admin/order/add-courses-to-order.js" |
| 6 | 5 | /*!***********************************************************!*\ |
| @@ -7,8 +6,9 @@ | ||
| 7 | 6 | !*** ./assets/src/js/admin/order/add-courses-to-order.js ***! |
| 8 | 7 | \***********************************************************/ |
| 9 | 8 | (__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 10 | 9 | |
| 10 | +"use strict"; | |
| 11 | 11 | __webpack_require__.r(__webpack_exports__); |
| 12 | 12 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 13 | 13 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 14 | 14 | /* harmony export */ }); |
| @@ -37,14 +37,14 @@ | ||
| 37 | 37 | modalSearchItemsTemplate = document.querySelector('#learn-press-modal-search-items'); |
| 38 | 38 | modalContainer = document.querySelector('#container-modal-search-items'); |
| 39 | 39 | }; |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * Fetch courses from API. | |
| 43 | - * | |
| 44 | - * @param keySearch | |
| 45 | - * @param course_ids_exclude | |
| 46 | - * @param paged | |
| 41 | + /** | |
| 42 | + * Fetch courses from API. | |
| 43 | + * | |
| 44 | + * @param keySearch | |
| 45 | + * @param course_ids_exclude | |
| 46 | + * @param paged | |
| 47 | 47 | */ |
| 48 | 48 | const fetchCoursesAPI = (keySearch = '', course_ids_exclude = [], paged = 1) => { |
| 49 | 49 | let id_not_in = ''; |
| 50 | 50 | if (course_ids_exclude.length > 0) { |
| @@ -90,10 +90,10 @@ | ||
| 90 | 90 | } |
| 91 | 91 | }); |
| 92 | 92 | }; |
| 93 | 93 | |
| 94 | - /** | |
| 95 | - * Get list course ids added. | |
| 94 | + /** | |
| 95 | + * Get list course ids added. | |
| 96 | 96 | */ |
| 97 | 97 | const getCoursesAdded = () => { |
| 98 | 98 | courseIdsAdded = []; |
| 99 | 99 | const orderItems = document.querySelectorAll('#learn-press-order .list-order-items tbody .order-item-row'); |
| @@ -102,12 +102,12 @@ | ||
| 102 | 102 | courseIdsAdded.push(orderItemId); |
| 103 | 103 | }); |
| 104 | 104 | }; |
| 105 | 105 | |
| 106 | - /** | |
| 107 | - * Add courses to order. | |
| 108 | - * @param e | |
| 109 | - * @param target | |
| 106 | + /** | |
| 107 | + * Add courses to order. | |
| 108 | + * @param e | |
| 109 | + * @param target | |
| 110 | 110 | */ |
| 111 | 111 | const addCourses = (e, target) => { |
| 112 | 112 | if (!target.classList.contains('add')) { |
| 113 | 113 | return; |
| @@ -157,13 +157,13 @@ | ||
| 157 | 157 | }; |
| 158 | 158 | _utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpFetchAPI(_utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpAddQueryArgs(_utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpGetCurrentURLNoParam(), dataSend), {}, callBack); |
| 159 | 159 | }; |
| 160 | 160 | |
| 161 | - /** | |
| 162 | - * Remove course from order. | |
| 163 | - * | |
| 164 | - * @param e | |
| 165 | - * @param target | |
| 161 | + /** | |
| 162 | + * Remove course from order. | |
| 163 | + * | |
| 164 | + * @param e | |
| 165 | + * @param target | |
| 166 | 166 | */ |
| 167 | 167 | const removeCourse = (e, target) => { |
| 168 | 168 | if (target.tagName !== 'SPAN') { |
| 169 | 169 | return; |
| @@ -224,13 +224,13 @@ | ||
| 224 | 224 | }; |
| 225 | 225 | _utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpFetchAPI(_utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpAddQueryArgs(_utils_admin_js__WEBPACK_IMPORTED_MODULE_0__.Utils.lpGetCurrentURLNoParam(), dataSend), {}, callBack); |
| 226 | 226 | }; |
| 227 | 227 | |
| 228 | - /** | |
| 229 | - * Search courses before add Order. | |
| 230 | - * | |
| 231 | - * @param e | |
| 232 | - * @param target | |
| 228 | + /** | |
| 229 | + * Search courses before add Order. | |
| 230 | + * | |
| 231 | + * @param e | |
| 232 | + * @param target | |
| 233 | 233 | */ |
| 234 | 234 | const searchCourse = (e, target) => { |
| 235 | 235 | if ('search' !== target.name) { |
| 236 | 236 | return; |
| @@ -250,12 +250,12 @@ | ||
| 250 | 250 | }, 800); |
| 251 | 251 | } |
| 252 | 252 | }; |
| 253 | 253 | |
| 254 | - /** | |
| 255 | - * Display list courses when search done. | |
| 256 | - * | |
| 257 | - * @param courses | |
| 254 | + /** | |
| 255 | + * Display list courses when search done. | |
| 256 | + * | |
| 257 | + * @param courses | |
| 258 | 258 | */ |
| 259 | 259 | const renderSearchResult = courses => { |
| 260 | 260 | let html = ''; |
| 261 | 261 | courses.forEach(course => { |
| @@ -271,13 +271,13 @@ | ||
| 271 | 271 | }); |
| 272 | 272 | return html; |
| 273 | 273 | }; |
| 274 | 274 | |
| 275 | - /** | |
| 276 | - * Render pagination. | |
| 277 | - * | |
| 278 | - * @param currentPage | |
| 279 | - * @param maxPage | |
| 275 | + /** | |
| 276 | + * Render pagination. | |
| 277 | + * | |
| 278 | + * @param currentPage | |
| 279 | + * @param maxPage | |
| 280 | 280 | */ |
| 281 | 281 | const renderPagination = (currentPage, maxPage) => { |
| 282 | 282 | currentPage = parseInt(currentPage); |
| 283 | 283 | maxPage = parseInt(maxPage); |
| @@ -418,14 +418,15 @@ | ||
| 418 | 418 | !*** ./assets/src/js/admin/order/export_invoice.js ***! |
| 419 | 419 | \*****************************************************/ |
| 420 | 420 | (__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 421 | 421 | |
| 422 | +"use strict"; | |
| 422 | 423 | __webpack_require__.r(__webpack_exports__); |
| 423 | 424 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 424 | 425 | /* harmony export */ "default": () => (/* binding */ export_invoice) |
| 425 | 426 | /* harmony export */ }); |
| 426 | -/** | |
| 427 | - * Export invoice to PDF | |
| 427 | +/** | |
| 428 | + * Export invoice to PDF | |
| 428 | 429 | */ |
| 429 | 430 | function export_invoice() { |
| 430 | 431 | let html2pdf_obj, modal; |
| 431 | 432 | document.addEventListener('click', e => { |
| @@ -540,8 +541,212 @@ | ||
| 540 | 541 | } |
| 541 | 542 | |
| 542 | 543 | /***/ }, |
| 543 | 544 | |
| 545 | +/***/ "./assets/src/js/admin/order/refund-order.js" | |
| 546 | +/*!***************************************************!*\ | |
| 547 | + !*** ./assets/src/js/admin/order/refund-order.js ***! | |
| 548 | + \***************************************************/ | |
| 549 | +(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 550 | + | |
| 551 | +"use strict"; | |
| 552 | +__webpack_require__.r(__webpack_exports__); | |
| 553 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 554 | +/* harmony export */ RefundOrder: () => (/* binding */ RefundOrder), | |
| 555 | +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | |
| 556 | +/* harmony export */ }); | |
| 557 | +/* harmony import */ var sweetalert2__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! sweetalert2 */ "./node_modules/sweetalert2/dist/sweetalert2.all.js"); | |
| 558 | +/* harmony import */ var sweetalert2__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(sweetalert2__WEBPACK_IMPORTED_MODULE_0__); | |
| 559 | +/* harmony import */ var lpAssetsJsPath_lpToastify__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lpAssetsJsPath/lpToastify */ "./assets/src/js/lpToastify.js"); | |
| 560 | +/* harmony import */ var lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lpAssetsJsPath/utils.js */ "./assets/src/js/utils.js"); | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | +/** | |
| 566 | + * Handle admin approve/deny refund actions. | |
| 567 | + * | |
| 568 | + * @since 4.3.9 | |
| 569 | + * @version 1.0.0 | |
| 570 | + */ | |
| 571 | +class RefundOrder { | |
| 572 | + constructor() { | |
| 573 | + this.isRequesting = false; | |
| 574 | + this.isReloading = false; | |
| 575 | + } | |
| 576 | + static selectors = { | |
| 577 | + panel: '.order-data-refund-request', | |
| 578 | + action: '.lp-admin-refund-order-action' | |
| 579 | + }; | |
| 580 | + init() { | |
| 581 | + this.events(); | |
| 582 | + } | |
| 583 | + events() { | |
| 584 | + if (RefundOrder._loadedEvents) { | |
| 585 | + return; | |
| 586 | + } | |
| 587 | + RefundOrder._loadedEvents = this; | |
| 588 | + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_2__.eventHandlers('click', [{ | |
| 589 | + selector: RefundOrder.selectors.action, | |
| 590 | + class: this, | |
| 591 | + callBack: this.handleAction.name | |
| 592 | + }]); | |
| 593 | + } | |
| 594 | + getPanelData(panel) { | |
| 595 | + const orderTotal = parseFloat(panel.dataset.orderTotal || '0'); | |
| 596 | + return { | |
| 597 | + orderId: parseInt(panel.dataset.orderId || '0', 10), | |
| 598 | + orderTotal: Number.isNaN(orderTotal) ? 0 : orderTotal, | |
| 599 | + orderTotalFormatted: panel.dataset.orderTotalFormatted || '', | |
| 600 | + confirmTitle: panel.dataset.confirmTitle || 'Approve refund?', | |
| 601 | + confirmText: panel.dataset.confirmText || '', | |
| 602 | + messageLabel: panel.dataset.messageLabel || 'Message to payer', | |
| 603 | + messagePlaceholder: panel.dataset.messagePlaceholder || '', | |
| 604 | + amountLabel: panel.dataset.amountLabel || 'Refund amount', | |
| 605 | + amountInvalid: panel.dataset.amountInvalid || 'Invalid refund amount.', | |
| 606 | + confirmButton: panel.dataset.confirmButton || 'Approve Refund', | |
| 607 | + cancelButton: panel.dataset.cancelButton || 'Cancel' | |
| 608 | + }; | |
| 609 | + } | |
| 610 | + setLoadingState(panel, isLoading) { | |
| 611 | + panel.querySelectorAll(RefundOrder.selectors.action).forEach(button => { | |
| 612 | + button.disabled = isLoading; | |
| 613 | + }); | |
| 614 | + } | |
| 615 | + openApproveModal(data) { | |
| 616 | + const content = document.createElement('div'); | |
| 617 | + const messageLabel = document.createElement('label'); | |
| 618 | + const message = document.createElement('textarea'); | |
| 619 | + const amountLabel = document.createElement('label'); | |
| 620 | + const amount = document.createElement('input'); | |
| 621 | + content.className = 'lp-admin-refund-modal__form'; | |
| 622 | + if (data.confirmText) { | |
| 623 | + const confirmText = document.createElement('p'); | |
| 624 | + confirmText.className = 'lp-admin-refund-modal__description'; | |
| 625 | + confirmText.textContent = data.confirmText; | |
| 626 | + content.append(confirmText); | |
| 627 | + } | |
| 628 | + messageLabel.textContent = data.messageLabel; | |
| 629 | + messageLabel.htmlFor = 'lp-admin-refund-message'; | |
| 630 | + messageLabel.className = 'swal2-input-label'; | |
| 631 | + message.id = 'lp-admin-refund-message'; | |
| 632 | + message.className = 'swal2-textarea'; | |
| 633 | + message.placeholder = data.messagePlaceholder; | |
| 634 | + amountLabel.textContent = `${data.amountLabel} (${data.orderTotalFormatted})`; | |
| 635 | + amountLabel.htmlFor = 'lp-admin-refund-amount'; | |
| 636 | + amountLabel.className = 'swal2-input-label'; | |
| 637 | + amount.id = 'lp-admin-refund-amount'; | |
| 638 | + amount.className = 'swal2-input'; | |
| 639 | + amount.type = 'number'; | |
| 640 | + amount.min = '0.01'; | |
| 641 | + amount.max = data.orderTotal.toString(); | |
| 642 | + amount.step = '0.01'; | |
| 643 | + amount.value = data.orderTotal.toFixed(2); | |
| 644 | + content.append(messageLabel, message, amountLabel, amount); | |
| 645 | + return sweetalert2__WEBPACK_IMPORTED_MODULE_0___default().fire({ | |
| 646 | + icon: 'warning', | |
| 647 | + title: data.confirmTitle, | |
| 648 | + html: content, | |
| 649 | + showCancelButton: true, | |
| 650 | + confirmButtonText: data.confirmButton, | |
| 651 | + cancelButtonText: data.cancelButton, | |
| 652 | + focusConfirm: false, | |
| 653 | + customClass: { | |
| 654 | + popup: 'lp-admin-refund-modal', | |
| 655 | + htmlContainer: 'lp-admin-refund-modal__content', | |
| 656 | + actions: 'lp-admin-refund-modal__actions' | |
| 657 | + }, | |
| 658 | + preConfirm: () => { | |
| 659 | + const refundAmount = parseFloat(amount.value); | |
| 660 | + if (Number.isNaN(refundAmount) || refundAmount <= 0 || refundAmount > data.orderTotal) { | |
| 661 | + sweetalert2__WEBPACK_IMPORTED_MODULE_0___default().showValidationMessage(data.amountInvalid); | |
| 662 | + return false; | |
| 663 | + } | |
| 664 | + return { | |
| 665 | + note: message.value.trim(), | |
| 666 | + refundAmount | |
| 667 | + }; | |
| 668 | + } | |
| 669 | + }); | |
| 670 | + } | |
| 671 | + sendAction(actionButton, panel, refundAction, refundAmount = 0, note = '') { | |
| 672 | + const data = this.getPanelData(panel); | |
| 673 | + if (!data.orderId) { | |
| 674 | + lpAssetsJsPath_lpToastify__WEBPACK_IMPORTED_MODULE_1__.show('Invalid order.', 'error'); | |
| 675 | + return; | |
| 676 | + } | |
| 677 | + this.isRequesting = true; | |
| 678 | + this.setLoadingState(panel, true); | |
| 679 | + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_2__.lpSetLoadingEl(actionButton, 1); | |
| 680 | + window.lpAJAXG.fetchAJAX({ | |
| 681 | + action: 'admin_handle_request_refund', | |
| 682 | + order_id: data.orderId, | |
| 683 | + refund_action: refundAction, | |
| 684 | + refund_amount: refundAmount, | |
| 685 | + note | |
| 686 | + }, { | |
| 687 | + success: response => { | |
| 688 | + const { | |
| 689 | + status, | |
| 690 | + message, | |
| 691 | + data | |
| 692 | + } = response; | |
| 693 | + if (status !== 'success') { | |
| 694 | + throw new Error(message); | |
| 695 | + } | |
| 696 | + lpAssetsJsPath_lpToastify__WEBPACK_IMPORTED_MODULE_1__.show(message, 'success'); | |
| 697 | + this.isReloading = true; | |
| 698 | + window.setTimeout(() => window.location.reload(), 1200); | |
| 699 | + }, | |
| 700 | + error: error => { | |
| 701 | + const messageResponse = error?.message || error || 'Refund action failed.'; | |
| 702 | + lpAssetsJsPath_lpToastify__WEBPACK_IMPORTED_MODULE_1__.show(messageResponse, 'error'); | |
| 703 | + }, | |
| 704 | + completed: () => { | |
| 705 | + if (this.isReloading) { | |
| 706 | + return; | |
| 707 | + } | |
| 708 | + this.isRequesting = false; | |
| 709 | + this.setLoadingState(panel, false); | |
| 710 | + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_2__.lpSetLoadingEl(actionButton, 0); | |
| 711 | + } | |
| 712 | + }); | |
| 713 | + } | |
| 714 | + async handleAction(args) { | |
| 715 | + const { | |
| 716 | + e, | |
| 717 | + target | |
| 718 | + } = args; | |
| 719 | + e.preventDefault(); | |
| 720 | + const actionButton = target.closest(RefundOrder.selectors.action); | |
| 721 | + const panel = actionButton?.closest(RefundOrder.selectors.panel); | |
| 722 | + if (!actionButton || !panel || this.isRequesting) { | |
| 723 | + return; | |
| 724 | + } | |
| 725 | + const refundAction = actionButton.dataset.refundAction || ''; | |
| 726 | + let amount = ''; | |
| 727 | + let note = ''; | |
| 728 | + if ('reject' === refundAction) { | |
| 729 | + return this.sendAction(actionButton, panel, refundAction); | |
| 730 | + } | |
| 731 | + const result = await this.openApproveModal(this.getPanelData(panel)); | |
| 732 | + if (result.isConfirmed && result.value) { | |
| 733 | + amount = result.value.refundAmount; | |
| 734 | + note = result.value.note; | |
| 735 | + this.sendAction(actionButton, panel, refundAction, amount, note); | |
| 736 | + } | |
| 737 | + } | |
| 738 | +} | |
| 739 | +const refundOrder = () => { | |
| 740 | + const refundOrderHandle = new RefundOrder(); | |
| 741 | + lpAssetsJsPath_utils_js__WEBPACK_IMPORTED_MODULE_2__.lpOnElementReady(RefundOrder.selectors.action, () => { | |
| 742 | + refundOrderHandle.init(); | |
| 743 | + }); | |
| 744 | +}; | |
| 745 | +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (refundOrder); | |
| 746 | + | |
| 747 | +/***/ }, | |
| 748 | + | |
| 544 | 749 | /***/ "./assets/src/js/admin/utils-admin.js" |
| 545 | 750 | /*!********************************************!*\ |
| 546 | 751 | !*** ./assets/src/js/admin/utils-admin.js ***! |
| 547 | 752 | \********************************************/ |
| @@ -546,8 +751,9 @@ | ||
| 546 | 751 | !*** ./assets/src/js/admin/utils-admin.js ***! |
| 547 | 752 | \********************************************/ |
| 548 | 753 | (__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 549 | 754 | |
| 755 | +"use strict"; | |
| 550 | 756 | __webpack_require__.r(__webpack_exports__); |
| 551 | 757 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 552 | 758 | /* harmony export */ AdminUtilsFunctions: () => (/* binding */ AdminUtilsFunctions), |
| 553 | 759 | /* harmony export */ Api: () => (/* reexport safe */ _api_js__WEBPACK_IMPORTED_MODULE_2__["default"]), |
| @@ -555,13 +761,13 @@ | ||
| 555 | 761 | /* harmony export */ }); |
| 556 | 762 | /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils.js */ "./assets/src/js/utils.js"); |
| 557 | 763 | /* harmony import */ var tom_select__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! tom-select */ "./node_modules/tom-select/dist/esm/tom-select.complete.js"); |
| 558 | 764 | /* harmony import */ var _api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../api.js */ "./assets/src/js/api.js"); |
| 559 | -/** | |
| 560 | - * Library run on Admin | |
| 561 | - * | |
| 562 | - * @since 4.2.6.9 | |
| 563 | - * @version 1.0.1 | |
| 765 | +/** | |
| 766 | + * Library run on Admin | |
| 767 | + * | |
| 768 | + * @since 4.2.6.9 | |
| 769 | + * @version 1.0.1 | |
| 564 | 770 | */ |
| 565 | 771 | |
| 566 | 772 | |
| 567 | 773 | |
| @@ -601,26 +807,26 @@ | ||
| 601 | 807 | ...optionDefault, |
| 602 | 808 | ...options |
| 603 | 809 | }; |
| 604 | 810 | const items_selected = options.options; |
| 605 | - /*if ( options?.options?.length > 20 ) { | |
| 606 | - const chunkSize = 20; | |
| 607 | - const length = options.options.length; | |
| 608 | - let i = 0; | |
| 609 | - const chunkedOptions = { ...options }; | |
| 610 | - chunkedOptions.options = items_selected.slice( i, chunkSize ); | |
| 611 | - const tomSelect = new TomSelect( elTomSelect, chunkedOptions ); | |
| 612 | - i += chunkSize; | |
| 613 | - const interval = setInterval( () => { | |
| 614 | - if ( i > ( length - 1 ) ) { | |
| 615 | - clearInterval( interval ); | |
| 616 | - } | |
| 617 | - const optionsSlice = items_selected.slice( i, i + chunkSize ); | |
| 618 | - i += chunkSize; | |
| 619 | - tomSelect.addOptions( optionsSlice ); | |
| 620 | - tomSelect.setValue( options.items ); | |
| 621 | - }, 200 ); | |
| 622 | - return tomSelect; | |
| 811 | + /*if ( options?.options?.length > 20 ) { | |
| 812 | + const chunkSize = 20; | |
| 813 | + const length = options.options.length; | |
| 814 | + let i = 0; | |
| 815 | + const chunkedOptions = { ...options }; | |
| 816 | + chunkedOptions.options = items_selected.slice( i, chunkSize ); | |
| 817 | + const tomSelect = new TomSelect( elTomSelect, chunkedOptions ); | |
| 818 | + i += chunkSize; | |
| 819 | + const interval = setInterval( () => { | |
| 820 | + if ( i > ( length - 1 ) ) { | |
| 821 | + clearInterval( interval ); | |
| 822 | + } | |
| 823 | + const optionsSlice = items_selected.slice( i, i + chunkSize ); | |
| 824 | + i += chunkSize; | |
| 825 | + tomSelect.addOptions( optionsSlice ); | |
| 826 | + tomSelect.setValue( options.items ); | |
| 827 | + }, 200 ); | |
| 828 | + return tomSelect; | |
| 623 | 829 | }*/ |
| 624 | 830 | |
| 625 | 831 | return new tom_select__WEBPACK_IMPORTED_MODULE_1__["default"](elTomSelect, options); |
| 626 | 832 | }, |
| @@ -668,17 +874,18 @@ | ||
| 668 | 874 | !*** ./assets/src/js/api.js ***! |
| 669 | 875 | \******************************/ |
| 670 | 876 | (__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 671 | 877 | |
| 878 | +"use strict"; | |
| 672 | 879 | __webpack_require__.r(__webpack_exports__); |
| 673 | 880 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 674 | 881 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 675 | 882 | /* harmony export */ }); |
| 676 | -/** | |
| 677 | - * List API on backend | |
| 678 | - * | |
| 679 | - * @since 4.2.6 | |
| 680 | - * @version 1.0.2 | |
| 883 | +/** | |
| 884 | + * List API on backend | |
| 885 | + * | |
| 886 | + * @since 4.2.6 | |
| 887 | + * @version 1.0.2 | |
| 681 | 888 | */ |
| 682 | 889 | |
| 683 | 890 | const lplistAPI = {}; |
| 684 | 891 | let lp_rest_url; |
| @@ -684,12 +891,9 @@ | ||
| 684 | 891 | let lp_rest_url; |
| 685 | 892 | if ('undefined' !== typeof lpDataAdmin) { |
| 686 | 893 | lp_rest_url = lpDataAdmin.lp_rest_url; |
| 687 | 894 | lplistAPI.admin = { |
| 688 | - apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices', | |
| 689 | - apiAddons: lp_rest_url + 'lp/v1/addon/all', | |
| 690 | - apiAddonAction: lp_rest_url + 'lp/v1/addon/action-n', | |
| 691 | - apiAddonsPurchase: lp_rest_url + 'lp/v1/addon/info-addons-purchase', | |
| 895 | + // apiAdminNotice: lp_rest_url + 'lp/v1/admin/tools/admin-notices', | |
| 692 | 896 | apiSearchCourses: lp_rest_url + 'lp/v1/admin/tools/search-course', |
| 693 | 897 | apiSearchUsers: lp_rest_url + 'lp/v1/admin/tools/search-user', |
| 694 | 898 | apiAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/assign-user-course', |
| 695 | 899 | apiUnAssignUserCourse: lp_rest_url + 'lp/v1/admin/tools/unassign-user-course' |
| @@ -714,8 +918,62 @@ | ||
| 714 | 918 | /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lplistAPI); |
| 715 | 919 | |
| 716 | 920 | /***/ }, |
| 717 | 921 | |
| 922 | +/***/ "./assets/src/js/lpToastify.js" | |
| 923 | +/*!*************************************!*\ | |
| 924 | + !*** ./assets/src/js/lpToastify.js ***! | |
| 925 | + \*************************************/ | |
| 926 | +(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 927 | + | |
| 928 | +"use strict"; | |
| 929 | +__webpack_require__.r(__webpack_exports__); | |
| 930 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 931 | +/* harmony export */ show: () => (/* binding */ show) | |
| 932 | +/* harmony export */ }); | |
| 933 | +/* harmony import */ var toastify_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! toastify-js */ "./node_modules/toastify-js/src/toastify.js"); | |
| 934 | +/* harmony import */ var toastify_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(toastify_js__WEBPACK_IMPORTED_MODULE_0__); | |
| 935 | +/* harmony import */ var toastify_js_src_toastify_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! toastify-js/src/toastify.css */ "./node_modules/toastify-js/src/toastify.css"); | |
| 936 | +/** | |
| 937 | + * Utils functions | |
| 938 | + * | |
| 939 | + * @param url | |
| 940 | + * @param data | |
| 941 | + * @param functions | |
| 942 | + * @since 4.3.0 | |
| 943 | + * @version 1.0.0 | |
| 944 | + */ | |
| 945 | + | |
| 946 | + | |
| 947 | +const argsToastify = { | |
| 948 | + text: '', | |
| 949 | + gravity: lpData.toast.gravity, | |
| 950 | + // `top` or `bottom` | |
| 951 | + position: lpData.toast.position, | |
| 952 | + // `left`, `center` or `right` | |
| 953 | + className: `${lpData.toast.classPrefix}`, | |
| 954 | + close: lpData.toast.close == 1, | |
| 955 | + stopOnFocus: lpData.toast.stopOnFocus == 1, | |
| 956 | + duration: lpData.toast.duration | |
| 957 | +}; | |
| 958 | +const show = (message, status = 'success', argsCustom) => { | |
| 959 | + let args = argsToastify; | |
| 960 | + if (argsCustom) { | |
| 961 | + args = { | |
| 962 | + ...args, | |
| 963 | + ...argsCustom | |
| 964 | + }; | |
| 965 | + } | |
| 966 | + const toastify = new (toastify_js__WEBPACK_IMPORTED_MODULE_0___default())({ | |
| 967 | + ...args, | |
| 968 | + text: message, | |
| 969 | + className: `${lpData.toast.classPrefix} ${status}` | |
| 970 | + }); | |
| 971 | + toastify.showToast(); | |
| 972 | +}; | |
| 973 | + | |
| 974 | +/***/ }, | |
| 975 | + | |
| 718 | 976 | /***/ "./assets/src/js/utils.js" |
| 719 | 977 | /*!********************************!*\ |
| 720 | 978 | !*** ./assets/src/js/utils.js ***! |
| 721 | 979 | \********************************/ |
| @@ -720,12 +978,14 @@ | ||
| 720 | 978 | !*** ./assets/src/js/utils.js ***! |
| 721 | 979 | \********************************/ |
| 722 | 980 | (__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 723 | 981 | |
| 982 | +"use strict"; | |
| 724 | 983 | __webpack_require__.r(__webpack_exports__); |
| 725 | 984 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 726 | 985 | /* harmony export */ debounce: () => (/* binding */ debounce), |
| 727 | 986 | /* harmony export */ eventHandlers: () => (/* binding */ eventHandlers), |
| 987 | +/* harmony export */ fullScreenView: () => (/* binding */ fullScreenView), | |
| 728 | 988 | /* harmony export */ getDataOfForm: () => (/* binding */ getDataOfForm), |
| 729 | 989 | /* harmony export */ getFieldKeysOfForm: () => (/* binding */ getFieldKeysOfForm), |
| 730 | 990 | /* harmony export */ listenElementCreated: () => (/* binding */ listenElementCreated), |
| 731 | 991 | /* harmony export */ listenElementViewed: () => (/* binding */ listenElementViewed), |
| @@ -737,18 +997,19 @@ | ||
| 737 | 997 | /* harmony export */ lpOnElementReady: () => (/* binding */ lpOnElementReady), |
| 738 | 998 | /* harmony export */ lpSetLoadingEl: () => (/* binding */ lpSetLoadingEl), |
| 739 | 999 | /* harmony export */ lpShowHideEl: () => (/* binding */ lpShowHideEl), |
| 740 | 1000 | /* harmony export */ mergeDataWithDatForm: () => (/* binding */ mergeDataWithDatForm), |
| 741 | -/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse) | |
| 1001 | +/* harmony export */ toggleCollapse: () => (/* binding */ toggleCollapse), | |
| 1002 | +/* harmony export */ toggleEnable: () => (/* binding */ toggleEnable) | |
| 742 | 1003 | /* harmony export */ }); |
| 743 | -/** | |
| 744 | - * Utils functions | |
| 745 | - * | |
| 746 | - * @param url | |
| 747 | - * @param data | |
| 748 | - * @param functions | |
| 749 | - * @since 4.2.5.1 | |
| 750 | - * @version 1.0.6 | |
| 1004 | +/** | |
| 1005 | + * Utils functions | |
| 1006 | + * | |
| 1007 | + * @param url | |
| 1008 | + * @param data | |
| 1009 | + * @param functions | |
| 1010 | + * @since 4.2.5.1 | |
| 1011 | + * @version 1.0.7 | |
| 751 | 1012 | */ |
| 752 | 1013 | const lpClassName = { |
| 753 | 1014 | hidden: 'lp-hidden', |
| 754 | 1015 | loading: 'loading', |
| @@ -753,9 +1014,12 @@ | ||
| 753 | 1014 | hidden: 'lp-hidden', |
| 754 | 1015 | loading: 'loading', |
| 755 | 1016 | elCollapse: 'lp-collapse', |
| 756 | 1017 | elSectionToggle: '.lp-section-toggle', |
| 757 | - elTriggerToggle: '.lp-trigger-toggle' | |
| 1018 | + elTriggerToggle: '.lp-trigger-toggle', | |
| 1019 | + elBtnFullScreen: '.lp-btn-full-screen-view', | |
| 1020 | + elFullScreen: 'lp-full-screen-view', | |
| 1021 | + elBtnFullScreenClose: 'lp-full-screen-view__close' | |
| 758 | 1022 | }; |
| 759 | 1023 | const lpFetchAPI = (url, data = {}, functions = {}) => { |
| 760 | 1024 | if ('function' === typeof functions.before) { |
| 761 | 1025 | functions.before(); |
| @@ -777,12 +1041,12 @@ | ||
| 777 | 1041 | } |
| 778 | 1042 | }); |
| 779 | 1043 | }; |
| 780 | 1044 | |
| 781 | -/** | |
| 782 | - * Get current URL without params. | |
| 783 | - * | |
| 784 | - * @since 4.2.5.1 | |
| 1045 | +/** | |
| 1046 | + * Get current URL without params. | |
| 1047 | + * | |
| 1048 | + * @since 4.2.5.1 | |
| 785 | 1049 | */ |
| 786 | 1050 | const lpGetCurrentURLNoParam = () => { |
| 787 | 1051 | let currentUrl = window.location.href; |
| 788 | 1052 | const hasParams = currentUrl.includes('?'); |
| @@ -798,14 +1062,14 @@ | ||
| 798 | 1062 | }); |
| 799 | 1063 | return url; |
| 800 | 1064 | }; |
| 801 | 1065 | |
| 802 | -/** | |
| 803 | - * Listen element viewed. | |
| 804 | - * | |
| 805 | - * @param el | |
| 806 | - * @param callback | |
| 807 | - * @since 4.2.5.8 | |
| 1066 | +/** | |
| 1067 | + * Listen element viewed. | |
| 1068 | + * | |
| 1069 | + * @param el | |
| 1070 | + * @param callback | |
| 1071 | + * @since 4.2.5.8 | |
| 808 | 1072 | */ |
| 809 | 1073 | const listenElementViewed = (el, callback) => { |
| 810 | 1074 | const observerSeeItem = new IntersectionObserver(function (entries) { |
| 811 | 1075 | for (const entry of entries) { |
| @@ -816,13 +1080,13 @@ | ||
| 816 | 1080 | }); |
| 817 | 1081 | observerSeeItem.observe(el); |
| 818 | 1082 | }; |
| 819 | 1083 | |
| 820 | -/** | |
| 821 | - * Listen element created. | |
| 822 | - * | |
| 823 | - * @param callback | |
| 824 | - * @since 4.2.5.8 | |
| 1084 | +/** | |
| 1085 | + * Listen element created. | |
| 1086 | + * | |
| 1087 | + * @param callback | |
| 1088 | + * @since 4.2.5.8 | |
| 825 | 1089 | */ |
| 826 | 1090 | const listenElementCreated = callback => { |
| 827 | 1091 | const observerCreateItem = new MutationObserver(function (mutations) { |
| 828 | 1092 | mutations.forEach(function (mutation) { |
| @@ -841,14 +1105,14 @@ | ||
| 841 | 1105 | }); |
| 842 | 1106 | // End. |
| 843 | 1107 | }; |
| 844 | 1108 | |
| 845 | -/** | |
| 846 | - * Listen element created. | |
| 847 | - * | |
| 848 | - * @param selector | |
| 849 | - * @param callback | |
| 850 | - * @since 4.2.7.1 | |
| 1109 | +/** | |
| 1110 | + * Listen element created. | |
| 1111 | + * | |
| 1112 | + * @param selector | |
| 1113 | + * @param callback | |
| 1114 | + * @since 4.2.7.1 | |
| 851 | 1115 | */ |
| 852 | 1116 | const lpOnElementReady = (selector, callback) => { |
| 853 | 1117 | const element = document.querySelector(selector); |
| 854 | 1118 | if (element) { |
| @@ -989,17 +1253,17 @@ | ||
| 989 | 1253 | }; |
| 990 | 1254 | return dataHandle; |
| 991 | 1255 | }; |
| 992 | 1256 | |
| 993 | -/** | |
| 994 | - * Event trigger | |
| 995 | - * For each list of event handlers, listen event on document. | |
| 996 | - * | |
| 997 | - * eventName: 'click', 'change', ... | |
| 998 | - * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] | |
| 999 | - * | |
| 1000 | - * @param eventName | |
| 1001 | - * @param eventHandlers | |
| 1257 | +/** | |
| 1258 | + * Event trigger | |
| 1259 | + * For each list of event handlers, listen event on document. | |
| 1260 | + * | |
| 1261 | + * eventName: 'click', 'change', ... | |
| 1262 | + * eventHandlers = [ { selector: '.lp-button', callBack: function(){}, class: object } ] | |
| 1263 | + * | |
| 1264 | + * @param eventName | |
| 1265 | + * @param eventHandlers | |
| 1002 | 1266 | */ |
| 1003 | 1267 | const eventHandlers = (eventName, eventHandlers) => { |
| 1004 | 1268 | document.addEventListener(eventName, e => { |
| 1005 | 1269 | const target = e.target; |
| @@ -1040,32 +1304,32 @@ | ||
| 1040 | 1304 | }); |
| 1041 | 1305 | }); |
| 1042 | 1306 | }; |
| 1043 | 1307 | |
| 1044 | -/** | |
| 1045 | - * Debounce - delays function execution until after `wait` ms of inactivity. | |
| 1046 | - * | |
| 1047 | - * Each call resets the timer. Only the last call in a burst executes. | |
| 1048 | - * | |
| 1049 | - * USE CASES: | |
| 1050 | - * - Search inputs, form validation, window resize | |
| 1051 | - * - Multiple elements need independent timers | |
| 1052 | - * - When you need to call with different arguments | |
| 1053 | - * | |
| 1054 | - * EXAMPLES: | |
| 1055 | - * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); | |
| 1056 | - * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); | |
| 1057 | - * | |
| 1058 | - * const debouncedResize = debounce( recalculateLayout, 250 ); | |
| 1059 | - * window.addEventListener('resize', debouncedResize); | |
| 1060 | - * | |
| 1061 | - * ⚠️ Create ONCE outside event handlers, not inside. | |
| 1062 | - * | |
| 1063 | - * @param {Function} func - Function to debounce (can be anonymous) | |
| 1064 | - * @param {number} wait - Milliseconds to wait (default: 500) | |
| 1065 | - * @return {Function} Debounced wrapper function | |
| 1066 | - * @since 4.3.7 | |
| 1067 | - * @version 1.0.0 | |
| 1308 | +/** | |
| 1309 | + * Debounce - delays function execution until after `wait` ms of inactivity. | |
| 1310 | + * | |
| 1311 | + * Each call resets the timer. Only the last call in a burst executes. | |
| 1312 | + * | |
| 1313 | + * USE CASES: | |
| 1314 | + * - Search inputs, form validation, window resize | |
| 1315 | + * - Multiple elements need independent timers | |
| 1316 | + * - When you need to call with different arguments | |
| 1317 | + * | |
| 1318 | + * EXAMPLES: | |
| 1319 | + * const debouncedSearch = debounce( (query) => fetchResults(query), 300 ); | |
| 1320 | + * searchInput.addEventListener('input', (e) => debouncedSearch(e.target.value)); | |
| 1321 | + * | |
| 1322 | + * const debouncedResize = debounce( recalculateLayout, 250 ); | |
| 1323 | + * window.addEventListener('resize', debouncedResize); | |
| 1324 | + * | |
| 1325 | + * ⚠️ Create ONCE outside event handlers, not inside. | |
| 1326 | + * | |
| 1327 | + * @param {Function} func - Function to debounce (can be anonymous) | |
| 1328 | + * @param {number} wait - Milliseconds to wait (default: 500) | |
| 1329 | + * @return {Function} Debounced wrapper function | |
| 1330 | + * @since 4.3.7 | |
| 1331 | + * @version 1.0.0 | |
| 1068 | 1332 | */ |
| 1069 | 1333 | const debounce = (func, wait = 500) => { |
| 1070 | 1334 | let timer; |
| 1071 | 1335 | return args => { |
| @@ -1073,10 +1337,5954 @@ | ||
| 1073 | 1337 | timer = setTimeout(() => func(args), wait); |
| 1074 | 1338 | }; |
| 1075 | 1339 | }; |
| 1076 | 1340 | |
| 1341 | +/** | |
| 1342 | + * Initialize lp-toggle-enable components. | |
| 1343 | + * | |
| 1344 | + * Finds all `.lp-toggle-enable` elements and wires up toggle behavior. | |
| 1345 | + * Reads initial state from `data-enabled` attribute ("true"/"false"). | |
| 1346 | + * Calls `data-on-toggle` callback (if provided via options) on state change. | |
| 1347 | + * | |
| 1348 | + * HTML structure: | |
| 1349 | + * <label class="lp-toggle-enable" data-enabled="true"> | |
| 1350 | + * <input type="checkbox" class="lp-toggle-enable__input" /> | |
| 1351 | + * <span class="lp-toggle-enable__track"></span> | |
| 1352 | + * </label> | |
| 1353 | + * | |
| 1354 | + * @param {string} selector CSS selector for toggle elements (default: '.lp-toggle-enable') | |
| 1355 | + * @param {Function} onToggle Optional callback( el, isEnabled ) called on state change | |
| 1356 | + * @since 4.4.5 | |
| 1357 | + * @version 1.0.0 | |
| 1358 | + */ | |
| 1359 | +window.lpToggleEnableInit = 0; | |
| 1360 | +const toggleEnable = (onToggle = null) => { | |
| 1361 | + if (window.lpToggleEnableInit) { | |
| 1362 | + return; | |
| 1363 | + } | |
| 1364 | + window.lpToggleEnableInit = 1; | |
| 1365 | + const selector = '.lp-toggle-enable'; | |
| 1366 | + const updateUI = (toggle, isEnabled) => { | |
| 1367 | + toggle.classList.toggle('is-enabled', isEnabled); | |
| 1368 | + const input = toggle.querySelector('.lp-toggle-enable__input'); | |
| 1369 | + if (input) { | |
| 1370 | + input.checked = isEnabled; | |
| 1371 | + input.value = isEnabled ? '1' : '0'; | |
| 1372 | + } | |
| 1373 | + }; | |
| 1374 | + | |
| 1375 | + // Delegate click handling via eventHandlers. | |
| 1376 | + eventHandlers('click', [{ | |
| 1377 | + selector, | |
| 1378 | + callBack: args => { | |
| 1379 | + const { | |
| 1380 | + e, | |
| 1381 | + target | |
| 1382 | + } = args; | |
| 1383 | + const toggle = target.closest(selector); | |
| 1384 | + if (!toggle || toggle.classList.contains('is-disabled')) { | |
| 1385 | + return; | |
| 1386 | + } | |
| 1387 | + e.preventDefault(); | |
| 1388 | + const isEnabled = !toggle.classList.contains('is-enabled'); | |
| 1389 | + updateUI(toggle, isEnabled); | |
| 1390 | + if ('function' === typeof onToggle) { | |
| 1391 | + onToggle(toggle, isEnabled); | |
| 1392 | + } | |
| 1393 | + } | |
| 1394 | + }]); | |
| 1395 | +}; | |
| 1396 | + | |
| 1397 | +/** | |
| 1398 | + * Initialize custom fullscreen view buttons. | |
| 1399 | + * | |
| 1400 | + * Delegates clicks on `.lp-btn-full-screen-view` buttons to | |
| 1401 | + * `lpToggleFullscreenView`. Reads the `data-target` attribute to find the | |
| 1402 | + * target element. Falls back to the button's parent element when | |
| 1403 | + * `data-target` is not provided. | |
| 1404 | + * | |
| 1405 | + * @since 4.4.5 | |
| 1406 | + * @version 1.0.0 | |
| 1407 | + */ | |
| 1408 | +window.lpFullScreenViewInit = 0; | |
| 1409 | +const fullScreenView = () => { | |
| 1410 | + if (window.lpFullScreenViewInit) { | |
| 1411 | + return; | |
| 1412 | + } | |
| 1413 | + window.lpFullScreenViewInit = 1; | |
| 1414 | + let lastScrollY = 0; | |
| 1415 | + const lpToggleFullscreenView = (elTarget, elBtnFullScreen = null) => { | |
| 1416 | + const isFullscreen = elTarget.classList.contains(lpClassName.elFullScreen); | |
| 1417 | + if (isFullscreen) { | |
| 1418 | + elTarget.classList.remove(lpClassName.elFullScreen); | |
| 1419 | + document.documentElement.classList.remove('lp-full-screen-active'); | |
| 1420 | + window.scrollTo(0, lastScrollY); | |
| 1421 | + } else { | |
| 1422 | + lastScrollY = window.scrollY; | |
| 1423 | + elTarget.classList.add(lpClassName.elFullScreen); | |
| 1424 | + document.documentElement.classList.add('lp-full-screen-active'); | |
| 1425 | + } | |
| 1426 | + if (!isFullscreen) { | |
| 1427 | + if (!elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`)) { | |
| 1428 | + const closeButton = document.createElement('button'); | |
| 1429 | + closeButton.type = 'button'; | |
| 1430 | + closeButton.className = lpClassName.elBtnFullScreenClose; | |
| 1431 | + closeButton.setAttribute('aria-label', 'Close'); | |
| 1432 | + closeButton.innerHTML = lpData.i18n.closeButtonFullScreen || 'Close ×'; | |
| 1433 | + closeButton.addEventListener('click', e => { | |
| 1434 | + e.preventDefault(); | |
| 1435 | + lpToggleFullscreenView(elTarget); | |
| 1436 | + }); | |
| 1437 | + elTarget.appendChild(closeButton); | |
| 1438 | + } | |
| 1439 | + } else { | |
| 1440 | + const closeButton = elTarget.querySelector(`.${lpClassName.elBtnFullScreenClose}`); | |
| 1441 | + if (closeButton) { | |
| 1442 | + closeButton.remove(); | |
| 1443 | + } | |
| 1444 | + } | |
| 1445 | + }; | |
| 1446 | + eventHandlers('click', [{ | |
| 1447 | + selector: lpClassName.elBtnFullScreen, | |
| 1448 | + callBack: args => { | |
| 1449 | + const { | |
| 1450 | + e, | |
| 1451 | + target | |
| 1452 | + } = args; | |
| 1453 | + const elBtnFullScreen = target.closest(lpClassName.elBtnFullScreen); | |
| 1454 | + if (!elBtnFullScreen) { | |
| 1455 | + console.log('No full screen button found'); | |
| 1456 | + return; | |
| 1457 | + } | |
| 1458 | + e.preventDefault(); | |
| 1459 | + let elTarget = null; | |
| 1460 | + const targetSelector = elBtnFullScreen.dataset.targetFullscreen; | |
| 1461 | + console.log(targetSelector); | |
| 1462 | + if (targetSelector) { | |
| 1463 | + elTarget = document.querySelector(targetSelector); | |
| 1464 | + } | |
| 1465 | + if (!elTarget) { | |
| 1466 | + console.log('No target element found'); | |
| 1467 | + return; | |
| 1468 | + } | |
| 1469 | + lpToggleFullscreenView(elTarget, elBtnFullScreen); | |
| 1470 | + } | |
| 1471 | + }]); | |
| 1472 | +}; | |
| 1473 | + | |
| 1077 | 1474 | /***/ }, |
| 1078 | 1475 | |
| 1476 | +/***/ "./node_modules/css-loader/dist/cjs.js!./node_modules/toastify-js/src/toastify.css" | |
| 1477 | +/*!*****************************************************************************************!*\ | |
| 1478 | + !*** ./node_modules/css-loader/dist/cjs.js!./node_modules/toastify-js/src/toastify.css ***! | |
| 1479 | + \*****************************************************************************************/ | |
| 1480 | +(module, __webpack_exports__, __webpack_require__) { | |
| 1481 | + | |
| 1482 | +"use strict"; | |
| 1483 | +__webpack_require__.r(__webpack_exports__); | |
| 1484 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 1485 | +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | |
| 1486 | +/* harmony export */ }); | |
| 1487 | +/* harmony import */ var _css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../css-loader/dist/runtime/sourceMaps.js */ "./node_modules/css-loader/dist/runtime/sourceMaps.js"); | |
| 1488 | +/* harmony import */ var _css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0__); | |
| 1489 | +/* harmony import */ var _css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../css-loader/dist/runtime/api.js */ "./node_modules/css-loader/dist/runtime/api.js"); | |
| 1490 | +/* harmony import */ var _css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__); | |
| 1491 | +// Imports | |
| 1492 | + | |
| 1493 | + | |
| 1494 | +var ___CSS_LOADER_EXPORT___ = _css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1___default()((_css_loader_dist_runtime_sourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default())); | |
| 1495 | +// Module | |
| 1496 | +___CSS_LOADER_EXPORT___.push([module.id, `/*! | |
| 1497 | + * Toastify js 1.12.0 | |
| 1498 | + * https://github.com/apvarun/toastify-js | |
| 1499 | + * @license MIT licensed | |
| 1500 | + * | |
| 1501 | + * Copyright (C) 2018 Varun A P | |
| 1502 | + */ | |
| 1503 | + | |
| 1504 | +.toastify { | |
| 1505 | + padding: 12px 20px; | |
| 1506 | + color: #ffffff; | |
| 1507 | + display: inline-block; | |
| 1508 | + box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.12), 0 10px 36px -4px rgba(77, 96, 232, 0.3); | |
| 1509 | + background: -webkit-linear-gradient(315deg, #73a5ff, #5477f5); | |
| 1510 | + background: linear-gradient(135deg, #73a5ff, #5477f5); | |
| 1511 | + position: fixed; | |
| 1512 | + opacity: 0; | |
| 1513 | + transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1); | |
| 1514 | + border-radius: 2px; | |
| 1515 | + cursor: pointer; | |
| 1516 | + text-decoration: none; | |
| 1517 | + max-width: calc(50% - 20px); | |
| 1518 | + z-index: 2147483647; | |
| 1519 | +} | |
| 1520 | + | |
| 1521 | +.toastify.on { | |
| 1522 | + opacity: 1; | |
| 1523 | +} | |
| 1524 | + | |
| 1525 | +.toast-close { | |
| 1526 | + background: transparent; | |
| 1527 | + border: 0; | |
| 1528 | + color: white; | |
| 1529 | + cursor: pointer; | |
| 1530 | + font-family: inherit; | |
| 1531 | + font-size: 1em; | |
| 1532 | + opacity: 0.4; | |
| 1533 | + padding: 0 5px; | |
| 1534 | +} | |
| 1535 | + | |
| 1536 | +.toastify-right { | |
| 1537 | + right: 15px; | |
| 1538 | +} | |
| 1539 | + | |
| 1540 | +.toastify-left { | |
| 1541 | + left: 15px; | |
| 1542 | +} | |
| 1543 | + | |
| 1544 | +.toastify-top { | |
| 1545 | + top: -150px; | |
| 1546 | +} | |
| 1547 | + | |
| 1548 | +.toastify-bottom { | |
| 1549 | + bottom: -150px; | |
| 1550 | +} | |
| 1551 | + | |
| 1552 | +.toastify-rounded { | |
| 1553 | + border-radius: 25px; | |
| 1554 | +} | |
| 1555 | + | |
| 1556 | +.toastify-avatar { | |
| 1557 | + width: 1.5em; | |
| 1558 | + height: 1.5em; | |
| 1559 | + margin: -7px 5px; | |
| 1560 | + border-radius: 2px; | |
| 1561 | +} | |
| 1562 | + | |
| 1563 | +.toastify-center { | |
| 1564 | + margin-left: auto; | |
| 1565 | + margin-right: auto; | |
| 1566 | + left: 0; | |
| 1567 | + right: 0; | |
| 1568 | + max-width: fit-content; | |
| 1569 | + max-width: -moz-fit-content; | |
| 1570 | +} | |
| 1571 | + | |
| 1572 | +@media only screen and (max-width: 360px) { | |
| 1573 | + .toastify-right, .toastify-left { | |
| 1574 | + margin-left: auto; | |
| 1575 | + margin-right: auto; | |
| 1576 | + left: 0; | |
| 1577 | + right: 0; | |
| 1578 | + max-width: fit-content; | |
| 1579 | + } | |
| 1580 | +} | |
| 1581 | +`, "",{"version":3,"sources":["webpack://./node_modules/toastify-js/src/toastify.css"],"names":[],"mappings":"AAAA;;;;;;EAME;;AAEF;IACI,kBAAkB;IAClB,cAAc;IACd,qBAAqB;IACrB,uFAAuF;IACvF,6DAA6D;IAC7D,qDAAqD;IACrD,eAAe;IACf,UAAU;IACV,wDAAwD;IACxD,kBAAkB;IAClB,eAAe;IACf,qBAAqB;IACrB,2BAA2B;IAC3B,mBAAmB;AACvB;;AAEA;IACI,UAAU;AACd;;AAEA;IACI,uBAAuB;IACvB,SAAS;IACT,YAAY;IACZ,eAAe;IACf,oBAAoB;IACpB,cAAc;IACd,YAAY;IACZ,cAAc;AAClB;;AAEA;IACI,WAAW;AACf;;AAEA;IACI,UAAU;AACd;;AAEA;IACI,WAAW;AACf;;AAEA;IACI,cAAc;AAClB;;AAEA;IACI,mBAAmB;AACvB;;AAEA;IACI,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,kBAAkB;AACtB;;AAEA;IACI,iBAAiB;IACjB,kBAAkB;IAClB,OAAO;IACP,QAAQ;IACR,sBAAsB;IACtB,2BAA2B;AAC/B;;AAEA;IACI;QACI,iBAAiB;QACjB,kBAAkB;QAClB,OAAO;QACP,QAAQ;QACR,sBAAsB;IAC1B;AACJ","sourcesContent":["/*!\n * Toastify js 1.12.0\n * https://github.com/apvarun/toastify-js\n * @license MIT licensed\n *\n * Copyright (C) 2018 Varun A P\n */\n\n.toastify {\n padding: 12px 20px;\n color: #ffffff;\n display: inline-block;\n box-shadow: 0 3px 6px -1px rgba(0, 0, 0, 0.12), 0 10px 36px -4px rgba(77, 96, 232, 0.3);\n background: -webkit-linear-gradient(315deg, #73a5ff, #5477f5);\n background: linear-gradient(135deg, #73a5ff, #5477f5);\n position: fixed;\n opacity: 0;\n transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1);\n border-radius: 2px;\n cursor: pointer;\n text-decoration: none;\n max-width: calc(50% - 20px);\n z-index: 2147483647;\n}\n\n.toastify.on {\n opacity: 1;\n}\n\n.toast-close {\n background: transparent;\n border: 0;\n color: white;\n cursor: pointer;\n font-family: inherit;\n font-size: 1em;\n opacity: 0.4;\n padding: 0 5px;\n}\n\n.toastify-right {\n right: 15px;\n}\n\n.toastify-left {\n left: 15px;\n}\n\n.toastify-top {\n top: -150px;\n}\n\n.toastify-bottom {\n bottom: -150px;\n}\n\n.toastify-rounded {\n border-radius: 25px;\n}\n\n.toastify-avatar {\n width: 1.5em;\n height: 1.5em;\n margin: -7px 5px;\n border-radius: 2px;\n}\n\n.toastify-center {\n margin-left: auto;\n margin-right: auto;\n left: 0;\n right: 0;\n max-width: fit-content;\n max-width: -moz-fit-content;\n}\n\n@media only screen and (max-width: 360px) {\n .toastify-right, .toastify-left {\n margin-left: auto;\n margin-right: auto;\n left: 0;\n right: 0;\n max-width: fit-content;\n }\n}\n"],"sourceRoot":""}]); | |
| 1582 | +// Exports | |
| 1583 | +/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (___CSS_LOADER_EXPORT___); | |
| 1584 | + | |
| 1585 | + | |
| 1586 | +/***/ }, | |
| 1587 | + | |
| 1588 | +/***/ "./node_modules/css-loader/dist/runtime/api.js" | |
| 1589 | +/*!*****************************************************!*\ | |
| 1590 | + !*** ./node_modules/css-loader/dist/runtime/api.js ***! | |
| 1591 | + \*****************************************************/ | |
| 1592 | +(module) { | |
| 1593 | + | |
| 1594 | +"use strict"; | |
| 1595 | + | |
| 1596 | + | |
| 1597 | +/* | |
| 1598 | + MIT License http://www.opensource.org/licenses/mit-license.php | |
| 1599 | + Author Tobias Koppers @sokra | |
| 1600 | +*/ | |
| 1601 | +module.exports = function (cssWithMappingToString) { | |
| 1602 | + var list = []; | |
| 1603 | + | |
| 1604 | + // return the list of modules as css string | |
| 1605 | + list.toString = function toString() { | |
| 1606 | + return this.map(function (item) { | |
| 1607 | + var content = ""; | |
| 1608 | + var needLayer = typeof item[5] !== "undefined"; | |
| 1609 | + if (item[4]) { | |
| 1610 | + content += "@supports (".concat(item[4], ") {"); | |
| 1611 | + } | |
| 1612 | + if (item[2]) { | |
| 1613 | + content += "@media ".concat(item[2], " {"); | |
| 1614 | + } | |
| 1615 | + if (needLayer) { | |
| 1616 | + content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {"); | |
| 1617 | + } | |
| 1618 | + content += cssWithMappingToString(item); | |
| 1619 | + if (needLayer) { | |
| 1620 | + content += "}"; | |
| 1621 | + } | |
| 1622 | + if (item[2]) { | |
| 1623 | + content += "}"; | |
| 1624 | + } | |
| 1625 | + if (item[4]) { | |
| 1626 | + content += "}"; | |
| 1627 | + } | |
| 1628 | + return content; | |
| 1629 | + }).join(""); | |
| 1630 | + }; | |
| 1631 | + | |
| 1632 | + // import a list of modules into the list | |
| 1633 | + list.i = function i(modules, media, dedupe, supports, layer) { | |
| 1634 | + if (typeof modules === "string") { | |
| 1635 | + modules = [[null, modules, undefined]]; | |
| 1636 | + } | |
| 1637 | + var alreadyImportedModules = {}; | |
| 1638 | + if (dedupe) { | |
| 1639 | + for (var k = 0; k < this.length; k++) { | |
| 1640 | + var id = this[k][0]; | |
| 1641 | + if (id != null) { | |
| 1642 | + alreadyImportedModules[id] = true; | |
| 1643 | + } | |
| 1644 | + } | |
| 1645 | + } | |
| 1646 | + for (var _k = 0; _k < modules.length; _k++) { | |
| 1647 | + var item = [].concat(modules[_k]); | |
| 1648 | + if (dedupe && alreadyImportedModules[item[0]]) { | |
| 1649 | + continue; | |
| 1650 | + } | |
| 1651 | + if (typeof layer !== "undefined") { | |
| 1652 | + if (typeof item[5] === "undefined") { | |
| 1653 | + item[5] = layer; | |
| 1654 | + } else { | |
| 1655 | + item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}"); | |
| 1656 | + item[5] = layer; | |
| 1657 | + } | |
| 1658 | + } | |
| 1659 | + if (media) { | |
| 1660 | + if (!item[2]) { | |
| 1661 | + item[2] = media; | |
| 1662 | + } else { | |
| 1663 | + item[1] = "@media ".concat(item[2], " {").concat(item[1], "}"); | |
| 1664 | + item[2] = media; | |
| 1665 | + } | |
| 1666 | + } | |
| 1667 | + if (supports) { | |
| 1668 | + if (!item[4]) { | |
| 1669 | + item[4] = "".concat(supports); | |
| 1670 | + } else { | |
| 1671 | + item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}"); | |
| 1672 | + item[4] = supports; | |
| 1673 | + } | |
| 1674 | + } | |
| 1675 | + list.push(item); | |
| 1676 | + } | |
| 1677 | + }; | |
| 1678 | + return list; | |
| 1679 | +}; | |
| 1680 | + | |
| 1681 | +/***/ }, | |
| 1682 | + | |
| 1683 | +/***/ "./node_modules/css-loader/dist/runtime/sourceMaps.js" | |
| 1684 | +/*!************************************************************!*\ | |
| 1685 | + !*** ./node_modules/css-loader/dist/runtime/sourceMaps.js ***! | |
| 1686 | + \************************************************************/ | |
| 1687 | +(module) { | |
| 1688 | + | |
| 1689 | +"use strict"; | |
| 1690 | + | |
| 1691 | + | |
| 1692 | +module.exports = function (item) { | |
| 1693 | + var content = item[1]; | |
| 1694 | + var cssMapping = item[3]; | |
| 1695 | + if (!cssMapping) { | |
| 1696 | + return content; | |
| 1697 | + } | |
| 1698 | + if (typeof btoa === "function") { | |
| 1699 | + var base64 = btoa(unescape(encodeURIComponent(JSON.stringify(cssMapping)))); | |
| 1700 | + var data = "sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(base64); | |
| 1701 | + var sourceMapping = "/*# ".concat(data, " */"); | |
| 1702 | + return [content].concat([sourceMapping]).join("\n"); | |
| 1703 | + } | |
| 1704 | + return [content].join("\n"); | |
| 1705 | +}; | |
| 1706 | + | |
| 1707 | +/***/ }, | |
| 1708 | + | |
| 1709 | +/***/ "./node_modules/toastify-js/src/toastify.css" | |
| 1710 | +/*!***************************************************!*\ | |
| 1711 | + !*** ./node_modules/toastify-js/src/toastify.css ***! | |
| 1712 | + \***************************************************/ | |
| 1713 | +(__unused_webpack_module, __webpack_exports__, __webpack_require__) { | |
| 1714 | + | |
| 1715 | +"use strict"; | |
| 1716 | +__webpack_require__.r(__webpack_exports__); | |
| 1717 | +/* harmony export */ __webpack_require__.d(__webpack_exports__, { | |
| 1718 | +/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) | |
| 1719 | +/* harmony export */ }); | |
| 1720 | +/* harmony import */ var _style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! !../../style-loader/dist/runtime/injectStylesIntoStyleTag.js */ "./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js"); | |
| 1721 | +/* harmony import */ var _style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0__); | |
| 1722 | +/* harmony import */ var _style_loader_dist_runtime_styleDomAPI_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! !../../style-loader/dist/runtime/styleDomAPI.js */ "./node_modules/style-loader/dist/runtime/styleDomAPI.js"); | |
| 1723 | +/* harmony import */ var _style_loader_dist_runtime_styleDomAPI_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_runtime_styleDomAPI_js__WEBPACK_IMPORTED_MODULE_1__); | |
| 1724 | +/* harmony import */ var _style_loader_dist_runtime_insertBySelector_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! !../../style-loader/dist/runtime/insertBySelector.js */ "./node_modules/style-loader/dist/runtime/insertBySelector.js"); | |
| 1725 | +/* harmony import */ var _style_loader_dist_runtime_insertBySelector_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_runtime_insertBySelector_js__WEBPACK_IMPORTED_MODULE_2__); | |
| 1726 | +/* harmony import */ var _style_loader_dist_runtime_setAttributesWithoutAttributes_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! !../../style-loader/dist/runtime/setAttributesWithoutAttributes.js */ "./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js"); | |
| 1727 | +/* harmony import */ var _style_loader_dist_runtime_setAttributesWithoutAttributes_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_runtime_setAttributesWithoutAttributes_js__WEBPACK_IMPORTED_MODULE_3__); | |
| 1728 | +/* harmony import */ var _style_loader_dist_runtime_insertStyleElement_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! !../../style-loader/dist/runtime/insertStyleElement.js */ "./node_modules/style-loader/dist/runtime/insertStyleElement.js"); | |
| 1729 | +/* harmony import */ var _style_loader_dist_runtime_insertStyleElement_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_runtime_insertStyleElement_js__WEBPACK_IMPORTED_MODULE_4__); | |
| 1730 | +/* harmony import */ var _style_loader_dist_runtime_styleTagTransform_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! !../../style-loader/dist/runtime/styleTagTransform.js */ "./node_modules/style-loader/dist/runtime/styleTagTransform.js"); | |
| 1731 | +/* harmony import */ var _style_loader_dist_runtime_styleTagTransform_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_style_loader_dist_runtime_styleTagTransform_js__WEBPACK_IMPORTED_MODULE_5__); | |
| 1732 | +/* harmony import */ var _css_loader_dist_cjs_js_toastify_css__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! !!../../css-loader/dist/cjs.js!./toastify.css */ "./node_modules/css-loader/dist/cjs.js!./node_modules/toastify-js/src/toastify.css"); | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | +var options = {}; | |
| 1745 | + | |
| 1746 | +options.styleTagTransform = (_style_loader_dist_runtime_styleTagTransform_js__WEBPACK_IMPORTED_MODULE_5___default()); | |
| 1747 | +options.setAttributes = (_style_loader_dist_runtime_setAttributesWithoutAttributes_js__WEBPACK_IMPORTED_MODULE_3___default()); | |
| 1748 | + | |
| 1749 | + options.insert = _style_loader_dist_runtime_insertBySelector_js__WEBPACK_IMPORTED_MODULE_2___default().bind(null, "head"); | |
| 1750 | + | |
| 1751 | +options.domAPI = (_style_loader_dist_runtime_styleDomAPI_js__WEBPACK_IMPORTED_MODULE_1___default()); | |
| 1752 | +options.insertStyleElement = (_style_loader_dist_runtime_insertStyleElement_js__WEBPACK_IMPORTED_MODULE_4___default()); | |
| 1753 | + | |
| 1754 | +var update = _style_loader_dist_runtime_injectStylesIntoStyleTag_js__WEBPACK_IMPORTED_MODULE_0___default()(_css_loader_dist_cjs_js_toastify_css__WEBPACK_IMPORTED_MODULE_6__["default"], options); | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_css_loader_dist_cjs_js_toastify_css__WEBPACK_IMPORTED_MODULE_6__["default"] && _css_loader_dist_cjs_js_toastify_css__WEBPACK_IMPORTED_MODULE_6__["default"].locals ? _css_loader_dist_cjs_js_toastify_css__WEBPACK_IMPORTED_MODULE_6__["default"].locals : undefined); | |
| 1760 | + | |
| 1761 | + | |
| 1762 | +/***/ }, | |
| 1763 | + | |
| 1764 | +/***/ "./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js" | |
| 1765 | +/*!****************************************************************************!*\ | |
| 1766 | + !*** ./node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js ***! | |
| 1767 | + \****************************************************************************/ | |
| 1768 | +(module) { | |
| 1769 | + | |
| 1770 | +"use strict"; | |
| 1771 | + | |
| 1772 | + | |
| 1773 | +var stylesInDOM = []; | |
| 1774 | +function getIndexByIdentifier(identifier) { | |
| 1775 | + var result = -1; | |
| 1776 | + for (var i = 0; i < stylesInDOM.length; i++) { | |
| 1777 | + if (stylesInDOM[i].identifier === identifier) { | |
| 1778 | + result = i; | |
| 1779 | + break; | |
| 1780 | + } | |
| 1781 | + } | |
| 1782 | + return result; | |
| 1783 | +} | |
| 1784 | +function modulesToDom(list, options) { | |
| 1785 | + var idCountMap = {}; | |
| 1786 | + var identifiers = []; | |
| 1787 | + for (var i = 0; i < list.length; i++) { | |
| 1788 | + var item = list[i]; | |
| 1789 | + var id = options.base ? item[0] + options.base : item[0]; | |
| 1790 | + var count = idCountMap[id] || 0; | |
| 1791 | + var identifier = "".concat(id, " ").concat(count); | |
| 1792 | + idCountMap[id] = count + 1; | |
| 1793 | + var indexByIdentifier = getIndexByIdentifier(identifier); | |
| 1794 | + var obj = { | |
| 1795 | + css: item[1], | |
| 1796 | + media: item[2], | |
| 1797 | + sourceMap: item[3], | |
| 1798 | + supports: item[4], | |
| 1799 | + layer: item[5] | |
| 1800 | + }; | |
| 1801 | + if (indexByIdentifier !== -1) { | |
| 1802 | + stylesInDOM[indexByIdentifier].references++; | |
| 1803 | + stylesInDOM[indexByIdentifier].updater(obj); | |
| 1804 | + } else { | |
| 1805 | + var updater = addElementStyle(obj, options); | |
| 1806 | + options.byIndex = i; | |
| 1807 | + stylesInDOM.splice(i, 0, { | |
| 1808 | + identifier: identifier, | |
| 1809 | + updater: updater, | |
| 1810 | + references: 1 | |
| 1811 | + }); | |
| 1812 | + } | |
| 1813 | + identifiers.push(identifier); | |
| 1814 | + } | |
| 1815 | + return identifiers; | |
| 1816 | +} | |
| 1817 | +function addElementStyle(obj, options) { | |
| 1818 | + var api = options.domAPI(options); | |
| 1819 | + api.update(obj); | |
| 1820 | + var updater = function updater(newObj) { | |
| 1821 | + if (newObj) { | |
| 1822 | + if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap && newObj.supports === obj.supports && newObj.layer === obj.layer) { | |
| 1823 | + return; | |
| 1824 | + } | |
| 1825 | + api.update(obj = newObj); | |
| 1826 | + } else { | |
| 1827 | + api.remove(); | |
| 1828 | + } | |
| 1829 | + }; | |
| 1830 | + return updater; | |
| 1831 | +} | |
| 1832 | +module.exports = function (list, options) { | |
| 1833 | + options = options || {}; | |
| 1834 | + list = list || []; | |
| 1835 | + var lastIdentifiers = modulesToDom(list, options); | |
| 1836 | + return function update(newList) { | |
| 1837 | + newList = newList || []; | |
| 1838 | + for (var i = 0; i < lastIdentifiers.length; i++) { | |
| 1839 | + var identifier = lastIdentifiers[i]; | |
| 1840 | + var index = getIndexByIdentifier(identifier); | |
| 1841 | + stylesInDOM[index].references--; | |
| 1842 | + } | |
| 1843 | + var newLastIdentifiers = modulesToDom(newList, options); | |
| 1844 | + for (var _i = 0; _i < lastIdentifiers.length; _i++) { | |
| 1845 | + var _identifier = lastIdentifiers[_i]; | |
| 1846 | + var _index = getIndexByIdentifier(_identifier); | |
| 1847 | + if (stylesInDOM[_index].references === 0) { | |
| 1848 | + stylesInDOM[_index].updater(); | |
| 1849 | + stylesInDOM.splice(_index, 1); | |
| 1850 | + } | |
| 1851 | + } | |
| 1852 | + lastIdentifiers = newLastIdentifiers; | |
| 1853 | + }; | |
| 1854 | +}; | |
| 1855 | + | |
| 1856 | +/***/ }, | |
| 1857 | + | |
| 1858 | +/***/ "./node_modules/style-loader/dist/runtime/insertBySelector.js" | |
| 1859 | +/*!********************************************************************!*\ | |
| 1860 | + !*** ./node_modules/style-loader/dist/runtime/insertBySelector.js ***! | |
| 1861 | + \********************************************************************/ | |
| 1862 | +(module) { | |
| 1863 | + | |
| 1864 | +"use strict"; | |
| 1865 | + | |
| 1866 | + | |
| 1867 | +var memo = {}; | |
| 1868 | + | |
| 1869 | +/* istanbul ignore next */ | |
| 1870 | +function getTarget(target) { | |
| 1871 | + if (typeof memo[target] === "undefined") { | |
| 1872 | + var styleTarget = document.querySelector(target); | |
| 1873 | + | |
| 1874 | + // Special case to return head of iframe instead of iframe itself | |
| 1875 | + if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) { | |
| 1876 | + try { | |
| 1877 | + // This will throw an exception if access to iframe is blocked | |
| 1878 | + // due to cross-origin restrictions | |
| 1879 | + styleTarget = styleTarget.contentDocument.head; | |
| 1880 | + } catch (e) { | |
| 1881 | + // istanbul ignore next | |
| 1882 | + styleTarget = null; | |
| 1883 | + } | |
| 1884 | + } | |
| 1885 | + memo[target] = styleTarget; | |
| 1886 | + } | |
| 1887 | + return memo[target]; | |
| 1888 | +} | |
| 1889 | + | |
| 1890 | +/* istanbul ignore next */ | |
| 1891 | +function insertBySelector(insert, style) { | |
| 1892 | + var target = getTarget(insert); | |
| 1893 | + if (!target) { | |
| 1894 | + throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid."); | |
| 1895 | + } | |
| 1896 | + target.appendChild(style); | |
| 1897 | +} | |
| 1898 | +module.exports = insertBySelector; | |
| 1899 | + | |
| 1900 | +/***/ }, | |
| 1901 | + | |
| 1902 | +/***/ "./node_modules/style-loader/dist/runtime/insertStyleElement.js" | |
| 1903 | +/*!**********************************************************************!*\ | |
| 1904 | + !*** ./node_modules/style-loader/dist/runtime/insertStyleElement.js ***! | |
| 1905 | + \**********************************************************************/ | |
| 1906 | +(module) { | |
| 1907 | + | |
| 1908 | +"use strict"; | |
| 1909 | + | |
| 1910 | + | |
| 1911 | +/* istanbul ignore next */ | |
| 1912 | +function insertStyleElement(options) { | |
| 1913 | + var element = document.createElement("style"); | |
| 1914 | + options.setAttributes(element, options.attributes); | |
| 1915 | + options.insert(element, options.options); | |
| 1916 | + return element; | |
| 1917 | +} | |
| 1918 | +module.exports = insertStyleElement; | |
| 1919 | + | |
| 1920 | +/***/ }, | |
| 1921 | + | |
| 1922 | +/***/ "./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js" | |
| 1923 | +/*!**********************************************************************************!*\ | |
| 1924 | + !*** ./node_modules/style-loader/dist/runtime/setAttributesWithoutAttributes.js ***! | |
| 1925 | + \**********************************************************************************/ | |
| 1926 | +(module, __unused_webpack_exports, __webpack_require__) { | |
| 1927 | + | |
| 1928 | +"use strict"; | |
| 1929 | + | |
| 1930 | + | |
| 1931 | +/* istanbul ignore next */ | |
| 1932 | +function setAttributesWithoutAttributes(styleElement) { | |
| 1933 | + var nonce = true ? __webpack_require__.nc : 0; | |
| 1934 | + if (nonce) { | |
| 1935 | + styleElement.setAttribute("nonce", nonce); | |
| 1936 | + } | |
| 1937 | +} | |
| 1938 | +module.exports = setAttributesWithoutAttributes; | |
| 1939 | + | |
| 1940 | +/***/ }, | |
| 1941 | + | |
| 1942 | +/***/ "./node_modules/style-loader/dist/runtime/styleDomAPI.js" | |
| 1943 | +/*!***************************************************************!*\ | |
| 1944 | + !*** ./node_modules/style-loader/dist/runtime/styleDomAPI.js ***! | |
| 1945 | + \***************************************************************/ | |
| 1946 | +(module) { | |
| 1947 | + | |
| 1948 | +"use strict"; | |
| 1949 | + | |
| 1950 | + | |
| 1951 | +/* istanbul ignore next */ | |
| 1952 | +function apply(styleElement, options, obj) { | |
| 1953 | + var css = ""; | |
| 1954 | + if (obj.supports) { | |
| 1955 | + css += "@supports (".concat(obj.supports, ") {"); | |
| 1956 | + } | |
| 1957 | + if (obj.media) { | |
| 1958 | + css += "@media ".concat(obj.media, " {"); | |
| 1959 | + } | |
| 1960 | + var needLayer = typeof obj.layer !== "undefined"; | |
| 1961 | + if (needLayer) { | |
| 1962 | + css += "@layer".concat(obj.layer.length > 0 ? " ".concat(obj.layer) : "", " {"); | |
| 1963 | + } | |
| 1964 | + css += obj.css; | |
| 1965 | + if (needLayer) { | |
| 1966 | + css += "}"; | |
| 1967 | + } | |
| 1968 | + if (obj.media) { | |
| 1969 | + css += "}"; | |
| 1970 | + } | |
| 1971 | + if (obj.supports) { | |
| 1972 | + css += "}"; | |
| 1973 | + } | |
| 1974 | + var sourceMap = obj.sourceMap; | |
| 1975 | + if (sourceMap && typeof btoa !== "undefined") { | |
| 1976 | + css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */"); | |
| 1977 | + } | |
| 1978 | + | |
| 1979 | + // For old IE | |
| 1980 | + /* istanbul ignore if */ | |
| 1981 | + options.styleTagTransform(css, styleElement, options.options); | |
| 1982 | +} | |
| 1983 | +function removeStyleElement(styleElement) { | |
| 1984 | + // istanbul ignore if | |
| 1985 | + if (styleElement.parentNode === null) { | |
| 1986 | + return false; | |
| 1987 | + } | |
| 1988 | + styleElement.parentNode.removeChild(styleElement); | |
| 1989 | +} | |
| 1990 | + | |
| 1991 | +/* istanbul ignore next */ | |
| 1992 | +function domAPI(options) { | |
| 1993 | + if (typeof document === "undefined") { | |
| 1994 | + return { | |
| 1995 | + update: function update() {}, | |
| 1996 | + remove: function remove() {} | |
| 1997 | + }; | |
| 1998 | + } | |
| 1999 | + var styleElement = options.insertStyleElement(options); | |
| 2000 | + return { | |
| 2001 | + update: function update(obj) { | |
| 2002 | + apply(styleElement, options, obj); | |
| 2003 | + }, | |
| 2004 | + remove: function remove() { | |
| 2005 | + removeStyleElement(styleElement); | |
| 2006 | + } | |
| 2007 | + }; | |
| 2008 | +} | |
| 2009 | +module.exports = domAPI; | |
| 2010 | + | |
| 2011 | +/***/ }, | |
| 2012 | + | |
| 2013 | +/***/ "./node_modules/style-loader/dist/runtime/styleTagTransform.js" | |
| 2014 | +/*!*********************************************************************!*\ | |
| 2015 | + !*** ./node_modules/style-loader/dist/runtime/styleTagTransform.js ***! | |
| 2016 | + \*********************************************************************/ | |
| 2017 | +(module) { | |
| 2018 | + | |
| 2019 | +"use strict"; | |
| 2020 | + | |
| 2021 | + | |
| 2022 | +/* istanbul ignore next */ | |
| 2023 | +function styleTagTransform(css, styleElement) { | |
| 2024 | + if (styleElement.styleSheet) { | |
| 2025 | + styleElement.styleSheet.cssText = css; | |
| 2026 | + } else { | |
| 2027 | + while (styleElement.firstChild) { | |
| 2028 | + styleElement.removeChild(styleElement.firstChild); | |
| 2029 | + } | |
| 2030 | + styleElement.appendChild(document.createTextNode(css)); | |
| 2031 | + } | |
| 2032 | +} | |
| 2033 | +module.exports = styleTagTransform; | |
| 2034 | + | |
| 2035 | +/***/ }, | |
| 2036 | + | |
| 2037 | +/***/ "./node_modules/sweetalert2/dist/sweetalert2.all.js" | |
| 2038 | +/*!**********************************************************!*\ | |
| 2039 | + !*** ./node_modules/sweetalert2/dist/sweetalert2.all.js ***! | |
| 2040 | + \**********************************************************/ | |
| 2041 | +(module) { | |
| 2042 | + | |
| 2043 | +/*! | |
| 2044 | +* sweetalert2 v11.26.25 | |
| 2045 | +* Released under the MIT License. | |
| 2046 | +*/ | |
| 2047 | +(function (global, factory) { | |
| 2048 | + true ? module.exports = factory() : | |
| 2049 | + 0; | |
| 2050 | +})(this, (function () { 'use strict'; | |
| 2051 | + | |
| 2052 | + function _assertClassBrand(e, t, n) { | |
| 2053 | + if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; | |
| 2054 | + throw new TypeError("Private element is not present on this object"); | |
| 2055 | + } | |
| 2056 | + function _checkPrivateRedeclaration(e, t) { | |
| 2057 | + if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); | |
| 2058 | + } | |
| 2059 | + function _classPrivateFieldGet2(s, a) { | |
| 2060 | + return s.get(_assertClassBrand(s, a)); | |
| 2061 | + } | |
| 2062 | + function _classPrivateFieldInitSpec(e, t, a) { | |
| 2063 | + _checkPrivateRedeclaration(e, t), t.set(e, a); | |
| 2064 | + } | |
| 2065 | + function _classPrivateFieldSet2(s, a, r) { | |
| 2066 | + return s.set(_assertClassBrand(s, a), r), r; | |
| 2067 | + } | |
| 2068 | + | |
| 2069 | + const RESTORE_FOCUS_TIMEOUT = 100; | |
| 2070 | + | |
| 2071 | + /** @type {GlobalState} */ | |
| 2072 | + const globalState = {}; | |
| 2073 | + const focusPreviousActiveElement = () => { | |
| 2074 | + if (globalState.previousActiveElement instanceof HTMLElement) { | |
| 2075 | + globalState.previousActiveElement.focus(); | |
| 2076 | + globalState.previousActiveElement = null; | |
| 2077 | + } else if (document.body) { | |
| 2078 | + document.body.focus(); | |
| 2079 | + } | |
| 2080 | + }; | |
| 2081 | + | |
| 2082 | + /** | |
| 2083 | + * Restore previous active (focused) element | |
| 2084 | + * | |
| 2085 | + * @param {boolean} returnFocus | |
| 2086 | + * @returns {Promise<void>} | |
| 2087 | + */ | |
| 2088 | + const restoreActiveElement = returnFocus => { | |
| 2089 | + return new Promise(resolve => { | |
| 2090 | + if (!returnFocus) { | |
| 2091 | + return resolve(); | |
| 2092 | + } | |
| 2093 | + const x = window.scrollX; | |
| 2094 | + const y = window.scrollY; | |
| 2095 | + globalState.restoreFocusTimeout = setTimeout(() => { | |
| 2096 | + focusPreviousActiveElement(); | |
| 2097 | + resolve(); | |
| 2098 | + }, RESTORE_FOCUS_TIMEOUT); // issues/900 | |
| 2099 | + | |
| 2100 | + window.scrollTo(x, y); | |
| 2101 | + }); | |
| 2102 | + }; | |
| 2103 | + | |
| 2104 | + const swalPrefix = 'swal2-'; | |
| 2105 | + | |
| 2106 | + /** | |
| 2107 | + * @typedef {Record<SwalClass, string>} SwalClasses | |
| 2108 | + */ | |
| 2109 | + | |
| 2110 | + /** | |
| 2111 | + * @typedef {'success' | 'warning' | 'info' | 'question' | 'error'} SwalIcon | |
| 2112 | + * @typedef {Record<SwalIcon, string>} SwalIcons | |
| 2113 | + */ | |
| 2114 | + | |
| 2115 | + /** @type {SwalClass[]} */ | |
| 2116 | + const classNames = ['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'no-transition', 'toast', 'toast-shown', 'show', 'hide', 'close', 'title', 'html-container', 'actions', 'confirm', 'deny', 'cancel', 'footer', 'icon', 'icon-content', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'input-label', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', 'loader', 'loading', 'styled', 'top', 'top-start', 'top-end', 'top-left', 'top-right', 'center', 'center-start', 'center-end', 'center-left', 'center-right', 'bottom', 'bottom-start', 'bottom-end', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen', 'rtl', 'timer-progress-bar', 'timer-progress-bar-container', 'scrollbar-measure', 'icon-success', 'icon-warning', 'icon-info', 'icon-question', 'icon-error', 'draggable', 'dragging']; | |
| 2117 | + const swalClasses = classNames.reduce((acc, className) => { | |
| 2118 | + acc[className] = swalPrefix + className; | |
| 2119 | + return acc; | |
| 2120 | + }, /** @type {SwalClasses} */{}); | |
| 2121 | + | |
| 2122 | + /** @type {SwalIcon[]} */ | |
| 2123 | + const icons = ['success', 'warning', 'info', 'question', 'error']; | |
| 2124 | + const iconTypes = icons.reduce((acc, icon) => { | |
| 2125 | + acc[icon] = swalPrefix + icon; | |
| 2126 | + return acc; | |
| 2127 | + }, /** @type {SwalIcons} */{}); | |
| 2128 | + | |
| 2129 | + const consolePrefix = 'SweetAlert2:'; | |
| 2130 | + | |
| 2131 | + /** | |
| 2132 | + * Capitalize the first letter of a string | |
| 2133 | + * | |
| 2134 | + * @param {string} str | |
| 2135 | + * @returns {string} | |
| 2136 | + */ | |
| 2137 | + const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1); | |
| 2138 | + | |
| 2139 | + /** | |
| 2140 | + * Standardize console warnings | |
| 2141 | + * | |
| 2142 | + * @param {string | string[]} message | |
| 2143 | + */ | |
| 2144 | + const warn = message => { | |
| 2145 | + console.warn(`${consolePrefix} ${typeof message === 'object' ? message.join(' ') : message}`); | |
| 2146 | + }; | |
| 2147 | + | |
| 2148 | + /** | |
| 2149 | + * Standardize console errors | |
| 2150 | + * | |
| 2151 | + * @param {string} message | |
| 2152 | + */ | |
| 2153 | + const error = message => { | |
| 2154 | + console.error(`${consolePrefix} ${message}`); | |
| 2155 | + }; | |
| 2156 | + | |
| 2157 | + /** | |
| 2158 | + * Private global state for `warnOnce` | |
| 2159 | + * | |
| 2160 | + * @type {string[]} | |
| 2161 | + * @private | |
| 2162 | + */ | |
| 2163 | + const previousWarnOnceMessages = []; | |
| 2164 | + | |
| 2165 | + /** | |
| 2166 | + * Show a console warning, but only if it hasn't already been shown | |
| 2167 | + * | |
| 2168 | + * @param {string} message | |
| 2169 | + */ | |
| 2170 | + const warnOnce = message => { | |
| 2171 | + if (!previousWarnOnceMessages.includes(message)) { | |
| 2172 | + previousWarnOnceMessages.push(message); | |
| 2173 | + warn(message); | |
| 2174 | + } | |
| 2175 | + }; | |
| 2176 | + | |
| 2177 | + /** | |
| 2178 | + * Show a one-time console warning about deprecated params/methods | |
| 2179 | + * | |
| 2180 | + * @param {string} deprecatedParam | |
| 2181 | + * @param {string?} useInstead | |
| 2182 | + */ | |
| 2183 | + const warnAboutDeprecation = (deprecatedParam, useInstead = null) => { | |
| 2184 | + warnOnce(`"${deprecatedParam}" is deprecated and will be removed in the next major release.${useInstead ? ` Use "${useInstead}" instead.` : ''}`); | |
| 2185 | + }; | |
| 2186 | + | |
| 2187 | + /** | |
| 2188 | + * If `arg` is a function, call it (with no arguments or context) and return the result. | |
| 2189 | + * Otherwise, just pass the value through | |
| 2190 | + * | |
| 2191 | + * @param {(() => *) | *} arg | |
| 2192 | + * @returns {*} | |
| 2193 | + */ | |
| 2194 | + const callIfFunction = arg => typeof arg === 'function' ? arg() : arg; | |
| 2195 | + | |
| 2196 | + /** | |
| 2197 | + * @param {*} arg | |
| 2198 | + * @returns {boolean} | |
| 2199 | + */ | |
| 2200 | + const hasToPromiseFn = arg => arg && typeof arg.toPromise === 'function'; | |
| 2201 | + | |
| 2202 | + /** | |
| 2203 | + * @param {*} arg | |
| 2204 | + * @returns {Promise<*>} | |
| 2205 | + */ | |
| 2206 | + const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg); | |
| 2207 | + | |
| 2208 | + /** | |
| 2209 | + * @param {*} arg | |
| 2210 | + * @returns {boolean} | |
| 2211 | + */ | |
| 2212 | + const isPromise = arg => arg && Promise.resolve(arg) === arg; | |
| 2213 | + | |
| 2214 | + /** | |
| 2215 | + * @returns {boolean} | |
| 2216 | + */ | |
| 2217 | + const isFirefox = () => navigator.userAgent.includes('Firefox'); | |
| 2218 | + | |
| 2219 | + /** | |
| 2220 | + * Gets the popup container which contains the backdrop and the popup itself. | |
| 2221 | + * | |
| 2222 | + * @returns {HTMLElement | null} | |
| 2223 | + */ | |
| 2224 | + const getContainer = () => document.body.querySelector(`.${swalClasses.container}`); | |
| 2225 | + | |
| 2226 | + /** | |
| 2227 | + * @param {string} selectorString | |
| 2228 | + * @returns {HTMLElement | null} | |
| 2229 | + */ | |
| 2230 | + const elementBySelector = selectorString => { | |
| 2231 | + const container = getContainer(); | |
| 2232 | + return container ? container.querySelector(selectorString) : null; | |
| 2233 | + }; | |
| 2234 | + | |
| 2235 | + /** | |
| 2236 | + * @param {string} className | |
| 2237 | + * @returns {HTMLElement | null} | |
| 2238 | + */ | |
| 2239 | + const elementByClass = className => { | |
| 2240 | + return elementBySelector(`.${className}`); | |
| 2241 | + }; | |
| 2242 | + | |
| 2243 | + /** | |
| 2244 | + * @returns {HTMLElement | null} | |
| 2245 | + */ | |
| 2246 | + const getPopup = () => elementByClass(swalClasses.popup); | |
| 2247 | + | |
| 2248 | + /** | |
| 2249 | + * @returns {HTMLElement | null} | |
| 2250 | + */ | |
| 2251 | + const getIcon = () => elementByClass(swalClasses.icon); | |
| 2252 | + | |
| 2253 | + /** | |
| 2254 | + * @returns {HTMLElement | null} | |
| 2255 | + */ | |
| 2256 | + const getIconContent = () => elementByClass(swalClasses['icon-content']); | |
| 2257 | + | |
| 2258 | + /** | |
| 2259 | + * @returns {HTMLElement | null} | |
| 2260 | + */ | |
| 2261 | + const getTitle = () => elementByClass(swalClasses.title); | |
| 2262 | + | |
| 2263 | + /** | |
| 2264 | + * @returns {HTMLElement | null} | |
| 2265 | + */ | |
| 2266 | + const getHtmlContainer = () => elementByClass(swalClasses['html-container']); | |
| 2267 | + | |
| 2268 | + /** | |
| 2269 | + * @returns {HTMLElement | null} | |
| 2270 | + */ | |
| 2271 | + const getImage = () => elementByClass(swalClasses.image); | |
| 2272 | + | |
| 2273 | + /** | |
| 2274 | + * @returns {HTMLElement | null} | |
| 2275 | + */ | |
| 2276 | + const getProgressSteps = () => elementByClass(swalClasses['progress-steps']); | |
| 2277 | + | |
| 2278 | + /** | |
| 2279 | + * @returns {HTMLElement | null} | |
| 2280 | + */ | |
| 2281 | + const getValidationMessage = () => elementByClass(swalClasses['validation-message']); | |
| 2282 | + | |
| 2283 | + /** | |
| 2284 | + * @returns {HTMLButtonElement | null} | |
| 2285 | + */ | |
| 2286 | + const getConfirmButton = () => (/** @type {HTMLButtonElement} */elementBySelector(`.${swalClasses.actions} .${swalClasses.confirm}`)); | |
| 2287 | + | |
| 2288 | + /** | |
| 2289 | + * @returns {HTMLButtonElement | null} | |
| 2290 | + */ | |
| 2291 | + const getCancelButton = () => (/** @type {HTMLButtonElement} */elementBySelector(`.${swalClasses.actions} .${swalClasses.cancel}`)); | |
| 2292 | + | |
| 2293 | + /** | |
| 2294 | + * @returns {HTMLButtonElement | null} | |
| 2295 | + */ | |
| 2296 | + const getDenyButton = () => (/** @type {HTMLButtonElement} */elementBySelector(`.${swalClasses.actions} .${swalClasses.deny}`)); | |
| 2297 | + | |
| 2298 | + /** | |
| 2299 | + * @returns {HTMLElement | null} | |
| 2300 | + */ | |
| 2301 | + const getInputLabel = () => elementByClass(swalClasses['input-label']); | |
| 2302 | + | |
| 2303 | + /** | |
| 2304 | + * @returns {HTMLElement | null} | |
| 2305 | + */ | |
| 2306 | + const getLoader = () => elementBySelector(`.${swalClasses.loader}`); | |
| 2307 | + | |
| 2308 | + /** | |
| 2309 | + * @returns {HTMLElement | null} | |
| 2310 | + */ | |
| 2311 | + const getActions = () => elementByClass(swalClasses.actions); | |
| 2312 | + | |
| 2313 | + /** | |
| 2314 | + * @returns {HTMLElement | null} | |
| 2315 | + */ | |
| 2316 | + const getFooter = () => elementByClass(swalClasses.footer); | |
| 2317 | + | |
| 2318 | + /** | |
| 2319 | + * @returns {HTMLElement | null} | |
| 2320 | + */ | |
| 2321 | + const getTimerProgressBar = () => elementByClass(swalClasses['timer-progress-bar']); | |
| 2322 | + | |
| 2323 | + /** | |
| 2324 | + * @returns {HTMLElement | null} | |
| 2325 | + */ | |
| 2326 | + const getCloseButton = () => elementByClass(swalClasses.close); | |
| 2327 | + | |
| 2328 | + // https://github.com/jkup/focusable/blob/master/index.js | |
| 2329 | + const focusable = ` | |
| 2330 | + a[href], | |
| 2331 | + area[href], | |
| 2332 | + input:not([disabled]), | |
| 2333 | + select:not([disabled]), | |
| 2334 | + textarea:not([disabled]), | |
| 2335 | + button:not([disabled]), | |
| 2336 | + iframe, | |
| 2337 | + object, | |
| 2338 | + embed, | |
| 2339 | + [tabindex="0"], | |
| 2340 | + [contenteditable], | |
| 2341 | + audio[controls], | |
| 2342 | + video[controls], | |
| 2343 | + summary | |
| 2344 | +`; | |
| 2345 | + /** | |
| 2346 | + * @returns {HTMLElement[]} | |
| 2347 | + */ | |
| 2348 | + const getFocusableElements = () => { | |
| 2349 | + const popup = getPopup(); | |
| 2350 | + if (!popup) { | |
| 2351 | + return []; | |
| 2352 | + } | |
| 2353 | + /** @type {NodeListOf<HTMLElement>} */ | |
| 2354 | + const focusableElementsWithTabindex = popup.querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'); | |
| 2355 | + const focusableElementsWithTabindexSorted = Array.from(focusableElementsWithTabindex) | |
| 2356 | + // sort according to tabindex | |
| 2357 | + .sort((a, b) => { | |
| 2358 | + const tabindexA = parseInt(a.getAttribute('tabindex') || '0'); | |
| 2359 | + const tabindexB = parseInt(b.getAttribute('tabindex') || '0'); | |
| 2360 | + if (tabindexA > tabindexB) { | |
| 2361 | + return 1; | |
| 2362 | + } else if (tabindexA < tabindexB) { | |
| 2363 | + return -1; | |
| 2364 | + } | |
| 2365 | + return 0; | |
| 2366 | + }); | |
| 2367 | + | |
| 2368 | + /** @type {NodeListOf<HTMLElement>} */ | |
| 2369 | + const otherFocusableElements = popup.querySelectorAll(focusable); | |
| 2370 | + const otherFocusableElementsFiltered = Array.from(otherFocusableElements).filter(el => el.getAttribute('tabindex') !== '-1'); | |
| 2371 | + return [...new Set(focusableElementsWithTabindexSorted.concat(otherFocusableElementsFiltered))].filter(el => isVisible$1(el)); | |
| 2372 | + }; | |
| 2373 | + | |
| 2374 | + /** | |
| 2375 | + * @returns {boolean} | |
| 2376 | + */ | |
| 2377 | + const isModal = () => { | |
| 2378 | + return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']); | |
| 2379 | + }; | |
| 2380 | + | |
| 2381 | + /** | |
| 2382 | + * @returns {boolean} | |
| 2383 | + */ | |
| 2384 | + const isToast = () => { | |
| 2385 | + const popup = getPopup(); | |
| 2386 | + if (!popup) { | |
| 2387 | + return false; | |
| 2388 | + } | |
| 2389 | + return hasClass(popup, swalClasses.toast); | |
| 2390 | + }; | |
| 2391 | + | |
| 2392 | + /** | |
| 2393 | + * @returns {boolean} | |
| 2394 | + */ | |
| 2395 | + const isLoading = () => { | |
| 2396 | + const popup = getPopup(); | |
| 2397 | + if (!popup) { | |
| 2398 | + return false; | |
| 2399 | + } | |
| 2400 | + return popup.hasAttribute('data-loading'); | |
| 2401 | + }; | |
| 2402 | + | |
| 2403 | + /** | |
| 2404 | + * Securely set innerHTML of an element | |
| 2405 | + * https://github.com/sweetalert2/sweetalert2/issues/1926 | |
| 2406 | + * | |
| 2407 | + * @param {HTMLElement} elem | |
| 2408 | + * @param {string} html | |
| 2409 | + */ | |
| 2410 | + const setInnerHtml = (elem, html) => { | |
| 2411 | + elem.textContent = ''; | |
| 2412 | + if (html) { | |
| 2413 | + const parser = new DOMParser(); | |
| 2414 | + const parsed = parser.parseFromString(html, `text/html`); | |
| 2415 | + const head = parsed.querySelector('head'); | |
| 2416 | + if (head) { | |
| 2417 | + Array.from(head.childNodes).forEach(child => { | |
| 2418 | + elem.appendChild(child); | |
| 2419 | + }); | |
| 2420 | + } | |
| 2421 | + const body = parsed.querySelector('body'); | |
| 2422 | + if (body) { | |
| 2423 | + Array.from(body.childNodes).forEach(child => { | |
| 2424 | + if (child instanceof HTMLVideoElement || child instanceof HTMLAudioElement) { | |
| 2425 | + elem.appendChild(child.cloneNode(true)); // https://github.com/sweetalert2/sweetalert2/issues/2507 | |
| 2426 | + } else { | |
| 2427 | + elem.appendChild(child); | |
| 2428 | + } | |
| 2429 | + }); | |
| 2430 | + } | |
| 2431 | + } | |
| 2432 | + }; | |
| 2433 | + | |
| 2434 | + /** | |
| 2435 | + * @param {HTMLElement} elem | |
| 2436 | + * @param {string} className | |
| 2437 | + * @returns {boolean} | |
| 2438 | + */ | |
| 2439 | + const hasClass = (elem, className) => { | |
| 2440 | + if (!className) { | |
| 2441 | + return false; | |
| 2442 | + } | |
| 2443 | + return className.split(/\s+/).every(cls => elem.classList.contains(cls)); | |
| 2444 | + }; | |
| 2445 | + | |
| 2446 | + /** | |
| 2447 | + * @param {HTMLElement} elem | |
| 2448 | + * @param {SweetAlertOptions} params | |
| 2449 | + */ | |
| 2450 | + const removeCustomClasses = (elem, params) => { | |
| 2451 | + Array.from(elem.classList).forEach(className => { | |
| 2452 | + if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass || {}).includes(className)) { | |
| 2453 | + elem.classList.remove(className); | |
| 2454 | + } | |
| 2455 | + }); | |
| 2456 | + }; | |
| 2457 | + | |
| 2458 | + /** | |
| 2459 | + * @param {HTMLElement} elem | |
| 2460 | + * @param {SweetAlertOptions} params | |
| 2461 | + * @param {string} className | |
| 2462 | + */ | |
| 2463 | + const applyCustomClass = (elem, params, className) => { | |
| 2464 | + removeCustomClasses(elem, params); | |
| 2465 | + if (!params.customClass) { | |
| 2466 | + return; | |
| 2467 | + } | |
| 2468 | + const customClass = params.customClass[(/** @type {keyof SweetAlertCustomClass} */className)]; | |
| 2469 | + if (!customClass) { | |
| 2470 | + return; | |
| 2471 | + } | |
| 2472 | + if (typeof customClass !== 'string' && !customClass.forEach) { | |
| 2473 | + warn(`Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof customClass}"`); | |
| 2474 | + return; | |
| 2475 | + } | |
| 2476 | + addClass(elem, customClass); | |
| 2477 | + }; | |
| 2478 | + | |
| 2479 | + /** | |
| 2480 | + * @param {HTMLElement} popup | |
| 2481 | + * @param {import('./renderers/renderInput').InputClass | SweetAlertInput} inputClass | |
| 2482 | + * @returns {HTMLInputElement | null} | |
| 2483 | + */ | |
| 2484 | + const getInput$1 = (popup, inputClass) => { | |
| 2485 | + if (!inputClass) { | |
| 2486 | + return null; | |
| 2487 | + } | |
| 2488 | + switch (inputClass) { | |
| 2489 | + case 'select': | |
| 2490 | + case 'textarea': | |
| 2491 | + case 'file': | |
| 2492 | + return popup.querySelector(`.${swalClasses.popup} > .${swalClasses[inputClass]}`); | |
| 2493 | + case 'checkbox': | |
| 2494 | + return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.checkbox} input`); | |
| 2495 | + case 'radio': | |
| 2496 | + return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) || popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:first-child`); | |
| 2497 | + case 'range': | |
| 2498 | + return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.range} input`); | |
| 2499 | + default: | |
| 2500 | + return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.input}`); | |
| 2501 | + } | |
| 2502 | + }; | |
| 2503 | + | |
| 2504 | + /** | |
| 2505 | + * @param {HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement} input | |
| 2506 | + */ | |
| 2507 | + const focusInput = input => { | |
| 2508 | + input.focus(); | |
| 2509 | + | |
| 2510 | + // place cursor at end of text in text input | |
| 2511 | + if (input.type !== 'file') { | |
| 2512 | + // http://stackoverflow.com/a/2345915 | |
| 2513 | + const val = input.value; | |
| 2514 | + input.value = ''; | |
| 2515 | + input.value = val; | |
| 2516 | + } | |
| 2517 | + }; | |
| 2518 | + | |
| 2519 | + /** | |
| 2520 | + * @param {HTMLElement | HTMLElement[] | null} target | |
| 2521 | + * @param {string | string[] | readonly string[] | undefined} classList | |
| 2522 | + * @param {boolean} condition | |
| 2523 | + */ | |
| 2524 | + const toggleClass = (target, classList, condition) => { | |
| 2525 | + if (!target || !classList) { | |
| 2526 | + return; | |
| 2527 | + } | |
| 2528 | + const classes = typeof classList === 'string' ? classList.split(/\s+/).filter(Boolean) : classList; | |
| 2529 | + const targets = Array.isArray(target) ? target : [target]; | |
| 2530 | + targets.forEach(elem => { | |
| 2531 | + classes.forEach(className => { | |
| 2532 | + if (condition) { | |
| 2533 | + elem.classList.add(className); | |
| 2534 | + } else { | |
| 2535 | + elem.classList.remove(className); | |
| 2536 | + } | |
| 2537 | + }); | |
| 2538 | + }); | |
| 2539 | + }; | |
| 2540 | + | |
| 2541 | + /** | |
| 2542 | + * @param {HTMLElement | HTMLElement[] | null} target | |
| 2543 | + * @param {string | string[] | readonly string[] | undefined} classList | |
| 2544 | + */ | |
| 2545 | + const addClass = (target, classList) => { | |
| 2546 | + toggleClass(target, classList, true); | |
| 2547 | + }; | |
| 2548 | + | |
| 2549 | + /** | |
| 2550 | + * @param {HTMLElement | HTMLElement[] | null} target | |
| 2551 | + * @param {string | string[] | readonly string[] | undefined} classList | |
| 2552 | + */ | |
| 2553 | + const removeClass = (target, classList) => { | |
| 2554 | + toggleClass(target, classList, false); | |
| 2555 | + }; | |
| 2556 | + | |
| 2557 | + /** | |
| 2558 | + * Get direct child of an element by class name | |
| 2559 | + * | |
| 2560 | + * @param {HTMLElement} elem | |
| 2561 | + * @param {string} className | |
| 2562 | + * @returns {HTMLElement | undefined} | |
| 2563 | + */ | |
| 2564 | + const getDirectChildByClass = (elem, className) => (/** @type {HTMLElement | undefined} */ | |
| 2565 | + Array.from(elem.children).find(child => child instanceof HTMLElement && hasClass(child, className))); | |
| 2566 | + | |
| 2567 | + /** | |
| 2568 | + * @param {HTMLElement} elem | |
| 2569 | + * @param {string} property | |
| 2570 | + * @param {string | number | null | undefined} value | |
| 2571 | + */ | |
| 2572 | + const applyNumericalStyle = (elem, property, value) => { | |
| 2573 | + if (value === `${parseInt(`${value}`)}`) { | |
| 2574 | + value = parseInt(value); | |
| 2575 | + } | |
| 2576 | + if (value || value === 0) { | |
| 2577 | + elem.style.setProperty(property, typeof value === 'number' ? `${value}px` : (/** @type {string} */value)); | |
| 2578 | + } else { | |
| 2579 | + elem.style.removeProperty(property); | |
| 2580 | + } | |
| 2581 | + }; | |
| 2582 | + | |
| 2583 | + /** | |
| 2584 | + * @param {HTMLElement | null} elem | |
| 2585 | + * @param {string} display | |
| 2586 | + */ | |
| 2587 | + const show = (elem, display = 'flex') => { | |
| 2588 | + if (!elem) { | |
| 2589 | + return; | |
| 2590 | + } | |
| 2591 | + elem.style.display = display; | |
| 2592 | + }; | |
| 2593 | + | |
| 2594 | + /** | |
| 2595 | + * @param {HTMLElement | null} elem | |
| 2596 | + */ | |
| 2597 | + const hide = elem => { | |
| 2598 | + if (!elem) { | |
| 2599 | + return; | |
| 2600 | + } | |
| 2601 | + elem.style.display = 'none'; | |
| 2602 | + }; | |
| 2603 | + | |
| 2604 | + /** | |
| 2605 | + * @param {HTMLElement | null} elem | |
| 2606 | + * @param {string} display | |
| 2607 | + */ | |
| 2608 | + const showWhenInnerHtmlPresent = (elem, display = 'block') => { | |
| 2609 | + if (!elem) { | |
| 2610 | + return; | |
| 2611 | + } | |
| 2612 | + new MutationObserver(() => { | |
| 2613 | + toggle(elem, elem.innerHTML, display); | |
| 2614 | + }).observe(elem, { | |
| 2615 | + childList: true, | |
| 2616 | + subtree: true | |
| 2617 | + }); | |
| 2618 | + }; | |
| 2619 | + | |
| 2620 | + /** | |
| 2621 | + * @param {HTMLElement} parent | |
| 2622 | + * @param {string} selector | |
| 2623 | + * @param {string} property | |
| 2624 | + * @param {string} value | |
| 2625 | + */ | |
| 2626 | + const setStyle = (parent, selector, property, value) => { | |
| 2627 | + /** @type {HTMLElement | null} */ | |
| 2628 | + const el = parent.querySelector(selector); | |
| 2629 | + if (el) { | |
| 2630 | + el.style.setProperty(property, value); | |
| 2631 | + } | |
| 2632 | + }; | |
| 2633 | + | |
| 2634 | + /** | |
| 2635 | + * @param {HTMLElement} elem | |
| 2636 | + * @param {boolean | string | null | undefined} condition | |
| 2637 | + * @param {string} display | |
| 2638 | + */ | |
| 2639 | + const toggle = (elem, condition, display = 'flex') => { | |
| 2640 | + if (condition) { | |
| 2641 | + show(elem, display); | |
| 2642 | + } else { | |
| 2643 | + hide(elem); | |
| 2644 | + } | |
| 2645 | + }; | |
| 2646 | + | |
| 2647 | + /** | |
| 2648 | + * borrowed from jquery $(elem).is(':visible') implementation | |
| 2649 | + * | |
| 2650 | + * @param {HTMLElement | null} elem | |
| 2651 | + * @returns {boolean} | |
| 2652 | + */ | |
| 2653 | + const isVisible$1 = elem => Boolean(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length)); | |
| 2654 | + | |
| 2655 | + /** | |
| 2656 | + * @returns {boolean} | |
| 2657 | + */ | |
| 2658 | + const allButtonsAreHidden = () => !isVisible$1(getConfirmButton()) && !isVisible$1(getDenyButton()) && !isVisible$1(getCancelButton()); | |
| 2659 | + | |
| 2660 | + /** | |
| 2661 | + * @param {HTMLElement} elem | |
| 2662 | + * @returns {boolean} | |
| 2663 | + */ | |
| 2664 | + const isScrollable = elem => Boolean(elem.scrollHeight > elem.clientHeight); | |
| 2665 | + | |
| 2666 | + /** | |
| 2667 | + * @param {HTMLElement} element | |
| 2668 | + * @param {HTMLElement} stopElement | |
| 2669 | + * @returns {boolean} | |
| 2670 | + */ | |
| 2671 | + const selfOrParentIsScrollable = (element, stopElement) => { | |
| 2672 | + let parent = /** @type {HTMLElement | null} */element; | |
| 2673 | + while (parent && parent !== stopElement) { | |
| 2674 | + if (isScrollable(parent)) { | |
| 2675 | + return true; | |
| 2676 | + } | |
| 2677 | + parent = parent.parentElement; | |
| 2678 | + } | |
| 2679 | + return false; | |
| 2680 | + }; | |
| 2681 | + | |
| 2682 | + /** | |
| 2683 | + * borrowed from https://stackoverflow.com/a/46352119 | |
| 2684 | + * | |
| 2685 | + * @param {HTMLElement} elem | |
| 2686 | + * @returns {boolean} | |
| 2687 | + */ | |
| 2688 | + const hasCssAnimation = elem => { | |
| 2689 | + const style = window.getComputedStyle(elem); | |
| 2690 | + const animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0'); | |
| 2691 | + const transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0'); | |
| 2692 | + return animDuration > 0 || transDuration > 0; | |
| 2693 | + }; | |
| 2694 | + | |
| 2695 | + /** | |
| 2696 | + * @param {number} timer | |
| 2697 | + * @param {boolean} reset | |
| 2698 | + */ | |
| 2699 | + const animateTimerProgressBar = (timer, reset = false) => { | |
| 2700 | + const timerProgressBar = getTimerProgressBar(); | |
| 2701 | + if (!timerProgressBar) { | |
| 2702 | + return; | |
| 2703 | + } | |
| 2704 | + if (isVisible$1(timerProgressBar)) { | |
| 2705 | + if (reset) { | |
| 2706 | + timerProgressBar.style.transition = 'none'; | |
| 2707 | + timerProgressBar.style.width = '100%'; | |
| 2708 | + } | |
| 2709 | + setTimeout(() => { | |
| 2710 | + timerProgressBar.style.transition = `width ${timer / 1000}s linear`; | |
| 2711 | + timerProgressBar.style.width = '0%'; | |
| 2712 | + }, 10); | |
| 2713 | + } | |
| 2714 | + }; | |
| 2715 | + const stopTimerProgressBar = () => { | |
| 2716 | + const timerProgressBar = getTimerProgressBar(); | |
| 2717 | + if (!timerProgressBar) { | |
| 2718 | + return; | |
| 2719 | + } | |
| 2720 | + const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width); | |
| 2721 | + timerProgressBar.style.removeProperty('transition'); | |
| 2722 | + timerProgressBar.style.width = '100%'; | |
| 2723 | + const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width); | |
| 2724 | + const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100; | |
| 2725 | + timerProgressBar.style.width = `${timerProgressBarPercent}%`; | |
| 2726 | + }; | |
| 2727 | + | |
| 2728 | + /** | |
| 2729 | + * Detect Node env | |
| 2730 | + * | |
| 2731 | + * @returns {boolean} | |
| 2732 | + */ | |
| 2733 | + const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined'; | |
| 2734 | + | |
| 2735 | + const sweetHTML = ` | |
| 2736 | + <div aria-labelledby="${swalClasses.title}" aria-describedby="${swalClasses['html-container']}" class="${swalClasses.popup}" tabindex="-1"> | |
| 2737 | + <button type="button" class="${swalClasses.close}"></button> | |
| 2738 | + <ul class="${swalClasses['progress-steps']}"></ul> | |
| 2739 | + <div class="${swalClasses.icon}"></div> | |
| 2740 | + <img class="${swalClasses.image}" /> | |
| 2741 | + <h2 class="${swalClasses.title}" id="${swalClasses.title}"></h2> | |
| 2742 | + <div class="${swalClasses['html-container']}" id="${swalClasses['html-container']}"></div> | |
| 2743 | + <input class="${swalClasses.input}" id="${swalClasses.input}" /> | |
| 2744 | + <input type="file" class="${swalClasses.file}" /> | |
| 2745 | + <div class="${swalClasses.range}"> | |
| 2746 | + <input type="range" /> | |
| 2747 | + <output></output> | |
| 2748 | + </div> | |
| 2749 | + <select class="${swalClasses.select}" id="${swalClasses.select}"></select> | |
| 2750 | + <div class="${swalClasses.radio}"></div> | |
| 2751 | + <label class="${swalClasses.checkbox}"> | |
| 2752 | + <input type="checkbox" id="${swalClasses.checkbox}" /> | |
| 2753 | + <span class="${swalClasses.label}"></span> | |
| 2754 | + </label> | |
| 2755 | + <textarea class="${swalClasses.textarea}" id="${swalClasses.textarea}"></textarea> | |
| 2756 | + <div class="${swalClasses['validation-message']}" id="${swalClasses['validation-message']}"></div> | |
| 2757 | + <div class="${swalClasses.actions}"> | |
| 2758 | + <div class="${swalClasses.loader}"></div> | |
| 2759 | + <button type="button" class="${swalClasses.confirm}"></button> | |
| 2760 | + <button type="button" class="${swalClasses.deny}"></button> | |
| 2761 | + <button type="button" class="${swalClasses.cancel}"></button> | |
| 2762 | + </div> | |
| 2763 | + <div class="${swalClasses.footer}"></div> | |
| 2764 | + <div class="${swalClasses['timer-progress-bar-container']}"> | |
| 2765 | + <div class="${swalClasses['timer-progress-bar']}"></div> | |
| 2766 | + </div> | |
| 2767 | + </div> | |
| 2768 | +`.replace(/(^|\n)\s*/g, ''); | |
| 2769 | + | |
| 2770 | + /** | |
| 2771 | + * @returns {boolean} | |
| 2772 | + */ | |
| 2773 | + const resetOldContainer = () => { | |
| 2774 | + const oldContainer = getContainer(); | |
| 2775 | + if (!oldContainer) { | |
| 2776 | + return false; | |
| 2777 | + } | |
| 2778 | + oldContainer.remove(); | |
| 2779 | + removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], | |
| 2780 | + // @ts-ignore: 'has-column' is not defined in swalClasses but may be set dynamically | |
| 2781 | + swalClasses['has-column']]); | |
| 2782 | + return true; | |
| 2783 | + }; | |
| 2784 | + const resetValidationMessage$1 = () => { | |
| 2785 | + if (globalState.currentInstance) { | |
| 2786 | + globalState.currentInstance.resetValidationMessage(); | |
| 2787 | + } | |
| 2788 | + }; | |
| 2789 | + const addInputChangeListeners = () => { | |
| 2790 | + const popup = getPopup(); | |
| 2791 | + if (!popup) { | |
| 2792 | + return; | |
| 2793 | + } | |
| 2794 | + const input = getDirectChildByClass(popup, swalClasses.input); | |
| 2795 | + const file = getDirectChildByClass(popup, swalClasses.file); | |
| 2796 | + /** @type {HTMLInputElement | null} */ | |
| 2797 | + const range = popup.querySelector(`.${swalClasses.range} input`); | |
| 2798 | + /** @type {HTMLOutputElement | null} */ | |
| 2799 | + const rangeOutput = popup.querySelector(`.${swalClasses.range} output`); | |
| 2800 | + const select = getDirectChildByClass(popup, swalClasses.select); | |
| 2801 | + /** @type {HTMLInputElement | null} */ | |
| 2802 | + const checkbox = popup.querySelector(`.${swalClasses.checkbox} input`); | |
| 2803 | + const textarea = getDirectChildByClass(popup, swalClasses.textarea); | |
| 2804 | + if (input) { | |
| 2805 | + input.oninput = resetValidationMessage$1; | |
| 2806 | + } | |
| 2807 | + if (file) { | |
| 2808 | + file.onchange = resetValidationMessage$1; | |
| 2809 | + } | |
| 2810 | + if (select) { | |
| 2811 | + select.onchange = resetValidationMessage$1; | |
| 2812 | + } | |
| 2813 | + if (checkbox) { | |
| 2814 | + checkbox.onchange = resetValidationMessage$1; | |
| 2815 | + } | |
| 2816 | + if (textarea) { | |
| 2817 | + textarea.oninput = resetValidationMessage$1; | |
| 2818 | + } | |
| 2819 | + if (range && rangeOutput) { | |
| 2820 | + range.oninput = () => { | |
| 2821 | + resetValidationMessage$1(); | |
| 2822 | + rangeOutput.value = range.value; | |
| 2823 | + }; | |
| 2824 | + range.onchange = () => { | |
| 2825 | + resetValidationMessage$1(); | |
| 2826 | + rangeOutput.value = range.value; | |
| 2827 | + }; | |
| 2828 | + } | |
| 2829 | + }; | |
| 2830 | + | |
| 2831 | + /** | |
| 2832 | + * @param {string | HTMLElement} target | |
| 2833 | + * @returns {HTMLElement} | |
| 2834 | + */ | |
| 2835 | + const getTarget = target => { | |
| 2836 | + if (typeof target === 'string') { | |
| 2837 | + const element = document.querySelector(target); | |
| 2838 | + if (!element) { | |
| 2839 | + throw new Error(`Target element "${target}" not found`); | |
| 2840 | + } | |
| 2841 | + return /** @type {HTMLElement} */element; | |
| 2842 | + } | |
| 2843 | + return target; | |
| 2844 | + }; | |
| 2845 | + | |
| 2846 | + /** | |
| 2847 | + * @param {SweetAlertOptions} params | |
| 2848 | + */ | |
| 2849 | + const setupAccessibility = params => { | |
| 2850 | + const popup = getPopup(); | |
| 2851 | + if (!popup) { | |
| 2852 | + return; | |
| 2853 | + } | |
| 2854 | + popup.setAttribute('role', params.toast ? 'alert' : 'dialog'); | |
| 2855 | + popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive'); | |
| 2856 | + if (!params.toast) { | |
| 2857 | + popup.setAttribute('aria-modal', 'true'); | |
| 2858 | + } | |
| 2859 | + }; | |
| 2860 | + | |
| 2861 | + /** | |
| 2862 | + * @param {HTMLElement} targetElement | |
| 2863 | + */ | |
| 2864 | + const setupRTL = targetElement => { | |
| 2865 | + if (window.getComputedStyle(targetElement).direction === 'rtl') { | |
| 2866 | + addClass(getContainer(), swalClasses.rtl); | |
| 2867 | + globalState.isRTL = true; | |
| 2868 | + } | |
| 2869 | + }; | |
| 2870 | + | |
| 2871 | + /** | |
| 2872 | + * Add modal + backdrop to DOM | |
| 2873 | + * | |
| 2874 | + * @param {SweetAlertOptions} params | |
| 2875 | + */ | |
| 2876 | + const init = params => { | |
| 2877 | + // Clean up the old popup container if it exists | |
| 2878 | + const oldContainerExisted = resetOldContainer(); | |
| 2879 | + if (isNodeEnv()) { | |
| 2880 | + error('SweetAlert2 requires document to initialize'); | |
| 2881 | + return; | |
| 2882 | + } | |
| 2883 | + const container = document.createElement('div'); | |
| 2884 | + container.className = swalClasses.container; | |
| 2885 | + if (oldContainerExisted) { | |
| 2886 | + addClass(container, swalClasses['no-transition']); | |
| 2887 | + } | |
| 2888 | + setInnerHtml(container, sweetHTML); | |
| 2889 | + container.dataset['swal2Theme'] = params.theme; | |
| 2890 | + const targetElement = getTarget(params.target || 'body'); | |
| 2891 | + targetElement.appendChild(container); | |
| 2892 | + if (params.topLayer) { | |
| 2893 | + container.setAttribute('popover', ''); | |
| 2894 | + container.showPopover(); | |
| 2895 | + } | |
| 2896 | + setupAccessibility(params); | |
| 2897 | + setupRTL(targetElement); | |
| 2898 | + addInputChangeListeners(); | |
| 2899 | + }; | |
| 2900 | + | |
| 2901 | + /** | |
| 2902 | + * @param {HTMLElement | object | string} param | |
| 2903 | + * @param {HTMLElement} target | |
| 2904 | + */ | |
| 2905 | + const parseHtmlToContainer = (param, target) => { | |
| 2906 | + // DOM element | |
| 2907 | + if (param instanceof HTMLElement) { | |
| 2908 | + target.appendChild(param); | |
| 2909 | + } | |
| 2910 | + | |
| 2911 | + // Object | |
| 2912 | + else if (typeof param === 'object') { | |
| 2913 | + handleObject(param, target); | |
| 2914 | + } | |
| 2915 | + | |
| 2916 | + // Plain string | |
| 2917 | + else if (param) { | |
| 2918 | + setInnerHtml(target, param); | |
| 2919 | + } | |
| 2920 | + }; | |
| 2921 | + | |
| 2922 | + /** | |
| 2923 | + * @param {object} param | |
| 2924 | + * @param {HTMLElement} target | |
| 2925 | + */ | |
| 2926 | + const handleObject = (param, target) => { | |
| 2927 | + // JQuery element(s) | |
| 2928 | + if ('jquery' in param) { | |
| 2929 | + handleJqueryElem(target, param); | |
| 2930 | + } | |
| 2931 | + | |
| 2932 | + // For other objects use their string representation | |
| 2933 | + else { | |
| 2934 | + setInnerHtml(target, param.toString()); | |
| 2935 | + } | |
| 2936 | + }; | |
| 2937 | + | |
| 2938 | + /** | |
| 2939 | + * @param {HTMLElement} target | |
| 2940 | + * @param {any} elem | |
| 2941 | + */ | |
| 2942 | + const handleJqueryElem = (target, elem) => { | |
| 2943 | + target.textContent = ''; | |
| 2944 | + if (0 in elem) { | |
| 2945 | + for (let i = 0; i in elem; i++) { | |
| 2946 | + target.appendChild(elem[i].cloneNode(true)); | |
| 2947 | + } | |
| 2948 | + } else { | |
| 2949 | + target.appendChild(elem.cloneNode(true)); | |
| 2950 | + } | |
| 2951 | + }; | |
| 2952 | + | |
| 2953 | + /** | |
| 2954 | + * @param {SweetAlert} instance | |
| 2955 | + * @param {SweetAlertOptions} params | |
| 2956 | + */ | |
| 2957 | + const renderActions = (instance, params) => { | |
| 2958 | + const actions = getActions(); | |
| 2959 | + const loader = getLoader(); | |
| 2960 | + if (!actions || !loader) { | |
| 2961 | + return; | |
| 2962 | + } | |
| 2963 | + | |
| 2964 | + // Actions (buttons) wrapper | |
| 2965 | + if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) { | |
| 2966 | + hide(actions); | |
| 2967 | + } else { | |
| 2968 | + show(actions); | |
| 2969 | + } | |
| 2970 | + | |
| 2971 | + // Custom class | |
| 2972 | + applyCustomClass(actions, params, 'actions'); | |
| 2973 | + | |
| 2974 | + // Render all the buttons | |
| 2975 | + renderButtons(actions, loader, params); | |
| 2976 | + | |
| 2977 | + // Loader | |
| 2978 | + setInnerHtml(loader, params.loaderHtml || ''); | |
| 2979 | + applyCustomClass(loader, params, 'loader'); | |
| 2980 | + }; | |
| 2981 | + | |
| 2982 | + /** | |
| 2983 | + * @param {HTMLElement} actions | |
| 2984 | + * @param {HTMLElement} loader | |
| 2985 | + * @param {SweetAlertOptions} params | |
| 2986 | + */ | |
| 2987 | + function renderButtons(actions, loader, params) { | |
| 2988 | + const confirmButton = getConfirmButton(); | |
| 2989 | + const denyButton = getDenyButton(); | |
| 2990 | + const cancelButton = getCancelButton(); | |
| 2991 | + if (!confirmButton || !denyButton || !cancelButton) { | |
| 2992 | + return; | |
| 2993 | + } | |
| 2994 | + | |
| 2995 | + // Render buttons | |
| 2996 | + renderButton(confirmButton, 'confirm', params); | |
| 2997 | + renderButton(denyButton, 'deny', params); | |
| 2998 | + renderButton(cancelButton, 'cancel', params); | |
| 2999 | + handleButtonsStyling(confirmButton, denyButton, cancelButton, params); | |
| 3000 | + if (params.reverseButtons) { | |
| 3001 | + if (params.toast) { | |
| 3002 | + actions.insertBefore(cancelButton, confirmButton); | |
| 3003 | + actions.insertBefore(denyButton, confirmButton); | |
| 3004 | + } else { | |
| 3005 | + actions.insertBefore(cancelButton, loader); | |
| 3006 | + actions.insertBefore(denyButton, loader); | |
| 3007 | + actions.insertBefore(confirmButton, loader); | |
| 3008 | + } | |
| 3009 | + } | |
| 3010 | + } | |
| 3011 | + | |
| 3012 | + /** | |
| 3013 | + * @param {HTMLElement} confirmButton | |
| 3014 | + * @param {HTMLElement} denyButton | |
| 3015 | + * @param {HTMLElement} cancelButton | |
| 3016 | + * @param {SweetAlertOptions} params | |
| 3017 | + */ | |
| 3018 | + function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) { | |
| 3019 | + if (!params.buttonsStyling) { | |
| 3020 | + removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled); | |
| 3021 | + return; | |
| 3022 | + } | |
| 3023 | + addClass([confirmButton, denyButton, cancelButton], swalClasses.styled); | |
| 3024 | + | |
| 3025 | + // Apply custom background colors and outline colors to action buttons | |
| 3026 | + /** @type {[HTMLElement, string, string | undefined][]} */ | |
| 3027 | + const buttons = [[confirmButton, 'confirm', params.confirmButtonColor], [denyButton, 'deny', params.denyButtonColor], [cancelButton, 'cancel', params.cancelButtonColor]]; | |
| 3028 | + buttons.forEach(([button, type, color]) => { | |
| 3029 | + if (color) { | |
| 3030 | + button.style.setProperty(`--swal2-${type}-button-background-color`, color); | |
| 3031 | + } | |
| 3032 | + applyOutlineColor(button); | |
| 3033 | + }); | |
| 3034 | + } | |
| 3035 | + | |
| 3036 | + /** | |
| 3037 | + * @param {HTMLElement} button | |
| 3038 | + */ | |
| 3039 | + function applyOutlineColor(button) { | |
| 3040 | + const buttonStyle = window.getComputedStyle(button); | |
| 3041 | + if (buttonStyle.getPropertyValue('--swal2-action-button-focus-box-shadow')) { | |
| 3042 | + // If the button already has a custom outline color, no need to change it | |
| 3043 | + return; | |
| 3044 | + } | |
| 3045 | + const outlineColor = buttonStyle.backgroundColor.replace(/rgba?\((\d+), (\d+), (\d+).*/, 'rgba($1, $2, $3, 0.5)'); | |
| 3046 | + button.style.setProperty('--swal2-action-button-focus-box-shadow', buttonStyle.getPropertyValue('--swal2-outline').replace(/ rgba\(.*/, ` ${outlineColor}`)); | |
| 3047 | + } | |
| 3048 | + | |
| 3049 | + /** | |
| 3050 | + * @param {HTMLElement} button | |
| 3051 | + * @param {'confirm' | 'deny' | 'cancel'} buttonType | |
| 3052 | + * @param {SweetAlertOptions} params | |
| 3053 | + */ | |
| 3054 | + function renderButton(button, buttonType, params) { | |
| 3055 | + const buttonName = /** @type {'Confirm' | 'Deny' | 'Cancel'} */capitalizeFirstLetter(buttonType); | |
| 3056 | + toggle(button, params[`show${buttonName}Button`], 'inline-block'); | |
| 3057 | + setInnerHtml(button, params[`${buttonType}ButtonText`] || ''); // Set caption text | |
| 3058 | + button.setAttribute('aria-label', params[`${buttonType}ButtonAriaLabel`] || ''); // ARIA label | |
| 3059 | + | |
| 3060 | + // Add buttons custom classes | |
| 3061 | + button.className = swalClasses[buttonType]; | |
| 3062 | + applyCustomClass(button, params, `${buttonType}Button`); | |
| 3063 | + } | |
| 3064 | + | |
| 3065 | + /** | |
| 3066 | + * @param {SweetAlert} instance | |
| 3067 | + * @param {SweetAlertOptions} params | |
| 3068 | + */ | |
| 3069 | + const renderCloseButton = (instance, params) => { | |
| 3070 | + const closeButton = getCloseButton(); | |
| 3071 | + if (!closeButton) { | |
| 3072 | + return; | |
| 3073 | + } | |
| 3074 | + setInnerHtml(closeButton, params.closeButtonHtml || ''); | |
| 3075 | + | |
| 3076 | + // Custom class | |
| 3077 | + applyCustomClass(closeButton, params, 'closeButton'); | |
| 3078 | + toggle(closeButton, params.showCloseButton); | |
| 3079 | + closeButton.setAttribute('aria-label', params.closeButtonAriaLabel || ''); | |
| 3080 | + }; | |
| 3081 | + | |
| 3082 | + /** | |
| 3083 | + * @param {SweetAlert} instance | |
| 3084 | + * @param {SweetAlertOptions} params | |
| 3085 | + */ | |
| 3086 | + const renderContainer = (instance, params) => { | |
| 3087 | + const container = getContainer(); | |
| 3088 | + if (!container) { | |
| 3089 | + return; | |
| 3090 | + } | |
| 3091 | + handleBackdropParam(container, params.backdrop); | |
| 3092 | + handlePositionParam(container, params.position); | |
| 3093 | + handleGrowParam(container, params.grow); | |
| 3094 | + | |
| 3095 | + // Custom class | |
| 3096 | + applyCustomClass(container, params, 'container'); | |
| 3097 | + }; | |
| 3098 | + | |
| 3099 | + /** | |
| 3100 | + * @param {HTMLElement} container | |
| 3101 | + * @param {SweetAlertOptions['backdrop']} backdrop | |
| 3102 | + */ | |
| 3103 | + function handleBackdropParam(container, backdrop) { | |
| 3104 | + if (typeof backdrop === 'string') { | |
| 3105 | + container.style.background = backdrop; | |
| 3106 | + } else if (!backdrop) { | |
| 3107 | + addClass([document.documentElement, document.body], swalClasses['no-backdrop']); | |
| 3108 | + } | |
| 3109 | + } | |
| 3110 | + | |
| 3111 | + /** | |
| 3112 | + * @param {HTMLElement} container | |
| 3113 | + * @param {SweetAlertOptions['position']} position | |
| 3114 | + */ | |
| 3115 | + function handlePositionParam(container, position) { | |
| 3116 | + if (!position) { | |
| 3117 | + return; | |
| 3118 | + } | |
| 3119 | + if (position in swalClasses) { | |
| 3120 | + addClass(container, swalClasses[position]); | |
| 3121 | + } else { | |
| 3122 | + warn('The "position" parameter is not valid, defaulting to "center"'); | |
| 3123 | + addClass(container, swalClasses.center); | |
| 3124 | + } | |
| 3125 | + } | |
| 3126 | + | |
| 3127 | + /** | |
| 3128 | + * @param {HTMLElement} container | |
| 3129 | + * @param {SweetAlertOptions['grow']} grow | |
| 3130 | + */ | |
| 3131 | + function handleGrowParam(container, grow) { | |
| 3132 | + if (!grow) { | |
| 3133 | + return; | |
| 3134 | + } | |
| 3135 | + addClass(container, swalClasses[`grow-${grow}`]); | |
| 3136 | + } | |
| 3137 | + | |
| 3138 | + /** | |
| 3139 | + * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has. | |
| 3140 | + * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` | |
| 3141 | + * This is the approach that Babel will probably take to implement private methods/fields | |
| 3142 | + * https://github.com/tc39/proposal-private-methods | |
| 3143 | + * https://github.com/babel/babel/pull/7555 | |
| 3144 | + * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* | |
| 3145 | + * then we can use that language feature. | |
| 3146 | + */ | |
| 3147 | + | |
| 3148 | + var privateProps = { | |
| 3149 | + innerParams: new WeakMap(), | |
| 3150 | + domCache: new WeakMap(), | |
| 3151 | + focusedElement: new WeakMap() | |
| 3152 | + }; | |
| 3153 | + | |
| 3154 | + /// <reference path="../../../../sweetalert2.d.ts"/> | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + /** @type {InputClass[]} */ | |
| 3158 | + const inputClasses = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; | |
| 3159 | + | |
| 3160 | + /** | |
| 3161 | + * @param {SweetAlert} instance | |
| 3162 | + * @param {SweetAlertOptions} params | |
| 3163 | + */ | |
| 3164 | + const renderInput = (instance, params) => { | |
| 3165 | + const popup = getPopup(); | |
| 3166 | + if (!popup) { | |
| 3167 | + return; | |
| 3168 | + } | |
| 3169 | + const innerParams = privateProps.innerParams.get(instance); | |
| 3170 | + const rerender = !innerParams || params.input !== innerParams.input; | |
| 3171 | + inputClasses.forEach(inputClass => { | |
| 3172 | + const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]); | |
| 3173 | + if (!inputContainer) { | |
| 3174 | + return; | |
| 3175 | + } | |
| 3176 | + | |
| 3177 | + // set attributes | |
| 3178 | + setAttributes(inputClass, params.inputAttributes); | |
| 3179 | + | |
| 3180 | + // set class | |
| 3181 | + inputContainer.className = swalClasses[inputClass]; | |
| 3182 | + if (rerender) { | |
| 3183 | + hide(inputContainer); | |
| 3184 | + } | |
| 3185 | + }); | |
| 3186 | + if (params.input) { | |
| 3187 | + if (rerender) { | |
| 3188 | + showInput(params); | |
| 3189 | + } | |
| 3190 | + // set custom class | |
| 3191 | + setCustomClass(params); | |
| 3192 | + } | |
| 3193 | + }; | |
| 3194 | + | |
| 3195 | + /** | |
| 3196 | + * @param {SweetAlertOptions} params | |
| 3197 | + */ | |
| 3198 | + const showInput = params => { | |
| 3199 | + if (!params.input) { | |
| 3200 | + return; | |
| 3201 | + } | |
| 3202 | + if (!renderInputType[params.input]) { | |
| 3203 | + error(`Unexpected type of input! Expected ${Object.keys(renderInputType).join(' | ')}, got "${params.input}"`); | |
| 3204 | + return; | |
| 3205 | + } | |
| 3206 | + const inputContainer = getInputContainer(params.input); | |
| 3207 | + if (!inputContainer) { | |
| 3208 | + return; | |
| 3209 | + } | |
| 3210 | + const input = renderInputType[params.input](inputContainer, params); | |
| 3211 | + show(inputContainer); | |
| 3212 | + | |
| 3213 | + // input autofocus | |
| 3214 | + if (params.inputAutoFocus) { | |
| 3215 | + setTimeout(() => { | |
| 3216 | + focusInput(input); | |
| 3217 | + }); | |
| 3218 | + } | |
| 3219 | + }; | |
| 3220 | + | |
| 3221 | + /** | |
| 3222 | + * @param {HTMLInputElement} input | |
| 3223 | + */ | |
| 3224 | + const removeAttributes = input => { | |
| 3225 | + for (const { | |
| 3226 | + name | |
| 3227 | + } of Array.from(input.attributes)) { | |
| 3228 | + if (!['id', 'type', 'value', 'style'].includes(name)) { | |
| 3229 | + input.removeAttribute(name); | |
| 3230 | + } | |
| 3231 | + } | |
| 3232 | + }; | |
| 3233 | + | |
| 3234 | + /** | |
| 3235 | + * @param {InputClass} inputClass | |
| 3236 | + * @param {SweetAlertOptions['inputAttributes']} inputAttributes | |
| 3237 | + */ | |
| 3238 | + const setAttributes = (inputClass, inputAttributes) => { | |
| 3239 | + const popup = getPopup(); | |
| 3240 | + if (!popup) { | |
| 3241 | + return; | |
| 3242 | + } | |
| 3243 | + const input = getInput$1(popup, inputClass); | |
| 3244 | + if (!input) { | |
| 3245 | + return; | |
| 3246 | + } | |
| 3247 | + removeAttributes(input); | |
| 3248 | + for (const attr in inputAttributes) { | |
| 3249 | + input.setAttribute(attr, inputAttributes[attr]); | |
| 3250 | + } | |
| 3251 | + }; | |
| 3252 | + | |
| 3253 | + /** | |
| 3254 | + * @param {SweetAlertOptions} params | |
| 3255 | + */ | |
| 3256 | + const setCustomClass = params => { | |
| 3257 | + if (!params.input) { | |
| 3258 | + return; | |
| 3259 | + } | |
| 3260 | + const inputContainer = getInputContainer(params.input); | |
| 3261 | + if (inputContainer) { | |
| 3262 | + applyCustomClass(inputContainer, params, 'input'); | |
| 3263 | + } | |
| 3264 | + }; | |
| 3265 | + | |
| 3266 | + /** | |
| 3267 | + * @param {HTMLInputElement | HTMLTextAreaElement} input | |
| 3268 | + * @param {SweetAlertOptions} params | |
| 3269 | + */ | |
| 3270 | + const setInputPlaceholder = (input, params) => { | |
| 3271 | + if (!input.placeholder && params.inputPlaceholder) { | |
| 3272 | + input.placeholder = params.inputPlaceholder; | |
| 3273 | + } | |
| 3274 | + }; | |
| 3275 | + | |
| 3276 | + /** | |
| 3277 | + * @param {Input} input | |
| 3278 | + * @param {Input} prependTo | |
| 3279 | + * @param {SweetAlertOptions} params | |
| 3280 | + */ | |
| 3281 | + const setInputLabel = (input, prependTo, params) => { | |
| 3282 | + if (params.inputLabel) { | |
| 3283 | + const label = document.createElement('label'); | |
| 3284 | + const labelClass = swalClasses['input-label']; | |
| 3285 | + label.setAttribute('for', input.id); | |
| 3286 | + label.className = labelClass; | |
| 3287 | + if (typeof params.customClass === 'object') { | |
| 3288 | + addClass(label, params.customClass.inputLabel); | |
| 3289 | + } | |
| 3290 | + label.innerText = params.inputLabel; | |
| 3291 | + prependTo.insertAdjacentElement('beforebegin', label); | |
| 3292 | + } | |
| 3293 | + }; | |
| 3294 | + | |
| 3295 | + /** | |
| 3296 | + * @param {SweetAlertInput} inputType | |
| 3297 | + * @returns {HTMLElement | undefined} | |
| 3298 | + */ | |
| 3299 | + const getInputContainer = inputType => { | |
| 3300 | + const popup = getPopup(); | |
| 3301 | + if (!popup) { | |
| 3302 | + return; | |
| 3303 | + } | |
| 3304 | + return getDirectChildByClass(popup, swalClasses[(/** @type {SwalClass} */inputType)] || swalClasses.input); | |
| 3305 | + }; | |
| 3306 | + | |
| 3307 | + /** | |
| 3308 | + * @param {HTMLInputElement | HTMLOutputElement | HTMLTextAreaElement} input | |
| 3309 | + * @param {SweetAlertOptions['inputValue']} inputValue | |
| 3310 | + */ | |
| 3311 | + const checkAndSetInputValue = (input, inputValue) => { | |
| 3312 | + if (['string', 'number'].includes(typeof inputValue)) { | |
| 3313 | + input.value = `${inputValue}`; | |
| 3314 | + } else if (!isPromise(inputValue)) { | |
| 3315 | + warn(`Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof inputValue}"`); | |
| 3316 | + } | |
| 3317 | + }; | |
| 3318 | + | |
| 3319 | + /** @type {Record<SweetAlertInput, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */ | |
| 3320 | + const renderInputType = {}; | |
| 3321 | + | |
| 3322 | + /** | |
| 3323 | + * @param {Input | HTMLElement} input | |
| 3324 | + * @param {SweetAlertOptions} params | |
| 3325 | + * @returns {Input} | |
| 3326 | + */ | |
| 3327 | + renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = renderInputType.search = renderInputType.date = renderInputType['datetime-local'] = renderInputType.time = renderInputType.week = renderInputType.month = /** @type {(input: Input | HTMLElement, params: SweetAlertOptions) => Input} */ | |
| 3328 | + (input, params) => { | |
| 3329 | + // oxfmt-ignore | |
| 3330 | + const inputElement = /** @type {HTMLInputElement} */input; | |
| 3331 | + checkAndSetInputValue(inputElement, params.inputValue); | |
| 3332 | + setInputLabel(inputElement, inputElement, params); | |
| 3333 | + setInputPlaceholder(inputElement, params); | |
| 3334 | + // oxfmt-ignore | |
| 3335 | + inputElement.type = /** @type {string} */params.input; | |
| 3336 | + return inputElement; | |
| 3337 | + }; | |
| 3338 | + | |
| 3339 | + /** | |
| 3340 | + * @param {Input | HTMLElement} input | |
| 3341 | + * @param {SweetAlertOptions} params | |
| 3342 | + * @returns {Input} | |
| 3343 | + */ | |
| 3344 | + renderInputType.file = (input, params) => { | |
| 3345 | + const inputElement = /** @type {HTMLInputElement} */input; | |
| 3346 | + setInputLabel(inputElement, inputElement, params); | |
| 3347 | + setInputPlaceholder(inputElement, params); | |
| 3348 | + return inputElement; | |
| 3349 | + }; | |
| 3350 | + | |
| 3351 | + /** | |
| 3352 | + * @param {Input | HTMLElement} range | |
| 3353 | + * @param {SweetAlertOptions} params | |
| 3354 | + * @returns {Input} | |
| 3355 | + */ | |
| 3356 | + renderInputType.range = (range, params) => { | |
| 3357 | + const rangeContainer = /** @type {HTMLElement} */range; | |
| 3358 | + const rangeInput = rangeContainer.querySelector('input'); | |
| 3359 | + const rangeOutput = rangeContainer.querySelector('output'); | |
| 3360 | + if (rangeInput) { | |
| 3361 | + checkAndSetInputValue(rangeInput, params.inputValue); | |
| 3362 | + rangeInput.type = /** @type {string} */params.input; | |
| 3363 | + setInputLabel(rangeInput, /** @type {Input} */range, params); | |
| 3364 | + } | |
| 3365 | + if (rangeOutput) { | |
| 3366 | + checkAndSetInputValue(rangeOutput, params.inputValue); | |
| 3367 | + } | |
| 3368 | + return /** @type {Input} */range; | |
| 3369 | + }; | |
| 3370 | + | |
| 3371 | + /** | |
| 3372 | + * @param {Input | HTMLElement} select | |
| 3373 | + * @param {SweetAlertOptions} params | |
| 3374 | + * @returns {Input} | |
| 3375 | + */ | |
| 3376 | + renderInputType.select = (select, params) => { | |
| 3377 | + const selectElement = /** @type {HTMLSelectElement} */select; | |
| 3378 | + selectElement.textContent = ''; | |
| 3379 | + if (params.inputPlaceholder) { | |
| 3380 | + const placeholder = document.createElement('option'); | |
| 3381 | + setInnerHtml(placeholder, params.inputPlaceholder); | |
| 3382 | + placeholder.value = ''; | |
| 3383 | + placeholder.disabled = true; | |
| 3384 | + placeholder.selected = true; | |
| 3385 | + selectElement.appendChild(placeholder); | |
| 3386 | + } | |
| 3387 | + setInputLabel(selectElement, selectElement, params); | |
| 3388 | + return selectElement; | |
| 3389 | + }; | |
| 3390 | + | |
| 3391 | + /** | |
| 3392 | + * @param {Input | HTMLElement} radio | |
| 3393 | + * @returns {Input} | |
| 3394 | + */ | |
| 3395 | + renderInputType.radio = radio => { | |
| 3396 | + const radioElement = /** @type {HTMLElement} */radio; | |
| 3397 | + radioElement.textContent = ''; | |
| 3398 | + return /** @type {Input} */radio; | |
| 3399 | + }; | |
| 3400 | + | |
| 3401 | + /** | |
| 3402 | + * @param {Input | HTMLElement} checkboxContainer | |
| 3403 | + * @param {SweetAlertOptions} params | |
| 3404 | + * @returns {Input} | |
| 3405 | + */ | |
| 3406 | + renderInputType.checkbox = (checkboxContainer, params) => { | |
| 3407 | + const popup = getPopup(); | |
| 3408 | + if (!popup) { | |
| 3409 | + throw new Error('Popup not found'); | |
| 3410 | + } | |
| 3411 | + const checkbox = getInput$1(popup, 'checkbox'); | |
| 3412 | + if (!checkbox) { | |
| 3413 | + throw new Error('Checkbox input not found'); | |
| 3414 | + } | |
| 3415 | + checkbox.value = '1'; | |
| 3416 | + checkbox.checked = Boolean(params.inputValue); | |
| 3417 | + const containerElement = /** @type {HTMLElement} */checkboxContainer; | |
| 3418 | + const label = containerElement.querySelector('span'); | |
| 3419 | + if (label) { | |
| 3420 | + const placeholderOrLabel = params.inputPlaceholder || params.inputLabel; | |
| 3421 | + if (placeholderOrLabel) { | |
| 3422 | + setInnerHtml(label, placeholderOrLabel); | |
| 3423 | + } | |
| 3424 | + } | |
| 3425 | + return checkbox; | |
| 3426 | + }; | |
| 3427 | + | |
| 3428 | + /** | |
| 3429 | + * @param {Input | HTMLElement} textarea | |
| 3430 | + * @param {SweetAlertOptions} params | |
| 3431 | + * @returns {Input} | |
| 3432 | + */ | |
| 3433 | + renderInputType.textarea = (textarea, params) => { | |
| 3434 | + const textareaElement = /** @type {HTMLTextAreaElement} */textarea; | |
| 3435 | + checkAndSetInputValue(textareaElement, params.inputValue); | |
| 3436 | + setInputPlaceholder(textareaElement, params); | |
| 3437 | + setInputLabel(textareaElement, textareaElement, params); | |
| 3438 | + | |
| 3439 | + /** | |
| 3440 | + * @param {HTMLElement} el | |
| 3441 | + * @returns {number} | |
| 3442 | + */ | |
| 3443 | + const getMargin = el => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight); | |
| 3444 | + | |
| 3445 | + // https://github.com/sweetalert2/sweetalert2/issues/2291 | |
| 3446 | + setTimeout(() => { | |
| 3447 | + // https://github.com/sweetalert2/sweetalert2/issues/1699 | |
| 3448 | + if ('MutationObserver' in window) { | |
| 3449 | + const popup = getPopup(); | |
| 3450 | + if (!popup) { | |
| 3451 | + return; | |
| 3452 | + } | |
| 3453 | + const initialPopupWidth = parseInt(window.getComputedStyle(popup).width); | |
| 3454 | + const textareaResizeHandler = () => { | |
| 3455 | + // check if texarea is still in document (i.e. popup wasn't closed in the meantime) | |
| 3456 | + if (!document.body.contains(textareaElement)) { | |
| 3457 | + return; | |
| 3458 | + } | |
| 3459 | + const textareaWidth = textareaElement.offsetWidth + getMargin(textareaElement); | |
| 3460 | + const popupElement = getPopup(); | |
| 3461 | + if (popupElement) { | |
| 3462 | + if (textareaWidth > initialPopupWidth) { | |
| 3463 | + popupElement.style.width = `${textareaWidth}px`; | |
| 3464 | + } else { | |
| 3465 | + applyNumericalStyle(popupElement, 'width', params.width); | |
| 3466 | + } | |
| 3467 | + } | |
| 3468 | + }; | |
| 3469 | + new MutationObserver(textareaResizeHandler).observe(textareaElement, { | |
| 3470 | + attributes: true, | |
| 3471 | + attributeFilter: ['style'] | |
| 3472 | + }); | |
| 3473 | + } | |
| 3474 | + }); | |
| 3475 | + return textareaElement; | |
| 3476 | + }; | |
| 3477 | + | |
| 3478 | + /** | |
| 3479 | + * @param {SweetAlert} instance | |
| 3480 | + * @param {SweetAlertOptions} params | |
| 3481 | + */ | |
| 3482 | + const renderContent = (instance, params) => { | |
| 3483 | + const htmlContainer = getHtmlContainer(); | |
| 3484 | + if (!htmlContainer) { | |
| 3485 | + return; | |
| 3486 | + } | |
| 3487 | + showWhenInnerHtmlPresent(htmlContainer); | |
| 3488 | + applyCustomClass(htmlContainer, params, 'htmlContainer'); | |
| 3489 | + | |
| 3490 | + // Content as HTML | |
| 3491 | + if (params.html) { | |
| 3492 | + parseHtmlToContainer(params.html, htmlContainer); | |
| 3493 | + show(htmlContainer, 'block'); | |
| 3494 | + } | |
| 3495 | + | |
| 3496 | + // Content as plain text | |
| 3497 | + else if (params.text) { | |
| 3498 | + htmlContainer.textContent = params.text; | |
| 3499 | + show(htmlContainer, 'block'); | |
| 3500 | + } | |
| 3501 | + | |
| 3502 | + // No content | |
| 3503 | + else { | |
| 3504 | + hide(htmlContainer); | |
| 3505 | + } | |
| 3506 | + renderInput(instance, params); | |
| 3507 | + }; | |
| 3508 | + | |
| 3509 | + /** | |
| 3510 | + * @param {SweetAlert} instance | |
| 3511 | + * @param {SweetAlertOptions} params | |
| 3512 | + */ | |
| 3513 | + const renderFooter = (instance, params) => { | |
| 3514 | + const footer = getFooter(); | |
| 3515 | + if (!footer) { | |
| 3516 | + return; | |
| 3517 | + } | |
| 3518 | + showWhenInnerHtmlPresent(footer); | |
| 3519 | + toggle(footer, Boolean(params.footer), 'block'); | |
| 3520 | + if (params.footer) { | |
| 3521 | + parseHtmlToContainer(params.footer, footer); | |
| 3522 | + } | |
| 3523 | + | |
| 3524 | + // Custom class | |
| 3525 | + applyCustomClass(footer, params, 'footer'); | |
| 3526 | + }; | |
| 3527 | + | |
| 3528 | + /** | |
| 3529 | + * @param {SweetAlert} instance | |
| 3530 | + * @param {SweetAlertOptions} params | |
| 3531 | + */ | |
| 3532 | + const renderIcon = (instance, params) => { | |
| 3533 | + const innerParams = privateProps.innerParams.get(instance); | |
| 3534 | + const icon = getIcon(); | |
| 3535 | + if (!icon) { | |
| 3536 | + return; | |
| 3537 | + } | |
| 3538 | + | |
| 3539 | + // if the given icon already rendered, apply the styling without re-rendering the icon | |
| 3540 | + if (innerParams && params.icon === innerParams.icon) { | |
| 3541 | + // Custom or default content | |
| 3542 | + setContent(icon, params); | |
| 3543 | + applyStyles(icon, params); | |
| 3544 | + return; | |
| 3545 | + } | |
| 3546 | + if (!params.icon && !params.iconHtml) { | |
| 3547 | + hide(icon); | |
| 3548 | + return; | |
| 3549 | + } | |
| 3550 | + if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) { | |
| 3551 | + error(`Unknown icon! Expected "success", "error", "warning", "info" or "question", got "${params.icon}"`); | |
| 3552 | + hide(icon); | |
| 3553 | + return; | |
| 3554 | + } | |
| 3555 | + show(icon); | |
| 3556 | + | |
| 3557 | + // Custom or default content | |
| 3558 | + setContent(icon, params); | |
| 3559 | + applyStyles(icon, params); | |
| 3560 | + | |
| 3561 | + // Animate icon | |
| 3562 | + addClass(icon, params.showClass && params.showClass.icon); | |
| 3563 | + | |
| 3564 | + // Re-adjust the success icon on system theme change | |
| 3565 | + const colorSchemeQueryList = window.matchMedia('(prefers-color-scheme: dark)'); | |
| 3566 | + colorSchemeQueryList.addEventListener('change', adjustSuccessIconBackgroundColor); | |
| 3567 | + }; | |
| 3568 | + | |
| 3569 | + /** | |
| 3570 | + * @param {HTMLElement} icon | |
| 3571 | + * @param {SweetAlertOptions} params | |
| 3572 | + */ | |
| 3573 | + const applyStyles = (icon, params) => { | |
| 3574 | + for (const [iconType, iconClassName] of Object.entries(iconTypes)) { | |
| 3575 | + if (params.icon !== iconType) { | |
| 3576 | + removeClass(icon, iconClassName); | |
| 3577 | + } | |
| 3578 | + } | |
| 3579 | + addClass(icon, params.icon && iconTypes[params.icon]); | |
| 3580 | + | |
| 3581 | + // Icon color | |
| 3582 | + setColor(icon, params); | |
| 3583 | + | |
| 3584 | + // Success icon background color | |
| 3585 | + adjustSuccessIconBackgroundColor(); | |
| 3586 | + | |
| 3587 | + // Custom class | |
| 3588 | + applyCustomClass(icon, params, 'icon'); | |
| 3589 | + }; | |
| 3590 | + | |
| 3591 | + // Adjust success icon background color to match the popup background color | |
| 3592 | + const adjustSuccessIconBackgroundColor = () => { | |
| 3593 | + const popup = getPopup(); | |
| 3594 | + if (!popup) { | |
| 3595 | + return; | |
| 3596 | + } | |
| 3597 | + const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color'); | |
| 3598 | + /** @type {NodeListOf<HTMLElement>} */ | |
| 3599 | + const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); | |
| 3600 | + successIconParts.forEach(part => { | |
| 3601 | + part.style.backgroundColor = popupBackgroundColor; | |
| 3602 | + }); | |
| 3603 | + }; | |
| 3604 | + | |
| 3605 | + /** | |
| 3606 | + * | |
| 3607 | + * @param {SweetAlertOptions} params | |
| 3608 | + * @returns {string} | |
| 3609 | + */ | |
| 3610 | + const successIconHtml = params => ` | |
| 3611 | + ${params.animation ? '<div class="swal2-success-circular-line-left"></div>' : ''} | |
| 3612 | + <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span> | |
| 3613 | + <div class="swal2-success-ring"></div> | |
| 3614 | + ${params.animation ? '<div class="swal2-success-fix"></div>' : ''} | |
| 3615 | + ${params.animation ? '<div class="swal2-success-circular-line-right"></div>' : ''} | |
| 3616 | +`; | |
| 3617 | + const errorIconHtml = ` | |
| 3618 | + <span class="swal2-x-mark"> | |
| 3619 | + <span class="swal2-x-mark-line-left"></span> | |
| 3620 | + <span class="swal2-x-mark-line-right"></span> | |
| 3621 | + </span> | |
| 3622 | +`; | |
| 3623 | + | |
| 3624 | + /** | |
| 3625 | + * @param {HTMLElement} icon | |
| 3626 | + * @param {SweetAlertOptions} params | |
| 3627 | + */ | |
| 3628 | + const setContent = (icon, params) => { | |
| 3629 | + if (!params.icon && !params.iconHtml) { | |
| 3630 | + return; | |
| 3631 | + } | |
| 3632 | + let oldContent = icon.innerHTML; | |
| 3633 | + let newContent = ''; | |
| 3634 | + if (params.iconHtml) { | |
| 3635 | + newContent = iconContent(params.iconHtml); | |
| 3636 | + } else if (params.icon === 'success') { | |
| 3637 | + newContent = successIconHtml(params); | |
| 3638 | + oldContent = oldContent.replace(/ style=".*?"/g, ''); // undo adjustSuccessIconBackgroundColor() | |
| 3639 | + } else if (params.icon === 'error') { | |
| 3640 | + newContent = errorIconHtml; | |
| 3641 | + } else if (params.icon) { | |
| 3642 | + const defaultIconHtml = { | |
| 3643 | + question: '?', | |
| 3644 | + warning: '!', | |
| 3645 | + info: 'i' | |
| 3646 | + }; | |
| 3647 | + newContent = iconContent(defaultIconHtml[params.icon]); | |
| 3648 | + } | |
| 3649 | + if (oldContent.trim() !== newContent.trim()) { | |
| 3650 | + setInnerHtml(icon, newContent); | |
| 3651 | + } | |
| 3652 | + }; | |
| 3653 | + | |
| 3654 | + /** | |
| 3655 | + * @param {HTMLElement} icon | |
| 3656 | + * @param {SweetAlertOptions} params | |
| 3657 | + */ | |
| 3658 | + const setColor = (icon, params) => { | |
| 3659 | + if (!params.iconColor) { | |
| 3660 | + return; | |
| 3661 | + } | |
| 3662 | + icon.style.color = params.iconColor; | |
| 3663 | + icon.style.borderColor = params.iconColor; | |
| 3664 | + for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) { | |
| 3665 | + setStyle(icon, sel, 'background-color', params.iconColor); | |
| 3666 | + } | |
| 3667 | + setStyle(icon, '.swal2-success-ring', 'border-color', params.iconColor); | |
| 3668 | + }; | |
| 3669 | + | |
| 3670 | + /** | |
| 3671 | + * @param {string} content | |
| 3672 | + * @returns {string} | |
| 3673 | + */ | |
| 3674 | + const iconContent = content => `<div class="${swalClasses['icon-content']}">${content}</div>`; | |
| 3675 | + | |
| 3676 | + /** | |
| 3677 | + * @param {SweetAlert} instance | |
| 3678 | + * @param {SweetAlertOptions} params | |
| 3679 | + */ | |
| 3680 | + const renderImage = (instance, params) => { | |
| 3681 | + const image = getImage(); | |
| 3682 | + if (!image) { | |
| 3683 | + return; | |
| 3684 | + } | |
| 3685 | + if (!params.imageUrl) { | |
| 3686 | + hide(image); | |
| 3687 | + return; | |
| 3688 | + } | |
| 3689 | + show(image, ''); | |
| 3690 | + | |
| 3691 | + // Src, alt | |
| 3692 | + image.setAttribute('src', params.imageUrl); | |
| 3693 | + image.setAttribute('alt', params.imageAlt || ''); | |
| 3694 | + | |
| 3695 | + // Width, height | |
| 3696 | + applyNumericalStyle(image, 'width', params.imageWidth); | |
| 3697 | + applyNumericalStyle(image, 'height', params.imageHeight); | |
| 3698 | + | |
| 3699 | + // Class | |
| 3700 | + image.className = swalClasses.image; | |
| 3701 | + applyCustomClass(image, params, 'image'); | |
| 3702 | + }; | |
| 3703 | + | |
| 3704 | + let dragging = false; | |
| 3705 | + let mousedownX = 0; | |
| 3706 | + let mousedownY = 0; | |
| 3707 | + let initialX = 0; | |
| 3708 | + let initialY = 0; | |
| 3709 | + | |
| 3710 | + /** | |
| 3711 | + * @param {HTMLElement} popup | |
| 3712 | + */ | |
| 3713 | + const addDraggableListeners = popup => { | |
| 3714 | + popup.addEventListener('mousedown', down); | |
| 3715 | + document.body.addEventListener('mousemove', move); | |
| 3716 | + popup.addEventListener('mouseup', up); | |
| 3717 | + popup.addEventListener('touchstart', down); | |
| 3718 | + document.body.addEventListener('touchmove', move); | |
| 3719 | + popup.addEventListener('touchend', up); | |
| 3720 | + }; | |
| 3721 | + | |
| 3722 | + /** | |
| 3723 | + * @param {HTMLElement} popup | |
| 3724 | + */ | |
| 3725 | + const removeDraggableListeners = popup => { | |
| 3726 | + popup.removeEventListener('mousedown', down); | |
| 3727 | + document.body.removeEventListener('mousemove', move); | |
| 3728 | + popup.removeEventListener('mouseup', up); | |
| 3729 | + popup.removeEventListener('touchstart', down); | |
| 3730 | + document.body.removeEventListener('touchmove', move); | |
| 3731 | + popup.removeEventListener('touchend', up); | |
| 3732 | + }; | |
| 3733 | + | |
| 3734 | + /** | |
| 3735 | + * @param {MouseEvent | TouchEvent} event | |
| 3736 | + */ | |
| 3737 | + const down = event => { | |
| 3738 | + const popup = getPopup(); | |
| 3739 | + if (!popup) { | |
| 3740 | + return; | |
| 3741 | + } | |
| 3742 | + const icon = getIcon(); | |
| 3743 | + if (event.target === popup || icon && icon.contains(/** @type {HTMLElement} */event.target)) { | |
| 3744 | + dragging = true; | |
| 3745 | + const clientXY = getClientXY(event); | |
| 3746 | + mousedownX = clientXY.clientX; | |
| 3747 | + mousedownY = clientXY.clientY; | |
| 3748 | + initialX = parseInt(popup.style.insetInlineStart) || 0; | |
| 3749 | + initialY = parseInt(popup.style.insetBlockStart) || 0; | |
| 3750 | + addClass(popup, 'swal2-dragging'); | |
| 3751 | + } | |
| 3752 | + }; | |
| 3753 | + | |
| 3754 | + /** | |
| 3755 | + * @param {MouseEvent | TouchEvent} event | |
| 3756 | + */ | |
| 3757 | + const move = event => { | |
| 3758 | + const popup = getPopup(); | |
| 3759 | + if (!popup) { | |
| 3760 | + return; | |
| 3761 | + } | |
| 3762 | + if (dragging) { | |
| 3763 | + let { | |
| 3764 | + clientX, | |
| 3765 | + clientY | |
| 3766 | + } = getClientXY(event); | |
| 3767 | + const deltaX = clientX - mousedownX; | |
| 3768 | + // In RTL mode, negate the horizontal delta since insetInlineStart refers to the right edge | |
| 3769 | + popup.style.insetInlineStart = `${initialX + (globalState.isRTL ? -deltaX : deltaX)}px`; | |
| 3770 | + popup.style.insetBlockStart = `${initialY + (clientY - mousedownY)}px`; | |
| 3771 | + } | |
| 3772 | + }; | |
| 3773 | + const up = () => { | |
| 3774 | + const popup = getPopup(); | |
| 3775 | + dragging = false; | |
| 3776 | + removeClass(popup, 'swal2-dragging'); | |
| 3777 | + }; | |
| 3778 | + | |
| 3779 | + /** | |
| 3780 | + * @param {MouseEvent | TouchEvent} event | |
| 3781 | + * @returns {{ clientX: number, clientY: number }} | |
| 3782 | + */ | |
| 3783 | + const getClientXY = event => { | |
| 3784 | + const source = event.type.startsWith('touch') ? /** @type {TouchEvent} */event.touches[0] : (/** @type {MouseEvent} */event); | |
| 3785 | + return { | |
| 3786 | + clientX: source.clientX, | |
| 3787 | + clientY: source.clientY | |
| 3788 | + }; | |
| 3789 | + }; | |
| 3790 | + | |
| 3791 | + /** | |
| 3792 | + * @param {SweetAlert} instance | |
| 3793 | + * @param {SweetAlertOptions} params | |
| 3794 | + */ | |
| 3795 | + const renderPopup = (instance, params) => { | |
| 3796 | + const container = getContainer(); | |
| 3797 | + const popup = getPopup(); | |
| 3798 | + if (!container || !popup) { | |
| 3799 | + return; | |
| 3800 | + } | |
| 3801 | + | |
| 3802 | + // Width | |
| 3803 | + // https://github.com/sweetalert2/sweetalert2/issues/2170 | |
| 3804 | + if (params.toast) { | |
| 3805 | + applyNumericalStyle(container, 'width', params.width); | |
| 3806 | + popup.style.width = '100%'; | |
| 3807 | + const loader = getLoader(); | |
| 3808 | + if (loader) { | |
| 3809 | + popup.insertBefore(loader, getIcon()); | |
| 3810 | + } | |
| 3811 | + } else { | |
| 3812 | + applyNumericalStyle(popup, 'width', params.width); | |
| 3813 | + } | |
| 3814 | + | |
| 3815 | + // Padding | |
| 3816 | + applyNumericalStyle(popup, 'padding', params.padding); | |
| 3817 | + | |
| 3818 | + // Color | |
| 3819 | + if (params.color) { | |
| 3820 | + popup.style.color = params.color; | |
| 3821 | + } | |
| 3822 | + | |
| 3823 | + // Background | |
| 3824 | + if (params.background) { | |
| 3825 | + popup.style.background = params.background; | |
| 3826 | + } | |
| 3827 | + hide(getValidationMessage()); | |
| 3828 | + | |
| 3829 | + // Classes | |
| 3830 | + addClasses$1(popup, params); | |
| 3831 | + if (params.draggable && !params.toast) { | |
| 3832 | + addClass(popup, swalClasses.draggable); | |
| 3833 | + addDraggableListeners(popup); | |
| 3834 | + } else { | |
| 3835 | + removeClass(popup, swalClasses.draggable); | |
| 3836 | + removeDraggableListeners(popup); | |
| 3837 | + } | |
| 3838 | + }; | |
| 3839 | + | |
| 3840 | + /** | |
| 3841 | + * @param {HTMLElement} popup | |
| 3842 | + * @param {SweetAlertOptions} params | |
| 3843 | + */ | |
| 3844 | + const addClasses$1 = (popup, params) => { | |
| 3845 | + const showClass = params.showClass || {}; | |
| 3846 | + // Default Class + showClass when updating Swal.update({}) | |
| 3847 | + popup.className = `${swalClasses.popup} ${isVisible$1(popup) ? showClass.popup : ''}`; | |
| 3848 | + if (params.toast) { | |
| 3849 | + addClass([document.documentElement, document.body], swalClasses['toast-shown']); | |
| 3850 | + addClass(popup, swalClasses.toast); | |
| 3851 | + } else { | |
| 3852 | + addClass(popup, swalClasses.modal); | |
| 3853 | + } | |
| 3854 | + | |
| 3855 | + // Custom class | |
| 3856 | + applyCustomClass(popup, params, 'popup'); | |
| 3857 | + // TODO: remove in the next major | |
| 3858 | + if (typeof params.customClass === 'string') { | |
| 3859 | + addClass(popup, params.customClass); | |
| 3860 | + } | |
| 3861 | + | |
| 3862 | + // Icon class (#1842) | |
| 3863 | + if (params.icon) { | |
| 3864 | + addClass(popup, swalClasses[`icon-${params.icon}`]); | |
| 3865 | + } | |
| 3866 | + }; | |
| 3867 | + | |
| 3868 | + /** | |
| 3869 | + * @param {SweetAlert} instance | |
| 3870 | + * @param {SweetAlertOptions} params | |
| 3871 | + */ | |
| 3872 | + const renderProgressSteps = (instance, params) => { | |
| 3873 | + const progressStepsContainer = getProgressSteps(); | |
| 3874 | + if (!progressStepsContainer) { | |
| 3875 | + return; | |
| 3876 | + } | |
| 3877 | + const { | |
| 3878 | + progressSteps, | |
| 3879 | + currentProgressStep | |
| 3880 | + } = params; | |
| 3881 | + if (!progressSteps || progressSteps.length === 0 || currentProgressStep === undefined) { | |
| 3882 | + hide(progressStepsContainer); | |
| 3883 | + return; | |
| 3884 | + } | |
| 3885 | + show(progressStepsContainer); | |
| 3886 | + progressStepsContainer.textContent = ''; | |
| 3887 | + if (currentProgressStep >= progressSteps.length) { | |
| 3888 | + warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); | |
| 3889 | + } | |
| 3890 | + progressSteps.forEach((step, index) => { | |
| 3891 | + const stepEl = createStepElement(step); | |
| 3892 | + progressStepsContainer.appendChild(stepEl); | |
| 3893 | + if (index === currentProgressStep) { | |
| 3894 | + addClass(stepEl, swalClasses['active-progress-step']); | |
| 3895 | + } | |
| 3896 | + if (index !== progressSteps.length - 1) { | |
| 3897 | + const lineEl = createLineElement(params); | |
| 3898 | + progressStepsContainer.appendChild(lineEl); | |
| 3899 | + } | |
| 3900 | + }); | |
| 3901 | + }; | |
| 3902 | + | |
| 3903 | + /** | |
| 3904 | + * @param {string} step | |
| 3905 | + * @returns {HTMLLIElement} | |
| 3906 | + */ | |
| 3907 | + const createStepElement = step => { | |
| 3908 | + const stepEl = document.createElement('li'); | |
| 3909 | + addClass(stepEl, swalClasses['progress-step']); | |
| 3910 | + setInnerHtml(stepEl, step); | |
| 3911 | + return stepEl; | |
| 3912 | + }; | |
| 3913 | + | |
| 3914 | + /** | |
| 3915 | + * @param {SweetAlertOptions} params | |
| 3916 | + * @returns {HTMLLIElement} | |
| 3917 | + */ | |
| 3918 | + const createLineElement = params => { | |
| 3919 | + const lineEl = document.createElement('li'); | |
| 3920 | + addClass(lineEl, swalClasses['progress-step-line']); | |
| 3921 | + if (params.progressStepsDistance) { | |
| 3922 | + applyNumericalStyle(lineEl, 'width', params.progressStepsDistance); | |
| 3923 | + } | |
| 3924 | + return lineEl; | |
| 3925 | + }; | |
| 3926 | + | |
| 3927 | + /** | |
| 3928 | + * @param {SweetAlert} instance | |
| 3929 | + * @param {SweetAlertOptions} params | |
| 3930 | + */ | |
| 3931 | + const renderTitle = (instance, params) => { | |
| 3932 | + const title = getTitle(); | |
| 3933 | + if (!title) { | |
| 3934 | + return; | |
| 3935 | + } | |
| 3936 | + showWhenInnerHtmlPresent(title); | |
| 3937 | + toggle(title, Boolean(params.title || params.titleText), 'block'); | |
| 3938 | + if (params.title) { | |
| 3939 | + parseHtmlToContainer(params.title, title); | |
| 3940 | + } | |
| 3941 | + if (params.titleText) { | |
| 3942 | + title.innerText = params.titleText; | |
| 3943 | + } | |
| 3944 | + | |
| 3945 | + // Custom class | |
| 3946 | + applyCustomClass(title, params, 'title'); | |
| 3947 | + }; | |
| 3948 | + | |
| 3949 | + /** | |
| 3950 | + * @param {SweetAlert} instance | |
| 3951 | + * @param {SweetAlertOptions} params | |
| 3952 | + */ | |
| 3953 | + const render = (instance, params) => { | |
| 3954 | + var _globalState$eventEmi; | |
| 3955 | + renderPopup(instance, params); | |
| 3956 | + renderContainer(instance, params); | |
| 3957 | + renderProgressSteps(instance, params); | |
| 3958 | + renderIcon(instance, params); | |
| 3959 | + renderImage(instance, params); | |
| 3960 | + renderTitle(instance, params); | |
| 3961 | + renderCloseButton(instance, params); | |
| 3962 | + renderContent(instance, params); | |
| 3963 | + renderActions(instance, params); | |
| 3964 | + renderFooter(instance, params); | |
| 3965 | + const popup = getPopup(); | |
| 3966 | + if (typeof params.didRender === 'function' && popup) { | |
| 3967 | + params.didRender(popup); | |
| 3968 | + } | |
| 3969 | + (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('didRender', popup); | |
| 3970 | + }; | |
| 3971 | + | |
| 3972 | + /* | |
| 3973 | + * Global function to determine if SweetAlert2 popup is shown | |
| 3974 | + */ | |
| 3975 | + const isVisible = () => { | |
| 3976 | + return isVisible$1(getPopup()); | |
| 3977 | + }; | |
| 3978 | + | |
| 3979 | + /* | |
| 3980 | + * Global function to click 'Confirm' button | |
| 3981 | + */ | |
| 3982 | + const clickConfirm = () => { | |
| 3983 | + var _dom$getConfirmButton; | |
| 3984 | + return (_dom$getConfirmButton = getConfirmButton()) === null || _dom$getConfirmButton === void 0 ? void 0 : _dom$getConfirmButton.click(); | |
| 3985 | + }; | |
| 3986 | + | |
| 3987 | + /* | |
| 3988 | + * Global function to click 'Deny' button | |
| 3989 | + */ | |
| 3990 | + const clickDeny = () => { | |
| 3991 | + var _dom$getDenyButton; | |
| 3992 | + return (_dom$getDenyButton = getDenyButton()) === null || _dom$getDenyButton === void 0 ? void 0 : _dom$getDenyButton.click(); | |
| 3993 | + }; | |
| 3994 | + | |
| 3995 | + /* | |
| 3996 | + * Global function to click 'Cancel' button | |
| 3997 | + */ | |
| 3998 | + const clickCancel = () => { | |
| 3999 | + var _dom$getCancelButton; | |
| 4000 | + return (_dom$getCancelButton = getCancelButton()) === null || _dom$getCancelButton === void 0 ? void 0 : _dom$getCancelButton.click(); | |
| 4001 | + }; | |
| 4002 | + | |
| 4003 | + /** @type {Record<DismissReason, DismissReason>} */ | |
| 4004 | + const DismissReason = Object.freeze({ | |
| 4005 | + cancel: 'cancel', | |
| 4006 | + backdrop: 'backdrop', | |
| 4007 | + close: 'close', | |
| 4008 | + esc: 'esc', | |
| 4009 | + timer: 'timer' | |
| 4010 | + }); | |
| 4011 | + | |
| 4012 | + /** | |
| 4013 | + * @param {GlobalState} globalState | |
| 4014 | + */ | |
| 4015 | + const removeKeydownHandler = globalState => { | |
| 4016 | + if (globalState.keydownTarget && globalState.keydownHandlerAdded && globalState.keydownHandler) { | |
| 4017 | + const handler = /** @type {EventListenerOrEventListenerObject} */ | |
| 4018 | + /** @type {unknown} */globalState.keydownHandler; | |
| 4019 | + globalState.keydownTarget.removeEventListener('keydown', handler, { | |
| 4020 | + capture: globalState.keydownListenerCapture | |
| 4021 | + }); | |
| 4022 | + globalState.keydownHandlerAdded = false; | |
| 4023 | + } | |
| 4024 | + }; | |
| 4025 | + | |
| 4026 | + /** | |
| 4027 | + * @param {GlobalState} globalState | |
| 4028 | + * @param {SweetAlertOptions} innerParams | |
| 4029 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 4030 | + */ | |
| 4031 | + const addKeydownHandler = (globalState, innerParams, dismissWith) => { | |
| 4032 | + removeKeydownHandler(globalState); | |
| 4033 | + if (!innerParams.toast) { | |
| 4034 | + /** @type {(this: HTMLElement, event: KeyboardEvent) => void} */ | |
| 4035 | + const handler = e => keydownHandler(innerParams, e, dismissWith); | |
| 4036 | + globalState.keydownHandler = handler; | |
| 4037 | + const target = innerParams.keydownListenerCapture ? window : getPopup(); | |
| 4038 | + if (target) { | |
| 4039 | + globalState.keydownTarget = target; | |
| 4040 | + globalState.keydownListenerCapture = innerParams.keydownListenerCapture; | |
| 4041 | + const eventHandler = /** @type {EventListenerOrEventListenerObject} */ /** @type {unknown} */handler; | |
| 4042 | + globalState.keydownTarget.addEventListener('keydown', eventHandler, { | |
| 4043 | + capture: globalState.keydownListenerCapture | |
| 4044 | + }); | |
| 4045 | + globalState.keydownHandlerAdded = true; | |
| 4046 | + } | |
| 4047 | + } | |
| 4048 | + }; | |
| 4049 | + | |
| 4050 | + /** | |
| 4051 | + * @param {number} index | |
| 4052 | + * @param {number} increment | |
| 4053 | + * @returns {boolean} shouldPreventDefault | |
| 4054 | + */ | |
| 4055 | + const setFocus = (index, increment) => { | |
| 4056 | + var _dom$getPopup; | |
| 4057 | + const focusableElements = getFocusableElements(); | |
| 4058 | + // search for visible elements and select the next possible match | |
| 4059 | + if (focusableElements.length) { | |
| 4060 | + index = index + increment; | |
| 4061 | + | |
| 4062 | + // shift + tab when .swal2-popup is focused | |
| 4063 | + if (index === -2) { | |
| 4064 | + index = focusableElements.length - 1; | |
| 4065 | + } | |
| 4066 | + | |
| 4067 | + // rollover to first item | |
| 4068 | + if (index === focusableElements.length) { | |
| 4069 | + index = 0; | |
| 4070 | + | |
| 4071 | + // go to last item | |
| 4072 | + } else if (index === -1) { | |
| 4073 | + index = focusableElements.length - 1; | |
| 4074 | + } | |
| 4075 | + focusableElements[index].focus(); | |
| 4076 | + | |
| 4077 | + // don't prevent default for iframes (Firefox fix) | |
| 4078 | + // https://github.com/sweetalert2/sweetalert2/issues/2931 | |
| 4079 | + if (isFirefox() && focusableElements[index] instanceof HTMLIFrameElement) { | |
| 4080 | + return false; | |
| 4081 | + } | |
| 4082 | + return true; | |
| 4083 | + } | |
| 4084 | + // no visible focusable elements, focus the popup | |
| 4085 | + (_dom$getPopup = getPopup()) === null || _dom$getPopup === void 0 || _dom$getPopup.focus(); | |
| 4086 | + return true; | |
| 4087 | + }; | |
| 4088 | + const arrowKeysNextButton = ['ArrowRight', 'ArrowDown']; | |
| 4089 | + const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp']; | |
| 4090 | + | |
| 4091 | + /** | |
| 4092 | + * @param {SweetAlertOptions} innerParams | |
| 4093 | + * @param {KeyboardEvent} event | |
| 4094 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 4095 | + */ | |
| 4096 | + const keydownHandler = (innerParams, event, dismissWith) => { | |
| 4097 | + if (!innerParams) { | |
| 4098 | + return; // This instance has already been destroyed | |
| 4099 | + } | |
| 4100 | + | |
| 4101 | + // Ignore keydown during IME composition | |
| 4102 | + // https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition | |
| 4103 | + // https://github.com/sweetalert2/sweetalert2/issues/720 | |
| 4104 | + // https://github.com/sweetalert2/sweetalert2/issues/2406 | |
| 4105 | + if (event.isComposing || event.keyCode === 229) { | |
| 4106 | + return; | |
| 4107 | + } | |
| 4108 | + if (innerParams.stopKeydownPropagation) { | |
| 4109 | + event.stopPropagation(); | |
| 4110 | + } | |
| 4111 | + | |
| 4112 | + // ENTER | |
| 4113 | + if (event.key === 'Enter') { | |
| 4114 | + handleEnter(event, innerParams); | |
| 4115 | + } | |
| 4116 | + | |
| 4117 | + // TAB | |
| 4118 | + else if (event.key === 'Tab') { | |
| 4119 | + handleTab(event); | |
| 4120 | + } | |
| 4121 | + | |
| 4122 | + // ARROWS - switch focus between buttons | |
| 4123 | + else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(event.key)) { | |
| 4124 | + handleArrows(event.key); | |
| 4125 | + } | |
| 4126 | + | |
| 4127 | + // ESC | |
| 4128 | + else if (event.key === 'Escape') { | |
| 4129 | + handleEsc(event, innerParams, dismissWith); | |
| 4130 | + } | |
| 4131 | + }; | |
| 4132 | + | |
| 4133 | + /** | |
| 4134 | + * @param {KeyboardEvent} event | |
| 4135 | + * @param {SweetAlertOptions} innerParams | |
| 4136 | + */ | |
| 4137 | + const handleEnter = (event, innerParams) => { | |
| 4138 | + // https://github.com/sweetalert2/sweetalert2/issues/2386 | |
| 4139 | + if (!callIfFunction(innerParams.allowEnterKey)) { | |
| 4140 | + return; | |
| 4141 | + } | |
| 4142 | + const popup = getPopup(); | |
| 4143 | + if (!popup || !innerParams.input) { | |
| 4144 | + return; | |
| 4145 | + } | |
| 4146 | + const input = getInput$1(popup, innerParams.input); | |
| 4147 | + if (event.target && input && event.target instanceof HTMLElement && event.target.outerHTML === input.outerHTML) { | |
| 4148 | + if (['textarea', 'file'].includes(innerParams.input)) { | |
| 4149 | + return; // do not submit | |
| 4150 | + } | |
| 4151 | + clickConfirm(); | |
| 4152 | + event.preventDefault(); | |
| 4153 | + } | |
| 4154 | + }; | |
| 4155 | + | |
| 4156 | + /** | |
| 4157 | + * @param {KeyboardEvent} event | |
| 4158 | + */ | |
| 4159 | + const handleTab = event => { | |
| 4160 | + const targetElement = event.target; | |
| 4161 | + const focusableElements = getFocusableElements(); | |
| 4162 | + const btnIndex = focusableElements.findIndex(el => el === targetElement); | |
| 4163 | + | |
| 4164 | + // don't prevent default for iframes (Firefox fix) | |
| 4165 | + // https://github.com/sweetalert2/sweetalert2/issues/2931 | |
| 4166 | + let shouldPreventDefault = true; | |
| 4167 | + | |
| 4168 | + // Cycle to the next button | |
| 4169 | + if (!event.shiftKey) { | |
| 4170 | + shouldPreventDefault = setFocus(btnIndex, 1); | |
| 4171 | + } | |
| 4172 | + | |
| 4173 | + // Cycle to the prev button | |
| 4174 | + else { | |
| 4175 | + shouldPreventDefault = setFocus(btnIndex, -1); | |
| 4176 | + } | |
| 4177 | + event.stopPropagation(); | |
| 4178 | + if (shouldPreventDefault) { | |
| 4179 | + event.preventDefault(); | |
| 4180 | + } | |
| 4181 | + }; | |
| 4182 | + | |
| 4183 | + /** | |
| 4184 | + * @param {string} key | |
| 4185 | + */ | |
| 4186 | + const handleArrows = key => { | |
| 4187 | + const actions = getActions(); | |
| 4188 | + const confirmButton = getConfirmButton(); | |
| 4189 | + const denyButton = getDenyButton(); | |
| 4190 | + const cancelButton = getCancelButton(); | |
| 4191 | + if (!actions || !confirmButton || !denyButton || !cancelButton) { | |
| 4192 | + return; | |
| 4193 | + } | |
| 4194 | + /** @type HTMLElement[] */ | |
| 4195 | + const buttons = [confirmButton, denyButton, cancelButton]; | |
| 4196 | + if (document.activeElement instanceof HTMLElement && !buttons.includes(document.activeElement)) { | |
| 4197 | + return; | |
| 4198 | + } | |
| 4199 | + const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling'; | |
| 4200 | + let buttonToFocus = document.activeElement; | |
| 4201 | + if (!buttonToFocus) { | |
| 4202 | + return; | |
| 4203 | + } | |
| 4204 | + for (let i = 0; i < actions.children.length; i++) { | |
| 4205 | + buttonToFocus = buttonToFocus[sibling]; | |
| 4206 | + if (!buttonToFocus) { | |
| 4207 | + return; | |
| 4208 | + } | |
| 4209 | + if (buttonToFocus instanceof HTMLButtonElement && isVisible$1(buttonToFocus)) { | |
| 4210 | + break; | |
| 4211 | + } | |
| 4212 | + } | |
| 4213 | + if (buttonToFocus instanceof HTMLButtonElement) { | |
| 4214 | + buttonToFocus.focus(); | |
| 4215 | + } | |
| 4216 | + }; | |
| 4217 | + | |
| 4218 | + /** | |
| 4219 | + * @param {KeyboardEvent} event | |
| 4220 | + * @param {SweetAlertOptions} innerParams | |
| 4221 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 4222 | + */ | |
| 4223 | + const handleEsc = (event, innerParams, dismissWith) => { | |
| 4224 | + event.preventDefault(); | |
| 4225 | + if (callIfFunction(innerParams.allowEscapeKey)) { | |
| 4226 | + dismissWith(DismissReason.esc); | |
| 4227 | + } | |
| 4228 | + }; | |
| 4229 | + | |
| 4230 | + /** | |
| 4231 | + * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has. | |
| 4232 | + * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` | |
| 4233 | + * This is the approach that Babel will probably take to implement private methods/fields | |
| 4234 | + * https://github.com/tc39/proposal-private-methods | |
| 4235 | + * https://github.com/babel/babel/pull/7555 | |
| 4236 | + * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* | |
| 4237 | + * then we can use that language feature. | |
| 4238 | + */ | |
| 4239 | + | |
| 4240 | + var privateMethods = { | |
| 4241 | + swalPromiseResolve: new WeakMap(), | |
| 4242 | + swalPromiseReject: new WeakMap() | |
| 4243 | + }; | |
| 4244 | + | |
| 4245 | + // From https://developer.paciellogroup.com/blog/2018/06/the-current-state-of-modal-dialog-accessibility/ | |
| 4246 | + // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that | |
| 4247 | + // elements not within the active modal dialog will not be surfaced if a user opens a screen | |
| 4248 | + // reader’s list of elements (headings, form controls, landmarks, etc.) in the document. | |
| 4249 | + | |
| 4250 | + const setAriaHidden = () => { | |
| 4251 | + const container = getContainer(); | |
| 4252 | + const bodyChildren = Array.from(document.body.children); | |
| 4253 | + bodyChildren.forEach(el => { | |
| 4254 | + if (el.contains(container)) { | |
| 4255 | + return; | |
| 4256 | + } | |
| 4257 | + if (el.hasAttribute('aria-hidden')) { | |
| 4258 | + el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden') || ''); | |
| 4259 | + } | |
| 4260 | + el.setAttribute('aria-hidden', 'true'); | |
| 4261 | + }); | |
| 4262 | + }; | |
| 4263 | + const unsetAriaHidden = () => { | |
| 4264 | + const bodyChildren = Array.from(document.body.children); | |
| 4265 | + bodyChildren.forEach(el => { | |
| 4266 | + if (el.hasAttribute('data-previous-aria-hidden')) { | |
| 4267 | + el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden') || ''); | |
| 4268 | + el.removeAttribute('data-previous-aria-hidden'); | |
| 4269 | + } else { | |
| 4270 | + el.removeAttribute('aria-hidden'); | |
| 4271 | + } | |
| 4272 | + }); | |
| 4273 | + }; | |
| 4274 | + | |
| 4275 | + // @ts-ignore | |
| 4276 | + const isSafariOrIOS = typeof window !== 'undefined' && Boolean(window.GestureEvent); // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394 | |
| 4277 | + | |
| 4278 | + // @ts-ignore | |
| 4279 | + const isIOS = isSafariOrIOS && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; | |
| 4280 | + | |
| 4281 | + /** | |
| 4282 | + * Fix iOS scrolling | |
| 4283 | + * http://stackoverflow.com/q/39626302 | |
| 4284 | + */ | |
| 4285 | + const iOSfix = () => { | |
| 4286 | + if (isSafariOrIOS && !hasClass(document.body, swalClasses.iosfix)) { | |
| 4287 | + const offset = document.body.scrollTop; | |
| 4288 | + document.body.style.top = `${offset * -1}px`; | |
| 4289 | + addClass(document.body, swalClasses.iosfix); | |
| 4290 | + lockBodyScroll(); | |
| 4291 | + } | |
| 4292 | + }; | |
| 4293 | + | |
| 4294 | + /** | |
| 4295 | + * https://github.com/sweetalert2/sweetalert2/issues/1246 | |
| 4296 | + */ | |
| 4297 | + const lockBodyScroll = () => { | |
| 4298 | + const container = getContainer(); | |
| 4299 | + if (!container) { | |
| 4300 | + return; | |
| 4301 | + } | |
| 4302 | + /** @type {boolean} */ | |
| 4303 | + let preventTouchMove; | |
| 4304 | + /** | |
| 4305 | + * @param {TouchEvent} event | |
| 4306 | + */ | |
| 4307 | + container.ontouchstart = event => { | |
| 4308 | + preventTouchMove = shouldPreventTouchMove(event); | |
| 4309 | + }; | |
| 4310 | + /** | |
| 4311 | + * @param {TouchEvent} event | |
| 4312 | + */ | |
| 4313 | + container.ontouchmove = event => { | |
| 4314 | + if (preventTouchMove) { | |
| 4315 | + event.preventDefault(); | |
| 4316 | + event.stopPropagation(); | |
| 4317 | + } | |
| 4318 | + }; | |
| 4319 | + }; | |
| 4320 | + | |
| 4321 | + /** | |
| 4322 | + * @param {TouchEvent} event | |
| 4323 | + * @returns {boolean} | |
| 4324 | + */ | |
| 4325 | + const shouldPreventTouchMove = event => { | |
| 4326 | + const target = event.target; | |
| 4327 | + const container = getContainer(); | |
| 4328 | + const htmlContainer = getHtmlContainer(); | |
| 4329 | + if (!container || !htmlContainer) { | |
| 4330 | + return false; | |
| 4331 | + } | |
| 4332 | + if (isStylus(event) || isZoom(event)) { | |
| 4333 | + return false; | |
| 4334 | + } | |
| 4335 | + if (target === container) { | |
| 4336 | + return true; | |
| 4337 | + } | |
| 4338 | + if (!isScrollable(container) && target instanceof HTMLElement && !selfOrParentIsScrollable(target, htmlContainer) && | |
| 4339 | + // #2823 | |
| 4340 | + target.tagName !== 'INPUT' && | |
| 4341 | + // #1603 | |
| 4342 | + target.tagName !== 'TEXTAREA' && | |
| 4343 | + // #2266 | |
| 4344 | + !(isScrollable(htmlContainer) && | |
| 4345 | + // #1944 | |
| 4346 | + htmlContainer.contains(target))) { | |
| 4347 | + return true; | |
| 4348 | + } | |
| 4349 | + return false; | |
| 4350 | + }; | |
| 4351 | + | |
| 4352 | + /** | |
| 4353 | + * https://github.com/sweetalert2/sweetalert2/issues/1786 | |
| 4354 | + * | |
| 4355 | + * @param {TouchEvent} event | |
| 4356 | + * @returns {boolean} | |
| 4357 | + */ | |
| 4358 | + const isStylus = event => { | |
| 4359 | + return Boolean(event.touches && event.touches.length && | |
| 4360 | + // @ts-ignore - touchType is not a standard property | |
| 4361 | + event.touches[0].touchType === 'stylus'); | |
| 4362 | + }; | |
| 4363 | + | |
| 4364 | + /** | |
| 4365 | + * https://github.com/sweetalert2/sweetalert2/issues/1891 | |
| 4366 | + * | |
| 4367 | + * @param {TouchEvent} event | |
| 4368 | + * @returns {boolean} | |
| 4369 | + */ | |
| 4370 | + const isZoom = event => { | |
| 4371 | + return event.touches && event.touches.length > 1; | |
| 4372 | + }; | |
| 4373 | + const undoIOSfix = () => { | |
| 4374 | + if (hasClass(document.body, swalClasses.iosfix)) { | |
| 4375 | + const offset = parseInt(document.body.style.top, 10); | |
| 4376 | + removeClass(document.body, swalClasses.iosfix); | |
| 4377 | + document.body.style.top = ''; | |
| 4378 | + document.body.scrollTop = offset * -1; | |
| 4379 | + } | |
| 4380 | + }; | |
| 4381 | + | |
| 4382 | + /** | |
| 4383 | + * Measure scrollbar width for padding body during modal show/hide | |
| 4384 | + * https://github.com/twbs/bootstrap/blob/master/js/src/modal.js | |
| 4385 | + * | |
| 4386 | + * @returns {number} | |
| 4387 | + */ | |
| 4388 | + const measureScrollbar = () => { | |
| 4389 | + const scrollDiv = document.createElement('div'); | |
| 4390 | + scrollDiv.className = swalClasses['scrollbar-measure']; | |
| 4391 | + document.body.appendChild(scrollDiv); | |
| 4392 | + const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; | |
| 4393 | + document.body.removeChild(scrollDiv); | |
| 4394 | + return scrollbarWidth; | |
| 4395 | + }; | |
| 4396 | + | |
| 4397 | + /** | |
| 4398 | + * Remember state in cases where opening and handling a modal will fiddle with it. | |
| 4399 | + * @type {number | null} | |
| 4400 | + */ | |
| 4401 | + let previousBodyPadding = null; | |
| 4402 | + | |
| 4403 | + /** | |
| 4404 | + * @param {string} initialBodyOverflow | |
| 4405 | + */ | |
| 4406 | + const replaceScrollbarWithPadding = initialBodyOverflow => { | |
| 4407 | + // for queues, do not do this more than once | |
| 4408 | + if (previousBodyPadding !== null) { | |
| 4409 | + return; | |
| 4410 | + } | |
| 4411 | + // if the body has overflow | |
| 4412 | + if (document.body.scrollHeight > window.innerHeight || initialBodyOverflow === 'scroll' // https://github.com/sweetalert2/sweetalert2/issues/2663 | |
| 4413 | + ) { | |
| 4414 | + // add padding so the content doesn't shift after removal of scrollbar | |
| 4415 | + previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right')); | |
| 4416 | + document.body.style.paddingRight = `${previousBodyPadding + measureScrollbar()}px`; | |
| 4417 | + } | |
| 4418 | + }; | |
| 4419 | + const undoReplaceScrollbarWithPadding = () => { | |
| 4420 | + if (previousBodyPadding !== null) { | |
| 4421 | + document.body.style.paddingRight = `${previousBodyPadding}px`; | |
| 4422 | + previousBodyPadding = null; | |
| 4423 | + } | |
| 4424 | + }; | |
| 4425 | + | |
| 4426 | + /** | |
| 4427 | + * @param {SweetAlert} instance | |
| 4428 | + * @param {HTMLElement} container | |
| 4429 | + * @param {boolean} returnFocus | |
| 4430 | + * @param {(() => void) | undefined} didClose | |
| 4431 | + */ | |
| 4432 | + function removePopupAndResetState(instance, container, returnFocus, didClose) { | |
| 4433 | + if (isToast()) { | |
| 4434 | + triggerDidCloseAndDispose(instance, didClose); | |
| 4435 | + } else { | |
| 4436 | + restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose)); | |
| 4437 | + removeKeydownHandler(globalState); | |
| 4438 | + } | |
| 4439 | + | |
| 4440 | + // workaround for https://github.com/sweetalert2/sweetalert2/issues/2088 | |
| 4441 | + // for some reason removing the container in Safari will scroll the document to bottom | |
| 4442 | + if (isSafariOrIOS) { | |
| 4443 | + container.setAttribute('style', 'display:none !important'); | |
| 4444 | + container.removeAttribute('class'); | |
| 4445 | + container.innerHTML = ''; | |
| 4446 | + } else { | |
| 4447 | + container.remove(); | |
| 4448 | + } | |
| 4449 | + if (isModal()) { | |
| 4450 | + undoReplaceScrollbarWithPadding(); | |
| 4451 | + undoIOSfix(); | |
| 4452 | + unsetAriaHidden(); | |
| 4453 | + } | |
| 4454 | + removeBodyClasses(); | |
| 4455 | + } | |
| 4456 | + | |
| 4457 | + /** | |
| 4458 | + * Remove SweetAlert2 classes from body | |
| 4459 | + */ | |
| 4460 | + function removeBodyClasses() { | |
| 4461 | + removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]); | |
| 4462 | + } | |
| 4463 | + | |
| 4464 | + /** | |
| 4465 | + * Instance method to close sweetAlert | |
| 4466 | + * | |
| 4467 | + * @param {SweetAlertResult | undefined} resolveValue | |
| 4468 | + * @this {SweetAlert} | |
| 4469 | + */ | |
| 4470 | + function close(resolveValue) { | |
| 4471 | + resolveValue = prepareResolveValue(resolveValue); | |
| 4472 | + const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this); | |
| 4473 | + const didClose = triggerClosePopup(this); | |
| 4474 | + if (this.isAwaitingPromise) { | |
| 4475 | + // A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335 | |
| 4476 | + if (!resolveValue.isDismissed) { | |
| 4477 | + handleAwaitingPromise(this); | |
| 4478 | + swalPromiseResolve(resolveValue); | |
| 4479 | + } | |
| 4480 | + } else if (didClose) { | |
| 4481 | + // Resolve Swal promise | |
| 4482 | + swalPromiseResolve(resolveValue); | |
| 4483 | + } | |
| 4484 | + } | |
| 4485 | + | |
| 4486 | + /** | |
| 4487 | + * @param {SweetAlert} instance | |
| 4488 | + * @returns {boolean} | |
| 4489 | + */ | |
| 4490 | + const triggerClosePopup = instance => { | |
| 4491 | + const popup = getPopup(); | |
| 4492 | + if (!popup) { | |
| 4493 | + return false; | |
| 4494 | + } | |
| 4495 | + const innerParams = privateProps.innerParams.get(instance); | |
| 4496 | + if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) { | |
| 4497 | + return false; | |
| 4498 | + } | |
| 4499 | + removeClass(popup, innerParams.showClass.popup); | |
| 4500 | + addClass(popup, innerParams.hideClass.popup); | |
| 4501 | + const backdrop = getContainer(); | |
| 4502 | + removeClass(backdrop, innerParams.showClass.backdrop); | |
| 4503 | + addClass(backdrop, innerParams.hideClass.backdrop); | |
| 4504 | + handlePopupAnimation(instance, popup, innerParams); | |
| 4505 | + return true; | |
| 4506 | + }; | |
| 4507 | + | |
| 4508 | + /** | |
| 4509 | + * @param {Error | string} error | |
| 4510 | + * @this {SweetAlert} | |
| 4511 | + */ | |
| 4512 | + function rejectPromise(error) { | |
| 4513 | + const rejectPromise = privateMethods.swalPromiseReject.get(this); | |
| 4514 | + handleAwaitingPromise(this); | |
| 4515 | + if (rejectPromise) { | |
| 4516 | + // Reject Swal promise | |
| 4517 | + rejectPromise(error); | |
| 4518 | + } | |
| 4519 | + } | |
| 4520 | + | |
| 4521 | + /** | |
| 4522 | + * @param {SweetAlert} instance | |
| 4523 | + */ | |
| 4524 | + const handleAwaitingPromise = instance => { | |
| 4525 | + if (instance.isAwaitingPromise) { | |
| 4526 | + // @ts-ignore | |
| 4527 | + delete instance.isAwaitingPromise; | |
| 4528 | + // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335 | |
| 4529 | + if (!privateProps.innerParams.get(instance)) { | |
| 4530 | + instance._destroy(); | |
| 4531 | + } | |
| 4532 | + } | |
| 4533 | + }; | |
| 4534 | + | |
| 4535 | + /** | |
| 4536 | + * @param {SweetAlertResult | undefined} resolveValue | |
| 4537 | + * @returns {SweetAlertResult} | |
| 4538 | + */ | |
| 4539 | + const prepareResolveValue = resolveValue => { | |
| 4540 | + // When user calls Swal.close() | |
| 4541 | + if (typeof resolveValue === 'undefined') { | |
| 4542 | + return { | |
| 4543 | + isConfirmed: false, | |
| 4544 | + isDenied: false, | |
| 4545 | + isDismissed: true | |
| 4546 | + }; | |
| 4547 | + } | |
| 4548 | + return Object.assign({ | |
| 4549 | + isConfirmed: false, | |
| 4550 | + isDenied: false, | |
| 4551 | + isDismissed: false | |
| 4552 | + }, resolveValue); | |
| 4553 | + }; | |
| 4554 | + | |
| 4555 | + /** | |
| 4556 | + * @param {SweetAlert} instance | |
| 4557 | + * @param {HTMLElement} popup | |
| 4558 | + * @param {SweetAlertOptions} innerParams | |
| 4559 | + */ | |
| 4560 | + const handlePopupAnimation = (instance, popup, innerParams) => { | |
| 4561 | + var _globalState$eventEmi; | |
| 4562 | + const container = getContainer(); | |
| 4563 | + // If animation is supported, animate | |
| 4564 | + const animationIsSupported = hasCssAnimation(popup); | |
| 4565 | + if (typeof innerParams.willClose === 'function') { | |
| 4566 | + innerParams.willClose(popup); | |
| 4567 | + } | |
| 4568 | + (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('willClose', popup); | |
| 4569 | + if (animationIsSupported && container) { | |
| 4570 | + animatePopup(instance, popup, container, Boolean(innerParams.returnFocus), innerParams.didClose); | |
| 4571 | + } else if (container) { | |
| 4572 | + // Otherwise, remove immediately | |
| 4573 | + removePopupAndResetState(instance, container, Boolean(innerParams.returnFocus), innerParams.didClose); | |
| 4574 | + } | |
| 4575 | + }; | |
| 4576 | + | |
| 4577 | + /** | |
| 4578 | + * @param {SweetAlert} instance | |
| 4579 | + * @param {HTMLElement} popup | |
| 4580 | + * @param {HTMLElement} container | |
| 4581 | + * @param {boolean} returnFocus | |
| 4582 | + * @param {(() => void) | undefined} didClose | |
| 4583 | + */ | |
| 4584 | + const animatePopup = (instance, popup, container, returnFocus, didClose) => { | |
| 4585 | + globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose); | |
| 4586 | + /** | |
| 4587 | + * @param {AnimationEvent | TransitionEvent} e | |
| 4588 | + */ | |
| 4589 | + const swalCloseAnimationFinished = function (e) { | |
| 4590 | + if (e.target === popup) { | |
| 4591 | + var _globalState$swalClos; | |
| 4592 | + (_globalState$swalClos = globalState.swalCloseEventFinishedCallback) === null || _globalState$swalClos === void 0 || _globalState$swalClos.call(globalState); | |
| 4593 | + delete globalState.swalCloseEventFinishedCallback; | |
| 4594 | + popup.removeEventListener('animationend', swalCloseAnimationFinished); | |
| 4595 | + popup.removeEventListener('transitionend', swalCloseAnimationFinished); | |
| 4596 | + } | |
| 4597 | + }; | |
| 4598 | + popup.addEventListener('animationend', swalCloseAnimationFinished); | |
| 4599 | + popup.addEventListener('transitionend', swalCloseAnimationFinished); | |
| 4600 | + }; | |
| 4601 | + | |
| 4602 | + /** | |
| 4603 | + * @param {SweetAlert} instance | |
| 4604 | + * @param {(() => void) | undefined} didClose | |
| 4605 | + */ | |
| 4606 | + const triggerDidCloseAndDispose = (instance, didClose) => { | |
| 4607 | + setTimeout(() => { | |
| 4608 | + var _globalState$eventEmi2; | |
| 4609 | + if (typeof didClose === 'function') { | |
| 4610 | + didClose.bind(instance.params)(); | |
| 4611 | + } | |
| 4612 | + (_globalState$eventEmi2 = globalState.eventEmitter) === null || _globalState$eventEmi2 === void 0 || _globalState$eventEmi2.emit('didClose'); | |
| 4613 | + // instance might have been destroyed already | |
| 4614 | + if (instance._destroy) { | |
| 4615 | + instance._destroy(); | |
| 4616 | + } | |
| 4617 | + }); | |
| 4618 | + }; | |
| 4619 | + | |
| 4620 | + /** | |
| 4621 | + * Shows loader (spinner), this is useful with AJAX requests. | |
| 4622 | + * By default the loader be shown instead of the "Confirm" button. | |
| 4623 | + * | |
| 4624 | + * @param {HTMLButtonElement | null} [buttonToReplace] | |
| 4625 | + */ | |
| 4626 | + const showLoading = buttonToReplace => { | |
| 4627 | + let popup = getPopup(); | |
| 4628 | + if (!popup) { | |
| 4629 | + new Swal(); | |
| 4630 | + } | |
| 4631 | + popup = getPopup(); | |
| 4632 | + if (!popup) { | |
| 4633 | + return; | |
| 4634 | + } | |
| 4635 | + const loader = getLoader(); | |
| 4636 | + if (isToast()) { | |
| 4637 | + hide(getIcon()); | |
| 4638 | + } else { | |
| 4639 | + replaceButton(popup, buttonToReplace); | |
| 4640 | + } | |
| 4641 | + show(loader); | |
| 4642 | + popup.setAttribute('data-loading', 'true'); | |
| 4643 | + popup.setAttribute('aria-busy', 'true'); | |
| 4644 | + popup.focus(); | |
| 4645 | + }; | |
| 4646 | + | |
| 4647 | + /** | |
| 4648 | + * @param {HTMLElement} popup | |
| 4649 | + * @param {HTMLButtonElement | null} [buttonToReplace] | |
| 4650 | + */ | |
| 4651 | + const replaceButton = (popup, buttonToReplace) => { | |
| 4652 | + const actions = getActions(); | |
| 4653 | + const loader = getLoader(); | |
| 4654 | + if (!actions || !loader) { | |
| 4655 | + return; | |
| 4656 | + } | |
| 4657 | + if (!buttonToReplace && isVisible$1(getConfirmButton())) { | |
| 4658 | + buttonToReplace = getConfirmButton(); | |
| 4659 | + } | |
| 4660 | + show(actions); | |
| 4661 | + if (buttonToReplace) { | |
| 4662 | + hide(buttonToReplace); | |
| 4663 | + loader.setAttribute('data-button-to-replace', buttonToReplace.className); | |
| 4664 | + actions.insertBefore(loader, buttonToReplace); | |
| 4665 | + } | |
| 4666 | + addClass([popup, actions], swalClasses.loading); | |
| 4667 | + }; | |
| 4668 | + | |
| 4669 | + /** | |
| 4670 | + * @param {SweetAlert} instance | |
| 4671 | + * @param {SweetAlertOptions} params | |
| 4672 | + */ | |
| 4673 | + const handleInputOptionsAndValue = (instance, params) => { | |
| 4674 | + if (params.input === 'select' || params.input === 'radio') { | |
| 4675 | + handleInputOptions(instance, params); | |
| 4676 | + } else if (['text', 'email', 'number', 'tel', 'textarea'].some(i => i === params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) { | |
| 4677 | + showLoading(getConfirmButton()); | |
| 4678 | + handleInputValue(instance, params); | |
| 4679 | + } | |
| 4680 | + }; | |
| 4681 | + | |
| 4682 | + /** | |
| 4683 | + * @param {SweetAlert} instance | |
| 4684 | + * @param {SweetAlertOptions} innerParams | |
| 4685 | + * @returns {SweetAlertInputValue} | |
| 4686 | + */ | |
| 4687 | + const getInputValue = (instance, innerParams) => { | |
| 4688 | + const input = instance.getInput(); | |
| 4689 | + if (!input) { | |
| 4690 | + return null; | |
| 4691 | + } | |
| 4692 | + switch (innerParams.input) { | |
| 4693 | + case 'checkbox': | |
| 4694 | + return getCheckboxValue(input); | |
| 4695 | + case 'radio': | |
| 4696 | + return getRadioValue(input); | |
| 4697 | + case 'file': | |
| 4698 | + return getFileValue(input); | |
| 4699 | + default: | |
| 4700 | + return innerParams.inputAutoTrim ? input.value.trim() : input.value; | |
| 4701 | + } | |
| 4702 | + }; | |
| 4703 | + | |
| 4704 | + /** | |
| 4705 | + * @param {HTMLInputElement} input | |
| 4706 | + * @returns {number} | |
| 4707 | + */ | |
| 4708 | + const getCheckboxValue = input => input.checked ? 1 : 0; | |
| 4709 | + | |
| 4710 | + /** | |
| 4711 | + * @param {HTMLInputElement} input | |
| 4712 | + * @returns {string | null} | |
| 4713 | + */ | |
| 4714 | + const getRadioValue = input => input.checked ? input.value : null; | |
| 4715 | + | |
| 4716 | + /** | |
| 4717 | + * @param {HTMLInputElement} input | |
| 4718 | + * @returns {FileList | File | null} | |
| 4719 | + */ | |
| 4720 | + const getFileValue = input => input.files && input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null; | |
| 4721 | + | |
| 4722 | + /** | |
| 4723 | + * @param {SweetAlert} instance | |
| 4724 | + * @param {SweetAlertOptions} params | |
| 4725 | + */ | |
| 4726 | + const handleInputOptions = (instance, params) => { | |
| 4727 | + const popup = getPopup(); | |
| 4728 | + if (!popup) { | |
| 4729 | + return; | |
| 4730 | + } | |
| 4731 | + /** | |
| 4732 | + * @param {*} inputOptions | |
| 4733 | + */ | |
| 4734 | + const processInputOptions = inputOptions => { | |
| 4735 | + if (params.input === 'select') { | |
| 4736 | + populateSelectOptions(popup, formatInputOptions(inputOptions), params); | |
| 4737 | + } else if (params.input === 'radio') { | |
| 4738 | + populateRadioOptions(popup, formatInputOptions(inputOptions), params); | |
| 4739 | + } | |
| 4740 | + }; | |
| 4741 | + if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) { | |
| 4742 | + showLoading(getConfirmButton()); | |
| 4743 | + asPromise(params.inputOptions).then(inputOptions => { | |
| 4744 | + instance.hideLoading(); | |
| 4745 | + processInputOptions(inputOptions); | |
| 4746 | + }); | |
| 4747 | + } else if (typeof params.inputOptions === 'object') { | |
| 4748 | + processInputOptions(params.inputOptions); | |
| 4749 | + } else { | |
| 4750 | + error(`Unexpected type of inputOptions! Expected object, Map or Promise, got ${typeof params.inputOptions}`); | |
| 4751 | + } | |
| 4752 | + }; | |
| 4753 | + | |
| 4754 | + /** | |
| 4755 | + * @param {SweetAlert} instance | |
| 4756 | + * @param {SweetAlertOptions} params | |
| 4757 | + */ | |
| 4758 | + const handleInputValue = (instance, params) => { | |
| 4759 | + const input = instance.getInput(); | |
| 4760 | + if (!input) { | |
| 4761 | + return; | |
| 4762 | + } | |
| 4763 | + hide(input); | |
| 4764 | + asPromise(params.inputValue).then(inputValue => { | |
| 4765 | + input.value = params.input === 'number' ? `${parseFloat(inputValue) || 0}` : `${inputValue}`; | |
| 4766 | + show(input); | |
| 4767 | + input.focus(); | |
| 4768 | + instance.hideLoading(); | |
| 4769 | + }).catch(err => { | |
| 4770 | + error(`Error in inputValue promise: ${err}`); | |
| 4771 | + input.value = ''; | |
| 4772 | + show(input); | |
| 4773 | + input.focus(); | |
| 4774 | + instance.hideLoading(); | |
| 4775 | + }); | |
| 4776 | + }; | |
| 4777 | + | |
| 4778 | + /** | |
| 4779 | + * @param {HTMLElement} popup | |
| 4780 | + * @param {InputOptionFlattened[]} inputOptions | |
| 4781 | + * @param {SweetAlertOptions} params | |
| 4782 | + */ | |
| 4783 | + function populateSelectOptions(popup, inputOptions, params) { | |
| 4784 | + const select = getDirectChildByClass(popup, swalClasses.select); | |
| 4785 | + if (!select) { | |
| 4786 | + return; | |
| 4787 | + } | |
| 4788 | + /** | |
| 4789 | + * @param {HTMLElement} parent | |
| 4790 | + * @param {string} optionLabel | |
| 4791 | + * @param {string} optionValue | |
| 4792 | + */ | |
| 4793 | + const renderOption = (parent, optionLabel, optionValue) => { | |
| 4794 | + const option = document.createElement('option'); | |
| 4795 | + option.value = optionValue; | |
| 4796 | + setInnerHtml(option, optionLabel); | |
| 4797 | + option.selected = isSelected(optionValue, params.inputValue); | |
| 4798 | + parent.appendChild(option); | |
| 4799 | + }; | |
| 4800 | + inputOptions.forEach(inputOption => { | |
| 4801 | + const optionValue = inputOption[0]; | |
| 4802 | + const optionLabel = inputOption[1]; | |
| 4803 | + // <optgroup> spec: | |
| 4804 | + // https://www.w3.org/TR/html401/interact/forms.html#h-17.6 | |
| 4805 | + // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..." | |
| 4806 | + // check whether this is a <optgroup> | |
| 4807 | + if (Array.isArray(optionLabel)) { | |
| 4808 | + // if it is an array, then it is an <optgroup> | |
| 4809 | + const optgroup = document.createElement('optgroup'); | |
| 4810 | + optgroup.label = optionValue; | |
| 4811 | + optgroup.disabled = false; // not configurable for now | |
| 4812 | + select.appendChild(optgroup); | |
| 4813 | + optionLabel.forEach(o => renderOption(optgroup, o[1], o[0])); | |
| 4814 | + } else { | |
| 4815 | + // case of <option> | |
| 4816 | + renderOption(select, optionLabel, optionValue); | |
| 4817 | + } | |
| 4818 | + }); | |
| 4819 | + select.focus(); | |
| 4820 | + } | |
| 4821 | + | |
| 4822 | + /** | |
| 4823 | + * @param {HTMLElement} popup | |
| 4824 | + * @param {InputOptionFlattened[]} inputOptions | |
| 4825 | + * @param {SweetAlertOptions} params | |
| 4826 | + */ | |
| 4827 | + function populateRadioOptions(popup, inputOptions, params) { | |
| 4828 | + const radio = getDirectChildByClass(popup, swalClasses.radio); | |
| 4829 | + if (!radio) { | |
| 4830 | + return; | |
| 4831 | + } | |
| 4832 | + inputOptions.forEach(inputOption => { | |
| 4833 | + const radioValue = inputOption[0]; | |
| 4834 | + const radioLabel = inputOption[1]; | |
| 4835 | + const radioInput = document.createElement('input'); | |
| 4836 | + const radioLabelElement = document.createElement('label'); | |
| 4837 | + radioInput.type = 'radio'; | |
| 4838 | + radioInput.name = swalClasses.radio; | |
| 4839 | + radioInput.value = radioValue; | |
| 4840 | + if (isSelected(radioValue, params.inputValue)) { | |
| 4841 | + radioInput.checked = true; | |
| 4842 | + } | |
| 4843 | + const label = document.createElement('span'); | |
| 4844 | + setInnerHtml(label, radioLabel); | |
| 4845 | + label.className = swalClasses.label; | |
| 4846 | + radioLabelElement.appendChild(radioInput); | |
| 4847 | + radioLabelElement.appendChild(label); | |
| 4848 | + radio.appendChild(radioLabelElement); | |
| 4849 | + }); | |
| 4850 | + const radios = radio.querySelectorAll('input'); | |
| 4851 | + if (radios.length) { | |
| 4852 | + radios[0].focus(); | |
| 4853 | + } | |
| 4854 | + } | |
| 4855 | + | |
| 4856 | + /** | |
| 4857 | + * Converts `inputOptions` into an array of `[value, label]`s | |
| 4858 | + * | |
| 4859 | + * @param {*} inputOptions | |
| 4860 | + * @typedef {string[]} InputOptionFlattened | |
| 4861 | + * @returns {InputOptionFlattened[]} | |
| 4862 | + */ | |
| 4863 | + const formatInputOptions = inputOptions => { | |
| 4864 | + const entries = inputOptions instanceof Map ? Array.from(inputOptions) : Object.entries(inputOptions); | |
| 4865 | + return entries.map(([key, value]) => [key, typeof value === 'object' ? formatInputOptions(value) : value]); // case of <optgroup> | |
| 4866 | + }; | |
| 4867 | + | |
| 4868 | + /** | |
| 4869 | + * @param {string} optionValue | |
| 4870 | + * @param {SweetAlertInputValue} inputValue | |
| 4871 | + * @returns {boolean} | |
| 4872 | + */ | |
| 4873 | + const isSelected = (optionValue, inputValue) => Boolean(inputValue) && inputValue != null && inputValue.toString() === optionValue.toString(); | |
| 4874 | + | |
| 4875 | + /** | |
| 4876 | + * @param {SweetAlert} instance | |
| 4877 | + */ | |
| 4878 | + const handleConfirmButtonClick = instance => { | |
| 4879 | + const innerParams = privateProps.innerParams.get(instance); | |
| 4880 | + instance.disableButtons(); | |
| 4881 | + if (innerParams.input) { | |
| 4882 | + handleConfirmOrDenyWithInput(instance, 'confirm'); | |
| 4883 | + } else { | |
| 4884 | + confirm(instance, true); | |
| 4885 | + } | |
| 4886 | + }; | |
| 4887 | + | |
| 4888 | + /** | |
| 4889 | + * @param {SweetAlert} instance | |
| 4890 | + */ | |
| 4891 | + const handleDenyButtonClick = instance => { | |
| 4892 | + const innerParams = privateProps.innerParams.get(instance); | |
| 4893 | + instance.disableButtons(); | |
| 4894 | + if (innerParams.returnInputValueOnDeny) { | |
| 4895 | + handleConfirmOrDenyWithInput(instance, 'deny'); | |
| 4896 | + } else { | |
| 4897 | + deny(instance, false); | |
| 4898 | + } | |
| 4899 | + }; | |
| 4900 | + | |
| 4901 | + /** | |
| 4902 | + * @param {SweetAlert} instance | |
| 4903 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 4904 | + */ | |
| 4905 | + const handleCancelButtonClick = (instance, dismissWith) => { | |
| 4906 | + instance.disableButtons(); | |
| 4907 | + dismissWith(DismissReason.cancel); | |
| 4908 | + }; | |
| 4909 | + | |
| 4910 | + /** | |
| 4911 | + * @param {SweetAlert} instance | |
| 4912 | + * @param {'confirm' | 'deny'} type | |
| 4913 | + */ | |
| 4914 | + const handleConfirmOrDenyWithInput = (instance, type) => { | |
| 4915 | + const innerParams = privateProps.innerParams.get(instance); | |
| 4916 | + if (!innerParams.input) { | |
| 4917 | + error(`The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`); | |
| 4918 | + return; | |
| 4919 | + } | |
| 4920 | + const input = instance.getInput(); | |
| 4921 | + const inputValue = getInputValue(instance, innerParams); | |
| 4922 | + if (innerParams.inputValidator) { | |
| 4923 | + handleInputValidator(instance, inputValue, type); | |
| 4924 | + } else if (input && !input.checkValidity()) { | |
| 4925 | + instance.enableButtons(); | |
| 4926 | + instance.showValidationMessage(innerParams.validationMessage || input.validationMessage); | |
| 4927 | + } else if (type === 'deny') { | |
| 4928 | + deny(instance, inputValue); | |
| 4929 | + } else { | |
| 4930 | + confirm(instance, inputValue); | |
| 4931 | + } | |
| 4932 | + }; | |
| 4933 | + | |
| 4934 | + /** | |
| 4935 | + * @param {SweetAlert} instance | |
| 4936 | + * @param {SweetAlertInputValue} inputValue | |
| 4937 | + * @param {'confirm' | 'deny'} type | |
| 4938 | + */ | |
| 4939 | + const handleInputValidator = (instance, inputValue, type) => { | |
| 4940 | + const innerParams = privateProps.innerParams.get(instance); | |
| 4941 | + instance.disableInput(); | |
| 4942 | + const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage))); | |
| 4943 | + validationPromise.then(validationMessage => { | |
| 4944 | + instance.enableButtons(); | |
| 4945 | + instance.enableInput(); | |
| 4946 | + if (validationMessage) { | |
| 4947 | + instance.showValidationMessage(validationMessage); | |
| 4948 | + } else if (type === 'deny') { | |
| 4949 | + deny(instance, inputValue); | |
| 4950 | + } else { | |
| 4951 | + confirm(instance, inputValue); | |
| 4952 | + } | |
| 4953 | + }); | |
| 4954 | + }; | |
| 4955 | + | |
| 4956 | + /** | |
| 4957 | + * @param {SweetAlert} instance | |
| 4958 | + * @param {*} value | |
| 4959 | + */ | |
| 4960 | + const deny = (instance, value) => { | |
| 4961 | + const innerParams = privateProps.innerParams.get(instance); | |
| 4962 | + if (innerParams.showLoaderOnDeny) { | |
| 4963 | + showLoading(getDenyButton()); | |
| 4964 | + } | |
| 4965 | + if (innerParams.preDeny) { | |
| 4966 | + instance.isAwaitingPromise = 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 | |
| 4967 | + const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage))); | |
| 4968 | + preDenyPromise.then(preDenyValue => { | |
| 4969 | + if (preDenyValue === false) { | |
| 4970 | + instance.hideLoading(); | |
| 4971 | + handleAwaitingPromise(instance); | |
| 4972 | + } else { | |
| 4973 | + instance.close(/** @type SweetAlertResult */{ | |
| 4974 | + isDenied: true, | |
| 4975 | + value: typeof preDenyValue === 'undefined' ? value : preDenyValue | |
| 4976 | + }); | |
| 4977 | + } | |
| 4978 | + }).catch(error => rejectWith(instance, error)); | |
| 4979 | + } else { | |
| 4980 | + instance.close(/** @type SweetAlertResult */{ | |
| 4981 | + isDenied: true, | |
| 4982 | + value | |
| 4983 | + }); | |
| 4984 | + } | |
| 4985 | + }; | |
| 4986 | + | |
| 4987 | + /** | |
| 4988 | + * @param {SweetAlert} instance | |
| 4989 | + * @param {*} value | |
| 4990 | + */ | |
| 4991 | + const succeedWith = (instance, value) => { | |
| 4992 | + instance.close(/** @type SweetAlertResult */{ | |
| 4993 | + isConfirmed: true, | |
| 4994 | + value | |
| 4995 | + }); | |
| 4996 | + }; | |
| 4997 | + | |
| 4998 | + /** | |
| 4999 | + * | |
| 5000 | + * @param {SweetAlert} instance | |
| 5001 | + * @param {string} error | |
| 5002 | + */ | |
| 5003 | + const rejectWith = (instance, error) => { | |
| 5004 | + instance.rejectPromise(error); | |
| 5005 | + }; | |
| 5006 | + | |
| 5007 | + /** | |
| 5008 | + * | |
| 5009 | + * @param {SweetAlert} instance | |
| 5010 | + * @param {*} value | |
| 5011 | + */ | |
| 5012 | + const confirm = (instance, value) => { | |
| 5013 | + const innerParams = privateProps.innerParams.get(instance); | |
| 5014 | + if (innerParams.showLoaderOnConfirm) { | |
| 5015 | + showLoading(); | |
| 5016 | + } | |
| 5017 | + if (innerParams.preConfirm) { | |
| 5018 | + instance.resetValidationMessage(); | |
| 5019 | + instance.isAwaitingPromise = 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 | |
| 5020 | + const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage))); | |
| 5021 | + preConfirmPromise.then(preConfirmValue => { | |
| 5022 | + if (isVisible$1(getValidationMessage()) || preConfirmValue === false) { | |
| 5023 | + instance.hideLoading(); | |
| 5024 | + handleAwaitingPromise(instance); | |
| 5025 | + } else { | |
| 5026 | + succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue); | |
| 5027 | + } | |
| 5028 | + }).catch(error => rejectWith(instance, error)); | |
| 5029 | + } else { | |
| 5030 | + succeedWith(instance, value); | |
| 5031 | + } | |
| 5032 | + }; | |
| 5033 | + | |
| 5034 | + /** | |
| 5035 | + * Hides loader and shows back the button which was hidden by .showLoading() | |
| 5036 | + * @this {SweetAlert} | |
| 5037 | + */ | |
| 5038 | + function hideLoading() { | |
| 5039 | + // do nothing if popup is closed | |
| 5040 | + const innerParams = privateProps.innerParams.get(this); | |
| 5041 | + if (!innerParams) { | |
| 5042 | + return; | |
| 5043 | + } | |
| 5044 | + const domCache = privateProps.domCache.get(this); | |
| 5045 | + hide(domCache.loader); | |
| 5046 | + if (isToast()) { | |
| 5047 | + if (innerParams.icon) { | |
| 5048 | + show(getIcon()); | |
| 5049 | + } | |
| 5050 | + } else { | |
| 5051 | + showRelatedButton(domCache); | |
| 5052 | + } | |
| 5053 | + removeClass([domCache.popup, domCache.actions], swalClasses.loading); | |
| 5054 | + domCache.popup.removeAttribute('aria-busy'); | |
| 5055 | + domCache.popup.removeAttribute('data-loading'); | |
| 5056 | + this.enableButtons(); | |
| 5057 | + } | |
| 5058 | + | |
| 5059 | + /** | |
| 5060 | + * @param {DomCache} domCache | |
| 5061 | + */ | |
| 5062 | + const showRelatedButton = domCache => { | |
| 5063 | + const dataButtonToReplace = domCache.loader.getAttribute('data-button-to-replace'); | |
| 5064 | + const buttonToReplace = dataButtonToReplace ? domCache.popup.getElementsByClassName(dataButtonToReplace) : []; | |
| 5065 | + if (buttonToReplace.length) { | |
| 5066 | + show(/** @type {HTMLElement} */buttonToReplace[0], 'inline-block'); | |
| 5067 | + } else if (allButtonsAreHidden()) { | |
| 5068 | + hide(domCache.actions); | |
| 5069 | + } | |
| 5070 | + }; | |
| 5071 | + | |
| 5072 | + /** | |
| 5073 | + * Gets the input DOM node, this method works with input parameter. | |
| 5074 | + * | |
| 5075 | + * @returns {HTMLInputElement | null} | |
| 5076 | + * @this {SweetAlert} | |
| 5077 | + */ | |
| 5078 | + function getInput() { | |
| 5079 | + const innerParams = privateProps.innerParams.get(this); | |
| 5080 | + const domCache = privateProps.domCache.get(this); | |
| 5081 | + if (!domCache) { | |
| 5082 | + return null; | |
| 5083 | + } | |
| 5084 | + return getInput$1(domCache.popup, innerParams.input); | |
| 5085 | + } | |
| 5086 | + | |
| 5087 | + /** | |
| 5088 | + * @param {SweetAlert} instance | |
| 5089 | + * @param {string[]} buttons | |
| 5090 | + * @param {boolean} disabled | |
| 5091 | + */ | |
| 5092 | + function setButtonsDisabled(instance, buttons, disabled) { | |
| 5093 | + const domCache = privateProps.domCache.get(instance); | |
| 5094 | + buttons.forEach(button => { | |
| 5095 | + domCache[button].disabled = disabled; | |
| 5096 | + }); | |
| 5097 | + } | |
| 5098 | + | |
| 5099 | + /** | |
| 5100 | + * @param {HTMLInputElement | null} input | |
| 5101 | + * @param {boolean} disabled | |
| 5102 | + */ | |
| 5103 | + function setInputDisabled(input, disabled) { | |
| 5104 | + const popup = getPopup(); | |
| 5105 | + if (!popup || !input) { | |
| 5106 | + return; | |
| 5107 | + } | |
| 5108 | + if (input.type === 'radio') { | |
| 5109 | + /** @type {NodeListOf<HTMLInputElement>} */ | |
| 5110 | + const radios = popup.querySelectorAll(`[name="${swalClasses.radio}"]`); | |
| 5111 | + radios.forEach(radio => { | |
| 5112 | + radio.disabled = disabled; | |
| 5113 | + }); | |
| 5114 | + } else { | |
| 5115 | + input.disabled = disabled; | |
| 5116 | + } | |
| 5117 | + } | |
| 5118 | + | |
| 5119 | + /** | |
| 5120 | + * Enable all the buttons | |
| 5121 | + * @this {SweetAlert} | |
| 5122 | + */ | |
| 5123 | + function enableButtons() { | |
| 5124 | + setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false); | |
| 5125 | + const focusedElement = privateProps.focusedElement.get(this); | |
| 5126 | + if (focusedElement instanceof HTMLElement && document.activeElement === document.body) { | |
| 5127 | + focusedElement.focus(); | |
| 5128 | + } | |
| 5129 | + privateProps.focusedElement.delete(this); | |
| 5130 | + } | |
| 5131 | + | |
| 5132 | + /** | |
| 5133 | + * Disable all the buttons | |
| 5134 | + * @this {SweetAlert} | |
| 5135 | + */ | |
| 5136 | + function disableButtons() { | |
| 5137 | + privateProps.focusedElement.set(this, document.activeElement); | |
| 5138 | + setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true); | |
| 5139 | + } | |
| 5140 | + | |
| 5141 | + /** | |
| 5142 | + * Enable the input field | |
| 5143 | + * @this {SweetAlert} | |
| 5144 | + */ | |
| 5145 | + function enableInput() { | |
| 5146 | + setInputDisabled(this.getInput(), false); | |
| 5147 | + } | |
| 5148 | + | |
| 5149 | + /** | |
| 5150 | + * Disable the input field | |
| 5151 | + * @this {SweetAlert} | |
| 5152 | + */ | |
| 5153 | + function disableInput() { | |
| 5154 | + setInputDisabled(this.getInput(), true); | |
| 5155 | + } | |
| 5156 | + | |
| 5157 | + /** | |
| 5158 | + * Show block with validation message | |
| 5159 | + * | |
| 5160 | + * @param {string} error | |
| 5161 | + * @this {SweetAlert} | |
| 5162 | + */ | |
| 5163 | + function showValidationMessage(error) { | |
| 5164 | + const domCache = privateProps.domCache.get(this); | |
| 5165 | + const params = privateProps.innerParams.get(this); | |
| 5166 | + setInnerHtml(domCache.validationMessage, error); | |
| 5167 | + domCache.validationMessage.className = swalClasses['validation-message']; | |
| 5168 | + if (params.customClass && params.customClass.validationMessage) { | |
| 5169 | + addClass(domCache.validationMessage, params.customClass.validationMessage); | |
| 5170 | + } | |
| 5171 | + show(domCache.validationMessage); | |
| 5172 | + const input = this.getInput(); | |
| 5173 | + if (input) { | |
| 5174 | + input.setAttribute('aria-invalid', 'true'); | |
| 5175 | + input.setAttribute('aria-describedby', swalClasses['validation-message']); | |
| 5176 | + focusInput(input); | |
| 5177 | + addClass(input, swalClasses.inputerror); | |
| 5178 | + } | |
| 5179 | + } | |
| 5180 | + | |
| 5181 | + /** | |
| 5182 | + * Hide block with validation message | |
| 5183 | + * | |
| 5184 | + * @this {SweetAlert} | |
| 5185 | + */ | |
| 5186 | + function resetValidationMessage() { | |
| 5187 | + const domCache = privateProps.domCache.get(this); | |
| 5188 | + if (domCache.validationMessage) { | |
| 5189 | + hide(domCache.validationMessage); | |
| 5190 | + } | |
| 5191 | + const input = this.getInput(); | |
| 5192 | + if (input) { | |
| 5193 | + input.removeAttribute('aria-invalid'); | |
| 5194 | + input.removeAttribute('aria-describedby'); | |
| 5195 | + removeClass(input, swalClasses.inputerror); | |
| 5196 | + } | |
| 5197 | + } | |
| 5198 | + | |
| 5199 | + const defaultParams = { | |
| 5200 | + title: '', | |
| 5201 | + titleText: '', | |
| 5202 | + text: '', | |
| 5203 | + html: '', | |
| 5204 | + footer: '', | |
| 5205 | + icon: undefined, | |
| 5206 | + iconColor: undefined, | |
| 5207 | + iconHtml: undefined, | |
| 5208 | + template: undefined, | |
| 5209 | + toast: false, | |
| 5210 | + draggable: false, | |
| 5211 | + animation: true, | |
| 5212 | + theme: 'light', | |
| 5213 | + showClass: { | |
| 5214 | + popup: 'swal2-show', | |
| 5215 | + backdrop: 'swal2-backdrop-show', | |
| 5216 | + icon: 'swal2-icon-show' | |
| 5217 | + }, | |
| 5218 | + hideClass: { | |
| 5219 | + popup: 'swal2-hide', | |
| 5220 | + backdrop: 'swal2-backdrop-hide', | |
| 5221 | + icon: 'swal2-icon-hide' | |
| 5222 | + }, | |
| 5223 | + customClass: {}, | |
| 5224 | + target: 'body', | |
| 5225 | + color: undefined, | |
| 5226 | + backdrop: true, | |
| 5227 | + heightAuto: true, | |
| 5228 | + allowOutsideClick: true, | |
| 5229 | + allowEscapeKey: true, | |
| 5230 | + allowEnterKey: true, | |
| 5231 | + stopKeydownPropagation: true, | |
| 5232 | + keydownListenerCapture: false, | |
| 5233 | + showConfirmButton: true, | |
| 5234 | + showDenyButton: false, | |
| 5235 | + showCancelButton: false, | |
| 5236 | + preConfirm: undefined, | |
| 5237 | + preDeny: undefined, | |
| 5238 | + confirmButtonText: 'OK', | |
| 5239 | + confirmButtonAriaLabel: '', | |
| 5240 | + confirmButtonColor: undefined, | |
| 5241 | + denyButtonText: 'No', | |
| 5242 | + denyButtonAriaLabel: '', | |
| 5243 | + denyButtonColor: undefined, | |
| 5244 | + cancelButtonText: 'Cancel', | |
| 5245 | + cancelButtonAriaLabel: '', | |
| 5246 | + cancelButtonColor: undefined, | |
| 5247 | + buttonsStyling: true, | |
| 5248 | + reverseButtons: false, | |
| 5249 | + focusConfirm: true, | |
| 5250 | + focusDeny: false, | |
| 5251 | + focusCancel: false, | |
| 5252 | + returnFocus: true, | |
| 5253 | + showCloseButton: false, | |
| 5254 | + closeButtonHtml: '×', | |
| 5255 | + closeButtonAriaLabel: 'Close this dialog', | |
| 5256 | + loaderHtml: '', | |
| 5257 | + showLoaderOnConfirm: false, | |
| 5258 | + showLoaderOnDeny: false, | |
| 5259 | + imageUrl: undefined, | |
| 5260 | + imageWidth: undefined, | |
| 5261 | + imageHeight: undefined, | |
| 5262 | + imageAlt: '', | |
| 5263 | + timer: undefined, | |
| 5264 | + timerProgressBar: false, | |
| 5265 | + width: undefined, | |
| 5266 | + padding: undefined, | |
| 5267 | + background: undefined, | |
| 5268 | + input: undefined, | |
| 5269 | + inputPlaceholder: '', | |
| 5270 | + inputLabel: '', | |
| 5271 | + inputValue: '', | |
| 5272 | + inputOptions: {}, | |
| 5273 | + inputAutoFocus: true, | |
| 5274 | + inputAutoTrim: true, | |
| 5275 | + inputAttributes: {}, | |
| 5276 | + inputValidator: undefined, | |
| 5277 | + returnInputValueOnDeny: false, | |
| 5278 | + validationMessage: undefined, | |
| 5279 | + grow: false, | |
| 5280 | + position: 'center', | |
| 5281 | + progressSteps: [], | |
| 5282 | + currentProgressStep: undefined, | |
| 5283 | + progressStepsDistance: undefined, | |
| 5284 | + willOpen: undefined, | |
| 5285 | + didOpen: undefined, | |
| 5286 | + didRender: undefined, | |
| 5287 | + willClose: undefined, | |
| 5288 | + didClose: undefined, | |
| 5289 | + didDestroy: undefined, | |
| 5290 | + scrollbarPadding: true, | |
| 5291 | + topLayer: false | |
| 5292 | + }; | |
| 5293 | + const updatableParams = ['allowEscapeKey', 'allowOutsideClick', 'background', 'buttonsStyling', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonText', 'closeButtonAriaLabel', 'closeButtonHtml', 'color', 'confirmButtonAriaLabel', 'confirmButtonColor', 'confirmButtonText', 'currentProgressStep', 'customClass', 'denyButtonAriaLabel', 'denyButtonColor', 'denyButtonText', 'didClose', 'didDestroy', 'draggable', 'footer', 'hideClass', 'html', 'icon', 'iconColor', 'iconHtml', 'imageAlt', 'imageHeight', 'imageUrl', 'imageWidth', 'preConfirm', 'preDeny', 'progressSteps', 'returnFocus', 'reverseButtons', 'showCancelButton', 'showCloseButton', 'showConfirmButton', 'showDenyButton', 'text', 'title', 'titleText', 'theme', 'willClose']; | |
| 5294 | + | |
| 5295 | + /** @type {Record<string, string | undefined>} */ | |
| 5296 | + const deprecatedParams = { | |
| 5297 | + allowEnterKey: undefined | |
| 5298 | + }; | |
| 5299 | + const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'draggable', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture']; | |
| 5300 | + | |
| 5301 | + /** | |
| 5302 | + * Is valid parameter | |
| 5303 | + * | |
| 5304 | + * @param {string} paramName | |
| 5305 | + * @returns {boolean} | |
| 5306 | + */ | |
| 5307 | + const isValidParameter = paramName => { | |
| 5308 | + return Object.prototype.hasOwnProperty.call(defaultParams, paramName); | |
| 5309 | + }; | |
| 5310 | + | |
| 5311 | + /** | |
| 5312 | + * Is valid parameter for Swal.update() method | |
| 5313 | + * | |
| 5314 | + * @param {string} paramName | |
| 5315 | + * @returns {boolean} | |
| 5316 | + */ | |
| 5317 | + const isUpdatableParameter = paramName => { | |
| 5318 | + return updatableParams.indexOf(paramName) !== -1; | |
| 5319 | + }; | |
| 5320 | + | |
| 5321 | + /** | |
| 5322 | + * Is deprecated parameter | |
| 5323 | + * | |
| 5324 | + * @param {string} paramName | |
| 5325 | + * @returns {string | undefined} | |
| 5326 | + */ | |
| 5327 | + const isDeprecatedParameter = paramName => { | |
| 5328 | + return deprecatedParams[paramName]; | |
| 5329 | + }; | |
| 5330 | + | |
| 5331 | + /** | |
| 5332 | + * @param {string} param | |
| 5333 | + */ | |
| 5334 | + const checkIfParamIsValid = param => { | |
| 5335 | + if (!isValidParameter(param)) { | |
| 5336 | + warn(`Unknown parameter "${param}"`); | |
| 5337 | + } | |
| 5338 | + }; | |
| 5339 | + | |
| 5340 | + /** | |
| 5341 | + * @param {string} param | |
| 5342 | + */ | |
| 5343 | + const checkIfToastParamIsValid = param => { | |
| 5344 | + if (toastIncompatibleParams.includes(param)) { | |
| 5345 | + warn(`The parameter "${param}" is incompatible with toasts`); | |
| 5346 | + } | |
| 5347 | + }; | |
| 5348 | + | |
| 5349 | + /** | |
| 5350 | + * @param {string} param | |
| 5351 | + */ | |
| 5352 | + const checkIfParamIsDeprecated = param => { | |
| 5353 | + const isDeprecated = isDeprecatedParameter(param); | |
| 5354 | + if (isDeprecated) { | |
| 5355 | + warnAboutDeprecation(param, isDeprecated); | |
| 5356 | + } | |
| 5357 | + }; | |
| 5358 | + | |
| 5359 | + /** | |
| 5360 | + * Show relevant warnings for given params | |
| 5361 | + * | |
| 5362 | + * @param {SweetAlertOptions} params | |
| 5363 | + */ | |
| 5364 | + const showWarningsForParams = params => { | |
| 5365 | + if (params.backdrop === false && params.allowOutsideClick) { | |
| 5366 | + warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`'); | |
| 5367 | + } | |
| 5368 | + if (params.theme && !['light', 'dark', 'auto', 'minimal', 'borderless', 'bootstrap-4', 'bootstrap-4-light', 'bootstrap-4-dark', 'bootstrap-5', 'bootstrap-5-light', 'bootstrap-5-dark', 'material-ui', 'material-ui-light', 'material-ui-dark', 'embed-iframe', 'bulma', 'bulma-light', 'bulma-dark'].includes(params.theme)) { | |
| 5369 | + warn(`Invalid theme "${params.theme}"`); | |
| 5370 | + } | |
| 5371 | + for (const param in params) { | |
| 5372 | + checkIfParamIsValid(param); | |
| 5373 | + if (params.toast) { | |
| 5374 | + checkIfToastParamIsValid(param); | |
| 5375 | + } | |
| 5376 | + checkIfParamIsDeprecated(param); | |
| 5377 | + } | |
| 5378 | + }; | |
| 5379 | + | |
| 5380 | + /** | |
| 5381 | + * Updates popup parameters. | |
| 5382 | + * | |
| 5383 | + * @this {any} | |
| 5384 | + * @param {SweetAlertOptions} params | |
| 5385 | + */ | |
| 5386 | + function update(params) { | |
| 5387 | + const container = getContainer(); | |
| 5388 | + const popup = getPopup(); | |
| 5389 | + const innerParams = privateProps.innerParams.get(this); | |
| 5390 | + if (!popup || hasClass(popup, innerParams.hideClass.popup)) { | |
| 5391 | + 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.`); | |
| 5392 | + return; | |
| 5393 | + } | |
| 5394 | + const validUpdatableParams = filterValidParams(params); | |
| 5395 | + const updatedParams = Object.assign({}, innerParams, validUpdatableParams); | |
| 5396 | + showWarningsForParams(updatedParams); | |
| 5397 | + if (container) { | |
| 5398 | + container.dataset['swal2Theme'] = updatedParams.theme; | |
| 5399 | + } | |
| 5400 | + render(this, updatedParams); | |
| 5401 | + privateProps.innerParams.set(this, updatedParams); | |
| 5402 | + Object.defineProperties(this, { | |
| 5403 | + params: { | |
| 5404 | + value: Object.assign({}, this.params, params), | |
| 5405 | + writable: false, | |
| 5406 | + enumerable: true | |
| 5407 | + } | |
| 5408 | + }); | |
| 5409 | + } | |
| 5410 | + | |
| 5411 | + /** | |
| 5412 | + * @param {SweetAlertOptions} params | |
| 5413 | + * @returns {SweetAlertOptions} | |
| 5414 | + */ | |
| 5415 | + const filterValidParams = params => { | |
| 5416 | + /** @type {Record<string, any>} */ | |
| 5417 | + const validUpdatableParams = {}; | |
| 5418 | + Object.keys(params).forEach(param => { | |
| 5419 | + if (isUpdatableParameter(param)) { | |
| 5420 | + const typedParams = /** @type {Record<string, any>} */params; | |
| 5421 | + validUpdatableParams[param] = typedParams[param]; | |
| 5422 | + } else { | |
| 5423 | + warn(`Invalid parameter to update: ${param}`); | |
| 5424 | + } | |
| 5425 | + }); | |
| 5426 | + return validUpdatableParams; | |
| 5427 | + }; | |
| 5428 | + | |
| 5429 | + /** | |
| 5430 | + * Dispose the current SweetAlert2 instance | |
| 5431 | + * @this {SweetAlert} | |
| 5432 | + */ | |
| 5433 | + function _destroy() { | |
| 5434 | + var _globalState$eventEmi; | |
| 5435 | + const domCache = privateProps.domCache.get(this); | |
| 5436 | + const innerParams = privateProps.innerParams.get(this); | |
| 5437 | + if (!innerParams) { | |
| 5438 | + disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335 | |
| 5439 | + return; // This instance has already been destroyed | |
| 5440 | + } | |
| 5441 | + | |
| 5442 | + // Check if there is another Swal closing | |
| 5443 | + if (domCache.popup && globalState.swalCloseEventFinishedCallback) { | |
| 5444 | + globalState.swalCloseEventFinishedCallback(); | |
| 5445 | + delete globalState.swalCloseEventFinishedCallback; | |
| 5446 | + } | |
| 5447 | + if (typeof innerParams.didDestroy === 'function') { | |
| 5448 | + innerParams.didDestroy(); | |
| 5449 | + } | |
| 5450 | + (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('didDestroy'); | |
| 5451 | + disposeSwal(this); | |
| 5452 | + } | |
| 5453 | + | |
| 5454 | + /** | |
| 5455 | + * @param {SweetAlert} instance | |
| 5456 | + */ | |
| 5457 | + const disposeSwal = instance => { | |
| 5458 | + disposeWeakMaps(instance); | |
| 5459 | + // Unset this.params so GC will dispose it (#1569) | |
| 5460 | + // @ts-ignore | |
| 5461 | + delete instance.params; | |
| 5462 | + // Unset globalState props so GC will dispose globalState (#1569) | |
| 5463 | + delete globalState.keydownHandler; | |
| 5464 | + delete globalState.keydownTarget; | |
| 5465 | + // Unset currentInstance | |
| 5466 | + delete globalState.currentInstance; | |
| 5467 | + }; | |
| 5468 | + | |
| 5469 | + /** | |
| 5470 | + * @param {SweetAlert} instance | |
| 5471 | + */ | |
| 5472 | + const disposeWeakMaps = instance => { | |
| 5473 | + // If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335 | |
| 5474 | + if (instance.isAwaitingPromise) { | |
| 5475 | + unsetWeakMaps(privateProps, instance); | |
| 5476 | + instance.isAwaitingPromise = true; | |
| 5477 | + } else { | |
| 5478 | + unsetWeakMaps(privateMethods, instance); | |
| 5479 | + unsetWeakMaps(privateProps, instance); | |
| 5480 | + | |
| 5481 | + // @ts-ignore | |
| 5482 | + delete instance.isAwaitingPromise; | |
| 5483 | + // Unset instance methods | |
| 5484 | + // @ts-ignore | |
| 5485 | + delete instance.disableButtons; | |
| 5486 | + // @ts-ignore | |
| 5487 | + delete instance.enableButtons; | |
| 5488 | + // @ts-ignore | |
| 5489 | + delete instance.getInput; | |
| 5490 | + // @ts-ignore | |
| 5491 | + delete instance.disableInput; | |
| 5492 | + // @ts-ignore | |
| 5493 | + delete instance.enableInput; | |
| 5494 | + // @ts-ignore | |
| 5495 | + delete instance.hideLoading; | |
| 5496 | + // @ts-ignore | |
| 5497 | + delete instance.disableLoading; | |
| 5498 | + // @ts-ignore | |
| 5499 | + delete instance.showValidationMessage; | |
| 5500 | + // @ts-ignore | |
| 5501 | + delete instance.resetValidationMessage; | |
| 5502 | + // @ts-ignore | |
| 5503 | + delete instance.close; | |
| 5504 | + // @ts-ignore | |
| 5505 | + delete instance.closePopup; | |
| 5506 | + // @ts-ignore | |
| 5507 | + delete instance.closeModal; | |
| 5508 | + // @ts-ignore | |
| 5509 | + delete instance.closeToast; | |
| 5510 | + // @ts-ignore | |
| 5511 | + delete instance.rejectPromise; | |
| 5512 | + // @ts-ignore | |
| 5513 | + delete instance.update; | |
| 5514 | + // @ts-ignore | |
| 5515 | + delete instance._destroy; | |
| 5516 | + } | |
| 5517 | + }; | |
| 5518 | + | |
| 5519 | + /** | |
| 5520 | + * @param {Record<string, WeakMap<any, any>>} obj | |
| 5521 | + * @param {SweetAlert} instance | |
| 5522 | + */ | |
| 5523 | + const unsetWeakMaps = (obj, instance) => { | |
| 5524 | + for (const i in obj) { | |
| 5525 | + obj[i].delete(instance); | |
| 5526 | + } | |
| 5527 | + }; | |
| 5528 | + | |
| 5529 | + var instanceMethods = /*#__PURE__*/Object.freeze({ | |
| 5530 | + __proto__: null, | |
| 5531 | + _destroy: _destroy, | |
| 5532 | + close: close, | |
| 5533 | + closeModal: close, | |
| 5534 | + closePopup: close, | |
| 5535 | + closeToast: close, | |
| 5536 | + disableButtons: disableButtons, | |
| 5537 | + disableInput: disableInput, | |
| 5538 | + disableLoading: hideLoading, | |
| 5539 | + enableButtons: enableButtons, | |
| 5540 | + enableInput: enableInput, | |
| 5541 | + getInput: getInput, | |
| 5542 | + handleAwaitingPromise: handleAwaitingPromise, | |
| 5543 | + hideLoading: hideLoading, | |
| 5544 | + rejectPromise: rejectPromise, | |
| 5545 | + resetValidationMessage: resetValidationMessage, | |
| 5546 | + showValidationMessage: showValidationMessage, | |
| 5547 | + update: update | |
| 5548 | + }); | |
| 5549 | + | |
| 5550 | + /** | |
| 5551 | + * @param {SweetAlertOptions} innerParams | |
| 5552 | + * @param {DomCache} domCache | |
| 5553 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 5554 | + */ | |
| 5555 | + const handlePopupClick = (innerParams, domCache, dismissWith) => { | |
| 5556 | + if (innerParams.toast) { | |
| 5557 | + handleToastClick(innerParams, domCache, dismissWith); | |
| 5558 | + } else { | |
| 5559 | + // Ignore click events that had mousedown on the popup but mouseup on the container | |
| 5560 | + // This can happen when the user drags a slider | |
| 5561 | + handleModalMousedown(domCache); | |
| 5562 | + | |
| 5563 | + // Ignore click events that had mousedown on the container but mouseup on the popup | |
| 5564 | + handleContainerMousedown(domCache); | |
| 5565 | + handleModalClick(innerParams, domCache, dismissWith); | |
| 5566 | + } | |
| 5567 | + }; | |
| 5568 | + | |
| 5569 | + /** | |
| 5570 | + * @param {SweetAlertOptions} innerParams | |
| 5571 | + * @param {DomCache} domCache | |
| 5572 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 5573 | + */ | |
| 5574 | + const handleToastClick = (innerParams, domCache, dismissWith) => { | |
| 5575 | + // Closing toast by internal click | |
| 5576 | + domCache.popup.onclick = () => { | |
| 5577 | + if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) { | |
| 5578 | + return; | |
| 5579 | + } | |
| 5580 | + dismissWith(DismissReason.close); | |
| 5581 | + }; | |
| 5582 | + }; | |
| 5583 | + | |
| 5584 | + /** | |
| 5585 | + * @param {SweetAlertOptions} innerParams | |
| 5586 | + * @returns {boolean} | |
| 5587 | + */ | |
| 5588 | + const isAnyButtonShown = innerParams => { | |
| 5589 | + return Boolean(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton); | |
| 5590 | + }; | |
| 5591 | + let ignoreOutsideClick = false; | |
| 5592 | + | |
| 5593 | + /** | |
| 5594 | + * @param {DomCache} domCache | |
| 5595 | + */ | |
| 5596 | + const handleModalMousedown = domCache => { | |
| 5597 | + domCache.popup.onmousedown = () => { | |
| 5598 | + domCache.container.onmouseup = function (e) { | |
| 5599 | + domCache.container.onmouseup = () => {}; | |
| 5600 | + // We only check if the mouseup target is the container because usually it doesn't | |
| 5601 | + // have any other direct children aside of the popup | |
| 5602 | + if (e.target === domCache.container) { | |
| 5603 | + ignoreOutsideClick = true; | |
| 5604 | + } | |
| 5605 | + }; | |
| 5606 | + }; | |
| 5607 | + }; | |
| 5608 | + | |
| 5609 | + /** | |
| 5610 | + * @param {DomCache} domCache | |
| 5611 | + */ | |
| 5612 | + const handleContainerMousedown = domCache => { | |
| 5613 | + domCache.container.onmousedown = e => { | |
| 5614 | + // prevent the modal text from being selected on double click on the container (allowOutsideClick: false) | |
| 5615 | + if (e.target === domCache.container) { | |
| 5616 | + e.preventDefault(); | |
| 5617 | + } | |
| 5618 | + domCache.popup.onmouseup = function (e) { | |
| 5619 | + domCache.popup.onmouseup = () => {}; | |
| 5620 | + // We also need to check if the mouseup target is a child of the popup | |
| 5621 | + if (e.target === domCache.popup || e.target instanceof HTMLElement && domCache.popup.contains(e.target)) { | |
| 5622 | + ignoreOutsideClick = true; | |
| 5623 | + } | |
| 5624 | + }; | |
| 5625 | + }; | |
| 5626 | + }; | |
| 5627 | + | |
| 5628 | + /** | |
| 5629 | + * @param {SweetAlertOptions} innerParams | |
| 5630 | + * @param {DomCache} domCache | |
| 5631 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 5632 | + */ | |
| 5633 | + const handleModalClick = (innerParams, domCache, dismissWith) => { | |
| 5634 | + domCache.container.onclick = e => { | |
| 5635 | + if (ignoreOutsideClick) { | |
| 5636 | + ignoreOutsideClick = false; | |
| 5637 | + return; | |
| 5638 | + } | |
| 5639 | + if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) { | |
| 5640 | + dismissWith(DismissReason.backdrop); | |
| 5641 | + } | |
| 5642 | + }; | |
| 5643 | + }; | |
| 5644 | + | |
| 5645 | + /** | |
| 5646 | + * @param {unknown} elem | |
| 5647 | + * @returns {boolean} | |
| 5648 | + */ | |
| 5649 | + const isJqueryElement = elem => typeof elem === 'object' && elem !== null && 'jquery' in elem; | |
| 5650 | + | |
| 5651 | + /** | |
| 5652 | + * @param {unknown} elem | |
| 5653 | + * @returns {boolean} | |
| 5654 | + */ | |
| 5655 | + const isElement = elem => elem instanceof Element || isJqueryElement(elem); | |
| 5656 | + | |
| 5657 | + /** | |
| 5658 | + * @param {ReadonlyArray<unknown>} args | |
| 5659 | + * @returns {SweetAlertOptions} | |
| 5660 | + */ | |
| 5661 | + const argsToParams = args => { | |
| 5662 | + /** @type {Record<string, unknown>} */ | |
| 5663 | + const params = {}; | |
| 5664 | + if (typeof args[0] === 'object' && !isElement(args[0])) { | |
| 5665 | + Object.assign(params, args[0]); | |
| 5666 | + } else { | |
| 5667 | + ['title', 'html', 'icon'].forEach((name, index) => { | |
| 5668 | + const arg = args[index]; | |
| 5669 | + if (typeof arg === 'string' || isElement(arg)) { | |
| 5670 | + params[name] = arg; | |
| 5671 | + } else if (arg !== undefined) { | |
| 5672 | + error(`Unexpected type of ${name}! Expected "string" or "Element", got ${typeof arg}`); | |
| 5673 | + } | |
| 5674 | + }); | |
| 5675 | + } | |
| 5676 | + return /** @type {SweetAlertOptions} */params; | |
| 5677 | + }; | |
| 5678 | + | |
| 5679 | + /** | |
| 5680 | + * Main method to create a new SweetAlert2 popup | |
| 5681 | + * | |
| 5682 | + * @this {new (...args: any[]) => any} | |
| 5683 | + * @param {...SweetAlertOptions} args | |
| 5684 | + * @returns {Promise<SweetAlertResult>} | |
| 5685 | + */ | |
| 5686 | + function fire(...args) { | |
| 5687 | + return new this(...args); | |
| 5688 | + } | |
| 5689 | + | |
| 5690 | + /** | |
| 5691 | + * Returns an extended version of `Swal` containing `params` as defaults. | |
| 5692 | + * Useful for reusing Swal configuration. | |
| 5693 | + * | |
| 5694 | + * For example: | |
| 5695 | + * | |
| 5696 | + * Before: | |
| 5697 | + * const textPromptOptions = { input: 'text', showCancelButton: true } | |
| 5698 | + * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' }) | |
| 5699 | + * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' }) | |
| 5700 | + * | |
| 5701 | + * After: | |
| 5702 | + * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true }) | |
| 5703 | + * const {value: firstName} = await TextPrompt('What is your first name?') | |
| 5704 | + * const {value: lastName} = await TextPrompt('What is your last name?') | |
| 5705 | + * | |
| 5706 | + * @param {SweetAlertOptions} mixinParams | |
| 5707 | + * @returns {SweetAlert} | |
| 5708 | + * @this {typeof import('../SweetAlert.js').SweetAlert} | |
| 5709 | + */ | |
| 5710 | + function mixin(mixinParams) { | |
| 5711 | + // @ts-ignore: 'this' refers to the SweetAlert constructor | |
| 5712 | + class MixinSwal extends this { | |
| 5713 | + /** | |
| 5714 | + * @param {any} params | |
| 5715 | + * @param {any} priorityMixinParams | |
| 5716 | + */ | |
| 5717 | + _main(params, priorityMixinParams) { | |
| 5718 | + return super._main(params, Object.assign({}, mixinParams, priorityMixinParams)); | |
| 5719 | + } | |
| 5720 | + } | |
| 5721 | + // @ts-ignore | |
| 5722 | + return MixinSwal; | |
| 5723 | + } | |
| 5724 | + | |
| 5725 | + /** | |
| 5726 | + * If `timer` parameter is set, returns number of milliseconds of timer remained. | |
| 5727 | + * Otherwise, returns undefined. | |
| 5728 | + * | |
| 5729 | + * @returns {number | undefined} | |
| 5730 | + */ | |
| 5731 | + const getTimerLeft = () => { | |
| 5732 | + return globalState.timeout && globalState.timeout.getTimerLeft(); | |
| 5733 | + }; | |
| 5734 | + | |
| 5735 | + /** | |
| 5736 | + * Stop timer. Returns number of milliseconds of timer remained. | |
| 5737 | + * If `timer` parameter isn't set, returns undefined. | |
| 5738 | + * | |
| 5739 | + * @returns {number | undefined} | |
| 5740 | + */ | |
| 5741 | + const stopTimer = () => { | |
| 5742 | + if (globalState.timeout) { | |
| 5743 | + stopTimerProgressBar(); | |
| 5744 | + return globalState.timeout.stop(); | |
| 5745 | + } | |
| 5746 | + }; | |
| 5747 | + | |
| 5748 | + /** | |
| 5749 | + * Resume timer. Returns number of milliseconds of timer remained. | |
| 5750 | + * If `timer` parameter isn't set, returns undefined. | |
| 5751 | + * | |
| 5752 | + * @returns {number | undefined} | |
| 5753 | + */ | |
| 5754 | + const resumeTimer = () => { | |
| 5755 | + if (globalState.timeout) { | |
| 5756 | + const remaining = globalState.timeout.start(); | |
| 5757 | + animateTimerProgressBar(remaining); | |
| 5758 | + return remaining; | |
| 5759 | + } | |
| 5760 | + }; | |
| 5761 | + | |
| 5762 | + /** | |
| 5763 | + * Resume timer. Returns number of milliseconds of timer remained. | |
| 5764 | + * If `timer` parameter isn't set, returns undefined. | |
| 5765 | + * | |
| 5766 | + * @returns {number | undefined} | |
| 5767 | + */ | |
| 5768 | + const toggleTimer = () => { | |
| 5769 | + const timer = globalState.timeout; | |
| 5770 | + return timer && (timer.running ? stopTimer() : resumeTimer()); | |
| 5771 | + }; | |
| 5772 | + | |
| 5773 | + /** | |
| 5774 | + * Increase timer. Returns number of milliseconds of an updated timer. | |
| 5775 | + * If `timer` parameter isn't set, returns undefined. | |
| 5776 | + * | |
| 5777 | + * @param {number} ms | |
| 5778 | + * @returns {number | undefined} | |
| 5779 | + */ | |
| 5780 | + const increaseTimer = ms => { | |
| 5781 | + if (globalState.timeout) { | |
| 5782 | + const remaining = globalState.timeout.increase(ms); | |
| 5783 | + animateTimerProgressBar(remaining, true); | |
| 5784 | + return remaining; | |
| 5785 | + } | |
| 5786 | + }; | |
| 5787 | + | |
| 5788 | + /** | |
| 5789 | + * Check if timer is running. Returns true if timer is running | |
| 5790 | + * or false if timer is paused or stopped. | |
| 5791 | + * If `timer` parameter isn't set, returns undefined | |
| 5792 | + * | |
| 5793 | + * @returns {boolean} | |
| 5794 | + */ | |
| 5795 | + const isTimerRunning = () => { | |
| 5796 | + return Boolean(globalState.timeout && globalState.timeout.isRunning()); | |
| 5797 | + }; | |
| 5798 | + | |
| 5799 | + let bodyClickListenerAdded = false; | |
| 5800 | + /** @type {Record<string, any>} */ | |
| 5801 | + const clickHandlers = {}; | |
| 5802 | + | |
| 5803 | + /** | |
| 5804 | + * @this {any} | |
| 5805 | + * @param {string} attr | |
| 5806 | + */ | |
| 5807 | + function bindClickHandler(attr = 'data-swal-template') { | |
| 5808 | + clickHandlers[attr] = this; | |
| 5809 | + if (!bodyClickListenerAdded) { | |
| 5810 | + document.body.addEventListener('click', bodyClickListener); | |
| 5811 | + bodyClickListenerAdded = true; | |
| 5812 | + } | |
| 5813 | + } | |
| 5814 | + | |
| 5815 | + /** | |
| 5816 | + * @param {MouseEvent} event | |
| 5817 | + */ | |
| 5818 | + const bodyClickListener = event => { | |
| 5819 | + for (let el = /** @type {any} */event.target; el && el !== document; el = el.parentNode) { | |
| 5820 | + for (const attr in clickHandlers) { | |
| 5821 | + const template = el.getAttribute && el.getAttribute(attr); | |
| 5822 | + if (template) { | |
| 5823 | + clickHandlers[attr].fire({ | |
| 5824 | + template | |
| 5825 | + }); | |
| 5826 | + return; | |
| 5827 | + } | |
| 5828 | + } | |
| 5829 | + } | |
| 5830 | + }; | |
| 5831 | + | |
| 5832 | + // Source: https://gist.github.com/mudge/5830382?permalink_comment_id=2691957#gistcomment-2691957 | |
| 5833 | + | |
| 5834 | + class EventEmitter { | |
| 5835 | + constructor() { | |
| 5836 | + /** @type {Events} */ | |
| 5837 | + this.events = {}; | |
| 5838 | + } | |
| 5839 | + | |
| 5840 | + /** | |
| 5841 | + * @param {string} eventName | |
| 5842 | + * @returns {EventHandlers} | |
| 5843 | + */ | |
| 5844 | + _getHandlersByEventName(eventName) { | |
| 5845 | + if (typeof this.events[eventName] === 'undefined') { | |
| 5846 | + // not Set because we need to keep the FIFO order | |
| 5847 | + // https://github.com/sweetalert2/sweetalert2/pull/2763#discussion_r1748990334 | |
| 5848 | + this.events[eventName] = []; | |
| 5849 | + } | |
| 5850 | + return this.events[eventName]; | |
| 5851 | + } | |
| 5852 | + | |
| 5853 | + /** | |
| 5854 | + * @param {string} eventName | |
| 5855 | + * @param {EventHandler} eventHandler | |
| 5856 | + */ | |
| 5857 | + on(eventName, eventHandler) { | |
| 5858 | + const currentHandlers = this._getHandlersByEventName(eventName); | |
| 5859 | + if (!currentHandlers.includes(eventHandler)) { | |
| 5860 | + currentHandlers.push(eventHandler); | |
| 5861 | + } | |
| 5862 | + } | |
| 5863 | + | |
| 5864 | + /** | |
| 5865 | + * @param {string} eventName | |
| 5866 | + * @param {EventHandler} eventHandler | |
| 5867 | + */ | |
| 5868 | + once(eventName, eventHandler) { | |
| 5869 | + /** | |
| 5870 | + * @param {...any} args | |
| 5871 | + */ | |
| 5872 | + const onceFn = (...args) => { | |
| 5873 | + this.removeListener(eventName, onceFn); | |
| 5874 | + // @ts-ignore | |
| 5875 | + eventHandler.apply(this, args); | |
| 5876 | + }; | |
| 5877 | + this.on(eventName, onceFn); | |
| 5878 | + } | |
| 5879 | + | |
| 5880 | + /** | |
| 5881 | + * @param {string} eventName | |
| 5882 | + * @param {...any} args | |
| 5883 | + */ | |
| 5884 | + emit(eventName, ...args) { | |
| 5885 | + this._getHandlersByEventName(eventName).forEach( | |
| 5886 | + /** | |
| 5887 | + * @param {EventHandler} eventHandler | |
| 5888 | + */ | |
| 5889 | + eventHandler => { | |
| 5890 | + try { | |
| 5891 | + // @ts-ignore | |
| 5892 | + eventHandler.apply(this, args); | |
| 5893 | + } catch (error) { | |
| 5894 | + console.error(error); | |
| 5895 | + } | |
| 5896 | + }); | |
| 5897 | + } | |
| 5898 | + | |
| 5899 | + /** | |
| 5900 | + * @param {string} eventName | |
| 5901 | + * @param {EventHandler} eventHandler | |
| 5902 | + */ | |
| 5903 | + removeListener(eventName, eventHandler) { | |
| 5904 | + const currentHandlers = this._getHandlersByEventName(eventName); | |
| 5905 | + const index = currentHandlers.indexOf(eventHandler); | |
| 5906 | + if (index > -1) { | |
| 5907 | + currentHandlers.splice(index, 1); | |
| 5908 | + } | |
| 5909 | + } | |
| 5910 | + | |
| 5911 | + /** | |
| 5912 | + * @param {string} eventName | |
| 5913 | + */ | |
| 5914 | + removeAllListeners(eventName) { | |
| 5915 | + if (this.events[eventName] !== undefined) { | |
| 5916 | + // https://github.com/sweetalert2/sweetalert2/pull/2763#discussion_r1749239222 | |
| 5917 | + this.events[eventName].length = 0; | |
| 5918 | + } | |
| 5919 | + } | |
| 5920 | + reset() { | |
| 5921 | + this.events = {}; | |
| 5922 | + } | |
| 5923 | + } | |
| 5924 | + | |
| 5925 | + globalState.eventEmitter = new EventEmitter(); | |
| 5926 | + | |
| 5927 | + /** | |
| 5928 | + * @param {string} eventName | |
| 5929 | + * @param {EventHandler} eventHandler | |
| 5930 | + */ | |
| 5931 | + const on = (eventName, eventHandler) => { | |
| 5932 | + if (globalState.eventEmitter) { | |
| 5933 | + globalState.eventEmitter.on(eventName, eventHandler); | |
| 5934 | + } | |
| 5935 | + }; | |
| 5936 | + | |
| 5937 | + /** | |
| 5938 | + * @param {string} eventName | |
| 5939 | + * @param {EventHandler} eventHandler | |
| 5940 | + */ | |
| 5941 | + const once = (eventName, eventHandler) => { | |
| 5942 | + if (globalState.eventEmitter) { | |
| 5943 | + globalState.eventEmitter.once(eventName, eventHandler); | |
| 5944 | + } | |
| 5945 | + }; | |
| 5946 | + | |
| 5947 | + /** | |
| 5948 | + * @param {string} [eventName] | |
| 5949 | + * @param {EventHandler} [eventHandler] | |
| 5950 | + */ | |
| 5951 | + const off = (eventName, eventHandler) => { | |
| 5952 | + if (!globalState.eventEmitter) { | |
| 5953 | + return; | |
| 5954 | + } | |
| 5955 | + | |
| 5956 | + // Remove all handlers for all events | |
| 5957 | + if (!eventName) { | |
| 5958 | + globalState.eventEmitter.reset(); | |
| 5959 | + return; | |
| 5960 | + } | |
| 5961 | + if (eventHandler) { | |
| 5962 | + // Remove a specific handler | |
| 5963 | + globalState.eventEmitter.removeListener(eventName, eventHandler); | |
| 5964 | + } else { | |
| 5965 | + // Remove all handlers for a specific event | |
| 5966 | + globalState.eventEmitter.removeAllListeners(eventName); | |
| 5967 | + } | |
| 5968 | + }; | |
| 5969 | + | |
| 5970 | + var staticMethods = /*#__PURE__*/Object.freeze({ | |
| 5971 | + __proto__: null, | |
| 5972 | + argsToParams: argsToParams, | |
| 5973 | + bindClickHandler: bindClickHandler, | |
| 5974 | + clickCancel: clickCancel, | |
| 5975 | + clickConfirm: clickConfirm, | |
| 5976 | + clickDeny: clickDeny, | |
| 5977 | + enableLoading: showLoading, | |
| 5978 | + fire: fire, | |
| 5979 | + getActions: getActions, | |
| 5980 | + getCancelButton: getCancelButton, | |
| 5981 | + getCloseButton: getCloseButton, | |
| 5982 | + getConfirmButton: getConfirmButton, | |
| 5983 | + getContainer: getContainer, | |
| 5984 | + getDenyButton: getDenyButton, | |
| 5985 | + getFocusableElements: getFocusableElements, | |
| 5986 | + getFooter: getFooter, | |
| 5987 | + getHtmlContainer: getHtmlContainer, | |
| 5988 | + getIcon: getIcon, | |
| 5989 | + getIconContent: getIconContent, | |
| 5990 | + getImage: getImage, | |
| 5991 | + getInputLabel: getInputLabel, | |
| 5992 | + getLoader: getLoader, | |
| 5993 | + getPopup: getPopup, | |
| 5994 | + getProgressSteps: getProgressSteps, | |
| 5995 | + getTimerLeft: getTimerLeft, | |
| 5996 | + getTimerProgressBar: getTimerProgressBar, | |
| 5997 | + getTitle: getTitle, | |
| 5998 | + getValidationMessage: getValidationMessage, | |
| 5999 | + increaseTimer: increaseTimer, | |
| 6000 | + isDeprecatedParameter: isDeprecatedParameter, | |
| 6001 | + isLoading: isLoading, | |
| 6002 | + isTimerRunning: isTimerRunning, | |
| 6003 | + isUpdatableParameter: isUpdatableParameter, | |
| 6004 | + isValidParameter: isValidParameter, | |
| 6005 | + isVisible: isVisible, | |
| 6006 | + mixin: mixin, | |
| 6007 | + off: off, | |
| 6008 | + on: on, | |
| 6009 | + once: once, | |
| 6010 | + resumeTimer: resumeTimer, | |
| 6011 | + showLoading: showLoading, | |
| 6012 | + stopTimer: stopTimer, | |
| 6013 | + toggleTimer: toggleTimer | |
| 6014 | + }); | |
| 6015 | + | |
| 6016 | + class Timer { | |
| 6017 | + /** | |
| 6018 | + * @param {() => void} callback | |
| 6019 | + * @param {number} delay | |
| 6020 | + */ | |
| 6021 | + constructor(callback, delay) { | |
| 6022 | + this.callback = callback; | |
| 6023 | + this.remaining = delay; | |
| 6024 | + this.running = false; | |
| 6025 | + this.start(); | |
| 6026 | + } | |
| 6027 | + | |
| 6028 | + /** | |
| 6029 | + * @returns {number} | |
| 6030 | + */ | |
| 6031 | + start() { | |
| 6032 | + if (!this.running) { | |
| 6033 | + this.running = true; | |
| 6034 | + this.started = new Date(); | |
| 6035 | + this.id = setTimeout(this.callback, this.remaining); | |
| 6036 | + } | |
| 6037 | + return this.remaining; | |
| 6038 | + } | |
| 6039 | + | |
| 6040 | + /** | |
| 6041 | + * @returns {number} | |
| 6042 | + */ | |
| 6043 | + stop() { | |
| 6044 | + if (this.started && this.running) { | |
| 6045 | + this.running = false; | |
| 6046 | + clearTimeout(this.id); | |
| 6047 | + this.remaining -= new Date().getTime() - this.started.getTime(); | |
| 6048 | + } | |
| 6049 | + return this.remaining; | |
| 6050 | + } | |
| 6051 | + | |
| 6052 | + /** | |
| 6053 | + * @param {number} n | |
| 6054 | + * @returns {number} | |
| 6055 | + */ | |
| 6056 | + increase(n) { | |
| 6057 | + const running = this.running; | |
| 6058 | + if (running) { | |
| 6059 | + this.stop(); | |
| 6060 | + } | |
| 6061 | + this.remaining += n; | |
| 6062 | + if (running) { | |
| 6063 | + this.start(); | |
| 6064 | + } | |
| 6065 | + return this.remaining; | |
| 6066 | + } | |
| 6067 | + | |
| 6068 | + /** | |
| 6069 | + * @returns {number} | |
| 6070 | + */ | |
| 6071 | + getTimerLeft() { | |
| 6072 | + if (this.running) { | |
| 6073 | + this.stop(); | |
| 6074 | + this.start(); | |
| 6075 | + } | |
| 6076 | + return this.remaining; | |
| 6077 | + } | |
| 6078 | + | |
| 6079 | + /** | |
| 6080 | + * @returns {boolean} | |
| 6081 | + */ | |
| 6082 | + isRunning() { | |
| 6083 | + return this.running; | |
| 6084 | + } | |
| 6085 | + } | |
| 6086 | + | |
| 6087 | + const swalStringParams = ['swal-title', 'swal-html', 'swal-footer']; | |
| 6088 | + | |
| 6089 | + /** | |
| 6090 | + * @param {SweetAlertOptions} params | |
| 6091 | + * @returns {SweetAlertOptions} | |
| 6092 | + */ | |
| 6093 | + const getTemplateParams = params => { | |
| 6094 | + const template = typeof params.template === 'string' ? (/** @type {HTMLTemplateElement} */document.querySelector(params.template)) : params.template; | |
| 6095 | + if (!template) { | |
| 6096 | + return {}; | |
| 6097 | + } | |
| 6098 | + /** @type {DocumentFragment} */ | |
| 6099 | + const templateContent = template.content; | |
| 6100 | + showWarningsForElements(templateContent); | |
| 6101 | + const result = Object.assign(getSwalParams(templateContent), getSwalFunctionParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams)); | |
| 6102 | + return result; | |
| 6103 | + }; | |
| 6104 | + | |
| 6105 | + /** | |
| 6106 | + * @param {DocumentFragment} templateContent | |
| 6107 | + * @returns {Record<string, string | boolean | number>} | |
| 6108 | + */ | |
| 6109 | + const getSwalParams = templateContent => { | |
| 6110 | + /** @type {Record<string, string | boolean | number>} */ | |
| 6111 | + const result = {}; | |
| 6112 | + /** @type {HTMLElement[]} */ | |
| 6113 | + const swalParams = Array.from(templateContent.querySelectorAll('swal-param')); | |
| 6114 | + swalParams.forEach(param => { | |
| 6115 | + showWarningsForAttributes(param, ['name', 'value']); | |
| 6116 | + const paramName = /** @type {keyof SweetAlertOptions} */param.getAttribute('name'); | |
| 6117 | + const value = param.getAttribute('value'); | |
| 6118 | + if (!paramName || !value) { | |
| 6119 | + return; | |
| 6120 | + } | |
| 6121 | + if (paramName in defaultParams && typeof defaultParams[(/** @type {keyof typeof defaultParams} */paramName)] === 'boolean') { | |
| 6122 | + result[paramName] = value !== 'false'; | |
| 6123 | + } else if (paramName in defaultParams && typeof defaultParams[(/** @type {keyof typeof defaultParams} */paramName)] === 'object') { | |
| 6124 | + result[paramName] = JSON.parse(value); | |
| 6125 | + } else { | |
| 6126 | + result[paramName] = value; | |
| 6127 | + } | |
| 6128 | + }); | |
| 6129 | + return result; | |
| 6130 | + }; | |
| 6131 | + | |
| 6132 | + /** | |
| 6133 | + * @param {DocumentFragment} templateContent | |
| 6134 | + * @returns {Record<string, () => void>} | |
| 6135 | + */ | |
| 6136 | + const getSwalFunctionParams = templateContent => { | |
| 6137 | + /** @type {Record<string, () => void>} */ | |
| 6138 | + const result = {}; | |
| 6139 | + /** @type {HTMLElement[]} */ | |
| 6140 | + const swalFunctions = Array.from(templateContent.querySelectorAll('swal-function-param')); | |
| 6141 | + swalFunctions.forEach(param => { | |
| 6142 | + const paramName = /** @type {keyof SweetAlertOptions} */param.getAttribute('name'); | |
| 6143 | + const value = param.getAttribute('value'); | |
| 6144 | + if (!paramName || !value) { | |
| 6145 | + return; | |
| 6146 | + } | |
| 6147 | + result[paramName] = new Function(`return ${value}`)(); | |
| 6148 | + }); | |
| 6149 | + return result; | |
| 6150 | + }; | |
| 6151 | + | |
| 6152 | + /** | |
| 6153 | + * @param {DocumentFragment} templateContent | |
| 6154 | + * @returns {Record<string, string | boolean>} | |
| 6155 | + */ | |
| 6156 | + const getSwalButtons = templateContent => { | |
| 6157 | + /** @type {Record<string, string | boolean>} */ | |
| 6158 | + const result = {}; | |
| 6159 | + /** @type {HTMLElement[]} */ | |
| 6160 | + const swalButtons = Array.from(templateContent.querySelectorAll('swal-button')); | |
| 6161 | + swalButtons.forEach(button => { | |
| 6162 | + showWarningsForAttributes(button, ['type', 'color', 'aria-label']); | |
| 6163 | + const type = button.getAttribute('type'); | |
| 6164 | + if (!type || !['confirm', 'cancel', 'deny'].includes(type)) { | |
| 6165 | + return; | |
| 6166 | + } | |
| 6167 | + result[`${type}ButtonText`] = button.innerHTML; | |
| 6168 | + result[`show${capitalizeFirstLetter(type)}Button`] = true; | |
| 6169 | + const color = button.getAttribute('color'); | |
| 6170 | + if (color !== null) { | |
| 6171 | + result[`${type}ButtonColor`] = color; | |
| 6172 | + } | |
| 6173 | + const ariaLabel = button.getAttribute('aria-label'); | |
| 6174 | + if (ariaLabel !== null) { | |
| 6175 | + result[`${type}ButtonAriaLabel`] = ariaLabel; | |
| 6176 | + } | |
| 6177 | + }); | |
| 6178 | + return result; | |
| 6179 | + }; | |
| 6180 | + | |
| 6181 | + /** | |
| 6182 | + * @param {DocumentFragment} templateContent | |
| 6183 | + * @returns {Pick<SweetAlertOptions, 'imageUrl' | 'imageWidth' | 'imageHeight' | 'imageAlt'>} | |
| 6184 | + */ | |
| 6185 | + const getSwalImage = templateContent => { | |
| 6186 | + const result = {}; | |
| 6187 | + /** @type {HTMLElement | null} */ | |
| 6188 | + const image = templateContent.querySelector('swal-image'); | |
| 6189 | + if (image) { | |
| 6190 | + showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']); | |
| 6191 | + // getAttribute returns null if attribute is absent; `|| undefined` converts empty string to undefined | |
| 6192 | + const src = image.getAttribute('src'); | |
| 6193 | + if (src !== null) result.imageUrl = src || undefined; | |
| 6194 | + const width = image.getAttribute('width'); | |
| 6195 | + if (width !== null) result.imageWidth = width || undefined; | |
| 6196 | + const height = image.getAttribute('height'); | |
| 6197 | + if (height !== null) result.imageHeight = height || undefined; | |
| 6198 | + const alt = image.getAttribute('alt'); | |
| 6199 | + if (alt !== null) result.imageAlt = alt || undefined; | |
| 6200 | + } | |
| 6201 | + return result; | |
| 6202 | + }; | |
| 6203 | + | |
| 6204 | + /** | |
| 6205 | + * @param {DocumentFragment} templateContent | |
| 6206 | + * @returns {object} | |
| 6207 | + */ | |
| 6208 | + const getSwalIcon = templateContent => { | |
| 6209 | + const result = {}; | |
| 6210 | + /** @type {HTMLElement | null} */ | |
| 6211 | + const icon = templateContent.querySelector('swal-icon'); | |
| 6212 | + if (icon) { | |
| 6213 | + showWarningsForAttributes(icon, ['type', 'color']); | |
| 6214 | + if (icon.hasAttribute('type')) { | |
| 6215 | + result.icon = icon.getAttribute('type'); | |
| 6216 | + } | |
| 6217 | + if (icon.hasAttribute('color')) { | |
| 6218 | + result.iconColor = icon.getAttribute('color'); | |
| 6219 | + } | |
| 6220 | + result.iconHtml = icon.innerHTML; | |
| 6221 | + } | |
| 6222 | + return result; | |
| 6223 | + }; | |
| 6224 | + | |
| 6225 | + /** | |
| 6226 | + * @param {DocumentFragment} templateContent | |
| 6227 | + * @returns {object} | |
| 6228 | + */ | |
| 6229 | + const getSwalInput = templateContent => { | |
| 6230 | + /** @type {Record<string, any>} */ | |
| 6231 | + const result = {}; | |
| 6232 | + /** @type {HTMLElement | null} */ | |
| 6233 | + const input = templateContent.querySelector('swal-input'); | |
| 6234 | + if (input) { | |
| 6235 | + showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']); | |
| 6236 | + result.input = input.getAttribute('type') || 'text'; | |
| 6237 | + if (input.hasAttribute('label')) { | |
| 6238 | + result.inputLabel = input.getAttribute('label'); | |
| 6239 | + } | |
| 6240 | + if (input.hasAttribute('placeholder')) { | |
| 6241 | + result.inputPlaceholder = input.getAttribute('placeholder'); | |
| 6242 | + } | |
| 6243 | + if (input.hasAttribute('value')) { | |
| 6244 | + result.inputValue = input.getAttribute('value'); | |
| 6245 | + } | |
| 6246 | + } | |
| 6247 | + /** @type {HTMLElement[]} */ | |
| 6248 | + const inputOptions = Array.from(templateContent.querySelectorAll('swal-input-option')); | |
| 6249 | + if (inputOptions.length) { | |
| 6250 | + result.inputOptions = {}; | |
| 6251 | + inputOptions.forEach(option => { | |
| 6252 | + showWarningsForAttributes(option, ['value']); | |
| 6253 | + const optionValue = option.getAttribute('value'); | |
| 6254 | + if (!optionValue) { | |
| 6255 | + return; | |
| 6256 | + } | |
| 6257 | + const optionName = option.innerHTML; | |
| 6258 | + result.inputOptions[optionValue] = optionName; | |
| 6259 | + }); | |
| 6260 | + } | |
| 6261 | + return result; | |
| 6262 | + }; | |
| 6263 | + | |
| 6264 | + /** | |
| 6265 | + * @param {DocumentFragment} templateContent | |
| 6266 | + * @param {string[]} paramNames | |
| 6267 | + * @returns {Record<string, string>} | |
| 6268 | + */ | |
| 6269 | + const getSwalStringParams = (templateContent, paramNames) => { | |
| 6270 | + /** @type {Record<string, string>} */ | |
| 6271 | + const result = {}; | |
| 6272 | + for (const i in paramNames) { | |
| 6273 | + const paramName = paramNames[i]; | |
| 6274 | + /** @type {HTMLElement | null} */ | |
| 6275 | + const tag = templateContent.querySelector(paramName); | |
| 6276 | + if (tag) { | |
| 6277 | + showWarningsForAttributes(tag, []); | |
| 6278 | + result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim(); | |
| 6279 | + } | |
| 6280 | + } | |
| 6281 | + return result; | |
| 6282 | + }; | |
| 6283 | + | |
| 6284 | + /** | |
| 6285 | + * @param {DocumentFragment} templateContent | |
| 6286 | + */ | |
| 6287 | + const showWarningsForElements = templateContent => { | |
| 6288 | + const allowedElements = swalStringParams.concat(['swal-param', 'swal-function-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']); | |
| 6289 | + Array.from(templateContent.children).forEach(el => { | |
| 6290 | + const tagName = el.tagName.toLowerCase(); | |
| 6291 | + if (!allowedElements.includes(tagName)) { | |
| 6292 | + warn(`Unrecognized element <${tagName}>`); | |
| 6293 | + } | |
| 6294 | + }); | |
| 6295 | + }; | |
| 6296 | + | |
| 6297 | + /** | |
| 6298 | + * @param {HTMLElement} el | |
| 6299 | + * @param {string[]} allowedAttributes | |
| 6300 | + */ | |
| 6301 | + const showWarningsForAttributes = (el, allowedAttributes) => { | |
| 6302 | + Array.from(el.attributes).forEach(attribute => { | |
| 6303 | + if (allowedAttributes.indexOf(attribute.name) === -1) { | |
| 6304 | + warn([`Unrecognized attribute "${attribute.name}" on <${el.tagName.toLowerCase()}>.`, `${allowedAttributes.length ? `Allowed attributes are: ${allowedAttributes.join(', ')}` : 'To set the value, use HTML within the element.'}`]); | |
| 6305 | + } | |
| 6306 | + }); | |
| 6307 | + }; | |
| 6308 | + | |
| 6309 | + const SHOW_CLASS_TIMEOUT = 10; | |
| 6310 | + | |
| 6311 | + /** | |
| 6312 | + * Open popup, add necessary classes and styles, fix scrollbar | |
| 6313 | + * | |
| 6314 | + * @param {SweetAlertOptions} params | |
| 6315 | + */ | |
| 6316 | + const openPopup = params => { | |
| 6317 | + var _globalState$eventEmi, _globalState$eventEmi2; | |
| 6318 | + const container = getContainer(); | |
| 6319 | + const popup = getPopup(); | |
| 6320 | + if (!container || !popup) { | |
| 6321 | + return; | |
| 6322 | + } | |
| 6323 | + if (typeof params.willOpen === 'function') { | |
| 6324 | + params.willOpen(popup); | |
| 6325 | + } | |
| 6326 | + (_globalState$eventEmi = globalState.eventEmitter) === null || _globalState$eventEmi === void 0 || _globalState$eventEmi.emit('willOpen', popup); | |
| 6327 | + const bodyStyles = window.getComputedStyle(document.body); | |
| 6328 | + const initialBodyOverflow = bodyStyles.overflowY; | |
| 6329 | + addClasses(container, popup, params); | |
| 6330 | + | |
| 6331 | + // scrolling is 'hidden' until animation is done, after that 'auto' | |
| 6332 | + setTimeout(() => { | |
| 6333 | + setScrollingVisibility(container, popup); | |
| 6334 | + }, SHOW_CLASS_TIMEOUT); | |
| 6335 | + if (isModal()) { | |
| 6336 | + fixScrollContainer(container, params.scrollbarPadding !== undefined ? params.scrollbarPadding : false, initialBodyOverflow); | |
| 6337 | + setAriaHidden(); | |
| 6338 | + } | |
| 6339 | + | |
| 6340 | + // https://github.com/sweetalert2/sweetalert2/issues/2923 | |
| 6341 | + if (isIOS && params.backdrop === false && popup.scrollHeight > container.clientHeight) { | |
| 6342 | + // remove pointer-events: none from container, it breaks scrolling tall popups in iOS | |
| 6343 | + container.style.pointerEvents = 'auto'; | |
| 6344 | + } | |
| 6345 | + if (!isToast() && !globalState.previousActiveElement) { | |
| 6346 | + globalState.previousActiveElement = document.activeElement; | |
| 6347 | + } | |
| 6348 | + if (typeof params.didOpen === 'function') { | |
| 6349 | + const didOpen = params.didOpen; | |
| 6350 | + setTimeout(() => didOpen(popup)); | |
| 6351 | + } | |
| 6352 | + (_globalState$eventEmi2 = globalState.eventEmitter) === null || _globalState$eventEmi2 === void 0 || _globalState$eventEmi2.emit('didOpen', popup); | |
| 6353 | + }; | |
| 6354 | + | |
| 6355 | + /** | |
| 6356 | + * @param {Event} event | |
| 6357 | + */ | |
| 6358 | + const swalOpenAnimationFinished = event => { | |
| 6359 | + const popup = getPopup(); | |
| 6360 | + if (!popup || event.target !== popup) { | |
| 6361 | + return; | |
| 6362 | + } | |
| 6363 | + const container = getContainer(); | |
| 6364 | + if (!container) { | |
| 6365 | + return; | |
| 6366 | + } | |
| 6367 | + popup.removeEventListener('animationend', swalOpenAnimationFinished); | |
| 6368 | + popup.removeEventListener('transitionend', swalOpenAnimationFinished); | |
| 6369 | + container.style.overflowY = 'auto'; | |
| 6370 | + | |
| 6371 | + // no-transition is added in init() in case one swal is opened right after another | |
| 6372 | + removeClass(container, swalClasses['no-transition']); | |
| 6373 | + }; | |
| 6374 | + | |
| 6375 | + /** | |
| 6376 | + * @param {HTMLElement} container | |
| 6377 | + * @param {HTMLElement} popup | |
| 6378 | + */ | |
| 6379 | + const setScrollingVisibility = (container, popup) => { | |
| 6380 | + if (hasCssAnimation(popup)) { | |
| 6381 | + container.style.overflowY = 'hidden'; | |
| 6382 | + popup.addEventListener('animationend', swalOpenAnimationFinished); | |
| 6383 | + popup.addEventListener('transitionend', swalOpenAnimationFinished); | |
| 6384 | + } else { | |
| 6385 | + container.style.overflowY = 'auto'; | |
| 6386 | + } | |
| 6387 | + }; | |
| 6388 | + | |
| 6389 | + /** | |
| 6390 | + * @param {HTMLElement} container | |
| 6391 | + * @param {boolean} scrollbarPadding | |
| 6392 | + * @param {string} initialBodyOverflow | |
| 6393 | + */ | |
| 6394 | + const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => { | |
| 6395 | + iOSfix(); | |
| 6396 | + if (scrollbarPadding && initialBodyOverflow !== 'hidden') { | |
| 6397 | + replaceScrollbarWithPadding(initialBodyOverflow); | |
| 6398 | + } | |
| 6399 | + | |
| 6400 | + // sweetalert2/issues/1247 | |
| 6401 | + setTimeout(() => { | |
| 6402 | + container.scrollTop = 0; | |
| 6403 | + }); | |
| 6404 | + }; | |
| 6405 | + | |
| 6406 | + /** | |
| 6407 | + * @param {HTMLElement} container | |
| 6408 | + * @param {HTMLElement} popup | |
| 6409 | + * @param {SweetAlertOptions} params | |
| 6410 | + */ | |
| 6411 | + const addClasses = (container, popup, params) => { | |
| 6412 | + var _params$showClass; | |
| 6413 | + if ((_params$showClass = params.showClass) !== null && _params$showClass !== void 0 && _params$showClass.backdrop) { | |
| 6414 | + addClass(container, params.showClass.backdrop); | |
| 6415 | + } | |
| 6416 | + if (params.animation) { | |
| 6417 | + // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059 | |
| 6418 | + popup.style.setProperty('opacity', '0', 'important'); | |
| 6419 | + show(popup, 'grid'); | |
| 6420 | + setTimeout(() => { | |
| 6421 | + var _params$showClass2; | |
| 6422 | + // Animate popup right after showing it | |
| 6423 | + if ((_params$showClass2 = params.showClass) !== null && _params$showClass2 !== void 0 && _params$showClass2.popup) { | |
| 6424 | + addClass(popup, params.showClass.popup); | |
| 6425 | + } | |
| 6426 | + // and remove the opacity workaround | |
| 6427 | + popup.style.removeProperty('opacity'); | |
| 6428 | + }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062 | |
| 6429 | + } else { | |
| 6430 | + show(popup, 'grid'); | |
| 6431 | + } | |
| 6432 | + addClass([document.documentElement, document.body], swalClasses.shown); | |
| 6433 | + if (params.heightAuto && params.backdrop && !params.toast) { | |
| 6434 | + addClass([document.documentElement, document.body], swalClasses['height-auto']); | |
| 6435 | + } | |
| 6436 | + }; | |
| 6437 | + | |
| 6438 | + var defaultInputValidators = { | |
| 6439 | + /** | |
| 6440 | + * @param {string} string | |
| 6441 | + * @param {string} [validationMessage] | |
| 6442 | + * @returns {Promise<string | void>} | |
| 6443 | + */ | |
| 6444 | + email: (string, validationMessage) => { | |
| 6445 | + return /^[a-zA-Z0-9.+_'-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]+$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid email address'); | |
| 6446 | + }, | |
| 6447 | + /** | |
| 6448 | + * @param {string} string | |
| 6449 | + * @param {string} [validationMessage] | |
| 6450 | + * @returns {Promise<string | void>} | |
| 6451 | + */ | |
| 6452 | + url: (string, validationMessage) => { | |
| 6453 | + // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013 | |
| 6454 | + return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid URL'); | |
| 6455 | + } | |
| 6456 | + }; | |
| 6457 | + | |
| 6458 | + /** | |
| 6459 | + * @param {SweetAlertOptions} params | |
| 6460 | + */ | |
| 6461 | + function setDefaultInputValidators(params) { | |
| 6462 | + // Use default `inputValidator` for supported input types if not provided | |
| 6463 | + if (params.inputValidator) { | |
| 6464 | + return; | |
| 6465 | + } | |
| 6466 | + if (params.input === 'email') { | |
| 6467 | + params.inputValidator = defaultInputValidators['email']; | |
| 6468 | + } | |
| 6469 | + if (params.input === 'url') { | |
| 6470 | + params.inputValidator = defaultInputValidators['url']; | |
| 6471 | + } | |
| 6472 | + } | |
| 6473 | + | |
| 6474 | + /** | |
| 6475 | + * @param {SweetAlertOptions} params | |
| 6476 | + */ | |
| 6477 | + function validateCustomTargetElement(params) { | |
| 6478 | + // Determine if the custom target element is valid | |
| 6479 | + if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) { | |
| 6480 | + warn('Target parameter is not valid, defaulting to "body"'); | |
| 6481 | + params.target = 'body'; | |
| 6482 | + } | |
| 6483 | + } | |
| 6484 | + | |
| 6485 | + /** | |
| 6486 | + * Set type, text and actions on popup | |
| 6487 | + * | |
| 6488 | + * @param {SweetAlertOptions} params | |
| 6489 | + */ | |
| 6490 | + function setParameters(params) { | |
| 6491 | + setDefaultInputValidators(params); | |
| 6492 | + | |
| 6493 | + // showLoaderOnConfirm && preConfirm | |
| 6494 | + if (params.showLoaderOnConfirm && !params.preConfirm) { | |
| 6495 | + warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request'); | |
| 6496 | + } | |
| 6497 | + validateCustomTargetElement(params); | |
| 6498 | + | |
| 6499 | + // Replace newlines with <br> in title | |
| 6500 | + if (typeof params.title === 'string') { | |
| 6501 | + params.title = params.title.split('\n').join('<br />'); | |
| 6502 | + } | |
| 6503 | + init(params); | |
| 6504 | + } | |
| 6505 | + | |
| 6506 | + /** @type {SweetAlert} */ | |
| 6507 | + let currentInstance; | |
| 6508 | + var _promise = /*#__PURE__*/new WeakMap(); | |
| 6509 | + class SweetAlert { | |
| 6510 | + /** | |
| 6511 | + * @param {...(SweetAlertOptions | string)} args | |
| 6512 | + * @this {SweetAlert} | |
| 6513 | + */ | |
| 6514 | + constructor(...args) { | |
| 6515 | + /** | |
| 6516 | + * @type {Promise<SweetAlertResult>} | |
| 6517 | + */ | |
| 6518 | + _classPrivateFieldInitSpec(this, _promise, /** @type {Promise<SweetAlertResult>} */ | |
| 6519 | + Promise.resolve({ | |
| 6520 | + isConfirmed: false, | |
| 6521 | + isDenied: false, | |
| 6522 | + isDismissed: true | |
| 6523 | + })); | |
| 6524 | + // Prevent run in Node env | |
| 6525 | + if (typeof window === 'undefined') { | |
| 6526 | + return; | |
| 6527 | + } | |
| 6528 | + currentInstance = this; | |
| 6529 | + | |
| 6530 | + // @ts-ignore | |
| 6531 | + const outerParams = Object.freeze(this.constructor.argsToParams(args)); | |
| 6532 | + | |
| 6533 | + /** @type {Readonly<SweetAlertOptions>} */ | |
| 6534 | + this.params = outerParams; | |
| 6535 | + | |
| 6536 | + /** @type {boolean} */ | |
| 6537 | + this.isAwaitingPromise = false; | |
| 6538 | + _classPrivateFieldSet2(_promise, this, this._main(currentInstance.params)); | |
| 6539 | + } | |
| 6540 | + | |
| 6541 | + /** | |
| 6542 | + * @param {any} userParams | |
| 6543 | + * @param {any} mixinParams | |
| 6544 | + */ | |
| 6545 | + _main(userParams, mixinParams = {}) { | |
| 6546 | + showWarningsForParams(Object.assign({}, mixinParams, userParams)); | |
| 6547 | + if (globalState.currentInstance) { | |
| 6548 | + const swalPromiseResolve = privateMethods.swalPromiseResolve.get(globalState.currentInstance); | |
| 6549 | + const { | |
| 6550 | + isAwaitingPromise | |
| 6551 | + } = globalState.currentInstance; | |
| 6552 | + globalState.currentInstance._destroy(); | |
| 6553 | + if (!isAwaitingPromise) { | |
| 6554 | + swalPromiseResolve({ | |
| 6555 | + isDismissed: true | |
| 6556 | + }); | |
| 6557 | + } | |
| 6558 | + if (isModal()) { | |
| 6559 | + unsetAriaHidden(); | |
| 6560 | + } | |
| 6561 | + } | |
| 6562 | + globalState.currentInstance = currentInstance; | |
| 6563 | + const innerParams = prepareParams(userParams, mixinParams); | |
| 6564 | + setParameters(innerParams); | |
| 6565 | + Object.freeze(innerParams); | |
| 6566 | + | |
| 6567 | + // clear the previous timer | |
| 6568 | + if (globalState.timeout) { | |
| 6569 | + globalState.timeout.stop(); | |
| 6570 | + delete globalState.timeout; | |
| 6571 | + } | |
| 6572 | + | |
| 6573 | + // clear the restore focus timeout | |
| 6574 | + clearTimeout(globalState.restoreFocusTimeout); | |
| 6575 | + const domCache = populateDomCache(currentInstance); | |
| 6576 | + render(currentInstance, innerParams); | |
| 6577 | + privateProps.innerParams.set(currentInstance, innerParams); | |
| 6578 | + return swalPromise(currentInstance, domCache, innerParams); | |
| 6579 | + } | |
| 6580 | + | |
| 6581 | + // `catch` cannot be the name of a module export, so we define our thenable methods here instead | |
| 6582 | + /** | |
| 6583 | + * @param {any} onFulfilled | |
| 6584 | + */ | |
| 6585 | + // oxlint-disable-next-line unicorn/no-thenable | |
| 6586 | + then(onFulfilled) { | |
| 6587 | + return _classPrivateFieldGet2(_promise, this).then(onFulfilled); | |
| 6588 | + } | |
| 6589 | + | |
| 6590 | + /** | |
| 6591 | + * @param {any} onFinally | |
| 6592 | + */ | |
| 6593 | + finally(onFinally) { | |
| 6594 | + return _classPrivateFieldGet2(_promise, this).finally(onFinally); | |
| 6595 | + } | |
| 6596 | + } | |
| 6597 | + | |
| 6598 | + /** | |
| 6599 | + * @param {SweetAlert} instance | |
| 6600 | + * @param {DomCache} domCache | |
| 6601 | + * @param {SweetAlertOptions} innerParams | |
| 6602 | + * @returns {Promise<SweetAlertResult>} | |
| 6603 | + */ | |
| 6604 | + const swalPromise = (instance, domCache, innerParams) => { | |
| 6605 | + return new Promise((resolve, reject) => { | |
| 6606 | + // functions to handle all closings/dismissals | |
| 6607 | + /** | |
| 6608 | + * @param {DismissReason} dismiss | |
| 6609 | + */ | |
| 6610 | + const dismissWith = dismiss => { | |
| 6611 | + instance.close({ | |
| 6612 | + isDismissed: true, | |
| 6613 | + dismiss, | |
| 6614 | + isConfirmed: false, | |
| 6615 | + isDenied: false | |
| 6616 | + }); | |
| 6617 | + }; | |
| 6618 | + privateMethods.swalPromiseResolve.set(instance, resolve); | |
| 6619 | + privateMethods.swalPromiseReject.set(instance, reject); | |
| 6620 | + domCache.confirmButton.onclick = () => { | |
| 6621 | + handleConfirmButtonClick(instance); | |
| 6622 | + }; | |
| 6623 | + domCache.denyButton.onclick = () => { | |
| 6624 | + handleDenyButtonClick(instance); | |
| 6625 | + }; | |
| 6626 | + domCache.cancelButton.onclick = () => { | |
| 6627 | + handleCancelButtonClick(instance, dismissWith); | |
| 6628 | + }; | |
| 6629 | + domCache.closeButton.onclick = () => { | |
| 6630 | + dismissWith(DismissReason.close); | |
| 6631 | + }; | |
| 6632 | + handlePopupClick(innerParams, domCache, dismissWith); | |
| 6633 | + addKeydownHandler(globalState, innerParams, dismissWith); | |
| 6634 | + handleInputOptionsAndValue(instance, innerParams); | |
| 6635 | + openPopup(innerParams); | |
| 6636 | + setupTimer(globalState, innerParams, dismissWith); | |
| 6637 | + initFocus(domCache, innerParams); | |
| 6638 | + | |
| 6639 | + // Scroll container to top on open (#1247, #1946) | |
| 6640 | + setTimeout(() => { | |
| 6641 | + domCache.container.scrollTop = 0; | |
| 6642 | + }); | |
| 6643 | + }); | |
| 6644 | + }; | |
| 6645 | + | |
| 6646 | + /** | |
| 6647 | + * @param {SweetAlertOptions} userParams | |
| 6648 | + * @param {SweetAlertOptions} mixinParams | |
| 6649 | + * @returns {SweetAlertOptions} | |
| 6650 | + */ | |
| 6651 | + const prepareParams = (userParams, mixinParams) => { | |
| 6652 | + const templateParams = getTemplateParams(userParams); | |
| 6653 | + const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131 | |
| 6654 | + params.showClass = Object.assign({}, defaultParams.showClass, params.showClass); | |
| 6655 | + params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass); | |
| 6656 | + if (params.animation === false) { | |
| 6657 | + params.showClass = { | |
| 6658 | + backdrop: 'swal2-noanimation' | |
| 6659 | + }; | |
| 6660 | + params.hideClass = {}; | |
| 6661 | + } | |
| 6662 | + return params; | |
| 6663 | + }; | |
| 6664 | + | |
| 6665 | + /** | |
| 6666 | + * @param {SweetAlert} instance | |
| 6667 | + * @returns {DomCache} | |
| 6668 | + */ | |
| 6669 | + const populateDomCache = instance => { | |
| 6670 | + const domCache = /** @type {DomCache} */{ | |
| 6671 | + popup: (/** @type {HTMLElement} */getPopup()), | |
| 6672 | + container: (/** @type {HTMLElement} */getContainer()), | |
| 6673 | + actions: (/** @type {HTMLElement} */getActions()), | |
| 6674 | + confirmButton: (/** @type {HTMLElement} */getConfirmButton()), | |
| 6675 | + denyButton: (/** @type {HTMLElement} */getDenyButton()), | |
| 6676 | + cancelButton: (/** @type {HTMLElement} */getCancelButton()), | |
| 6677 | + loader: (/** @type {HTMLElement} */getLoader()), | |
| 6678 | + closeButton: (/** @type {HTMLElement} */getCloseButton()), | |
| 6679 | + validationMessage: (/** @type {HTMLElement} */getValidationMessage()), | |
| 6680 | + progressSteps: (/** @type {HTMLElement} */getProgressSteps()) | |
| 6681 | + }; | |
| 6682 | + privateProps.domCache.set(instance, domCache); | |
| 6683 | + return domCache; | |
| 6684 | + }; | |
| 6685 | + | |
| 6686 | + /** | |
| 6687 | + * @param {GlobalState} globalState | |
| 6688 | + * @param {SweetAlertOptions} innerParams | |
| 6689 | + * @param {(dismiss: DismissReason) => void} dismissWith | |
| 6690 | + */ | |
| 6691 | + const setupTimer = (globalState, innerParams, dismissWith) => { | |
| 6692 | + const timerProgressBar = getTimerProgressBar(); | |
| 6693 | + hide(timerProgressBar); | |
| 6694 | + if (innerParams.timer) { | |
| 6695 | + globalState.timeout = new Timer(() => { | |
| 6696 | + dismissWith('timer'); | |
| 6697 | + delete globalState.timeout; | |
| 6698 | + }, innerParams.timer); | |
| 6699 | + if (innerParams.timerProgressBar && timerProgressBar) { | |
| 6700 | + show(timerProgressBar); | |
| 6701 | + applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar'); | |
| 6702 | + setTimeout(() => { | |
| 6703 | + if (globalState.timeout && globalState.timeout.running) { | |
| 6704 | + // timer can be already stopped or unset at this point | |
| 6705 | + animateTimerProgressBar(/** @type {number} */innerParams.timer); | |
| 6706 | + } | |
| 6707 | + }); | |
| 6708 | + } | |
| 6709 | + } | |
| 6710 | + }; | |
| 6711 | + | |
| 6712 | + /** | |
| 6713 | + * Initialize focus in the popup: | |
| 6714 | + * | |
| 6715 | + * 1. If `toast` is `true`, don't steal focus from the document. | |
| 6716 | + * 2. Else if there is an [autofocus] element, focus it. | |
| 6717 | + * 3. Else if `focusConfirm` is `true` and confirm button is visible, focus it. | |
| 6718 | + * 4. Else if `focusDeny` is `true` and deny button is visible, focus it. | |
| 6719 | + * 5. Else if `focusCancel` is `true` and cancel button is visible, focus it. | |
| 6720 | + * 6. Else focus the first focusable element in a popup (if any). | |
| 6721 | + * | |
| 6722 | + * @param {DomCache} domCache | |
| 6723 | + * @param {SweetAlertOptions} innerParams | |
| 6724 | + */ | |
| 6725 | + const initFocus = (domCache, innerParams) => { | |
| 6726 | + if (innerParams.toast) { | |
| 6727 | + return; | |
| 6728 | + } | |
| 6729 | + // TODO: this is dumb, remove `allowEnterKey` param in the next major version | |
| 6730 | + if (!callIfFunction(innerParams.allowEnterKey)) { | |
| 6731 | + warnAboutDeprecation('allowEnterKey', 'preConfirm: () => false'); | |
| 6732 | + domCache.popup.focus(); | |
| 6733 | + return; | |
| 6734 | + } | |
| 6735 | + if (focusAutofocus(domCache)) { | |
| 6736 | + return; | |
| 6737 | + } | |
| 6738 | + if (focusButton(domCache, innerParams)) { | |
| 6739 | + return; | |
| 6740 | + } | |
| 6741 | + setFocus(-1, 1); | |
| 6742 | + }; | |
| 6743 | + | |
| 6744 | + /** | |
| 6745 | + * @param {DomCache} domCache | |
| 6746 | + * @returns {boolean} | |
| 6747 | + */ | |
| 6748 | + const focusAutofocus = domCache => { | |
| 6749 | + const autofocusElements = Array.from(domCache.popup.querySelectorAll('[autofocus]')); | |
| 6750 | + for (const autofocusElement of autofocusElements) { | |
| 6751 | + if (autofocusElement instanceof HTMLElement && isVisible$1(autofocusElement)) { | |
| 6752 | + autofocusElement.focus(); | |
| 6753 | + return true; | |
| 6754 | + } | |
| 6755 | + } | |
| 6756 | + return false; | |
| 6757 | + }; | |
| 6758 | + | |
| 6759 | + /** | |
| 6760 | + * @param {DomCache} domCache | |
| 6761 | + * @param {SweetAlertOptions} innerParams | |
| 6762 | + * @returns {boolean} | |
| 6763 | + */ | |
| 6764 | + const focusButton = (domCache, innerParams) => { | |
| 6765 | + if (innerParams.focusDeny && isVisible$1(domCache.denyButton)) { | |
| 6766 | + domCache.denyButton.focus(); | |
| 6767 | + return true; | |
| 6768 | + } | |
| 6769 | + if (innerParams.focusCancel && isVisible$1(domCache.cancelButton)) { | |
| 6770 | + domCache.cancelButton.focus(); | |
| 6771 | + return true; | |
| 6772 | + } | |
| 6773 | + if (innerParams.focusConfirm && isVisible$1(domCache.confirmButton)) { | |
| 6774 | + domCache.confirmButton.focus(); | |
| 6775 | + return true; | |
| 6776 | + } | |
| 6777 | + return false; | |
| 6778 | + }; | |
| 6779 | + | |
| 6780 | + // Assign instance methods from src/instanceMethods/*.js to prototype | |
| 6781 | + SweetAlert.prototype.disableButtons = disableButtons; | |
| 6782 | + SweetAlert.prototype.enableButtons = enableButtons; | |
| 6783 | + SweetAlert.prototype.getInput = getInput; | |
| 6784 | + SweetAlert.prototype.disableInput = disableInput; | |
| 6785 | + SweetAlert.prototype.enableInput = enableInput; | |
| 6786 | + SweetAlert.prototype.hideLoading = hideLoading; | |
| 6787 | + SweetAlert.prototype.disableLoading = hideLoading; | |
| 6788 | + SweetAlert.prototype.showValidationMessage = showValidationMessage; | |
| 6789 | + SweetAlert.prototype.resetValidationMessage = resetValidationMessage; | |
| 6790 | + SweetAlert.prototype.close = close; | |
| 6791 | + SweetAlert.prototype.closePopup = close; | |
| 6792 | + SweetAlert.prototype.closeModal = close; | |
| 6793 | + SweetAlert.prototype.closeToast = close; | |
| 6794 | + SweetAlert.prototype.rejectPromise = rejectPromise; | |
| 6795 | + SweetAlert.prototype.update = update; | |
| 6796 | + SweetAlert.prototype._destroy = _destroy; | |
| 6797 | + | |
| 6798 | + // Assign static methods from src/staticMethods/*.js to constructor | |
| 6799 | + Object.assign(SweetAlert, staticMethods); | |
| 6800 | + | |
| 6801 | + // Proxy to instance methods to constructor, for now, for backwards compatibility | |
| 6802 | + Object.keys(instanceMethods).forEach(key => { | |
| 6803 | + /** | |
| 6804 | + * @param {...(SweetAlertOptions | string | undefined)} args | |
| 6805 | + * @returns {SweetAlertResult | Promise<SweetAlertResult> | undefined} | |
| 6806 | + */ | |
| 6807 | + // @ts-ignore: Dynamic property assignment for backwards compatibility | |
| 6808 | + SweetAlert[key] = function (...args) { | |
| 6809 | + // @ts-ignore | |
| 6810 | + if (currentInstance && currentInstance[key]) { | |
| 6811 | + // @ts-ignore | |
| 6812 | + return currentInstance[key](...args); | |
| 6813 | + } | |
| 6814 | + return undefined; | |
| 6815 | + }; | |
| 6816 | + }); | |
| 6817 | + SweetAlert.DismissReason = DismissReason; | |
| 6818 | + SweetAlert.version = '11.26.25'; | |
| 6819 | + | |
| 6820 | + const Swal = SweetAlert; | |
| 6821 | + // @ts-ignore | |
| 6822 | + Swal.default = Swal; | |
| 6823 | + | |
| 6824 | + return Swal; | |
| 6825 | + | |
| 6826 | +})); | |
| 6827 | +if (typeof this !== 'undefined' && this.Sweetalert2){this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2} | |
| 6828 | +"undefined"!=typeof document&&function(e,t){var n=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=t);else try{n.innerHTML=t}catch(e){n.innerText=t}}(document,":root{--swal2-outline: 0 0 0 3px rgba(100, 150, 200, 0.5);--swal2-container-padding: 0.625em;--swal2-backdrop: rgba(0, 0, 0, 0.4);--swal2-backdrop-transition: background-color 0.15s;--swal2-width: 32em;--swal2-padding: 0 0 1.25em;--swal2-border: none;--swal2-border-radius: 0.3125rem;--swal2-background: white;--swal2-color: #545454;--swal2-show-animation: swal2-show 0.3s;--swal2-hide-animation: swal2-hide 0.15s forwards;--swal2-icon-zoom: 1;--swal2-title-padding: 0.8em 1em 0;--swal2-html-container-padding: 1em 1.6em 0.3em;--swal2-input-border: 1px solid #d9d9d9;--swal2-input-border-radius: 0.1875em;--swal2-input-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06), 0 0 0 3px transparent;--swal2-input-background: transparent;--swal2-input-transition: border-color 0.2s, box-shadow 0.2s;--swal2-input-hover-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06), 0 0 0 3px transparent;--swal2-input-focus-border: 1px solid #b4dbed;--swal2-input-focus-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06), 0 0 0 3px rgba(100, 150, 200, 0.5);--swal2-progress-step-background: #add8e6;--swal2-validation-message-background: #f0f0f0;--swal2-validation-message-color: #666;--swal2-footer-border-color: #eee;--swal2-footer-background: transparent;--swal2-footer-color: inherit;--swal2-timer-progress-bar-background: rgba(0, 0, 0, 0.3);--swal2-close-button-position: initial;--swal2-close-button-inset: auto;--swal2-close-button-font-size: 2.5em;--swal2-close-button-color: #ccc;--swal2-close-button-transition: color 0.2s, box-shadow 0.2s;--swal2-close-button-outline: initial;--swal2-close-button-box-shadow: inset 0 0 0 3px transparent;--swal2-close-button-focus-box-shadow: inset var(--swal2-outline);--swal2-close-button-hover-transform: none;--swal2-actions-justify-content: center;--swal2-actions-width: auto;--swal2-actions-margin: 1.25em auto 0;--swal2-actions-padding: 0;--swal2-actions-border-radius: 0;--swal2-actions-background: transparent;--swal2-action-button-transition: background-color 0.2s, box-shadow 0.2s;--swal2-action-button-hover: black 10%;--swal2-action-button-active: black 10%;--swal2-confirm-button-box-shadow: none;--swal2-confirm-button-border-radius: 0.25em;--swal2-confirm-button-background-color: #7066e0;--swal2-confirm-button-color: #fff;--swal2-deny-button-box-shadow: none;--swal2-deny-button-border-radius: 0.25em;--swal2-deny-button-background-color: #dc3741;--swal2-deny-button-color: #fff;--swal2-cancel-button-box-shadow: none;--swal2-cancel-button-border-radius: 0.25em;--swal2-cancel-button-background-color: #6e7881;--swal2-cancel-button-color: #fff;--swal2-toast-show-animation: swal2-toast-show 0.5s;--swal2-toast-hide-animation: swal2-toast-hide 0.1s forwards;--swal2-toast-border: none;--swal2-toast-box-shadow: 0 0 1px hsl(0deg 0% 0% / 0.075), 0 1px 2px hsl(0deg 0% 0% / 0.075), 1px 2px 4px hsl(0deg 0% 0% / 0.075), 1px 3px 8px hsl(0deg 0% 0% / 0.075), 2px 4px 16px hsl(0deg 0% 0% / 0.075)}[data-swal2-theme=dark]{--swal2-dark-theme-black: #19191a;--swal2-dark-theme-white: #e1e1e1;--swal2-background: var(--swal2-dark-theme-black);--swal2-color: var(--swal2-dark-theme-white);--swal2-footer-border-color: #555;--swal2-input-background: color-mix(in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10%);--swal2-validation-message-background: color-mix( in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10% );--swal2-validation-message-color: var(--swal2-dark-theme-white);--swal2-timer-progress-bar-background: rgba(255, 255, 255, 0.7)}@media(prefers-color-scheme: dark){[data-swal2-theme=auto]{--swal2-dark-theme-black: #19191a;--swal2-dark-theme-white: #e1e1e1;--swal2-background: var(--swal2-dark-theme-black);--swal2-color: var(--swal2-dark-theme-white);--swal2-footer-border-color: #555;--swal2-input-background: color-mix(in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10%);--swal2-validation-message-background: color-mix( in srgb, var(--swal2-dark-theme-black), var(--swal2-dark-theme-white) 10% );--swal2-validation-message-color: var(--swal2-dark-theme-white);--swal2-timer-progress-bar-background: rgba(255, 255, 255, 0.7)}}body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto !important}body.swal2-no-backdrop .swal2-container{background-color:rgba(0,0,0,0) !important;pointer-events:none}body.swal2-no-backdrop .swal2-container .swal2-popup{pointer-events:auto}body.swal2-no-backdrop .swal2-container .swal2-modal{box-shadow:0 0 10px var(--swal2-backdrop)}body.swal2-toast-shown .swal2-container{box-sizing:border-box;width:360px;max-width:100%;background-color:rgba(0,0,0,0);pointer-events:none}body.swal2-toast-shown .swal2-container.swal2-top{inset:0 auto auto 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{inset:0 0 auto auto}body.swal2-toast-shown .swal2-container.swal2-top-start,body.swal2-toast-shown .swal2-container.swal2-top-left{inset:0 auto auto 0}body.swal2-toast-shown .swal2-container.swal2-center-start,body.swal2-toast-shown .swal2-container.swal2-center-left{inset:50% auto auto 0;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{inset:50% auto auto 50%;transform:translate(-50%, -50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{inset:50% 0 auto auto;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-start,body.swal2-toast-shown .swal2-container.swal2-bottom-left{inset:auto auto 0 0}body.swal2-toast-shown .swal2-container.swal2-bottom{inset:auto auto 0 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{inset:auto 0 0 auto}@media print{body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown){overflow-y:scroll !important}body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop,.swal2-toast-shown) .swal2-container{position:static !important}}div:where(.swal2-container){display:grid;position:fixed;z-index:1060;inset:0;box-sizing:border-box;grid-template-areas:\"top-start top top-end\" \"center-start center center-end\" \"bottom-start bottom-center bottom-end\";grid-template-rows:minmax(min-content, auto) minmax(min-content, auto) minmax(min-content, auto);height:100%;padding:var(--swal2-container-padding);overflow-x:hidden;transition:var(--swal2-backdrop-transition);-webkit-overflow-scrolling:touch}div:where(.swal2-container).swal2-backdrop-show,div:where(.swal2-container).swal2-noanimation{background:var(--swal2-backdrop)}div:where(.swal2-container).swal2-backdrop-hide{background:rgba(0,0,0,0) !important}div:where(.swal2-container).swal2-top-start,div:where(.swal2-container).swal2-center-start,div:where(.swal2-container).swal2-bottom-start{grid-template-columns:minmax(0, 1fr) auto auto}div:where(.swal2-container).swal2-top,div:where(.swal2-container).swal2-center,div:where(.swal2-container).swal2-bottom{grid-template-columns:auto minmax(0, 1fr) auto}div:where(.swal2-container).swal2-top-end,div:where(.swal2-container).swal2-center-end,div:where(.swal2-container).swal2-bottom-end{grid-template-columns:auto auto minmax(0, 1fr)}div:where(.swal2-container).swal2-top-start>.swal2-popup{align-self:start}div:where(.swal2-container).swal2-top>.swal2-popup{grid-column:2;place-self:start center}div:where(.swal2-container).swal2-top-end>.swal2-popup,div:where(.swal2-container).swal2-top-right>.swal2-popup{grid-column:3;place-self:start end}div:where(.swal2-container).swal2-center-start>.swal2-popup,div:where(.swal2-container).swal2-center-left>.swal2-popup{grid-row:2;align-self:center}div:where(.swal2-container).swal2-center>.swal2-popup{grid-column:2;grid-row:2;place-self:center center}div:where(.swal2-container).swal2-center-end>.swal2-popup,div:where(.swal2-container).swal2-center-right>.swal2-popup{grid-column:3;grid-row:2;place-self:center end}div:where(.swal2-container).swal2-bottom-start>.swal2-popup,div:where(.swal2-container).swal2-bottom-left>.swal2-popup{grid-column:1;grid-row:3;align-self:end}div:where(.swal2-container).swal2-bottom>.swal2-popup{grid-column:2;grid-row:3;place-self:end center}div:where(.swal2-container).swal2-bottom-end>.swal2-popup,div:where(.swal2-container).swal2-bottom-right>.swal2-popup{grid-column:3;grid-row:3;place-self:end end}div:where(.swal2-container).swal2-grow-row>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-column:1/4;width:100%}div:where(.swal2-container).swal2-grow-column>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-row:1/4;align-self:stretch}div:where(.swal2-container).swal2-no-transition{transition:none !important}div:where(.swal2-container)[popover]{width:auto;border:0}div:where(.swal2-container) div:where(.swal2-popup){display:none;position:relative;box-sizing:border-box;grid-template-columns:minmax(0, 100%);width:var(--swal2-width);max-width:100%;padding:var(--swal2-padding);border:var(--swal2-border);border-radius:var(--swal2-border-radius);background:var(--swal2-background);color:var(--swal2-color);font-family:inherit;font-size:1rem}div:where(.swal2-container) div:where(.swal2-popup):focus{outline:none}div:where(.swal2-container) div:where(.swal2-popup).swal2-loading{overflow-y:hidden}div:where(.swal2-container) div:where(.swal2-popup).swal2-draggable{cursor:grab}div:where(.swal2-container) div:where(.swal2-popup).swal2-draggable div:where(.swal2-icon){cursor:grab}div:where(.swal2-container) div:where(.swal2-popup).swal2-dragging{cursor:grabbing}div:where(.swal2-container) div:where(.swal2-popup).swal2-dragging div:where(.swal2-icon){cursor:grabbing}div:where(.swal2-container) h2:where(.swal2-title){position:relative;max-width:100%;margin:0;padding:var(--swal2-title-padding);color:inherit;font-size:1.875em;font-weight:600;text-align:center;text-transform:none;overflow-wrap:break-word;cursor:initial}div:where(.swal2-container) div:where(.swal2-actions){display:flex;z-index:1;box-sizing:border-box;flex-wrap:wrap;align-items:center;justify-content:var(--swal2-actions-justify-content);width:var(--swal2-actions-width);margin:var(--swal2-actions-margin);padding:var(--swal2-actions-padding);border-radius:var(--swal2-actions-border-radius);background:var(--swal2-actions-background)}div:where(.swal2-container) div:where(.swal2-loader){display:none;align-items:center;justify-content:center;width:2.2em;height:2.2em;margin:0 1.875em;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-width:.25em;border-style:solid;border-radius:100%;border-color:#2778c4 rgba(0,0,0,0) #2778c4 rgba(0,0,0,0)}div:where(.swal2-container) button:where(.swal2-styled){margin:.3125em;padding:.625em 1.1em;transition:var(--swal2-action-button-transition);border:none;box-shadow:0 0 0 3px rgba(0,0,0,0);font-weight:500}div:where(.swal2-container) button:where(.swal2-styled):not([disabled]){cursor:pointer}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-confirm){border-radius:var(--swal2-confirm-button-border-radius);background:initial;background-color:var(--swal2-confirm-button-background-color);box-shadow:var(--swal2-confirm-button-box-shadow);color:var(--swal2-confirm-button-color);font-size:1em}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-confirm):hover{background-color:color-mix(in srgb, var(--swal2-confirm-button-background-color), var(--swal2-action-button-hover))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-confirm):active{background-color:color-mix(in srgb, var(--swal2-confirm-button-background-color), var(--swal2-action-button-active))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-deny){border-radius:var(--swal2-deny-button-border-radius);background:initial;background-color:var(--swal2-deny-button-background-color);box-shadow:var(--swal2-deny-button-box-shadow);color:var(--swal2-deny-button-color);font-size:1em}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-deny):hover{background-color:color-mix(in srgb, var(--swal2-deny-button-background-color), var(--swal2-action-button-hover))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-deny):active{background-color:color-mix(in srgb, var(--swal2-deny-button-background-color), var(--swal2-action-button-active))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-cancel){border-radius:var(--swal2-cancel-button-border-radius);background:initial;background-color:var(--swal2-cancel-button-background-color);box-shadow:var(--swal2-cancel-button-box-shadow);color:var(--swal2-cancel-button-color);font-size:1em}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-cancel):hover{background-color:color-mix(in srgb, var(--swal2-cancel-button-background-color), var(--swal2-action-button-hover))}div:where(.swal2-container) button:where(.swal2-styled):where(.swal2-cancel):active{background-color:color-mix(in srgb, var(--swal2-cancel-button-background-color), var(--swal2-action-button-active))}div:where(.swal2-container) button:where(.swal2-styled):focus-visible{outline:none;box-shadow:var(--swal2-action-button-focus-box-shadow)}div:where(.swal2-container) button:where(.swal2-styled)[disabled]:not(.swal2-loading){opacity:.4}div:where(.swal2-container) button:where(.swal2-styled)::-moz-focus-inner{border:0}div:where(.swal2-container) div:where(.swal2-footer){margin:1em 0 0;padding:1em 1em 0;border-top:1px solid var(--swal2-footer-border-color);background:var(--swal2-footer-background);color:var(--swal2-footer-color);font-size:1em;text-align:center;cursor:initial}div:where(.swal2-container) .swal2-timer-progress-bar-container{position:absolute;right:0;bottom:0;left:0;grid-column:auto !important;overflow:hidden;border-bottom-right-radius:var(--swal2-border-radius);border-bottom-left-radius:var(--swal2-border-radius)}div:where(.swal2-container) div:where(.swal2-timer-progress-bar){width:100%;height:.25em;background:var(--swal2-timer-progress-bar-background)}div:where(.swal2-container) img:where(.swal2-image){max-width:100%;margin:2em auto 1em;cursor:initial}div:where(.swal2-container) button:where(.swal2-close){position:var(--swal2-close-button-position);inset:var(--swal2-close-button-inset);z-index:2;align-items:center;justify-content:center;width:1.2em;height:1.2em;margin-top:0;margin-right:0;margin-bottom:-1.2em;padding:0;overflow:hidden;transition:var(--swal2-close-button-transition);border:none;border-radius:var(--swal2-border-radius);outline:var(--swal2-close-button-outline);background:rgba(0,0,0,0);color:var(--swal2-close-button-color);font-family:monospace;font-size:var(--swal2-close-button-font-size);cursor:pointer;justify-self:end}div:where(.swal2-container) button:where(.swal2-close):hover{transform:var(--swal2-close-button-hover-transform);background:rgba(0,0,0,0);color:#f27474}div:where(.swal2-container) button:where(.swal2-close):focus-visible{outline:none;box-shadow:var(--swal2-close-button-focus-box-shadow)}div:where(.swal2-container) button:where(.swal2-close)::-moz-focus-inner{border:0}div:where(.swal2-container) div:where(.swal2-html-container){z-index:1;justify-content:center;margin:0;padding:var(--swal2-html-container-padding);overflow:auto;color:inherit;font-size:1.125em;font-weight:normal;line-height:normal;text-align:center;overflow-wrap:break-word;word-break:break-word;cursor:initial}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea),div:where(.swal2-container) select:where(.swal2-select),div:where(.swal2-container) div:where(.swal2-radio),div:where(.swal2-container) label:where(.swal2-checkbox){margin:1em 2em 3px}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea){box-sizing:border-box;width:auto;transition:var(--swal2-input-transition);border:var(--swal2-input-border);border-radius:var(--swal2-input-border-radius);background:var(--swal2-input-background);box-shadow:var(--swal2-input-box-shadow);color:inherit;font-size:1.125em}div:where(.swal2-container) input:where(.swal2-input).swal2-inputerror,div:where(.swal2-container) input:where(.swal2-file).swal2-inputerror,div:where(.swal2-container) textarea:where(.swal2-textarea).swal2-inputerror{border-color:#f27474 !important;box-shadow:0 0 2px #f27474 !important}div:where(.swal2-container) input:where(.swal2-input):hover,div:where(.swal2-container) input:where(.swal2-file):hover,div:where(.swal2-container) textarea:where(.swal2-textarea):hover{box-shadow:var(--swal2-input-hover-box-shadow)}div:where(.swal2-container) input:where(.swal2-input):focus,div:where(.swal2-container) input:where(.swal2-file):focus,div:where(.swal2-container) textarea:where(.swal2-textarea):focus{border:var(--swal2-input-focus-border);outline:none;box-shadow:var(--swal2-input-focus-box-shadow)}div:where(.swal2-container) input:where(.swal2-input)::placeholder,div:where(.swal2-container) input:where(.swal2-file)::placeholder,div:where(.swal2-container) textarea:where(.swal2-textarea)::placeholder{color:#ccc}div:where(.swal2-container) .swal2-range{margin:1em 2em 3px;background:var(--swal2-background)}div:where(.swal2-container) .swal2-range input{width:80%}div:where(.swal2-container) .swal2-range output{width:20%;color:inherit;font-weight:600;text-align:center}div:where(.swal2-container) .swal2-range input,div:where(.swal2-container) .swal2-range output{height:2.625em;padding:0;font-size:1.125em;line-height:2.625em}div:where(.swal2-container) .swal2-input{height:2.625em;padding:0 .75em}div:where(.swal2-container) .swal2-file{width:75%;margin-right:auto;margin-left:auto;background:var(--swal2-input-background);font-size:1.125em}div:where(.swal2-container) .swal2-textarea{height:6.75em;padding:.75em}div:where(.swal2-container) .swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:var(--swal2-input-background);color:inherit;font-size:1.125em}div:where(.swal2-container) .swal2-radio,div:where(.swal2-container) .swal2-checkbox{align-items:center;justify-content:center;background:var(--swal2-background);color:inherit}div:where(.swal2-container) .swal2-radio label,div:where(.swal2-container) .swal2-checkbox label{margin:0 .6em;font-size:1.125em}div:where(.swal2-container) .swal2-radio input,div:where(.swal2-container) .swal2-checkbox input{flex-shrink:0;margin:0 .4em}div:where(.swal2-container) label:where(.swal2-input-label){display:flex;justify-content:center;margin:1em auto 0}div:where(.swal2-container) div:where(.swal2-validation-message){align-items:center;justify-content:center;margin:1em 0 0;padding:.625em;overflow:hidden;background:var(--swal2-validation-message-background);color:var(--swal2-validation-message-color);font-size:1em;font-weight:300}div:where(.swal2-container) div:where(.swal2-validation-message)::before{content:\"!\";display:inline-block;width:1.5em;min-width:1.5em;height:1.5em;margin:0 .625em;border-radius:50%;background-color:#f27474;color:#fff;font-weight:600;line-height:1.5em;text-align:center}div:where(.swal2-container) .swal2-progress-steps{flex-wrap:wrap;align-items:center;max-width:100%;margin:1.25em auto;padding:0;background:rgba(0,0,0,0);font-weight:600}div:where(.swal2-container) .swal2-progress-steps li{display:inline-block;position:relative}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step{z-index:20;flex-shrink:0;width:2em;height:2em;border-radius:2em;background:#2778c4;color:#fff;line-height:2em;text-align:center}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:var(--swal2-progress-step-background);color:#fff}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:var(--swal2-progress-step-background)}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step-line{z-index:10;flex-shrink:0;width:2.5em;height:.4em;margin:0 -1px;background:#2778c4}div:where(.swal2-icon){position:relative;box-sizing:content-box;justify-content:center;width:5em;height:5em;margin:2.5em auto .6em;zoom:var(--swal2-icon-zoom);border:.25em solid rgba(0,0,0,0);border-radius:50%;border-color:#000;font-family:inherit;line-height:5em;cursor:default;user-select:none}div:where(.swal2-icon) .swal2-icon-content{display:flex;align-items:center;font-size:3.75em}div:where(.swal2-icon).swal2-error{border-color:#f27474;color:#f27474}div:where(.swal2-icon).swal2-error .swal2-x-mark{position:relative;flex-grow:1}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line]{display:block;position:absolute;top:2.3125em;width:2.9375em;height:.3125em;border-radius:.125em;background-color:#f27474}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-error.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}div:where(.swal2-icon).swal2-warning{border-color:#f8bb86;color:#f8bb86}div:where(.swal2-icon).swal2-warning.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-warning.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .5s}div:where(.swal2-icon).swal2-info{border-color:#3fc3ee;color:#3fc3ee}div:where(.swal2-icon).swal2-info.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-info.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .8s}div:where(.swal2-icon).swal2-question{border-color:#87adbd;color:#87adbd}div:where(.swal2-icon).swal2-question.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-question.swal2-icon-show .swal2-icon-content{animation:swal2-animate-question-mark .8s}div:where(.swal2-icon).swal2-success{border-color:#a5dc86;color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line]{position:absolute;width:3.75em;height:7.5em;border-radius:50%}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.4375em;left:-2.0635em;transform:rotate(-45deg);transform-origin:3.75em 3.75em;border-radius:7.5em 0 0 7.5em}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.6875em;left:1.875em;transform:rotate(-45deg);transform-origin:0 3.75em;border-radius:0 7.5em 7.5em 0}div:where(.swal2-icon).swal2-success .swal2-success-ring{position:absolute;z-index:2;top:-0.25em;left:-0.25em;box-sizing:content-box;width:100%;height:100%;border:.25em solid rgba(165,220,134,.3);border-radius:50%}div:where(.swal2-icon).swal2-success .swal2-success-fix{position:absolute;z-index:1;top:.5em;left:1.625em;width:.4375em;height:5.625em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-success [class^=swal2-success-line]{display:block;position:absolute;z-index:2;height:.3125em;border-radius:.125em;background-color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-line][class$=tip]{top:2.875em;left:.8125em;width:1.5625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-success [class^=swal2-success-line][class$=long]{top:2.375em;right:.5em;width:2.9375em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-animate-success-line-tip .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-circular-line-right{animation:swal2-rotate-success-circular-line 4.25s ease-in}[class^=swal2]{-webkit-tap-highlight-color:rgba(0,0,0,0)}.swal2-show{animation:var(--swal2-show-animation)}.swal2-hide{animation:var(--swal2-hide-animation)}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}.swal2-rtl .swal2-close{margin-right:initial;margin-left:0}.swal2-rtl .swal2-timer-progress-bar{right:0;left:auto}.swal2-toast{box-sizing:border-box;grid-column:1/4 !important;grid-row:1/4 !important;grid-template-columns:min-content auto min-content;padding:1em;overflow-y:hidden;border:var(--swal2-toast-border);background:var(--swal2-background);box-shadow:var(--swal2-toast-box-shadow);pointer-events:auto}.swal2-toast>*{grid-column:2}.swal2-toast h2:where(.swal2-title){margin:.5em 1em;padding:0;font-size:1em;text-align:initial}.swal2-toast .swal2-loading{justify-content:center}.swal2-toast input:where(.swal2-input){height:2em;margin:.5em;font-size:1em}.swal2-toast .swal2-validation-message{font-size:1em}.swal2-toast div:where(.swal2-footer){margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-toast button:where(.swal2-close){grid-column:3/3;grid-row:1/99;align-self:center;width:.8em;height:.8em;margin:0;font-size:2em}.swal2-toast div:where(.swal2-html-container){margin:.5em 1em;padding:0;overflow:initial;font-size:1em;text-align:initial}.swal2-toast div:where(.swal2-html-container):empty{padding:0}.swal2-toast .swal2-loader{grid-column:1;grid-row:1/99;align-self:center;width:2em;height:2em;margin:.25em}.swal2-toast .swal2-icon{grid-column:1;grid-row:1/99;align-self:center;width:2em;min-width:2em;height:2em;margin:0 .5em 0 0}.swal2-toast .swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:1.8em;font-weight:bold}.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-toast div:where(.swal2-actions){justify-content:flex-start;height:auto;margin:0;margin-top:.5em;padding:0 .5em}.swal2-toast button:where(.swal2-styled){margin:.25em .5em;padding:.4em .6em;font-size:1em}.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;border-radius:50%}.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.8em;left:-0.5em;transform:rotate(-45deg);transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.25em;left:.9375em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-toast.swal2-show{animation:var(--swal2-toast-show-animation)}.swal2-toast.swal2-hide{animation:var(--swal2-toast-hide-animation)}@keyframes swal2-show{0%{transform:translate3d(0, -50px, 0) scale(0.9);opacity:0}100%{transform:translate3d(0, 0, 0) scale(1);opacity:1}}@keyframes swal2-hide{0%{transform:translate3d(0, 0, 0) scale(1);opacity:1}100%{transform:translate3d(0, -50px, 0) scale(0.9);opacity:0}}@keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-0.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(0.4);opacity:0}50%{margin-top:1.625em;transform:scale(0.4);opacity:0}80%{margin-top:-0.375em;transform:scale(1.15)}100%{margin-top:0;transform:scale(1);opacity:1}}@keyframes swal2-animate-error-icon{0%{transform:rotateX(100deg);opacity:0}100%{transform:rotateX(0deg);opacity:1}}@keyframes swal2-rotate-loading{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}@keyframes swal2-animate-question-mark{0%{transform:rotateY(-360deg)}100%{transform:rotateY(0)}}@keyframes swal2-animate-i-mark{0%{transform:rotateZ(45deg);opacity:0}25%{transform:rotateZ(-25deg);opacity:.4}50%{transform:rotateZ(15deg);opacity:.8}75%{transform:rotateZ(-5deg);opacity:1}100%{transform:rotateX(0);opacity:1}}@keyframes swal2-toast-show{0%{transform:translateY(-0.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(0.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0deg)}}@keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}}@keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-0.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}"); | |
| 6829 | + | |
| 6830 | +/***/ }, | |
| 6831 | + | |
| 6832 | +/***/ "./node_modules/toastify-js/src/toastify.js" | |
| 6833 | +/*!**************************************************!*\ | |
| 6834 | + !*** ./node_modules/toastify-js/src/toastify.js ***! | |
| 6835 | + \**************************************************/ | |
| 6836 | +(module) { | |
| 6837 | + | |
| 6838 | +/*! | |
| 6839 | + * Toastify js 1.12.0 | |
| 6840 | + * https://github.com/apvarun/toastify-js | |
| 6841 | + * @license MIT licensed | |
| 6842 | + * | |
| 6843 | + * Copyright (C) 2018 Varun A P | |
| 6844 | + */ | |
| 6845 | +(function(root, factory) { | |
| 6846 | + if ( true && module.exports) { | |
| 6847 | + module.exports = factory(); | |
| 6848 | + } else { | |
| 6849 | + root.Toastify = factory(); | |
| 6850 | + } | |
| 6851 | +})(this, function(global) { | |
| 6852 | + // Object initialization | |
| 6853 | + var Toastify = function(options) { | |
| 6854 | + // Returning a new init object | |
| 6855 | + return new Toastify.lib.init(options); | |
| 6856 | + }, | |
| 6857 | + // Library version | |
| 6858 | + version = "1.12.0"; | |
| 6859 | + | |
| 6860 | + // Set the default global options | |
| 6861 | + Toastify.defaults = { | |
| 6862 | + oldestFirst: true, | |
| 6863 | + text: "Toastify is awesome!", | |
| 6864 | + node: undefined, | |
| 6865 | + duration: 3000, | |
| 6866 | + selector: undefined, | |
| 6867 | + callback: function () { | |
| 6868 | + }, | |
| 6869 | + destination: undefined, | |
| 6870 | + newWindow: false, | |
| 6871 | + close: false, | |
| 6872 | + gravity: "toastify-top", | |
| 6873 | + positionLeft: false, | |
| 6874 | + position: '', | |
| 6875 | + backgroundColor: '', | |
| 6876 | + avatar: "", | |
| 6877 | + className: "", | |
| 6878 | + stopOnFocus: true, | |
| 6879 | + onClick: function () { | |
| 6880 | + }, | |
| 6881 | + offset: {x: 0, y: 0}, | |
| 6882 | + escapeMarkup: true, | |
| 6883 | + ariaLive: 'polite', | |
| 6884 | + style: {background: ''} | |
| 6885 | + }; | |
| 6886 | + | |
| 6887 | + // Defining the prototype of the object | |
| 6888 | + Toastify.lib = Toastify.prototype = { | |
| 6889 | + toastify: version, | |
| 6890 | + | |
| 6891 | + constructor: Toastify, | |
| 6892 | + | |
| 6893 | + // Initializing the object with required parameters | |
| 6894 | + init: function(options) { | |
| 6895 | + // Verifying and validating the input object | |
| 6896 | + if (!options) { | |
| 6897 | + options = {}; | |
| 6898 | + } | |
| 6899 | + | |
| 6900 | + // Creating the options object | |
| 6901 | + this.options = {}; | |
| 6902 | + | |
| 6903 | + this.toastElement = null; | |
| 6904 | + | |
| 6905 | + // Validating the options | |
| 6906 | + this.options.text = options.text || Toastify.defaults.text; // Display message | |
| 6907 | + this.options.node = options.node || Toastify.defaults.node; // Display content as node | |
| 6908 | + this.options.duration = options.duration === 0 ? 0 : options.duration || Toastify.defaults.duration; // Display duration | |
| 6909 | + this.options.selector = options.selector || Toastify.defaults.selector; // Parent selector | |
| 6910 | + this.options.callback = options.callback || Toastify.defaults.callback; // Callback after display | |
| 6911 | + this.options.destination = options.destination || Toastify.defaults.destination; // On-click destination | |
| 6912 | + this.options.newWindow = options.newWindow || Toastify.defaults.newWindow; // Open destination in new window | |
| 6913 | + this.options.close = options.close || Toastify.defaults.close; // Show toast close icon | |
| 6914 | + this.options.gravity = options.gravity === "bottom" ? "toastify-bottom" : Toastify.defaults.gravity; // toast position - top or bottom | |
| 6915 | + this.options.positionLeft = options.positionLeft || Toastify.defaults.positionLeft; // toast position - left or right | |
| 6916 | + this.options.position = options.position || Toastify.defaults.position; // toast position - left or right | |
| 6917 | + this.options.backgroundColor = options.backgroundColor || Toastify.defaults.backgroundColor; // toast background color | |
| 6918 | + this.options.avatar = options.avatar || Toastify.defaults.avatar; // img element src - url or a path | |
| 6919 | + this.options.className = options.className || Toastify.defaults.className; // additional class names for the toast | |
| 6920 | + this.options.stopOnFocus = options.stopOnFocus === undefined ? Toastify.defaults.stopOnFocus : options.stopOnFocus; // stop timeout on focus | |
| 6921 | + this.options.onClick = options.onClick || Toastify.defaults.onClick; // Callback after click | |
| 6922 | + this.options.offset = options.offset || Toastify.defaults.offset; // toast offset | |
| 6923 | + this.options.escapeMarkup = options.escapeMarkup !== undefined ? options.escapeMarkup : Toastify.defaults.escapeMarkup; | |
| 6924 | + this.options.ariaLive = options.ariaLive || Toastify.defaults.ariaLive; | |
| 6925 | + this.options.style = options.style || Toastify.defaults.style; | |
| 6926 | + if(options.backgroundColor) { | |
| 6927 | + this.options.style.background = options.backgroundColor; | |
| 6928 | + } | |
| 6929 | + | |
| 6930 | + // Returning the current object for chaining functions | |
| 6931 | + return this; | |
| 6932 | + }, | |
| 6933 | + | |
| 6934 | + // Building the DOM element | |
| 6935 | + buildToast: function() { | |
| 6936 | + // Validating if the options are defined | |
| 6937 | + if (!this.options) { | |
| 6938 | + throw "Toastify is not initialized"; | |
| 6939 | + } | |
| 6940 | + | |
| 6941 | + // Creating the DOM object | |
| 6942 | + var divElement = document.createElement("div"); | |
| 6943 | + divElement.className = "toastify on " + this.options.className; | |
| 6944 | + | |
| 6945 | + // Positioning toast to left or right or center | |
| 6946 | + if (!!this.options.position) { | |
| 6947 | + divElement.className += " toastify-" + this.options.position; | |
| 6948 | + } else { | |
| 6949 | + // To be depreciated in further versions | |
| 6950 | + if (this.options.positionLeft === true) { | |
| 6951 | + divElement.className += " toastify-left"; | |
| 6952 | + console.warn('Property `positionLeft` will be depreciated in further versions. Please use `position` instead.') | |
| 6953 | + } else { | |
| 6954 | + // Default position | |
| 6955 | + divElement.className += " toastify-right"; | |
| 6956 | + } | |
| 6957 | + } | |
| 6958 | + | |
| 6959 | + // Assigning gravity of element | |
| 6960 | + divElement.className += " " + this.options.gravity; | |
| 6961 | + | |
| 6962 | + if (this.options.backgroundColor) { | |
| 6963 | + // This is being deprecated in favor of using the style HTML DOM property | |
| 6964 | + console.warn('DEPRECATION NOTICE: "backgroundColor" is being deprecated. Please use the "style.background" property.'); | |
| 6965 | + } | |
| 6966 | + | |
| 6967 | + // Loop through our style object and apply styles to divElement | |
| 6968 | + for (var property in this.options.style) { | |
| 6969 | + divElement.style[property] = this.options.style[property]; | |
| 6970 | + } | |
| 6971 | + | |
| 6972 | + // Announce the toast to screen readers | |
| 6973 | + if (this.options.ariaLive) { | |
| 6974 | + divElement.setAttribute('aria-live', this.options.ariaLive) | |
| 6975 | + } | |
| 6976 | + | |
| 6977 | + // Adding the toast message/node | |
| 6978 | + if (this.options.node && this.options.node.nodeType === Node.ELEMENT_NODE) { | |
| 6979 | + // If we have a valid node, we insert it | |
| 6980 | + divElement.appendChild(this.options.node) | |
| 6981 | + } else { | |
| 6982 | + if (this.options.escapeMarkup) { | |
| 6983 | + divElement.innerText = this.options.text; | |
| 6984 | + } else { | |
| 6985 | + divElement.innerHTML = this.options.text; | |
| 6986 | + } | |
| 6987 | + | |
| 6988 | + if (this.options.avatar !== "") { | |
| 6989 | + var avatarElement = document.createElement("img"); | |
| 6990 | + avatarElement.src = this.options.avatar; | |
| 6991 | + | |
| 6992 | + avatarElement.className = "toastify-avatar"; | |
| 6993 | + | |
| 6994 | + if (this.options.position == "left" || this.options.positionLeft === true) { | |
| 6995 | + // Adding close icon on the left of content | |
| 6996 | + divElement.appendChild(avatarElement); | |
| 6997 | + } else { | |
| 6998 | + // Adding close icon on the right of content | |
| 6999 | + divElement.insertAdjacentElement("afterbegin", avatarElement); | |
| 7000 | + } | |
| 7001 | + } | |
| 7002 | + } | |
| 7003 | + | |
| 7004 | + // Adding a close icon to the toast | |
| 7005 | + if (this.options.close === true) { | |
| 7006 | + // Create a span for close element | |
| 7007 | + var closeElement = document.createElement("button"); | |
| 7008 | + closeElement.type = "button"; | |
| 7009 | + closeElement.setAttribute("aria-label", "Close"); | |
| 7010 | + closeElement.className = "toast-close"; | |
| 7011 | + closeElement.innerHTML = "✖"; | |
| 7012 | + | |
| 7013 | + // Triggering the removal of toast from DOM on close click | |
| 7014 | + closeElement.addEventListener( | |
| 7015 | + "click", | |
| 7016 | + function(event) { | |
| 7017 | + event.stopPropagation(); | |
| 7018 | + this.removeElement(this.toastElement); | |
| 7019 | + window.clearTimeout(this.toastElement.timeOutValue); | |
| 7020 | + }.bind(this) | |
| 7021 | + ); | |
| 7022 | + | |
| 7023 | + //Calculating screen width | |
| 7024 | + var width = window.innerWidth > 0 ? window.innerWidth : screen.width; | |
| 7025 | + | |
| 7026 | + // Adding the close icon to the toast element | |
| 7027 | + // Display on the right if screen width is less than or equal to 360px | |
| 7028 | + if ((this.options.position == "left" || this.options.positionLeft === true) && width > 360) { | |
| 7029 | + // Adding close icon on the left of content | |
| 7030 | + divElement.insertAdjacentElement("afterbegin", closeElement); | |
| 7031 | + } else { | |
| 7032 | + // Adding close icon on the right of content | |
| 7033 | + divElement.appendChild(closeElement); | |
| 7034 | + } | |
| 7035 | + } | |
| 7036 | + | |
| 7037 | + // Clear timeout while toast is focused | |
| 7038 | + if (this.options.stopOnFocus && this.options.duration > 0) { | |
| 7039 | + var self = this; | |
| 7040 | + // stop countdown | |
| 7041 | + divElement.addEventListener( | |
| 7042 | + "mouseover", | |
| 7043 | + function(event) { | |
| 7044 | + window.clearTimeout(divElement.timeOutValue); | |
| 7045 | + } | |
| 7046 | + ) | |
| 7047 | + // add back the timeout | |
| 7048 | + divElement.addEventListener( | |
| 7049 | + "mouseleave", | |
| 7050 | + function() { | |
| 7051 | + divElement.timeOutValue = window.setTimeout( | |
| 7052 | + function() { | |
| 7053 | + // Remove the toast from DOM | |
| 7054 | + self.removeElement(divElement); | |
| 7055 | + }, | |
| 7056 | + self.options.duration | |
| 7057 | + ) | |
| 7058 | + } | |
| 7059 | + ) | |
| 7060 | + } | |
| 7061 | + | |
| 7062 | + // Adding an on-click destination path | |
| 7063 | + if (typeof this.options.destination !== "undefined") { | |
| 7064 | + divElement.addEventListener( | |
| 7065 | + "click", | |
| 7066 | + function(event) { | |
| 7067 | + event.stopPropagation(); | |
| 7068 | + if (this.options.newWindow === true) { | |
| 7069 | + window.open(this.options.destination, "_blank"); | |
| 7070 | + } else { | |
| 7071 | + window.location = this.options.destination; | |
| 7072 | + } | |
| 7073 | + }.bind(this) | |
| 7074 | + ); | |
| 7075 | + } | |
| 7076 | + | |
| 7077 | + if (typeof this.options.onClick === "function" && typeof this.options.destination === "undefined") { | |
| 7078 | + divElement.addEventListener( | |
| 7079 | + "click", | |
| 7080 | + function(event) { | |
| 7081 | + event.stopPropagation(); | |
| 7082 | + this.options.onClick(); | |
| 7083 | + }.bind(this) | |
| 7084 | + ); | |
| 7085 | + } | |
| 7086 | + | |
| 7087 | + // Adding offset | |
| 7088 | + if(typeof this.options.offset === "object") { | |
| 7089 | + | |
| 7090 | + var x = getAxisOffsetAValue("x", this.options); | |
| 7091 | + var y = getAxisOffsetAValue("y", this.options); | |
| 7092 | + | |
| 7093 | + var xOffset = this.options.position == "left" ? x : "-" + x; | |
| 7094 | + var yOffset = this.options.gravity == "toastify-top" ? y : "-" + y; | |
| 7095 | + | |
| 7096 | + divElement.style.transform = "translate(" + xOffset + "," + yOffset + ")"; | |
| 7097 | + | |
| 7098 | + } | |
| 7099 | + | |
| 7100 | + // Returning the generated element | |
| 7101 | + return divElement; | |
| 7102 | + }, | |
| 7103 | + | |
| 7104 | + // Displaying the toast | |
| 7105 | + showToast: function() { | |
| 7106 | + // Creating the DOM object for the toast | |
| 7107 | + this.toastElement = this.buildToast(); | |
| 7108 | + | |
| 7109 | + // Getting the root element to with the toast needs to be added | |
| 7110 | + var rootElement; | |
| 7111 | + if (typeof this.options.selector === "string") { | |
| 7112 | + rootElement = document.getElementById(this.options.selector); | |
| 7113 | + } else if (this.options.selector instanceof HTMLElement || (typeof ShadowRoot !== 'undefined' && this.options.selector instanceof ShadowRoot)) { | |
| 7114 | + rootElement = this.options.selector; | |
| 7115 | + } else { | |
| 7116 | + rootElement = document.body; | |
| 7117 | + } | |
| 7118 | + | |
| 7119 | + // Validating if root element is present in DOM | |
| 7120 | + if (!rootElement) { | |
| 7121 | + throw "Root element is not defined"; | |
| 7122 | + } | |
| 7123 | + | |
| 7124 | + // Adding the DOM element | |
| 7125 | + var elementToInsert = Toastify.defaults.oldestFirst ? rootElement.firstChild : rootElement.lastChild; | |
| 7126 | + rootElement.insertBefore(this.toastElement, elementToInsert); | |
| 7127 | + | |
| 7128 | + // Repositioning the toasts in case multiple toasts are present | |
| 7129 | + Toastify.reposition(); | |
| 7130 | + | |
| 7131 | + if (this.options.duration > 0) { | |
| 7132 | + this.toastElement.timeOutValue = window.setTimeout( | |
| 7133 | + function() { | |
| 7134 | + // Remove the toast from DOM | |
| 7135 | + this.removeElement(this.toastElement); | |
| 7136 | + }.bind(this), | |
| 7137 | + this.options.duration | |
| 7138 | + ); // Binding `this` for function invocation | |
| 7139 | + } | |
| 7140 | + | |
| 7141 | + // Supporting function chaining | |
| 7142 | + return this; | |
| 7143 | + }, | |
| 7144 | + | |
| 7145 | + hideToast: function() { | |
| 7146 | + if (this.toastElement.timeOutValue) { | |
| 7147 | + clearTimeout(this.toastElement.timeOutValue); | |
| 7148 | + } | |
| 7149 | + this.removeElement(this.toastElement); | |
| 7150 | + }, | |
| 7151 | + | |
| 7152 | + // Removing the element from the DOM | |
| 7153 | + removeElement: function(toastElement) { | |
| 7154 | + // Hiding the element | |
| 7155 | + // toastElement.classList.remove("on"); | |
| 7156 | + toastElement.className = toastElement.className.replace(" on", ""); | |
| 7157 | + | |
| 7158 | + // Removing the element from DOM after transition end | |
| 7159 | + window.setTimeout( | |
| 7160 | + function() { | |
| 7161 | + // remove options node if any | |
| 7162 | + if (this.options.node && this.options.node.parentNode) { | |
| 7163 | + this.options.node.parentNode.removeChild(this.options.node); | |
| 7164 | + } | |
| 7165 | + | |
| 7166 | + // Remove the element from the DOM, only when the parent node was not removed before. | |
| 7167 | + if (toastElement.parentNode) { | |
| 7168 | + toastElement.parentNode.removeChild(toastElement); | |
| 7169 | + } | |
| 7170 | + | |
| 7171 | + // Calling the callback function | |
| 7172 | + this.options.callback.call(toastElement); | |
| 7173 | + | |
| 7174 | + // Repositioning the toasts again | |
| 7175 | + Toastify.reposition(); | |
| 7176 | + }.bind(this), | |
| 7177 | + 400 | |
| 7178 | + ); // Binding `this` for function invocation | |
| 7179 | + }, | |
| 7180 | + }; | |
| 7181 | + | |
| 7182 | + // Positioning the toasts on the DOM | |
| 7183 | + Toastify.reposition = function() { | |
| 7184 | + | |
| 7185 | + // Top margins with gravity | |
| 7186 | + var topLeftOffsetSize = { | |
| 7187 | + top: 15, | |
| 7188 | + bottom: 15, | |
| 7189 | + }; | |
| 7190 | + var topRightOffsetSize = { | |
| 7191 | + top: 15, | |
| 7192 | + bottom: 15, | |
| 7193 | + }; | |
| 7194 | + var offsetSize = { | |
| 7195 | + top: 15, | |
| 7196 | + bottom: 15, | |
| 7197 | + }; | |
| 7198 | + | |
| 7199 | + // Get all toast messages on the DOM | |
| 7200 | + var allToasts = document.getElementsByClassName("toastify"); | |
| 7201 | + | |
| 7202 | + var classUsed; | |
| 7203 | + | |
| 7204 | + // Modifying the position of each toast element | |
| 7205 | + for (var i = 0; i < allToasts.length; i++) { | |
| 7206 | + // Getting the applied gravity | |
| 7207 | + if (containsClass(allToasts[i], "toastify-top") === true) { | |
| 7208 | + classUsed = "toastify-top"; | |
| 7209 | + } else { | |
| 7210 | + classUsed = "toastify-bottom"; | |
| 7211 | + } | |
| 7212 | + | |
| 7213 | + var height = allToasts[i].offsetHeight; | |
| 7214 | + classUsed = classUsed.substr(9, classUsed.length-1) | |
| 7215 | + // Spacing between toasts | |
| 7216 | + var offset = 15; | |
| 7217 | + | |
| 7218 | + var width = window.innerWidth > 0 ? window.innerWidth : screen.width; | |
| 7219 | + | |
| 7220 | + // Show toast in center if screen with less than or equal to 360px | |
| 7221 | + if (width <= 360) { | |
| 7222 | + // Setting the position | |
| 7223 | + allToasts[i].style[classUsed] = offsetSize[classUsed] + "px"; | |
| 7224 | + | |
| 7225 | + offsetSize[classUsed] += height + offset; | |
| 7226 | + } else { | |
| 7227 | + if (containsClass(allToasts[i], "toastify-left") === true) { | |
| 7228 | + // Setting the position | |
| 7229 | + allToasts[i].style[classUsed] = topLeftOffsetSize[classUsed] + "px"; | |
| 7230 | + | |
| 7231 | + topLeftOffsetSize[classUsed] += height + offset; | |
| 7232 | + } else { | |
| 7233 | + // Setting the position | |
| 7234 | + allToasts[i].style[classUsed] = topRightOffsetSize[classUsed] + "px"; | |
| 7235 | + | |
| 7236 | + topRightOffsetSize[classUsed] += height + offset; | |
| 7237 | + } | |
| 7238 | + } | |
| 7239 | + } | |
| 7240 | + | |
| 7241 | + // Supporting function chaining | |
| 7242 | + return this; | |
| 7243 | + }; | |
| 7244 | + | |
| 7245 | + // Helper function to get offset. | |
| 7246 | + function getAxisOffsetAValue(axis, options) { | |
| 7247 | + | |
| 7248 | + if(options.offset[axis]) { | |
| 7249 | + if(isNaN(options.offset[axis])) { | |
| 7250 | + return options.offset[axis]; | |
| 7251 | + } | |
| 7252 | + else { | |
| 7253 | + return options.offset[axis] + 'px'; | |
| 7254 | + } | |
| 7255 | + } | |
| 7256 | + | |
| 7257 | + return '0px'; | |
| 7258 | + | |
| 7259 | + } | |
| 7260 | + | |
| 7261 | + function containsClass(elem, yourClass) { | |
| 7262 | + if (!elem || typeof yourClass !== "string") { | |
| 7263 | + return false; | |
| 7264 | + } else if ( | |
| 7265 | + elem.className && | |
| 7266 | + elem.className | |
| 7267 | + .trim() | |
| 7268 | + .split(/\s+/gi) | |
| 7269 | + .indexOf(yourClass) > -1 | |
| 7270 | + ) { | |
| 7271 | + return true; | |
| 7272 | + } else { | |
| 7273 | + return false; | |
| 7274 | + } | |
| 7275 | + } | |
| 7276 | + | |
| 7277 | + // Setting up the prototype for the init object | |
| 7278 | + Toastify.lib.init.prototype = Toastify.lib; | |
| 7279 | + | |
| 7280 | + // Returning the Toastify function to be assigned to the window object/module | |
| 7281 | + return Toastify; | |
| 7282 | +}); | |
| 7283 | + | |
| 7284 | + | |
| 7285 | +/***/ }, | |
| 7286 | + | |
| 1079 | 7287 | /***/ "./node_modules/@orchidjs/sifter/dist/esm/sifter.js" |
| 1080 | 7288 | /*!**********************************************************!*\ |
| 1081 | 7289 | !*** ./node_modules/@orchidjs/sifter/dist/esm/sifter.js ***! |
| 1082 | 7290 | \**********************************************************/ |
| @@ -1081,8 +7289,9 @@ | ||
| 1081 | 7289 | !*** ./node_modules/@orchidjs/sifter/dist/esm/sifter.js ***! |
| 1082 | 7290 | \**********************************************************/ |
| 1083 | 7291 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1084 | 7292 | |
| 7293 | +"use strict"; | |
| 1085 | 7294 | __webpack_require__.r(__webpack_exports__); |
| 1086 | 7295 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1087 | 7296 | /* harmony export */ Sifter: () => (/* binding */ Sifter), |
| 1088 | 7297 | /* harmony export */ cmp: () => (/* reexport safe */ _utils_js__WEBPACK_IMPORTED_MODULE_0__.cmp), |
| @@ -1408,8 +7617,9 @@ | ||
| 1408 | 7617 | !*** ./node_modules/@orchidjs/sifter/dist/esm/types.js ***! |
| 1409 | 7618 | \*********************************************************/ |
| 1410 | 7619 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1411 | 7620 | |
| 7621 | +"use strict"; | |
| 1412 | 7622 | __webpack_require__.r(__webpack_exports__); |
| 1413 | 7623 | |
| 1414 | 7624 | //# sourceMappingURL=types.js.map |
| 1415 | 7625 | |
| @@ -1420,8 +7630,9 @@ | ||
| 1420 | 7630 | !*** ./node_modules/@orchidjs/sifter/dist/esm/utils.js ***! |
| 1421 | 7631 | \*********************************************************/ |
| 1422 | 7632 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1423 | 7633 | |
| 7634 | +"use strict"; | |
| 1424 | 7635 | __webpack_require__.r(__webpack_exports__); |
| 1425 | 7636 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1426 | 7637 | /* harmony export */ cmp: () => (/* binding */ cmp), |
| 1427 | 7638 | /* harmony export */ getAttr: () => (/* binding */ getAttr), |
| @@ -1532,8 +7743,9 @@ | ||
| 1532 | 7743 | !*** ./node_modules/@orchidjs/unicode-variants/dist/esm/index.js ***! |
| 1533 | 7744 | \*******************************************************************/ |
| 1534 | 7745 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1535 | 7746 | |
| 7747 | +"use strict"; | |
| 1536 | 7748 | __webpack_require__.r(__webpack_exports__); |
| 1537 | 7749 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1538 | 7750 | /* harmony export */ _asciifold: () => (/* binding */ _asciifold), |
| 1539 | 7751 | /* harmony export */ asciifold: () => (/* binding */ asciifold), |
| @@ -1935,8 +8147,9 @@ | ||
| 1935 | 8147 | !*** ./node_modules/@orchidjs/unicode-variants/dist/esm/regex.js ***! |
| 1936 | 8148 | \*******************************************************************/ |
| 1937 | 8149 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 1938 | 8150 | |
| 8151 | +"use strict"; | |
| 1939 | 8152 | __webpack_require__.r(__webpack_exports__); |
| 1940 | 8153 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1941 | 8154 | /* harmony export */ arrayToPattern: () => (/* binding */ arrayToPattern), |
| 1942 | 8155 | /* harmony export */ escape_regex: () => (/* binding */ escape_regex), |
| @@ -2020,8 +8233,9 @@ | ||
| 2020 | 8233 | !*** ./node_modules/@orchidjs/unicode-variants/dist/esm/strings.js ***! |
| 2021 | 8234 | \*********************************************************************/ |
| 2022 | 8235 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2023 | 8236 | |
| 8237 | +"use strict"; | |
| 2024 | 8238 | __webpack_require__.r(__webpack_exports__); |
| 2025 | 8239 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2026 | 8240 | /* harmony export */ allSubstrings: () => (/* binding */ allSubstrings) |
| 2027 | 8241 | /* harmony export */ }); |
| @@ -2054,8 +8268,9 @@ | ||
| 2054 | 8268 | !*** ./node_modules/tom-select/dist/esm/constants.js ***! |
| 2055 | 8269 | \*******************************************************/ |
| 2056 | 8270 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2057 | 8271 | |
| 8272 | +"use strict"; | |
| 2058 | 8273 | __webpack_require__.r(__webpack_exports__); |
| 2059 | 8274 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2060 | 8275 | /* harmony export */ IS_MAC: () => (/* binding */ IS_MAC), |
| 2061 | 8276 | /* harmony export */ KEY_A: () => (/* binding */ KEY_A), |
| @@ -2091,8 +8306,9 @@ | ||
| 2091 | 8306 | !*** ./node_modules/tom-select/dist/esm/contrib/highlight.js ***! |
| 2092 | 8307 | \***************************************************************/ |
| 2093 | 8308 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2094 | 8309 | |
| 8310 | +"use strict"; | |
| 2095 | 8311 | __webpack_require__.r(__webpack_exports__); |
| 2096 | 8312 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2097 | 8313 | /* harmony export */ highlight: () => (/* binding */ highlight), |
| 2098 | 8314 | /* harmony export */ removeHighlight: () => (/* binding */ removeHighlight) |
| @@ -2170,8 +8386,9 @@ | ||
| 2170 | 8386 | !*** ./node_modules/tom-select/dist/esm/contrib/microevent.js ***! |
| 2171 | 8387 | \****************************************************************/ |
| 2172 | 8388 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2173 | 8389 | |
| 8390 | +"use strict"; | |
| 2174 | 8391 | __webpack_require__.r(__webpack_exports__); |
| 2175 | 8392 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2176 | 8393 | /* harmony export */ "default": () => (/* binding */ MicroEvent) |
| 2177 | 8394 | /* harmony export */ }); |
| @@ -2244,8 +8461,9 @@ | ||
| 2244 | 8461 | !*** ./node_modules/tom-select/dist/esm/contrib/microplugin.js ***! |
| 2245 | 8462 | \*****************************************************************/ |
| 2246 | 8463 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2247 | 8464 | |
| 8465 | +"use strict"; | |
| 2248 | 8466 | __webpack_require__.r(__webpack_exports__); |
| 2249 | 8467 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2250 | 8468 | /* harmony export */ "default": () => (/* binding */ MicroPlugin) |
| 2251 | 8469 | /* harmony export */ }); |
| @@ -2366,8 +8584,9 @@ | ||
| 2366 | 8584 | !*** ./node_modules/tom-select/dist/esm/defaults.js ***! |
| 2367 | 8585 | \******************************************************/ |
| 2368 | 8586 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2369 | 8587 | |
| 8588 | +"use strict"; | |
| 2370 | 8589 | __webpack_require__.r(__webpack_exports__); |
| 2371 | 8590 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2372 | 8591 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 2373 | 8592 | /* harmony export */ }); |
| @@ -2381,8 +8600,9 @@ | ||
| 2381 | 8600 | diacritics: true, |
| 2382 | 8601 | create: null, |
| 2383 | 8602 | createOnBlur: false, |
| 2384 | 8603 | createFilter: null, |
| 8604 | + clearAfterSelect: false, | |
| 2385 | 8605 | highlight: true, |
| 2386 | 8606 | openOnFocus: true, |
| 2387 | 8607 | shouldOpen: null, |
| 2388 | 8608 | maxOptions: 50, |
| @@ -2461,8 +8681,9 @@ | ||
| 2461 | 8681 | !*** ./node_modules/tom-select/dist/esm/getSettings.js ***! |
| 2462 | 8682 | \*********************************************************/ |
| 2463 | 8683 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2464 | 8684 | |
| 8685 | +"use strict"; | |
| 2465 | 8686 | __webpack_require__.r(__webpack_exports__); |
| 2466 | 8687 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2467 | 8688 | /* harmony export */ "default": () => (/* binding */ getSettings) |
| 2468 | 8689 | /* harmony export */ }); |
| @@ -2579,11 +8800,12 @@ | ||
| 2579 | 8800 | * Initialize from a <input type="text"> element. |
| 2580 | 8801 | * |
| 2581 | 8802 | */ |
| 2582 | 8803 | var init_textbox = () => { |
| 8804 | + var _a, _b; | |
| 2583 | 8805 | const data_raw = input.getAttribute(attr_data); |
| 2584 | 8806 | if (!data_raw) { |
| 2585 | - var value = input.value.trim() || ''; | |
| 8807 | + var value = (_b = (_a = input === null || input === void 0 ? void 0 : input.value) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : ''; | |
| 2586 | 8808 | if (!settings.allowEmptyOption && !value.length) |
| 2587 | 8809 | return; |
| 2588 | 8810 | const values = value.split(settings.delimiter); |
| 2589 | 8811 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.iterate)(values, (value) => { |
| @@ -2619,14 +8841,15 @@ | ||
| 2619 | 8841 | !*** ./node_modules/tom-select/dist/esm/plugins/caret_position/plugin.js ***! |
| 2620 | 8842 | \***************************************************************************/ |
| 2621 | 8843 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2622 | 8844 | |
| 8845 | +"use strict"; | |
| 2623 | 8846 | __webpack_require__.r(__webpack_exports__); |
| 2624 | 8847 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2625 | 8848 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 2626 | 8849 | /* harmony export */ }); |
| 2627 | 8850 | /** |
| 2628 | -* Tom Select v2.4.3 | |
| 8851 | +* Tom Select v2.6.2 | |
| 2629 | 8852 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 2630 | 8853 | */ |
| 2631 | 8854 | |
| 2632 | 8855 | /** |
| @@ -2796,14 +9019,15 @@ | ||
| 2796 | 9019 | !*** ./node_modules/tom-select/dist/esm/plugins/change_listener/plugin.js ***! |
| 2797 | 9020 | \****************************************************************************/ |
| 2798 | 9021 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2799 | 9022 | |
| 9023 | +"use strict"; | |
| 2800 | 9024 | __webpack_require__.r(__webpack_exports__); |
| 2801 | 9025 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2802 | 9026 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 2803 | 9027 | /* harmony export */ }); |
| 2804 | 9028 | /** |
| 2805 | -* Tom Select v2.4.3 | |
| 9029 | +* Tom Select v2.6.2 | |
| 2806 | 9030 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 2807 | 9031 | */ |
| 2808 | 9032 | |
| 2809 | 9033 | /** |
| @@ -2861,14 +9085,15 @@ | ||
| 2861 | 9085 | !*** ./node_modules/tom-select/dist/esm/plugins/checkbox_options/plugin.js ***! |
| 2862 | 9086 | \*****************************************************************************/ |
| 2863 | 9087 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 2864 | 9088 | |
| 9089 | +"use strict"; | |
| 2865 | 9090 | __webpack_require__.r(__webpack_exports__); |
| 2866 | 9091 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2867 | 9092 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 2868 | 9093 | /* harmony export */ }); |
| 2869 | 9094 | /** |
| 2870 | -* Tom Select v2.4.3 | |
| 9095 | +* Tom Select v2.6.2 | |
| 2871 | 9096 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 2872 | 9097 | */ |
| 2873 | 9098 | |
| 2874 | 9099 | /** |
| @@ -3054,14 +9279,15 @@ | ||
| 3054 | 9279 | !*** ./node_modules/tom-select/dist/esm/plugins/clear_button/plugin.js ***! |
| 3055 | 9280 | \*************************************************************************/ |
| 3056 | 9281 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3057 | 9282 | |
| 9283 | +"use strict"; | |
| 3058 | 9284 | __webpack_require__.r(__webpack_exports__); |
| 3059 | 9285 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3060 | 9286 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3061 | 9287 | /* harmony export */ }); |
| 3062 | 9288 | /** |
| 3063 | -* Tom Select v2.4.3 | |
| 9289 | +* Tom Select v2.6.2 | |
| 3064 | 9290 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3065 | 9291 | */ |
| 3066 | 9292 | |
| 3067 | 9293 | /** |
| @@ -3110,10 +9336,12 @@ | ||
| 3110 | 9336 | const self = this; |
| 3111 | 9337 | const options = Object.assign({ |
| 3112 | 9338 | className: 'clear-button', |
| 3113 | 9339 | title: 'Clear All', |
| 9340 | + role: 'button', | |
| 9341 | + tabindex: 0, | |
| 3114 | 9342 | html: data => { |
| 3115 | - return `<div class="${data.className}" title="${data.title}">⨯</div>`; | |
| 9343 | + return `<div class="${data.className}" title="${data.title}" role="${data.role}" tabindex="${data.tabindex}">×</div>`; | |
| 3116 | 9344 | } |
| 3117 | 9345 | }, userOptions); |
| 3118 | 9346 | self.on('initialize', () => { |
| 3119 | 9347 | var button = getDom(options.html(options)); |
| @@ -3122,8 +9350,9 @@ | ||
| 3122 | 9350 | self.clear(); |
| 3123 | 9351 | if (self.settings.mode === 'single' && self.settings.allowEmptyOption) { |
| 3124 | 9352 | self.addItem(''); |
| 3125 | 9353 | } |
| 9354 | + self.refreshOptions(false); | |
| 3126 | 9355 | evt.preventDefault(); |
| 3127 | 9356 | evt.stopPropagation(); |
| 3128 | 9357 | }); |
| 3129 | 9358 | self.control.appendChild(button); |
| @@ -3141,14 +9370,15 @@ | ||
| 3141 | 9370 | !*** ./node_modules/tom-select/dist/esm/plugins/drag_drop/plugin.js ***! |
| 3142 | 9371 | \**********************************************************************/ |
| 3143 | 9372 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3144 | 9373 | |
| 9374 | +"use strict"; | |
| 3145 | 9375 | __webpack_require__.r(__webpack_exports__); |
| 3146 | 9376 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3147 | 9377 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3148 | 9378 | /* harmony export */ }); |
| 3149 | 9379 | /** |
| 3150 | -* Tom Select v2.4.3 | |
| 9380 | +* Tom Select v2.6.2 | |
| 3151 | 9381 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3152 | 9382 | */ |
| 3153 | 9383 | |
| 3154 | 9384 | /** |
| @@ -3375,14 +9605,15 @@ | ||
| 3375 | 9605 | !*** ./node_modules/tom-select/dist/esm/plugins/dropdown_header/plugin.js ***! |
| 3376 | 9606 | \****************************************************************************/ |
| 3377 | 9607 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3378 | 9608 | |
| 9609 | +"use strict"; | |
| 3379 | 9610 | __webpack_require__.r(__webpack_exports__); |
| 3380 | 9611 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3381 | 9612 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3382 | 9613 | /* harmony export */ }); |
| 3383 | 9614 | /** |
| 3384 | -* Tom Select v2.4.3 | |
| 9615 | +* Tom Select v2.6.2 | |
| 3385 | 9616 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3386 | 9617 | */ |
| 3387 | 9618 | |
| 3388 | 9619 | /** |
| @@ -3491,14 +9722,15 @@ | ||
| 3491 | 9722 | !*** ./node_modules/tom-select/dist/esm/plugins/dropdown_input/plugin.js ***! |
| 3492 | 9723 | \***************************************************************************/ |
| 3493 | 9724 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3494 | 9725 | |
| 9726 | +"use strict"; | |
| 3495 | 9727 | __webpack_require__.r(__webpack_exports__); |
| 3496 | 9728 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3497 | 9729 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3498 | 9730 | /* harmony export */ }); |
| 3499 | 9731 | /** |
| 3500 | -* Tom Select v2.4.3 | |
| 9732 | +* Tom Select v2.6.2 | |
| 3501 | 9733 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3502 | 9734 | */ |
| 3503 | 9735 | |
| 3504 | 9736 | const KEY_ESC = 27; |
| @@ -3651,8 +9883,9 @@ | ||
| 3651 | 9883 | const self = this; |
| 3652 | 9884 | self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown |
| 3653 | 9885 | |
| 3654 | 9886 | self.hook('before', 'setup', () => { |
| 9887 | + var _self$input; | |
| 3655 | 9888 | self.focus_node = self.control; |
| 3656 | 9889 | addClasses(self.control_input, 'dropdown-input'); |
| 3657 | 9890 | const div = getDom('<div class="dropdown-input-wrap">'); |
| 3658 | 9891 | div.append(self.control_input); |
| @@ -3661,8 +9894,17 @@ | ||
| 3661 | 9894 | // set a placeholder in the select control |
| 3662 | 9895 | const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />'); |
| 3663 | 9896 | placeholder.placeholder = self.settings.placeholder || ''; |
| 3664 | 9897 | self.control.append(placeholder); |
| 9898 | + /** | |
| 9899 | + * TomSelect renders a custom control with a focusable <input class="items-placeholder">. | |
| 9900 | + * The source <select>'s aria-label is not automatically propagated to that input, | |
| 9901 | + * which triggers "Missing form label" accessibility warnings. | |
| 9902 | + * This helper copies the label from the <select> onto the generated input. | |
| 9903 | + */ | |
| 9904 | + const label = (_self$input = self.input) == null ? void 0 : _self$input.getAttribute('aria-label'); | |
| 9905 | + if (!label) return; | |
| 9906 | + placeholder.setAttribute('aria-label', label); | |
| 3665 | 9907 | }); |
| 3666 | 9908 | self.on('initialize', () => { |
| 3667 | 9909 | // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input |
| 3668 | 9910 | self.control_input.addEventListener('keydown', evt => { |
| @@ -3719,14 +9961,15 @@ | ||
| 3719 | 9961 | !*** ./node_modules/tom-select/dist/esm/plugins/input_autogrow/plugin.js ***! |
| 3720 | 9962 | \***************************************************************************/ |
| 3721 | 9963 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3722 | 9964 | |
| 9965 | +"use strict"; | |
| 3723 | 9966 | __webpack_require__.r(__webpack_exports__); |
| 3724 | 9967 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3725 | 9968 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3726 | 9969 | /* harmony export */ }); |
| 3727 | 9970 | /** |
| 3728 | -* Tom Select v2.4.3 | |
| 9971 | +* Tom Select v2.6.2 | |
| 3729 | 9972 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3730 | 9973 | */ |
| 3731 | 9974 | |
| 3732 | 9975 | /** |
| @@ -3807,14 +10050,15 @@ | ||
| 3807 | 10050 | !*** ./node_modules/tom-select/dist/esm/plugins/no_active_items/plugin.js ***! |
| 3808 | 10051 | \****************************************************************************/ |
| 3809 | 10052 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3810 | 10053 | |
| 10054 | +"use strict"; | |
| 3811 | 10055 | __webpack_require__.r(__webpack_exports__); |
| 3812 | 10056 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3813 | 10057 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3814 | 10058 | /* harmony export */ }); |
| 3815 | 10059 | /** |
| 3816 | -* Tom Select v2.4.3 | |
| 10060 | +* Tom Select v2.6.2 | |
| 3817 | 10061 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3818 | 10062 | */ |
| 3819 | 10063 | |
| 3820 | 10064 | /** |
| @@ -3847,14 +10091,15 @@ | ||
| 3847 | 10091 | !*** ./node_modules/tom-select/dist/esm/plugins/no_backspace_delete/plugin.js ***! |
| 3848 | 10092 | \********************************************************************************/ |
| 3849 | 10093 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3850 | 10094 | |
| 10095 | +"use strict"; | |
| 3851 | 10096 | __webpack_require__.r(__webpack_exports__); |
| 3852 | 10097 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3853 | 10098 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3854 | 10099 | /* harmony export */ }); |
| 3855 | 10100 | /** |
| 3856 | -* Tom Select v2.4.3 | |
| 10101 | +* Tom Select v2.6.2 | |
| 3857 | 10102 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3858 | 10103 | */ |
| 3859 | 10104 | |
| 3860 | 10105 | /** |
| @@ -3893,14 +10138,15 @@ | ||
| 3893 | 10138 | !*** ./node_modules/tom-select/dist/esm/plugins/optgroup_columns/plugin.js ***! |
| 3894 | 10139 | \*****************************************************************************/ |
| 3895 | 10140 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3896 | 10141 | |
| 10142 | +"use strict"; | |
| 3897 | 10143 | __webpack_require__.r(__webpack_exports__); |
| 3898 | 10144 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3899 | 10145 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3900 | 10146 | /* harmony export */ }); |
| 3901 | 10147 | /** |
| 3902 | -* Tom Select v2.4.3 | |
| 10148 | +* Tom Select v2.6.2 | |
| 3903 | 10149 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3904 | 10150 | */ |
| 3905 | 10151 | |
| 3906 | 10152 | const KEY_LEFT = 37; |
| @@ -3993,14 +10239,15 @@ | ||
| 3993 | 10239 | !*** ./node_modules/tom-select/dist/esm/plugins/remove_button/plugin.js ***! |
| 3994 | 10240 | \**************************************************************************/ |
| 3995 | 10241 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 3996 | 10242 | |
| 10243 | +"use strict"; | |
| 3997 | 10244 | __webpack_require__.r(__webpack_exports__); |
| 3998 | 10245 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3999 | 10246 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4000 | 10247 | /* harmony export */ }); |
| 4001 | 10248 | /** |
| 4002 | -* Tom Select v2.4.3 | |
| 10249 | +* Tom Select v2.6.2 | |
| 4003 | 10250 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4004 | 10251 | */ |
| 4005 | 10252 | |
| 4006 | 10253 | /** |
| @@ -4018,16 +10265,8 @@ | ||
| 4018 | 10265 | * |
| 4019 | 10266 | */ |
| 4020 | 10267 | |
| 4021 | 10268 | /** |
| 4022 | - * Escapes a string for use within HTML. | |
| 4023 | - * | |
| 4024 | - */ | |
| 4025 | -const escape_html = str => { | |
| 4026 | - return (str + '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | |
| 4027 | -}; | |
| 4028 | - | |
| 4029 | -/** | |
| 4030 | 10269 | * Prevent default |
| 4031 | 10270 | * |
| 4032 | 10271 | */ |
| 4033 | 10272 | const preventDefault = (evt, stop = false) => { |
| @@ -4089,28 +10328,31 @@ | ||
| 4089 | 10328 | * |
| 4090 | 10329 | */ |
| 4091 | 10330 | |
| 4092 | 10331 | function plugin (userOptions) { |
| 10332 | + const self = this; | |
| 4093 | 10333 | const options = Object.assign({ |
| 4094 | - label: '×', | |
| 10334 | + label: '×', | |
| 4095 | 10335 | title: 'Remove', |
| 4096 | 10336 | className: 'remove', |
| 4097 | - append: true | |
| 10337 | + tabindex: -1, | |
| 10338 | + role: 'button', | |
| 10339 | + html: data => { | |
| 10340 | + var _data$tabindex; | |
| 10341 | + const el = document.createElement('div'); | |
| 10342 | + el.className = data.className || ''; | |
| 10343 | + el.title = data.title || ''; | |
| 10344 | + el.setAttribute('role', data.role || 'button'); | |
| 10345 | + el.tabIndex = (_data$tabindex = data.tabindex) != null ? _data$tabindex : -1; | |
| 10346 | + el.textContent = data.label || ''; | |
| 10347 | + return el; | |
| 10348 | + } | |
| 4098 | 10349 | }, userOptions); |
| 4099 | - | |
| 4100 | - //options.className = 'remove-single'; | |
| 4101 | - var self = this; | |
| 4102 | - | |
| 4103 | - // override the render method to add remove button to each item | |
| 4104 | - if (!options.append) { | |
| 4105 | - return; | |
| 4106 | - } | |
| 4107 | - var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; | |
| 4108 | 10350 | self.hook('after', 'setupTemplates', () => { |
| 4109 | 10351 | var orig_render_item = self.settings.render.item; |
| 4110 | 10352 | self.settings.render.item = (data, escape) => { |
| 4111 | 10353 | var item = getDom(orig_render_item.call(self, data, escape)); |
| 4112 | - var close_button = getDom(html); | |
| 10354 | + var close_button = getDom(options.html(options)); | |
| 4113 | 10355 | item.appendChild(close_button); |
| 4114 | 10356 | addEvent(close_button, 'mousedown', evt => { |
| 4115 | 10357 | preventDefault(evt, true); |
| 4116 | 10358 | }); |
| @@ -4141,14 +10383,15 @@ | ||
| 4141 | 10383 | !*** ./node_modules/tom-select/dist/esm/plugins/restore_on_backspace/plugin.js ***! |
| 4142 | 10384 | \*********************************************************************************/ |
| 4143 | 10385 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 4144 | 10386 | |
| 10387 | +"use strict"; | |
| 4145 | 10388 | __webpack_require__.r(__webpack_exports__); |
| 4146 | 10389 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4147 | 10390 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4148 | 10391 | /* harmony export */ }); |
| 4149 | 10392 | /** |
| 4150 | -* Tom Select v2.4.3 | |
| 10393 | +* Tom Select v2.6.2 | |
| 4151 | 10394 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4152 | 10395 | */ |
| 4153 | 10396 | |
| 4154 | 10397 | /** |
| @@ -4197,14 +10440,15 @@ | ||
| 4197 | 10440 | !*** ./node_modules/tom-select/dist/esm/plugins/virtual_scroll/plugin.js ***! |
| 4198 | 10441 | \***************************************************************************/ |
| 4199 | 10442 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 4200 | 10443 | |
| 10444 | +"use strict"; | |
| 4201 | 10445 | __webpack_require__.r(__webpack_exports__); |
| 4202 | 10446 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4203 | 10447 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4204 | 10448 | /* harmony export */ }); |
| 4205 | 10449 | /** |
| 4206 | -* Tom Select v2.4.3 | |
| 10450 | +* Tom Select v2.6.2 | |
| 4207 | 10451 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4208 | 10452 | */ |
| 4209 | 10453 | |
| 4210 | 10454 | /** |
| @@ -4286,9 +10530,9 @@ | ||
| 4286 | 10530 | return arg; |
| 4287 | 10531 | }; |
| 4288 | 10532 | |
| 4289 | 10533 | /** |
| 4290 | - * Plugin: "restore_on_backspace" (Tom Select) | |
| 10534 | + * Plugin: "virtual_scroll" (Tom Select) | |
| 4291 | 10535 | * Copyright (c) contributors |
| 4292 | 10536 | * |
| 4293 | 10537 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 4294 | 10538 | * file except in compliance with the License. You may obtain a copy of the License at: |
| @@ -4310,8 +10554,12 @@ | ||
| 4310 | 10554 | var dropdown_content; |
| 4311 | 10555 | var loading_more = false; |
| 4312 | 10556 | var load_more_opt; |
| 4313 | 10557 | var default_values = []; |
| 10558 | + var default_values_loaded = false; | |
| 10559 | + var default_pagination; | |
| 10560 | + var default_options = []; | |
| 10561 | + var html_values = []; | |
| 4314 | 10562 | if (!self.settings.shouldLoadMore) { |
| 4315 | 10563 | // return true if additional results should be loaded |
| 4316 | 10564 | self.settings.shouldLoadMore = () => { |
| 4317 | 10565 | const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop); |
| @@ -4341,9 +10589,9 @@ | ||
| 4341 | 10589 | }]; |
| 4342 | 10590 | |
| 4343 | 10591 | // can we load more results for given query? |
| 4344 | 10592 | const canLoadMore = query => { |
| 4345 | - if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) { | |
| 10593 | + if (self.settings.maxOptions !== null && typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) { | |
| 4346 | 10594 | return false; |
| 4347 | 10595 | } |
| 4348 | 10596 | if (query in pagination && pagination[query]) { |
| 4349 | 10597 | return true; |
| @@ -4401,9 +10649,13 @@ | ||
| 4401 | 10649 | |
| 4402 | 10650 | // wrap the load |
| 4403 | 10651 | self.hook('instead', 'loadCallback', (options, optgroups) => { |
| 4404 | 10652 | if (!loading_more) { |
| 4405 | - self.clearOptions(clearFilter); | |
| 10653 | + // When searching (non-empty query), keep selected items and HTML default options, | |
| 10654 | + // but remove preloaded remote options so they don't bleed into search results. | |
| 10655 | + // For empty query, use clearFilter (keeps default_values + items). | |
| 10656 | + const activeFilter = self.lastValue !== '' ? (_option, value) => self.items.indexOf(value) >= 0 || html_values.indexOf(value) >= 0 : clearFilter; | |
| 10657 | + self.clearOptions(activeFilter); | |
| 4406 | 10658 | } else if (load_more_opt) { |
| 4407 | 10659 | const first_option = options[0]; |
| 4408 | 10660 | if (first_option !== undefined) { |
| 4409 | 10661 | load_more_opt.dataset.value = first_option[self.settings.valueField]; |
| @@ -4409,11 +10661,31 @@ | ||
| 4409 | 10661 | load_more_opt.dataset.value = first_option[self.settings.valueField]; |
| 4410 | 10662 | } |
| 4411 | 10663 | } |
| 4412 | 10664 | orig_loadCallback.call(self, options, optgroups); |
| 10665 | + | |
| 10666 | + // After the initial preload (empty query), snapshot default_values and option objects | |
| 10667 | + // so they can be restored when the user clears their search. | |
| 10668 | + if (!loading_more && !default_values_loaded) { | |
| 10669 | + default_values_loaded = true; | |
| 10670 | + if (self.lastValue === '') { | |
| 10671 | + default_values = Object.keys(self.options); | |
| 10672 | + default_pagination = pagination['']; | |
| 10673 | + default_options = Object.values(self.options); | |
| 10674 | + } | |
| 10675 | + } | |
| 4413 | 10676 | loading_more = false; |
| 4414 | 10677 | }); |
| 4415 | 10678 | |
| 10679 | + // as the “loading_more” element will be removed from the dropdown, | |
| 10680 | + // we activate the previous option if needed | |
| 10681 | + // to avoid the dropdown being scrolled back to the first one | |
| 10682 | + self.hook('before', 'refreshOptions', () => { | |
| 10683 | + if (self.activeOption && "option" !== self.activeOption.getAttribute("role")) { | |
| 10684 | + self.setActiveOption(self.activeOption.previousElementSibling); | |
| 10685 | + } | |
| 10686 | + }); | |
| 10687 | + | |
| 4416 | 10688 | // add templates to dropdown |
| 4417 | 10689 | // loading_more if we have another url in the queue |
| 4418 | 10690 | // no_more_results if we don't have another url in the queue |
| 4419 | 10691 | self.hook('after', 'refreshOptions', () => { |
| @@ -4437,10 +10709,32 @@ | ||
| 4437 | 10709 | dropdown_content.append(option); |
| 4438 | 10710 | } |
| 4439 | 10711 | }); |
| 4440 | 10712 | |
| 10713 | + // Restore preloaded options and pagination when clearing search | |
| 10714 | + const restoreDefaults = () => { | |
| 10715 | + if (!default_values_loaded) { | |
| 10716 | + return; | |
| 10717 | + } | |
| 10718 | + // Re-add preloaded option objects (clearOptions can only remove, not restore) | |
| 10719 | + self.addOptions(default_options); | |
| 10720 | + // Remove any search results that are not part of the preloaded defaults | |
| 10721 | + self.clearOptions(clearFilter); | |
| 10722 | + if (default_pagination) { | |
| 10723 | + pagination[''] = default_pagination; | |
| 10724 | + } | |
| 10725 | + }; | |
| 10726 | + self.on('type', query => { | |
| 10727 | + if (query === '') { | |
| 10728 | + restoreDefaults(); | |
| 10729 | + self.refreshOptions(false); | |
| 10730 | + } | |
| 10731 | + }); | |
| 10732 | + self.on('dropdown_close', restoreDefaults); | |
| 10733 | + | |
| 4441 | 10734 | // add scroll listener and default templates |
| 4442 | 10735 | self.on('initialize', () => { |
| 10736 | + html_values = Object.keys(self.options); | |
| 4443 | 10737 | default_values = Object.keys(self.options); |
| 4444 | 10738 | dropdown_content = self.dropdown_content; |
| 4445 | 10739 | |
| 4446 | 10740 | // default templates |
| @@ -4483,8 +10777,9 @@ | ||
| 4483 | 10777 | !*** ./node_modules/tom-select/dist/esm/tom-select.complete.js ***! |
| 4484 | 10778 | \*****************************************************************/ |
| 4485 | 10779 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 4486 | 10780 | |
| 10781 | +"use strict"; | |
| 4487 | 10782 | __webpack_require__.r(__webpack_exports__); |
| 4488 | 10783 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4489 | 10784 | /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 4490 | 10785 | /* harmony export */ }); |
| @@ -4542,8 +10837,9 @@ | ||
| 4542 | 10837 | !*** ./node_modules/tom-select/dist/esm/tom-select.js ***! |
| 4543 | 10838 | \********************************************************/ |
| 4544 | 10839 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 4545 | 10840 | |
| 10841 | +"use strict"; | |
| 4546 | 10842 | __webpack_require__.r(__webpack_exports__); |
| 4547 | 10843 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4548 | 10844 | /* harmony export */ "default": () => (/* binding */ TomSelect) |
| 4549 | 10845 | /* harmony export */ }); |
| @@ -4578,8 +10874,9 @@ | ||
| 4578 | 10874 | this.isLocked = false; |
| 4579 | 10875 | this.isFocused = false; |
| 4580 | 10876 | this.isInputHidden = false; |
| 4581 | 10877 | this.isSetup = false; |
| 10878 | + this.isDropdownContentStale = true; | |
| 4582 | 10879 | this.ignoreFocus = false; |
| 4583 | 10880 | this.ignoreHover = false; |
| 4584 | 10881 | this.hasOptions = false; |
| 4585 | 10882 | this.lastValue = ''; |
| @@ -4654,9 +10951,9 @@ | ||
| 4654 | 10951 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown, settings.dropdownClass, inputMode); |
| 4655 | 10952 | if (settings.copyClassesToDropdown) { |
| 4656 | 10953 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown, classes); |
| 4657 | 10954 | } |
| 4658 | - (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown_content, settings.dropdownContentClass); | |
| 10955 | + ;(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown_content, settings.dropdownContentClass); | |
| 4659 | 10956 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(dropdown, dropdown_content); |
| 4660 | 10957 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.dropdownParent || wrapper).appendChild(dropdown); |
| 4661 | 10958 | // default controlInput |
| 4662 | 10959 | if ((0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.isHtmlString)(settings.controlInput)) { |
| @@ -4661,9 +10958,9 @@ | ||
| 4661 | 10958 | // default controlInput |
| 4662 | 10959 | if ((0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.isHtmlString)(settings.controlInput)) { |
| 4663 | 10960 | control_input = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.controlInput); |
| 4664 | 10961 | // set attributes |
| 4665 | - var attrs = ['autocorrect', 'autocapitalize', 'autocomplete', 'spellcheck']; | |
| 10962 | + var attrs = ['autocorrect', 'autocapitalize', 'autocomplete', 'spellcheck', 'aria-label']; | |
| 4666 | 10963 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(attrs, (attr) => { |
| 4667 | 10964 | if (input.getAttribute(attr)) { |
| 4668 | 10965 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(control_input, { [attr]: input.getAttribute(attr) }); |
| 4669 | 10966 | } |
| @@ -4724,8 +11021,10 @@ | ||
| 4724 | 11021 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(focus_node, { 'aria-labelledby': label_id }); |
| 4725 | 11022 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(dropdown_content, { 'aria-labelledby': label_id }); |
| 4726 | 11023 | } |
| 4727 | 11024 | wrapper.style.width = input.style.width; |
| 11025 | + wrapper.style.minWidth = input.style.minWidth; | |
| 11026 | + wrapper.style.maxWidth = input.style.maxWidth; | |
| 4728 | 11027 | if (self.plugins.names.length) { |
| 4729 | 11028 | const classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-'); |
| 4730 | 11029 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)([wrapper, dropdown], classes_plugins); |
| 4731 | 11030 | } |
| @@ -4743,9 +11042,9 @@ | ||
| 4743 | 11042 | // after initializePlugins() so plugins can create/modify user defined loaders |
| 4744 | 11043 | if (settings.load && settings.loadThrottle) { |
| 4745 | 11044 | settings.load = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.loadDebounce)(settings.load, settings.loadThrottle); |
| 4746 | 11045 | } |
| 4747 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mousemove', () => { | |
| 11046 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mousemove', () => { | |
| 4748 | 11047 | self.ignoreHover = false; |
| 4749 | 11048 | }); |
| 4750 | 11049 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mouseenter', (e) => { |
| 4751 | 11050 | var target_match = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.parentMatch)(e.target, '[data-selectable]', dropdown); |
| @@ -4808,12 +11107,21 @@ | ||
| 4808 | 11107 | if (self.isOpen) { |
| 4809 | 11108 | self.positionDropdown(); |
| 4810 | 11109 | } |
| 4811 | 11110 | }; |
| 11111 | + const input_invalid = () => { | |
| 11112 | + if (self.isValid) { | |
| 11113 | + self.isValid = false; | |
| 11114 | + self.isInvalid = true; | |
| 11115 | + self.refreshState(); | |
| 11116 | + } | |
| 11117 | + }; | |
| 11118 | + (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(input, 'invalid', input_invalid); | |
| 4812 | 11119 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(document, 'mousedown', doc_mousedown); |
| 4813 | 11120 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(window, 'scroll', win_scroll, passive_event); |
| 4814 | 11121 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(window, 'resize', win_scroll, passive_event); |
| 4815 | 11122 | this._destroy = () => { |
| 11123 | + input.removeEventListener('invalid', input_invalid); | |
| 4816 | 11124 | document.removeEventListener('mousedown', doc_mousedown); |
| 4817 | 11125 | window.removeEventListener('scroll', win_scroll); |
| 4818 | 11126 | window.removeEventListener('resize', win_scroll); |
| 4819 | 11127 | if (label) |
| @@ -4830,29 +11138,12 @@ | ||
| 4830 | 11138 | self.sync(false); |
| 4831 | 11139 | settings.items = []; |
| 4832 | 11140 | delete settings.optgroups; |
| 4833 | 11141 | delete settings.options; |
| 4834 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(input, 'invalid', () => { | |
| 4835 | - if (self.isValid) { | |
| 4836 | - self.isValid = false; | |
| 4837 | - self.isInvalid = true; | |
| 4838 | - self.refreshState(); | |
| 4839 | - } | |
| 4840 | - }); | |
| 4841 | - self.updateOriginalInput(); | |
| 4842 | 11142 | self.refreshItems(); |
| 4843 | 11143 | self.close(false); |
| 4844 | 11144 | self.inputState(); |
| 4845 | 11145 | self.isSetup = true; |
| 4846 | - if (input.disabled) { | |
| 4847 | - self.disable(); | |
| 4848 | - } | |
| 4849 | - else if (input.readOnly) { | |
| 4850 | - self.setReadOnly(true); | |
| 4851 | - } | |
| 4852 | - else { | |
| 4853 | - self.enable(); //sets tabIndex | |
| 4854 | - } | |
| 4855 | 11146 | self.on('change', this.onChange); |
| 4856 | 11147 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(input, 'tomselected', 'ts-hidden-accessible'); |
| 4857 | 11148 | self.trigger('initialize'); |
| 4858 | 11149 | // preload options |
| @@ -4948,11 +11239,20 @@ | ||
| 4948 | 11239 | * |
| 4949 | 11240 | */ |
| 4950 | 11241 | sync(get_settings = true) { |
| 4951 | 11242 | const self = this; |
| 4952 | - const settings = get_settings ? (0,_getSettings_js__WEBPACK_IMPORTED_MODULE_6__["default"])(self.input, { delimiter: self.settings.delimiter }) : self.settings; | |
| 11243 | + const settings = get_settings ? (0,_getSettings_js__WEBPACK_IMPORTED_MODULE_6__["default"])(self.input, { delimiter: self.settings.delimiter, allowEmptyOption: self.settings.allowEmptyOption }) : self.settings; | |
| 4953 | 11244 | self.setupOptions(settings.options, settings.optgroups); |
| 4954 | 11245 | self.setValue(settings.items || [], true); // silent prevents recursion |
| 11246 | + if (self.input.disabled) { | |
| 11247 | + self.disable(); | |
| 11248 | + } | |
| 11249 | + else if (self.input.readOnly) { | |
| 11250 | + self.setReadOnly(true); | |
| 11251 | + } | |
| 11252 | + else { | |
| 11253 | + self.enable(); //sets tabIndex | |
| 11254 | + } | |
| 4955 | 11255 | self.lastQuery = null; // so updated options will be displayed in dropdown |
| 4956 | 11256 | } |
| 4957 | 11257 | /** |
| 4958 | 11258 | * Triggered when the main control element |
| @@ -4983,9 +11283,9 @@ | ||
| 4983 | 11283 | * This should propagate the event to the original DOM |
| 4984 | 11284 | * input / select element. |
| 4985 | 11285 | */ |
| 4986 | 11286 | onChange() { |
| 4987 | - (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'input'); | |
| 11287 | + ;(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'input'); | |
| 4988 | 11288 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'change'); |
| 4989 | 11289 | } |
| 4990 | 11290 | /** |
| 4991 | 11291 | * Triggered on <input> paste. |
| @@ -5080,9 +11380,9 @@ | ||
| 5080 | 11380 | let next = self.getAdjacent(self.activeOption, 1); |
| 5081 | 11381 | if (next) |
| 5082 | 11382 | self.setActiveOption(next); |
| 5083 | 11383 | } |
| 5084 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 11384 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 5085 | 11385 | return; |
| 5086 | 11386 | // up: move selection up |
| 5087 | 11387 | case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_UP: |
| 5088 | 11388 | if (self.activeOption) { |
| @@ -5089,9 +11389,9 @@ | ||
| 5089 | 11389 | let prev = self.getAdjacent(self.activeOption, -1); |
| 5090 | 11390 | if (prev) |
| 5091 | 11391 | self.setActiveOption(prev); |
| 5092 | 11392 | } |
| 5093 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 11393 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 5094 | 11394 | return; |
| 5095 | 11395 | // return: select active option |
| 5096 | 11396 | case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_RETURN: |
| 5097 | 11397 | if (self.canSelect(self.activeOption)) { |
| @@ -5123,9 +11423,9 @@ | ||
| 5123 | 11423 | // prevent default [tab] behaviour of jump to the next field |
| 5124 | 11424 | // if select isFull, then the dropdown won't be open and [tab] will work normally |
| 5125 | 11425 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 5126 | 11426 | } |
| 5127 | - if (self.settings.create && self.createItem()) { | |
| 11427 | + else if (self.settings.create && self.createItem()) { | |
| 5128 | 11428 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 5129 | 11429 | } |
| 5130 | 11430 | } |
| 5131 | 11431 | return; |
| @@ -5247,18 +11547,24 @@ | ||
| 5247 | 11547 | self.createItem(null, () => { |
| 5248 | 11548 | if (self.settings.closeAfterSelect) { |
| 5249 | 11549 | self.close(); |
| 5250 | 11550 | } |
| 11551 | + else if (self.settings.clearAfterSelect) { | |
| 11552 | + self.setTextboxValue(); | |
| 11553 | + } | |
| 5251 | 11554 | }); |
| 5252 | 11555 | } |
| 5253 | 11556 | else { |
| 5254 | 11557 | value = option.dataset.value; |
| 5255 | 11558 | if (typeof value !== 'undefined') { |
| 5256 | - self.lastQuery = null; | |
| 11559 | + self.isDropdownContentStale = self.settings.hideSelected; | |
| 5257 | 11560 | self.addItem(value); |
| 5258 | 11561 | if (self.settings.closeAfterSelect) { |
| 5259 | 11562 | self.close(); |
| 5260 | 11563 | } |
| 11564 | + else if (self.settings.clearAfterSelect) { | |
| 11565 | + self.setTextboxValue(); | |
| 11566 | + } | |
| 5261 | 11567 | if (!self.settings.hideSelected && evt.type && /click/.test(evt.type)) { |
| 5262 | 11568 | self.setActiveOption(option); |
| 5263 | 11569 | } |
| 5264 | 11570 | } |
| @@ -5330,9 +11636,9 @@ | ||
| 5330 | 11636 | */ |
| 5331 | 11637 | loadCallback(options, optgroups) { |
| 5332 | 11638 | const self = this; |
| 5333 | 11639 | self.loading = Math.max(self.loading - 1, 0); |
| 5334 | - self.lastQuery = null; | |
| 11640 | + self.isDropdownContentStale = true; | |
| 5335 | 11641 | self.clearActiveOption(); // when new results load, focus should be on first option |
| 5336 | 11642 | self.setupOptions(options, optgroups); |
| 5337 | 11643 | self.refreshOptions(self.isFocused && !self.isInputHidden); |
| 5338 | 11644 | if (!self.loading) { |
| @@ -5429,9 +11735,9 @@ | ||
| 5429 | 11735 | if (self.activeItems.indexOf(item) === -1) { |
| 5430 | 11736 | self.setActiveItemClass(item); |
| 5431 | 11737 | } |
| 5432 | 11738 | } |
| 5433 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 11739 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 5434 | 11740 | } |
| 5435 | 11741 | else if ((eventName === 'click' && (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)(_constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_SHORTCUT, e)) || (eventName === 'keydown' && (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.isKeyDown)('shiftKey', e))) { |
| 5436 | 11742 | if (item.classList.contains('active')) { |
| 5437 | 11743 | self.removeActiveItem(item); |
| @@ -5478,9 +11784,9 @@ | ||
| 5478 | 11784 | * Clears all the active items |
| 5479 | 11785 | * |
| 5480 | 11786 | */ |
| 5481 | 11787 | clearActiveItems() { |
| 5482 | - (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(this.activeItems, 'active'); | |
| 11788 | + ;(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(this.activeItems, 'active'); | |
| 5483 | 11789 | this.activeItems = []; |
| 5484 | 11790 | } |
| 5485 | 11791 | /** |
| 5486 | 11792 | * Sets the selected item in the dropdown menu |
| @@ -5595,17 +11901,21 @@ | ||
| 5595 | 11901 | var self = this; |
| 5596 | 11902 | if (self.isDisabled || self.isReadOnly) |
| 5597 | 11903 | return; |
| 5598 | 11904 | self.ignoreFocus = true; |
| 5599 | - if (self.control_input.offsetWidth) { | |
| 5600 | - self.control_input.focus(); | |
| 5601 | - } | |
| 5602 | - else { | |
| 5603 | - self.focus_node.focus(); | |
| 5604 | - } | |
| 11905 | + const focusTarget = this.control_input.offsetWidth ? this.control_input : this.focus_node; | |
| 11906 | + focusTarget.focus(); | |
| 5605 | 11907 | setTimeout(() => { |
| 5606 | 11908 | self.ignoreFocus = false; |
| 5607 | - self.onFocus(); | |
| 11909 | + // Fix https://github.com/orchidjs/tom-select/issues/806 | |
| 11910 | + // Only proceed if this instance's element is still the active element. If Edge autofill | |
| 11911 | + // (or anything else) has moved focus to a different element in the interim, calling | |
| 11912 | + // onFocus() here would steal focus back and restart the cascade loop. | |
| 11913 | + const root = focusTarget.getRootNode(); | |
| 11914 | + if (root.activeElement !== focusTarget) { | |
| 11915 | + return; | |
| 11916 | + } | |
| 11917 | + this.onFocus(); | |
| 5608 | 11918 | }, 0); |
| 5609 | 11919 | } |
| 5610 | 11920 | /** |
| 5611 | 11921 | * Forces the control out of focus. |
| @@ -5661,10 +11971,15 @@ | ||
| 5661 | 11971 | throw new Error('Tom Select "score" setting must be a function that returns a function'); |
| 5662 | 11972 | } |
| 5663 | 11973 | } |
| 5664 | 11974 | // perform search |
| 5665 | - if (query !== self.lastQuery) { | |
| 11975 | + if (self.isDropdownContentStale || query !== self.lastQuery) { | |
| 5666 | 11976 | self.lastQuery = query; |
| 11977 | + // temp fix for https://github.com/orchidjs/tom-select/issues/987 | |
| 11978 | + // UI crashed when more than 30 same chars in a row, prevent search and return empt result | |
| 11979 | + if (/(.)\1{15,}/.test(query)) { | |
| 11980 | + query = ''; | |
| 11981 | + } | |
| 5667 | 11982 | result = self.sifter.search(query, Object.assign(options, { score: calculateScore })); |
| 5668 | 11983 | self.currentResults = result; |
| 5669 | 11984 | } |
| 5670 | 11985 | else { |
| @@ -5673,9 +11988,9 @@ | ||
| 5673 | 11988 | // filter out selected items |
| 5674 | 11989 | if (self.settings.hideSelected) { |
| 5675 | 11990 | result.items = result.items.filter((item) => { |
| 5676 | 11991 | let hashed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(item.id); |
| 5677 | - return !(hashed && self.items.indexOf(hashed) !== -1); | |
| 11992 | + return !(hashed !== null && self.items.indexOf(hashed) !== -1); | |
| 5678 | 11993 | }); |
| 5679 | 11994 | } |
| 5680 | 11995 | return result; |
| 5681 | 11996 | } |
| @@ -5745,8 +12060,15 @@ | ||
| 5745 | 12060 | for (j = 0, k = optgroups && optgroups.length; j < k; j++) { |
| 5746 | 12061 | optgroup = optgroups[j]; |
| 5747 | 12062 | let order = option.$order; |
| 5748 | 12063 | let self_optgroup = self.optgroups[optgroup]; |
| 12064 | + if (self_optgroup === undefined && typeof self.settings.optionGroupRegister === 'function') { | |
| 12065 | + var regGroup; | |
| 12066 | + if (regGroup = self.settings.optionGroupRegister.apply(self, [optgroup])) { | |
| 12067 | + self.registerOptionGroup(regGroup); | |
| 12068 | + } | |
| 12069 | + } | |
| 12070 | + self_optgroup = self.optgroups[optgroup]; | |
| 5749 | 12071 | if (self_optgroup === undefined) { |
| 5750 | 12072 | optgroup = ''; |
| 5751 | 12073 | } |
| 5752 | 12074 | else { |
| @@ -5799,8 +12121,9 @@ | ||
| 5799 | 12121 | } |
| 5800 | 12122 | }); |
| 5801 | 12123 | dropdown_content.innerHTML = ''; |
| 5802 | 12124 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(dropdown_content, html); |
| 12125 | + self.isDropdownContentStale = false; | |
| 5803 | 12126 | // highlight matching terms inline |
| 5804 | 12127 | if (self.settings.highlight) { |
| 5805 | 12128 | (0,_contrib_highlight_js__WEBPACK_IMPORTED_MODULE_4__.removeHighlight)(dropdown_content); |
| 5806 | 12129 | if (results.query.length && results.tokens.length) { |
| @@ -5893,14 +12216,15 @@ | ||
| 5893 | 12216 | return false; |
| 5894 | 12217 | } |
| 5895 | 12218 | const key = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(data[self.settings.valueField]); |
| 5896 | 12219 | if (key === null || self.options.hasOwnProperty(key)) { |
| 12220 | + self.updateOption(data[self.settings.valueField], data); | |
| 5897 | 12221 | return false; |
| 5898 | 12222 | } |
| 5899 | 12223 | data.$order = data.$order || ++self.order; |
| 5900 | 12224 | data.$id = self.inputId + '-opt-' + data.$order; |
| 5901 | 12225 | self.options[key] = data; |
| 5902 | - self.lastQuery = null; | |
| 12226 | + self.isDropdownContentStale = true; | |
| 5903 | 12227 | if (user_created) { |
| 5904 | 12228 | self.userOptions[key] = user_created; |
| 5905 | 12229 | self.trigger('option_add', key, data); |
| 5906 | 12230 | } |
| @@ -5910,9 +12234,9 @@ | ||
| 5910 | 12234 | * Add multiple options |
| 5911 | 12235 | * |
| 5912 | 12236 | */ |
| 5913 | 12237 | addOptions(data, user_created = false) { |
| 5914 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(data, (dat) => { | |
| 12238 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(data, (dat) => { | |
| 5915 | 12239 | this.addOption(dat, user_created); |
| 5916 | 12240 | }); |
| 5917 | 12241 | } |
| 5918 | 12242 | /** |
| @@ -6014,10 +12338,10 @@ | ||
| 6014 | 12338 | if (item.classList.contains('active')) |
| 6015 | 12339 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(item_new, 'active'); |
| 6016 | 12340 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.replaceNode)(item, item_new); |
| 6017 | 12341 | } |
| 6018 | - // invalidate last query because we might have updated the sortField | |
| 6019 | - self.lastQuery = null; | |
| 12342 | + // we might have updated the sortField | |
| 12343 | + self.isDropdownContentStale = true; | |
| 6020 | 12344 | } |
| 6021 | 12345 | /** |
| 6022 | 12346 | * Removes a single option. |
| 6023 | 12347 | * |
| @@ -6027,9 +12351,9 @@ | ||
| 6027 | 12351 | value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.get_hash)(value); |
| 6028 | 12352 | self.uncacheValue(value); |
| 6029 | 12353 | delete self.userOptions[value]; |
| 6030 | 12354 | delete self.options[value]; |
| 6031 | - self.lastQuery = null; | |
| 12355 | + self.isDropdownContentStale = true; | |
| 6032 | 12356 | self.trigger('option_remove', value); |
| 6033 | 12357 | self.removeItem(value, silent); |
| 6034 | 12358 | } |
| 6035 | 12359 | /** |
| @@ -6046,9 +12370,9 @@ | ||
| 6046 | 12370 | selected[key] = option; |
| 6047 | 12371 | } |
| 6048 | 12372 | }); |
| 6049 | 12373 | this.options = this.sifter.items = selected; |
| 6050 | - this.lastQuery = null; | |
| 12374 | + this.isDropdownContentStale = true; | |
| 6051 | 12375 | this.trigger('option_clear'); |
| 6052 | 12376 | } |
| 6053 | 12377 | /** |
| 6054 | 12378 | * Used by clearOptions() to decide whether or not an option should be removed |
| @@ -6178,8 +12502,12 @@ | ||
| 6178 | 12502 | if (next) { |
| 6179 | 12503 | self.setActiveOption(next); |
| 6180 | 12504 | } |
| 6181 | 12505 | } |
| 12506 | + //remove input value when enabled | |
| 12507 | + if (self.settings.clearAfterSelect) { | |
| 12508 | + self.setTextboxValue(); | |
| 12509 | + } | |
| 6182 | 12510 | // refreshOptions after setActiveOption(), |
| 6183 | 12511 | // otherwise setActiveOption() will be called by refreshOptions() with the wrong value |
| 6184 | 12512 | if (!self.isPending && !self.settings.closeAfterSelect) { |
| 6185 | 12513 | self.refreshOptions(self.isFocused && inputMode !== 'single'); |
| @@ -6221,9 +12549,9 @@ | ||
| 6221 | 12549 | self.activeItems.splice(idx, 1); |
| 6222 | 12550 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(item, 'active'); |
| 6223 | 12551 | } |
| 6224 | 12552 | self.items.splice(i, 1); |
| 6225 | - self.lastQuery = null; | |
| 12553 | + self.isDropdownContentStale = true; | |
| 6226 | 12554 | if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) { |
| 6227 | 12555 | self.removeOption(value, silent); |
| 6228 | 12556 | } |
| 6229 | 12557 | if (i < self.caretPos) { |
| @@ -6255,8 +12583,14 @@ | ||
| 6255 | 12583 | var caret = self.caretPos; |
| 6256 | 12584 | var output; |
| 6257 | 12585 | input = input || self.inputValue(); |
| 6258 | 12586 | if (!self.canCreate(input)) { |
| 12587 | + const hash = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(input); | |
| 12588 | + if (hash) { | |
| 12589 | + if (this.options[input]) { | |
| 12590 | + self.addItem(input); | |
| 12591 | + } | |
| 12592 | + } | |
| 6259 | 12593 | callback(); |
| 6260 | 12594 | return false; |
| 6261 | 12595 | } |
| 6262 | 12596 | self.lock(); |
| @@ -6294,9 +12628,9 @@ | ||
| 6294 | 12628 | * Re-renders the selected item lists. |
| 6295 | 12629 | */ |
| 6296 | 12630 | refreshItems() { |
| 6297 | 12631 | var self = this; |
| 6298 | - self.lastQuery = null; | |
| 12632 | + self.isDropdownContentStale = true; | |
| 6299 | 12633 | if (self.isSetup) { |
| 6300 | 12634 | self.addItems(self.items); |
| 6301 | 12635 | } |
| 6302 | 12636 | self.updateOriginalInput(); |
| @@ -6373,9 +12707,9 @@ | ||
| 6373 | 12707 | } |
| 6374 | 12708 | selected.push(option_el); |
| 6375 | 12709 | // marking empty option as selected can break validation |
| 6376 | 12710 | // fixes https://github.com/orchidjs/tom-select/issues/303 |
| 6377 | - if (option_el != empty_option || has_selected > 0) { | |
| 12711 | + if (option_el != empty_option || has_selected > 0 || self.settings.mode == 'multi') { | |
| 6378 | 12712 | option_el.selected = true; |
| 6379 | 12713 | } |
| 6380 | 12714 | return option_el; |
| 6381 | 12715 | } |
| @@ -6516,9 +12850,9 @@ | ||
| 6516 | 12850 | caret = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.nodeIndex)(tail); |
| 6517 | 12851 | if (direction > 0) { |
| 6518 | 12852 | caret++; |
| 6519 | 12853 | } |
| 6520 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(self.activeItems, (item) => rm_items.push(item)); | |
| 12854 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(self.activeItems, (item) => rm_items.push(item)); | |
| 6521 | 12855 | } |
| 6522 | 12856 | else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) { |
| 6523 | 12857 | const items = self.controlChildren(); |
| 6524 | 12858 | let rm_item; |
| @@ -6534,9 +12868,9 @@ | ||
| 6534 | 12868 | } |
| 6535 | 12869 | if (!self.shouldDelete(rm_items, e)) { |
| 6536 | 12870 | return false; |
| 6537 | 12871 | } |
| 6538 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e, true); | |
| 12872 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e, true); | |
| 6539 | 12873 | // perform removal |
| 6540 | 12874 | if (typeof caret !== 'undefined') { |
| 6541 | 12875 | self.setCaret(caret); |
| 6542 | 12876 | } |
| @@ -6553,9 +12887,9 @@ | ||
| 6553 | 12887 | */ |
| 6554 | 12888 | shouldDelete(items, evt) { |
| 6555 | 12889 | const values = items.map(item => item.dataset.value); |
| 6556 | 12890 | // allow the callback to abort |
| 6557 | - if (!values.length || (typeof this.settings.onDelete === 'function' && this.settings.onDelete(values, evt) === false)) { | |
| 12891 | + if (!values.length || (typeof this.settings.onDelete === 'function' && this.settings.onDelete.call(this, values, evt) === false)) { | |
| 6558 | 12892 | return false; |
| 6559 | 12893 | } |
| 6560 | 12894 | return true; |
| 6561 | 12895 | } |
| @@ -6772,9 +13106,9 @@ | ||
| 6772 | 13106 | * caches. |
| 6773 | 13107 | * |
| 6774 | 13108 | */ |
| 6775 | 13109 | clearCache() { |
| 6776 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(this.options, (option) => { | |
| 13110 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(this.options, (option) => { | |
| 6777 | 13111 | if (option.$div) { |
| 6778 | 13112 | option.$div.remove(); |
| 6779 | 13113 | delete option.$div; |
| 6780 | 13114 | } |
| @@ -6833,8 +13167,9 @@ | ||
| 6833 | 13167 | !*** ./node_modules/tom-select/dist/esm/utils.js ***! |
| 6834 | 13168 | \***************************************************/ |
| 6835 | 13169 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 6836 | 13170 | |
| 13171 | +"use strict"; | |
| 6837 | 13172 | __webpack_require__.r(__webpack_exports__); |
| 6838 | 13173 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 6839 | 13174 | /* harmony export */ addEvent: () => (/* binding */ addEvent), |
| 6840 | 13175 | /* harmony export */ addSlashes: () => (/* binding */ addSlashes), |
| @@ -7054,8 +13389,9 @@ | ||
| 7054 | 13389 | !*** ./node_modules/tom-select/dist/esm/vanilla.js ***! |
| 7055 | 13390 | \*****************************************************/ |
| 7056 | 13391 | (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) { |
| 7057 | 13392 | |
| 13393 | +"use strict"; | |
| 7058 | 13394 | __webpack_require__.r(__webpack_exports__); |
| 7059 | 13395 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 7060 | 13396 | /* harmony export */ addClasses: () => (/* binding */ addClasses), |
| 7061 | 13397 | /* harmony export */ applyCSS: () => (/* binding */ applyCSS), |
| @@ -7251,20 +13587,20 @@ | ||
| 7251 | 13587 | |
| 7252 | 13588 | /******/ }); |
| 7253 | 13589 | /************************************************************************/ |
| 7254 | 13590 | /******/ // The module cache |
| 7255 | -/******/ var __webpack_module_cache__ = {}; | |
| 13591 | +/******/ const __webpack_module_cache__ = {}; | |
| 7256 | 13592 | /******/ |
| 7257 | 13593 | /******/ // The require function |
| 7258 | 13594 | /******/ function __webpack_require__(moduleId) { |
| 7259 | 13595 | /******/ // Check if module is in cache |
| 7260 | -/******/ var cachedModule = __webpack_module_cache__[moduleId]; | |
| 13596 | +/******/ const cachedModule = __webpack_module_cache__[moduleId]; | |
| 7261 | 13597 | /******/ if (cachedModule !== undefined) { |
| 7262 | 13598 | /******/ return cachedModule.exports; |
| 7263 | 13599 | /******/ } |
| 7264 | 13600 | /******/ // Create a new module (and put it into the cache) |
| 7265 | -/******/ var module = __webpack_module_cache__[moduleId] = { | |
| 7266 | -/******/ // no module.id needed | |
| 13601 | +/******/ const module = __webpack_module_cache__[moduleId] = { | |
| 13602 | +/******/ id: moduleId, | |
| 7267 | 13603 | /******/ // no module.loaded needed |
| 7268 | 13604 | /******/ exports: {} |
| 7269 | 13605 | /******/ }; |
| 7270 | 13606 | /******/ |
| @@ -7270,13 +13606,13 @@ | ||
| 7270 | 13606 | /******/ |
| 7271 | 13607 | /******/ // Execute the module function |
| 7272 | 13608 | /******/ if (!(moduleId in __webpack_modules__)) { |
| 7273 | 13609 | /******/ delete __webpack_module_cache__[moduleId]; |
| 7274 | -/******/ var e = new Error("Cannot find module '" + moduleId + "'"); | |
| 13610 | +/******/ const e = new Error("Cannot find module '" + moduleId + "'"); | |
| 7275 | 13611 | /******/ e.code = 'MODULE_NOT_FOUND'; |
| 7276 | 13612 | /******/ throw e; |
| 7277 | 13613 | /******/ } |
| 7278 | -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); | |
| 13614 | +/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); | |
| 7279 | 13615 | /******/ |
| 7280 | 13616 | /******/ // Return the exports of the module |
| 7281 | 13617 | /******/ return module.exports; |
| 7282 | 13618 | /******/ } |
| @@ -7281,16 +13617,43 @@ | ||
| 7281 | 13617 | /******/ return module.exports; |
| 7282 | 13618 | /******/ } |
| 7283 | 13619 | /******/ |
| 7284 | 13620 | /************************************************************************/ |
| 13621 | +/******/ /* webpack/runtime/compat get default export */ | |
| 13622 | +/******/ (() => { | |
| 13623 | +/******/ // getDefaultExport function for compatibility with non-harmony modules | |
| 13624 | +/******/ __webpack_require__.n = (module) => { | |
| 13625 | +/******/ const getter = module && module.__esModule ? | |
| 13626 | +/******/ () => (module['default']) : | |
| 13627 | +/******/ () => (module); | |
| 13628 | +/******/ __webpack_require__.d(getter, { a: getter }); | |
| 13629 | +/******/ return getter; | |
| 13630 | +/******/ }; | |
| 13631 | +/******/ })(); | |
| 13632 | +/******/ | |
| 7285 | 13633 | /******/ /* webpack/runtime/define property getters */ |
| 7286 | 13634 | /******/ (() => { |
| 7287 | -/******/ // define getter functions for harmony exports | |
| 13635 | +/******/ // define getter/value functions for harmony exports | |
| 7288 | 13636 | /******/ __webpack_require__.d = (exports, definition) => { |
| 7289 | -/******/ for(var key in definition) { | |
| 7290 | -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 7291 | -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 13637 | +/******/ if(Array.isArray(definition)) { | |
| 13638 | +/******/ var i = 0; | |
| 13639 | +/******/ while(i < definition.length) { | |
| 13640 | +/******/ var key = definition[i++]; | |
| 13641 | +/******/ var binding = definition[i++]; | |
| 13642 | +/******/ if(!__webpack_require__.o(exports, key)) { | |
| 13643 | +/******/ if(binding === 0) { | |
| 13644 | +/******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] }); | |
| 13645 | +/******/ } else { | |
| 13646 | +/******/ Object.defineProperty(exports, key, { enumerable: true, get: binding }); | |
| 13647 | +/******/ } | |
| 13648 | +/******/ } else if(binding === 0) { i++; } | |
| 7292 | 13649 | /******/ } |
| 13650 | +/******/ } else { | |
| 13651 | +/******/ for(var key in definition) { | |
| 13652 | +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 13653 | +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 13654 | +/******/ } | |
| 13655 | +/******/ } | |
| 7293 | 13656 | /******/ } |
| 7294 | 13657 | /******/ }; |
| 7295 | 13658 | /******/ })(); |
| 7296 | 13659 | /******/ |
| @@ -7295,9 +13658,9 @@ | ||
| 7295 | 13658 | /******/ })(); |
| 7296 | 13659 | /******/ |
| 7297 | 13660 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 7298 | 13661 | /******/ (() => { |
| 7299 | -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | |
| 13662 | +/******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop)) | |
| 7300 | 13663 | /******/ })(); |
| 7301 | 13664 | /******/ |
| 7302 | 13665 | /******/ /* webpack/runtime/make namespace object */ |
| 7303 | 13666 | /******/ (() => { |
| @@ -7302,9 +13665,9 @@ | ||
| 7302 | 13665 | /******/ /* webpack/runtime/make namespace object */ |
| 7303 | 13666 | /******/ (() => { |
| 7304 | 13667 | /******/ // define __esModule on exports |
| 7305 | 13668 | /******/ __webpack_require__.r = (exports) => { |
| 7306 | -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 13669 | +/******/ if(Symbol.toStringTag) { | |
| 7307 | 13670 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 7308 | 13671 | /******/ } |
| 7309 | 13672 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 7310 | 13673 | /******/ }; |
| @@ -7309,12 +13672,18 @@ | ||
| 7309 | 13672 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 7310 | 13673 | /******/ }; |
| 7311 | 13674 | /******/ })(); |
| 7312 | 13675 | /******/ |
| 13676 | +/******/ /* webpack/runtime/nonce */ | |
| 13677 | +/******/ (() => { | |
| 13678 | +/******/ __webpack_require__.nc = undefined; | |
| 13679 | +/******/ })(); | |
| 13680 | +/******/ | |
| 7313 | 13681 | /************************************************************************/ |
| 7314 | -var __webpack_exports__ = {}; | |
| 7315 | -// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk. | |
| 13682 | +let __webpack_exports__ = {}; | |
| 13683 | +// This entry needs to be wrapped in an IIFE because it needs to be in strict mode. | |
| 7316 | 13684 | (() => { |
| 13685 | +"use strict"; | |
| 7317 | 13686 | /*!********************************************!*\ |
| 7318 | 13687 | !*** ./assets/src/js/admin/admin-order.js ***! |
| 7319 | 13688 | \********************************************/ |
| 7320 | 13689 | __webpack_require__.r(__webpack_exports__); |
| @@ -7319,15 +13688,18 @@ | ||
| 7319 | 13688 | \********************************************/ |
| 7320 | 13689 | __webpack_require__.r(__webpack_exports__); |
| 7321 | 13690 | /* harmony import */ var _order_export_invoice__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./order/export_invoice */ "./assets/src/js/admin/order/export_invoice.js"); |
| 7322 | 13691 | /* harmony import */ var _order_add_courses_to_order__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./order/add-courses-to-order */ "./assets/src/js/admin/order/add-courses-to-order.js"); |
| 13692 | +/* harmony import */ var _order_refund_order__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./order/refund-order */ "./assets/src/js/admin/order/refund-order.js"); | |
| 7323 | 13693 | |
| 7324 | 13694 | |
| 7325 | 13695 | //import modalSearchCourses from './order/modal-search-courses'; |
| 7326 | 13696 | |
| 13697 | + | |
| 7327 | 13698 | (0,_order_export_invoice__WEBPACK_IMPORTED_MODULE_0__["default"])(); |
| 7328 | 13699 | (0,_order_add_courses_to_order__WEBPACK_IMPORTED_MODULE_1__["default"])(); |
| 13700 | +(0,_order_refund_order__WEBPACK_IMPORTED_MODULE_2__["default"])(); | |
| 7329 | 13701 | })(); |
| 7330 | 13702 | |
| 7331 | 13703 | /******/ })() |
| 7332 | 13704 | ; |
| 7333 | 13705 | //# sourceMappingURL=admin-order.js.map |