@magicx-eng/ai-autocomplete-react 0.1.10 → 0.1.12
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- 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.d.mts
CHANGED
|
@@ -21,7 +21,7 @@ interface Suggestion {
|
|
|
21
21
|
type: string;
|
|
22
22
|
text: string;
|
|
23
23
|
required: boolean;
|
|
24
|
-
options
|
|
24
|
+
options?: SuggestionOption[];
|
|
25
25
|
}
|
|
26
26
|
interface CompletedParamState extends CompletedParam {
|
|
27
27
|
id: string;
|
|
@@ -47,6 +47,7 @@ interface APIConfig {
|
|
|
47
47
|
endpoint?: string;
|
|
48
48
|
apiKey?: string;
|
|
49
49
|
authScheme?: "Bearer" | "Basic";
|
|
50
|
+
appIdentifier?: string;
|
|
50
51
|
headers?: Record<string, string>;
|
|
51
52
|
}
|
|
52
53
|
type OptionOverrides = Record<string, (query: string) => SuggestionOption[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface Suggestion {
|
|
|
21
21
|
type: string;
|
|
22
22
|
text: string;
|
|
23
23
|
required: boolean;
|
|
24
|
-
options
|
|
24
|
+
options?: SuggestionOption[];
|
|
25
25
|
}
|
|
26
26
|
interface CompletedParamState extends CompletedParam {
|
|
27
27
|
id: string;
|
|
@@ -47,6 +47,7 @@ interface APIConfig {
|
|
|
47
47
|
endpoint?: string;
|
|
48
48
|
apiKey?: string;
|
|
49
49
|
authScheme?: "Bearer" | "Basic";
|
|
50
|
+
appIdentifier?: string;
|
|
50
51
|
headers?: Record<string, string>;
|
|
51
52
|
}
|
|
52
53
|
type OptionOverrides = Record<string, (query: string) => SuggestionOption[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,57 +1,8 @@
|
|
|
1
|
-
"use strict";var ye=Object.defineProperty;var
|
|
1
|
+
"use strict";var ye=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var ot=(e,r)=>{for(var t in r)ye(e,t,{get:r[t],enumerable:!0})},nt=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of et(r))!tt.call(e,o)&&o!==t&&ye(e,o,{get:()=>r[o],enumerable:!(n=Ye(r,o))||n.enumerable});return e};var rt=e=>nt(ye({},"__esModule",{value:!0}),e);var gt={};ot(gt,{AIAutocomplete:()=>$e,AIAutocompleteDropdown:()=>re,useAIAutocomplete:()=>le});module.exports=rt(gt);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 $={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
|
|
108
|
+
`,document.head.appendChild(e)}var Se={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 ke={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 Z={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 ne=require("react/jsx-runtime");function Me({option:e,isHighlighted:r,onSelect:t,onHighlight:n,id:o}){let i=[Z.item,r?Z.highlighted:"",e.is_tappable?Z.tappable:Z.nonTappable].filter(Boolean).join(" ");return(0,ne.jsxs)("div",{id:o,role:"option","aria-selected":r,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:n,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,ne.jsx)("span",{className:Z.tag,children:e.tag})]})}var xe=require("react/jsx-runtime");function Te({options:e,activeIndex:r,onSelect:t,onHighlight:n,listboxId:o}){return(0,xe.jsx)("div",{className:ke.grid,children:e.map((i,s)=>(0,xe.jsx)(Me,{option:i,isHighlighted:s===r,onSelect:t,onHighlight:()=>n(s),id:`${o}-option-${s}`},i.text))})}var Ae=require("react/jsx-runtime");function re({suggestions:e,activeIndex:r,onSelect:t,onHighlight:n,isOpen:o,id:i,className:s}){let d=e[0]?.options??[],f=o&&d.length>0;return(0,Ae.jsx)("div",{id:i,role:"listbox",className:`${Se.dropdown} ${f?Se.visible:""} ${s??""}`,onMouseDown:c=>c.preventDefault(),children:d.length>0&&(0,Ae.jsx)(Te,{options:d,activeIndex:r,onSelect:t,onHighlight:n,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 it(e){return e===0?.4:e===1?.3:.15}function Me({pills:e,activePillIndex:o,onSelectPill:t}){return(0,xe.jsx)("span",{className:ie.list,children:e.map((r,n)=>(0,xe.jsx)("button",{type:"button",className:`${ie.pill} ${n===o?ie.active:""}`,style:{opacity:it(n)},onClick:()=>t(n),children:r.text},`${r.type}-${r.text}`))})}var p=require("react");function ae(e,o){if(!e)return[];let t=o.trimStart();if(!t)return e;let r=t.toLowerCase();return e.filter(n=>!n.is_tappable||n.text.toLowerCase().includes(r))}function J(e,o){if(!e)return null;let t=o.trim();if(!t)return null;let r=t.toLowerCase();return e.find(n=>n.is_tappable&&n.text.toLowerCase()===r)??null}function Le(e,o){let t=[],r=0;for(let i of o){let s=e.indexOf(i.text,r);s!==-1&&(s>r&&t.push({type:"text",value:e.slice(r,s)}),t.push({type:"completed",value:i.text,param:i}),r=s+i.text.length)}let n=e.slice(r);return n&&t.push({type:"text",value:n}),t}function Ue(e,o){let t=[],r=[],n=0;for(let i of o){let s=e.indexOf(i.text,n);s===-1?r.push(i):(t.push(i),n=s+i.text.length)}return{valid:t,invalid:r}}var E=require("react");var at="0.1.10",st="/ac/suggest",De=!1;function lt(e){let o=e?.apiKey||""||"";return!o&&!De&&(De=!0,console.warn("[AIAutocomplete] No API key set (MAGICX_AI_AUTOCOMPLETE_API_KEY). Requests will be sent without an Authorization header.")),o}function ct(e){return e?.authScheme?e.authScheme:""==="Basic"?"Basic":"Bearer"}function ut(){return crypto.randomUUID()}function pt(e,o){return{placeholder:e.placeholder,type:e.type,...o&&{text:e.text},kind:e.kind}}async function Ke(e,o,t){let r=t?.apiConfig,n=lt(r),i=ct(r),s=!t?.maskCompletedText,m=o.find(l=>l.type==="contact"&&l.metadata?.contact_account_count)?.metadata?.contact_account_count,f=typeof m=="number"?m:void 0,h={data:{raw_query:e,completed_params:o.map(l=>pt(l,s)),...f!=null&&{contact_account_count:f}},meta:{request_id:ut(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:at}},d={"Content-Type":"application/json","X-App-Identifier":"active-campaign-demo",...r?.headers};n&&(d.Authorization=i==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`);let b=await fetch(r?.endpoint||st,{method:"POST",headers:d,body:JSON.stringify(h),signal:t?.signal});if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}function Z(e,o){let t=e,r={},n=[];for(let i of o){let s=(r[i.type]??0)+1;r[i.type]=s;let f=`{{${i.type.toUpperCase().replace(/\s+/g,"_")}_${s}}}`,h=t.indexOf(i.text);h!==-1&&(t=t.slice(0,h)+f+t.slice(h+i.text.length)),n.push({...i,placeholder:f})}return{rawQuery:t,completedParams:n}}function je(e,o){return o?e.map(t=>{let r=o[t.type];if(!r)return t;let n=r("");if(n.length===0)return t;let i=new Set(n.map(m=>m.text)),s=(t.options??[]).filter(m=>!i.has(m.text));return{...t,options:[...n,...s]}}):e}var mt=100,dt=300,gt=2;function Fe({textRef:e,suggestionsRef:o,filterBaseRef:t,maskCompletedTextRef:r,apiConfigRef:n,optionOverridesRef:i,onErrorRef:s,setCompletedParams:m,setSuggestions:f,setActiveDropdownIndex:h}){let[d,b]=(0,E.useState)(!1),[l,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)(""),c=(0,E.useCallback)(async(a,u)=>{U.current?.abort();let S=new AbortController;U.current=S;let w=++v.current,O=e.current.length;o.current.some(I=>I.type!=="placeholder")||b(!0),A(null);try{let I=await Ke(a,u,{maskCompletedText:r.current,signal:S.signal,apiConfig:n.current});if(w!==v.current)return;let j=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 N=L.toLowerCase().lastIndexOf(M.text.toLowerCase());N!==-1?t.current=N:t.current=O}else t.current=O;let F=j.filter(N=>N.type!=="placeholder")[0];if(F){let N=L.slice(t.current),R=J(F.options,N);R&&(m(B=>[...B,{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}]),j=j.filter(B=>B!==F))}f(j),b(!1),h(-1)}catch(I){if(w===v.current){let j=I instanceof Error?I:new Error(String(I));A(j),b(!1),s.current?.(j)}}},[e,o,t,r,n,i,s,m,f,h]);return(0,E.useEffect)(()=>(c("",[]),()=>{U.current?.abort()}),[c]),{doFetch:c,isLoading:d,error:l,isReady:k,lastRawQueryRef:g}}function ze({text:e,completedParams:o,doFetch:t,filterBaseRef:r,skipNextFetchRef:n,suggestionsRef:i,lastRawQueryRef:s}){let m=(0,E.useRef)(null),f=(0,E.useRef)(null),h=(0,E.useRef)(!0);(0,E.useEffect)(()=>{m.current&&clearTimeout(m.current),f.current&&clearTimeout(f.current);let d=b=>{if(n.current)return n.current=!1,!1;if(!e&&o.length===0)return h.current?(t("",[]),!0):(h.current=!0,!1);let l=e.slice(r.current),y=i.current.filter(O=>O.type!=="placeholder")[0],U=(y?ae(y.options,l):[]).filter(O=>O.is_tappable),g=y?J(y.options,l)!==null:!1,c=l.trim().length>0;if(U.length>0&&!g&&c)return!1;let{rawQuery:a,completedParams:u}=Z(e,o),S=a.length<s.current.length,w=Math.abs(a.length-s.current.length);return S||w>=b?(t(a,u),!0):!1};return m.current=setTimeout(()=>{d(gt)&&f.current&&clearTimeout(f.current)},mt),f.current=setTimeout(()=>d(1),dt),()=>{m.current&&clearTimeout(m.current),f.current&&clearTimeout(f.current)}},[e,o,t,r,n,i,s])}var Pe=require("react");function Ne({activeDropdownIndex:e,setActiveDropdownIndex:o,filteredOptions:t,selectOption:r,onSubmitRef:n,text:i,completedParams:s,isDropdownOpen:m,hasPlaceholder:f,placeholderText:h,suggestions:d,filterBaseRef:b,columns:l,setText:A,setCompletedParams:k,setSuggestions:y}){let v=(0,Pe.useCallback)(()=>{let g=t.map((a,u)=>a.is_tappable?u:-1).filter(a=>a!==-1),c=Array.from({length:l},()=>[]);for(let a of g)c[a%l].push(a);return c.flat()},[t,l]);return{handleKeyDown:(0,Pe.useCallback)(g=>{let c=v();switch(g.key){case"ArrowDown":{if(g.preventDefault(),c.length===0)return;let a=c.indexOf(e),u=a<c.length-1?a+1:0;o(c[u]);break}case"ArrowUp":{if(g.preventDefault(),c.length===0)return;let a=c.indexOf(e),u=a>0?a-1:c.length-1;o(c[u]);break}case"ArrowRight":{if(e<0)break;if(e%l<l-1){let u=e+1;u<t.length&&t[u]?.is_tappable&&(g.preventDefault(),o(u))}break}case"ArrowLeft":{if(e<0)break;if(e%l>0){let a=e-1;a>=0&&t[a]?.is_tappable&&(g.preventDefault(),o(a))}break}case"Enter":{if(g.preventDefault(),e>=0&&t[e]?.is_tappable)r(t[e]);else if(n.current){let{rawQuery:a,completedParams:u}=Z(i,s),S={query:i.trim(),raw_query:a,completed_params:u};n.current(S)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)g.preventDefault(),r(t[e]);else if(m){let a=t.find(u=>u.is_tappable);a&&(g.preventDefault(),r(a))}else if(!i&&f){g.preventDefault();let a=d.find(u=>u.type==="placeholder");a?(A(h),b.current=h.length,k(u=>[...u,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:h,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options}]),y(u=>u.filter(S=>S!==a))):(A(h),b.current=h.length)}break}case"Escape":o(-1);break}},[e,l,s,t,b,v,f,m,n,h,r,o,k,y,A,d,i]),getTappableIndices:v}}var se=require("react");function Be({completedParams:e,suggestions:o,setCompletedParams:t,setSuggestions:r,setActiveDropdownIndex:n,filterBaseRef:i,pillTappedRef:s}){let m=(0,se.useCallback)(d=>{let b=o.filter(y=>y.type!=="placeholder");if(d<0||d>=b.length)return;let l=b[d],A=b.filter((y,v)=>v!==d),k=o.filter(y=>y.type==="placeholder");r([...k,l,...A]),s.current=!0,n(-1)},[o,r,n,s]),f=(0,se.useCallback)(()=>{if(e.length===0)return;let d=e[e.length-1],b={type:d.suggestionType,text:d.suggestionPlaceholder,required:!0,options:d.options};t(l=>l.slice(0,-1)),r(l=>[b,...l]),n(-1)},[e,t,r,n]),h=(0,se.useCallback)(d=>{let b={type:d.suggestionType,text:d.suggestionPlaceholder,required:!0,options:d.options};return{apply:l=>{l(A=>{let k=0;for(let y of e){let v=A.indexOf(y.text,k);if(v!==-1){if(y.id===d.id){let U=A.slice(0,v),g=A.slice(v+d.text.length),c=(U+g).replace(/ {2,}/g," ");return i.current=Math.min(i.current,c.length),c}k=v+y.text.length}}return A}),t(A=>A.filter(k=>k.id!==d.id)),r(A=>[b,...A]),n(-1),s.current=!0}}},[e,t,r,n,i,s]);return{setActivePill:m,removeLastParam:f,reEditParam:h}}var ft=0;function ht(){let e=(0,p.useRef)(null);return e.current===null&&(e.current=`:ac-${++ft}:`),e.current}function le({onSubmit:e,onError:o,optionOverrides:t,maskCompletedText:r,placeholder:n,apiConfig:i,columns:s=2,eagerSuggestions:m=!0,value:f,completedParams:h,onChange:d,onParamsChange:b}){let l=f!==void 0,A=h!==void 0,[k,y]=(0,p.useState)(""),[v,U]=(0,p.useState)([]),[g,c]=(0,p.useState)([]),[a,u]=(0,p.useState)(-1),S=l?f:k,w=A?h:v,O=(0,p.useRef)(e);O.current=e;let H=(0,p.useRef)(d);H.current=d;let I=(0,p.useRef)(b);I.current=b;let j=(0,p.useRef)(f);j.current=f;let q=(0,p.useRef)(h);q.current=h;let M=(0,p.useCallback)(_=>{if(typeof _=="function")if(l){let P=_(j.current??"");H.current?.(P)}else y(P=>{let Q=_(P);return H.current?.(Q),Q});else l||y(_),H.current?.(_)},[l]),L=(0,p.useCallback)(_=>{if(typeof _=="function")if(A){let P=_(q.current??[]);I.current?.(P)}else U(P=>{let Q=_(P);return I.current?.(Q),Q});else A||U(_),I.current?.(_)},[A]),X=(0,p.useRef)(o);X.current=o;let F=(0,p.useRef)(t);F.current=t;let N=(0,p.useRef)(r);N.current=r;let R=(0,p.useRef)(i);R.current=i;let B=(0,p.useRef)(S);B.current=S;let ce=(0,p.useRef)(g);ce.current=g;let $=(0,p.useRef)(0),ee=(0,p.useRef)(!1),ve=(0,p.useRef)(!1),ue=ht(),{doFetch:pe,isLoading:Ie,error:qe,isReady:Qe,lastRawQueryRef:me}=Fe({textRef:B,suggestionsRef:ce,filterBaseRef:$,maskCompletedTextRef:N,apiConfigRef:R,optionOverridesRef:F,onErrorRef:X,setCompletedParams:L,setSuggestions:c,setActiveDropdownIndex:u});ze({text:S,completedParams:w,doFetch:pe,filterBaseRef:$,skipNextFetchRef:ve,suggestionsRef:ce,lastRawQueryRef:me});let He=(0,p.useMemo)(()=>Le(S,w),[S,w]);$.current=Math.min($.current,S.length);let de=S.slice($.current),ge=(0,p.useMemo)(()=>g.filter(P=>P.type==="placeholder").map(P=>P.text).join(" ")||n||"",[g,n]),te=(0,p.useMemo)(()=>g.filter(_=>_.type!=="placeholder"),[g]),x=te[0],Ce=x?t?.[x.type]:void 0,ke=x?Ce?Ce(de.trim()):x.options??[]:[],fe=(0,p.useMemo)(()=>ae(ke,de),[ke,de]),we=ge.length>0,he=!Ie&&fe.length>0&&(!!S||ee.current||!we),Oe=(0,p.useCallback)(_=>{if(!x)return;let P={id:crypto.randomUUID(),placeholder:"",type:x.type,text:_.text,kind:_.kind,suggestionType:x.type,suggestionPlaceholder:x.text,options:x.options,metadata:_.metadata},Q=$.current,D=B.current.slice(0,Q);if(D.length>0&&!D.endsWith(" ")){let T=D.split(/\s+/).pop()??"";T&&_.text.toLowerCase().startsWith(T.toLowerCase())&&(D=D.slice(0,D.length-T.length))}let be=D.length>0&&D[D.length-1]!==" ",G=D+(be?" ":"")+_.text+" ";M(G),$.current=G.length,L(T=>[...T,P]),ee.current=!1,u(-1);let V=te.length-1;m&&V>0?(c(T=>T.filter(W=>W!==x)),ve.current=!0):c(T=>T.filter(W=>W.type==="placeholder"))},[x,te,m,M,L]),Ve=(0,p.useCallback)(_=>{let P=_.target.value,D=P.length>0&&!_.nativeEvent?.isComposing&&P[0]!==P[0].toUpperCase()?P[0].toUpperCase()+P.slice(1):P;M(D),ee.current=!1,u(-1);let{valid:be,invalid:G}=Ue(D,w);if(G.length>0){L(()=>be);for(let V of G)c(T=>[{type:V.suggestionType,text:V.suggestionPlaceholder,required:!0,options:V.options},...T])}if(x&&G.length===0){let V=D.slice($.current),T=J(x.options,V);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}]),c(W=>W.filter(Ze=>Ze!==x)))}},[w,x,M,L]),{handleKeyDown:We}=Ne({activeDropdownIndex:a,setActiveDropdownIndex:u,filteredOptions:fe,selectOption:Oe,onSubmitRef:O,text:S,completedParams:w,isDropdownOpen:he,hasPlaceholder:we,placeholderText:ge,suggestions:g,filterBaseRef:$,columns:s,setText:M,setCompletedParams:L,setSuggestions:c}),oe=Be({completedParams:w,suggestions:g,setCompletedParams:L,setSuggestions:c,setActiveDropdownIndex:u,filterBaseRef:$,pillTappedRef:ee}),Xe=(0,p.useCallback)(_=>{oe.reEditParam(_).apply(M)},[oe,M]),Ge=(0,p.useCallback)(()=>{M(""),L(()=>[]),c([]),u(-1),$.current=0,me.current="",pe("",[])},[pe,M,L,me]),Ye=a>=0?`${ue}-option-${a}`:void 0;return{completedParams:w,suggestionPills:te,setActivePill:oe.setActivePill,removeLastParam:oe.removeLastParam,reEditParam:Xe,segments:He,suggestions:g,activeIndex:a,isReady:Qe,isLoading:Ie,error:qe,inputProps:{value:S,placeholder:ge||void 0,onChange:Ve,onKeyDown:We,role:"combobox","aria-expanded":he,"aria-activedescendant":Ye,"aria-autocomplete":"list","aria-controls":ue},reset:Ge,dropdownProps:{suggestions:x?[{...x,options:fe}]:[],activeIndex:a,onSelect:Oe,onHighlight:u,isOpen:he,id:ue}}}var C=require("react/jsx-runtime"),$e=(0,K.forwardRef)(function({onSubmit:o,onError:t,optionOverrides:r,maskCompletedText:n,placeholder:i,className:s,apiConfig:m,columns:f,eagerSuggestions:h,value:d,completedParams:b,onChange:l,onParamsChange:A},k){let y=(0,K.useRef)(null),[v,U]=(0,K.useState)(!1),g=(0,K.useRef)(()=>{}),c=(0,K.useRef)(void 0);(0,K.useEffect)(()=>(y.current?.focus(),()=>clearTimeout(c.current)),[]);let{completedParams:a,suggestionPills:u,setActivePill:S,segments:w,inputProps:O,dropdownProps:H,reset:I}=le({onSubmit:R=>g.current(R),onError:t,optionOverrides:r,maskCompletedText:n,placeholder:i,apiConfig:m,columns:f,eagerSuggestions:h,value:d,completedParams:b,onChange:l,onParamsChange:A});(0,K.useImperativeHandle)(k,()=>({focus:()=>y.current?.focus(),reset:I}),[I]);let j=()=>{y.current?.focus()},q=!!O.value||a.length>0,M=(0,K.useCallback)(()=>{if(!q)return;let{rawQuery:R,completedParams:B}=Z(O.value,a);o({query:O.value.trim(),raw_query:R,completed_params:B}),I(),U(!0),clearTimeout(c.current),c.current=setTimeout(()=>U(!1),3e3)},[q,O.value,a,o,I]);g.current=M;let{onChange:L,placeholder:X,...F}=O,N=!O.value;return(0,C.jsxs)("div",{className:`${z.container} ${s??""}`,children:[(0,C.jsx)("div",{className:`${z.checkmark} ${v?z.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:z.checkmarkPath})]})}),(0,C.jsx)(re,{...H}),(0,C.jsxs)("div",{className:z.inputWrapper,onClick:j,children:[(0,C.jsxs)("div",{className:z.editorArea,children:[(0,C.jsxs)("div",{className:z.sizerContent,"aria-hidden":"true",children:[N&&X?(0,C.jsxs)("span",{className:z.placeholderText,children:[X," "]}):(0,C.jsxs)("span",{className:z.sizerText,children:[w.map((R,B)=>(0,C.jsx)("span",{children:R.value},`${B}-${R.type}`)),w.length===0&&"\xA0"]})," ",(0,C.jsx)(Me,{pills:u,activePillIndex:0,onSelectPill:S})]}),(0,C.jsx)("textarea",{ref:y,className:z.textarea,rows:1,onChange:L,...F})]}),(0,C.jsx)("button",{type:"button",className:z.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 ie={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",active:"PillList-module_active_Oll--"};var _e=require("react/jsx-runtime");function it(e){return e===0?.4:e===1?.3:.15}function Ee({pills:e,activePillIndex:r,onSelectPill:t}){return(0,_e.jsx)("span",{className:ie.list,children:e.map((n,o)=>(0,_e.jsx)("button",{type:"button",className:`${ie.pill} ${o===r?ie.active:""}`,style:{opacity:it(o)},onClick:()=>t(o),children:n.text},`${n.type}-${n.text}`))})}var p=require("react");function ae(e,r){if(!e)return[];let t=r.trimStart();if(!t)return e;let n=t.toLowerCase();return e.filter(o=>!o.is_tappable||o.text.toLowerCase().includes(n))}function Y(e,r){if(!e)return null;let t=r.trim();if(!t)return null;let n=t.toLowerCase();return e.find(o=>o.is_tappable&&o.text.toLowerCase()===n)??null}function Le(e,r){let t=[],n=0;for(let i of r){let s=e.indexOf(i.text,n);s!==-1&&(s>n&&t.push({type:"text",value:e.slice(n,s)}),t.push({type:"completed",value:i.text,param:i}),n=s+i.text.length)}let o=e.slice(n);return o&&t.push({type:"text",value:o}),t}function Ue(e,r){let t=[],n=[],o=0;for(let i of r){let s=e.indexOf(i.text,o);s===-1?n.push(i):(t.push(i),o=s+i.text.length)}return{valid:t,invalid:n}}var R=require("react");var at="0.1.12",Ke=!1;function st(){return crypto.randomUUID()}function lt(e,r){return{placeholder:e.placeholder,type:e.type,...r&&{text:e.text},kind:e.kind}}async function De(e,r,t){let n=t?.apiConfig,o=n?.apiKey??"";!o&&!Ke&&(Ke=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header."));let i=n?.authScheme??"Bearer",s=!t?.maskCompletedText,b=r.find(u=>u.type==="contact"&&u.metadata?.contact_account_count)?.metadata?.contact_account_count,d=typeof b=="number"?b:void 0,f={data:{raw_query:e,completed_params:r.map(u=>lt(u,s)),...d!=null&&{contact_account_count:d}},meta:{request_id:st(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:at}},c={"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers};o&&(c.Authorization=i==="Basic"?`Basic ${btoa(o)}`:`Bearer ${o}`);let h=await fetch(n?.endpoint??"/ac/suggest",{method:"POST",headers:c,body:JSON.stringify(f),signal:t?.signal});if(!h.ok)throw new Error(`API error: ${h.status} ${h.statusText}`);return h.json()}function J(e,r){let t=e,n={},o=[];for(let i of r){let s=(n[i.type]??0)+1;n[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)),o.push({...i,placeholder:d})}return{rawQuery:t,completedParams:o}}function ze(e,r){return r?e.map(t=>{let n=r[t.type];if(!n)return t;let o=n("");if(o.length===0)return t;let i=new Set(o.map(b=>b.text)),s=(t.options??[]).filter(b=>!i.has(b.text));return{...t,options:[...o,...s]}}):e}var ct=100,ut=300,pt=2;function je({textRef:e,suggestionsRef:r,filterBaseRef:t,maskCompletedTextRef:n,apiConfigRef:o,optionOverridesRef:i,onErrorRef:s,setCompletedParams:b,setSuggestions:d,setActiveDropdownIndex:f}){let[c,h]=(0,R.useState)(!1),[u,S]=(0,R.useState)(null),[w,y]=(0,R.useState)(!1),P=(0,R.useRef)(0),k=(0,R.useRef)(null),g=(0,R.useRef)(""),m=(0,R.useCallback)(async(a,l)=>{k.current?.abort();let A=new AbortController;k.current=A;let C=++P.current,z=e.current.length;r.current.some(I=>I.type!=="placeholder")||h(!0),S(null);try{let I=await De(a,l,{maskCompletedText:n.current,signal:A.signal,apiConfig:o.current});if(C!==P.current)return;let K=ze(I.data.suggestions??[],i.current);y(I.data.is_ready??!1),g.current=a;let B=I.data.input??[],E=B[B.length-1],M=e.current;if(E?.state==="in_progress"){let N=M.toLowerCase().lastIndexOf(E.text.toLowerCase());N!==-1?t.current=N:t.current=z}else t.current=z;let L=K.filter(N=>N.type!=="placeholder")[0];if(L){let N=M.slice(t.current),H=Y(L.options,N);H&&(b(W=>[...W,{id:crypto.randomUUID(),placeholder:"",type:L.type,text:H.text,kind:H.kind,suggestionType:L.type,suggestionPlaceholder:L.text,options:L.options??[],metadata:H.metadata}]),K=K.filter(W=>W!==L))}d(K),h(!1),f(-1)}catch(I){if(C===P.current){let K=I instanceof Error?I:new Error(String(I));S(K),h(!1),s.current?.(K)}}},[e,r,t,n,o,i,s,b,d,f]);return(0,R.useEffect)(()=>(m("",[]),()=>{k.current?.abort()}),[m]),{doFetch:m,isLoading:c,error:u,isReady:w,lastRawQueryRef:g}}function Fe({text:e,completedParams:r,doFetch:t,filterBaseRef:n,skipNextFetchRef:o,suggestionsRef:i,lastRawQueryRef:s}){let b=(0,R.useRef)(null),d=(0,R.useRef)(null),f=(0,R.useRef)(!0);(0,R.useEffect)(()=>{b.current&&clearTimeout(b.current),d.current&&clearTimeout(d.current);let c=h=>{if(o.current)return o.current=!1,!1;if(!e&&r.length===0)return f.current?(t("",[]),!0):(f.current=!0,!1);let u=e.slice(n.current),y=i.current.filter(z=>z.type!=="placeholder")[0],k=(y?ae(y.options,u):[]).filter(z=>z.is_tappable),g=y?Y(y.options,u)!==null:!1,m=u.trim().length>0;if(k.length>0&&!g&&m)return!1;let{rawQuery:a,completedParams:l}=J(e,r),A=a.length<s.current.length,C=Math.abs(a.length-s.current.length);return A||C>=h?(t(a,l),!0):!1};return b.current=setTimeout(()=>{c(pt)&&d.current&&clearTimeout(d.current)},ct),d.current=setTimeout(()=>c(1),ut),()=>{b.current&&clearTimeout(b.current),d.current&&clearTimeout(d.current)}},[e,r,t,n,o,i,s])}var Pe=require("react");function qe({activeDropdownIndex:e,setActiveDropdownIndex:r,filteredOptions:t,selectOption:n,onSubmitRef:o,text:i,completedParams:s,isDropdownOpen:b,hasPlaceholder:d,placeholderText:f,suggestions:c,filterBaseRef:h,columns:u,setText:S,setCompletedParams:w,setSuggestions:y}){let P=(0,Pe.useCallback)(()=>{let g=t.map((a,l)=>a.is_tappable?l:-1).filter(a=>a!==-1),m=Array.from({length:u},()=>[]);for(let a of g)m[a%u].push(a);return m.flat()},[t,u]);return{handleKeyDown:(0,Pe.useCallback)(g=>{let m=P();switch(g.key){case"ArrowDown":{if(g.preventDefault(),m.length===0)return;let a=m.indexOf(e),l=a<m.length-1?a+1:0;r(m[l]);break}case"ArrowUp":{if(g.preventDefault(),m.length===0)return;let a=m.indexOf(e),l=a>0?a-1:m.length-1;r(m[l]);break}case"ArrowRight":{if(e<0)break;if(e%u<u-1){let l=e+1;l<t.length&&t[l]?.is_tappable&&(g.preventDefault(),r(l))}break}case"ArrowLeft":{if(e<0)break;if(e%u>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)n(t[e]);else if(o.current){let{rawQuery:a,completedParams:l}=J(i,s),A={query:i.trim(),raw_query:a,completed_params:l};o.current(A)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)g.preventDefault(),n(t[e]);else if(b){let a=t.find(l=>l.is_tappable);a&&(g.preventDefault(),n(a))}else if(!i&&d){g.preventDefault();let a=c.find(l=>l.type==="placeholder");a?(S(f),h.current=f.length,w(l=>[...l,{id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:null,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[]}]),y(l=>l.filter(A=>A!==a))):(S(f),h.current=f.length)}break}case"Escape":r(-1);break}},[e,u,s,t,h,P,d,b,o,f,n,r,w,y,S,c,i]),getTappableIndices:P}}var se=require("react");function Ne({completedParams:e,suggestions:r,setCompletedParams:t,setSuggestions:n,setActiveDropdownIndex:o,filterBaseRef:i,pillTappedRef:s}){let b=(0,se.useCallback)(c=>{let h=r.filter(y=>y.type!=="placeholder");if(c<0||c>=h.length)return;let u=h[c],S=h.filter((y,P)=>P!==c),w=r.filter(y=>y.type==="placeholder");n([...w,u,...S]),s.current=!0,o(-1)},[r,n,o,s]),d=(0,se.useCallback)(()=>{if(e.length===0)return;let c=e[e.length-1],h={type:c.suggestionType,text:c.suggestionPlaceholder,required:!0,options:c.options};t(u=>u.slice(0,-1)),n(u=>[h,...u]),o(-1)},[e,t,n,o]),f=(0,se.useCallback)(c=>{let h={type:c.suggestionType,text:c.suggestionPlaceholder,required:!0,options:c.options};return{apply:u=>{u(S=>{let w=0;for(let y of e){let P=S.indexOf(y.text,w);if(P!==-1){if(y.id===c.id){let k=S.slice(0,P),g=S.slice(P+c.text.length),m=(k+g).replace(/ {2,}/g," ");return i.current=Math.min(i.current,m.length),m}w=P+y.text.length}}return S}),t(S=>S.filter(w=>w.id!==c.id)),n(S=>[h,...S]),o(-1),s.current=!0}}},[e,t,n,o,i,s]);return{setActivePill:b,removeLastParam:d,reEditParam:f}}var dt=0;function mt(){let e=(0,p.useRef)(null);return e.current===null&&(e.current=`:ac-${++dt}:`),e.current}function le({onSubmit:e,onError:r,optionOverrides:t,maskCompletedText:n,placeholder:o,apiConfig:i,columns:s=2,eagerSuggestions:b=!0,value:d,completedParams:f,onChange:c,onParamsChange:h}){let u=d!==void 0,S=f!==void 0,[w,y]=(0,p.useState)(""),[P,k]=(0,p.useState)([]),[g,m]=(0,p.useState)([]),[a,l]=(0,p.useState)(-1),A=u?d:w,C=S?f:P,z=(0,p.useRef)(e);z.current=e;let q=(0,p.useRef)(c);q.current=c;let I=(0,p.useRef)(h);I.current=h;let K=(0,p.useRef)(d);K.current=d;let B=(0,p.useRef)(f);B.current=f;let E=(0,p.useCallback)(x=>{if(typeof x=="function")if(u){let v=x(K.current??"");q.current?.(v)}else y(v=>{let Q=x(v);return q.current?.(Q),Q});else u||y(x),q.current?.(x)},[u]),M=(0,p.useCallback)(x=>{if(typeof x=="function")if(S){let v=x(B.current??[]);I.current?.(v)}else k(v=>{let Q=x(v);return I.current?.(Q),Q});else S||k(x),I.current?.(x)},[S]),D=(0,p.useRef)(r);D.current=r;let L=(0,p.useRef)(t);L.current=t;let N=(0,p.useRef)(n);N.current=n;let H=(0,p.useRef)(i);H.current=i;let W=(0,p.useRef)(A);W.current=A;let ce=(0,p.useRef)(g);ce.current=g;let j=(0,p.useRef)(0),ee=(0,p.useRef)(!1),ve=(0,p.useRef)(!1),ue=mt(),{doFetch:pe,isLoading:Ce,error:Be,isReady:Qe,lastRawQueryRef:de}=je({textRef:W,suggestionsRef:ce,filterBaseRef:j,maskCompletedTextRef:N,apiConfigRef:H,optionOverridesRef:L,onErrorRef:D,setCompletedParams:M,setSuggestions:m,setActiveDropdownIndex:l});Fe({text:A,completedParams:C,doFetch:pe,filterBaseRef:j,skipNextFetchRef:ve,suggestionsRef:ce,lastRawQueryRef:de});let He=(0,p.useMemo)(()=>Le(A,C),[A,C]);j.current=Math.min(j.current,A.length);let me=A.slice(j.current),ge=(0,p.useMemo)(()=>g.filter(v=>v.type==="placeholder").map(v=>v.text).join(" ")||o||"",[g,o]),te=(0,p.useMemo)(()=>g.filter(x=>x.type!=="placeholder"),[g]),_=te[0],Ie=_?t?.[_.type]:void 0,we=_?Ie?Ie(me.trim()):_.options??[]:[],fe=(0,p.useMemo)(()=>ae(we,me),[we,me]),Oe=ge.length>0,be=!Ce&&fe.length>0&&(!!A||ee.current||!Oe),Re=(0,p.useCallback)(x=>{if(!_)return;let v={id:crypto.randomUUID(),placeholder:"",type:_.type,text:x.text,kind:x.kind,suggestionType:_.type,suggestionPlaceholder:_.text,options:_.options??[],metadata:x.metadata},Q=j.current,U=W.current.slice(0,Q);if(U.length>0&&!U.endsWith(" ")){let O=U.split(/\s+/).pop()??"";O&&x.text.toLowerCase().startsWith(O.toLowerCase())&&(U=U.slice(0,U.length-O.length))}let he=U.length>0&&U[U.length-1]!==" ",X=U+(he?" ":"")+x.text+" ";E(X),j.current=X.length,M(O=>[...O,v]),ee.current=!1,l(-1);let V=te.length-1;b&&V>0?(m(O=>O.filter(G=>G!==_)),ve.current=!0):m(O=>O.filter(G=>G.type==="placeholder"))},[_,te,b,E,M]),We=(0,p.useCallback)(x=>{let v=x.target.value,U=v.length>0&&!x.nativeEvent?.isComposing&&v[0]!==v[0].toUpperCase()?v[0].toUpperCase()+v.slice(1):v;E(U),ee.current=!1,l(-1);let{valid:he,invalid:X}=Ue(U,C);if(X.length>0){M(()=>he);for(let V of X)m(O=>[{type:V.suggestionType,text:V.suggestionPlaceholder,required:!0,options:V.options},...O])}if(_&&X.length===0){let V=U.slice(j.current),O=Y(_.options,V);O&&(M(G=>[...G,{id:crypto.randomUUID(),placeholder:"",type:_.type,text:O.text,kind:O.kind,suggestionType:_.type,suggestionPlaceholder:_.text,options:_.options??[],metadata:O.metadata}]),m(G=>G.filter(Je=>Je!==_)))}},[C,_,E,M]),{handleKeyDown:Ve}=qe({activeDropdownIndex:a,setActiveDropdownIndex:l,filteredOptions:fe,selectOption:Re,onSubmitRef:z,text:A,completedParams:C,isDropdownOpen:be,hasPlaceholder:Oe,placeholderText:ge,suggestions:g,filterBaseRef:j,columns:s,setText:E,setCompletedParams:M,setSuggestions:m}),oe=Ne({completedParams:C,suggestions:g,setCompletedParams:M,setSuggestions:m,setActiveDropdownIndex:l,filterBaseRef:j,pillTappedRef:ee}),Ge=(0,p.useCallback)(x=>{oe.reEditParam(x).apply(E)},[oe,E]),Xe=(0,p.useCallback)(()=>{E(""),M(()=>[]),m([]),l(-1),j.current=0,de.current="",pe("",[])},[pe,E,M,de]),Ze=a>=0?`${ue}-option-${a}`:void 0;return{completedParams:C,suggestionPills:te,setActivePill:oe.setActivePill,removeLastParam:oe.removeLastParam,reEditParam:Ge,segments:He,suggestions:g,activeIndex:a,isReady:Qe,isLoading:Ce,error:Be,inputProps:{value:A,placeholder:ge||void 0,onChange:We,onKeyDown:Ve,role:"combobox","aria-expanded":be,"aria-activedescendant":Ze,"aria-autocomplete":"list","aria-controls":ue},reset:Xe,dropdownProps:{suggestions:_?[{..._,options:fe}]:[],activeIndex:a,onSelect:Re,onHighlight:l,isOpen:be,id:ue}}}var T=require("react/jsx-runtime"),$e=(0,F.forwardRef)(function({onSubmit:r,onError:t,optionOverrides:n,maskCompletedText:o,placeholder:i,className:s,apiConfig:b,columns:d,eagerSuggestions:f,value:c,completedParams:h,onChange:u,onParamsChange:S},w){let y=(0,F.useRef)(null),P=(0,F.useRef)(()=>{});(0,F.useEffect)(()=>{y.current?.focus()},[]);let{completedParams:k,suggestionPills:g,setActivePill:m,segments:a,inputProps:l,dropdownProps:A,reset:C}=le({onSubmit:D=>P.current(D),onError:t,optionOverrides:n,maskCompletedText:o,placeholder:i,apiConfig:b,columns:d,eagerSuggestions:f,value:c,completedParams:h,onChange:u,onParamsChange:S});(0,F.useImperativeHandle)(w,()=>({focus:()=>y.current?.focus(),reset:C}),[C]);let z=()=>{y.current?.focus()},q=!!l.value||k.length>0,I=(0,F.useCallback)(()=>{if(!q)return;let{rawQuery:D,completedParams:L}=J(l.value,k);r({query:l.value.trim(),raw_query:D,completed_params:L}),C()},[q,l.value,k,r,C]);P.current=I;let{onChange:K,placeholder:B,...E}=l,M=!l.value;return(0,T.jsxs)("div",{className:`${$.container} ${s??""}`,children:[(0,T.jsx)(re,{...A}),(0,T.jsxs)("div",{className:$.inputWrapper,onClick:z,children:[(0,T.jsxs)("div",{className:$.editorArea,children:[(0,T.jsxs)("div",{className:$.sizerContent,"aria-hidden":"true",children:[M&&B?(0,T.jsxs)("span",{className:$.placeholderText,children:[B," "]}):(0,T.jsxs)("span",{className:$.sizerText,children:[a.map((D,L)=>(0,T.jsx)("span",{children:D.value},`${L}-${D.type}`)),a.length===0&&"\xA0"]})," ",(0,T.jsx)(Ee,{pills:g,activePillIndex:0,onSelectPill:m})]}),(0,T.jsx)("textarea",{ref:y,className:$.textarea,rows:1,onChange:K,...E})]}),(0,T.jsx)("button",{type:"button",className:$.submitButton,disabled:!q,onClick:D=>{D.stopPropagation(),I()},"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
|