diff --git a/assets/scripts/choices.js b/assets/scripts/choices.js index e71f6042..9a0a9367 100644 --- a/assets/scripts/choices.js +++ b/assets/scripts/choices.js @@ -1,4 +1,4 @@ -/*! choices.js v11.0.6 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -872,7 +872,9 @@ score: 0, rank: 0, value: option.value, - label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments... + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, element: option, active: true, // this returns true if nothing is selected on initial load, which will break placeholder support @@ -3247,7 +3249,6 @@ inp.autocomplete = 'off'; inp.autocapitalize = 'off'; inp.spellcheck = false; - inp.setAttribute('role', 'textbox'); inp.setAttribute('aria-autocomplete', 'list'); if (placeholderValue) { inp.setAttribute('aria-label', placeholderValue); @@ -5220,7 +5221,7 @@ throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); } }; - Choices.version = '11.0.6'; + Choices.version = '11.1.0'; return Choices; }()); diff --git a/assets/scripts/choices.min.js b/assets/scripts/choices.min.js index fe403b85..cc5baa70 100644 --- a/assets/scripts/choices.min.js +++ b/assets/scripts/choices.min.js @@ -1,2 +1,2 @@ -/*! choices.js v11.0.6 | © 2025 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){P(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&(P(this.element,this.classNames.flippedState),this.isFlipped=!0)},e.prototype.close=function(){j(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(j(this.element,this.classNames.flippedState),this.isFlipped=!1)},e.prototype.addFocusState=function(){P(this.element,this.classNames.focusState)},e.prototype.removeFocusState=function(){j(this.element,this.classNames.focusState)},e.prototype.enable=function(){j(this.element,this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),this.type===_&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){P(this.element,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(){P(this.element,this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){j(this.element,this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),B=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}(),H=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}(),$=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=this.element;P(e,this.classNames.input),e.hidden=!0,e.tabIndex=-1;var t=e.getAttribute("style");t&&e.setAttribute("data-choice-orig-style",t),e.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e=this.element;j(e,this.classNames.input),e.hidden=!1,e.removeAttribute("tabindex");var t=e.getAttribute("data-choice-orig-style");t?(e.removeAttribute("data-choice-orig-style"),e.setAttribute("style",t)):e.removeAttribute("style"),e.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}(),q=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}($),W=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},U=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},G=function(e,t,i){if(void 0===i&&(i=!0),"string"==typeof e){var n=I(e);return G({value:e,label:i||n===e?e:{escaped:n,raw:e},selected:!0},!1)}var s=e;if("choices"in s){if(!t)throw new TypeError("optGroup is not allowed");var o=s,r=o.choices.map((function(e){return G(e,!1)}));return{id:0,label:L(o.label)||o.value,active:!!r.length,disabled:!!o.disabled,choices:r}}var c=s;return{id:0,group:null,score:0,rank:0,value:c.value,label:c.label||c.value,active:W(c.active),selected:W(c.selected,!1),disabled:W(c.disabled,!1),placeholder:W(c.placeholder,!1),highlighted:!1,labelClass:U(c.labelClass),labelDescription:c.labelDescription,customProperties:c.customProperties}},z=function(e){return"SELECT"===e.tagName},J=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,group:null,score:0,rank:0,value:e.value,label:e.innerText,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?U(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:R(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}($),X={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 L(void 0===i?e.value:i).localeCompare(L(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},Q=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},Y={groups:function(e,t){var i=e,n=!0;switch(t.type){case l:i.push(t.group);break;case h:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t,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 c=o.parentElement;c&&z(c)&&c.type===_&&(c.value="")}Q(t.item),n=n.filter((function(e){return e.id!==t.item.id}));break;case r:Q(t.choice),n=n.filter((function(e){return e.id!==t.choice.id}));break;case p:var a=t.highlighted,h=n.find((function(e){return e.id===t.item.id}));h&&h.highlighted!==a&&(h.highlighted=a,i&&function(e,t,i){var n=e.itemEl;n&&(j(n,i),P(n,t))}(h,a?i.classNames.highlightedState:i.classNames.selectedState,a?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,t.choice.group&&(t.choice.group.choices=t.choice.group.choices.filter((function(e){return e.id!==t.choice.id}))),n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:t.item.choiceEl=void 0;break;case c:var l=[];t.results.forEach((function(e){l[e.item.id]=e})),n.forEach((function(e){var t=l[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 a:n.forEach((function(e){e.active=t.active,i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case h:n=[];break;default:s=!1}return{state:n,update:s}}},Z=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){return this._listeners.push(e),this},e.prototype.dispatch=function(e){var t=this,i=this._state,n=!1,s=this._changeSet||this.changeSet(!1);Object.keys(Y).forEach((function(o){var r=Y[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.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}(),ee="no-choices",te="no-results",ie="add-choice";function ne(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 se(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 oe(e){for(var t=1;t`Missing ${e} property in key`,fe=e=>`Property 'weight' in key '${e}' must be a positive integer`,me=Object.prototype.hasOwnProperty;class ge{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=ve(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 ve(e){let t=null,i=null,n=null,s=1,o=null;if(ce(e)||re(e))n=e,t=_e(e),i=ye(e);else{if(!me.call(e,"name"))throw new Error(pe("name"));const r=e.name;if(n=r,me.call(e,"weight")&&(s=e.weight,s<=0))throw new Error(fe(r));t=_e(r),i=ye(r),o=e.getFn}return{path:t,id:i,weight:s,src:n,getFn:o}}function _e(e){return re(e)?e:e.split(".")}function ye(e){return re(e)?e.join("."):e}const be={useExtendedSearch:!1,getFn:function(e,t){let i=[],n=!1;const s=(e,t,o)=>{if(le(e))if(t[o]){const r=e[t[o]];if(!le(r))return;if(o===t.length-1&&(ce(r)||ae(r)||function(e){return!0===e||!1===e||function(e){return he(e)&&null!==e}(e)&&"[object Boolean]"==de(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(re(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,ce(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();ce(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(le(s))if(re(s)){let e=[];const t=[{nestedArrIndex:-1,value:s}];for(;t.length;){const{nestedArrIndex:i,value:n}=t.pop();if(le(n))if(ce(n)&&!ue(n)){let t={v:n,i:i,n:this.norm.get(n)};e.push(t)}else re(n)&&n.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[n]=e}else if(ce(s)&&!ue(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 we(e,t,{getFn:i=Ee.getFn,fieldNormWeight:n=Ee.fieldNormWeight}={}){const s=new Se({getFn:i,fieldNormWeight:n});return s.setKeys(e.map(ve)),s.setSources(t),s.create(),s}function Ie(e,{errors:t=0,currentLocation:i=0,expectedLocation:n=0,distance:s=Ee.distance,ignoreLocation:o=Ee.ignoreLocation}={}){const r=t/e.length;if(o)return r;const c=Math.abs(n-i);return s?r+c/s:c?1:r}const Ae=32;function xe(e){let t={};for(let i=0,n=e.length;i{this.chunks.push({pattern:e,alphabet:xe(e),startIndex:t})},l=this.pattern.length;if(l>Ae){let e=0;const t=l%Ae,i=l-t;for(;e{const{isMatch:f,score:m,indices:g}=function(e,t,i,{location:n=Ee.location,distance:s=Ee.distance,threshold:o=Ee.threshold,findAllMatches:r=Ee.findAllMatches,minMatchCharLength:c=Ee.minMatchCharLength,includeMatches:a=Ee.includeMatches,ignoreLocation:h=Ee.ignoreLocation}={}){if(t.length>Ae)throw new Error("Pattern length exceeds max of 32.");const l=t.length,u=e.length,d=Math.max(0,Math.min(n,u));let p=o,f=d;const m=c>1||a,g=m?Array(u):[];let v;for(;(v=e.indexOf(t,f))>-1;){let e=Ie(t,{currentLocation:v,expectedLocation:d,distance:s,ignoreLocation:h});if(p=Math.min(e,p),f=v+l,m){let e=0;for(;e=a;o-=1){let r=o-1,c=i[e.charAt(r)];if(m&&(g[r]=+!!c),C[o]=(C[o+1]<<1|1)&c,n&&(C[o]|=(_[o+1]|_[o])<<1|1|_[o+1]),C[o]&E&&(y=Ie(t,{errors:n,currentLocation:r,expectedLocation:d,distance:s,ignoreLocation:h}),y<=p)){if(p=y,f=r,f<=d)break;a=Math.max(1,2*d-f)}}if(Ie(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:h})>p)break;_=C}const C={isMatch:f>=0,score:Math.max(.001,y)};if(m){const e=function(e=[],t=Ee.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}(g,c);e.length?a&&(C.indices=e):C.isMatch=!1}return C}(e,t,d,{location:n+p,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:c,includeMatches:i,ignoreLocation:a});f&&(u=!0),l+=m,f&&g&&(h=[...h,...g])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&i&&(d.indices=h),d}}class Le{constructor(e){this.pattern=e}static isMultiMatch(e){return Me(e,this.multiRegex)}static isSingleMatch(e){return Me(e,this.singleRegex)}search(){}}function Me(e,t){const i=e.match(t);return i?i[1]:null}class Te extends Le{constructor(e,{location:t=Ee.location,threshold:i=Ee.threshold,distance:n=Ee.distance,includeMatches:s=Ee.includeMatches,findAllMatches:o=Ee.findAllMatches,minMatchCharLength:r=Ee.minMatchCharLength,isCaseSensitive:c=Ee.isCaseSensitive,ignoreLocation:a=Ee.ignoreLocation}={}){super(e),this._bitapSearch=new Oe(e,{location:t,threshold:i,distance:n,includeMatches:s,findAllMatches:o,minMatchCharLength:r,isCaseSensitive:c,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Ne extends Le{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 ke=[class extends Le{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]}}},Ne,class extends Le{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 Le{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 Le{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 Le{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 Le{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]}}},Te],Fe=ke.length,De=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Pe=new Set([Te.type,Ne.type]);const je=[];function Re(e,t){for(let i=0,n=je.length;i!(!e[Ke]&&!e.$or),He=e=>({[Ke]:Object.keys(e).map((t=>({[t]:e[t]})))});function $e(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Ve])(e);if(!o&&s.length>1&&!Be(e))return n(He(e));if((e=>!re(e)&&he(e)&&!Be(e))(e)){const n=o?e[Ve]:s[0],r=o?e.$val:e[n];if(!ce(r))throw new Error((e=>`Invalid value for key ${e}`)(n));const c={keyId:ye(n),pattern:r};return i&&(c.searcher=Re(r,t)),c}let r={children:[],operator:s[0]};return s.forEach((t=>{const i=e[t];re(i)&&i.forEach((e=>{r.children.push(n(e))}))})),r};return Be(e)||(e=He(e)),n(e)}function qe(e,t){const i=e.matches;t.matches=[],le(i)&&i.forEach((e=>{if(!le(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 We(e,t){t.score=e.score}class Ue{constructor(e,t={},i){this.options=oe(oe({},Ee),t),this._keyStore=new ge(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Se))throw new Error("Incorrect 'index' type");this._myIndex=t||we(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){le(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}))}(c,{ignoreFieldNorm:r}),s&&c.sort(o),ae(t)&&t>-1&&(c=c.slice(0,t)),function(e,t,{includeMatches:i=Ee.includeMatches,includeScore:n=Ee.includeScore}={}){const s=[];return i&&s.push(qe),n&&s.push(We),e.map((e=>{const{idx:i}=e,n={item:t[i],refIndex:i};return s.length&&s.forEach((t=>{t(e,n)})),n}))}(c,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(e){const t=Re(e,this.options),{records:i}=this._myIndex,n=[];return i.forEach((({v:e,i:i,n:s})=>{if(!le(e))return;const{isMatch:o,score:r,indices:c}=t.searchIn(e);o&&n.push({item:e,idx:i,matches:[{score:r,value:e,norm:s,indices:c}]})})),n}_searchLogical(e){const t=$e(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(le(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=Re(e,this.options),{keys:i,records:n}=this._myIndex,s=[];return n.forEach((({$:e,i:n})=>{if(!le(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(!le(t))return[];let n=[];if(re(t))t.forEach((({v:t,i:s,n:o})=>{if(!le(t))return;const{isMatch:r,score:c,indices:a}=i.searchIn(t);r&&n.push({score:c,key:e,value:t,idx:s,norm:o,indices:a})}));else{const{v:s,n:o}=t,{isMatch:r,score:c,indices:a}=i.searchIn(s);r&&n.push({score:c,key:e,value:s,norm:o,indices:a})}return n}}Ue.version="7.0.0",Ue.createIndex=we,Ue.parseIndex=function(e,{getFn:t=Ee.getFn,fieldNormWeight:i=Ee.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new Se({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},Ue.config=Ee,Ue.parseQuery=$e,function(...e){je.push(...e)}(class{constructor(e,{isCaseSensitive:t=Ee.isCaseSensitive,includeMatches:i=Ee.includeMatches,minMatchCharLength:n=Ee.minMatchCharLength,ignoreLocation:s=Ee.ignoreLocation,findAllMatches:o=Ee.findAllMatches,location:r=Ee.location,threshold:c=Ee.threshold,distance:a=Ee.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:i,minMatchCharLength:n,findAllMatches:o,ignoreLocation:s,location:r,threshold:c,distance:a},this.pattern=t?e:e.toLowerCase(),this.query=function(e,t={}){return e.split("|").map((e=>{let i=e.trim().split(De).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._clearNotice(),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(e,t){var i=this;return void 0===e&&(e=!0),void 0===t&&(t=!1),e&&(t?this.passedElement.element.replaceChildren(""):this.passedElement.element.querySelectorAll(":not([selected])").forEach((function(e){e.remove()}))),this.itemList.element.replaceChildren(""),this.choiceList.element.replaceChildren(""),this._clearNotice(),this._store.withTxn((function(){var e=t?[]:i._store.items;i._store.reset(),e.forEach((function(e){i._store.dispatch(b(e)),i._store.dispatch(E(e))}))})),this._searcher.reset(),this},e.prototype.clearStore=function(e){return void 0===e&&(e=!0),this.clearChoices(e,!0),this._stopSearch(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=X,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=this._store,s=n.activeGroups,o=n.activeChoices,r=0;if(i&&t.searchResultLimit>0?r=t.searchResultLimit:t.renderChoiceLimit>0&&(r=t.renderChoiceLimit),this._isSelectElement){var c=o.filter((function(e){return!e.element}));c.length&&this.passedElement.addOptions(c)}var a=document.createDocumentFragment(),h=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},l=!1,u=function(n,s,o){i?n.sort(k):t.shouldSort&&n.sort(t.sorter);var c=n.length;c=!s&&r&&c>r?r:c,c--,n.every((function(n,s){var r=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o);return n.choiceEl=r,a.appendChild(r),!i&&n.selected||(l=!0),s1){var h=i.querySelector(D(n.classNames.placeholder));h&&h.remove()}else c||a||!this._placeholderValue||(c=!0,r(G({selected:!0,value:"",label:this._placeholderValue,placeholder:!0},!1)))}c&&(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===ie&&(t===te||t===ee))?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(D(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){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:e.group?e.group.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&&Ze(e.parentElement),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.config.shouldSort?t._store.choices.reverse():t._store.choices).find((function(e){return 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=Ze(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=Ze(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,i=this.config;if(this._isTextElement){if(this._presetChoices=i.items.map((function(e){return G(e,!1)})),this.passedElement.value){var n=this.passedElement.value.split(i.delimiter).map((function(e){return G(e,!1,t.config.allowHtmlUserInput)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=i.choices.map((function(e){return G(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.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._notice=void 0,this._displayNotice("function"==typeof i?i(t):i,ie),!1):(this._notice&&this._notice.type===ie&&this._clearNotice(),!0)},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=x(t.customAddItemText,e)),i&&this._store.choices.find((function(i){return t.valueComparer(i.value,e)}))){if(this._isSelectElement)return this._displayNotice("",ie),!1;t.duplicateItemsAllowed||(i=!1,n=x(t.uniqueItemText,e))}return i&&(n=x(t.addItemText,e)),n&&this._displayNotice(n,ie),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;return(s&&s.type)!==ie&&(n.length?this._clearNotice():this._displayNotice(O(this.config.noResultsText),te)),this._store.dispatch(function(e){return{type:c,results:e}}(n)),n.length},e.prototype._stopSearch=function(){this._isSearching&&(this._currentValue="",this._isSearching=!1,this._clearNotice(),this._store.dispatch({type:a,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||27===t||9===t||16===t||(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;e?this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice()))):this._isTextElement?this.hideDropdown(!0):this._stopSearch()},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(D(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;i._addChoice(G(n,!1,i.config.allowHtmlUserInput),!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._stopSearch(),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,c=void 0;if(e.metaKey||34===o||33===o)c=this.dropdown.element.querySelector(r>0?"".concat(et,":last-of-type"):et);else{var a=this.dropdown.element.querySelector(D(this.config.classNames.highlightedState));c=a?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}(a,et,r):this.dropdown.element.querySelector(et)}c&&(i=c,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(c,r),this._highlightChoice(c)),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(Qe&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?t[this._highlightPosition]:t[t.length-1])||(i=t[0]),P(i,n),i.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:i}),this.dropdown.isActive&&(this.input.setActiveDescendant(i.id),this.containerOuter.setActiveDescendant(i.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(E(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){if(e.id){this._store.dispatch(C(e));var t=this._notice;t&&t.type===ee&&this._clearNotice(),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");var n=this.config;if(n.duplicateItemsAllowed||!this._store.choices.find((function(t){return n.valueComparer(t.value,e.value)}))){this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var s=n.prependValue,o=n.appendValue;s&&(e.value=s+e.value),o&&(e.value+=o.toString()),(s||o)&&e.element&&(e.element.value=e.value),this._clearNotice(),this._store.dispatch(b(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:l,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.group=e,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,A,T,F));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 V({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new V({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new B({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new H({element:e.choiceList(t,i)}),this.itemList=new H({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).withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),(!this._store.choices.length||this._isSelectOneElement&&this._hasNonChoicePlaceholder)&&this._render()},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.6",e}()})); +/*! choices.js v11.1.0 | © 2025 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){P(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&(P(this.element,this.classNames.flippedState),this.isFlipped=!0)},e.prototype.close=function(){j(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(j(this.element,this.classNames.flippedState),this.isFlipped=!1)},e.prototype.addFocusState=function(){P(this.element,this.classNames.focusState)},e.prototype.removeFocusState=function(){j(this.element,this.classNames.focusState)},e.prototype.enable=function(){j(this.element,this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),this.type===_&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){P(this.element,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(){P(this.element,this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){j(this.element,this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),B=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}(),H=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}(),$=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=this.element;P(e,this.classNames.input),e.hidden=!0,e.tabIndex=-1;var t=e.getAttribute("style");t&&e.setAttribute("data-choice-orig-style",t),e.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e=this.element;j(e,this.classNames.input),e.hidden=!1,e.removeAttribute("tabindex");var t=e.getAttribute("data-choice-orig-style");t?(e.removeAttribute("data-choice-orig-style"),e.setAttribute("style",t)):e.removeAttribute("style"),e.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}(),q=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}($),W=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},U=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},G=function(e,t,i){if(void 0===i&&(i=!0),"string"==typeof e){var n=I(e);return G({value:e,label:i||n===e?e:{escaped:n,raw:e},selected:!0},!1)}var s=e;if("choices"in s){if(!t)throw new TypeError("optGroup is not allowed");var o=s,r=o.choices.map((function(e){return G(e,!1)}));return{id:0,label:L(o.label)||o.value,active:!!r.length,disabled:!!o.disabled,choices:r}}var c=s;return{id:0,group:null,score:0,rank:0,value:c.value,label:c.label||c.value,active:W(c.active),selected:W(c.selected,!1),disabled:W(c.disabled,!1),placeholder:W(c.placeholder,!1),highlighted:!1,labelClass:U(c.labelClass),labelDescription:c.labelDescription,customProperties:c.customProperties}},z=function(e){return"SELECT"===e.tagName},J=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,group:null,score:0,rank:0,value:e.value,label:e.label,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?U(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:R(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}($),X={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 L(void 0===i?e.value:i).localeCompare(L(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},Q=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},Y={groups:function(e,t){var i=e,n=!0;switch(t.type){case l:i.push(t.group);break;case h:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t,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 c=o.parentElement;c&&z(c)&&c.type===_&&(c.value="")}Q(t.item),n=n.filter((function(e){return e.id!==t.item.id}));break;case r:Q(t.choice),n=n.filter((function(e){return e.id!==t.choice.id}));break;case p:var a=t.highlighted,h=n.find((function(e){return e.id===t.item.id}));h&&h.highlighted!==a&&(h.highlighted=a,i&&function(e,t,i){var n=e.itemEl;n&&(j(n,i),P(n,t))}(h,a?i.classNames.highlightedState:i.classNames.selectedState,a?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,t.choice.group&&(t.choice.group.choices=t.choice.group.choices.filter((function(e){return e.id!==t.choice.id}))),n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:t.item.choiceEl=void 0;break;case c:var l=[];t.results.forEach((function(e){l[e.item.id]=e})),n.forEach((function(e){var t=l[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 a:n.forEach((function(e){e.active=t.active,i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case h:n=[];break;default:s=!1}return{state:n,update:s}}},Z=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){return this._listeners.push(e),this},e.prototype.dispatch=function(e){var t=this,i=this._state,n=!1,s=this._changeSet||this.changeSet(!1);Object.keys(Y).forEach((function(o){var r=Y[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.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}(),ee="no-choices",te="no-results",ie="add-choice";function ne(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 se(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 oe(e){for(var t=1;t`Missing ${e} property in key`,fe=e=>`Property 'weight' in key '${e}' must be a positive integer`,me=Object.prototype.hasOwnProperty;class ge{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=ve(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 ve(e){let t=null,i=null,n=null,s=1,o=null;if(ce(e)||re(e))n=e,t=_e(e),i=ye(e);else{if(!me.call(e,"name"))throw new Error(pe("name"));const r=e.name;if(n=r,me.call(e,"weight")&&(s=e.weight,s<=0))throw new Error(fe(r));t=_e(r),i=ye(r),o=e.getFn}return{path:t,id:i,weight:s,src:n,getFn:o}}function _e(e){return re(e)?e:e.split(".")}function ye(e){return re(e)?e.join("."):e}const be={useExtendedSearch:!1,getFn:function(e,t){let i=[],n=!1;const s=(e,t,o)=>{if(le(e))if(t[o]){const r=e[t[o]];if(!le(r))return;if(o===t.length-1&&(ce(r)||ae(r)||function(e){return!0===e||!1===e||function(e){return he(e)&&null!==e}(e)&&"[object Boolean]"==de(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(re(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,ce(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();ce(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(le(s))if(re(s)){let e=[];const t=[{nestedArrIndex:-1,value:s}];for(;t.length;){const{nestedArrIndex:i,value:n}=t.pop();if(le(n))if(ce(n)&&!ue(n)){let t={v:n,i:i,n:this.norm.get(n)};e.push(t)}else re(n)&&n.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[n]=e}else if(ce(s)&&!ue(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 we(e,t,{getFn:i=Ee.getFn,fieldNormWeight:n=Ee.fieldNormWeight}={}){const s=new Se({getFn:i,fieldNormWeight:n});return s.setKeys(e.map(ve)),s.setSources(t),s.create(),s}function Ie(e,{errors:t=0,currentLocation:i=0,expectedLocation:n=0,distance:s=Ee.distance,ignoreLocation:o=Ee.ignoreLocation}={}){const r=t/e.length;if(o)return r;const c=Math.abs(n-i);return s?r+c/s:c?1:r}const Ae=32;function xe(e){let t={};for(let i=0,n=e.length;i{this.chunks.push({pattern:e,alphabet:xe(e),startIndex:t})},l=this.pattern.length;if(l>Ae){let e=0;const t=l%Ae,i=l-t;for(;e{const{isMatch:f,score:m,indices:g}=function(e,t,i,{location:n=Ee.location,distance:s=Ee.distance,threshold:o=Ee.threshold,findAllMatches:r=Ee.findAllMatches,minMatchCharLength:c=Ee.minMatchCharLength,includeMatches:a=Ee.includeMatches,ignoreLocation:h=Ee.ignoreLocation}={}){if(t.length>Ae)throw new Error("Pattern length exceeds max of 32.");const l=t.length,u=e.length,d=Math.max(0,Math.min(n,u));let p=o,f=d;const m=c>1||a,g=m?Array(u):[];let v;for(;(v=e.indexOf(t,f))>-1;){let e=Ie(t,{currentLocation:v,expectedLocation:d,distance:s,ignoreLocation:h});if(p=Math.min(e,p),f=v+l,m){let e=0;for(;e=a;o-=1){let r=o-1,c=i[e.charAt(r)];if(m&&(g[r]=+!!c),C[o]=(C[o+1]<<1|1)&c,n&&(C[o]|=(_[o+1]|_[o])<<1|1|_[o+1]),C[o]&E&&(y=Ie(t,{errors:n,currentLocation:r,expectedLocation:d,distance:s,ignoreLocation:h}),y<=p)){if(p=y,f=r,f<=d)break;a=Math.max(1,2*d-f)}}if(Ie(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:h})>p)break;_=C}const C={isMatch:f>=0,score:Math.max(.001,y)};if(m){const e=function(e=[],t=Ee.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}(g,c);e.length?a&&(C.indices=e):C.isMatch=!1}return C}(e,t,d,{location:n+p,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:c,includeMatches:i,ignoreLocation:a});f&&(u=!0),l+=m,f&&g&&(h=[...h,...g])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&i&&(d.indices=h),d}}class Le{constructor(e){this.pattern=e}static isMultiMatch(e){return Me(e,this.multiRegex)}static isSingleMatch(e){return Me(e,this.singleRegex)}search(){}}function Me(e,t){const i=e.match(t);return i?i[1]:null}class Te extends Le{constructor(e,{location:t=Ee.location,threshold:i=Ee.threshold,distance:n=Ee.distance,includeMatches:s=Ee.includeMatches,findAllMatches:o=Ee.findAllMatches,minMatchCharLength:r=Ee.minMatchCharLength,isCaseSensitive:c=Ee.isCaseSensitive,ignoreLocation:a=Ee.ignoreLocation}={}){super(e),this._bitapSearch=new Oe(e,{location:t,threshold:i,distance:n,includeMatches:s,findAllMatches:o,minMatchCharLength:r,isCaseSensitive:c,ignoreLocation:a})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class Ne extends Le{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 ke=[class extends Le{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]}}},Ne,class extends Le{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 Le{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 Le{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 Le{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 Le{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]}}},Te],Fe=ke.length,De=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,Pe=new Set([Te.type,Ne.type]);const je=[];function Re(e,t){for(let i=0,n=je.length;i!(!e[Ke]&&!e.$or),He=e=>({[Ke]:Object.keys(e).map((t=>({[t]:e[t]})))});function $e(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Ve])(e);if(!o&&s.length>1&&!Be(e))return n(He(e));if((e=>!re(e)&&he(e)&&!Be(e))(e)){const n=o?e[Ve]:s[0],r=o?e.$val:e[n];if(!ce(r))throw new Error((e=>`Invalid value for key ${e}`)(n));const c={keyId:ye(n),pattern:r};return i&&(c.searcher=Re(r,t)),c}let r={children:[],operator:s[0]};return s.forEach((t=>{const i=e[t];re(i)&&i.forEach((e=>{r.children.push(n(e))}))})),r};return Be(e)||(e=He(e)),n(e)}function qe(e,t){const i=e.matches;t.matches=[],le(i)&&i.forEach((e=>{if(!le(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 We(e,t){t.score=e.score}class Ue{constructor(e,t={},i){this.options=oe(oe({},Ee),t),this._keyStore=new ge(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Se))throw new Error("Incorrect 'index' type");this._myIndex=t||we(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){le(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}))}(c,{ignoreFieldNorm:r}),s&&c.sort(o),ae(t)&&t>-1&&(c=c.slice(0,t)),function(e,t,{includeMatches:i=Ee.includeMatches,includeScore:n=Ee.includeScore}={}){const s=[];return i&&s.push(qe),n&&s.push(We),e.map((e=>{const{idx:i}=e,n={item:t[i],refIndex:i};return s.length&&s.forEach((t=>{t(e,n)})),n}))}(c,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(e){const t=Re(e,this.options),{records:i}=this._myIndex,n=[];return i.forEach((({v:e,i:i,n:s})=>{if(!le(e))return;const{isMatch:o,score:r,indices:c}=t.searchIn(e);o&&n.push({item:e,idx:i,matches:[{score:r,value:e,norm:s,indices:c}]})})),n}_searchLogical(e){const t=$e(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(le(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=Re(e,this.options),{keys:i,records:n}=this._myIndex,s=[];return n.forEach((({$:e,i:n})=>{if(!le(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(!le(t))return[];let n=[];if(re(t))t.forEach((({v:t,i:s,n:o})=>{if(!le(t))return;const{isMatch:r,score:c,indices:a}=i.searchIn(t);r&&n.push({score:c,key:e,value:t,idx:s,norm:o,indices:a})}));else{const{v:s,n:o}=t,{isMatch:r,score:c,indices:a}=i.searchIn(s);r&&n.push({score:c,key:e,value:s,norm:o,indices:a})}return n}}Ue.version="7.0.0",Ue.createIndex=we,Ue.parseIndex=function(e,{getFn:t=Ee.getFn,fieldNormWeight:i=Ee.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new Se({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},Ue.config=Ee,Ue.parseQuery=$e,function(...e){je.push(...e)}(class{constructor(e,{isCaseSensitive:t=Ee.isCaseSensitive,includeMatches:i=Ee.includeMatches,minMatchCharLength:n=Ee.minMatchCharLength,ignoreLocation:s=Ee.ignoreLocation,findAllMatches:o=Ee.findAllMatches,location:r=Ee.location,threshold:c=Ee.threshold,distance:a=Ee.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:i,minMatchCharLength:n,findAllMatches:o,ignoreLocation:s,location:r,threshold:c,distance:a},this.pattern=t?e:e.toLowerCase(),this.query=function(e,t={}){return e.split("|").map((e=>{let i=e.trim().split(De).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._clearNotice(),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(e,t){var i=this;return void 0===e&&(e=!0),void 0===t&&(t=!1),e&&(t?this.passedElement.element.replaceChildren(""):this.passedElement.element.querySelectorAll(":not([selected])").forEach((function(e){e.remove()}))),this.itemList.element.replaceChildren(""),this.choiceList.element.replaceChildren(""),this._clearNotice(),this._store.withTxn((function(){var e=t?[]:i._store.items;i._store.reset(),e.forEach((function(e){i._store.dispatch(b(e)),i._store.dispatch(E(e))}))})),this._searcher.reset(),this},e.prototype.clearStore=function(e){return void 0===e&&(e=!0),this.clearChoices(e,!0),this._stopSearch(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=X,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=this._store,s=n.activeGroups,o=n.activeChoices,r=0;if(i&&t.searchResultLimit>0?r=t.searchResultLimit:t.renderChoiceLimit>0&&(r=t.renderChoiceLimit),this._isSelectElement){var c=o.filter((function(e){return!e.element}));c.length&&this.passedElement.addOptions(c)}var a=document.createDocumentFragment(),h=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},l=!1,u=function(n,s,o){i?n.sort(k):t.shouldSort&&n.sort(t.sorter);var c=n.length;c=!s&&r&&c>r?r:c,c--,n.every((function(n,s){var r=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o);return n.choiceEl=r,a.appendChild(r),!i&&n.selected||(l=!0),s1){var h=i.querySelector(D(n.classNames.placeholder));h&&h.remove()}else c||a||!this._placeholderValue||(c=!0,r(G({selected:!0,value:"",label:this._placeholderValue,placeholder:!0},!1)))}c&&(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===ie&&(t===te||t===ee))?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(D(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){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:e.group?e.group.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&&Ze(e.parentElement),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.config.shouldSort?t._store.choices.reverse():t._store.choices).find((function(e){return 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=Ze(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=Ze(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,i=this.config;if(this._isTextElement){if(this._presetChoices=i.items.map((function(e){return G(e,!1)})),this.passedElement.value){var n=this.passedElement.value.split(i.delimiter).map((function(e){return G(e,!1,t.config.allowHtmlUserInput)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=i.choices.map((function(e){return G(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.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._notice=void 0,this._displayNotice("function"==typeof i?i(t):i,ie),!1):(this._notice&&this._notice.type===ie&&this._clearNotice(),!0)},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=x(t.customAddItemText,e)),i&&this._store.choices.find((function(i){return t.valueComparer(i.value,e)}))){if(this._isSelectElement)return this._displayNotice("",ie),!1;t.duplicateItemsAllowed||(i=!1,n=x(t.uniqueItemText,e))}return i&&(n=x(t.addItemText,e)),n&&this._displayNotice(n,ie),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;return(s&&s.type)!==ie&&(n.length?this._clearNotice():this._displayNotice(O(this.config.noResultsText),te)),this._store.dispatch(function(e){return{type:c,results:e}}(n)),n.length},e.prototype._stopSearch=function(){this._isSearching&&(this._currentValue="",this._isSearching=!1,this._clearNotice(),this._store.dispatch({type:a,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||27===t||9===t||16===t||(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;e?this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice()))):this._isTextElement?this.hideDropdown(!0):this._stopSearch()},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(D(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;i._addChoice(G(n,!1,i.config.allowHtmlUserInput),!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._stopSearch(),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,c=void 0;if(e.metaKey||34===o||33===o)c=this.dropdown.element.querySelector(r>0?"".concat(et,":last-of-type"):et);else{var a=this.dropdown.element.querySelector(D(this.config.classNames.highlightedState));c=a?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}(a,et,r):this.dropdown.element.querySelector(et)}c&&(i=c,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(c,r),this._highlightChoice(c)),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(Qe&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?t[this._highlightPosition]:t[t.length-1])||(i=t[0]),P(i,n),i.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:i}),this.dropdown.isActive&&(this.input.setActiveDescendant(i.id),this.containerOuter.setActiveDescendant(i.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(E(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){if(e.id){this._store.dispatch(C(e));var t=this._notice;t&&t.type===ee&&this._clearNotice(),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");var n=this.config;if(n.duplicateItemsAllowed||!this._store.choices.find((function(t){return n.valueComparer(t.value,e.value)}))){this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var s=n.prependValue,o=n.appendValue;s&&(e.value=s+e.value),o&&(e.value+=o.toString()),(s||o)&&e.element&&(e.element.value=e.value),this._clearNotice(),this._store.dispatch(b(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:l,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.group=e,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,A,T,F));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 V({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new V({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new B({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new H({element:e.choiceList(t,i)}),this.itemList=new H({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).withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),(!this._store.choices.length||this._isSelectOneElement&&this._hasNonChoicePlaceholder)&&this._render()},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.1.0",e}()})); diff --git a/assets/scripts/choices.mjs b/assets/scripts/choices.mjs index 19a05a7f..9decc5a0 100644 --- a/assets/scripts/choices.mjs +++ b/assets/scripts/choices.mjs @@ -1,4 +1,4 @@ -/*! choices.js v11.0.6 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /****************************************************************************** Copyright (c) Microsoft Corporation. @@ -866,7 +866,9 @@ var WrappedSelect = /** @class */ (function (_super) { score: 0, rank: 0, value: option.value, - label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments... + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, element: option, active: true, // this returns true if nothing is selected on initial load, which will break placeholder support @@ -3241,7 +3243,6 @@ var templates = { inp.autocomplete = 'off'; inp.autocapitalize = 'off'; inp.spellcheck = false; - inp.setAttribute('role', 'textbox'); inp.setAttribute('aria-autocomplete', 'list'); if (placeholderValue) { inp.setAttribute('aria-label', placeholderValue); @@ -5214,7 +5215,7 @@ var Choices = /** @class */ (function () { throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); } }; - Choices.version = '11.0.6'; + Choices.version = '11.1.0'; return Choices; }()); diff --git a/assets/scripts/choices.search-basic.js b/assets/scripts/choices.search-basic.js index fb685926..bf077c7f 100644 --- a/assets/scripts/choices.search-basic.js +++ b/assets/scripts/choices.search-basic.js @@ -1,4 +1,4 @@ -/*! choices.js v11.0.6 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -872,7 +872,9 @@ score: 0, rank: 0, value: option.value, - label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments... + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, element: option, active: true, // this returns true if nothing is selected on initial load, which will break placeholder support @@ -2765,7 +2767,6 @@ inp.autocomplete = 'off'; inp.autocapitalize = 'off'; inp.spellcheck = false; - inp.setAttribute('role', 'textbox'); inp.setAttribute('aria-autocomplete', 'list'); if (placeholderValue) { inp.setAttribute('aria-label', placeholderValue); @@ -4738,7 +4739,7 @@ throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); } }; - Choices.version = '11.0.6'; + Choices.version = '11.1.0'; return Choices; }()); diff --git a/assets/scripts/choices.search-basic.min.js b/assets/scripts/choices.search-basic.min.js index bbcbb81e..b296e85e 100644 --- a/assets/scripts/choices.search-basic.min.js +++ b/assets/scripts/choices.search-basic.min.js @@ -1,2 +1,2 @@ -/*! choices.js v11.0.6 | © 2025 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){P(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&(P(this.element,this.classNames.flippedState),this.isFlipped=!0)},e.prototype.close=function(){j(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(j(this.element,this.classNames.flippedState),this.isFlipped=!1)},e.prototype.addFocusState=function(){P(this.element,this.classNames.focusState)},e.prototype.removeFocusState=function(){j(this.element,this.classNames.focusState)},e.prototype.enable=function(){j(this.element,this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),this.type===g&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){P(this.element,this.classNames.disabledState),this.element.setAttribute("aria-disabled","true"),this.type===g&&this.element.setAttribute("tabindex","-1"),this.isDisabled=!0},e.prototype.wrap=function(e){var t=this.element,i=e.parentNode;i&&(e.nextSibling?i.insertBefore(t,e.nextSibling):i.appendChild(t)),t.appendChild(e)},e.prototype.unwrap=function(e){var t=this.element,i=t.parentNode;i&&(i.insertBefore(e,t),i.removeChild(t))},e.prototype.addLoadingState=function(){P(this.element,this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){j(this.element,this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),H=function(){function e(e){var t=e.element,i=e.type,n=e.classNames,s=e.preventPaste;this.element=t,this.type=i,this.classNames=n,this.preventPaste=s,this.isFocussed=this.element.isEqualNode(document.activeElement),this.isDisabled=t.disabled,this._onPaste=this._onPaste.bind(this),this._onInput=this._onInput.bind(this),this._onFocus=this._onFocus.bind(this),this._onBlur=this._onBlur.bind(this)}return Object.defineProperty(e.prototype,"placeholder",{set:function(e){this.element.placeholder=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.element.value},set:function(e){this.element.value=e},enumerable:!1,configurable:!0}),e.prototype.addEventListeners=function(){var e=this.element;e.addEventListener("paste",this._onPaste),e.addEventListener("input",this._onInput,{passive:!0}),e.addEventListener("focus",this._onFocus,{passive:!0}),e.addEventListener("blur",this._onBlur,{passive:!0})},e.prototype.removeEventListeners=function(){var e=this.element;e.removeEventListener("input",this._onInput),e.removeEventListener("paste",this._onPaste),e.removeEventListener("focus",this._onFocus),e.removeEventListener("blur",this._onBlur)},e.prototype.enable=function(){this.element.removeAttribute("disabled"),this.isDisabled=!1},e.prototype.disable=function(){this.element.setAttribute("disabled",""),this.isDisabled=!0},e.prototype.focus=function(){this.isFocussed||this.element.focus()},e.prototype.blur=function(){this.isFocussed&&this.element.blur()},e.prototype.clear=function(e){return void 0===e&&(e=!0),this.element.value="",e&&this.setWidth(),this},e.prototype.setWidth=function(){var e=this.element;e.style.minWidth="".concat(e.placeholder.length+1,"ch"),e.style.width="".concat(e.value.length+1,"ch")},e.prototype.setActiveDescendant=function(e){this.element.setAttribute("aria-activedescendant",e)},e.prototype.removeActiveDescendant=function(){this.element.removeAttribute("aria-activedescendant")},e.prototype._onInput=function(){this.type!==g&&this.setWidth()},e.prototype._onPaste=function(e){this.preventPaste&&e.preventDefault()},e.prototype._onFocus=function(){this.isFocussed=!0},e.prototype._onBlur=function(){this.isFocussed=!1},e}(),R=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}(),q=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=this.element;P(e,this.classNames.input),e.hidden=!0,e.tabIndex=-1;var t=e.getAttribute("style");t&&e.setAttribute("data-choice-orig-style",t),e.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e=this.element;j(e,this.classNames.input),e.hidden=!1,e.removeAttribute("tabindex");var t=e.getAttribute("data-choice-orig-style");t?(e.removeAttribute("data-choice-orig-style"),e.setAttribute("style",t)):e.removeAttribute("style"),e.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}(),U=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(q),G=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},W=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},$=function(e,t,i){if(void 0===i&&(i=!0),"string"==typeof e){var n=I(e);return $({value:e,label:i||n===e?e:{escaped:n,raw:e},selected:!0},!1)}var s=e;if("choices"in s){if(!t)throw new TypeError("optGroup is not allowed");var o=s,r=o.choices.map((function(e){return $(e,!1)}));return{id:0,label:L(o.label)||o.value,active:!!r.length,disabled:!!o.disabled,choices:r}}var c=s;return{id:0,group:null,score:0,rank:0,value:c.value,label:c.label||c.value,active:G(c.active),selected:G(c.selected,!1),disabled:G(c.disabled,!1),placeholder:G(c.placeholder,!1),highlighted:!1,labelClass:W(c.labelClass),labelDescription:c.labelDescription,customProperties:c.customProperties}},J=function(e){return"SELECT"===e.tagName},z=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,group:null,score:0,rank:0,value:e.value,label:e.innerText,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?W(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:K(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}(q),X={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 L(void 0===i?e.value:i).localeCompare(L(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},Q=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},Y={groups:function(e,t){var i=e,n=!0;switch(t.type){case l:i.push(t.group);break;case h:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t,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 c=o.parentElement;c&&J(c)&&c.type===g&&(c.value="")}Q(t.item),n=n.filter((function(e){return e.id!==t.item.id}));break;case r:Q(t.choice),n=n.filter((function(e){return e.id!==t.choice.id}));break;case p:var a=t.highlighted,h=n.find((function(e){return e.id===t.item.id}));h&&h.highlighted!==a&&(h.highlighted=a,i&&function(e,t,i){var n=e.itemEl;n&&(j(n,i),P(n,t))}(h,a?i.classNames.highlightedState:i.classNames.selectedState,a?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,t.choice.group&&(t.choice.group.choices=t.choice.group.choices.filter((function(e){return e.id!==t.choice.id}))),n=n.filter((function(e){return e.id!==t.choice.id}));break;case u:case d:t.item.choiceEl=void 0;break;case c:var l=[];t.results.forEach((function(e){l[e.item.id]=e})),n.forEach((function(e){var t=l[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 a:n.forEach((function(e){e.active=t.active,i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case h:n=[];break;default:s=!1}return{state:n,update:s}}},Z=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){return this._listeners.push(e),this},e.prototype.dispatch=function(e){var t=this,i=this._state,n=!1,s=this._changeSet||this.changeSet(!1);Object.keys(Y).forEach((function(o){var r=Y[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.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}(),ee="no-choices",te="no-results",ie="add-choice";function ne(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 se(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 oe(e){for(var t=1;t`Missing ${e} property in key`,fe=e=>`Property 'weight' in key '${e}' must be a positive integer`,me=Object.prototype.hasOwnProperty;class ve{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach((e=>{let i=_e(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 _e(e){let t=null,i=null,n=null,s=1,o=null;if(ce(e)||re(e))n=e,t=ge(e),i=ye(e);else{if(!me.call(e,"name"))throw new Error(pe("name"));const r=e.name;if(n=r,me.call(e,"weight")&&(s=e.weight,s<=0))throw new Error(fe(r));t=ge(r),i=ye(r),o=e.getFn}return{path:t,id:i,weight:s,src:n,getFn:o}}function ge(e){return re(e)?e:e.split(".")}function ye(e){return re(e)?e.join("."):e}const be={useExtendedSearch:!1,getFn:function(e,t){let i=[],n=!1;const s=(e,t,o)=>{if(le(e))if(t[o]){const r=e[t[o]];if(!le(r))return;if(o===t.length-1&&(ce(r)||ae(r)||function(e){return!0===e||!1===e||function(e){return he(e)&&null!==e}(e)&&"[object Boolean]"==de(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(re(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,ce(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();ce(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(le(s))if(re(s)){let e=[];const t=[{nestedArrIndex:-1,value:s}];for(;t.length;){const{nestedArrIndex:i,value:n}=t.pop();if(le(n))if(ce(n)&&!ue(n)){let t={v:n,i:i,n:this.norm.get(n)};e.push(t)}else re(n)&&n.forEach(((e,i)=>{t.push({nestedArrIndex:i,value:e})}))}i.$[n]=e}else if(ce(s)&&!ue(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 Se(e,t,{getFn:i=Ee.getFn,fieldNormWeight:n=Ee.fieldNormWeight}={}){const s=new we({getFn:i,fieldNormWeight:n});return s.setKeys(e.map(_e)),s.setSources(t),s.create(),s}function Ie(e,{errors:t=0,currentLocation:i=0,expectedLocation:n=0,distance:s=Ee.distance,ignoreLocation:o=Ee.ignoreLocation}={}){const r=t/e.length;if(o)return r;const c=Math.abs(n-i);return s?r+c/s:c?1:r}const Ae=32;function Oe(e){let t={};for(let i=0,n=e.length;i{this.chunks.push({pattern:e,alphabet:Oe(e),startIndex:t})},l=this.pattern.length;if(l>Ae){let e=0;const t=l%Ae,i=l-t;for(;e{const{isMatch:f,score:m,indices:v}=function(e,t,i,{location:n=Ee.location,distance:s=Ee.distance,threshold:o=Ee.threshold,findAllMatches:r=Ee.findAllMatches,minMatchCharLength:c=Ee.minMatchCharLength,includeMatches:a=Ee.includeMatches,ignoreLocation:h=Ee.ignoreLocation}={}){if(t.length>Ae)throw new Error("Pattern length exceeds max of 32.");const l=t.length,u=e.length,d=Math.max(0,Math.min(n,u));let p=o,f=d;const m=c>1||a,v=m?Array(u):[];let _;for(;(_=e.indexOf(t,f))>-1;){let e=Ie(t,{currentLocation:_,expectedLocation:d,distance:s,ignoreLocation:h});if(p=Math.min(e,p),f=_+l,m){let e=0;for(;e=a;o-=1){let r=o-1,c=i[e.charAt(r)];if(m&&(v[r]=+!!c),C[o]=(C[o+1]<<1|1)&c,n&&(C[o]|=(g[o+1]|g[o])<<1|1|g[o+1]),C[o]&E&&(y=Ie(t,{errors:n,currentLocation:r,expectedLocation:d,distance:s,ignoreLocation:h}),y<=p)){if(p=y,f=r,f<=d)break;a=Math.max(1,2*d-f)}}if(Ie(t,{errors:n+1,currentLocation:d,expectedLocation:d,distance:s,ignoreLocation:h})>p)break;g=C}const C={isMatch:f>=0,score:Math.max(.001,y)};if(m){const e=function(e=[],t=Ee.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,c);e.length?a&&(C.indices=e):C.isMatch=!1}return C}(e,t,d,{location:n+p,distance:s,threshold:o,findAllMatches:r,minMatchCharLength:c,includeMatches:i,ignoreLocation:a});f&&(u=!0),l+=m,f&&v&&(h=[...h,...v])}));let d={isMatch:u,score:u?l/this.chunks.length:1};return u&&i&&(d.indices=h),d}}const Le=[];function Te(e,t){for(let i=0,n=Le.length;i!(!e[Ne]&&!e.$or),De=e=>({[Ne]:Object.keys(e).map((t=>({[t]:e[t]})))});function ke(e,t){const i=e.matches;t.matches=[],le(i)&&i.forEach((e=>{if(!le(e.indices)||!e.indices.length)return;const{indices:i,value:n}=e;let s={indices:i,value:n};e.key&&(s.key=e.key.src),e.idx>-1&&(s.refIndex=e.idx),t.matches.push(s)}))}function Pe(e,t){t.score=e.score}class je{constructor(e,t={},i){if(this.options=oe(oe({},Ee),t),this.options.useExtendedSearch)throw new Error("Extended search is not available");this._keyStore=new ve(this.options.keys),this.setCollection(e,i)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof we))throw new Error("Incorrect 'index' type");this._myIndex=t||Se(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){le(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}))}(c,{ignoreFieldNorm:r}),s&&c.sort(o),ae(t)&&t>-1&&(c=c.slice(0,t)),function(e,t,{includeMatches:i=Ee.includeMatches,includeScore:n=Ee.includeScore}={}){const s=[];return i&&s.push(ke),n&&s.push(Pe),e.map((e=>{const{idx:i}=e,n={item:t[i],refIndex:i};return s.length&&s.forEach((t=>{t(e,n)})),n}))}(c,this._docs,{includeMatches:i,includeScore:n})}_searchStringList(e){const t=Te(e,this.options),{records:i}=this._myIndex,n=[];return i.forEach((({v:e,i:i,n:s})=>{if(!le(e))return;const{isMatch:o,score:r,indices:c}=t.searchIn(e);o&&n.push({item:e,idx:i,matches:[{score:r,value:e,norm:s,indices:c}]})})),n}_searchLogical(e){throw new Error("Logical search is not available")}_searchObjectList(e){const t=Te(e,this.options),{keys:i,records:n}=this._myIndex,s=[];return n.forEach((({$:e,i:n})=>{if(!le(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(!le(t))return[];let n=[];if(re(t))t.forEach((({v:t,i:s,n:o})=>{if(!le(t))return;const{isMatch:r,score:c,indices:a}=i.searchIn(t);r&&n.push({score:c,key:e,value:t,idx:s,norm:o,indices:a})}));else{const{v:s,n:o}=t,{isMatch:r,score:c,indices:a}=i.searchIn(s);r&&n.push({score:c,key:e,value:s,norm:o,indices:a})}return n}}je.version="7.0.0",je.createIndex=Se,je.parseIndex=function(e,{getFn:t=Ee.getFn,fieldNormWeight:i=Ee.fieldNormWeight}={}){const{keys:n,records:s}=e,o=new we({getFn:t,fieldNormWeight:i});return o.setKeys(n),o.setIndexRecords(s),o},je.config=Ee,je.parseQuery=function(e,t,{auto:i=!0}={}){const n=e=>{let s=Object.keys(e);const o=(e=>!!e[Me])(e);if(!o&&s.length>1&&!Fe(e))return n(De(e));if((e=>!re(e)&&he(e)&&!Fe(e))(e)){const n=o?e[Me]:s[0],r=o?e.$val:e[n];if(!ce(r))throw new Error((e=>`Invalid value for key ${e}`)(n));const c={keyId:ye(n),pattern:r};return i&&(c.searcher=Te(r,t)),c}let r={children:[],operator:s[0]};return s.forEach((t=>{const i=e[t];re(i)&&i.forEach((e=>{r.children.push(n(e))}))})),r};return Fe(e)||(e=De(e)),n(e)};var Ke=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 je(this._haystack,this._fuseOptions)),this._fuse.search(e).map((function(e,t){return{item:e.item,score:e.score||0,rank:t+1}}))},e}(),Be=function(e,t,i){var n=e.dataset,s=t.customProperties,o=t.labelClass,r=t.labelDescription;o&&(n.labelClass=D(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)))},Ve=function(e,t,i){var n=t&&e.querySelector("label[for='".concat(t,"']")),s=n&&n.innerText;s&&i.setAttribute("aria-label",s)},He={containerOuter:function(e,t,i,n,s,o,r){var c=e.classNames.containerOuter,a=document.createElement("div");return P(a,c),a.dataset.type=o,t&&(a.dir=t),n&&(a.tabIndex=0),i&&(a.setAttribute("role",s?"combobox":"listbox"),s?a.setAttribute("aria-autocomplete","list"):r||Ve(this._docRoot,this.passedElement.element.id,a),a.setAttribute("aria-haspopup","true"),a.setAttribute("aria-expanded","false")),r&&a.setAttribute("aria-labelledby",r),a},containerInner:function(e){var t=e.classNames.containerInner,i=document.createElement("div");return P(i,t),i},itemList:function(e,t){var i=e.searchEnabled,n=e.classNames,s=n.list,o=n.listSingle,r=n.listItems,c=document.createElement("div");return P(c,s),P(c,t?o:r),this._isSelectElement&&i&&c.setAttribute("role","listbox"),c},placeholder:function(e,t){var i=e.allowHTML,n=e.classNames.placeholder,s=document.createElement("div");return P(s,n),M(s,i,t),s},item:function(e,t,i){var n=e.allowHTML,s=e.removeItemButtonAlignLeft,o=e.removeItemIconText,r=e.removeItemLabelText,c=e.classNames,a=c.item,h=c.button,l=c.highlightedState,u=c.itemSelectable,d=c.placeholder,p=L(t.value),f=document.createElement("div");if(P(f,a),t.labelClass){var m=document.createElement("span");M(m,n,t.label),P(m,t.labelClass),f.appendChild(m)}else M(f,n,t.label);if(f.dataset.item="",f.dataset.id=t.id,f.dataset.value=p,Be(f,t,!0),(t.disabled||this.containerOuter.isDisabled)&&f.setAttribute("aria-disabled","true"),this._isSelectElement&&(f.setAttribute("aria-selected","true"),f.setAttribute("role","option")),t.placeholder&&(P(f,d),f.dataset.placeholder=""),P(f,t.highlighted?l:u),i){t.disabled&&j(f,u),f.dataset.deletable="";var v=document.createElement("button");v.type="button",P(v,h),M(v,!0,O(o,t.value));var _=O(r,t.value);_&&v.setAttribute("aria-label",_),v.dataset.button="",s?f.insertAdjacentElement("afterbegin",v):f.appendChild(v)}return f},choiceList:function(e,t){var i=e.classNames.list,n=document.createElement("div");return P(n,i),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,c=t.id,a=t.label,h=t.disabled,l=L(a),u=document.createElement("div");P(u,s),h&&P(u,r),u.setAttribute("role","group"),u.dataset.group="",u.dataset.id=c,u.dataset.value=l,h&&u.setAttribute("aria-disabled","true");var d=document.createElement("div");return P(d,o),M(d,i,a||""),u.appendChild(d),u},choice:function(e,t,i,n){var s=e.allowHTML,o=e.classNames,r=o.item,c=o.itemChoice,a=o.itemSelectable,h=o.selectedState,l=o.itemDisabled,u=o.description,d=o.placeholder,p=t.label,f=L(t.value),m=document.createElement("div");m.id=t.elementId,P(m,r),P(m,c),n&&"string"==typeof p&&(p=N(s,p),p={trusted:p+=" (".concat(n,")")});var v=m;if(t.labelClass){var _=document.createElement("span");M(_,s,p),P(_,t.labelClass),v=_,m.appendChild(_)}else M(m,s,p);if(t.labelDescription){var g="".concat(t.elementId,"-description");v.setAttribute("aria-describedby",g);var y=document.createElement("span");M(y,s,t.labelDescription),y.id=g,P(y,u),m.appendChild(y)}return t.selected&&P(m,h),t.placeholder&&P(m,d),m.setAttribute("role",t.group?"treeitem":"option"),m.dataset.choice="",m.dataset.id=t.id,m.dataset.value=f,i&&(m.dataset.selectText=i),t.group&&(m.dataset.groupId="".concat(t.group.id)),Be(m,t,!1),t.disabled?(P(m,l),m.dataset.choiceDisabled="",m.setAttribute("aria-disabled","true")):(P(m,a),m.dataset.choiceSelectable=""),m},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",P(r,n),P(r,s),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||Ve(this._docRoot,this.passedElement.element.id,r),r},dropdown:function(e){var t=e.classNames,i=t.list,n=t.listDropdown,s=document.createElement("div");return P(s,i),P(s,n),s.setAttribute("aria-expanded","false"),s},notice:function(e,t,i){var n=e.classNames,s=n.item,o=n.itemChoice,r=n.addChoice,c=n.noResults,a=n.noChoices,h=n.notice;void 0===i&&(i="");var l=document.createElement("div");switch(M(l,!0,t),P(l,s),P(l,o),P(l,h),i){case ie:P(l,r);break;case te:P(l,c);break;case ee:P(l,a)}return i===ie&&(l.dataset.choiceSelectable="",l.dataset.choice=""),l},option:function(e){var t=L(e.label),i=new Option(t,e.value,!1,e.selected);return Be(i,e,!0),i.disabled=e.disabled,e.selected&&i.setAttribute("selected",""),i}},Re="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,qe={},Ue=function(e){if(e)return e.dataset.id?parseInt(e.dataset.id,10):void 0},Ge="[data-choice-selectable]";return function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this.initialisedOK=void 0,this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0;var o=e.defaults;this.config=i(i(i({},o.allOptions),o.options),n),_.forEach((function(e){s.config[e]=i(i(i({},o.allOptions[e]),o.options[e]),n[e])}));var r=this.config;r.silent||this._validateConfig();var c=r.shadowRoot||document.documentElement;this._docRoot=c;var a="string"==typeof t?c.querySelector(t):t;if(!a||"object"!=typeof a||"INPUT"!==a.tagName&&!J(a)){if(!a&&"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 h=a.type,l="text"===h;(l||1!==r.maxItemCount)&&(r.singleModeForMultiSelect=!1),r.singleModeForMultiSelect&&(h=y);var u=h===g,d=h===y,p=u||d;if(this._elementType=h,this._isTextElement=l,this._isSelectOneElement=u,this._isSelectMultipleElement=d,this._isSelectElement=u||d,this._canAddUserChoices=l&&r.addItems||p&&r.addChoices,"boolean"!=typeof r.renderSelectedChoices&&(r.renderSelectedChoices="always"===r.renderSelectedChoices||u),r.closeDropdownOnSelect="auto"===r.closeDropdownOnSelect?l||u||r.singleModeForMultiSelect:G(r.closeDropdownOnSelect),r.placeholder&&(r.placeholderValue?this._hasNonChoicePlaceholder=!0:a.dataset.placeholder&&(this._hasNonChoicePlaceholder=!0,r.placeholderValue=a.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 U({element:a,classNames:r.classNames}):new z({element:a,classNames:r.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:r.placeholder&&!this._hasNonChoicePlaceholder}),this.initialised=!1,this._store=new Z(r),this._currentValue="",r.searchEnabled=!l&&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(S(2))||S(4);return t=t.replace(/(:|\.|\[|\]|,)/g,""),"".concat("choices-","-").concat(t)}(a),this._direction=a.dir,!this._direction){var m=window.getComputedStyle(a).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 qe},get allOptions(){return X},get templates(){return He}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised&&void 0===this.initialisedOK){this._searcher=new Ke(this.config),this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._isTextElement&&!this.config.addItems||this.passedElement.element.hasAttribute("disabled")||this.passedElement.element.closest("fieldset:disabled")?this.disable():(this.enable(),this._addEventListeners()),this._initStore(),this.initialised=!0,this.initialisedOK=!0;var e=this.config.callbackOnInit;"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this._store._listeners=[],this.clearStore(!1),this._stopSearch(),this._templates=e.defaults.templates,this.initialised=!1,this.initialisedOK=void 0)},e.prototype.enable=function(){return this.passedElement.isDisabled&&this.passedElement.enable(),this.containerOuter.isDisabled&&(this._addEventListeners(),this.input.enable(),this.containerOuter.enable()),this},e.prototype.disable=function(){return this.passedElement.isDisabled||this.passedElement.disable(),this.containerOuter.isDisabled||(this._removeEventListeners(),this.input.disable(),this.containerOuter.disable()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.items.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(w(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(w(i,!1)),t&&this.passedElement.triggerEvent("unhighlightItem",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(w(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(w(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||(void 0===e&&(e=!this._canSearch),requestAnimationFrame((function(){t.dropdown.show();var i=t.dropdown.element.getBoundingClientRect();t.containerOuter.open(i.bottom,i.height),e||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,i=this._store.items.map((function(i){return e?i.value:t._getChoiceForOutput(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($(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,o,r){var c=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),void 0===o&&(o=!0),void 0===r&&(r=!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("function"==typeof e){var a=e(this);if("function"==typeof Promise&&a instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return c._handleLoadingState(!0)})).then((function(){return a})).then((function(e){return c.setChoices(e,t,n,s,o,r)})).catch((function(e){c.config.silent||console.error(e)})).then((function(){return c._handleLoadingState(!1)})).then((function(){return c}));if(!Array.isArray(a))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof a));return this.setChoices(a,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(){o&&(c._isSearching=!1),s&&c.clearChoices(!0,r);var a="value"===t,h="label"===n;e.forEach((function(e){if("choices"in e){var s=e;h||(s=i(i({},s),{label:s[n]})),c._addGroup($(s,!0))}else{var o=e;h&&a||(o=i(i({},o),{value:o[t],label:o[n]}));var r=$(o,!1);c._addChoice(r),r.placeholder&&!c._hasNonChoicePlaceholder&&(c._placeholderValue=T(r.label))}})),c.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&&(o[e.value]=!0)})),n.clearStore(!1);var r=function(e){i?n._store.dispatch(C(e)):o[e.value]&&(e.selected=!0)};s.forEach((function(e){"choices"in e?e.choices.forEach(r):r(e)})),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._clearNotice(),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(e,t){var i=this;return void 0===e&&(e=!0),void 0===t&&(t=!1),e&&(t?this.passedElement.element.replaceChildren(""):this.passedElement.element.querySelectorAll(":not([selected])").forEach((function(e){e.remove()}))),this.itemList.element.replaceChildren(""),this.choiceList.element.replaceChildren(""),this._clearNotice(),this._store.withTxn((function(){var e=t?[]:i._store.items;i._store.reset(),e.forEach((function(e){i._store.dispatch(b(e)),i._store.dispatch(E(e))}))})),this._searcher.reset(),this},e.prototype.clearStore=function(e){return void 0===e&&(e=!0),this.clearChoices(e,!0),this._stopSearch(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=X,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=this._store,s=n.activeGroups,o=n.activeChoices,r=0;if(i&&t.searchResultLimit>0?r=t.searchResultLimit:t.renderChoiceLimit>0&&(r=t.renderChoiceLimit),this._isSelectElement){var c=o.filter((function(e){return!e.element}));c.length&&this.passedElement.addOptions(c)}var a=document.createDocumentFragment(),h=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},l=!1,u=function(n,s,o){i?n.sort(F):t.shouldSort&&n.sort(t.sorter);var c=n.length;c=!s&&r&&c>r?r:c,c--,n.every((function(n,s){var r=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o);return n.choiceEl=r,a.appendChild(r),!i&&n.selected||(l=!0),s1){var h=i.querySelector(k(n.classNames.placeholder));h&&h.remove()}else c||a||!this._placeholderValue||(c=!0,r($({selected:!0,value:"",label:this._placeholderValue,placeholder:!0},!1)))}c&&(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===ie&&(t===te||t===ee))?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(k(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){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:e.group?e.group.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.parentElement),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.config.shouldSort?t._store.choices.reverse():t._store.choices).find((function(e){return 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,i=this.config;if(this._isTextElement){if(this._presetChoices=i.items.map((function(e){return $(e,!1)})),this.passedElement.value){var n=this.passedElement.value.split(i.delimiter).map((function(e){return $(e,!1,t.config.allowHtmlUserInput)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=i.choices.map((function(e){return $(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.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._notice=void 0,this._displayNotice("function"==typeof i?i(t):i,ie),!1):(this._notice&&this._notice.type===ie&&this._clearNotice(),!0)},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=O(t.customAddItemText,e)),i&&this._store.choices.find((function(i){return t.valueComparer(i.value,e)}))){if(this._isSelectElement)return this._displayNotice("",ie),!1;t.duplicateItemsAllowed||(i=!1,n=O(t.uniqueItemText,e))}return i&&(n=O(t.addItemText,e)),n&&this._displayNotice(n,ie),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;return(s&&s.type)!==ie&&(n.length?this._clearNotice():this._displayNotice(x(this.config.noResultsText),te)),this._store.dispatch(function(e){return{type:c,results:e}}(n)),n.length},e.prototype._stopSearch=function(){this._isSearching&&(this._currentValue="",this._isSearching=!1,this._clearNotice(),this._store.dispatch({type:a,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||27===t||9===t||16===t||(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;e?this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice()))):this._isTextElement?this.hideDropdown(!0):this._stopSearch()},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(k(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;i._addChoice($(n,!1,i.config.allowHtmlUserInput),!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._stopSearch(),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,c=void 0;if(e.metaKey||34===o||33===o)c=this.dropdown.element.querySelector(r>0?"".concat(Ge,":last-of-type"):Ge);else{var a=this.dropdown.element.querySelector(k(this.config.classNames.highlightedState));c=a?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}(a,Ge,r):this.dropdown.element.querySelector(Ge)}c&&(i=c,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(c,r),this._highlightChoice(c)),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(Re&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?t[this._highlightPosition]:t[t.length-1])||(i=t[0]),P(i,n),i.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:i}),this.dropdown.isActive&&(this.input.setActiveDescendant(i.id),this.containerOuter.setActiveDescendant(i.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(E(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){if(e.id){this._store.dispatch(C(e));var t=this._notice;t&&t.type===ee&&this._clearNotice(),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");var n=this.config;if(n.duplicateItemsAllowed||!this._store.choices.find((function(t){return n.valueComparer(t.value,e.value)}))){this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var s=n.prependValue,o=n.appendValue;s&&(e.value=s+e.value),o&&(e.value+=o.toString()),(s||o)&&e.element&&(e.element.value=e.value),this._clearNotice(),this._store.dispatch(b(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:l,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.group=e,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,A,N,D));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 V({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new V({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new H({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new R({element:e.choiceList(t,i)}),this.itemList=new R({element:e.itemList(t,i)}),this.dropdown=new B({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).withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),(!this._store.choices.length||this._isSelectOneElement&&this._hasNonChoicePlaceholder)&&this._render()},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.1.0",e}()})); diff --git a/assets/scripts/choices.search-basic.mjs b/assets/scripts/choices.search-basic.mjs index ddc98317..b32f469e 100644 --- a/assets/scripts/choices.search-basic.mjs +++ b/assets/scripts/choices.search-basic.mjs @@ -1,4 +1,4 @@ -/*! choices.js v11.0.6 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /****************************************************************************** Copyright (c) Microsoft Corporation. @@ -866,7 +866,9 @@ var WrappedSelect = /** @class */ (function (_super) { score: 0, rank: 0, value: option.value, - label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments... + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, element: option, active: true, // this returns true if nothing is selected on initial load, which will break placeholder support @@ -2759,7 +2761,6 @@ var templates = { inp.autocomplete = 'off'; inp.autocapitalize = 'off'; inp.spellcheck = false; - inp.setAttribute('role', 'textbox'); inp.setAttribute('aria-autocomplete', 'list'); if (placeholderValue) { inp.setAttribute('aria-label', placeholderValue); @@ -4732,7 +4733,7 @@ var Choices = /** @class */ (function () { throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); } }; - Choices.version = '11.0.6'; + Choices.version = '11.1.0'; return Choices; }()); diff --git a/assets/scripts/choices.search-kmp.js b/assets/scripts/choices.search-kmp.js new file mode 100644 index 00000000..235e175c --- /dev/null +++ b/assets/scripts/choices.search-kmp.js @@ -0,0 +1,3631 @@ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Choices = factory()); +})(this, (function () { 'use strict'; + + /****************************************************************************** + Copyright (c) Microsoft Corporation. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. + ***************************************************************************** */ + /* global Reflect, Promise, SuppressedError, Symbol */ + + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || { + __proto__: [] + } instanceof Array && function (d, b) { + d.__proto__ = b; + } || function (d, b) { + for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; + }; + return extendStatics(d, b); + }; + function __extends(d, b) { + if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { + this.constructor = d; + } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + } + var __assign = function () { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); + }; + typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { + var e = new Error(message); + return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; + }; + + var ActionType = { + ADD_CHOICE: 'ADD_CHOICE', + REMOVE_CHOICE: 'REMOVE_CHOICE', + FILTER_CHOICES: 'FILTER_CHOICES', + ACTIVATE_CHOICES: 'ACTIVATE_CHOICES', + CLEAR_CHOICES: 'CLEAR_CHOICES', + ADD_GROUP: 'ADD_GROUP', + ADD_ITEM: 'ADD_ITEM', + REMOVE_ITEM: 'REMOVE_ITEM', + HIGHLIGHT_ITEM: 'HIGHLIGHT_ITEM', + }; + + var EventType = { + showDropdown: 'showDropdown', + hideDropdown: 'hideDropdown', + change: 'change', + choice: 'choice', + search: 'search', + addItem: 'addItem', + removeItem: 'removeItem', + highlightItem: 'highlightItem', + highlightChoice: 'highlightChoice', + unhighlightItem: 'unhighlightItem', + }; + + var KeyCodeMap = { + TAB_KEY: 9, + SHIFT_KEY: 16, + BACK_KEY: 46, + DELETE_KEY: 8, + ENTER_KEY: 13, + A_KEY: 65, + ESC_KEY: 27, + UP_KEY: 38, + DOWN_KEY: 40, + PAGE_UP_KEY: 33, + PAGE_DOWN_KEY: 34, + }; + + 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, + }); }; + var removeChoice = function (choice) { return ({ + type: ActionType.REMOVE_CHOICE, + choice: choice, + }); }; + var filterChoices = function (results) { return ({ + type: ActionType.FILTER_CHOICES, + results: results, + }); }; + var activateChoices = function (active) { + return ({ + type: ActionType.ACTIVATE_CHOICES, + active: active, + }); + }; + + var addGroup = function (group) { return ({ + type: ActionType.ADD_GROUP, + group: group, + }); }; + + var addItem = function (item) { return ({ + type: ActionType.ADD_ITEM, + item: item, + }); }; + var removeItem$1 = function (item) { return ({ + type: ActionType.REMOVE_ITEM, + item: item, + }); }; + var highlightItem = function (item, highlighted) { return ({ + type: ActionType.HIGHLIGHT_ITEM, + item: item, + highlighted: highlighted, + }); }; + + var getRandomNumber = function (min, max) { return Math.floor(Math.random() * (max - min) + min); }; + var generateChars = function (length) { + return Array.from({ length: length }, function () { return getRandomNumber(0, 36).toString(36); }).join(''); + }; + var generateId = function (element, prefix) { + var id = element.id || (element.name && "".concat(element.name, "-").concat(generateChars(2))) || generateChars(4); + id = id.replace(/(:|\.|\[|\]|,)/g, ''); + id = "".concat(prefix, "-").concat(id); + return id; + }; + var getAdjacentEl = function (startEl, selector, direction) { + if (direction === void 0) { direction = 1; } + var prop = "".concat(direction > 0 ? 'next' : 'previous', "ElementSibling"); + var sibling = startEl[prop]; + while (sibling) { + if (sibling.matches(selector)) { + return sibling; + } + sibling = sibling[prop]; + } + return null; + }; + var isScrolledIntoView = function (element, parent, direction) { + if (direction === void 0) { direction = 1; } + var isVisible; + if (direction > 0) { + // In view from bottom + isVisible = parent.scrollTop + parent.offsetHeight >= element.offsetTop + element.offsetHeight; + } + else { + // In view from top + isVisible = element.offsetTop >= parent.scrollTop; + } + return isVisible; + }; + var sanitise = function (value) { + if (typeof value !== 'string') { + if (value === null || value === undefined) { + return ''; + } + if (typeof value === 'object') { + if ('raw' in value) { + return sanitise(value.raw); + } + if ('trusted' in value) { + return value.trusted; + } + } + return value; + } + return value + .replace(/&/g, '&') + .replace(/>/g, '>') + .replace(/= 0 && + !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)")).matches; + } + else if (this.position === 'top') { + shouldFlip = true; + } + return shouldFlip; + }; + Container.prototype.setActiveDescendant = function (activeDescendantID) { + this.element.setAttribute('aria-activedescendant', activeDescendantID); + }; + Container.prototype.removeActiveDescendant = function () { + this.element.removeAttribute('aria-activedescendant'); + }; + Container.prototype.open = function (dropdownPos, dropdownHeight) { + addClassesToElement(this.element, this.classNames.openState); + this.element.setAttribute('aria-expanded', 'true'); + this.isOpen = true; + if (this.shouldFlip(dropdownPos, dropdownHeight)) { + addClassesToElement(this.element, this.classNames.flippedState); + this.isFlipped = true; + } + }; + Container.prototype.close = function () { + removeClassesFromElement(this.element, this.classNames.openState); + this.element.setAttribute('aria-expanded', 'false'); + this.removeActiveDescendant(); + this.isOpen = false; + // A dropdown flips if it does not have space within the page + if (this.isFlipped) { + removeClassesFromElement(this.element, this.classNames.flippedState); + this.isFlipped = false; + } + }; + Container.prototype.addFocusState = function () { + addClassesToElement(this.element, this.classNames.focusState); + }; + Container.prototype.removeFocusState = function () { + removeClassesFromElement(this.element, this.classNames.focusState); + }; + Container.prototype.enable = function () { + removeClassesFromElement(this.element, this.classNames.disabledState); + this.element.removeAttribute('aria-disabled'); + if (this.type === PassedElementTypes.SelectOne) { + this.element.setAttribute('tabindex', '0'); + } + this.isDisabled = false; + }; + Container.prototype.disable = function () { + addClassesToElement(this.element, this.classNames.disabledState); + this.element.setAttribute('aria-disabled', 'true'); + 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(el, element.nextSibling); + } + else { + parentNode.appendChild(el); + } + } + el.appendChild(element); + }; + Container.prototype.unwrap = function (element) { + var el = this.element; + var parentNode = el.parentNode; + if (parentNode) { + // Move passed element outside this element + parentNode.insertBefore(element, el); + // Remove this element + parentNode.removeChild(el); + } + }; + Container.prototype.addLoadingState = function () { + addClassesToElement(this.element, this.classNames.loadingState); + this.element.setAttribute('aria-busy', 'true'); + this.isLoading = true; + }; + Container.prototype.removeLoadingState = function () { + removeClassesFromElement(this.element, this.classNames.loadingState); + this.element.removeAttribute('aria-busy'); + this.isLoading = false; + }; + return Container; + }()); + + var Input = /** @class */ (function () { + function Input(_a) { + var element = _a.element, type = _a.type, classNames = _a.classNames, preventPaste = _a.preventPaste; + this.element = element; + this.type = type; + this.classNames = classNames; + this.preventPaste = preventPaste; + this.isFocussed = this.element.isEqualNode(document.activeElement); + this.isDisabled = element.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); + } + Object.defineProperty(Input.prototype, "placeholder", { + set: function (placeholder) { + this.element.placeholder = placeholder; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Input.prototype, "value", { + get: function () { + return this.element.value; + }, + set: function (value) { + this.element.value = value; + }, + enumerable: false, + configurable: true + }); + Input.prototype.addEventListeners = function () { + var el = this.element; + el.addEventListener('paste', this._onPaste); + el.addEventListener('input', this._onInput, { + passive: true, + }); + el.addEventListener('focus', this._onFocus, { + passive: true, + }); + el.addEventListener('blur', this._onBlur, { + passive: true, + }); + }; + Input.prototype.removeEventListeners = function () { + var el = this.element; + el.removeEventListener('input', this._onInput); + el.removeEventListener('paste', this._onPaste); + el.removeEventListener('focus', this._onFocus); + el.removeEventListener('blur', this._onBlur); + }; + Input.prototype.enable = function () { + var el = this.element; + el.removeAttribute('disabled'); + this.isDisabled = false; + }; + Input.prototype.disable = function () { + var el = this.element; + el.setAttribute('disabled', ''); + this.isDisabled = true; + }; + Input.prototype.focus = function () { + if (!this.isFocussed) { + this.element.focus(); + } + }; + Input.prototype.blur = function () { + if (this.isFocussed) { + this.element.blur(); + } + }; + Input.prototype.clear = function (setWidth) { + if (setWidth === void 0) { setWidth = true; } + this.element.value = ''; + if (setWidth) { + this.setWidth(); + } + return this; + }; + /** + * Set the correct input width based on placeholder + * value or input value + */ + Input.prototype.setWidth = function () { + // Resize input to contents or placeholder + 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); + }; + Input.prototype.removeActiveDescendant = function () { + this.element.removeAttribute('aria-activedescendant'); + }; + Input.prototype._onInput = function () { + if (this.type !== PassedElementTypes.SelectOne) { + this.setWidth(); + } + }; + Input.prototype._onPaste = function (event) { + if (this.preventPaste) { + event.preventDefault(); + } + }; + Input.prototype._onFocus = function () { + this.isFocussed = true; + }; + Input.prototype._onBlur = function () { + this.isFocussed = false; + }; + return Input; + }()); + + var SCROLLING_SPEED = 4; + + var List = /** @class */ (function () { + function List(_a) { + var element = _a.element; + this.element = element; + this.scrollPos = this.element.scrollTop; + this.height = this.element.offsetHeight; + } + List.prototype.prepend = function (node) { + var child = this.element.firstElementChild; + if (child) { + this.element.insertBefore(node, child); + } + else { + this.element.append(node); + } + }; + List.prototype.scrollToTop = function () { + this.element.scrollTop = 0; + }; + List.prototype.scrollToChildElement = function (element, direction) { + var _this = this; + if (!element) { + return; + } + var listHeight = this.element.offsetHeight; + // Scroll position of dropdown + var listScrollPosition = this.element.scrollTop + listHeight; + var elementHeight = element.offsetHeight; + // Distance from bottom of element to top of parent + var elementPos = element.offsetTop + elementHeight; + // Difference between the element and scroll position + var destination = direction > 0 ? this.element.scrollTop + elementPos - listScrollPosition : element.offsetTop; + requestAnimationFrame(function () { + _this._animateScroll(destination, direction); + }); + }; + List.prototype._scrollDown = function (scrollPos, strength, destination) { + var easing = (destination - scrollPos) / strength; + var distance = easing > 1 ? easing : 1; + this.element.scrollTop = scrollPos + distance; + }; + List.prototype._scrollUp = function (scrollPos, strength, destination) { + var easing = (scrollPos - destination) / strength; + var distance = easing > 1 ? easing : 1; + this.element.scrollTop = scrollPos - distance; + }; + List.prototype._animateScroll = function (destination, direction) { + var _this = this; + var strength = SCROLLING_SPEED; + var choiceListScrollTop = this.element.scrollTop; + var continueAnimation = false; + if (direction > 0) { + this._scrollDown(choiceListScrollTop, strength, destination); + if (choiceListScrollTop < destination) { + continueAnimation = true; + } + } + else { + this._scrollUp(choiceListScrollTop, strength, destination); + if (choiceListScrollTop > destination) { + continueAnimation = true; + } + } + if (continueAnimation) { + requestAnimationFrame(function () { + _this._animateScroll(destination, direction); + }); + } + }; + return List; + }()); + + var WrappedElement = /** @class */ (function () { + function WrappedElement(_a) { + var element = _a.element, classNames = _a.classNames; + this.element = element; + this.classNames = classNames; + this.isDisabled = false; + } + Object.defineProperty(WrappedElement.prototype, "isActive", { + get: function () { + return this.element.dataset.choice === 'active'; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(WrappedElement.prototype, "dir", { + get: function () { + return this.element.dir; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(WrappedElement.prototype, "value", { + get: function () { + return this.element.value; + }, + set: function (value) { + this.element.setAttribute('value', value); + this.element.value = value; + }, + enumerable: false, + configurable: true + }); + WrappedElement.prototype.conceal = function () { + var el = this.element; + // Hide passed input + addClassesToElement(el, this.classNames.input); + el.hidden = true; + // Remove element from tab index + el.tabIndex = -1; + // Backup original styles if any + var origStyle = el.getAttribute('style'); + if (origStyle) { + el.setAttribute('data-choice-orig-style', origStyle); + } + el.setAttribute('data-choice', 'active'); + }; + WrappedElement.prototype.reveal = function () { + var el = this.element; + // Reinstate passed element + removeClassesFromElement(el, this.classNames.input); + el.hidden = false; + el.removeAttribute('tabindex'); + // Recover original styles if any + var origStyle = el.getAttribute('data-choice-orig-style'); + if (origStyle) { + el.removeAttribute('data-choice-orig-style'); + el.setAttribute('style', origStyle); + } + else { + el.removeAttribute('style'); + } + el.removeAttribute('data-choice'); + }; + WrappedElement.prototype.enable = function () { + this.element.removeAttribute('disabled'); + this.element.disabled = false; + this.isDisabled = false; + }; + WrappedElement.prototype.disable = function () { + this.element.setAttribute('disabled', ''); + this.element.disabled = true; + this.isDisabled = true; + }; + WrappedElement.prototype.triggerEvent = function (eventType, data) { + dispatchEvent(this.element, eventType, data || {}); + }; + return WrappedElement; + }()); + + var WrappedInput = /** @class */ (function (_super) { + __extends(WrappedInput, _super); + function WrappedInput() { + return _super !== null && _super.apply(this, arguments) || this; + } + return WrappedInput; + }(WrappedElement)); + + var coerceBool = function (arg, defaultValue) { + if (defaultValue === void 0) { defaultValue = true; } + return typeof arg === 'undefined' ? defaultValue : !!arg; + }; + var stringToHtmlClass = function (input) { + if (typeof input === 'string') { + // eslint-disable-next-line no-param-reassign + input = input.split(' ').filter(function (s) { return s.length; }); + } + if (Array.isArray(input) && input.length) { + return input; + } + return undefined; + }; + var mapInputToChoice = function (value, allowGroup, allowRawString) { + if (allowRawString === void 0) { allowRawString = true; } + if (typeof value === 'string') { + var sanitisedValue = sanitise(value); + var userValue = allowRawString || sanitisedValue === value ? value : { escaped: sanitisedValue, raw: value }; + var result_1 = mapInputToChoice({ + value: value, + label: userValue, + selected: true, + }, false); + return result_1; + } + var groupOrChoice = value; + if ('choices' in groupOrChoice) { + if (!allowGroup) { + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup + throw new TypeError("optGroup is not allowed"); + } + var group = groupOrChoice; + var choices = group.choices.map(function (e) { return mapInputToChoice(e, false); }); + var result_2 = { + id: 0, // actual ID will be assigned during _addGroup + label: unwrapStringForRaw(group.label) || group.value, + active: !!choices.length, + disabled: !!group.disabled, + choices: choices, + }; + return result_2; + } + var choice = groupOrChoice; + var result = { + id: 0, // actual ID will be assigned during _addChoice + group: null, // actual group will be assigned during _addGroup but before _addChoice + score: 0, // used in search + rank: 0, // used in search, stable sort order + value: choice.value, + label: choice.label || choice.value, + active: coerceBool(choice.active), + selected: coerceBool(choice.selected, false), + disabled: coerceBool(choice.disabled, false), + placeholder: coerceBool(choice.placeholder, false), + highlighted: false, + labelClass: stringToHtmlClass(choice.labelClass), + labelDescription: choice.labelDescription, + customProperties: choice.customProperties, + }; + return result; + }; + + var isHtmlInputElement = function (e) { return e.tagName === 'INPUT'; }; + var isHtmlSelectElement = function (e) { return e.tagName === 'SELECT'; }; + var isHtmlOption = function (e) { return e.tagName === 'OPTION'; }; + var isHtmlOptgroup = function (e) { return e.tagName === 'OPTGROUP'; }; + + var WrappedSelect = /** @class */ (function (_super) { + __extends(WrappedSelect, _super); + function WrappedSelect(_a) { + var element = _a.element, classNames = _a.classNames, template = _a.template, extractPlaceholder = _a.extractPlaceholder; + var _this = _super.call(this, { element: element, classNames: classNames }) || this; + _this.template = template; + _this.extractPlaceholder = extractPlaceholder; + return _this; + } + Object.defineProperty(WrappedSelect.prototype, "placeholderOption", { + get: function () { + return (this.element.querySelector('option[value=""]') || + // Backward compatibility layer for the non-standard placeholder attribute supported in older versions. + this.element.querySelector('option[placeholder]')); + }, + enumerable: false, + configurable: true + }); + WrappedSelect.prototype.addOptions = function (choices) { + var _this = this; + var fragment = document.createDocumentFragment(); + choices.forEach(function (obj) { + var choice = obj; + if (choice.element) { + return; + } + var option = _this.template(choice); + fragment.appendChild(option); + choice.element = option; + }); + this.element.appendChild(fragment); + }; + WrappedSelect.prototype.optionsAsChoices = function () { + var _this = this; + var choices = []; + this.element.querySelectorAll(':scope > option, :scope > optgroup').forEach(function (e) { + if (isHtmlOption(e)) { + choices.push(_this._optionToChoice(e)); + } + else if (isHtmlOptgroup(e)) { + choices.push(_this._optgroupToChoice(e)); + } + // todo: hr as empty optgroup, requires displaying empty opt-groups to be useful + }); + return choices; + }; + // eslint-disable-next-line class-methods-use-this + WrappedSelect.prototype._optionToChoice = function (option) { + // option.value returns the label if there is no value attribute, which can break legacy placeholder attribute support + if (!option.hasAttribute('value') && option.hasAttribute('placeholder')) { + option.setAttribute('value', ''); + option.value = ''; + } + return { + id: 0, + group: null, + score: 0, + rank: 0, + value: option.value, + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, + element: option, + active: true, + // this returns true if nothing is selected on initial load, which will break placeholder support + selected: this.extractPlaceholder ? option.selected : option.hasAttribute('selected'), + disabled: option.disabled, + highlighted: false, + placeholder: this.extractPlaceholder && (!option.value || option.hasAttribute('placeholder')), + 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) { + var _this = this; + var options = optgroup.querySelectorAll('option'); + var choices = Array.from(options).map(function (option) { return _this._optionToChoice(option); }); + return { + id: 0, + label: optgroup.label || '', + element: optgroup, + active: !!choices.length, + disabled: optgroup.disabled, + choices: choices, + }; + }; + return WrappedSelect; + }(WrappedElement)); + + var DEFAULT_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'], + }; + var DEFAULT_CONFIG = { + items: [], + choices: [], + silent: false, + renderChoiceLimit: -1, + maxItemCount: -1, + closeDropdownOnSelect: 'auto', + singleModeForMultiSelect: false, + addChoices: false, + addItems: true, + addItemFilter: function (value) { return !!value && value !== ''; }, + removeItems: true, + removeItemButton: false, + removeItemButtonAlignLeft: false, + editItems: false, + allowHTML: false, + allowHtmlUserInput: false, + duplicateItemsAllowed: true, + delimiter: ',', + paste: true, + searchEnabled: true, + searchChoices: true, + searchFloor: 1, + searchResultLimit: 4, + searchFields: ['label', 'value'], + position: 'auto', + resetScrollPosition: true, + shouldSort: true, + shouldSortItems: false, + sorter: sortByAlpha, + shadowRoot: null, + placeholder: true, + 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 (value) { return "Press Enter to add \"".concat(value, "\""); }, + removeItemIconText: function () { return "Remove item"; }, + removeItemLabelText: function (value) { return "Remove item: ".concat(value); }, + maxItemText: function (maxItemCount) { return "Only ".concat(maxItemCount, " values can be added"); }, + valueComparer: function (value1, value2) { return value1 === value2; }, + fuseOptions: { + includeScore: true, + }, + labelId: '', + callbackOnInit: null, + callbackOnCreateTemplates: null, + classNames: DEFAULT_CLASSNAMES, + appendGroupInSearch: false, + }; + + var removeItem = function (item) { + var itemEl = item.itemEl; + if (itemEl) { + itemEl.remove(); + item.itemEl = undefined; + } + }; + function items(s, action, context) { + var state = s; + var update = true; + switch (action.type) { + case ActionType.ADD_ITEM: { + action.item.selected = true; + var el = action.item.element; + if (el) { + el.selected = true; + el.setAttribute('selected', ''); + } + state.push(action.item); + break; + } + case ActionType.REMOVE_ITEM: { + 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 === PassedElementTypes.SelectOne) { + select.value = ''; + } + } + // this is mixing concerns, but this is *so much faster* + removeItem(action.item); + state = state.filter(function (choice) { return choice.id !== action.item.id; }); + break; + } + case ActionType.REMOVE_CHOICE: { + removeItem(action.choice); + state = state.filter(function (item) { return item.id !== action.choice.id; }); + break; + } + case ActionType.HIGHLIGHT_ITEM: { + var highlighted = action.highlighted; + var item = state.find(function (obj) { return obj.id === action.item.id; }); + if (item && item.highlighted !== highlighted) { + item.highlighted = highlighted; + if (context) { + updateClassList(item, highlighted ? context.classNames.highlightedState : context.classNames.selectedState, highlighted ? context.classNames.selectedState : context.classNames.highlightedState); + } + } + break; + } + default: { + update = false; + break; + } + } + return { state: state, update: update }; + } + + function groups(s, action) { + var state = s; + var update = true; + switch (action.type) { + case ActionType.ADD_GROUP: { + state.push(action.group); + break; + } + case ActionType.CLEAR_CHOICES: { + state = []; + break; + } + default: { + update = false; + break; + } + } + return { state: state, update: update }; + } + + /* eslint-disable */ + function choices(s, action, context) { + var state = s; + var update = true; + switch (action.type) { + case ActionType.ADD_CHOICE: { + state.push(action.choice); + break; + } + case ActionType.REMOVE_CHOICE: { + action.choice.choiceEl = undefined; + if (action.choice.group) { + action.choice.group.choices = action.choice.group.choices.filter(function (obj) { return obj.id !== action.choice.id; }); + } + 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: { + // avoid O(n^2) algorithm complexity when searching/filtering choices + var scoreLookup_1 = []; + action.results.forEach(function (result) { + scoreLookup_1[result.item.id] = result; + }); + state.forEach(function (choice) { + var result = scoreLookup_1[choice.id]; + if (result !== undefined) { + choice.score = result.score; + choice.rank = result.rank; + choice.active = true; + } + else { + choice.score = 0; + choice.rank = 0; + choice.active = false; + } + if (context && context.appendGroupInSearch) { + choice.choiceEl = undefined; + } + }); + break; + } + case ActionType.ACTIVATE_CHOICES: { + state.forEach(function (choice) { + choice.active = action.active; + if (context && context.appendGroupInSearch) { + choice.choiceEl = undefined; + } + }); + break; + } + case ActionType.CLEAR_CHOICES: { + state = []; + break; + } + default: { + update = false; + break; + } + } + return { state: state, update: update }; + } + + var reducers = { + groups: groups, + items: items, + choices: choices, + }; + var Store = /** @class */ (function () { + function Store(context) { + this._state = this.defaultState; + this._listeners = []; + this._txn = 0; + this._context = context; + } + Object.defineProperty(Store.prototype, "defaultState", { + // eslint-disable-next-line class-methods-use-this + get: function () { + return { + groups: [], + items: [], + choices: [], + }; + }, + enumerable: false, + configurable: true + }); + // eslint-disable-next-line class-methods-use-this + Store.prototype.changeSet = function (init) { + return { + groups: init, + items: init, + choices: init, + }; + }; + Store.prototype.reset = function () { + this._state = this.defaultState; + var changes = this.changeSet(true); + if (this._txn) { + this._changeSet = changes; + } + else { + this._listeners.forEach(function (l) { return l(changes); }); + } + }; + Store.prototype.subscribe = function (onChange) { + this._listeners.push(onChange); + return this; + }; + Store.prototype.dispatch = function (action) { + var _this = this; + var state = this._state; + var hasChanges = false; + var changes = this._changeSet || this.changeSet(false); + Object.keys(reducers).forEach(function (key) { + var stateUpdate = reducers[key](state[key], action, _this._context); + if (stateUpdate.update) { + hasChanges = true; + changes[key] = true; + state[key] = stateUpdate.state; + } + }); + if (hasChanges) { + if (this._txn) { + this._changeSet = changes; + } + else { + this._listeners.forEach(function (l) { return l(changes); }); + } + } + }; + Store.prototype.withTxn = function (func) { + this._txn++; + try { + func(); + } + finally { + this._txn = Math.max(0, this._txn - 1); + if (!this._txn) { + var changeSet_1 = this._changeSet; + if (changeSet_1) { + this._changeSet = undefined; + this._listeners.forEach(function (l) { return l(changeSet_1); }); + } + } + } + }; + Object.defineProperty(Store.prototype, "state", { + /** + * Get store object + */ + get: function () { + return this._state; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "items", { + /** + * Get items from store + */ + get: function () { + return this.state.items; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "highlightedActiveItems", { + /** + * Get highlighted items from store + */ + get: function () { + return this.items.filter(function (item) { return item.active && item.highlighted; }); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "choices", { + /** + * Get choices from store + */ + get: function () { + return this.state.choices; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "activeChoices", { + /** + * Get active choices from store + */ + get: function () { + return this.choices.filter(function (choice) { return choice.active; }); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "searchableChoices", { + /** + * Get choices that can be searched (excluding placeholders or disabled choices) + */ + get: function () { + return this.choices.filter(function (choice) { return !choice.disabled && !choice.placeholder; }); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "groups", { + /** + * Get groups from store + */ + get: function () { + return this.state.groups; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Store.prototype, "activeGroups", { + /** + * Get active groups from store + */ + get: function () { + var _this = this; + return this.state.groups.filter(function (group) { + var isActive = group.active && !group.disabled; + var hasActiveOptions = _this.state.choices.some(function (choice) { return choice.active && !choice.disabled; }); + return isActive && hasActiveOptions; + }, []); + }, + enumerable: false, + configurable: true + }); + Store.prototype.inTxn = function () { + return this._txn > 0; + }; + /** + * Get single choice by it's ID + */ + Store.prototype.getChoiceById = function (id) { + return this.activeChoices.find(function (choice) { return choice.id === id; }); + }; + /** + * Get group by group id + */ + Store.prototype.getGroupById = function (id) { + return this.groups.find(function (group) { return group.id === id; }); + }; + return Store; + }()); + + var NoticeTypes = { + noChoices: 'no-choices', + noResults: 'no-results', + addChoice: 'add-choice', + generic: '', + }; + + function kmpSearch(pattern, text) { + if (pattern.length === 0) { + return 0; // Immediate match + } + // Compute longest suffix-prefix table + var lsp = [0]; // Base case + for (var i = 1; i < pattern.length; i++) { + var j_1 = lsp[i - 1]; // Start by assuming we're extending the previous LSP + while (j_1 > 0 && pattern.charAt(i) !== pattern.charAt(j_1)) { + j_1 = lsp[j_1 - 1]; + } + if (pattern.charAt(i) === pattern.charAt(j_1)) { + j_1++; + } + lsp.push(j_1); + } + // Walk through text string + var j = 0; // Number of chars matched in pattern + for (var i = 0; i < text.length; i++) { + while (j > 0 && text.charAt(i) !== pattern.charAt(j)) { + j = lsp[j - 1]; // Fall back in the pattern + } + if (text.charAt(i) === pattern.charAt(j)) { + j++; // Next char matched, increment position + if (j === pattern.length) { + return i - (j - 1); + } + } + } + return -1; // Not found + } + var SearchByKMP = /** @class */ (function () { + function SearchByKMP(config) { + this._haystack = []; + this._fields = config.searchFields; + } + SearchByKMP.prototype.index = function (data) { + this._haystack = data; + }; + SearchByKMP.prototype.reset = function () { + this._haystack = []; + }; + SearchByKMP.prototype.isEmptyIndex = function () { + return !this._haystack.length; + }; + SearchByKMP.prototype.search = function (_needle) { + var fields = this._fields; + if (!fields || !fields.length || !_needle) { + return []; + } + var needle = _needle.toLowerCase(); + var results = []; + var count = 0; + for (var i = 0, j = this._haystack.length; i < j; i++) { + var obj = this._haystack[i]; + for (var k = 0, l = this._fields.length; k < l; k++) { + var field = this._fields[k]; + if (field in obj && kmpSearch(needle, obj[field].toLowerCase()) !== -1) { + results.push({ + item: obj[field], + score: count, + rank: count + 1, + }); + count++; + } + } + } + return results; + }; + return SearchByKMP; + }()); + + function getSearcher(config) { + { + return new SearchByKMP(config); + } + } + + /** + * Helpers to create HTML elements used by Choices + * Can be overridden by providing `callbackOnCreateTemplates` option. + * `Choices.defaults.templates` allows access to the default template methods from `callbackOnCreateTemplates` + */ + var isEmptyObject = function (obj) { + // eslint-disable-next-line no-restricted-syntax + for (var prop in obj) { + if (Object.prototype.hasOwnProperty.call(obj, prop)) { + return false; + } + } + return true; + }; + var assignCustomProperties = function (el, choice, withCustomProperties) { + var dataset = el.dataset; + var customProperties = choice.customProperties, labelClass = choice.labelClass, labelDescription = choice.labelDescription; + if (labelClass) { + dataset.labelClass = getClassNames(labelClass).join(' '); + } + if (labelDescription) { + dataset.labelDescription = labelDescription; + } + if (withCustomProperties && customProperties) { + if (typeof customProperties === 'string') { + dataset.customProperties = customProperties; + } + else if (typeof customProperties === 'object' && !isEmptyObject(customProperties)) { + dataset.customProperties = JSON.stringify(customProperties); + } + } + }; + var addAriaLabel = function (docRoot, id, element) { + var label = id && docRoot.querySelector("label[for='".concat(id, "']")); + var text = label && label.innerText; + if (text) { + element.setAttribute('aria-label', text); + } + }; + var templates = { + containerOuter: function (_a, dir, isSelectElement, isSelectOneElement, searchEnabled, passedElementType, labelId) { + var containerOuter = _a.classNames.containerOuter; + var div = document.createElement('div'); + addClassesToElement(div, containerOuter); + div.dataset.type = passedElementType; + if (dir) { + div.dir = dir; + } + if (isSelectOneElement) { + div.tabIndex = 0; + } + if (isSelectElement) { + div.setAttribute('role', searchEnabled ? 'combobox' : 'listbox'); + if (searchEnabled) { + div.setAttribute('aria-autocomplete', 'list'); + } + else if (!labelId) { + addAriaLabel(this._docRoot, this.passedElement.element.id, div); + } + div.setAttribute('aria-haspopup', 'true'); + div.setAttribute('aria-expanded', 'false'); + } + if (labelId) { + div.setAttribute('aria-labelledby', labelId); + } + return div; + }, + containerInner: function (_a) { + var containerInner = _a.classNames.containerInner; + var div = document.createElement('div'); + addClassesToElement(div, containerInner); + return div; + }, + itemList: function (_a, isSelectOneElement) { + var searchEnabled = _a.searchEnabled, _b = _a.classNames, list = _b.list, listSingle = _b.listSingle, listItems = _b.listItems; + var div = document.createElement('div'); + addClassesToElement(div, list); + addClassesToElement(div, isSelectOneElement ? listSingle : listItems); + if (this._isSelectElement && searchEnabled) { + div.setAttribute('role', 'listbox'); + } + return div; + }, + placeholder: function (_a, value) { + var allowHTML = _a.allowHTML, placeholder = _a.classNames.placeholder; + var div = document.createElement('div'); + addClassesToElement(div, placeholder); + setElementHtml(div, allowHTML, value); + return div; + }, + item: function (_a, choice, removeItemButton) { + var allowHTML = _a.allowHTML, removeItemButtonAlignLeft = _a.removeItemButtonAlignLeft, removeItemIconText = _a.removeItemIconText, removeItemLabelText = _a.removeItemLabelText, _b = _a.classNames, item = _b.item, button = _b.button, highlightedState = _b.highlightedState, itemSelectable = _b.itemSelectable, placeholder = _b.placeholder; + var rawValue = unwrapStringForRaw(choice.value); + var div = document.createElement('div'); + addClassesToElement(div, item); + if (choice.labelClass) { + var spanLabel = document.createElement('span'); + setElementHtml(spanLabel, allowHTML, choice.label); + addClassesToElement(spanLabel, choice.labelClass); + div.appendChild(spanLabel); + } + else { + setElementHtml(div, allowHTML, choice.label); + } + div.dataset.item = ''; + div.dataset.id = choice.id; + div.dataset.value = rawValue; + assignCustomProperties(div, choice, true); + if (choice.disabled || this.containerOuter.isDisabled) { + div.setAttribute('aria-disabled', 'true'); + } + if (this._isSelectElement) { + div.setAttribute('aria-selected', 'true'); + div.setAttribute('role', 'option'); + } + if (choice.placeholder) { + addClassesToElement(div, placeholder); + div.dataset.placeholder = ''; + } + addClassesToElement(div, choice.highlighted ? highlightedState : itemSelectable); + if (removeItemButton) { + if (choice.disabled) { + removeClassesFromElement(div, itemSelectable); + } + div.dataset.deletable = ''; + var removeButton = document.createElement('button'); + removeButton.type = 'button'; + addClassesToElement(removeButton, button); + 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); + } + removeButton.dataset.button = ''; + if (removeItemButtonAlignLeft) { + div.insertAdjacentElement('afterbegin', removeButton); + } + else { + div.appendChild(removeButton); + } + } + return div; + }, + choiceList: function (_a, isSelectOneElement) { + var list = _a.classNames.list; + var div = document.createElement('div'); + addClassesToElement(div, list); + if (!isSelectOneElement) { + div.setAttribute('aria-multiselectable', 'true'); + } + div.setAttribute('role', 'listbox'); + return div; + }, + choiceGroup: function (_a, _b) { + var allowHTML = _a.allowHTML, _c = _a.classNames, group = _c.group, groupHeading = _c.groupHeading, itemDisabled = _c.itemDisabled; + var id = _b.id, label = _b.label, disabled = _b.disabled; + var rawLabel = unwrapStringForRaw(label); + var div = document.createElement('div'); + addClassesToElement(div, group); + if (disabled) { + addClassesToElement(div, itemDisabled); + } + div.setAttribute('role', 'group'); + div.dataset.group = ''; + div.dataset.id = id; + div.dataset.value = rawLabel; + if (disabled) { + div.setAttribute('aria-disabled', 'true'); + } + var heading = document.createElement('div'); + addClassesToElement(heading, groupHeading); + setElementHtml(heading, allowHTML, label || ''); + div.appendChild(heading); + return div; + }, + choice: function (_a, choice, selectText, groupName) { + var allowHTML = _a.allowHTML, _b = _a.classNames, item = _b.item, itemChoice = _b.itemChoice, itemSelectable = _b.itemSelectable, selectedState = _b.selectedState, itemDisabled = _b.itemDisabled, description = _b.description, placeholder = _b.placeholder; + // eslint-disable-next-line prefer-destructuring + var label = choice.label; + var rawValue = unwrapStringForRaw(choice.value); + var div = document.createElement('div'); + div.id = choice.elementId; + addClassesToElement(div, item); + addClassesToElement(div, itemChoice); + if (groupName && typeof label === 'string') { + label = escapeForTemplate(allowHTML, label); + label += " (".concat(groupName, ")"); + label = { trusted: label }; + } + var describedBy = div; + if (choice.labelClass) { + var spanLabel = document.createElement('span'); + setElementHtml(spanLabel, allowHTML, label); + addClassesToElement(spanLabel, choice.labelClass); + describedBy = spanLabel; + div.appendChild(spanLabel); + } + else { + setElementHtml(div, allowHTML, label); + } + if (choice.labelDescription) { + var descId = "".concat(choice.elementId, "-description"); + describedBy.setAttribute('aria-describedby', descId); + var spanDesc = document.createElement('span'); + setElementHtml(spanDesc, allowHTML, choice.labelDescription); + spanDesc.id = descId; + addClassesToElement(spanDesc, description); + div.appendChild(spanDesc); + } + if (choice.selected) { + addClassesToElement(div, selectedState); + } + if (choice.placeholder) { + addClassesToElement(div, placeholder); + } + div.setAttribute('role', choice.group ? 'treeitem' : 'option'); + div.dataset.choice = ''; + div.dataset.id = choice.id; + div.dataset.value = rawValue; + if (selectText) { + div.dataset.selectText = selectText; + } + if (choice.group) { + div.dataset.groupId = "".concat(choice.group.id); + } + assignCustomProperties(div, choice, false); + if (choice.disabled) { + addClassesToElement(div, itemDisabled); + div.dataset.choiceDisabled = ''; + div.setAttribute('aria-disabled', 'true'); + } + else { + addClassesToElement(div, itemSelectable); + div.dataset.choiceSelectable = ''; + } + return div; + }, + input: function (_a, placeholderValue) { + var _b = _a.classNames, input = _b.input, inputCloned = _b.inputCloned, labelId = _a.labelId; + var inp = document.createElement('input'); + inp.type = 'search'; + addClassesToElement(inp, input); + addClassesToElement(inp, inputCloned); + inp.autocomplete = 'off'; + inp.autocapitalize = 'off'; + inp.spellcheck = false; + inp.setAttribute('aria-autocomplete', 'list'); + if (placeholderValue) { + inp.setAttribute('aria-label', placeholderValue); + } + else if (!labelId) { + addAriaLabel(this._docRoot, this.passedElement.element.id, inp); + } + return inp; + }, + dropdown: function (_a) { + var _b = _a.classNames, list = _b.list, listDropdown = _b.listDropdown; + var div = document.createElement('div'); + addClassesToElement(div, list); + addClassesToElement(div, listDropdown); + div.setAttribute('aria-expanded', 'false'); + return div; + }, + notice: function (_a, innerHTML, type) { + var _b = _a.classNames, item = _b.item, itemChoice = _b.itemChoice, addChoice = _b.addChoice, noResults = _b.noResults, noChoices = _b.noChoices, noticeItem = _b.notice; + if (type === void 0) { type = NoticeTypes.generic; } + var notice = document.createElement('div'); + setElementHtml(notice, true, innerHTML); + addClassesToElement(notice, item); + addClassesToElement(notice, itemChoice); + addClassesToElement(notice, noticeItem); + // eslint-disable-next-line default-case + switch (type) { + case NoticeTypes.addChoice: + addClassesToElement(notice, addChoice); + break; + case NoticeTypes.noResults: + addClassesToElement(notice, noResults); + break; + case NoticeTypes.noChoices: + addClassesToElement(notice, noChoices); + break; + } + if (type === NoticeTypes.addChoice) { + notice.dataset.choiceSelectable = ''; + notice.dataset.choice = ''; + } + return notice; + }, + option: function (choice) { + // HtmlOptionElement's label value does not support HTML, so the avoid double escaping unwrap the untrusted string. + var labelValue = unwrapStringForRaw(choice.label); + var opt = new Option(labelValue, choice.value, false, choice.selected); + assignCustomProperties(opt, choice, true); + opt.disabled = choice.disabled; + if (choice.selected) { + opt.setAttribute('selected', ''); + } + return opt; + }, + }; + + /** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */ + var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style && + '-ms-ime-align' in document.documentElement.style; + var USER_DEFAULTS = {}; + var parseDataSetId = function (element) { + if (!element) { + return undefined; + } + return element.dataset.id ? parseInt(element.dataset.id, 10) : undefined; + }; + var selectableChoiceIdentifier = '[data-choice-selectable]'; + /** + * Choices + * @author Josh Johnson + */ + var Choices = /** @class */ (function () { + function Choices(element, userConfig) { + if (element === void 0) { element = '[data-choice]'; } + if (userConfig === void 0) { userConfig = {}; } + var _this = this; + this.initialisedOK = undefined; + this._hasNonChoicePlaceholder = false; + this._lastAddedChoiceId = 0; + this._lastAddedGroupId = 0; + var defaults = Choices.defaults; + this.config = __assign(__assign(__assign({}, defaults.allOptions), defaults.options), userConfig); + ObjectsInConfig.forEach(function (key) { + _this.config[key] = __assign(__assign(__assign({}, defaults.allOptions[key]), defaults.options[key]), userConfig[key]); + }); + var config = this.config; + if (!config.silent) { + this._validateConfig(); + } + var docRoot = config.shadowRoot || document.documentElement; + this._docRoot = docRoot; + var passedElement = typeof element === 'string' ? docRoot.querySelector(element) : element; + if (!passedElement || + typeof passedElement !== 'object' || + !(isHtmlInputElement(passedElement) || isHtmlSelectElement(passedElement))) { + if (!passedElement && typeof element === 'string') { + throw TypeError("Selector ".concat(element, " failed to find an element")); + } + throw TypeError("Expected one of the following types text|select-one|select-multiple"); + } + var elementType = passedElement.type; + var isText = elementType === PassedElementTypes.Text; + if (isText || config.maxItemCount !== 1) { + config.singleModeForMultiSelect = false; + } + if (config.singleModeForMultiSelect) { + elementType = PassedElementTypes.SelectMultiple; + } + var isSelectOne = elementType === PassedElementTypes.SelectOne; + var isSelectMultiple = elementType === PassedElementTypes.SelectMultiple; + var isSelect = isSelectOne || isSelectMultiple; + this._elementType = elementType; + this._isTextElement = isText; + this._isSelectOneElement = isSelectOne; + this._isSelectMultipleElement = isSelectMultiple; + this._isSelectElement = isSelectOne || isSelectMultiple; + this._canAddUserChoices = (isText && config.addItems) || (isSelect && config.addChoices); + if (typeof config.renderSelectedChoices !== 'boolean') { + config.renderSelectedChoices = config.renderSelectedChoices === 'always' || isSelectOne; + } + if (config.closeDropdownOnSelect === 'auto') { + config.closeDropdownOnSelect = isText || isSelectOne || config.singleModeForMultiSelect; + } + else { + config.closeDropdownOnSelect = coerceBool(config.closeDropdownOnSelect); + } + if (config.placeholder) { + if (config.placeholderValue) { + this._hasNonChoicePlaceholder = true; + } + else if (passedElement.dataset.placeholder) { + this._hasNonChoicePlaceholder = true; + config.placeholderValue = passedElement.dataset.placeholder; + } + } + if (userConfig.addItemFilter && typeof userConfig.addItemFilter !== 'function') { + var re = userConfig.addItemFilter instanceof RegExp ? userConfig.addItemFilter : new RegExp(userConfig.addItemFilter); + config.addItemFilter = re.test.bind(re); + } + if (this._isTextElement) { + this.passedElement = new WrappedInput({ + element: passedElement, + classNames: config.classNames, + }); + } + else { + var selectEl = passedElement; + this.passedElement = new WrappedSelect({ + element: selectEl, + classNames: config.classNames, + template: function (data) { return _this._templates.option(data); }, + extractPlaceholder: config.placeholder && !this._hasNonChoicePlaceholder, + }); + } + this.initialised = false; + this._store = new Store(config); + this._currentValue = ''; + config.searchEnabled = (!isText && config.searchEnabled) || isSelectMultiple; + this._canSearch = config.searchEnabled; + this._isScrollingOnIe = false; + this._highlightPosition = 0; + this._wasTap = true; + this._placeholderValue = this._generatePlaceholderValue(); + this._baseId = generateId(passedElement, 'choices-'); + /** + * setting direction in cases where it's explicitly set on passedElement + * or when calculated direction is different from the document + */ + this._direction = passedElement.dir; + if (!this._direction) { + var elementDirection = window.getComputedStyle(passedElement).direction; + var documentDirection = window.getComputedStyle(document.documentElement).direction; + if (elementDirection !== documentDirection) { + this._direction = elementDirection; + } + } + this._idNames = { + itemChoice: 'item-choice', + }; + this._templates = defaults.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); + // If element has already been initialised with Choices, fail silently + if (this.passedElement.isActive) { + if (!config.silent) { + console.warn('Trying to initialise Choices on element already initialised', { element: element }); + } + this.initialised = true; + this.initialisedOK = false; + return; + } + // Let's go + this.init(); + // preserve the selected item list after setup for form reset + this._initialItems = this._store.items.map(function (choice) { return choice.value; }); + } + Object.defineProperty(Choices, "defaults", { + get: function () { + return Object.preventExtensions({ + get options() { + return USER_DEFAULTS; + }, + get allOptions() { + return DEFAULT_CONFIG; + }, + get templates() { + return templates; + }, + }); + }, + enumerable: false, + configurable: true + }); + Choices.prototype.init = function () { + if (this.initialised || this.initialisedOK !== undefined) { + return; + } + this._searcher = getSearcher(this.config); + this._loadChoices(); + this._createTemplates(); + this._createElements(); + this._createStructure(); + if ((this._isTextElement && !this.config.addItems) || + this.passedElement.element.hasAttribute('disabled') || + !!this.passedElement.element.closest('fieldset:disabled')) { + this.disable(); + } + else { + this.enable(); + this._addEventListeners(); + } + // should be triggered **after** disabled state to avoid additional re-draws + this._initStore(); + this.initialised = true; + this.initialisedOK = true; + var callbackOnInit = this.config.callbackOnInit; + // Run callback if it is a function + if (typeof callbackOnInit === 'function') { + callbackOnInit.call(this); + } + }; + Choices.prototype.destroy = function () { + if (!this.initialised) { + return; + } + this._removeEventListeners(); + this.passedElement.reveal(); + this.containerOuter.unwrap(this.passedElement.element); + this._store._listeners = []; // prevents select/input value being wiped + this.clearStore(false); + this._stopSearch(); + this._templates = Choices.defaults.templates; + this.initialised = false; + this.initialisedOK = undefined; + }; + Choices.prototype.enable = function () { + if (this.passedElement.isDisabled) { + this.passedElement.enable(); + } + if (this.containerOuter.isDisabled) { + this._addEventListeners(); + this.input.enable(); + this.containerOuter.enable(); + } + return this; + }; + Choices.prototype.disable = function () { + if (!this.passedElement.isDisabled) { + this.passedElement.disable(); + } + if (!this.containerOuter.isDisabled) { + this._removeEventListeners(); + this.input.disable(); + this.containerOuter.disable(); + } + return this; + }; + Choices.prototype.highlightItem = function (item, runEvent) { + if (runEvent === void 0) { runEvent = true; } + if (!item || !item.id) { + return this; + } + var choice = this._store.items.find(function (c) { return c.id === item.id; }); + if (!choice || choice.highlighted) { + return this; + } + this._store.dispatch(highlightItem(choice, true)); + if (runEvent) { + this.passedElement.triggerEvent(EventType.highlightItem, this._getChoiceForOutput(choice)); + } + return this; + }; + Choices.prototype.unhighlightItem = function (item, runEvent) { + if (runEvent === void 0) { runEvent = true; } + if (!item || !item.id) { + return this; + } + var choice = this._store.items.find(function (c) { return c.id === item.id; }); + if (!choice || !choice.highlighted) { + return this; + } + this._store.dispatch(highlightItem(choice, false)); + if (runEvent) { + this.passedElement.triggerEvent(EventType.unhighlightItem, this._getChoiceForOutput(choice)); + } + return this; + }; + Choices.prototype.highlightAll = function () { + var _this = this; + this._store.withTxn(function () { + _this._store.items.forEach(function (item) { + if (!item.highlighted) { + _this._store.dispatch(highlightItem(item, true)); + _this.passedElement.triggerEvent(EventType.highlightItem, _this._getChoiceForOutput(item)); + } + }); + }); + return this; + }; + Choices.prototype.unhighlightAll = function () { + var _this = this; + this._store.withTxn(function () { + _this._store.items.forEach(function (item) { + if (item.highlighted) { + _this._store.dispatch(highlightItem(item, false)); + _this.passedElement.triggerEvent(EventType.highlightItem, _this._getChoiceForOutput(item)); + } + }); + }); + return this; + }; + Choices.prototype.removeActiveItemsByValue = function (value) { + var _this = this; + this._store.withTxn(function () { + _this._store.items.filter(function (item) { return item.value === value; }).forEach(function (item) { return _this._removeItem(item); }); + }); + return this; + }; + Choices.prototype.removeActiveItems = function (excludedId) { + var _this = this; + this._store.withTxn(function () { + _this._store.items.filter(function (_a) { + var id = _a.id; + return id !== excludedId; + }).forEach(function (item) { return _this._removeItem(item); }); + }); + return this; + }; + Choices.prototype.removeHighlightedItems = function (runEvent) { + var _this = this; + if (runEvent === void 0) { runEvent = false; } + this._store.withTxn(function () { + _this._store.highlightedActiveItems.forEach(function (item) { + _this._removeItem(item); + // If this action was performed by the user + // trigger the event + if (runEvent) { + _this._triggerChange(item.value); + } + }); + }); + return this; + }; + Choices.prototype.showDropdown = function (preventInputFocus) { + var _this = this; + if (this.dropdown.isActive) { + return this; + } + if (preventInputFocus === undefined) { + // eslint-disable-next-line no-param-reassign + preventInputFocus = !this._canSearch; + } + requestAnimationFrame(function () { + _this.dropdown.show(); + var rect = _this.dropdown.element.getBoundingClientRect(); + _this.containerOuter.open(rect.bottom, rect.height); + if (!preventInputFocus) { + _this.input.focus(); + } + _this.passedElement.triggerEvent(EventType.showDropdown); + }); + return this; + }; + Choices.prototype.hideDropdown = function (preventInputBlur) { + var _this = this; + if (!this.dropdown.isActive) { + return this; + } + requestAnimationFrame(function () { + _this.dropdown.hide(); + _this.containerOuter.close(); + if (!preventInputBlur && _this._canSearch) { + _this.input.removeActiveDescendant(); + _this.input.blur(); + } + _this.passedElement.triggerEvent(EventType.hideDropdown); + }); + return this; + }; + Choices.prototype.getValue = function (valueOnly) { + var _this = this; + var values = this._store.items.map(function (item) { + return (valueOnly ? item.value : _this._getChoiceForOutput(item)); + }); + return this._isSelectOneElement || this.config.singleModeForMultiSelect ? values[0] : values; + }; + Choices.prototype.setValue = function (items) { + var _this = this; + if (!this.initialisedOK) { + this._warnChoicesInitFailed('setValue'); + return this; + } + this._store.withTxn(function () { + items.forEach(function (value) { + if (value) { + _this._addChoice(mapInputToChoice(value, false)); + } + }); + }); + // @todo integrate with Store + this._searcher.reset(); + return this; + }; + Choices.prototype.setChoiceByValue = function (value) { + var _this = this; + if (!this.initialisedOK) { + this._warnChoicesInitFailed('setChoiceByValue'); + return this; + } + if (this._isTextElement) { + return this; + } + this._store.withTxn(function () { + // If only one value has been passed, convert to array + var choiceValue = Array.isArray(value) ? value : [value]; + // Loop through each value and + choiceValue.forEach(function (val) { return _this._findAndSelectChoiceByValue(val); }); + _this.unhighlightAll(); + }); + // @todo integrate with Store + this._searcher.reset(); + return this; + }; + /** + * Set choices of select input via an array of objects (or function that returns array of object or promise of it), + * a value field name and a label field name. + * This behaves the same as passing items via the choices option but can be called after initialising Choices. + * This can also be used to add groups of choices (see example 2); Optionally pass a true `replaceChoices` value to remove any existing choices. + * Optionally pass a `customProperties` object to add additional data to your choices (useful when searching/filtering etc). + * + * **Input types affected:** select-one, select-multiple + * + * @example + * ```js + * const example = new Choices(element); + * + * example.setChoices([ + * {value: 'One', label: 'Label One', disabled: true}, + * {value: 'Two', label: 'Label Two', selected: true}, + * {value: 'Three', label: 'Label Three'}, + * ], 'value', 'label', false); + * ``` + * + * @example + * ```js + * const example = new Choices(element); + * + * example.setChoices(async () => { + * try { + * const items = await fetch('/items'); + * return items.json() + * } catch(err) { + * console.error(err) + * } + * }); + * ``` + * + * @example + * ```js + * const example = new Choices(element); + * + * example.setChoices([{ + * label: 'Group one', + * id: 1, + * disabled: false, + * choices: [ + * {value: 'Child One', label: 'Child One', selected: true}, + * {value: 'Child Two', label: 'Child Two', disabled: true}, + * {value: 'Child Three', label: 'Child Three'}, + * ] + * }, + * { + * label: 'Group two', + * id: 2, + * disabled: false, + * choices: [ + * {value: 'Child Four', label: 'Child Four', disabled: true}, + * {value: 'Child Five', label: 'Child Five'}, + * {value: 'Child Six', label: 'Child Six', customProperties: { + * description: 'Custom description about child six', + * random: 'Another random custom property' + * }}, + * ] + * }], 'value', 'label', false); + * ``` + */ + Choices.prototype.setChoices = function (choicesArrayOrFetcher, value, label, replaceChoices, clearSearchFlag, replaceItems) { + var _this = this; + if (choicesArrayOrFetcher === void 0) { choicesArrayOrFetcher = []; } + if (value === void 0) { value = 'value'; } + if (label === void 0) { label = 'label'; } + if (replaceChoices === void 0) { replaceChoices = false; } + if (clearSearchFlag === void 0) { clearSearchFlag = true; } + if (replaceItems === void 0) { replaceItems = false; } + if (!this.initialisedOK) { + this._warnChoicesInitFailed('setChoices'); + return this; + } + if (!this._isSelectElement) { + throw new TypeError("setChoices can't be used with INPUT based Choices"); + } + if (typeof value !== 'string' || !value) { + throw new TypeError("value parameter must be a name of 'value' field in passed objects"); + } + if (typeof choicesArrayOrFetcher === 'function') { + // it's a choices fetcher function + var fetcher_1 = choicesArrayOrFetcher(this); + if (typeof Promise === 'function' && fetcher_1 instanceof Promise) { + // that's a promise + // eslint-disable-next-line no-promise-executor-return + return new Promise(function (resolve) { return requestAnimationFrame(resolve); }) + .then(function () { return _this._handleLoadingState(true); }) + .then(function () { return fetcher_1; }) + .then(function (data) { + return _this.setChoices(data, value, label, replaceChoices, clearSearchFlag, replaceItems); + }) + .catch(function (err) { + if (!_this.config.silent) { + console.error(err); + } + }) + .then(function () { return _this._handleLoadingState(false); }) + .then(function () { return _this; }); + } + // function returned something else than promise, let's check if it's an array of choices + if (!Array.isArray(fetcher_1)) { + throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof fetcher_1)); + } + // recursion with results, it's sync and choices were cleared already + return this.setChoices(fetcher_1, value, label, false); + } + if (!Array.isArray(choicesArrayOrFetcher)) { + throw new TypeError(".setChoices must be called either with array of choices with a function resulting into Promise of array of choices"); + } + this.containerOuter.removeLoadingState(); + this._store.withTxn(function () { + if (clearSearchFlag) { + _this._isSearching = false; + } + // Clear choices if needed + if (replaceChoices) { + _this.clearChoices(true, replaceItems); + } + var isDefaultValue = value === 'value'; + var isDefaultLabel = label === 'label'; + choicesArrayOrFetcher.forEach(function (groupOrChoice) { + if ('choices' in groupOrChoice) { + var group = groupOrChoice; + if (!isDefaultLabel) { + group = __assign(__assign({}, group), { label: group[label] }); + } + _this._addGroup(mapInputToChoice(group, true)); + } + else { + var choice = groupOrChoice; + if (!isDefaultLabel || !isDefaultValue) { + choice = __assign(__assign({}, choice), { value: choice[value], label: choice[label] }); + } + var choiceFull = mapInputToChoice(choice, false); + _this._addChoice(choiceFull); + if (choiceFull.placeholder && !_this._hasNonChoicePlaceholder) { + _this._placeholderValue = unwrapStringForEscaped(choiceFull.label); + } + } + }); + _this.unhighlightAll(); + }); + // @todo integrate with Store + this._searcher.reset(); + return this; + }; + Choices.prototype.refresh = function (withEvents, selectFirstOption, deselectAll) { + var _this = this; + if (withEvents === void 0) { withEvents = false; } + if (selectFirstOption === void 0) { selectFirstOption = false; } + if (deselectAll === void 0) { deselectAll = false; } + if (!this._isSelectElement) { + if (!this.config.silent) { + console.warn('refresh method can only be used on choices backed by a element'); + } + return this; + } + this._store.withTxn(function () { + var choicesFromOptions = _this.passedElement.optionsAsChoices(); + // Build the list of items which require preserving + var existingItems = {}; + if (!deselectAll) { + _this._store.items.forEach(function (choice) { + if (choice.id && choice.active && choice.selected) { + existingItems[choice.value] = true; + } + }); + } + _this.clearStore(false); + var updateChoice = function (choice) { + if (deselectAll) { + _this._store.dispatch(removeItem$1(choice)); + } + else if (existingItems[choice.value]) { + choice.selected = true; + } + }; + choicesFromOptions.forEach(function (groupOrChoice) { + if ('choices' in groupOrChoice) { + groupOrChoice.choices.forEach(updateChoice); + return; + } + updateChoice(groupOrChoice); + }); + /* @todo only generate add events for the added options instead of all + if (withEvents) { + items.forEach((choice) => { + if (existingItems[choice.value]) { + this.passedElement.triggerEvent( + EventType.removeItem, + this._getChoiceForEvent(choice), + ); + } + }); + } + */ + // load new choices & items + _this._addPredefinedChoices(choicesFromOptions, selectFirstOption, withEvents); + // re-do search if required + if (_this._isSearching) { + _this._searchChoices(_this.input.value); + } + }); + return this; + }; + Choices.prototype.removeChoice = function (value) { + var choice = this._store.choices.find(function (c) { return c.value === value; }); + if (!choice) { + return this; + } + this._clearNotice(); + this._store.dispatch(removeChoice(choice)); + // @todo integrate with Store + this._searcher.reset(); + if (choice.selected) { + this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(choice)); + } + return this; + }; + Choices.prototype.clearChoices = function (clearOptions, clearItems) { + var _this = this; + if (clearOptions === void 0) { clearOptions = true; } + if (clearItems === void 0) { clearItems = false; } + if (clearOptions) { + if (clearItems) { + this.passedElement.element.replaceChildren(''); + } + else { + this.passedElement.element.querySelectorAll(':not([selected])').forEach(function (el) { + el.remove(); + }); + } + } + this.itemList.element.replaceChildren(''); + this.choiceList.element.replaceChildren(''); + this._clearNotice(); + this._store.withTxn(function () { + var items = clearItems ? [] : _this._store.items; + _this._store.reset(); + items.forEach(function (item) { + _this._store.dispatch(addChoice(item)); + _this._store.dispatch(addItem(item)); + }); + }); + // @todo integrate with Store + this._searcher.reset(); + return this; + }; + Choices.prototype.clearStore = function (clearOptions) { + if (clearOptions === void 0) { clearOptions = true; } + this.clearChoices(clearOptions, true); + this._stopSearch(); + this._lastAddedChoiceId = 0; + this._lastAddedGroupId = 0; + return this; + }; + Choices.prototype.clearInput = function () { + var shouldSetInputWidth = !this._isSelectOneElement; + this.input.clear(shouldSetInputWidth); + this._stopSearch(); + return this; + }; + Choices.prototype._validateConfig = function () { + var config = this.config; + var invalidConfigOptions = diff(config, DEFAULT_CONFIG); + if (invalidConfigOptions.length) { + console.warn('Unknown config option(s) passed', invalidConfigOptions.join(', ')); + } + if (config.allowHTML && config.allowHtmlUserInput) { + if (config.addItems) { + console.warn('Warning: allowHTML/allowHtmlUserInput/addItems all being true is strongly not recommended and may lead to XSS attacks'); + } + if (config.addChoices) { + console.warn('Warning: allowHTML/allowHtmlUserInput/addChoices all being true is strongly not recommended and may lead to XSS attacks'); + } + } + }; + Choices.prototype._render = function (changes) { + if (changes === void 0) { changes = { choices: true, groups: true, items: true }; } + if (this._store.inTxn()) { + return; + } + if (this._isSelectElement) { + if (changes.choices || changes.groups) { + this._renderChoices(); + } + } + if (changes.items) { + this._renderItems(); + } + }; + Choices.prototype._renderChoices = function () { + var _this = this; + if (!this._canAddItems()) { + return; // block rendering choices if the input limit is reached. + } + var _a = this, config = _a.config, isSearching = _a._isSearching; + var _b = this._store, activeGroups = _b.activeGroups, activeChoices = _b.activeChoices; + var renderLimit = 0; + if (isSearching && config.searchResultLimit > 0) { + renderLimit = config.searchResultLimit; + } + else if (config.renderChoiceLimit > 0) { + renderLimit = config.renderChoiceLimit; + } + if (this._isSelectElement) { + var backingOptions = activeChoices.filter(function (choice) { return !choice.element; }); + if (backingOptions.length) { + this.passedElement.addOptions(backingOptions); + } + } + var fragment = document.createDocumentFragment(); + var renderableChoices = function (choices) { + return choices.filter(function (choice) { + return !choice.placeholder && (isSearching ? !!choice.rank : config.renderSelectedChoices || !choice.selected); + }); + }; + var selectableChoices = false; + var renderChoices = function (choices, withinGroup, groupLabel) { + if (isSearching) { + // sortByRank is used to ensure stable sorting, as scores are non-unique + // this additionally ensures fuseOptions.sortFn is not ignored + choices.sort(sortByRank); + } + else if (config.shouldSort) { + choices.sort(config.sorter); + } + var choiceLimit = choices.length; + choiceLimit = !withinGroup && renderLimit && choiceLimit > renderLimit ? renderLimit : choiceLimit; + choiceLimit--; + choices.every(function (choice, index) { + // choiceEl being empty signals the contents has probably significantly changed + var dropdownItem = choice.choiceEl || _this._templates.choice(config, choice, config.itemSelectText, groupLabel); + choice.choiceEl = dropdownItem; + fragment.appendChild(dropdownItem); + if (isSearching || !choice.selected) { + selectableChoices = true; + } + return index < choiceLimit; + }); + }; + if (activeChoices.length) { + if (config.resetScrollPosition) { + requestAnimationFrame(function () { return _this.choiceList.scrollToTop(); }); + } + if (!this._hasNonChoicePlaceholder && !isSearching && this._isSelectOneElement) { + // If we have a placeholder choice along with groups + renderChoices(activeChoices.filter(function (choice) { return choice.placeholder && !choice.group; }), false, undefined); + } + // If we have grouped options + if (activeGroups.length && !isSearching) { + if (config.shouldSort) { + activeGroups.sort(config.sorter); + } + // render Choices without group first, regardless of sort, otherwise they won't be distinguishable + // from the last group + renderChoices(activeChoices.filter(function (choice) { return !choice.placeholder && !choice.group; }), false, undefined); + activeGroups.forEach(function (group) { + var groupChoices = renderableChoices(group.choices); + if (groupChoices.length) { + if (group.label) { + var dropdownGroup = group.groupEl || _this._templates.choiceGroup(_this.config, group); + group.groupEl = dropdownGroup; + dropdownGroup.remove(); + fragment.appendChild(dropdownGroup); + } + renderChoices(groupChoices, true, config.appendGroupInSearch && isSearching ? group.label : undefined); + } + }); + } + else { + renderChoices(renderableChoices(activeChoices), false, undefined); + } + } + if (!selectableChoices && (isSearching || !fragment.children.length || !config.renderSelectedChoices)) { + if (!this._notice) { + this._notice = { + text: resolveStringFunction(isSearching ? config.noResultsText : config.noChoicesText), + type: isSearching ? NoticeTypes.noResults : NoticeTypes.noChoices, + }; + } + fragment.replaceChildren(''); + } + this._renderNotice(fragment); + this.choiceList.element.replaceChildren(fragment); + if (selectableChoices) { + this._highlightChoice(); + } + }; + Choices.prototype._renderItems = function () { + var _this = this; + var items = this._store.items || []; + var itemList = this.itemList.element; + var config = this.config; + var fragment = document.createDocumentFragment(); + var itemFromList = function (item) { + return itemList.querySelector("[data-item][data-id=\"".concat(item.id, "\"]")); + }; + var addItemToFragment = function (item) { + var el = item.itemEl; + if (el && el.parentElement) { + return; + } + el = itemFromList(item) || _this._templates.item(config, item, config.removeItemButton); + item.itemEl = el; + fragment.appendChild(el); + }; + // new items + items.forEach(addItemToFragment); + var addedItems = !!fragment.childNodes.length; + if (this._isSelectOneElement) { + var existingItems = itemList.children.length; + if (addedItems || existingItems > 1) { + var placeholder = itemList.querySelector(getClassNamesSelector(config.classNames.placeholder)); + if (placeholder) { + placeholder.remove(); + } + } + else if (!addedItems && !existingItems && this._placeholderValue) { + addedItems = true; + addItemToFragment(mapInputToChoice({ + selected: true, + value: '', + label: this._placeholderValue, + placeholder: true, + }, false)); + } + } + if (addedItems) { + itemList.append(fragment); + if (config.shouldSortItems && !this._isSelectOneElement) { + items.sort(config.sorter); + // push sorting into the DOM + items.forEach(function (item) { + var el = itemFromList(item); + if (el) { + el.remove(); + fragment.append(el); + } + }); + itemList.append(fragment); + } + } + if (this._isTextElement) { + // Update the value of the hidden input + this.passedElement.value = items.map(function (_a) { + var value = _a.value; + return value; + }).join(config.delimiter); + } + }; + Choices.prototype._displayNotice = function (text, type, openDropdown) { + if (openDropdown === void 0) { openDropdown = true; } + var oldNotice = this._notice; + if (oldNotice && + ((oldNotice.type === type && oldNotice.text === text) || + (oldNotice.type === NoticeTypes.addChoice && + (type === NoticeTypes.noResults || type === NoticeTypes.noChoices)))) { + if (openDropdown) { + this.showDropdown(true); + } + return; + } + this._clearNotice(); + this._notice = text + ? { + text: text, + type: type, + } + : undefined; + this._renderNotice(); + if (openDropdown && text) { + this.showDropdown(true); + } + }; + Choices.prototype._clearNotice = function () { + if (!this._notice) { + return; + } + var noticeElement = this.choiceList.element.querySelector(getClassNamesSelector(this.config.classNames.notice)); + if (noticeElement) { + noticeElement.remove(); + } + this._notice = undefined; + }; + Choices.prototype._renderNotice = function (fragment) { + var noticeConf = this._notice; + if (noticeConf) { + var notice = this._templates.notice(this.config, noticeConf.text, noticeConf.type); + if (fragment) { + fragment.append(notice); + } + else { + this.choiceList.prepend(notice); + } + } + }; + // eslint-disable-next-line class-methods-use-this + Choices.prototype._getChoiceForOutput = function (choice, keyCode) { + return { + id: choice.id, + highlighted: choice.highlighted, + labelClass: choice.labelClass, + labelDescription: choice.labelDescription, + customProperties: choice.customProperties, + disabled: choice.disabled, + active: choice.active, + label: choice.label, + placeholder: choice.placeholder, + value: choice.value, + groupValue: choice.group ? choice.group.label : undefined, + element: choice.element, + keyCode: keyCode, + }; + }; + Choices.prototype._triggerChange = function (value) { + if (value === undefined || value === null) { + return; + } + this.passedElement.triggerEvent(EventType.change, { + value: value, + }); + }; + Choices.prototype._handleButtonAction = function (element) { + var _this = this; + var items = this._store.items; + if (!items.length || !this.config.removeItems || !this.config.removeItemButton) { + return; + } + var id = element && parseDataSetId(element.parentElement); + var itemToRemove = id && items.find(function (item) { return item.id === id; }); + if (!itemToRemove) { + return; + } + this._store.withTxn(function () { + // Remove item associated with button + _this._removeItem(itemToRemove); + _this._triggerChange(itemToRemove.value); + if (_this._isSelectOneElement && !_this._hasNonChoicePlaceholder) { + var placeholderChoice = (_this.config.shouldSort ? _this._store.choices.reverse() : _this._store.choices).find(function (choice) { return choice.placeholder; }); + if (placeholderChoice) { + _this._addItem(placeholderChoice); + _this.unhighlightAll(); + if (placeholderChoice.value) { + _this._triggerChange(placeholderChoice.value); + } + } + } + }); + }; + Choices.prototype._handleItemAction = function (element, hasShiftKey) { + var _this = this; + if (hasShiftKey === void 0) { hasShiftKey = false; } + var items = this._store.items; + if (!items.length || !this.config.removeItems || this._isSelectOneElement) { + return; + } + var id = parseDataSetId(element); + if (!id) { + return; + } + // We only want to select one item with a click + // so we deselect any items that aren't the target + // unless shift is being pressed + items.forEach(function (item) { + if (item.id === id && !item.highlighted) { + _this.highlightItem(item); + } + else if (!hasShiftKey && item.highlighted) { + _this.unhighlightItem(item); + } + }); + // Focus input as without focus, a user cannot do anything with a + // highlighted item + this.input.focus(); + }; + Choices.prototype._handleChoiceAction = function (element) { + var _this = this; + // If we are clicking on an option + var id = parseDataSetId(element); + var choice = id && this._store.getChoiceById(id); + if (!choice || choice.disabled) { + return false; + } + var hasActiveDropdown = this.dropdown.isActive; + if (!choice.selected) { + if (!this._canAddItems()) { + return true; // causes _onEnterKey to early out + } + this._store.withTxn(function () { + _this._addItem(choice, true, true); + _this.clearInput(); + _this.unhighlightAll(); + }); + this._triggerChange(choice.value); + } + // We want to close the dropdown if we are dealing with a single select box + if (hasActiveDropdown && this.config.closeDropdownOnSelect) { + this.hideDropdown(true); + this.containerOuter.element.focus(); + } + return true; + }; + Choices.prototype._handleBackspace = function (items) { + var config = this.config; + if (!config.removeItems || !items.length) { + return; + } + var lastItem = items[items.length - 1]; + var hasHighlightedItems = items.some(function (item) { return item.highlighted; }); + // If editing the last item is allowed and there are not other selected items, + // we can edit the item value. Otherwise if we can remove items, remove all selected items + if (config.editItems && !hasHighlightedItems && lastItem) { + this.input.value = lastItem.value; + this.input.setWidth(); + this._removeItem(lastItem); + this._triggerChange(lastItem.value); + } + else { + if (!hasHighlightedItems) { + // Highlight last item if none already highlighted + this.highlightItem(lastItem, false); + } + this.removeHighlightedItems(true); + } + }; + Choices.prototype._loadChoices = function () { + var _a; + var _this = this; + var config = this.config; + if (this._isTextElement) { + // Assign preset items from passed object first + this._presetChoices = config.items.map(function (e) { return mapInputToChoice(e, false); }); + // Add any values passed from attribute + if (this.passedElement.value) { + var elementItems = this.passedElement.value + .split(config.delimiter) + .map(function (e) { return mapInputToChoice(e, false, _this.config.allowHtmlUserInput); }); + this._presetChoices = this._presetChoices.concat(elementItems); + } + this._presetChoices.forEach(function (choice) { + choice.selected = true; + }); + } + else if (this._isSelectElement) { + // Assign preset choices from passed object + this._presetChoices = config.choices.map(function (e) { return mapInputToChoice(e, true); }); + // Create array of choices from option elements + var choicesFromOptions = this.passedElement.optionsAsChoices(); + if (choicesFromOptions) { + (_a = this._presetChoices).push.apply(_a, choicesFromOptions); + } + } + }; + Choices.prototype._handleLoadingState = function (setLoading) { + if (setLoading === void 0) { setLoading = true; } + var el = this.itemList.element; + if (setLoading) { + this.disable(); + this.containerOuter.addLoadingState(); + if (this._isSelectOneElement) { + el.replaceChildren(this._templates.placeholder(this.config, this.config.loadingText)); + } + else { + this.input.placeholder = this.config.loadingText; + } + } + else { + this.enable(); + this.containerOuter.removeLoadingState(); + if (this._isSelectOneElement) { + el.replaceChildren(''); + this._render(); + } + else { + this.input.placeholder = this._placeholderValue || ''; + } + } + }; + Choices.prototype._handleSearch = function (value) { + if (!this.input.isFocussed) { + return; + } + // Check that we have a value to search and the input was an alphanumeric character + 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, { + value: value, + resultCount: resultCount, + }); + } + } + else if (this._store.choices.some(function (option) { return !option.active; })) { + this._stopSearch(); + } + }; + Choices.prototype._canAddItems = function () { + var config = this.config; + var maxItemCount = config.maxItemCount, maxItemText = config.maxItemText; + if (!config.singleModeForMultiSelect && maxItemCount > 0 && maxItemCount <= this._store.items.length) { + this.choiceList.element.replaceChildren(''); + this._notice = undefined; + this._displayNotice(typeof maxItemText === 'function' ? maxItemText(maxItemCount) : maxItemText, NoticeTypes.addChoice); + return false; + } + if (this._notice && this._notice.type === NoticeTypes.addChoice) { + this._clearNotice(); + } + return true; + }; + Choices.prototype._canCreateItem = function (value) { + var config = this.config; + var canAddItem = true; + var notice = ''; + if (canAddItem && typeof config.addItemFilter === 'function' && !config.addItemFilter(value)) { + canAddItem = false; + notice = resolveNoticeFunction(config.customAddItemText, value); + } + if (canAddItem) { + var foundChoice = this._store.choices.find(function (choice) { return config.valueComparer(choice.value, value); }); + if (foundChoice) { + if (this._isSelectElement) { + // for exact matches, do not prompt to add it as a custom choice + this._displayNotice('', NoticeTypes.addChoice); + return false; + } + if (!config.duplicateItemsAllowed) { + canAddItem = false; + notice = resolveNoticeFunction(config.uniqueItemText, value); + } + } + } + if (canAddItem) { + notice = resolveNoticeFunction(config.addItemText, value); + } + if (notice) { + this._displayNotice(notice, NoticeTypes.addChoice); + } + return canAddItem; + }; + Choices.prototype._searchChoices = function (value) { + var newValue = value.trim().replace(/\s{2,}/, ' '); + // signal input didn't change search + if (!newValue.length || newValue === this._currentValue) { + return null; + } + var searcher = this._searcher; + if (searcher.isEmptyIndex()) { + searcher.index(this._store.searchableChoices); + } + // If new value matches the desired length and is not the same as the current value with a space + var results = searcher.search(newValue); + this._currentValue = newValue; + this._highlightPosition = 0; + this._isSearching = true; + var notice = this._notice; + var noticeType = notice && notice.type; + if (noticeType !== NoticeTypes.addChoice) { + if (!results.length) { + this._displayNotice(resolveStringFunction(this.config.noResultsText), NoticeTypes.noResults); + } + else { + this._clearNotice(); + } + } + this._store.dispatch(filterChoices(results)); + return results.length; + }; + Choices.prototype._stopSearch = function () { + if (this._isSearching) { + this._currentValue = ''; + this._isSearching = false; + this._clearNotice(); + this._store.dispatch(activateChoices(true)); + this.passedElement.triggerEvent(EventType.search, { + value: '', + resultCount: 0, + }); + } + }; + Choices.prototype._addEventListeners = function () { + var documentElement = this._docRoot; + var outerElement = this.containerOuter.element; + var inputElement = this.input.element; + // capture events - can cancel event processing or propagation + documentElement.addEventListener('touchend', this._onTouchEnd, true); + outerElement.addEventListener('keydown', this._onKeyDown, true); + outerElement.addEventListener('mousedown', this._onMouseDown, true); + // passive events - doesn't call `preventDefault` or `stopPropagation` + documentElement.addEventListener('click', this._onClick, { passive: true }); + documentElement.addEventListener('touchmove', this._onTouchMove, { + passive: true, + }); + this.dropdown.element.addEventListener('mouseover', this._onMouseOver, { + passive: true, + }); + if (this._isSelectOneElement) { + outerElement.addEventListener('focus', this._onFocus, { + passive: true, + }); + outerElement.addEventListener('blur', this._onBlur, { + passive: true, + }); + } + inputElement.addEventListener('keyup', this._onKeyUp, { + passive: true, + }); + inputElement.addEventListener('input', this._onInput, { + passive: true, + }); + inputElement.addEventListener('focus', this._onFocus, { + passive: true, + }); + inputElement.addEventListener('blur', this._onBlur, { + passive: true, + }); + if (inputElement.form) { + inputElement.form.addEventListener('reset', this._onFormReset, { + passive: true, + }); + } + this.input.addEventListeners(); + }; + Choices.prototype._removeEventListeners = function () { + var documentElement = this._docRoot; + var outerElement = this.containerOuter.element; + var inputElement = this.input.element; + documentElement.removeEventListener('touchend', this._onTouchEnd, true); + outerElement.removeEventListener('keydown', this._onKeyDown, true); + outerElement.removeEventListener('mousedown', this._onMouseDown, true); + documentElement.removeEventListener('click', this._onClick); + documentElement.removeEventListener('touchmove', this._onTouchMove); + this.dropdown.element.removeEventListener('mouseover', this._onMouseOver); + if (this._isSelectOneElement) { + outerElement.removeEventListener('focus', this._onFocus); + outerElement.removeEventListener('blur', this._onBlur); + } + inputElement.removeEventListener('keyup', this._onKeyUp); + inputElement.removeEventListener('input', this._onInput); + inputElement.removeEventListener('focus', this._onFocus); + inputElement.removeEventListener('blur', this._onBlur); + if (inputElement.form) { + inputElement.form.removeEventListener('reset', this._onFormReset); + } + this.input.removeEventListeners(); + }; + Choices.prototype._onKeyDown = function (event) { + var keyCode = event.keyCode; + var hasActiveDropdown = this.dropdown.isActive; + /* + See: + https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key + https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values + https://en.wikipedia.org/wiki/UTF-16#Code_points_from_U+010000_to_U+10FFFF - UTF-16 surrogate pairs + https://stackoverflow.com/a/70866532 - "Unidentified" for mobile + http://www.unicode.org/versions/Unicode5.2.0/ch16.pdf#G19635 - U+FFFF is reserved (Section 16.7) + + Logic: when a key event is sent, `event.key` represents its printable value _or_ one + of a large list of special values indicating meta keys/functionality. In addition, + key events for compose functionality contain a value of `Dead` when mid-composition. + + I can't quite verify it, but non-English IMEs may also be able to generate key codes + for code points in the surrogate-pair range, which could potentially be seen as having + key.length > 1. Since `Fn` is one of the special keys, we can't distinguish by that + alone. + + Here, key.length === 1 means we know for sure the input was printable and not a special + `key` value. When the length is greater than 1, it could be either a printable surrogate + pair or a special `key` value. We can tell the difference by checking if the _character + code_ value (not code point!) is in the "surrogate pair" range or not. + + We don't use .codePointAt because an invalid code point would return 65535, which wouldn't + pass the >= 0x10000 check we would otherwise use. + + > ...The Unicode Standard sets aside 66 noncharacter code points. The last two code points + > of each plane are noncharacters: U+FFFE and U+FFFF on the BMP... + */ + var wasPrintableChar = event.key.length === 1 || + (event.key.length === 2 && event.key.charCodeAt(0) >= 0xd800) || + event.key === 'Unidentified'; + /* + We do not show the dropdown if focusing out with esc or navigating through input fields. + An activated search can still be opened with any other key. + */ + if (!this._isTextElement && + !hasActiveDropdown && + keyCode !== KeyCodeMap.ESC_KEY && + keyCode !== KeyCodeMap.TAB_KEY && + keyCode !== KeyCodeMap.SHIFT_KEY) { + this.showDropdown(); + if (!this.input.isFocussed && wasPrintableChar) { + /* + We update the input value with the pressed key as + the input was not focussed at the time of key press + therefore does not have the value of the key. + */ + this.input.value += event.key; + // browsers interpret a space as pagedown + if (event.key === ' ') { + event.preventDefault(); + } + } + } + switch (keyCode) { + case KeyCodeMap.A_KEY: + return this._onSelectKey(event, this.itemList.element.hasChildNodes()); + case KeyCodeMap.ENTER_KEY: + return this._onEnterKey(event, hasActiveDropdown); + case KeyCodeMap.ESC_KEY: + return this._onEscapeKey(event, hasActiveDropdown); + case KeyCodeMap.UP_KEY: + case KeyCodeMap.PAGE_UP_KEY: + case KeyCodeMap.DOWN_KEY: + case KeyCodeMap.PAGE_DOWN_KEY: + return this._onDirectionKey(event, hasActiveDropdown); + case KeyCodeMap.DELETE_KEY: + case KeyCodeMap.BACK_KEY: + return this._onDeleteKey(event, this._store.items, this.input.isFocussed); + } + }; + Choices.prototype._onKeyUp = function ( /* event: KeyboardEvent */) { + this._canSearch = this.config.searchEnabled; + }; + Choices.prototype._onInput = function ( /* event: InputEvent */) { + var value = this.input.value; + if (!value) { + if (this._isTextElement) { + this.hideDropdown(true); + } + else { + this._stopSearch(); + } + return; + } + if (!this._canAddItems()) { + return; + } + if (this._canSearch) { + // do the search even if the entered text can not be added + this._handleSearch(value); + } + if (!this._canAddUserChoices) { + return; + } + // determine if a notice needs to be displayed for why a search result can't be added + this._canCreateItem(value); + if (this._isSelectElement) { + this._highlightPosition = 0; // reset to select the notice and/or exact match + this._highlightChoice(); + } + }; + Choices.prototype._onSelectKey = function (event, hasItems) { + // If CTRL + A or CMD + A have been pressed and there are items to select + if ((event.ctrlKey || event.metaKey) && hasItems) { + this._canSearch = false; + var shouldHightlightAll = this.config.removeItems && !this.input.value && this.input.element === document.activeElement; + if (shouldHightlightAll) { + this.highlightAll(); + } + } + }; + Choices.prototype._onEnterKey = function (event, hasActiveDropdown) { + var _this = this; + var value = this.input.value; + var target = event.target; + event.preventDefault(); + if (target && target.hasAttribute('data-button')) { + this._handleButtonAction(target); + return; + } + if (!hasActiveDropdown) { + if (this._isSelectElement || this._notice) { + this.showDropdown(); + } + return; + } + var highlightedChoice = this.dropdown.element.querySelector(getClassNamesSelector(this.config.classNames.highlightedState)); + if (highlightedChoice && this._handleChoiceAction(highlightedChoice)) { + return; + } + if (!target || !value) { + this.hideDropdown(true); + return; + } + if (!this._canAddItems()) { + return; + } + var addedItem = false; + this._store.withTxn(function () { + addedItem = _this._findAndSelectChoiceByValue(value, true); + if (!addedItem) { + if (!_this._canAddUserChoices) { + return; + } + if (!_this._canCreateItem(value)) { + return; + } + _this._addChoice(mapInputToChoice(value, false, _this.config.allowHtmlUserInput), true, true); + addedItem = true; + } + _this.clearInput(); + _this.unhighlightAll(); + }); + if (!addedItem) { + return; + } + this._triggerChange(value); + if (this.config.closeDropdownOnSelect) { + this.hideDropdown(true); + } + }; + Choices.prototype._onEscapeKey = function (event, hasActiveDropdown) { + if (hasActiveDropdown) { + event.stopPropagation(); + this.hideDropdown(true); + this._stopSearch(); + this.containerOuter.element.focus(); + } + }; + Choices.prototype._onDirectionKey = function (event, hasActiveDropdown) { + 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 === KeyCodeMap.DOWN_KEY || keyCode === KeyCodeMap.PAGE_DOWN_KEY ? 1 : -1; + var skipKey = event.metaKey || keyCode === KeyCodeMap.PAGE_DOWN_KEY || keyCode === KeyCodeMap.PAGE_UP_KEY; + var nextEl = void 0; + if (skipKey) { + if (directionInt > 0) { + nextEl = this.dropdown.element.querySelector("".concat(selectableChoiceIdentifier, ":last-of-type")); + } + else { + nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); + } + } + else { + var currentEl = this.dropdown.element.querySelector(getClassNamesSelector(this.config.classNames.highlightedState)); + if (currentEl) { + nextEl = getAdjacentEl(currentEl, selectableChoiceIdentifier, directionInt); + } + else { + nextEl = this.dropdown.element.querySelector(selectableChoiceIdentifier); + } + } + if (nextEl) { + // We prevent default to stop the cursor moving + // when pressing the arrow + if (!isScrolledIntoView(nextEl, this.choiceList.element, directionInt)) { + this.choiceList.scrollToChildElement(nextEl, directionInt); + } + this._highlightChoice(nextEl); + } + // Prevent default to maintain cursor position whilst + // traversing dropdown options + event.preventDefault(); + } + }; + Choices.prototype._onDeleteKey = function (event, items, hasFocusedInput) { + // If backspace or delete key is pressed and the input has no value + if (!this._isSelectOneElement && !event.target.value && hasFocusedInput) { + this._handleBackspace(items); + event.preventDefault(); + } + }; + Choices.prototype._onTouchMove = function () { + if (this._wasTap) { + this._wasTap = false; + } + }; + Choices.prototype._onTouchEnd = function (event) { + var target = (event || event.touches[0]).target; + var touchWasWithinContainer = this._wasTap && this.containerOuter.element.contains(target); + if (touchWasWithinContainer) { + var containerWasExactTarget = target === this.containerOuter.element || target === this.containerInner.element; + if (containerWasExactTarget) { + if (this._isTextElement) { + this.input.focus(); + } + else if (this._isSelectMultipleElement) { + this.showDropdown(); + } + } + // Prevents focus event firing + event.stopPropagation(); + } + this._wasTap = true; + }; + /** + * Handles mousedown event in capture mode for containetOuter.element + */ + Choices.prototype._onMouseDown = function (event) { + var target = event.target; + if (!(target instanceof HTMLElement)) { + return; + } + // If we have our mouse down on the scrollbar and are on IE11... + if (IS_IE11 && this.choiceList.element.contains(target)) { + // check if click was on a scrollbar area + var firstChoice = this.choiceList.element.firstElementChild; + this._isScrollingOnIe = + this._direction === 'ltr' ? event.offsetX >= firstChoice.offsetWidth : event.offsetX < firstChoice.offsetLeft; + } + if (target === this.input.element) { + return; + } + var item = target.closest('[data-button],[data-item],[data-choice]'); + if (item instanceof HTMLElement) { + if ('button' in item.dataset) { + this._handleButtonAction(item); + } + else if ('item' in item.dataset) { + this._handleItemAction(item, event.shiftKey); + } + else if ('choice' in item.dataset) { + this._handleChoiceAction(item); + } + } + event.preventDefault(); + }; + /** + * Handles mouseover event over this.dropdown + * @param {MouseEvent} event + */ + Choices.prototype._onMouseOver = function (_a) { + var target = _a.target; + if (target instanceof HTMLElement && 'choice' in target.dataset) { + this._highlightChoice(target); + } + }; + Choices.prototype._onClick = function (_a) { + var target = _a.target; + var containerOuter = this.containerOuter; + var clickWasWithinContainer = containerOuter.element.contains(target); + if (clickWasWithinContainer) { + if (!this.dropdown.isActive && !containerOuter.isDisabled) { + if (this._isTextElement) { + if (document.activeElement !== this.input.element) { + this.input.focus(); + } + } + else { + this.showDropdown(); + containerOuter.element.focus(); + } + } + else if (this._isSelectOneElement && + target !== this.input.element && + !this.dropdown.element.contains(target)) { + this.hideDropdown(); + } + } + else { + containerOuter.removeFocusState(); + this.hideDropdown(true); + this.unhighlightAll(); + } + }; + Choices.prototype._onFocus = function (_a) { + var target = _a.target; + var containerOuter = this.containerOuter; + var focusWasWithinContainer = target && containerOuter.element.contains(target); + if (!focusWasWithinContainer) { + return; + } + var targetIsInput = target === this.input.element; + if (this._isTextElement) { + if (targetIsInput) { + containerOuter.addFocusState(); + } + } + else if (this._isSelectMultipleElement) { + if (targetIsInput) { + this.showDropdown(true); + // If element is a select box, the focused element is the container and the dropdown + // isn't already open, focus and show dropdown + containerOuter.addFocusState(); + } + } + else { + containerOuter.addFocusState(); + if (targetIsInput) { + this.showDropdown(true); + } + } + }; + Choices.prototype._onBlur = function (_a) { + var target = _a.target; + var containerOuter = this.containerOuter; + var blurWasWithinContainer = target && containerOuter.element.contains(target); + if (blurWasWithinContainer && !this._isScrollingOnIe) { + if (target === this.input.element) { + containerOuter.removeFocusState(); + this.hideDropdown(true); + if (this._isTextElement || this._isSelectMultipleElement) { + this.unhighlightAll(); + } + } + else if (target === this.containerOuter.element) { + // Remove the focus state when the past outerContainer was the target + containerOuter.removeFocusState(); + // Also close the dropdown if search is disabled + if (!this._canSearch) { + this.hideDropdown(true); + } + } + } + else { + // On IE11, clicking the scollbar blurs our input and thus + // closes the dropdown. To stop this, we refocus our input + // if we know we are on IE *and* are scrolling. + this._isScrollingOnIe = false; + this.input.element.focus(); + } + }; + Choices.prototype._onFormReset = function () { + var _this = this; + this._store.withTxn(function () { + _this.clearInput(); + _this.hideDropdown(); + _this.refresh(false, false, true); + if (_this._initialItems.length) { + _this.setChoiceByValue(_this._initialItems); + } + }); + }; + Choices.prototype._highlightChoice = function (el) { + if (el === void 0) { el = null; } + var choices = Array.from(this.dropdown.element.querySelectorAll(selectableChoiceIdentifier)); + if (!choices.length) { + return; + } + var passedEl = el; + var highlightedState = this.config.classNames.highlightedState; + var highlightedChoices = Array.from(this.dropdown.element.querySelectorAll(getClassNamesSelector(highlightedState))); + // Remove any highlighted choices + highlightedChoices.forEach(function (choice) { + removeClassesFromElement(choice, highlightedState); + choice.setAttribute('aria-selected', 'false'); + }); + if (passedEl) { + this._highlightPosition = choices.indexOf(passedEl); + } + else { + // Highlight choice based on last known highlight location + if (choices.length > this._highlightPosition) { + // If we have an option to highlight + passedEl = choices[this._highlightPosition]; + } + else { + // Otherwise highlight the option before + passedEl = choices[choices.length - 1]; + } + if (!passedEl) { + passedEl = choices[0]; + } + } + addClassesToElement(passedEl, highlightedState); + passedEl.setAttribute('aria-selected', 'true'); + this.passedElement.triggerEvent(EventType.highlightChoice, { + el: passedEl, + }); + if (this.dropdown.isActive) { + // IE11 ignores aria-label and blocks virtual keyboard + // if aria-activedescendant is set without a dropdown + this.input.setActiveDescendant(passedEl.id); + this.containerOuter.setActiveDescendant(passedEl.id); + } + }; + Choices.prototype._addItem = function (item, withEvents, userTriggered) { + if (withEvents === void 0) { withEvents = true; } + if (userTriggered === void 0) { userTriggered = false; } + 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(item.id); + } + this._store.dispatch(addItem(item)); + if (withEvents) { + this.passedElement.triggerEvent(EventType.addItem, this._getChoiceForOutput(item)); + if (userTriggered) { + this.passedElement.triggerEvent(EventType.choice, this._getChoiceForOutput(item)); + } + } + }; + Choices.prototype._removeItem = function (item) { + if (!item.id) { + return; + } + this._store.dispatch(removeItem$1(item)); + var notice = this._notice; + if (notice && notice.type === NoticeTypes.noChoices) { + this._clearNotice(); + } + this.passedElement.triggerEvent(EventType.removeItem, this._getChoiceForOutput(item)); + }; + Choices.prototype._addChoice = function (choice, withEvents, userTriggered) { + if (withEvents === void 0) { withEvents = true; } + if (userTriggered === void 0) { userTriggered = false; } + if (choice.id) { + throw new TypeError('Can not re-add a choice which has already been added'); + } + var config = this.config; + if (!config.duplicateItemsAllowed && this._store.choices.find(function (c) { return config.valueComparer(c.value, choice.value); })) { + return; + } + // Generate unique id, in-place update is required so chaining _addItem works as expected + this._lastAddedChoiceId++; + choice.id = this._lastAddedChoiceId; + choice.elementId = "".concat(this._baseId, "-").concat(this._idNames.itemChoice, "-").concat(choice.id); + var prependValue = config.prependValue, appendValue = config.appendValue; + if (prependValue) { + choice.value = prependValue + choice.value; + } + if (appendValue) { + choice.value += appendValue.toString(); + } + if ((prependValue || appendValue) && choice.element) { + choice.element.value = choice.value; + } + this._clearNotice(); + this._store.dispatch(addChoice(choice)); + if (choice.selected) { + this._addItem(choice, withEvents, userTriggered); + } + }; + Choices.prototype._addGroup = function (group, withEvents) { + var _this = this; + if (withEvents === void 0) { withEvents = true; } + if (group.id) { + throw new TypeError('Can not re-add a group which has already been added'); + } + this._store.dispatch(addGroup(group)); + if (!group.choices) { + return; + } + // add unique id for the group(s), and do not store the full list of choices in this group + this._lastAddedGroupId++; + group.id = this._lastAddedGroupId; + group.choices.forEach(function (item) { + item.group = group; + if (group.disabled) { + item.disabled = true; + } + _this._addChoice(item, withEvents); + }); + }; + Choices.prototype._createTemplates = function () { + var _this = this; + var callbackOnCreateTemplates = this.config.callbackOnCreateTemplates; + var userTemplates = {}; + if (typeof callbackOnCreateTemplates === 'function') { + userTemplates = callbackOnCreateTemplates.call(this, strToEl, escapeForTemplate, getClassNames); + } + var templating = {}; + Object.keys(this._templates).forEach(function (name) { + if (name in userTemplates) { + templating[name] = userTemplates[name].bind(_this); + } + else { + templating[name] = _this._templates[name].bind(_this); + } + }); + this._templates = templating; + }; + Choices.prototype._createElements = function () { + var templating = this._templates; + 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, isSelectOneElement, config.searchEnabled, elementType, config.labelId), + classNames: classNames, + type: elementType, + position: position, + }); + this.containerInner = new Container({ + element: templating.containerInner(config), + classNames: classNames, + type: elementType, + position: position, + }); + this.input = new Input({ + element: templating.input(config, this._placeholderValue), + classNames: classNames, + type: elementType, + preventPaste: !config.paste, + }); + this.choiceList = new List({ + element: templating.choiceList(config, isSelectOneElement), + }); + this.itemList = new List({ + element: templating.itemList(config, isSelectOneElement), + }); + this.dropdown = new Dropdown({ + element: templating.dropdown(config), + classNames: classNames, + type: elementType, + }); + }; + Choices.prototype._createStructure = function () { + 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 + containerInner.wrap(passedElement.element); + // Wrapper inner container with outer container + containerOuter.wrap(containerInner.element); + if (this._isSelectOneElement) { + this.input.placeholder = this.config.searchPlaceholderValue || ''; + } + else { + if (this._placeholderValue) { + this.input.placeholder = this._placeholderValue; + } + this.input.setWidth(); + } + containerOuter.element.appendChild(containerInner.element); + containerOuter.element.appendChild(dropdownElement); + containerInner.element.appendChild(this.itemList.element); + dropdownElement.appendChild(this.choiceList.element); + if (!this._isSelectOneElement) { + containerInner.element.appendChild(this.input.element); + } + else if (this.config.searchEnabled) { + dropdownElement.insertBefore(this.input.element, dropdownElement.firstChild); + } + this._highlightPosition = 0; + this._isSearching = false; + }; + Choices.prototype._initStore = function () { + var _this = this; + this._store.subscribe(this._render).withTxn(function () { + _this._addPredefinedChoices(_this._presetChoices, _this._isSelectOneElement && !_this._hasNonChoicePlaceholder, false); + }); + if (!this._store.choices.length || (this._isSelectOneElement && this._hasNonChoicePlaceholder)) { + this._render(); + } + }; + Choices.prototype._addPredefinedChoices = function (choices, selectFirstOption, withEvents) { + var _this = this; + if (selectFirstOption === void 0) { selectFirstOption = false; } + if (withEvents === void 0) { withEvents = true; } + if (selectFirstOption) { + /** + * If there is a selected choice already or the choice is not the first in + * the array, add each choice normally. + * + * Otherwise we pre-select the first enabled choice in the array ("select-one" only) + */ + var noSelectedChoices = choices.findIndex(function (choice) { return choice.selected; }) === -1; + if (noSelectedChoices) { + choices.some(function (choice) { + if (choice.disabled || 'choices' in choice) { + return false; + } + choice.selected = true; + return true; + }); + } + } + choices.forEach(function (item) { + if ('choices' in item) { + if (_this._isSelectElement) { + _this._addGroup(item, withEvents); + } + } + else { + _this._addChoice(item, withEvents); + } + }); + }; + Choices.prototype._findAndSelectChoiceByValue = function (value, userTriggered) { + var _this = this; + if (userTriggered === void 0) { userTriggered = false; } + // Check 'value' property exists and the choice isn't already selected + 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; + } + return false; + }; + Choices.prototype._generatePlaceholderValue = function () { + var config = this.config; + if (!config.placeholder) { + return null; + } + if (this._hasNonChoicePlaceholder) { + return config.placeholderValue; + } + if (this._isSelectElement) { + var placeholderOption = this.passedElement.placeholderOption; + return placeholderOption ? placeholderOption.text : null; + } + return null; + }; + Choices.prototype._warnChoicesInitFailed = function (caller) { + if (this.config.silent) { + return; + } + if (!this.initialised) { + throw new TypeError("".concat(caller, " called on a non-initialised instance of Choices")); + } + else if (!this.initialisedOK) { + throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); + } + }; + Choices.version = '11.1.0'; + return Choices; +}()); + +export { Choices as default }; diff --git a/assets/scripts/choices.search-prefix.js b/assets/scripts/choices.search-prefix.js index 7a66253d..4efc5984 100644 --- a/assets/scripts/choices.search-prefix.js +++ b/assets/scripts/choices.search-prefix.js @@ -1,4 +1,4 @@ -/*! choices.js v11.0.6 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -863,7 +863,9 @@ score: 0, rank: 0, value: option.value, - label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments... + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, element: option, active: true, // this returns true if nothing is selected on initial load, which will break placeholder support @@ -1607,7 +1609,6 @@ inp.autocomplete = 'off'; inp.autocapitalize = 'off'; inp.spellcheck = false; - inp.setAttribute('role', 'textbox'); inp.setAttribute('aria-autocomplete', 'list'); if (placeholderValue) { inp.setAttribute('aria-label', placeholderValue); @@ -3580,7 +3581,7 @@ throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); } }; - Choices.version = '11.0.6'; + Choices.version = '11.1.0'; return Choices; }()); diff --git a/assets/scripts/choices.search-prefix.min.js b/assets/scripts/choices.search-prefix.min.js index d330c75f..c917cbba 100644 --- a/assets/scripts/choices.search-prefix.min.js +++ b/assets/scripts/choices.search-prefix.min.js @@ -1,2 +1,2 @@ -/*! choices.js v11.0.6 | © 2025 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){k(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","true"),this.isOpen=!0,this.shouldFlip(e,t)&&(k(this.element,this.classNames.flippedState),this.isFlipped=!0)},e.prototype.close=function(){M(this.element,this.classNames.openState),this.element.setAttribute("aria-expanded","false"),this.removeActiveDescendant(),this.isOpen=!1,this.isFlipped&&(M(this.element,this.classNames.flippedState),this.isFlipped=!1)},e.prototype.addFocusState=function(){k(this.element,this.classNames.focusState)},e.prototype.removeFocusState=function(){M(this.element,this.classNames.focusState)},e.prototype.enable=function(){M(this.element,this.classNames.disabledState),this.element.removeAttribute("aria-disabled"),this.type===_&&this.element.setAttribute("tabindex","0"),this.isDisabled=!1},e.prototype.disable=function(){k(this.element,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(){k(this.element,this.classNames.loadingState),this.element.setAttribute("aria-busy","true"),this.isLoading=!0},e.prototype.removeLoadingState=function(){M(this.element,this.classNames.loadingState),this.element.removeAttribute("aria-busy"),this.isLoading=!1},e}(),V=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}(),H=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}(),R=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=this.element;k(e,this.classNames.input),e.hidden=!0,e.tabIndex=-1;var t=e.getAttribute("style");t&&e.setAttribute("data-choice-orig-style",t),e.setAttribute("data-choice","active")},e.prototype.reveal=function(){var e=this.element;M(e,this.classNames.input),e.hidden=!1,e.removeAttribute("tabindex");var t=e.getAttribute("data-choice-orig-style");t?(e.removeAttribute("data-choice-orig-style"),e.setAttribute("style",t)):e.removeAttribute("style"),e.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}(),q=function(e){function i(){return null!==e&&e.apply(this,arguments)||this}return t(i,e),i}(R),U=function(e,t){return void 0===t&&(t=!0),void 0===e?t:!!e},G=function(e){if("string"==typeof e&&(e=e.split(" ").filter((function(e){return e.length}))),Array.isArray(e)&&e.length)return e},W=function(e,t,i){if(void 0===i&&(i=!0),"string"==typeof e){var n=w(e);return W({value:e,label:i||n===e?e:{escaped:n,raw:e},selected:!0},!1)}var s=e;if("choices"in s){if(!t)throw new TypeError("optGroup is not allowed");var o=s,r=o.choices.map((function(e){return W(e,!1)}));return{id:0,label:T(o.label)||o.value,active:!!r.length,disabled:!!o.disabled,choices:r}}var a=s;return{id:0,group:null,score:0,rank:0,value:a.value,label:a.label||a.value,active:U(a.active),selected:U(a.selected,!1),disabled:U(a.disabled,!1),placeholder:U(a.placeholder,!1),highlighted:!1,labelClass:G(a.labelClass),labelDescription:a.labelDescription,customProperties:a.customProperties}},X=function(e){return"SELECT"===e.tagName},J=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,group:null,score:0,rank:0,value:e.value,label:e.innerText,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?G(e.dataset.labelClass):void 0,labelDescription:void 0!==e.dataset.labelDescription?e.dataset.labelDescription:void 0,customProperties:K(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}(R),z={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 T(void 0===i?e.value:i).localeCompare(T(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},Q=function(e){var t=e.itemEl;t&&(t.remove(),e.itemEl=void 0)},Y={groups:function(e,t){var i=e,n=!0;switch(t.type){case l:i.push(t.group);break;case c:i=[];break;default:n=!1}return{state:i,update:n}},items:function(e,t,i){var n=e,s=!0;switch(t.type){case h:t.item.selected=!0,(r=t.item.element)&&(r.selected=!0,r.setAttribute("selected","")),n.push(t.item);break;case u:var r;if(t.item.selected=!1,r=t.item.element){r.selected=!1,r.removeAttribute("selected");var a=r.parentElement;a&&X(a)&&a.type===_&&(a.value="")}Q(t.item),n=n.filter((function(e){return e.id!==t.item.id}));break;case o:Q(t.choice),n=n.filter((function(e){return e.id!==t.choice.id}));break;case d: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=e.itemEl;n&&(M(n,i),k(n,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,l=!0;switch(t.type){case s:n.push(t.choice);break;case o:t.choice.choiceEl=void 0,t.choice.group&&(t.choice.group.choices=t.choice.group.choices.filter((function(e){return e.id!==t.choice.id}))),n=n.filter((function(e){return e.id!==t.choice.id}));break;case h:case u:t.item.choiceEl=void 0;break;case r:var d=[];t.results.forEach((function(e){d[e.item.id]=e})),n.forEach((function(e){var t=d[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 a:n.forEach((function(e){e.active=t.active,i&&i.appendGroupInSearch&&(e.choiceEl=void 0)}));break;case c:n=[];break;default:l=!1}return{state:n,update:l}}},Z=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){return this._listeners.push(e),this},e.prototype.dispatch=function(e){var t=this,i=this._state,n=!1,s=this._changeSet||this.changeSet(!1);Object.keys(Y).forEach((function(o){var r=Y[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.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}(),$="no-choices",ee="no-results",te="add-choice",ie=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}(),ne=function(e,t,i){var n=e.dataset,s=t.customProperties,o=t.labelClass,r=t.labelDescription;o&&(n.labelClass=P(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)))},se=function(e,t,i){var n=t&&e.querySelector("label[for='".concat(t,"']")),s=n&&n.innerText;s&&i.setAttribute("aria-label",s)},oe={containerOuter:function(e,t,i,n,s,o,r){var a=e.classNames.containerOuter,c=document.createElement("div");return k(c,a),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||se(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 k(i,t),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 k(a,s),k(a,t?o:r),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 k(s,n),D(s,i,t),s},item:function(e,t,i){var n=e.allowHTML,s=e.removeItemButtonAlignLeft,o=e.removeItemIconText,r=e.removeItemLabelText,a=e.classNames,c=a.item,l=a.button,h=a.highlightedState,u=a.itemSelectable,d=a.placeholder,p=T(t.value),m=document.createElement("div");if(k(m,c),t.labelClass){var f=document.createElement("span");D(f,n,t.label),k(f,t.labelClass),m.appendChild(f)}else D(m,n,t.label);if(m.dataset.item="",m.dataset.id=t.id,m.dataset.value=p,ne(m,t,!0),(t.disabled||this.containerOuter.isDisabled)&&m.setAttribute("aria-disabled","true"),this._isSelectElement&&(m.setAttribute("aria-selected","true"),m.setAttribute("role","option")),t.placeholder&&(k(m,d),m.dataset.placeholder=""),k(m,t.highlighted?h:u),i){t.disabled&&M(m,u),m.dataset.deletable="";var v=document.createElement("button");v.type="button",k(v,l),D(v,!0,A(o,t.value));var _=A(r,t.value);_&&v.setAttribute("aria-label",_),v.dataset.button="",s?m.insertAdjacentElement("afterbegin",v):m.appendChild(v)}return m},choiceList:function(e,t){var i=e.classNames.list,n=document.createElement("div");return k(n,i),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=T(c),u=document.createElement("div");k(u,s),l&&k(u,r),u.setAttribute("role","group"),u.dataset.group="",u.dataset.id=a,u.dataset.value=h,l&&u.setAttribute("aria-disabled","true");var d=document.createElement("div");return k(d,o),D(d,i,c||""),u.appendChild(d),u},choice:function(e,t,i,n){var s=e.allowHTML,o=e.classNames,r=o.item,a=o.itemChoice,c=o.itemSelectable,l=o.selectedState,h=o.itemDisabled,u=o.description,d=o.placeholder,p=t.label,m=T(t.value),f=document.createElement("div");f.id=t.elementId,k(f,r),k(f,a),n&&"string"==typeof p&&(p=L(s,p),p={trusted:p+=" (".concat(n,")")});var v=f;if(t.labelClass){var _=document.createElement("span");D(_,s,p),k(_,t.labelClass),v=_,f.appendChild(_)}else D(f,s,p);if(t.labelDescription){var g="".concat(t.elementId,"-description");v.setAttribute("aria-describedby",g);var y=document.createElement("span");D(y,s,t.labelDescription),y.id=g,k(y,u),f.appendChild(y)}return t.selected&&k(f,l),t.placeholder&&k(f,d),f.setAttribute("role",t.group?"treeitem":"option"),f.dataset.choice="",f.dataset.id=t.id,f.dataset.value=m,i&&(f.dataset.selectText=i),t.group&&(f.dataset.groupId="".concat(t.group.id)),ne(f,t,!1),t.disabled?(k(f,h),f.dataset.choiceDisabled="",f.setAttribute("aria-disabled","true")):(k(f,c),f.dataset.choiceSelectable=""),f},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",k(r,n),k(r,s),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||se(this._docRoot,this.passedElement.element.id,r),r},dropdown:function(e){var t=e.classNames,i=t.list,n=t.listDropdown,s=document.createElement("div");return k(s,i),k(s,n),s.setAttribute("aria-expanded","false"),s},notice:function(e,t,i){var n=e.classNames,s=n.item,o=n.itemChoice,r=n.addChoice,a=n.noResults,c=n.noChoices,l=n.notice;void 0===i&&(i="");var h=document.createElement("div");switch(D(h,!0,t),k(h,s),k(h,o),k(h,l),i){case te:k(h,r);break;case ee:k(h,a);break;case $:k(h,c)}return i===te&&(h.dataset.choiceSelectable="",h.dataset.choice=""),h},option:function(e){var t=T(e.label),i=new Option(t,e.value,!1,e.selected);return ne(i,e,!0),i.disabled=e.disabled,e.selected&&i.setAttribute("selected",""),i}},re="-ms-scroll-limit"in document.documentElement.style&&"-ms-ime-align"in document.documentElement.style,ae={},ce=function(e){if(e)return e.dataset.id?parseInt(e.dataset.id,10):void 0},le="[data-choice-selectable]";return function(){function e(t,n){void 0===t&&(t="[data-choice]"),void 0===n&&(n={});var s=this;this.initialisedOK=void 0,this._hasNonChoicePlaceholder=!1,this._lastAddedChoiceId=0,this._lastAddedGroupId=0;var o=e.defaults;this.config=i(i(i({},o.allOptions),o.options),n),v.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&&!X(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=g);var u=l===_,d=l===g,p=u||d;if(this._elementType=l,this._isTextElement=h,this._isSelectOneElement=u,this._isSelectMultipleElement=d,this._isSelectElement=u||d,this._canAddUserChoices=h&&r.addItems||p&&r.addChoices,"boolean"!=typeof r.renderSelectedChoices&&(r.renderSelectedChoices="always"===r.renderSelectedChoices||u),r.closeDropdownOnSelect="auto"===r.closeDropdownOnSelect?h||u||r.singleModeForMultiSelect:U(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 q({element:c,classNames:r.classNames}):new J({element:c,classNames:r.classNames,template:function(e){return s._templates.option(e)},extractPlaceholder:r.placeholder&&!this._hasNonChoicePlaceholder}),this.initialised=!1,this._store=new Z(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(S(2))||S(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 ae},get allOptions(){return z},get templates(){return oe}})},enumerable:!1,configurable:!0}),e.prototype.init=function(){if(!this.initialised&&void 0===this.initialisedOK){this._searcher=new ie(this.config),this._loadChoices(),this._createTemplates(),this._createElements(),this._createStructure(),this._isTextElement&&!this.config.addItems||this.passedElement.element.hasAttribute("disabled")||this.passedElement.element.closest("fieldset:disabled")?this.disable():(this.enable(),this._addEventListeners()),this._initStore(),this.initialised=!0,this.initialisedOK=!0;var e=this.config.callbackOnInit;"function"==typeof e&&e.call(this)}},e.prototype.destroy=function(){this.initialised&&(this._removeEventListeners(),this.passedElement.reveal(),this.containerOuter.unwrap(this.passedElement.element),this._store._listeners=[],this.clearStore(!1),this._stopSearch(),this._templates=e.defaults.templates,this.initialised=!1,this.initialisedOK=void 0)},e.prototype.enable=function(){return this.passedElement.isDisabled&&this.passedElement.enable(),this.containerOuter.isDisabled&&(this._addEventListeners(),this.input.enable(),this.containerOuter.enable()),this},e.prototype.disable=function(){return this.passedElement.isDisabled||this.passedElement.disable(),this.containerOuter.isDisabled||(this._removeEventListeners(),this.input.disable(),this.containerOuter.disable()),this},e.prototype.highlightItem=function(e,t){if(void 0===t&&(t=!0),!e||!e.id)return this;var i=this._store.items.find((function(t){return t.id===e.id}));return!i||i.highlighted||(this._store.dispatch(C(i,!0)),t&&this.passedElement.triggerEvent(f,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(C(i,!1)),t&&this.passedElement.triggerEvent("unhighlightItem",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(C(t,!0)),e.passedElement.triggerEvent(f,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(C(t,!1)),e.passedElement.triggerEvent(f,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||(void 0===e&&(e=!this._canSearch),requestAnimationFrame((function(){t.dropdown.show();var i=t.dropdown.element.getBoundingClientRect();t.containerOuter.open(i.bottom,i.height),e||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,i=this._store.items.map((function(i){return e?i.value:t._getChoiceForOutput(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(W(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,o,r){var a=this;if(void 0===e&&(e=[]),void 0===t&&(t="value"),void 0===n&&(n="label"),void 0===s&&(s=!1),void 0===o&&(o=!0),void 0===r&&(r=!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("function"==typeof e){var c=e(this);if("function"==typeof Promise&&c instanceof Promise)return new Promise((function(e){return requestAnimationFrame(e)})).then((function(){return a._handleLoadingState(!0)})).then((function(){return c})).then((function(e){return a.setChoices(e,t,n,s,o,r)})).catch((function(e){a.config.silent||console.error(e)})).then((function(){return a._handleLoadingState(!1)})).then((function(){return a}));if(!Array.isArray(c))throw new TypeError(".setChoices first argument function must return either array of choices or Promise, got: ".concat(typeof c));return this.setChoices(c,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(){o&&(a._isSearching=!1),s&&a.clearChoices(!0,r);var c="value"===t,l="label"===n;e.forEach((function(e){if("choices"in e){var s=e;l||(s=i(i({},s),{label:s[n]})),a._addGroup(W(s,!0))}else{var o=e;l&&c||(o=i(i({},o),{value:o[t],label:o[n]}));var r=W(o,!1);a._addChoice(r),r.placeholder&&!a._hasNonChoicePlaceholder&&(a._placeholderValue=x(r.label))}})),a.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&&(o[e.value]=!0)})),n.clearStore(!1);var r=function(e){i?n._store.dispatch(E(e)):o[e.value]&&(e.selected=!0)};s.forEach((function(e){"choices"in e?e.choices.forEach(r):r(e)})),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._clearNotice(),this._store.dispatch(function(e){return{type:o,choice:e}}(t)),this._searcher.reset(),t.selected&&this.passedElement.triggerEvent(m,this._getChoiceForOutput(t)),this):this},e.prototype.clearChoices=function(e,t){var i=this;return void 0===e&&(e=!0),void 0===t&&(t=!1),e&&(t?this.passedElement.element.replaceChildren(""):this.passedElement.element.querySelectorAll(":not([selected])").forEach((function(e){e.remove()}))),this.itemList.element.replaceChildren(""),this.choiceList.element.replaceChildren(""),this._clearNotice(),this._store.withTxn((function(){var e=t?[]:i._store.items;i._store.reset(),e.forEach((function(e){i._store.dispatch(y(e)),i._store.dispatch(b(e))}))})),this._searcher.reset(),this},e.prototype.clearStore=function(e){return void 0===e&&(e=!0),this.clearChoices(e,!0),this._stopSearch(),this._lastAddedChoiceId=0,this._lastAddedGroupId=0,this},e.prototype.clearInput=function(){return this.input.clear(!this._isSelectOneElement),this._stopSearch(),this},e.prototype._validateConfig=function(){var e,t,i,n=this.config,s=(e=z,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=this._store,s=n.activeGroups,o=n.activeChoices,r=0;if(i&&t.searchResultLimit>0?r=t.searchResultLimit:t.renderChoiceLimit>0&&(r=t.renderChoiceLimit),this._isSelectElement){var a=o.filter((function(e){return!e.element}));a.length&&this.passedElement.addOptions(a)}var c=document.createDocumentFragment(),l=function(e){return e.filter((function(e){return!e.placeholder&&(i?!!e.rank:t.renderSelectedChoices||!e.selected)}))},h=!1,u=function(n,s,o){i?n.sort(N):t.shouldSort&&n.sort(t.sorter);var a=n.length;a=!s&&r&&a>r?r:a,a--,n.every((function(n,s){var r=n.choiceEl||e._templates.choice(t,n,t.itemSelectText,o);return n.choiceEl=r,c.appendChild(r),!i&&n.selected||(h=!0),s1){var l=i.querySelector(F(n.classNames.placeholder));l&&l.remove()}else a||c||!this._placeholderValue||(a=!0,r(W({selected:!0,value:"",label:this._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===te&&(t===ee||t===$))?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(F(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){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:e.group?e.group.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&&ce(e.parentElement),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.config.shouldSort?t._store.choices.reverse():t._store.choices).find((function(e){return 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=ce(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=ce(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,i=this.config;if(this._isTextElement){if(this._presetChoices=i.items.map((function(e){return W(e,!1)})),this.passedElement.value){var n=this.passedElement.value.split(i.delimiter).map((function(e){return W(e,!1,t.config.allowHtmlUserInput)}));this._presetChoices=this._presetChoices.concat(n)}this._presetChoices.forEach((function(e){e.selected=!0}))}else if(this._isSelectElement){this._presetChoices=i.choices.map((function(e){return W(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.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(p,{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._notice=void 0,this._displayNotice("function"==typeof i?i(t):i,te),!1):(this._notice&&this._notice.type===te&&this._clearNotice(),!0)},e.prototype._canCreateItem=function(e){var t=this.config,i=!0,n="";if(i&&"function"==typeof t.addItemFilter&&!t.addItemFilter(e)&&(i=!1,n=A(t.customAddItemText,e)),i&&this._store.choices.find((function(i){return t.valueComparer(i.value,e)}))){if(this._isSelectElement)return this._displayNotice("",te),!1;t.duplicateItemsAllowed||(i=!1,n=A(t.uniqueItemText,e))}return i&&(n=A(t.addItemText,e)),n&&this._displayNotice(n,te),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;return(s&&s.type)!==te&&(n.length?this._clearNotice():this._displayNotice(O(this.config.noResultsText),ee)),this._store.dispatch(function(e){return{type:r,results:e}}(n)),n.length},e.prototype._stopSearch=function(){this._isSearching&&(this._currentValue="",this._isSearching=!1,this._clearNotice(),this._store.dispatch({type:a,active:!0}),this.passedElement.triggerEvent(p,{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||27===t||9===t||16===t||(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;e?this._canAddItems()&&(this._canSearch&&this._handleSearch(e),this._canAddUserChoices&&(this._canCreateItem(e),this._isSelectElement&&(this._highlightPosition=0,this._highlightChoice()))):this._isTextElement?this.hideDropdown(!0):this._stopSearch()},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(F(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;i._addChoice(W(n,!1,i.config.allowHtmlUserInput),!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._stopSearch(),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(le,":last-of-type"):le);else{var c=this.dropdown.element.querySelector(F(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,le,r):this.dropdown.element.querySelector(le)}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(re&&this.choiceList.element.contains(t)){var i=this.choiceList.element.firstElementChild;this._isScrollingOnIe="ltr"===this._direction?e.offsetX>=i.offsetWidth:e.offsetXthis._highlightPosition?t[this._highlightPosition]:t[t.length-1])||(i=t[0]),k(i,n),i.setAttribute("aria-selected","true"),this.passedElement.triggerEvent("highlightChoice",{el:i}),this.dropdown.isActive&&(this.input.setActiveDescendant(i.id),this.containerOuter.setActiveDescendant(i.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(b(e)),t&&(this.passedElement.triggerEvent("addItem",this._getChoiceForOutput(e)),i&&this.passedElement.triggerEvent("choice",this._getChoiceForOutput(e)))},e.prototype._removeItem=function(e){if(e.id){this._store.dispatch(E(e));var t=this._notice;t&&t.type===$&&this._clearNotice(),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");var n=this.config;if(n.duplicateItemsAllowed||!this._store.choices.find((function(t){return n.valueComparer(t.value,e.value)}))){this._lastAddedChoiceId++,e.id=this._lastAddedChoiceId,e.elementId="".concat(this._baseId,"-").concat(this._idNames.itemChoice,"-").concat(e.id);var s=n.prependValue,o=n.appendValue;s&&(e.value=s+e.value),o&&(e.value+=o.toString()),(s||o)&&e.element&&(e.element.value=e.value),this._clearNotice(),this._store.dispatch(y(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:l,group:e}}(e)),e.choices&&(this._lastAddedGroupId++,e.id=this._lastAddedGroupId,e.choices.forEach((function(n){n.group=e,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,I,L,P));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 B({element:e.containerOuter(t,this._direction,this._isSelectElement,i,t.searchEnabled,o,t.labelId),classNames:s,type:o,position:n}),this.containerInner=new B({element:e.containerInner(t),classNames:s,type:o,position:n}),this.input=new V({element:e.input(t,this._placeholderValue),classNames:s,type:o,preventPaste:!t.paste}),this.choiceList=new H({element:e.choiceList(t,i)}),this.itemList=new H({element:e.itemList(t,i)}),this.dropdown=new j({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).withTxn((function(){e._addPredefinedChoices(e._presetChoices,e._isSelectOneElement&&!e._hasNonChoicePlaceholder,!1)})),(!this._store.choices.length||this._isSelectOneElement&&this._hasNonChoicePlaceholder)&&this._render()},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.1.0",e}()})); diff --git a/assets/scripts/choices.search-prefix.mjs b/assets/scripts/choices.search-prefix.mjs index 237665dc..a5279fe3 100644 --- a/assets/scripts/choices.search-prefix.mjs +++ b/assets/scripts/choices.search-prefix.mjs @@ -1,4 +1,4 @@ -/*! choices.js v11.0.6 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ +/*! choices.js v11.1.0 | © 2025 Josh Johnson | https://github.com/jshjohnson/Choices#readme */ /****************************************************************************** Copyright (c) Microsoft Corporation. @@ -857,7 +857,9 @@ var WrappedSelect = /** @class */ (function (_super) { score: 0, rank: 0, value: option.value, - label: option.innerText, // HTML options do not support most html tags, but innerHtml will extract html comments... + // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option + // This attribute is text for the label indicating the meaning of the option. If the `label` attribute isn't defined, its value is that of the element text content (ie `innerText`). + label: option.label, element: option, active: true, // this returns true if nothing is selected on initial load, which will break placeholder support @@ -1601,7 +1603,6 @@ var templates = { inp.autocomplete = 'off'; inp.autocapitalize = 'off'; inp.spellcheck = false; - inp.setAttribute('role', 'textbox'); inp.setAttribute('aria-autocomplete', 'list'); if (placeholderValue) { inp.setAttribute('aria-label', placeholderValue); @@ -3574,7 +3575,7 @@ var Choices = /** @class */ (function () { throw new TypeError("".concat(caller, " called for an element which has multiple instances of Choices initialised on it")); } }; - Choices.version = '11.0.6'; + Choices.version = '11.1.0'; return Choices; }()); diff --git a/types/src/scripts/interfaces/build-flags.d.ts b/types/src/scripts/interfaces/build-flags.d.ts index c803580a..3a3f9d30 100644 --- a/types/src/scripts/interfaces/build-flags.d.ts +++ b/types/src/scripts/interfaces/build-flags.d.ts @@ -1,9 +1,11 @@ export declare const canUseDom: boolean; export declare const searchFuse: string | undefined; +export declare const searchKMP: boolean; /** * These are not directly used, as an exported object (even as const) will prevent tree-shake away code paths */ export declare const BuildFlags: { readonly searchFuse: string | undefined; + readonly searchKMP: boolean; readonly canUseDom: boolean; }; diff --git a/types/src/scripts/search/kmp.d.ts b/types/src/scripts/search/kmp.d.ts new file mode 100644 index 00000000..ce97001c --- /dev/null +++ b/types/src/scripts/search/kmp.d.ts @@ -0,0 +1,11 @@ +import { Options } from '../interfaces'; +import { Searcher, SearchResult } from '../interfaces/search'; +export declare class SearchByKMP implements Searcher { + _fields: string[]; + _haystack: T[]; + constructor(config: Options); + index(data: T[]): void; + reset(): void; + isEmptyIndex(): boolean; + search(_needle: string): SearchResult[]; +}