@magicx-eng/ai-autocomplete-react 0.1.11 → 0.1.13
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 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,57 +1,8 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var xe=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var rt=(e,n)=>{for(var t in n)xe(e,t,{get:n[t],enumerable:!0})},it=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of ot(n))!nt.call(e,r)&&r!==t&&xe(e,r,{get:()=>n[r],enumerable:!(o=tt(n,r))||o.enumerable});return e};var at=e=>it(xe({},"__esModule",{value:!0}),e);var bt={};rt(bt,{AIAutocomplete:()=>Be,AIAutocompleteDropdown:()=>se,useAIAutocomplete:()=>pe});module.exports=at(bt);var F=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-cc65f4cc")){let e=document.createElement("style");e.id="ac-style-cc65f4cc",e.textContent=`.AIAutocomplete-module_container_KKjFU {
|
|
2
2
|
position: relative;
|
|
3
3
|
font-family: "IBM Plex Sans", sans-serif;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
.AIAutocomplete-module_checkmark_CVE0Z {
|
|
7
|
-
position: absolute;
|
|
8
|
-
bottom: -130px;
|
|
9
|
-
left: 50%;
|
|
10
|
-
transform: translateX(-50%) translateY(8px) scale(0.8);
|
|
11
|
-
opacity: 0;
|
|
12
|
-
pointer-events: none;
|
|
13
|
-
z-index: 10;
|
|
14
|
-
animation: none;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.AIAutocomplete-module_checkmarkVisible_DWYbI {
|
|
18
|
-
animation: AIAutocomplete-module_checkmarkFadeInOut_U1Oof 3s ease forwards;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@keyframes AIAutocomplete-module_checkmarkFadeInOut_U1Oof {
|
|
22
|
-
0% {
|
|
23
|
-
opacity: 0;
|
|
24
|
-
transform: translateX(-50%) translateY(8px) scale(0.8);
|
|
25
|
-
}
|
|
26
|
-
10% {
|
|
27
|
-
opacity: 1;
|
|
28
|
-
transform: translateX(-50%) translateY(0) scale(1);
|
|
29
|
-
}
|
|
30
|
-
80% {
|
|
31
|
-
opacity: 1;
|
|
32
|
-
transform: translateX(-50%) translateY(0) scale(1);
|
|
33
|
-
}
|
|
34
|
-
100% {
|
|
35
|
-
opacity: 0;
|
|
36
|
-
transform: translateX(-50%) translateY(-8px) scale(0.8);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.AIAutocomplete-module_checkmarkPath_BJRUs {
|
|
41
|
-
stroke-dasharray: 30;
|
|
42
|
-
stroke-dashoffset: 30;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.AIAutocomplete-module_checkmarkVisible_DWYbI .AIAutocomplete-module_checkmarkPath_BJRUs {
|
|
46
|
-
animation: AIAutocomplete-module_drawCheck_je-B3 0.4s ease forwards 0.1s;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@keyframes AIAutocomplete-module_drawCheck_je-B3 {
|
|
50
|
-
to {
|
|
51
|
-
stroke-dashoffset: 0;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
6
|
.AIAutocomplete-module_inputWrapper_FLq1b {
|
|
56
7
|
min-height: 60px;
|
|
57
8
|
padding: 24px;
|
|
@@ -135,7 +86,7 @@
|
|
|
135
86
|
.AIAutocomplete-module_submitButton_sl1Mi:hover {
|
|
136
87
|
opacity: 0.85;
|
|
137
88
|
}
|
|
138
|
-
`,document.head.appendChild(e)}var
|
|
89
|
+
`,document.head.appendChild(e)}var Q={container:"AIAutocomplete-module_container_KKjFU",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",sizerContent:"AIAutocomplete-module_sizerContent_DQgmV",sizerText:"AIAutocomplete-module_sizerText_iZIMK",placeholderText:"AIAutocomplete-module_placeholderText_K3ayy",textarea:"AIAutocomplete-module_textarea_eyn6A",submitButton:"AIAutocomplete-module_submitButton_sl1Mi"};if(typeof document<"u"&&!document.getElementById("ac-style-2eef895d")){let e=document.createElement("style");e.id="ac-style-2eef895d",e.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
|
|
139
90
|
position: absolute;
|
|
140
91
|
left: 0;
|
|
141
92
|
right: 0;
|
|
@@ -154,7 +105,7 @@
|
|
|
154
105
|
opacity: 1;
|
|
155
106
|
pointer-events: auto;
|
|
156
107
|
}
|
|
157
|
-
`,document.head.appendChild(e)}var Ae={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj"};if(typeof document<"u"&&!document.getElementById("ac-style-
|
|
108
|
+
`,document.head.appendChild(e)}var Ae={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj"};if(typeof document<"u"&&!document.getElementById("ac-style-d91f2b06")){let e=document.createElement("style");e.id="ac-style-d91f2b06",e.textContent=`.SuggestionGrid-module_grid_jvaPb {
|
|
158
109
|
display: grid;
|
|
159
110
|
grid-template-columns: 1fr 1fr;
|
|
160
111
|
gap: 12px 18px;
|
|
@@ -177,7 +128,7 @@
|
|
|
177
128
|
background: rgba(255, 255, 255, 0.3);
|
|
178
129
|
border-radius: 3px;
|
|
179
130
|
}
|
|
180
|
-
`,document.head.appendChild(e)}var
|
|
131
|
+
`,document.head.appendChild(e)}var Te={grid:"SuggestionGrid-module_grid_jvaPb"};if(typeof document<"u"&&!document.getElementById("ac-style-f6bdc634")){let e=document.createElement("style");e.id="ac-style-f6bdc634",e.textContent=`.SuggestionItem-module_item_d4vpD {
|
|
181
132
|
display: flex;
|
|
182
133
|
align-items: center;
|
|
183
134
|
font-family: "IBM Plex Sans", sans-serif;
|
|
@@ -218,7 +169,7 @@
|
|
|
218
169
|
margin-left: 6px;
|
|
219
170
|
opacity: 0.5;
|
|
220
171
|
}
|
|
221
|
-
`,document.head.appendChild(e)}var
|
|
172
|
+
`,document.head.appendChild(e)}var J={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe"};var ae=require("react/jsx-runtime");function Ee({option:e,isHighlighted:n,onSelect:t,onHighlight:o,id:r}){let i=[J.item,n?J.highlighted:"",e.is_tappable?J.tappable:J.nonTappable].filter(Boolean).join(" ");return(0,ae.jsxs)("div",{id:r,role:"option","aria-selected":n,className:i,tabIndex:e.is_tappable?0:-1,onClick:()=>e.is_tappable&&t(e),onKeyDown:s=>{e.is_tappable&&(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),t(e))},onMouseEnter:o,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,ae.jsx)("span",{className:J.tag,children:e.tag})]})}var _e=require("react/jsx-runtime");function Le({options:e,activeIndex:n,onSelect:t,onHighlight:o,listboxId:r}){return(0,_e.jsx)("div",{className:Te.grid,children:e.map((i,s)=>(0,_e.jsx)(Ee,{option:i,isHighlighted:s===n,onSelect:t,onHighlight:()=>o(s),id:`${r}-option-${s}`},i.text))})}var ve=require("react/jsx-runtime");function se({suggestions:e,activeIndex:n,onSelect:t,onHighlight:o,isOpen:r,id:i,className:s}){let m=e[0]?.options??[],c=r&&m.length>0;return(0,ve.jsx)("div",{id:i,role:"listbox",className:`${Ae.dropdown} ${c?Ae.visible:""} ${s??""}`,onMouseDown:u=>u.preventDefault(),children:m.length>0&&(0,ve.jsx)(Le,{options:m,activeIndex:n,onSelect:t,onHighlight:o,listboxId:i})})}if(typeof document<"u"&&!document.getElementById("ac-style-b745b4fb")){let e=document.createElement("style");e.id="ac-style-b745b4fb",e.textContent=`.PillList-module_list_qvLqO {
|
|
222
173
|
position: relative;
|
|
223
174
|
z-index: 1;
|
|
224
175
|
pointer-events: auto;
|
|
@@ -260,5 +211,5 @@
|
|
|
260
211
|
opacity: 0;
|
|
261
212
|
}
|
|
262
213
|
}
|
|
263
|
-
`,document.head.appendChild(e)}var ie={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",active:"PillList-module_active_Oll--"};var xe=require("react/jsx-runtime");function rt(e){return e===0?.4:e===1?.3:.15}function Me({pills:e,activePillIndex:r,onSelectPill:t}){return(0,xe.jsx)("span",{className:ie.list,children:e.map((o,n)=>(0,xe.jsx)("button",{type:"button",className:`${ie.pill} ${n===r?ie.active:""}`,style:{opacity:rt(n)},onClick:()=>t(n),children:o.text},`${o.type}-${o.text}`))})}var m=require("react");function ae(e,r){if(!e)return[];let t=r.trimStart();if(!t)return e;let o=t.toLowerCase();return e.filter(n=>!n.is_tappable||n.text.toLowerCase().includes(o))}function J(e,r){if(!e)return null;let t=r.trim();if(!t)return null;let o=t.toLowerCase();return e.find(n=>n.is_tappable&&n.text.toLowerCase()===o)??null}function Le(e,r){let t=[],o=0;for(let i of r){let s=e.indexOf(i.text,o);s!==-1&&(s>o&&t.push({type:"text",value:e.slice(o,s)}),t.push({type:"completed",value:i.text,param:i}),o=s+i.text.length)}let n=e.slice(o);return n&&t.push({type:"text",value:n}),t}function Ue(e,r){let t=[],o=[],n=0;for(let i of r){let s=e.indexOf(i.text,n);s===-1?o.push(i):(t.push(i),n=s+i.text.length)}return{valid:t,invalid:o}}var E=require("react");var it="0.1.11";function at(){return crypto.randomUUID()}function st(e,r){return{placeholder:e.placeholder,type:e.type,...r&&{text:e.text},kind:e.kind}}async function De(e,r,t){let o=t?.apiConfig,n=o?.apiKey??"",i=o?.authScheme??"Bearer",s=!t?.maskCompletedText,h=r.find(c=>c.type==="contact"&&c.metadata?.contact_account_count)?.metadata?.contact_account_count,d=typeof h=="number"?h:void 0,f={data:{raw_query:e,completed_params:r.map(c=>st(c,s)),...d!=null&&{contact_account_count:d}},meta:{request_id:at(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:it}},l={"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers};n&&(l.Authorization=i==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`);let b=await fetch(o?.endpoint??"/ac/suggest",{method:"POST",headers:l,body:JSON.stringify(f),signal:t?.signal});if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}function Z(e,r){let t=e,o={},n=[];for(let i of r){let s=(o[i.type]??0)+1;o[i.type]=s;let d=`{{${i.type.toUpperCase().replace(/\s+/g,"_")}_${s}}}`,f=t.indexOf(i.text);f!==-1&&(t=t.slice(0,f)+d+t.slice(f+i.text.length)),n.push({...i,placeholder:d})}return{rawQuery:t,completedParams:n}}function je(e,r){return r?e.map(t=>{let o=r[t.type];if(!o)return t;let n=o("");if(n.length===0)return t;let i=new Set(n.map(h=>h.text)),s=(t.options??[]).filter(h=>!i.has(h.text));return{...t,options:[...n,...s]}}):e}var lt=100,ct=300,ut=2;function ze({textRef:e,suggestionsRef:r,filterBaseRef:t,maskCompletedTextRef:o,apiConfigRef:n,optionOverridesRef:i,onErrorRef:s,setCompletedParams:h,setSuggestions:d,setActiveDropdownIndex:f}){let[l,b]=(0,E.useState)(!1),[c,A]=(0,E.useState)(null),[k,y]=(0,E.useState)(!1),v=(0,E.useRef)(0),U=(0,E.useRef)(null),g=(0,E.useRef)(""),u=(0,E.useCallback)(async(a,p)=>{U.current?.abort();let _=new AbortController;U.current=_;let w=++v.current,O=e.current.length;r.current.some(I=>I.type!=="placeholder")||b(!0),A(null);try{let I=await De(a,p,{maskCompletedText:o.current,signal:_.signal,apiConfig:n.current});if(w!==v.current)return;let z=je(I.data.suggestions??[],i.current);y(I.data.is_ready??!1),g.current=a;let q=I.data.input??[],M=q[q.length-1],L=e.current;if(M?.state==="in_progress"){let B=L.toLowerCase().lastIndexOf(M.text.toLowerCase());B!==-1?t.current=B:t.current=O}else t.current=O;let F=z.filter(B=>B.type!=="placeholder")[0];if(F){let B=L.slice(t.current),R=J(F.options,B);R&&(h(N=>[...N,{id:crypto.randomUUID(),placeholder:"",type:F.type,text:R.text,kind:R.kind,suggestionType:F.type,suggestionPlaceholder:F.text,options:F.options??[],metadata:R.metadata}]),z=z.filter(N=>N!==F))}d(z),b(!1),f(-1)}catch(I){if(w===v.current){let z=I instanceof Error?I:new Error(String(I));A(z),b(!1),s.current?.(z)}}},[e,r,t,o,n,i,s,h,d,f]);return(0,E.useEffect)(()=>(u("",[]),()=>{U.current?.abort()}),[u]),{doFetch:u,isLoading:l,error:c,isReady:k,lastRawQueryRef:g}}function Fe({text:e,completedParams:r,doFetch:t,filterBaseRef:o,skipNextFetchRef:n,suggestionsRef:i,lastRawQueryRef:s}){let h=(0,E.useRef)(null),d=(0,E.useRef)(null),f=(0,E.useRef)(!0);(0,E.useEffect)(()=>{h.current&&clearTimeout(h.current),d.current&&clearTimeout(d.current);let l=b=>{if(n.current)return n.current=!1,!1;if(!e&&r.length===0)return f.current?(t("",[]),!0):(f.current=!0,!1);let c=e.slice(o.current),y=i.current.filter(O=>O.type!=="placeholder")[0],U=(y?ae(y.options,c):[]).filter(O=>O.is_tappable),g=y?J(y.options,c)!==null:!1,u=c.trim().length>0;if(U.length>0&&!g&&u)return!1;let{rawQuery:a,completedParams:p}=Z(e,r),_=a.length<s.current.length,w=Math.abs(a.length-s.current.length);return _||w>=b?(t(a,p),!0):!1};return h.current=setTimeout(()=>{l(ut)&&d.current&&clearTimeout(d.current)},lt),d.current=setTimeout(()=>l(1),ct),()=>{h.current&&clearTimeout(h.current),d.current&&clearTimeout(d.current)}},[e,r,t,o,n,i,s])}var Pe=require("react");function Ke({activeDropdownIndex:e,setActiveDropdownIndex:r,filteredOptions:t,selectOption:o,onSubmitRef:n,text:i,completedParams:s,isDropdownOpen:h,hasPlaceholder:d,placeholderText:f,suggestions:l,filterBaseRef:b,columns:c,setText:A,setCompletedParams:k,setSuggestions:y}){let v=(0,Pe.useCallback)(()=>{let g=t.map((a,p)=>a.is_tappable?p:-1).filter(a=>a!==-1),u=Array.from({length:c},()=>[]);for(let a of g)u[a%c].push(a);return u.flat()},[t,c]);return{handleKeyDown:(0,Pe.useCallback)(g=>{let u=v();switch(g.key){case"ArrowDown":{if(g.preventDefault(),u.length===0)return;let a=u.indexOf(e),p=a<u.length-1?a+1:0;r(u[p]);break}case"ArrowUp":{if(g.preventDefault(),u.length===0)return;let a=u.indexOf(e),p=a>0?a-1:u.length-1;r(u[p]);break}case"ArrowRight":{if(e<0)break;if(e%c<c-1){let p=e+1;p<t.length&&t[p]?.is_tappable&&(g.preventDefault(),r(p))}break}case"ArrowLeft":{if(e<0)break;if(e%c>0){let a=e-1;a>=0&&t[a]?.is_tappable&&(g.preventDefault(),r(a))}break}case"Enter":{if(g.preventDefault(),e>=0&&t[e]?.is_tappable)o(t[e]);else if(n.current){let{rawQuery:a,completedParams:p}=Z(i,s),_={query:i.trim(),raw_query:a,completed_params:p};n.current(_)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)g.preventDefault(),o(t[e]);else if(h){let a=t.find(p=>p.is_tappable);a&&(g.preventDefault(),o(a))}else if(!i&&d){g.preventDefault();let a=l.find(p=>p.type==="placeholder");a?(A(f),b.current=f.length,k(p=>[...p,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[]}]),y(p=>p.filter(_=>_!==a))):(A(f),b.current=f.length)}break}case"Escape":r(-1);break}},[e,c,s,t,b,v,d,h,n,f,o,r,k,y,A,l,i]),getTappableIndices:v}}var se=require("react");function Be({completedParams:e,suggestions:r,setCompletedParams:t,setSuggestions:o,setActiveDropdownIndex:n,filterBaseRef:i,pillTappedRef:s}){let h=(0,se.useCallback)(l=>{let b=r.filter(y=>y.type!=="placeholder");if(l<0||l>=b.length)return;let c=b[l],A=b.filter((y,v)=>v!==l),k=r.filter(y=>y.type==="placeholder");o([...k,c,...A]),s.current=!0,n(-1)},[r,o,n,s]),d=(0,se.useCallback)(()=>{if(e.length===0)return;let l=e[e.length-1],b={type:l.suggestionType,text:l.suggestionPlaceholder,required:!0,options:l.options};t(c=>c.slice(0,-1)),o(c=>[b,...c]),n(-1)},[e,t,o,n]),f=(0,se.useCallback)(l=>{let b={type:l.suggestionType,text:l.suggestionPlaceholder,required:!0,options:l.options};return{apply:c=>{c(A=>{let k=0;for(let y of e){let v=A.indexOf(y.text,k);if(v!==-1){if(y.id===l.id){let U=A.slice(0,v),g=A.slice(v+l.text.length),u=(U+g).replace(/ {2,}/g," ");return i.current=Math.min(i.current,u.length),u}k=v+y.text.length}}return A}),t(A=>A.filter(k=>k.id!==l.id)),o(A=>[b,...A]),n(-1),s.current=!0}}},[e,t,o,n,i,s]);return{setActivePill:h,removeLastParam:d,reEditParam:f}}var pt=0;function mt(){let e=(0,m.useRef)(null);return e.current===null&&(e.current=`:ac-${++pt}:`),e.current}function le({onSubmit:e,onError:r,optionOverrides:t,maskCompletedText:o,placeholder:n,apiConfig:i,columns:s=2,eagerSuggestions:h=!0,value:d,completedParams:f,onChange:l,onParamsChange:b}){let c=d!==void 0,A=f!==void 0,[k,y]=(0,m.useState)(""),[v,U]=(0,m.useState)([]),[g,u]=(0,m.useState)([]),[a,p]=(0,m.useState)(-1),_=c?d:k,w=A?f:v,O=(0,m.useRef)(e);O.current=e;let V=(0,m.useRef)(l);V.current=l;let I=(0,m.useRef)(b);I.current=b;let z=(0,m.useRef)(d);z.current=d;let q=(0,m.useRef)(f);q.current=f;let M=(0,m.useCallback)(S=>{if(typeof S=="function")if(c){let P=S(z.current??"");V.current?.(P)}else y(P=>{let Q=S(P);return V.current?.(Q),Q});else c||y(S),V.current?.(S)},[c]),L=(0,m.useCallback)(S=>{if(typeof S=="function")if(A){let P=S(q.current??[]);I.current?.(P)}else U(P=>{let Q=S(P);return I.current?.(Q),Q});else A||U(S),I.current?.(S)},[A]),G=(0,m.useRef)(r);G.current=r;let F=(0,m.useRef)(t);F.current=t;let B=(0,m.useRef)(o);B.current=o;let R=(0,m.useRef)(i);R.current=i;let N=(0,m.useRef)(_);N.current=_;let ce=(0,m.useRef)(g);ce.current=g;let $=(0,m.useRef)(0),ee=(0,m.useRef)(!1),ve=(0,m.useRef)(!1),ue=mt(),{doFetch:pe,isLoading:Ie,error:$e,isReady:qe,lastRawQueryRef:me}=ze({textRef:N,suggestionsRef:ce,filterBaseRef:$,maskCompletedTextRef:B,apiConfigRef:R,optionOverridesRef:F,onErrorRef:G,setCompletedParams:L,setSuggestions:u,setActiveDropdownIndex:p});Fe({text:_,completedParams:w,doFetch:pe,filterBaseRef:$,skipNextFetchRef:ve,suggestionsRef:ce,lastRawQueryRef:me});let Qe=(0,m.useMemo)(()=>Le(_,w),[_,w]);$.current=Math.min($.current,_.length);let de=_.slice($.current),ge=(0,m.useMemo)(()=>g.filter(P=>P.type==="placeholder").map(P=>P.text).join(" ")||n||"",[g,n]),te=(0,m.useMemo)(()=>g.filter(S=>S.type!=="placeholder"),[g]),x=te[0],Ce=x?t?.[x.type]:void 0,ke=x?Ce?Ce(de.trim()):x.options??[]:[],fe=(0,m.useMemo)(()=>ae(ke,de),[ke,de]),we=ge.length>0,he=!Ie&&fe.length>0&&(!!_||ee.current||!we),Oe=(0,m.useCallback)(S=>{if(!x)return;let P={id:crypto.randomUUID(),placeholder:"",type:x.type,text:S.text,kind:S.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:S.metadata},Q=$.current,D=N.current.slice(0,Q);if(D.length>0&&!D.endsWith(" ")){let T=D.split(/\s+/).pop()??"";T&&S.text.toLowerCase().startsWith(T.toLowerCase())&&(D=D.slice(0,D.length-T.length))}let be=D.length>0&&D[D.length-1]!==" ",X=D+(be?" ":"")+S.text+" ";M(X),$.current=X.length,L(T=>[...T,P]),ee.current=!1,p(-1);let H=te.length-1;h&&H>0?(u(T=>T.filter(W=>W!==x)),ve.current=!0):u(T=>T.filter(W=>W.type==="placeholder"))},[x,te,h,M,L]),Ve=(0,m.useCallback)(S=>{let P=S.target.value,D=P.length>0&&!S.nativeEvent?.isComposing&&P[0]!==P[0].toUpperCase()?P[0].toUpperCase()+P.slice(1):P;M(D),ee.current=!1,p(-1);let{valid:be,invalid:X}=Ue(D,w);if(X.length>0){L(()=>be);for(let H of X)u(T=>[{type:H.suggestionType,text:H.suggestionPlaceholder,required:!0,options:H.options},...T])}if(x&&X.length===0){let H=D.slice($.current),T=J(x.options,H);T&&(L(W=>[...W,{id:crypto.randomUUID(),placeholder:"",type:x.type,text:T.text,kind:T.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options??[],metadata:T.metadata}]),u(W=>W.filter(Ye=>Ye!==x)))}},[w,x,M,L]),{handleKeyDown:He}=Ke({activeDropdownIndex:a,setActiveDropdownIndex:p,filteredOptions:fe,selectOption:Oe,onSubmitRef:O,text:_,completedParams:w,isDropdownOpen:he,hasPlaceholder:we,placeholderText:ge,suggestions:g,filterBaseRef:$,columns:s,setText:M,setCompletedParams:L,setSuggestions:u}),oe=Be({completedParams:w,suggestions:g,setCompletedParams:L,setSuggestions:u,setActiveDropdownIndex:p,filterBaseRef:$,pillTappedRef:ee}),We=(0,m.useCallback)(S=>{oe.reEditParam(S).apply(M)},[oe,M]),Ge=(0,m.useCallback)(()=>{M(""),L(()=>[]),u([]),p(-1),$.current=0,me.current="",pe("",[])},[pe,M,L,me]),Xe=a>=0?`${ue}-option-${a}`:void 0;return{completedParams:w,suggestionPills:te,setActivePill:oe.setActivePill,removeLastParam:oe.removeLastParam,reEditParam:We,segments:Qe,suggestions:g,activeIndex:a,isReady:qe,isLoading:Ie,error:$e,inputProps:{value:_,placeholder:ge||void 0,onChange:Ve,onKeyDown:He,role:"combobox","aria-expanded":he,"aria-activedescendant":Xe,"aria-autocomplete":"list","aria-controls":ue},reset:Ge,dropdownProps:{suggestions:x?[{...x,options:fe}]:[],activeIndex:a,onSelect:Oe,onHighlight:p,isOpen:he,id:ue}}}var C=require("react/jsx-runtime"),Ne=(0,j.forwardRef)(function({onSubmit:r,onError:t,optionOverrides:o,maskCompletedText:n,placeholder:i,className:s,apiConfig:h,columns:d,eagerSuggestions:f,value:l,completedParams:b,onChange:c,onParamsChange:A},k){let y=(0,j.useRef)(null),[v,U]=(0,j.useState)(!1),g=(0,j.useRef)(()=>{}),u=(0,j.useRef)(void 0);(0,j.useEffect)(()=>(y.current?.focus(),()=>clearTimeout(u.current)),[]);let{completedParams:a,suggestionPills:p,setActivePill:_,segments:w,inputProps:O,dropdownProps:V,reset:I}=le({onSubmit:R=>g.current(R),onError:t,optionOverrides:o,maskCompletedText:n,placeholder:i,apiConfig:h,columns:d,eagerSuggestions:f,value:l,completedParams:b,onChange:c,onParamsChange:A});(0,j.useImperativeHandle)(k,()=>({focus:()=>y.current?.focus(),reset:I}),[I]);let z=()=>{y.current?.focus()},q=!!O.value||a.length>0,M=(0,j.useCallback)(()=>{if(!q)return;let{rawQuery:R,completedParams:N}=Z(O.value,a);r({query:O.value.trim(),raw_query:R,completed_params:N}),I(),U(!0),clearTimeout(u.current),u.current=setTimeout(()=>U(!1),3e3)},[q,O.value,a,r,I]);g.current=M;let{onChange:L,placeholder:G,...F}=O,B=!O.value;return(0,C.jsxs)("div",{className:`${K.container} ${s??""}`,children:[(0,C.jsx)("div",{className:`${K.checkmark} ${v?K.checkmarkVisible:""}`,children:(0,C.jsxs)("svg",{width:"72",height:"72",viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Success",children:[(0,C.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"#34C759"}),(0,C.jsx)("path",{d:"M7 12.5l3.5 3.5L17 9",stroke:"#000",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:K.checkmarkPath})]})}),(0,C.jsx)(re,{...V}),(0,C.jsxs)("div",{className:K.inputWrapper,onClick:z,children:[(0,C.jsxs)("div",{className:K.editorArea,children:[(0,C.jsxs)("div",{className:K.sizerContent,"aria-hidden":"true",children:[B&&G?(0,C.jsxs)("span",{className:K.placeholderText,children:[G," "]}):(0,C.jsxs)("span",{className:K.sizerText,children:[w.map((R,N)=>(0,C.jsx)("span",{children:R.value},`${N}-${R.type}`)),w.length===0&&"\xA0"]})," ",(0,C.jsx)(Me,{pills:p,activePillIndex:0,onSelectPill:_})]}),(0,C.jsx)("textarea",{ref:y,className:K.textarea,rows:1,onChange:L,...F})]}),(0,C.jsx)("button",{type:"button",className:K.submitButton,disabled:!q,onClick:R=>{R.stopPropagation(),M()},"aria-label":"Submit",children:(0,C.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,C.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
|
|
214
|
+
`,document.head.appendChild(e)}var le={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",active:"PillList-module_active_Oll--"};var Pe=require("react/jsx-runtime");function st(e){return e===0?.4:e===1?.3:.15}function Ue({pills:e,activePillIndex:n,onSelectPill:t}){return(0,Pe.jsx)("span",{className:le.list,children:e.map((o,r)=>(0,Pe.jsx)("button",{type:"button",className:`${le.pill} ${r===n?le.active:""}`,style:{opacity:st(r)},onClick:()=>t(r),children:o.text},`${o.type}-${o.text}`))})}var p=require("react");function Y(e,n,t){let o=e.slice(n);if(t||n===0||e[n-1]===" ")return o;let r=o.indexOf(" ");return r===-1?"":o.slice(r+1)}function ce(e,n){if(!e)return[];let t=n.trimStart();if(!t)return e;let o=t.toLowerCase();return e.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(o))}function re(e,n){if(!e)return null;let t=n.trim();if(!t)return null;let o=t.toLowerCase();return e.find(r=>r.is_tappable&&r.text.toLowerCase()===o)??null}function De(e,n){let t=[],o=0;for(let i of n){let s=e.indexOf(i.text,o);s!==-1&&(s>o&&t.push({type:"text",value:e.slice(o,s)}),t.push({type:"completed",value:i.text,param:i}),o=s+i.text.length)}let r=e.slice(o);return r&&t.push({type:"text",value:r}),t}function Ke(e,n){let t=[],o=[],r=0;for(let i of n){let s=e.indexOf(i.text,r);s===-1?o.push(i):(t.push(i),r=s+i.text.length)}return{valid:t,invalid:o}}var R=require("react");var lt="0.1.13",je=!1;function ct(){return crypto.randomUUID()}function ut(e,n){return{placeholder:e.placeholder,type:e.type,...n&&{text:e.text},kind:e.kind}}async function ze(e,n,t){let o=t?.apiConfig,r=o?.apiKey??"";!r&&!je&&(je=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header."));let i=o?.authScheme??"Bearer",s=!t?.maskCompletedText,h=n.find(g=>g.type==="contact"&&g.metadata?.contact_account_count)?.metadata?.contact_account_count,m=typeof h=="number"?h:void 0,c={data:{raw_query:e,completed_params:n.map(g=>ut(g,s)),...m!=null&&{contact_account_count:m}},meta:{request_id:ct(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:lt}},u={"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers};r&&(u.Authorization=i==="Basic"?`Basic ${btoa(r)}`:`Bearer ${r}`);let y=await fetch(o?.endpoint??"/ac/suggest",{method:"POST",headers:u,body:JSON.stringify(c),signal:t?.signal});if(!y.ok)throw new Error(`API error: ${y.status} ${y.statusText}`);return y.json()}function ee(e,n){let t=e,o={},r=[];for(let i of n){let s=(o[i.type]??0)+1;o[i.type]=s;let m=`{{${i.type.toUpperCase().replace(/\s+/g,"_")}_${s}}}`,c=t.indexOf(i.text);c!==-1&&(t=t.slice(0,c)+m+t.slice(c+i.text.length)),r.push({...i,placeholder:m})}return{rawQuery:t,completedParams:r}}function Fe(e,n){return n?e.map(t=>{let o=n[t.type];if(!o)return t;let r=o("");if(r.length===0)return t;let i=new Set(r.map(h=>h.text)),s=(t.options??[]).filter(h=>!i.has(h.text));return{...t,options:[...r,...s]}}):e}var pt=100,dt=300,mt=2;function qe({textRef:e,suggestionsRef:n,filterBaseRef:t,filterInProgressRef:o,maskCompletedTextRef:r,apiConfigRef:i,optionOverridesRef:s,onErrorRef:h,setCompletedParams:m,setSuggestions:c,setActiveDropdownIndex:u}){let[y,g]=(0,R.useState)(!1),[f,_]=(0,R.useState)(null),[x,v]=(0,R.useState)(!1),w=(0,R.useRef)(0),A=(0,R.useRef)(null),I=(0,R.useRef)(""),b=(0,R.useCallback)(async(d,a)=>{A.current?.abort();let l=new AbortController;A.current=l;let K=++w.current,k=e.current.length;n.current.some(E=>E.type!=="placeholder")||g(!0),_(null);try{let E=await ze(d,a,{maskCompletedText:r.current,signal:l.signal,apiConfig:i.current});if(K!==w.current)return;let j=Fe(E.data.suggestions??[],s.current);v(E.data.is_ready??!1),I.current=d;let L=E.data.input??[],M=L[L.length-1],U=e.current;if(M?.state==="in_progress"){o.current=!0;let N=U.toLowerCase().lastIndexOf(M.text.toLowerCase());N!==-1?t.current=N:t.current=k}else o.current=!1,t.current=k;let q=j.filter(N=>N.type!=="placeholder")[0];if(q){let N=Y(U,t.current,o.current),B=re(q.options,N);B&&(m(V=>[...V,{id:crypto.randomUUID(),placeholder:"",type:q.type,text:B.text,kind:B.kind,suggestionType:q.type,suggestionPlaceholder:q.text,options:q.options??[],metadata:B.metadata}]),j=j.filter(V=>V!==q))}c(j),g(!1),u(-1)}catch(E){if(K===w.current){let j=E instanceof Error?E:new Error(String(E));_(j),g(!1),h.current?.(j)}}},[e,n,t,o,r,i,s,h,m,c,u]);return(0,R.useEffect)(()=>(b("",[]),()=>{A.current?.abort()}),[b]),{doFetch:b,isLoading:y,error:f,isReady:x,lastRawQueryRef:I}}function Ne({text:e,completedParams:n,doFetch:t,filterBaseRef:o,filterInProgressRef:r,skipNextFetchRef:i,suggestionsRef:s,lastRawQueryRef:h}){let m=(0,R.useRef)(null),c=(0,R.useRef)(null),u=(0,R.useRef)(!0);(0,R.useEffect)(()=>{m.current&&clearTimeout(m.current),c.current&&clearTimeout(c.current);let y=g=>{if(i.current)return i.current=!1,!1;if(!e&&n.length===0)return u.current?(t("",[]),!0):(u.current=!0,!1);let f=Y(e,o.current,r.current),v=s.current.filter(k=>k.type!=="placeholder")[0],A=(v?ce(v.options,f):[]).filter(k=>k.is_tappable),I=v?re(v.options,f)!==null:!1,b=f.trim().length>0;if(A.length>0&&!I&&b)return!1;let{rawQuery:d,completedParams:a}=ee(e,n),l=d.length<h.current.length,K=Math.abs(d.length-h.current.length);return l||K>=g?(t(d,a),!0):!1};return m.current=setTimeout(()=>{y(mt)&&c.current&&clearTimeout(c.current)},pt),c.current=setTimeout(()=>y(1),dt),()=>{m.current&&clearTimeout(m.current),c.current&&clearTimeout(c.current)}},[e,n,t,o,r,i,s,h])}var Ce=require("react");function Qe({activeDropdownIndex:e,setActiveDropdownIndex:n,filteredOptions:t,selectOption:o,onSubmitRef:r,text:i,completedParams:s,isDropdownOpen:h,hasPlaceholder:m,placeholderText:c,suggestions:u,actionableSuggestions:y,setActivePill:g,filterBaseRef:f,columns:_,setText:x,setCompletedParams:v,setSuggestions:w}){let A=(0,Ce.useCallback)(()=>{let b=t.map((a,l)=>a.is_tappable?l:-1).filter(a=>a!==-1),d=Array.from({length:_},()=>[]);for(let a of b)d[a%_].push(a);return d.flat()},[t,_]);return{handleKeyDown:(0,Ce.useCallback)(b=>{let d=A();switch(b.key){case"ArrowDown":{if(b.preventDefault(),d.length===0)return;let a=d.indexOf(e),l=a<d.length-1?a+1:0;n(d[l]);break}case"ArrowUp":{if(b.preventDefault(),d.length===0)return;let a=d.indexOf(e),l=a>0?a-1:d.length-1;n(d[l]);break}case"ArrowRight":{if(e<0){y.length>1&&(b.preventDefault(),g(1));break}if(e%_<_-1){let l=e+1;l<t.length&&t[l]?.is_tappable&&(b.preventDefault(),n(l))}break}case"ArrowLeft":{if(e<0)break;if(e%_>0){let a=e-1;a>=0&&t[a]?.is_tappable&&(b.preventDefault(),n(a))}break}case"Enter":{if(b.preventDefault(),e>=0&&t[e]?.is_tappable)o(t[e]);else if(r.current){let{rawQuery:a,completedParams:l}=ee(i,s),K={query:i.trim(),raw_query:a,completed_params:l};r.current(K)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)b.preventDefault(),o(t[e]);else if(h){let a=t.find(l=>l.is_tappable);a&&(b.preventDefault(),o(a))}else if(!i&&m){b.preventDefault();let a=u.find(l=>l.type==="placeholder");a?(x(c),f.current=c.length,v(l=>[...l,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:c,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[]}]),w(l=>l.filter(K=>K!==a))):(x(c),f.current=c.length)}break}case"Escape":n(-1);break}},[y,e,_,s,t,f,A,m,h,r,c,o,n,g,v,w,x,u,i]),getTappableIndices:A}}var ue=require("react");function $e({completedParams:e,suggestions:n,setCompletedParams:t,setSuggestions:o,setActiveDropdownIndex:r,filterBaseRef:i,pillTappedRef:s}){let h=(0,ue.useCallback)(u=>{let y=n.filter(x=>x.type!=="placeholder");if(u<0||u>=y.length)return;let g=y[u],f=y.filter((x,v)=>v!==u),_=n.filter(x=>x.type==="placeholder");o([..._,g,...f]),s.current=!0,r(-1)},[n,o,r,s]),m=(0,ue.useCallback)(()=>{if(e.length===0)return;let u=e[e.length-1],y={type:u.suggestionType,text:u.suggestionPlaceholder,required:!0,options:u.options};t(g=>g.slice(0,-1)),o(g=>[y,...g]),r(-1)},[e,t,o,r]),c=(0,ue.useCallback)(u=>{let y={type:u.suggestionType,text:u.suggestionPlaceholder,required:!0,options:u.options};return{apply:g=>{g(f=>{let _=0;for(let x of e){let v=f.indexOf(x.text,_);if(v!==-1){if(x.id===u.id){let w=f.slice(0,v),A=f.slice(v+u.text.length),I=(w+A).replace(/ {2,}/g," ");return i.current=Math.min(i.current,I.length),I}_=v+x.text.length}}return f}),t(f=>f.filter(_=>_.id!==u.id)),o(f=>[y,...f]),r(-1),s.current=!0}}},[e,t,o,r,i,s]);return{setActivePill:h,removeLastParam:m,reEditParam:c}}var gt=0;function ft(){let e=(0,p.useRef)(null);return e.current===null&&(e.current=`:ac-${++gt}:`),e.current}function pe({onSubmit:e,onError:n,optionOverrides:t,maskCompletedText:o,placeholder:r,apiConfig:i,columns:s=2,eagerSuggestions:h=!0,value:m,completedParams:c,onChange:u,onParamsChange:y}){let g=m!==void 0,f=c!==void 0,[_,x]=(0,p.useState)(""),[v,w]=(0,p.useState)([]),[A,I]=(0,p.useState)([]),[b,d]=(0,p.useState)(-1),a=g?m:_,l=f?c:v,K=(0,p.useRef)(e);K.current=e;let k=(0,p.useRef)(u);k.current=u;let $=(0,p.useRef)(y);$.current=y;let E=(0,p.useRef)(m);E.current=m;let j=(0,p.useRef)(c);j.current=c;let L=(0,p.useCallback)(S=>{if(typeof S=="function")if(g){let C=S(E.current??"");k.current?.(C)}else x(C=>{let H=S(C);return k.current?.(H),H});else g||x(S),k.current?.(S)},[g]),M=(0,p.useCallback)(S=>{if(typeof S=="function")if(f){let C=S(j.current??[]);$.current?.(C)}else w(C=>{let H=S(C);return $.current?.(H),H});else f||w(S),$.current?.(S)},[f]),U=(0,p.useRef)(n);U.current=n;let W=(0,p.useRef)(t);W.current=t;let q=(0,p.useRef)(o);q.current=o;let N=(0,p.useRef)(i);N.current=i;let B=(0,p.useRef)(a);B.current=a;let V=(0,p.useRef)(A);V.current=A;let z=(0,p.useRef)(0),te=(0,p.useRef)(!1),ie=(0,p.useRef)(!1),Ie=(0,p.useRef)(!1),de=ft(),{doFetch:me,isLoading:we,error:He,isReady:We,lastRawQueryRef:ge}=qe({textRef:B,suggestionsRef:V,filterBaseRef:z,filterInProgressRef:te,maskCompletedTextRef:q,apiConfigRef:N,optionOverridesRef:W,onErrorRef:U,setCompletedParams:M,setSuggestions:I,setActiveDropdownIndex:d});Ne({text:a,completedParams:l,doFetch:me,filterBaseRef:z,filterInProgressRef:te,skipNextFetchRef:Ie,suggestionsRef:V,lastRawQueryRef:ge});let Ve=(0,p.useMemo)(()=>De(a,l),[a,l]);z.current=Math.min(z.current,a.length);let fe=Y(a,z.current,te.current),be=(0,p.useMemo)(()=>A.filter(C=>C.type==="placeholder").map(C=>C.text).join(" ")||r||"",[A,r]),oe=(0,p.useMemo)(()=>A.filter(S=>S.type!=="placeholder"),[A]),P=oe[0],Oe=P?t?.[P.type]:void 0,Re=P?Oe?Oe(fe.trim()):P.options??[]:[],he=(0,p.useMemo)(()=>ce(Re,fe),[Re,fe]),ke=be.length>0,ye=!we&&he.length>0&&(!!a||ie.current||!ke),Me=(0,p.useCallback)(S=>{if(!P)return;let C={id:crypto.randomUUID(),placeholder:"",type:P.type,text:S.text,kind:S.kind,suggestionType:P.type,suggestionPlaceholder:P.text,options:P.options??[],metadata:S.metadata},H=z.current,D=B.current.slice(0,H);if(D.length>0&&!D.endsWith(" ")){let O=D.split(/\s+/).pop()??"";O&&S.text.toLowerCase().startsWith(O.toLowerCase())&&(D=D.slice(0,D.length-O.length))}let Se=D.length>0&&D[D.length-1]!==" ",Z=D+(Se?" ":"")+S.text+" ";L(Z),z.current=Z.length,M(O=>[...O,C]),ie.current=!1,d(-1);let G=oe.length-1;h&&G>0?(I(O=>O.filter(X=>X!==P)),Ie.current=!0):I(O=>O.filter(X=>X.type==="placeholder"))},[P,oe,h,L,M]),Ge=(0,p.useCallback)(S=>{let C=S.target.value,D=C.length>0&&!S.nativeEvent?.isComposing&&C[0]!==C[0].toUpperCase()?C[0].toUpperCase()+C.slice(1):C;L(D),ie.current=!1,d(-1);let{valid:Se,invalid:Z}=Ke(D,l);if(Z.length>0){M(()=>Se);for(let G of Z)I(O=>[{type:G.suggestionType,text:G.suggestionPlaceholder,required:!0,options:G.options},...O])}if(P&&Z.length===0){let G=Y(D,z.current,te.current),O=re(P.options,G);O&&(M(X=>[...X,{id:crypto.randomUUID(),placeholder:"",type:P.type,text:O.text,kind:O.kind,suggestionType:P.type,suggestionPlaceholder:P.text,options:P.options??[],metadata:O.metadata}]),I(X=>X.filter(et=>et!==P)))}},[l,P,L,M]),ne=$e({completedParams:l,suggestions:A,setCompletedParams:M,setSuggestions:I,setActiveDropdownIndex:d,filterBaseRef:z,pillTappedRef:ie}),Xe=(0,p.useCallback)(S=>{ne.reEditParam(S).apply(L)},[ne,L]),{handleKeyDown:Ze}=Qe({activeDropdownIndex:b,setActiveDropdownIndex:d,filteredOptions:he,selectOption:Me,onSubmitRef:K,text:a,completedParams:l,isDropdownOpen:ye,hasPlaceholder:ke,placeholderText:be,suggestions:A,actionableSuggestions:oe,setActivePill:ne.setActivePill,filterBaseRef:z,columns:s,setText:L,setCompletedParams:M,setSuggestions:I}),Je=(0,p.useCallback)(()=>{L(""),M(()=>[]),I([]),d(-1),z.current=0,te.current=!1,ge.current="",me("",[])},[me,L,M,ge]),Ye=b>=0?`${de}-option-${b}`:void 0;return{completedParams:l,suggestionPills:oe,setActivePill:ne.setActivePill,removeLastParam:ne.removeLastParam,reEditParam:Xe,segments:Ve,suggestions:A,activeIndex:b,isReady:We,isLoading:we,error:He,inputProps:{value:a,placeholder:be||void 0,onChange:Ge,onKeyDown:Ze,role:"combobox","aria-expanded":ye,"aria-activedescendant":Ye,"aria-autocomplete":"list","aria-controls":de},reset:Je,dropdownProps:{suggestions:P?[{...P,options:he}]:[],activeIndex:b,onSelect:Me,onHighlight:d,isOpen:ye,id:de}}}var T=require("react/jsx-runtime"),Be=(0,F.forwardRef)(function({onSubmit:n,onError:t,optionOverrides:o,maskCompletedText:r,placeholder:i,className:s,apiConfig:h,columns:m,eagerSuggestions:c,value:u,completedParams:y,onChange:g,onParamsChange:f},_){let x=(0,F.useRef)(null),v=(0,F.useRef)(()=>{});(0,F.useEffect)(()=>{x.current?.focus()},[]);let{completedParams:w,suggestionPills:A,setActivePill:I,segments:b,inputProps:d,dropdownProps:a,reset:l}=pe({onSubmit:U=>v.current(U),onError:t,optionOverrides:o,maskCompletedText:r,placeholder:i,apiConfig:h,columns:m,eagerSuggestions:c,value:u,completedParams:y,onChange:g,onParamsChange:f});(0,F.useImperativeHandle)(_,()=>({focus:()=>x.current?.focus(),reset:l}),[l]);let K=()=>{x.current?.focus()},k=!!d.value||w.length>0,$=(0,F.useCallback)(()=>{if(!k)return;let{rawQuery:U,completedParams:W}=ee(d.value,w);n({query:d.value.trim(),raw_query:U,completed_params:W}),l()},[k,d.value,w,n,l]);v.current=$;let{onChange:E,placeholder:j,...L}=d,M=!d.value;return(0,T.jsxs)("div",{className:`${Q.container} ${s??""}`,children:[(0,T.jsx)(se,{...a}),(0,T.jsxs)("div",{className:Q.inputWrapper,onClick:K,children:[(0,T.jsxs)("div",{className:Q.editorArea,children:[(0,T.jsxs)("div",{className:Q.sizerContent,"aria-hidden":"true",children:[M&&j?(0,T.jsxs)("span",{className:Q.placeholderText,children:[j," "]}):(0,T.jsxs)("span",{className:Q.sizerText,children:[b.map((U,W)=>(0,T.jsx)("span",{children:U.value},`${W}-${U.type}`)),b.length===0&&"\xA0"]})," ",(0,T.jsx)(Ue,{pills:A,activePillIndex:0,onSelectPill:I})]}),(0,T.jsx)("textarea",{ref:x,className:Q.textarea,rows:1,onChange:E,...L})]}),(0,T.jsx)("button",{type:"button",className:Q.submitButton,disabled:!k,onClick:U=>{U.stopPropagation(),$()},"aria-label":"Submit",children:(0,T.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,T.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
|
|
264
215
|
//# sourceMappingURL=index.js.map
|