@magicx-eng/ai-autocomplete-react 0.1.12 → 0.1.14

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 CHANGED
@@ -1,4 +1,4 @@
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 {
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
  }
@@ -29,7 +29,7 @@
29
29
  white-space: pre-wrap;
30
30
  word-break: break-word;
31
31
  font-family: inherit;
32
- font-size: 21px;
32
+ font-size: 19px;
33
33
  line-height: 38px;
34
34
  }
35
35
 
@@ -54,7 +54,7 @@
54
54
  color: var(--ac-color-text-default, #fff);
55
55
  caret-color: var(--ac-color-text-default, #fff);
56
56
  font-family: inherit;
57
- font-size: 21px;
57
+ font-size: 19px;
58
58
  line-height: 38px;
59
59
  white-space: pre-wrap;
60
60
  word-break: break-word;
@@ -86,13 +86,13 @@
86
86
  .AIAutocomplete-module_submitButton_sl1Mi:hover {
87
87
  opacity: 0.85;
88
88
  }
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 {
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 {
90
90
  position: absolute;
91
91
  left: 0;
92
92
  right: 0;
93
93
  top: 100%;
94
94
  margin-top: 6px;
95
- background: var(--ac-color-background-default, #00002d);
95
+ background: var(--ac-color-background-default, #0b0247);
96
96
  border-radius: 23px;
97
97
  overflow: hidden;
98
98
  z-index: 10;
@@ -105,7 +105,7 @@
105
105
  opacity: 1;
106
106
  pointer-events: auto;
107
107
  }
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 {
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 {
109
109
  display: grid;
110
110
  grid-template-columns: 1fr 1fr;
111
111
  gap: 12px 18px;
@@ -128,14 +128,15 @@
128
128
  background: rgba(255, 255, 255, 0.3);
129
129
  border-radius: 3px;
130
130
  }
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 {
131
+ `,document.head.appendChild(e)}var Ee={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 {
132
132
  display: flex;
133
133
  align-items: center;
134
134
  font-family: "IBM Plex Sans", sans-serif;
135
- font-size: 21px;
135
+ font-size: 19px;
136
136
  line-height: 30px;
137
137
  color: var(--ac-color-text-muted, #c1c4cb);
138
- white-space: nowrap;
138
+ white-space: normal;
139
+ word-break: break-word;
139
140
  opacity: 0.35;
140
141
  animation: SuggestionItem-module_fadeIn_I8u35 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
141
142
  }
@@ -165,11 +166,11 @@
165
166
  }
166
167
 
167
168
  .SuggestionItem-module_tag_e3Fwe {
168
- font-size: 13px;
169
+ font-size: 11px;
169
170
  margin-left: 6px;
170
171
  opacity: 0.5;
171
172
  }
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 {
173
+ `,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 Te({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:Ee.grid,children:e.map((i,s)=>(0,_e.jsx)(Te,{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 {
173
174
  position: relative;
174
175
  z-index: 1;
175
176
  pointer-events: auto;
@@ -191,7 +192,7 @@
191
192
  background: var(--ac-color-background-supportive, #313255);
192
193
  color: var(--ac-color-text-muted, #c1c4cb);
193
194
  font-family: "IBM Plex Sans", sans-serif;
194
- font-size: 21px;
195
+ font-size: 19px;
195
196
  line-height: 30px;
196
197
  cursor: pointer;
197
198
  white-space: nowrap;
@@ -211,5 +212,5 @@
211
212
  opacity: 0;
212
213
  }
213
214
  }
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});
215
+ `,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.14",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),[b,_]=(0,R.useState)(null),[x,v]=(0,R.useState)(!1),w=(0,R.useRef)(0),A=(0,R.useRef)(null),I=(0,R.useRef)(""),f=(0,R.useCallback)(async(d,a)=>{A.current?.abort();let l=new AbortController;A.current=l;let T=++w.current,k=e.current.length;n.current.some(L=>L.type!=="placeholder")||g(!0),_(null);try{let L=await ze(d,a,{maskCompletedText:r.current,signal:l.signal,apiConfig:i.current});if(T!==w.current)return;let j=Fe(L.data.suggestions??[],s.current);v(L.data.is_ready??!1),I.current=d;let U=L.data.input??[],M=U[U.length-1],D=e.current;if(M?.state==="in_progress"){o.current=!0;let N=D.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(D,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(L){if(T===w.current){let j=L instanceof Error?L:new Error(String(L));_(j),g(!1),h.current?.(j)}}},[e,n,t,o,r,i,s,h,m,c,u]);return(0,R.useEffect)(()=>(f("",[]),()=>{A.current?.abort()}),[f]),{doFetch:f,isLoading:y,error:b,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 b=Y(e,o.current,r.current),v=s.current.filter(k=>k.type!=="placeholder")[0],A=(v?ce(v.options,b):[]).filter(k=>k.is_tappable),I=v?re(v.options,b)!==null:!1,f=b.trim().length>0;if(A.length>0&&!I&&f)return!1;let{rawQuery:d,completedParams:a}=ee(e,n),l=d.length<h.current.length,T=Math.abs(d.length-h.current.length);return l||T>=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:b,columns:_,setText:x,setCompletedParams:v,setSuggestions:w}){let A=(0,Ce.useCallback)(()=>{let f=t.map((a,l)=>a.is_tappable?l:-1).filter(a=>a!==-1),d=Array.from({length:_},()=>[]);for(let a of f)d[a%_].push(a);return d.flat()},[t,_]);return{handleKeyDown:(0,Ce.useCallback)(f=>{let d=A();switch(f.key){case"ArrowDown":{if(f.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(f.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){let l=f.target;l.selectionStart!=null&&l.selectionStart===l.value.length&&y.length>1&&(f.preventDefault(),g(1));break}if(e%_<_-1){let l=e+1;l<t.length&&t[l]?.is_tappable&&(f.preventDefault(),n(l))}break}case"ArrowLeft":{if(e<0)break;if(e%_>0){let a=e-1;a>=0&&t[a]?.is_tappable&&(f.preventDefault(),n(a))}break}case"Enter":{if(f.preventDefault(),e>=0&&t[e]?.is_tappable)o(t[e]);else if(r.current){let{rawQuery:a,completedParams:l}=ee(i,s),T={query:i.trim(),raw_query:a,completed_params:l};r.current(T)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)f.preventDefault(),o(t[e]);else if(h){let a=t.find(l=>l.is_tappable);a&&(f.preventDefault(),o(a))}else if(!i&&m){f.preventDefault();let a=u.find(l=>l.type==="placeholder");a?(x(c),b.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(T=>T!==a))):(x(c),b.current=c.length)}break}case"Escape":n(-1);break}},[y,e,_,s,t,b,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],b=y.filter((x,v)=>v!==u),_=n.filter(x=>x.type==="placeholder");o([..._,g,...b]),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(b=>{let _=0;for(let x of e){let v=b.indexOf(x.text,_);if(v!==-1){if(x.id===u.id){let w=b.slice(0,v),A=b.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 b}),t(b=>b.filter(_=>_.id!==u.id)),o(b=>[y,...b]),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,b=c!==void 0,[_,x]=(0,p.useState)(""),[v,w]=(0,p.useState)([]),[A,I]=(0,p.useState)([]),[f,d]=(0,p.useState)(-1),a=g?m:_,l=b?c:v,T=(0,p.useRef)(e);T.current=e;let k=(0,p.useRef)(u);k.current=u;let $=(0,p.useRef)(y);$.current=y;let L=(0,p.useRef)(m);L.current=m;let j=(0,p.useRef)(c);j.current=c;let U=(0,p.useCallback)(S=>{if(typeof S=="function")if(g){let C=S(L.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(b){let C=S(j.current??[]);$.current?.(C)}else w(C=>{let H=S(C);return $.current?.(H),H});else b||w(S),$.current?.(S)},[b]),D=(0,p.useRef)(n);D.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:D,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,K=B.current.slice(0,H);if(K.length>0&&!K.endsWith(" ")){let O=K.split(/\s+/).pop()??"";O&&S.text.toLowerCase().startsWith(O.toLowerCase())&&(K=K.slice(0,K.length-O.length))}let Se=K.length>0&&K[K.length-1]!==" ",Z=K+(Se?" ":"")+S.text+" ";U(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,U,M]),Ge=(0,p.useCallback)(S=>{let C=S.target.value,K=C.length>0&&!S.nativeEvent?.isComposing&&C[0]!==C[0].toUpperCase()?C[0].toUpperCase()+C.slice(1):C;U(K),ie.current=!1,d(-1);let{valid:Se,invalid:Z}=Ke(K,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(K,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,U,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(U)},[ne,U]),{handleKeyDown:Ze}=Qe({activeDropdownIndex:f,setActiveDropdownIndex:d,filteredOptions:he,selectOption:Me,onSubmitRef:T,text:a,completedParams:l,isDropdownOpen:ye,hasPlaceholder:ke,placeholderText:be,suggestions:A,actionableSuggestions:oe,setActivePill:ne.setActivePill,filterBaseRef:z,columns:s,setText:U,setCompletedParams:M,setSuggestions:I}),Je=(0,p.useCallback)(()=>{U(""),M(()=>[]),I([]),d(-1),z.current=0,te.current=!1,ge.current="",me("",[])},[me,U,M,ge]),Ye=f>=0?`${de}-option-${f}`:void 0;return{completedParams:l,suggestionPills:oe,setActivePill:ne.setActivePill,removeLastParam:ne.removeLastParam,reEditParam:Xe,segments:Ve,suggestions:A,activeIndex:f,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:f,onSelect:Me,onHighlight:d,isOpen:ye,id:de}}}var E=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:b},_){let x=(0,F.useRef)(null),v=(0,F.useRef)(()=>{});(0,F.useEffect)(()=>{x.current?.focus()},[]);let{completedParams:w,suggestionPills:A,setActivePill:I,segments:f,inputProps:d,dropdownProps:a,reset:l}=pe({onSubmit:D=>v.current(D),onError:t,optionOverrides:o,maskCompletedText:r,placeholder:i,apiConfig:h,columns:m,eagerSuggestions:c,value:u,completedParams:y,onChange:g,onParamsChange:b});(0,F.useImperativeHandle)(_,()=>({focus:()=>x.current?.focus(),reset:l}),[l]);let T=()=>{x.current?.focus()},k=!!d.value||w.length>0,$=(0,F.useCallback)(()=>{if(!k)return;let{rawQuery:D,completedParams:W}=ee(d.value,w);n({query:d.value.trim(),raw_query:D,completed_params:W}),l()},[k,d.value,w,n,l]);v.current=$;let{onChange:L,placeholder:j,...U}=d,M=!d.value;return(0,E.jsxs)("div",{className:`${Q.container} ${s??""}`,children:[(0,E.jsx)(se,{...a}),(0,E.jsxs)("div",{className:Q.inputWrapper,onClick:T,children:[(0,E.jsxs)("div",{className:Q.editorArea,children:[(0,E.jsxs)("div",{className:Q.sizerContent,"aria-hidden":"true",children:[M&&j?(0,E.jsxs)("span",{className:Q.placeholderText,children:[j," "]}):(0,E.jsxs)("span",{className:Q.sizerText,children:[f.map((D,W)=>(0,E.jsx)("span",{children:D.value},`${W}-${D.type}`)),f.length===0&&"\xA0"]})," ",(0,E.jsx)(Ue,{pills:A,activePillIndex:0,onSelectPill:I})]}),(0,E.jsx)("textarea",{ref:x,className:Q.textarea,rows:1,onChange:L,...U})]}),(0,E.jsx)("button",{type:"button",className:Q.submitButton,disabled:!k,onClick:D=>{D.stopPropagation(),$()},"aria-label":"Submit",children:(0,E.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,E.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
215
216
  //# sourceMappingURL=index.js.map