diff --git a/.eslintrc.json b/.eslintrc.json index 72942a45..53bfc92a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -115,7 +115,8 @@ "CustomEvent", "Element.prototype.classList", "Element.prototype.closest", - "Element.prototype.dataset" + "Element.prototype.dataset", + "Element.prototype.replaceChildren" ], "import/resolver": { "node": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 5239e2fc..6af57a0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [11.0.0] + +### ⚠ BREAKING CHANGES +* Update polyfills to include `Element.prototype.replaceChildren` + +### Bug Fixes (from 10.2.0) +* Reduce work done for `unhighlightAll` during on-click handler (batching in v11.0.0-rc8 would also have helped) [#522](https://github.com/Choices-js/Choices/issues/522) [#599](https://github.com/Choices-js/Choices/issues/599) +* Improve performance when rendering very large number of items and choices. Stuttering when stopping searching or selecting an item still happens depending on device and number of choices. + ## [11.0.0-rc8] (2024-08-23) ### ⚠ BREAKING CHANGES diff --git a/README.md b/README.md index ef9a8e61..d33fc912 100644 --- a/README.md +++ b/README.md @@ -1250,7 +1250,7 @@ I suggest including a polyfill from [cdnjs.cloudflare.com/polyfill](https://cdnj **Polyfill example used for the demo:** ```html - + ``` **Features used in Choices:** @@ -1267,6 +1267,7 @@ CustomEvent Element.prototype.classList Element.prototype.closest Element.prototype.dataset +Element.prototype.replaceChildren ``` ## Development diff --git a/public/assets/scripts/choices.js b/public/assets/scripts/choices.js index 58b64185..79fcaa59 100644 --- a/public/assets/scripts/choices.js +++ b/public/assets/scripts/choices.js @@ -76,8 +76,27 @@ HIGHLIGHT_ITEM: 'HIGHLIGHT_ITEM', }; + var EventType = { + showDropdown: 'showDropdown', + hideDropdown: 'hideDropdown', + change: 'change', + choice: 'choice', + search: 'search', + addItem: 'addItem', + removeItem: 'removeItem', + highlightItem: 'highlightItem', + highlightChoice: 'highlightChoice', + unhighlightItem: 'unhighlightItem', + }; + var ObjectsInConfig = ['fuseOptions', 'classNames']; + var PassedElementTypes = { + Text: 'text', + SelectOne: 'select-one', + SelectMultiple: 'select-multiple', + }; + var addChoice = function (choice) { return ({ type: ActionType.ADD_CHOICE, choice: choice, @@ -109,7 +128,7 @@ type: ActionType.ADD_ITEM, item: item, }); }; - var removeItem = function (item) { return ({ + var removeItem$1 = function (item) { return ({ type: ActionType.REMOVE_ITEM, item: item, }); }; @@ -281,6 +300,14 @@ } return {}; }; + var updateClassList = function (item, add, remove) { + var _a, _b; + var itemEl = item.itemEl; + if (itemEl) { + (_a = itemEl.classList).remove.apply(_a, getClassNames(remove)); + (_b = itemEl.classList).add.apply(_b, getClassNames(add)); + } + }; var Dropdown = /** @class */ (function () { function Dropdown(_a) { @@ -290,16 +317,6 @@ this.type = type; this.isActive = false; } - Object.defineProperty(Dropdown.prototype, "distanceFromTopWindow", { - /** - * Bottom position of dropdown in viewport coordinates - */ - get: function () { - return this.element.getBoundingClientRect().bottom; - }, - enumerable: false, - configurable: true - }); /** * Show dropdown to user by adding active state class */ @@ -323,11 +340,6 @@ return Dropdown; }()); - var TEXT_TYPE = 'text'; - var SELECT_ONE_TYPE = 'select-one'; - var SELECT_MULTIPLE_TYPE = 'select-multiple'; - var SCROLLING_SPEED = 4; - var Container = /** @class */ (function () { function Container(_a) { var element = _a.element, type = _a.type, classNames = _a.classNames, position = _a.position; @@ -344,12 +356,14 @@ * Determine whether container should be flipped based on passed * dropdown position */ - Container.prototype.shouldFlip = function (dropdownPos) { + Container.prototype.shouldFlip = function (dropdownPos, dropdownHeight) { // If flip is enabled and the dropdown bottom position is // greater than the window height flip the dropdown. var shouldFlip = false; if (this.position === 'auto') { - shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)")).matches; + shouldFlip = + this.element.getBoundingClientRect().top - dropdownHeight >= 0 && + !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)")).matches; } else if (this.position === 'top') { shouldFlip = true; @@ -362,12 +376,12 @@ Container.prototype.removeActiveDescendant = function () { this.element.removeAttribute('aria-activedescendant'); }; - Container.prototype.open = function (dropdownPos) { + Container.prototype.open = function (dropdownPos, dropdownHeight) { var _a, _b; (_a = this.element.classList).add.apply(_a, getClassNames(this.classNames.openState)); this.element.setAttribute('aria-expanded', 'true'); this.isOpen = true; - if (this.shouldFlip(dropdownPos)) { + if (this.shouldFlip(dropdownPos, dropdownHeight)) { (_b = this.element.classList).add.apply(_b, getClassNames(this.classNames.flippedState)); this.isFlipped = true; } @@ -396,7 +410,7 @@ var _a; (_a = this.element.classList).remove.apply(_a, getClassNames(this.classNames.disabledState)); this.element.removeAttribute('aria-disabled'); - if (this.type === SELECT_ONE_TYPE) { + if (this.type === PassedElementTypes.SelectOne) { this.element.setAttribute('tabindex', '0'); } this.isDisabled = false; @@ -405,30 +419,32 @@ var _a; (_a = this.element.classList).add.apply(_a, getClassNames(this.classNames.disabledState)); this.element.setAttribute('aria-disabled', 'true'); - if (this.type === SELECT_ONE_TYPE) { + if (this.type === PassedElementTypes.SelectOne) { this.element.setAttribute('tabindex', '-1'); } this.isDisabled = true; }; Container.prototype.wrap = function (element) { + var el = this.element; var parentNode = element.parentNode; if (parentNode) { if (element.nextSibling) { - parentNode.insertBefore(this.element, element.nextSibling); + parentNode.insertBefore(el, element.nextSibling); } else { - parentNode.appendChild(this.element); + parentNode.appendChild(el); } } - this.element.appendChild(element); + el.appendChild(element); }; Container.prototype.unwrap = function (element) { - var parentNode = this.element.parentNode; + var el = this.element; + var parentNode = el.parentNode; if (parentNode) { // Move passed element outside this element - parentNode.insertBefore(element, this.element); + parentNode.insertBefore(element, el); // Remove this element - parentNode.removeChild(this.element); + parentNode.removeChild(el); } }; Container.prototype.addLoadingState = function () { @@ -531,9 +547,9 @@ */ Input.prototype.setWidth = function () { // Resize input to contents or placeholder - var _a = this.element, style = _a.style, value = _a.value, placeholder = _a.placeholder; - style.minWidth = "".concat(placeholder.length + 1, "ch"); - style.width = "".concat(value.length + 1, "ch"); + var element = this.element; + element.style.minWidth = "".concat(element.placeholder.length + 1, "ch"); + element.style.width = "".concat(element.value.length + 1, "ch"); }; Input.prototype.setActiveDescendant = function (activeDescendantID) { this.element.setAttribute('aria-activedescendant', activeDescendantID); @@ -542,7 +558,7 @@ this.element.removeAttribute('aria-activedescendant'); }; Input.prototype._onInput = function () { - if (this.type !== SELECT_ONE_TYPE) { + if (this.type !== PassedElementTypes.SelectOne) { this.setWidth(); } }; @@ -560,6 +576,8 @@ return Input; }()); + var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -567,9 +585,6 @@ this.scrollPos = this.element.scrollTop; this.height = this.element.offsetHeight; } - List.prototype.clear = function () { - this.element.innerHTML = ''; - }; List.prototype.prepend = function (node) { var child = this.element.firstElementChild; if (child) { @@ -701,15 +716,13 @@ el.removeAttribute('data-choice'); }; WrappedElement.prototype.enable = function () { - var element = this.element; - element.removeAttribute('disabled'); - element.disabled = false; + this.element.removeAttribute('disabled'); + this.element.disabled = false; this.isDisabled = false; }; WrappedElement.prototype.disable = function () { - var element = this.element; - element.setAttribute('disabled', ''); - element.disabled = true; + this.element.setAttribute('disabled', ''); + this.element.disabled = true; this.isDisabled = true; }; WrappedElement.prototype.triggerEvent = function (eventType, data) { @@ -843,7 +856,6 @@ option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -858,9 +870,9 @@ disabled: option.disabled, highlighted: false, placeholder: this.extractPlaceholder && (!option.value || option.hasAttribute('placeholder')), - labelClass: typeof dataset.labelClass !== 'undefined' ? stringToHtmlClass(dataset.labelClass) : undefined, - labelDescription: typeof dataset.labelDescription !== 'undefined' ? dataset.labelDescription : undefined, - customProperties: parseCustomProperties(dataset.customProperties), + labelClass: typeof option.dataset.labelClass !== 'undefined' ? stringToHtmlClass(option.dataset.labelClass) : undefined, + labelDescription: typeof option.dataset.labelDescription !== 'undefined' ? option.dataset.labelDescription : undefined, + customProperties: parseCustomProperties(option.dataset.customProperties), }; }; WrappedSelect.prototype._optgroupToChoice = function (optgroup) { @@ -968,51 +980,58 @@ appendGroupInSearch: false, }; - function items(s, action) { + var removeItem = function (item) { + var itemEl = item.itemEl; + if (itemEl) { + itemEl.remove(); + item.itemEl = undefined; + } + }; + function items(s, action, context) { var state = s; var update = true; switch (action.type) { case ActionType.ADD_ITEM: { - var item = action.item; - item.selected = true; - var el = item.element; + action.item.selected = true; + var el = action.item.element; if (el) { el.selected = true; el.setAttribute('selected', ''); } - state.push(item); - state.forEach(function (choice) { - choice.highlighted = false; - }); + state.push(action.item); break; } case ActionType.REMOVE_ITEM: { - var item_1 = action.item; - item_1.selected = false; - var el = item_1.element; + action.item.selected = false; + var el = action.item.element; if (el) { el.selected = false; el.removeAttribute('selected'); // For a select-one, if all options are deselected, the first item is selected. To set a black value, select.value needs to be set var select = el.parentElement; - if (select && isHtmlSelectElement(select) && select.type === SELECT_ONE_TYPE) { + if (select && isHtmlSelectElement(select) && select.type === PassedElementTypes.SelectOne) { select.value = ''; } } - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + // this is mixing concerns, but this is *so much faster* + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { - var highlightItemAction_1 = action; - state.forEach(function (choice) { - if (choice.id === highlightItemAction_1.item.id) { - choice.highlighted = highlightItemAction_1.highlighted; + var highlighted = action.highlighted; + var item = state.find(function (obj) { return obj.id === action.item.id; }); + if (item && item.highlighted !== highlighted) { + item.highlighted = highlighted; + if (context) { + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } - }); + } break; } default: { @@ -1044,7 +1063,7 @@ } /* eslint-disable */ - function choices(s, action) { + function choices(s, action, context) { var state = s; var update = true; switch (action.type) { @@ -1058,11 +1077,13 @@ break; } case ActionType.REMOVE_CHOICE: { + action.choice.choiceEl = undefined; state = state.filter(function (obj) { return obj.id !== action.choice.id; }); break; } case ActionType.ADD_ITEM: case ActionType.REMOVE_ITEM: { + action.item.choiceEl = undefined; break; } case ActionType.FILTER_CHOICES: { @@ -1083,12 +1104,18 @@ choice.rank = 0; choice.active = false; } + if (context && context.appendGroupInSearch) { + choice.choiceEl = undefined; + } }); break; } case ActionType.ACTIVATE_CHOICES: { state.forEach(function (choice) { choice.active = action.active; + if (context && context.appendGroupInSearch) { + choice.choiceEl = undefined; + } }); break; } @@ -1110,10 +1137,11 @@ choices: choices, }; var Store = /** @class */ (function () { - function Store() { + function Store(context) { this._state = this.defaultState; this._listeners = []; this._txn = 0; + this._context = context; } Object.defineProperty(Store.prototype, "defaultState", { // eslint-disable-next-line class-methods-use-this @@ -1149,11 +1177,12 @@ this._listeners.push(onChange); }; Store.prototype.dispatch = function (action) { + var _this = this; var state = this._state; var hasChanges = false; var changes = this._changeSet || this.changeSet(false); Object.keys(reducers).forEach(function (key) { - var stateUpdate = reducers[key](state[key], action); + var stateUpdate = reducers[key](state[key], action, _this._context); if (stateUpdate.update) { hasChanges = true; changes[key] = true; @@ -3055,25 +3084,23 @@ item: function (_a, choice, removeItemButton) { var _b, _c, _d; var allowHTML = _a.allowHTML, removeItemButtonAlignLeft = _a.removeItemButtonAlignLeft, removeItemIconText = _a.removeItemIconText, removeItemLabelText = _a.removeItemLabelText, _e = _a.classNames, item = _e.item, button = _e.button, highlightedState = _e.highlightedState, itemSelectable = _e.itemSelectable, placeholder = _e.placeholder; - var labelClass = choice.labelClass, label = choice.label, disabled = choice.disabled, value = choice.value; - var rawValue = unwrapStringForRaw(value); + var rawValue = unwrapStringForRaw(choice.value); var div = document.createElement('div'); div.className = getClassNames(item).join(' '); - if (labelClass) { + if (choice.labelClass) { var spanLabel = document.createElement('span'); - setElementHtml(spanLabel, allowHTML, label); - spanLabel.className = getClassNames(labelClass).join(' '); + setElementHtml(spanLabel, allowHTML, choice.label); + spanLabel.className = getClassNames(choice.labelClass).join(' '); div.appendChild(spanLabel); } else { - setElementHtml(div, allowHTML, label); + setElementHtml(div, allowHTML, choice.label); } - var dataset = div.dataset; - dataset.item = ''; - dataset.id = choice.id; - dataset.value = rawValue; + div.dataset.item = ''; + div.dataset.id = choice.id; + div.dataset.value = rawValue; assignCustomProperties(div, choice, true); - if (disabled || this.containerOuter.isDisabled) { + if (choice.disabled || this.containerOuter.isDisabled) { div.setAttribute('aria-disabled', 'true'); } if (this._isSelectElement) { @@ -3082,19 +3109,19 @@ } if (choice.placeholder) { (_b = div.classList).add.apply(_b, getClassNames(placeholder)); - dataset.placeholder = ''; + div.dataset.placeholder = ''; } (_c = div.classList).add.apply(_c, (choice.highlighted ? getClassNames(highlightedState) : getClassNames(itemSelectable))); if (removeItemButton) { - if (disabled) { + if (choice.disabled) { (_d = div.classList).remove.apply(_d, getClassNames(itemSelectable)); } - dataset.deletable = ''; + div.dataset.deletable = ''; var removeButton = document.createElement('button'); removeButton.type = 'button'; removeButton.className = getClassNames(button).join(' '); - setElementHtml(removeButton, true, resolveNoticeFunction(removeItemIconText, value)); - var REMOVE_ITEM_LABEL = resolveNoticeFunction(removeItemLabelText, value); + setElementHtml(removeButton, true, resolveNoticeFunction(removeItemIconText, choice.value)); + var REMOVE_ITEM_LABEL = resolveNoticeFunction(removeItemLabelText, choice.value); if (REMOVE_ITEM_LABEL) { removeButton.setAttribute('aria-label', REMOVE_ITEM_LABEL); } @@ -3125,43 +3152,49 @@ var div = document.createElement('div'); div.className = "".concat(getClassNames(group).join(' '), " ").concat(disabled ? getClassNames(itemDisabled).join(' ') : ''); div.setAttribute('role', 'group'); - var dataset = div.dataset; - dataset.group = ''; - dataset.id = id; - dataset.value = rawLabel; + div.dataset.group = ''; + div.dataset.id = id; + div.dataset.value = rawLabel; if (disabled) { div.setAttribute('aria-disabled', 'true'); } var heading = document.createElement('div'); heading.className = getClassNames(groupHeading).join(' '); - setElementHtml(heading, allowHTML, label); + setElementHtml(heading, allowHTML, label || ''); div.appendChild(heading); return div; }, - choice: function (_a, choice, selectText) { + choice: function (_a, choice, selectText, groupName) { var _b, _c, _d, _e, _f; var allowHTML = _a.allowHTML, _g = _a.classNames, item = _g.item, itemChoice = _g.itemChoice, itemSelectable = _g.itemSelectable, selectedState = _g.selectedState, itemDisabled = _g.itemDisabled, description = _g.description, placeholder = _g.placeholder; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, label = choice.label, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + // eslint-disable-next-line prefer-destructuring + var label = choice.label; + var rawValue = unwrapStringForRaw(choice.value); var div = document.createElement('div'); - div.id = elementId; + div.id = choice.elementId; div.className = "".concat(getClassNames(item).join(' '), " ").concat(getClassNames(itemChoice).join(' ')); + if (groupName && typeof label === 'string') { + label = escapeForTemplate(allowHTML, label); + label += " (".concat(groupName, ")"); + label = { trusted: label }; + div.dataset.groupId = "".concat(choice.groupId); + } var describedBy = div; - if (labelClass) { + if (choice.labelClass) { var spanLabel = document.createElement('span'); setElementHtml(spanLabel, allowHTML, label); - spanLabel.className = getClassNames(labelClass).join(' '); + spanLabel.className = getClassNames(choice.labelClass).join(' '); describedBy = spanLabel; div.appendChild(spanLabel); } else { setElementHtml(div, allowHTML, label); } - if (labelDescription) { - var descId = "".concat(elementId, "-description"); + if (choice.labelDescription) { + var descId = "".concat(choice.elementId, "-description"); describedBy.setAttribute('aria-describedby', descId); var spanDesc = document.createElement('span'); - setElementHtml(spanDesc, allowHTML, labelDescription); + setElementHtml(spanDesc, allowHTML, choice.labelDescription); spanDesc.id = descId; (_b = spanDesc.classList).add.apply(_b, getClassNames(description)); div.appendChild(spanDesc); @@ -3172,27 +3205,22 @@ if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - var showGroupId = groupId && groupId > 0; - div.setAttribute('role', showGroupId ? 'treeitem' : 'option'); - if (showGroupId) { - dataset.groupId = "".concat(groupId); - } - dataset.choice = ''; - dataset.id = choice.id; - dataset.value = rawValue; + div.setAttribute('role', choice.groupId ? 'treeitem' : 'option'); + div.dataset.choice = ''; + div.dataset.id = choice.id; + div.dataset.value = rawValue; if (selectText) { - dataset.selectText = selectText; + div.dataset.selectText = selectText; } assignCustomProperties(div, choice, false); if (choice.disabled) { (_e = div.classList).add.apply(_e, getClassNames(itemDisabled)); - dataset.choiceDisabled = ''; + div.dataset.choiceDisabled = ''; div.setAttribute('aria-disabled', 'true'); } else { (_f = div.classList).add.apply(_f, getClassNames(itemSelectable)); - dataset.choiceSelectable = ''; + div.dataset.choiceSelectable = ''; } return div; }, @@ -3243,9 +3271,8 @@ setElementHtml(notice, true, innerHTML); notice.className = classes.join(' '); if (type === NoticeTypes.addChoice) { - var dataset = notice.dataset; - dataset.choiceSelectable = ''; - dataset.choice = ''; + notice.dataset.choiceSelectable = ''; + notice.dataset.choice = ''; } return notice; }, @@ -3270,9 +3297,9 @@ if (!element) { return undefined; } - var id = element.dataset.id; - return id ? parseInt(id, 10) : undefined; + return element.dataset.id ? parseInt(element.dataset.id, 10) : undefined; }; + var selectableChoiceIdentifier = '[data-choice-selectable]'; /** * Choices * @author Josh Johnson @@ -3306,23 +3333,28 @@ } throw TypeError("Expected one of the following types text|select-one|select-multiple"); } - this._elementType = passedElement.type; - this._isTextElement = this._elementType === TEXT_TYPE; - if (this._isTextElement || config.maxItemCount !== 1) { + var elementType = passedElement.type; + var isText = elementType === PassedElementTypes.Text; + if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - this._elementType = SELECT_MULTIPLE_TYPE; - } - this._isSelectOneElement = this._elementType === SELECT_ONE_TYPE; - this._isSelectMultipleElement = this._elementType === SELECT_MULTIPLE_TYPE; - this._isSelectElement = this._isSelectOneElement || this._isSelectMultipleElement; - this._canAddUserChoices = (this._isTextElement && config.addItems) || (this._isSelectElement && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + elementType = PassedElementTypes.SelectMultiple; + } + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; + var isSelect = isSelectOne || isSelectMultiple; + this._elementType = elementType; + this._isTextElement = isText; + this._isSelectOneElement = isSelectOne; + this._isSelectMultipleElement = isSelectMultiple; + this._isSelectElement = isSelectOne || isSelectMultiple; + this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { - config.closeDropdownOnSelect = this._isTextElement || this._isSelectOneElement || config.singleModeForMultiSelect; + config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; } else { config.closeDropdownOnSelect = coerceBool(config.closeDropdownOnSelect); @@ -3356,9 +3388,9 @@ }); } this.initialised = false; - this._store = new Store(); + this._store = new Store(config); this._currentValue = ''; - config.searchEnabled = (!this._isTextElement && config.searchEnabled) || this._elementType === SELECT_MULTIPLE_TYPE; + config.searchEnabled = (!isText && config.searchEnabled) || isSelectMultiple; this._canSearch = config.searchEnabled; this._isScrollingOnIe = false; this._highlightPosition = 0; @@ -3369,9 +3401,9 @@ * setting direction in cases where it's explicitly set on passedElement * or when calculated direction is different from the document */ - this._direction = this.passedElement.dir; + this._direction = passedElement.dir; if (!this._direction) { - var elementDirection = window.getComputedStyle(this.passedElement.element).direction; + var elementDirection = window.getComputedStyle(passedElement).direction; var documentDirection = window.getComputedStyle(document.documentElement).direction; if (elementDirection !== documentDirection) { this._direction = elementDirection; @@ -3453,7 +3485,7 @@ this.initialisedOK = true; var callbackOnInit = this.config.callbackOnInit; // Run callback if it is a function - if (callbackOnInit && typeof callbackOnInit === 'function') { + if (typeof callbackOnInit === 'function') { callbackOnInit.call(this); } }; @@ -3472,28 +3504,24 @@ this.initialisedOK = undefined; }; Choices.prototype.enable = function () { - var _a = this, passedElement = _a.passedElement, containerOuter = _a.containerOuter; - if (passedElement.isDisabled) { - passedElement.enable(); + if (this.passedElement.isDisabled) { + this.passedElement.enable(); } - if (containerOuter.isDisabled) { + if (this.containerOuter.isDisabled) { this._addEventListeners(); this.input.enable(); - containerOuter.enable(); - this._render(); + this.containerOuter.enable(); } return this; }; Choices.prototype.disable = function () { - var _a = this, passedElement = _a.passedElement, containerOuter = _a.containerOuter; - if (!passedElement.isDisabled) { - passedElement.disable(); + if (!this.passedElement.isDisabled) { + this.passedElement.disable(); } - if (!containerOuter.isDisabled) { + if (!this.containerOuter.isDisabled) { this._removeEventListeners(); this.input.disable(); - containerOuter.disable(); - this._render(); + this.containerOuter.disable(); } return this; }; @@ -3502,13 +3530,13 @@ if (!item || !item.id) { return this; } - var choice = this._store.choices.find(function (c) { return c.id === item.id; }); + var choice = this._store.items.find(function (c) { return c.id === item.id; }); if (!choice || choice.highlighted) { return this; } this._store.dispatch(highlightItem(choice, true)); if (runEvent) { - this.passedElement.triggerEvent("highlightItem" /* EventType.highlightItem */, this._getChoiceForOutput(choice)); + this.passedElement.triggerEvent(EventType.highlightItem, this._getChoiceForOutput(choice)); } return this; }; @@ -3517,27 +3545,37 @@ if (!item || !item.id) { return this; } - var choice = this._store.choices.find(function (c) { return c.id === item.id; }); + var choice = this._store.items.find(function (c) { return c.id === item.id; }); if (!choice || !choice.highlighted) { return this; } this._store.dispatch(highlightItem(choice, false)); if (runEvent) { - this.passedElement.triggerEvent("highlightItem" /* EventType.highlightItem */, this._getChoiceForOutput(choice)); + this.passedElement.triggerEvent(EventType.highlightItem, this._getChoiceForOutput(choice)); } return this; }; Choices.prototype.highlightAll = function () { var _this = this; this._store.withTxn(function () { - _this._store.items.forEach(function (item) { return _this.highlightItem(item); }); + _this._store.items.forEach(function (item) { + if (!item.highlighted) { + _this._store.dispatch(highlightItem(item, true)); + _this.passedElement.triggerEvent(EventType.highlightItem, _this._getChoiceForOutput(item)); + } + }); }); return this; }; Choices.prototype.unhighlightAll = function () { var _this = this; this._store.withTxn(function () { - _this._store.items.forEach(function (item) { return _this.unhighlightItem(item); }); + _this._store.items.forEach(function (item) { + if (item.highlighted) { + _this._store.dispatch(highlightItem(item, false)); + _this.passedElement.triggerEvent(EventType.highlightItem, _this._getChoiceForOutput(item)); + } + }); }); return this; }; @@ -3580,11 +3618,12 @@ } requestAnimationFrame(function () { _this.dropdown.show(); - _this.containerOuter.open(_this.dropdown.distanceFromTopWindow); + var rect = _this.dropdown.element.getBoundingClientRect(); + _this.containerOuter.open(rect.bottom, rect.height); if (!preventInputFocus && _this._canSearch) { _this.input.focus(); } - _this.passedElement.triggerEvent("showDropdown" /* EventType.showDropdown */); + _this.passedElement.triggerEvent(EventType.showDropdown); }); return this; }; @@ -3600,7 +3639,7 @@ _this.input.removeActiveDescendant(); _this.input.blur(); } - _this.passedElement.triggerEvent("hideDropdown" /* EventType.hideDropdown */); + _this.passedElement.triggerEvent(EventType.hideDropdown); }); return this; }; @@ -3645,6 +3684,7 @@ var choiceValue = Array.isArray(value) ? value : [value]; // Loop through each value and choiceValue.forEach(function (val) { return _this._findAndSelectChoiceByValue(val); }); + _this.unhighlightAll(); }); // @todo integrate with Store this._searcher.reset(); @@ -3781,6 +3821,7 @@ _this._addChoice(mapInputToChoice(choice, false)); } }); + _this.unhighlightAll(); }); // @todo integrate with Store this._searcher.reset(); @@ -3799,11 +3840,10 @@ } this._store.withTxn(function () { var choicesFromOptions = _this.passedElement.optionsAsChoices(); - var items = _this._store.items; // Build the list of items which require preserving var existingItems = {}; if (!deselectAll) { - items.forEach(function (choice) { + _this._store.items.forEach(function (choice) { if (choice.id && choice.active && choice.selected && !choice.disabled) { existingItems[choice.value] = true; } @@ -3852,7 +3892,7 @@ // @todo integrate with Store this._searcher.reset(); if (choice.selected) { - this.passedElement.triggerEvent("removeItem" /* EventType.removeItem */, this._getChoiceForOutput(choice)); + this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(choice)); } return this; }; @@ -3911,199 +3951,173 @@ }; Choices.prototype._renderChoices = function () { var _this = this; - this.choiceList.clear(); if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var config = this.config; - var _a = this._store, activeGroups = _a.activeGroups, activeChoices = _a.activeChoices; - var choiceListFragment = document.createDocumentFragment(); - var noChoices = true; - if (activeChoices.length) { + var _a = this, config = _a.config, isSearching = _a._isSearching; + var renderLimit = 0; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; + } + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; + } + var groupLookup = []; + var appendGroupInSearch = config.appendGroupInSearch && isSearching; + if (appendGroupInSearch) { + this._store.activeGroups.forEach(function (group) { + if (group.label) { + groupLookup[group.id] = group.label; + } + }); + } + if (this._isSelectElement) { + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); + if (backingOptions.length) { + this.passedElement.addOptions(backingOptions); + } + } + var fragment = document.createDocumentFragment(); + var renderableChoices = function (choices) { + return choices.filter(function (choice) { + return !choice.placeholder && (isSearching ? !!choice.rank : config.renderSelectedChoices || !choice.selected); + }); + }; + var selectableChoices = this._isSelectOneElement; + var renderChoices = function (choices, withinGroup) { + if (isSearching) { + // sortByRank is used to ensure stable sorting, as scores are non-unique + // this additionally ensures fuseOptions.sortFn is not ignored + choices.sort(sortByRank); + } + else if (config.shouldSort) { + choices.sort(config.sorter); + } + var choiceLimit = choices.length; + choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; + choiceLimit--; + choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed + var dropdownItem = choice.choiceEl || + _this._templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + choice.choiceEl = dropdownItem; + fragment.appendChild(dropdownItem); + if (isSearching || !choice.selected) { + selectableChoices = true; + } + return index < choiceLimit; + }); + }; + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } + if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { + // If we have a placeholder choice along with groups + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + } // If we have grouped options - if (activeGroups.length && !this._isSearching) { - if (!this._hasNonChoicePlaceholder) { - // If we have a placeholder choice along with groups - var activePlaceholders = activeChoices.filter(function (activeChoice) { return activeChoice.placeholder && activeChoice.groupId === -1; }); - if (activePlaceholders.length) { - choiceListFragment = this._createChoicesFragment(activePlaceholders, choiceListFragment); - } + if (this._store.activeGroups.length && !isSearching) { + if (config.shouldSort) { + this._store.activeGroups.sort(config.sorter); } - choiceListFragment = this._createGroupsFragment(activeGroups, activeChoices, choiceListFragment); + this._store.activeGroups.forEach(function (group) { + var groupChoices = renderableChoices(group.choices); + if (groupChoices.length) { + if (group.label) { + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); + group.groupEl = dropdownGroup; + dropdownGroup.remove(); + fragment.appendChild(dropdownGroup); + } + renderChoices(groupChoices, true); + } + }); } else { - choiceListFragment = this._createChoicesFragment(activeChoices, choiceListFragment); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !choiceListFragment.childNodes.length; } var notice = this._notice; - if (noChoices) { + if (!selectableChoices) { if (!notice) { this._notice = { text: resolveStringFunction(config.noChoicesText), type: NoticeTypes.noChoices, }; } + fragment.replaceChildren(''); } else if (notice && notice.type === NoticeTypes.noChoices) { this._notice = undefined; } - this._renderNotice(); - if (!noChoices) { - this.choiceList.element.append(choiceListFragment); + this._renderNotice(fragment); + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; Choices.prototype._renderItems = function () { - var items = this._store.items || []; - this.itemList.clear(); - // Create a fragment to store our list items - // (so we don't have to update the DOM for each item) - var itemListFragment = this._createItemsFragment(items); - // If we have items to add, append them - if (itemListFragment.childNodes.length) { - this.itemList.element.append(itemListFragment); - } - }; - Choices.prototype._createGroupsFragment = function (groups, choices, fragment) { var _this = this; - if (fragment === void 0) { fragment = document.createDocumentFragment(); } + var items = this._store.items || []; + var itemList = this.itemList.element; var config = this.config; - var getGroupChoices = function (group) { - return choices.filter(function (choice) { - if (_this._isSelectOneElement) { - return choice.groupId === group.id; - } - return choice.groupId === group.id && (config.renderSelectedChoices === 'always' || !choice.selected); - }); + var fragment = document.createDocumentFragment(); + var itemFromList = function (item) { + return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); }; - // If sorting is enabled, filter groups - if (config.shouldSort) { - groups.sort(config.sorter); - } - // Add Choices without group first, regardless of sort, otherwise they won't be distinguishable - // from the last group - var choicesWithoutGroup = choices.filter(function (c) { return !c.groupId; }); - if (choicesWithoutGroup.length) { - this._createChoicesFragment(choicesWithoutGroup, fragment, false); - } - groups.forEach(function (group) { - var groupChoices = getGroupChoices(group); - if (groupChoices.length) { - var dropdownGroup = _this._templates.choiceGroup(_this.config, group); - fragment.appendChild(dropdownGroup); - _this._createChoicesFragment(groupChoices, fragment, true); - } - }); - return fragment; - }; - Choices.prototype._createChoicesFragment = function (choices, fragment, withinGroup) { - var _this = this; - if (fragment === void 0) { fragment = document.createDocumentFragment(); } - if (withinGroup === void 0) { withinGroup = false; } - // Create a fragment to store our list items (so we don't have to update the DOM for each item) - var _a = this, config = _a.config, isSearching = _a._isSearching, isSelectOneElement = _a._isSelectOneElement; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; - var groupLookup = []; - var appendGroupInSearch = config.appendGroupInSearch && isSearching; - if (appendGroupInSearch) { - this._store.groups.forEach(function (group) { - groupLookup[group.id] = group.label; - }); - } - if (this._isSelectElement) { - var backingOptions = choices.filter(function (choice) { return !choice.element; }); - if (backingOptions.length) { - this.passedElement.addOptions(backingOptions); - } - } - var skipSelected = config.renderSelectedChoices === 'auto' && !isSelectOneElement; - var placeholderChoices = []; - var normalChoices = []; - choices.forEach(function (choice) { - if ((isSearching && !choice.rank) || (skipSelected && choice.selected)) { + var addItemToFragment = function (item) { + var el = item.itemEl; + if (el && el.parentElement) { return; } - if (_this._hasNonChoicePlaceholder || !choice.placeholder) { - normalChoices.push(choice); + el = itemFromList(item) || _this._templates.item(config, item, config.removeItemButton); + item.itemEl = el; + fragment.appendChild(el); + }; + // new items + items.forEach(addItemToFragment); + var addItems = !!fragment.childNodes.length; + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { + var existingItems = itemList.children.length; + if (addItems || existingItems > 1) { + var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); + if (placeholder) { + placeholder.remove(); + } } - else { - placeholderChoices.push(choice); + else if (!existingItems) { + addItems = true; + addItemToFragment(mapInputToChoice({ + selected: true, + value: '', + label: config.placeholderValue || '', + placeholder: true, + }, false)); } - }); - if (isSearching) { - // sortByRank is used to ensure stable sorting, as scores are non-unique - // this additionally ensures fuseOptions.sortFn is not ignored - normalChoices.sort(sortByRank); - } - else if (config.shouldSort) { - normalChoices.sort(config.sorter); - } - var sortedChoices = isSelectOneElement && placeholderChoices.length ? __spreadArray(__spreadArray([], placeholderChoices, true), normalChoices, true) : normalChoices; - var choiceLimit = sortedChoices.length; - var limit = choiceLimit; - if (isSearching && searchResultLimit > 0) { - limit = searchResultLimit; - } - else if (renderChoiceLimit > 0 && !withinGroup) { - limit = renderChoiceLimit; - } - if (limit < choiceLimit) { - choiceLimit = limit; - } - choiceLimit--; - // Add each choice to dropdown within range - sortedChoices.every(function (choice, index) { - var dropdownItem = _this._templates.choice(config, choice, config.itemSelectText); - if (appendGroupInSearch && choice.groupId > 0) { - var groupName = groupLookup[choice.groupId]; - if (groupName) { - dropdownItem.innerHTML += " (".concat(groupName, ")"); - } + } + if (addItems) { + itemList.append(fragment); + if (config.shouldSortItems && !this._isSelectOneElement) { + items.sort(config.sorter); + // push sorting into the DOM + items.forEach(function (item) { + var el = itemFromList(item); + if (el) { + el.remove(); + fragment.append(el); + } + }); + itemList.append(fragment); } - fragment.appendChild(dropdownItem); - return index < choiceLimit; - }); - return fragment; - }; - Choices.prototype._createItemsFragment = function (items, fragment) { - var _this = this; - if (fragment === void 0) { fragment = document.createDocumentFragment(); } - // Create fragment to add elements to - var config = this.config; - var shouldSortItems = config.shouldSortItems, sorter = config.sorter, removeItemButton = config.removeItemButton, delimiter = config.delimiter; - // If sorting is enabled, filter items - if (shouldSortItems && !this._isSelectOneElement) { - items.sort(sorter); } if (this._isTextElement) { // Update the value of the hidden input this.passedElement.value = items.map(function (_a) { var value = _a.value; return value; - }).join(delimiter); + }).join(config.delimiter); } - var addItemToFragment = function (item) { - // Create new list element - var listItem = _this._templates.item(config, item, removeItemButton); - // Append it to list - fragment.appendChild(listItem); - }; - // Add each list item to list - items.forEach(addItemToFragment); - if (this._isSelectOneElement && this._hasNonChoicePlaceholder && !items.length) { - addItemToFragment(mapInputToChoice({ - selected: true, - value: '', - label: this.config.placeholderValue || '', - active: true, - placeholder: true, - }, false)); - } - return fragment; }; Choices.prototype._displayNotice = function (text, type, openDropdown) { if (openDropdown === void 0) { openDropdown = true; } @@ -4139,18 +4153,23 @@ } this._notice = undefined; }; - Choices.prototype._renderNotice = function () { + Choices.prototype._renderNotice = function (fragment) { var noticeConf = this._notice; if (noticeConf) { var notice = this._templates.notice(this.config, noticeConf.text, noticeConf.type); - this.choiceList.prepend(notice); + if (fragment) { + fragment.append(notice); + } + else { + this.choiceList.prepend(notice); + } } }; Choices.prototype._getChoiceForOutput = function (choice, keyCode) { if (!choice) { return undefined; } - var group = choice.groupId > 0 ? this._store.getGroupById(choice.groupId) : null; + var group = choice.groupId ? this._store.getGroupById(choice.groupId) : null; return { id: choice.id, highlighted: choice.highlighted, @@ -4171,11 +4190,12 @@ if (value === undefined || value === null) { return; } - this.passedElement.triggerEvent("change" /* EventType.change */, { + this.passedElement.triggerEvent(EventType.change, { value: value, }); }; Choices.prototype._handleButtonAction = function (element) { + var _this = this; var items = this._store.items; if (!items.length || !this.config.removeItems || !this.config.removeItemButton) { return; @@ -4185,18 +4205,23 @@ if (!itemToRemove) { return; } - // Remove item associated with button - this._removeItem(itemToRemove); - this._triggerChange(itemToRemove.value); - if (this._isSelectOneElement && !this._hasNonChoicePlaceholder) { - var placeholderChoice = this._store.choices.reverse().find(function (choice) { return !choice.disabled && choice.placeholder; }); - if (placeholderChoice) { - this._addItem(placeholderChoice); - if (placeholderChoice.value) { - this._triggerChange(placeholderChoice.value); + this._store.withTxn(function () { + // Remove item associated with button + _this._removeItem(itemToRemove); + _this._triggerChange(itemToRemove.value); + if (_this._isSelectOneElement && !_this._hasNonChoicePlaceholder) { + var placeholderChoice = _this._store.choices + .reverse() + .find(function (choice) { return !choice.disabled && choice.placeholder; }); + if (placeholderChoice) { + _this._addItem(placeholderChoice); + _this.unhighlightAll(); + if (placeholderChoice.value) { + _this._triggerChange(placeholderChoice.value); + } } } - } + }); }; Choices.prototype._handleItemAction = function (element, hasShiftKey) { var _this = this; @@ -4281,9 +4306,8 @@ // Assign preset items from passed object first this._presetChoices = config.items.map(function (e) { return mapInputToChoice(e, false); }); // Add any values passed from attribute - var value = this.passedElement.value; - if (value) { - var elementItems = value + if (this.passedElement.value) { + var elementItems = this.passedElement.value .split(config.delimiter) .map(function (e) { return mapInputToChoice(e, false); }); this._presetChoices = this._presetChoices.concat(elementItems); @@ -4304,22 +4328,25 @@ }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var config = this.config; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); if (this._isSelectOneElement) { - this.itemList.clear(); - this.itemList.element.append(this._templates.placeholder(config, config.loadingText)); + el.replaceChildren(this._templates.placeholder(this.config, this.config.loadingText)); } else { - this.input.placeholder = config.loadingText; + this.input.placeholder = this.config.loadingText; } } else { this.enable(); this.containerOuter.removeLoadingState(); - if (!this._isSelectOneElement) { + if (this._isSelectOneElement) { + el.replaceChildren(''); + this._render(); + } + else { this.input.placeholder = this._placeholderValue || ''; } } @@ -4328,21 +4355,18 @@ if (!this.input.isFocussed) { return; } - var choices = this._store.choices; - var _a = this.config, searchFloor = _a.searchFloor, searchChoices = _a.searchChoices; - var hasUnactiveChoices = choices.some(function (option) { return !option.active; }); // Check that we have a value to search and the input was an alphanumeric character - if (value !== null && typeof value !== 'undefined' && value.length >= searchFloor) { - var resultCount = searchChoices ? this._searchChoices(value) : 0; + if (value !== null && typeof value !== 'undefined' && value.length >= this.config.searchFloor) { + var resultCount = this.config.searchChoices ? this._searchChoices(value) : 0; if (resultCount !== null) { // Trigger search event - this.passedElement.triggerEvent("search" /* EventType.search */, { + this.passedElement.triggerEvent(EventType.search, { value: value, resultCount: resultCount, }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -4350,6 +4374,7 @@ var config = this.config; var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -4421,7 +4446,7 @@ this._isSearching = false; if (wasSearching) { this._store.dispatch(activateChoices(true)); - this.passedElement.triggerEvent("search" /* EventType.search */, { + this.passedElement.triggerEvent(EventType.search, { value: '', resultCount: 0, }); @@ -4592,10 +4617,8 @@ } }; Choices.prototype._onSelectKey = function (event, hasItems) { - var ctrlKey = event.ctrlKey, metaKey = event.metaKey; - var hasCtrlDownKeyPressed = ctrlKey || metaKey; // If CTRL + A or CMD + A have been pressed and there are items to select - if (hasCtrlDownKeyPressed && hasItems) { + if ((event.ctrlKey || event.metaKey) && hasItems) { this._canSearch = false; var shouldHightlightAll = this.config.removeItems && !this.input.value && this.input.element === document.activeElement; if (shouldHightlightAll) { @@ -4605,12 +4628,10 @@ }; Choices.prototype._onEnterKey = function (event, hasActiveDropdown) { var _this = this; - var config = this.config; var value = this.input.value; var target = event.target; - var targetWasRemoveButton = target && target.hasAttribute('data-button'); event.preventDefault(); - if (targetWasRemoveButton) { + if (target && target.hasAttribute('data-button')) { this._handleButtonAction(target); return; } @@ -4620,7 +4641,7 @@ } return; } - var highlightedChoice = this.dropdown.element.querySelector(getClassNamesSelector(config.classNames.highlightedState)); + var highlightedChoice = this.dropdown.element.querySelector(getClassNamesSelector(this.config.classNames.highlightedState)); if (highlightedChoice && this._handleChoiceAction(highlightedChoice)) { return; } @@ -4642,7 +4663,7 @@ return; } var sanitisedValue = sanitise(value); - var userValue = config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value }; + var userValue = _this.config.allowHtmlUserInput || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value }; _this._addChoice(mapInputToChoice({ value: userValue, label: userValue, @@ -4657,7 +4678,7 @@ return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -4669,14 +4690,13 @@ } }; Choices.prototype._onDirectionKey = function (event, hasActiveDropdown) { - var keyCode = event.keyCode, metaKey = event.metaKey; + var keyCode = event.keyCode; // If up or down key is pressed, traverse through options if (hasActiveDropdown || this._isSelectOneElement) { this.showDropdown(); this._canSearch = false; var directionInt = keyCode === 40 /* KeyCodeMap.DOWN_KEY */ || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ ? 1 : -1; - var skipKey = metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */; - var selectableChoiceIdentifier = '[data-choice-selectable]'; + var skipKey = event.metaKey || keyCode === 34 /* KeyCodeMap.PAGE_DOWN_KEY */ || keyCode === 33 /* KeyCodeMap.PAGE_UP_KEY */; var nextEl = void 0; if (skipKey) { if (directionInt > 0) { @@ -4709,9 +4729,8 @@ } }; Choices.prototype._onDeleteKey = function (event, items, hasFocusedInput) { - var target = event.target; // If backspace or delete key is pressed and the input has no value - if (!this._isSelectOneElement && !target.value && hasFocusedInput) { + if (!this._isSelectOneElement && !event.target.value && hasFocusedInput) { this._handleBackspace(items); event.preventDefault(); } @@ -4759,15 +4778,13 @@ } var item = target.closest('[data-button],[data-item],[data-choice]'); if (item instanceof HTMLElement) { - var hasShiftKey = event.shiftKey; - var dataset = item.dataset; - if ('button' in dataset) { + if ('button' in item.dataset) { this._handleButtonAction(item); } - else if ('item' in dataset) { - this._handleItemAction(item, hasShiftKey); + else if ('item' in item.dataset) { + this._handleItemAction(item, event.shiftKey); } - else if ('choice' in dataset) { + else if ('choice' in item.dataset) { this._handleChoiceAction(item); } } @@ -4788,7 +4805,7 @@ var containerOuter = this.containerOuter; var clickWasWithinContainer = containerOuter.element.contains(target); if (clickWasWithinContainer) { - if (!this.dropdown.isActive && !this.containerOuter.isDisabled) { + if (!this.dropdown.isActive && !containerOuter.isDisabled) { if (this._isTextElement) { if (document.activeElement !== this.input.element) { this.input.focus(); @@ -4806,17 +4823,12 @@ } } else { - var hasHighlightedItems = !!this._store.highlightedActiveItems.length; - if (hasHighlightedItems) { - this.unhighlightAll(); - } containerOuter.removeFocusState(); this.hideDropdown(true); + this.unhighlightAll(); } }; Choices.prototype._onFocus = function (_a) { - var _b; - var _this = this; var target = _a.target; var containerOuter = this.containerOuter; var focusWasWithinContainer = target && containerOuter.element.contains(target); @@ -4824,66 +4836,45 @@ return; } var targetIsInput = target === this.input.element; - var focusActions = (_b = {}, - _b[TEXT_TYPE] = function () { - if (targetIsInput) { - containerOuter.addFocusState(); - } - }, - _b[SELECT_ONE_TYPE] = function () { + if (this._isTextElement) { + if (targetIsInput) { containerOuter.addFocusState(); - if (targetIsInput) { - _this.showDropdown(true); - } - }, - _b[SELECT_MULTIPLE_TYPE] = function () { - if (targetIsInput) { - _this.showDropdown(true); - // If element is a select box, the focused element is the container and the dropdown - // isn't already open, focus and show dropdown - containerOuter.addFocusState(); - } - }, - _b); - focusActions[this._elementType](); + } + } + else if (this._isSelectMultipleElement) { + if (targetIsInput) { + this.showDropdown(true); + // If element is a select box, the focused element is the container and the dropdown + // isn't already open, focus and show dropdown + containerOuter.addFocusState(); + } + } + else { + containerOuter.addFocusState(); + if (targetIsInput) { + this.showDropdown(true); + } + } }; Choices.prototype._onBlur = function (_a) { - var _b; - var _this = this; var target = _a.target; var containerOuter = this.containerOuter; var blurWasWithinContainer = target && containerOuter.element.contains(target); if (blurWasWithinContainer && !this._isScrollingOnIe) { - var activeChoices = this._store.activeChoices; - var hasHighlightedItems_1 = activeChoices.some(function (item) { return item.highlighted; }); - var targetIsInput_1 = target === this.input.element; - var blurActions = (_b = {}, - _b[TEXT_TYPE] = function () { - if (targetIsInput_1) { - containerOuter.removeFocusState(); - if (hasHighlightedItems_1) { - _this.unhighlightAll(); - } - _this.hideDropdown(true); - } - }, - _b[SELECT_ONE_TYPE] = function () { + var targetIsInput = target === this.input.element; + if (this._isTextElement || this._isSelectMultipleElement) { + if (targetIsInput) { containerOuter.removeFocusState(); - if (targetIsInput_1 || (target === containerOuter.element && !_this._canSearch)) { - _this.hideDropdown(true); - } - }, - _b[SELECT_MULTIPLE_TYPE] = function () { - if (targetIsInput_1) { - containerOuter.removeFocusState(); - _this.hideDropdown(true); - if (hasHighlightedItems_1) { - _this.unhighlightAll(); - } - } - }, - _b); - blurActions[this._elementType](); + this.hideDropdown(true); + this.unhighlightAll(); + } + } + else { + containerOuter.removeFocusState(); + if (targetIsInput || (target === containerOuter.element && !this._canSearch)) { + this.hideDropdown(true); + } + } } else { // On IE11, clicking the scollbar blurs our input and thus @@ -4907,17 +4898,17 @@ Choices.prototype._highlightChoice = function (el) { var _a; if (el === void 0) { el = null; } - var highlightedState = this.config.classNames.highlightedState; - var choices = Array.from(this.dropdown.element.querySelectorAll('[data-choice-selectable]')); + var choices = Array.from(this.dropdown.element.querySelectorAll(selectableChoiceIdentifier)); if (!choices.length) { return; } var passedEl = el; + var highlightedState = getClassNames(this.config.classNames.highlightedState); var highlightedChoices = Array.from(this.dropdown.element.querySelectorAll(getClassNamesSelector(highlightedState))); // Remove any highlighted choices highlightedChoices.forEach(function (choice) { var _a; - (_a = choice.classList).remove.apply(_a, getClassNames(highlightedState)); + (_a = choice.classList).remove.apply(_a, highlightedState); choice.setAttribute('aria-selected', 'false'); }); if (passedEl) { @@ -4937,9 +4928,9 @@ passedEl = choices[0]; } } - (_a = passedEl.classList).add.apply(_a, getClassNames(highlightedState)); + (_a = passedEl.classList).add.apply(_a, highlightedState); passedEl.setAttribute('aria-selected', 'true'); - this.passedElement.triggerEvent("highlightChoice" /* EventType.highlightChoice */, { + this.passedElement.triggerEvent(EventType.highlightChoice, { el: passedEl, }); if (this.dropdown.isActive) { @@ -4952,28 +4943,26 @@ Choices.prototype._addItem = function (item, withEvents, userTriggered) { if (withEvents === void 0) { withEvents = true; } if (userTriggered === void 0) { userTriggered = false; } - var id = item.id; - if (!id) { + if (!item.id) { throw new TypeError('item.id must be set before _addItem is called for a choice/item'); } if (this.config.singleModeForMultiSelect || this._isSelectOneElement) { - this.removeActiveItems(id); + this.removeActiveItems(item.id); } this._store.dispatch(addItem(item)); if (withEvents) { - this.passedElement.triggerEvent("addItem" /* EventType.addItem */, this._getChoiceForOutput(item)); + this.passedElement.triggerEvent(EventType.addItem, this._getChoiceForOutput(item)); if (userTriggered) { - this.passedElement.triggerEvent("choice" /* EventType.choice */, this._getChoiceForOutput(item)); + this.passedElement.triggerEvent(EventType.choice, this._getChoiceForOutput(item)); } } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } - this._store.dispatch(removeItem(item)); - this.passedElement.triggerEvent("removeItem" /* EventType.removeItem */, this._getChoiceForOutput(item)); + this._store.dispatch(removeItem$1(item)); + this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item)); }; Choices.prototype._addChoice = function (choice, withEvents, userTriggered) { if (withEvents === void 0) { withEvents = true; } @@ -5011,13 +5000,10 @@ return; } // add unique id for the group(s), and do not store the full list of choices in this group - var g = group; this._lastAddedGroupId++; - g.id = this._lastAddedGroupId; - var id = group.id, choices = group.choices; - g.choices = []; - choices.forEach(function (item) { - item.groupId = id; + group.id = this._lastAddedGroupId; + group.choices.forEach(function (item) { + item.groupId = group.id; if (group.disabled) { item.disabled = true; } @@ -5028,7 +5014,7 @@ var _this = this; var callbackOnCreateTemplates = this.config.callbackOnCreateTemplates; var userTemplates = {}; - if (callbackOnCreateTemplates && typeof callbackOnCreateTemplates === 'function') { + if (typeof callbackOnCreateTemplates === 'function') { userTemplates = callbackOnCreateTemplates.call(this, strToEl, escapeForTemplate); } var templating = {}; @@ -5044,11 +5030,11 @@ }; Choices.prototype._createElements = function () { var templating = this._templates; - var config = this.config; + var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; var position = config.position, classNames = config.classNames; var elementType = this._elementType; this.containerOuter = new Container({ - element: templating.containerOuter(config, this._direction, this._isSelectElement, this._isSelectOneElement, config.searchEnabled, elementType, config.labelId), + element: templating.containerOuter(config, this._direction, this._isSelectElement, isSelectOneElement, config.searchEnabled, elementType, config.labelId), classNames: classNames, type: elementType, position: position, @@ -5066,10 +5052,10 @@ preventPaste: !config.paste, }); this.choiceList = new List({ - element: templating.choiceList(config, this._isSelectOneElement), + element: templating.choiceList(config, isSelectOneElement), }); this.itemList = new List({ - element: templating.itemList(config, this._isSelectOneElement), + element: templating.itemList(config, isSelectOneElement), }); this.dropdown = new Dropdown({ element: templating.dropdown(config), @@ -5078,7 +5064,8 @@ }); }; Choices.prototype._createStructure = function () { - var _a = this, containerInner = _a.containerInner, containerOuter = _a.containerOuter, passedElement = _a.passedElement, dropdown = _a.dropdown, input = _a.input; + var _a = this, containerInner = _a.containerInner, containerOuter = _a.containerOuter, passedElement = _a.passedElement; + var dropdownElement = this.dropdown.element; // Hide original element passedElement.conceal(); // Wrap input in container preserving DOM ordering @@ -5086,23 +5073,23 @@ // Wrapper inner container with outer container containerOuter.wrap(containerInner.element); if (this._isSelectOneElement) { - input.placeholder = this.config.searchPlaceholderValue || ''; + this.input.placeholder = this.config.searchPlaceholderValue || ''; } else { if (this._placeholderValue) { - input.placeholder = this._placeholderValue; + this.input.placeholder = this._placeholderValue; } - input.setWidth(); + this.input.setWidth(); } containerOuter.element.appendChild(containerInner.element); - containerOuter.element.appendChild(dropdown.element); + containerOuter.element.appendChild(dropdownElement); containerInner.element.appendChild(this.itemList.element); - dropdown.element.appendChild(this.choiceList.element); + dropdownElement.appendChild(this.choiceList.element); if (!this._isSelectOneElement) { - containerInner.element.appendChild(input.element); + containerInner.element.appendChild(this.input.element); } else if (this.config.searchEnabled) { - dropdown.element.insertBefore(input.element, dropdown.element.firstChild); + dropdownElement.insertBefore(this.input.element, dropdownElement.firstChild); } this._highlightPosition = 0; this._isSearching = false; @@ -5153,9 +5140,8 @@ Choices.prototype._findAndSelectChoiceByValue = function (value, userTriggered) { var _this = this; if (userTriggered === void 0) { userTriggered = false; } - var choices = this._store.choices; // Check 'value' property exists and the choice isn't already selected - var foundChoice = choices.find(function (choice) { return _this.config.valueComparer(choice.value, value); }); + var foundChoice = this._store.choices.find(function (choice) { return _this.config.valueComparer(choice.value, value); }); if (foundChoice && !foundChoice.disabled && !foundChoice.selected) { this._addItem(foundChoice, true, userTriggered); return true; diff --git a/public/assets/scripts/choices.min.js b/public/assets/scripts/choices.min.js index ce495560..cdd882f8 100644 --- a/public/assets/scripts/choices.min.js +++ b/public/assets/scripts/choices.min.js @@ -1,2 +1,2 @@ /*! choices.js v11.0.0-rc8 | © 2024 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Choices=t()}(this,(function(){"use strict";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};function t(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,i=1,n=arguments.length;i/g,">").replace(/0?this.element.scrollTop+(e.offsetTop+e.offsetHeight)-(this.element.scrollTop+this.element.offsetHeight):e.offsetTop;requestAnimationFrame((function(){i._animateScroll(n,t)}))}},e.prototype._scrollDown=function(e,t,i){var n=(i-e)/t;this.element.scrollTop=e+(n>1?n:1)},e.prototype._scrollUp=function(e,t,i){var n=(e-i)/t;this.element.scrollTop=e-(n>1?n:1)},e.prototype._animateScroll=function(e,t){var i=this,n=this.element.scrollTop,s=!1;t>0?(this._scrollDown(n,4,e),ne&&(s=!0)),s&&requestAnimationFrame((function(){i._animateScroll(e,t)}))},e}(),D=function(){function e(e){var t=e.classNames;this.element=e.element,this.classNames=t,this.isDisabled=!1}return Object.defineProperty(e.prototype,"isActive",{get:function(){return"active"===this.element.dataset.choice},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dir",{get:function(){return this.element.dir},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.setAttribute("value",e),this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.conceal=function(){var e,t=this.element;(e=t.classList).add.apply(e,I(this.classNames.input)),t.hidden=!0,t.tabIndex=-1;var i=t.getAttribute("style");i&&t.setAttribute("data-choice-orig-style",i),t.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e,t=this.element;(e=t.classList).remove.apply(e,I(this.classNames.input)),t.hidden=!1,t.removeAttribute("tabindex");var i=t.getAttribute("data-choice-orig-style");i?(t.removeAttribute("data-choice-orig-style"),t.setAttribute("style",i)):t.removeAttribute("style"),t.removeAttribute("data-choice")},e.prototype.enable=function(){var e=this.element;e.removeAttribute("disabled"),e.disabled=!1,this.isDisabled=!1},e.prototype.disable=function(){var e=this.element;e.setAttribute("disabled",""),e.disabled=!0,this.isDisabled=!0},e.prototype.triggerEvent=function(e,t){var i;void 0===(i=t||{})&&(i=null),this.element.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0}))},e}(),P=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(D),j=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},R=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},K=function(e,t){if("string"==typeof e)return K({value:e,label:e},!1);var i=e;if("choices"in i){if(!t)throw new TypeError("optGroup is not allowed");var n=i,s=n.choices.map((function(e){return K(e,!1)}));return{id:0,label:E(n.label)||n.value,active:!!s.length,disabled:!!n.disabled,choices:s}}var o=i;return{id:0,groupId:0,score:0,rank:0,value:o.value,label:o.label||o.value,active:j(o.active),selected:j(o.selected,!1),disabled:j(o.disabled,!1),placeholder:j(o.placeholder,!1),highlighted:!1,labelClass:R(o.labelClass),labelDescription:o.labelDescription,customProperties:o.customProperties}},B=function(e){return"SELECT"===e.tagName},H=function(e){function i(t){var i=t.template,n=t.extractPlaceholder,s=e.call(this,{element:t.element,classNames:t.classNames})||this;return s.template=i,s.extractPlaceholder=n,s}return t(i,e),Object.defineProperty(i.prototype,"placeholderOption",{get:function(){return this.element.querySelector('option[value=""]')||this.element.querySelector("option[placeholder]")},enumerable:!1,configurable:!0}),i.prototype.addOptions=function(e){var t=this,i=document.createDocumentFragment();e.forEach((function(e){var n=e;if(!n.element){var s=t.template(n);i.appendChild(s),n.element=s}})),this.element.appendChild(i)},i.prototype.optionsAsChoices=function(){var e=this,t=[];return this.element.querySelectorAll(":scope > option, :scope > optgroup").forEach((function(i){!function(e){return"OPTION"===e.tagName}(i)?function(e){return"OPTGROUP"===e.tagName}(i)&&t.push(e._optgroupToChoice(i)):t.push(e._optionToChoice(i))})),t},i.prototype._optionToChoice=function(e){!e.hasAttribute("value")&&e.hasAttribute("placeholder")&&(e.setAttribute("value",""),e.value="");var t=e.dataset;return{id:0,groupId:0,score:0,rank:0,value:e.value,label:e.innerHTML,element:e,active:!0,selected:this.extractPlaceholder?e.selected:e.hasAttribute("selected"),disabled:e.disabled,highlighted:!1,placeholder:this.extractPlaceholder&&(!e.value||e.hasAttribute("placeholder")),labelClass:void 0!==t.labelClass?R(t.labelClass):void 0,labelDescription:void 0!==t.labelDescription?t.labelDescription:void 0,customProperties:x(t.customProperties)}},i.prototype._optgroupToChoice=function(e){var t=this,i=e.querySelectorAll("option"),n=Array.from(i).map((function(e){return t._optionToChoice(e)}));return{id:0,label:e.label||"",element:e,active:!!n.length,disabled:e.disabled,choices:n}},i}(D),V={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,closeDropdownOnSelect:"auto",singleModeForMultiSelect:!1,addChoices:!1,addItems:!0,addItemFilter:function(e){return!!e&&""!==e},removeItems:!0,removeItemButton:!1,removeItemButtonAlignLeft:!1,editItems:!1,allowHTML:!1,allowHtmlUserInput:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sorter:function(e,t){var i=e.label,n=t.label,s=void 0===n?t.value:n;return E(void 0===i?e.value:i).localeCompare(E(s),[],{sensitivity:"base",ignorePunctuation:!0,numeric:!0})},shadowRoot:null,placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add "'.concat(e,'"')},removeItemIconText:function(){return"Remove item"},removeItemLabelText:function(e){return"Remove item: ".concat(e)},maxItemText:function(e){return"Only ".concat(e," values can be added")},valueComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},labelId:"",callbackOnInit:null,callbackOnCreateTemplates:null,classNames:{containerOuter:["choices"],containerInner:["choices__inner"],input:["choices__input"],inputCloned:["choices__input--cloned"],list:["choices__list"],listItems:["choices__list--multiple"],listSingle:["choices__list--single"],listDropdown:["choices__list--dropdown"],item:["choices__item"],itemSelectable:["choices__item--selectable"],itemDisabled:["choices__item--disabled"],itemChoice:["choices__item--choice"],description:["choices__description"],placeholder:["choices__placeholder"],group:["choices__group"],groupHeading:["choices__heading"],button:["choices__button"],activeState:["is-active"],focusState:["is-focused"],openState:["is-open"],disabledState:["is-disabled"],highlightedState:["is-highlighted"],selectedState:["is-selected"],flippedState:["is-flipped"],loadingState:["is-loading"],notice:["choices__notice"],addChoice:["choices__item--selectable","add-choice"],noResults:["has-no-results"],noChoices:["has-no-choices"]},appendGroupInSearch:!1},$={groups:function(e,t){var i=e,n=!0;switch(t.type){case l:i.push(t.group);break;case h:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t){var i=e,n=!0;switch(t.type){case u:var s=t.item;s.selected=!0,(o=s.element)&&(o.selected=!0,o.setAttribute("selected","")),i.push(s),i.forEach((function(e){e.highlighted=!1}));break;case d:var o,a=t.item;if(a.selected=!1,o=a.element){o.selected=!1,o.removeAttribute("selected");var c=o.parentElement;c&&B(c)&&c.type===M&&(c.value="")}i=i.filter((function(e){return e.id!==a.id}));break;case r:i=i.filter((function(e){return e.id!==t.choice.id}));break;case p:var h=t;i.forEach((function(e){e.id===h.item.id&&(e.highlighted=h.highlighted)}));break;default:n=!1}return{state:i,update:n}},choices:function(e,t){var i=e,n=!0;switch(t.type){case o:i.push(t.choice);break;case r:i=i.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:break;case a:var s=[];t.results.forEach((function(e){s[e.item.id]=e})),i.forEach((function(e){var t=s[e.id];void 0!==t?(e.score=t.score,e.rank=t.rank,e.active=!0):(e.score=0,e.rank=0,e.active=!1)}));break;case c:i.forEach((function(e){e.active=t.active}));break;case h:i=[];break;default:n=!1}return{state:i,update:n}}},q=function(){function e(){this._state=this.defaultState,this._listeners=[],this._txn=0}return Object.defineProperty(e.prototype,"defaultState",{get:function(){return{groups:[],items:[],choices:[]}},enumerable:!1,configurable:!0}),e.prototype.changeSet=function(e){return{groups:e,items:e,choices:e}},e.prototype.reset=function(){this._state=this.defaultState;var e=this.changeSet(!0);this._txn?this._changeSet=e:this._listeners.forEach((function(t){return t(e)}))},e.prototype.subscribe=function(e){this._listeners.push(e)},e.prototype.dispatch=function(e){var t=this._state,i=!1,n=this._changeSet||this.changeSet(!1);Object.keys($).forEach((function(s){var o=$[s](t[s],e);o.update&&(i=!0,n[s]=!0,t[s]=o.state)})),i&&(this._txn?this._changeSet=n:this._listeners.forEach((function(e){return e(n)})))},e.prototype.withTxn=function(e){this._txn++;try{e()}finally{if(this._txn=Math.max(0,this._txn-1),!this._txn){var t=this._changeSet;t&&(this._changeSet=void 0,this._listeners.forEach((function(e){return e(t)})))}}},Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"items",{get:function(){return this.state.items},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"highlightedActiveItems",{get:function(){return this.items.filter((function(e){return!e.disabled&&e.active&&e.highlighted}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"choices",{get:function(){return this.state.choices},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeChoices",{get:function(){return this.choices.filter((function(e){return e.active}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"searchableChoices",{get:function(){return this.choices.filter((function(e){return!e.disabled&&!e.placeholder}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"groups",{get:function(){return this.state.groups},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeGroups",{get:function(){var e=this;return this.state.groups.filter((function(t){var i=t.active&&!t.disabled,n=e.state.choices.some((function(e){return e.active&&!e.disabled}));return i&&n}),[])},enumerable:!1,configurable:!0}),e.prototype.inTxn=function(){return this._txn>0},e.prototype.getChoiceById=function(e){return this.activeChoices.find((function(t){return t.id===e}))},e.prototype.getGroupById=function(e){return this.groups.find((function(t){return t.id===e}))},e}(),W="no-choices",G="no-results",U="add-choice";function z(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function J(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function X(e){for(var t=1;t`Missing ${e} property in key`,oe=e=>`Property 'weight' in key '${e}' must be a positive integer`,re=Object.prototype.hasOwnProperty;class ae{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=ce(e);this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ce(e){let t=null,i=null,n=null,s=1,o=null;if(Y(e)||Q(e))n=e,t=he(e),i=le(e);else{if(!re.call(e,"name"))throw new Error(se("name"));const r=e.name;if(n=r,re.call(e,"weight")&&(s=e.weight,s<=0))throw new Error(oe(r));t=he(r),i=le(r),o=e.getFn}return{path:t,id:i,weight:s,src:n,getFn:o}}function he(e){return Q(e)?e:e.split(".")}function le(e){return Q(e)?e.join("."):e}const ue={useExtendedSearch:!1,getFn:function(e,t){let i=[],n=!1;const s=(e,t,o)=>{if(te(e))if(t[o]){const r=e[t[o]];if(!te(r))return;if(o===t.length-1&&(Y(r)||Z(r)||function(e){return!0===e||!1===e||function(e){return ee(e)&&null!==e}(e)&&"[object Boolean]"==ne(e)}(r)))i.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;let t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(r));else if(Q(r)){n=!0;for(let e=0,i=r.length;ee.score===t.score?e.idx{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,Y(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const t=this.size();Y(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,i=this.size();t{let s=t.getFn?t.getFn(e):this.getFn(e,t.path);if(te(s))if(Q(s)){let e=[];const t=[{nestedArrIndex:-1,value:s}];for(;t.length;){const{nestedArrIndex:i,value:n}=t.pop();if(te(n))if(Y(n)&&!ie(n)){let t={v:n,i:i,n:this.norm.get(n)};e.push(t)}else Q(n)&&n.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[n]=e}else if(Y(s)&&!ie(s)){let e={v:s,n:this.norm.get(s)};i.$[n]=e}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function me(e,t,{getFn:i=de.getFn,fieldNormWeight:n=de.fieldNormWeight}={}){const s=new fe({getFn:i,fieldNormWeight:n});return s.setKeys(e.map(ce)),s.setSources(t),s.create(),s}function ve(e,{errors:t=0,currentLocation:i=0,expectedLocation:n=0,distance:s=de.distance,ignoreLocation:o=de.ignoreLocation}={}){const r=t/e.length;if(o)return r;const a=Math.abs(n-i);return s?r+a/s:a?1:r}const ge=32;function _e(e){let t={};for(let i=0,n=e.length;i{this.chunks.push({pattern:e,alphabet:_e(e),startIndex:t})},l=this.pattern.length;if(l>ge){let e=0;const t=l%ge,i=l-t;for(;e{const{isMatch:f,score:m,indices:v}=function(e,t,i,{location:n=de.location,distance:s=de.distance,threshold:o=de.threshold,findAllMatches:r=de.findAllMatches,minMatchCharLength:a=de.minMatchCharLength,includeMatches:c=de.includeMatches,ignoreLocation:h=de.ignoreLocation}={}){if(t.length>ge)throw new Error("Pattern length exceeds max of 32.");const l=t.length,u=e.length,d=Math.max(0,Math.min(n,u));let p=o,f=d;const m=a>1||c,v=m?Array(u):[];let g;for(;(g=e.indexOf(t,f))>-1;){let e=ve(t,{currentLocation:g,expectedLocation:d,distance:s,ignoreLocation:h});if(p=Math.min(e,p),f=g+l,m){let e=0;for(;e=c;o-=1){let r=o-1,a=i[e.charAt(r)];if(m&&(v[r]=+!!a),C[o]=(C[o+1]<<1|1)&a,n&&(C[o]|=(_[o+1]|_[o])<<1|1|_[o+1]),C[o]&E&&(y=ve(t,{errors:n,currentLocation:r,expectedLocation:d,distance:s,ignoreLocation:h}),y<=p)){if(p=y,f=r,f<=d)break;c=Math.max(1,2*d-f)}}if(ve(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:h})>p)break;_=C}const C={isMatch:f>=0,score:Math.max(.001,y)};if(m){const e=function(e=[],t=de.minMatchCharLength){let i=[],n=-1,s=-1,o=0;for(let r=e.length;o=t&&i.push([n,s]),n=-1)}return e[o-1]&&o-n>=t&&i.push([n,o-1]),i}(v,a);e.length?c&&(C.indices=e):C.isMatch=!1}return C}(e,t,d,{location:n+p,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:a,includeMatches:i,ignoreLocation:c});f&&(u=!0),l+=m,f&&v&&(h=[...h,...v])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&i&&(d.indices=h),d}}class be{constructor(e){this.pattern=e}static isMultiMatch(e){return Ee(e,this.multiRegex)}static isSingleMatch(e){return Ee(e,this.singleRegex)}search(){}}function Ee(e,t){const i=e.match(t);return i?i[1]:null}class Ce extends be{constructor(e,{location:t=de.location,threshold:i=de.threshold,distance:n=de.distance,includeMatches:s=de.includeMatches,findAllMatches:o=de.findAllMatches,minMatchCharLength:r=de.minMatchCharLength,isCaseSensitive:a=de.isCaseSensitive,ignoreLocation:c=de.ignoreLocation}={}){super(e),this._bitapSearch=new ye(e,{location:t,threshold:i,distance:n,includeMatches:s,findAllMatches:o,minMatchCharLength:r,isCaseSensitive:a,ignoreLocation:c})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Se extends be{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t,i=0;const n=[],s=this.pattern.length;for(;(t=e.indexOf(this.pattern,i))>-1;)i=t+s,n.push([t,i-1]);const o=!!n.length;return{isMatch:o,score:o?0:1,indices:n}}}const we=[class extends be{constructor(e){super(e)}static get type(){return"exact"}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){const t=e===this.pattern;return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},Se,class extends be{constructor(e){super(e)}static get type(){return"prefix-exact"}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){const t=e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,this.pattern.length-1]}}},class extends be{constructor(e){super(e)}static get type(){return"inverse-prefix-exact"}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){const t=!e.startsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class extends be{constructor(e){super(e)}static get type(){return"inverse-suffix-exact"}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){const t=!e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},class extends be{constructor(e){super(e)}static get type(){return"suffix-exact"}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){const t=e.endsWith(this.pattern);return{isMatch:t,score:t?0:1,indices:[e.length-this.pattern.length,e.length-1]}}},class extends be{constructor(e){super(e)}static get type(){return"inverse-exact"}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){const t=-1===e.indexOf(this.pattern);return{isMatch:t,score:t?0:1,indices:[0,e.length-1]}}},Ce],Ie=we.length,Ae=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,xe=new Set([Ce.type,Se.type]);const Le=[];function Oe(e,t){for(let i=0,n=Le.length;i!(!e[Me]&&!e.$or),Fe=e=>({[Me]:Object.keys(e).map((t=>({[t]:e[t]})))});function ke(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Te])(e);if(!o&&s.length>1&&!Ne(e))return n(Fe(e));if((e=>!Q(e)&&ee(e)&&!Ne(e))(e)){const n=o?e[Te]:s[0],r=o?e.$val:e[n];if(!Y(r))throw new Error((e=>`Invalid value for key ${e}`)(n));const a={keyId:le(n),pattern:r};return i&&(a.searcher=Oe(r,t)),a}let r={children:[],operator:s[0]};return s.forEach((t=>{const i=e[t];Q(i)&&i.forEach((e=>{r.children.push(n(e))}))})),r};return Ne(e)||(e=Fe(e)),n(e)}function De(e,t){const i=e.matches;t.matches=[],te(i)&&i.forEach((e=>{if(!te(e.indices)||!e.indices.length)return;const{indices:i,value:n}=e;let s={indices:i,value:n};e.key&&(s.key=e.key.src),e.idx>-1&&(s.refIndex=e.idx),t.matches.push(s)}))}function Pe(e,t){t.score=e.score}class je{constructor(e,t={},i){this.options=X(X({},de),t),this._keyStore=new ae(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof fe))throw new Error("Incorrect 'index' type");this._myIndex=t||me(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){te(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let i=0,n=this._docs.length;i{let i=1;e.matches.forEach((({key:e,norm:n,score:s})=>{const o=e?e.weight:null;i*=Math.pow(0===s&&o?Number.EPSILON:s,(o||1)*(t?1:n))})),e.score=i}))}(a,{ignoreFieldNorm:r}),s&&a.sort(o),Z(t)&&t>-1&&(a=a.slice(0,t)),function(e,t,{includeMatches:i=de.includeMatches,includeScore:n=de.includeScore}={}){const s=[];return i&&s.push(De),n&&s.push(Pe),e.map((e=>{const{idx:i}=e,n={item:t[i],refIndex:i};return s.length&&s.forEach((t=>{t(e,n)})),n}))}(a,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(e){const t=Oe(e,this.options),{records:i}=this._myIndex,n=[];return i.forEach((({v:e,i:i,n:s})=>{if(!te(e))return;const{isMatch:o,score:r,indices:a}=t.searchIn(e);o&&n.push({item:e,idx:i,matches:[{score:r,value:e,norm:s,indices:a}]})})),n}_searchLogical(e){const t=ke(e,this.options),i=(e,t,n)=>{if(!e.children){const{keyId:i,searcher:s}=e,o=this._findMatches({key:this._keyStore.get(i),value:this._myIndex.getValueForItemAtKeyId(t,i),searcher:s});return o&&o.length?[{idx:n,item:t,matches:o}]:[]}const s=[];for(let o=0,r=e.children.length;o{if(te(e)){let r=i(t,e,o);r.length&&(n[o]||(n[o]={idx:o,item:e,matches:[]},s.push(n[o])),r.forEach((({matches:e})=>{n[o].matches.push(...e)})))}})),s}_searchObjectList(e){const t=Oe(e,this.options),{keys:i,records:n}=this._myIndex,s=[];return n.forEach((({$:e,i:n})=>{if(!te(e))return;let o=[];i.forEach(((i,n)=>{o.push(...this._findMatches({key:i,value:e[n],searcher:t}))})),o.length&&s.push({idx:n,item:e,matches:o})})),s}_findMatches({key:e,value:t,searcher:i}){if(!te(t))return[];let n=[];if(Q(t))t.forEach((({v:t,i:s,n:o})=>{if(!te(t))return;const{isMatch:r,score:a,indices:c}=i.searchIn(t);r&&n.push({score:a,key:e,value:t,idx:s,norm:o,indices:c})}));else{const{v:s,n:o}=t,{isMatch:r,score:a,indices:c}=i.searchIn(s);r&&n.push({score:a,key:e,value:s,norm:o,indices:c})}return n}}je.version="7.0.0",je.createIndex=me,je.parseIndex=function(e,{getFn:t=de.getFn,fieldNormWeight:i=de.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new fe({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},je.config=de,je.parseQuery=ke,function(...e){Le.push(...e)}(class{constructor(e,{isCaseSensitive:t=de.isCaseSensitive,includeMatches:i=de.includeMatches,minMatchCharLength:n=de.minMatchCharLength,ignoreLocation:s=de.ignoreLocation,findAllMatches:o=de.findAllMatches,location:r=de.location,threshold:a=de.threshold,distance:c=de.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:i,minMatchCharLength:n,findAllMatches:o,ignoreLocation:s,location:r,threshold:a,distance:c},this.pattern=t?e:e.toLowerCase(),this.query=function(e,t={}){return e.split("|").map((e=>{let i=e.trim().split(Ae).filter((e=>e&&!!e.trim())),n=[];for(let e=0,s=i.length;e0;return A.setAttribute("role",N?"treeitem":"option"),N&&(T.groupId="".concat(_)),T.choice="",T.id=t.id,T.value=w,i&&(T.selectText=i),Ke(A,t,!1),t.disabled?((r=A.classList).add.apply(r,I(f)),T.choiceDisabled="",A.setAttribute("aria-disabled","true")):((a=A.classList).add.apply(a,I(d)),T.choiceSelectable=""),A},input:function(e,t){var i=e.classNames,n=i.input,s=i.inputCloned,o=e.labelId,r=document.createElement("input");return r.type="search",r.className="".concat(I(n).join(" ")," ").concat(I(s).join(" ")),r.autocomplete="off",r.autocapitalize="off",r.spellcheck=!1,r.setAttribute("role","textbox"),r.setAttribute("aria-autocomplete","list"),t?r.setAttribute("aria-label",t):o||Be(this._docRoot,this.passedElement.element.id,r),r},dropdown:function(e){var t,i,n=e.classNames,s=n.list,o=n.listDropdown,r=document.createElement("div");return(t=r.classList).add.apply(t,I(s)),(i=r.classList).add.apply(i,I(o)),r.setAttribute("aria-expanded","false"),r},notice:function(e,t,i){var s=e.classNames,o=s.itemChoice,r=s.addChoice,a=s.noResults,c=s.noChoices,h=s.notice;void 0===i&&(i="");var l=n(n(n([],I(s.item),!0),I(o),!0),I(h),!0);switch(i){case U:l.push.apply(l,I(r));break;case G:l.push.apply(l,I(a));break;case W:l.push.apply(l,I(c))}var u=document.createElement("div");if(S(u,!0,t),u.className=l.join(" "),i===U){var d=u.dataset;d.choiceSelectable="",d.choice=""}return u},option:function(e){var t=E(e.label),i=new Option(t,e.value,!1,e.selected);return Ke(i,e,!0),i.disabled=e.disabled,e.selected&&i.setAttribute("selected",""),i}},Ve="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,$e={},qe=function(e){if(e){var t=e.dataset.id;return t?parseInt(t,10):void 0}};return function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this.initialisedOK=void 0,this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0;var o=e.defaults;this.config=i(i(i({},o.allOptions),o.options),n),f.forEach((function(e){s.config[e]=i(i(i({},o.allOptions[e]),o.options[e]),n[e])}));var r=this.config;r.silent||this._validateConfig();var a=r.shadowRoot||document.documentElement;this._docRoot=a;var c="string"==typeof t?a.querySelector(t):t;if(!c||"object"!=typeof c||"INPUT"!==c.tagName&&!B(c)){if(!c&&"string"==typeof t)throw TypeError("Selector ".concat(t," failed to find an element"));throw TypeError("Expected one of the following types text|select-one|select-multiple")}if(this._elementType=c.type,this._isTextElement=this._elementType===O,(this._isTextElement||1!==r.maxItemCount)&&(r.singleModeForMultiSelect=!1),r.singleModeForMultiSelect&&(this._elementType=T),this._isSelectOneElement=this._elementType===M,this._isSelectMultipleElement=this._elementType===T,this._isSelectElement=this._isSelectOneElement||this._isSelectMultipleElement,this._canAddUserChoices=this._isTextElement&&r.addItems||this._isSelectElement&&r.addChoices,["auto","always"].includes("".concat(r.renderSelectedChoices))||(r.renderSelectedChoices="auto"),r.closeDropdownOnSelect="auto"===r.closeDropdownOnSelect?this._isTextElement||this._isSelectOneElement||r.singleModeForMultiSelect:j(r.closeDropdownOnSelect),r.placeholder&&(r.placeholderValue?this._hasNonChoicePlaceholder=!0:c.dataset.placeholder&&(this._hasNonChoicePlaceholder=!0,r.placeholderValue=c.dataset.placeholder)),n.addItemFilter&&"function"!=typeof n.addItemFilter){var h=n.addItemFilter instanceof RegExp?n.addItemFilter:new RegExp(n.addItemFilter);r.addItemFilter=h.test.bind(h)}if(this.passedElement=this._isTextElement?new P({element:c,classNames:r.classNames}):new H({element:c,classNames:r.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:r.placeholder&&!this._hasNonChoicePlaceholder}),this.initialised=!1,this._store=new q,this._currentValue="",r.searchEnabled=!this._isTextElement&&r.searchEnabled||this._elementType===T,this._canSearch=r.searchEnabled,this._isScrollingOnIe=!1,this._highlightPosition=0,this._wasTap=!0,this._placeholderValue=this._generatePlaceholderValue(),this._baseId=function(e){var t=e.id||e.name&&"".concat(e.name,"-").concat(v(2))||v(4);return t=t.replace(/(:|\.|\[|\]|,)/g,""),"".concat("choices-","-").concat(t)}(c),this._direction=this.passedElement.dir,!this._direction){var l=window.getComputedStyle(this.passedElement.element).direction;l!==window.getComputedStyle(document.documentElement).direction&&(this._direction=l)}if(this._idNames={itemChoice:"item-choice"},this._templates=o.templates,this._render=this._render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onInput=this._onInput.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onFormReset=this._onFormReset.bind(this),this._onSelectKey=this._onSelectKey.bind(this),this._onEnterKey=this._onEnterKey.bind(this),this._onEscapeKey=this._onEscapeKey.bind(this),this._onDirectionKey=this._onDirectionKey.bind(this),this._onDeleteKey=this._onDeleteKey.bind(this),this.passedElement.isActive)return r.silent||console.warn("Trying to initialise Choices on element already initialised",{element:t}),this.initialised=!0,void(this.initialisedOK=!1);this.init(),this._initialItems=this._store.items.map((function(e){return e.value}))}return Object.defineProperty(e,"defaults",{get:function(){return Object.preventExtensions({get options(){return $e},get allOptions(){return V},get templates(){return He}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised&&void 0===this.initialisedOK){this._searcher=new Re(this.config),this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._isTextElement&&!this.config.addItems||this.passedElement.element.hasAttribute("disabled")||this.passedElement.element.closest("fieldset:disabled")?this.disable():(this.enable(),this._addEventListeners()),this._initStore(),this.initialised=!0,this.initialisedOK=!0;var e=this.config.callbackOnInit;e&&"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this._store._listeners=[],this.clearStore(),this._stopSearch(),this._templates=e.defaults.templates,this.initialised=!1,this.initialisedOK=void 0)},e.prototype.enable=function(){var e=this.passedElement,t=this.containerOuter;return e.isDisabled&&e.enable(),t.isDisabled&&(this._addEventListeners(),this.input.enable(),t.enable(),this._render()),this},e.prototype.disable=function(){var e=this.passedElement,t=this.containerOuter;return e.isDisabled||e.disable(),t.isDisabled||(this._removeEventListeners(),this.input.disable(),t.disable(),this._render()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.choices.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(m(i,!0)),t&&this.passedElement.triggerEvent("highlightItem",this._getChoiceForOutput(i))),this},e.prototype.unhighlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.choices.find((function(t){return t.id===e.id}));return i&&i.highlighted?(this._store.dispatch(m(i,!1)),t&&this.passedElement.triggerEvent("highlightItem",this._getChoiceForOutput(i)),this):this},e.prototype.highlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){return e.highlightItem(t)}))})),this},e.prototype.unhighlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){return e.unhighlightItem(t)}))})),this},e.prototype.removeActiveItemsByValue=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeActiveItems=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.withTxn((function(){t._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)}))})),this},e.prototype.showDropdown=function(e){var t=this;return this.dropdown.isActive||requestAnimationFrame((function(){t.dropdown.show(),t.containerOuter.open(t.dropdown.distanceFromTopWindow),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent("showDropdown")})),this},e.prototype.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent("hideDropdown")})),this):this},e.prototype.getValue=function(e){var t=this;void 0===e&&(e=!1);var i=this._store.items.reduce((function(i,n){var s=e?n.value:t._getChoiceForOutput(n);return i.push(s),i}),[]);return this._isSelectOneElement||this.config.singleModeForMultiSelect?i[0]:i},e.prototype.setValue=function(e){var t=this;return this.initialisedOK?(this._store.withTxn((function(){e.forEach((function(e){e&&t._addChoice(K(e,!1))}))})),this._searcher.reset(),this):(this._warnChoicesInitFailed("setValue"),this)},e.prototype.setChoiceByValue=function(e){var t=this;return this.initialisedOK?(this._isTextElement||(this._store.withTxn((function(){(Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)}))})),this._searcher.reset()),this):(this._warnChoicesInitFailed("setChoiceByValue"),this)},e.prototype.setChoices=function(e,t,n,s){var o=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),!this.initialisedOK)return this._warnChoicesInitFailed("setChoices"),this;if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(s&&this.clearChoices(),"function"==typeof e){var r=e(this);if("function"==typeof Promise&&r instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return o._handleLoadingState(!0)})).then((function(){return r})).then((function(e){return o.setChoices(e,t,n,s)})).catch((function(e){o.config.silent||console.error(e)})).then((function(){return o._handleLoadingState(!1)})).then((function(){return o}));if(!Array.isArray(r))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof r));return this.setChoices(r,t,n,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._store.withTxn((function(){var s="value"===t,r="label"===n;e.forEach((function(e){if("choices"in e){var a=e;r||(a=i(i({},a),{label:a[n]})),o._addGroup(K(a,!0))}else{var c=e;r&&s||(c=i(i({},c),{value:c[t],label:c[n]})),o._addChoice(K(c,!1))}}))})),this._searcher.reset(),this},e.prototype.refresh=function(e,t,i){var n=this;return void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===i&&(i=!1),this._isSelectElement?(this._store.withTxn((function(){var s=n.passedElement.optionsAsChoices(),o={};i||n._store.items.forEach((function(e){e.id&&e.active&&e.selected&&!e.disabled&&(o[e.value]=!0)})),s.forEach((function(e){if(!("choices"in e)){var t=e;i?t.selected=!1:o[t.value]&&(t.selected=!0)}})),n.clearStore(),n._addPredefinedChoices(s,t,e),n._isSearching&&n._searchChoices(n.input.value)})),this):(this.config.silent||console.warn("refresh method can only be used on choices backed by a element"),this)},e.prototype.removeChoice=function(e){var t=this._store.choices.find((function(t){return t.value===e}));return t?(this._store.dispatch(function(e){return{type:r,choice:e}}(t)),this._searcher.reset(),t.selected&&this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(t)),this):this},e.prototype.clearChoices=function(){return this.passedElement.element.innerHTML="",this._store.dispatch({type:l}),this._searcher.reset(),this},e.prototype.clearStore=function(){return this._store.reset(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this._searcher.reset(),this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._clearNotice(),this._isSearching&&this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=R,t=Object.keys(n).sort(),i=Object.keys(e).sort(),t.filter((function(e){return i.indexOf(e)<0})));s.length&&console.warn("Unknown config option(s) passed",s.join(", ")),n.allowHTML&&n.allowHtmlUserInput&&(n.addItems&&console.warn("Warning: allowHTML/allowHtmlUserInput/addItems all being true is strongly not recommended and may lead to XSS attacks"),n.addChoices&&console.warn("Warning: allowHTML/allowHtmlUserInput/addChoices all being true is strongly not recommended and may lead to XSS attacks"))},e.prototype._render=function(e){void 0===e&&(e={choices:!0,groups:!0,items:!0}),this._store.inTxn()||(this._isSelectElement&&(e.choices||e.groups)&&this._renderChoices(),e.items&&this._renderItems())},e.prototype._renderChoices=function(){var e=this;if(this.choiceList.clear(),this._canAddItems()){var t=this.config,i=this._store,n=i.activeGroups,s=i.activeChoices,o=document.createDocumentFragment(),r=!0;if(s.length){if(t.resetScrollPosition&&requestAnimationFrame((function(){return e.choiceList.scrollToTop()})),n.length&&!this._isSearching){if(!this._hasNonChoicePlaceholder){var a=s.filter((function(e){return e.placeholder&&-1===e.groupId}));a.length&&(o=this._createChoicesFragment(a,o))}o=this._createGroupsFragment(n,s,o)}else o=this._createChoicesFragment(s,o);r=!o.childNodes.length}var c=this._notice;r?c||(this._notice={text:b(t.noChoicesText),type:U}):c&&c.type===U&&(this._notice=void 0),this._renderNotice(),r||(this.choiceList.element.append(o),this._highlightChoice())}},e.prototype._renderItems=function(){var e=this._store.items||[];this.itemList.clear();var t=this._createItemsFragment(e);t.childNodes.length&&this.itemList.element.append(t)},e.prototype._createGroupsFragment=function(e,t,i){var n=this;void 0===i&&(i=document.createDocumentFragment());var s=this.config;s.shouldSort&&e.sort(s.sorter);var o=t.filter((function(e){return!e.groupId}));return o.length&&this._createChoicesFragment(o,i,!1),e.forEach((function(e){var o=function(e){return t.filter((function(t){return n._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===s.renderSelectedChoices||!t.selected)}))}(e);if(o.length){var r=n._templates.choiceGroup(n.config,e);i.appendChild(r),n._createChoicesFragment(o,i,!0)}})),i},e.prototype._createChoicesFragment=function(e,t,i){var s=this;void 0===t&&(t=document.createDocumentFragment()),void 0===i&&(i=!1);var o=this,r=o.config,a=o._isSearching,c=o._isSelectOneElement,l=r.searchResultLimit,h=r.renderChoiceLimit,u=[],d=r.appendGroupInSearch&&a;if(d&&this._store.groups.forEach((function(e){u[e.id]=e.label})),this._isSelectElement){var p=e.filter((function(e){return!e.element}));p.length&&this.passedElement.addOptions(p)}var m="auto"===r.renderSelectedChoices&&!c,f=[],v=[];e.forEach((function(e){a&&!e.rank||m&&e.selected||(s._hasNonChoicePlaceholder||!e.placeholder?v.push(e):f.push(e))})),a?v.sort(C):r.shouldSort&&v.sort(r.sorter);var _=c&&f.length?n(n([],f,!0),v,!0):v,g=_.length,y=g;return a&&l>0?y=l:h>0&&!i&&(y=h),y0){var o=u[e.groupId];o&&(n.innerHTML+=" (".concat(o,")"))}return t.appendChild(n),i0?this._store.getGroupById(e.groupId):null;return{id:e.id,highlighted:e.highlighted,labelClass:e.labelClass,labelDescription:e.labelDescription,customProperties:e.customProperties,disabled:e.disabled,active:e.active,label:e.label,placeholder:e.placeholder,value:e.value,groupValue:i&&i.label?i.label:void 0,element:e.element,keyCode:t}}},e.prototype._triggerChange=function(e){null!=e&&this.passedElement.triggerEvent("change",{value:e})},e.prototype._handleButtonAction=function(e){var t=this._store.items;if(t.length&&this.config.removeItems&&this.config.removeItemButton){var i=e&&ke(e.parentNode),n=i&&t.find((function(e){return e.id===i}));if(n&&(this._removeItem(n),this._triggerChange(n.value),this._isSelectOneElement&&!this._hasNonChoicePlaceholder)){var s=this._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));s&&(this._addItem(s),s.value&&this._triggerChange(s.value))}}},e.prototype._handleItemAction=function(e,t){var i=this;void 0===t&&(t=!1);var n=this._store.items;if(n.length&&this.config.removeItems&&!this._isSelectOneElement){var s=ke(e);s&&(n.forEach((function(e){e.id!==s||e.highlighted?!t&&e.highlighted&&i.unhighlightItem(e):i.highlightItem(e)})),this.input.focus())}},e.prototype._handleChoiceAction=function(e){var t=this,i=ke(e),n=i&&this._store.getChoiceById(i);if(!n||n.disabled)return!1;var s=this.dropdown.isActive;if(!n.selected){if(!this._canAddItems())return!0;this._store.withTxn((function(){t._addItem(n,!0,!0),t.clearInput(),t.unhighlightAll()})),this._triggerChange(n.value)}return s&&this.config.closeDropdownOnSelect&&(this.hideDropdown(!0),this.containerOuter.element.focus()),!0},e.prototype._handleBackspace=function(e){var t=this.config;if(t.removeItems&&e.length){var i=e[e.length-1],n=e.some((function(e){return e.highlighted}));t.editItems&&!n&&i?(this.input.value=i.value,this.input.setWidth(),this._removeItem(i),this._triggerChange(i.value)):(n||this.highlightItem(i,!1),this.removeHighlightedItems(!0))}},e.prototype._loadChoices=function(){var e,t=this.config;if(this._isTextElement){this._presetChoices=t.items.map((function(e){return B(e,!1)}));var i=this.passedElement.value;if(i){var n=i.split(t.delimiter).map((function(e){return B(e,!1)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=t.choices.map((function(e){return B(e,!0)}));var s=this.passedElement.optionsAsChoices();s&&(e=this._presetChoices).push.apply(e,s)}},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.config;e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?(this.itemList.clear(),this.itemList.element.append(this._templates.placeholder(t,t.loadingText))):this.input.placeholder=t.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement||(this.input.placeholder=this._placeholderValue||""))},e.prototype._handleSearch=function(e){if(this.input.isFocussed){var t=this.config,i=t.searchFloor,n=t.searchChoices,s=this._store.choices.some((function(e){return!e.active}));if(null!=e&&e.length>=i){var o=n?this._searchChoices(e):0;null!==o&&this.passedElement.triggerEvent("search",{value:e,resultCount:o})}else s&&this._stopSearch()}},e.prototype._canAddItems=function(){var e=this.config,t=e.maxItemCount,i=e.maxItemText;return!(!e.singleModeForMultiSelect&&t>0&&t<=this._store.items.length&&(this._displayNotice("function"==typeof i?i(t):i,$),1))},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=y(t.customAddItemText,e)),i){var s=this._store.choices.find((function(i){return t.valueComparer(i.value,e)}));if(this._isSelectElement){if(s)return this._displayNotice("",$),!1}else this._isTextElement&&!t.duplicateItemsAllowed&&s&&(i=!1,n=y(t.uniqueItemText,e))}return i&&(n=y(t.addItemText,e)),n&&this._displayNotice(n,$),i},e.prototype._searchChoices=function(e){var t=e.trim().replace(/\s{2,}/," ");if(!t.length||t===this._currentValue)return null;var i=this._searcher;i.isEmptyIndex()&&i.index(this._store.searchableChoices);var n=i.search(t);this._currentValue=t,this._highlightPosition=0,this._isSearching=!0;var s=this._notice,o=s&&s.type;return o!==$&&(n.length?o===W&&this._clearNotice():this._displayNotice(b(this.config.noResultsText),W)),this._store.dispatch(function(e){return{type:a,results:e}}(n)),n.length},e.prototype._stopSearch=function(){var e=this._isSearching;this._currentValue="",this._isSearching=!1,e&&(this._store.dispatch({type:c,active:!0}),this.passedElement.triggerEvent("search",{value:"",resultCount:0}))},e.prototype._addEventListeners=function(){var e=this._docRoot,t=this.containerOuter.element,i=this.input.element;e.addEventListener("touchend",this._onTouchEnd,!0),t.addEventListener("keydown",this._onKeyDown,!0),t.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(t.addEventListener("focus",this._onFocus,{passive:!0}),t.addEventListener("blur",this._onBlur,{passive:!0})),i.addEventListener("keyup",this._onKeyUp,{passive:!0}),i.addEventListener("input",this._onInput,{passive:!0}),i.addEventListener("focus",this._onFocus,{passive:!0}),i.addEventListener("blur",this._onBlur,{passive:!0}),i.form&&i.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()},e.prototype._removeEventListeners=function(){var e=this._docRoot,t=this.containerOuter.element,i=this.input.element;e.removeEventListener("touchend",this._onTouchEnd,!0),t.removeEventListener("keydown",this._onKeyDown,!0),t.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(t.removeEventListener("focus",this._onFocus),t.removeEventListener("blur",this._onBlur)),i.removeEventListener("keyup",this._onKeyUp),i.removeEventListener("input",this._onInput),i.removeEventListener("focus",this._onFocus),i.removeEventListener("blur",this._onBlur),i.form&&i.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()},e.prototype._onKeyDown=function(e){var t=e.keyCode,i=this.dropdown.isActive,n=1===e.key.length||2===e.key.length&&e.key.charCodeAt(0)>=55296||"Unidentified"===e.key;switch(this._isTextElement||i||(this.showDropdown(),!this.input.isFocussed&&n&&(this.input.value+=e.key," "===e.key&&e.preventDefault())),t){case 65:return this._onSelectKey(e,this.itemList.element.hasChildNodes());case 13:return this._onEnterKey(e,i);case 27:return this._onEscapeKey(e,i);case 38:case 33:case 40:case 34:return this._onDirectionKey(e,i);case 8:case 46:return this._onDeleteKey(e,this._store.items,this.input.isFocussed)}},e.prototype._onKeyUp=function(){this._canSearch=this.config.searchEnabled},e.prototype._onInput=function(){var e=this.input.value;if(!e)return this._isTextElement?this.hideDropdown(!0):this._stopSearch(),void this._clearNotice();this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice())))},e.prototype._onSelectKey=function(e,t){(e.ctrlKey||e.metaKey)&&t&&(this._canSearch=!1,this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll())},e.prototype._onEnterKey=function(e,t){var i=this,n=this.config,s=this.input.value,o=e.target,r=o&&o.hasAttribute("data-button");if(e.preventDefault(),r)this._handleButtonAction(o);else if(t){var a=this.dropdown.element.querySelector(A(n.classNames.highlightedState));if(!a||!this._handleChoiceAction(a))if(o&&s){if(this._canAddItems()){var c=!1;this._store.withTxn((function(){if(!(c=i._findAndSelectChoiceByValue(s,!0))){if(!i._canAddUserChoices)return;if(!i._canCreateItem(s))return;var e=_(s),t=n.allowHtmlUserInput||e===s?s:{escaped:e,raw:s};i._addChoice(B({value:t,label:t,selected:!0},!1),!0,!0),c=!0}i.clearInput(),i.unhighlightAll()})),c&&(this._triggerChange(s),n.closeDropdownOnSelect&&this.hideDropdown(!0))}}else this.hideDropdown(!0)}else(this._isSelectElement||this._notice)&&this.showDropdown()},e.prototype._onEscapeKey=function(e,t){t&&(e.stopPropagation(),this.hideDropdown(!0),this.containerOuter.element.focus())},e.prototype._onDirectionKey=function(e,t){var i,n,s,o=e.keyCode,r=e.metaKey;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var a=40===o||34===o?1:-1,c="[data-choice-selectable]",l=void 0;if(r||34===o||33===o)l=this.dropdown.element.querySelector(a>0?"".concat(c,":last-of-type"):c);else{var h=this.dropdown.element.querySelector(A(this.config.classNames.highlightedState));l=h?function(e,t,i){void 0===i&&(i=1);for(var n="".concat(i>0?"next":"previous","ElementSibling"),s=e[n];s;){if(s.matches(t))return s;s=s[n]}return null}(h,c,a):this.dropdown.element.querySelector(c)}l&&(i=l,n=this.choiceList.element,void 0===(s=a)&&(s=1),(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(l,a),this._highlightChoice(l)),e.preventDefault()}},e.prototype._onDeleteKey=function(e,t,i){this._isSelectOneElement||e.target.value||!i||(this._handleBackspace(t),e.preventDefault())},e.prototype._onTouchMove=function(){this._wasTap&&(this._wasTap=!1)},e.prototype._onTouchEnd=function(e){var t=(e||e.touches[0]).target;this._wasTap&&this.containerOuter.element.contains(t)&&((t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation()),this._wasTap=!0},e.prototype._onMouseDown=function(e){var t=e.target;if(t instanceof HTMLElement){if(Me&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?n[this._highlightPosition]:n[n.length-1])||(s=n[0]),(t=s.classList).add.apply(t,I(i)),s.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:s}),this.dropdown.isActive&&(this.input.setActiveDescendant(s.id),this.containerOuter.setActiveDescendant(s.id))}},e.prototype._addItem=function(e,t,i){void 0===t&&(t=!0),void 0===i&&(i=!1);var n=e.id;if(!n)throw new TypeError("item.id must be set before _addItem is called for a choice/item");(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&this.removeActiveItems(n),this._store.dispatch(function(e){return{type:u,item:e}}(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){e.id&&(this._store.dispatch(function(e){return{type:d,item:e}}(e)),this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(e)))},e.prototype._addChoice=function(e,t,i){if(void 0===t&&(t=!0),void 0===i&&(i=!1),e.id)throw new TypeError("Can not re-add a choice which has already been added");this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var n=this.config,s=n.prependValue,r=n.appendValue;s&&(e.value=s+e.value),r&&(e.value+=r.toString()),(s||r)&&e.element&&(e.element.value=e.value),this._store.dispatch(function(e){return{type:o,choice:e}}(e)),e.selected&&this._addItem(e,t,i)},e.prototype._addGroup=function(e,t){var i=this;if(void 0===t&&(t=!0),e.id)throw new TypeError("Can not re-add a group which has already been added");if(this._store.dispatch(function(e){return{type:h,group:e}}(e)),e.choices){var n=e;this._lastAddedGroupId++,n.id=this._lastAddedGroupId;var s=e.id,o=e.choices;n.choices=[],o.forEach((function(n){n.groupId=s,e.disabled&&(n.disabled=!0),i._addChoice(n,t)}))}},e.prototype._createTemplates=function(){var e=this,t=this.config.callbackOnCreateTemplates,i={};t&&"function"==typeof t&&(i=t.call(this,g,w));var n={};Object.keys(this._templates).forEach((function(t){n[t]=t in i?i[t].bind(e):e._templates[t].bind(e)})),this._templates=n},e.prototype._createElements=function(){var e=this._templates,t=this.config,i=t.position,n=t.classNames,s=this._elementType;this.containerOuter=new F({element:e.containerOuter(t,this._direction,this._isSelectElement,this._isSelectOneElement,t.searchEnabled,s,t.labelId),classNames:n,type:s,position:i}),this.containerInner=new F({element:e.containerInner(t),classNames:n,type:s,position:i}),this.input=new M({element:e.input(t,this._placeholderValue),classNames:n,type:s,preventPaste:!t.paste}),this.choiceList=new D({element:e.choiceList(t,this._isSelectOneElement)}),this.itemList=new D({element:e.itemList(t,this._isSelectOneElement)}),this.dropdown=new L({element:e.dropdown(t),classNames:n,type:s})},e.prototype._createStructure=function(){var e=this,t=e.containerInner,i=e.containerOuter,n=e.passedElement,s=e.dropdown,o=e.input;n.conceal(),t.wrap(n.element),i.wrap(t.element),this._isSelectOneElement?o.placeholder=this.config.searchPlaceholderValue||"":(this._placeholderValue&&(o.placeholder=this._placeholderValue),o.setWidth()),i.element.appendChild(t.element),i.element.appendChild(s.element),t.element.appendChild(this.itemList.element),s.element.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&s.element.insertBefore(o.element,s.element.firstChild):t.element.appendChild(o.element),this._highlightPosition=0,this._isSearching=!1},e.prototype._initStore=function(){var e=this;this._store.subscribe(this._render),this._store.withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),this._isSelectOneElement&&this._hasNonChoicePlaceholder&&this._render({choices:!1,groups:!1,items:!0})},e.prototype._addPredefinedChoices=function(e,t,i){var n=this;void 0===t&&(t=!1),void 0===i&&(i=!0),t&&-1===e.findIndex((function(e){return e.selected}))&&e.some((function(e){return!e.disabled&&!("choices"in e)&&(e.selected=!0,!0)})),e.forEach((function(e){"choices"in e?n._isSelectElement&&n._addGroup(e,i):n._addChoice(e,i)}))},e.prototype._findAndSelectChoiceByValue=function(e,t){var i=this;void 0===t&&(t=!1);var n=this._store.choices.find((function(t){return i.config.valueComparer(t.value,e)}));return!(!n||n.disabled||n.selected||(this._addItem(n,!0,t),0))},e.prototype._generatePlaceholderValue=function(){var e=this.config;if(!e.placeholder)return null;if(this._hasNonChoicePlaceholder)return e.placeholderValue;if(this._isSelectElement){var t=this.passedElement.placeholderOption;return t?t.text:null}return null},e.prototype._warnChoicesInitFailed=function(e){if(!this.config.silent){if(!this.initialised)throw new TypeError("".concat(e," called on a non-initialised instance of Choices"));if(!this.initialisedOK)throw new TypeError("".concat(e," called for an element which has multiple instances of Choices initialised on it"))}},e.version="11.0.0-rc8",e}()})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Choices=t()}(this,(function(){"use strict";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};function t(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,i=1,n=arguments.length;i/g,">").replace(/=0&&!window.matchMedia("(min-height: ".concat(e+1,"px)")).matches:"top"===this.position&&(i=!0),i},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype.open=function(e,t){var i,n;(i=this.element.classList).add.apply(i,T(this.classNames.openState)),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&((n=this.element.classList).add.apply(n,T(this.classNames.flippedState)),this.isFlipped=!0)},e.prototype.close=function(){var e,t;(e=this.element.classList).remove.apply(e,T(this.classNames.openState)),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&((t=this.element.classList).remove.apply(t,T(this.classNames.flippedState)),this.isFlipped=!1)},e.prototype.addFocusState=function(){var e;(e=this.element.classList).add.apply(e,T(this.classNames.focusState))},e.prototype.removeFocusState=function(){var e;(e=this.element.classList).remove.apply(e,T(this.classNames.focusState))},e.prototype.enable=function(){var e;(e=this.element.classList).remove.apply(e,T(this.classNames.disabledState)),this.element.removeAttribute("aria-disabled"),this.type===g&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){var e;(e=this.element.classList).add.apply(e,T(this.classNames.disabledState)),this.element.setAttribute("aria-disabled","true"),this.type===g&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=this.element,i=e.parentNode;i&&(e.nextSibling?i.insertBefore(t,e.nextSibling):i.appendChild(t)),t.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element,i=t.parentNode;i&&(i.insertBefore(e,t),i.removeChild(t))},e.prototype.addLoadingState=function(){var e;(e=this.element.classList).add.apply(e,T(this.classNames.loadingState)),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){var e;(e=this.element.classList).remove.apply(e,T(this.classNames.loadingState)),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),k=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,s=e.preventPaste;this.element=t,this.type=i,this.classNames=n,this.preventPaste=s,this.isFocussed=this.element.isEqualNode(document.activeElement),this.isDisabled=t.disabled,this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}return Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.element.placeholder=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.addEventListeners=function(){var e=this.element;e.addEventListener("paste",this._onPaste),e.addEventListener("input",this._onInput,{passive:!0}),e.addEventListener("focus",this._onFocus,{passive:!0}),e.addEventListener("blur",this._onBlur,{passive:!0})},e.prototype.removeEventListeners=function(){var e=this.element;e.removeEventListener("input",this._onInput),e.removeEventListener("paste",this._onPaste),e.removeEventListener("focus",this._onFocus),e.removeEventListener("blur",this._onBlur)},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.isDisabled=!0},e.prototype.focus=function(){this.isFocussed||this.element.focus()},e.prototype.blur=function(){this.isFocussed&&this.element.blur()},e.prototype.clear=function(e){return void 0===e&&(e=!0),this.element.value="",e&&this.setWidth(),this},e.prototype.setWidth=function(){var e=this.element;e.style.minWidth="".concat(e.placeholder.length+1,"ch"),e.style.width="".concat(e.value.length+1,"ch")},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype._onInput=function(){this.type!==g&&this.setWidth()},e.prototype._onPaste=function(e){this.preventPaste&&e.preventDefault()},e.prototype._onFocus=function(){this.isFocussed=!0},e.prototype._onBlur=function(){this.isFocussed=!1},e}(),P=function(){function e(e){this.element=e.element,this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight}return e.prototype.prepend=function(e){var t=this.element.firstElementChild;t?this.element.insertBefore(e,t):this.element.append(e)},e.prototype.scrollToTop=function(){this.element.scrollTop=0},e.prototype.scrollToChildElement=function(e,t){var i=this;if(e){var n=t>0?this.element.scrollTop+(e.offsetTop+e.offsetHeight)-(this.element.scrollTop+this.element.offsetHeight):e.offsetTop;requestAnimationFrame((function(){i._animateScroll(n,t)}))}},e.prototype._scrollDown=function(e,t,i){var n=(i-e)/t;this.element.scrollTop=e+(n>1?n:1)},e.prototype._scrollUp=function(e,t,i){var n=(e-i)/t;this.element.scrollTop=e-(n>1?n:1)},e.prototype._animateScroll=function(e,t){var i=this,n=this.element.scrollTop,s=!1;t>0?(this._scrollDown(n,4,e),ne&&(s=!0)),s&&requestAnimationFrame((function(){i._animateScroll(e,t)}))},e}(),j=function(){function e(e){var t=e.classNames;this.element=e.element,this.classNames=t,this.isDisabled=!1}return Object.defineProperty(e.prototype,"isActive",{get:function(){return"active"===this.element.dataset.choice},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dir",{get:function(){return this.element.dir},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.setAttribute("value",e),this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.conceal=function(){var e,t=this.element;(e=t.classList).add.apply(e,T(this.classNames.input)),t.hidden=!0,t.tabIndex=-1;var i=t.getAttribute("style");i&&t.setAttribute("data-choice-orig-style",i),t.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e,t=this.element;(e=t.classList).remove.apply(e,T(this.classNames.input)),t.hidden=!1,t.removeAttribute("tabindex");var i=t.getAttribute("data-choice-orig-style");i?(t.removeAttribute("data-choice-orig-style"),t.setAttribute("style",i)):t.removeAttribute("style"),t.removeAttribute("data-choice")},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.element.disabled=!1,this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.element.disabled=!0,this.isDisabled=!0},e.prototype.triggerEvent=function(e,t){var i;void 0===(i=t||{})&&(i=null),this.element.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0}))},e}(),K=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(j),B=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},H=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},V=function(e,t){if("string"==typeof e)return V({value:e,label:e},!1);var i=e;if("choices"in i){if(!t)throw new TypeError("optGroup is not allowed");var n=i,s=n.choices.map((function(e){return V(e,!1)}));return{id:0,label:A(n.label)||n.value,active:!!s.length,disabled:!!n.disabled,choices:s}}var o=i;return{id:0,groupId:0,score:0,rank:0,value:o.value,label:o.label||o.value,active:B(o.active),selected:B(o.selected,!1),disabled:B(o.disabled,!1),placeholder:B(o.placeholder,!1),highlighted:!1,labelClass:H(o.labelClass),labelDescription:o.labelDescription,customProperties:o.customProperties}},R=function(e){return"SELECT"===e.tagName},q=function(e){function i(t){var i=t.template,n=t.extractPlaceholder,s=e.call(this,{element:t.element,classNames:t.classNames})||this;return s.template=i,s.extractPlaceholder=n,s}return t(i,e),Object.defineProperty(i.prototype,"placeholderOption",{get:function(){return this.element.querySelector('option[value=""]')||this.element.querySelector("option[placeholder]")},enumerable:!1,configurable:!0}),i.prototype.addOptions=function(e){var t=this,i=document.createDocumentFragment();e.forEach((function(e){var n=e;if(!n.element){var s=t.template(n);i.appendChild(s),n.element=s}})),this.element.appendChild(i)},i.prototype.optionsAsChoices=function(){var e=this,t=[];return this.element.querySelectorAll(":scope > option, :scope > optgroup").forEach((function(i){!function(e){return"OPTION"===e.tagName}(i)?function(e){return"OPTGROUP"===e.tagName}(i)&&t.push(e._optgroupToChoice(i)):t.push(e._optionToChoice(i))})),t},i.prototype._optionToChoice=function(e){return!e.hasAttribute("value")&&e.hasAttribute("placeholder")&&(e.setAttribute("value",""),e.value=""),{id:0,groupId:0,score:0,rank:0,value:e.value,label:e.innerHTML,element:e,active:!0,selected:this.extractPlaceholder?e.selected:e.hasAttribute("selected"),disabled:e.disabled,highlighted:!1,placeholder:this.extractPlaceholder&&(!e.value||e.hasAttribute("placeholder")),labelClass:void 0!==e.dataset.labelClass?H(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:M(e.dataset.customProperties)}},i.prototype._optgroupToChoice=function(e){var t=this,i=e.querySelectorAll("option"),n=Array.from(i).map((function(e){return t._optionToChoice(e)}));return{id:0,label:e.label||"",element:e,active:!!n.length,disabled:e.disabled,choices:n}},i}(j),G={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,closeDropdownOnSelect:"auto",singleModeForMultiSelect:!1,addChoices:!1,addItems:!0,addItemFilter:function(e){return!!e&&""!==e},removeItems:!0,removeItemButton:!1,removeItemButtonAlignLeft:!1,editItems:!1,allowHTML:!1,allowHtmlUserInput:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sorter:function(e,t){var i=e.label,n=t.label,s=void 0===n?t.value:n;return A(void 0===i?e.value:i).localeCompare(A(s),[],{sensitivity:"base",ignorePunctuation:!0,numeric:!0})},shadowRoot:null,placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add "'.concat(e,'"')},removeItemIconText:function(){return"Remove item"},removeItemLabelText:function(e){return"Remove item: ".concat(e)},maxItemText:function(e){return"Only ".concat(e," values can be added")},valueComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},labelId:"",callbackOnInit:null,callbackOnCreateTemplates:null,classNames:{containerOuter:["choices"],containerInner:["choices__inner"],input:["choices__input"],inputCloned:["choices__input--cloned"],list:["choices__list"],listItems:["choices__list--multiple"],listSingle:["choices__list--single"],listDropdown:["choices__list--dropdown"],item:["choices__item"],itemSelectable:["choices__item--selectable"],itemDisabled:["choices__item--disabled"],itemChoice:["choices__item--choice"],description:["choices__description"],placeholder:["choices__placeholder"],group:["choices__group"],groupHeading:["choices__heading"],button:["choices__button"],activeState:["is-active"],focusState:["is-focused"],openState:["is-open"],disabledState:["is-disabled"],highlightedState:["is-highlighted"],selectedState:["is-selected"],flippedState:["is-flipped"],loadingState:["is-loading"],notice:["choices__notice"],addChoice:["choices__item--selectable","add-choice"],noResults:["has-no-results"],noChoices:["has-no-choices"]},appendGroupInSearch:!1},U=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},W={groups:function(e,t){var i=e,n=!0;switch(t.type){case h:i.push(t.group);break;case l:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t,i){var n=e,s=!0;switch(t.type){case u:t.item.selected=!0,(o=t.item.element)&&(o.selected=!0,o.setAttribute("selected","")),n.push(t.item);break;case d:var o;if(t.item.selected=!1,o=t.item.element){o.selected=!1,o.removeAttribute("selected");var a=o.parentElement;a&&R(a)&&a.type===g&&(a.value="")}U(t.item),n=n.filter((function(e){return e.id!==t.item.id}));break;case r:n=n.filter((function(e){return e.id!==t.choice.id})),U(t.choice);break;case p:var c=t.highlighted,l=n.find((function(e){return e.id===t.item.id}));l&&l.highlighted!==c&&(l.highlighted=c,i&&function(e,t,i){var n,s,o=e.itemEl;o&&((n=o.classList).remove.apply(n,T(i)),(s=o.classList).add.apply(s,T(t)))}(l,c?i.classNames.highlightedState:i.classNames.selectedState,c?i.classNames.selectedState:i.classNames.highlightedState));break;default:s=!1}return{state:n,update:s}},choices:function(e,t,i){var n=e,s=!0;switch(t.type){case o:n.push(t.choice);break;case r:t.choice.choiceEl=void 0,n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:t.item.choiceEl=void 0;break;case a:var h=[];t.results.forEach((function(e){h[e.item.id]=e})),n.forEach((function(e){var t=h[e.id];void 0!==t?(e.score=t.score,e.rank=t.rank,e.active=!0):(e.score=0,e.rank=0,e.active=!1),i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case c:n.forEach((function(e){e.active=t.active,i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case l:n=[];break;default:s=!1}return{state:n,update:s}}},$=function(){function e(e){this._state=this.defaultState,this._listeners=[],this._txn=0,this._context=e}return Object.defineProperty(e.prototype,"defaultState",{get:function(){return{groups:[],items:[],choices:[]}},enumerable:!1,configurable:!0}),e.prototype.changeSet=function(e){return{groups:e,items:e,choices:e}},e.prototype.reset=function(){this._state=this.defaultState;var e=this.changeSet(!0);this._txn?this._changeSet=e:this._listeners.forEach((function(t){return t(e)}))},e.prototype.subscribe=function(e){this._listeners.push(e)},e.prototype.dispatch=function(e){var t=this,i=this._state,n=!1,s=this._changeSet||this.changeSet(!1);Object.keys(W).forEach((function(o){var r=W[o](i[o],e,t._context);r.update&&(n=!0,s[o]=!0,i[o]=r.state)})),n&&(this._txn?this._changeSet=s:this._listeners.forEach((function(e){return e(s)})))},e.prototype.withTxn=function(e){this._txn++;try{e()}finally{if(this._txn=Math.max(0,this._txn-1),!this._txn){var t=this._changeSet;t&&(this._changeSet=void 0,this._listeners.forEach((function(e){return e(t)})))}}},Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"items",{get:function(){return this.state.items},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"highlightedActiveItems",{get:function(){return this.items.filter((function(e){return!e.disabled&&e.active&&e.highlighted}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"choices",{get:function(){return this.state.choices},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeChoices",{get:function(){return this.choices.filter((function(e){return e.active}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"searchableChoices",{get:function(){return this.choices.filter((function(e){return!e.disabled&&!e.placeholder}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"groups",{get:function(){return this.state.groups},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeGroups",{get:function(){var e=this;return this.state.groups.filter((function(t){var i=t.active&&!t.disabled,n=e.state.choices.some((function(e){return e.active&&!e.disabled}));return i&&n}),[])},enumerable:!1,configurable:!0}),e.prototype.inTxn=function(){return this._txn>0},e.prototype.getChoiceById=function(e){return this.activeChoices.find((function(t){return t.id===e}))},e.prototype.getGroupById=function(e){return this.groups.find((function(t){return t.id===e}))},e}(),J="no-choices",z="no-results",X="add-choice";function Q(e,t,i){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function Y(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function Z(e){for(var t=1;t`Missing ${e} property in key`,ce=e=>`Property 'weight' in key '${e}' must be a positive integer`,le=Object.prototype.hasOwnProperty;class he{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=ue(e);this._keys.push(i),this._keyMap[i.id]=i,t+=i.weight})),this._keys.forEach((e=>{e.weight/=t}))}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}}function ue(e){let t=null,i=null,n=null,s=1,o=null;if(te(e)||ee(e))n=e,t=de(e),i=pe(e);else{if(!le.call(e,"name"))throw new Error(ae("name"));const r=e.name;if(n=r,le.call(e,"weight")&&(s=e.weight,s<=0))throw new Error(ce(r));t=de(r),i=pe(r),o=e.getFn}return{path:t,id:i,weight:s,src:n,getFn:o}}function de(e){return ee(e)?e:e.split(".")}function pe(e){return ee(e)?e.join("."):e}const fe={useExtendedSearch:!1,getFn:function(e,t){let i=[],n=!1;const s=(e,t,o)=>{if(se(e))if(t[o]){const r=e[t[o]];if(!se(r))return;if(o===t.length-1&&(te(r)||ie(r)||function(e){return!0===e||!1===e||function(e){return ne(e)&&null!==e}(e)&&"[object Boolean]"==re(e)}(r)))i.push(function(e){return null==e?"":function(e){if("string"==typeof e)return e;let t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(e)}(r));else if(ee(r)){n=!0;for(let e=0,i=r.length;ee.score===t.score?e.idx{this._keysMap[e.id]=t}))}create(){!this.isCreated&&this.docs.length&&(this.isCreated=!0,te(this.docs[0])?this.docs.forEach(((e,t)=>{this._addString(e,t)})):this.docs.forEach(((e,t)=>{this._addObject(e,t)})),this.norm.clear())}add(e){const t=this.size();te(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,i=this.size();t{let s=t.getFn?t.getFn(e):this.getFn(e,t.path);if(se(s))if(ee(s)){let e=[];const t=[{nestedArrIndex:-1,value:s}];for(;t.length;){const{nestedArrIndex:i,value:n}=t.pop();if(se(n))if(te(n)&&!oe(n)){let t={v:n,i:i,n:this.norm.get(n)};e.push(t)}else ee(n)&&n.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[n]=e}else if(te(s)&&!oe(s)){let e={v:s,n:this.norm.get(s)};i.$[n]=e}})),this.records.push(i)}toJSON(){return{keys:this.keys,records:this.records}}}function ge(e,t,{getFn:i=me.getFn,fieldNormWeight:n=me.fieldNormWeight}={}){const s=new _e({getFn:i,fieldNormWeight:n});return s.setKeys(e.map(ue)),s.setSources(t),s.create(),s}function ye(e,{errors:t=0,currentLocation:i=0,expectedLocation:n=0,distance:s=me.distance,ignoreLocation:o=me.ignoreLocation}={}){const r=t/e.length;if(o)return r;const a=Math.abs(n-i);return s?r+a/s:a?1:r}const be=32;function Ee(e){let t={};for(let i=0,n=e.length;i{this.chunks.push({pattern:e,alphabet:Ee(e),startIndex:t})},h=this.pattern.length;if(h>be){let e=0;const t=h%be,i=h-t;for(;e{const{isMatch:f,score:m,indices:v}=function(e,t,i,{location:n=me.location,distance:s=me.distance,threshold:o=me.threshold,findAllMatches:r=me.findAllMatches,minMatchCharLength:a=me.minMatchCharLength,includeMatches:c=me.includeMatches,ignoreLocation:l=me.ignoreLocation}={}){if(t.length>be)throw new Error("Pattern length exceeds max of 32.");const h=t.length,u=e.length,d=Math.max(0,Math.min(n,u));let p=o,f=d;const m=a>1||c,v=m?Array(u):[];let _;for(;(_=e.indexOf(t,f))>-1;){let e=ye(t,{currentLocation:_,expectedLocation:d,distance:s,ignoreLocation:l});if(p=Math.min(e,p),f=_+h,m){let e=0;for(;e=c;o-=1){let r=o-1,a=i[e.charAt(r)];if(m&&(v[r]=+!!a),C[o]=(C[o+1]<<1|1)&a,n&&(C[o]|=(g[o+1]|g[o])<<1|1|g[o+1]),C[o]&E&&(y=ye(t,{errors:n,currentLocation:r,expectedLocation:d,distance:s,ignoreLocation:l}),y<=p)){if(p=y,f=r,f<=d)break;c=Math.max(1,2*d-f)}}if(ye(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:l})>p)break;g=C}const C={isMatch:f>=0,score:Math.max(.001,y)};if(m){const e=function(e=[],t=me.minMatchCharLength){let i=[],n=-1,s=-1,o=0;for(let r=e.length;o=t&&i.push([n,s]),n=-1)}return e[o-1]&&o-n>=t&&i.push([n,o-1]),i}(v,a);e.length?c&&(C.indices=e):C.isMatch=!1}return C}(e,t,d,{location:n+p,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:a,includeMatches:i,ignoreLocation:c});f&&(u=!0),h+=m,f&&v&&(l=[...l,...v])}));let d={isMatch:u,score:u?h/this.chunks.length:1};return u&&i&&(d.indices=l),d}}const we=[];function Se(e,t){for(let i=0,n=we.length;i!(!e[Ie]&&!e.$or),Le=e=>({[Ie]:Object.keys(e).map((t=>({[t]:e[t]})))});function xe(e,t){const i=e.matches;t.matches=[],se(i)&&i.forEach((e=>{if(!se(e.indices)||!e.indices.length)return;const{indices:i,value:n}=e;let s={indices:i,value:n};e.key&&(s.key=e.key.src),e.idx>-1&&(s.refIndex=e.idx),t.matches.push(s)}))}function Te(e,t){t.score=e.score}class Ne{constructor(e,t={},i){if(this.options=Z(Z({},me),t),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new he(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof _e))throw new Error("Incorrect 'index' type");this._myIndex=t||ge(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){se(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let i=0,n=this._docs.length;i{let i=1;e.matches.forEach((({key:e,norm:n,score:s})=>{const o=e?e.weight:null;i*=Math.pow(0===s&&o?Number.EPSILON:s,(o||1)*(t?1:n))})),e.score=i}))}(a,{ignoreFieldNorm:r}),s&&a.sort(o),ie(t)&&t>-1&&(a=a.slice(0,t)),function(e,t,{includeMatches:i=me.includeMatches,includeScore:n=me.includeScore}={}){const s=[];return i&&s.push(xe),n&&s.push(Te),e.map((e=>{const{idx:i}=e,n={item:t[i],refIndex:i};return s.length&&s.forEach((t=>{t(e,n)})),n}))}(a,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(e){const t=Se(e,this.options),{records:i}=this._myIndex,n=[];return i.forEach((({v:e,i:i,n:s})=>{if(!se(e))return;const{isMatch:o,score:r,indices:a}=t.searchIn(e);o&&n.push({item:e,idx:i,matches:[{score:r,value:e,norm:s,indices:a}]})})),n}_searchLogical(e){throw new Error("Logical search is not available")}_searchObjectList(e){const t=Se(e,this.options),{keys:i,records:n}=this._myIndex,s=[];return n.forEach((({$:e,i:n})=>{if(!se(e))return;let o=[];i.forEach(((i,n)=>{o.push(...this._findMatches({key:i,value:e[n],searcher:t}))})),o.length&&s.push({idx:n,item:e,matches:o})})),s}_findMatches({key:e,value:t,searcher:i}){if(!se(t))return[];let n=[];if(ee(t))t.forEach((({v:t,i:s,n:o})=>{if(!se(t))return;const{isMatch:r,score:a,indices:c}=i.searchIn(t);r&&n.push({score:a,key:e,value:t,idx:s,norm:o,indices:c})}));else{const{v:s,n:o}=t,{isMatch:r,score:a,indices:c}=i.searchIn(s);r&&n.push({score:a,key:e,value:s,norm:o,indices:c})}return n}}Ne.version="7.0.0",Ne.createIndex=ge,Ne.parseIndex=function(e,{getFn:t=me.getFn,fieldNormWeight:i=me.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new _e({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},Ne.config=me,Ne.parseQuery=function(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Ae])(e);if(!o&&s.length>1&&!Oe(e))return n(Le(e));if((e=>!ee(e)&&ne(e)&&!Oe(e))(e)){const n=o?e[Ae]:s[0],r=o?e.$val:e[n];if(!te(r))throw new Error((e=>`Invalid value for key ${e}`)(n));const a={keyId:pe(n),pattern:r};return i&&(a.searcher=Se(r,t)),a}let r={children:[],operator:s[0]};return s.forEach((t=>{const i=e[t];ee(i)&&i.forEach((e=>{r.children.push(n(e))}))})),r};return Oe(e)||(e=Le(e)),n(e)};var Me=function(){function e(e){this._haystack=[],this._fuseOptions=i(i({},e.fuseOptions),{keys:n([],e.searchFields,!0),includeMatches:!0})}return e.prototype.index=function(e){this._haystack=e,this._fuse&&this._fuse.setCollection(e)},e.prototype.reset=function(){this._haystack=[],this._fuse=void 0},e.prototype.isEmptyIndex=function(){return!this._haystack.length},e.prototype.search=function(e){return this._fuse||(this._fuse=new Ne(this._haystack,this._fuseOptions)),this._fuse.search(e).map((function(e,t){return{item:e.item,score:e.score||0,rank:t+1}}))},e}(),Fe=function(e,t,i){var n=e.dataset,s=t.customProperties,o=t.labelClass,r=t.labelDescription;o&&(n.labelClass=T(o).join(" ")),r&&(n.labelDescription=r),i&&s&&("string"==typeof s?n.customProperties=s:"object"!=typeof s||function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}(s)||(n.customProperties=JSON.stringify(s)))},De=function(e,t,i){var n=t&&e.querySelector("label[for='".concat(t,"']")),s=n&&n.innerText;s&&i.setAttribute("aria-label",s)},ke={containerOuter:function(e,t,i,n,s,o,r){var a=e.classNames.containerOuter,c=document.createElement("div");return c.className=T(a).join(" "),c.dataset.type=o,t&&(c.dir=t),n&&(c.tabIndex=0),i&&(c.setAttribute("role",s?"combobox":"listbox"),s?c.setAttribute("aria-autocomplete","list"):r||De(this._docRoot,this.passedElement.element.id,c),c.setAttribute("aria-haspopup","true"),c.setAttribute("aria-expanded","false")),r&&c.setAttribute("aria-labelledby",r),c},containerInner:function(e){var t=e.classNames.containerInner,i=document.createElement("div");return i.className=T(t).join(" "),i},itemList:function(e,t){var i=e.searchEnabled,n=e.classNames,s=n.list,o=n.listSingle,r=n.listItems,a=document.createElement("div");return a.className="".concat(T(s).join(" ")," ").concat(t?T(o).join(" "):T(r).join(" ")),this._isSelectElement&&i&&a.setAttribute("role","listbox"),a},placeholder:function(e,t){var i=e.allowHTML,n=e.classNames.placeholder,s=document.createElement("div");return s.className=T(n).join(" "),L(s,i,t),s},item:function(e,t,i){var n,s,o,r=e.allowHTML,a=e.removeItemButtonAlignLeft,c=e.removeItemIconText,l=e.removeItemLabelText,h=e.classNames,u=h.item,d=h.button,p=h.highlightedState,f=h.itemSelectable,m=h.placeholder,v=A(t.value),_=document.createElement("div");if(_.className=T(u).join(" "),t.labelClass){var g=document.createElement("span");L(g,r,t.label),g.className=T(t.labelClass).join(" "),_.appendChild(g)}else L(_,r,t.label);if(_.dataset.item="",_.dataset.id=t.id,_.dataset.value=v,Fe(_,t,!0),(t.disabled||this.containerOuter.isDisabled)&&_.setAttribute("aria-disabled","true"),this._isSelectElement&&(_.setAttribute("aria-selected","true"),_.setAttribute("role","option")),t.placeholder&&((n=_.classList).add.apply(n,T(m)),_.dataset.placeholder=""),(s=_.classList).add.apply(s,T(t.highlighted?p:f)),i){t.disabled&&(o=_.classList).remove.apply(o,T(f)),_.dataset.deletable="";var y=document.createElement("button");y.type="button",y.className=T(d).join(" "),L(y,!0,S(c,t.value));var b=S(l,t.value);b&&y.setAttribute("aria-label",b),y.dataset.button="",a?_.insertAdjacentElement("afterbegin",y):_.appendChild(y)}return _},choiceList:function(e,t){var i=e.classNames.list,n=document.createElement("div");return n.className=T(i).join(" "),t||n.setAttribute("aria-multiselectable","true"),n.setAttribute("role","listbox"),n},choiceGroup:function(e,t){var i=e.allowHTML,n=e.classNames,s=n.group,o=n.groupHeading,r=n.itemDisabled,a=t.id,c=t.label,l=t.disabled,h=A(c),u=document.createElement("div");u.className="".concat(T(s).join(" ")," ").concat(l?T(r).join(" "):""),u.setAttribute("role","group"),u.dataset.group="",u.dataset.id=a,u.dataset.value=h,l&&u.setAttribute("aria-disabled","true");var d=document.createElement("div");return d.className=T(o).join(" "),L(d,i,c||""),u.appendChild(d),u},choice:function(e,t,i,n){var s,o,r,a,c,l=e.allowHTML,h=e.classNames,u=h.item,d=h.itemChoice,p=h.itemSelectable,f=h.selectedState,m=h.itemDisabled,v=h.description,_=h.placeholder,g=t.label,y=A(t.value),b=document.createElement("div");b.id=t.elementId,b.className="".concat(T(u).join(" ")," ").concat(T(d).join(" ")),n&&"string"==typeof g&&(g=O(l,g),g={trusted:g+=" (".concat(n,")")},b.dataset.groupId="".concat(t.groupId));var E=b;if(t.labelClass){var C=document.createElement("span");L(C,l,g),C.className=T(t.labelClass).join(" "),E=C,b.appendChild(C)}else L(b,l,g);if(t.labelDescription){var w="".concat(t.elementId,"-description");E.setAttribute("aria-describedby",w);var S=document.createElement("span");L(S,l,t.labelDescription),S.id=w,(s=S.classList).add.apply(s,T(v)),b.appendChild(S)}return t.selected&&(o=b.classList).add.apply(o,T(f)),t.placeholder&&(r=b.classList).add.apply(r,T(_)),b.setAttribute("role",t.groupId?"treeitem":"option"),b.dataset.choice="",b.dataset.id=t.id,b.dataset.value=y,i&&(b.dataset.selectText=i),Fe(b,t,!1),t.disabled?((a=b.classList).add.apply(a,T(m)),b.dataset.choiceDisabled="",b.setAttribute("aria-disabled","true")):((c=b.classList).add.apply(c,T(p)),b.dataset.choiceSelectable=""),b},input:function(e,t){var i=e.classNames,n=i.input,s=i.inputCloned,o=e.labelId,r=document.createElement("input");return r.type="search",r.className="".concat(T(n).join(" ")," ").concat(T(s).join(" ")),r.autocomplete="off",r.autocapitalize="off",r.spellcheck=!1,r.setAttribute("role","textbox"),r.setAttribute("aria-autocomplete","list"),t?r.setAttribute("aria-label",t):o||De(this._docRoot,this.passedElement.element.id,r),r},dropdown:function(e){var t,i,n=e.classNames,s=n.list,o=n.listDropdown,r=document.createElement("div");return(t=r.classList).add.apply(t,T(s)),(i=r.classList).add.apply(i,T(o)),r.setAttribute("aria-expanded","false"),r},notice:function(e,t,i){var s=e.classNames,o=s.itemChoice,r=s.addChoice,a=s.noResults,c=s.noChoices,l=s.notice;void 0===i&&(i="");var h=n(n(n([],T(s.item),!0),T(o),!0),T(l),!0);switch(i){case X:h.push.apply(h,T(r));break;case z:h.push.apply(h,T(a));break;case J:h.push.apply(h,T(c))}var u=document.createElement("div");return L(u,!0,t),u.className=h.join(" "),i===X&&(u.dataset.choiceSelectable="",u.dataset.choice=""),u},option:function(e){var t=A(e.label),i=new Option(t,e.value,!1,e.selected);return Fe(i,e,!0),i.disabled=e.disabled,e.selected&&i.setAttribute("selected",""),i}},Pe="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,je={},Ke=function(e){if(e)return e.dataset.id?parseInt(e.dataset.id,10):void 0},Be="[data-choice-selectable]";return function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this.initialisedOK=void 0,this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0;var o=e.defaults;this.config=i(i(i({},o.allOptions),o.options),n),_.forEach((function(e){s.config[e]=i(i(i({},o.allOptions[e]),o.options[e]),n[e])}));var r=this.config;r.silent||this._validateConfig();var a=r.shadowRoot||document.documentElement;this._docRoot=a;var c="string"==typeof t?a.querySelector(t):t;if(!c||"object"!=typeof c||"INPUT"!==c.tagName&&!R(c)){if(!c&&"string"==typeof t)throw TypeError("Selector ".concat(t," failed to find an element"));throw TypeError("Expected one of the following types text|select-one|select-multiple")}var l=c.type,h="text"===l;(h||1!==r.maxItemCount)&&(r.singleModeForMultiSelect=!1),r.singleModeForMultiSelect&&(l=y);var u=l===g,d=l===y,p=u||d;if(this._elementType=l,this._isTextElement=h,this._isSelectOneElement=u,this._isSelectMultipleElement=d,this._isSelectElement=u||d,this._canAddUserChoices=h&&r.addItems||p&&r.addChoices,"boolean"!=typeof r.renderSelectedChoices&&(r.renderSelectedChoices="always"===r.renderSelectedChoices||u),r.closeDropdownOnSelect="auto"===r.closeDropdownOnSelect?h||u||r.singleModeForMultiSelect:B(r.closeDropdownOnSelect),r.placeholder&&(r.placeholderValue?this._hasNonChoicePlaceholder=!0:c.dataset.placeholder&&(this._hasNonChoicePlaceholder=!0,r.placeholderValue=c.dataset.placeholder)),n.addItemFilter&&"function"!=typeof n.addItemFilter){var f=n.addItemFilter instanceof RegExp?n.addItemFilter:new RegExp(n.addItemFilter);r.addItemFilter=f.test.bind(f)}if(this.passedElement=this._isTextElement?new K({element:c,classNames:r.classNames}):new q({element:c,classNames:r.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:r.placeholder&&!this._hasNonChoicePlaceholder}),this.initialised=!1,this._store=new $(r),this._currentValue="",r.searchEnabled=!h&&r.searchEnabled||d,this._canSearch=r.searchEnabled,this._isScrollingOnIe=!1,this._highlightPosition=0,this._wasTap=!0,this._placeholderValue=this._generatePlaceholderValue(),this._baseId=function(e){var t=e.id||e.name&&"".concat(e.name,"-").concat(E(2))||E(4);return t=t.replace(/(:|\.|\[|\]|,)/g,""),"".concat("choices-","-").concat(t)}(c),this._direction=c.dir,!this._direction){var m=window.getComputedStyle(c).direction;m!==window.getComputedStyle(document.documentElement).direction&&(this._direction=m)}if(this._idNames={itemChoice:"item-choice"},this._templates=o.templates,this._render=this._render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onInput=this._onInput.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onFormReset=this._onFormReset.bind(this),this._onSelectKey=this._onSelectKey.bind(this),this._onEnterKey=this._onEnterKey.bind(this),this._onEscapeKey=this._onEscapeKey.bind(this),this._onDirectionKey=this._onDirectionKey.bind(this),this._onDeleteKey=this._onDeleteKey.bind(this),this.passedElement.isActive)return r.silent||console.warn("Trying to initialise Choices on element already initialised",{element:t}),this.initialised=!0,void(this.initialisedOK=!1);this.init(),this._initialItems=this._store.items.map((function(e){return e.value}))}return Object.defineProperty(e,"defaults",{get:function(){return Object.preventExtensions({get options(){return je},get allOptions(){return G},get templates(){return ke}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised&&void 0===this.initialisedOK){this._searcher=new Me(this.config),this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._isTextElement&&!this.config.addItems||this.passedElement.element.hasAttribute("disabled")||this.passedElement.element.closest("fieldset:disabled")?this.disable():(this.enable(),this._addEventListeners()),this._initStore(),this.initialised=!0,this.initialisedOK=!0;var e=this.config.callbackOnInit;"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this._store._listeners=[],this.clearStore(),this._stopSearch(),this._templates=e.defaults.templates,this.initialised=!1,this.initialisedOK=void 0)},e.prototype.enable=function(){return this.passedElement.isDisabled&&this.passedElement.enable(),this.containerOuter.isDisabled&&(this._addEventListeners(),this.input.enable(),this.containerOuter.enable()),this},e.prototype.disable=function(){return this.passedElement.isDisabled||this.passedElement.disable(),this.containerOuter.isDisabled||(this._removeEventListeners(),this.input.disable(),this.containerOuter.disable()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.items.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(b(i,!0)),t&&this.passedElement.triggerEvent(v,this._getChoiceForOutput(i))),this},e.prototype.unhighlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.items.find((function(t){return t.id===e.id}));return i&&i.highlighted?(this._store.dispatch(b(i,!1)),t&&this.passedElement.triggerEvent(v,this._getChoiceForOutput(i)),this):this},e.prototype.highlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){t.highlighted||(e._store.dispatch(b(t,!0)),e.passedElement.triggerEvent(v,e._getChoiceForOutput(t)))}))})),this},e.prototype.unhighlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){t.highlighted&&(e._store.dispatch(b(t,!1)),e.passedElement.triggerEvent(v,e._getChoiceForOutput(t)))}))})),this},e.prototype.removeActiveItemsByValue=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeActiveItems=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.withTxn((function(){t._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)}))})),this},e.prototype.showDropdown=function(e){var t=this;return this.dropdown.isActive||requestAnimationFrame((function(){t.dropdown.show();var i=t.dropdown.element.getBoundingClientRect();t.containerOuter.open(i.bottom,i.height),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent("showDropdown")})),this},e.prototype.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent("hideDropdown")})),this):this},e.prototype.getValue=function(e){var t=this;void 0===e&&(e=!1);var i=this._store.items.reduce((function(i,n){var s=e?n.value:t._getChoiceForOutput(n);return i.push(s),i}),[]);return this._isSelectOneElement||this.config.singleModeForMultiSelect?i[0]:i},e.prototype.setValue=function(e){var t=this;return this.initialisedOK?(this._store.withTxn((function(){e.forEach((function(e){e&&t._addChoice(V(e,!1))}))})),this._searcher.reset(),this):(this._warnChoicesInitFailed("setValue"),this)},e.prototype.setChoiceByValue=function(e){var t=this;return this.initialisedOK?(this._isTextElement||(this._store.withTxn((function(){(Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)})),t.unhighlightAll()})),this._searcher.reset()),this):(this._warnChoicesInitFailed("setChoiceByValue"),this)},e.prototype.setChoices=function(e,t,n,s){var o=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),!this.initialisedOK)return this._warnChoicesInitFailed("setChoices"),this;if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(s&&this.clearChoices(),"function"==typeof e){var r=e(this);if("function"==typeof Promise&&r instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return o._handleLoadingState(!0)})).then((function(){return r})).then((function(e){return o.setChoices(e,t,n,s)})).catch((function(e){o.config.silent||console.error(e)})).then((function(){return o._handleLoadingState(!1)})).then((function(){return o}));if(!Array.isArray(r))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof r));return this.setChoices(r,t,n,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._store.withTxn((function(){var s="value"===t,r="label"===n;e.forEach((function(e){if("choices"in e){var a=e;r||(a=i(i({},a),{label:a[n]})),o._addGroup(V(a,!0))}else{var c=e;r&&s||(c=i(i({},c),{value:c[t],label:c[n]})),o._addChoice(V(c,!1))}})),o.unhighlightAll()})),this._searcher.reset(),this},e.prototype.refresh=function(e,t,i){var n=this;return void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===i&&(i=!1),this._isSelectElement?(this._store.withTxn((function(){var s=n.passedElement.optionsAsChoices(),o={};i||n._store.items.forEach((function(e){e.id&&e.active&&e.selected&&!e.disabled&&(o[e.value]=!0)})),s.forEach((function(e){if(!("choices"in e)){var t=e;i?t.selected=!1:o[t.value]&&(t.selected=!0)}})),n.clearStore(),n._addPredefinedChoices(s,t,e),n._isSearching&&n._searchChoices(n.input.value)})),this):(this.config.silent||console.warn("refresh method can only be used on choices backed by a element"),this)},e.prototype.removeChoice=function(e){var t=this._store.choices.find((function(t){return t.value===e}));return t?(this._store.dispatch(function(e){return{type:r,choice:e}}(t)),this._searcher.reset(),t.selected&&this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(t)),this):this},e.prototype.clearChoices=function(){return this.passedElement.element.innerHTML="",this._store.dispatch({type:l}),this._searcher.reset(),this},e.prototype.clearStore=function(){return this._store.reset(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this._searcher.reset(),this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._clearNotice(),this._isSearching&&this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=R,t=Object.keys(n).sort(),i=Object.keys(e).sort(),t.filter((function(e){return i.indexOf(e)<0})));s.length&&console.warn("Unknown config option(s) passed",s.join(", ")),n.allowHTML&&n.allowHtmlUserInput&&(n.addItems&&console.warn("Warning: allowHTML/allowHtmlUserInput/addItems all being true is strongly not recommended and may lead to XSS attacks"),n.addChoices&&console.warn("Warning: allowHTML/allowHtmlUserInput/addChoices all being true is strongly not recommended and may lead to XSS attacks"))},e.prototype._render=function(e){void 0===e&&(e={choices:!0,groups:!0,items:!0}),this._store.inTxn()||(this._isSelectElement&&(e.choices||e.groups)&&this._renderChoices(),e.items&&this._renderItems())},e.prototype._renderChoices=function(){var e=this;if(this.choiceList.clear(),this._canAddItems()){var t=this.config,i=this._store,n=i.activeGroups,s=i.activeChoices,o=document.createDocumentFragment(),r=!0;if(s.length){if(t.resetScrollPosition&&requestAnimationFrame((function(){return e.choiceList.scrollToTop()})),n.length&&!this._isSearching){if(!this._hasNonChoicePlaceholder){var a=s.filter((function(e){return e.placeholder&&-1===e.groupId}));a.length&&(o=this._createChoicesFragment(a,o))}o=this._createGroupsFragment(n,s,o)}else o=this._createChoicesFragment(s,o);r=!o.childNodes.length}var c=this._notice;r?c||(this._notice={text:b(t.noChoicesText),type:U}):c&&c.type===U&&(this._notice=void 0),this._renderNotice(),r||(this.choiceList.element.append(o),this._highlightChoice())}},e.prototype._renderItems=function(){var e=this._store.items||[];this.itemList.clear();var t=this._createItemsFragment(e);t.childNodes.length&&this.itemList.element.append(t)},e.prototype._createGroupsFragment=function(e,t,i){var n=this;void 0===i&&(i=document.createDocumentFragment());var s=this.config;s.shouldSort&&e.sort(s.sorter);var o=t.filter((function(e){return!e.groupId}));return o.length&&this._createChoicesFragment(o,i,!1),e.forEach((function(e){var o=function(e){return t.filter((function(t){return n._isSelectOneElement?t.groupId===e.id:t.groupId===e.id&&("always"===s.renderSelectedChoices||!t.selected)}))}(e);if(o.length){var r=n._templates.choiceGroup(n.config,e);i.appendChild(r),n._createChoicesFragment(o,i,!0)}})),i},e.prototype._createChoicesFragment=function(e,t,i){var s=this;void 0===t&&(t=document.createDocumentFragment()),void 0===i&&(i=!1);var o=this,r=o.config,a=o._isSearching,c=o._isSelectOneElement,l=r.searchResultLimit,h=r.renderChoiceLimit,u=[],d=r.appendGroupInSearch&&a;if(d&&this._store.groups.forEach((function(e){u[e.id]=e.label})),this._isSelectElement){var p=e.filter((function(e){return!e.element}));p.length&&this.passedElement.addOptions(p)}var m="auto"===r.renderSelectedChoices&&!c,f=[],v=[];e.forEach((function(e){a&&!e.rank||m&&e.selected||(s._hasNonChoicePlaceholder||!e.placeholder?v.push(e):f.push(e))})),a?v.sort(w):r.shouldSort&&v.sort(r.sorter);var _=c&&f.length?n(n([],f,!0),v,!0):v,g=_.length,y=g;return a&&l>0?y=l:h>0&&!i&&(y=h),y0){var o=u[e.groupId];o&&(n.innerHTML+=" (".concat(o,")"))}return t.appendChild(n),i0?this._store.getGroupById(e.groupId):null;return{id:e.id,highlighted:e.highlighted,labelClass:e.labelClass,labelDescription:e.labelDescription,customProperties:e.customProperties,disabled:e.disabled,active:e.active,label:e.label,placeholder:e.placeholder,value:e.value,groupValue:i&&i.label?i.label:void 0,element:e.element,keyCode:t}}},e.prototype._triggerChange=function(e){null!=e&&this.passedElement.triggerEvent("change",{value:e})},e.prototype._handleButtonAction=function(e){var t=this._store.items;if(t.length&&this.config.removeItems&&this.config.removeItemButton){var i=e&&ee(e.parentNode),n=i&&t.find((function(e){return e.id===i}));if(n&&(this._removeItem(n),this._triggerChange(n.value),this._isSelectOneElement&&!this._hasNonChoicePlaceholder)){var s=this._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));s&&(this._addItem(s),s.value&&this._triggerChange(s.value))}}},e.prototype._handleItemAction=function(e,t){var i=this;void 0===t&&(t=!1);var n=this._store.items;if(n.length&&this.config.removeItems&&!this._isSelectOneElement){var s=ee(e);s&&(n.forEach((function(e){e.id!==s||e.highlighted?!t&&e.highlighted&&i.unhighlightItem(e):i.highlightItem(e)})),this.input.focus())}},e.prototype._handleChoiceAction=function(e){var t=this,i=ee(e),n=i&&this._store.getChoiceById(i);if(!n||n.disabled)return!1;var s=this.dropdown.isActive;if(!n.selected){if(!this._canAddItems())return!0;this._store.withTxn((function(){t._addItem(n,!0,!0),t.clearInput(),t.unhighlightAll()})),this._triggerChange(n.value)}return s&&this.config.closeDropdownOnSelect&&(this.hideDropdown(!0),this.containerOuter.element.focus()),!0},e.prototype._handleBackspace=function(e){var t=this.config;if(t.removeItems&&e.length){var i=e[e.length-1],n=e.some((function(e){return e.highlighted}));t.editItems&&!n&&i?(this.input.value=i.value,this.input.setWidth(),this._removeItem(i),this._triggerChange(i.value)):(n||this.highlightItem(i,!1),this.removeHighlightedItems(!0))}},e.prototype._loadChoices=function(){var e,t=this.config;if(this._isTextElement){this._presetChoices=t.items.map((function(e){return H(e,!1)}));var i=this.passedElement.value;if(i){var n=i.split(t.delimiter).map((function(e){return H(e,!1)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=t.choices.map((function(e){return H(e,!0)}));var s=this.passedElement.optionsAsChoices();s&&(e=this._presetChoices).push.apply(e,s)}},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.config;e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?(this.itemList.clear(),this.itemList.element.append(this._templates.placeholder(t,t.loadingText))):this.input.placeholder=t.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement||(this.input.placeholder=this._placeholderValue||""))},e.prototype._handleSearch=function(e){if(this.input.isFocussed){var t=this.config,i=t.searchFloor,n=t.searchChoices,s=this._store.choices.some((function(e){return!e.active}));if(null!=e&&e.length>=i){var o=n?this._searchChoices(e):0;null!==o&&this.passedElement.triggerEvent("search",{value:e,resultCount:o})}else s&&this._stopSearch()}},e.prototype._canAddItems=function(){var e=this.config,t=e.maxItemCount,i=e.maxItemText;return!(!e.singleModeForMultiSelect&&t>0&&t<=this._store.items.length&&(this._displayNotice("function"==typeof i?i(t):i,X),1))},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=y(t.customAddItemText,e)),i){var s=this._store.choices.find((function(i){return t.valueComparer(i.value,e)}));if(this._isSelectElement){if(s)return this._displayNotice("",X),!1}else this._isTextElement&&!t.duplicateItemsAllowed&&s&&(i=!1,n=y(t.uniqueItemText,e))}return i&&(n=y(t.addItemText,e)),n&&this._displayNotice(n,X),i},e.prototype._searchChoices=function(e){var t=e.trim().replace(/\s{2,}/," ");if(!t.length||t===this._currentValue)return null;var i=this._searcher;i.isEmptyIndex()&&i.index(this._store.searchableChoices);var n=i.search(t);this._currentValue=t,this._highlightPosition=0,this._isSearching=!0;var s=this._notice,o=s&&s.type;return o!==X&&(n.length?o===W&&this._clearNotice():this._displayNotice(b(this.config.noResultsText),W)),this._store.dispatch(function(e){return{type:a,results:e}}(n)),n.length},e.prototype._stopSearch=function(){var e=this._isSearching;this._currentValue="",this._isSearching=!1,e&&(this._store.dispatch({type:c,active:!0}),this.passedElement.triggerEvent("search",{value:"",resultCount:0}))},e.prototype._addEventListeners=function(){var e=this._docRoot,t=this.containerOuter.element,i=this.input.element;e.addEventListener("touchend",this._onTouchEnd,!0),t.addEventListener("keydown",this._onKeyDown,!0),t.addEventListener("mousedown",this._onMouseDown,!0),e.addEventListener("click",this._onClick,{passive:!0}),e.addEventListener("touchmove",this._onTouchMove,{passive:!0}),this.dropdown.element.addEventListener("mouseover",this._onMouseOver,{passive:!0}),this._isSelectOneElement&&(t.addEventListener("focus",this._onFocus,{passive:!0}),t.addEventListener("blur",this._onBlur,{passive:!0})),i.addEventListener("keyup",this._onKeyUp,{passive:!0}),i.addEventListener("input",this._onInput,{passive:!0}),i.addEventListener("focus",this._onFocus,{passive:!0}),i.addEventListener("blur",this._onBlur,{passive:!0}),i.form&&i.form.addEventListener("reset",this._onFormReset,{passive:!0}),this.input.addEventListeners()},e.prototype._removeEventListeners=function(){var e=this._docRoot,t=this.containerOuter.element,i=this.input.element;e.removeEventListener("touchend",this._onTouchEnd,!0),t.removeEventListener("keydown",this._onKeyDown,!0),t.removeEventListener("mousedown",this._onMouseDown,!0),e.removeEventListener("click",this._onClick),e.removeEventListener("touchmove",this._onTouchMove),this.dropdown.element.removeEventListener("mouseover",this._onMouseOver),this._isSelectOneElement&&(t.removeEventListener("focus",this._onFocus),t.removeEventListener("blur",this._onBlur)),i.removeEventListener("keyup",this._onKeyUp),i.removeEventListener("input",this._onInput),i.removeEventListener("focus",this._onFocus),i.removeEventListener("blur",this._onBlur),i.form&&i.form.removeEventListener("reset",this._onFormReset),this.input.removeEventListeners()},e.prototype._onKeyDown=function(e){var t=e.keyCode,i=this.dropdown.isActive,n=1===e.key.length||2===e.key.length&&e.key.charCodeAt(0)>=55296||"Unidentified"===e.key;switch(this._isTextElement||i||(this.showDropdown(),!this.input.isFocussed&&n&&(this.input.value+=e.key," "===e.key&&e.preventDefault())),t){case 65:return this._onSelectKey(e,this.itemList.element.hasChildNodes());case 13:return this._onEnterKey(e,i);case 27:return this._onEscapeKey(e,i);case 38:case 33:case 40:case 34:return this._onDirectionKey(e,i);case 8:case 46:return this._onDeleteKey(e,this._store.items,this.input.isFocussed)}},e.prototype._onKeyUp=function(){this._canSearch=this.config.searchEnabled},e.prototype._onInput=function(){var e=this.input.value;if(!e)return this._isTextElement?this.hideDropdown(!0):this._stopSearch(),void this._clearNotice();this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice())))},e.prototype._onSelectKey=function(e,t){(e.ctrlKey||e.metaKey)&&t&&(this._canSearch=!1,this.config.removeItems&&!this.input.value&&this.input.element===document.activeElement&&this.highlightAll())},e.prototype._onEnterKey=function(e,t){var i=this,n=this.config,s=this.input.value,o=e.target,r=o&&o.hasAttribute("data-button");if(e.preventDefault(),r)this._handleButtonAction(o);else if(t){var a=this.dropdown.element.querySelector(A(n.classNames.highlightedState));if(!a||!this._handleChoiceAction(a))if(o&&s){if(this._canAddItems()){var c=!1;this._store.withTxn((function(){if(!(c=i._findAndSelectChoiceByValue(s,!0))){if(!i._canAddUserChoices)return;if(!i._canCreateItem(s))return;var e=_(s),t=n.allowHtmlUserInput||e===s?s:{escaped:e,raw:s};i._addChoice(H({value:t,label:t,selected:!0},!1),!0,!0),c=!0}i.clearInput(),i.unhighlightAll()})),c&&(this._triggerChange(s),n.closeDropdownOnSelect&&this.hideDropdown(!0))}}else this.hideDropdown(!0)}else(this._isSelectElement||this._notice)&&this.showDropdown()},e.prototype._onEscapeKey=function(e,t){t&&(e.stopPropagation(),this.hideDropdown(!0),this.containerOuter.element.focus())},e.prototype._onDirectionKey=function(e,t){var i,n,s,o=e.keyCode,r=e.metaKey;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var a=40===o||34===o?1:-1,c="[data-choice-selectable]",l=void 0;if(r||34===o||33===o)l=this.dropdown.element.querySelector(a>0?"".concat(c,":last-of-type"):c);else{var h=this.dropdown.element.querySelector(A(this.config.classNames.highlightedState));l=h?function(e,t,i){void 0===i&&(i=1);for(var n="".concat(i>0?"next":"previous","ElementSibling"),s=e[n];s;){if(s.matches(t))return s;s=s[n]}return null}(h,c,a):this.dropdown.element.querySelector(c)}l&&(i=l,n=this.choiceList.element,void 0===(s=a)&&(s=1),(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(l,a),this._highlightChoice(l)),e.preventDefault()}},e.prototype._onDeleteKey=function(e,t,i){this._isSelectOneElement||e.target.value||!i||(this._handleBackspace(t),e.preventDefault())},e.prototype._onTouchMove=function(){this._wasTap&&(this._wasTap=!1)},e.prototype._onTouchEnd=function(e){var t=(e||e.touches[0]).target;this._wasTap&&this.containerOuter.element.contains(t)&&((t===this.containerOuter.element||t===this.containerInner.element)&&(this._isTextElement?this.input.focus():this._isSelectMultipleElement&&this.showDropdown()),e.stopPropagation()),this._wasTap=!0},e.prototype._onMouseDown=function(e){var t=e.target;if(t instanceof HTMLElement){if(Z&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?n[this._highlightPosition]:n[n.length-1])||(s=n[0]),(t=s.classList).add.apply(t,I(i)),s.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:s}),this.dropdown.isActive&&(this.input.setActiveDescendant(s.id),this.containerOuter.setActiveDescendant(s.id))}},e.prototype._addItem=function(e,t,i){void 0===t&&(t=!0),void 0===i&&(i=!1);var n=e.id;if(!n)throw new TypeError("item.id must be set before _addItem is called for a choice/item");(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&this.removeActiveItems(n),this._store.dispatch(function(e){return{type:u,item:e}}(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){e.id&&(this._store.dispatch(function(e){return{type:d,item:e}}(e)),this.passedElement.triggerEvent("removeItem",this._getChoiceForOutput(e)))},e.prototype._addChoice=function(e,t,i){if(void 0===t&&(t=!0),void 0===i&&(i=!1),e.id)throw new TypeError("Can not re-add a choice which has already been added");this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var n=this.config,s=n.prependValue,r=n.appendValue;s&&(e.value=s+e.value),r&&(e.value+=r.toString()),(s||r)&&e.element&&(e.element.value=e.value),this._store.dispatch(function(e){return{type:o,choice:e}}(e)),e.selected&&this._addItem(e,t,i)},e.prototype._addGroup=function(e,t){var i=this;if(void 0===t&&(t=!0),e.id)throw new TypeError("Can not re-add a group which has already been added");if(this._store.dispatch(function(e){return{type:h,group:e}}(e)),e.choices){var n=e;this._lastAddedGroupId++,n.id=this._lastAddedGroupId;var s=e.id,o=e.choices;n.choices=[],o.forEach((function(n){n.groupId=s,e.disabled&&(n.disabled=!0),i._addChoice(n,t)}))}},e.prototype._createTemplates=function(){var e=this,t=this.config.callbackOnCreateTemplates,i={};t&&"function"==typeof t&&(i=t.call(this,g,C));var n={};Object.keys(this._templates).forEach((function(t){n[t]=t in i?i[t].bind(e):e._templates[t].bind(e)})),this._templates=n},e.prototype._createElements=function(){var e=this._templates,t=this.config,i=t.position,n=t.classNames,s=this._elementType;this.containerOuter=new D({element:e.containerOuter(t,this._direction,this._isSelectElement,this._isSelectOneElement,t.searchEnabled,s,t.labelId),classNames:n,type:s,position:i}),this.containerInner=new D({element:e.containerInner(t),classNames:n,type:s,position:i}),this.input=new F({element:e.input(t,this._placeholderValue),classNames:n,type:s,preventPaste:!t.paste}),this.choiceList=new P({element:e.choiceList(t,this._isSelectOneElement)}),this.itemList=new P({element:e.itemList(t,this._isSelectOneElement)}),this.dropdown=new O({element:e.dropdown(t),classNames:n,type:s})},e.prototype._createStructure=function(){var e=this,t=e.containerInner,i=e.containerOuter,n=e.passedElement,s=e.dropdown,o=e.input;n.conceal(),t.wrap(n.element),i.wrap(t.element),this._isSelectOneElement?o.placeholder=this.config.searchPlaceholderValue||"":(this._placeholderValue&&(o.placeholder=this._placeholderValue),o.setWidth()),i.element.appendChild(t.element),i.element.appendChild(s.element),t.element.appendChild(this.itemList.element),s.element.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&s.element.insertBefore(o.element,s.element.firstChild):t.element.appendChild(o.element),this._highlightPosition=0,this._isSearching=!1},e.prototype._initStore=function(){var e=this;this._store.subscribe(this._render),this._store.withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),this._isSelectOneElement&&this._hasNonChoicePlaceholder&&this._render({choices:!1,groups:!1,items:!0})},e.prototype._addPredefinedChoices=function(e,t,i){var n=this;void 0===t&&(t=!1),void 0===i&&(i=!0),t&&-1===e.findIndex((function(e){return e.selected}))&&e.some((function(e){return!e.disabled&&!("choices"in e)&&(e.selected=!0,!0)})),e.forEach((function(e){"choices"in e?n._isSelectElement&&n._addGroup(e,i):n._addChoice(e,i)}))},e.prototype._findAndSelectChoiceByValue=function(e,t){var i=this;void 0===t&&(t=!1);var n=this._store.choices.find((function(t){return i.config.valueComparer(t.value,e)}));return!(!n||n.disabled||n.selected||(this._addItem(n,!0,t),0))},e.prototype._generatePlaceholderValue=function(){var e=this.config;if(!e.placeholder)return null;if(this._hasNonChoicePlaceholder)return e.placeholderValue;if(this._isSelectElement){var t=this.passedElement.placeholderOption;return t?t.text:null}return null},e.prototype._warnChoicesInitFailed=function(e){if(!this.config.silent){if(!this.initialised)throw new TypeError("".concat(e," called on a non-initialised instance of Choices"));if(!this.initialisedOK)throw new TypeError("".concat(e," called for an element which has multiple instances of Choices initialised on it"))}},e.version="11.0.0-rc8",e}()})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Choices=t()}(this,(function(){"use strict";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},e(t,i)};function t(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,i=1,n=arguments.length;i/g,">").replace(/=0&&!window.matchMedia("(min-height: ".concat(e+1,"px)")).matches:"top"===this.position&&(i=!0),i},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype.open=function(e,t){var i,n;(i=this.element.classList).add.apply(i,x(this.classNames.openState)),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&((n=this.element.classList).add.apply(n,x(this.classNames.flippedState)),this.isFlipped=!0)},e.prototype.close=function(){var e,t;(e=this.element.classList).remove.apply(e,x(this.classNames.openState)),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&((t=this.element.classList).remove.apply(t,x(this.classNames.flippedState)),this.isFlipped=!1)},e.prototype.addFocusState=function(){var e;(e=this.element.classList).add.apply(e,x(this.classNames.focusState))},e.prototype.removeFocusState=function(){var e;(e=this.element.classList).remove.apply(e,x(this.classNames.focusState))},e.prototype.enable=function(){var e;(e=this.element.classList).remove.apply(e,x(this.classNames.disabledState)),this.element.removeAttribute("aria-disabled"),this.type===g&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){var e;(e=this.element.classList).add.apply(e,x(this.classNames.disabledState)),this.element.setAttribute("aria-disabled","true"),this.type===g&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=this.element,i=e.parentNode;i&&(e.nextSibling?i.insertBefore(t,e.nextSibling):i.appendChild(t)),t.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element,i=t.parentNode;i&&(i.insertBefore(e,t),i.removeChild(t))},e.prototype.addLoadingState=function(){var e;(e=this.element.classList).add.apply(e,x(this.classNames.loadingState)),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){var e;(e=this.element.classList).remove.apply(e,x(this.classNames.loadingState)),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),k=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,s=e.preventPaste;this.element=t,this.type=i,this.classNames=n,this.preventPaste=s,this.isFocussed=this.element.isEqualNode(document.activeElement),this.isDisabled=t.disabled,this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}return Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.element.placeholder=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.addEventListeners=function(){var e=this.element;e.addEventListener("paste",this._onPaste),e.addEventListener("input",this._onInput,{passive:!0}),e.addEventListener("focus",this._onFocus,{passive:!0}),e.addEventListener("blur",this._onBlur,{passive:!0})},e.prototype.removeEventListeners=function(){var e=this.element;e.removeEventListener("input",this._onInput),e.removeEventListener("paste",this._onPaste),e.removeEventListener("focus",this._onFocus),e.removeEventListener("blur",this._onBlur)},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.isDisabled=!0},e.prototype.focus=function(){this.isFocussed||this.element.focus()},e.prototype.blur=function(){this.isFocussed&&this.element.blur()},e.prototype.clear=function(e){return void 0===e&&(e=!0),this.element.value="",e&&this.setWidth(),this},e.prototype.setWidth=function(){var e=this.element;e.style.minWidth="".concat(e.placeholder.length+1,"ch"),e.style.width="".concat(e.value.length+1,"ch")},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype._onInput=function(){this.type!==g&&this.setWidth()},e.prototype._onPaste=function(e){this.preventPaste&&e.preventDefault()},e.prototype._onFocus=function(){this.isFocussed=!0},e.prototype._onBlur=function(){this.isFocussed=!1},e}(),j=function(){function e(e){this.element=e.element,this.scrollPos=this.element.scrollTop,this.height=this.element.offsetHeight}return e.prototype.prepend=function(e){var t=this.element.firstElementChild;t?this.element.insertBefore(e,t):this.element.append(e)},e.prototype.scrollToTop=function(){this.element.scrollTop=0},e.prototype.scrollToChildElement=function(e,t){var i=this;if(e){var n=t>0?this.element.scrollTop+(e.offsetTop+e.offsetHeight)-(this.element.scrollTop+this.element.offsetHeight):e.offsetTop;requestAnimationFrame((function(){i._animateScroll(n,t)}))}},e.prototype._scrollDown=function(e,t,i){var n=(i-e)/t;this.element.scrollTop=e+(n>1?n:1)},e.prototype._scrollUp=function(e,t,i){var n=(e-i)/t;this.element.scrollTop=e-(n>1?n:1)},e.prototype._animateScroll=function(e,t){var i=this,n=this.element.scrollTop,s=!1;t>0?(this._scrollDown(n,4,e),ne&&(s=!0)),s&&requestAnimationFrame((function(){i._animateScroll(e,t)}))},e}(),M=function(){function e(e){var t=e.classNames;this.element=e.element,this.classNames=t,this.isDisabled=!1}return Object.defineProperty(e.prototype,"isActive",{get:function(){return"active"===this.element.dataset.choice},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dir",{get:function(){return this.element.dir},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.setAttribute("value",e),this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.conceal=function(){var e,t=this.element;(e=t.classList).add.apply(e,x(this.classNames.input)),t.hidden=!0,t.tabIndex=-1;var i=t.getAttribute("style");i&&t.setAttribute("data-choice-orig-style",i),t.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e,t=this.element;(e=t.classList).remove.apply(e,x(this.classNames.input)),t.hidden=!1,t.removeAttribute("tabindex");var i=t.getAttribute("data-choice-orig-style");i?(t.removeAttribute("data-choice-orig-style"),t.setAttribute("style",i)):t.removeAttribute("style"),t.removeAttribute("data-choice")},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.element.disabled=!1,this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.element.disabled=!0,this.isDisabled=!0},e.prototype.triggerEvent=function(e,t){var i;void 0===(i=t||{})&&(i=null),this.element.dispatchEvent(new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0}))},e}(),K=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(M),B=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},H=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},V=function(e,t){if("string"==typeof e)return V({value:e,label:e},!1);var i=e;if("choices"in i){if(!t)throw new TypeError("optGroup is not allowed");var n=i,s=n.choices.map((function(e){return V(e,!1)}));return{id:0,label:A(n.label)||n.value,active:!!s.length,disabled:!!n.disabled,choices:s}}var o=i;return{id:0,groupId:0,score:0,rank:0,value:o.value,label:o.label||o.value,active:B(o.active),selected:B(o.selected,!1),disabled:B(o.disabled,!1),placeholder:B(o.placeholder,!1),highlighted:!1,labelClass:H(o.labelClass),labelDescription:o.labelDescription,customProperties:o.customProperties}},R=function(e){return"SELECT"===e.tagName},q=function(e){function i(t){var i=t.template,n=t.extractPlaceholder,s=e.call(this,{element:t.element,classNames:t.classNames})||this;return s.template=i,s.extractPlaceholder=n,s}return t(i,e),Object.defineProperty(i.prototype,"placeholderOption",{get:function(){return this.element.querySelector('option[value=""]')||this.element.querySelector("option[placeholder]")},enumerable:!1,configurable:!0}),i.prototype.addOptions=function(e){var t=this,i=document.createDocumentFragment();e.forEach((function(e){var n=e;if(!n.element){var s=t.template(n);i.appendChild(s),n.element=s}})),this.element.appendChild(i)},i.prototype.optionsAsChoices=function(){var e=this,t=[];return this.element.querySelectorAll(":scope > option, :scope > optgroup").forEach((function(i){!function(e){return"OPTION"===e.tagName}(i)?function(e){return"OPTGROUP"===e.tagName}(i)&&t.push(e._optgroupToChoice(i)):t.push(e._optionToChoice(i))})),t},i.prototype._optionToChoice=function(e){return!e.hasAttribute("value")&&e.hasAttribute("placeholder")&&(e.setAttribute("value",""),e.value=""),{id:0,groupId:0,score:0,rank:0,value:e.value,label:e.innerHTML,element:e,active:!0,selected:this.extractPlaceholder?e.selected:e.hasAttribute("selected"),disabled:e.disabled,highlighted:!1,placeholder:this.extractPlaceholder&&(!e.value||e.hasAttribute("placeholder")),labelClass:void 0!==e.dataset.labelClass?H(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:D(e.dataset.customProperties)}},i.prototype._optgroupToChoice=function(e){var t=this,i=e.querySelectorAll("option"),n=Array.from(i).map((function(e){return t._optionToChoice(e)}));return{id:0,label:e.label||"",element:e,active:!!n.length,disabled:e.disabled,choices:n}},i}(M),G={items:[],choices:[],silent:!1,renderChoiceLimit:-1,maxItemCount:-1,closeDropdownOnSelect:"auto",singleModeForMultiSelect:!1,addChoices:!1,addItems:!0,addItemFilter:function(e){return!!e&&""!==e},removeItems:!0,removeItemButton:!1,removeItemButtonAlignLeft:!1,editItems:!1,allowHTML:!1,allowHtmlUserInput:!1,duplicateItemsAllowed:!0,delimiter:",",paste:!0,searchEnabled:!0,searchChoices:!0,searchFloor:1,searchResultLimit:4,searchFields:["label","value"],position:"auto",resetScrollPosition:!0,shouldSort:!0,shouldSortItems:!1,sorter:function(e,t){var i=e.label,n=t.label,s=void 0===n?t.value:n;return A(void 0===i?e.value:i).localeCompare(A(s),[],{sensitivity:"base",ignorePunctuation:!0,numeric:!0})},shadowRoot:null,placeholder:!0,placeholderValue:null,searchPlaceholderValue:null,prependValue:null,appendValue:null,renderSelectedChoices:"auto",loadingText:"Loading...",noResultsText:"No results found",noChoicesText:"No choices to choose from",itemSelectText:"Press to select",uniqueItemText:"Only unique values can be added",customAddItemText:"Only values matching specific conditions can be added",addItemText:function(e){return'Press Enter to add "'.concat(e,'"')},removeItemIconText:function(){return"Remove item"},removeItemLabelText:function(e){return"Remove item: ".concat(e)},maxItemText:function(e){return"Only ".concat(e," values can be added")},valueComparer:function(e,t){return e===t},fuseOptions:{includeScore:!0},labelId:"",callbackOnInit:null,callbackOnCreateTemplates:null,classNames:{containerOuter:["choices"],containerInner:["choices__inner"],input:["choices__input"],inputCloned:["choices__input--cloned"],list:["choices__list"],listItems:["choices__list--multiple"],listSingle:["choices__list--single"],listDropdown:["choices__list--dropdown"],item:["choices__item"],itemSelectable:["choices__item--selectable"],itemDisabled:["choices__item--disabled"],itemChoice:["choices__item--choice"],description:["choices__description"],placeholder:["choices__placeholder"],group:["choices__group"],groupHeading:["choices__heading"],button:["choices__button"],activeState:["is-active"],focusState:["is-focused"],openState:["is-open"],disabledState:["is-disabled"],highlightedState:["is-highlighted"],selectedState:["is-selected"],flippedState:["is-flipped"],loadingState:["is-loading"],notice:["choices__notice"],addChoice:["choices__item--selectable","add-choice"],noResults:["has-no-results"],noChoices:["has-no-choices"]},appendGroupInSearch:!1},U=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},W={groups:function(e,t){var i=e,n=!0;switch(t.type){case h:i.push(t.group);break;case l:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t,i){var n=e,s=!0;switch(t.type){case d:t.item.selected=!0,(o=t.item.element)&&(o.selected=!0,o.setAttribute("selected","")),n.push(t.item);break;case u:var o;if(t.item.selected=!1,o=t.item.element){o.selected=!1,o.removeAttribute("selected");var a=o.parentElement;a&&R(a)&&a.type===g&&(a.value="")}U(t.item),n=n.filter((function(e){return e.id!==t.item.id}));break;case r:n=n.filter((function(e){return e.id!==t.choice.id})),U(t.choice);break;case p:var c=t.highlighted,l=n.find((function(e){return e.id===t.item.id}));l&&l.highlighted!==c&&(l.highlighted=c,i&&function(e,t,i){var n,s,o=e.itemEl;o&&((n=o.classList).remove.apply(n,x(i)),(s=o.classList).add.apply(s,x(t)))}(l,c?i.classNames.highlightedState:i.classNames.selectedState,c?i.classNames.selectedState:i.classNames.highlightedState));break;default:s=!1}return{state:n,update:s}},choices:function(e,t,i){var n=e,s=!0;switch(t.type){case o:n.push(t.choice);break;case r:t.choice.choiceEl=void 0,n=n.filter((function(e){return e.id!==t.choice.id}));break;case d:case u:t.item.choiceEl=void 0;break;case a:var h=[];t.results.forEach((function(e){h[e.item.id]=e})),n.forEach((function(e){var t=h[e.id];void 0!==t?(e.score=t.score,e.rank=t.rank,e.active=!0):(e.score=0,e.rank=0,e.active=!1),i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case c:n.forEach((function(e){e.active=t.active,i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case l:n=[];break;default:s=!1}return{state:n,update:s}}},X=function(){function e(e){this._state=this.defaultState,this._listeners=[],this._txn=0,this._context=e}return Object.defineProperty(e.prototype,"defaultState",{get:function(){return{groups:[],items:[],choices:[]}},enumerable:!1,configurable:!0}),e.prototype.changeSet=function(e){return{groups:e,items:e,choices:e}},e.prototype.reset=function(){this._state=this.defaultState;var e=this.changeSet(!0);this._txn?this._changeSet=e:this._listeners.forEach((function(t){return t(e)}))},e.prototype.subscribe=function(e){this._listeners.push(e)},e.prototype.dispatch=function(e){var t=this,i=this._state,n=!1,s=this._changeSet||this.changeSet(!1);Object.keys(W).forEach((function(o){var r=W[o](i[o],e,t._context);r.update&&(n=!0,s[o]=!0,i[o]=r.state)})),n&&(this._txn?this._changeSet=s:this._listeners.forEach((function(e){return e(s)})))},e.prototype.withTxn=function(e){this._txn++;try{e()}finally{if(this._txn=Math.max(0,this._txn-1),!this._txn){var t=this._changeSet;t&&(this._changeSet=void 0,this._listeners.forEach((function(e){return e(t)})))}}},Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"items",{get:function(){return this.state.items},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"highlightedActiveItems",{get:function(){return this.items.filter((function(e){return!e.disabled&&e.active&&e.highlighted}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"choices",{get:function(){return this.state.choices},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeChoices",{get:function(){return this.choices.filter((function(e){return e.active}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"searchableChoices",{get:function(){return this.choices.filter((function(e){return!e.disabled&&!e.placeholder}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"groups",{get:function(){return this.state.groups},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"activeGroups",{get:function(){var e=this;return this.state.groups.filter((function(t){var i=t.active&&!t.disabled,n=e.state.choices.some((function(e){return e.active&&!e.disabled}));return i&&n}),[])},enumerable:!1,configurable:!0}),e.prototype.inTxn=function(){return this._txn>0},e.prototype.getChoiceById=function(e){return this.activeChoices.find((function(t){return t.id===e}))},e.prototype.getGroupById=function(e){return this.groups.find((function(t){return t.id===e}))},e}(),J="no-choices",z="no-results",Q="add-choice",Y=function(){function e(e){this._haystack=[],this._fields=e.searchFields}return e.prototype.index=function(e){this._haystack=e},e.prototype.reset=function(){this._haystack=[]},e.prototype.isEmptyIndex=function(){return!this._haystack.length},e.prototype.search=function(e){var t=this._fields;if(!t||!t.length||!e)return[];var i=e.toLowerCase();return this._haystack.filter((function(e){return t.some((function(t){return t in e&&e[t].toLowerCase().startsWith(i)}))})).map((function(e,t){return{item:e,score:t,rank:t+1}}))},e}(),Z=function(e,t,i){var n=e.dataset,s=t.customProperties,o=t.labelClass,r=t.labelDescription;o&&(n.labelClass=x(o).join(" ")),r&&(n.labelDescription=r),i&&s&&("string"==typeof s?n.customProperties=s:"object"!=typeof s||function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}(s)||(n.customProperties=JSON.stringify(s)))},$=function(e,t,i){var n=t&&e.querySelector("label[for='".concat(t,"']")),s=n&&n.innerText;s&&i.setAttribute("aria-label",s)},ee={containerOuter:function(e,t,i,n,s,o,r){var a=e.classNames.containerOuter,c=document.createElement("div");return c.className=x(a).join(" "),c.dataset.type=o,t&&(c.dir=t),n&&(c.tabIndex=0),i&&(c.setAttribute("role",s?"combobox":"listbox"),s?c.setAttribute("aria-autocomplete","list"):r||$(this._docRoot,this.passedElement.element.id,c),c.setAttribute("aria-haspopup","true"),c.setAttribute("aria-expanded","false")),r&&c.setAttribute("aria-labelledby",r),c},containerInner:function(e){var t=e.classNames.containerInner,i=document.createElement("div");return i.className=x(t).join(" "),i},itemList:function(e,t){var i=e.searchEnabled,n=e.classNames,s=n.list,o=n.listSingle,r=n.listItems,a=document.createElement("div");return a.className="".concat(x(s).join(" ")," ").concat(t?x(o).join(" "):x(r).join(" ")),this._isSelectElement&&i&&a.setAttribute("role","listbox"),a},placeholder:function(e,t){var i=e.allowHTML,n=e.classNames.placeholder,s=document.createElement("div");return s.className=x(n).join(" "),T(s,i,t),s},item:function(e,t,i){var n,s,o,r=e.allowHTML,a=e.removeItemButtonAlignLeft,c=e.removeItemIconText,l=e.removeItemLabelText,h=e.classNames,d=h.item,u=h.button,p=h.highlightedState,m=h.itemSelectable,f=h.placeholder,v=A(t.value),_=document.createElement("div");if(_.className=x(d).join(" "),t.labelClass){var g=document.createElement("span");T(g,r,t.label),g.className=x(t.labelClass).join(" "),_.appendChild(g)}else T(_,r,t.label);if(_.dataset.item="",_.dataset.id=t.id,_.dataset.value=v,Z(_,t,!0),(t.disabled||this.containerOuter.isDisabled)&&_.setAttribute("aria-disabled","true"),this._isSelectElement&&(_.setAttribute("aria-selected","true"),_.setAttribute("role","option")),t.placeholder&&((n=_.classList).add.apply(n,x(f)),_.dataset.placeholder=""),(s=_.classList).add.apply(s,x(t.highlighted?p:m)),i){t.disabled&&(o=_.classList).remove.apply(o,x(m)),_.dataset.deletable="";var y=document.createElement("button");y.type="button",y.className=x(u).join(" "),T(y,!0,w(c,t.value));var b=w(l,t.value);b&&y.setAttribute("aria-label",b),y.dataset.button="",a?_.insertAdjacentElement("afterbegin",y):_.appendChild(y)}return _},choiceList:function(e,t){var i=e.classNames.list,n=document.createElement("div");return n.className=x(i).join(" "),t||n.setAttribute("aria-multiselectable","true"),n.setAttribute("role","listbox"),n},choiceGroup:function(e,t){var i=e.allowHTML,n=e.classNames,s=n.group,o=n.groupHeading,r=n.itemDisabled,a=t.id,c=t.label,l=t.disabled,h=A(c),d=document.createElement("div");d.className="".concat(x(s).join(" ")," ").concat(l?x(r).join(" "):""),d.setAttribute("role","group"),d.dataset.group="",d.dataset.id=a,d.dataset.value=h,l&&d.setAttribute("aria-disabled","true");var u=document.createElement("div");return u.className=x(o).join(" "),T(u,i,c||""),d.appendChild(u),d},choice:function(e,t,i,n){var s,o,r,a,c,l=e.allowHTML,h=e.classNames,d=h.item,u=h.itemChoice,p=h.itemSelectable,m=h.selectedState,f=h.itemDisabled,v=h.description,_=h.placeholder,g=t.label,y=A(t.value),b=document.createElement("div");b.id=t.elementId,b.className="".concat(x(d).join(" ")," ").concat(x(u).join(" ")),n&&"string"==typeof g&&(g=O(l,g),g={trusted:g+=" (".concat(n,")")},b.dataset.groupId="".concat(t.groupId));var E=b;if(t.labelClass){var C=document.createElement("span");T(C,l,g),C.className=x(t.labelClass).join(" "),E=C,b.appendChild(C)}else T(b,l,g);if(t.labelDescription){var S="".concat(t.elementId,"-description");E.setAttribute("aria-describedby",S);var w=document.createElement("span");T(w,l,t.labelDescription),w.id=S,(s=w.classList).add.apply(s,x(v)),b.appendChild(w)}return t.selected&&(o=b.classList).add.apply(o,x(m)),t.placeholder&&(r=b.classList).add.apply(r,x(_)),b.setAttribute("role",t.groupId?"treeitem":"option"),b.dataset.choice="",b.dataset.id=t.id,b.dataset.value=y,i&&(b.dataset.selectText=i),Z(b,t,!1),t.disabled?((a=b.classList).add.apply(a,x(f)),b.dataset.choiceDisabled="",b.setAttribute("aria-disabled","true")):((c=b.classList).add.apply(c,x(p)),b.dataset.choiceSelectable=""),b},input:function(e,t){var i=e.classNames,n=i.input,s=i.inputCloned,o=e.labelId,r=document.createElement("input");return r.type="search",r.className="".concat(x(n).join(" ")," ").concat(x(s).join(" ")),r.autocomplete="off",r.autocapitalize="off",r.spellcheck=!1,r.setAttribute("role","textbox"),r.setAttribute("aria-autocomplete","list"),t?r.setAttribute("aria-label",t):o||$(this._docRoot,this.passedElement.element.id,r),r},dropdown:function(e){var t,i,n=e.classNames,s=n.list,o=n.listDropdown,r=document.createElement("div");return(t=r.classList).add.apply(t,x(s)),(i=r.classList).add.apply(i,x(o)),r.setAttribute("aria-expanded","false"),r},notice:function(e,t,i){var s=e.classNames,o=s.itemChoice,r=s.addChoice,a=s.noResults,c=s.noChoices,l=s.notice;void 0===i&&(i="");var h=n(n(n([],x(s.item),!0),x(o),!0),x(l),!0);switch(i){case Q:h.push.apply(h,x(r));break;case z:h.push.apply(h,x(a));break;case J:h.push.apply(h,x(c))}var d=document.createElement("div");return T(d,!0,t),d.className=h.join(" "),i===Q&&(d.dataset.choiceSelectable="",d.dataset.choice=""),d},option:function(e){var t=A(e.label),i=new Option(t,e.value,!1,e.selected);return Z(i,e,!0),i.disabled=e.disabled,e.selected&&i.setAttribute("selected",""),i}},te="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,ie={},ne=function(e){if(e)return e.dataset.id?parseInt(e.dataset.id,10):void 0},se="[data-choice-selectable]";return function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this.initialisedOK=void 0,this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0;var o=e.defaults;this.config=i(i(i({},o.allOptions),o.options),n),_.forEach((function(e){s.config[e]=i(i(i({},o.allOptions[e]),o.options[e]),n[e])}));var r=this.config;r.silent||this._validateConfig();var a=r.shadowRoot||document.documentElement;this._docRoot=a;var c="string"==typeof t?a.querySelector(t):t;if(!c||"object"!=typeof c||"INPUT"!==c.tagName&&!R(c)){if(!c&&"string"==typeof t)throw TypeError("Selector ".concat(t," failed to find an element"));throw TypeError("Expected one of the following types text|select-one|select-multiple")}var l=c.type,h="text"===l;(h||1!==r.maxItemCount)&&(r.singleModeForMultiSelect=!1),r.singleModeForMultiSelect&&(l=y);var d=l===g,u=l===y,p=d||u;if(this._elementType=l,this._isTextElement=h,this._isSelectOneElement=d,this._isSelectMultipleElement=u,this._isSelectElement=d||u,this._canAddUserChoices=h&&r.addItems||p&&r.addChoices,"boolean"!=typeof r.renderSelectedChoices&&(r.renderSelectedChoices="always"===r.renderSelectedChoices||d),r.closeDropdownOnSelect="auto"===r.closeDropdownOnSelect?h||d||r.singleModeForMultiSelect:B(r.closeDropdownOnSelect),r.placeholder&&(r.placeholderValue?this._hasNonChoicePlaceholder=!0:c.dataset.placeholder&&(this._hasNonChoicePlaceholder=!0,r.placeholderValue=c.dataset.placeholder)),n.addItemFilter&&"function"!=typeof n.addItemFilter){var m=n.addItemFilter instanceof RegExp?n.addItemFilter:new RegExp(n.addItemFilter);r.addItemFilter=m.test.bind(m)}if(this.passedElement=this._isTextElement?new K({element:c,classNames:r.classNames}):new q({element:c,classNames:r.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:r.placeholder&&!this._hasNonChoicePlaceholder}),this.initialised=!1,this._store=new X(r),this._currentValue="",r.searchEnabled=!h&&r.searchEnabled||u,this._canSearch=r.searchEnabled,this._isScrollingOnIe=!1,this._highlightPosition=0,this._wasTap=!0,this._placeholderValue=this._generatePlaceholderValue(),this._baseId=function(e){var t=e.id||e.name&&"".concat(e.name,"-").concat(E(2))||E(4);return t=t.replace(/(:|\.|\[|\]|,)/g,""),"".concat("choices-","-").concat(t)}(c),this._direction=c.dir,!this._direction){var f=window.getComputedStyle(c).direction;f!==window.getComputedStyle(document.documentElement).direction&&(this._direction=f)}if(this._idNames={itemChoice:"item-choice"},this._templates=o.templates,this._render=this._render.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this),this._onKeyUp=this._onKeyUp.bind(this),this._onKeyDown=this._onKeyDown.bind(this),this._onInput=this._onInput.bind(this),this._onClick=this._onClick.bind(this),this._onTouchMove=this._onTouchMove.bind(this),this._onTouchEnd=this._onTouchEnd.bind(this),this._onMouseDown=this._onMouseDown.bind(this),this._onMouseOver=this._onMouseOver.bind(this),this._onFormReset=this._onFormReset.bind(this),this._onSelectKey=this._onSelectKey.bind(this),this._onEnterKey=this._onEnterKey.bind(this),this._onEscapeKey=this._onEscapeKey.bind(this),this._onDirectionKey=this._onDirectionKey.bind(this),this._onDeleteKey=this._onDeleteKey.bind(this),this.passedElement.isActive)return r.silent||console.warn("Trying to initialise Choices on element already initialised",{element:t}),this.initialised=!0,void(this.initialisedOK=!1);this.init(),this._initialItems=this._store.items.map((function(e){return e.value}))}return Object.defineProperty(e,"defaults",{get:function(){return Object.preventExtensions({get options(){return ie},get allOptions(){return G},get templates(){return ee}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised&&void 0===this.initialisedOK){this._searcher=new Y(this.config),this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._isTextElement&&!this.config.addItems||this.passedElement.element.hasAttribute("disabled")||this.passedElement.element.closest("fieldset:disabled")?this.disable():(this.enable(),this._addEventListeners()),this._initStore(),this.initialised=!0,this.initialisedOK=!0;var e=this.config.callbackOnInit;"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this._store._listeners=[],this.clearStore(),this._stopSearch(),this._templates=e.defaults.templates,this.initialised=!1,this.initialisedOK=void 0)},e.prototype.enable=function(){return this.passedElement.isDisabled&&this.passedElement.enable(),this.containerOuter.isDisabled&&(this._addEventListeners(),this.input.enable(),this.containerOuter.enable()),this},e.prototype.disable=function(){return this.passedElement.isDisabled||this.passedElement.disable(),this.containerOuter.isDisabled||(this._removeEventListeners(),this.input.disable(),this.containerOuter.disable()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.items.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(b(i,!0)),t&&this.passedElement.triggerEvent(v,this._getChoiceForOutput(i))),this},e.prototype.unhighlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.items.find((function(t){return t.id===e.id}));return i&&i.highlighted?(this._store.dispatch(b(i,!1)),t&&this.passedElement.triggerEvent(v,this._getChoiceForOutput(i)),this):this},e.prototype.highlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){t.highlighted||(e._store.dispatch(b(t,!0)),e.passedElement.triggerEvent(v,e._getChoiceForOutput(t)))}))})),this},e.prototype.unhighlightAll=function(){var e=this;return this._store.withTxn((function(){e._store.items.forEach((function(t){t.highlighted&&(e._store.dispatch(b(t,!1)),e.passedElement.triggerEvent(v,e._getChoiceForOutput(t)))}))})),this},e.prototype.removeActiveItemsByValue=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.value===e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeActiveItems=function(e){var t=this;return this._store.withTxn((function(){t._store.items.filter((function(t){return t.id!==e})).forEach((function(e){return t._removeItem(e)}))})),this},e.prototype.removeHighlightedItems=function(e){var t=this;return void 0===e&&(e=!1),this._store.withTxn((function(){t._store.highlightedActiveItems.forEach((function(i){t._removeItem(i),e&&t._triggerChange(i.value)}))})),this},e.prototype.showDropdown=function(e){var t=this;return this.dropdown.isActive||requestAnimationFrame((function(){t.dropdown.show();var i=t.dropdown.element.getBoundingClientRect();t.containerOuter.open(i.bottom,i.height),!e&&t._canSearch&&t.input.focus(),t.passedElement.triggerEvent("showDropdown")})),this},e.prototype.hideDropdown=function(e){var t=this;return this.dropdown.isActive?(requestAnimationFrame((function(){t.dropdown.hide(),t.containerOuter.close(),!e&&t._canSearch&&(t.input.removeActiveDescendant(),t.input.blur()),t.passedElement.triggerEvent("hideDropdown")})),this):this},e.prototype.getValue=function(e){var t=this;void 0===e&&(e=!1);var i=this._store.items.reduce((function(i,n){var s=e?n.value:t._getChoiceForOutput(n);return i.push(s),i}),[]);return this._isSelectOneElement||this.config.singleModeForMultiSelect?i[0]:i},e.prototype.setValue=function(e){var t=this;return this.initialisedOK?(this._store.withTxn((function(){e.forEach((function(e){e&&t._addChoice(V(e,!1))}))})),this._searcher.reset(),this):(this._warnChoicesInitFailed("setValue"),this)},e.prototype.setChoiceByValue=function(e){var t=this;return this.initialisedOK?(this._isTextElement||(this._store.withTxn((function(){(Array.isArray(e)?e:[e]).forEach((function(e){return t._findAndSelectChoiceByValue(e)})),t.unhighlightAll()})),this._searcher.reset()),this):(this._warnChoicesInitFailed("setChoiceByValue"),this)},e.prototype.setChoices=function(e,t,n,s){var o=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),!this.initialisedOK)return this._warnChoicesInitFailed("setChoices"),this;if(!this._isSelectElement)throw new TypeError("setChoices can't be used with INPUT based Choices");if("string"!=typeof t||!t)throw new TypeError("value parameter must be a name of 'value' field in passed objects");if(s&&this.clearChoices(),"function"==typeof e){var r=e(this);if("function"==typeof Promise&&r instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return o._handleLoadingState(!0)})).then((function(){return r})).then((function(e){return o.setChoices(e,t,n,s)})).catch((function(e){o.config.silent||console.error(e)})).then((function(){return o._handleLoadingState(!1)})).then((function(){return o}));if(!Array.isArray(r))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof r));return this.setChoices(r,t,n,!1)}if(!Array.isArray(e))throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices");return this.containerOuter.removeLoadingState(),this._store.withTxn((function(){var s="value"===t,r="label"===n;e.forEach((function(e){if("choices"in e){var a=e;r||(a=i(i({},a),{label:a[n]})),o._addGroup(V(a,!0))}else{var c=e;r&&s||(c=i(i({},c),{value:c[t],label:c[n]})),o._addChoice(V(c,!1))}})),o.unhighlightAll()})),this._searcher.reset(),this},e.prototype.refresh=function(e,t,i){var n=this;return void 0===e&&(e=!1),void 0===t&&(t=!1),void 0===i&&(i=!1),this._isSelectElement?(this._store.withTxn((function(){var s=n.passedElement.optionsAsChoices(),o={};i||n._store.items.forEach((function(e){e.id&&e.active&&e.selected&&!e.disabled&&(o[e.value]=!0)})),s.forEach((function(e){if(!("choices"in e)){var t=e;i?t.selected=!1:o[t.value]&&(t.selected=!0)}})),n.clearStore(),n._addPredefinedChoices(s,t,e),n._isSearching&&n._searchChoices(n.input.value)})),this):(this.config.silent||console.warn("refresh method can only be used on choices backed by a + + + + + + + diff --git a/public/test/select-multiple/index.html b/public/test/select-multiple/index.html index 12de4e21..854db4d1 100644 --- a/public/test/select-multiple/index.html +++ b/public/test/select-multiple/index.html @@ -91,6 +91,29 @@

Select multiple inputs

+
+ + + +
+