From f6b54f7c3052cd32503cca4136f2ada122e58400 Mon Sep 17 00:00:00 2001 From: Xon <635541+Xon@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:50:40 +0800 Subject: [PATCH] Compile JS files --- public/assets/scripts/choices.js | 382 ++++++++---------- public/assets/scripts/choices.min.js | 2 +- public/assets/scripts/choices.mjs | 382 ++++++++---------- public/assets/scripts/choices.search-basic.js | 382 ++++++++---------- .../scripts/choices.search-basic.min.js | 2 +- .../assets/scripts/choices.search-basic.mjs | 382 ++++++++---------- .../assets/scripts/choices.search-prefix.js | 382 ++++++++---------- .../scripts/choices.search-prefix.min.js | 2 +- .../assets/scripts/choices.search-prefix.mjs | 382 ++++++++---------- public/types/src/scripts/components/list.d.ts | 1 - public/types/src/scripts/constants.d.ts | 3 - .../src/scripts/interfaces/action-type.d.ts | 3 +- .../src/scripts/interfaces/event-type.d.ts | 3 +- .../types/src/scripts/interfaces/options.d.ts | 2 +- .../interfaces/passed-element-type.d.ts | 8 +- .../src/scripts/interfaces/templates.d.ts | 3 +- .../types/src/scripts/interfaces/types.d.ts | 1 + 17 files changed, 1056 insertions(+), 1266 deletions(-) diff --git a/public/assets/scripts/choices.js b/public/assets/scripts/choices.js index aff28cb71..79fcaa591 100644 --- a/public/assets/scripts/choices.js +++ b/public/assets/scripts/choices.js @@ -91,6 +91,12 @@ 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, @@ -334,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; @@ -409,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; @@ -418,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 () { @@ -544,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); @@ -555,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(); } }; @@ -573,6 +576,8 @@ return Input; }()); + var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -580,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) { @@ -714,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) { @@ -856,7 +856,6 @@ option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -871,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) { @@ -993,38 +992,35 @@ 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.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 = ''; } } // this is mixing concerns, but this is *so much faster* - removeItem(item_1); - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { - var choice_1 = action.choice; - state = state.filter(function (item) { return item.id !== choice_1.id; }); - removeItem(choice_1); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { @@ -1033,9 +1029,7 @@ if (item && item.highlighted !== highlighted) { item.highlighted = highlighted; if (context) { - var classNames = context.classNames; - var highlightedState = classNames.highlightedState, selectedState = classNames.selectedState; - updateClassList(item, highlighted ? highlightedState : selectedState, highlighted ? selectedState : highlightedState); + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } } break; @@ -1083,17 +1077,13 @@ break; } case ActionType.REMOVE_CHOICE: { - var choice = action.choice; - var choiceEl = choice.choiceEl; - if (choiceEl) { - choiceEl.remove(); - choice.choiceEl = undefined; - } + 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: { @@ -1141,7 +1131,6 @@ return { state: state, update: update }; } - // eslint-disable-next-line import/no-cycle var reducers = { groups: groups, items: items, @@ -3095,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) { @@ -3122,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); } @@ -3165,10 +3152,9 @@ 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'); } @@ -3183,32 +3169,32 @@ 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; // eslint-disable-next-line prefer-destructuring var label = choice.label; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + 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); @@ -3219,26 +3205,22 @@ if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - div.setAttribute('role', groupId ? 'treeitem' : 'option'); - if (groupId) { - 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; }, @@ -3289,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; }, @@ -3316,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 @@ -3353,15 +3334,15 @@ throw TypeError("Expected one of the following types text|select-one|select-multiple"); } var elementType = passedElement.type; - var isText = elementType === TEXT_TYPE; + var isText = elementType === PassedElementTypes.Text; if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - elementType = SELECT_MULTIPLE_TYPE; + elementType = PassedElementTypes.SelectMultiple; } - var isSelectOne = elementType === SELECT_ONE_TYPE; - var isSelectMultiple = elementType === SELECT_MULTIPLE_TYPE; + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; var isSelect = isSelectOne || isSelectMultiple; this._elementType = elementType; this._isTextElement = isText; @@ -3369,8 +3350,8 @@ this._isSelectMultipleElement = isSelectMultiple; this._isSelectElement = isSelectOne || isSelectMultiple; this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; @@ -3504,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); } }; @@ -3523,26 +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.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.containerOuter.disable(); } return this; }; @@ -3861,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; } @@ -3976,36 +3954,36 @@ if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var _a = this, config = _a.config, templates = _a._templates, isSearching = _a._isSearching, choiceList = _a.choiceList; - var _b = this._store, groups = _b.activeGroups, activeChoices = _b.activeChoices; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; + var _a = this, config = _a.config, isSearching = _a._isSearching; var renderLimit = 0; - if (isSearching && searchResultLimit > 0) { - renderLimit = searchResultLimit; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; } - else if (renderChoiceLimit > 0) { - renderLimit = renderChoiceLimit; + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; } var groupLookup = []; var appendGroupInSearch = config.appendGroupInSearch && isSearching; if (appendGroupInSearch) { - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { if (group.label) { groupLookup[group.id] = group.label; } }); } if (this._isSelectElement) { - var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); if (backingOptions.length) { this.passedElement.addOptions(backingOptions); } } var fragment = document.createDocumentFragment(); - var skipSelected = config.renderSelectedChoices === 'auto' && !this._isSelectOneElement; var renderableChoices = function (choices) { - return choices.filter(function (choice) { return !choice.placeholder && !(isSearching && !choice.rank) && !(skipSelected && choice.selected); }); + 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 @@ -4018,34 +3996,36 @@ var choiceLimit = choices.length; choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; choiceLimit--; - // Add each choice to dropdown within range choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed var dropdownItem = choice.choiceEl || - templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + _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; }); }; - var noChoices = true; - if (activeChoices.length) { + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { - requestAnimationFrame(function () { return choiceList.scrollToTop(); }); + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { // If we have a placeholder choice along with groups - renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); } // If we have grouped options - if (groups.length && !isSearching) { + if (this._store.activeGroups.length && !isSearching) { if (config.shouldSort) { - groups.sort(config.sorter); + this._store.activeGroups.sort(config.sorter); } - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { var groupChoices = renderableChoices(group.choices); if (groupChoices.length) { if (group.label) { - var dropdownGroup = group.groupEl || templates.choiceGroup(_this.config, group); + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); group.groupEl = dropdownGroup; dropdownGroup.remove(); fragment.appendChild(dropdownGroup); @@ -4055,25 +4035,25 @@ }); } else { - renderChoices(renderableChoices(activeChoices), false); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !fragment.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(fragment); - choiceList.element.replaceChildren(fragment); - if (!noChoices) { + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; @@ -4081,7 +4061,7 @@ var _this = this; var items = this._store.items || []; var itemList = this.itemList.element; - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; + var config = this.config; var fragment = document.createDocumentFragment(); var itemFromList = function (item) { return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); @@ -4098,7 +4078,7 @@ // new items items.forEach(addItemToFragment); var addItems = !!fragment.childNodes.length; - if (isSelectOneElement && this._hasNonChoicePlaceholder) { + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { var existingItems = itemList.children.length; if (addItems || existingItems > 1) { var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); @@ -4118,7 +4098,7 @@ } if (addItems) { itemList.append(fragment); - if (config.shouldSortItems && !isSelectOneElement) { + if (config.shouldSortItems && !this._isSelectOneElement) { items.sort(config.sorter); // push sorting into the DOM items.forEach(function (item) { @@ -4326,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); @@ -4349,23 +4328,22 @@ }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement, itemList = _a.itemList; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); - if (isSelectOneElement) { - itemList.clear(); - itemList.element.append(this._templates.placeholder(config, config.loadingText)); + if (this._isSelectOneElement) { + 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 (isSelectOneElement) { - itemList.clear(); + if (this._isSelectOneElement) { + el.replaceChildren(''); this._render(); } else { @@ -4377,12 +4355,9 @@ 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(EventType.search, { @@ -4391,7 +4366,7 @@ }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -4399,7 +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.clear(); + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -4642,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) { @@ -4655,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; } @@ -4670,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; } @@ -4692,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, @@ -4707,7 +4678,7 @@ return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -4719,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) { @@ -4759,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(); } @@ -4809,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); } } @@ -4838,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(); @@ -4931,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) { @@ -4961,7 +4928,7 @@ 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(EventType.highlightChoice, { el: passedEl, @@ -4976,12 +4943,11 @@ 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) { @@ -4992,8 +4958,7 @@ } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } this._store.dispatch(removeItem$1(item)); @@ -5035,9 +5000,8 @@ 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; + group.id = this._lastAddedGroupId; group.choices.forEach(function (item) { item.groupId = group.id; if (group.disabled) { @@ -5050,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 = {}; @@ -5066,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, @@ -5088,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), @@ -5100,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 @@ -5108,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; @@ -5175,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 f8c970fd0..cdd882f86 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&&!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,L(this.classNames.openState)),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&((n=this.element.classList).add.apply(n,L(this.classNames.flippedState)),this.isFlipped=!0)},e.prototype.close=function(){var e,t;(e=this.element.classList).remove.apply(e,L(this.classNames.openState)),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&((t=this.element.classList).remove.apply(t,L(this.classNames.flippedState)),this.isFlipped=!1)},e.prototype.addFocusState=function(){var e;(e=this.element.classList).add.apply(e,L(this.classNames.focusState))},e.prototype.removeFocusState=function(){var e;(e=this.element.classList).remove.apply(e,L(this.classNames.focusState))},e.prototype.enable=function(){var e;(e=this.element.classList).remove.apply(e,L(this.classNames.disabledState)),this.element.removeAttribute("aria-disabled"),this.type===N&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){var e;(e=this.element.classList).add.apply(e,L(this.classNames.disabledState)),this.element.setAttribute("aria-disabled","true"),this.type===N&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=e.parentNode;t&&(e.nextSibling?t.insertBefore(this.element,e.nextSibling):t.appendChild(this.element)),this.element.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element.parentNode;t&&(t.insertBefore(e,this.element),t.removeChild(this.element))},e.prototype.addLoadingState=function(){var e;(e=this.element.classList).add.apply(e,L(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,L(this.classNames.loadingState)),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),D=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,t=e.style,i=e.value;t.minWidth="".concat(e.placeholder.length+1,"ch"),t.width="".concat(i.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!==N&&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.clear=function(){this.element.innerHTML=""},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,L(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,L(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}(),R=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(j),K=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},B=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},H=function(e,t){if("string"==typeof e)return H({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 H(e,!1)}));return{id:0,label:w(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:K(o.active),selected:K(o.selected,!1),disabled:K(o.disabled,!1),placeholder:K(o.placeholder,!1),highlighted:!1,labelClass:B(o.labelClass),labelDescription:o.labelDescription,customProperties:o.customProperties}},V=function(e){return"SELECT"===e.tagName},$=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?B(t.labelClass):void 0,labelDescription:void 0!==t.labelDescription?t.labelDescription:void 0,customProperties:M(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}(j),q={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 w(void 0===i?e.value:i).localeCompare(w(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},W=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},G={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:(h=t.item).selected=!0,(o=h.element)&&(o.selected=!0,o.setAttribute("selected","")),n.push(h);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&&V(c)&&c.type===N&&(c.value="")}W(a),n=n.filter((function(e){return e.id!==a.id}));break;case r:var l=t.choice;n=n.filter((function(e){return e.id!==l.id})),W(l);break;case p:var h,f=t.highlighted;if((h=n.find((function(e){return e.id===t.item.id})))&&h.highlighted!==f&&(h.highlighted=f,i)){var m=i.classNames,v=m.highlightedState,g=m.selectedState;!function(e,t,i){var n,s,o=e.itemEl;o&&((n=o.classList).remove.apply(n,L(i)),(s=o.classList).add.apply(s,L(t)))}(h,f?v:g,f?g:v)}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:var h=t.choice,p=h.choiceEl;p&&(p.remove(),h.choiceEl=void 0),n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:break;case a:var f=[];t.results.forEach((function(e){f[e.item.id]=e})),n.forEach((function(e){var t=f[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}}},U=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(G).forEach((function(o){var r=G[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}(),z="no-choices",J="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 _e(e,t,{getFn:i=me.getFn,fieldNormWeight:n=me.fieldNormWeight}={}){const s=new ge({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 g;for(;(g=e.indexOf(t,f))>-1;){let e=ye(t,{currentLocation:g,expectedLocation:d,distance:s,ignoreLocation:l});if(p=Math.min(e,p),f=g+h,m){let e=0;for(;e=c;o-=1){let r=o-1,a=i[e.charAt(r)];if(m&&(v[r]=+!!a),S[o]=(S[o+1]<<1|1)&a,n&&(S[o]|=(_[o+1]|_[o])<<1|1|_[o+1]),S[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;_=S}const S={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&&(S.indices=e):S.isMatch=!1}return S}(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}}class Ce{constructor(e){this.pattern=e}static isMultiMatch(e){return we(e,this.multiRegex)}static isSingleMatch(e){return we(e,this.singleRegex)}search(){}}function we(e,t){const i=e.match(t);return i?i[1]:null}class Ie extends Ce{constructor(e,{location:t=me.location,threshold:i=me.threshold,distance:n=me.distance,includeMatches:s=me.includeMatches,findAllMatches:o=me.findAllMatches,minMatchCharLength:r=me.minMatchCharLength,isCaseSensitive:a=me.isCaseSensitive,ignoreLocation:c=me.ignoreLocation}={}){super(e),this._bitapSearch=new Se(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 Ae extends Ce{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 xe=[class extends Ce{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]}}},Ae,class extends Ce{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 Ce{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 Ce{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 Ce{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 Ce{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]}}},Ie],Le=xe.length,Oe=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Me=new Set([Ie.type,Ae.type]);const Te=[];function Ne(e,t){for(let i=0,n=Te.length;i!(!e[ke]&&!e.$or),Pe=e=>({[ke]:Object.keys(e).map((t=>({[t]:e[t]})))});function je(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Fe])(e);if(!o&&s.length>1&&!De(e))return n(Pe(e));if((e=>!ee(e)&&ne(e)&&!De(e))(e)){const n=o?e[Fe]: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=Ne(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 De(e)||(e=Pe(e)),n(e)}function Re(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 Ke(e,t){t.score=e.score}class Be{constructor(e,t={},i){this.options=Z(Z({},me),t),this._keyStore=new he(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof ge))throw new Error("Incorrect 'index' type");this._myIndex=t||_e(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(Re),n&&s.push(Ke),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=Ne(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){const t=je(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(se(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=Ne(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}}Be.version="7.0.0",Be.createIndex=_e,Be.parseIndex=function(e,{getFn:t=me.getFn,fieldNormWeight:i=me.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new ge({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},Be.config=me,Be.parseQuery=je,function(...e){Te.push(...e)}(class{constructor(e,{isCaseSensitive:t=me.isCaseSensitive,includeMatches:i=me.includeMatches,minMatchCharLength:n=me.minMatchCharLength,ignoreLocation:s=me.ignoreLocation,findAllMatches:o=me.findAllMatches,location:r=me.location,threshold:a=me.threshold,distance:c=me.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(Oe).filter((e=>e&&!!e.trim())),n=[];for(let e=0,s=i.length;e 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(m,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=q,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._canAddItems()){var t=this,i=t.config,n=t._templates,s=t._isSearching,o=t.choiceList,r=this._store,a=r.activeGroups,c=r.activeChoices,l=i.searchResultLimit,h=i.renderChoiceLimit,u=0;s&&l>0?u=l:h>0&&(u=h);var d=[],p=i.appendGroupInSearch&&s;if(p&&a.forEach((function(e){e.label&&(d[e.id]=e.label)})),this._isSelectElement){var f=c.filter((function(e){return!e.element}));f.length&&this.passedElement.addOptions(f)}var m=document.createDocumentFragment(),v="auto"===i.renderSelectedChoices&&!this._isSelectOneElement,g=function(e){return e.filter((function(e){return!(e.placeholder||s&&!e.rank||v&&e.selected)}))},_=function(e,t){s?e.sort(x):i.shouldSort&&e.sort(i.sorter);var o=e.length;o=!t&&u&&o>u?u:o,o--,e.every((function(e,t){var s=e.choiceEl||n.choice(i,e,i.itemSelectText,p&&e.groupId?d[e.groupId]:void 0);return e.choiceEl=s,m.appendChild(s),t1){var h=i.querySelector(O(n.classNames.placeholder));h&&h.remove()}else l||(c=!0,a(H({selected:!0,value:"",label:n.placeholderValue||"",placeholder:!0},!1)))}c&&(i.append(o),n.shouldSortItems&&!s&&(t.sort(n.sorter),t.forEach((function(e){var t=r(e);t&&(t.remove(),o.append(t))})),i.append(o))),this._isTextElement&&(this.passedElement.value=t.map((function(e){return e.value})).join(n.delimiter))},e.prototype._displayNotice=function(e,t,i){void 0===i&&(i=!0);var n=this._notice;n&&(n.type===t&&n.text===e||n.type===X&&(t===J||t===z))?i&&this.showDropdown(!0):(this._clearNotice(),this._notice=e?{text:e,type:t}:void 0,this._renderNotice(),i&&e&&this.showDropdown(!0))},e.prototype._clearNotice=function(){if(this._notice){var e=this.choiceList.element.querySelector(O(this.config.classNames.notice));e&&e.remove(),this._notice=void 0}},e.prototype._renderNotice=function(e){var t=this._notice;if(t){var i=this._templates.notice(this.config,t.text,t.type);e?e.append(i):this.choiceList.prepend(i)}},e.prototype._getChoiceForOutput=function(e,t){if(e){var i=e.groupId?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,i=this._store.items;if(i.length&&this.config.removeItems&&this.config.removeItemButton){var n=e&&Ue(e.parentNode),s=n&&i.find((function(e){return e.id===n}));s&&this._store.withTxn((function(){if(t._removeItem(s),t._triggerChange(s.value),t._isSelectOneElement&&!t._hasNonChoicePlaceholder){var e=t._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));e&&(t._addItem(e),t.unhighlightAll(),e.value&&t._triggerChange(e.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=Ue(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=Ue(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,i=t.config,n=t._isSelectOneElement,s=t.itemList;e?(this.disable(),this.containerOuter.addLoadingState(),n?(s.clear(),s.element.append(this._templates.placeholder(i,i.loadingText))):this.input.placeholder=i.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),n?(s.clear(),this._render()):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(f,{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.choiceList.clear(),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=S(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=S(t.uniqueItemText,e))}return i&&(n=S(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===J&&this._clearNotice():this._displayNotice(C(this.config.noResultsText),J)),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(f,{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(O(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=b(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(O(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(We&&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,L(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(m,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,e.choices.forEach((function(n){n.groupId=e.id,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,E,I));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 D({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 T({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}();return ze})); +!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,M(this.classNames.openState)),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&((n=this.element.classList).add.apply(n,M(this.classNames.flippedState)),this.isFlipped=!0)},e.prototype.close=function(){var e,t;(e=this.element.classList).remove.apply(e,M(this.classNames.openState)),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&((t=this.element.classList).remove.apply(t,M(this.classNames.flippedState)),this.isFlipped=!1)},e.prototype.addFocusState=function(){var e;(e=this.element.classList).add.apply(e,M(this.classNames.focusState))},e.prototype.removeFocusState=function(){var e;(e=this.element.classList).remove.apply(e,M(this.classNames.focusState))},e.prototype.enable=function(){var e;(e=this.element.classList).remove.apply(e,M(this.classNames.disabledState)),this.element.removeAttribute("aria-disabled"),this.type===_&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){var e;(e=this.element.classList).add.apply(e,M(this.classNames.disabledState)),this.element.setAttribute("aria-disabled","true"),this.type===_&&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,M(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,M(this.classNames.loadingState)),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),D=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!==_&&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,M(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,M(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}(),R=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(j),K=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},B=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:K(o.active),selected:K(o.selected,!1),disabled:K(o.disabled,!1),placeholder:K(o.placeholder,!1),highlighted:!1,labelClass:B(o.labelClass),labelDescription:o.labelDescription,customProperties:o.customProperties}},H=function(e){return"SELECT"===e.tagName},$=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?B(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:N(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),q={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},G=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&&H(a)&&a.type===_&&(a.value="")}G(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})),G(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,M(i)),(s=o.classList).add.apply(s,M(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}}},U=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}(),z="no-choices",J="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 _e(e,t,{getFn:i=me.getFn,fieldNormWeight:n=me.fieldNormWeight}={}){const s=new ge({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 g;for(;(g=e.indexOf(t,f))>-1;){let e=ye(t,{currentLocation:g,expectedLocation:d,distance:s,ignoreLocation:l});if(p=Math.min(e,p),f=g+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]|=(_[o+1]|_[o])<<1|1|_[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;_=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}}class Se{constructor(e){this.pattern=e}static isMultiMatch(e){return we(e,this.multiRegex)}static isSingleMatch(e){return we(e,this.singleRegex)}search(){}}function we(e,t){const i=e.match(t);return i?i[1]:null}class Ie extends Se{constructor(e,{location:t=me.location,threshold:i=me.threshold,distance:n=me.distance,includeMatches:s=me.includeMatches,findAllMatches:o=me.findAllMatches,minMatchCharLength:r=me.minMatchCharLength,isCaseSensitive:a=me.isCaseSensitive,ignoreLocation:c=me.ignoreLocation}={}){super(e),this._bitapSearch=new Ce(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 Ae extends Se{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 xe=[class extends Se{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]}}},Ae,class extends Se{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 Se{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 Se{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 Se{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 Se{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]}}},Ie],Le=xe.length,Oe=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Me=new Set([Ie.type,Ae.type]);const Te=[];function Ne(e,t){for(let i=0,n=Te.length;i!(!e[ke]&&!e.$or),Pe=e=>({[ke]:Object.keys(e).map((t=>({[t]:e[t]})))});function je(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Fe])(e);if(!o&&s.length>1&&!De(e))return n(Pe(e));if((e=>!ee(e)&&ne(e)&&!De(e))(e)){const n=o?e[Fe]: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=Ne(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 De(e)||(e=Pe(e)),n(e)}function Re(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 Ke(e,t){t.score=e.score}class Be{constructor(e,t={},i){this.options=Z(Z({},me),t),this._keyStore=new he(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof ge))throw new Error("Incorrect 'index' type");this._myIndex=t||_e(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(Re),n&&s.push(Ke),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=Ne(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){const t=je(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(se(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=Ne(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}}Be.version="7.0.0",Be.createIndex=_e,Be.parseIndex=function(e,{getFn:t=me.getFn,fieldNormWeight:i=me.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new ge({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},Be.config=me,Be.parseQuery=je,function(...e){Te.push(...e)}(class{constructor(e,{isCaseSensitive:t=me.isCaseSensitive,includeMatches:i=me.includeMatches,minMatchCharLength:n=me.minMatchCharLength,ignoreLocation:s=me.ignoreLocation,findAllMatches:o=me.findAllMatches,location:r=me.location,threshold:a=me.threshold,distance:c=me.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(Oe).filter((e=>e&&!!e.trim())),n=[];for(let e=0,s=i.length;e 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(m,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=q,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._canAddItems()){var t=this.config,i=this._isSearching,n=0;i&&t.searchResultLimit>0?n=t.searchResultLimit:t.renderChoiceLimit>0&&(n=t.renderChoiceLimit);var s=[],o=t.appendGroupInSearch&&i;if(o&&this._store.activeGroups.forEach((function(e){e.label&&(s[e.id]=e.label)})),this._isSelectElement){var r=this._store.activeChoices.filter((function(e){return!e.element}));r.length&&this.passedElement.addOptions(r)}var a=document.createDocumentFragment(),c=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},l=this._isSelectOneElement,h=function(r,c){i?r.sort(O):t.shouldSort&&r.sort(t.sorter);var h=r.length;h=!c&&n&&h>n?n:h,h--,r.every((function(n,r){var c=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o&&n.groupId?s[n.groupId]:void 0);return n.choiceEl=c,a.appendChild(c),!i&&n.selected||(l=!0),r1){var l=i.querySelector(T(n.classNames.placeholder));l&&l.remove()}else c||(a=!0,r(V({selected:!0,value:"",label:n.placeholderValue||"",placeholder:!0},!1)))}a&&(i.append(s),n.shouldSortItems&&!this._isSelectOneElement&&(t.sort(n.sorter),t.forEach((function(e){var t=o(e);t&&(t.remove(),s.append(t))})),i.append(s))),this._isTextElement&&(this.passedElement.value=t.map((function(e){return e.value})).join(n.delimiter))},e.prototype._displayNotice=function(e,t,i){void 0===i&&(i=!0);var n=this._notice;n&&(n.type===t&&n.text===e||n.type===X&&(t===J||t===z))?i&&this.showDropdown(!0):(this._clearNotice(),this._notice=e?{text:e,type:t}:void 0,this._renderNotice(),i&&e&&this.showDropdown(!0))},e.prototype._clearNotice=function(){if(this._notice){var e=this.choiceList.element.querySelector(T(this.config.classNames.notice));e&&e.remove(),this._notice=void 0}},e.prototype._renderNotice=function(e){var t=this._notice;if(t){var i=this._templates.notice(this.config,t.text,t.type);e?e.append(i):this.choiceList.prepend(i)}},e.prototype._getChoiceForOutput=function(e,t){if(e){var i=e.groupId?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,i=this._store.items;if(i.length&&this.config.removeItems&&this.config.removeItemButton){var n=e&&Ue(e.parentNode),s=n&&i.find((function(e){return e.id===n}));s&&this._store.withTxn((function(){if(t._removeItem(s),t._triggerChange(s.value),t._isSelectOneElement&&!t._hasNonChoicePlaceholder){var e=t._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));e&&(t._addItem(e),t.unhighlightAll(),e.value&&t._triggerChange(e.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=Ue(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=Ue(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){if(this._presetChoices=t.items.map((function(e){return V(e,!1)})),this.passedElement.value){var i=this.passedElement.value.split(t.delimiter).map((function(e){return V(e,!1)}));this._presetChoices=this._presetChoices.concat(i)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=t.choices.map((function(e){return V(e,!0)}));var n=this.passedElement.optionsAsChoices();n&&(e=this._presetChoices).push.apply(e,n)}},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.itemList.element;e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?t.replaceChildren(this._templates.placeholder(this.config,this.config.loadingText)):this.input.placeholder=this.config.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement?(t.replaceChildren(""),this._render()):this.input.placeholder=this._placeholderValue||"")},e.prototype._handleSearch=function(e){if(this.input.isFocussed)if(null!=e&&e.length>=this.config.searchFloor){var t=this.config.searchChoices?this._searchChoices(e):0;null!==t&&this.passedElement.triggerEvent(f,{value:e,resultCount:t})}else this._store.choices.some((function(e){return!e.active}))&&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.choiceList.element.replaceChildren(""),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=w(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=w(t.uniqueItemText,e))}return i&&(n=w(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===J&&this._clearNotice():this._displayNotice(I(this.config.noResultsText),J)),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(f,{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.input.value,s=e.target;if(e.preventDefault(),s&&s.hasAttribute("data-button"))this._handleButtonAction(s);else if(t){var o=this.dropdown.element.querySelector(T(this.config.classNames.highlightedState));if(!o||!this._handleChoiceAction(o))if(s&&n){if(this._canAddItems()){var r=!1;this._store.withTxn((function(){if(!(r=i._findAndSelectChoiceByValue(n,!0))){if(!i._canAddUserChoices)return;if(!i._canCreateItem(n))return;var e=C(n),t=i.config.allowHtmlUserInput||e===n?n:{escaped:e,raw:n};i._addChoice(V({value:t,label:t,selected:!0},!1),!0,!0),r=!0}i.clearInput(),i.unhighlightAll()})),r&&(this._triggerChange(n),this.config.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;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var r=40===o||34===o?1:-1,a=void 0;if(e.metaKey||34===o||33===o)a=this.dropdown.element.querySelector(r>0?"".concat(ze,":last-of-type"):ze);else{var c=this.dropdown.element.querySelector(T(this.config.classNames.highlightedState));a=c?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}(c,ze,r):this.dropdown.element.querySelector(ze)}a&&(i=a,n=this.choiceList.element,void 0===(s=r)&&(s=1),(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(a,r),this._highlightChoice(a)),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(Ge&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?i[this._highlightPosition]:i[i.length-1])||(n=i[0]),(t=n.classList).add.apply(t,s),n.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:n}),this.dropdown.isActive&&(this.input.setActiveDescendant(n.id),this.containerOuter.setActiveDescendant(n.id))}},e.prototype._addItem=function(e,t,i){if(void 0===t&&(t=!0),void 0===i&&(i=!1),!e.id)throw new TypeError("item.id must be set before _addItem is called for a choice/item");(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&this.removeActiveItems(e.id),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(m,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");this._store.dispatch(function(e){return{type:h,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.groupId=e.id,e.disabled&&(n.disabled=!0),i._addChoice(n,t)})))},e.prototype._createTemplates=function(){var e=this,t=this.config.callbackOnCreateTemplates,i={};"function"==typeof t&&(i=t.call(this,S,x));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=this._isSelectOneElement,n=t.position,s=t.classNames,o=this._elementType;this.containerOuter=new F({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new F({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new D({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new P({element:e.choiceList(t,i)}),this.itemList=new P({element:e.itemList(t,i)}),this.dropdown=new k({element:e.dropdown(t),classNames:s,type:o})},e.prototype._createStructure=function(){var e=this,t=e.containerInner,i=e.containerOuter,n=e.passedElement,s=this.dropdown.element;n.conceal(),t.wrap(n.element),i.wrap(t.element),this._isSelectOneElement?this.input.placeholder=this.config.searchPlaceholderValue||"":(this._placeholderValue&&(this.input.placeholder=this._placeholderValue),this.input.setWidth()),i.element.appendChild(t.element),i.element.appendChild(s),t.element.appendChild(this.itemList.element),s.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&s.insertBefore(this.input.element,s.firstChild):t.element.appendChild(this.input.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}()})); diff --git a/public/assets/scripts/choices.mjs b/public/assets/scripts/choices.mjs index 729df97ee..cdc6efc57 100644 --- a/public/assets/scripts/choices.mjs +++ b/public/assets/scripts/choices.mjs @@ -85,6 +85,12 @@ var EventType = { 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, @@ -328,11 +334,6 @@ var Dropdown = /** @class */ (function () { 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; @@ -403,7 +404,7 @@ var Container = /** @class */ (function () { 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; @@ -412,30 +413,32 @@ var Container = /** @class */ (function () { 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 () { @@ -538,9 +541,9 @@ var Input = /** @class */ (function () { */ 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); @@ -549,7 +552,7 @@ var Input = /** @class */ (function () { this.element.removeAttribute('aria-activedescendant'); }; Input.prototype._onInput = function () { - if (this.type !== SELECT_ONE_TYPE) { + if (this.type !== PassedElementTypes.SelectOne) { this.setWidth(); } }; @@ -567,6 +570,8 @@ var Input = /** @class */ (function () { return Input; }()); +var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -574,9 +579,6 @@ var List = /** @class */ (function () { 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) { @@ -708,15 +710,13 @@ var WrappedElement = /** @class */ (function () { 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) { @@ -850,7 +850,6 @@ var WrappedSelect = /** @class */ (function (_super) { option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -865,9 +864,9 @@ var WrappedSelect = /** @class */ (function (_super) { 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) { @@ -987,38 +986,35 @@ function items(s, action, context) { 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.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 = ''; } } // this is mixing concerns, but this is *so much faster* - removeItem(item_1); - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { - var choice_1 = action.choice; - state = state.filter(function (item) { return item.id !== choice_1.id; }); - removeItem(choice_1); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { @@ -1027,9 +1023,7 @@ function items(s, action, context) { if (item && item.highlighted !== highlighted) { item.highlighted = highlighted; if (context) { - var classNames = context.classNames; - var highlightedState = classNames.highlightedState, selectedState = classNames.selectedState; - updateClassList(item, highlighted ? highlightedState : selectedState, highlighted ? selectedState : highlightedState); + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } } break; @@ -1077,17 +1071,13 @@ function choices(s, action, context) { break; } case ActionType.REMOVE_CHOICE: { - var choice = action.choice; - var choiceEl = choice.choiceEl; - if (choiceEl) { - choiceEl.remove(); - choice.choiceEl = undefined; - } + 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: { @@ -1135,7 +1125,6 @@ function choices(s, action, context) { return { state: state, update: update }; } -// eslint-disable-next-line import/no-cycle var reducers = { groups: groups, items: items, @@ -3089,25 +3078,23 @@ var templates = { 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) { @@ -3116,19 +3103,19 @@ var templates = { } 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); } @@ -3159,10 +3146,9 @@ var templates = { 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'); } @@ -3177,32 +3163,32 @@ var templates = { 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; // eslint-disable-next-line prefer-destructuring var label = choice.label; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + 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); @@ -3213,26 +3199,22 @@ var templates = { if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - div.setAttribute('role', groupId ? 'treeitem' : 'option'); - if (groupId) { - 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; }, @@ -3283,9 +3265,8 @@ var templates = { 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; }, @@ -3310,9 +3291,9 @@ var parseDataSetId = function (element) { 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 @@ -3347,15 +3328,15 @@ var Choices = /** @class */ (function () { throw TypeError("Expected one of the following types text|select-one|select-multiple"); } var elementType = passedElement.type; - var isText = elementType === TEXT_TYPE; + var isText = elementType === PassedElementTypes.Text; if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - elementType = SELECT_MULTIPLE_TYPE; + elementType = PassedElementTypes.SelectMultiple; } - var isSelectOne = elementType === SELECT_ONE_TYPE; - var isSelectMultiple = elementType === SELECT_MULTIPLE_TYPE; + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; var isSelect = isSelectOne || isSelectMultiple; this._elementType = elementType; this._isTextElement = isText; @@ -3363,8 +3344,8 @@ var Choices = /** @class */ (function () { this._isSelectMultipleElement = isSelectMultiple; this._isSelectElement = isSelectOne || isSelectMultiple; this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; @@ -3498,7 +3479,7 @@ var Choices = /** @class */ (function () { 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); } }; @@ -3517,26 +3498,24 @@ var Choices = /** @class */ (function () { 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.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.containerOuter.disable(); } return this; }; @@ -3855,11 +3834,10 @@ var Choices = /** @class */ (function () { } 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; } @@ -3970,36 +3948,36 @@ var Choices = /** @class */ (function () { if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var _a = this, config = _a.config, templates = _a._templates, isSearching = _a._isSearching, choiceList = _a.choiceList; - var _b = this._store, groups = _b.activeGroups, activeChoices = _b.activeChoices; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; + var _a = this, config = _a.config, isSearching = _a._isSearching; var renderLimit = 0; - if (isSearching && searchResultLimit > 0) { - renderLimit = searchResultLimit; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; } - else if (renderChoiceLimit > 0) { - renderLimit = renderChoiceLimit; + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; } var groupLookup = []; var appendGroupInSearch = config.appendGroupInSearch && isSearching; if (appendGroupInSearch) { - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { if (group.label) { groupLookup[group.id] = group.label; } }); } if (this._isSelectElement) { - var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); if (backingOptions.length) { this.passedElement.addOptions(backingOptions); } } var fragment = document.createDocumentFragment(); - var skipSelected = config.renderSelectedChoices === 'auto' && !this._isSelectOneElement; var renderableChoices = function (choices) { - return choices.filter(function (choice) { return !choice.placeholder && !(isSearching && !choice.rank) && !(skipSelected && choice.selected); }); + 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 @@ -4012,34 +3990,36 @@ var Choices = /** @class */ (function () { var choiceLimit = choices.length; choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; choiceLimit--; - // Add each choice to dropdown within range choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed var dropdownItem = choice.choiceEl || - templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + _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; }); }; - var noChoices = true; - if (activeChoices.length) { + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { - requestAnimationFrame(function () { return choiceList.scrollToTop(); }); + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { // If we have a placeholder choice along with groups - renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); } // If we have grouped options - if (groups.length && !isSearching) { + if (this._store.activeGroups.length && !isSearching) { if (config.shouldSort) { - groups.sort(config.sorter); + this._store.activeGroups.sort(config.sorter); } - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { var groupChoices = renderableChoices(group.choices); if (groupChoices.length) { if (group.label) { - var dropdownGroup = group.groupEl || templates.choiceGroup(_this.config, group); + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); group.groupEl = dropdownGroup; dropdownGroup.remove(); fragment.appendChild(dropdownGroup); @@ -4049,25 +4029,25 @@ var Choices = /** @class */ (function () { }); } else { - renderChoices(renderableChoices(activeChoices), false); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !fragment.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(fragment); - choiceList.element.replaceChildren(fragment); - if (!noChoices) { + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; @@ -4075,7 +4055,7 @@ var Choices = /** @class */ (function () { var _this = this; var items = this._store.items || []; var itemList = this.itemList.element; - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; + var config = this.config; var fragment = document.createDocumentFragment(); var itemFromList = function (item) { return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); @@ -4092,7 +4072,7 @@ var Choices = /** @class */ (function () { // new items items.forEach(addItemToFragment); var addItems = !!fragment.childNodes.length; - if (isSelectOneElement && this._hasNonChoicePlaceholder) { + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { var existingItems = itemList.children.length; if (addItems || existingItems > 1) { var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); @@ -4112,7 +4092,7 @@ var Choices = /** @class */ (function () { } if (addItems) { itemList.append(fragment); - if (config.shouldSortItems && !isSelectOneElement) { + if (config.shouldSortItems && !this._isSelectOneElement) { items.sort(config.sorter); // push sorting into the DOM items.forEach(function (item) { @@ -4320,9 +4300,8 @@ var Choices = /** @class */ (function () { // 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); @@ -4343,23 +4322,22 @@ var Choices = /** @class */ (function () { }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement, itemList = _a.itemList; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); - if (isSelectOneElement) { - itemList.clear(); - itemList.element.append(this._templates.placeholder(config, config.loadingText)); + if (this._isSelectOneElement) { + 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 (isSelectOneElement) { - itemList.clear(); + if (this._isSelectOneElement) { + el.replaceChildren(''); this._render(); } else { @@ -4371,12 +4349,9 @@ var Choices = /** @class */ (function () { 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(EventType.search, { @@ -4385,7 +4360,7 @@ var Choices = /** @class */ (function () { }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -4393,7 +4368,7 @@ var Choices = /** @class */ (function () { var config = this.config; var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { - this.choiceList.clear(); + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -4636,10 +4611,8 @@ var Choices = /** @class */ (function () { } }; 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) { @@ -4649,12 +4622,10 @@ var Choices = /** @class */ (function () { }; 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; } @@ -4664,7 +4635,7 @@ var Choices = /** @class */ (function () { } 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; } @@ -4686,7 +4657,7 @@ var Choices = /** @class */ (function () { 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, @@ -4701,7 +4672,7 @@ var Choices = /** @class */ (function () { return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -4713,14 +4684,13 @@ var Choices = /** @class */ (function () { } }; 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) { @@ -4753,9 +4723,8 @@ var Choices = /** @class */ (function () { } }; 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(); } @@ -4803,15 +4772,13 @@ var Choices = /** @class */ (function () { } 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); } } @@ -4832,7 +4799,7 @@ var Choices = /** @class */ (function () { 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(); @@ -4925,17 +4892,17 @@ var Choices = /** @class */ (function () { 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) { @@ -4955,7 +4922,7 @@ var Choices = /** @class */ (function () { 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(EventType.highlightChoice, { el: passedEl, @@ -4970,12 +4937,11 @@ var Choices = /** @class */ (function () { 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) { @@ -4986,8 +4952,7 @@ var Choices = /** @class */ (function () { } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } this._store.dispatch(removeItem$1(item)); @@ -5029,9 +4994,8 @@ var Choices = /** @class */ (function () { 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; + group.id = this._lastAddedGroupId; group.choices.forEach(function (item) { item.groupId = group.id; if (group.disabled) { @@ -5044,7 +5008,7 @@ var Choices = /** @class */ (function () { 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 = {}; @@ -5060,11 +5024,11 @@ var Choices = /** @class */ (function () { }; 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, @@ -5082,10 +5046,10 @@ var Choices = /** @class */ (function () { 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), @@ -5094,7 +5058,8 @@ var Choices = /** @class */ (function () { }); }; 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 @@ -5102,23 +5067,23 @@ var Choices = /** @class */ (function () { // 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; @@ -5169,9 +5134,8 @@ var Choices = /** @class */ (function () { 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.search-basic.js b/public/assets/scripts/choices.search-basic.js index ef6d3c420..ad787cff6 100644 --- a/public/assets/scripts/choices.search-basic.js +++ b/public/assets/scripts/choices.search-basic.js @@ -91,6 +91,12 @@ 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, @@ -334,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; @@ -409,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; @@ -418,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 () { @@ -544,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); @@ -555,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(); } }; @@ -573,6 +576,8 @@ return Input; }()); + var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -580,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) { @@ -714,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) { @@ -856,7 +856,6 @@ option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -871,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) { @@ -993,38 +992,35 @@ 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.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 = ''; } } // this is mixing concerns, but this is *so much faster* - removeItem(item_1); - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { - var choice_1 = action.choice; - state = state.filter(function (item) { return item.id !== choice_1.id; }); - removeItem(choice_1); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { @@ -1033,9 +1029,7 @@ if (item && item.highlighted !== highlighted) { item.highlighted = highlighted; if (context) { - var classNames = context.classNames; - var highlightedState = classNames.highlightedState, selectedState = classNames.selectedState; - updateClassList(item, highlighted ? highlightedState : selectedState, highlighted ? selectedState : highlightedState); + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } } break; @@ -1083,17 +1077,13 @@ break; } case ActionType.REMOVE_CHOICE: { - var choice = action.choice; - var choiceEl = choice.choiceEl; - if (choiceEl) { - choiceEl.remove(); - choice.choiceEl = undefined; - } + 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: { @@ -1141,7 +1131,6 @@ return { state: state, update: update }; } - // eslint-disable-next-line import/no-cycle var reducers = { groups: groups, items: items, @@ -2613,25 +2602,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) { @@ -2640,19 +2627,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); } @@ -2683,10 +2670,9 @@ 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'); } @@ -2701,32 +2687,32 @@ 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; // eslint-disable-next-line prefer-destructuring var label = choice.label; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + 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); @@ -2737,26 +2723,22 @@ if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - div.setAttribute('role', groupId ? 'treeitem' : 'option'); - if (groupId) { - 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; }, @@ -2807,9 +2789,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; }, @@ -2834,9 +2815,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 @@ -2871,15 +2852,15 @@ throw TypeError("Expected one of the following types text|select-one|select-multiple"); } var elementType = passedElement.type; - var isText = elementType === TEXT_TYPE; + var isText = elementType === PassedElementTypes.Text; if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - elementType = SELECT_MULTIPLE_TYPE; + elementType = PassedElementTypes.SelectMultiple; } - var isSelectOne = elementType === SELECT_ONE_TYPE; - var isSelectMultiple = elementType === SELECT_MULTIPLE_TYPE; + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; var isSelect = isSelectOne || isSelectMultiple; this._elementType = elementType; this._isTextElement = isText; @@ -2887,8 +2868,8 @@ this._isSelectMultipleElement = isSelectMultiple; this._isSelectElement = isSelectOne || isSelectMultiple; this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; @@ -3022,7 +3003,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); } }; @@ -3041,26 +3022,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.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.containerOuter.disable(); } return this; }; @@ -3379,11 +3358,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; } @@ -3494,36 +3472,36 @@ if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var _a = this, config = _a.config, templates = _a._templates, isSearching = _a._isSearching, choiceList = _a.choiceList; - var _b = this._store, groups = _b.activeGroups, activeChoices = _b.activeChoices; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; + var _a = this, config = _a.config, isSearching = _a._isSearching; var renderLimit = 0; - if (isSearching && searchResultLimit > 0) { - renderLimit = searchResultLimit; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; } - else if (renderChoiceLimit > 0) { - renderLimit = renderChoiceLimit; + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; } var groupLookup = []; var appendGroupInSearch = config.appendGroupInSearch && isSearching; if (appendGroupInSearch) { - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { if (group.label) { groupLookup[group.id] = group.label; } }); } if (this._isSelectElement) { - var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); if (backingOptions.length) { this.passedElement.addOptions(backingOptions); } } var fragment = document.createDocumentFragment(); - var skipSelected = config.renderSelectedChoices === 'auto' && !this._isSelectOneElement; var renderableChoices = function (choices) { - return choices.filter(function (choice) { return !choice.placeholder && !(isSearching && !choice.rank) && !(skipSelected && choice.selected); }); + 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 @@ -3536,34 +3514,36 @@ var choiceLimit = choices.length; choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; choiceLimit--; - // Add each choice to dropdown within range choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed var dropdownItem = choice.choiceEl || - templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + _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; }); }; - var noChoices = true; - if (activeChoices.length) { + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { - requestAnimationFrame(function () { return choiceList.scrollToTop(); }); + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { // If we have a placeholder choice along with groups - renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); } // If we have grouped options - if (groups.length && !isSearching) { + if (this._store.activeGroups.length && !isSearching) { if (config.shouldSort) { - groups.sort(config.sorter); + this._store.activeGroups.sort(config.sorter); } - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { var groupChoices = renderableChoices(group.choices); if (groupChoices.length) { if (group.label) { - var dropdownGroup = group.groupEl || templates.choiceGroup(_this.config, group); + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); group.groupEl = dropdownGroup; dropdownGroup.remove(); fragment.appendChild(dropdownGroup); @@ -3573,25 +3553,25 @@ }); } else { - renderChoices(renderableChoices(activeChoices), false); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !fragment.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(fragment); - choiceList.element.replaceChildren(fragment); - if (!noChoices) { + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; @@ -3599,7 +3579,7 @@ var _this = this; var items = this._store.items || []; var itemList = this.itemList.element; - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; + var config = this.config; var fragment = document.createDocumentFragment(); var itemFromList = function (item) { return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); @@ -3616,7 +3596,7 @@ // new items items.forEach(addItemToFragment); var addItems = !!fragment.childNodes.length; - if (isSelectOneElement && this._hasNonChoicePlaceholder) { + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { var existingItems = itemList.children.length; if (addItems || existingItems > 1) { var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); @@ -3636,7 +3616,7 @@ } if (addItems) { itemList.append(fragment); - if (config.shouldSortItems && !isSelectOneElement) { + if (config.shouldSortItems && !this._isSelectOneElement) { items.sort(config.sorter); // push sorting into the DOM items.forEach(function (item) { @@ -3844,9 +3824,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); @@ -3867,23 +3846,22 @@ }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement, itemList = _a.itemList; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); - if (isSelectOneElement) { - itemList.clear(); - itemList.element.append(this._templates.placeholder(config, config.loadingText)); + if (this._isSelectOneElement) { + 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 (isSelectOneElement) { - itemList.clear(); + if (this._isSelectOneElement) { + el.replaceChildren(''); this._render(); } else { @@ -3895,12 +3873,9 @@ 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(EventType.search, { @@ -3909,7 +3884,7 @@ }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -3917,7 +3892,7 @@ var config = this.config; var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { - this.choiceList.clear(); + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -4160,10 +4135,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) { @@ -4173,12 +4146,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; } @@ -4188,7 +4159,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; } @@ -4210,7 +4181,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, @@ -4225,7 +4196,7 @@ return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -4237,14 +4208,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) { @@ -4277,9 +4247,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(); } @@ -4327,15 +4296,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); } } @@ -4356,7 +4323,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(); @@ -4449,17 +4416,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) { @@ -4479,7 +4446,7 @@ 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(EventType.highlightChoice, { el: passedEl, @@ -4494,12 +4461,11 @@ 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) { @@ -4510,8 +4476,7 @@ } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } this._store.dispatch(removeItem$1(item)); @@ -4553,9 +4518,8 @@ 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; + group.id = this._lastAddedGroupId; group.choices.forEach(function (item) { item.groupId = group.id; if (group.disabled) { @@ -4568,7 +4532,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 = {}; @@ -4584,11 +4548,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, @@ -4606,10 +4570,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), @@ -4618,7 +4582,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 @@ -4626,23 +4591,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; @@ -4693,9 +4658,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.search-basic.min.js b/public/assets/scripts/choices.search-basic.min.js index e8507f9d9..789b8977e 100644 --- a/public/assets/scripts/choices.search-basic.min.js +++ b/public/assets/scripts/choices.search-basic.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&&!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,L(this.classNames.openState)),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&((n=this.element.classList).add.apply(n,L(this.classNames.flippedState)),this.isFlipped=!0)},e.prototype.close=function(){var e,t;(e=this.element.classList).remove.apply(e,L(this.classNames.openState)),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&((t=this.element.classList).remove.apply(t,L(this.classNames.flippedState)),this.isFlipped=!1)},e.prototype.addFocusState=function(){var e;(e=this.element.classList).add.apply(e,L(this.classNames.focusState))},e.prototype.removeFocusState=function(){var e;(e=this.element.classList).remove.apply(e,L(this.classNames.focusState))},e.prototype.enable=function(){var e;(e=this.element.classList).remove.apply(e,L(this.classNames.disabledState)),this.element.removeAttribute("aria-disabled"),this.type===M&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){var e;(e=this.element.classList).add.apply(e,L(this.classNames.disabledState)),this.element.setAttribute("aria-disabled","true"),this.type===M&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=e.parentNode;t&&(e.nextSibling?t.insertBefore(this.element,e.nextSibling):t.appendChild(this.element)),this.element.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element.parentNode;t&&(t.insertBefore(e,this.element),t.removeChild(this.element))},e.prototype.addLoadingState=function(){var e;(e=this.element.classList).add.apply(e,L(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,L(this.classNames.loadingState)),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),D=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,t=e.style,i=e.value;t.minWidth="".concat(e.placeholder.length+1,"ch"),t.width="".concat(i.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!==M&&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.clear=function(){this.element.innerHTML=""},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,L(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,L(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}(),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:C(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){!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?H(t.labelClass):void 0,labelDescription:void 0!==t.labelDescription?t.labelDescription:void 0,customProperties:T(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}(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 C(void 0===i?e.value:i).localeCompare(C(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:(h=t.item).selected=!0,(o=h.element)&&(o.selected=!0,o.setAttribute("selected","")),n.push(h);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&&R(c)&&c.type===M&&(c.value="")}U(a),n=n.filter((function(e){return e.id!==a.id}));break;case r:var l=t.choice;n=n.filter((function(e){return e.id!==l.id})),U(l);break;case p:var h,f=t.highlighted;if((h=n.find((function(e){return e.id===t.item.id})))&&h.highlighted!==f&&(h.highlighted=f,i)){var m=i.classNames,v=m.highlightedState,_=m.selectedState;!function(e,t,i){var n,s,o=e.itemEl;o&&((n=o.classList).remove.apply(n,L(i)),(s=o.classList).add.apply(s,L(t)))}(h,f?v:_,f?_:v)}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:var h=t.choice,p=h.choiceEl;p&&(p.remove(),h.choiceEl=void 0),n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:break;case a:var f=[];t.results.forEach((function(e){f[e.item.id]=e})),n.forEach((function(e){var t=f[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),w[o]=(w[o+1]<<1|1)&a,n&&(w[o]|=(g[o+1]|g[o])<<1|1|g[o+1]),w[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=w}const w={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&&(w.indices=e):w.isMatch=!1}return w}(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 Se=[];function Ce(e,t){for(let i=0,n=Se.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=Ce(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=Ce(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=Ce(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=L(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)))},ke=function(e,t,i){var n=t&&e.querySelector("label[for='".concat(t,"']")),s=n&&n.innerText;s&&i.setAttribute("aria-label",s)},De={containerOuter:function(e,t,i,n,s,o,r){var a=e.classNames.containerOuter,c=document.createElement("div");return c.className=L(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||ke(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=L(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(L(s).join(" ")," ").concat(t?L(o).join(" "):L(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=L(n).join(" "),A(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=t.labelClass,_=t.label,g=t.disabled,y=t.value,b=C(y),E=document.createElement("div");if(E.className=L(u).join(" "),v){var S=document.createElement("span");A(S,r,_),S.className=L(v).join(" "),E.appendChild(S)}else A(E,r,_);var I=E.dataset;if(I.item="",I.id=t.id,I.value=b,Fe(E,t,!0),(g||this.containerOuter.isDisabled)&&E.setAttribute("aria-disabled","true"),this._isSelectElement&&(E.setAttribute("aria-selected","true"),E.setAttribute("role","option")),t.placeholder&&((n=E.classList).add.apply(n,L(m)),I.placeholder=""),(s=E.classList).add.apply(s,L(t.highlighted?p:f)),i){g&&(o=E.classList).remove.apply(o,L(f)),I.deletable="";var O=document.createElement("button");O.type="button",O.className=L(d).join(" "),A(O,!0,w(c,y));var x=w(l,y);x&&O.setAttribute("aria-label",x),O.dataset.button="",a?E.insertAdjacentElement("afterbegin",O):E.appendChild(O)}return E},choiceList:function(e,t){var i=e.classNames.list,n=document.createElement("div");return n.className=L(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=C(c),u=document.createElement("div");u.className="".concat(L(s).join(" ")," ").concat(l?L(r).join(" "):""),u.setAttribute("role","group");var d=u.dataset;d.group="",d.id=a,d.value=h,l&&u.setAttribute("aria-disabled","true");var p=document.createElement("div");return p.className=L(o).join(" "),A(p,i,c||""),u.appendChild(p),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=t.elementId,b=t.groupId,E=t.labelClass,w=t.labelDescription,S=C(t.value),O=document.createElement("div");O.id=y,O.className="".concat(L(u).join(" ")," ").concat(L(d).join(" ")),n&&"string"==typeof g&&(g=I(l,g),g={trusted:g+=" (".concat(n,")")});var x=O;if(E){var T=document.createElement("span");A(T,l,g),T.className=L(E).join(" "),x=T,O.appendChild(T)}else A(O,l,g);if(w){var N="".concat(y,"-description");x.setAttribute("aria-describedby",N);var M=document.createElement("span");A(M,l,w),M.id=N,(s=M.classList).add.apply(s,L(v)),O.appendChild(M)}t.selected&&(o=O.classList).add.apply(o,L(f)),t.placeholder&&(r=O.classList).add.apply(r,L(_));var F=O.dataset;return O.setAttribute("role",b?"treeitem":"option"),b&&(F.groupId="".concat(b)),F.choice="",F.id=t.id,F.value=S,i&&(F.selectText=i),Fe(O,t,!1),t.disabled?((a=O.classList).add.apply(a,L(m)),F.choiceDisabled="",O.setAttribute("aria-disabled","true")):((c=O.classList).add.apply(c,L(p)),F.choiceSelectable=""),O},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(L(n).join(" ")," ").concat(L(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||ke(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,L(s)),(i=r.classList).add.apply(i,L(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([],L(s.item),!0),L(o),!0),L(l),!0);switch(i){case X:h.push.apply(h,L(r));break;case z:h.push.apply(h,L(a));break;case J:h.push.apply(h,L(c))}var u=document.createElement("div");if(A(u,!0,t),u.className=h.join(" "),i===X){var d=u.dataset;d.choiceSelectable="",d.choice=""}return u},option:function(e){var t=C(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){var t=e.dataset.id;return t?parseInt(t,10):void 0}},Be=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=F);var u=l===M,d=l===F,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,["auto","always"].includes("".concat(r.renderSelectedChoices))||(r.renderSelectedChoices="auto"),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(y(2))||y(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 De}})},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;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},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},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(g(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(g(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(g(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(g(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(m,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=G,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._canAddItems()){var t=this.config,i=this._isSearching,n=0;i&&t.searchResultLimit>0?n=t.searchResultLimit:t.renderChoiceLimit>0&&(n=t.renderChoiceLimit);var s=[],o=t.appendGroupInSearch&&i;if(o&&this._store.activeGroups.forEach((function(e){e.label&&(s[e.id]=e.label)})),this._isSelectElement){var r=this._store.activeChoices.filter((function(e){return!e.element}));r.length&&this.passedElement.addOptions(r)}var a=document.createDocumentFragment(),c=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},l=this._isSelectOneElement,h=function(r,c){i?r.sort(x):t.shouldSort&&r.sort(t.sorter);var h=r.length;h=!c&&n&&h>n?n:h,h--,r.every((function(n,r){var c=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o&&n.groupId?s[n.groupId]:void 0);return n.choiceEl=c,a.appendChild(c),!i&&n.selected||(l=!0),r1){var l=i.querySelector(N(n.classNames.placeholder));l&&l.remove()}else c||(a=!0,r(V({selected:!0,value:"",label:n.placeholderValue||"",placeholder:!0},!1)))}a&&(i.append(s),n.shouldSortItems&&!this._isSelectOneElement&&(t.sort(n.sorter),t.forEach((function(e){var t=o(e);t&&(t.remove(),s.append(t))})),i.append(s))),this._isTextElement&&(this.passedElement.value=t.map((function(e){return e.value})).join(n.delimiter))},e.prototype._displayNotice=function(e,t,i){void 0===i&&(i=!0);var n=this._notice;n&&(n.type===t&&n.text===e||n.type===X&&(t===z||t===J))?i&&this.showDropdown(!0):(this._clearNotice(),this._notice=e?{text:e,type:t}:void 0,this._renderNotice(),i&&e&&this.showDropdown(!0))},e.prototype._clearNotice=function(){if(this._notice){var e=this.choiceList.element.querySelector(N(this.config.classNames.notice));e&&e.remove(),this._notice=void 0}},e.prototype._renderNotice=function(e){var t=this._notice;if(t){var i=this._templates.notice(this.config,t.text,t.type);e?e.append(i):this.choiceList.prepend(i)}},e.prototype._getChoiceForOutput=function(e,t){if(e){var i=e.groupId?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,i=this._store.items;if(i.length&&this.config.removeItems&&this.config.removeItemButton){var n=e&&Ke(e.parentNode),s=n&&i.find((function(e){return e.id===n}));s&&this._store.withTxn((function(){if(t._removeItem(s),t._triggerChange(s.value),t._isSelectOneElement&&!t._hasNonChoicePlaceholder){var e=t._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));e&&(t._addItem(e),t.unhighlightAll(),e.value&&t._triggerChange(e.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){if(this._presetChoices=t.items.map((function(e){return V(e,!1)})),this.passedElement.value){var i=this.passedElement.value.split(t.delimiter).map((function(e){return V(e,!1)}));this._presetChoices=this._presetChoices.concat(i)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=t.choices.map((function(e){return V(e,!0)}));var n=this.passedElement.optionsAsChoices();n&&(e=this._presetChoices).push.apply(e,n)}},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.itemList.element;e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?t.replaceChildren(this._templates.placeholder(this.config,this.config.loadingText)):this.input.placeholder=this.config.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement?(t.replaceChildren(""),this._render()):this.input.placeholder=this._placeholderValue||"")},e.prototype._handleSearch=function(e){if(this.input.isFocussed)if(null!=e&&e.length>=this.config.searchFloor){var t=this.config.searchChoices?this._searchChoices(e):0;null!==t&&this.passedElement.triggerEvent(f,{value:e,resultCount:t})}else this._store.choices.some((function(e){return!e.active}))&&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.choiceList.element.replaceChildren(""),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=S(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=S(t.uniqueItemText,e))}return i&&(n=S(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===z&&this._clearNotice():this._displayNotice(I(this.config.noResultsText),z)),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(f,{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.input.value,s=e.target;if(e.preventDefault(),s&&s.hasAttribute("data-button"))this._handleButtonAction(s);else if(t){var o=this.dropdown.element.querySelector(N(this.config.classNames.highlightedState));if(!o||!this._handleChoiceAction(o))if(s&&n){if(this._canAddItems()){var r=!1;this._store.withTxn((function(){if(!(r=i._findAndSelectChoiceByValue(n,!0))){if(!i._canAddUserChoices)return;if(!i._canCreateItem(n))return;var e=C(n),t=i.config.allowHtmlUserInput||e===n?n:{escaped:e,raw:n};i._addChoice(V({value:t,label:t,selected:!0},!1),!0,!0),r=!0}i.clearInput(),i.unhighlightAll()})),r&&(this._triggerChange(n),this.config.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;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var r=40===o||34===o?1:-1,a=void 0;if(e.metaKey||34===o||33===o)a=this.dropdown.element.querySelector(r>0?"".concat(Be,":last-of-type"):Be);else{var c=this.dropdown.element.querySelector(N(this.config.classNames.highlightedState));a=c?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}(c,Be,r):this.dropdown.element.querySelector(Be)}a&&(i=a,n=this.choiceList.element,void 0===(s=r)&&(s=1),(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(a,r),this._highlightChoice(a)),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(Pe&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?i[this._highlightPosition]:i[i.length-1])||(n=i[0]),(t=n.classList).add.apply(t,s),n.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:n}),this.dropdown.isActive&&(this.input.setActiveDescendant(n.id),this.containerOuter.setActiveDescendant(n.id))}},e.prototype._addItem=function(e,t,i){if(void 0===t&&(t=!0),void 0===i&&(i=!1),!e.id)throw new TypeError("item.id must be set before _addItem is called for a choice/item");(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&this.removeActiveItems(e.id),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(m,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");this._store.dispatch(function(e){return{type:h,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.groupId=e.id,e.disabled&&(n.disabled=!0),i._addChoice(n,t)})))},e.prototype._createTemplates=function(){var e=this,t=this.config.callbackOnCreateTemplates,i={};"function"==typeof t&&(i=t.call(this,w,O));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=this._isSelectOneElement,n=t.position,s=t.classNames,o=this._elementType;this.containerOuter=new D({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new D({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new k({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new P({element:e.choiceList(t,i)}),this.itemList=new P({element:e.itemList(t,i)}),this.dropdown=new F({element:e.dropdown(t),classNames:s,type:o})},e.prototype._createStructure=function(){var e=this,t=e.containerInner,i=e.containerOuter,n=e.passedElement,s=this.dropdown.element;n.conceal(),t.wrap(n.element),i.wrap(t.element),this._isSelectOneElement?this.input.placeholder=this.config.searchPlaceholderValue||"":(this._placeholderValue&&(this.input.placeholder=this._placeholderValue),this.input.setWidth()),i.element.appendChild(t.element),i.element.appendChild(s),t.element.appendChild(this.itemList.element),s.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&s.insertBefore(this.input.element,s.firstChild):t.element.appendChild(this.input.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}()})); diff --git a/public/assets/scripts/choices.search-basic.mjs b/public/assets/scripts/choices.search-basic.mjs index 0651a316a..1b764e3d8 100644 --- a/public/assets/scripts/choices.search-basic.mjs +++ b/public/assets/scripts/choices.search-basic.mjs @@ -85,6 +85,12 @@ var EventType = { 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, @@ -328,11 +334,6 @@ var Dropdown = /** @class */ (function () { 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; @@ -403,7 +404,7 @@ var Container = /** @class */ (function () { 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; @@ -412,30 +413,32 @@ var Container = /** @class */ (function () { 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 () { @@ -538,9 +541,9 @@ var Input = /** @class */ (function () { */ 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); @@ -549,7 +552,7 @@ var Input = /** @class */ (function () { this.element.removeAttribute('aria-activedescendant'); }; Input.prototype._onInput = function () { - if (this.type !== SELECT_ONE_TYPE) { + if (this.type !== PassedElementTypes.SelectOne) { this.setWidth(); } }; @@ -567,6 +570,8 @@ var Input = /** @class */ (function () { return Input; }()); +var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -574,9 +579,6 @@ var List = /** @class */ (function () { 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) { @@ -708,15 +710,13 @@ var WrappedElement = /** @class */ (function () { 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) { @@ -850,7 +850,6 @@ var WrappedSelect = /** @class */ (function (_super) { option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -865,9 +864,9 @@ var WrappedSelect = /** @class */ (function (_super) { 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) { @@ -987,38 +986,35 @@ function items(s, action, context) { 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.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 = ''; } } // this is mixing concerns, but this is *so much faster* - removeItem(item_1); - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { - var choice_1 = action.choice; - state = state.filter(function (item) { return item.id !== choice_1.id; }); - removeItem(choice_1); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { @@ -1027,9 +1023,7 @@ function items(s, action, context) { if (item && item.highlighted !== highlighted) { item.highlighted = highlighted; if (context) { - var classNames = context.classNames; - var highlightedState = classNames.highlightedState, selectedState = classNames.selectedState; - updateClassList(item, highlighted ? highlightedState : selectedState, highlighted ? selectedState : highlightedState); + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } } break; @@ -1077,17 +1071,13 @@ function choices(s, action, context) { break; } case ActionType.REMOVE_CHOICE: { - var choice = action.choice; - var choiceEl = choice.choiceEl; - if (choiceEl) { - choiceEl.remove(); - choice.choiceEl = undefined; - } + 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: { @@ -1135,7 +1125,6 @@ function choices(s, action, context) { return { state: state, update: update }; } -// eslint-disable-next-line import/no-cycle var reducers = { groups: groups, items: items, @@ -2607,25 +2596,23 @@ var templates = { 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) { @@ -2634,19 +2621,19 @@ var templates = { } 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); } @@ -2677,10 +2664,9 @@ var templates = { 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'); } @@ -2695,32 +2681,32 @@ var templates = { 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; // eslint-disable-next-line prefer-destructuring var label = choice.label; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + 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); @@ -2731,26 +2717,22 @@ var templates = { if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - div.setAttribute('role', groupId ? 'treeitem' : 'option'); - if (groupId) { - 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; }, @@ -2801,9 +2783,8 @@ var templates = { 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; }, @@ -2828,9 +2809,9 @@ var parseDataSetId = function (element) { 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 @@ -2865,15 +2846,15 @@ var Choices = /** @class */ (function () { throw TypeError("Expected one of the following types text|select-one|select-multiple"); } var elementType = passedElement.type; - var isText = elementType === TEXT_TYPE; + var isText = elementType === PassedElementTypes.Text; if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - elementType = SELECT_MULTIPLE_TYPE; + elementType = PassedElementTypes.SelectMultiple; } - var isSelectOne = elementType === SELECT_ONE_TYPE; - var isSelectMultiple = elementType === SELECT_MULTIPLE_TYPE; + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; var isSelect = isSelectOne || isSelectMultiple; this._elementType = elementType; this._isTextElement = isText; @@ -2881,8 +2862,8 @@ var Choices = /** @class */ (function () { this._isSelectMultipleElement = isSelectMultiple; this._isSelectElement = isSelectOne || isSelectMultiple; this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; @@ -3016,7 +2997,7 @@ var Choices = /** @class */ (function () { 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); } }; @@ -3035,26 +3016,24 @@ var Choices = /** @class */ (function () { 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.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.containerOuter.disable(); } return this; }; @@ -3373,11 +3352,10 @@ var Choices = /** @class */ (function () { } 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; } @@ -3488,36 +3466,36 @@ var Choices = /** @class */ (function () { if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var _a = this, config = _a.config, templates = _a._templates, isSearching = _a._isSearching, choiceList = _a.choiceList; - var _b = this._store, groups = _b.activeGroups, activeChoices = _b.activeChoices; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; + var _a = this, config = _a.config, isSearching = _a._isSearching; var renderLimit = 0; - if (isSearching && searchResultLimit > 0) { - renderLimit = searchResultLimit; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; } - else if (renderChoiceLimit > 0) { - renderLimit = renderChoiceLimit; + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; } var groupLookup = []; var appendGroupInSearch = config.appendGroupInSearch && isSearching; if (appendGroupInSearch) { - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { if (group.label) { groupLookup[group.id] = group.label; } }); } if (this._isSelectElement) { - var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); if (backingOptions.length) { this.passedElement.addOptions(backingOptions); } } var fragment = document.createDocumentFragment(); - var skipSelected = config.renderSelectedChoices === 'auto' && !this._isSelectOneElement; var renderableChoices = function (choices) { - return choices.filter(function (choice) { return !choice.placeholder && !(isSearching && !choice.rank) && !(skipSelected && choice.selected); }); + 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 @@ -3530,34 +3508,36 @@ var Choices = /** @class */ (function () { var choiceLimit = choices.length; choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; choiceLimit--; - // Add each choice to dropdown within range choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed var dropdownItem = choice.choiceEl || - templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + _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; }); }; - var noChoices = true; - if (activeChoices.length) { + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { - requestAnimationFrame(function () { return choiceList.scrollToTop(); }); + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { // If we have a placeholder choice along with groups - renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); } // If we have grouped options - if (groups.length && !isSearching) { + if (this._store.activeGroups.length && !isSearching) { if (config.shouldSort) { - groups.sort(config.sorter); + this._store.activeGroups.sort(config.sorter); } - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { var groupChoices = renderableChoices(group.choices); if (groupChoices.length) { if (group.label) { - var dropdownGroup = group.groupEl || templates.choiceGroup(_this.config, group); + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); group.groupEl = dropdownGroup; dropdownGroup.remove(); fragment.appendChild(dropdownGroup); @@ -3567,25 +3547,25 @@ var Choices = /** @class */ (function () { }); } else { - renderChoices(renderableChoices(activeChoices), false); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !fragment.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(fragment); - choiceList.element.replaceChildren(fragment); - if (!noChoices) { + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; @@ -3593,7 +3573,7 @@ var Choices = /** @class */ (function () { var _this = this; var items = this._store.items || []; var itemList = this.itemList.element; - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; + var config = this.config; var fragment = document.createDocumentFragment(); var itemFromList = function (item) { return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); @@ -3610,7 +3590,7 @@ var Choices = /** @class */ (function () { // new items items.forEach(addItemToFragment); var addItems = !!fragment.childNodes.length; - if (isSelectOneElement && this._hasNonChoicePlaceholder) { + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { var existingItems = itemList.children.length; if (addItems || existingItems > 1) { var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); @@ -3630,7 +3610,7 @@ var Choices = /** @class */ (function () { } if (addItems) { itemList.append(fragment); - if (config.shouldSortItems && !isSelectOneElement) { + if (config.shouldSortItems && !this._isSelectOneElement) { items.sort(config.sorter); // push sorting into the DOM items.forEach(function (item) { @@ -3838,9 +3818,8 @@ var Choices = /** @class */ (function () { // 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); @@ -3861,23 +3840,22 @@ var Choices = /** @class */ (function () { }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement, itemList = _a.itemList; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); - if (isSelectOneElement) { - itemList.clear(); - itemList.element.append(this._templates.placeholder(config, config.loadingText)); + if (this._isSelectOneElement) { + 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 (isSelectOneElement) { - itemList.clear(); + if (this._isSelectOneElement) { + el.replaceChildren(''); this._render(); } else { @@ -3889,12 +3867,9 @@ var Choices = /** @class */ (function () { 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(EventType.search, { @@ -3903,7 +3878,7 @@ var Choices = /** @class */ (function () { }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -3911,7 +3886,7 @@ var Choices = /** @class */ (function () { var config = this.config; var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { - this.choiceList.clear(); + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -4154,10 +4129,8 @@ var Choices = /** @class */ (function () { } }; 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) { @@ -4167,12 +4140,10 @@ var Choices = /** @class */ (function () { }; 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; } @@ -4182,7 +4153,7 @@ var Choices = /** @class */ (function () { } 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; } @@ -4204,7 +4175,7 @@ var Choices = /** @class */ (function () { 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, @@ -4219,7 +4190,7 @@ var Choices = /** @class */ (function () { return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -4231,14 +4202,13 @@ var Choices = /** @class */ (function () { } }; 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) { @@ -4271,9 +4241,8 @@ var Choices = /** @class */ (function () { } }; 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(); } @@ -4321,15 +4290,13 @@ var Choices = /** @class */ (function () { } 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); } } @@ -4350,7 +4317,7 @@ var Choices = /** @class */ (function () { 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(); @@ -4443,17 +4410,17 @@ var Choices = /** @class */ (function () { 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) { @@ -4473,7 +4440,7 @@ var Choices = /** @class */ (function () { 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(EventType.highlightChoice, { el: passedEl, @@ -4488,12 +4455,11 @@ var Choices = /** @class */ (function () { 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) { @@ -4504,8 +4470,7 @@ var Choices = /** @class */ (function () { } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } this._store.dispatch(removeItem$1(item)); @@ -4547,9 +4512,8 @@ var Choices = /** @class */ (function () { 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; + group.id = this._lastAddedGroupId; group.choices.forEach(function (item) { item.groupId = group.id; if (group.disabled) { @@ -4562,7 +4526,7 @@ var Choices = /** @class */ (function () { 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 = {}; @@ -4578,11 +4542,11 @@ var Choices = /** @class */ (function () { }; 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, @@ -4600,10 +4564,10 @@ var Choices = /** @class */ (function () { 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), @@ -4612,7 +4576,8 @@ var Choices = /** @class */ (function () { }); }; 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 @@ -4620,23 +4585,23 @@ var Choices = /** @class */ (function () { // 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; @@ -4687,9 +4652,8 @@ var Choices = /** @class */ (function () { 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.search-prefix.js b/public/assets/scripts/choices.search-prefix.js index 87f266da7..d821bc579 100644 --- a/public/assets/scripts/choices.search-prefix.js +++ b/public/assets/scripts/choices.search-prefix.js @@ -91,6 +91,12 @@ 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, @@ -334,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; @@ -409,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; @@ -418,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 () { @@ -544,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); @@ -555,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(); } }; @@ -573,6 +576,8 @@ return Input; }()); + var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -580,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) { @@ -714,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) { @@ -856,7 +856,6 @@ option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -871,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) { @@ -993,38 +992,35 @@ 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.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 = ''; } } // this is mixing concerns, but this is *so much faster* - removeItem(item_1); - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { - var choice_1 = action.choice; - state = state.filter(function (item) { return item.id !== choice_1.id; }); - removeItem(choice_1); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { @@ -1033,9 +1029,7 @@ if (item && item.highlighted !== highlighted) { item.highlighted = highlighted; if (context) { - var classNames = context.classNames; - var highlightedState = classNames.highlightedState, selectedState = classNames.selectedState; - updateClassList(item, highlighted ? highlightedState : selectedState, highlighted ? selectedState : highlightedState); + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } } break; @@ -1083,17 +1077,13 @@ break; } case ActionType.REMOVE_CHOICE: { - var choice = action.choice; - var choiceEl = choice.choiceEl; - if (choiceEl) { - choiceEl.remove(); - choice.choiceEl = undefined; - } + 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: { @@ -1141,7 +1131,6 @@ return { state: state, update: update }; } - // eslint-disable-next-line import/no-cycle var reducers = { groups: groups, items: items, @@ -1464,25 +1453,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) { @@ -1491,19 +1478,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); } @@ -1534,10 +1521,9 @@ 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'); } @@ -1552,32 +1538,32 @@ 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; // eslint-disable-next-line prefer-destructuring var label = choice.label; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + 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); @@ -1588,26 +1574,22 @@ if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - div.setAttribute('role', groupId ? 'treeitem' : 'option'); - if (groupId) { - 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; }, @@ -1658,9 +1640,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; }, @@ -1685,9 +1666,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 @@ -1722,15 +1703,15 @@ throw TypeError("Expected one of the following types text|select-one|select-multiple"); } var elementType = passedElement.type; - var isText = elementType === TEXT_TYPE; + var isText = elementType === PassedElementTypes.Text; if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - elementType = SELECT_MULTIPLE_TYPE; + elementType = PassedElementTypes.SelectMultiple; } - var isSelectOne = elementType === SELECT_ONE_TYPE; - var isSelectMultiple = elementType === SELECT_MULTIPLE_TYPE; + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; var isSelect = isSelectOne || isSelectMultiple; this._elementType = elementType; this._isTextElement = isText; @@ -1738,8 +1719,8 @@ this._isSelectMultipleElement = isSelectMultiple; this._isSelectElement = isSelectOne || isSelectMultiple; this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; @@ -1873,7 +1854,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); } }; @@ -1892,26 +1873,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.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.containerOuter.disable(); } return this; }; @@ -2230,11 +2209,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; } @@ -2345,36 +2323,36 @@ if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var _a = this, config = _a.config, templates = _a._templates, isSearching = _a._isSearching, choiceList = _a.choiceList; - var _b = this._store, groups = _b.activeGroups, activeChoices = _b.activeChoices; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; + var _a = this, config = _a.config, isSearching = _a._isSearching; var renderLimit = 0; - if (isSearching && searchResultLimit > 0) { - renderLimit = searchResultLimit; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; } - else if (renderChoiceLimit > 0) { - renderLimit = renderChoiceLimit; + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; } var groupLookup = []; var appendGroupInSearch = config.appendGroupInSearch && isSearching; if (appendGroupInSearch) { - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { if (group.label) { groupLookup[group.id] = group.label; } }); } if (this._isSelectElement) { - var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); if (backingOptions.length) { this.passedElement.addOptions(backingOptions); } } var fragment = document.createDocumentFragment(); - var skipSelected = config.renderSelectedChoices === 'auto' && !this._isSelectOneElement; var renderableChoices = function (choices) { - return choices.filter(function (choice) { return !choice.placeholder && !(isSearching && !choice.rank) && !(skipSelected && choice.selected); }); + 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 @@ -2387,34 +2365,36 @@ var choiceLimit = choices.length; choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; choiceLimit--; - // Add each choice to dropdown within range choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed var dropdownItem = choice.choiceEl || - templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + _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; }); }; - var noChoices = true; - if (activeChoices.length) { + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { - requestAnimationFrame(function () { return choiceList.scrollToTop(); }); + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { // If we have a placeholder choice along with groups - renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); } // If we have grouped options - if (groups.length && !isSearching) { + if (this._store.activeGroups.length && !isSearching) { if (config.shouldSort) { - groups.sort(config.sorter); + this._store.activeGroups.sort(config.sorter); } - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { var groupChoices = renderableChoices(group.choices); if (groupChoices.length) { if (group.label) { - var dropdownGroup = group.groupEl || templates.choiceGroup(_this.config, group); + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); group.groupEl = dropdownGroup; dropdownGroup.remove(); fragment.appendChild(dropdownGroup); @@ -2424,25 +2404,25 @@ }); } else { - renderChoices(renderableChoices(activeChoices), false); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !fragment.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(fragment); - choiceList.element.replaceChildren(fragment); - if (!noChoices) { + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; @@ -2450,7 +2430,7 @@ var _this = this; var items = this._store.items || []; var itemList = this.itemList.element; - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; + var config = this.config; var fragment = document.createDocumentFragment(); var itemFromList = function (item) { return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); @@ -2467,7 +2447,7 @@ // new items items.forEach(addItemToFragment); var addItems = !!fragment.childNodes.length; - if (isSelectOneElement && this._hasNonChoicePlaceholder) { + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { var existingItems = itemList.children.length; if (addItems || existingItems > 1) { var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); @@ -2487,7 +2467,7 @@ } if (addItems) { itemList.append(fragment); - if (config.shouldSortItems && !isSelectOneElement) { + if (config.shouldSortItems && !this._isSelectOneElement) { items.sort(config.sorter); // push sorting into the DOM items.forEach(function (item) { @@ -2695,9 +2675,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); @@ -2718,23 +2697,22 @@ }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement, itemList = _a.itemList; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); - if (isSelectOneElement) { - itemList.clear(); - itemList.element.append(this._templates.placeholder(config, config.loadingText)); + if (this._isSelectOneElement) { + 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 (isSelectOneElement) { - itemList.clear(); + if (this._isSelectOneElement) { + el.replaceChildren(''); this._render(); } else { @@ -2746,12 +2724,9 @@ 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(EventType.search, { @@ -2760,7 +2735,7 @@ }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -2768,7 +2743,7 @@ var config = this.config; var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { - this.choiceList.clear(); + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -3011,10 +2986,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) { @@ -3024,12 +2997,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; } @@ -3039,7 +3010,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; } @@ -3061,7 +3032,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, @@ -3076,7 +3047,7 @@ return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -3088,14 +3059,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) { @@ -3128,9 +3098,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(); } @@ -3178,15 +3147,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); } } @@ -3207,7 +3174,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(); @@ -3300,17 +3267,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) { @@ -3330,7 +3297,7 @@ 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(EventType.highlightChoice, { el: passedEl, @@ -3345,12 +3312,11 @@ 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) { @@ -3361,8 +3327,7 @@ } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } this._store.dispatch(removeItem$1(item)); @@ -3404,9 +3369,8 @@ 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; + group.id = this._lastAddedGroupId; group.choices.forEach(function (item) { item.groupId = group.id; if (group.disabled) { @@ -3419,7 +3383,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 = {}; @@ -3435,11 +3399,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, @@ -3457,10 +3421,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), @@ -3469,7 +3433,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 @@ -3477,23 +3442,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; @@ -3544,9 +3509,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.search-prefix.min.js b/public/assets/scripts/choices.search-prefix.min.js index 23aa5f952..db65005d5 100644 --- a/public/assets/scripts/choices.search-prefix.min.js +++ b/public/assets/scripts/choices.search-prefix.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&&!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===D&&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===D&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=e.parentNode;t&&(e.nextSibling?t.insertBefore(this.element,e.nextSibling):t.appendChild(this.element)),this.element.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element.parentNode;t&&(t.insertBefore(e,this.element),t.removeChild(this.element))},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,t=e.style,i=e.value;t.minWidth="".concat(e.placeholder.length+1,"ch"),t.width="".concat(i.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!==D&&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.clear=function(){this.element.innerHTML=""},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,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(){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}(),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:w(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){!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?H(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}(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 w(void 0===i?e.value:i).localeCompare(w(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:(h=t.item).selected=!0,(o=h.element)&&(o.selected=!0,o.setAttribute("selected","")),n.push(h);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&&R(c)&&c.type===D&&(c.value="")}U(a),n=n.filter((function(e){return e.id!==a.id}));break;case r:var l=t.choice;n=n.filter((function(e){return e.id!==l.id})),U(l);break;case p:var h,m=t.highlighted;if((h=n.find((function(e){return e.id===t.item.id})))&&h.highlighted!==m&&(h.highlighted=m,i)){var f=i.classNames,v=f.highlightedState,_=f.selectedState;!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)))}(h,m?v:_,m?_:v)}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:var h=t.choice,p=h.choiceEl;p&&(p.remove(),h.choiceEl=void 0),n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:break;case a:var m=[];t.results.forEach((function(e){m[e.item.id]=e})),n.forEach((function(e){var t=m[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=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)))},$=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=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||$(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(" "),A(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,m=h.itemSelectable,f=h.placeholder,v=t.labelClass,_=t.label,g=t.disabled,y=t.value,b=w(y),E=document.createElement("div");if(E.className=T(u).join(" "),v){var S=document.createElement("span");A(S,r,_),S.className=T(v).join(" "),E.appendChild(S)}else A(E,r,_);var I=E.dataset;if(I.item="",I.id=t.id,I.value=b,Z(E,t,!0),(g||this.containerOuter.isDisabled)&&E.setAttribute("aria-disabled","true"),this._isSelectElement&&(E.setAttribute("aria-selected","true"),E.setAttribute("role","option")),t.placeholder&&((n=E.classList).add.apply(n,T(f)),I.placeholder=""),(s=E.classList).add.apply(s,T(t.highlighted?p:m)),i){g&&(o=E.classList).remove.apply(o,T(m)),I.deletable="";var O=document.createElement("button");O.type="button",O.className=T(d).join(" "),A(O,!0,C(c,y));var L=C(l,y);L&&O.setAttribute("aria-label",L),O.dataset.button="",a?E.insertAdjacentElement("afterbegin",O):E.appendChild(O)}return E},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=w(c),u=document.createElement("div");u.className="".concat(T(s).join(" ")," ").concat(l?T(r).join(" "):""),u.setAttribute("role","group");var d=u.dataset;d.group="",d.id=a,d.value=h,l&&u.setAttribute("aria-disabled","true");var p=document.createElement("div");return p.className=T(o).join(" "),A(p,i,c||""),u.appendChild(p),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,m=h.selectedState,f=h.itemDisabled,v=h.description,_=h.placeholder,g=t.label,y=t.elementId,b=t.groupId,E=t.labelClass,C=t.labelDescription,S=w(t.value),O=document.createElement("div");O.id=y,O.className="".concat(T(u).join(" ")," ").concat(T(d).join(" ")),n&&"string"==typeof g&&(g=I(l,g),g={trusted:g+=" (".concat(n,")")});var L=O;if(E){var x=document.createElement("span");A(x,l,g),x.className=T(E).join(" "),L=x,O.appendChild(x)}else A(O,l,g);if(C){var N="".concat(y,"-description");L.setAttribute("aria-describedby",N);var D=document.createElement("span");A(D,l,C),D.id=N,(s=D.classList).add.apply(s,T(v)),O.appendChild(D)}t.selected&&(o=O.classList).add.apply(o,T(m)),t.placeholder&&(r=O.classList).add.apply(r,T(_));var P=O.dataset;return O.setAttribute("role",b?"treeitem":"option"),b&&(P.groupId="".concat(b)),P.choice="",P.id=t.id,P.value=S,i&&(P.selectText=i),Z(O,t,!1),t.disabled?((a=O.classList).add.apply(a,T(f)),P.choiceDisabled="",O.setAttribute("aria-disabled","true")):((c=O.classList).add.apply(c,T(p)),P.choiceSelectable=""),O},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||$(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 Q: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");if(A(u,!0,t),u.className=h.join(" "),i===Q){var d=u.dataset;d.choiceSelectable="",d.choice=""}return u},option:function(e){var t=w(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){var t=e.dataset.id;return t?parseInt(t,10):void 0}},se=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=P);var u=l===D,d=l===P,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,["auto","always"].includes("".concat(r.renderSelectedChoices))||(r.renderSelectedChoices="auto"),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 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||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(y(2))||y(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;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},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},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(g(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(g(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(g(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(g(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(f,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=G,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._canAddItems()){var t=this.config,i=this._isSearching,n=0;i&&t.searchResultLimit>0?n=t.searchResultLimit:t.renderChoiceLimit>0&&(n=t.renderChoiceLimit);var s=[],o=t.appendGroupInSearch&&i;if(o&&this._store.activeGroups.forEach((function(e){e.label&&(s[e.id]=e.label)})),this._isSelectElement){var r=this._store.activeChoices.filter((function(e){return!e.element}));r.length&&this.passedElement.addOptions(r)}var a=document.createDocumentFragment(),c=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},l=this._isSelectOneElement,h=function(r,c){i?r.sort(L):t.shouldSort&&r.sort(t.sorter);var h=r.length;h=!c&&n&&h>n?n:h,h--,r.every((function(n,r){var c=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o&&n.groupId?s[n.groupId]:void 0);return n.choiceEl=c,a.appendChild(c),!i&&n.selected||(l=!0),r1){var l=i.querySelector(N(n.classNames.placeholder));l&&l.remove()}else c||(a=!0,r(V({selected:!0,value:"",label:n.placeholderValue||"",placeholder:!0},!1)))}a&&(i.append(s),n.shouldSortItems&&!this._isSelectOneElement&&(t.sort(n.sorter),t.forEach((function(e){var t=o(e);t&&(t.remove(),s.append(t))})),i.append(s))),this._isTextElement&&(this.passedElement.value=t.map((function(e){return e.value})).join(n.delimiter))},e.prototype._displayNotice=function(e,t,i){void 0===i&&(i=!0);var n=this._notice;n&&(n.type===t&&n.text===e||n.type===Q&&(t===z||t===J))?i&&this.showDropdown(!0):(this._clearNotice(),this._notice=e?{text:e,type:t}:void 0,this._renderNotice(),i&&e&&this.showDropdown(!0))},e.prototype._clearNotice=function(){if(this._notice){var e=this.choiceList.element.querySelector(N(this.config.classNames.notice));e&&e.remove(),this._notice=void 0}},e.prototype._renderNotice=function(e){var t=this._notice;if(t){var i=this._templates.notice(this.config,t.text,t.type);e?e.append(i):this.choiceList.prepend(i)}},e.prototype._getChoiceForOutput=function(e,t){if(e){var i=e.groupId?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,i=this._store.items;if(i.length&&this.config.removeItems&&this.config.removeItemButton){var n=e&&ne(e.parentNode),s=n&&i.find((function(e){return e.id===n}));s&&this._store.withTxn((function(){if(t._removeItem(s),t._triggerChange(s.value),t._isSelectOneElement&&!t._hasNonChoicePlaceholder){var e=t._store.choices.reverse().find((function(e){return!e.disabled&&e.placeholder}));e&&(t._addItem(e),t.unhighlightAll(),e.value&&t._triggerChange(e.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=ne(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=ne(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){if(this._presetChoices=t.items.map((function(e){return V(e,!1)})),this.passedElement.value){var i=this.passedElement.value.split(t.delimiter).map((function(e){return V(e,!1)}));this._presetChoices=this._presetChoices.concat(i)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=t.choices.map((function(e){return V(e,!0)}));var n=this.passedElement.optionsAsChoices();n&&(e=this._presetChoices).push.apply(e,n)}},e.prototype._handleLoadingState=function(e){void 0===e&&(e=!0);var t=this.itemList.element;e?(this.disable(),this.containerOuter.addLoadingState(),this._isSelectOneElement?t.replaceChildren(this._templates.placeholder(this.config,this.config.loadingText)):this.input.placeholder=this.config.loadingText):(this.enable(),this.containerOuter.removeLoadingState(),this._isSelectOneElement?(t.replaceChildren(""),this._render()):this.input.placeholder=this._placeholderValue||"")},e.prototype._handleSearch=function(e){if(this.input.isFocussed)if(null!=e&&e.length>=this.config.searchFloor){var t=this.config.searchChoices?this._searchChoices(e):0;null!==t&&this.passedElement.triggerEvent(m,{value:e,resultCount:t})}else this._store.choices.some((function(e){return!e.active}))&&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.choiceList.element.replaceChildren(""),this._displayNotice("function"==typeof i?i(t):i,Q),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=w(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("",Q),!1}else this._isTextElement&&!t.duplicateItemsAllowed&&s&&(i=!1,n=w(t.uniqueItemText,e))}return i&&(n=w(t.addItemText,e)),n&&this._displayNotice(n,Q),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!==Q&&(n.length?o===z&&this._clearNotice():this._displayNotice(I(this.config.noResultsText),z)),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(m,{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.input.value,s=e.target;if(e.preventDefault(),s&&s.hasAttribute("data-button"))this._handleButtonAction(s);else if(t){var o=this.dropdown.element.querySelector(N(this.config.classNames.highlightedState));if(!o||!this._handleChoiceAction(o))if(s&&n){if(this._canAddItems()){var r=!1;this._store.withTxn((function(){if(!(r=i._findAndSelectChoiceByValue(n,!0))){if(!i._canAddUserChoices)return;if(!i._canCreateItem(n))return;var e=C(n),t=i.config.allowHtmlUserInput||e===n?n:{escaped:e,raw:n};i._addChoice(V({value:t,label:t,selected:!0},!1),!0,!0),r=!0}i.clearInput(),i.unhighlightAll()})),r&&(this._triggerChange(n),this.config.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;if(t||this._isSelectOneElement){this.showDropdown(),this._canSearch=!1;var r=40===o||34===o?1:-1,a=void 0;if(e.metaKey||34===o||33===o)a=this.dropdown.element.querySelector(r>0?"".concat(se,":last-of-type"):se);else{var c=this.dropdown.element.querySelector(N(this.config.classNames.highlightedState));a=c?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}(c,se,r):this.dropdown.element.querySelector(se)}a&&(i=a,n=this.choiceList.element,void 0===(s=r)&&(s=1),(s>0?n.scrollTop+n.offsetHeight>=i.offsetTop+i.offsetHeight:i.offsetTop>=n.scrollTop)||this.choiceList.scrollToChildElement(a,r),this._highlightChoice(a)),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(te&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?i[this._highlightPosition]:i[i.length-1])||(n=i[0]),(t=n.classList).add.apply(t,s),n.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:n}),this.dropdown.isActive&&(this.input.setActiveDescendant(n.id),this.containerOuter.setActiveDescendant(n.id))}},e.prototype._addItem=function(e,t,i){if(void 0===t&&(t=!0),void 0===i&&(i=!1),!e.id)throw new TypeError("item.id must be set before _addItem is called for a choice/item");(this.config.singleModeForMultiSelect||this._isSelectOneElement)&&this.removeActiveItems(e.id),this._store.dispatch(function(e){return{type:d,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:u,item:e}}(e)),this.passedElement.triggerEvent(f,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");this._store.dispatch(function(e){return{type:h,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.groupId=e.id,e.disabled&&(n.disabled=!0),i._addChoice(n,t)})))},e.prototype._createTemplates=function(){var e=this,t=this.config.callbackOnCreateTemplates,i={};"function"==typeof t&&(i=t.call(this,S,O));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=this._isSelectOneElement,n=t.position,s=t.classNames,o=this._elementType;this.containerOuter=new F({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new F({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new k({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new j({element:e.choiceList(t,i)}),this.itemList=new j({element:e.itemList(t,i)}),this.dropdown=new P({element:e.dropdown(t),classNames:s,type:o})},e.prototype._createStructure=function(){var e=this,t=e.containerInner,i=e.containerOuter,n=e.passedElement,s=this.dropdown.element;n.conceal(),t.wrap(n.element),i.wrap(t.element),this._isSelectOneElement?this.input.placeholder=this.config.searchPlaceholderValue||"":(this._placeholderValue&&(this.input.placeholder=this._placeholderValue),this.input.setWidth()),i.element.appendChild(t.element),i.element.appendChild(s),t.element.appendChild(this.itemList.element),s.appendChild(this.choiceList.element),this._isSelectOneElement?this.config.searchEnabled&&s.insertBefore(this.input.element,s.firstChild):t.element.appendChild(this.input.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}()})); diff --git a/public/assets/scripts/choices.search-prefix.mjs b/public/assets/scripts/choices.search-prefix.mjs index a543e1caa..e1cdee3d2 100644 --- a/public/assets/scripts/choices.search-prefix.mjs +++ b/public/assets/scripts/choices.search-prefix.mjs @@ -85,6 +85,12 @@ var EventType = { 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, @@ -328,11 +334,6 @@ var Dropdown = /** @class */ (function () { 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; @@ -403,7 +404,7 @@ var Container = /** @class */ (function () { 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; @@ -412,30 +413,32 @@ var Container = /** @class */ (function () { 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 () { @@ -538,9 +541,9 @@ var Input = /** @class */ (function () { */ 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); @@ -549,7 +552,7 @@ var Input = /** @class */ (function () { this.element.removeAttribute('aria-activedescendant'); }; Input.prototype._onInput = function () { - if (this.type !== SELECT_ONE_TYPE) { + if (this.type !== PassedElementTypes.SelectOne) { this.setWidth(); } }; @@ -567,6 +570,8 @@ var Input = /** @class */ (function () { return Input; }()); +var SCROLLING_SPEED = 4; + var List = /** @class */ (function () { function List(_a) { var element = _a.element; @@ -574,9 +579,6 @@ var List = /** @class */ (function () { 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) { @@ -708,15 +710,13 @@ var WrappedElement = /** @class */ (function () { 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) { @@ -850,7 +850,6 @@ var WrappedSelect = /** @class */ (function (_super) { option.setAttribute('value', ''); option.value = ''; } - var dataset = option.dataset; return { id: 0, groupId: 0, @@ -865,9 +864,9 @@ var WrappedSelect = /** @class */ (function (_super) { 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) { @@ -987,38 +986,35 @@ function items(s, action, context) { 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.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 = ''; } } // this is mixing concerns, but this is *so much faster* - removeItem(item_1); - state = state.filter(function (choice) { return choice.id !== item_1.id; }); + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); break; } case ActionType.REMOVE_CHOICE: { - var choice_1 = action.choice; - state = state.filter(function (item) { return item.id !== choice_1.id; }); - removeItem(choice_1); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + removeItem(action.choice); break; } case ActionType.HIGHLIGHT_ITEM: { @@ -1027,9 +1023,7 @@ function items(s, action, context) { if (item && item.highlighted !== highlighted) { item.highlighted = highlighted; if (context) { - var classNames = context.classNames; - var highlightedState = classNames.highlightedState, selectedState = classNames.selectedState; - updateClassList(item, highlighted ? highlightedState : selectedState, highlighted ? selectedState : highlightedState); + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); } } break; @@ -1077,17 +1071,13 @@ function choices(s, action, context) { break; } case ActionType.REMOVE_CHOICE: { - var choice = action.choice; - var choiceEl = choice.choiceEl; - if (choiceEl) { - choiceEl.remove(); - choice.choiceEl = undefined; - } + 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: { @@ -1135,7 +1125,6 @@ function choices(s, action, context) { return { state: state, update: update }; } -// eslint-disable-next-line import/no-cycle var reducers = { groups: groups, items: items, @@ -1458,25 +1447,23 @@ var templates = { 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) { @@ -1485,19 +1472,19 @@ var templates = { } 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); } @@ -1528,10 +1515,9 @@ var templates = { 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'); } @@ -1546,32 +1532,32 @@ var templates = { 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; // eslint-disable-next-line prefer-destructuring var label = choice.label; - var value = choice.value, elementId = choice.elementId, groupId = choice.groupId, labelClass = choice.labelClass, labelDescription = choice.labelDescription; - var rawValue = unwrapStringForRaw(value); + 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); @@ -1582,26 +1568,22 @@ var templates = { if (choice.placeholder) { (_d = div.classList).add.apply(_d, getClassNames(placeholder)); } - var dataset = div.dataset; - div.setAttribute('role', groupId ? 'treeitem' : 'option'); - if (groupId) { - 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; }, @@ -1652,9 +1634,8 @@ var templates = { 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; }, @@ -1679,9 +1660,9 @@ var parseDataSetId = function (element) { 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 @@ -1716,15 +1697,15 @@ var Choices = /** @class */ (function () { throw TypeError("Expected one of the following types text|select-one|select-multiple"); } var elementType = passedElement.type; - var isText = elementType === TEXT_TYPE; + var isText = elementType === PassedElementTypes.Text; if (isText || config.maxItemCount !== 1) { config.singleModeForMultiSelect = false; } if (config.singleModeForMultiSelect) { - elementType = SELECT_MULTIPLE_TYPE; + elementType = PassedElementTypes.SelectMultiple; } - var isSelectOne = elementType === SELECT_ONE_TYPE; - var isSelectMultiple = elementType === SELECT_MULTIPLE_TYPE; + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; var isSelect = isSelectOne || isSelectMultiple; this._elementType = elementType; this._isTextElement = isText; @@ -1732,8 +1713,8 @@ var Choices = /** @class */ (function () { this._isSelectMultipleElement = isSelectMultiple; this._isSelectElement = isSelectOne || isSelectMultiple; this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); - if (!['auto', 'always'].includes("".concat(config.renderSelectedChoices))) { - config.renderSelectedChoices = 'auto'; + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; } if (config.closeDropdownOnSelect === 'auto') { config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; @@ -1867,7 +1848,7 @@ var Choices = /** @class */ (function () { 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); } }; @@ -1886,26 +1867,24 @@ var Choices = /** @class */ (function () { 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.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.containerOuter.disable(); } return this; }; @@ -2224,11 +2203,10 @@ var Choices = /** @class */ (function () { } 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; } @@ -2339,36 +2317,36 @@ var Choices = /** @class */ (function () { if (!this._canAddItems()) { return; // block rendering choices if the input limit is reached. } - var _a = this, config = _a.config, templates = _a._templates, isSearching = _a._isSearching, choiceList = _a.choiceList; - var _b = this._store, groups = _b.activeGroups, activeChoices = _b.activeChoices; - var searchResultLimit = config.searchResultLimit, renderChoiceLimit = config.renderChoiceLimit; + var _a = this, config = _a.config, isSearching = _a._isSearching; var renderLimit = 0; - if (isSearching && searchResultLimit > 0) { - renderLimit = searchResultLimit; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; } - else if (renderChoiceLimit > 0) { - renderLimit = renderChoiceLimit; + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; } var groupLookup = []; var appendGroupInSearch = config.appendGroupInSearch && isSearching; if (appendGroupInSearch) { - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { if (group.label) { groupLookup[group.id] = group.label; } }); } if (this._isSelectElement) { - var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + var backingOptions = this._store.activeChoices.filter(function (choice) { return !choice.element; }); if (backingOptions.length) { this.passedElement.addOptions(backingOptions); } } var fragment = document.createDocumentFragment(); - var skipSelected = config.renderSelectedChoices === 'auto' && !this._isSelectOneElement; var renderableChoices = function (choices) { - return choices.filter(function (choice) { return !choice.placeholder && !(isSearching && !choice.rank) && !(skipSelected && choice.selected); }); + 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 @@ -2381,34 +2359,36 @@ var Choices = /** @class */ (function () { var choiceLimit = choices.length; choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; choiceLimit--; - // Add each choice to dropdown within range choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed var dropdownItem = choice.choiceEl || - templates.choice(config, choice, config.itemSelectText, appendGroupInSearch && choice.groupId ? groupLookup[choice.groupId] : undefined); + _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; }); }; - var noChoices = true; - if (activeChoices.length) { + if (this._store.activeChoices.length) { if (config.resetScrollPosition) { - requestAnimationFrame(function () { return choiceList.scrollToTop(); }); + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); } if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { // If we have a placeholder choice along with groups - renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); + renderChoices(this._store.activeChoices.filter(function (choice) { return choice.placeholder && !choice.groupId; }), false); } // If we have grouped options - if (groups.length && !isSearching) { + if (this._store.activeGroups.length && !isSearching) { if (config.shouldSort) { - groups.sort(config.sorter); + this._store.activeGroups.sort(config.sorter); } - groups.forEach(function (group) { + this._store.activeGroups.forEach(function (group) { var groupChoices = renderableChoices(group.choices); if (groupChoices.length) { if (group.label) { - var dropdownGroup = group.groupEl || templates.choiceGroup(_this.config, group); + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); group.groupEl = dropdownGroup; dropdownGroup.remove(); fragment.appendChild(dropdownGroup); @@ -2418,25 +2398,25 @@ var Choices = /** @class */ (function () { }); } else { - renderChoices(renderableChoices(activeChoices), false); + renderChoices(renderableChoices(this._store.activeChoices), false); } - noChoices = !fragment.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(fragment); - choiceList.element.replaceChildren(fragment); - if (!noChoices) { + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { this._highlightChoice(); } }; @@ -2444,7 +2424,7 @@ var Choices = /** @class */ (function () { var _this = this; var items = this._store.items || []; var itemList = this.itemList.element; - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement; + var config = this.config; var fragment = document.createDocumentFragment(); var itemFromList = function (item) { return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); @@ -2461,7 +2441,7 @@ var Choices = /** @class */ (function () { // new items items.forEach(addItemToFragment); var addItems = !!fragment.childNodes.length; - if (isSelectOneElement && this._hasNonChoicePlaceholder) { + if (this._isSelectOneElement && this._hasNonChoicePlaceholder) { var existingItems = itemList.children.length; if (addItems || existingItems > 1) { var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); @@ -2481,7 +2461,7 @@ var Choices = /** @class */ (function () { } if (addItems) { itemList.append(fragment); - if (config.shouldSortItems && !isSelectOneElement) { + if (config.shouldSortItems && !this._isSelectOneElement) { items.sort(config.sorter); // push sorting into the DOM items.forEach(function (item) { @@ -2689,9 +2669,8 @@ var Choices = /** @class */ (function () { // 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); @@ -2712,23 +2691,22 @@ var Choices = /** @class */ (function () { }; Choices.prototype._handleLoadingState = function (setLoading) { if (setLoading === void 0) { setLoading = true; } - var _a = this, config = _a.config, isSelectOneElement = _a._isSelectOneElement, itemList = _a.itemList; + var el = this.itemList.element; if (setLoading) { this.disable(); this.containerOuter.addLoadingState(); - if (isSelectOneElement) { - itemList.clear(); - itemList.element.append(this._templates.placeholder(config, config.loadingText)); + if (this._isSelectOneElement) { + 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 (isSelectOneElement) { - itemList.clear(); + if (this._isSelectOneElement) { + el.replaceChildren(''); this._render(); } else { @@ -2740,12 +2718,9 @@ var Choices = /** @class */ (function () { 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(EventType.search, { @@ -2754,7 +2729,7 @@ var Choices = /** @class */ (function () { }); } } - else if (hasUnactiveChoices) { + else if (this._store.choices.some(function (option) { return !option.active; })) { this._stopSearch(); } }; @@ -2762,7 +2737,7 @@ var Choices = /** @class */ (function () { var config = this.config; var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { - this.choiceList.clear(); + this.choiceList.element.replaceChildren(''); this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); return false; } @@ -3005,10 +2980,8 @@ var Choices = /** @class */ (function () { } }; 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) { @@ -3018,12 +2991,10 @@ var Choices = /** @class */ (function () { }; 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; } @@ -3033,7 +3004,7 @@ var Choices = /** @class */ (function () { } 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; } @@ -3055,7 +3026,7 @@ var Choices = /** @class */ (function () { 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, @@ -3070,7 +3041,7 @@ var Choices = /** @class */ (function () { return; } this._triggerChange(value); - if (config.closeDropdownOnSelect) { + if (this.config.closeDropdownOnSelect) { this.hideDropdown(true); } }; @@ -3082,14 +3053,13 @@ var Choices = /** @class */ (function () { } }; 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) { @@ -3122,9 +3092,8 @@ var Choices = /** @class */ (function () { } }; 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(); } @@ -3172,15 +3141,13 @@ var Choices = /** @class */ (function () { } 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); } } @@ -3201,7 +3168,7 @@ var Choices = /** @class */ (function () { 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(); @@ -3294,17 +3261,17 @@ var Choices = /** @class */ (function () { 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) { @@ -3324,7 +3291,7 @@ var Choices = /** @class */ (function () { 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(EventType.highlightChoice, { el: passedEl, @@ -3339,12 +3306,11 @@ var Choices = /** @class */ (function () { 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) { @@ -3355,8 +3321,7 @@ var Choices = /** @class */ (function () { } }; Choices.prototype._removeItem = function (item) { - var id = item.id; - if (!id) { + if (!item.id) { return; } this._store.dispatch(removeItem$1(item)); @@ -3398,9 +3363,8 @@ var Choices = /** @class */ (function () { 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; + group.id = this._lastAddedGroupId; group.choices.forEach(function (item) { item.groupId = group.id; if (group.disabled) { @@ -3413,7 +3377,7 @@ var Choices = /** @class */ (function () { 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 = {}; @@ -3429,11 +3393,11 @@ var Choices = /** @class */ (function () { }; 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, @@ -3451,10 +3415,10 @@ var Choices = /** @class */ (function () { 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), @@ -3463,7 +3427,8 @@ var Choices = /** @class */ (function () { }); }; 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 @@ -3471,23 +3436,23 @@ var Choices = /** @class */ (function () { // 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; @@ -3538,9 +3503,8 @@ var Choices = /** @class */ (function () { 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/types/src/scripts/components/list.d.ts b/public/types/src/scripts/components/list.d.ts index baaa1c94e..f202a854b 100644 --- a/public/types/src/scripts/components/list.d.ts +++ b/public/types/src/scripts/components/list.d.ts @@ -5,7 +5,6 @@ export default class List { constructor({ element }: { element: HTMLElement; }); - clear(): void; prepend(node: Element | DocumentFragment): void; scrollToTop(): void; scrollToChildElement(element: HTMLElement, direction: 1 | -1): void; diff --git a/public/types/src/scripts/constants.d.ts b/public/types/src/scripts/constants.d.ts index b16044a29..99194be4c 100644 --- a/public/types/src/scripts/constants.d.ts +++ b/public/types/src/scripts/constants.d.ts @@ -1,4 +1 @@ -export declare const TEXT_TYPE: HTMLInputElement['type']; -export declare const SELECT_ONE_TYPE: HTMLSelectElement['type']; -export declare const SELECT_MULTIPLE_TYPE: HTMLSelectElement['type']; export declare const SCROLLING_SPEED: number; diff --git a/public/types/src/scripts/interfaces/action-type.d.ts b/public/types/src/scripts/interfaces/action-type.d.ts index 156999cee..443038e4a 100644 --- a/public/types/src/scripts/interfaces/action-type.d.ts +++ b/public/types/src/scripts/interfaces/action-type.d.ts @@ -1,3 +1,4 @@ +import { Types } from './types'; export declare const ActionType: { readonly ADD_CHOICE: "ADD_CHOICE"; readonly REMOVE_CHOICE: "REMOVE_CHOICE"; @@ -9,4 +10,4 @@ export declare const ActionType: { readonly REMOVE_ITEM: "REMOVE_ITEM"; readonly HIGHLIGHT_ITEM: "HIGHLIGHT_ITEM"; }; -export type ActionTypes = (typeof ActionType)[keyof typeof ActionType]; +export type ActionTypes = Types.ValueOf; diff --git a/public/types/src/scripts/interfaces/event-type.d.ts b/public/types/src/scripts/interfaces/event-type.d.ts index 4ad3b304c..2562c9d61 100644 --- a/public/types/src/scripts/interfaces/event-type.d.ts +++ b/public/types/src/scripts/interfaces/event-type.d.ts @@ -1,3 +1,4 @@ +import { Types } from './types'; export declare const EventType: { readonly showDropdown: "showDropdown"; readonly hideDropdown: "hideDropdown"; @@ -10,4 +11,4 @@ export declare const EventType: { readonly highlightChoice: "highlightChoice"; readonly unhighlightItem: "unhighlightItem"; }; -export type EventTypes = (typeof EventType)[keyof typeof EventType]; +export type EventTypes = Types.ValueOf; diff --git a/public/types/src/scripts/interfaces/options.d.ts b/public/types/src/scripts/interfaces/options.d.ts index 5554ccf85..10e9eb97e 100644 --- a/public/types/src/scripts/interfaces/options.d.ts +++ b/public/types/src/scripts/interfaces/options.d.ts @@ -429,7 +429,7 @@ export interface Options { * * @default 'auto'; */ - renderSelectedChoices: 'auto' | 'always'; + renderSelectedChoices: 'auto' | 'always' | boolean; /** * The text that is shown whilst choices are being populated via AJAX. * diff --git a/public/types/src/scripts/interfaces/passed-element-type.d.ts b/public/types/src/scripts/interfaces/passed-element-type.d.ts index 492258227..9748c0884 100644 --- a/public/types/src/scripts/interfaces/passed-element-type.d.ts +++ b/public/types/src/scripts/interfaces/passed-element-type.d.ts @@ -1 +1,7 @@ -export type PassedElementType = 'text' | 'select-one' | 'select-multiple'; +import { Types } from './types'; +export declare const PassedElementTypes: { + readonly Text: "text"; + readonly SelectOne: "select-one"; + readonly SelectMultiple: "select-multiple"; +}; +export type PassedElementType = Types.ValueOf; diff --git a/public/types/src/scripts/interfaces/templates.d.ts b/public/types/src/scripts/interfaces/templates.d.ts index ef4c98331..8de4217f8 100644 --- a/public/types/src/scripts/interfaces/templates.d.ts +++ b/public/types/src/scripts/interfaces/templates.d.ts @@ -3,6 +3,7 @@ import { StringPreEscaped } from './string-pre-escaped'; import { ChoiceFull } from './choice-full'; import { GroupFull } from './group-full'; import { Options } from './options'; +import { Types } from './types'; export type TemplateOptions = Pick; export declare const NoticeTypes: { readonly noChoices: "no-choices"; @@ -10,7 +11,7 @@ export declare const NoticeTypes: { readonly addChoice: "add-choice"; readonly generic: ""; }; -export type NoticeType = (typeof NoticeTypes)[keyof typeof NoticeTypes]; +export type NoticeType = Types.ValueOf; export interface Templates { containerOuter(options: TemplateOptions, dir: HTMLElement['dir'], isSelectElement: boolean, isSelectOneElement: boolean, searchEnabled: boolean, passedElementType: PassedElementType, labelId: string): HTMLDivElement; containerInner({ classNames: { containerInner } }: TemplateOptions): HTMLDivElement; diff --git a/public/types/src/scripts/interfaces/types.d.ts b/public/types/src/scripts/interfaces/types.d.ts index 716ad8ff0..b76f39a1f 100644 --- a/public/types/src/scripts/interfaces/types.d.ts +++ b/public/types/src/scripts/interfaces/types.d.ts @@ -12,4 +12,5 @@ export declare namespace Types { value?: StringUntrusted | string; label?: StringUntrusted | string; } + type ValueOf = T[keyof T]; }