@magicx-eng/ai-autocomplete-react 0.1.44 → 0.2.0

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/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as gt,useLayoutEffect as ft,useRef as le}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-67791514")){let e=document.createElement("style");e.id="ac-style-67791514",e.textContent=`.AIAutocomplete-module_container_KKjFU {
1
+ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as gt,useLayoutEffect as ft,useRef as le}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-67791514")){let e=document.createElement("style");e.id="ac-style-67791514",e.textContent=`.AIAutocomplete-module_container_KKjFU {
2
2
  position: relative;
3
3
  /* Inherits the host page's font by default. Consumers can pin a specific
4
4
  font on the library via \`--aia-font-family: 'Custom Font'\` without
@@ -248,7 +248,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as
248
248
  opacity: 0.25;
249
249
  }
250
250
  }
251
- `,document.head.appendChild(e)}var Z={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj",pillBar:"AIAutocompleteDropdown-module_pillBar_pwTXe",skeletonBars:"AIAutocompleteDropdown-module_skeletonBars_HVr9C",skeletonBar:"AIAutocompleteDropdown-module_skeletonBar_O3xIx",aiaSkeletonPulse:"AIAutocompleteDropdown-module_aiaSkeletonPulse_G8W7q"};if(typeof document<"u"&&!document.getElementById("ac-style-0fcb7940")){let e=document.createElement("style");e.id="ac-style-0fcb7940",e.textContent=`.PillList-module_list_qvLqO {
251
+ `,document.head.appendChild(e)}var te={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj",pillBar:"AIAutocompleteDropdown-module_pillBar_pwTXe",skeletonBars:"AIAutocompleteDropdown-module_skeletonBars_HVr9C",skeletonBar:"AIAutocompleteDropdown-module_skeletonBar_O3xIx",aiaSkeletonPulse:"AIAutocompleteDropdown-module_aiaSkeletonPulse_G8W7q"};if(typeof document<"u"&&!document.getElementById("ac-style-0fcb7940")){let e=document.createElement("style");e.id="ac-style-0fcb7940",e.textContent=`.PillList-module_list_qvLqO {
252
252
  position: relative;
253
253
  z-index: 1;
254
254
  pointer-events: auto;
@@ -331,7 +331,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as
331
331
  opacity: 0;
332
332
  }
333
333
  }
334
- `,document.head.appendChild(e)}var M={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",skeleton:"PillList-module_skeleton_Lp8x6",skeletonPulse:"PillList-module_skeletonPulse_xZ8Yf",active:"PillList-module_active_Oll--"};import{jsx as ge}from"react/jsx-runtime";var Je=[125,69];function Te(e){return e===0?.4:e===1?.3:.15}function se({pills:e,activePillIndex:y,onSelectPill:b,rounded:v,loading:p}){return p&&e.length===0?ge("span",{className:M.list,"data-aia-pill-list-loading":"",children:Je.map((l,u)=>ge("span",{"data-aia-pill-skeleton":"",className:`${M.pill} ${v?M.rounded:""} ${M.skeleton}`,style:{width:l,opacity:Te(u)}},`skel-${l}`))}):ge("span",{className:M.list,"data-aia-pill-list-loading":p?"":void 0,children:e.map((l,u)=>ge("button",{type:"button","data-aia-pill":"","data-aia-loading":p?"":void 0,tabIndex:-1,contentEditable:!1,suppressContentEditableWarning:!0,className:`${M.pill} ${v?M.rounded:""} ${u===y&&!p?M.active:""} ${p?M.skeleton:""}`,style:{opacity:Te(u)},onMouseDown:c=>c.preventDefault(),onClick:p?void 0:()=>b(u),disabled:p,children:l.text},`${l.type}-${l.text}`))})}import{useEffect as tt,useLayoutEffect as ot,useRef as at,useState as nt}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-ff33a0ab")){let e=document.createElement("style");e.id="ac-style-ff33a0ab",e.textContent=`.SuggestionGrid-module_scrollWrapper_MOqfw {
334
+ `,document.head.appendChild(e)}var B={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",skeleton:"PillList-module_skeleton_Lp8x6",skeletonPulse:"PillList-module_skeletonPulse_xZ8Yf",active:"PillList-module_active_Oll--"};import{jsx as fe}from"react/jsx-runtime";var Je=[125,69];function ze(e){return e===0?.4:e===1?.3:.15}function se({pills:e,activePillIndex:_,onSelectPill:f,rounded:v,loading:c}){return c&&e.length===0?fe("span",{className:B.list,"data-aia-pill-list-loading":"",children:Je.map((d,m)=>fe("span",{"data-aia-pill-skeleton":"",className:`${B.pill} ${v?B.rounded:""} ${B.skeleton}`,style:{width:d,opacity:ze(m)}},`skel-${d}`))}):fe("span",{className:B.list,"data-aia-pill-list-loading":c?"":void 0,children:e.map((d,m)=>fe("button",{type:"button","data-aia-pill":"","data-aia-loading":c?"":void 0,tabIndex:-1,contentEditable:!1,suppressContentEditableWarning:!0,className:`${B.pill} ${v?B.rounded:""} ${m===_&&!c?B.active:""} ${c?B.skeleton:""}`,style:{opacity:ze(m)},onMouseDown:g=>g.preventDefault(),onClick:c?void 0:()=>f(m),disabled:c,children:d.text},`${d.type}-${d.text}`))})}import{useEffect as tt,useLayoutEffect as ot,useRef as at,useState as nt}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-ff33a0ab")){let e=document.createElement("style");e.id="ac-style-ff33a0ab",e.textContent=`.SuggestionGrid-module_scrollWrapper_MOqfw {
335
335
  position: relative;
336
336
  }
337
337
 
@@ -386,7 +386,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as
386
386
  background: var(--aia-scrollbar-thumb, rgba(0, 0, 0, 0.3));
387
387
  border-radius: 3px;
388
388
  }
389
- `,document.head.appendChild(e)}var _e={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};import{useEffect as Ye,useRef as Ze,useState as et}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-82820da7")){let e=document.createElement("style");e.id="ac-style-82820da7",e.textContent=`.SuggestionItem-module_item_d4vpD {
389
+ `,document.head.appendChild(e)}var ye={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};import{useEffect as Ye,useRef as Ze,useState as et}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-82820da7")){let e=document.createElement("style");e.id="ac-style-82820da7",e.textContent=`.SuggestionItem-module_item_d4vpD {
390
390
  position: relative;
391
391
  overflow: visible;
392
392
  display: flex;
@@ -733,7 +733,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as
733
733
  filter: brightness(0.55);
734
734
  }
735
735
  }
736
- `,document.head.appendChild(e)}var D={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",skeletonPulse:"SuggestionItem-module_skeletonPulse_plvdD",text:"SuggestionItem-module_text_yqoh9"};import{jsx as fe,jsxs as ze}from"react/jsx-runtime";function Me({option:e,isHighlighted:y,onSelect:b,onHighlight:v,id:p,loading:l}){let[u,c]=et(!1),x=Ze(void 0);Ye(()=>()=>clearTimeout(x.current),[]);let n=()=>{l||!e.is_tappable||u||(c(!0),b(e),clearTimeout(x.current),x.current=setTimeout(()=>c(!1),500))},m=[D.item,y&&!l?D.highlighted:"",e.is_tappable?D.tappable:D.nonTappable,u?D.pressed:""].filter(Boolean).join(" ");return ze("div",{id:p,role:"option","data-aia-option":"","data-aia-loading":l?"":void 0,"aria-selected":y,className:m,tabIndex:l||!e.is_tappable?-1:0,onClick:n,onKeyDown:w=>{!l&&e.is_tappable&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),n())},onMouseEnter:!l&&e.is_tappable?v:void 0,children:[fe("div",{className:D.streaks}),fe("div",{className:D.streaksVert}),ze("span",{className:D.content,children:[fe("span",{className:D.text,children:e.icon?`${e.icon} ${e.text}`:e.text}),e.tag&&fe("span",{className:D.tag,children:e.tag})]})]})}import{jsx as ye}from"react/jsx-runtime";function Oe({options:e,activeIndex:y,onSelect:b,onHighlight:v,listboxId:p,loading:l}){let u=at(null),[c,x]=nt(!1);return tt(()=>{let n=u.current;if(!n)return;let m=()=>{x(n.scrollHeight-n.scrollTop-n.clientHeight>1)};n.addEventListener("scroll",m,{passive:!0});let w=new ResizeObserver(m);return w.observe(n),()=>{n.removeEventListener("scroll",m),w.disconnect()}},[]),ot(()=>{let n=u.current;n&&x(n.scrollHeight-n.scrollTop-n.clientHeight>1)},[e]),ye("div",{className:_e.scrollWrapper,"data-fade":c?"":void 0,children:ye("div",{ref:u,className:_e.grid,children:e.map((n,m)=>ye(Me,{option:n,isHighlighted:m===y,onSelect:b,onHighlight:()=>v(m),id:`${p}-option-${m}`,loading:l},n.text))})})}import{jsx as ee,jsxs as it}from"react/jsx-runtime";var rt=[159,119,164];function Ie({suggestions:e,activeIndex:y,onSelect:b,onHighlight:v,isOpen:p,id:l,className:u,pills:c,onPillClick:x,showPills:n=!0,isLoading:m=!1}){let S=e[0]?.options??[],O=n&&c&&c.length>0&&x,E=S.length>0,N=m&&!E,B=p&&(E||O||m);return it("div",{id:l,role:"listbox","data-aia-dropdown":"","data-aia-loading":m?"":void 0,className:`${Z.dropdown} ${B?Z.visible:""} ${u??""}`,onMouseDown:a=>a.preventDefault(),children:[n&&c&&c.length>0&&x&&ee("div",{className:Z.pillBar,"data-aia-pillbar":"",children:ee(se,{pills:c,activePillIndex:0,onSelectPill:x,rounded:!0,loading:m})}),n&&(!c||c.length===0)&&m&&ee("div",{className:Z.pillBar,"data-aia-pillbar":"",children:ee(se,{pills:[],activePillIndex:0,onSelectPill:()=>{},rounded:!0,loading:!0})}),E&&ee(Oe,{options:S,activeIndex:y,onSelect:b,onHighlight:v,listboxId:l,loading:m}),N&&ee("div",{className:Z.skeletonBars,"data-aia-skeleton-bars":"",children:rt.map(a=>ee("span",{className:Z.skeletonBar,style:{width:a}},`bar-${a}`))})]})}if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
736
+ `,document.head.appendChild(e)}var z={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",skeletonPulse:"SuggestionItem-module_skeletonPulse_plvdD",text:"SuggestionItem-module_text_yqoh9"};import{jsx as be,jsxs as Me}from"react/jsx-runtime";function Oe({option:e,isHighlighted:_,onSelect:f,onHighlight:v,id:c,loading:d}){let[m,g]=et(!1),h=Ze(void 0);Ye(()=>()=>clearTimeout(h.current),[]);let n=()=>{d||!e.is_tappable||m||(g(!0),f(e),clearTimeout(h.current),h.current=setTimeout(()=>g(!1),500))},p=[z.item,_&&!d?z.highlighted:"",e.is_tappable?z.tappable:z.nonTappable,m?z.pressed:""].filter(Boolean).join(" ");return Me("div",{id:c,role:"option","data-aia-option":"","data-aia-loading":d?"":void 0,"aria-selected":_,className:p,tabIndex:d||!e.is_tappable?-1:0,onClick:n,onKeyDown:I=>{!d&&e.is_tappable&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),n())},onMouseEnter:!d&&e.is_tappable?v:void 0,children:[be("div",{className:z.streaks}),be("div",{className:z.streaksVert}),Me("span",{className:z.content,children:[be("span",{className:z.text,children:e.icon?`${e.icon} ${e.text}`:e.text}),e.tag&&be("span",{className:z.tag,children:e.tag})]})]})}import{jsx as Ie}from"react/jsx-runtime";function Be({options:e,activeIndex:_,onSelect:f,onHighlight:v,listboxId:c,loading:d}){let m=at(null),[g,h]=nt(!1);return tt(()=>{let n=m.current;if(!n)return;let p=()=>{h(n.scrollHeight-n.scrollTop-n.clientHeight>1)};n.addEventListener("scroll",p,{passive:!0});let I=new ResizeObserver(p);return I.observe(n),()=>{n.removeEventListener("scroll",p),I.disconnect()}},[]),ot(()=>{let n=m.current;n&&h(n.scrollHeight-n.scrollTop-n.clientHeight>1)},[e]),Ie("div",{className:ye.scrollWrapper,"data-fade":g?"":void 0,children:Ie("div",{ref:m,className:ye.grid,children:e.map((n,p)=>Ie(Oe,{option:n,isHighlighted:p===_,onSelect:f,onHighlight:()=>v(p),id:`${c}-option-${p}`,loading:d},n.text))})})}import{jsx as oe,jsxs as it}from"react/jsx-runtime";var rt=[159,119,164];function ke({suggestions:e,activeIndex:_,onSelect:f,onHighlight:v,isOpen:c,id:d,className:m,pills:g,onPillClick:h,showPills:n=!0,isLoading:p=!1}){let A=e[0]?.options??[],S=n&&g&&g.length>0&&h,D=A.length>0,H=p&&!D,N=c&&(D||S||p);return it("div",{id:d,role:"listbox","data-aia-dropdown":"","data-aia-loading":p?"":void 0,className:`${te.dropdown} ${N?te.visible:""} ${m??""}`,onMouseDown:P=>P.preventDefault(),children:[n&&g&&g.length>0&&h&&oe("div",{className:te.pillBar,"data-aia-pillbar":"",children:oe(se,{pills:g,activePillIndex:0,onSelectPill:h,rounded:!0,loading:p})}),n&&(!g||g.length===0)&&p&&oe("div",{className:te.pillBar,"data-aia-pillbar":"",children:oe(se,{pills:[],activePillIndex:0,onSelectPill:()=>{},rounded:!0,loading:!0})}),D&&oe(Be,{options:A,activeIndex:_,onSelect:f,onHighlight:v,listboxId:d,loading:p}),H&&oe("div",{className:te.skeletonBars,"data-aia-skeleton-bars":"",children:rt.map(P=>oe("span",{className:te.skeletonBar,style:{width:P}},`bar-${P}`))})]})}if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
737
737
  * Built-in appearance defaults \u2014 zero specificity via :where().
738
738
  * Consumer CSS always wins without !important.
739
739
  *
@@ -818,7 +818,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as
818
818
  }
819
819
 
820
820
  :where(.magicx-aia[data-options-position="above"]) [data-aia-pillbar] {
821
- padding: 0 27px 27px 27px;
821
+ padding: 13px 27px 13px 27px;
822
822
  }
823
823
 
824
824
  /* Disable all animations when data-animations="off" */
