@magicx-eng/ai-autocomplete-react 0.4.1 → 0.5.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/README.md +77 -12
- package/dist/index.d.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{forwardRef as
|
|
1
|
+
import{forwardRef as zt,useCallback as Le,useEffect as at,useImperativeHandle as Ft,useLayoutEffect as Ht,useRef as ce}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
|
|
@@ -145,7 +145,7 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
145
145
|
background-position: -50% 0;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
`,document.head.appendChild(e)}var te={container:"AIAutocomplete-module_container_KKjFU",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",input:"AIAutocomplete-module_input_IW-P-",pillListContainer:"AIAutocomplete-module_pillListContainer_h92IA",submitSlot:"AIAutocomplete-module_submitSlot_GhuCM",textShimmer:"AIAutocomplete-module_textShimmer_eCLdq"};import{useRef as It}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
|
|
148
|
+
`,document.head.appendChild(e)}var te={container:"AIAutocomplete-module_container_KKjFU",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",input:"AIAutocomplete-module_input_IW-P-",pillListContainer:"AIAutocomplete-module_pillListContainer_h92IA",submitSlot:"AIAutocomplete-module_submitSlot_GhuCM",textShimmer:"AIAutocomplete-module_textShimmer_eCLdq"};import{useEffect as kt,useRef as It,useState as St}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
|
|
149
149
|
* Built-in appearance defaults \u2014 zero specificity via :where().
|
|
150
150
|
* Consumer CSS always wins without !important.
|
|
151
151
|
*
|
|
@@ -414,7 +414,7 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
414
414
|
justify-content: space-around;
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
|
-
`,document.head.appendChild(e)}import{jsx as Me}from"react/jsx-runtime";function le({gap:e,align:
|
|
417
|
+
`,document.head.appendChild(e)}import{jsx as Me}from"react/jsx-runtime";function le({gap:e,align:d="center",justify:i="start",noWrap:p=!1,inline:o=!1,className:t,children:s,...l}){let m=e?{"--aia-cluster-gap":e}:void 0,b={className:t?`aia-cluster ${t}`:"aia-cluster","data-align":d,"data-justify":i,"data-nowrap":p||void 0,"data-inline":o||void 0,style:m,...l};return o?Me("span",{...b,children:s}):Me("div",{...b,children:s})}if(typeof document<"u"&&!document.getElementById("ac-style-56b0c577")){let e=document.createElement("style");e.id="ac-style-56b0c577",e.textContent=`/* The footer adds its own 8px horizontal inset (no vertical padding \u2014 the 8px
|
|
418
418
|
section gap above and its own 8px gap provide the vertical rhythm), so the
|
|
419
419
|
divider spans the full footer width yet still stays clear of the dropdown's
|
|
420
420
|
rounded edges. */
|
|
@@ -487,7 +487,7 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
487
487
|
line-height: 18px;
|
|
488
488
|
color: var(--aia-footer-brand-color, #b0b0b0);
|
|
489
489
|
}
|
|
490
|
-
`,document.head.appendChild(e)}var
|
|
490
|
+
`,document.head.appendChild(e)}var X={footer:"DropdownFooter-module_footer_qQQ7x",divider:"DropdownFooter-module_divider_FlX4C",hintGroup:"DropdownFooter-module_hintGroup_ZzbPf",brandLink:"DropdownFooter-module_brandLink_r4f3R",key:"DropdownFooter-module_key_Bz1H-",hint:"DropdownFooter-module_hint_GKEOH",brand:"DropdownFooter-module_brand_Al-lR",badge:"DropdownFooter-module_badge_Fk9vg"};import{jsx as de,jsxs as be}from"react/jsx-runtime";function Ne({hasTabbedToHighlight:e=!1,isOptionHighlighted:d=!1,isInputEmpty:i=!1}){let{key:p,hint:o}=ut(e,d,i);return be("footer",{className:X.footer,"data-aia-footer":"",children:[de("div",{className:X.divider}),be(le,{justify:"between",noWrap:!0,children:[be(le,{gap:"5px",className:X.hintGroup,children:[de("kbd",{className:X.key,children:p}),de("span",{className:X.hint,children:o})]}),be("a",{className:X.brandLink,href:"https://ai-autocomplete.com",target:"_blank",rel:"noopener noreferrer",children:[de("span",{className:X.brand,children:"AI"}),de("span",{className:X.badge,children:"Autocomplete"})]})]})]})}if(typeof document<"u"&&!document.getElementById("ac-style-04fef8d6")){let e=document.createElement("style");e.id="ac-style-04fef8d6",e.textContent=`.Pill-module_pill_3Rkw- {
|
|
491
491
|
display: inline-flex;
|
|
492
492
|
align-items: center;
|
|
493
493
|
justify-content: center;
|
|
@@ -539,16 +539,17 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
539
539
|
opacity: 0;
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
|
-
`,document.head.appendChild(e)}var
|
|
542
|
+
`,document.head.appendChild(e)}var J={pill:"Pill-module_pill_3Rkw-",fadeIn:"Pill-module_fadeIn_Bbqtz",rounded:"Pill-module_rounded_6WMps",skeleton:"Pill-module_skeleton_-u9-j",skeletonPulse:"Pill-module_skeletonPulse_xHh-7"};import{jsx as mt}from"react/jsx-runtime";var Ae={selected:1,first:.7,next:.4,last:.2};function Ke({label:e,state:d,selected:i,rounded:p,loading:o,onClick:t}){let s=[J.pill,p?J.rounded:"",i&&!o?J.active:"",o?J.skeleton:""].filter(Boolean).join(" ");return mt("button",{type:"button","data-aia-pill":"","data-aia-loading":o?"":void 0,tabIndex:-1,contentEditable:!1,suppressContentEditableWarning:!0,className:s,style:{opacity:Ae[d]},onMouseDown:l=>l.preventDefault(),onClick:o?void 0:t,disabled:o,children:e})}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 {
|
|
543
543
|
position: relative;
|
|
544
544
|
z-index: 1;
|
|
545
545
|
pointer-events: auto;
|
|
546
546
|
display: inline-flex;
|
|
547
547
|
gap: 7px;
|
|
548
|
+
padding: 0 8px;
|
|
548
549
|
align-items: center;
|
|
549
550
|
vertical-align: middle;
|
|
550
551
|
}
|
|
551
|
-
`,document.head.appendChild(e)}var Pe={list:"PillList-module_list_qvLqO"};import{jsx as xe}from"react/jsx-runtime";var gt=[125,69];function We(e){return e===0?"first":e===1?"next":"last"}function ve({pills:e,activePillIndex:
|
|
552
|
+
`,document.head.appendChild(e)}var Pe={list:"PillList-module_list_qvLqO"};import{jsx as xe}from"react/jsx-runtime";var gt=[125,69];function We(e){return e===0?"first":e===1?"next":"last"}function ve({pills:e,activePillIndex:d,onSelectPill:i,activeSelected:p,rounded:o,loading:t}){return t&&e.length===0?xe("span",{className:Pe.list,"data-aia-pill-list-loading":"",children:gt.map((s,l)=>xe("span",{"data-aia-pill-skeleton":"",className:`${J.pill} ${o?J.rounded:""} ${J.skeleton}`,style:{width:s,opacity:Ae[We(l)]}},`skel-${s}`))}):xe("span",{className:Pe.list,"data-aia-pill-list-loading":t?"":void 0,children:e.map((s,l)=>{let m=!!p&&l===d;return xe(Ke,{label:s.text,state:m?"selected":We(l),selected:m,rounded:o,loading:t,onClick:()=>i(l)},`${s.type}-${s.text}`)})})}import{useEffect as ft,useLayoutEffect as ht,useRef as bt,useState as xt}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-948e58da")){let e=document.createElement("style");e.id="ac-style-948e58da",e.textContent=`@layer layout {
|
|
552
553
|
.aia-grid {
|
|
553
554
|
display: grid;
|
|
554
555
|
grid-template-columns: repeat(
|
|
@@ -602,7 +603,7 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
602
603
|
opacity: 1;
|
|
603
604
|
}
|
|
604
605
|
}
|
|
605
|
-
`,document.head.appendChild(e)}import{jsx as Ge}from"react/jsx-runtime";function je({min:e="16rem",max:
|
|
606
|
+
`,document.head.appendChild(e)}import{jsx as Ge}from"react/jsx-runtime";function je({min:e="16rem",max:d,gap:i,scroll:p=!1,maxHeight:o,fade:t=!1,className:s,children:l,...m}){let b=bt(null),[R,I]=xt(!1);ft(()=>{if(!t)return;let v=b.current;if(!v)return;let T=()=>{I(v.scrollHeight-v.scrollTop-v.clientHeight>1)};v.addEventListener("scroll",T,{passive:!0});let L=new ResizeObserver(T);return L.observe(v),()=>{v.removeEventListener("scroll",T),L.disconnect()}},[t]),ht(()=>{let v=b.current;!t||!v||I(v.scrollHeight-v.scrollTop-v.clientHeight>1)},[t,l]);let k={"--aia-grid-min":e};d&&(k["--aia-grid-max"]=d),i&&(k["--aia-grid-gap"]=i),o&&(k["--aia-grid-max-height"]=o);let S=Ge("div",{ref:b,className:!t&&s?`aia-grid ${s}`:"aia-grid","data-scroll":p||void 0,style:k,...t?{}:m,children:l});return t?Ge("div",{className:s?`aia-grid-fade ${s}`:"aia-grid-fade","data-fade":R?"":void 0,...m,children:S}):S}import{useEffect as vt,useRef as wt,useState as yt}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 {
|
|
606
607
|
position: relative;
|
|
607
608
|
overflow: visible;
|
|
608
609
|
display: flex;
|
|
@@ -952,7 +953,7 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
952
953
|
filter: brightness(0.55);
|
|
953
954
|
}
|
|
954
955
|
}
|
|
955
|
-
`,document.head.appendChild(e)}var
|
|
956
|
+
`,document.head.appendChild(e)}var N={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 we,jsxs as Ve}from"react/jsx-runtime";function qe({option:e,isHighlighted:d,onSelect:i,onHighlight:p,id:o,loading:t}){let[s,l]=yt(!1),m=wt(void 0);vt(()=>()=>clearTimeout(m.current),[]);let b=()=>{t||!e.is_tappable||s||(l(!0),i(e),clearTimeout(m.current),m.current=setTimeout(()=>l(!1),500))},R=[N.item,d&&!t?N.highlighted:"",e.is_tappable?N.tappable:N.nonTappable,s?N.pressed:""].filter(Boolean).join(" ");return Ve("div",{id:o,role:"option","data-aia-option":"","data-aia-loading":t?"":void 0,"aria-selected":d,className:R,tabIndex:t||!e.is_tappable?-1:0,onClick:b,onKeyDown:I=>{!t&&e.is_tappable&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),b())},onMouseEnter:!t&&e.is_tappable?p:void 0,children:[we("div",{className:N.streaks}),we("div",{className:N.streaksVert}),Ve("span",{className:N.content,children:[we("span",{className:N.text,children:e.icon?`${e.icon} ${e.text}`:e.text}),e.tag&&we("span",{className:N.tag,children:e.tag})]})]})}import{jsx as $e}from"react/jsx-runtime";function Ue({options:e,activeIndex:d,onSelect:i,onHighlight:p,listboxId:o,loading:t}){return $e(je,{min:"250px",max:"250px",gap:"0",scroll:!0,fade:!0,children:e.map((s,l)=>$e(qe,{option:s,isHighlighted:l===d,onSelect:i,onHighlight:()=>p(l),id:`${o}-option-${l}`,loading:t},s.text))})}if(typeof document<"u"&&!document.getElementById("ac-style-8414cd5f")){let e=document.createElement("style");e.id="ac-style-8414cd5f",e.textContent=`@layer layout {
|
|
956
957
|
.aia-stack {
|
|
957
958
|
display: flex;
|
|
958
959
|
flex-direction: column;
|
|
@@ -969,7 +970,7 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
969
970
|
}
|
|
970
971
|
/* data-align="stretch" is the flex default \u2014 no rule needed. */
|
|
971
972
|
}
|
|
972
|
-
`,document.head.appendChild(e)}import{jsx as _t}from"react/jsx-runtime";function Qe({space:e,align:
|
|
973
|
+
`,document.head.appendChild(e)}import{jsx as _t}from"react/jsx-runtime";function Qe({space:e,align:d="stretch",className:i,children:p,...o}){let t=e?{"--aia-stack-space":e}:void 0;return _t("div",{className:i?`aia-stack ${i}`:"aia-stack","data-align":d,style:t,...o,children:p})}import{jsx as oe,jsxs as Ct}from"react/jsx-runtime";var At=[159,119,164];function Pt(e){let d=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[i,p]=St(d);if(kt(()=>{if(e!=="auto"||typeof window>"u"||typeof window.matchMedia!="function")return;let o=window.matchMedia("(prefers-color-scheme: dark)"),t=()=>p(o.matches);return o.addEventListener("change",t),()=>o.removeEventListener("change",t)},[e]),e!==void 0)return e==="auto"?i?"dark":"light":e}function Ce({suggestions:e,activeIndex:d,onSelect:i,onHighlight:p,isOpen:o,id:t,className:s,pills:l,onPillClick:m,showPills:b=!0,activeSelected:R=!1,isLoading:I=!1,hasTabbedToHighlight:k=!1,isInputEmpty:S=!1,optionsPosition:v="below",mode:T}){let L=Pt(T),V=L!==void 0,r=e[0]?.options??[],_=!!(l&&l.length>0&&m),B=o&&(r.length>0||b&&_||I),O={suggestions:e,activeIndex:d,pills:l,showPills:b,activeSelected:R,isLoading:I,hasTabbedToHighlight:k,isInputEmpty:S},z=It(O);B&&(z.current=O);let g=B?O:z.current,A=g.suggestions[0]?.options??[],$=g.activeIndex>=0&&!!A[g.activeIndex]?.is_tappable,E=!!(g.pills&&g.pills.length>0&&m),Z=g.showPills&&E,U=g.showPills&&!E&&g.isLoading,G=Z||U,F=A.length>0,x=g.isLoading&&!F;return oe("div",{id:t,role:"listbox","data-aia-dropdown":"","data-options-position":v,"data-mode":L,"data-aia-loading":g.isLoading?"":void 0,className:`${V?"magicx-aia ":""}${ne.dropdown} ${B?ne.visible:""} ${s??""}`,onMouseDown:H=>H.preventDefault(),children:Ct(Qe,{space:"8px",children:[G&&oe(le,{noWrap:!0,className:ne.pillBar,"data-aia-pillbar":"",children:oe(ve,{pills:g.pills??[],activePillIndex:0,activeSelected:g.activeSelected,onSelectPill:m??(()=>{}),rounded:!0,loading:g.isLoading})}),F&&oe(Ue,{options:A,activeIndex:g.activeIndex,onSelect:i,onHighlight:p,listboxId:t,loading:g.isLoading}),x&&oe("div",{className:ne.skeletonBars,"data-aia-skeleton-bars":"",children:At.map(H=>oe("span",{className:ne.skeletonBar,style:{width:H}},`bar-${H}`))}),oe(Ne,{hasTabbedToHighlight:g.hasTabbedToHighlight,isOptionHighlighted:$,isInputEmpty:g.isInputEmpty})]})})}import{buildQuery as Ot,ModeController as Mt,setCursorOffset as Nt}from"@magicx-eng/ai-autocomplete-vanilla";if(typeof document<"u"&&!document.getElementById("ac-style-fdee06e6")){let e=document.createElement("style");e.id="ac-style-fdee06e6",e.textContent=`.SubmitButton-module_submitButton_otz7H {
|
|
973
974
|
flex-shrink: 0;
|
|
974
975
|
width: 32px;
|
|
975
976
|
height: 32px;
|
|
@@ -993,5 +994,5 @@ import{forwardRef as Tt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
993
994
|
opacity: 0.4;
|
|
994
995
|
cursor: default;
|
|
995
996
|
}
|
|
996
|
-
`,document.head.appendChild(e)}var Xe={submitButton:"SubmitButton-module_submitButton_otz7H"};import{jsx as Ee}from"react/jsx-runtime";function Je({disabled:e,onClick:c}){return Ee("button",{type:"button","data-aia-submit":"",className:Xe.submitButton,disabled:e,onClick:i=>{i.stopPropagation(),c()},"aria-label":"Submit",children:Ee("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:Ee("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as At}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Ze,useEffect as ye,useRef as N,useState as Pt}from"react";var Ct={text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!0,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,isActivePillSelected:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,hasTabbedToHighlight:!1};function De({onSubmit:e,onError:c,optionOverrides:i,maskCompletedText:u,apiConfig:r,columns:n=2,dropdownTrigger:s,optionsPosition:l,closeDropdownOnBlur:g,showNonTappableOptions:b,onFocus:D,onBlur:k,value:I,completedParams:S,onChange:x,onParamsChange:R,source:z,setCursor:F}){let t=N(null),[w,m]=Pt(null),J=N(e);J.current=e;let T=N(c);T.current=c;let G=N(x);G.current=x;let H=N(R);H.current=R;let C=N(D);C.current=D;let j=N(k);j.current=k;let L=N(F);L.current=F,ye(()=>{if(typeof document>"u")return;let a=new At(document.createElement("div"),{renderMode:"headless",apiConfig:r,optionOverrides:i,maskCompletedText:u,columns:n,dropdownTrigger:s,optionsPosition:l,closeDropdownOnBlur:g,showNonTappableOptions:b,source:z,value:I,completedParams:S,onSubmit:(...A)=>J.current?.(...A),onError:(...A)=>T.current?.(...A),onChange:(...A)=>G.current?.(...A),onParamsChange:(...A)=>H.current?.(...A),onFocus:()=>C.current?.(),onBlur:()=>j.current?.(),setCursor:A=>L.current?.(A)});t.current=a,m(a.getState());let P=a.subscribe(A=>m(A));return()=>{P(),a.destroy(),t.current===a&&(t.current=null)}},[]),ye(()=>{I!==void 0&&t.current?.setValue(I)},[I]),ye(()=>{S!==void 0&&t.current?.setCompletedParams(S)},[S]);let V=JSON.stringify(r??null),q=N(i),B=N(0);if(i!==q.current){let a=q.current,P=i,A=Object.keys(a??{}),ae=Object.keys(P??{});(A.length!==ae.length||ae.some(se=>!a?.[se]||P[se]!==a[se]))&&B.current++,q.current=i}ye(()=>{t.current?.update({apiConfig:r,optionOverrides:i,dropdownTrigger:s,optionsPosition:l,closeDropdownOnBlur:g,showNonTappableOptions:b})},[V,B.current,s,l,g,b]);let $=N(null);$.current===null&&($.current={handleTextChange:a=>t.current?.handleTextChange(a),handleKeyDown:a=>{let P="nativeEvent"in a?a.nativeEvent:a;t.current?.handleKeyDown(P)},setFocused:a=>t.current?.setFocused(a),startEditingParam:a=>t.current?.startEditingParam(a),exitEditMode:()=>t.current?.exitEditMode(),handleCaretAfterInput:a=>t.current?.handleCaretAfterInput(a),handleCaretMove:a=>t.current?.handleCaretMove(a),replaceEditingRange:a=>t.current?.replaceEditingRange(a)??!1,setActivePill:a=>t.current?.setActivePill(a),removeLastParam:()=>t.current?.removeLastParam(),clearNewParamId:()=>t.current?.clearNewParamId(),reset:()=>t.current?.reset(),selectOption:a=>t.current?.selectOption(a),setActiveDropdownIndex:a=>t.current?.setActiveDropdownIndex(a),handleFocus:()=>t.current?.setFocused(!0),handleBlur:()=>t.current?.setFocused(!1)});let y=$.current,Y=Ze(a=>{let P=a.target.value,ae=P.length>0&&!a.nativeEvent?.isComposing&&P[0]!==P[0].toUpperCase()?P[0].toUpperCase()+P.slice(1):P;t.current?.handleTextChange(ae)},[]),ee=Ze(a=>{t.current?.handleKeyDown(a.nativeEvent)},[]),Z=t.current,d=w??Ct,o=I!==void 0?I:d.text,p=S!==void 0?S:d.completedParams,f=d.actionableSuggestions,_=f[0],h=Z?.listboxId??"",E=d.activeDropdownIndex>=0&&Z?`${h}-option-${d.activeDropdownIndex}`:void 0,O=d.editingParam,U=O?{type:O.suggestionType,text:O.suggestionPlaceholder,required:!0,options:O.options}:null,pe=U??_,Ie=U?[U]:f,ue=!Z||d.isLoading&&!d.editingParam&&!d.inSelectionAnimation;return{completedParams:p,suggestionPills:f,setActivePill:y.setActivePill,removeLastParam:y.removeLastParam,segments:d.segments,newParamId:d.newParamId,clearNewParamId:y.clearNewParamId,suggestions:d.suggestions,activeIndex:d.activeDropdownIndex,isReady:d.isReady,isLoading:ue,isFocused:d.isFocused,isDropdownOpen:d.isDropdownOpen,isActivePillSelected:d.isActivePillSelected,placeholderText:d.placeholderText,listboxId:h,error:d.error,handleTextChange:y.handleTextChange,handleKeyDown:y.handleKeyDown,setFocused:y.setFocused,editingParam:O,editingAnchor:d.editingAnchor,caretOffset:d.caretOffset,startEditingParam:y.startEditingParam,exitEditMode:y.exitEditMode,handleCaretAfterInput:y.handleCaretAfterInput,handleCaretMove:y.handleCaretMove,replaceEditingRange:y.replaceEditingRange,inputProps:{value:o,placeholder:d.placeholderText||void 0,onChange:Y,onKeyDown:ee,onFocus:y.handleFocus,onBlur:y.handleBlur,role:"combobox","aria-expanded":d.isDropdownOpen,"aria-activedescendant":E,"aria-autocomplete":"list","aria-controls":h},reset:y.reset,dropdownProps:{suggestions:pe?[{...pe,options:d.filteredOptions}]:[],activeIndex:d.activeDropdownIndex,onSelect:y.selectOption,onHighlight:y.setActiveDropdownIndex,isOpen:d.isDropdownOpen,id:h,pills:Ie,activeSelected:d.isActivePillSelected,onPillClick:y.setActivePill,isLoading:ue,hasTabbedToHighlight:d.hasTabbedToHighlight,isInputEmpty:o.trim().length===0,optionsPosition:l??"below"}}}import{extractPlainText as Ye,getCursorOffset as et,plainTextLength as Et,renderEditableContent as Dt,setCursorOffset as tt}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as K,useEffect as Re,useLayoutEffect as Te,useRef as ie}from"react";var _e;function Rt(){if(_e!==void 0)return _e;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),_e=e.contentEditable==="plaintext-only",_e}function ot(e){let{segments:c,newParamId:i,editingParam:u,editingAnchor:r,caretOffset:n,placeholderText:s,isFocused:l,isDropdownOpen:g,listboxId:b,activeDescendantId:D,autoFocus:k,handleTextChange:I,handleKeyDown:S,handleCaretAfterInput:x,handleCaretMove:R,startEditingParam:z,replaceEditingRange:F,setFocused:t}=e,w=ie(null),m=ie(!1),J=ie(""),T=ie(""),G=ie(null),H=ie(0);G.current=n,Re(()=>{if(!k)return;let o=w.current;o&&(document.activeElement===o?t(!0):o.focus())},[k,t]),Re(()=>{let o=w.current;if(!o)return;let p=o.ownerDocument??document,f=()=>{let _=p.getSelection();if(!_||_.rangeCount===0||!_.anchorNode||!o.contains(_.anchorNode))return;let h=_.anchorNode,U=(h.nodeType===Node.ELEMENT_NODE?h:h.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if(U&&U!==u?.id){z(U);return}performance.now()-H.current<50||R(et(o))};return p.addEventListener("selectionchange",f),()=>p.removeEventListener("selectionchange",f)},[u,z,R]),Te(()=>{let o=w.current;o&&Dt({input:o,segments:c,newParamId:i,editingParamId:u?.id??null,placeholderText:s??"",isFocused:l})},[c,i,u,s,l]),Te(()=>{let o=J.current,p=i??"";if(J.current=p,!p||p===o)return;let f=w.current;if(!f)return;f.focus();let _=G.current??Et(f);tt(f,_)},[i]),Te(()=>{let o=T.current,p=u?.id??"";if(T.current=p,!p||p===o||r==null)return;let f=w.current;f&&tt(f,r)},[u,r]);let C=K(()=>{if(m.current)return;let o=w.current;if(!o)return;let p=Ye(o),_=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;I(_)},[I]),j=K(()=>{H.current=performance.now(),C();let o=w.current;o&&x(et(o))},[C,x]);Re(()=>{let o=w.current;if(!o)return;let p=f=>{let _=f,h=_.inputType;if(h==="insertParagraph"||h==="insertLineBreak"||h==="insertFromDrop"){f.preventDefault();return}if(h.startsWith("insert")||h.startsWith("delete")){let E=h.startsWith("delete")?"":_.data??"";F(E)&&f.preventDefault()}};return o.addEventListener("beforeinput",p),()=>o.removeEventListener("beforeinput",p)},[F]);let L=K(()=>{m.current=!0},[]),V=K(()=>{m.current=!1,C()},[C]),q=K(o=>{o.preventDefault();let p=w.current;if(!p)return;let f=(o.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!f)return;let _=p.ownerDocument??document,h=_.getSelection();if(!h||h.rangeCount===0)return;let E=h.getRangeAt(0);if(!p.contains(E.startContainer))return;E.deleteContents();let O=_.createTextNode(f);E.insertNode(O),E.setStartAfter(O),E.collapse(!0),h.removeAllRanges(),h.addRange(E),C()},[C]),B=K(o=>S(o),[S]),$=K(()=>t(!0),[t]),y=K(()=>t(!1),[t]),Y=K(()=>w.current?.focus(),[]),ee=K(()=>w.current?.blur(),[]),Z=K(()=>{let o=w.current;return o?Ye(o):""},[]),d=Rt()?"plaintext-only":"true";return{inputRef:w,editorProps:{ref:w,contentEditable:d,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":b,"aria-expanded":g,"aria-activedescendant":D,spellCheck:!0,enterKeyHint:"send",onInput:j,onKeyDown:B,onCompositionStart:L,onCompositionEnd:V,onPaste:q,onFocus:$,onBlur:y},getPlainText:Z,focus:Y,blur:ee}}import{jsx as re,jsxs as Be}from"react/jsx-runtime";function Ot(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var Mt=Tt(function({onSubmit:c,onError:i,optionOverrides:u,maskCompletedText:r,className:n,apiConfig:s,columns:l,pillPlacement:g="inline",mode:b="auto",optionsPosition:D="below",animations:k=!0,dropdownTrigger:I,closeDropdownOnBlur:S,showNonTappableOptions:x,autoFocus:R=!0,onFocus:z,onBlur:F,value:t,completedParams:w,onChange:m,onParamsChange:J,submitButton:T},G){let H=ce(null),C=ce(null),j=ce(()=>{}),L=ce(null),V=ce(null);at(()=>{let v=H.current;if(v)return L.current?L.current.setMode(b):L.current=new Ft(v,b),()=>{L.current?.destroy(),L.current=null}},[b]);let q=Le(v=>{let W=V.current?.current;W&&(W.focus(),Ht(W,v))},[]),{completedParams:B,suggestionPills:$,setActivePill:y,segments:Y,newParamId:ee,clearNewParamId:Z,placeholderText:d,isFocused:o,isDropdownOpen:p,isActivePillSelected:f,isLoading:_,activeIndex:h,listboxId:E,handleTextChange:O,handleKeyDown:U,setFocused:pe,editingParam:Ie,editingAnchor:ue,caretOffset:a,startEditingParam:P,handleCaretAfterInput:A,handleCaretMove:ae,replaceEditingRange:se,dropdownProps:nt,reset:me}=De({onSubmit:v=>j.current(v),onError:i,optionOverrides:u,maskCompletedText:r,apiConfig:s,columns:l,dropdownTrigger:I,optionsPosition:D,closeDropdownOnBlur:S,showNonTappableOptions:x,onFocus:z,onBlur:F,value:t,completedParams:w,onChange:m,onParamsChange:J,source:"full-sdk",setCursor:q});at(()=>{if(!ee)return;let v=window.setTimeout(()=>Z(),650);return()=>window.clearTimeout(v)},[ee,Z]);let it=h>=0?`${E}-option-${h}`:void 0,{inputRef:ke,editorProps:rt,focus:ge,blur:ze,getPlainText:Fe}=ot({segments:Y,newParamId:ee,editingParam:Ie,editingAnchor:ue,caretOffset:a,placeholderText:d,isFocused:o,isDropdownOpen:p,listboxId:E,activeDescendantId:it,autoFocus:R,handleTextChange:O,handleKeyDown:U,handleCaretAfterInput:A,handleCaretMove:ae,startEditingParam:P,replaceEditingRange:se,setFocused:pe});V.current=ke,Bt(()=>{let v=C.current,W=ke.current;if(!v||!W)return;let he=()=>{let Oe=v.firstElementChild;if(!Oe)return;let ct=Oe.getBoundingClientRect(),pt=W.getBoundingClientRect();ct.top>=pt.bottom-2?v.setAttribute("data-aia-pill-wrapped",""):v.removeAttribute("data-aia-pill-wrapped")};he();let He=new ResizeObserver(he);return He.observe(W),()=>He.disconnect()},[Y,$.length,_,ke]),Lt(G,()=>({focus:ge,blur:ze,reset:me,setMode:v=>L.current?.setMode(v)}),[ge,ze,me]);let fe=!!Y.length||B.length>0,Se=Le(()=>{if(!fe)return;let v=Fe(),{rawQuery:W,completedParams:he}=zt(v,B);c({query:v.trim(),raw_query:W,completed_params:he}),me()},[fe,B,c,me,Fe]);j.current=Se;let st=Le(v=>{v.target?.closest("[data-aia-pill]")||ge()},[ge]),lt=g==="inline",dt=g==="dropdown";return Be("div",{ref:H,className:`magicx-aia ${te.container} ${n??""}`,"data-pill-placement":g,"data-options-position":D,"data-animations":k?"on":"off","data-mode":Ot(b),children:[re(Ce,{...nt,showPills:dt}),Be("div",{className:te.inputWrapper,onClick:st,children:[Be("div",{className:te.editorArea,"data-aia-editor":"",children:[re("div",{...rt,className:te.input,"data-aia-input":""}),lt&&(_||$.length>0)&&re("span",{ref:C,className:te.pillListContainer,"data-aia-pill-list-container":"",children:re(ve,{pills:$,activePillIndex:0,activeSelected:f,onSelectPill:y,loading:_})})]}),T===null?null:T===void 0?re(Je,{disabled:!fe,onClick:Se}):re("span",{"data-aia-submit":"",className:te.submitSlot,onClick:v=>{fe&&(v.stopPropagation(),Se())},children:T})]})]})});export{Mt as AIAutocomplete,Ce as AIAutocompleteDropdown,De as useAIAutocomplete};
|
|
997
|
+
`,document.head.appendChild(e)}var Xe={submitButton:"SubmitButton-module_submitButton_otz7H"};import{jsx as Ee}from"react/jsx-runtime";function Je({disabled:e,onClick:d}){return Ee("button",{type:"button","data-aia-submit":"",className:Xe.submitButton,disabled:e,onClick:i=>{i.stopPropagation(),d()},"aria-label":"Submit",children:Ee("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:Ee("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as Et}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Ze,useEffect as ye,useRef as K,useState as Dt}from"react";var Rt={text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!0,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,isActivePillSelected:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,hasTabbedToHighlight:!1};function De({onSubmit:e,onError:d,optionOverrides:i,maskCompletedText:p,apiConfig:o,columns:t=2,dropdownTrigger:s,optionsPosition:l,closeDropdownOnBlur:m,showNonTappableOptions:b,onFocus:R,onBlur:I,value:k,completedParams:S,onChange:v,onParamsChange:T,source:L,setCursor:V}){let r=K(null),[_,B]=Dt(null),O=K(e);O.current=e;let z=K(d);z.current=d;let g=K(v);g.current=v;let q=K(T);q.current=T;let A=K(R);A.current=R;let $=K(I);$.current=I;let E=K(V);E.current=V,ye(()=>{if(typeof document>"u")return;let n=new Et(document.createElement("div"),{renderMode:"headless",apiConfig:o,optionOverrides:i,maskCompletedText:p,columns:t,dropdownTrigger:s,optionsPosition:l,closeDropdownOnBlur:m,showNonTappableOptions:b,source:L,value:k,completedParams:S,onSubmit:(...P)=>O.current?.(...P),onError:(...P)=>z.current?.(...P),onChange:(...P)=>g.current?.(...P),onParamsChange:(...P)=>q.current?.(...P),onFocus:()=>A.current?.(),onBlur:()=>$.current?.(),setCursor:P=>E.current?.(P)});r.current=n,B(n.getState());let C=n.subscribe(P=>B(P));return()=>{C(),n.destroy(),r.current===n&&(r.current=null)}},[]),ye(()=>{k!==void 0&&r.current?.setValue(k)},[k]),ye(()=>{S!==void 0&&r.current?.setCompletedParams(S)},[S]);let Z=JSON.stringify(o??null),U=K(i),G=K(0);if(i!==U.current){let n=U.current,C=i,P=Object.keys(n??{}),ae=Object.keys(C??{});(P.length!==ae.length||ae.some(se=>!n?.[se]||C[se]!==n[se]))&&G.current++,U.current=i}ye(()=>{r.current?.update({apiConfig:o,optionOverrides:i,dropdownTrigger:s,optionsPosition:l,closeDropdownOnBlur:m,showNonTappableOptions:b})},[Z,G.current,s,l,m,b]);let F=K(null);F.current===null&&(F.current={handleTextChange:n=>r.current?.handleTextChange(n),handleKeyDown:n=>{let C="nativeEvent"in n?n.nativeEvent:n;r.current?.handleKeyDown(C)},setFocused:n=>r.current?.setFocused(n),startEditingParam:n=>r.current?.startEditingParam(n),exitEditMode:()=>r.current?.exitEditMode(),handleCaretAfterInput:n=>r.current?.handleCaretAfterInput(n),handleCaretMove:n=>r.current?.handleCaretMove(n),replaceEditingRange:n=>r.current?.replaceEditingRange(n)??!1,setActivePill:n=>r.current?.setActivePill(n),removeLastParam:()=>r.current?.removeLastParam(),clearNewParamId:()=>r.current?.clearNewParamId(),reset:()=>r.current?.reset(),selectOption:n=>r.current?.selectOption(n),setActiveDropdownIndex:n=>r.current?.setActiveDropdownIndex(n),handleFocus:()=>r.current?.setFocused(!0),handleBlur:()=>r.current?.setFocused(!1)});let x=F.current,H=Ze(n=>{let C=n.target.value,ae=C.length>0&&!n.nativeEvent?.isComposing&&C[0]!==C[0].toUpperCase()?C[0].toUpperCase()+C.slice(1):C;r.current?.handleTextChange(ae)},[]),ee=Ze(n=>{r.current?.handleKeyDown(n.nativeEvent)},[]),Y=r.current,c=_??Rt,a=k!==void 0?k:c.text,u=S!==void 0?S:c.completedParams,f=c.actionableSuggestions,y=f[0],h=Y?.listboxId??"",D=c.activeDropdownIndex>=0&&Y?`${h}-option-${c.activeDropdownIndex}`:void 0,M=c.editingParam,Q=M?{type:M.suggestionType,text:M.suggestionPlaceholder,required:!0,options:M.options}:null,pe=Q??y,ke=Q?[Q]:f,ue=!Y||c.isLoading&&!c.editingParam&&!c.inSelectionAnimation;return{completedParams:u,suggestionPills:f,setActivePill:x.setActivePill,removeLastParam:x.removeLastParam,segments:c.segments,newParamId:c.newParamId,clearNewParamId:x.clearNewParamId,suggestions:c.suggestions,activeIndex:c.activeDropdownIndex,isReady:c.isReady,isLoading:ue,isFocused:c.isFocused,isDropdownOpen:c.isDropdownOpen,isActivePillSelected:c.isActivePillSelected,placeholderText:c.placeholderText,listboxId:h,error:c.error,handleTextChange:x.handleTextChange,handleKeyDown:x.handleKeyDown,setFocused:x.setFocused,editingParam:M,editingAnchor:c.editingAnchor,caretOffset:c.caretOffset,startEditingParam:x.startEditingParam,exitEditMode:x.exitEditMode,handleCaretAfterInput:x.handleCaretAfterInput,handleCaretMove:x.handleCaretMove,replaceEditingRange:x.replaceEditingRange,inputProps:{value:a,placeholder:c.placeholderText||void 0,onChange:H,onKeyDown:ee,onFocus:x.handleFocus,onBlur:x.handleBlur,role:"combobox","aria-expanded":c.isDropdownOpen,"aria-activedescendant":D,"aria-autocomplete":"list","aria-controls":h},reset:x.reset,dropdownProps:{suggestions:pe?[{...pe,options:c.filteredOptions}]:[],activeIndex:c.activeDropdownIndex,onSelect:x.selectOption,onHighlight:x.setActiveDropdownIndex,isOpen:c.isDropdownOpen,id:h,pills:ke,activeSelected:c.isActivePillSelected,onPillClick:x.setActivePill,isLoading:ue,hasTabbedToHighlight:c.hasTabbedToHighlight,isInputEmpty:a.trim().length===0,optionsPosition:l??"below"}}}import{extractPlainText as Ye,getCursorOffset as et,plainTextLength as Tt,renderEditableContent as Lt,setCursorOffset as tt}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as W,useEffect as Re,useLayoutEffect as Te,useRef as ie}from"react";var _e;function Bt(){if(_e!==void 0)return _e;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),_e=e.contentEditable==="plaintext-only",_e}function ot(e){let{segments:d,newParamId:i,editingParam:p,editingAnchor:o,caretOffset:t,placeholderText:s,isFocused:l,isDropdownOpen:m,listboxId:b,activeDescendantId:R,autoFocus:I,handleTextChange:k,handleKeyDown:S,handleCaretAfterInput:v,handleCaretMove:T,startEditingParam:L,replaceEditingRange:V,setFocused:r}=e,_=ie(null),B=ie(!1),O=ie(""),z=ie(""),g=ie(null),q=ie(0);g.current=t,Re(()=>{if(!I)return;let a=_.current;a&&(document.activeElement===a?r(!0):a.focus())},[I,r]),Re(()=>{let a=_.current;if(!a)return;let u=a.ownerDocument??document,f=()=>{let y=u.getSelection();if(!y||y.rangeCount===0||!y.anchorNode||!a.contains(y.anchorNode))return;let h=y.anchorNode,Q=(h.nodeType===Node.ELEMENT_NODE?h:h.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if(Q&&Q!==p?.id){L(Q);return}performance.now()-q.current<50||T(et(a))};return u.addEventListener("selectionchange",f),()=>u.removeEventListener("selectionchange",f)},[p,L,T]),Te(()=>{let a=_.current;a&&Lt({input:a,segments:d,newParamId:i,editingParamId:p?.id??null,placeholderText:s??"",isFocused:l})},[d,i,p,s,l]),Te(()=>{let a=O.current,u=i??"";if(O.current=u,!u||u===a)return;let f=_.current;if(!f)return;f.focus();let y=g.current??Tt(f);tt(f,y)},[i]),Te(()=>{let a=z.current,u=p?.id??"";if(z.current=u,!u||u===a||o==null)return;let f=_.current;f&&tt(f,o)},[p,o]);let A=W(()=>{if(B.current)return;let a=_.current;if(!a)return;let u=Ye(a),y=u.length>0&&u[0]!==u[0].toUpperCase()?u[0].toUpperCase()+u.slice(1):u;k(y)},[k]),$=W(()=>{q.current=performance.now(),A();let a=_.current;a&&v(et(a))},[A,v]);Re(()=>{let a=_.current;if(!a)return;let u=f=>{let y=f,h=y.inputType;if(h==="insertParagraph"||h==="insertLineBreak"||h==="insertFromDrop"){f.preventDefault();return}if(h.startsWith("insert")||h.startsWith("delete")){let D=h.startsWith("delete")?"":y.data??"";V(D)&&f.preventDefault()}};return a.addEventListener("beforeinput",u),()=>a.removeEventListener("beforeinput",u)},[V]);let E=W(()=>{B.current=!0},[]),Z=W(()=>{B.current=!1,A()},[A]),U=W(a=>{a.preventDefault();let u=_.current;if(!u)return;let f=(a.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!f)return;let y=u.ownerDocument??document,h=y.getSelection();if(!h||h.rangeCount===0)return;let D=h.getRangeAt(0);if(!u.contains(D.startContainer))return;D.deleteContents();let M=y.createTextNode(f);D.insertNode(M),D.setStartAfter(M),D.collapse(!0),h.removeAllRanges(),h.addRange(D),A()},[A]),G=W(a=>S(a),[S]),F=W(()=>r(!0),[r]),x=W(()=>r(!1),[r]),H=W(()=>_.current?.focus(),[]),ee=W(()=>_.current?.blur(),[]),Y=W(()=>{let a=_.current;return a?Ye(a):""},[]),c=Bt()?"plaintext-only":"true";return{inputRef:_,editorProps:{ref:_,contentEditable:c,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":b,"aria-expanded":m,"aria-activedescendant":R,spellCheck:!0,enterKeyHint:"send",onInput:$,onKeyDown:G,onCompositionStart:E,onCompositionEnd:Z,onPaste:U,onFocus:F,onBlur:x},getPlainText:Y,focus:H,blur:ee}}import{jsx as re,jsxs as Be}from"react/jsx-runtime";function Kt(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var Wt=zt(function({onSubmit:d,onError:i,optionOverrides:p,maskCompletedText:o,className:t,apiConfig:s,columns:l,pillPlacement:m="inline",mode:b="auto",optionsPosition:R="below",animations:I=!0,dropdownTrigger:k,closeDropdownOnBlur:S,showNonTappableOptions:v,autoFocus:T=!0,onFocus:L,onBlur:V,value:r,completedParams:_,onChange:B,onParamsChange:O,submitButton:z},g){let q=ce(null),A=ce(null),$=ce(()=>{}),E=ce(null),Z=ce(null);at(()=>{let w=q.current;if(w)return E.current?E.current.setMode(b):E.current=new Mt(w,b),()=>{E.current?.destroy(),E.current=null}},[b]);let U=Le(w=>{let j=Z.current?.current;j&&(j.focus(),Nt(j,w))},[]),{completedParams:G,suggestionPills:F,setActivePill:x,segments:H,newParamId:ee,clearNewParamId:Y,placeholderText:c,isFocused:a,isDropdownOpen:u,isActivePillSelected:f,isLoading:y,activeIndex:h,listboxId:D,handleTextChange:M,handleKeyDown:Q,setFocused:pe,editingParam:ke,editingAnchor:ue,caretOffset:n,startEditingParam:C,handleCaretAfterInput:P,handleCaretMove:ae,replaceEditingRange:se,dropdownProps:nt,reset:me}=De({onSubmit:w=>$.current(w),onError:i,optionOverrides:p,maskCompletedText:o,apiConfig:s,columns:l,dropdownTrigger:k,optionsPosition:R,closeDropdownOnBlur:S,showNonTappableOptions:v,onFocus:L,onBlur:V,value:r,completedParams:_,onChange:B,onParamsChange:O,source:"full-sdk",setCursor:U});at(()=>{if(!ee)return;let w=window.setTimeout(()=>Y(),650);return()=>window.clearTimeout(w)},[ee,Y]);let it=h>=0?`${D}-option-${h}`:void 0,{inputRef:Ie,editorProps:rt,focus:ge,blur:ze,getPlainText:Fe}=ot({segments:H,newParamId:ee,editingParam:ke,editingAnchor:ue,caretOffset:n,placeholderText:c,isFocused:a,isDropdownOpen:u,listboxId:D,activeDescendantId:it,autoFocus:T,handleTextChange:M,handleKeyDown:Q,handleCaretAfterInput:P,handleCaretMove:ae,startEditingParam:C,replaceEditingRange:se,setFocused:pe});Z.current=Ie,Ht(()=>{let w=A.current,j=Ie.current;if(!w||!j)return;let he=()=>{let Oe=w.firstElementChild;if(!Oe)return;let ct=Oe.getBoundingClientRect(),pt=j.getBoundingClientRect();ct.top>=pt.bottom-2?w.setAttribute("data-aia-pill-wrapped",""):w.removeAttribute("data-aia-pill-wrapped")};he();let He=new ResizeObserver(he);return He.observe(j),()=>He.disconnect()},[H,F.length,y,Ie]),Ft(g,()=>({focus:ge,blur:ze,reset:me,setMode:w=>E.current?.setMode(w)}),[ge,ze,me]);let fe=!!H.length||G.length>0,Se=Le(()=>{if(!fe)return;let w=Fe(),{rawQuery:j,completedParams:he}=Ot(w,G);d({query:w.trim(),raw_query:j,completed_params:he}),me()},[fe,G,d,me,Fe]);$.current=Se;let st=Le(w=>{w.target?.closest("[data-aia-pill]")||ge()},[ge]),lt=m==="inline",dt=m==="dropdown";return Be("div",{ref:q,className:`magicx-aia ${te.container} ${t??""}`,"data-pill-placement":m,"data-options-position":R,"data-animations":I?"on":"off","data-mode":Kt(b),children:[re(Ce,{...nt,showPills:dt}),Be("div",{className:te.inputWrapper,onClick:st,children:[Be("div",{className:te.editorArea,"data-aia-editor":"",children:[re("div",{...rt,className:te.input,"data-aia-input":""}),lt&&(y||F.length>0)&&re("span",{ref:A,className:te.pillListContainer,"data-aia-pill-list-container":"",children:re(ve,{pills:F,activePillIndex:0,activeSelected:f,onSelectPill:x,loading:y})})]}),z===null?null:z===void 0?re(Je,{disabled:!fe,onClick:Se}):re("span",{"data-aia-submit":"",className:te.submitSlot,onClick:w=>{fe&&(w.stopPropagation(),Se())},children:z})]})]})});export{Wt as AIAutocomplete,Ce as AIAutocompleteDropdown,De as useAIAutocomplete};
|
|
997
998
|
//# sourceMappingURL=index.mjs.map
|