1const a=(r,l,h,c)=>({query:"",selection:h,results:[],cachedResults:{},controller:new AbortController,inputFocus:!1,hasInitialized:!1,url:r,refName:l,suggestedResults:c,ensureInitialized(){this.hasInitialized||(this.hasInitialized=!0,this.suggestedResults.length&&(this.groupify(this.suggestedResults),this.updateSelectable(this.suggestedResults,`${this.refName}_on_suggested_result`)),this.selection.length&&window.dispatchEvent(new CustomEvent(`${this.refName}_on_selection`,{detail:this.selection})))},search(e){if(this.ensureInitialized(),window.dispatchEvent(new CustomEvent(`${this.refName}_on_typing`,{detail:{query:e}})),this.query=e.trim(),e.trim().length<=1){this.results=[];return}window.dispatchEvent(new CustomEvent(`${this.refName}_on_search`,{detail:{term:e}}));const t=this.cachedResults[this.query];if(t){this.results=t,this.updateSelectable(this.results,`${this.refName}_on_result`);return}this.controller=new AbortController;const{signal:s}=this.controller;fetch(`${this.url}?term=${e}`,{signal:s}).then(i=>{if(i.ok)return i.json();throw new Error("Something went wrong on the server.")}).then(i=>{this.results=i.results,this.groupify(this.results),this.updateSelectable(this.results,`${this.refName}_on_result`),this.results.length>0&&(this.cachedResults[e]=this.results)}).catch(i=>{i.name==="AbortError"||(this.results=[])})},_findItemIndex(e){return this.selection.findIndex(t=>t.id===e.id)},_scrollToEnd(){setTimeout(()=>{const e=this.$refs[`${this.refName}_container`];e&&(e.scrollLeft=e.scrollWidth-e.clientWidth)},0)},groupify(e){if(e.length&&e[0].children){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)){const s=e[t];for(const i in s.children){const n=e[t].children[i].id.split(":",1)[0];s.groupId=n,e[t].children[i].group=n}}}},updateSelectable(e,t){if(e.length){if(e[0].children){for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const i=e[s];if(!i.children)continue;let n=!1;for(const o of i.children)for(const d of this.selection)if(d.group===i.groupId){n=!0;break}for(const o in i.children)e[s].children[o].skip=n}}else for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)){const i=e[s];let n=!1;for(const o of this.selection)if(o.id===i.id){n=!0;break}e[s].skip=n}}window.dispatchEvent(new CustomEvent(t,{detail:e}))},selectOption(e,t=!1){if(this._findItemIndex(e)<0){if(e.id.startsWith("job:")||e.id.startsWith("company:/company/")){window.open(e.url,"_blank");return}this.selection.push(e),this.$refs[`${this.refName}_query`].value="",window.dispatchEvent(new CustomEvent(`${this.refName}_on_typing`,{detail:{query:""}})),this.triggerSelectionEvents(t)}},removeOption(e){const t=this._findItemIndex(e);t>=0&&(this.selection.splice(t,1),this.triggerSelectionEvents())},batchSelectOptions(e){this.selection=[];for(const t of e)this._findItemIndex(t)<0&&this.selection.push(t);this.triggerSelectionEvents()},triggerSelectionEvents(e=!1){this.updateSelectable(this.results,`${this.refName}_on_result`),this.updateSelectable(this.suggestedResults,`${this.refName}_on_suggested_result`),e||this._scrollToEnd(),window.dispatchEvent(new CustomEvent(`${this.refName}_on_selection`,{detail:this.selection}))},clearResults(){this.results=[]}});export{a as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.