@@ -828,5 +828,5 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ne,useImperativeHandle as
828
828
  animation-duration: 0s !important;
829
829
  transition-duration: 0s !important;
830
830
  }
831
- `,document.head.appendChild(e)}import{buildQuery as bt,ModeController as ht,setCursorOffset as xt}from"@magicx-eng/ai-autocomplete-vanilla";import{AIAutocomplete as st}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Be,useEffect as be,useRef as L,useState as lt}from"react";var dt={text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!0,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1};function ke({onSubmit:e,onError:y,optionOverrides:b,maskCompletedText:v,apiConfig:p,columns:l=2,dropdownTrigger:u,closeDropdownOnBlur:c,showNonTappableOptions:x,onFocus:n,onBlur:m,value:w,completedParams:S,onChange:O,onParamsChange:E,source:N,setCursor:B}){let a=L(null),[T,_]=lt(null),G=L(e);G.current=e;let X=L(y);X.current=y;let H=L(O);H.current=O;let Q=L(E);Q.current=E;let V=L(n);V.current=n;let P=L(m);P.current=m;let J=L(B);J.current=B,be(()=>{if(typeof document>"u")return;let t=new st(document.createElement("div"),{renderMode:"headless",apiConfig:p,optionOverrides:b,maskCompletedText:v,columns:l,dropdownTrigger:u,closeDropdownOnBlur:c,showNonTappableOptions:x,source:N,value:w,completedParams:S,onSubmit:(...k)=>G.current?.(...k),onError:(...k)=>X.current?.(...k),onChange:(...k)=>H.current?.(...k),onParamsChange:(...k)=>Q.current?.(...k),onFocus:()=>V.current?.(),onBlur:()=>P.current?.(),setCursor:k=>J.current?.(k)});a.current=t,_(t.getState());let A=t.subscribe(k=>_(k));return()=>{A(),t.destroy(),a.current===t&&(a.current=null)}},[]),be(()=>{w!==void 0&&a.current?.setValue(w)},[w]),be(()=>{S!==void 0&&a.current?.setCompletedParams(S)},[S]);let z=JSON.stringify(p??null),q=L(b),te=L(0);if(b!==q.current){let t=q.current,A=b,k=Object.keys(t??{}),oe=Object.keys(A??{});(k.length!==oe.length||oe.some(ie=>!t?.[ie]||A[ie]!==t[ie]))&&te.current++,q.current=b}be(()=>{a.current?.update({apiConfig:p,optionOverrides:b,dropdownTrigger:u,closeDropdownOnBlur:c,showNonTappableOptions:x})},[z,te.current,u,c,x]);let K=L(null);K.current===null&&(K.current={handleTextChange:t=>a.current?.handleTextChange(t),handleKeyDown:t=>{let A="nativeEvent"in t?t.nativeEvent:t;a.current?.handleKeyDown(A)},setFocused:t=>a.current?.setFocused(t),startEditingParam:t=>a.current?.startEditingParam(t),exitEditMode:()=>a.current?.exitEditMode(),handleCaretAfterInput:t=>a.current?.handleCaretAfterInput(t),handleCaretMove:t=>a.current?.handleCaretMove(t),replaceEditingRange:t=>a.current?.replaceEditingRange(t)??!1,setActivePill:t=>a.current?.setActivePill(t),removeLastParam:()=>a.current?.removeLastParam(),clearNewParamId:()=>a.current?.clearNewParamId(),reset:()=>a.current?.reset(),selectOption:t=>a.current?.selectOption(t),setActiveDropdownIndex:t=>a.current?.setActiveDropdownIndex(t),handleFocus:()=>a.current?.setFocused(!0),handleBlur:()=>a.current?.setFocused(!1)});let g=K.current,ne=Be(t=>{let A=t.target.value,oe=A.length>0&&!t.nativeEvent?.isComposing&&A[0]!==A[0].toUpperCase()?A[0].toUpperCase()+A.slice(1):A;a.current?.handleTextChange(oe)},[]),Y=Be(t=>{a.current?.handleKeyDown(t.nativeEvent)},[]),F=a.current,i=T??dt,re=w!==void 0?w:i.text,o=S!==void 0?S:i.completedParams,r=i.actionableSuggestions,d=r[0],f=F?.listboxId??"",h=i.activeDropdownIndex>=0&&F?`${f}-option-${i.activeDropdownIndex}`:void 0,I=i.editingParam,W=I?{type:I.suggestionType,text:I.suggestionPlaceholder,required:!0,options:I.options}:null,$=W??d,xe=W?[W]:r,de=!F||i.isLoading&&!i.editingParam&&!i.inSelectionAnimation;return{completedParams:o,suggestionPills:r,setActivePill:g.setActivePill,removeLastParam:g.removeLastParam,segments:i.segments,newParamId:i.newParamId,clearNewParamId:g.clearNewParamId,suggestions:i.suggestions,activeIndex:i.activeDropdownIndex,isReady:i.isReady,isLoading:de,isFocused:i.isFocused,isDropdownOpen:i.isDropdownOpen,placeholderText:i.placeholderText,listboxId:f,error:i.error,handleTextChange:g.handleTextChange,handleKeyDown:g.handleKeyDown,setFocused:g.setFocused,editingParam:I,editingAnchor:i.editingAnchor,caretOffset:i.caretOffset,startEditingParam:g.startEditingParam,exitEditMode:g.exitEditMode,handleCaretAfterInput:g.handleCaretAfterInput,handleCaretMove:g.handleCaretMove,replaceEditingRange:g.replaceEditingRange,inputProps:{value:re,placeholder:i.placeholderText||void 0,onChange:ne,onKeyDown:Y,onFocus:g.handleFocus,onBlur:g.handleBlur,role:"combobox","aria-expanded":i.isDropdownOpen,"aria-activedescendant":h,"aria-autocomplete":"list","aria-controls":f},reset:g.reset,dropdownProps:{suggestions:$?[{...$,options:i.filteredOptions}]:[],activeIndex:i.activeDropdownIndex,onSelect:g.selectOption,onHighlight:g.setActiveDropdownIndex,isOpen:i.isDropdownOpen,id:f,pills:xe,onPillClick:g.setActivePill,isLoading:de}}}import{extractPlainText as He,getCursorOffset as Ke,plainTextLength as pt,renderEditableContent as ut,setCursorOffset as Fe}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as R,useEffect as Ae,useLayoutEffect as Se,useRef as ae}from"react";var he;function ct(){if(he!==void 0)return he;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),he=e.contentEditable==="plaintext-only",he}function We(e){let{segments:y,newParamId:b,editingParam:v,editingAnchor:p,caretOffset:l,placeholderText:u,isFocused:c,isDropdownOpen:x,listboxId:n,activeDescendantId:m,autoFocus:w,handleTextChange:S,handleKeyDown:O,handleCaretAfterInput:E,handleCaretMove:N,startEditingParam:B,replaceEditingRange:a,setFocused:T}=e,_=ae(null),G=ae(!1),X=ae(""),H=ae(""),Q=ae(null),V=ae(0);Q.current=l,Ae(()=>{if(!w)return;let o=_.current;o&&(document.activeElement===o?T(!0):o.focus())},[w,T]),Ae(()=>{let o=_.current;if(!o)return;let r=o.ownerDocument??document,d=()=>{let f=r.getSelection();if(!f||f.rangeCount===0||!f.anchorNode||!o.contains(f.anchorNode))return;let h=f.anchorNode,$=(h.nodeType===Node.ELEMENT_NODE?h:h.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if($&&$!==v?.id){B($);return}performance.now()-V.current<50||N(Ke(o))};return r.addEventListener("selectionchange",d),()=>r.removeEventListener("selectionchange",d)},[v,B,N]),Se(()=>{let o=_.current;o&&ut({input:o,segments:y,newParamId:b,editingParamId:v?.id??null,placeholderText:u??"",isFocused:c})},[y,b,v,u,c]),Se(()=>{let o=X.current,r=b??"";if(X.current=r,!r||r===o)return;let d=_.current;if(!d)return;d.focus();let f=Q.current??pt(d);Fe(d,f)},[b]),Se(()=>{let o=H.current,r=v?.id??"";if(H.current=r,!r||r===o||p==null)return;let d=_.current;d&&Fe(d,p)},[v,p]);let P=R(()=>{if(G.current)return;let o=_.current;if(!o)return;let r=He(o),f=r.length>0&&r[0]!==r[0].toUpperCase()?r[0].toUpperCase()+r.slice(1):r;S(f)},[S]),J=R(()=>{V.current=performance.now(),P();let o=_.current;o&&E(Ke(o))},[P,E]);Ae(()=>{let o=_.current;if(!o)return;let r=d=>{let f=d,h=f.inputType;if(h==="insertParagraph"||h==="insertLineBreak"||h==="insertFromDrop"){d.preventDefault();return}if(h.startsWith("insert")||h.startsWith("delete")){let I=h.startsWith("delete")?"":f.data??"";a(I)&&d.preventDefault()}};return o.addEventListener("beforeinput",r),()=>o.removeEventListener("beforeinput",r)},[a]);let z=R(()=>{G.current=!0},[]),q=R(()=>{G.current=!1,P()},[P]),te=R(o=>{o.preventDefault();let r=_.current;if(!r)return;let d=(o.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!d)return;let f=r.ownerDocument??document,h=f.getSelection();if(!h||h.rangeCount===0)return;let I=h.getRangeAt(0);if(!r.contains(I.startContainer))return;I.deleteContents();let W=f.createTextNode(d);I.insertNode(W),I.setStartAfter(W),I.collapse(!0),h.removeAllRanges(),h.addRange(I),P()},[P]),K=R(o=>O(o),[O]),g=R(()=>T(!0),[T]),ne=R(()=>T(!1),[T]),Y=R(()=>_.current?.focus(),[]),F=R(()=>_.current?.blur(),[]),i=R(()=>{let o=_.current;return o?He(o):""},[]),re=ct()?"plaintext-only":"true";return{inputRef:_,editorProps:{ref:_,contentEditable:re,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n,"aria-expanded":x,"aria-activedescendant":m,spellCheck:!0,enterKeyHint:"send",onInput:J,onKeyDown:K,onCompositionStart:z,onCompositionEnd:q,onPaste:te,onFocus:g,onBlur:ne},getPlainText:i,focus:Y,blur:F}}import{jsx as j,jsxs as Ee}from"react/jsx-runtime";function vt(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var wt=mt(function({onSubmit:y,onError:b,optionOverrides:v,maskCompletedText:p,className:l,apiConfig:u,columns:c,pillPlacement:x="inline",mode:n="auto",optionsPosition:m="below",animations:w=!0,dropdownTrigger:S,closeDropdownOnBlur:O,showNonTappableOptions:E,autoFocus:N=!0,onFocus:B,onBlur:a,value:T,completedParams:_,onChange:G,onParamsChange:X,submitButton:H},Q){let V=le(null),P=le(null),J=le(()=>{}),z=le(null),q=le(null);Ne(()=>{let s=V.current;if(s)return z.current?z.current.setMode(n):z.current=new ht(s,n),()=>{z.current?.destroy(),z.current=null}},[n]);let te=Pe(s=>{let C=q.current?.current;C&&(C.focus(),xt(C,s))},[]),{completedParams:K,suggestionPills:g,setActivePill:ne,segments:Y,newParamId:F,clearNewParamId:i,placeholderText:re,isFocused:o,isDropdownOpen:r,isLoading:d,activeIndex:f,listboxId:h,handleTextChange:I,handleKeyDown:W,setFocused:$,editingParam:xe,editingAnchor:de,caretOffset:t,startEditingParam:A,handleCaretAfterInput:k,handleCaretMove:oe,replaceEditingRange:ie,dropdownProps:Ge,reset:pe}=ke({onSubmit:s=>J.current(s),onError:b,optionOverrides:v,maskCompletedText:p,apiConfig:u,columns:c,dropdownTrigger:S,closeDropdownOnBlur:O,showNonTappableOptions:E,onFocus:B,onBlur:a,value:T,completedParams:_,onChange:G,onParamsChange:X,source:"full-sdk",setCursor:te});Ne(()=>{if(!F)return;let s=window.setTimeout(()=>i(),650);return()=>window.clearTimeout(s)},[F,i]);let Ve=f>=0?`${h}-option-${f}`:void 0,{inputRef:ve,editorProps:qe,focus:ue,blur:Ce,getPlainText:De}=We({segments:Y,newParamId:F,editingParam:xe,editingAnchor:de,caretOffset:t,placeholderText:re,isFocused:o,isDropdownOpen:r,listboxId:h,activeDescendantId:Ve,autoFocus:N,handleTextChange:I,handleKeyDown:W,handleCaretAfterInput:k,handleCaretMove:oe,startEditingParam:A,replaceEditingRange:ie,setFocused:$});q.current=ve,ft(()=>{let s=P.current,C=ve.current;if(!s||!C)return;let me=()=>{let Re=s.firstElementChild;if(!Re)return;if(C.dataset.aiaEmpty==="true"){s.setAttribute("data-aia-pill-wrapped","");return}let Xe=Re.getBoundingClientRect(),Qe=C.getBoundingClientRect();Xe.top>=Qe.bottom-2?s.setAttribute("data-aia-pill-wrapped",""):s.removeAttribute("data-aia-pill-wrapped")};me();let Le=new ResizeObserver(me);return Le.observe(C),()=>Le.disconnect()},[Y,g.length,d,ve]),gt(Q,()=>({focus:ue,blur:Ce,reset:pe,setMode:s=>z.current?.setMode(s)}),[ue,Ce,pe]);let ce=!!Y.length||K.length>0,we=Pe(()=>{if(!ce)return;let s=De(),{rawQuery:C,completedParams:me}=bt(s,K);y({query:s.trim(),raw_query:C,completed_params:me}),pe()},[ce,K,y,pe,De]);J.current=we;let $e=Pe(s=>{s.target?.closest("[data-aia-pill]")||ue()},[ue]),Ue=x==="inline",je=x==="dropdown";return Ee("div",{ref:V,className:`magicx-aia ${U.container} ${l??""}`,"data-pill-placement":x,"data-options-position":m,"data-animations":w?"on":"off","data-mode":vt(n),children:[j(Ie,{...Ge,showPills:je}),Ee("div",{className:U.inputWrapper,onClick:$e,children:[Ee("div",{className:U.editorArea,"data-aia-editor":"",children:[j("div",{...qe,className:U.input,"data-aia-input":""}),Ue&&(d||g.length>0)&&j("span",{ref:P,className:U.pillListContainer,"data-aia-pill-list-container":"",children:j(se,{pills:g,activePillIndex:0,onSelectPill:ne,loading:d})})]}),H===null?null:H===void 0?j("button",{type:"button","data-aia-submit":"",className:U.submitButton,disabled:!ce,onClick:s=>{s.stopPropagation(),we()},"aria-label":"Submit",children:j("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:j("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):j("span",{"data-aia-submit":"",className:U.submitSlot,onClick:s=>{ce&&(s.stopPropagation(),we())},children:H})]})]})});export{wt as AIAutocomplete,Ie as AIAutocompleteDropdown,ke as useAIAutocomplete};
831
+ `,document.head.appendChild(e)}import{buildQuery as bt,ModeController as ht,setCursorOffset as xt}from"@magicx-eng/ai-autocomplete-vanilla";import{AIAutocomplete as st}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as He,useEffect as he,useRef as M,useState as lt}from"react";var dt={text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!0,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1};function Ae({onSubmit:e,onError:_,optionOverrides:f,maskCompletedText:v,apiConfig:c,columns:d=2,dropdownTrigger:m,optionsPosition:g,closeDropdownOnBlur:h,showNonTappableOptions:n,onFocus:p,onBlur:I,value:A,completedParams:S,onChange:D,onParamsChange:H,source:N,setCursor:P}){let a=M(null),[w,G]=lt(null),X=M(e);X.current=e;let K=M(_);K.current=_;let Q=M(D);Q.current=D;let V=M(H);V.current=H;let C=M(p);C.current=p;let J=M(I);J.current=I;let L=M(P);L.current=P,he(()=>{if(typeof document>"u")return;let t=new st(document.createElement("div"),{renderMode:"headless",apiConfig:c,optionOverrides:f,maskCompletedText:v,columns:d,dropdownTrigger:m,optionsPosition:g,closeDropdownOnBlur:h,showNonTappableOptions:n,source:N,value:A,completedParams:S,onSubmit:(...y)=>X.current?.(...y),onError:(...y)=>K.current?.(...y),onChange:(...y)=>Q.current?.(...y),onParamsChange:(...y)=>V.current?.(...y),onFocus:()=>C.current?.(),onBlur:()=>J.current?.(),setCursor:y=>L.current?.(y)});a.current=t,G(t.getState());let k=t.subscribe(y=>G(y));return()=>{k(),t.destroy(),a.current===t&&(a.current=null)}},[]),he(()=>{A!==void 0&&a.current?.setValue(A)},[A]),he(()=>{S!==void 0&&a.current?.setCompletedParams(S)},[S]);let ae=JSON.stringify(c??null),Y=M(f),q=M(0);if(f!==Y.current){let t=Y.current,k=f,y=Object.keys(t??{}),ne=Object.keys(k??{});(y.length!==ne.length||ne.some(ie=>!t?.[ie]||k[ie]!==t[ie]))&&q.current++,Y.current=f}he(()=>{a.current?.update({apiConfig:c,optionOverrides:f,dropdownTrigger:m,optionsPosition:g,closeDropdownOnBlur:h,showNonTappableOptions:n})},[ae,q.current,m,g,h,n]);let F=M(null);F.current===null&&(F.current={handleTextChange:t=>a.current?.handleTextChange(t),handleKeyDown:t=>{let k="nativeEvent"in t?t.nativeEvent:t;a.current?.handleKeyDown(k)},setFocused:t=>a.current?.setFocused(t),startEditingParam:t=>a.current?.startEditingParam(t),exitEditMode:()=>a.current?.exitEditMode(),handleCaretAfterInput:t=>a.current?.handleCaretAfterInput(t),handleCaretMove:t=>a.current?.handleCaretMove(t),replaceEditingRange:t=>a.current?.replaceEditingRange(t)??!1,setActivePill:t=>a.current?.setActivePill(t),removeLastParam:()=>a.current?.removeLastParam(),clearNewParamId:()=>a.current?.clearNewParamId(),reset:()=>a.current?.reset(),selectOption:t=>a.current?.selectOption(t),setActiveDropdownIndex:t=>a.current?.setActiveDropdownIndex(t),handleFocus:()=>a.current?.setFocused(!0),handleBlur:()=>a.current?.setFocused(!1)});let b=F.current,Z=He(t=>{let k=t.target.value,ne=k.length>0&&!t.nativeEvent?.isComposing&&k[0]!==k[0].toUpperCase()?k[0].toUpperCase()+k.slice(1):k;a.current?.handleTextChange(ne)},[]),ee=He(t=>{a.current?.handleKeyDown(t.nativeEvent)},[]),$=a.current,r=w??dt,o=A!==void 0?A:r.text,i=S!==void 0?S:r.completedParams,s=r.actionableSuggestions,x=s[0],u=$?.listboxId??"",E=r.activeDropdownIndex>=0&&$?`${u}-option-${r.activeDropdownIndex}`:void 0,R=r.editingParam,W=R?{type:R.suggestionType,text:R.suggestionPlaceholder,required:!0,options:R.options}:null,de=W??x,ve=W?[W]:s,pe=!$||r.isLoading&&!r.editingParam&&!r.inSelectionAnimation;return{completedParams:i,suggestionPills:s,setActivePill:b.setActivePill,removeLastParam:b.removeLastParam,segments:r.segments,newParamId:r.newParamId,clearNewParamId:b.clearNewParamId,suggestions:r.suggestions,activeIndex:r.activeDropdownIndex,isReady:r.isReady,isLoading:pe,isFocused:r.isFocused,isDropdownOpen:r.isDropdownOpen,placeholderText:r.placeholderText,listboxId:u,error:r.error,handleTextChange:b.handleTextChange,handleKeyDown:b.handleKeyDown,setFocused:b.setFocused,editingParam:R,editingAnchor:r.editingAnchor,caretOffset:r.caretOffset,startEditingParam:b.startEditingParam,exitEditMode:b.exitEditMode,handleCaretAfterInput:b.handleCaretAfterInput,handleCaretMove:b.handleCaretMove,replaceEditingRange:b.replaceEditingRange,inputProps:{value:o,placeholder:r.placeholderText||void 0,onChange:Z,onKeyDown:ee,onFocus:b.handleFocus,onBlur:b.handleBlur,role:"combobox","aria-expanded":r.isDropdownOpen,"aria-activedescendant":E,"aria-autocomplete":"list","aria-controls":u},reset:b.reset,dropdownProps:{suggestions:de?[{...de,options:r.filteredOptions}]:[],activeIndex:r.activeDropdownIndex,onSelect:b.selectOption,onHighlight:b.setActiveDropdownIndex,isOpen:r.isDropdownOpen,id:u,pills:ve,onPillClick:b.setActivePill,isLoading:pe}}}import{extractPlainText as Ke,getCursorOffset as Fe,plainTextLength as pt,renderEditableContent as ut,setCursorOffset as We}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as O,useEffect as Se,useLayoutEffect as Ee,useRef as re}from"react";var xe;function ct(){if(xe!==void 0)return xe;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),xe=e.contentEditable==="plaintext-only",xe}function Ne(e){let{segments:_,newParamId:f,editingParam:v,editingAnchor:c,caretOffset:d,placeholderText:m,isFocused:g,isDropdownOpen:h,listboxId:n,activeDescendantId:p,autoFocus:I,handleTextChange:A,handleKeyDown:S,handleCaretAfterInput:D,handleCaretMove:H,startEditingParam:N,replaceEditingRange:P,setFocused:a}=e,w=re(null),G=re(!1),X=re(""),K=re(""),Q=re(null),V=re(0);Q.current=d,Se(()=>{if(!I)return;let o=w.current;o&&(document.activeElement===o?a(!0):o.focus())},[I,a]),Se(()=>{let o=w.current;if(!o)return;let i=o.ownerDocument??document,s=()=>{let x=i.getSelection();if(!x||x.rangeCount===0||!x.anchorNode||!o.contains(x.anchorNode))return;let u=x.anchorNode,W=(u.nodeType===Node.ELEMENT_NODE?u:u.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if(W&&W!==v?.id){N(W);return}performance.now()-V.current<50||H(Fe(o))};return i.addEventListener("selectionchange",s),()=>i.removeEventListener("selectionchange",s)},[v,N,H]),Ee(()=>{let o=w.current;o&&ut({input:o,segments:_,newParamId:f,editingParamId:v?.id??null,placeholderText:m??"",isFocused:g})},[_,f,v,m,g]),Ee(()=>{let o=X.current,i=f??"";if(X.current=i,!i||i===o)return;let s=w.current;if(!s)return;s.focus();let x=Q.current??pt(s);We(s,x)},[f]),Ee(()=>{let o=K.current,i=v?.id??"";if(K.current=i,!i||i===o||c==null)return;let s=w.current;s&&We(s,c)},[v,c]);let C=O(()=>{if(G.current)return;let o=w.current;if(!o)return;let i=Ke(o),x=i.length>0&&i[0]!==i[0].toUpperCase()?i[0].toUpperCase()+i.slice(1):i;A(x)},[A]),J=O(()=>{V.current=performance.now(),C();let o=w.current;o&&D(Fe(o))},[C,D]);Se(()=>{let o=w.current;if(!o)return;let i=s=>{let x=s,u=x.inputType;if(u==="insertParagraph"||u==="insertLineBreak"||u==="insertFromDrop"){s.preventDefault();return}if(u.startsWith("insert")||u.startsWith("delete")){let E=u.startsWith("delete")?"":x.data??"";P(E)&&s.preventDefault()}};return o.addEventListener("beforeinput",i),()=>o.removeEventListener("beforeinput",i)},[P]);let L=O(()=>{G.current=!0},[]),ae=O(()=>{G.current=!1,C()},[C]),Y=O(o=>{o.preventDefault();let i=w.current;if(!i)return;let s=(o.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!s)return;let x=i.ownerDocument??document,u=x.getSelection();if(!u||u.rangeCount===0)return;let E=u.getRangeAt(0);if(!i.contains(E.startContainer))return;E.deleteContents();let R=x.createTextNode(s);E.insertNode(R),E.setStartAfter(R),E.collapse(!0),u.removeAllRanges(),u.addRange(E),C()},[C]),q=O(o=>S(o),[S]),F=O(()=>a(!0),[a]),b=O(()=>a(!1),[a]),Z=O(()=>w.current?.focus(),[]),ee=O(()=>w.current?.blur(),[]),$=O(()=>{let o=w.current;return o?Ke(o):""},[]),r=ct()?"plaintext-only":"true";return{inputRef:w,editorProps:{ref:w,contentEditable:r,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n,"aria-expanded":h,"aria-activedescendant":p,spellCheck:!0,enterKeyHint:"send",onInput:J,onKeyDown:q,onCompositionStart:L,onCompositionEnd:ae,onPaste:Y,onFocus:F,onBlur:b},getPlainText:$,focus:Z,blur:ee}}import{jsx as j,jsxs as Ce}from"react/jsx-runtime";function vt(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var wt=mt(function({onSubmit:_,onError:f,optionOverrides:v,maskCompletedText:c,className:d,apiConfig:m,columns:g,pillPlacement:h="inline",mode:n="auto",optionsPosition:p="below",animations:I=!0,dropdownTrigger:A,closeDropdownOnBlur:S,showNonTappableOptions:D,autoFocus:H=!0,onFocus:N,onBlur:P,value:a,completedParams:w,onChange:G,onParamsChange:X,submitButton:K},Q){let V=le(null),C=le(null),J=le(()=>{}),L=le(null),ae=le(null);Ge(()=>{let l=V.current;if(l)return L.current?L.current.setMode(n):L.current=new ht(l,n),()=>{L.current?.destroy(),L.current=null}},[n]);let Y=Pe(l=>{let T=ae.current?.current;T&&(T.focus(),xt(T,l))},[]),{completedParams:q,suggestionPills:F,setActivePill:b,segments:Z,newParamId:ee,clearNewParamId:$,placeholderText:r,isFocused:o,isDropdownOpen:i,isLoading:s,activeIndex:x,listboxId:u,handleTextChange:E,handleKeyDown:R,setFocused:W,editingParam:de,editingAnchor:ve,caretOffset:pe,startEditingParam:t,handleCaretAfterInput:k,handleCaretMove:y,replaceEditingRange:ne,dropdownProps:ie,reset:ue}=Ae({onSubmit:l=>J.current(l),onError:f,optionOverrides:v,maskCompletedText:c,apiConfig:m,columns:g,dropdownTrigger:A,optionsPosition:p,closeDropdownOnBlur:S,showNonTappableOptions:D,onFocus:N,onBlur:P,value:a,completedParams:w,onChange:G,onParamsChange:X,source:"full-sdk",setCursor:Y});Ge(()=>{if(!ee)return;let l=window.setTimeout(()=>$(),650);return()=>window.clearTimeout(l)},[ee,$]);let Ve=x>=0?`${u}-option-${x}`:void 0,{inputRef:we,editorProps:qe,focus:ce,blur:De,getPlainText:Le}=Ne({segments:Z,newParamId:ee,editingParam:de,editingAnchor:ve,caretOffset:pe,placeholderText:r,isFocused:o,isDropdownOpen:i,listboxId:u,activeDescendantId:Ve,autoFocus:H,handleTextChange:E,handleKeyDown:R,handleCaretAfterInput:k,handleCaretMove:y,startEditingParam:t,replaceEditingRange:ne,setFocused:W});ae.current=we,ft(()=>{let l=C.current,T=we.current;if(!l||!T)return;let ge=()=>{let Te=l.firstElementChild;if(!Te)return;if(T.dataset.aiaEmpty==="true"){l.setAttribute("data-aia-pill-wrapped","");return}let Xe=Te.getBoundingClientRect(),Qe=T.getBoundingClientRect();Xe.top>=Qe.bottom-2?l.setAttribute("data-aia-pill-wrapped",""):l.removeAttribute("data-aia-pill-wrapped")};ge();let Re=new ResizeObserver(ge);return Re.observe(T),()=>Re.disconnect()},[Z,F.length,s,we]),gt(Q,()=>({focus:ce,blur:De,reset:ue,setMode:l=>L.current?.setMode(l)}),[ce,De,ue]);let me=!!Z.length||q.length>0,_e=Pe(()=>{if(!me)return;let l=Le(),{rawQuery:T,completedParams:ge}=bt(l,q);_({query:l.trim(),raw_query:T,completed_params:ge}),ue()},[me,q,_,ue,Le]);J.current=_e;let $e=Pe(l=>{l.target?.closest("[data-aia-pill]")||ce()},[ce]),Ue=h==="inline",je=h==="dropdown";return Ce("div",{ref:V,className:`magicx-aia ${U.container} ${d??""}`,"data-pill-placement":h,"data-options-position":p,"data-animations":I?"on":"off","data-mode":vt(n),children:[j(ke,{...ie,showPills:je}),Ce("div",{className:U.inputWrapper,onClick:$e,children:[Ce("div",{className:U.editorArea,"data-aia-editor":"",children:[j("div",{...qe,className:U.input,"data-aia-input":""}),Ue&&(s||F.length>0)&&j("span",{ref:C,className:U.pillListContainer,"data-aia-pill-list-container":"",children:j(se,{pills:F,activePillIndex:0,onSelectPill:b,loading:s})})]}),K===null?null:K===void 0?j("button",{type:"button","data-aia-submit":"",className:U.submitButton,disabled:!me,onClick:l=>{l.stopPropagation(),_e()},"aria-label":"Submit",children:j("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:j("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}):j("span",{"data-aia-submit":"",className:U.submitSlot,onClick:l=>{me&&(l.stopPropagation(),_e())},children:K})]})]})});export{wt as AIAutocomplete,ke as AIAutocompleteDropdown,Ae as useAIAutocomplete};
832
832
  //# sourceMappingURL=index.mjs.map