@magicx-eng/ai-autocomplete-react 0.2.0 → 0.2.1
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.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -8
- 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 mt,useCallback as
|
|
1
|
+
import{forwardRef as mt,useCallback as Ee,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
|
|
@@ -97,7 +97,6 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
97
97
|
.AIAutocomplete-module_input_IW-P-[data-aia-empty="true"] {
|
|
98
98
|
display: inline-block;
|
|
99
99
|
min-width: 1px;
|
|
100
|
-
vertical-align: top;
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
.AIAutocomplete-module_pillListContainer_h92IA {
|
|
@@ -202,7 +201,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
202
201
|
}
|
|
203
202
|
|
|
204
203
|
.AIAutocompleteDropdown-module_pillBar_pwTXe {
|
|
205
|
-
padding: 27px 27px
|
|
204
|
+
padding: 27px 27px 3px 27px;
|
|
206
205
|
overflow-x: auto;
|
|
207
206
|
overflow-y: hidden;
|
|
208
207
|
scrollbar-width: none;
|
|
@@ -256,7 +255,6 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
256
255
|
gap: 5px;
|
|
257
256
|
align-items: center;
|
|
258
257
|
vertical-align: middle;
|
|
259
|
-
transform: translateY(-3px);
|
|
260
258
|
}
|
|
261
259
|
|
|
262
260
|
.PillList-module_pill_osSyz {
|
|
@@ -331,7 +329,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
331
329
|
opacity: 0;
|
|
332
330
|
}
|
|
333
331
|
}
|
|
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((
|
|
332
|
+
`,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((l,m)=>fe("span",{"data-aia-pill-skeleton":"",className:`${B.pill} ${v?B.rounded:""} ${B.skeleton}`,style:{width:l,opacity:ze(m)}},`skel-${l}`))}):fe("span",{className:B.list,"data-aia-pill-list-loading":c?"":void 0,children:e.map((l,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: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 {
|
|
335
333
|
position: relative;
|
|
336
334
|
}
|
|
337
335
|
|
|
@@ -386,7 +384,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
386
384
|
background: var(--aia-scrollbar-thumb, rgba(0, 0, 0, 0.3));
|
|
387
385
|
border-radius: 3px;
|
|
388
386
|
}
|
|
389
|
-
`,document.head.appendChild(e)}var ye={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};import{useEffect as
|
|
387
|
+
`,document.head.appendChild(e)}var ye={scrollWrapper:"SuggestionGrid-module_scrollWrapper_MOqfw",grid:"SuggestionGrid-module_grid_jvaPb"};import{useEffect as Ze,useRef as Ye,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
388
|
position: relative;
|
|
391
389
|
overflow: visible;
|
|
392
390
|
display: flex;
|
|
@@ -733,7 +731,7 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
733
731
|
filter: brightness(0.55);
|
|
734
732
|
}
|
|
735
733
|
}
|
|
736
|
-
`,document.head.appendChild(e)}var
|
|
734
|
+
`,document.head.appendChild(e)}var T={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:l}){let[m,g]=et(!1),h=Ye(void 0);Ze(()=>()=>clearTimeout(h.current),[]);let n=()=>{l||!e.is_tappable||m||(g(!0),f(e),clearTimeout(h.current),h.current=setTimeout(()=>g(!1),500))},d=[T.item,_&&!l?T.highlighted:"",e.is_tappable?T.tappable:T.nonTappable,m?T.pressed:""].filter(Boolean).join(" ");return Me("div",{id:c,role:"option","data-aia-option":"","data-aia-loading":l?"":void 0,"aria-selected":_,className:d,tabIndex:l||!e.is_tappable?-1:0,onClick:n,onKeyDown:I=>{!l&&e.is_tappable&&(I.key==="Enter"||I.key===" ")&&(I.preventDefault(),n())},onMouseEnter:!l&&e.is_tappable?v:void 0,children:[be("div",{className:T.streaks}),be("div",{className:T.streaksVert}),Me("span",{className:T.content,children:[be("span",{className:T.text,children:e.icon?`${e.icon} ${e.text}`:e.text}),e.tag&&be("span",{className:T.tag,children:e.tag})]})]})}import{jsx as Ie}from"react/jsx-runtime";function Be({options:e,activeIndex:_,onSelect:f,onHighlight:v,listboxId:c,loading:l}){let m=at(null),[g,h]=nt(!1);return tt(()=>{let n=m.current;if(!n)return;let d=()=>{h(n.scrollHeight-n.scrollTop-n.clientHeight>1)};n.addEventListener("scroll",d,{passive:!0});let I=new ResizeObserver(d);return I.observe(n),()=>{n.removeEventListener("scroll",d),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,d)=>Ie(Oe,{option:n,isHighlighted:d===_,onSelect:f,onHighlight:()=>v(d),id:`${c}-option-${d}`,loading:l},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:l,className:m,pills:g,onPillClick:h,showPills:n=!0,isLoading:d=!1}){let A=e[0]?.options??[],S=n&&g&&g.length>0&&h,D=A.length>0,H=d&&!D,N=c&&(D||S||d);return it("div",{id:l,role:"listbox","data-aia-dropdown":"","data-aia-loading":d?"":void 0,className:`${te.dropdown} ${N?te.visible:""} ${m??""}`,onMouseDown:E=>E.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:d})}),n&&(!g||g.length===0)&&d&&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:l,loading:d}),H&&oe("div",{className:te.skeletonBars,"data-aia-skeleton-bars":"",children:rt.map(E=>oe("span",{className:te.skeletonBar,style:{width:E}},`bar-${E}`))})]})}if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
|
|
737
735
|
* Built-in appearance defaults \u2014 zero specificity via :where().
|
|
738
736
|
* Consumer CSS always wins without !important.
|
|
739
737
|
*
|
|
@@ -828,5 +826,5 @@ import{forwardRef as mt,useCallback as Pe,useEffect as Ge,useImperativeHandle as
|
|
|
828
826
|
animation-duration: 0s !important;
|
|
829
827
|
transition-duration: 0s !important;
|
|
830
828
|
}
|
|
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};
|
|
829
|
+
`,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 z,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:l=2,dropdownTrigger:m,optionsPosition:g,closeDropdownOnBlur:h,showNonTappableOptions:n,onFocus:d,onBlur:I,value:A,completedParams:S,onChange:D,onParamsChange:H,source:N,setCursor:E}){let a=z(null),[w,G]=lt(null),X=z(e);X.current=e;let K=z(_);K.current=_;let Q=z(D);Q.current=D;let V=z(H);V.current=H;let C=z(d);C.current=d;let J=z(I);J.current=I;let L=z(E);L.current=E,he(()=>{if(typeof document>"u")return;let t=new st(document.createElement("div"),{renderMode:"headless",apiConfig:c,optionOverrides:f,maskCompletedText:v,columns:l,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),Z=z(f),q=z(0);if(f!==Z.current){let t=Z.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++,Z.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=z(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,Y=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],p=$?.listboxId??"",P=r.activeDropdownIndex>=0&&$?`${p}-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:p,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:Y,onKeyDown:ee,onFocus:b.handleFocus,onBlur:b.handleBlur,role:"combobox","aria-expanded":r.isDropdownOpen,"aria-activedescendant":P,"aria-autocomplete":"list","aria-controls":p},reset:b.reset,dropdownProps:{suggestions:de?[{...de,options:r.filteredOptions}]:[],activeIndex:r.activeDropdownIndex,onSelect:b.selectOption,onHighlight:b.setActiveDropdownIndex,isOpen:r.isDropdownOpen,id:p,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 M,useEffect as Se,useLayoutEffect as Pe,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:l,placeholderText:m,isFocused:g,isDropdownOpen:h,listboxId:n,activeDescendantId:d,autoFocus:I,handleTextChange:A,handleKeyDown:S,handleCaretAfterInput:D,handleCaretMove:H,startEditingParam:N,replaceEditingRange:E,setFocused:a}=e,w=re(null),G=re(!1),X=re(""),K=re(""),Q=re(null),V=re(0);Q.current=l,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 p=x.anchorNode,W=(p.nodeType===Node.ELEMENT_NODE?p:p.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]),Pe(()=>{let o=w.current;o&&ut({input:o,segments:_,newParamId:f,editingParamId:v?.id??null,placeholderText:m??"",isFocused:g})},[_,f,v,m,g]),Pe(()=>{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]),Pe(()=>{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=M(()=>{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=M(()=>{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,p=x.inputType;if(p==="insertParagraph"||p==="insertLineBreak"||p==="insertFromDrop"){s.preventDefault();return}if(p.startsWith("insert")||p.startsWith("delete")){let P=p.startsWith("delete")?"":x.data??"";E(P)&&s.preventDefault()}};return o.addEventListener("beforeinput",i),()=>o.removeEventListener("beforeinput",i)},[E]);let L=M(()=>{G.current=!0},[]),ae=M(()=>{G.current=!1,C()},[C]),Z=M(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,p=x.getSelection();if(!p||p.rangeCount===0)return;let P=p.getRangeAt(0);if(!i.contains(P.startContainer))return;P.deleteContents();let R=x.createTextNode(s);P.insertNode(R),P.setStartAfter(R),P.collapse(!0),p.removeAllRanges(),p.addRange(P),C()},[C]),q=M(o=>S(o),[S]),F=M(()=>a(!0),[a]),b=M(()=>a(!1),[a]),Y=M(()=>w.current?.focus(),[]),ee=M(()=>w.current?.blur(),[]),$=M(()=>{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":d,spellCheck:!0,enterKeyHint:"send",onInput:J,onKeyDown:q,onCompositionStart:L,onCompositionEnd:ae,onPaste:Z,onFocus:F,onBlur:b},getPlainText:$,focus:Y,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:l,apiConfig:m,columns:g,pillPlacement:h="inline",mode:n="auto",optionsPosition:d="below",animations:I=!0,dropdownTrigger:A,closeDropdownOnBlur:S,showNonTappableOptions:D,autoFocus:H=!0,onFocus:N,onBlur:E,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 u=V.current;if(u)return L.current?L.current.setMode(n):L.current=new ht(u,n),()=>{L.current?.destroy(),L.current=null}},[n]);let Z=Ee(u=>{let O=ae.current?.current;O&&(O.focus(),xt(O,u))},[]),{completedParams:q,suggestionPills:F,setActivePill:b,segments:Y,newParamId:ee,clearNewParamId:$,placeholderText:r,isFocused:o,isDropdownOpen:i,isLoading:s,activeIndex:x,listboxId:p,handleTextChange:P,handleKeyDown:R,setFocused:W,editingParam:de,editingAnchor:ve,caretOffset:pe,startEditingParam:t,handleCaretAfterInput:k,handleCaretMove:y,replaceEditingRange:ne,dropdownProps:ie,reset:ue}=Ae({onSubmit:u=>J.current(u),onError:f,optionOverrides:v,maskCompletedText:c,apiConfig:m,columns:g,dropdownTrigger:A,optionsPosition:d,closeDropdownOnBlur:S,showNonTappableOptions:D,onFocus:N,onBlur:E,value:a,completedParams:w,onChange:G,onParamsChange:X,source:"full-sdk",setCursor:Z});Ge(()=>{if(!ee)return;let u=window.setTimeout(()=>$(),650);return()=>window.clearTimeout(u)},[ee,$]);let Ve=x>=0?`${p}-option-${x}`:void 0,{inputRef:we,editorProps:qe,focus:ce,blur:De,getPlainText:Le}=Ne({segments:Y,newParamId:ee,editingParam:de,editingAnchor:ve,caretOffset:pe,placeholderText:r,isFocused:o,isDropdownOpen:i,listboxId:p,activeDescendantId:Ve,autoFocus:H,handleTextChange:P,handleKeyDown:R,handleCaretAfterInput:k,handleCaretMove:y,startEditingParam:t,replaceEditingRange:ne,setFocused:W});ae.current=we,ft(()=>{let u=C.current,O=we.current;if(!u||!O)return;let ge=()=>{let Te=u.firstElementChild;if(!Te)return;let Xe=Te.getBoundingClientRect(),Qe=O.getBoundingClientRect();Xe.top>=Qe.bottom-2?u.setAttribute("data-aia-pill-wrapped",""):u.removeAttribute("data-aia-pill-wrapped")};ge();let Re=new ResizeObserver(ge);return Re.observe(O),()=>Re.disconnect()},[Y,F.length,s,we]),gt(Q,()=>({focus:ce,blur:De,reset:ue,setMode:u=>L.current?.setMode(u)}),[ce,De,ue]);let me=!!Y.length||q.length>0,_e=Ee(()=>{if(!me)return;let u=Le(),{rawQuery:O,completedParams:ge}=bt(u,q);_({query:u.trim(),raw_query:O,completed_params:ge}),ue()},[me,q,_,ue,Le]);J.current=_e;let $e=Ee(u=>{u.target?.closest("[data-aia-pill]")||ce()},[ce]),Ue=h==="inline",je=h==="dropdown";return Ce("div",{ref:V,className:`magicx-aia ${U.container} ${l??""}`,"data-pill-placement":h,"data-options-position":d,"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:u=>{u.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:u=>{me&&(u.stopPropagation(),_e())},children:K})]})]})});export{wt as AIAutocomplete,ke as AIAutocompleteDropdown,Ae as useAIAutocomplete};
|
|
832
830
|
//# sourceMappingURL=index.mjs.map
|