| @@ -3624,8 +3624,9 @@ | ||
| 3624 | 3624 | diacritics: true, |
| 3625 | 3625 | create: null, |
| 3626 | 3626 | createOnBlur: false, |
| 3627 | 3627 | createFilter: null, |
| 3628 | + clearAfterSelect: false, | |
| 3628 | 3629 | highlight: true, |
| 3629 | 3630 | openOnFocus: true, |
| 3630 | 3631 | shouldOpen: null, |
| 3631 | 3632 | maxOptions: 50, |
| @@ -3823,11 +3824,12 @@ | ||
| 3823 | 3824 | * Initialize from a <input type="text"> element. |
| 3824 | 3825 | * |
| 3825 | 3826 | */ |
| 3826 | 3827 | var init_textbox = () => { |
| 3828 | + var _a, _b; | |
| 3827 | 3829 | const data_raw = input.getAttribute(attr_data); |
| 3828 | 3830 | if (!data_raw) { |
| 3829 | - var value = input.value.trim() || ''; | |
| 3831 | + 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 : ''; | |
| 3830 | 3832 | if (!settings.allowEmptyOption && !value.length) |
| 3831 | 3833 | return; |
| 3832 | 3834 | const values = value.split(settings.delimiter); |
| 3833 | 3835 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_1__.iterate)(values, (value) => { |
| @@ -3869,9 +3871,9 @@ | ||
| 3869 | 3871 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3870 | 3872 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 3871 | 3873 | /* harmony export */ }); |
| 3872 | 3874 | /** |
| 3873 | -* Tom Select v2.4.3 | |
| 3875 | +* Tom Select v2.6.2 | |
| 3874 | 3876 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3875 | 3877 | */ |
| 3876 | 3878 | |
| 3877 | 3879 | /** |
| @@ -4047,9 +4049,9 @@ | ||
| 4047 | 4049 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4048 | 4050 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4049 | 4051 | /* harmony export */ }); |
| 4050 | 4052 | /** |
| 4051 | -* Tom Select v2.4.3 | |
| 4053 | +* Tom Select v2.6.2 | |
| 4052 | 4054 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4053 | 4055 | */ |
| 4054 | 4056 | |
| 4055 | 4057 | /** |
| @@ -4113,9 +4115,9 @@ | ||
| 4113 | 4115 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4114 | 4116 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4115 | 4117 | /* harmony export */ }); |
| 4116 | 4118 | /** |
| 4117 | -* Tom Select v2.4.3 | |
| 4119 | +* Tom Select v2.6.2 | |
| 4118 | 4120 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4119 | 4121 | */ |
| 4120 | 4122 | |
| 4121 | 4123 | /** |
| @@ -4307,9 +4309,9 @@ | ||
| 4307 | 4309 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4308 | 4310 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4309 | 4311 | /* harmony export */ }); |
| 4310 | 4312 | /** |
| 4311 | -* Tom Select v2.4.3 | |
| 4313 | +* Tom Select v2.6.2 | |
| 4312 | 4314 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4313 | 4315 | */ |
| 4314 | 4316 | |
| 4315 | 4317 | /** |
| @@ -4358,10 +4360,12 @@ | ||
| 4358 | 4360 | const self = this; |
| 4359 | 4361 | const options = Object.assign({ |
| 4360 | 4362 | className: 'clear-button', |
| 4361 | 4363 | title: 'Clear All', |
| 4364 | + role: 'button', | |
| 4365 | + tabindex: 0, | |
| 4362 | 4366 | html: data => { |
| 4363 | - return `<div class="${data.className}" title="${data.title}">⨯</div>`; | |
| 4367 | + return `<div class="${data.className}" title="${data.title}" role="${data.role}" tabindex="${data.tabindex}">×</div>`; | |
| 4364 | 4368 | } |
| 4365 | 4369 | }, userOptions); |
| 4366 | 4370 | self.on('initialize', () => { |
| 4367 | 4371 | var button = getDom(options.html(options)); |
| @@ -4370,8 +4374,9 @@ | ||
| 4370 | 4374 | self.clear(); |
| 4371 | 4375 | if (self.settings.mode === 'single' && self.settings.allowEmptyOption) { |
| 4372 | 4376 | self.addItem(''); |
| 4373 | 4377 | } |
| 4378 | + self.refreshOptions(false); | |
| 4374 | 4379 | evt.preventDefault(); |
| 4375 | 4380 | evt.stopPropagation(); |
| 4376 | 4381 | }); |
| 4377 | 4382 | self.control.appendChild(button); |
| @@ -4395,9 +4400,9 @@ | ||
| 4395 | 4400 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4396 | 4401 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4397 | 4402 | /* harmony export */ }); |
| 4398 | 4403 | /** |
| 4399 | -* Tom Select v2.4.3 | |
| 4404 | +* Tom Select v2.6.2 | |
| 4400 | 4405 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4401 | 4406 | */ |
| 4402 | 4407 | |
| 4403 | 4408 | /** |
| @@ -4630,9 +4635,9 @@ | ||
| 4630 | 4635 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4631 | 4636 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4632 | 4637 | /* harmony export */ }); |
| 4633 | 4638 | /** |
| 4634 | -* Tom Select v2.4.3 | |
| 4639 | +* Tom Select v2.6.2 | |
| 4635 | 4640 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4636 | 4641 | */ |
| 4637 | 4642 | |
| 4638 | 4643 | /** |
| @@ -4747,9 +4752,9 @@ | ||
| 4747 | 4752 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4748 | 4753 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4749 | 4754 | /* harmony export */ }); |
| 4750 | 4755 | /** |
| 4751 | -* Tom Select v2.4.3 | |
| 4756 | +* Tom Select v2.6.2 | |
| 4752 | 4757 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4753 | 4758 | */ |
| 4754 | 4759 | |
| 4755 | 4760 | const KEY_ESC = 27; |
| @@ -4902,8 +4907,9 @@ | ||
| 4902 | 4907 | const self = this; |
| 4903 | 4908 | self.settings.shouldOpen = true; // make sure the input is shown even if there are no options to display in the dropdown |
| 4904 | 4909 | |
| 4905 | 4910 | self.hook('before', 'setup', () => { |
| 4911 | + var _self$input; | |
| 4906 | 4912 | self.focus_node = self.control; |
| 4907 | 4913 | addClasses(self.control_input, 'dropdown-input'); |
| 4908 | 4914 | const div = getDom('<div class="dropdown-input-wrap">'); |
| 4909 | 4915 | div.append(self.control_input); |
| @@ -4912,8 +4918,17 @@ | ||
| 4912 | 4918 | // set a placeholder in the select control |
| 4913 | 4919 | const placeholder = getDom('<input class="items-placeholder" tabindex="-1" />'); |
| 4914 | 4920 | placeholder.placeholder = self.settings.placeholder || ''; |
| 4915 | 4921 | self.control.append(placeholder); |
| 4922 | + /** | |
| 4923 | + * TomSelect renders a custom control with a focusable <input class="items-placeholder">. | |
| 4924 | + * The source <select>'s aria-label is not automatically propagated to that input, | |
| 4925 | + * which triggers "Missing form label" accessibility warnings. | |
| 4926 | + * This helper copies the label from the <select> onto the generated input. | |
| 4927 | + */ | |
| 4928 | + const label = (_self$input = self.input) == null ? void 0 : _self$input.getAttribute('aria-label'); | |
| 4929 | + if (!label) return; | |
| 4930 | + placeholder.setAttribute('aria-label', label); | |
| 4916 | 4931 | }); |
| 4917 | 4932 | self.on('initialize', () => { |
| 4918 | 4933 | // set tabIndex on control to -1, otherwise [shift+tab] will put focus right back on control_input |
| 4919 | 4934 | self.control_input.addEventListener('keydown', evt => { |
| @@ -4976,9 +4991,9 @@ | ||
| 4976 | 4991 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 4977 | 4992 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 4978 | 4993 | /* harmony export */ }); |
| 4979 | 4994 | /** |
| 4980 | -* Tom Select v2.4.3 | |
| 4995 | +* Tom Select v2.6.2 | |
| 4981 | 4996 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4982 | 4997 | */ |
| 4983 | 4998 | |
| 4984 | 4999 | /** |
| @@ -5065,9 +5080,9 @@ | ||
| 5065 | 5080 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 5066 | 5081 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 5067 | 5082 | /* harmony export */ }); |
| 5068 | 5083 | /** |
| 5069 | -* Tom Select v2.4.3 | |
| 5084 | +* Tom Select v2.6.2 | |
| 5070 | 5085 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5071 | 5086 | */ |
| 5072 | 5087 | |
| 5073 | 5088 | /** |
| @@ -5106,9 +5121,9 @@ | ||
| 5106 | 5121 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 5107 | 5122 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 5108 | 5123 | /* harmony export */ }); |
| 5109 | 5124 | /** |
| 5110 | -* Tom Select v2.4.3 | |
| 5125 | +* Tom Select v2.6.2 | |
| 5111 | 5126 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5112 | 5127 | */ |
| 5113 | 5128 | |
| 5114 | 5129 | /** |
| @@ -5153,9 +5168,9 @@ | ||
| 5153 | 5168 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 5154 | 5169 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 5155 | 5170 | /* harmony export */ }); |
| 5156 | 5171 | /** |
| 5157 | -* Tom Select v2.4.3 | |
| 5172 | +* Tom Select v2.6.2 | |
| 5158 | 5173 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5159 | 5174 | */ |
| 5160 | 5175 | |
| 5161 | 5176 | const KEY_LEFT = 37; |
| @@ -5254,9 +5269,9 @@ | ||
| 5254 | 5269 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 5255 | 5270 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 5256 | 5271 | /* harmony export */ }); |
| 5257 | 5272 | /** |
| 5258 | -* Tom Select v2.4.3 | |
| 5273 | +* Tom Select v2.6.2 | |
| 5259 | 5274 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5260 | 5275 | */ |
| 5261 | 5276 | |
| 5262 | 5277 | /** |
| @@ -5274,16 +5289,8 @@ | ||
| 5274 | 5289 | * |
| 5275 | 5290 | */ |
| 5276 | 5291 | |
| 5277 | 5292 | /** |
| 5278 | - * Escapes a string for use within HTML. | |
| 5279 | - * | |
| 5280 | - */ | |
| 5281 | -const escape_html = str => { | |
| 5282 | - return (str + '').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); | |
| 5283 | -}; | |
| 5284 | - | |
| 5285 | -/** | |
| 5286 | 5293 | * Prevent default |
| 5287 | 5294 | * |
| 5288 | 5295 | */ |
| 5289 | 5296 | const preventDefault = (evt, stop = false) => { |
| @@ -5345,28 +5352,31 @@ | ||
| 5345 | 5352 | * |
| 5346 | 5353 | */ |
| 5347 | 5354 | |
| 5348 | 5355 | function plugin (userOptions) { |
| 5356 | + const self = this; | |
| 5349 | 5357 | const options = Object.assign({ |
| 5350 | - label: '×', | |
| 5358 | + label: '×', | |
| 5351 | 5359 | title: 'Remove', |
| 5352 | 5360 | className: 'remove', |
| 5353 | - append: true | |
| 5361 | + tabindex: -1, | |
| 5362 | + role: 'button', | |
| 5363 | + html: data => { | |
| 5364 | + var _data$tabindex; | |
| 5365 | + const el = document.createElement('div'); | |
| 5366 | + el.className = data.className || ''; | |
| 5367 | + el.title = data.title || ''; | |
| 5368 | + el.setAttribute('role', data.role || 'button'); | |
| 5369 | + el.tabIndex = (_data$tabindex = data.tabindex) != null ? _data$tabindex : -1; | |
| 5370 | + el.textContent = data.label || ''; | |
| 5371 | + return el; | |
| 5372 | + } | |
| 5354 | 5373 | }, userOptions); |
| 5355 | - | |
| 5356 | - //options.className = 'remove-single'; | |
| 5357 | - var self = this; | |
| 5358 | - | |
| 5359 | - // override the render method to add remove button to each item | |
| 5360 | - if (!options.append) { | |
| 5361 | - return; | |
| 5362 | - } | |
| 5363 | - var html = '<a href="javascript:void(0)" class="' + options.className + '" tabindex="-1" title="' + escape_html(options.title) + '">' + options.label + '</a>'; | |
| 5364 | 5374 | self.hook('after', 'setupTemplates', () => { |
| 5365 | 5375 | var orig_render_item = self.settings.render.item; |
| 5366 | 5376 | self.settings.render.item = (data, escape) => { |
| 5367 | 5377 | var item = getDom(orig_render_item.call(self, data, escape)); |
| 5368 | - var close_button = getDom(html); | |
| 5378 | + var close_button = getDom(options.html(options)); | |
| 5369 | 5379 | item.appendChild(close_button); |
| 5370 | 5380 | addEvent(close_button, 'mousedown', evt => { |
| 5371 | 5381 | preventDefault(evt, true); |
| 5372 | 5382 | }); |
| @@ -5403,9 +5413,9 @@ | ||
| 5403 | 5413 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 5404 | 5414 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 5405 | 5415 | /* harmony export */ }); |
| 5406 | 5416 | /** |
| 5407 | -* Tom Select v2.4.3 | |
| 5417 | +* Tom Select v2.6.2 | |
| 5408 | 5418 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5409 | 5419 | */ |
| 5410 | 5420 | |
| 5411 | 5421 | /** |
| @@ -5460,9 +5470,9 @@ | ||
| 5460 | 5470 | /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 5461 | 5471 | /* harmony export */ "default": () => (/* binding */ plugin) |
| 5462 | 5472 | /* harmony export */ }); |
| 5463 | 5473 | /** |
| 5464 | -* Tom Select v2.4.3 | |
| 5474 | +* Tom Select v2.6.2 | |
| 5465 | 5475 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5466 | 5476 | */ |
| 5467 | 5477 | |
| 5468 | 5478 | /** |
| @@ -5544,9 +5554,9 @@ | ||
| 5544 | 5554 | return arg; |
| 5545 | 5555 | }; |
| 5546 | 5556 | |
| 5547 | 5557 | /** |
| 5548 | - * Plugin: "restore_on_backspace" (Tom Select) | |
| 5558 | + * Plugin: "virtual_scroll" (Tom Select) | |
| 5549 | 5559 | * Copyright (c) contributors |
| 5550 | 5560 | * |
| 5551 | 5561 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this |
| 5552 | 5562 | * file except in compliance with the License. You may obtain a copy of the License at: |
| @@ -5568,8 +5578,12 @@ | ||
| 5568 | 5578 | var dropdown_content; |
| 5569 | 5579 | var loading_more = false; |
| 5570 | 5580 | var load_more_opt; |
| 5571 | 5581 | var default_values = []; |
| 5582 | + var default_values_loaded = false; | |
| 5583 | + var default_pagination; | |
| 5584 | + var default_options = []; | |
| 5585 | + var html_values = []; | |
| 5572 | 5586 | if (!self.settings.shouldLoadMore) { |
| 5573 | 5587 | // return true if additional results should be loaded |
| 5574 | 5588 | self.settings.shouldLoadMore = () => { |
| 5575 | 5589 | const scroll_percent = dropdown_content.clientHeight / (dropdown_content.scrollHeight - dropdown_content.scrollTop); |
| @@ -5599,9 +5613,9 @@ | ||
| 5599 | 5613 | }]; |
| 5600 | 5614 | |
| 5601 | 5615 | // can we load more results for given query? |
| 5602 | 5616 | const canLoadMore = query => { |
| 5603 | - if (typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) { | |
| 5617 | + if (self.settings.maxOptions !== null && typeof self.settings.maxOptions === 'number' && dropdown_content.children.length >= self.settings.maxOptions) { | |
| 5604 | 5618 | return false; |
| 5605 | 5619 | } |
| 5606 | 5620 | if (query in pagination && pagination[query]) { |
| 5607 | 5621 | return true; |
| @@ -5659,9 +5673,13 @@ | ||
| 5659 | 5673 | |
| 5660 | 5674 | // wrap the load |
| 5661 | 5675 | self.hook('instead', 'loadCallback', (options, optgroups) => { |
| 5662 | 5676 | if (!loading_more) { |
| 5663 | - self.clearOptions(clearFilter); | |
| 5677 | + // When searching (non-empty query), keep selected items and HTML default options, | |
| 5678 | + // but remove preloaded remote options so they don't bleed into search results. | |
| 5679 | + // For empty query, use clearFilter (keeps default_values + items). | |
| 5680 | + const activeFilter = self.lastValue !== '' ? (_option, value) => self.items.indexOf(value) >= 0 || html_values.indexOf(value) >= 0 : clearFilter; | |
| 5681 | + self.clearOptions(activeFilter); | |
| 5664 | 5682 | } else if (load_more_opt) { |
| 5665 | 5683 | const first_option = options[0]; |
| 5666 | 5684 | if (first_option !== undefined) { |
| 5667 | 5685 | load_more_opt.dataset.value = first_option[self.settings.valueField]; |
| @@ -5667,11 +5685,31 @@ | ||
| 5667 | 5685 | load_more_opt.dataset.value = first_option[self.settings.valueField]; |
| 5668 | 5686 | } |
| 5669 | 5687 | } |
| 5670 | 5688 | orig_loadCallback.call(self, options, optgroups); |
| 5689 | + | |
| 5690 | + // After the initial preload (empty query), snapshot default_values and option objects | |
| 5691 | + // so they can be restored when the user clears their search. | |
| 5692 | + if (!loading_more && !default_values_loaded) { | |
| 5693 | + default_values_loaded = true; | |
| 5694 | + if (self.lastValue === '') { | |
| 5695 | + default_values = Object.keys(self.options); | |
| 5696 | + default_pagination = pagination['']; | |
| 5697 | + default_options = Object.values(self.options); | |
| 5698 | + } | |
| 5699 | + } | |
| 5671 | 5700 | loading_more = false; |
| 5672 | 5701 | }); |
| 5673 | 5702 | |
| 5703 | + // as the “loading_more” element will be removed from the dropdown, | |
| 5704 | + // we activate the previous option if needed | |
| 5705 | + // to avoid the dropdown being scrolled back to the first one | |
| 5706 | + self.hook('before', 'refreshOptions', () => { | |
| 5707 | + if (self.activeOption && "option" !== self.activeOption.getAttribute("role")) { | |
| 5708 | + self.setActiveOption(self.activeOption.previousElementSibling); | |
| 5709 | + } | |
| 5710 | + }); | |
| 5711 | + | |
| 5674 | 5712 | // add templates to dropdown |
| 5675 | 5713 | // loading_more if we have another url in the queue |
| 5676 | 5714 | // no_more_results if we don't have another url in the queue |
| 5677 | 5715 | self.hook('after', 'refreshOptions', () => { |
| @@ -5695,10 +5733,32 @@ | ||
| 5695 | 5733 | dropdown_content.append(option); |
| 5696 | 5734 | } |
| 5697 | 5735 | }); |
| 5698 | 5736 | |
| 5737 | + // Restore preloaded options and pagination when clearing search | |
| 5738 | + const restoreDefaults = () => { | |
| 5739 | + if (!default_values_loaded) { | |
| 5740 | + return; | |
| 5741 | + } | |
| 5742 | + // Re-add preloaded option objects (clearOptions can only remove, not restore) | |
| 5743 | + self.addOptions(default_options); | |
| 5744 | + // Remove any search results that are not part of the preloaded defaults | |
| 5745 | + self.clearOptions(clearFilter); | |
| 5746 | + if (default_pagination) { | |
| 5747 | + pagination[''] = default_pagination; | |
| 5748 | + } | |
| 5749 | + }; | |
| 5750 | + self.on('type', query => { | |
| 5751 | + if (query === '') { | |
| 5752 | + restoreDefaults(); | |
| 5753 | + self.refreshOptions(false); | |
| 5754 | + } | |
| 5755 | + }); | |
| 5756 | + self.on('dropdown_close', restoreDefaults); | |
| 5757 | + | |
| 5699 | 5758 | // add scroll listener and default templates |
| 5700 | 5759 | self.on('initialize', () => { |
| 5760 | + html_values = Object.keys(self.options); | |
| 5701 | 5761 | default_values = Object.keys(self.options); |
| 5702 | 5762 | dropdown_content = self.dropdown_content; |
| 5703 | 5763 | |
| 5704 | 5764 | // default templates |
| @@ -5838,8 +5898,9 @@ | ||
| 5838 | 5898 | this.isLocked = false; |
| 5839 | 5899 | this.isFocused = false; |
| 5840 | 5900 | this.isInputHidden = false; |
| 5841 | 5901 | this.isSetup = false; |
| 5902 | + this.isDropdownContentStale = true; | |
| 5842 | 5903 | this.ignoreFocus = false; |
| 5843 | 5904 | this.ignoreHover = false; |
| 5844 | 5905 | this.hasOptions = false; |
| 5845 | 5906 | this.lastValue = ''; |
| @@ -5914,9 +5975,9 @@ | ||
| 5914 | 5975 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown, settings.dropdownClass, inputMode); |
| 5915 | 5976 | if (settings.copyClassesToDropdown) { |
| 5916 | 5977 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown, classes); |
| 5917 | 5978 | } |
| 5918 | - (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown_content, settings.dropdownContentClass); | |
| 5979 | + ;(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(dropdown_content, settings.dropdownContentClass); | |
| 5919 | 5980 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(dropdown, dropdown_content); |
| 5920 | 5981 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.dropdownParent || wrapper).appendChild(dropdown); |
| 5921 | 5982 | // default controlInput |
| 5922 | 5983 | if ((0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.isHtmlString)(settings.controlInput)) { |
| @@ -5921,9 +5982,9 @@ | ||
| 5921 | 5982 | // default controlInput |
| 5922 | 5983 | if ((0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.isHtmlString)(settings.controlInput)) { |
| 5923 | 5984 | control_input = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.getDom)(settings.controlInput); |
| 5924 | 5985 | // set attributes |
| 5925 | - var attrs = ['autocorrect', 'autocapitalize', 'autocomplete', 'spellcheck']; | |
| 5986 | + var attrs = ['autocorrect', 'autocapitalize', 'autocomplete', 'spellcheck', 'aria-label']; | |
| 5926 | 5987 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(attrs, (attr) => { |
| 5927 | 5988 | if (input.getAttribute(attr)) { |
| 5928 | 5989 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(control_input, { [attr]: input.getAttribute(attr) }); |
| 5929 | 5990 | } |
| @@ -5984,8 +6045,10 @@ | ||
| 5984 | 6045 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(focus_node, { 'aria-labelledby': label_id }); |
| 5985 | 6046 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.setAttr)(dropdown_content, { 'aria-labelledby': label_id }); |
| 5986 | 6047 | } |
| 5987 | 6048 | wrapper.style.width = input.style.width; |
| 6049 | + wrapper.style.minWidth = input.style.minWidth; | |
| 6050 | + wrapper.style.maxWidth = input.style.maxWidth; | |
| 5988 | 6051 | if (self.plugins.names.length) { |
| 5989 | 6052 | const classes_plugins = 'plugin-' + self.plugins.names.join(' plugin-'); |
| 5990 | 6053 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)([wrapper, dropdown], classes_plugins); |
| 5991 | 6054 | } |
| @@ -6003,9 +6066,9 @@ | ||
| 6003 | 6066 | // after initializePlugins() so plugins can create/modify user defined loaders |
| 6004 | 6067 | if (settings.load && settings.loadThrottle) { |
| 6005 | 6068 | settings.load = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.loadDebounce)(settings.load, settings.loadThrottle); |
| 6006 | 6069 | } |
| 6007 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mousemove', () => { | |
| 6070 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mousemove', () => { | |
| 6008 | 6071 | self.ignoreHover = false; |
| 6009 | 6072 | }); |
| 6010 | 6073 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(dropdown, 'mouseenter', (e) => { |
| 6011 | 6074 | var target_match = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.parentMatch)(e.target, '[data-selectable]', dropdown); |
| @@ -6068,12 +6131,21 @@ | ||
| 6068 | 6131 | if (self.isOpen) { |
| 6069 | 6132 | self.positionDropdown(); |
| 6070 | 6133 | } |
| 6071 | 6134 | }; |
| 6135 | + const input_invalid = () => { | |
| 6136 | + if (self.isValid) { | |
| 6137 | + self.isValid = false; | |
| 6138 | + self.isInvalid = true; | |
| 6139 | + self.refreshState(); | |
| 6140 | + } | |
| 6141 | + }; | |
| 6142 | + (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(input, 'invalid', input_invalid); | |
| 6072 | 6143 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(document, 'mousedown', doc_mousedown); |
| 6073 | 6144 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(window, 'scroll', win_scroll, passive_event); |
| 6074 | 6145 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(window, 'resize', win_scroll, passive_event); |
| 6075 | 6146 | this._destroy = () => { |
| 6147 | + input.removeEventListener('invalid', input_invalid); | |
| 6076 | 6148 | document.removeEventListener('mousedown', doc_mousedown); |
| 6077 | 6149 | window.removeEventListener('scroll', win_scroll); |
| 6078 | 6150 | window.removeEventListener('resize', win_scroll); |
| 6079 | 6151 | if (label) |
| @@ -6090,29 +6162,12 @@ | ||
| 6090 | 6162 | self.sync(false); |
| 6091 | 6163 | settings.items = []; |
| 6092 | 6164 | delete settings.optgroups; |
| 6093 | 6165 | delete settings.options; |
| 6094 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.addEvent)(input, 'invalid', () => { | |
| 6095 | - if (self.isValid) { | |
| 6096 | - self.isValid = false; | |
| 6097 | - self.isInvalid = true; | |
| 6098 | - self.refreshState(); | |
| 6099 | - } | |
| 6100 | - }); | |
| 6101 | - self.updateOriginalInput(); | |
| 6102 | 6166 | self.refreshItems(); |
| 6103 | 6167 | self.close(false); |
| 6104 | 6168 | self.inputState(); |
| 6105 | 6169 | self.isSetup = true; |
| 6106 | - if (input.disabled) { | |
| 6107 | - self.disable(); | |
| 6108 | - } | |
| 6109 | - else if (input.readOnly) { | |
| 6110 | - self.setReadOnly(true); | |
| 6111 | - } | |
| 6112 | - else { | |
| 6113 | - self.enable(); //sets tabIndex | |
| 6114 | - } | |
| 6115 | 6170 | self.on('change', this.onChange); |
| 6116 | 6171 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(input, 'tomselected', 'ts-hidden-accessible'); |
| 6117 | 6172 | self.trigger('initialize'); |
| 6118 | 6173 | // preload options |
| @@ -6208,11 +6263,20 @@ | ||
| 6208 | 6263 | * |
| 6209 | 6264 | */ |
| 6210 | 6265 | sync(get_settings = true) { |
| 6211 | 6266 | const self = this; |
| 6212 | - const settings = get_settings ? (0,_getSettings_js__WEBPACK_IMPORTED_MODULE_6__["default"])(self.input, { delimiter: self.settings.delimiter }) : self.settings; | |
| 6267 | + const settings = get_settings ? (0,_getSettings_js__WEBPACK_IMPORTED_MODULE_6__["default"])(self.input, { delimiter: self.settings.delimiter, allowEmptyOption: self.settings.allowEmptyOption }) : self.settings; | |
| 6213 | 6268 | self.setupOptions(settings.options, settings.optgroups); |
| 6214 | 6269 | self.setValue(settings.items || [], true); // silent prevents recursion |
| 6270 | + if (self.input.disabled) { | |
| 6271 | + self.disable(); | |
| 6272 | + } | |
| 6273 | + else if (self.input.readOnly) { | |
| 6274 | + self.setReadOnly(true); | |
| 6275 | + } | |
| 6276 | + else { | |
| 6277 | + self.enable(); //sets tabIndex | |
| 6278 | + } | |
| 6215 | 6279 | self.lastQuery = null; // so updated options will be displayed in dropdown |
| 6216 | 6280 | } |
| 6217 | 6281 | /** |
| 6218 | 6282 | * Triggered when the main control element |
| @@ -6243,9 +6307,9 @@ | ||
| 6243 | 6307 | * This should propagate the event to the original DOM |
| 6244 | 6308 | * input / select element. |
| 6245 | 6309 | */ |
| 6246 | 6310 | onChange() { |
| 6247 | - (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'input'); | |
| 6311 | + ;(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'input'); | |
| 6248 | 6312 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.triggerEvent)(this.input, 'change'); |
| 6249 | 6313 | } |
| 6250 | 6314 | /** |
| 6251 | 6315 | * Triggered on <input> paste. |
| @@ -6340,9 +6404,9 @@ | ||
| 6340 | 6404 | let next = self.getAdjacent(self.activeOption, 1); |
| 6341 | 6405 | if (next) |
| 6342 | 6406 | self.setActiveOption(next); |
| 6343 | 6407 | } |
| 6344 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 6408 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 6345 | 6409 | return; |
| 6346 | 6410 | // up: move selection up |
| 6347 | 6411 | case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_UP: |
| 6348 | 6412 | if (self.activeOption) { |
| @@ -6349,9 +6413,9 @@ | ||
| 6349 | 6413 | let prev = self.getAdjacent(self.activeOption, -1); |
| 6350 | 6414 | if (prev) |
| 6351 | 6415 | self.setActiveOption(prev); |
| 6352 | 6416 | } |
| 6353 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 6417 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 6354 | 6418 | return; |
| 6355 | 6419 | // return: select active option |
| 6356 | 6420 | case _constants_js__WEBPACK_IMPORTED_MODULE_5__.KEY_RETURN: |
| 6357 | 6421 | if (self.canSelect(self.activeOption)) { |
| @@ -6383,9 +6447,9 @@ | ||
| 6383 | 6447 | // prevent default [tab] behaviour of jump to the next field |
| 6384 | 6448 | // if select isFull, then the dropdown won't be open and [tab] will work normally |
| 6385 | 6449 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 6386 | 6450 | } |
| 6387 | - if (self.settings.create && self.createItem()) { | |
| 6451 | + else if (self.settings.create && self.createItem()) { | |
| 6388 | 6452 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); |
| 6389 | 6453 | } |
| 6390 | 6454 | } |
| 6391 | 6455 | return; |
| @@ -6507,18 +6571,24 @@ | ||
| 6507 | 6571 | self.createItem(null, () => { |
| 6508 | 6572 | if (self.settings.closeAfterSelect) { |
| 6509 | 6573 | self.close(); |
| 6510 | 6574 | } |
| 6575 | + else if (self.settings.clearAfterSelect) { | |
| 6576 | + self.setTextboxValue(); | |
| 6577 | + } | |
| 6511 | 6578 | }); |
| 6512 | 6579 | } |
| 6513 | 6580 | else { |
| 6514 | 6581 | value = option.dataset.value; |
| 6515 | 6582 | if (typeof value !== 'undefined') { |
| 6516 | - self.lastQuery = null; | |
| 6583 | + self.isDropdownContentStale = self.settings.hideSelected; | |
| 6517 | 6584 | self.addItem(value); |
| 6518 | 6585 | if (self.settings.closeAfterSelect) { |
| 6519 | 6586 | self.close(); |
| 6520 | 6587 | } |
| 6588 | + else if (self.settings.clearAfterSelect) { | |
| 6589 | + self.setTextboxValue(); | |
| 6590 | + } | |
| 6521 | 6591 | if (!self.settings.hideSelected && evt.type && /click/.test(evt.type)) { |
| 6522 | 6592 | self.setActiveOption(option); |
| 6523 | 6593 | } |
| 6524 | 6594 | } |
| @@ -6590,9 +6660,9 @@ | ||
| 6590 | 6660 | */ |
| 6591 | 6661 | loadCallback(options, optgroups) { |
| 6592 | 6662 | const self = this; |
| 6593 | 6663 | self.loading = Math.max(self.loading - 1, 0); |
| 6594 | - self.lastQuery = null; | |
| 6664 | + self.isDropdownContentStale = true; | |
| 6595 | 6665 | self.clearActiveOption(); // when new results load, focus should be on first option |
| 6596 | 6666 | self.setupOptions(options, optgroups); |
| 6597 | 6667 | self.refreshOptions(self.isFocused && !self.isInputHidden); |
| 6598 | 6668 | if (!self.loading) { |
| @@ -6689,9 +6759,9 @@ | ||
| 6689 | 6759 | if (self.activeItems.indexOf(item) === -1) { |
| 6690 | 6760 | self.setActiveItemClass(item); |
| 6691 | 6761 | } |
| 6692 | 6762 | } |
| 6693 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 6763 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e); | |
| 6694 | 6764 | } |
| 6695 | 6765 | 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))) { |
| 6696 | 6766 | if (item.classList.contains('active')) { |
| 6697 | 6767 | self.removeActiveItem(item); |
| @@ -6738,9 +6808,9 @@ | ||
| 6738 | 6808 | * Clears all the active items |
| 6739 | 6809 | * |
| 6740 | 6810 | */ |
| 6741 | 6811 | clearActiveItems() { |
| 6742 | - (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(this.activeItems, 'active'); | |
| 6812 | + ;(0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(this.activeItems, 'active'); | |
| 6743 | 6813 | this.activeItems = []; |
| 6744 | 6814 | } |
| 6745 | 6815 | /** |
| 6746 | 6816 | * Sets the selected item in the dropdown menu |
| @@ -6855,17 +6925,21 @@ | ||
| 6855 | 6925 | var self = this; |
| 6856 | 6926 | if (self.isDisabled || self.isReadOnly) |
| 6857 | 6927 | return; |
| 6858 | 6928 | self.ignoreFocus = true; |
| 6859 | - if (self.control_input.offsetWidth) { | |
| 6860 | - self.control_input.focus(); | |
| 6861 | - } | |
| 6862 | - else { | |
| 6863 | - self.focus_node.focus(); | |
| 6864 | - } | |
| 6929 | + const focusTarget = this.control_input.offsetWidth ? this.control_input : this.focus_node; | |
| 6930 | + focusTarget.focus(); | |
| 6865 | 6931 | setTimeout(() => { |
| 6866 | 6932 | self.ignoreFocus = false; |
| 6867 | - self.onFocus(); | |
| 6933 | + // Fix https://github.com/orchidjs/tom-select/issues/806 | |
| 6934 | + // Only proceed if this instance's element is still the active element. If Edge autofill | |
| 6935 | + // (or anything else) has moved focus to a different element in the interim, calling | |
| 6936 | + // onFocus() here would steal focus back and restart the cascade loop. | |
| 6937 | + const root = focusTarget.getRootNode(); | |
| 6938 | + if (root.activeElement !== focusTarget) { | |
| 6939 | + return; | |
| 6940 | + } | |
| 6941 | + this.onFocus(); | |
| 6868 | 6942 | }, 0); |
| 6869 | 6943 | } |
| 6870 | 6944 | /** |
| 6871 | 6945 | * Forces the control out of focus. |
| @@ -6921,10 +6995,15 @@ | ||
| 6921 | 6995 | throw new Error('Tom Select "score" setting must be a function that returns a function'); |
| 6922 | 6996 | } |
| 6923 | 6997 | } |
| 6924 | 6998 | // perform search |
| 6925 | - if (query !== self.lastQuery) { | |
| 6999 | + if (self.isDropdownContentStale || query !== self.lastQuery) { | |
| 6926 | 7000 | self.lastQuery = query; |
| 7001 | + // temp fix for https://github.com/orchidjs/tom-select/issues/987 | |
| 7002 | + // UI crashed when more than 30 same chars in a row, prevent search and return empt result | |
| 7003 | + if (/(.)\1{15,}/.test(query)) { | |
| 7004 | + query = ''; | |
| 7005 | + } | |
| 6927 | 7006 | result = self.sifter.search(query, Object.assign(options, { score: calculateScore })); |
| 6928 | 7007 | self.currentResults = result; |
| 6929 | 7008 | } |
| 6930 | 7009 | else { |
| @@ -6933,9 +7012,9 @@ | ||
| 6933 | 7012 | // filter out selected items |
| 6934 | 7013 | if (self.settings.hideSelected) { |
| 6935 | 7014 | result.items = result.items.filter((item) => { |
| 6936 | 7015 | let hashed = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(item.id); |
| 6937 | - return !(hashed && self.items.indexOf(hashed) !== -1); | |
| 7016 | + return !(hashed !== null && self.items.indexOf(hashed) !== -1); | |
| 6938 | 7017 | }); |
| 6939 | 7018 | } |
| 6940 | 7019 | return result; |
| 6941 | 7020 | } |
| @@ -7005,8 +7084,15 @@ | ||
| 7005 | 7084 | for (j = 0, k = optgroups && optgroups.length; j < k; j++) { |
| 7006 | 7085 | optgroup = optgroups[j]; |
| 7007 | 7086 | let order = option.$order; |
| 7008 | 7087 | let self_optgroup = self.optgroups[optgroup]; |
| 7088 | + if (self_optgroup === undefined && typeof self.settings.optionGroupRegister === 'function') { | |
| 7089 | + var regGroup; | |
| 7090 | + if (regGroup = self.settings.optionGroupRegister.apply(self, [optgroup])) { | |
| 7091 | + self.registerOptionGroup(regGroup); | |
| 7092 | + } | |
| 7093 | + } | |
| 7094 | + self_optgroup = self.optgroups[optgroup]; | |
| 7009 | 7095 | if (self_optgroup === undefined) { |
| 7010 | 7096 | optgroup = ''; |
| 7011 | 7097 | } |
| 7012 | 7098 | else { |
| @@ -7059,8 +7145,9 @@ | ||
| 7059 | 7145 | } |
| 7060 | 7146 | }); |
| 7061 | 7147 | dropdown_content.innerHTML = ''; |
| 7062 | 7148 | (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.append)(dropdown_content, html); |
| 7149 | + self.isDropdownContentStale = false; | |
| 7063 | 7150 | // highlight matching terms inline |
| 7064 | 7151 | if (self.settings.highlight) { |
| 7065 | 7152 | (0,_contrib_highlight_js__WEBPACK_IMPORTED_MODULE_4__.removeHighlight)(dropdown_content); |
| 7066 | 7153 | if (results.query.length && results.tokens.length) { |
| @@ -7153,14 +7240,15 @@ | ||
| 7153 | 7240 | return false; |
| 7154 | 7241 | } |
| 7155 | 7242 | const key = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(data[self.settings.valueField]); |
| 7156 | 7243 | if (key === null || self.options.hasOwnProperty(key)) { |
| 7244 | + self.updateOption(data[self.settings.valueField], data); | |
| 7157 | 7245 | return false; |
| 7158 | 7246 | } |
| 7159 | 7247 | data.$order = data.$order || ++self.order; |
| 7160 | 7248 | data.$id = self.inputId + '-opt-' + data.$order; |
| 7161 | 7249 | self.options[key] = data; |
| 7162 | - self.lastQuery = null; | |
| 7250 | + self.isDropdownContentStale = true; | |
| 7163 | 7251 | if (user_created) { |
| 7164 | 7252 | self.userOptions[key] = user_created; |
| 7165 | 7253 | self.trigger('option_add', key, data); |
| 7166 | 7254 | } |
| @@ -7170,9 +7258,9 @@ | ||
| 7170 | 7258 | * Add multiple options |
| 7171 | 7259 | * |
| 7172 | 7260 | */ |
| 7173 | 7261 | addOptions(data, user_created = false) { |
| 7174 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(data, (dat) => { | |
| 7262 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(data, (dat) => { | |
| 7175 | 7263 | this.addOption(dat, user_created); |
| 7176 | 7264 | }); |
| 7177 | 7265 | } |
| 7178 | 7266 | /** |
| @@ -7274,10 +7362,10 @@ | ||
| 7274 | 7362 | if (item.classList.contains('active')) |
| 7275 | 7363 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.addClasses)(item_new, 'active'); |
| 7276 | 7364 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.replaceNode)(item, item_new); |
| 7277 | 7365 | } |
| 7278 | - // invalidate last query because we might have updated the sortField | |
| 7279 | - self.lastQuery = null; | |
| 7366 | + // we might have updated the sortField | |
| 7367 | + self.isDropdownContentStale = true; | |
| 7280 | 7368 | } |
| 7281 | 7369 | /** |
| 7282 | 7370 | * Removes a single option. |
| 7283 | 7371 | * |
| @@ -7287,9 +7375,9 @@ | ||
| 7287 | 7375 | value = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.get_hash)(value); |
| 7288 | 7376 | self.uncacheValue(value); |
| 7289 | 7377 | delete self.userOptions[value]; |
| 7290 | 7378 | delete self.options[value]; |
| 7291 | - self.lastQuery = null; | |
| 7379 | + self.isDropdownContentStale = true; | |
| 7292 | 7380 | self.trigger('option_remove', value); |
| 7293 | 7381 | self.removeItem(value, silent); |
| 7294 | 7382 | } |
| 7295 | 7383 | /** |
| @@ -7306,9 +7394,9 @@ | ||
| 7306 | 7394 | selected[key] = option; |
| 7307 | 7395 | } |
| 7308 | 7396 | }); |
| 7309 | 7397 | this.options = this.sifter.items = selected; |
| 7310 | - this.lastQuery = null; | |
| 7398 | + this.isDropdownContentStale = true; | |
| 7311 | 7399 | this.trigger('option_clear'); |
| 7312 | 7400 | } |
| 7313 | 7401 | /** |
| 7314 | 7402 | * Used by clearOptions() to decide whether or not an option should be removed |
| @@ -7438,8 +7526,12 @@ | ||
| 7438 | 7526 | if (next) { |
| 7439 | 7527 | self.setActiveOption(next); |
| 7440 | 7528 | } |
| 7441 | 7529 | } |
| 7530 | + //remove input value when enabled | |
| 7531 | + if (self.settings.clearAfterSelect) { | |
| 7532 | + self.setTextboxValue(); | |
| 7533 | + } | |
| 7442 | 7534 | // refreshOptions after setActiveOption(), |
| 7443 | 7535 | // otherwise setActiveOption() will be called by refreshOptions() with the wrong value |
| 7444 | 7536 | if (!self.isPending && !self.settings.closeAfterSelect) { |
| 7445 | 7537 | self.refreshOptions(self.isFocused && inputMode !== 'single'); |
| @@ -7481,9 +7573,9 @@ | ||
| 7481 | 7573 | self.activeItems.splice(idx, 1); |
| 7482 | 7574 | (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.removeClasses)(item, 'active'); |
| 7483 | 7575 | } |
| 7484 | 7576 | self.items.splice(i, 1); |
| 7485 | - self.lastQuery = null; | |
| 7577 | + self.isDropdownContentStale = true; | |
| 7486 | 7578 | if (!self.settings.persist && self.userOptions.hasOwnProperty(value)) { |
| 7487 | 7579 | self.removeOption(value, silent); |
| 7488 | 7580 | } |
| 7489 | 7581 | if (i < self.caretPos) { |
| @@ -7515,8 +7607,14 @@ | ||
| 7515 | 7607 | var caret = self.caretPos; |
| 7516 | 7608 | var output; |
| 7517 | 7609 | input = input || self.inputValue(); |
| 7518 | 7610 | if (!self.canCreate(input)) { |
| 7611 | + const hash = (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.hash_key)(input); | |
| 7612 | + if (hash) { | |
| 7613 | + if (this.options[input]) { | |
| 7614 | + self.addItem(input); | |
| 7615 | + } | |
| 7616 | + } | |
| 7519 | 7617 | callback(); |
| 7520 | 7618 | return false; |
| 7521 | 7619 | } |
| 7522 | 7620 | self.lock(); |
| @@ -7554,9 +7652,9 @@ | ||
| 7554 | 7652 | * Re-renders the selected item lists. |
| 7555 | 7653 | */ |
| 7556 | 7654 | refreshItems() { |
| 7557 | 7655 | var self = this; |
| 7558 | - self.lastQuery = null; | |
| 7656 | + self.isDropdownContentStale = true; | |
| 7559 | 7657 | if (self.isSetup) { |
| 7560 | 7658 | self.addItems(self.items); |
| 7561 | 7659 | } |
| 7562 | 7660 | self.updateOriginalInput(); |
| @@ -7633,9 +7731,9 @@ | ||
| 7633 | 7731 | } |
| 7634 | 7732 | selected.push(option_el); |
| 7635 | 7733 | // marking empty option as selected can break validation |
| 7636 | 7734 | // fixes https://github.com/orchidjs/tom-select/issues/303 |
| 7637 | - if (option_el != empty_option || has_selected > 0) { | |
| 7735 | + if (option_el != empty_option || has_selected > 0 || self.settings.mode == 'multi') { | |
| 7638 | 7736 | option_el.selected = true; |
| 7639 | 7737 | } |
| 7640 | 7738 | return option_el; |
| 7641 | 7739 | } |
| @@ -7776,9 +7874,9 @@ | ||
| 7776 | 7874 | caret = (0,_vanilla_js__WEBPACK_IMPORTED_MODULE_8__.nodeIndex)(tail); |
| 7777 | 7875 | if (direction > 0) { |
| 7778 | 7876 | caret++; |
| 7779 | 7877 | } |
| 7780 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(self.activeItems, (item) => rm_items.push(item)); | |
| 7878 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(self.activeItems, (item) => rm_items.push(item)); | |
| 7781 | 7879 | } |
| 7782 | 7880 | else if ((self.isFocused || self.settings.mode === 'single') && self.items.length) { |
| 7783 | 7881 | const items = self.controlChildren(); |
| 7784 | 7882 | let rm_item; |
| @@ -7794,9 +7892,9 @@ | ||
| 7794 | 7892 | } |
| 7795 | 7893 | if (!self.shouldDelete(rm_items, e)) { |
| 7796 | 7894 | return false; |
| 7797 | 7895 | } |
| 7798 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e, true); | |
| 7896 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.preventDefault)(e, true); | |
| 7799 | 7897 | // perform removal |
| 7800 | 7898 | if (typeof caret !== 'undefined') { |
| 7801 | 7899 | self.setCaret(caret); |
| 7802 | 7900 | } |
| @@ -7813,9 +7911,9 @@ | ||
| 7813 | 7911 | */ |
| 7814 | 7912 | shouldDelete(items, evt) { |
| 7815 | 7913 | const values = items.map(item => item.dataset.value); |
| 7816 | 7914 | // allow the callback to abort |
| 7817 | - if (!values.length || (typeof this.settings.onDelete === 'function' && this.settings.onDelete(values, evt) === false)) { | |
| 7915 | + if (!values.length || (typeof this.settings.onDelete === 'function' && this.settings.onDelete.call(this, values, evt) === false)) { | |
| 7818 | 7916 | return false; |
| 7819 | 7917 | } |
| 7820 | 7918 | return true; |
| 7821 | 7919 | } |
| @@ -8032,9 +8130,9 @@ | ||
| 8032 | 8130 | * caches. |
| 8033 | 8131 | * |
| 8034 | 8132 | */ |
| 8035 | 8133 | clearCache() { |
| 8036 | - (0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(this.options, (option) => { | |
| 8134 | + ;(0,_utils_js__WEBPACK_IMPORTED_MODULE_7__.iterate)(this.options, (option) => { | |
| 8037 | 8135 | if (option.$div) { |
| 8038 | 8136 | option.$div.remove(); |
| 8039 | 8137 | delete option.$div; |
| 8040 | 8138 | } |
| @@ -8513,19 +8611,19 @@ | ||
| 8513 | 8611 | |
| 8514 | 8612 | /******/ }); |
| 8515 | 8613 | /************************************************************************/ |
| 8516 | 8614 | /******/ // The module cache |
| 8517 | -/******/ var __webpack_module_cache__ = {}; | |
| 8615 | +/******/ const __webpack_module_cache__ = {}; | |
| 8518 | 8616 | /******/ |
| 8519 | 8617 | /******/ // The require function |
| 8520 | 8618 | /******/ function __webpack_require__(moduleId) { |
| 8521 | 8619 | /******/ // Check if module is in cache |
| 8522 | -/******/ var cachedModule = __webpack_module_cache__[moduleId]; | |
| 8620 | +/******/ const cachedModule = __webpack_module_cache__[moduleId]; | |
| 8523 | 8621 | /******/ if (cachedModule !== undefined) { |
| 8524 | 8622 | /******/ return cachedModule.exports; |
| 8525 | 8623 | /******/ } |
| 8526 | 8624 | /******/ // Create a new module (and put it into the cache) |
| 8527 | -/******/ var module = __webpack_module_cache__[moduleId] = { | |
| 8625 | +/******/ const module = __webpack_module_cache__[moduleId] = { | |
| 8528 | 8626 | /******/ id: moduleId, |
| 8529 | 8627 | /******/ // no module.loaded needed |
| 8530 | 8628 | /******/ exports: {} |
| 8531 | 8629 | /******/ }; |
| @@ -8532,9 +8630,9 @@ | ||
| 8532 | 8630 | /******/ |
| 8533 | 8631 | /******/ // Execute the module function |
| 8534 | 8632 | /******/ if (!(moduleId in __webpack_modules__)) { |
| 8535 | 8633 | /******/ delete __webpack_module_cache__[moduleId]; |
| 8536 | -/******/ var e = new Error("Cannot find module '" + moduleId + "'"); | |
| 8634 | +/******/ const e = new Error("Cannot find module '" + moduleId + "'"); | |
| 8537 | 8635 | /******/ e.code = 'MODULE_NOT_FOUND'; |
| 8538 | 8636 | /******/ throw e; |
| 8539 | 8637 | /******/ } |
| 8540 | 8638 | /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| @@ -8547,9 +8645,9 @@ | ||
| 8547 | 8645 | /******/ /* webpack/runtime/compat get default export */ |
| 8548 | 8646 | /******/ (() => { |
| 8549 | 8647 | /******/ // getDefaultExport function for compatibility with non-harmony modules |
| 8550 | 8648 | /******/ __webpack_require__.n = (module) => { |
| 8551 | -/******/ var getter = module && module.__esModule ? | |
| 8649 | +/******/ const getter = module && module.__esModule ? | |
| 8552 | 8650 | /******/ () => (module['default']) : |
| 8553 | 8651 | /******/ () => (module); |
| 8554 | 8652 | /******/ __webpack_require__.d(getter, { a: getter }); |
| 8555 | 8653 | /******/ return getter; |
| @@ -8557,14 +8655,29 @@ | ||
| 8557 | 8655 | /******/ })(); |
| 8558 | 8656 | /******/ |
| 8559 | 8657 | /******/ /* webpack/runtime/define property getters */ |
| 8560 | 8658 | /******/ (() => { |
| 8561 | -/******/ // define getter functions for harmony exports | |
| 8659 | +/******/ // define getter/value functions for harmony exports | |
| 8562 | 8660 | /******/ __webpack_require__.d = (exports, definition) => { |
| 8563 | -/******/ for(var key in definition) { | |
| 8564 | -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 8565 | -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 8661 | +/******/ if(Array.isArray(definition)) { | |
| 8662 | +/******/ var i = 0; | |
| 8663 | +/******/ while(i < definition.length) { | |
| 8664 | +/******/ var key = definition[i++]; | |
| 8665 | +/******/ var binding = definition[i++]; | |
| 8666 | +/******/ if(!__webpack_require__.o(exports, key)) { | |
| 8667 | +/******/ if(binding === 0) { | |
| 8668 | +/******/ Object.defineProperty(exports, key, { enumerable: true, value: definition[i++] }); | |
| 8669 | +/******/ } else { | |
| 8670 | +/******/ Object.defineProperty(exports, key, { enumerable: true, get: binding }); | |
| 8671 | +/******/ } | |
| 8672 | +/******/ } else if(binding === 0) { i++; } | |
| 8566 | 8673 | /******/ } |
| 8674 | +/******/ } else { | |
| 8675 | +/******/ for(var key in definition) { | |
| 8676 | +/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 8677 | +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 8678 | +/******/ } | |
| 8679 | +/******/ } | |
| 8567 | 8680 | /******/ } |
| 8568 | 8681 | /******/ }; |
| 8569 | 8682 | /******/ })(); |
| 8570 | 8683 | /******/ |
| @@ -8569,9 +8682,9 @@ | ||
| 8569 | 8682 | /******/ })(); |
| 8570 | 8683 | /******/ |
| 8571 | 8684 | /******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 8572 | 8685 | /******/ (() => { |
| 8573 | -/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | |
| 8686 | +/******/ __webpack_require__.o = (obj, prop) => (Object.hasOwn(obj, prop)) | |
| 8574 | 8687 | /******/ })(); |
| 8575 | 8688 | /******/ |
| 8576 | 8689 | /******/ /* webpack/runtime/make namespace object */ |
| 8577 | 8690 | /******/ (() => { |
| @@ -8576,9 +8689,9 @@ | ||
| 8576 | 8689 | /******/ /* webpack/runtime/make namespace object */ |
| 8577 | 8690 | /******/ (() => { |
| 8578 | 8691 | /******/ // define __esModule on exports |
| 8579 | 8692 | /******/ __webpack_require__.r = (exports) => { |
| 8580 | -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 8693 | +/******/ if(Symbol.toStringTag) { | |
| 8581 | 8694 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 8582 | 8695 | /******/ } |
| 8583 | 8696 | /******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 8584 | 8697 | /******/ }; |
| @@ -8589,9 +8702,9 @@ | ||
| 8589 | 8702 | /******/ __webpack_require__.nc = undefined; |
| 8590 | 8703 | /******/ })(); |
| 8591 | 8704 | /******/ |
| 8592 | 8705 | /************************************************************************/ |
| 8593 | -var __webpack_exports__ = {}; | |
| 8706 | +let __webpack_exports__ = {}; | |
| 8594 | 8707 | // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. |
| 8595 | 8708 | (() => { |
| 8596 | 8709 | "use strict"; |
| 8597 | 8710 | /*!**************************************!*\ |