@magicx-eng/ai-autocomplete-react 0.1.11 → 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.js CHANGED
@@ -1,57 +1,8 @@
1
- "use strict";var ye=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var et=Object.prototype.hasOwnProperty;var tt=(e,r)=>{for(var t in r)ye(e,t,{get:r[t],enumerable:!0})},ot=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Je(r))!et.call(e,n)&&n!==t&&ye(e,n,{get:()=>r[n],enumerable:!(o=Ze(r,n))||o.enumerable});return e};var nt=e=>ot(ye({},"__esModule",{value:!0}),e);var dt={};tt(dt,{AIAutocomplete:()=>Ne,AIAutocompleteDropdown:()=>re,useAIAutocomplete:()=>le});module.exports=nt(dt);var j=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-AIAutocomplete")){let e=document.createElement("style");e.id="ac-style-AIAutocomplete",e.textContent=`.AIAutocomplete-module_container_KKjFU {
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 K={container:"AIAutocomplete-module_container_KKjFU",checkmark:"AIAutocomplete-module_checkmark_CVE0Z",checkmarkVisible:"AIAutocomplete-module_checkmarkVisible_DWYbI",checkmarkFadeInOut:"AIAutocomplete-module_checkmarkFadeInOut_U1Oof",checkmarkPath:"AIAutocomplete-module_checkmarkPath_BJRUs",drawCheck:"AIAutocomplete-module_drawCheck_je-B3",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-AIAutocompleteDropdown")){let e=document.createElement("style");e.id="ac-style-AIAutocompleteDropdown",e.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
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 Ae={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj"};if(typeof document<"u"&&!document.getElementById("ac-style-SuggestionGrid")){let e=document.createElement("style");e.id="ac-style-SuggestionGrid",e.textContent=`.SuggestionGrid-module_grid_jvaPb {
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 Re={grid:"SuggestionGrid-module_grid_jvaPb"};if(typeof document<"u"&&!document.getElementById("ac-style-SuggestionItem")){let e=document.createElement("style");e.id="ac-style-SuggestionItem",e.textContent=`.SuggestionItem-module_item_d4vpD {
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 Y={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 Te({option:e,isHighlighted:r,onSelect:t,onHighlight:o,id:n}){let i=[Y.item,r?Y.highlighted:"",e.is_tappable?Y.tappable:Y.nonTappable].filter(Boolean).join(" ");return(0,ne.jsxs)("div",{id:n,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:o,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,ne.jsx)("span",{className:Y.tag,children:e.tag})]})}var Se=require("react/jsx-runtime");function Ee({options:e,activeIndex:r,onSelect:t,onHighlight:o,listboxId:n}){return(0,Se.jsx)("div",{className:Re.grid,children:e.map((i,s)=>(0,Se.jsx)(Te,{option:i,isHighlighted:s===r,onSelect:t,onHighlight:()=>o(s),id:`${n}-option-${s}`},i.text))})}var _e=require("react/jsx-runtime");function re({suggestions:e,activeIndex:r,onSelect:t,onHighlight:o,isOpen:n,id:i,className:s}){let d=e[0]?.options??[],f=n&&d.length>0;return(0,_e.jsx)("div",{id:i,role:"listbox",className:`${Ae.dropdown} ${f?Ae.visible:""} ${s??""}`,onMouseDown:l=>l.preventDefault(),children:d.length>0&&(0,_e.jsx)(Ee,{options:d,activeIndex:r,onSelect:t,onHighlight:o,listboxId:i})})}if(typeof document<"u"&&!document.getElementById("ac-style-PillList")){let e=document.createElement("style");e.id="ac-style-PillList",e.textContent=`.PillList-module_list_qvLqO {
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 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 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