@magicx-eng/ai-autocomplete-react 0.1.7 → 0.1.9
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 +263 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
- package/dist/index.css +0 -2
- package/dist/index.css.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,264 @@
|
|
|
1
|
-
"use strict";var ye=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var ot=(e,o)=>{for(var t in o)ye(e,t,{get:o[t],enumerable:!0})},rt=(e,o,t,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of et(o))!tt.call(e,r)&&r!==t&&ye(e,r,{get:()=>o[r],enumerable:!(n=Ze(o,r))||n.enumerable});return e};var nt=e=>rt(ye({},"__esModule",{value:!0}),e);var vt={};ot(vt,{AIAutocomplete:()=>qe,AIAutocompleteDropdown:()=>ne,useAIAutocomplete:()=>ce});module.exports=nt(vt);var D=require("react");var K={};var Se={};var _e={};var Y={};var re=require("react/jsx-runtime");function Te({option:e,isHighlighted:o,onSelect:t,onHighlight:n,id:r}){let a=[Y.item,o?Y.highlighted:"",e.is_tappable?Y.tappable:Y.nonTappable].filter(Boolean).join(" ");return(0,re.jsxs)("div",{id:r,role:"option","aria-selected":o,className:a,tabIndex:e.is_tappable?0:-1,onClick:()=>e.is_tappable&&t(e),onKeyDown:i=>{e.is_tappable&&(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),t(e))},onMouseEnter:n,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,re.jsx)("span",{className:Y.tag,children:e.tag})]})}var xe=require("react/jsx-runtime");function Ee({options:e,activeIndex:o,onSelect:t,onHighlight:n,listboxId:r}){return(0,xe.jsx)("div",{className:_e.grid,children:e.map((a,i)=>(0,xe.jsx)(Te,{option:a,isHighlighted:i===o,onSelect:t,onHighlight:()=>n(i),id:`${r}-option-${i}`},a.text))})}var Pe=require("react/jsx-runtime");function ne({suggestions:e,activeIndex:o,onSelect:t,onHighlight:n,isOpen:r,id:a,className:i}){let m=e[0],g=r&&m&&m.options.length>0;return(0,Pe.jsx)("div",{id:a,role:"listbox",className:`${Se.dropdown} ${g?Se.visible:""} ${i??""}`,onMouseDown:h=>h.preventDefault(),children:m&&m.options.length>0&&(0,Pe.jsx)(Ee,{options:m.options,activeIndex:o,onSelect:t,onHighlight:n,listboxId:a})})}var ae={};var ve=require("react/jsx-runtime");function ut(e){return e===0?.4:e===1?.3:.15}function Me({pills:e,activePillIndex:o,onSelectPill:t}){return(0,ve.jsx)("span",{className:ae.list,children:e.map((n,r)=>(0,ve.jsx)("button",{type:"button",className:`${ae.pill} ${r===o?ae.active:""}`,style:{opacity:ut(r)},onClick:()=>t(r),children:n.text},`${n.type}-${n.text}`))})}var p=require("react");function se(e,o){let t=o.trimStart();if(!t)return e;let n=t.toLowerCase();return e.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(n))}function Z(e,o){let t=o.trim();if(!t)return null;let n=t.toLowerCase();return e.find(r=>r.is_tappable&&r.text.toLowerCase()===n)??null}function Ue(e,o){let t=[],n=0;for(let a of o){let i=e.indexOf(a.text,n);i!==-1&&(i>n&&t.push({type:"text",value:e.slice(n,i)}),t.push({type:"completed",value:a.text,param:a}),n=i+a.text.length)}let r=e.slice(n);return r&&t.push({type:"text",value:r}),t}function Le(e,o){let t=[],n=[],r=0;for(let a of o){let i=e.indexOf(a.text,r);i===-1?n.push(a):(t.push(a),r=i+a.text.length)}return{valid:t,invalid:n}}var E=require("react");var pt="0.1.7",mt="/ac/suggest",Ne=!1;function dt(e){let o=e?.apiKey||""||"";return!o&&!Ne&&(Ne=!0,console.warn("[AIAutocomplete] No API key set (MAGICX_AI_AUTOCOMPLETE_API_KEY). Requests will be sent without an Authorization header.")),o}function ft(e){return e?.authScheme?e.authScheme:""==="Basic"?"Basic":"Bearer"}function gt(){return crypto.randomUUID()}function ht(e,o){return{placeholder:e.placeholder,type:e.type,...o&&{text:e.text},kind:e.kind}}async function De(e,o,t){let n=t?.apiConfig,r=dt(n),a=ft(n),i=!t?.maskCompletedText,m=o.find(c=>c.type==="contact"&&c.metadata?.contact_account_count)?.metadata?.contact_account_count,g=typeof m=="number"?m:void 0,h={data:{raw_query:e,completed_params:o.map(c=>ht(c,i)),...g!=null&&{contact_account_count:g}},meta:{request_id:gt(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:pt}},d={"Content-Type":"application/json","X-App-Identifier":"active-campaign-demo",...n?.headers};r&&(d.Authorization=a==="Basic"?`Basic ${btoa(r)}`:`Bearer ${r}`);let b=await fetch(n?.endpoint||mt,{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 J(e,o){let t=e,n={},r=[];for(let a of o){let i=(n[a.type]??0)+1;n[a.type]=i;let g=`{{${a.type.toUpperCase().replace(/\s+/g,"_")}_${i}}}`,h=t.indexOf(a.text);h!==-1&&(t=t.slice(0,h)+g+t.slice(h+a.text.length)),r.push({...a,placeholder:g})}return{rawQuery:t,completedParams:r}}function Fe(e,o){return o?e.map(t=>{let n=o[t.type];if(!n)return t;let r=n("");if(r.length===0)return t;let a=new Set(r.map(m=>m.text)),i=(t.options??[]).filter(m=>!a.has(m.text));return{...t,options:[...r,...i]}}):e}var bt=100,yt=300,St=2;function $e({textRef:e,suggestionsRef:o,filterBaseRef:t,maskCompletedTextRef:n,apiConfigRef:r,optionOverridesRef:a,onErrorRef:i,setCompletedParams:m,setSuggestions:g,setActiveDropdownIndex:h}){let[d,b]=(0,E.useState)(!1),[c,S]=(0,E.useState)(null),[O,y]=(0,E.useState)(!1),C=(0,E.useRef)(0),L=(0,E.useRef)(null),f=(0,E.useRef)(""),l=(0,E.useCallback)(async(s,u)=>{L.current?.abort();let P=new AbortController;L.current=P;let I=++C.current,R=e.current.length;o.current.some(k=>k.type!=="placeholder")||b(!0),S(null);try{let k=await De(s,u,{maskCompletedText:n.current,signal:P.signal,apiConfig:r.current});if(I!==C.current)return;let F=Fe(k.data.suggestions??[],a.current);y(k.data.is_ready??!1),f.current=s;let B=k.data.input??[],M=B[B.length-1],U=e.current;if(M?.state==="in_progress"){let j=U.toLowerCase().lastIndexOf(M.text.toLowerCase());j!==-1?t.current=j:t.current=R}else t.current=R;let $=F.filter(j=>j.type!=="placeholder")[0];if($){let j=U.slice(t.current),_=Z($.options,j);_&&(m(z=>[...z,{id:crypto.randomUUID(),placeholder:"",type:$.type,text:_.text,kind:_.kind,suggestionType:$.type,suggestionPlaceholder:$.text,options:$.options,metadata:_.metadata}]),F=F.filter(z=>z!==$))}g(F),b(!1),h(-1)}catch(k){if(I===C.current){let F=k instanceof Error?k:new Error(String(k));S(F),b(!1),i.current?.(F)}}},[e,o,t,n,r,a,i,m,g,h]);return(0,E.useEffect)(()=>(l("",[]),()=>{L.current?.abort()}),[l]),{doFetch:l,isLoading:d,error:c,isReady:O,lastRawQueryRef:f}}function Ke({text:e,completedParams:o,doFetch:t,filterBaseRef:n,skipNextFetchRef:r,suggestionsRef:a,lastRawQueryRef:i}){let m=(0,E.useRef)(null),g=(0,E.useRef)(null),h=(0,E.useRef)(!0);(0,E.useEffect)(()=>{m.current&&clearTimeout(m.current),g.current&&clearTimeout(g.current);let d=b=>{if(r.current)return r.current=!1,!1;if(!e&&o.length===0)return h.current?(t("",[]),!0):(h.current=!0,!1);let c=e.slice(n.current),y=a.current.filter(R=>R.type!=="placeholder")[0],L=(y?se(y.options,c):[]).filter(R=>R.is_tappable),f=y?Z(y.options,c)!==null:!1,l=c.trim().length>0;if(L.length>0&&!f&&l)return!1;let{rawQuery:s,completedParams:u}=J(e,o),P=s.length<i.current.length,I=Math.abs(s.length-i.current.length);return P||I>=b?(t(s,u),!0):!1};return m.current=setTimeout(()=>{d(St)&&g.current&&clearTimeout(g.current)},bt),g.current=setTimeout(()=>d(1),yt),()=>{m.current&&clearTimeout(m.current),g.current&&clearTimeout(g.current)}},[e,o,t,n,r,a,i])}var Ae=require("react");function je({activeDropdownIndex:e,setActiveDropdownIndex:o,filteredOptions:t,selectOption:n,onSubmitRef:r,text:a,completedParams:i,isDropdownOpen:m,hasPlaceholder:g,placeholderText:h,suggestions:d,filterBaseRef:b,columns:c,setText:S,setCompletedParams:O,setSuggestions:y}){let C=(0,Ae.useCallback)(()=>{let f=t.map((s,u)=>s.is_tappable?u:-1).filter(s=>s!==-1),l=Array.from({length:c},()=>[]);for(let s of f)l[s%c].push(s);return l.flat()},[t,c]);return{handleKeyDown:(0,Ae.useCallback)(f=>{let l=C();switch(f.key){case"ArrowDown":{if(f.preventDefault(),l.length===0)return;let s=l.indexOf(e),u=s<l.length-1?s+1:0;o(l[u]);break}case"ArrowUp":{if(f.preventDefault(),l.length===0)return;let s=l.indexOf(e),u=s>0?s-1:l.length-1;o(l[u]);break}case"ArrowRight":{if(e<0)break;if(e%c<c-1){let u=e+1;u<t.length&&t[u]?.is_tappable&&(f.preventDefault(),o(u))}break}case"ArrowLeft":{if(e<0)break;if(e%c>0){let s=e-1;s>=0&&t[s]?.is_tappable&&(f.preventDefault(),o(s))}break}case"Enter":{if(f.preventDefault(),e>=0&&t[e]?.is_tappable)n(t[e]);else if(r.current){let{rawQuery:s,completedParams:u}=J(a,i),P={query:a.trim(),raw_query:s,completed_params:u};r.current(P)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable)f.preventDefault(),n(t[e]);else if(m){let s=t.find(u=>u.is_tappable);s&&(f.preventDefault(),n(s))}else if(!a&&g){f.preventDefault();let s=d.find(u=>u.type==="placeholder");s?(S(h),b.current=h.length,O(u=>[...u,{id:crypto.randomUUID(),placeholder:"",type:s.type,text:h,kind:null,suggestionType:s.type,suggestionPlaceholder:s.text,options:s.options}]),y(u=>u.filter(P=>P!==s))):(S(h),b.current=h.length)}break}case"Escape":o(-1);break}},[e,c,i,t,b,C,g,m,r,h,n,o,O,y,S,d,a]),getTappableIndices:C}}var ie=require("react");function ze({completedParams:e,suggestions:o,setCompletedParams:t,setSuggestions:n,setActiveDropdownIndex:r,filterBaseRef:a,pillTappedRef:i}){let m=(0,ie.useCallback)(d=>{let b=o.filter(y=>y.type!=="placeholder");if(d<0||d>=b.length)return;let c=b[d],S=b.filter((y,C)=>C!==d),O=o.filter(y=>y.type==="placeholder");n([...O,c,...S]),i.current=!0,r(-1)},[o,n,r,i]),g=(0,ie.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(c=>c.slice(0,-1)),n(c=>[b,...c]),r(-1)},[e,t,n,r]),h=(0,ie.useCallback)(d=>{let b={type:d.suggestionType,text:d.suggestionPlaceholder,required:!0,options:d.options};return{apply:c=>{c(S=>{let O=0;for(let y of e){let C=S.indexOf(y.text,O);if(C!==-1){if(y.id===d.id){let L=S.slice(0,C),f=S.slice(C+d.text.length),l=(L+f).replace(/ {2,}/g," ");return a.current=Math.min(a.current,l.length),l}O=C+y.text.length}}return S}),t(S=>S.filter(O=>O.id!==d.id)),n(S=>[b,...S]),r(-1),i.current=!0}}},[e,t,n,r,a,i]);return{setActivePill:m,removeLastParam:g,reEditParam:h}}var xt=0;function Pt(){let e=(0,p.useRef)(null);return e.current===null&&(e.current=`:ac-${++xt}:`),e.current}function ce({onSubmit:e,onError:o,optionOverrides:t,maskCompletedText:n,placeholder:r,apiConfig:a,columns:i=2,eagerSuggestions:m=!0,value:g,completedParams:h,onChange:d,onParamsChange:b}){let c=g!==void 0,S=h!==void 0,[O,y]=(0,p.useState)(""),[C,L]=(0,p.useState)([]),[f,l]=(0,p.useState)([]),[s,u]=(0,p.useState)(-1),P=c?g:O,I=S?h:C,R=(0,p.useRef)(e);R.current=e;let H=(0,p.useRef)(d);H.current=d;let k=(0,p.useRef)(b);k.current=b;let F=(0,p.useRef)(g);F.current=g;let B=(0,p.useRef)(h);B.current=h;let M=(0,p.useCallback)(x=>{if(typeof x=="function")if(c){let A=x(F.current??"");H.current?.(A)}else y(A=>{let Q=x(A);return H.current?.(Q),Q});else c||y(x),H.current?.(x)},[c]),U=(0,p.useCallback)(x=>{if(typeof x=="function")if(S){let A=x(B.current??[]);k.current?.(A)}else L(A=>{let Q=x(A);return k.current?.(Q),Q});else S||L(x),k.current?.(x)},[S]),W=(0,p.useRef)(o);W.current=o;let $=(0,p.useRef)(t);$.current=t;let j=(0,p.useRef)(n);j.current=n;let _=(0,p.useRef)(a);_.current=a;let z=(0,p.useRef)(P);z.current=P;let le=(0,p.useRef)(f);le.current=f;let q=(0,p.useRef)(0),ee=(0,p.useRef)(!1),Ce=(0,p.useRef)(!1),ue=Pt(),{doFetch:pe,isLoading:ke,error:Be,isReady:Qe,lastRawQueryRef:me}=$e({textRef:z,suggestionsRef:le,filterBaseRef:q,maskCompletedTextRef:j,apiConfigRef:_,optionOverridesRef:$,onErrorRef:W,setCompletedParams:U,setSuggestions:l,setActiveDropdownIndex:u});Ke({text:P,completedParams:I,doFetch:pe,filterBaseRef:q,skipNextFetchRef:Ce,suggestionsRef:le,lastRawQueryRef:me});let He=(0,p.useMemo)(()=>Ue(P,I),[P,I]);q.current=Math.min(q.current,P.length);let de=P.slice(q.current),fe=(0,p.useMemo)(()=>f.filter(A=>A.type==="placeholder").map(A=>A.text).join(" ")||r||"",[f,r]),te=(0,p.useMemo)(()=>f.filter(x=>x.type!=="placeholder"),[f]),v=te[0],we=v?t?.[v.type]:void 0,Oe=v?we?we(de.trim()):v.options??[]:[],ge=(0,p.useMemo)(()=>se(Oe,de),[Oe,de]),Ie=fe.length>0,he=!ke&&ge.length>0&&(!!P||ee.current||!Ie),Re=(0,p.useCallback)(x=>{if(!v)return;let A={id:crypto.randomUUID(),placeholder:"",type:v.type,text:x.text,kind:x.kind,suggestionType:v.type,suggestionPlaceholder:v.text,options:v.options,metadata:x.metadata},Q=q.current,N=z.current.slice(0,Q);if(N.length>0&&!N.endsWith(" ")){let T=N.split(/\s+/).pop()??"";T&&x.text.toLowerCase().startsWith(T.toLowerCase())&&(N=N.slice(0,N.length-T.length))}let be=N.length>0&&N[N.length-1]!==" ",G=N+(be?" ":"")+x.text+" ";M(G),q.current=G.length,U(T=>[...T,A]),ee.current=!1,u(-1);let V=te.length-1;m&&V>0?(l(T=>T.filter(X=>X!==v)),Ce.current=!0):l(T=>T.filter(X=>X.type==="placeholder"))},[v,te,m,M,U]),Ve=(0,p.useCallback)(x=>{let A=x.target.value,N=A.length>0&&!x.nativeEvent?.isComposing&&A[0]!==A[0].toUpperCase()?A[0].toUpperCase()+A.slice(1):A;M(N),ee.current=!1,u(-1);let{valid:be,invalid:G}=Le(N,I);if(G.length>0){U(()=>be);for(let V of G)l(T=>[{type:V.suggestionType,text:V.suggestionPlaceholder,required:!0,options:V.options},...T])}if(v&&G.length===0){let V=N.slice(q.current),T=Z(v.options,V);T&&(U(X=>[...X,{id:crypto.randomUUID(),placeholder:"",type:v.type,text:T.text,kind:T.kind,suggestionType:v.type,suggestionPlaceholder:v.text,options:v.options,metadata:T.metadata}]),l(X=>X.filter(Je=>Je!==v)))}},[I,v,M,U]),{handleKeyDown:Xe}=je({activeDropdownIndex:s,setActiveDropdownIndex:u,filteredOptions:ge,selectOption:Re,onSubmitRef:R,text:P,completedParams:I,isDropdownOpen:he,hasPlaceholder:Ie,placeholderText:fe,suggestions:f,filterBaseRef:q,columns:i,setText:M,setCompletedParams:U,setSuggestions:l}),oe=ze({completedParams:I,suggestions:f,setCompletedParams:U,setSuggestions:l,setActiveDropdownIndex:u,filterBaseRef:q,pillTappedRef:ee}),We=(0,p.useCallback)(x=>{oe.reEditParam(x).apply(M)},[oe,M]),Ge=(0,p.useCallback)(()=>{M(""),U(()=>[]),l([]),u(-1),q.current=0,me.current="",pe("",[])},[pe,M,U,me]),Ye=s>=0?`${ue}-option-${s}`:void 0;return{completedParams:I,suggestionPills:te,setActivePill:oe.setActivePill,removeLastParam:oe.removeLastParam,reEditParam:We,segments:He,suggestions:f,activeIndex:s,isReady:Qe,isLoading:ke,error:Be,inputProps:{value:P,placeholder:fe||void 0,onChange:Ve,onKeyDown:Xe,role:"combobox","aria-expanded":he,"aria-activedescendant":Ye,"aria-autocomplete":"list","aria-controls":ue},reset:Ge,dropdownProps:{suggestions:v?[{...v,options:ge}]:[],activeIndex:s,onSelect:Re,onHighlight:u,isOpen:he,id:ue}}}var w=require("react/jsx-runtime"),qe=(0,D.forwardRef)(function({onSubmit:o,onError:t,optionOverrides:n,maskCompletedText:r,placeholder:a,className:i,apiConfig:m,columns:g,eagerSuggestions:h,value:d,completedParams:b,onChange:c,onParamsChange:S},O){let y=(0,D.useRef)(null),[C,L]=(0,D.useState)(!1),f=(0,D.useRef)(()=>{}),l=(0,D.useRef)(void 0);(0,D.useEffect)(()=>(y.current?.focus(),()=>clearTimeout(l.current)),[]);let{completedParams:s,suggestionPills:u,setActivePill:P,segments:I,inputProps:R,dropdownProps:H,reset:k}=ce({onSubmit:_=>f.current(_),onError:t,optionOverrides:n,maskCompletedText:r,placeholder:a,apiConfig:m,columns:g,eagerSuggestions:h,value:d,completedParams:b,onChange:c,onParamsChange:S});(0,D.useImperativeHandle)(O,()=>({focus:()=>y.current?.focus(),reset:k}),[k]);let F=()=>{y.current?.focus()},B=!!R.value||s.length>0,M=(0,D.useCallback)(()=>{if(!B)return;let{rawQuery:_,completedParams:z}=J(R.value,s);o({query:R.value.trim(),raw_query:_,completed_params:z}),k(),L(!0),clearTimeout(l.current),l.current=setTimeout(()=>L(!1),3e3)},[B,R.value,s,o,k]);f.current=M;let{onChange:U,placeholder:W,...$}=R,j=!R.value;return(0,w.jsxs)("div",{className:`${K.container} ${i??""}`,children:[(0,w.jsx)("div",{className:`${K.checkmark} ${C?K.checkmarkVisible:""}`,children:(0,w.jsxs)("svg",{width:"72",height:"72",viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Success",children:[(0,w.jsx)("circle",{cx:"12",cy:"12",r:"12",fill:"#34C759"}),(0,w.jsx)("path",{d:"M7 12.5l3.5 3.5L17 9",stroke:"#000",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:K.checkmarkPath})]})}),(0,w.jsx)(ne,{...H}),(0,w.jsxs)("div",{className:K.inputWrapper,onClick:F,children:[(0,w.jsxs)("div",{className:K.editorArea,children:[(0,w.jsxs)("div",{className:K.sizerContent,"aria-hidden":"true",children:[j&&W?(0,w.jsxs)("span",{className:K.placeholderText,children:[W," "]}):(0,w.jsxs)("span",{className:K.sizerText,children:[I.map((_,z)=>(0,w.jsx)("span",{children:_.value},`${z}-${_.type}`)),I.length===0&&"\xA0"]})," ",(0,w.jsx)(Me,{pills:u,activePillIndex:0,onSelectPill:P})]}),(0,w.jsx)("textarea",{ref:y,className:K.textarea,rows:1,onChange:U,...$})]}),(0,w.jsx)("button",{type:"button",className:K.submitButton,disabled:!B,onClick:_=>{_.stopPropagation(),M()},"aria-label":"Submit",children:(0,w.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,w.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
|
|
1
|
+
"use strict";var ye=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var ot=(e,o)=>{for(var t in o)ye(e,t,{get:o[t],enumerable:!0})},nt=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of et(o))!tt.call(e,n)&&n!==t&&ye(e,n,{get:()=>o[n],enumerable:!(r=Je(o,n))||r.enumerable});return e};var rt=e=>nt(ye({},"__esModule",{value:!0}),e);var bt={};ot(bt,{AIAutocomplete:()=>$e,AIAutocompleteDropdown:()=>re,useAIAutocomplete:()=>le});module.exports=rt(bt);var K=require("react");if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.AIAutocomplete-module_container_KKjFU {
|
|
2
|
+
position: relative;
|
|
3
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
4
|
+
}
|
|
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
|
+
.AIAutocomplete-module_inputWrapper_FLq1b {
|
|
56
|
+
min-height: 60px;
|
|
57
|
+
padding: 24px;
|
|
58
|
+
border: 1px solid var(--ac-color-border-default, #9ea5b2);
|
|
59
|
+
border-radius: 23px;
|
|
60
|
+
background: transparent;
|
|
61
|
+
overflow: hidden;
|
|
62
|
+
display: flex;
|
|
63
|
+
align-items: center;
|
|
64
|
+
gap: 12px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.AIAutocomplete-module_editorArea_7rBWq {
|
|
68
|
+
position: relative;
|
|
69
|
+
flex: 1;
|
|
70
|
+
min-width: 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.AIAutocomplete-module_sizerContent_DQgmV {
|
|
74
|
+
position: relative;
|
|
75
|
+
z-index: 1;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
min-height: 60px;
|
|
78
|
+
white-space: pre-wrap;
|
|
79
|
+
word-break: break-word;
|
|
80
|
+
font-family: inherit;
|
|
81
|
+
font-size: 21px;
|
|
82
|
+
line-height: 38px;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.AIAutocomplete-module_sizerText_iZIMK {
|
|
86
|
+
color: transparent;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.AIAutocomplete-module_placeholderText_K3ayy {
|
|
90
|
+
color: var(--ac-color-text-muted, #c1c4cb);
|
|
91
|
+
opacity: 0.7;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.AIAutocomplete-module_textarea_eyn6A {
|
|
95
|
+
position: absolute;
|
|
96
|
+
top: 0;
|
|
97
|
+
left: 0;
|
|
98
|
+
width: 100%;
|
|
99
|
+
height: 100%;
|
|
100
|
+
padding: 0;
|
|
101
|
+
border: none;
|
|
102
|
+
background: transparent;
|
|
103
|
+
color: var(--ac-color-text-default, #fff);
|
|
104
|
+
caret-color: var(--ac-color-text-default, #fff);
|
|
105
|
+
font-family: inherit;
|
|
106
|
+
font-size: 21px;
|
|
107
|
+
line-height: 38px;
|
|
108
|
+
white-space: pre-wrap;
|
|
109
|
+
word-break: break-word;
|
|
110
|
+
outline: none;
|
|
111
|
+
resize: none;
|
|
112
|
+
overflow: hidden;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.AIAutocomplete-module_textarea_eyn6A::placeholder {
|
|
116
|
+
color: var(--ac-color-text-muted, #c1c4cb);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.AIAutocomplete-module_submitButton_sl1Mi {
|
|
120
|
+
flex-shrink: 0;
|
|
121
|
+
width: 36px;
|
|
122
|
+
height: 36px;
|
|
123
|
+
border-radius: 50%;
|
|
124
|
+
border: none;
|
|
125
|
+
background: var(--ac-color-text-default, #fff);
|
|
126
|
+
color: var(--ac-color-bg-default, #000);
|
|
127
|
+
cursor: pointer;
|
|
128
|
+
display: flex;
|
|
129
|
+
align-items: center;
|
|
130
|
+
justify-content: center;
|
|
131
|
+
padding: 0;
|
|
132
|
+
transition: opacity 0.2s ease;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.AIAutocomplete-module_submitButton_sl1Mi:hover {
|
|
136
|
+
opacity: 0.85;
|
|
137
|
+
}
|
|
138
|
+
`,document.head.appendChild(e)}var z={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"){let e=document.createElement("style");e.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
|
|
139
|
+
position: absolute;
|
|
140
|
+
left: 0;
|
|
141
|
+
right: 0;
|
|
142
|
+
top: 100%;
|
|
143
|
+
margin-top: 6px;
|
|
144
|
+
background: var(--ac-color-background-default, #00002d);
|
|
145
|
+
border-radius: 23px;
|
|
146
|
+
overflow: hidden;
|
|
147
|
+
z-index: 10;
|
|
148
|
+
opacity: 0;
|
|
149
|
+
pointer-events: none;
|
|
150
|
+
transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.AIAutocompleteDropdown-module_visible_QCoXj {
|
|
154
|
+
opacity: 1;
|
|
155
|
+
pointer-events: auto;
|
|
156
|
+
}
|
|
157
|
+
`,document.head.appendChild(e)}var Ae={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj"};if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.SuggestionGrid-module_grid_jvaPb {
|
|
158
|
+
display: grid;
|
|
159
|
+
grid-template-columns: 1fr 1fr;
|
|
160
|
+
gap: 12px 18px;
|
|
161
|
+
padding: 18px 24px;
|
|
162
|
+
max-height: 192px;
|
|
163
|
+
overflow-y: auto;
|
|
164
|
+
scrollbar-width: thin;
|
|
165
|
+
scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.SuggestionGrid-module_grid_jvaPb::-webkit-scrollbar {
|
|
169
|
+
width: 6px;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.SuggestionGrid-module_grid_jvaPb::-webkit-scrollbar-track {
|
|
173
|
+
background: transparent;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.SuggestionGrid-module_grid_jvaPb::-webkit-scrollbar-thumb {
|
|
177
|
+
background: rgba(255, 255, 255, 0.3);
|
|
178
|
+
border-radius: 3px;
|
|
179
|
+
}
|
|
180
|
+
`,document.head.appendChild(e)}var Re={grid:"SuggestionGrid-module_grid_jvaPb"};if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.SuggestionItem-module_item_d4vpD {
|
|
181
|
+
display: flex;
|
|
182
|
+
align-items: center;
|
|
183
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
184
|
+
font-size: 21px;
|
|
185
|
+
line-height: 30px;
|
|
186
|
+
color: var(--ac-color-text-muted, #c1c4cb);
|
|
187
|
+
white-space: nowrap;
|
|
188
|
+
opacity: 0.35;
|
|
189
|
+
animation: SuggestionItem-module_fadeIn_I8u35 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@keyframes SuggestionItem-module_fadeIn_I8u35 {
|
|
193
|
+
from {
|
|
194
|
+
opacity: 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.SuggestionItem-module_tappable_70KcX {
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.SuggestionItem-module_tappable_70KcX:hover {
|
|
203
|
+
color: var(--ac-color-text-default, #fff);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.SuggestionItem-module_nonTappable_xSZM- {
|
|
207
|
+
cursor: default;
|
|
208
|
+
opacity: 0.3;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.SuggestionItem-module_highlighted_Hb0SU {
|
|
212
|
+
color: var(--ac-color-text-default, #fff);
|
|
213
|
+
opacity: 0.5;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.SuggestionItem-module_tag_e3Fwe {
|
|
217
|
+
font-size: 13px;
|
|
218
|
+
margin-left: 6px;
|
|
219
|
+
opacity: 0.5;
|
|
220
|
+
}
|
|
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:o,onSelect:t,onHighlight:r,id:n}){let i=[Y.item,o?Y.highlighted:"",e.is_tappable?Y.tappable:Y.nonTappable].filter(Boolean).join(" ");return(0,ne.jsxs)("div",{id:n,role:"option","aria-selected":o,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:r,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,ne.jsx)("span",{className:Y.tag,children:e.tag})]})}var _e=require("react/jsx-runtime");function Ee({options:e,activeIndex:o,onSelect:t,onHighlight:r,listboxId:n}){return(0,_e.jsx)("div",{className:Re.grid,children:e.map((i,s)=>(0,_e.jsx)(Te,{option:i,isHighlighted:s===o,onSelect:t,onHighlight:()=>r(s),id:`${n}-option-${s}`},i.text))})}var Se=require("react/jsx-runtime");function re({suggestions:e,activeIndex:o,onSelect:t,onHighlight:r,isOpen:n,id:i,className:s}){let m=e[0],f=n&&m&&m.options.length>0;return(0,Se.jsx)("div",{id:i,role:"listbox",className:`${Ae.dropdown} ${f?Ae.visible:""} ${s??""}`,onMouseDown:h=>h.preventDefault(),children:m&&m.options.length>0&&(0,Se.jsx)(Ee,{options:m.options,activeIndex:o,onSelect:t,onHighlight:r,listboxId:i})})}if(typeof document<"u"){let e=document.createElement("style");e.textContent=`.PillList-module_list_qvLqO {
|
|
222
|
+
position: relative;
|
|
223
|
+
z-index: 1;
|
|
224
|
+
pointer-events: auto;
|
|
225
|
+
display: inline-flex;
|
|
226
|
+
gap: 5px;
|
|
227
|
+
align-items: center;
|
|
228
|
+
vertical-align: middle;
|
|
229
|
+
transform: translateY(-3px);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.PillList-module_pill_osSyz {
|
|
233
|
+
display: inline-flex;
|
|
234
|
+
align-items: center;
|
|
235
|
+
justify-content: center;
|
|
236
|
+
height: 36px;
|
|
237
|
+
padding: 7px 9px;
|
|
238
|
+
border: none;
|
|
239
|
+
border-radius: 6px;
|
|
240
|
+
background: var(--ac-color-background-supportive, #313255);
|
|
241
|
+
color: var(--ac-color-text-muted, #c1c4cb);
|
|
242
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
243
|
+
font-size: 21px;
|
|
244
|
+
line-height: 30px;
|
|
245
|
+
cursor: pointer;
|
|
246
|
+
white-space: nowrap;
|
|
247
|
+
animation: PillList-module_fadeIn_Aezob 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.PillList-module_pill_osSyz:hover {
|
|
251
|
+
filter: brightness(1.2);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.PillList-module_active_Oll-- {
|
|
255
|
+
outline: 1px solid #5a5b8a;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@keyframes PillList-module_fadeIn_Aezob {
|
|
259
|
+
from {
|
|
260
|
+
opacity: 0;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
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){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){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.9",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});
|
|
2
264
|
//# sourceMappingURL=index.js.map
|