@magicx-eng/ai-autocomplete-vanilla 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ const ac = new AIAutocomplete(container, {
|
|
|
66
66
|
renderMode: "full",
|
|
67
67
|
|
|
68
68
|
// API
|
|
69
|
-
apiConfig: { apiKey: "...", authScheme: "Bearer", endpoint: "/
|
|
69
|
+
apiConfig: { apiKey: "...", authScheme: "Bearer", endpoint: "https://api.ai-autocomplete.com/api/suggest" },
|
|
70
70
|
optionOverrides: { account: (query) => [...] },
|
|
71
71
|
columns: 2,
|
|
72
72
|
maskCompletedText: false, // when true, omits completed params' text from API requests (PII masking)
|
|
@@ -250,7 +250,7 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
|
|
|
250
250
|
{
|
|
251
251
|
apiKey: "your_api_key",
|
|
252
252
|
authScheme: "Bearer", // or "Basic"
|
|
253
|
-
endpoint: "/
|
|
253
|
+
endpoint: "https://api.ai-autocomplete.com/api/suggest", // optional, this is the default
|
|
254
254
|
appIdentifier: "my-app", // optional
|
|
255
255
|
headers: { "X-Custom": "v" }, // optional
|
|
256
256
|
}
|
|
@@ -266,7 +266,7 @@ A discriminated union: `APIKeyConfig | AccessTokenConfig`.
|
|
|
266
266
|
const { access_token, expires_at } = await res.json();
|
|
267
267
|
return { accessToken: access_token, expiresAt: expires_at };
|
|
268
268
|
},
|
|
269
|
-
endpoint: "/
|
|
269
|
+
endpoint: "https://api.ai-autocomplete.com/api/suggest", // optional, this is the default
|
|
270
270
|
}
|
|
271
271
|
```
|
|
272
272
|
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var oe=(i,e)=>{for(var t in e)k(i,t,{get:e[t],enumerable:!0})},ie=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ee(e))!te.call(i,s)&&s!==t&&k(i,s,{get:()=>e[s],enumerable:!(o=Z(e,s))||o.enumerable});return i};var ne=i=>ie(k({},"__esModule",{value:!0}),i);var Ce={};oe(Ce,{AIAutocomplete:()=>M,createStore:()=>L});module.exports=ne(Ce);function v(i,e,t){let o=i.slice(e);if(t||e===0||i[e-1]===" ")return o;let s=o.indexOf(" ");return s===-1?"":o.slice(s+1)}function B(i,e){let t=i.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let o=t.split(" "),s=e.toLowerCase();for(let n=0;n<o.length;n++){let r=o.slice(n).join(" ");if(s.startsWith(r.toLowerCase())){let d=t.length-r.length;return i.length-d}}return 0}function C(i,e){if(!i)return[];let t=e.trimStart();if(!t)return i;let o=t.toLowerCase();return i.filter(s=>!s.is_tappable||s.text.toLowerCase().includes(o))}function R(i,e){if(!i)return null;let t=e.trim();if(!t)return null;let o=t.toLowerCase();return i.find(s=>s.is_tappable&&s.text.toLowerCase()===o)??null}var w=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function K(i,e){let t=[],o=0;for(let n of e){let r=i.indexOf(n.text,o);r!==-1&&(r>o&&t.push({type:"text",value:i.slice(o,r)}),t.push({type:"completed",value:n.text,param:n}),o=r+n.text.length)}let s=i.slice(o);return s&&t.push({type:"text",value:s}),t}function N(i,e){let t=[],o=[],s=0;for(let n of e){let r=i.indexOf(n.text,s);r===-1?o.push(n):(t.push(n),s=r+n.text.length)}return{valid:t,invalid:o}}var P=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var se="0.1.29",$=!1;function re(){return crypto.randomUUID()}function ae(i,e){return{placeholder:i.placeholder,type:i.type,...e&&{text:i.text},kind:i.kind}}function U(i){return i?.type==="accessToken"}function le(i){if(!(!i||U(i)))return i}var q=new WeakMap;function ce(i){let e=q.get(i.getAccessToken);return e||(e=new P(i),q.set(i.getAccessToken,e)),e}function de(i,e,t){let o=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof o=="number"?o:void 0;return{data:{raw_query:i,completed_params:e.map(n=>ae(n,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:re(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:se}}}function pe(i){return{"Content-Type":"application/json",...i?.appIdentifier&&{"X-App-Identifier":i.appIdentifier},...i?.headers}}async function Q(i,e,t,o,s){return fetch(i,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:o,signal:s})}async function j(i,e,t){let o=t?.apiConfig,s=!t?.maskCompletedText,n=de(i,e,s),r=pe(o),d=o?.endpoint??"/ac/suggest",a=JSON.stringify(n);if(U(o)){let u=ce(o),g=await u.getToken(),m=await Q(d,r,g,a,t?.signal);if(m.status===401){let x=await u.getToken(!0);m=await Q(d,r,x,a,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let c=le(o),l=c?.apiKey??"";if(!l&&!$&&($=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),l){let u=c?.authScheme??"Bearer";r.Authorization=u==="Basic"?`Basic ${btoa(l)}`:`Bearer ${l}`}let p=await fetch(d,{method:"POST",headers:r,body:a,signal:t?.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function y(i,e){let t=i,o={},s=[];for(let n of e){let r=(o[n.type]??0)+1;o[n.type]=r;let a=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${r}}}`,c=t.indexOf(n.text);c!==-1&&(t=t.slice(0,c)+a+t.slice(c+n.text.length)),s.push({...n,placeholder:a})}return{rawQuery:t,completedParams:s}}function V(i,e){return e?i.map(t=>{let o=e[t.type];if(!o)return t;let s=o("");if(s.length===0)return t;let n=new Set(s.map(d=>d.text)),r=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...s,...r]}}):i}var ue=100,me=300,ge=2,O=class{constructor(e,t,o,s,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=o;this.getMaskCompletedText=s;this.getOnError=n;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(o=>{(o.text!==e||o.completedParams!==t)&&(e=o.text,t=o.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let o=new AbortController;this.abortController=o;let s=++this.fetchVersion,n=this.store.get(),r=n.text.length;n.suggestions.some(a=>a.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let a=await j(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:o.signal,apiConfig:this.getApiConfig()});if(s!==this.fetchVersion)return;let c=V(a.data.suggestions??[],this.getOptionOverrides()),l=a.data.input??[],p=l[l.length-1],u=this.store.get().text,g,m;if(p?.state==="in_progress"){m=!0;let b=u.toLowerCase().lastIndexOf(p.text.toLowerCase());g=b!==-1?b:r}else m=!1,g=r;let h=c.filter(b=>b.type!=="placeholder")[0],f=null;if(h){let b=v(u,g,m),S=R(h.options,b);S&&(f={id:crypto.randomUUID(),placeholder:"",type:h.type,text:S.text,kind:S.kind,suggestionType:h.type,suggestionPlaceholder:h.text,options:h.options??[],metadata:S.metadata},c=c.filter(J=>J!==h))}this.store.set(b=>({suggestions:c,isLoading:!1,isReady:a.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:g,filterInProgress:m,...f?{completedParams:[...b.completedParams,f]}:{}}))}catch(a){if(s===this.fetchVersion){let c=a instanceof Error?a:new Error(String(a));this.store.set({error:c,isLoading:!1}),this.getOnError()?.(c)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=o=>{let s=this.store.get();if(!s.text&&s.completedParams.length===0)return this.doFetch("",[]),!0;let n=v(s.text,s.filterBase,s.filterInProgress),d=s.suggestions.filter(h=>h.type!=="placeholder")[0],c=(d?C(d.options,n):[]).filter(h=>h.is_tappable),l=d?R(d.options,n)!==null:!1,p=n.trim().length>0;if(c.length>0&&!l&&p)return!1;if(s.completedParams.length===0&&s.text.length>0){let h=s.suggestions.filter(f=>f.type==="placeholder").map(f=>f.text).join(" ");if(h.length>0&&h.toLowerCase().startsWith(s.text.toLowerCase()))return!1}let{rawQuery:u,completedParams:g}=y(s.text,s.completedParams),m=u.length<s.lastRawQuery.length,x=Math.abs(u.length-s.lastRawQuery.length);return m||x>=o?(this.doFetch(u,g),!0):!1};this.debounceTimer=setTimeout(()=>{t(ge)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},ue),this.slowDebounceTimer=setTimeout(()=>t(1),me)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var T=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:o,getOnSubmit:s}=this.ctx,n=this.getEffectiveColumns(),r=s(),d=this.getTappableIndices(n);switch(e.key){case"ArrowDown":{let a=e.target;if(!(a.selectionStart!=null&&a.selectionStart===a.value.length)&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:d[0]??0});break}if(d.length===0)return;let l=d.indexOf(t.activeDropdownIndex),p=l<d.length-1?l+1:0;this.store.set({activeDropdownIndex:d[p]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<n){this.store.set({activeDropdownIndex:-1});break}let a=d.indexOf(t.activeDropdownIndex),c=a>0?a-1:d.length-1;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let c=e.target;c.selectionStart!=null&&c.selectionStart===c.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%n<n-1){let c=t.activeDropdownIndex+1;c<t.filteredOptions.length&&t.filteredOptions[c]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:c}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%n>0){let a=t.activeDropdownIndex-1;a>=0&&t.filteredOptions[a]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:a}))}break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(r){let{rawQuery:a,completedParams:c}=y(t.text,t.completedParams);r({query:t.text.trim(),raw_query:a,completed_params:c})}break}case"Tab":{let a=!t.text&&!!t.placeholderText,c=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(a&&!c){e.preventDefault();let l=t.suggestions.find(p=>p.type==="placeholder");l?this.store.set(p=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...p.completedParams,{id:crypto.randomUUID(),placeholder:"",type:l.type,text:t.placeholderText,kind:null,suggestionType:l.type,suggestionPlaceholder:l.text,options:l.options??[]}],suggestions:p.suggestions.filter(u=>u!==l)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}else if(c)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(t.isDropdownOpen){let l=t.filteredOptions.findIndex(p=>p.is_tappable);l>=0&&(e.preventDefault(),this.clickOrSelect(l,t.filteredOptions,o))}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(e){let o=this.store.get().filteredOptions.map((n,r)=>n.is_tappable?r:-1).filter(n=>n!==-1),s=Array.from({length:e},()=>[]);for(let n of o)s[n%e].push(n);return s.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let o=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return o>0?o:this.ctx.columns}clickOrSelect(e,t,o){let s=document.getElementById(`${o}-option-${e}`);s?s.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),o=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=o.length)return;let s=o[e],n=o.filter((d,a)=>a!==e),r=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...r,s,...n],pillTapped:!0,activeDropdownIndex:-1})}};var I=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),o=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=o.length)return;let s=o[e],n=o.filter((d,a)=>a!==e),r=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...r,s,...n],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){let e=this.store.get();if(e.completedParams.length===0)return;let t=e.completedParams[e.completedParams.length-1],o={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(s=>({completedParams:s.completedParams.slice(0,-1),suggestions:[o,...s.suggestions],activeDropdownIndex:-1}))}};function he(i){return i===0?.4:i===1?.3:.15}function A(i,e,t,o,s=!1){let n=i.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",i.appendChild(n));let r=new Map;for(let a of n.querySelectorAll(".magicx-aia-pill"))r.set(a.dataset.pillKey??"",a);let d=new Set;for(let a=0;a<e.length;a++){let c=e[a],l=`${c.type}-${c.text}`;d.add(l);let p=r.get(l);p||(p=document.createElement("button"),p.type="button",p.dataset.pillKey=l,p.setAttribute("data-aia-pill",""),p.textContent=c.text),p.className=`magicx-aia-pill${s?" magicx-aia-pill--rounded":""}${a===t?" magicx-aia-pill--active":""}`,p.style.opacity=String(he(a)),p.onclick=()=>o(a),n.children[a]!==p&&n.insertBefore(p,n.children[a]??null)}for(let[a,c]of r)d.has(a)||c.remove()}function D(i){let e=document.createElement("div");return e.id=i,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function E(i,e){let{filteredOptions:t,activeIndex:o,isOpen:s,pills:n,showPills:r,onSelect:d,onHighlight:a,onPillClick:c}=e,l=r&&n.length>0;s&&t.length>0||s&&l?i.classList.add("magicx-aia-dropdown--visible"):i.classList.remove("magicx-aia-dropdown--visible");let g=i.querySelector(".magicx-aia-pill-bar");l?(g||(g=document.createElement("div"),g.className="magicx-aia-pill-bar",g.setAttribute("data-aia-pillbar",""),i.insertBefore(g,i.firstChild)),A(g,n,0,c,!0)):g&&g.remove();let m=i.querySelector(".magicx-aia-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-aia-grid",i.appendChild(m)),fe(m,t,o,d,a,e.listboxId)):m&&(m.innerHTML="")}function fe(i,e,t,o,s,n){let r=e.map(c=>c.text).join("\0"),d=i.dataset.optionsKey??"",a=r!==d;if(i.dataset.optionsKey=r,a){let c=document.createDocumentFragment();for(let l=0;l<e.length;l++){let p=e[l],u=xe(p,l,t,o,s,n);c.appendChild(u)}i.innerHTML="",i.appendChild(c)}else{let c=i.querySelectorAll(".magicx-aia-option");for(let l=0;l<c.length;l++){let p=c[l],u=l===t;p.setAttribute("aria-selected",String(u)),u?p.classList.add("magicx-aia-option--highlighted"):p.classList.remove("magicx-aia-option--highlighted")}}}function xe(i,e,t,o,s,n){let r=document.createElement("div");r.id=`${n}-option-${e}`,r.setAttribute("role","option"),r.setAttribute("data-aia-option",""),r.setAttribute("aria-selected",String(e===t)),r.tabIndex=i.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),i.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),r.className=d.join(" ");let a=document.createElement("div");a.className="magicx-aia-streaks",r.appendChild(a);let c=document.createElement("div");c.className="magicx-aia-streaks-vert",r.appendChild(c);let l=document.createElement("span");if(l.className="magicx-aia-option-content",l.textContent=i.icon?`${i.icon} ${i.text}`:i.text,i.tag){let p=document.createElement("span");p.className="magicx-aia-option-tag",p.textContent=i.tag,l.appendChild(p)}return r.appendChild(l),i.is_tappable&&(r.addEventListener("click",()=>{r.classList.add("magicx-aia-option--pressed"),o(i),setTimeout(()=>r.classList.remove("magicx-aia-option--pressed"),400)}),r.addEventListener("mouseenter",()=>s(e))),r}function W(i,e){let t=D(e.listboxId);return i.appendChild(t),{dropdown:t}}function _(i,e,t){E(i.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:o=>t.store.set({activeDropdownIndex:o}),onPillClick:t.setActivePill})}function z(i,e,t,o,s){let n=i.querySelector(".magicx-aia-sizer-text"),r=i.querySelector(".magicx-aia-placeholder");if(o&&s){n&&(n.style.display="none"),r||(r=document.createElement("span"),r.className="magicx-aia-placeholder",i.insertBefore(r,i.firstChild)),r.style.display="",r.textContent=`${s} `,i.dataset.segmentKey="";return}r&&(r.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",i.insertBefore(n,i.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(l=>`${l.type}:${l.value}`).join("\0"),a=i.dataset.segmentKey??"",c=i.dataset.newParamId??"";if(!(d===a&&(t??"")===c)){i.dataset.segmentKey=d,i.dataset.newParamId=t??"",n.innerHTML="";for(let l of e){let p=document.createElement("span");l.type==="completed"&&(l.param.id===t?p.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":p.className="magicx-aia-segment magicx-aia-segment--completed"),p.textContent=l.value,n.appendChild(p)}e.length===0&&(n.textContent="\xA0")}}var be='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function G(i,e){let{listboxId:t}=e,o=D(t);i.appendChild(o);let s=document.createElement("div");s.className="magicx-aia-input-wrapper",i.appendChild(s);let n=document.createElement("div");n.className="magicx-aia-editor",n.setAttribute("data-aia-editor",""),s.appendChild(n);let r=document.createElement("div");r.className="magicx-aia-sizer",r.setAttribute("aria-hidden","true"),n.appendChild(r);let d=document.createElement("span");r.appendChild(document.createTextNode(" ")),r.appendChild(d);let a=document.createElement("textarea");a.className="magicx-aia-textarea",a.rows=1,a.setAttribute("role","combobox"),a.setAttribute("aria-autocomplete","list"),a.setAttribute("aria-controls",t),a.setAttribute("data-aia-textarea",""),n.appendChild(a);let c=document.createElement("button");return c.type="button",c.className="magicx-aia-submit",c.setAttribute("aria-label","Submit"),c.setAttribute("data-aia-submit",""),c.innerHTML=be,s.appendChild(c),s.addEventListener("click",()=>a.focus()),a.addEventListener("input",()=>{let l=a.value,u=l.length>0&&l[0]!==l[0].toUpperCase()?l[0].toUpperCase()+l.slice(1):l;e.handleChange(u)}),a.addEventListener("keydown",l=>e.handleKeyDown(l)),a.addEventListener("focus",()=>e.store.set({isFocused:!0})),a.addEventListener("blur",()=>e.store.set({isFocused:!1})),c.addEventListener("click",l=>{l.stopPropagation();let p=e.store.get();if(!(!!p.text||p.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:g,completedParams:m}=y(p.text,p.completedParams);e.onSubmit({query:p.text.trim(),raw_query:g,completed_params:m})}),e.autoFocus!==!1&&a.focus(),{textarea:a,dropdown:o,sizer:r,submitButton:c,inlinePillContainer:d}}function F(i,e,t){let{textarea:o,dropdown:s,sizer:n,submitButton:r,inlinePillContainer:d}=i,{pillPlacement:a,setActivePill:c,selectOption:l,store:p}=t;o.value!==e.text&&(o.value=e.text),e.placeholderText?o.placeholder=e.placeholderText:o.removeAttribute("placeholder"),o.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";u?o.setAttribute("aria-activedescendant",u):o.removeAttribute("aria-activedescendant"),e.newParamId?o.classList.add("magicx-aia-textarea--hidden"):o.classList.remove("magicx-aia-textarea--hidden");let g=!!e.text||e.completedParams.length>0;r.disabled=!g,z(n,e.segments,e.newParamId,!e.text,e.placeholderText),a==="inline"?A(d,e.actionableSuggestions,0,c):d.innerHTML="",E(s,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:a==="dropdown",onSelect:l,onHighlight:m=>p.set({activeDropdownIndex:m}),onPillClick:c})}function L(i){let e=i,t=new Set;return{get:()=>e,set:o=>{let s=typeof o=="function"?o(e):o,n={...e,...s},r=e;e=n;for(let d of t)d(n,r)},subscribe:o=>(t.add(o),()=>{t.delete(o)})}}var H=!1;function X(){if(H||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){H=!0;return}H=!0;let i=document.createElement("style");i.setAttribute("data-magicx-aia",""),i.textContent=ye,document.head.appendChild(i)}var ye=`/* ===================================================================
|
|
1
|
+
"use strict";var k=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var oe=(i,e)=>{for(var t in e)k(i,t,{get:e[t],enumerable:!0})},ie=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of ee(e))!te.call(i,s)&&s!==t&&k(i,s,{get:()=>e[s],enumerable:!(o=Z(e,s))||o.enumerable});return i};var ne=i=>ie(k({},"__esModule",{value:!0}),i);var Ce={};oe(Ce,{AIAutocomplete:()=>M,createStore:()=>L});module.exports=ne(Ce);function v(i,e,t){let o=i.slice(e);if(t||e===0||i[e-1]===" ")return o;let s=o.indexOf(" ");return s===-1?"":o.slice(s+1)}function B(i,e){let t=i.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let o=t.split(" "),s=e.toLowerCase();for(let n=0;n<o.length;n++){let r=o.slice(n).join(" ");if(s.startsWith(r.toLowerCase())){let d=t.length-r.length;return i.length-d}}return 0}function C(i,e){if(!i)return[];let t=e.trimStart();if(!t)return i;let o=t.toLowerCase();return i.filter(s=>!s.is_tappable||s.text.toLowerCase().includes(o))}function R(i,e){if(!i)return null;let t=e.trim();if(!t)return null;let o=t.toLowerCase();return i.find(s=>s.is_tappable&&s.text.toLowerCase()===o)??null}var w=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function K(i,e){let t=[],o=0;for(let n of e){let r=i.indexOf(n.text,o);r!==-1&&(r>o&&t.push({type:"text",value:i.slice(o,r)}),t.push({type:"completed",value:n.text,param:n}),o=r+n.text.length)}let s=i.slice(o);return s&&t.push({type:"text",value:s}),t}function N(i,e){let t=[],o=[],s=0;for(let n of e){let r=i.indexOf(n.text,s);r===-1?o.push(n):(t.push(n),s=r+n.text.length)}return{valid:t,invalid:o}}var P=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var se="0.1.30",$=!1;function re(){return crypto.randomUUID()}function ae(i,e){return{placeholder:i.placeholder,type:i.type,...e&&{text:i.text},kind:i.kind}}function U(i){return i?.type==="accessToken"}function le(i){if(!(!i||U(i)))return i}var q=new WeakMap;function ce(i){let e=q.get(i.getAccessToken);return e||(e=new P(i),q.set(i.getAccessToken,e)),e}function de(i,e,t){let o=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof o=="number"?o:void 0;return{data:{raw_query:i,completed_params:e.map(n=>ae(n,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:re(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:se}}}function pe(i){return{"Content-Type":"application/json",...i?.appIdentifier&&{"X-App-Identifier":i.appIdentifier},...i?.headers}}async function Q(i,e,t,o,s){return fetch(i,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:o,signal:s})}async function j(i,e,t){let o=t?.apiConfig,s=!t?.maskCompletedText,n=de(i,e,s),r=pe(o),d=o?.endpoint??"https://api.ai-autocomplete.com/api/suggest",a=JSON.stringify(n);if(U(o)){let u=ce(o),g=await u.getToken(),m=await Q(d,r,g,a,t?.signal);if(m.status===401){let x=await u.getToken(!0);m=await Q(d,r,x,a,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let c=le(o),l=c?.apiKey??"";if(!l&&!$&&($=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),l){let u=c?.authScheme??"Bearer";r.Authorization=u==="Basic"?`Basic ${btoa(l)}`:`Bearer ${l}`}let p=await fetch(d,{method:"POST",headers:r,body:a,signal:t?.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function y(i,e){let t=i,o={},s=[];for(let n of e){let r=(o[n.type]??0)+1;o[n.type]=r;let a=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${r}}}`,c=t.indexOf(n.text);c!==-1&&(t=t.slice(0,c)+a+t.slice(c+n.text.length)),s.push({...n,placeholder:a})}return{rawQuery:t,completedParams:s}}function V(i,e){return e?i.map(t=>{let o=e[t.type];if(!o)return t;let s=o("");if(s.length===0)return t;let n=new Set(s.map(d=>d.text)),r=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...s,...r]}}):i}var ue=100,me=300,ge=2,O=class{constructor(e,t,o,s,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=o;this.getMaskCompletedText=s;this.getOnError=n;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(o=>{(o.text!==e||o.completedParams!==t)&&(e=o.text,t=o.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let o=new AbortController;this.abortController=o;let s=++this.fetchVersion,n=this.store.get(),r=n.text.length;n.suggestions.some(a=>a.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let a=await j(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:o.signal,apiConfig:this.getApiConfig()});if(s!==this.fetchVersion)return;let c=V(a.data.suggestions??[],this.getOptionOverrides()),l=a.data.input??[],p=l[l.length-1],u=this.store.get().text,g,m;if(p?.state==="in_progress"){m=!0;let b=u.toLowerCase().lastIndexOf(p.text.toLowerCase());g=b!==-1?b:r}else m=!1,g=r;let h=c.filter(b=>b.type!=="placeholder")[0],f=null;if(h){let b=v(u,g,m),S=R(h.options,b);S&&(f={id:crypto.randomUUID(),placeholder:"",type:h.type,text:S.text,kind:S.kind,suggestionType:h.type,suggestionPlaceholder:h.text,options:h.options??[],metadata:S.metadata},c=c.filter(J=>J!==h))}this.store.set(b=>({suggestions:c,isLoading:!1,isReady:a.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:g,filterInProgress:m,...f?{completedParams:[...b.completedParams,f]}:{}}))}catch(a){if(s===this.fetchVersion){let c=a instanceof Error?a:new Error(String(a));this.store.set({error:c,isLoading:!1}),this.getOnError()?.(c)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=o=>{let s=this.store.get();if(!s.text&&s.completedParams.length===0)return this.doFetch("",[]),!0;let n=v(s.text,s.filterBase,s.filterInProgress),d=s.suggestions.filter(h=>h.type!=="placeholder")[0],c=(d?C(d.options,n):[]).filter(h=>h.is_tappable),l=d?R(d.options,n)!==null:!1,p=n.trim().length>0;if(c.length>0&&!l&&p)return!1;if(s.completedParams.length===0&&s.text.length>0){let h=s.suggestions.filter(f=>f.type==="placeholder").map(f=>f.text).join(" ");if(h.length>0&&h.toLowerCase().startsWith(s.text.toLowerCase()))return!1}let{rawQuery:u,completedParams:g}=y(s.text,s.completedParams),m=u.length<s.lastRawQuery.length,x=Math.abs(u.length-s.lastRawQuery.length);return m||x>=o?(this.doFetch(u,g),!0):!1};this.debounceTimer=setTimeout(()=>{t(ge)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},ue),this.slowDebounceTimer=setTimeout(()=>t(1),me)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var T=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:o,getOnSubmit:s}=this.ctx,n=this.getEffectiveColumns(),r=s(),d=this.getTappableIndices(n);switch(e.key){case"ArrowDown":{let a=e.target;if(!(a.selectionStart!=null&&a.selectionStart===a.value.length)&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:d[0]??0});break}if(d.length===0)return;let l=d.indexOf(t.activeDropdownIndex),p=l<d.length-1?l+1:0;this.store.set({activeDropdownIndex:d[p]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<n){this.store.set({activeDropdownIndex:-1});break}let a=d.indexOf(t.activeDropdownIndex),c=a>0?a-1:d.length-1;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let c=e.target;c.selectionStart!=null&&c.selectionStart===c.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%n<n-1){let c=t.activeDropdownIndex+1;c<t.filteredOptions.length&&t.filteredOptions[c]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:c}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%n>0){let a=t.activeDropdownIndex-1;a>=0&&t.filteredOptions[a]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:a}))}break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(r){let{rawQuery:a,completedParams:c}=y(t.text,t.completedParams);r({query:t.text.trim(),raw_query:a,completed_params:c})}break}case"Tab":{let a=!t.text&&!!t.placeholderText,c=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(a&&!c){e.preventDefault();let l=t.suggestions.find(p=>p.type==="placeholder");l?this.store.set(p=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...p.completedParams,{id:crypto.randomUUID(),placeholder:"",type:l.type,text:t.placeholderText,kind:null,suggestionType:l.type,suggestionPlaceholder:l.text,options:l.options??[]}],suggestions:p.suggestions.filter(u=>u!==l)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}else if(c)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,o);else if(t.isDropdownOpen){let l=t.filteredOptions.findIndex(p=>p.is_tappable);l>=0&&(e.preventDefault(),this.clickOrSelect(l,t.filteredOptions,o))}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(e){let o=this.store.get().filteredOptions.map((n,r)=>n.is_tappable?r:-1).filter(n=>n!==-1),s=Array.from({length:e},()=>[]);for(let n of o)s[n%e].push(n);return s.flat()}getEffectiveColumns(){let t=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement;if(!t)return this.ctx.columns;let o=getComputedStyle(t).gridTemplateColumns.split(" ").filter(Boolean).length;return o>0?o:this.ctx.columns}clickOrSelect(e,t,o){let s=document.getElementById(`${o}-option-${e}`);s?s.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),o=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=o.length)return;let s=o[e],n=o.filter((d,a)=>a!==e),r=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...r,s,...n],pillTapped:!0,activeDropdownIndex:-1})}};var I=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),o=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=o.length)return;let s=o[e],n=o.filter((d,a)=>a!==e),r=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...r,s,...n],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){let e=this.store.get();if(e.completedParams.length===0)return;let t=e.completedParams[e.completedParams.length-1],o={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(s=>({completedParams:s.completedParams.slice(0,-1),suggestions:[o,...s.suggestions],activeDropdownIndex:-1}))}};function he(i){return i===0?.4:i===1?.3:.15}function A(i,e,t,o,s=!1){let n=i.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",i.appendChild(n));let r=new Map;for(let a of n.querySelectorAll(".magicx-aia-pill"))r.set(a.dataset.pillKey??"",a);let d=new Set;for(let a=0;a<e.length;a++){let c=e[a],l=`${c.type}-${c.text}`;d.add(l);let p=r.get(l);p||(p=document.createElement("button"),p.type="button",p.dataset.pillKey=l,p.setAttribute("data-aia-pill",""),p.textContent=c.text),p.className=`magicx-aia-pill${s?" magicx-aia-pill--rounded":""}${a===t?" magicx-aia-pill--active":""}`,p.style.opacity=String(he(a)),p.onclick=()=>o(a),n.children[a]!==p&&n.insertBefore(p,n.children[a]??null)}for(let[a,c]of r)d.has(a)||c.remove()}function D(i){let e=document.createElement("div");return e.id=i,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function E(i,e){let{filteredOptions:t,activeIndex:o,isOpen:s,pills:n,showPills:r,onSelect:d,onHighlight:a,onPillClick:c}=e,l=r&&n.length>0;s&&t.length>0||s&&l?i.classList.add("magicx-aia-dropdown--visible"):i.classList.remove("magicx-aia-dropdown--visible");let g=i.querySelector(".magicx-aia-pill-bar");l?(g||(g=document.createElement("div"),g.className="magicx-aia-pill-bar",g.setAttribute("data-aia-pillbar",""),i.insertBefore(g,i.firstChild)),A(g,n,0,c,!0)):g&&g.remove();let m=i.querySelector(".magicx-aia-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-aia-grid",i.appendChild(m)),fe(m,t,o,d,a,e.listboxId)):m&&(m.innerHTML="")}function fe(i,e,t,o,s,n){let r=e.map(c=>c.text).join("\0"),d=i.dataset.optionsKey??"",a=r!==d;if(i.dataset.optionsKey=r,a){let c=document.createDocumentFragment();for(let l=0;l<e.length;l++){let p=e[l],u=xe(p,l,t,o,s,n);c.appendChild(u)}i.innerHTML="",i.appendChild(c)}else{let c=i.querySelectorAll(".magicx-aia-option");for(let l=0;l<c.length;l++){let p=c[l],u=l===t;p.setAttribute("aria-selected",String(u)),u?p.classList.add("magicx-aia-option--highlighted"):p.classList.remove("magicx-aia-option--highlighted")}}}function xe(i,e,t,o,s,n){let r=document.createElement("div");r.id=`${n}-option-${e}`,r.setAttribute("role","option"),r.setAttribute("data-aia-option",""),r.setAttribute("aria-selected",String(e===t)),r.tabIndex=i.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),i.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),r.className=d.join(" ");let a=document.createElement("div");a.className="magicx-aia-streaks",r.appendChild(a);let c=document.createElement("div");c.className="magicx-aia-streaks-vert",r.appendChild(c);let l=document.createElement("span");if(l.className="magicx-aia-option-content",l.textContent=i.icon?`${i.icon} ${i.text}`:i.text,i.tag){let p=document.createElement("span");p.className="magicx-aia-option-tag",p.textContent=i.tag,l.appendChild(p)}return r.appendChild(l),i.is_tappable&&(r.addEventListener("click",()=>{r.classList.add("magicx-aia-option--pressed"),o(i),setTimeout(()=>r.classList.remove("magicx-aia-option--pressed"),400)}),r.addEventListener("mouseenter",()=>s(e))),r}function W(i,e){let t=D(e.listboxId);return i.appendChild(t),{dropdown:t}}function _(i,e,t){E(i.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:o=>t.store.set({activeDropdownIndex:o}),onPillClick:t.setActivePill})}function z(i,e,t,o,s){let n=i.querySelector(".magicx-aia-sizer-text"),r=i.querySelector(".magicx-aia-placeholder");if(o&&s){n&&(n.style.display="none"),r||(r=document.createElement("span"),r.className="magicx-aia-placeholder",i.insertBefore(r,i.firstChild)),r.style.display="",r.textContent=`${s} `,i.dataset.segmentKey="";return}r&&(r.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",i.insertBefore(n,i.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(l=>`${l.type}:${l.value}`).join("\0"),a=i.dataset.segmentKey??"",c=i.dataset.newParamId??"";if(!(d===a&&(t??"")===c)){i.dataset.segmentKey=d,i.dataset.newParamId=t??"",n.innerHTML="";for(let l of e){let p=document.createElement("span");l.type==="completed"&&(l.param.id===t?p.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":p.className="magicx-aia-segment magicx-aia-segment--completed"),p.textContent=l.value,n.appendChild(p)}e.length===0&&(n.textContent="\xA0")}}var be='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function G(i,e){let{listboxId:t}=e,o=D(t);i.appendChild(o);let s=document.createElement("div");s.className="magicx-aia-input-wrapper",i.appendChild(s);let n=document.createElement("div");n.className="magicx-aia-editor",n.setAttribute("data-aia-editor",""),s.appendChild(n);let r=document.createElement("div");r.className="magicx-aia-sizer",r.setAttribute("aria-hidden","true"),n.appendChild(r);let d=document.createElement("span");r.appendChild(document.createTextNode(" ")),r.appendChild(d);let a=document.createElement("textarea");a.className="magicx-aia-textarea",a.rows=1,a.setAttribute("role","combobox"),a.setAttribute("aria-autocomplete","list"),a.setAttribute("aria-controls",t),a.setAttribute("data-aia-textarea",""),n.appendChild(a);let c=document.createElement("button");return c.type="button",c.className="magicx-aia-submit",c.setAttribute("aria-label","Submit"),c.setAttribute("data-aia-submit",""),c.innerHTML=be,s.appendChild(c),s.addEventListener("click",()=>a.focus()),a.addEventListener("input",()=>{let l=a.value,u=l.length>0&&l[0]!==l[0].toUpperCase()?l[0].toUpperCase()+l.slice(1):l;e.handleChange(u)}),a.addEventListener("keydown",l=>e.handleKeyDown(l)),a.addEventListener("focus",()=>e.store.set({isFocused:!0})),a.addEventListener("blur",()=>e.store.set({isFocused:!1})),c.addEventListener("click",l=>{l.stopPropagation();let p=e.store.get();if(!(!!p.text||p.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:g,completedParams:m}=y(p.text,p.completedParams);e.onSubmit({query:p.text.trim(),raw_query:g,completed_params:m})}),e.autoFocus!==!1&&a.focus(),{textarea:a,dropdown:o,sizer:r,submitButton:c,inlinePillContainer:d}}function F(i,e,t){let{textarea:o,dropdown:s,sizer:n,submitButton:r,inlinePillContainer:d}=i,{pillPlacement:a,setActivePill:c,selectOption:l,store:p}=t;o.value!==e.text&&(o.value=e.text),e.placeholderText?o.placeholder=e.placeholderText:o.removeAttribute("placeholder"),o.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";u?o.setAttribute("aria-activedescendant",u):o.removeAttribute("aria-activedescendant"),e.newParamId?o.classList.add("magicx-aia-textarea--hidden"):o.classList.remove("magicx-aia-textarea--hidden");let g=!!e.text||e.completedParams.length>0;r.disabled=!g,z(n,e.segments,e.newParamId,!e.text,e.placeholderText),a==="inline"?A(d,e.actionableSuggestions,0,c):d.innerHTML="",E(s,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:a==="dropdown",onSelect:l,onHighlight:m=>p.set({activeDropdownIndex:m}),onPillClick:c})}function L(i){let e=i,t=new Set;return{get:()=>e,set:o=>{let s=typeof o=="function"?o(e):o,n={...e,...s},r=e;e=n;for(let d of t)d(n,r)},subscribe:o=>(t.add(o),()=>{t.delete(o)})}}var H=!1;function X(){if(H||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){H=!0;return}H=!0;let i=document.createElement("style");i.setAttribute("data-magicx-aia",""),i.textContent=ye,document.head.appendChild(i)}var ye=`/* ===================================================================
|
|
2
2
|
Vanilla core styles \u2014 stable BEM class names (magicx-aia-*)
|
|
3
3
|
Auto-injected at runtime on first instantiation.
|
|
4
4
|
=================================================================== */
|