@magicx-eng/ai-autocomplete-react 0.6.8 → 0.7.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 +14 -1
- package/dist/index.d.mts +9 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- 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{buildSubmitResult as co,withSkippedParams as uo}from"@magicx-eng/ai-autocomplete-vanilla";import{forwardRef as Ot,useCallback as Te,useEffect as at,useImperativeHandle as Ht,useLayoutEffect as Nt,useRef as pe}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
|
|
@@ -158,7 +158,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
158
158
|
opacity: 0;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
`,document.head.appendChild(e)}var
|
|
161
|
+
`,document.head.appendChild(e)}var ee={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",aiaPillReveal:"AIAutocomplete-module_aiaPillReveal_wf05b"};import{useEffect as St,useRef as At,useState as Ct}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
|
|
162
162
|
* Built-in appearance defaults \u2014 zero specificity via :where().
|
|
163
163
|
* Consumer CSS always wins without !important.
|
|
164
164
|
*
|
|
@@ -521,7 +521,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
521
521
|
opacity: 0.25;
|
|
522
522
|
}
|
|
523
523
|
}
|
|
524
|
-
`,document.head.appendChild(e)}var
|
|
524
|
+
`,document.head.appendChild(e)}var oe={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"};import{ATTRIBUTION_URL as ut,buildAttributionUrl as mt,getFooterHint as gt}from"@magicx-eng/ai-autocomplete-vanilla";import{useEffect as ht,useState as ft}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-5259a217")){let e=document.createElement("style");e.id="ac-style-5259a217",e.textContent=`@layer layout {
|
|
525
525
|
.aia-cluster {
|
|
526
526
|
display: flex;
|
|
527
527
|
flex-wrap: wrap;
|
|
@@ -563,7 +563,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
563
563
|
justify-content: space-around;
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
|
-
`,document.head.appendChild(e)}import{jsx as He}from"react/jsx-runtime";function le({gap:e,align:
|
|
566
|
+
`,document.head.appendChild(e)}import{jsx as He}from"react/jsx-runtime";function le({gap:e,align:d="center",justify:o="start",noWrap:s=!1,inline:r=!1,className:i,children:u,...m}){let h=e?{"--aia-cluster-gap":e}:void 0,v={className:i?`aia-cluster ${i}`:"aia-cluster","data-align":d,"data-justify":o,"data-nowrap":s||void 0,"data-inline":r||void 0,style:h,...m};return r?He("span",{...v,children:u}):He("div",{...v,children:u})}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 so it stays clear of the
|
|
567
567
|
dropdown's rounded edges. The top inset (--aia-footer-gap) adds breathing
|
|
568
568
|
room above the hint/branding row so the footer doesn't butt against the last
|
|
569
569
|
option row \u2014 additive to the dropdown's 8px section gap. */
|
|
@@ -682,7 +682,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
682
682
|
justify-content: flex-end;
|
|
683
683
|
}
|
|
684
684
|
}
|
|
685
|
-
`,document.head.appendChild(e)}var q={footer:"DropdownFooter-module_footer_qQQ7x",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",row:"DropdownFooter-module_row_BgZ6Q"};import{jsx as de,jsxs as
|
|
685
|
+
`,document.head.appendChild(e)}var q={footer:"DropdownFooter-module_footer_qQQ7x",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",row:"DropdownFooter-module_row_BgZ6Q"};import{jsx as de,jsxs as Ie}from"react/jsx-runtime";function Ne({isOptionHighlighted:e=!1,isInputEmpty:d=!1}){let{key:o,hint:s}=gt(e,d),[r,i]=ft(ut);return ht(()=>{i(mt())},[]),de("footer",{className:q.footer,"data-aia-footer":"",children:Ie(le,{justify:"between",noWrap:!0,className:q.row,children:[Ie(le,{gap:"5px",className:q.hintGroup,children:[de("kbd",{className:q.key,children:o}),de("span",{className:q.hint,children:s})]}),Ie("a",{className:q.brandLink,href:r,target:"_blank",rel:"noopener noreferrer",children:[de("span",{className:q.brand,children:"AI"}),de("span",{className:q.badge,children:"Autocomplete"})]})]})})}if(typeof document<"u"&&!document.getElementById("ac-style-199d0432")){let e=document.createElement("style");e.id="ac-style-199d0432",e.textContent=`/* ParamPill (Figma "ParamPill") \u2014 unfilled suggestion pill: transparent fill
|
|
686
686
|
with a dashed border. ~28px via 6px padding + 14px text + the 1px border
|
|
687
687
|
(border-box). */
|
|
688
688
|
.ParamPill-module_pill_6Ga7S {
|
|
@@ -734,7 +734,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
734
734
|
opacity: 0;
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
|
-
`,document.head.appendChild(e)}var J={pill:"ParamPill-module_pill_6Ga7S",fadeIn:"ParamPill-module_fadeIn_Ux4eQ",rounded:"ParamPill-module_rounded_y7xA9",skeleton:"ParamPill-module_skeleton_57P0T",skeletonPulse:"ParamPill-module_skeletonPulse_xGcUy"};import{jsx as
|
|
737
|
+
`,document.head.appendChild(e)}var J={pill:"ParamPill-module_pill_6Ga7S",fadeIn:"ParamPill-module_fadeIn_Ux4eQ",rounded:"ParamPill-module_rounded_y7xA9",skeleton:"ParamPill-module_skeleton_57P0T",skeletonPulse:"ParamPill-module_skeletonPulse_xGcUy"};import{jsx as bt}from"react/jsx-runtime";var Pe={selected:1,first:.7,next:.4,last:.2};function Ke({label:e,state:d,rounded:o,loading:s,onClick:r}){let i=[J.pill,o?J.rounded:"",s?J.skeleton:""].filter(Boolean).join(" ");return bt("button",{type:"button","data-aia-pill":"","data-aia-loading":s?"":void 0,tabIndex:-1,contentEditable:!1,suppressContentEditableWarning:!0,className:i,style:{opacity:Pe[d]},onMouseDown:u=>u.preventDefault(),onClick:s?void 0:r,disabled:s,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 {
|
|
738
738
|
position: relative;
|
|
739
739
|
z-index: 1;
|
|
740
740
|
pointer-events: auto;
|
|
@@ -744,7 +744,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
744
744
|
align-items: center;
|
|
745
745
|
vertical-align: middle;
|
|
746
746
|
}
|
|
747
|
-
`,document.head.appendChild(e)}var
|
|
747
|
+
`,document.head.appendChild(e)}var Se={list:"PillList-module_list_qvLqO"};import{jsx as fe}from"react/jsx-runtime";var vt=[125,69];function We(e){return e===0?"first":e===1?"next":"last"}function be({pills:e,activePillIndex:d,onSelectPill:o,activeSelected:s,rounded:r,loading:i}){return i&&e.length===0?fe("span",{className:Se.list,"data-aia-pill-list-loading":"",children:vt.map((u,m)=>fe("span",{"data-aia-pill-skeleton":"",className:`${J.pill} ${r?J.rounded:""} ${J.skeleton}`,style:{width:u,opacity:Pe[We(m)]}},`skel-${u}`))}):fe("span",{className:Se.list,"data-aia-pill-list-loading":i?"":void 0,children:e.map((u,m)=>{let h=!!s&&m===d;return fe(Ke,{label:u.text,state:h?"selected":We(m),selected:h,rounded:r,loading:i,onClick:()=>o(m)},`${u.type}-${u.text}`)})})}import{useLayoutEffect as xt,useRef as wt}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 {
|
|
748
748
|
.aia-grid {
|
|
749
749
|
display: grid;
|
|
750
750
|
grid-template-columns: repeat(
|
|
@@ -779,7 +779,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
779
779
|
border-radius: 3px;
|
|
780
780
|
}
|
|
781
781
|
}
|
|
782
|
-
`,document.head.appendChild(e)}import{jsx as
|
|
782
|
+
`,document.head.appendChild(e)}import{jsx as yt}from"react/jsx-runtime";function Ge({min:e="16rem",max:d,gap:o,scroll:s=!1,maxHeight:r,scrollResetKey:i,className:u,children:m,...h}){let v=wt(null);xt(()=>{if(i===void 0)return;let k=v.current;k&&(k.scrollTop=0)},[i]);let _={"--aia-grid-min":e};return d&&(_["--aia-grid-max"]=d),o&&(_["--aia-grid-gap"]=o),r&&(_["--aia-grid-max-height"]=r),yt("div",{ref:v,className:u?`aia-grid ${u}`:"aia-grid","data-scroll":s||void 0,style:_,...h,children:m})}import{useEffect as kt,useRef as _t,useState as It}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 {
|
|
783
783
|
position: relative;
|
|
784
784
|
overflow: visible;
|
|
785
785
|
display: flex;
|
|
@@ -1129,7 +1129,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
1129
1129
|
filter: brightness(0.55);
|
|
1130
1130
|
}
|
|
1131
1131
|
}
|
|
1132
|
-
`,document.head.appendChild(e)}var
|
|
1132
|
+
`,document.head.appendChild(e)}var B={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 ve,jsxs as Ue}from"react/jsx-runtime";function je({option:e,isHighlighted:d,onSelect:o,onHighlight:s,id:r,loading:i}){let[u,m]=It(!1),h=_t(void 0);kt(()=>()=>clearTimeout(h.current),[]);let v=()=>{i||!e.is_tappable||u||(m(!0),o(e),clearTimeout(h.current),h.current=setTimeout(()=>m(!1),500))},_=[B.item,d&&!i?B.highlighted:"",e.is_tappable?B.tappable:B.nonTappable,u?B.pressed:""].filter(Boolean).join(" ");return Ue("div",{id:r,role:"option","data-aia-option":"","data-aia-loading":i?"":void 0,"aria-selected":d,className:_,tabIndex:i||!e.is_tappable?-1:0,onClick:v,onKeyDown:k=>{!i&&e.is_tappable&&(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),v())},onMouseEnter:!i&&e.is_tappable?s:void 0,children:[ve("div",{className:B.streaks}),ve("div",{className:B.streaksVert}),Ue("span",{className:B.content,children:[ve("span",{className:B.text,children:e.icon?`${e.icon} ${e.text}`:e.text}),e.tag&&ve("span",{className:B.tag,children:e.tag})]})]})}import{jsx as Ve}from"react/jsx-runtime";function $e({options:e,activeIndex:d,onSelect:o,onHighlight:s,listboxId:r,loading:i,groupKey:u}){return Ve(Ge,{min:"250px",max:"1fr",gap:"0",scroll:!0,scrollResetKey:u,children:e.map((m,h)=>Ve(je,{option:m,isHighlighted:h===d,onSelect:o,onHighlight:()=>s(h),id:`${r}-option-${h}`,loading:i},m.text))})}if(typeof document<"u"&&!document.getElementById("ac-style-8414cd5f")){let e=document.createElement("style");e.id="ac-style-8414cd5f",e.textContent=`@layer layout {
|
|
1133
1133
|
.aia-stack {
|
|
1134
1134
|
display: flex;
|
|
1135
1135
|
flex-direction: column;
|
|
@@ -1146,7 +1146,7 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
1146
1146
|
}
|
|
1147
1147
|
/* data-align="stretch" is the flex default \u2014 no rule needed. */
|
|
1148
1148
|
}
|
|
1149
|
-
`,document.head.appendChild(e)}import{jsx as
|
|
1149
|
+
`,document.head.appendChild(e)}import{jsx as Pt}from"react/jsx-runtime";function qe({space:e,align:d="stretch",className:o,children:s,...r}){let i=e?{"--aia-stack-space":e}:void 0;return Pt("div",{className:o?`aia-stack ${o}`:"aia-stack","data-align":d,style:i,...r,children:s})}import{jsx as te,jsxs as Dt}from"react/jsx-runtime";var Et=[159,119,164];function Rt(e){let d=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[o,s]=Ct(d);if(St(()=>{if(e!=="auto"||typeof window>"u"||typeof window.matchMedia!="function")return;let r=window.matchMedia("(prefers-color-scheme: dark)"),i=()=>s(r.matches);return r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),e!==void 0)return e==="auto"?o?"dark":"light":e}function Ae({suggestions:e,activeIndex:d,onSelect:o,onHighlight:s,isOpen:r,id:i,className:u,pills:m,onPillClick:h,showPills:v=!0,activeSelected:_=!1,isLoading:k=!1,isInputEmpty:C=!1,optionsPosition:E="below",mode:G}){let H=Rt(G),Q=H!==void 0,U=e[0]?.options??[],n=!!(m&&m.length>0&&h),x=r&&(U.length>0||v&&n||k),D={suggestions:e,activeIndex:d,pills:m,showPills:v,activeSelected:_,isLoading:k,isInputEmpty:C},N=At(D);x&&(N.current=D);let b=x?D:N.current,T=b.suggestions[0],L=T?.options??[],S=b.activeIndex>=0&&!!L[b.activeIndex]?.is_tappable,K=!!(b.pills&&b.pills.length>0&&h),R=b.showPills&&K,Z=b.showPills&&!K&&b.isLoading,j=R||Z,F=L.length>0,W=b.isLoading&&!F;return te("div",{id:i,role:"listbox","data-aia-dropdown":"","data-options-position":E,"data-mode":H,"data-aia-loading":b.isLoading?"":void 0,className:`${Q?"magicx-aia ":""}${oe.dropdown} ${x?oe.visible:""} ${u??""}`,onMouseDown:f=>f.preventDefault(),children:Dt(qe,{space:"8px",children:[j&&te(le,{noWrap:!0,className:oe.pillBar,"data-aia-pillbar":"",children:te(be,{pills:b.pills??[],activePillIndex:0,activeSelected:b.activeSelected,onSelectPill:h??(()=>{}),rounded:!0,loading:b.isLoading})}),F&&te($e,{options:L,activeIndex:b.activeIndex,onSelect:o,onHighlight:s,listboxId:i,loading:b.isLoading,groupKey:T?`${T.type} ${T.text}`:""}),W&&te("div",{className:oe.skeletonBars,"data-aia-skeleton-bars":"",children:Et.map(f=>te("span",{className:oe.skeletonBar,style:{width:f}},`bar-${f}`))}),te(Ne,{isOptionHighlighted:S,isInputEmpty:b.isInputEmpty})]})})}import{buildSubmitResult as Kt,ModeController as Wt,setCursorOffset as Gt}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 {
|
|
1150
1150
|
flex-shrink: 0;
|
|
1151
1151
|
width: 32px;
|
|
1152
1152
|
height: 32px;
|
|
@@ -1181,5 +1181,5 @@ import{forwardRef as Mt,useCallback as Le,useEffect as at,useImperativeHandle as
|
|
|
1181
1181
|
);
|
|
1182
1182
|
cursor: default;
|
|
1183
1183
|
}
|
|
1184
|
-
`,document.head.appendChild(e)}var Qe={submitButton:"SubmitButton-module_submitButton_otz7H"};import{jsx as Ee}from"react/jsx-runtime";function Ze({disabled:e,onClick:l}){return Ee("button",{type:"button","data-aia-submit":"",className:Qe.submitButton,disabled:e,onClick:o=>{o.stopPropagation(),l()},"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 Dt}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Xe,useEffect as we,useRef as O,useState as Tt}from"react";var Lt={text:"",completedParams:[],identifiedParams:[],pendingSpan:null,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};function Re({onSubmit:e,onError:l,optionOverrides:o,maskCompletedText:s,apiConfig:r,columns:i=2,dropdownTrigger:u,optionsPosition:m,closeDropdownOnBlur:g,showNonTappableOptions:x,onFocus:k,onBlur:_,value:C,completedParams:E,onChange:U,onParamsChange:N,source:Q,setCursor:j}){let n=O(null),[w,D]=Tt(null),K=O(e);K.current=e;let f=O(l);f.current=l;let T=O(U);T.current=U;let L=O(N);L.current=N;let S=O(k);S.current=k;let W=O(_);W.current=_;let R=O(j);R.current=j,we(()=>{if(typeof document>"u")return;let a=new Dt(document.createElement("div"),{renderMode:"headless",apiConfig:r,optionOverrides:o,maskCompletedText:s,columns:i,dropdownTrigger:u,optionsPosition:m,closeDropdownOnBlur:g,showNonTappableOptions:x,source:Q,value:C,completedParams:E,onSubmit:(...I)=>K.current?.(...I),onError:(...I)=>f.current?.(...I),onChange:(...I)=>T.current?.(...I),onParamsChange:(...I)=>L.current?.(...I),onFocus:()=>S.current?.(),onBlur:()=>W.current?.(),setCursor:I=>R.current?.(I)});n.current=a,D(a.getState());let P=a.subscribe(I=>D(I));return()=>{P(),a.destroy(),n.current===a&&(n.current=null)}},[]),we(()=>{C!==void 0&&n.current?.setValue(C)},[C]),we(()=>{E!==void 0&&n.current?.setCompletedParams(E)},[E]);let Z=JSON.stringify(r??null),V=O(o),z=O(0);if(o!==V.current){let a=V.current,P=o,I=Object.keys(a??{}),oe=Object.keys(P??{});(I.length!==oe.length||oe.some(se=>!a?.[se]||P[se]!==a[se]))&&z.current++,V.current=o}we(()=>{n.current?.update({apiConfig:r,optionOverrides:o,dropdownTrigger:u,optionsPosition:m,closeDropdownOnBlur:g,showNonTappableOptions:x})},[Z,z.current,u,m,g,x]);let F=O(null);F.current===null&&(F.current={handleTextChange:a=>n.current?.handleTextChange(a),handleKeyDown:a=>{let P="nativeEvent"in a?a.nativeEvent:a;n.current?.handleKeyDown(P)},setFocused:a=>n.current?.setFocused(a),startEditingParam:a=>n.current?.startEditingParam(a),exitEditMode:()=>n.current?.exitEditMode(),handleCaretAfterInput:a=>n.current?.handleCaretAfterInput(a),handleCaretMove:a=>n.current?.handleCaretMove(a),replaceEditingRange:a=>n.current?.replaceEditingRange(a)??!1,setActivePill:a=>n.current?.setActivePill(a),removeLastParam:()=>n.current?.removeLastParam(),clearNewParamId:()=>n.current?.clearNewParamId(),reset:()=>n.current?.reset(),selectOption:a=>n.current?.selectOption(a),setActiveDropdownIndex:a=>n.current?.setActiveDropdownIndex(a),handleFocus:()=>n.current?.setFocused(!0),handleBlur:()=>n.current?.setFocused(!1)});let b=F.current,Y=Xe(a=>{let P=a.target.value,oe=P.length>0&&!a.nativeEvent?.isComposing&&P[0]!==P[0].toUpperCase()?P[0].toUpperCase()+P.slice(1):P;n.current?.handleTextChange(oe)},[]),ee=Xe(a=>{n.current?.handleKeyDown(a.nativeEvent)},[]),X=n.current,p=w??Lt,t=C!==void 0?C:p.text,d=E!==void 0?E:p.completedParams,c=p.actionableSuggestions,v=c[0],h=X?.listboxId??"",A=p.activeDropdownIndex>=0&&X?`${h}-option-${p.activeDropdownIndex}`:void 0,B=p.editingParam,$=B?{type:B.suggestionType,text:B.suggestionPlaceholder,required:!0,options:B.options}:null,ce=$??v,_e=$?[$]:c,ue=!X||p.isLoading&&!p.editingParam&&!p.inSelectionAnimation;return{completedParams:d,suggestionPills:c,setActivePill:b.setActivePill,removeLastParam:b.removeLastParam,segments:p.segments,newParamId:p.newParamId,clearNewParamId:b.clearNewParamId,suggestions:p.suggestions,activeIndex:p.activeDropdownIndex,isReady:p.isReady,isLoading:ue,isFocused:p.isFocused,isDropdownOpen:p.isDropdownOpen,isActivePillSelected:p.isActivePillSelected,placeholderText:p.placeholderText,listboxId:h,error:p.error,handleTextChange:b.handleTextChange,handleKeyDown:b.handleKeyDown,setFocused:b.setFocused,editingParam:B,editingAnchor:p.editingAnchor,caretOffset:p.caretOffset,startEditingParam:b.startEditingParam,exitEditMode:b.exitEditMode,handleCaretAfterInput:b.handleCaretAfterInput,handleCaretMove:b.handleCaretMove,replaceEditingRange:b.replaceEditingRange,inputProps:{value:t,placeholder:p.placeholderText||void 0,onChange:Y,onKeyDown:ee,onFocus:b.handleFocus,onBlur:b.handleBlur,role:"combobox","aria-expanded":p.isDropdownOpen,"aria-activedescendant":A,"aria-autocomplete":"list","aria-controls":h},reset:b.reset,dropdownProps:{suggestions:ce?[{...ce,options:p.filteredOptions}]:[],activeIndex:p.activeDropdownIndex,onSelect:b.selectOption,onHighlight:b.setActiveDropdownIndex,isOpen:p.isDropdownOpen,id:h,pills:_e,activeSelected:p.isActivePillSelected,onPillClick:b.setActivePill,isLoading:ue,isInputEmpty:t.trim().length===0,optionsPosition:m??"below"}}}import{extractPlainText as Je,getCursorOffset as Ye,plainTextLength as zt,renderEditableContent as Ft,setCursorOffset as et}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as H,useEffect as De,useLayoutEffect as Te,useRef as ne}from"react";var ye;function Bt(){if(ye!==void 0)return ye;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),ye=e.contentEditable==="plaintext-only",ye}function tt(e){let{segments:l,newParamId:o,editingParam:s,editingAnchor:r,caretOffset:i,placeholderText:u,isFocused:m,isDropdownOpen:g,listboxId:x,activeDescendantId:k,autoFocus:_,handleTextChange:C,handleKeyDown:E,handleCaretAfterInput:U,handleCaretMove:N,startEditingParam:Q,replaceEditingRange:j,setFocused:n}=e,w=ne(null),D=ne(!1),K=ne(""),f=ne(""),T=ne(null),L=ne(0);T.current=i,De(()=>{if(!_)return;let t=w.current;if(!t)return;document.activeElement===t?n(!0):t.focus();let d=t.ownerDocument??document,c=d.getSelection(),v=c&&c.rangeCount>0&&t.contains(c.anchorNode);if(c&&!v){let h=d.createRange();h.selectNodeContents(t),h.collapse(!0),c.removeAllRanges(),c.addRange(h)}},[_,n]),De(()=>{let t=w.current;if(!t)return;let d=t.ownerDocument??document,c=()=>{let v=d.getSelection();if(!v||v.rangeCount===0||!v.anchorNode||!t.contains(v.anchorNode))return;let h=v.anchorNode,$=(h.nodeType===Node.ELEMENT_NODE?h:h.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if($&&$!==s?.id){Q($);return}performance.now()-L.current<50||N(Ye(t))};return d.addEventListener("selectionchange",c),()=>d.removeEventListener("selectionchange",c)},[s,Q,N]),Te(()=>{let t=w.current;t&&Ft({input:t,segments:l,newParamId:o,editingParamId:s?.id??null,placeholderText:u??"",isFocused:m})},[l,o,s,u,m]),Te(()=>{let t=K.current,d=o??"";if(K.current=d,!d||d===t)return;let c=w.current;if(!c)return;c.focus();let v=T.current??zt(c);et(c,v)},[o]),Te(()=>{let t=f.current,d=s?.id??"";if(f.current=d,!d||d===t||r==null)return;let c=w.current;c&&et(c,r)},[s,r]);let S=H(()=>{if(D.current)return;let t=w.current;if(!t)return;let d=Je(t),v=d.length>0&&d[0]!==d[0].toUpperCase()?d[0].toUpperCase()+d.slice(1):d;C(v)},[C]),W=H(()=>{L.current=performance.now(),S();let t=w.current;t&&U(Ye(t))},[S,U]);De(()=>{let t=w.current;if(!t)return;let d=c=>{let v=c,h=v.inputType;if(h==="insertParagraph"||h==="insertLineBreak"||h==="insertFromDrop"){c.preventDefault();return}if(h.startsWith("insert")||h.startsWith("delete")){let A=h.startsWith("delete")?"":v.data??"";j(A)&&c.preventDefault()}};return t.addEventListener("beforeinput",d),()=>t.removeEventListener("beforeinput",d)},[j]);let R=H(()=>{D.current=!0},[]),Z=H(()=>{D.current=!1,S()},[S]),V=H(t=>{t.preventDefault();let d=w.current;if(!d)return;let c=(t.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!c)return;let v=d.ownerDocument??document,h=v.getSelection();if(!h||h.rangeCount===0)return;let A=h.getRangeAt(0);if(!d.contains(A.startContainer))return;A.deleteContents();let B=v.createTextNode(c);A.insertNode(B),A.setStartAfter(B),A.collapse(!0),h.removeAllRanges(),h.addRange(A),S()},[S]),z=H(t=>E(t),[E]),F=H(()=>n(!0),[n]),b=H(()=>n(!1),[n]),Y=H(()=>w.current?.focus(),[]),ee=H(()=>w.current?.blur(),[]),X=H(()=>{let t=w.current;return t?Je(t):""},[]),p=Bt()?"plaintext-only":"true";return{inputRef:w,editorProps:{ref:w,contentEditable:p,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":x,"aria-expanded":g,"aria-activedescendant":k,spellCheck:!0,enterKeyHint:"send",onInput:W,onKeyDown:z,onCompositionStart:R,onCompositionEnd:Z,onPaste:V,onFocus:F,onBlur:b},getPlainText:X,focus:Y,blur:ee}}import{jsx as re,jsxs as ze}from"react/jsx-runtime";function Gt(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var Ut=Mt(function({onSubmit:l,onError:o,optionOverrides:s,maskCompletedText:r,className:i,apiConfig:u,columns:m,pillPlacement:g="dropdown",mode:x="auto",optionsPosition:k="below",animations:_=!0,dropdownTrigger:C,closeDropdownOnBlur:E,showNonTappableOptions:U,autoFocus:N=!0,onFocus:Q,onBlur:j,value:n,completedParams:w,onChange:D,onParamsChange:K,submitButton:f},T){let L=pe(null),S=pe(null),W=pe(()=>{}),R=pe(null),Z=pe(null);at(()=>{let y=L.current;if(y)return R.current?R.current.setMode(x):R.current=new Kt(y,x),()=>{R.current?.destroy(),R.current=null}},[x]);let V=Le(y=>{let G=Z.current?.current;G&&(G.focus(),Wt(G,y))},[]),{completedParams:z,suggestionPills:F,setActivePill:b,segments:Y,newParamId:ee,clearNewParamId:X,placeholderText:p,isFocused:t,isDropdownOpen:d,isActivePillSelected:c,isLoading:v,activeIndex:h,listboxId:A,handleTextChange:B,handleKeyDown:$,setFocused:ce,editingParam:_e,editingAnchor:ue,caretOffset:a,startEditingParam:P,handleCaretAfterInput:I,handleCaretMove:oe,replaceEditingRange:se,dropdownProps:ot,reset:me}=Re({onSubmit:y=>W.current(y),onError:o,optionOverrides:s,maskCompletedText:r,apiConfig:u,columns:m,dropdownTrigger:C,optionsPosition:k,closeDropdownOnBlur:E,showNonTappableOptions:U,onFocus:Q,onBlur:j,value:n,completedParams:w,onChange:D,onParamsChange:K,source:"full-sdk",setCursor:V});at(()=>{if(!ee)return;let y=window.setTimeout(()=>X(),650);return()=>window.clearTimeout(y)},[ee,X]);let it=h>=0?`${A}-option-${h}`:void 0,{inputRef:ke,editorProps:nt,focus:ge,blur:Fe,getPlainText:Be}=tt({segments:Y,newParamId:ee,editingParam:_e,editingAnchor:ue,caretOffset:a,placeholderText:p,isFocused:t,isDropdownOpen:d,listboxId:A,activeDescendantId:it,autoFocus:N,handleTextChange:B,handleKeyDown:$,handleCaretAfterInput:I,handleCaretMove:oe,startEditingParam:P,replaceEditingRange:se,setFocused:ce});Z.current=ke,Ht(()=>{let y=S.current,G=ke.current;if(!y||!G)return;let fe=()=>{let Oe=y.firstElementChild;if(!Oe)return;let dt=Oe.getBoundingClientRect(),pt=G.getBoundingClientRect();dt.top>=pt.bottom-2?y.setAttribute("data-aia-pill-wrapped",""):y.removeAttribute("data-aia-pill-wrapped")};fe();let Me=new ResizeObserver(fe);return Me.observe(G),()=>Me.disconnect()},[Y,F.length,v,ke]),Ot(T,()=>({focus:ge,blur:Fe,reset:me,setMode:y=>R.current?.setMode(y)}),[ge,Fe,me]);let he=!!Y.length||z.length>0,Ie=Le(()=>{if(!he)return;let y=Be(),{rawQuery:G,completedParams:fe}=Nt(y,z);l({query:y.trim(),raw_query:G,completed_params:fe}),me()},[he,z,l,me,Be]);W.current=Ie;let rt=Le(y=>{y.target?.closest("[data-aia-pill]")||ge()},[ge]),st=g==="inline",lt=g==="dropdown";return ze("div",{ref:L,className:`magicx-aia ${te.container} ${i??""}`,"data-pill-placement":g,"data-options-position":k,"data-animations":_?"on":"off","data-mode":Gt(x),children:[re(Ce,{...ot,showPills:lt}),ze("div",{className:te.inputWrapper,onClick:rt,children:[ze("div",{className:te.editorArea,"data-aia-editor":"",children:[re("div",{...nt,className:te.input,"data-aia-input":""}),st&&(v||F.length>0)&&re("span",{ref:S,className:te.pillListContainer,"data-aia-pill-list-container":"",children:re(ve,{pills:F,activePillIndex:0,activeSelected:c,onSelectPill:b,loading:v})})]}),f===null?null:f===void 0?re(Ze,{disabled:!he,onClick:Ie}):re("span",{"data-aia-submit":"",className:te.submitSlot,onClick:y=>{he&&(y.stopPropagation(),Ie())},children:f})]})]})});export{Ut as AIAutocomplete,Ce as AIAutocompleteDropdown,Re as useAIAutocomplete};
|
|
1184
|
+
`,document.head.appendChild(e)}var Qe={submitButton:"SubmitButton-module_submitButton_otz7H"};import{jsx as Ce}from"react/jsx-runtime";function Ze({disabled:e,onClick:d}){return Ce("button",{type:"button","data-aia-submit":"",className:Qe.submitButton,disabled:e,onClick:o=>{o.stopPropagation(),d()},"aria-label":"Submit",children:Ce("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:Ce("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as Tt}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Xe,useEffect as xe,useRef as M,useState as Lt}from"react";var zt={text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,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};function Ee({onSubmit:e,onError:d,optionOverrides:o,maskCompletedText:s,apiConfig:r,columns:i=2,dropdownTrigger:u,optionsPosition:m,closeDropdownOnBlur:h,showNonTappableOptions:v,onFocus:_,onBlur:k,value:C,completedParams:E,onChange:G,onParamsChange:H,source:Q,setCursor:U}){let n=M(null),[x,D]=Lt(null),N=M(e);N.current=e;let b=M(d);b.current=d;let T=M(G);T.current=G;let L=M(H);L.current=H;let S=M(_);S.current=_;let K=M(k);K.current=k;let R=M(U);R.current=U,xe(()=>{if(typeof document>"u")return;let a=new Tt(document.createElement("div"),{renderMode:"headless",apiConfig:r,optionOverrides:o,maskCompletedText:s,columns:i,dropdownTrigger:u,optionsPosition:m,closeDropdownOnBlur:h,showNonTappableOptions:v,source:Q,value:C,completedParams:E,onSubmit:(...I)=>N.current?.(...I),onError:(...I)=>b.current?.(...I),onChange:(...I)=>T.current?.(...I),onParamsChange:(...I)=>L.current?.(...I),onFocus:()=>S.current?.(),onBlur:()=>K.current?.(),setCursor:I=>R.current?.(I)});n.current=a,D(a.getState());let P=a.subscribe(I=>D(I));return()=>{P(),a.destroy(),n.current===a&&(n.current=null)}},[]),xe(()=>{C!==void 0&&n.current?.setValue(C)},[C]),xe(()=>{E!==void 0&&n.current?.setCompletedParams(E)},[E]);let Z=JSON.stringify(r??null),j=M(o),F=M(0);if(o!==j.current){let a=j.current,P=o,I=Object.keys(a??{}),ae=Object.keys(P??{});(I.length!==ae.length||ae.some(se=>!a?.[se]||P[se]!==a[se]))&&F.current++,j.current=o}xe(()=>{n.current?.update({apiConfig:r,optionOverrides:o,dropdownTrigger:u,optionsPosition:m,closeDropdownOnBlur:h,showNonTappableOptions:v})},[Z,F.current,u,m,h,v]);let W=M(null);W.current===null&&(W.current={handleTextChange:a=>n.current?.handleTextChange(a),handleKeyDown:a=>{let P="nativeEvent"in a?a.nativeEvent:a;n.current?.handleKeyDown(P)},setFocused:a=>n.current?.setFocused(a),startEditingParam:a=>n.current?.startEditingParam(a),exitEditMode:()=>n.current?.exitEditMode(),handleCaretAfterInput:a=>n.current?.handleCaretAfterInput(a),handleCaretMove:a=>n.current?.handleCaretMove(a),replaceEditingRange:a=>n.current?.replaceEditingRange(a)??!1,setActivePill:a=>n.current?.setActivePill(a),removeLastParam:()=>n.current?.removeLastParam(),clearNewParamId:()=>n.current?.clearNewParamId(),reset:()=>n.current?.reset(),selectOption:a=>n.current?.selectOption(a),setActiveDropdownIndex:a=>n.current?.setActiveDropdownIndex(a),handleFocus:()=>n.current?.setFocused(!0),handleBlur:()=>n.current?.setFocused(!1)});let f=W.current,re=Xe(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;n.current?.handleTextChange(ae)},[]),Y=Xe(a=>{n.current?.handleKeyDown(a.nativeEvent)},[]),V=n.current,l=x??zt,t=C!==void 0?C:l.text,p=E!==void 0?E:l.completedParams,c=l.actionableSuggestions,w=c[0],g=V?.listboxId??"",A=l.activeDropdownIndex>=0&&V?`${g}-option-${l.activeDropdownIndex}`:void 0,z=l.editingParam,$=z?{type:z.suggestionType,text:z.suggestionPlaceholder,required:!0,options:z.options}:null,ce=$??w,ye=$?[$]:c,ue=!V||l.isLoading&&!l.editingParam&&!l.inSelectionAnimation;return{completedParams:p,skippedParams:l.skippedParams,suggestionPills:c,setActivePill:f.setActivePill,removeLastParam:f.removeLastParam,segments:l.segments,newParamId:l.newParamId,clearNewParamId:f.clearNewParamId,suggestions:l.suggestions,activeIndex:l.activeDropdownIndex,isReady:l.isReady,isLoading:ue,isFocused:l.isFocused,isDropdownOpen:l.isDropdownOpen,isActivePillSelected:l.isActivePillSelected,placeholderText:l.placeholderText,listboxId:g,error:l.error,handleTextChange:f.handleTextChange,handleKeyDown:f.handleKeyDown,setFocused:f.setFocused,editingParam:z,editingAnchor:l.editingAnchor,caretOffset:l.caretOffset,startEditingParam:f.startEditingParam,exitEditMode:f.exitEditMode,handleCaretAfterInput:f.handleCaretAfterInput,handleCaretMove:f.handleCaretMove,replaceEditingRange:f.replaceEditingRange,inputProps:{value:t,placeholder:l.placeholderText||void 0,onChange:re,onKeyDown:Y,onFocus:f.handleFocus,onBlur:f.handleBlur,role:"combobox","aria-expanded":l.isDropdownOpen,"aria-activedescendant":A,"aria-autocomplete":"list","aria-controls":g},reset:f.reset,dropdownProps:{suggestions:ce?[{...ce,options:l.filteredOptions}]:[],activeIndex:l.activeDropdownIndex,onSelect:f.selectOption,onHighlight:f.setActiveDropdownIndex,isOpen:l.isDropdownOpen,id:g,pills:ye,activeSelected:l.isActivePillSelected,onPillClick:f.setActivePill,isLoading:ue,isInputEmpty:t.trim().length===0,optionsPosition:m??"below"}}}import{extractPlainText as Je,getCursorOffset as Ye,plainTextLength as Ft,renderEditableContent as Bt,setCursorOffset as et}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as O,useEffect as Re,useLayoutEffect as De,useRef as ie}from"react";var we;function Mt(){if(we!==void 0)return we;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),we=e.contentEditable==="plaintext-only",we}function tt(e){let{segments:d,newParamId:o,editingParam:s,editingAnchor:r,caretOffset:i,placeholderText:u,isFocused:m,isDropdownOpen:h,listboxId:v,activeDescendantId:_,autoFocus:k,handleTextChange:C,handleKeyDown:E,handleCaretAfterInput:G,handleCaretMove:H,startEditingParam:Q,replaceEditingRange:U,setFocused:n}=e,x=ie(null),D=ie(!1),N=ie(""),b=ie(""),T=ie(null),L=ie(0);T.current=i,Re(()=>{if(!k)return;let t=x.current;if(!t)return;document.activeElement===t?n(!0):t.focus();let p=t.ownerDocument??document,c=p.getSelection(),w=c&&c.rangeCount>0&&t.contains(c.anchorNode);if(c&&!w){let g=p.createRange();g.selectNodeContents(t),g.collapse(!0),c.removeAllRanges(),c.addRange(g)}},[k,n]),Re(()=>{let t=x.current;if(!t)return;let p=t.ownerDocument??document,c=()=>{let w=p.getSelection();if(!w||w.rangeCount===0||!w.anchorNode||!t.contains(w.anchorNode))return;let g=w.anchorNode,$=(g.nodeType===Node.ELEMENT_NODE?g:g.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null;if($&&$!==s?.id){Q($);return}performance.now()-L.current<50||H(Ye(t))};return p.addEventListener("selectionchange",c),()=>p.removeEventListener("selectionchange",c)},[s,Q,H]),De(()=>{let t=x.current;t&&Bt({input:t,segments:d,newParamId:o,editingParamId:s?.id??null,placeholderText:u??"",isFocused:m})},[d,o,s,u,m]),De(()=>{let t=N.current,p=o??"";if(N.current=p,!p||p===t)return;let c=x.current;if(!c)return;c.focus();let w=T.current??Ft(c);et(c,w)},[o]),De(()=>{let t=b.current,p=s?.id??"";if(b.current=p,!p||p===t||r==null)return;let c=x.current;c&&et(c,r)},[s,r]);let S=O(()=>{if(D.current)return;let t=x.current;if(!t)return;let p=Je(t),w=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;C(w)},[C]),K=O(()=>{L.current=performance.now(),S();let t=x.current;t&&G(Ye(t))},[S,G]);Re(()=>{let t=x.current;if(!t)return;let p=c=>{let w=c,g=w.inputType;if(g==="insertParagraph"||g==="insertLineBreak"||g==="insertFromDrop"){c.preventDefault();return}if(g.startsWith("insert")||g.startsWith("delete")){let A=g.startsWith("delete")?"":w.data??"";U(A)&&c.preventDefault()}};return t.addEventListener("beforeinput",p),()=>t.removeEventListener("beforeinput",p)},[U]);let R=O(()=>{D.current=!0},[]),Z=O(()=>{D.current=!1,S()},[S]),j=O(t=>{t.preventDefault();let p=x.current;if(!p)return;let c=(t.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!c)return;let w=p.ownerDocument??document,g=w.getSelection();if(!g||g.rangeCount===0)return;let A=g.getRangeAt(0);if(!p.contains(A.startContainer))return;A.deleteContents();let z=w.createTextNode(c);A.insertNode(z),A.setStartAfter(z),A.collapse(!0),g.removeAllRanges(),g.addRange(A),S()},[S]),F=O(t=>E(t),[E]),W=O(()=>n(!0),[n]),f=O(()=>n(!1),[n]),re=O(()=>x.current?.focus(),[]),Y=O(()=>x.current?.blur(),[]),V=O(()=>{let t=x.current;return t?Je(t):""},[]),l=Mt()?"plaintext-only":"true";return{inputRef:x,editorProps:{ref:x,contentEditable:l,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":v,"aria-expanded":h,"aria-activedescendant":_,spellCheck:!0,enterKeyHint:"send",onInput:K,onKeyDown:F,onCompositionStart:R,onCompositionEnd:Z,onPaste:j,onFocus:W,onBlur:f},getPlainText:V,focus:re,blur:Y}}import{jsx as ne,jsxs as Le}from"react/jsx-runtime";function Ut(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var jt=Ot(function({onSubmit:d,onError:o,optionOverrides:s,maskCompletedText:r,className:i,apiConfig:u,columns:m,pillPlacement:h="dropdown",mode:v="auto",optionsPosition:_="below",animations:k=!0,dropdownTrigger:C,closeDropdownOnBlur:E,showNonTappableOptions:G,autoFocus:H=!0,onFocus:Q,onBlur:U,value:n,completedParams:x,onChange:D,onParamsChange:N,submitButton:b},T){let L=pe(null),S=pe(null),K=pe(()=>{}),R=pe(null),Z=pe(null);at(()=>{let y=L.current;if(y)return R.current?R.current.setMode(v):R.current=new Wt(y,v),()=>{R.current?.destroy(),R.current=null}},[v]);let j=Te(y=>{let X=Z.current?.current;X&&(X.focus(),Gt(X,y))},[]),{completedParams:F,skippedParams:W,suggestionPills:f,setActivePill:re,segments:Y,newParamId:V,clearNewParamId:l,placeholderText:t,isFocused:p,isDropdownOpen:c,isActivePillSelected:w,isLoading:g,activeIndex:A,listboxId:z,handleTextChange:$,handleKeyDown:ce,setFocused:ye,editingParam:ue,editingAnchor:a,caretOffset:P,startEditingParam:I,handleCaretAfterInput:ae,handleCaretMove:se,replaceEditingRange:ot,dropdownProps:it,reset:me}=Ee({onSubmit:y=>K.current(y),onError:o,optionOverrides:s,maskCompletedText:r,apiConfig:u,columns:m,dropdownTrigger:C,optionsPosition:_,closeDropdownOnBlur:E,showNonTappableOptions:G,onFocus:Q,onBlur:U,value:n,completedParams:x,onChange:D,onParamsChange:N,source:"full-sdk",setCursor:j});at(()=>{if(!V)return;let y=window.setTimeout(()=>l(),650);return()=>window.clearTimeout(y)},[V,l]);let nt=A>=0?`${z}-option-${A}`:void 0,{inputRef:ke,editorProps:rt,focus:ge,blur:ze,getPlainText:Fe}=tt({segments:Y,newParamId:V,editingParam:ue,editingAnchor:a,caretOffset:P,placeholderText:t,isFocused:p,isDropdownOpen:c,listboxId:z,activeDescendantId:nt,autoFocus:H,handleTextChange:$,handleKeyDown:ce,handleCaretAfterInput:ae,handleCaretMove:se,startEditingParam:I,replaceEditingRange:ot,setFocused:ye});Z.current=ke,Nt(()=>{let y=S.current,X=ke.current;if(!y||!X)return;let Be=()=>{let Oe=y.firstElementChild;if(!Oe)return;let pt=Oe.getBoundingClientRect(),ct=X.getBoundingClientRect();pt.top>=ct.bottom-2?y.setAttribute("data-aia-pill-wrapped",""):y.removeAttribute("data-aia-pill-wrapped")};Be();let Me=new ResizeObserver(Be);return Me.observe(X),()=>Me.disconnect()},[Y,f.length,g,ke]),Ht(T,()=>({focus:ge,blur:ze,reset:me,setMode:y=>R.current?.setMode(y)}),[ge,ze,me]);let he=!!Y.length||F.length>0,_e=Te(()=>{if(!he)return;let y=Fe();d(Kt(y,F,W)),me()},[he,F,W,d,me,Fe]);K.current=_e;let st=Te(y=>{y.target?.closest("[data-aia-pill]")||ge()},[ge]),lt=h==="inline",dt=h==="dropdown";return Le("div",{ref:L,className:`magicx-aia ${ee.container} ${i??""}`,"data-pill-placement":h,"data-options-position":_,"data-animations":k?"on":"off","data-mode":Ut(v),children:[ne(Ae,{...it,showPills:dt}),Le("div",{className:ee.inputWrapper,onClick:st,children:[Le("div",{className:ee.editorArea,"data-aia-editor":"",children:[ne("div",{...rt,className:ee.input,"data-aia-input":""}),lt&&(g||f.length>0)&&ne("span",{ref:S,className:ee.pillListContainer,"data-aia-pill-list-container":"",children:ne(be,{pills:f,activePillIndex:0,activeSelected:w,onSelectPill:re,loading:g})})]}),b===null?null:b===void 0?ne(Ze,{disabled:!he,onClick:_e}):ne("span",{"data-aia-submit":"",className:ee.submitSlot,onClick:y=>{he&&(y.stopPropagation(),_e())},children:b})]})]})});export{jt as AIAutocomplete,Ae as AIAutocompleteDropdown,co as buildSubmitResult,Ee as useAIAutocomplete,uo as withSkippedParams};
|
|
1185
1185
|
//# sourceMappingURL=index.mjs.map
|