@magicx-eng/ai-autocomplete-react 0.1.21 → 0.1.23
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 +4 -1
- package/dist/index.d.mts +1 -8
- package/dist/index.d.ts +1 -8
- package/dist/index.js +43 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{forwardRef as
|
|
1
|
+
import{forwardRef as xt,useCallback as bt,useEffect as Ie,useImperativeHandle as vt,useRef as ae}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-cc65f4cc")){let o=document.createElement("style");o.id="ac-style-cc65f4cc",o.textContent=`.AIAutocomplete-module_container_KKjFU {
|
|
2
2
|
position: relative;
|
|
3
3
|
font-family: "IBM Plex Sans", sans-serif;
|
|
4
4
|
container-type: inline-size;
|
|
@@ -152,19 +152,19 @@ import{forwardRef as gt,useCallback as ht,useEffect as we,useImperativeHandle as
|
|
|
152
152
|
opacity: 0;
|
|
153
153
|
pointer-events: none;
|
|
154
154
|
transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
border:
|
|
155
|
+
box-shadow:
|
|
156
|
+
hsla(0, 0%, 100%, 1) -3.2px -3.2px 3.2px -3.2px inset,
|
|
157
|
+
hsla(0, 0%, 100%, 1) 6.4px 6.4px 1.6px -8px inset,
|
|
158
|
+
var(--aia-dropdown-bg, transparent) -6.4px 6.4px 1.6px -8px inset, /* same color as bg */
|
|
159
|
+
var(--aia-dropdown-bg, transparent) 6.4px -6.4px 1.6px -8px inset, /* same color as bg */
|
|
160
|
+
hsla(0, 0%, 100%, 0.15) -1.6px 0px 0px -1.6px inset,
|
|
161
|
+
hsla(0, 0%, 100%, 0.15) 0px -1.6px 0px -1.6px inset,
|
|
162
|
+
hsla(0, 0%, 100%, 0.3) 0px 1.6px 0px 0px inset,
|
|
163
|
+
hsla(0, 0%, 100%, 0.3) 1.6px 0px 0px 0px inset,
|
|
164
|
+
inset 0 0 30px 5px hsla(0, 0%, 0%, 0.05),
|
|
165
|
+
hsla(0, 0%, 0%, 0.08) 0px 0px 30px 2px;
|
|
166
|
+
backdrop-filter: blur(30px);
|
|
167
|
+
border-radius: 28px;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
.AIAutocompleteDropdown-module_visible_QCoXj {
|
|
@@ -175,7 +175,7 @@ import{forwardRef as gt,useCallback as ht,useEffect as we,useImperativeHandle as
|
|
|
175
175
|
.AIAutocompleteDropdown-module_pillBar_pwTXe {
|
|
176
176
|
padding: 27px 27px 0px 27px;
|
|
177
177
|
}
|
|
178
|
-
`,document.head.appendChild(o)}var
|
|
178
|
+
`,document.head.appendChild(o)}var G={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj",pillBar:"AIAutocompleteDropdown-module_pillBar_pwTXe"};if(typeof document<"u"&&!document.getElementById("ac-style-b745b4fb")){let o=document.createElement("style");o.id="ac-style-b745b4fb",o.textContent=`.PillList-module_list_qvLqO {
|
|
179
179
|
position: relative;
|
|
180
180
|
z-index: 1;
|
|
181
181
|
pointer-events: auto;
|
|
@@ -226,15 +226,37 @@ import{forwardRef as gt,useCallback as ht,useEffect as we,useImperativeHandle as
|
|
|
226
226
|
opacity: 0;
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
`,document.head.appendChild(o)}var q={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",active:"PillList-module_active_Oll--"};import{jsx as
|
|
229
|
+
`,document.head.appendChild(o)}var q={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",active:"PillList-module_active_Oll--"};import{jsx as _e}from"react/jsx-runtime";function Ve(o){return o===0?.4:o===1?.3:.15}function X({pills:o,activePillIndex:e,onSelectPill:t,rounded:i}){return _e("span",{className:q.list,children:o.map((s,n)=>_e("button",{type:"button",className:`${q.pill} ${i?q.rounded:""} ${n===e?q.active:""}`,style:{opacity:Ve(n)},onClick:()=>t(n),children:s.text},`${s.type}-${s.text}`))})}import{useEffect as je,useLayoutEffect as Ge,useRef as Xe,useState as Je}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-d91f2b06")){let o=document.createElement("style");o.id="ac-style-d91f2b06",o.textContent=`.SuggestionGrid-module_scrollWrapper_MOqfw {
|
|
230
|
+
position: relative;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.SuggestionGrid-module_scrollWrapper_MOqfw::after {
|
|
234
|
+
content: "";
|
|
235
|
+
position: absolute;
|
|
236
|
+
left: 0;
|
|
237
|
+
right: 0;
|
|
238
|
+
bottom: 0;
|
|
239
|
+
height: 50%;
|
|
240
|
+
pointer-events: none;
|
|
241
|
+
opacity: 0;
|
|
242
|
+
transition: opacity 150ms ease-out;
|
|
243
|
+
backdrop-filter: blur(12px);
|
|
244
|
+
mask-image: linear-gradient(to bottom, transparent, white);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.SuggestionGrid-module_scrollWrapper_MOqfw[data-fade]::after {
|
|
248
|
+
opacity: 1;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.SuggestionGrid-module_grid_jvaPb {
|
|
230
252
|
display: grid;
|
|
231
253
|
grid-template-columns: minmax(0, 1fr);
|
|
232
254
|
max-width: 100cqi;
|
|
233
255
|
padding: 13px 13px;
|
|
234
|
-
max-height:
|
|
256
|
+
max-height: 200px;
|
|
235
257
|
overflow-y: auto;
|
|
236
258
|
scrollbar-width: thin;
|
|
237
|
-
scrollbar-color: rgba(
|
|
259
|
+
scrollbar-color: var(--aia-scrollbar-thumb, rgba(0, 0, 0, 0.3)) transparent;
|
|
238
260
|
}
|
|
239
261
|
|
|
240
262
|
@container (min-width: 650px) {
|
|
@@ -253,10 +275,10 @@ import{forwardRef as gt,useCallback as ht,useEffect as we,useImperativeHandle as
|
|
|
253
275
|
}
|
|
254
276
|
|
|
255
277
|
.SuggestionGrid-module_grid_jvaPb::-webkit-scrollbar-thumb {
|
|
256
|
-
background: rgba(
|
|
278
|
+
background: var(--aia-scrollbar-thumb, rgba(0, 0, 0, 0.3));
|
|
257
279
|
border-radius: 3px;
|
|
258
280
|
}
|
|
259
|
-
`,document.head.appendChild(o)}var
|
|
281
|
+
`,document.head.appendChild(o)}var me={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};import{useEffect as Ue,useRef as Qe,useState as We}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-f6bdc634")){let o=document.createElement("style");o.id="ac-style-f6bdc634",o.textContent=`.SuggestionItem-module_item_d4vpD {
|
|
260
282
|
position: relative;
|
|
261
283
|
overflow: visible;
|
|
262
284
|
display: flex;
|
|
@@ -563,5 +585,5 @@ import{forwardRef as gt,useCallback as ht,useEffect as we,useImperativeHandle as
|
|
|
563
585
|
box-shadow: 0 0 24px 10px rgba(255, 255, 255, 0.02);
|
|
564
586
|
}
|
|
565
587
|
}
|
|
566
|
-
`,document.head.appendChild(o)}var A={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh"};import{jsx as me,jsxs as _e}from"react/jsx-runtime";function Pe({option:o,isHighlighted:e,onSelect:t,onHighlight:i,id:r}){let[n,s]=Ge(!1),d=je(void 0);Qe(()=>()=>clearTimeout(d.current),[]);let a=()=>{!o.is_tappable||n||(s(!0),t(o),clearTimeout(d.current),d.current=setTimeout(()=>s(!1),400))},l=[A.item,e?A.highlighted:"",o.is_tappable?A.tappable:A.nonTappable,n?A.pressed:""].filter(Boolean).join(" ");return _e("div",{id:r,role:"option","aria-selected":e,className:l,tabIndex:o.is_tappable?0:-1,onClick:a,onKeyDown:p=>{o.is_tappable&&(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),a())},onMouseEnter:i,children:[me("div",{className:A.streaks}),me("div",{className:A.streaksVert}),_e("span",{className:A.content,children:[o.icon?`${o.icon} ${o.text}`:o.text,o.tag&&me("span",{className:A.tag,children:o.tag})]})]})}import{jsx as Ce}from"react/jsx-runtime";function Ae({options:o,activeIndex:e,onSelect:t,onHighlight:i,listboxId:r}){return Ce("div",{className:Ie.grid,children:o.map((n,s)=>Ce(Pe,{option:n,isHighlighted:s===e,onSelect:t,onHighlight:()=>i(s),id:`${r}-option-${s}`},n.text))})}import{jsx as ge,jsxs as We}from"react/jsx-runtime";function he({suggestions:o,activeIndex:e,onSelect:t,onHighlight:i,isOpen:r,id:n,className:s,pills:d,onPillClick:a,showPills:l=!0}){let c=o[0]?.options??[],u=l&&d&&d.length>0&&a,m=r&&c.length>0||r&&u;return We("div",{id:n,role:"listbox","data-aia-dropdown":"",className:`${W.dropdown} ${m?W.visible:""} ${s??""}`,onMouseDown:w=>w.preventDefault(),children:[u&&ge("div",{className:W.pillBar,"data-aia-pillbar":"",children:ge(X,{pills:d,activePillIndex:0,onSelectPill:a,rounded:!0})}),c.length>0&&ge(Ae,{options:c,activeIndex:e,onSelect:t,onHighlight:i,listboxId:n})]})}import{useCallback as T,useEffect as se,useRef as R,useState as mt}from"react";function V(o,e,t){let i=o.slice(e);if(t||e===0||o[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function ke(o,e){let t=o.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let n=0;n<i.length;n++){let s=i.slice(n).join(" ");if(r.startsWith(s.toLowerCase())){let d=t.length-s.length;return o.length-d}}return 0}function J(o,e){if(!o)return[];let t=e.trimStart();if(!t)return o;let i=t.toLowerCase();return o.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function fe(o,e){if(!o)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return o.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}var H=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 Te(o,e){let t=[],i=0;for(let n of e){let s=o.indexOf(n.text,i);s!==-1&&(s>i&&t.push({type:"text",value:o.slice(i,s)}),t.push({type:"completed",value:n.text,param:n}),i=s+n.text.length)}let r=o.slice(i);return r&&t.push({type:"text",value:r}),t}function Oe(o,e){let t=[],i=[],r=0;for(let n of e){let s=o.indexOf(n.text,r);s===-1?i.push(n):(t.push(n),r=s+n.text.length)}return{valid:t,invalid:i}}var Y=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 Xe="0.1.21",De=!1;function Je(){return crypto.randomUUID()}function Ye(o,e){return{placeholder:o.placeholder,type:o.type,...e&&{text:o.text},kind:o.kind}}function Re(o){return o?.type==="accessToken"}function Ze(o){if(!(!o||Re(o)))return o}var Ee=new WeakMap;function et(o){let e=Ee.get(o.getAccessToken);return e||(e=new Y(o),Ee.set(o.getAccessToken,e)),e}function tt(o,e,t){let i=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,r=typeof i=="number"?i:void 0;return{data:{raw_query:o,completed_params:e.map(n=>Ye(n,t)),...r!=null&&{contact_account_count:r}},meta:{request_id:Je(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:Xe}}}function ot(o){return{"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers}}async function Le(o,e,t,i,r){return fetch(o,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function Me(o,e,t){let i=t?.apiConfig,r=!t?.maskCompletedText,n=tt(o,e,r),s=ot(i),d=i?.endpoint??"/ac/suggest",a=JSON.stringify(n);if(Re(i)){let u=et(i),f=await u.getToken(),m=await Le(d,s,f,a,t?.signal);if(m.status===401){let w=await u.getToken(!0);m=await Le(d,s,w,a,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let l=Ze(i),p=l?.apiKey??"";if(!p&&!De&&(De=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),p){let u=l?.authScheme??"Bearer";s.Authorization=u==="Basic"?`Basic ${btoa(p)}`:`Bearer ${p}`}let c=await fetch(d,{method:"POST",headers:s,body:a,signal:t?.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}function D(o,e){let t=o,i={},r=[];for(let n of e){let s=(i[n.type]??0)+1;i[n.type]=s;let a=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${s}}}`,l=t.indexOf(n.text);l!==-1&&(t=t.slice(0,l)+a+t.slice(l+n.text.length)),r.push({...n,placeholder:a})}return{rawQuery:t,completedParams:r}}function ze(o,e){return e?o.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let n=new Set(r.map(d=>d.text)),s=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...r,...s]}}):o}var it=100,nt=300,rt=2,Z=class{constructor(e,t,i,r,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;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(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,n=this.store.get(),s=n.text.length;n.suggestions.some(a=>a.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let a=await Me(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let l=ze(a.data.suggestions??[],this.getOptionOverrides()),p=a.data.input??[],c=p[p.length-1],u=this.store.get().text,f,m;if(c?.state==="in_progress"){m=!0;let I=u.toLowerCase().lastIndexOf(c.text.toLowerCase());f=I!==-1?I:s}else m=!1,f=s;let x=l.filter(I=>I.type!=="placeholder")[0],b=null;if(x){let I=V(u,f,m),g=fe(x.options,I);g&&(b={id:crypto.randomUUID(),placeholder:"",type:x.type,text:g.text,kind:g.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:g.metadata},l=l.filter(S=>S!==x))}this.store.set(I=>({suggestions:l,isLoading:!1,isReady:a.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:f,filterInProgress:m,...b?{completedParams:[...I.completedParams,b]}:{}}))}catch(a){if(r===this.fetchVersion){let l=a instanceof Error?a:new Error(String(a));this.store.set({error:l,isLoading:!1}),this.getOnError()?.(l)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let n=V(r.text,r.filterBase,r.filterInProgress),d=r.suggestions.filter(x=>x.type!=="placeholder")[0],l=(d?J(d.options,n):[]).filter(x=>x.is_tappable),p=d?fe(d.options,n)!==null:!1,c=n.trim().length>0;if(l.length>0&&!p&&c)return!1;if(r.completedParams.length===0&&r.text.length>0){let x=r.suggestions.filter(b=>b.type==="placeholder").map(b=>b.text).join(" ");if(x.length>0&&x.toLowerCase().startsWith(r.text.toLowerCase()))return!1}let{rawQuery:u,completedParams:f}=D(r.text,r.completedParams),m=u.length<r.lastRawQuery.length,w=Math.abs(u.length-r.lastRawQuery.length);return m||w>=i?(this.doFetch(u,f),!0):!1};this.debounceTimer=setTimeout(()=>{t(rt)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},it),this.slowDebounceTimer=setTimeout(()=>t(1),nt)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ee=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{columns:i,listboxId:r,getOnSubmit:n}=this.ctx,s=n(),d=this.getTappableIndices();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 p=d.indexOf(t.activeDropdownIndex),c=p<d.length-1?p+1:0;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<i){this.store.set({activeDropdownIndex:-1});break}let a=d.indexOf(t.activeDropdownIndex),l=a>0?a-1:d.length-1;this.store.set({activeDropdownIndex:d[l]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let l=e.target;l.selectionStart!=null&&l.selectionStart===l.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%i<i-1){let l=t.activeDropdownIndex+1;l<t.filteredOptions.length&&t.filteredOptions[l]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:l}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%i>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,r);else if(s){let{rawQuery:a,completedParams:l}=D(t.text,t.completedParams);s({query:t.text.trim(),raw_query:a,completed_params:l})}break}case"Tab":{if(t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,r);else if(t.isDropdownOpen){let a=t.filteredOptions.findIndex(l=>l.is_tappable);a>=0&&(e.preventDefault(),this.clickOrSelect(a,t.filteredOptions,r))}else if(!t.text&&t.placeholderText){e.preventDefault();let a=t.suggestions.find(l=>l.type==="placeholder");a?this.store.set(l=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...l.completedParams,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:t.placeholderText,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[]}],suggestions:l.suggestions.filter(p=>p!==a)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(){let e=this.store.get(),{columns:t}=this.ctx,i=e.filteredOptions.map((n,s)=>n.is_tappable?s:-1).filter(n=>n!==-1),r=Array.from({length:t},()=>[]);for(let n of i)r[n%t].push(n);return r.flat()}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,a)=>a!==e),s=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...s,r,...n],pillTapped:!0,activeDropdownIndex:-1})}};var te=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,a)=>a!==e),s=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...s,r,...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],i={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(r=>({completedParams:r.completedParams.slice(0,-1),suggestions:[i,...r.suggestions],activeDropdownIndex:-1}))}};function st(o){return o===0?.4:o===1?.3:.15}function oe(o,e,t,i,r=!1){let n=o.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",o.appendChild(n));let s=new Map;for(let a of n.querySelectorAll(".magicx-aia-pill"))s.set(a.dataset.pillKey??"",a);let d=new Set;for(let a=0;a<e.length;a++){let l=e[a],p=`${l.type}-${l.text}`;d.add(p);let c=s.get(p);c||(c=document.createElement("button"),c.type="button",c.dataset.pillKey=p,c.textContent=l.text),c.className=`magicx-aia-pill${r?" magicx-aia-pill--rounded":""}${a===t?" magicx-aia-pill--active":""}`,c.style.opacity=String(st(a)),c.onclick=()=>i(a),n.children[a]!==c&&n.insertBefore(c,n.children[a]??null)}for(let[a,l]of s)d.has(a)||l.remove()}function ie(o){let e=document.createElement("div");return e.id=o,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function ne(o,e){let{filteredOptions:t,activeIndex:i,isOpen:r,pills:n,showPills:s,onSelect:d,onHighlight:a,onPillClick:l}=e,p=s&&n.length>0;r&&t.length>0||r&&p?o.classList.add("magicx-aia-dropdown--visible"):o.classList.remove("magicx-aia-dropdown--visible");let f=o.querySelector(".magicx-aia-pill-bar");p?(f||(f=document.createElement("div"),f.className="magicx-aia-pill-bar",o.insertBefore(f,o.firstChild)),oe(f,n,0,l,!0)):f&&f.remove();let m=o.querySelector(".magicx-aia-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-aia-grid",o.appendChild(m)),at(m,t,i,d,a,e.listboxId)):m&&(m.innerHTML="")}function at(o,e,t,i,r,n){let s=e.map(l=>l.text).join("\0"),d=o.dataset.optionsKey??"",a=s!==d;if(o.dataset.optionsKey=s,a){let l=document.createDocumentFragment();for(let p=0;p<e.length;p++){let c=e[p],u=lt(c,p,t,i,r,n);l.appendChild(u)}o.innerHTML="",o.appendChild(l)}else{let l=o.querySelectorAll(".magicx-aia-option");for(let p=0;p<l.length;p++){let c=l[p],u=p===t;c.setAttribute("aria-selected",String(u)),u?c.classList.add("magicx-aia-option--highlighted"):c.classList.remove("magicx-aia-option--highlighted")}}}function lt(o,e,t,i,r,n){let s=document.createElement("div");s.id=`${n}-option-${e}`,s.setAttribute("role","option"),s.setAttribute("aria-selected",String(e===t)),s.tabIndex=o.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),o.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),s.className=d.join(" ");let a=document.createElement("div");a.className="magicx-aia-streaks",s.appendChild(a);let l=document.createElement("div");l.className="magicx-aia-streaks-vert",s.appendChild(l);let p=document.createElement("span");if(p.className="magicx-aia-option-content",p.textContent=o.icon?`${o.icon} ${o.text}`:o.text,o.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=o.tag,p.appendChild(c)}return s.appendChild(p),o.is_tappable&&s.addEventListener("click",()=>{s.classList.add("magicx-aia-option--pressed"),i(o),setTimeout(()=>s.classList.remove("magicx-aia-option--pressed"),400)}),s.addEventListener("mouseenter",()=>r(e)),s}function He(o,e){let t=ie(e.listboxId);return o.appendChild(t),{dropdown:t}}function xe(o,e,t){ne(o.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:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function Be(o,e,t,i,r){let n=o.querySelector(".magicx-aia-sizer-text"),s=o.querySelector(".magicx-aia-placeholder");if(i&&r){n&&(n.style.display="none"),s||(s=document.createElement("span"),s.className="magicx-aia-placeholder",o.insertBefore(s,o.firstChild)),s.style.display="",s.textContent=`${r} `,o.dataset.segmentKey="";return}s&&(s.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",o.insertBefore(n,o.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(p=>`${p.type}:${p.value}`).join("\0"),a=o.dataset.segmentKey??"",l=o.dataset.newParamId??"";if(!(d===a&&(t??"")===l)){o.dataset.segmentKey=d,o.dataset.newParamId=t??"",n.innerHTML="";for(let p of e){let c=document.createElement("span");p.type==="completed"&&(p.param.id===t?c.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":c.className="magicx-aia-segment magicx-aia-segment--completed"),c.textContent=p.value,n.appendChild(c)}e.length===0&&(n.textContent="\xA0")}}var dt='<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 Ne(o,e){let{listboxId:t}=e,i=ie(t);o.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",o.appendChild(r);let n=document.createElement("div");n.className="magicx-aia-editor",r.appendChild(n);let s=document.createElement("div");s.className="magicx-aia-sizer",s.setAttribute("aria-hidden","true"),n.appendChild(s);let d=document.createElement("span");s.appendChild(document.createTextNode(" ")),s.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),n.appendChild(a);let l=document.createElement("button");return l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.innerHTML=dt,r.appendChild(l),r.addEventListener("click",()=>a.focus()),a.addEventListener("input",()=>{let p=a.value,u=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(u)}),a.addEventListener("keydown",p=>e.handleKeyDown(p)),l.addEventListener("click",p=>{p.stopPropagation();let c=e.store.get();if(!(!!c.text||c.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:f,completedParams:m}=D(c.text,c.completedParams);e.onSubmit({query:c.text.trim(),raw_query:f,completed_params:m})}),a.focus(),{textarea:a,dropdown:i,sizer:s,submitButton:l,inlinePillContainer:d}}function be(o,e,t){let{textarea:i,dropdown:r,sizer:n,submitButton:s,inlinePillContainer:d}=o,{pillPlacement:a,setActivePill:l,selectOption:p,store:c}=t;i.value!==e.text&&(i.value=e.text),e.placeholderText?i.placeholder=e.placeholderText:i.removeAttribute("placeholder"),i.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";u?i.setAttribute("aria-activedescendant",u):i.removeAttribute("aria-activedescendant"),e.newParamId?i.classList.add("magicx-aia-textarea--hidden"):i.classList.remove("magicx-aia-textarea--hidden");let f=!!e.text||e.completedParams.length>0;s.disabled=!f,Be(n,e.segments,e.newParamId,!e.text,e.placeholderText),a==="inline"?oe(d,e.actionableSuggestions,0,l):d.innerHTML="",ne(r,{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:p,onHighlight:m=>c.set({activeDropdownIndex:m}),onPillClick:l})}function $e(o){let e=o,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,n={...e,...r},s=e;e=n;for(let d of t)d(n,s)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}var ve=!1;function Ke(){if(ve||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){ve=!0;return}ve=!0;let o=document.createElement("style");o.setAttribute("data-magicx-aia",""),o.textContent=pt,document.head.appendChild(o)}var pt="";var ct=0;function ut(){return`:ac-${++ct}:`}function Fe(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:""}}var re=class{constructor(e,t={}){this.store=$e(Fe());this._listboxId=ut();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new te(this.store),this.fetchController=new Z(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError),this.keyboardController=new ee(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,selectOption:i=>this.selectOption(i)}),this.unsubscribers.push(this.store.subscribe((i,r)=>{this.recomputeDerived(i,r)})),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.opts.onChange?.(i.text),i.completedParams!==r.completedParams&&this.opts.onParamsChange?.(i.completedParams),this.opts.onStateChange?.(i)})),this.renderMode!=="headless"&&(Ke(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...Fe()}),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}clearNewParamId(){this.store.set({newParamId:null})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),e.dropdownTrigger!==void 0&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get(),i=t.actionableSuggestions[0];if(!i)return;let r=t.filterBase,n=t.text.slice(0,r),s=n.length===0&&t.text.length===0,d=n.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(s||d)&&t.placeholderText&&(n=`${t.placeholderText} `);let a=ke(n,e.text);a>0&&(n=n.slice(0,n.length-a));let l=n.length>0&&n[n.length-1]!==" ",p=`${n}${l?" ":""}${e.text} `,c=(s||d)&&p.length>0?p[0].toUpperCase()+p.slice(1):p,u=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),f=u>=0?c.slice(u,u+e.text.length):e.text,m={id:crypto.randomUUID(),placeholder:"",type:i.type,text:f,kind:e.kind,suggestionType:i.type,suggestionPlaceholder:i.text,options:i.options??[],metadata:e.metadata},w=t.actionableSuggestions.length-1;this.store.set(x=>({text:c,filterBase:c.length,completedParams:[...x.completedParams,m],newParamId:m.id,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:w>0})),this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(x=>({suggestions:x.suggestions.filter(b=>b!==i)}))},400)}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let i=Te(e.text,e.completedParams),r=e.suggestions.filter(b=>b.type!=="placeholder"),n=r[0],s=n?this.opts.optionOverrides?.[n.type]:void 0,d=Math.min(e.filterBase,e.text.length),l=e.lastRawQuery!==""||d>0?V(e.text,d,e.filterInProgress):"",p=n?s?s(l.trim()):n.options??[]:[],c=J(p,l),u=e.suggestions.filter(b=>b.type==="placeholder").map(b=>b.text).join(" ")||this.opts.placeholder||"",f=u.length>0,m=this.opts.dropdownTrigger??"auto",w=!1;m==="auto"?w=!e.isLoading&&c.length>0&&(!!e.text||e.pillTapped||!f):m==="manual"&&(w=!e.isLoading&&c.length>0&&e.pillTapped),this.store.set({segments:i,actionableSuggestions:r,filteredOptions:c,placeholderText:u,isDropdownOpen:w}),this.derivedInProgress=!1;let x=this.store.get();for(let b of this.externalListeners)b(x)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new H(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i)};this.domRefs=Ne(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&be(this.domRefs,this.store.get(),t)}),be(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=He(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&xe(this.dropdownRefs,this.store.get(),e)}),xe(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=Oe(e,t.completedParams);r.length>0&&this.store.set(n=>({completedParams:i,suggestions:[...r.map(s=>({type:s.suggestionType,text:s.suggestionPlaceholder,required:!0,options:s.options})),...n.suggestions]}))}};function ye({onSubmit:o,onError:e,optionOverrides:t,maskCompletedText:i,placeholder:r,apiConfig:n,columns:s=2,dropdownTrigger:d,value:a,completedParams:l,onChange:p,onParamsChange:c}){let u=R(null),[f,m]=mt(null),w=R(o);w.current=o;let x=R(e);x.current=e;let b=R(p);b.current=p;let I=R(c);I.current=c,se(()=>{if(typeof document>"u")return;let v=new re(document.createElement("div"),{renderMode:"headless",apiConfig:n,optionOverrides:t,maskCompletedText:i,placeholder:r,columns:s,dropdownTrigger:d,value:a,completedParams:l,onSubmit:(...h)=>w.current?.(...h),onError:(...h)=>x.current?.(...h),onChange:(...h)=>b.current?.(...h),onParamsChange:(...h)=>I.current?.(...h)});u.current=v,m(v.getState());let _=v.subscribe(h=>m(h));return()=>{_(),v.destroy(),u.current===v&&(u.current=null)}},[]);let g=u.current,S=T(()=>{},[]);se(()=>{a!==void 0&&g?.setValue(a)},[a,g]),se(()=>{l!==void 0&&g?.setCompletedParams(l)},[l,g]);let U=JSON.stringify(n??null),C=R(t),M=R(0);if(t!==C.current){let v=C.current,_=t,h=Object.keys(v??{}),k=Object.keys(_??{});(h.length!==k.length||k.some(G=>!v?.[G]||_[G]!==v[G]))&&M.current++,C.current=t}se(()=>{g?.update({apiConfig:n,optionOverrides:t,dropdownTrigger:d})},[U,M.current,d,g]);let le=T(v=>{if(!g)return;let _=v.target.value,k=_.length>0&&!v.nativeEvent?.isComposing&&_[0]!==_[0].toUpperCase()?_[0].toUpperCase()+_.slice(1):_;g.handleTextChange(k)},[g]),de=T(v=>{g?.handleKeyDown(v.nativeEvent)},[g]),N=T(v=>g?.setActivePill(v),[g]),L=T(()=>g?.removeLastParam(),[g]),Q=T(()=>g?.clearNewParamId(),[g]),O=T(()=>g?.reset(),[g]),pe=T(v=>g?.selectOption(v),[g]),z=T(v=>g?.setActiveDropdownIndex(v),[g]);if(!g)return{completedParams:l??[],suggestionPills:[],setActivePill:S,removeLastParam:S,segments:[],newParamId:null,clearNewParamId:S,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,error:null,inputProps:{value:a??"",placeholder:r,onChange:S,onKeyDown:S,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:S,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:S,onHighlight:S,isOpen:!1,id:"",pills:[],onPillClick:S}};let y=f??g.getState(),$=a!==void 0?a:y.text,j=l!==void 0?l:y.completedParams,K=y.actionableSuggestions,F=K[0],ce=y.filteredOptions,ue=y.activeDropdownIndex>=0?`${g.listboxId}-option-${y.activeDropdownIndex}`:void 0;return{completedParams:j,suggestionPills:K,setActivePill:N,removeLastParam:L,segments:y.segments,newParamId:y.newParamId,clearNewParamId:Q,suggestions:y.suggestions,activeIndex:y.activeDropdownIndex,isReady:y.isReady,isLoading:y.isLoading,error:y.error,inputProps:{value:$,placeholder:y.placeholderText||void 0,onChange:le,onKeyDown:de,role:"combobox","aria-expanded":y.isDropdownOpen,"aria-activedescendant":ue,"aria-autocomplete":"list","aria-controls":g.listboxId},reset:O,dropdownProps:{suggestions:F?[{...F,options:ce}]:[],activeIndex:y.activeDropdownIndex,onSelect:pe,onHighlight:z,isOpen:y.isDropdownOpen,id:g.listboxId,pills:K,onPillClick:N}}}import{jsx as E,jsxs as B}from"react/jsx-runtime";function xt(o){return o!=="auto"?o:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var bt=gt(function({onSubmit:e,onError:t,optionOverrides:i,maskCompletedText:r,placeholder:n,className:s,apiConfig:d,columns:a,pillPlacement:l="inline",mode:p="auto",optionsPosition:c="below",animations:u=!0,dropdownTrigger:f,value:m,completedParams:w,onChange:x,onParamsChange:b},I){let g=ae(null),S=ae(null),U=ae(()=>{}),C=ae(null);we(()=>{S.current?.focus()},[]),we(()=>{let h=g.current;if(h)return C.current?C.current.setMode(p):C.current=new H(h,p),()=>{C.current?.destroy(),C.current=null}},[p]);let{completedParams:M,suggestionPills:le,setActivePill:de,segments:N,newParamId:L,clearNewParamId:Q,inputProps:O,dropdownProps:pe,reset:z}=ye({onSubmit:h=>U.current(h),onError:t,optionOverrides:i,maskCompletedText:r,placeholder:n,apiConfig:d,columns:a,dropdownTrigger:f,value:m,completedParams:w,onChange:x,onParamsChange:b});we(()=>{if(!L)return;let h=window.setTimeout(()=>Q(),650);return()=>window.clearTimeout(h)},[L,Q]),ft(I,()=>({focus:()=>S.current?.focus(),reset:z,setMode:h=>C.current?.setMode(h)}),[z]);let y=()=>{S.current?.focus()},$=!!O.value||M.length>0,j=ht(()=>{if(!$)return;let{rawQuery:h,completedParams:k}=D(O.value,M);e({query:O.value.trim(),raw_query:h,completed_params:k}),z()},[$,O.value,M,e,z]);U.current=j;let{onChange:K,placeholder:F,...ce}=O,ue=!O.value,v=l==="inline",_=l==="dropdown";return B("div",{ref:g,className:`magicx-aia ${P.container} ${s??""}`,"data-pill-placement":l,"data-options-position":c,"data-animations":u?"on":"off","data-mode":xt(p),children:[E(he,{...pe,showPills:_}),B("div",{className:P.inputWrapper,onClick:y,children:[B("div",{className:P.editorArea,children:[B("div",{className:P.sizerContent,"aria-hidden":"true",children:[ue&&F?B("span",{className:P.placeholderText,children:[F," "]}):B("span",{className:`${P.sizerText} ${L?P.sizerTextVisible:""}`,children:[N.map((h,k)=>{if(h.type==="completed"&&h.param.id===L){let Ve=`${P.shimmerRevealed} ${P.shimmerSweep}`;return E("span",{className:Ve,children:h.value},`${k}-${h.type}`)}return E("span",{children:h.value},`${k}-${h.type}`)}),N.length===0&&"\xA0"]})," ",v&&E(X,{pills:le,activePillIndex:0,onSelectPill:de})]}),E("textarea",{ref:S,className:`${P.textarea} ${L?P.textareaHidden:""}`,rows:1,onChange:K,...ce})]}),E("button",{type:"button",className:P.submitButton,disabled:!$,onClick:h=>{h.stopPropagation(),j()},"aria-label":"Submit",children:E("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:E("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});function vt(o){let e=o.replace(/^#/,""),t=e.length===3?e.split("").map(c=>c+c).join(""):e,i=Number.parseInt(t.slice(0,2),16)/255,r=Number.parseInt(t.slice(2,4),16)/255,n=Number.parseInt(t.slice(4,6),16)/255,s=Math.max(i,r,n),d=Math.min(i,r,n),a=(s+d)/2,l=0,p=0;if(s!==d){let c=s-d;p=a>.5?c/(2-s-d):c/(s+d),s===i?l=(r-n)/c+(r<n?6:0):s===r?l=(n-i)/c+2:l=(i-r)/c+4,l*=60}return{h:Math.round(l),s:Math.round(p*100),l:Math.round(a*100)}}var qe=o=>Math.max(0,Math.min(100,o));function yt(o){let{h:e,s:t,l:i}=vt(o),r=i<=50?1:-1,n=qe(i+r*20),s=qe(i+r*10),d=(a,l,p,c)=>`hsla(${a}, ${l}%, ${p}%, ${c})`;return`linear-gradient(${d(e,t,i,1)}, ${d(e,t,i,1)}) padding-box, linear-gradient(105deg, ${d(0,0,n,1)}, ${d(0,0,s,.8)} 5%, ${d(0,0,0,0)} 50%, ${d(0,0,s,.8)} 95%, ${d(0,0,n,1)} 100%) border-box`}export{bt as AIAutocomplete,he as AIAutocompleteDropdown,yt as buildGlassBackground,ye as useAIAutocomplete};
|
|
588
|
+
`,document.head.appendChild(o)}var A={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh"};import{jsx as ge,jsxs as Pe}from"react/jsx-runtime";function Ce({option:o,isHighlighted:e,onSelect:t,onHighlight:i,id:s}){let[n,a]=We(!1),d=Qe(void 0);Ue(()=>()=>clearTimeout(d.current),[]);let r=()=>{!o.is_tappable||n||(a(!0),t(o),clearTimeout(d.current),d.current=setTimeout(()=>a(!1),400))},l=[A.item,e?A.highlighted:"",o.is_tappable?A.tappable:A.nonTappable,n?A.pressed:""].filter(Boolean).join(" ");return Pe("div",{id:s,role:"option","aria-selected":e,className:l,tabIndex:o.is_tappable?0:-1,onClick:r,onKeyDown:p=>{o.is_tappable&&(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),r())},onMouseEnter:i,children:[ge("div",{className:A.streaks}),ge("div",{className:A.streaksVert}),Pe("span",{className:A.content,children:[o.icon?`${o.icon} ${o.text}`:o.text,o.tag&&ge("span",{className:A.tag,children:o.tag})]})]})}import{jsx as fe}from"react/jsx-runtime";function Ae({options:o,activeIndex:e,onSelect:t,onHighlight:i,listboxId:s}){let n=Xe(null),[a,d]=Je(!1);return je(()=>{let r=n.current;if(!r)return;let l=()=>{d(r.scrollHeight-r.scrollTop-r.clientHeight>1)};r.addEventListener("scroll",l,{passive:!0});let p=new ResizeObserver(l);return p.observe(r),()=>{r.removeEventListener("scroll",l),p.disconnect()}},[]),Ge(()=>{let r=n.current;r&&d(r.scrollHeight-r.scrollTop-r.clientHeight>1)},[o]),fe("div",{className:me.scrollWrapper,"data-fade":a?"":void 0,children:fe("div",{ref:n,className:me.grid,children:o.map((r,l)=>fe(Ce,{option:r,isHighlighted:l===e,onSelect:t,onHighlight:()=>i(l),id:`${s}-option-${l}`},r.text))})})}import{jsx as he,jsxs as Ye}from"react/jsx-runtime";function xe({suggestions:o,activeIndex:e,onSelect:t,onHighlight:i,isOpen:s,id:n,className:a,pills:d,onPillClick:r,showPills:l=!0}){let c=o[0]?.options??[],u=l&&d&&d.length>0&&r,m=s&&c.length>0||s&&u;return Ye("div",{id:n,role:"listbox","data-aia-dropdown":"",className:`${G.dropdown} ${m?G.visible:""} ${a??""}`,onMouseDown:w=>w.preventDefault(),children:[u&&he("div",{className:G.pillBar,"data-aia-pillbar":"",children:he(X,{pills:d,activePillIndex:0,onSelectPill:r,rounded:!0})}),c.length>0&&he(Ae,{options:c,activeIndex:e,onSelect:t,onHighlight:i,listboxId:n})]})}import{useCallback as T,useEffect as se,useRef as R,useState as ht}from"react";function V(o,e,t){let i=o.slice(e);if(t||e===0||o[e-1]===" ")return i;let s=i.indexOf(" ");return s===-1?"":i.slice(s+1)}function ke(o,e){let t=o.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),s=e.toLowerCase();for(let n=0;n<i.length;n++){let a=i.slice(n).join(" ");if(s.startsWith(a.toLowerCase())){let d=t.length-a.length;return o.length-d}}return 0}function J(o,e){if(!o)return[];let t=e.trimStart();if(!t)return o;let i=t.toLowerCase();return o.filter(s=>!s.is_tappable||s.text.toLowerCase().includes(i))}function be(o,e){if(!o)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return o.find(s=>s.is_tappable&&s.text.toLowerCase()===i)??null}var z=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 Te(o,e){let t=[],i=0;for(let n of e){let a=o.indexOf(n.text,i);a!==-1&&(a>i&&t.push({type:"text",value:o.slice(i,a)}),t.push({type:"completed",value:n.text,param:n}),i=a+n.text.length)}let s=o.slice(i);return s&&t.push({type:"text",value:s}),t}function Oe(o,e){let t=[],i=[],s=0;for(let n of e){let a=o.indexOf(n.text,s);a===-1?i.push(n):(t.push(n),s=a+n.text.length)}return{valid:t,invalid:i}}var Y=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 Ze="0.1.23",De=!1;function et(){return crypto.randomUUID()}function tt(o,e){return{placeholder:o.placeholder,type:o.type,...e&&{text:o.text},kind:o.kind}}function Re(o){return o?.type==="accessToken"}function ot(o){if(!(!o||Re(o)))return o}var Ee=new WeakMap;function it(o){let e=Ee.get(o.getAccessToken);return e||(e=new Y(o),Ee.set(o.getAccessToken,e)),e}function nt(o,e,t){let i=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof i=="number"?i:void 0;return{data:{raw_query:o,completed_params:e.map(n=>tt(n,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:et(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:Ze}}}function rt(o){return{"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers}}async function Le(o,e,t,i,s){return fetch(o,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:s})}async function Me(o,e,t){let i=t?.apiConfig,s=!t?.maskCompletedText,n=nt(o,e,s),a=rt(i),d=i?.endpoint??"/ac/suggest",r=JSON.stringify(n);if(Re(i)){let u=it(i),h=await u.getToken(),m=await Le(d,a,h,r,t?.signal);if(m.status===401){let w=await u.getToken(!0);m=await Le(d,a,w,r,t?.signal)}if(!m.ok)throw new Error(`API error: ${m.status} ${m.statusText}`);return m.json()}let l=ot(i),p=l?.apiKey??"";if(!p&&!De&&(De=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),p){let u=l?.authScheme??"Bearer";a.Authorization=u==="Basic"?`Basic ${btoa(p)}`:`Bearer ${p}`}let c=await fetch(d,{method:"POST",headers:a,body:r,signal:t?.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}function D(o,e){let t=o,i={},s=[];for(let n of e){let a=(i[n.type]??0)+1;i[n.type]=a;let r=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${a}}}`,l=t.indexOf(n.text);l!==-1&&(t=t.slice(0,l)+r+t.slice(l+n.text.length)),s.push({...n,placeholder:r})}return{rawQuery:t,completedParams:s}}function He(o,e){return e?o.map(t=>{let i=e[t.type];if(!i)return t;let s=i("");if(s.length===0)return t;let n=new Set(s.map(d=>d.text)),a=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...s,...a]}}):o}var st=100,at=300,lt=2,Z=class{constructor(e,t,i,s,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;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(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let s=++this.fetchVersion,n=this.store.get(),a=n.text.length;n.suggestions.some(r=>r.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let r=await Me(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(s!==this.fetchVersion)return;let l=He(r.data.suggestions??[],this.getOptionOverrides()),p=r.data.input??[],c=p[p.length-1],u=this.store.get().text,h,m;if(c?.state==="in_progress"){m=!0;let I=u.toLowerCase().lastIndexOf(c.text.toLowerCase());h=I!==-1?I:a}else m=!1,h=a;let x=l.filter(I=>I.type!=="placeholder")[0],b=null;if(x){let I=V(u,h,m),g=be(x.options,I);g&&(b={id:crypto.randomUUID(),placeholder:"",type:x.type,text:g.text,kind:g.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:g.metadata},l=l.filter(S=>S!==x))}this.store.set(I=>({suggestions:l,isLoading:!1,isReady:r.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:h,filterInProgress:m,...b?{completedParams:[...I.completedParams,b]}:{}}))}catch(r){if(s===this.fetchVersion){let l=r instanceof Error?r:new Error(String(r));this.store.set({error:l,isLoading:!1}),this.getOnError()?.(l)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{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(x=>x.type!=="placeholder")[0],l=(d?J(d.options,n):[]).filter(x=>x.is_tappable),p=d?be(d.options,n)!==null:!1,c=n.trim().length>0;if(l.length>0&&!p&&c)return!1;if(s.completedParams.length===0&&s.text.length>0){let x=s.suggestions.filter(b=>b.type==="placeholder").map(b=>b.text).join(" ");if(x.length>0&&x.toLowerCase().startsWith(s.text.toLowerCase()))return!1}let{rawQuery:u,completedParams:h}=D(s.text,s.completedParams),m=u.length<s.lastRawQuery.length,w=Math.abs(u.length-s.lastRawQuery.length);return m||w>=i?(this.doFetch(u,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(lt)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},st),this.slowDebounceTimer=setTimeout(()=>t(1),at)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ee=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{columns:i,listboxId:s,getOnSubmit:n}=this.ctx,a=n(),d=this.getTappableIndices();switch(e.key){case"ArrowDown":{let r=e.target;if(!(r.selectionStart!=null&&r.selectionStart===r.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 p=d.indexOf(t.activeDropdownIndex),c=p<d.length-1?p+1:0;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<i){this.store.set({activeDropdownIndex:-1});break}let r=d.indexOf(t.activeDropdownIndex),l=r>0?r-1:d.length-1;this.store.set({activeDropdownIndex:d[l]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let l=e.target;l.selectionStart!=null&&l.selectionStart===l.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%i<i-1){let l=t.activeDropdownIndex+1;l<t.filteredOptions.length&&t.filteredOptions[l]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:l}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%i>0){let r=t.activeDropdownIndex-1;r>=0&&t.filteredOptions[r]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:r}))}break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,s);else if(a){let{rawQuery:r,completedParams:l}=D(t.text,t.completedParams);a({query:t.text.trim(),raw_query:r,completed_params:l})}break}case"Tab":{if(t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,s);else if(t.isDropdownOpen){let r=t.filteredOptions.findIndex(l=>l.is_tappable);r>=0&&(e.preventDefault(),this.clickOrSelect(r,t.filteredOptions,s))}else if(!t.text&&t.placeholderText){e.preventDefault();let r=t.suggestions.find(l=>l.type==="placeholder");r?this.store.set(l=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...l.completedParams,{id:crypto.randomUUID(),placeholder:"",type:r.type,text:t.placeholderText,kind:null,suggestionType:r.type,suggestionPlaceholder:r.text,options:r.options??[]}],suggestions:l.suggestions.filter(p=>p!==r)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(){let e=this.store.get(),{columns:t}=this.ctx,i=e.filteredOptions.map((n,a)=>n.is_tappable?a:-1).filter(n=>n!==-1),s=Array.from({length:t},()=>[]);for(let n of i)s[n%t].push(n);return s.flat()}clickOrSelect(e,t,i){let s=document.getElementById(`${i}-option-${e}`);s?s.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let s=i[e],n=i.filter((d,r)=>r!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,s,...n],pillTapped:!0,activeDropdownIndex:-1})}};var te=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let s=i[e],n=i.filter((d,r)=>r!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,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],i={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(s=>({completedParams:s.completedParams.slice(0,-1),suggestions:[i,...s.suggestions],activeDropdownIndex:-1}))}};function dt(o){return o===0?.4:o===1?.3:.15}function oe(o,e,t,i,s=!1){let n=o.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",o.appendChild(n));let a=new Map;for(let r of n.querySelectorAll(".magicx-aia-pill"))a.set(r.dataset.pillKey??"",r);let d=new Set;for(let r=0;r<e.length;r++){let l=e[r],p=`${l.type}-${l.text}`;d.add(p);let c=a.get(p);c||(c=document.createElement("button"),c.type="button",c.dataset.pillKey=p,c.textContent=l.text),c.className=`magicx-aia-pill${s?" magicx-aia-pill--rounded":""}${r===t?" magicx-aia-pill--active":""}`,c.style.opacity=String(dt(r)),c.onclick=()=>i(r),n.children[r]!==c&&n.insertBefore(c,n.children[r]??null)}for(let[r,l]of a)d.has(r)||l.remove()}function ie(o){let e=document.createElement("div");return e.id=o,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function ne(o,e){let{filteredOptions:t,activeIndex:i,isOpen:s,pills:n,showPills:a,onSelect:d,onHighlight:r,onPillClick:l}=e,p=a&&n.length>0;s&&t.length>0||s&&p?o.classList.add("magicx-aia-dropdown--visible"):o.classList.remove("magicx-aia-dropdown--visible");let h=o.querySelector(".magicx-aia-pill-bar");p?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",o.insertBefore(h,o.firstChild)),oe(h,n,0,l,!0)):h&&h.remove();let m=o.querySelector(".magicx-aia-grid");t.length>0?(m||(m=document.createElement("div"),m.className="magicx-aia-grid",o.appendChild(m)),pt(m,t,i,d,r,e.listboxId)):m&&(m.innerHTML="")}function pt(o,e,t,i,s,n){let a=e.map(l=>l.text).join("\0"),d=o.dataset.optionsKey??"",r=a!==d;if(o.dataset.optionsKey=a,r){let l=document.createDocumentFragment();for(let p=0;p<e.length;p++){let c=e[p],u=ct(c,p,t,i,s,n);l.appendChild(u)}o.innerHTML="",o.appendChild(l)}else{let l=o.querySelectorAll(".magicx-aia-option");for(let p=0;p<l.length;p++){let c=l[p],u=p===t;c.setAttribute("aria-selected",String(u)),u?c.classList.add("magicx-aia-option--highlighted"):c.classList.remove("magicx-aia-option--highlighted")}}}function ct(o,e,t,i,s,n){let a=document.createElement("div");a.id=`${n}-option-${e}`,a.setAttribute("role","option"),a.setAttribute("aria-selected",String(e===t)),a.tabIndex=o.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),o.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),a.className=d.join(" ");let r=document.createElement("div");r.className="magicx-aia-streaks",a.appendChild(r);let l=document.createElement("div");l.className="magicx-aia-streaks-vert",a.appendChild(l);let p=document.createElement("span");if(p.className="magicx-aia-option-content",p.textContent=o.icon?`${o.icon} ${o.text}`:o.text,o.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=o.tag,p.appendChild(c)}return a.appendChild(p),o.is_tappable&&a.addEventListener("click",()=>{a.classList.add("magicx-aia-option--pressed"),i(o),setTimeout(()=>a.classList.remove("magicx-aia-option--pressed"),400)}),a.addEventListener("mouseenter",()=>s(e)),a}function ze(o,e){let t=ie(e.listboxId);return o.appendChild(t),{dropdown:t}}function ve(o,e,t){ne(o.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:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function Be(o,e,t,i,s){let n=o.querySelector(".magicx-aia-sizer-text"),a=o.querySelector(".magicx-aia-placeholder");if(i&&s){n&&(n.style.display="none"),a||(a=document.createElement("span"),a.className="magicx-aia-placeholder",o.insertBefore(a,o.firstChild)),a.style.display="",a.textContent=`${s} `,o.dataset.segmentKey="";return}a&&(a.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",o.insertBefore(n,o.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(p=>`${p.type}:${p.value}`).join("\0"),r=o.dataset.segmentKey??"",l=o.dataset.newParamId??"";if(!(d===r&&(t??"")===l)){o.dataset.segmentKey=d,o.dataset.newParamId=t??"",n.innerHTML="";for(let p of e){let c=document.createElement("span");p.type==="completed"&&(p.param.id===t?c.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":c.className="magicx-aia-segment magicx-aia-segment--completed"),c.textContent=p.value,n.appendChild(c)}e.length===0&&(n.textContent="\xA0")}}var ut='<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 Ne(o,e){let{listboxId:t}=e,i=ie(t);o.appendChild(i);let s=document.createElement("div");s.className="magicx-aia-input-wrapper",o.appendChild(s);let n=document.createElement("div");n.className="magicx-aia-editor",s.appendChild(n);let a=document.createElement("div");a.className="magicx-aia-sizer",a.setAttribute("aria-hidden","true"),n.appendChild(a);let d=document.createElement("span");a.appendChild(document.createTextNode(" ")),a.appendChild(d);let r=document.createElement("textarea");r.className="magicx-aia-textarea",r.rows=1,r.setAttribute("role","combobox"),r.setAttribute("aria-autocomplete","list"),r.setAttribute("aria-controls",t),n.appendChild(r);let l=document.createElement("button");return l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.innerHTML=ut,s.appendChild(l),s.addEventListener("click",()=>r.focus()),r.addEventListener("input",()=>{let p=r.value,u=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(u)}),r.addEventListener("keydown",p=>e.handleKeyDown(p)),l.addEventListener("click",p=>{p.stopPropagation();let c=e.store.get();if(!(!!c.text||c.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:h,completedParams:m}=D(c.text,c.completedParams);e.onSubmit({query:c.text.trim(),raw_query:h,completed_params:m})}),r.focus(),{textarea:r,dropdown:i,sizer:a,submitButton:l,inlinePillContainer:d}}function ye(o,e,t){let{textarea:i,dropdown:s,sizer:n,submitButton:a,inlinePillContainer:d}=o,{pillPlacement:r,setActivePill:l,selectOption:p,store:c}=t;i.value!==e.text&&(i.value=e.text),e.placeholderText?i.placeholder=e.placeholderText:i.removeAttribute("placeholder"),i.setAttribute("aria-expanded",String(e.isDropdownOpen));let u=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";u?i.setAttribute("aria-activedescendant",u):i.removeAttribute("aria-activedescendant"),e.newParamId?i.classList.add("magicx-aia-textarea--hidden"):i.classList.remove("magicx-aia-textarea--hidden");let h=!!e.text||e.completedParams.length>0;a.disabled=!h,Be(n,e.segments,e.newParamId,!e.text,e.placeholderText),r==="inline"?oe(d,e.actionableSuggestions,0,l):d.innerHTML="",ne(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:r==="dropdown",onSelect:p,onHighlight:m=>c.set({activeDropdownIndex:m}),onPillClick:l})}function Ke(o){let e=o,t=new Set;return{get:()=>e,set:i=>{let s=typeof i=="function"?i(e):i,n={...e,...s},a=e;e=n;for(let d of t)d(n,a)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}var we=!1;function $e(){if(we||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){we=!0;return}we=!0;let o=document.createElement("style");o.setAttribute("data-magicx-aia",""),o.textContent=mt,document.head.appendChild(o)}var mt="";var gt=0;function ft(){return`:ac-${++gt}:`}function Fe(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:""}}var re=class{constructor(e,t={}){this.store=Ke(Fe());this._listboxId=ft();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new te(this.store),this.fetchController=new Z(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError),this.keyboardController=new ee(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,selectOption:i=>this.selectOption(i)}),this.unsubscribers.push(this.store.subscribe((i,s)=>{this.recomputeDerived(i,s)})),this.unsubscribers.push(this.store.subscribe((i,s)=>{i.text!==s.text&&this.opts.onChange?.(i.text),i.completedParams!==s.completedParams&&this.opts.onParamsChange?.(i.completedParams),this.opts.onStateChange?.(i)})),this.renderMode!=="headless"&&($e(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...Fe()}),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}clearNewParamId(){this.store.set({newParamId:null})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),e.dropdownTrigger!==void 0&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get(),i=t.actionableSuggestions[0];if(!i)return;let s=t.filterBase,n=t.text.slice(0,s),a=n.length===0&&t.text.length===0,d=n.length===0&&t.text.length>0&&t.placeholderText.length>0&&t.placeholderText.toLowerCase().startsWith(t.text.toLowerCase());(a||d)&&t.placeholderText&&(n=`${t.placeholderText} `);let r=ke(n,e.text);r>0&&(n=n.slice(0,n.length-r));let l=n.length>0&&n[n.length-1]!==" ",p=`${n}${l?" ":""}${e.text} `,c=(a||d)&&p.length>0?p[0].toUpperCase()+p.slice(1):p,u=c.toLowerCase().lastIndexOf(e.text.toLowerCase()),h=u>=0?c.slice(u,u+e.text.length):e.text,m={id:crypto.randomUUID(),placeholder:"",type:i.type,text:h,kind:e.kind,suggestionType:i.type,suggestionPlaceholder:i.text,options:i.options??[],metadata:e.metadata},w=t.actionableSuggestions.length-1;this.store.set(x=>({text:c,filterBase:c.length,completedParams:[...x.completedParams,m],newParamId:m.id,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:w>0})),this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(x=>({suggestions:x.suggestions.filter(b=>b!==i)}))},400)}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let i=Te(e.text,e.completedParams),s=e.suggestions.filter(b=>b.type!=="placeholder"),n=s[0],a=n?this.opts.optionOverrides?.[n.type]:void 0,d=Math.min(e.filterBase,e.text.length),l=e.lastRawQuery!==""||d>0?V(e.text,d,e.filterInProgress):"",p=n?a?a(l.trim()):n.options??[]:[],c=J(p,l),u=e.suggestions.filter(b=>b.type==="placeholder").map(b=>b.text).join(" ")||this.opts.placeholder||"",h=u.length>0,m=this.opts.dropdownTrigger??"auto",w=!1;m==="auto"?w=!e.isLoading&&c.length>0&&(!!e.text||e.pillTapped||!h):m==="manual"&&(w=!e.isLoading&&c.length>0&&e.pillTapped),this.store.set({segments:i,actionableSuggestions:s,filteredOptions:c,placeholderText:u,isDropdownOpen:w}),this.derivedInProgress=!1;let x=this.store.get();for(let b of this.externalListeners)b(x)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new z(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i)};this.domRefs=Ne(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&ye(this.domRefs,this.store.get(),t)}),ye(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=ze(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&ve(this.dropdownRefs,this.store.get(),e)}),ve(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:s}=Oe(e,t.completedParams);s.length>0&&this.store.set(n=>({completedParams:i,suggestions:[...s.map(a=>({type:a.suggestionType,text:a.suggestionPlaceholder,required:!0,options:a.options})),...n.suggestions]}))}};function Se({onSubmit:o,onError:e,optionOverrides:t,maskCompletedText:i,placeholder:s,apiConfig:n,columns:a=2,dropdownTrigger:d,value:r,completedParams:l,onChange:p,onParamsChange:c}){let u=R(null),[h,m]=ht(null),w=R(o);w.current=o;let x=R(e);x.current=e;let b=R(p);b.current=p;let I=R(c);I.current=c,se(()=>{if(typeof document>"u")return;let v=new re(document.createElement("div"),{renderMode:"headless",apiConfig:n,optionOverrides:t,maskCompletedText:i,placeholder:s,columns:a,dropdownTrigger:d,value:r,completedParams:l,onSubmit:(...f)=>w.current?.(...f),onError:(...f)=>x.current?.(...f),onChange:(...f)=>b.current?.(...f),onParamsChange:(...f)=>I.current?.(...f)});u.current=v,m(v.getState());let _=v.subscribe(f=>m(f));return()=>{_(),v.destroy(),u.current===v&&(u.current=null)}},[]);let g=u.current,S=T(()=>{},[]);se(()=>{r!==void 0&&g?.setValue(r)},[r,g]),se(()=>{l!==void 0&&g?.setCompletedParams(l)},[l,g]);let U=JSON.stringify(n??null),C=R(t),M=R(0);if(t!==C.current){let v=C.current,_=t,f=Object.keys(v??{}),k=Object.keys(_??{});(f.length!==k.length||k.some(j=>!v?.[j]||_[j]!==v[j]))&&M.current++,C.current=t}se(()=>{g?.update({apiConfig:n,optionOverrides:t,dropdownTrigger:d})},[U,M.current,d,g]);let le=T(v=>{if(!g)return;let _=v.target.value,k=_.length>0&&!v.nativeEvent?.isComposing&&_[0]!==_[0].toUpperCase()?_[0].toUpperCase()+_.slice(1):_;g.handleTextChange(k)},[g]),de=T(v=>{g?.handleKeyDown(v.nativeEvent)},[g]),N=T(v=>g?.setActivePill(v),[g]),L=T(()=>g?.removeLastParam(),[g]),Q=T(()=>g?.clearNewParamId(),[g]),O=T(()=>g?.reset(),[g]),pe=T(v=>g?.selectOption(v),[g]),H=T(v=>g?.setActiveDropdownIndex(v),[g]);if(!g)return{completedParams:l??[],suggestionPills:[],setActivePill:S,removeLastParam:S,segments:[],newParamId:null,clearNewParamId:S,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,error:null,inputProps:{value:r??"",placeholder:s,onChange:S,onKeyDown:S,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:S,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:S,onHighlight:S,isOpen:!1,id:"",pills:[],onPillClick:S}};let y=h??g.getState(),K=r!==void 0?r:y.text,W=l!==void 0?l:y.completedParams,$=y.actionableSuggestions,F=$[0],ce=y.filteredOptions,ue=y.activeDropdownIndex>=0?`${g.listboxId}-option-${y.activeDropdownIndex}`:void 0;return{completedParams:W,suggestionPills:$,setActivePill:N,removeLastParam:L,segments:y.segments,newParamId:y.newParamId,clearNewParamId:Q,suggestions:y.suggestions,activeIndex:y.activeDropdownIndex,isReady:y.isReady,isLoading:y.isLoading,error:y.error,inputProps:{value:K,placeholder:y.placeholderText||void 0,onChange:le,onKeyDown:de,role:"combobox","aria-expanded":y.isDropdownOpen,"aria-activedescendant":ue,"aria-autocomplete":"list","aria-controls":g.listboxId},reset:O,dropdownProps:{suggestions:F?[{...F,options:ce}]:[],activeIndex:y.activeDropdownIndex,onSelect:pe,onHighlight:H,isOpen:y.isDropdownOpen,id:g.listboxId,pills:$,onPillClick:N}}}import{jsx as E,jsxs as B}from"react/jsx-runtime";function yt(o){return o!=="auto"?o:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var wt=xt(function({onSubmit:e,onError:t,optionOverrides:i,maskCompletedText:s,placeholder:n,className:a,apiConfig:d,columns:r,pillPlacement:l="inline",mode:p="auto",optionsPosition:c="below",animations:u=!0,dropdownTrigger:h,value:m,completedParams:w,onChange:x,onParamsChange:b},I){let g=ae(null),S=ae(null),U=ae(()=>{}),C=ae(null);Ie(()=>{S.current?.focus()},[]),Ie(()=>{let f=g.current;if(f)return C.current?C.current.setMode(p):C.current=new z(f,p),()=>{C.current?.destroy(),C.current=null}},[p]);let{completedParams:M,suggestionPills:le,setActivePill:de,segments:N,newParamId:L,clearNewParamId:Q,inputProps:O,dropdownProps:pe,reset:H}=Se({onSubmit:f=>U.current(f),onError:t,optionOverrides:i,maskCompletedText:s,placeholder:n,apiConfig:d,columns:r,dropdownTrigger:h,value:m,completedParams:w,onChange:x,onParamsChange:b});Ie(()=>{if(!L)return;let f=window.setTimeout(()=>Q(),650);return()=>window.clearTimeout(f)},[L,Q]),vt(I,()=>({focus:()=>S.current?.focus(),reset:H,setMode:f=>C.current?.setMode(f)}),[H]);let y=()=>{S.current?.focus()},K=!!O.value||M.length>0,W=bt(()=>{if(!K)return;let{rawQuery:f,completedParams:k}=D(O.value,M);e({query:O.value.trim(),raw_query:f,completed_params:k}),H()},[K,O.value,M,e,H]);U.current=W;let{onChange:$,placeholder:F,...ce}=O,ue=!O.value,v=l==="inline",_=l==="dropdown";return B("div",{ref:g,className:`magicx-aia ${P.container} ${a??""}`,"data-pill-placement":l,"data-options-position":c,"data-animations":u?"on":"off","data-mode":yt(p),children:[E(xe,{...pe,showPills:_}),B("div",{className:P.inputWrapper,onClick:y,children:[B("div",{className:P.editorArea,children:[B("div",{className:P.sizerContent,"aria-hidden":"true",children:[ue&&F?B("span",{className:P.placeholderText,children:[F," "]}):B("span",{className:`${P.sizerText} ${L?P.sizerTextVisible:""}`,children:[N.map((f,k)=>{if(f.type==="completed"&&f.param.id===L){let qe=`${P.shimmerRevealed} ${P.shimmerSweep}`;return E("span",{className:qe,children:f.value},`${k}-${f.type}`)}return E("span",{children:f.value},`${k}-${f.type}`)}),N.length===0&&"\xA0"]})," ",v&&E(X,{pills:le,activePillIndex:0,onSelectPill:de})]}),E("textarea",{ref:S,className:`${P.textarea} ${L?P.textareaHidden:""}`,rows:1,onChange:$,...ce})]}),E("button",{type:"button",className:P.submitButton,disabled:!K,onClick:f=>{f.stopPropagation(),W()},"aria-label":"Submit",children:E("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:E("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});export{wt as AIAutocomplete,xe as AIAutocompleteDropdown,Se as useAIAutocomplete};
|
|
567
589
|
//# sourceMappingURL=index.mjs.map
|