@magicx-eng/ai-autocomplete-vanilla 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +190 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +190 -103
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ie=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Be=(n,e)=>{for(var t in e)ie(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Fe(e))!He.call(n,r)&&r!==t&&ie(n,r,{get:()=>e[r],enumerable:!(i=Ne(e,r))||i.enumerable});return n};var Qe=n=>Ke(ie({},"__esModule",{value:!0}),n);var gt={};Be(gt,{AIAutocomplete:()=>ne,ModeController:()=>D,buildQuery:()=>S,createStore:()=>Z,cursorIsAtEnd:()=>$,extractPlainText:()=>L,getCursorOffset:()=>T,plainTextLength:()=>Q,previousGraphemeBoundary:()=>U,renderEditableContent:()=>J,setCursorOffset:()=>P});module.exports=Qe(gt);var k=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var $e="https://api.ai-autocomplete.com",R=`${$e}/api/suggest`,ce=new WeakMap;function M(n){return n?.type==="accessToken"}function Ue(n){if(!(!n||M(n)))return n}function _(n){let e=ce.get(n.getAccessToken);return e||(e=new k(n),ce.set(n.getAccessToken,e)),e}function N(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function F(n){let e=Ue(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}var qe="0.2.1",pe=!1;function We(){return crypto.randomUUID()}function Ge(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function je(n,e,t,i){let r=e.find(o=>o.type==="contact"&&o.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(o=>Ge(o,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:We(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:qe,session_id:i}}}async function ue(n,e,t,i,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function me(n,e,t){let i=t.apiConfig,r=!t.maskCompletedText,s=je(n,e,r,t.sessionId),o=N(i),a=i?.endpoint??R,l=JSON.stringify(s);if(M(i)){let c=_(i),m=await c.getToken(),b=await ue(a,o,m,l,t.signal);if(b.status===401){let g=await c.getToken(!0);b=await ue(a,o,g,l,t.signal)}if(!b.ok)throw new Error(`API error: ${b.status} ${b.statusText}`);return b.json()}let d=F(i);!d&&!pe&&(pe=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),d&&(o.Authorization=d);let p=await fetch(a,{method:"POST",headers:o,body:l,signal:t.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function S(n,e){let t=n,i={},r=[];for(let s of e){let o=(i[s.type]??0)+1;i[s.type]=o;let l=`{{${s.type.toUpperCase().replace(/\s+/g,"_")}_${o}}}`,d=t.indexOf(s.text);d!==-1&&(t=t.slice(0,d)+l+t.slice(d+s.text.length)),r.push({...s,placeholder:l})}return{rawQuery:t,completedParams:r}}function I(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function w(n,e,t){let i=n.slice(e);if(t||e===0||n[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function ge(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let s=0;s<i.length;s++){let o=i.slice(s).join(" ");if(r.startsWith(o.toLowerCase())){let a=t.length-o.length;return n.length-a}}return 0}function E(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let i=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function A(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}function fe(n,e){return e?n.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let s=new Set(r.map(a=>a.text)),o=(t.options??[]).filter(a=>!s.has(a.text));return{...t,options:[...r,...o]}}):n}var Ve=100,ze=300,Xe=2,H=class{constructor(e,t,i,r,s,o,a={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=s;this.getSessionId=o;this.callbacks=a;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,s=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let o=await me(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let a=fe(o.data.suggestions??[],this.getOptionOverrides()),l=o.data.input??[],d=l[l.length-1],p=this.store.get().text,c,m;if(d?.state==="in_progress"){m=!0;let f=p.toLowerCase().lastIndexOf(d.text.toLowerCase());c=f!==-1?f:s}else m=!1,c=s;let g=a.filter(f=>f.type!=="placeholder")[0],h=null;if(g){let f=w(p,c,m),u=A(g.options,f);u&&(h={id:crypto.randomUUID(),placeholder:"",type:g.type,text:u.text,kind:u.kind,suggestionType:g.type,suggestionPlaceholder:g.text,options:g.options??[],metadata:u.metadata},a=a.filter(x=>x!==g),this.callbacks.onAutoMatch?.({active:g,matched:u,rawQuery:e}))}this.store.set(f=>({suggestions:a,isLoading:!1,isReady:o.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:c,filterInProgress:m,...h?{completedParams:[...f.completedParams,h]}:{}}))}catch(o){if(r===this.fetchVersion){let a=o instanceof Error?o:new Error(String(o));this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let s=r.suggestions.filter(x=>x.type==="placeholder").map(x=>x.text).join(" "),o=I(r.text,r.filterBase,s),a=w(r.text,o,r.filterInProgress),d=r.suggestions.filter(x=>x.type!=="placeholder")[0],c=(d?E(d.options,a):[]).filter(x=>x.is_tappable),m=d?A(d.options,a)!==null:!1,b=a.trim().length>0;if(c.length>0&&!m&&b||r.completedParams.length===0&&r.text.length>0&&s.length>0&&s.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:g,completedParams:h}=S(r.text,r.completedParams),f=g.length<r.lastRawQuery.length,u=Math.abs(g.length-r.lastRawQuery.length);return f||u>=i?(this.doFetch(g,h),!0):!1};this.debounceTimer=setTimeout(()=>{t(Xe)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},Ve),this.slowDebounceTimer=setTimeout(()=>t(1),ze)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var xe='[contenteditable="false"]',O;function Ye(){if(O!==void 0)return O;let n=globalThis.Intl.Segmenter;if(!n)return O=null,null;try{O=new n(void 0,{granularity:"grapheme"})}catch{O=null}return O??null}function B(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(xe))return!0;t=t.parentNode}return!1}function K(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return B(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function L(n){let e=K(n),t="",i=e.nextNode();for(;i;)t+=i.data,i=e.nextNode();return t}function Q(n){let e=K(n),t=0,i=e.nextNode();for(;i;)t+=i.data.length,i=e.nextNode();return t}function T(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,i=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(B(r,n)&&r!==n)return null;let s=0;for(let o=0;o<i&&o<r.childNodes.length;o++)s+=be(r.childNodes[o],n);return s+he(r,n)}return t.nodeType!==Node.TEXT_NODE||B(t,n)?null:he(t,n)+i}function be(n,e){if(n.nodeType===Node.TEXT_NODE)return B(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(xe))return 0;let i=0;for(let r of Array.from(t.childNodes))i+=be(r,e);return i}function he(n,e){let t=K(e),i=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return i;i+=r.data.length,r=t.nextNode()}return i}function P(n,e){let t=n.ownerDocument??document,i=t.getSelection();if(!i)return;let r=Math.max(0,Math.min(e,Q(n))),s=K(n),o=0,a=null,l=0,d=s.nextNode(),p=null;for(;d;){let m=d.data.length;if(r<o+m){a=d,l=r-o;break}if(r===o+m){let b=s.nextNode();b?(a=b,l=0):(a=d,l=m);break}o+=m,p=d,d=s.nextNode()}let c=t.createRange();if(a){let m=a.parentElement?.closest('strong[data-seg="completed"]');m&&m!==n&&n.contains(m)?l===0?c.setStartBefore(m):l===a.data.length?c.setStartAfter(m):c.setStart(a,l):c.setStart(a,l)}else p?c.setStart(p,p.data.length):c.setStart(n,0);c.collapse(!0),i.removeAllRanges(),i.addRange(c)}function $(n){let e=T(n);return e==null?!1:e>=Q(n)}function U(n,e){if(e<=0)return 0;let t=Ye();if(!t)return e-1;let i=n.slice(0,e),r=0;for(let{index:s}of t.segment(i))s<e&&(r=s);return r}function re(n){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?$(n):!1}function Je(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?T(n):null}var q=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:i,getOnSubmit:r}=this.ctx,s=this.getEffectiveColumns(),o=r(),a=this.getTappableIndices(s);if((e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)&&(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return;let l=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let d=re(e.target),p=!!t.editingParam;if(!d&&!p&&t.activeDropdownIndex<0)break;if(t.activeDropdownIndex<0){if(l)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:a[0]??0});break}if(a.length===0)return;this.store.set({activeDropdownIndex:a[0]});break}if(e.preventDefault(),a.length===0)return;if(t.filteredOptions.length>0){let b=Math.floor((t.filteredOptions.length-1)/s);if(Math.floor(t.activeDropdownIndex/s)===b){this.store.set({activeDropdownIndex:-1});break}}let c=a.indexOf(t.activeDropdownIndex),m=c<a.length-1?c+1:0;this.store.set({activeDropdownIndex:a[m]});break}case"ArrowUp":{if(t.activeDropdownIndex<0){if(!l)break;let c=re(e.target),m=!!t.editingParam;if(!c&&!m)break;e.preventDefault();let b=this.firstTappableInBottomRow(s)??a[0]??0;if(!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:b});break}if(a.length===0)return;this.store.set({activeDropdownIndex:b});break}if(a.length===0)break;if(e.preventDefault(),t.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let d=a.indexOf(t.activeDropdownIndex),p=d>0?d-1:a.length-1;this.store.set({activeDropdownIndex:a[p]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s<s-1){let c=t.activeDropdownIndex+1;c<t.filteredOptions.length&&t.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let p=e.target.closest("[data-aia-input]")??e.target,c=t.editingTail;this.ctx.exitEditMode?.(),P(p,c);break}re(e.target)&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s>0){let d=t.activeDropdownIndex-1;d>=0&&t.filteredOptions[d]?.is_tappable&&this.store.set({activeDropdownIndex:d})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let d=e.target.closest("[data-aia-input]")??e.target,p=t.editingAnchor;this.ctx.exitEditMode?.(),P(d,p);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let d=Je(e.target);if(d==null)break;this.ctx.removeParamAtCaret(d)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(o){let{rawQuery:d,completedParams:p}=S(t.text,t.completedParams);o({query:t.text.trim(),raw_query:d,completed_params:p}),this.ctx.afterSubmit?.()}break}case"Tab":{let d=!t.text&&!!t.placeholderText,p=t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable;if(d&&!p){e.preventDefault();let c=t.placeholderText;if(this.store.set(m=>({text:c,filterBase:c.length,suggestions:m.suggestions.filter(b=>b.type!=="placeholder")})),e.target instanceof HTMLElement){let m=e.target.closest("[data-aia-input]")??e.target;queueMicrotask(()=>P(m,c.length))}}else if(p)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(t.isDropdownOpen){let c=t.filteredOptions.findIndex(m=>m.is_tappable);c>=0&&(e.preventDefault(),this.clickOrSelect(c,t.filteredOptions,i))}break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let d=e.target.closest("[data-aia-input]")??e.target,p=t.editingTail;this.ctx.exitEditMode?.(),P(d,p)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let t=this.store.get();if(t.filteredOptions.length===0)return null;let r=Math.floor((t.filteredOptions.length-1)/e)*e;for(let s=r;s<t.filteredOptions.length;s++)if(t.filteredOptions[s]?.is_tappable)return s;return null}getTappableIndices(e){let i=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),r=Array.from({length:e},()=>[]);for(let s of i)r[s%e].push(s);return r.flat()}getEffectiveColumns(){let e=document.getElementById(this.ctx.listboxId);if(!e)return this.ctx.columns;let i=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let r=getComputedStyle(i).gridTemplateColumns;if(r&&r!=="none"){let s=r.split(" ").filter(Boolean).length;if(s>0)return s}if(i===e)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}};var W=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(a=>a.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((a,l)=>l!==e),o=t.suggestions.filter(a=>a.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:a}=S(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:a,selectedPill:r.text,otherPills:s.map(l=>l.text)})}this.store.set({suggestions:[...o,r,...s],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};function ye(n,e){let t=[],i=0;for(let s of e){let o=n.indexOf(s.text,i);o!==-1&&(o>i&&t.push({type:"text",value:n.slice(i,o)}),t.push({type:"completed",value:s.text,param:s}),i=o+s.text.length)}let r=n.slice(i);return r&&t.push({type:"text",value:r}),t}function ve(n,e){let t=[],i=[],r=0;for(let s of e){let o=n.indexOf(s.text,r);o===-1?i.push(s):(t.push(s),r=o+s.text.length)}return{valid:t,invalid:i}}function Se(n,e){let t=e.dropdownTrigger??"auto",i=e.closeDropdownOnBlur??!0,r=n.filteredOptionsLength>0;if(n.inEditMode){let s=i?n.isFocused:!0;return r&&s}if(t==="auto"){let s=i?n.isFocused:!0,o=n.text.replace(/\s+$/,"").length,a=n.caretOffset==null||n.caretOffset>=o;return(r||n.isLoading)&&s&&a}return t==="manual"?(r||n.isLoading)&&n.pillTapped:!1}function Pe(n,e){let t=ye(n.text,n.completedParams),i=n.suggestions.filter(g=>g.type!=="placeholder"),r=i[0],s=r?e.optionOverrides?.[r.type]:void 0,o=n.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),a=I(n.text,Math.min(n.filterBase,n.text.length),o),d=n.lastRawQuery!==""||a>0?w(n.text,a,n.filterInProgress):"",p=r?s?s(d.trim()):r.options??[]:[],c=n.editingParam!=null&&n.editingAnchor!=null,m;if(c&&n.editingParam&&n.editingAnchor!=null){let g=n.editingParam.id,h=n.completedParams.some(x=>x.id===g),f=n.caretOffset??n.editingAnchor,u=h?"":n.text.slice(n.editingAnchor,f);m=E(n.editingParam.options,u)}else m=E(p,d);e.showNonTappableOptions===!1&&(m=m.filter(g=>g.is_tappable));let b=Se({inEditMode:c,filteredOptionsLength:m.length,isFocused:n.isFocused,text:n.text,caretOffset:n.caretOffset,isLoading:n.isLoading,pillTapped:n.pillTapped},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur});return{segments:t,actionableSuggestions:i,filteredOptions:m,placeholderText:o,isDropdownOpen:b}}function G(n){return n.mode==="fresh"?Ze(n):et(n)}function Ze(n){let{text:e,completedParams:t,suggestions:i,filterBase:r,filterInProgress:s}=n,a=i.filter(v=>v.type!=="placeholder")[0];if(!a?.options)return null;let l=i.filter(v=>v.type==="placeholder").map(v=>v.text).join(" "),d=I(e,r,l),p=w(e,d,s),c=A(a.options,p);if(!c)return null;let m=c.text.toLowerCase(),b=e.toLowerCase().lastIndexOf(m),g=b>=0?b:Math.max(0,e.length-c.text.length),h=g+c.text.length,f=e.slice(g,h),x=h<e.length&&e[h]===" "?h+1:h,y={id:crypto.randomUUID(),placeholder:"",type:a.type,text:f,kind:c.kind,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:c.metadata};return{patch:{text:e,completedParams:[...t,y],suggestions:i.filter(v=>v!==a),filterBase:x,newParamId:y.id,caretOffset:x,activeDropdownIndex:-1},caretPos:x}}function et(n){let{text:e,completedParams:t,editingParam:i,editingAnchor:r,editingTail:s}=n;if(t.some(y=>y.id===i.id))return null;let o=e.slice(r,s),a=A(i.options,o);if(!a)return null;let l=a.text.toLowerCase(),d=o.toLowerCase().lastIndexOf(l),p=r+Math.max(0,d),c=p+a.text.length,m=e.slice(p,c),g=c<e.length&&e[c]===" "?c+1:c,h={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:m,kind:a.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:a.metadata},f=t.length,u=0;for(let y=0;y<t.length;y++){let v=e.indexOf(t[y].text,u);if(v!==-1){if(v>=g){f=y;break}u=v+t[y].text.length}}let x=[...t];return x.splice(f,0,h),{patch:{text:e,completedParams:x,newParamId:h.id,filterBase:g,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:g,activeDropdownIndex:-1},caretPos:g}}var j=class{constructor(e){this.deps=e}start(e){let t=this.deps.store.get();if(t.editingParam?.id===e)return;let i=t.completedParams.find(o=>o.id===e);if(!i)return;let r=0,s=-1;for(let o of t.completedParams){let a=t.text.indexOf(o.text,r);if(a!==-1){if(o.id===e){s=a;break}r=a+o.text.length}}s<0||this.deps.store.set({editingParam:i,editingAnchor:s,editingTail:s+i.text.length,caretOffset:s+i.text.length,activeDropdownIndex:-1})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null||!t.completedParams.some(l=>l.id===i.id))return!1;let o=t.text.slice(0,r)+e+t.text.slice(s),a=r+e.length;return this.deps.store.set(l=>({text:o,completedParams:l.completedParams.filter(d=>d.id!==i.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.tryPromote(),!0}caretAfterInput(e){let t=this.deps.store.get(),i={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(i.editingParam=null,i.editingAnchor=null,i.editingTail=null,i.activeDropdownIndex=-1):t.editingTail!=null&&(i.editingTail=Math.max(t.editingTail,e))),this.deps.store.set(i),this.tryPromote()}caretMove(e){let t=this.deps.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null)return;this.deps.fireTelemetry("option",{raw_query:S(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:i.options.filter(u=>u.text!==e.text).map(u=>u.text)});let o=t.text.slice(0,r),a=t.text.slice(s),l=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,d=a.length===0||a[0]!==" ",p=d?`${l} `:l,c=o+p+a,m=r+p.length+(d?0:1),b={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:l,kind:e.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:e.metadata},g=t.completedParams.findIndex(u=>u.id===i.id),h=t.completedParams.filter(u=>u.id!==i.id),f=g>=0?Math.min(g,h.length):h.length;h.splice(f,0,b),this.deps.store.set({text:c,completedParams:h,newParamId:b.id,filterBase:m,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:m,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(m)}tryPromote(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let t=G({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});t&&(this.deps.store.set(t.patch),this.deps.scheduleSetCursor(t.caretPos))}};var Te="data-aia-key";function V(n,e,t){let i=new Map;for(let o of Array.from(n.children)){let a=o.getAttribute(Te);a!=null&&i.set(a,o)}let r=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],l=t.keyOf(a,o);r.add(l);let d=i.get(l);d||(d=t.create(a,o),d.setAttribute(Te,l)),t.update?.(d,a,o),n.children[o]!==d&&n.insertBefore(d,n.children[o]??null),s.push(d)}for(let[o,a]of i)r.has(o)||a.remove();return s}var Ce=[125,69];function we(n){return n===0?.4:n===1?.3:.15}function z(n,e,t,i,r=!1,s=!1){let o=n.querySelector(".magicx-aia-pill-list");if(o||(o=document.createElement("span"),o.className="magicx-aia-pill-list",n.appendChild(o)),s&&e.length===0){o.setAttribute("data-aia-pill-list-loading",""),o.innerHTML="";for(let a=0;a<Ce.length;a++){let l=Ce[a],d=document.createElement("span");d.setAttribute("data-aia-pill-skeleton",""),d.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,d.style.width=`${l}px`,d.style.opacity=String(we(a)),o.appendChild(d)}return}s?o.setAttribute("data-aia-pill-list-loading",""):o.removeAttribute("data-aia-pill-list-loading");for(let a of o.querySelectorAll("[data-aia-pill-skeleton]"))a.remove();V(o,e,{keyOf:a=>`${a.type}-${a.text}`,create:a=>{let l=document.createElement("button");return l.type="button",l.tabIndex=-1,l.setAttribute("data-aia-pill",""),l.setAttribute("contenteditable","false"),l.textContent=a.text,l.addEventListener("mousedown",d=>d.preventDefault()),l},update:(a,l,d)=>{let p=a,c=["magicx-aia-pill"];r&&c.push("magicx-aia-pill--rounded"),d===t&&!s&&c.push("magicx-aia-pill--active"),s&&c.push("magicx-aia-pill--skeleton"),p.className=c.join(" "),p.style.width="",p.style.opacity=String(we(d)),s?(p.setAttribute("data-aia-loading",""),p.disabled=!0,p.onclick=null):(p.removeAttribute("data-aia-loading"),p.disabled=!1,p.onclick=()=>i(d))}})}function oe(n){n.querySelector(".magicx-aia-pill-list")?.remove()}var tt=[159,119,164];function X(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function Y(n,e){let{filteredOptions:t,activeIndex:i,isOpen:r,isLoading:s,pills:o,showPills:a,onSelect:l,onHighlight:d,onPillClick:p}=e,c=a&&o.length>0,m=t.length>0;r&&(m||c||s)?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),s?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading");let g=c||s&&a,h=n.querySelector(".magicx-aia-pill-bar");g?(h||(h=document.createElement("div"),h.className="magicx-aia-pill-bar",h.setAttribute("data-aia-pillbar",""),n.insertBefore(h,n.firstChild)),z(h,o,0,p,!0,s)):h&&h.remove();let f=n.querySelector(".magicx-aia-grid");m?(f||(f=document.createElement("div"),f.className="magicx-aia-grid",n.appendChild(f)),nt(f,t,i,l,d,e.listboxId,s)):f&&f.remove();let u=n.querySelector(".magicx-aia-skeleton-bars");if(s&&!m){if(!u){u=document.createElement("div"),u.className="magicx-aia-skeleton-bars",u.setAttribute("data-aia-skeleton-bars","");for(let x of tt){let y=document.createElement("span");y.className="magicx-aia-skeleton-bar",y.style.width=`${x}px`,u.appendChild(y)}n.appendChild(u)}}else u&&u.remove()}function nt(n,e,t,i,r,s,o){let a=o?"1":"0";V(n,e,{keyOf:l=>`${l.text}\0${a}`,create:l=>it(l,o),update:(l,d,p)=>{let c=p===t&&!o;l.id=`${s}-option-${p}`,l.dataset.aiaIndex=String(p),l.setAttribute("aria-selected",String(c)),l.classList.toggle("magicx-aia-option--highlighted",c),!o&&d.is_tappable?(l.onclick=()=>{l.classList.add("magicx-aia-option--pressed"),i(d),setTimeout(()=>l.classList.remove("magicx-aia-option--pressed"),500)},l.onmouseenter=()=>{let m=Number.parseInt(l.dataset.aiaIndex??"-1",10);m>=0&&r(m)}):(l.onclick=null,l.onmouseenter=null)}})}function it(n,e){let t=document.createElement("div");t.setAttribute("role","option"),t.setAttribute("data-aia-option",""),e&&t.setAttribute("data-aia-loading",""),t.tabIndex=e||!n.is_tappable?-1:0;let i=["magicx-aia-option"];n.is_tappable?i.push("magicx-aia-option--tappable"):i.push("magicx-aia-option--non-tappable"),t.className=i.join(" ");let r=document.createElement("div");r.className="magicx-aia-streaks",t.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-streaks-vert",t.appendChild(s);let o=document.createElement("span");o.className="magicx-aia-option-content";let a=document.createElement("span");if(a.className="magicx-aia-option-text",a.textContent=n.icon?`${n.icon} ${n.text}`:n.text,o.appendChild(a),n.tag){let l=document.createElement("span");l.className="magicx-aia-option-tag",l.textContent=n.tag,o.appendChild(l)}return t.appendChild(o),t}function Ee(n,e){let t=X(e.listboxId);return n.appendChild(t),{dropdown:t}}function se(n,e,t){Y(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function J(n){let{input:e,segments:t,newParamId:i,editingParamId:r,placeholderText:s,isFocused:o}=n,a=t.length===0;e.dataset.aiaEmpty=a?"true":"false",a&&s?e.dataset.placeholder=s:delete e.dataset.placeholder;let l=t.map(f=>`${f.type}:${f.value}`).join("\0"),d=e.dataset.segKey??"",p=e.dataset.newParamId??"",c=e.dataset.editingParamId??"";if(l===d&&(i??"")===p&&(r??"")===c)return;let m=o?T(e):null;e.dataset.segKey=l,e.dataset.newParamId=i??"",e.dataset.editingParamId=r??"";let b=e.ownerDocument??document,g=b.createDocumentFragment(),h=0;for(let f of t)if(h+=f.value.length,f.type==="completed"){let u=b.createElement("strong");u.dataset.seg="completed",u.dataset.paramId=f.param.id;let x=f.param.id===i,y=f.param.id===r,v=["magicx-aia-segment","magicx-aia-segment--completed"];x&&v.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),y&&v.push("magicx-aia-segment--editing"),u.className=v.join(" "),u.textContent=f.value,g.appendChild(u)}else g.appendChild(b.createTextNode(f.value));e.replaceChildren(g),e.dataset.aiaTextLength=String(h),m!=null&&P(e,Math.max(0,Math.min(m,h)))}var rt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ot(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function Ie(n,e){let t=e.firstElementChild;if(!t){e.removeAttribute("data-aia-pill-wrapped");return}let i=t.getBoundingClientRect(),r=n.getBoundingClientRect();i.top>=r.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function Ae(n,e){let{listboxId:t}=e,i=X(t);n.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),r.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",ot()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",t),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let l=null,d=null;e.submitButton===void 0?(l=document.createElement("button"),l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.setAttribute("data-aia-submit",""),l.innerHTML=rt,r.appendChild(l),d=l):e.submitButton!==null&&(d=e.submitButton,d.hasAttribute("data-aia-submit")||d.setAttribute("data-aia-submit",""),r.appendChild(d));let p=new AbortController,{signal:c}=p,m=!1,b=0,g=()=>{let u=L(o),y=u.length>0&&u[0]!==u[0].toUpperCase()?u[0].toUpperCase()+u.slice(1):u;e.handleChange(y)},h=()=>{let u=(o.ownerDocument??document).getSelection();if(!u||u.rangeCount===0)return null;let x=u.anchorNode;return!x||!o.contains(x)?null:(x.nodeType===Node.ELEMENT_NODE?x:x.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",u=>{u.target?.closest("[data-aia-pill]")||o.focus()},{signal:c}),o.addEventListener("input",()=>{m||(b=performance.now(),g(),e.handleCaretAfterInput(T(o)))},{signal:c});let f=o.ownerDocument??document;if(f.addEventListener("selectionchange",()=>{let u=f.getSelection();if(!u||u.rangeCount===0||!o.contains(u.anchorNode))return;let x=h(),y=e.store.get().editingParam?.id??null;if(x&&x!==y){e.startEditingParam(x);return}performance.now()-b<50||e.handleCaretMove(T(o))},{signal:c}),o.addEventListener("compositionstart",()=>{m=!0},{signal:c}),o.addEventListener("compositionend",()=>{m=!1,g()},{signal:c}),o.addEventListener("beforeinput",u=>{let x=u,y=x.inputType;if(y==="insertParagraph"||y==="insertLineBreak"||y==="insertFromDrop"){u.preventDefault();return}if(y.startsWith("insert")||y.startsWith("delete")){let v=y.startsWith("delete")?"":x.data??"";e.replaceEditingRange(v)&&u.preventDefault()}},{signal:c}),o.addEventListener("paste",u=>{u.preventDefault();let x=(u.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!x)return;let y=o.ownerDocument??document,v=y.getSelection();if(!v||v.rangeCount===0)return;let C=v.getRangeAt(0);if(!o.contains(C.startContainer))return;C.deleteContents();let de=y.createTextNode(x);C.insertNode(de),C.setStartAfter(de),C.collapse(!0),v.removeAllRanges(),v.addRange(C),g()},{signal:c}),o.addEventListener("keydown",u=>e.handleKeyDown(u),{signal:c}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:c}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:c}),d&&d.addEventListener("click",u=>{let x=e.store.get();if(!(!!x.text||x.completedParams.length>0)||!e.onSubmit)return;u.stopPropagation();let{rawQuery:v,completedParams:C}=S(x.text,x.completedParams);e.onSubmit({query:x.text.trim(),raw_query:v,completed_params:C}),e.afterSubmit?.()},{signal:c}),e.autoFocus!==!1&&o.focus(),typeof ResizeObserver<"u"){let u=new ResizeObserver(()=>Ie(o,a));u.observe(o),p.signal.addEventListener("abort",()=>u.disconnect(),{once:!0})}return{input:o,inlinePillContainer:a,dropdown:i,submitButton:l,abort:p}}function ae(n,e,t){let{input:i,inlinePillContainer:r,dropdown:s,submitButton:o}=n,{pillPlacement:a,setActivePill:l,selectOption:d,store:p}=t;i.setAttribute("aria-expanded",String(e.isDropdownOpen));let c=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(c?i.setAttribute("aria-activedescendant",c):i.removeAttribute("aria-activedescendant"),o){let f=!!e.text||e.completedParams.length>0;o.disabled=!f}let m=i.dataset.newParamId??"",b=e.newParamId!==null&&e.newParamId!==m;if(J({input:i,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),a==="inline"){let f=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;f||e.actionableSuggestions.length>0?z(r,e.actionableSuggestions,0,l,!1,f):oe(r)}else oe(r);Ie(i,r),b?(i.focus(),P(i,e.caretOffset??e.text.length)):e.isFocused&&L(i)!==e.text&&P(i,e.text.length);let g=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,h=g??e.actionableSuggestions[0];Y(s,{suggestions:h?[{...h,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:g?[g]:e.actionableSuggestions,showPills:a==="dropdown",onSelect:d,onHighlight:f=>p.set({activeDropdownIndex:f}),onPillClick:l})}function Oe(n,e){let t=n.actionableSuggestions[0];if(!t)return null;let i=n.filterBase,r=n.text.slice(0,i),s=r.length===0&&n.text.length===0,o=r.length===0&&n.text.length>0&&n.placeholderText.length>0&&n.placeholderText.toLowerCase().startsWith(n.text.toLowerCase());(s||o)&&n.placeholderText&&(r=`${n.placeholderText} `);let a=ge(r,e.text);a>0&&(r=r.slice(0,r.length-a));let l=r.length>0&&r[r.length-1]!==" ",d=`${r}${l?" ":""}${e.text} `,p=(s||o)&&d.length>0?d[0].toUpperCase()+d.slice(1):d,c=p.toLowerCase().lastIndexOf(e.text.toLowerCase()),m=c>=0?p.slice(c,c+e.text.length):e.text,b={id:crypto.randomUUID(),placeholder:"",type:t.type,text:m,kind:e.kind,suggestionType:t.type,suggestionPlaceholder:t.text,options:t.options??[],metadata:e.metadata},g=n.actionableSuggestions.length-1;return{patch:{text:p,filterBase:p.length,completedParams:[...n.completedParams,b],newParamId:b.id,caretOffset:p.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:g>0,inSelectionAnimation:!0},telemetry:{selectedOption:e.text,otherOptions:n.filteredOptions.filter(h=>h.text!==e.text).map(h=>h.text)},consumedSuggestion:t,remainingActionable:g}}function Z(n){let e=n,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,s={...e,...r},o=e;e=s;for(let a of t)a(s,o)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}function De(n,e){let t,i,r=s=>(s!==t&&(t=s,i=e(s)),i);return{get:()=>{let s=n.get();return{...s,...r(s)}},set:s=>{typeof s=="function"?n.set(o=>{let a={...o,...r(o)};return s(a)}):n.set(s)},subscribe:s=>n.subscribe((o,a)=>{let l={...a,...r(a)},d={...o,...r(o)};s(d,l)})}}var le=!1;function Me(){if(le||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){le=!0;return}le=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=st,document.head.appendChild(n)}var st=`@layer layout {
|
|
1
|
+
"use strict";var oe=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Qe=Object.prototype.hasOwnProperty;var qe=(n,e)=>{for(var t in e)oe(n,t,{get:e[t],enumerable:!0})},$e=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ke(e))!Qe.call(n,r)&&r!==t&&oe(n,r,{get:()=>e[r],enumerable:!(i=Be(e,r))||i.enumerable});return n};var Ue=n=>$e(oe({},"__esModule",{value:!0}),n);var yt={};qe(yt,{AIAutocomplete:()=>re,ModeController:()=>k,buildQuery:()=>S,createStore:()=>te,cursorIsAtEnd:()=>$,extractPlainText:()=>L,getCursorOffset:()=>C,getFooterHint:()=>z,plainTextLength:()=>q,previousGraphemeBoundary:()=>U,renderEditableContent:()=>ee,setCursorOffset:()=>P});module.exports=Ue(yt);var R=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var Ge="https://api.ai-autocomplete.com",N=`${Ge}/api/suggest`,pe=new WeakMap;function M(n){return n?.type==="accessToken"}function We(n){if(!(!n||M(n)))return n}function _(n){let e=pe.get(n.getAccessToken);return e||(e=new R(n),pe.set(n.getAccessToken,e)),e}function H(n){return{"Content-Type":"application/json",...n?.appIdentifier&&{"X-App-Identifier":n.appIdentifier},...n?.headers}}function F(n){let e=We(n),t=e?.apiKey;return t?(e?.authScheme??"Bearer")==="Basic"?`Basic ${btoa(t)}`:`Bearer ${t}`:null}var je="0.4.0",ue=!1;function Ve(){return crypto.randomUUID()}function ze(n,e){return{placeholder:n.placeholder,type:n.type,...e&&{text:n.text},kind:n.kind}}function Xe(n,e,t,i){let r=e.find(o=>o.type==="contact"&&o.metadata?.contact_account_count)?.metadata?.contact_account_count,s=typeof r=="number"?r:void 0;return{data:{raw_query:n,completed_params:e.map(o=>ze(o,t)),...s!=null&&{contact_account_count:s}},meta:{request_id:Ve(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:je,session_id:i}}}async function me(n,e,t,i,r){return fetch(n,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function ge(n,e,t){let i=t.apiConfig,r=!t.maskCompletedText,s=Xe(n,e,r,t.sessionId),o=H(i),a=i?.endpoint??N,d=JSON.stringify(s);if(M(i)){let c=_(i),u=await c.getToken(),h=await me(a,o,u,d,t.signal);if(h.status===401){let b=await c.getToken(!0);h=await me(a,o,b,d,t.signal)}if(!h.ok)throw new Error(`API error: ${h.status} ${h.statusText}`);return h.json()}let l=F(i);!l&&!ue&&(ue=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),l&&(o.Authorization=l);let p=await fetch(a,{method:"POST",headers:o,body:d,signal:t.signal});if(!p.ok)throw new Error(`API error: ${p.status} ${p.statusText}`);return p.json()}function S(n,e){let t=n,i={},r=[];for(let s of e){let o=(i[s.type]??0)+1;i[s.type]=o;let d=`{{${s.type.toUpperCase().replace(/\s+/g,"_")}_${o}}}`,l=t.indexOf(s.text);l!==-1&&(t=t.slice(0,l)+d+t.slice(l+s.text.length)),r.push({...s,placeholder:d})}return{rawQuery:t,completedParams:r}}function I(n,e,t){return e>0||!t?e:n.toLowerCase().startsWith(t.toLowerCase())?t.length:e}function E(n,e,t){let i=n.slice(e);if(t||e===0||n[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function fe(n,e){let t=n.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let s=0;s<i.length;s++){let o=i.slice(s).join(" ");if(r.startsWith(o.toLowerCase())){let a=t.length-o.length;return n.length-a}}return 0}function w(n,e){if(!n)return[];let t=e.trimStart();if(!t)return n;let i=t.toLowerCase();return n.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function O(n,e){if(!n)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return n.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}function he(n,e){return e?n.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let s=new Set(r.map(a=>a.text)),o=(t.options??[]).filter(a=>!s.has(a.text));return{...t,options:[...r,...o]}}):n}var Ye=100,Je=300,Ze=2,B=class{constructor(e,t,i,r,s,o,a={}){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=s;this.getSessionId=o;this.callbacks=a;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,s=this.store.get().text.length;this.store.set({isLoading:!0,error:null});try{let o=await ge(e,t,{sessionId:this.getSessionId(),maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let a=he(o.data.suggestions??[],this.getOptionOverrides()),d=o.data.input??[],l=d[d.length-1],p=this.store.get().text,c,u;if(l?.state==="in_progress"){u=!0;let x=p.toLowerCase().lastIndexOf(l.text.toLowerCase());c=x!==-1?x:s}else u=!1,c=s;let b=a.filter(x=>x.type!=="placeholder")[0],g=null;if(b){let x=E(p,c,u),m=O(b.options,x);m&&(g={id:crypto.randomUUID(),placeholder:"",type:b.type,text:m.text,kind:m.kind,suggestionType:b.type,suggestionPlaceholder:b.text,options:b.options??[],metadata:m.metadata},a=a.filter(f=>f!==b),this.callbacks.onAutoMatch?.({active:b,matched:m,rawQuery:e}))}this.store.set(x=>({suggestions:a,isLoading:!1,isReady:o.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:c,filterInProgress:u,...g?{completedParams:[...x.completedParams,g]}:{}}))}catch(o){if(r===this.fetchVersion){let a=o instanceof Error?o:new Error(String(o));this.store.set({error:a,isLoading:!1}),this.getOnError()?.(a)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let s=r.suggestions.filter(f=>f.type==="placeholder").map(f=>f.text).join(" "),o=I(r.text,r.filterBase,s),a=E(r.text,o,r.filterInProgress),l=r.suggestions.filter(f=>f.type!=="placeholder")[0],c=(l?w(l.options,a):[]).filter(f=>f.is_tappable),u=l?O(l.options,a)!==null:!1,h=a.trim().length>0;if(c.length>0&&!u&&h||r.completedParams.length===0&&r.text.length>0&&s.length>0&&s.toLowerCase().startsWith(r.text.toLowerCase()))return!1;let{rawQuery:b,completedParams:g}=S(r.text,r.completedParams),x=b.length<r.lastRawQuery.length,m=Math.abs(b.length-r.lastRawQuery.length);return x||m>=i?(this.doFetch(b,g),!0):!1};this.debounceTimer=setTimeout(()=>{t(Ze)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},Ye),this.slowDebounceTimer=setTimeout(()=>t(1),Je)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var xe='[contenteditable="false"]',D;function et(){if(D!==void 0)return D;let n=globalThis.Intl.Segmenter;if(!n)return D=null,null;try{D=new n(void 0,{granularity:"grapheme"})}catch{D=null}return D??null}function K(n,e){let t=n;for(;t&&t!==e;){if(t.nodeType===Node.ELEMENT_NODE&&t.matches(xe))return!0;t=t.parentNode}return!1}function Q(n){return(n.ownerDocument??document).createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(e){return K(e,n)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}})}function L(n){let e=Q(n),t="",i=e.nextNode();for(;i;)t+=i.data,i=e.nextNode();return t}function q(n){let e=Q(n),t=0,i=e.nextNode();for(;i;)t+=i.data.length,i=e.nextNode();return t}function C(n){let e=(n.ownerDocument??document).getSelection();if(!e||e.rangeCount===0)return null;let t=e.anchorNode,i=e.anchorOffset;if(!t||!n.contains(t))return null;if(t.nodeType===Node.ELEMENT_NODE){let r=t;if(K(r,n)&&r!==n)return null;let s=0;for(let o=0;o<i&&o<r.childNodes.length;o++)s+=ye(r.childNodes[o],n);return s+be(r,n)}return t.nodeType!==Node.TEXT_NODE||K(t,n)?null:be(t,n)+i}function ye(n,e){if(n.nodeType===Node.TEXT_NODE)return K(n,e)?0:n.data.length;if(n.nodeType!==Node.ELEMENT_NODE)return 0;let t=n;if(t.matches(xe))return 0;let i=0;for(let r of Array.from(t.childNodes))i+=ye(r,e);return i}function be(n,e){let t=Q(e),i=0,r=t.nextNode();for(;r;){if(r===n||n.nodeType===Node.ELEMENT_NODE&&n.contains(r))return i;i+=r.data.length,r=t.nextNode()}return i}function P(n,e){let t=n.ownerDocument??document,i=t.getSelection();if(!i)return;let r=Math.max(0,Math.min(e,q(n))),s=Q(n),o=0,a=null,d=0,l=s.nextNode(),p=null;for(;l;){let u=l.data.length;if(r<o+u){a=l,d=r-o;break}if(r===o+u){let h=s.nextNode();h?(a=h,d=0):(a=l,d=u);break}o+=u,p=l,l=s.nextNode()}let c=t.createRange();if(a){let u=a.parentElement?.closest('strong[data-seg="completed"]');u&&u!==n&&n.contains(u)?d===0?c.setStartBefore(u):d===a.data.length?c.setStartAfter(u):c.setStart(a,d):c.setStart(a,d)}else p?c.setStart(p,p.data.length):c.setStart(n,0);c.collapse(!0),i.removeAllRanges(),i.addRange(c)}function $(n){let e=C(n);return e==null?!1:e>=q(n)}function U(n,e){if(e<=0)return 0;let t=et();if(!t)return e-1;let i=n.slice(0,e),r=0;for(let{index:s}of t.segment(i))s<e&&(r=s);return r}function se(n,e){return n instanceof HTMLTextAreaElement||n instanceof HTMLInputElement?n.selectionStart!=null&&n.selectionStart===n.value.length:n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?$(n):e?.caretOffset!=null?e.caretOffset>=e.text.length:!1}function tt(n){return n instanceof HTMLElement&&n.hasAttribute("data-aia-input")?C(n):null}var G=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{listboxId:i,getOnSubmit:r}=this.ctx,s=this.getEffectiveColumns(),o=r(),a=this.getTappableIndices(s);if((e.shiftKey||e.metaKey||e.ctrlKey||e.altKey)&&(e.key==="ArrowDown"||e.key==="ArrowUp"||e.key==="ArrowLeft"||e.key==="ArrowRight"))return;let d=this.ctx.getOptionsPosition()==="above";switch(e.key){case"ArrowDown":{let l=se(e.target,t),p=!!t.editingParam;if(!l&&!p&&t.activeDropdownIndex<0)break;if(t.activeDropdownIndex<0){if(d)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:a[0]??0});break}if(a.length===0)return;this.store.set({activeDropdownIndex:a[0]});break}if(e.preventDefault(),a.length===0)return;if(t.filteredOptions.length>0){let h=Math.floor((t.filteredOptions.length-1)/s);if(Math.floor(t.activeDropdownIndex/s)===h){this.store.set({activeDropdownIndex:-1});break}}let c=a.indexOf(t.activeDropdownIndex),u=c<a.length-1?c+1:0;this.store.set({activeDropdownIndex:a[u]});break}case"ArrowUp":{if(t.activeDropdownIndex<0){if(!d)break;let c=se(e.target,t),u=!!t.editingParam;if(!c&&!u)break;e.preventDefault();let h=this.firstTappableInBottomRow(s)??a[0]??0;if(!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:h});break}if(a.length===0)return;this.store.set({activeDropdownIndex:h});break}if(a.length===0)break;if(e.preventDefault(),t.activeDropdownIndex<s){this.store.set({activeDropdownIndex:-1});break}let l=a.indexOf(t.activeDropdownIndex),p=l>0?l-1:a.length-1;this.store.set({activeDropdownIndex:a[p]});break}case"ArrowRight":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s<s-1){let c=t.activeDropdownIndex+1;c<t.filteredOptions.length&&t.filteredOptions[c]?.is_tappable&&this.store.set({activeDropdownIndex:c})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){e.preventDefault();let p=e.target.closest("[data-aia-input]")??e.target,c=t.editingTail;this.ctx.exitEditMode?.(),P(p,c);break}se(e.target,t)&&t.actionableSuggestions.length>=1&&(e.preventDefault(),this.removeActivePill());break}case"ArrowLeft":{if(t.activeDropdownIndex>=0){if(e.preventDefault(),t.activeDropdownIndex%s>0){let l=t.activeDropdownIndex-1;l>=0&&t.filteredOptions[l]?.is_tappable&&this.store.set({activeDropdownIndex:l})}break}if(t.editingParam&&e.target instanceof HTMLElement&&t.editingAnchor!=null){e.preventDefault();let l=e.target.closest("[data-aia-input]")??e.target,p=t.editingAnchor;this.ctx.exitEditMode?.(),P(l,p);break}break}case"Backspace":{if(t.editingParam||!this.ctx.removeParamAtCaret)break;let l=tt(e.target);if(l==null)break;this.ctx.removeParamAtCaret(l)&&e.preventDefault();break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,i);else if(o){let{rawQuery:l,completedParams:p}=S(t.text,t.completedParams);o({query:t.text.trim(),raw_query:l,completed_params:p}),this.ctx.afterSubmit?.()}break}case"Tab":{let l=t.filteredOptions.map((u,h)=>u.is_tappable?h:-1).filter(u=>u!==-1);if(l.length===0)break;if(!t.isDropdownOpen){if(t.actionableSuggestions.length===0)break;e.preventDefault();let u=e.shiftKey?l[l.length-1]:l[0];this.store.set({pillTapped:!0,activeDropdownIndex:u,hasTabbedToHighlight:!0});break}e.preventDefault();let p=l.indexOf(t.activeDropdownIndex),c;if(p<0)c=e.shiftKey?l.length-1:0;else{let u=e.shiftKey?-1:1;c=(p+u+l.length)%l.length}this.store.set({activeDropdownIndex:l[c],hasTabbedToHighlight:!0});break}case"Escape":{if(t.editingParam&&e.target instanceof HTMLElement&&t.editingTail!=null){let l=e.target.closest("[data-aia-input]")??e.target,p=t.editingTail;this.ctx.exitEditMode?.(),P(l,p)}this.store.set({activeDropdownIndex:-1});break}}}firstTappableInBottomRow(e){let t=this.store.get();if(t.filteredOptions.length===0)return null;let r=Math.floor((t.filteredOptions.length-1)/e)*e;for(let s=r;s<t.filteredOptions.length;s++)if(t.filteredOptions[s]?.is_tappable)return s;return null}getTappableIndices(e){let i=this.store.get().filteredOptions.map((s,o)=>s.is_tappable?o:-1).filter(s=>s!==-1),r=Array.from({length:e},()=>[]);for(let s of i)r[s%e].push(s);return r.flat()}getEffectiveColumns(){let e=document.getElementById(this.ctx.listboxId);if(!e)return this.ctx.columns;let i=document.getElementById(`${this.ctx.listboxId}-option-0`)?.parentElement??null;for(;i;){let r=getComputedStyle(i).gridTemplateColumns;if(r&&r!=="none"){let s=r.split(" ").filter(Boolean).length;if(s>0)return s}if(i===e)break;i=i.parentElement}return this.ctx.columns}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}removeActivePill(){let e=this.store.get(),t=e.suggestions.filter(s=>s.type==="placeholder"),i=e.suggestions.filter(s=>s.type!=="placeholder");if(i.length===0)return;let r=i.slice(1);this.store.set({suggestions:[...t,...r],pillTapped:r.length>0,activeDropdownIndex:-1})}};var W=class{constructor(e,t={}){this.store=e;this.callbacks=t}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(l=>l.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],s=i.filter((l,p)=>p!==e),o=t.suggestions.filter(l=>l.type==="placeholder");if(this.callbacks.onPillSelected){let{rawQuery:l}=S(t.text,t.completedParams);this.callbacks.onPillSelected({rawQuery:l,selectedPill:r.text,otherPills:s.map(p=>p.text)})}let a=[...o,r,...s],d=this.store.peek({suggestions:a}).filteredOptions.findIndex(l=>l.is_tappable);this.store.set({suggestions:a,pillTapped:!0,activeDropdownIndex:d})}removeLastParam(){this.store.get().completedParams.length!==0&&this.store.set(t=>({completedParams:t.completedParams.slice(0,-1),activeDropdownIndex:-1}))}};function ve(n,e){let t=[],i=0;for(let s of e){let o=n.indexOf(s.text,i);o!==-1&&(o>i&&t.push({type:"text",value:n.slice(i,o)}),t.push({type:"completed",value:s.text,param:s}),i=o+s.text.length)}let r=n.slice(i);return r&&t.push({type:"text",value:r}),t}function Se(n,e){let t=[],i=[],r=0;for(let s of e){let o=n.indexOf(s.text,r);o===-1?i.push(s):(t.push(s),r=o+s.text.length)}return{valid:t,invalid:i}}function Pe(n,e){let t=e.dropdownTrigger??"auto",i=e.closeDropdownOnBlur??!0,r=n.filteredOptionsLength>0;if(n.inEditMode){let s=i?n.isFocused:!0;return r&&s}if(t==="auto"){let s=i?n.isFocused:!0,o=n.text.replace(/\s+$/,"").length,a=n.caretOffset==null||n.caretOffset>=o;return(r||n.isLoading)&&s&&a}return t==="manual"?(r||n.isLoading)&&n.pillTapped:!1}function Te(n,e){let t=ve(n.text,n.completedParams),i=n.suggestions.filter(g=>g.type!=="placeholder"),r=i[0],s=r?e.optionOverrides?.[r.type]:void 0,o=n.suggestions.filter(g=>g.type==="placeholder").map(g=>g.text).join(" "),a=I(n.text,Math.min(n.filterBase,n.text.length),o),l=n.lastRawQuery!==""||a>0?E(n.text,a,n.filterInProgress):"",p=r?s?s(l.trim()):r.options??[]:[],c=n.editingParam!=null&&n.editingAnchor!=null,u;if(c&&n.editingParam&&n.editingAnchor!=null){let g=n.editingParam.id,x=n.completedParams.some(y=>y.id===g),m=n.caretOffset??n.editingAnchor,f=x?"":n.text.slice(n.editingAnchor,m);u=w(n.editingParam.options,f)}else u=w(p,l);e.showNonTappableOptions===!1&&(u=u.filter(g=>g.is_tappable));let h=Pe({inEditMode:c,filteredOptionsLength:u.length,isFocused:n.isFocused,text:n.text,caretOffset:n.caretOffset,isLoading:n.isLoading,pillTapped:n.pillTapped},{dropdownTrigger:e.dropdownTrigger,closeDropdownOnBlur:e.closeDropdownOnBlur}),b=h&&n.activeDropdownIndex>=0&&!!u[n.activeDropdownIndex]?.is_tappable;return{segments:t,actionableSuggestions:i,filteredOptions:u,placeholderText:o,isDropdownOpen:h,isActivePillSelected:b}}function j(n){return n.mode==="fresh"?nt(n):it(n)}function nt(n){let{text:e,completedParams:t,suggestions:i,filterBase:r,filterInProgress:s}=n,a=i.filter(v=>v.type!=="placeholder")[0];if(!a?.options)return null;let d=i.filter(v=>v.type==="placeholder").map(v=>v.text).join(" "),l=I(e,r,d),p=E(e,l,s),c=O(a.options,p);if(!c)return null;let u=c.text.toLowerCase(),h=e.toLowerCase().lastIndexOf(u),b=h>=0?h:Math.max(0,e.length-c.text.length),g=b+c.text.length,x=e.slice(b,g),f=g<e.length&&e[g]===" "?g+1:g,y={id:crypto.randomUUID(),placeholder:"",type:a.type,text:x,kind:c.kind,suggestionType:a.type,suggestionPlaceholder:a.text,options:a.options??[],metadata:c.metadata};return{patch:{text:e,completedParams:[...t,y],suggestions:i.filter(v=>v!==a),filterBase:f,newParamId:y.id,caretOffset:f,activeDropdownIndex:-1},caretPos:f}}function it(n){let{text:e,completedParams:t,editingParam:i,editingAnchor:r,editingTail:s}=n;if(t.some(y=>y.id===i.id))return null;let o=e.slice(r,s),a=O(i.options,o);if(!a)return null;let d=a.text.toLowerCase(),l=o.toLowerCase().lastIndexOf(d),p=r+Math.max(0,l),c=p+a.text.length,u=e.slice(p,c),b=c<e.length&&e[c]===" "?c+1:c,g={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:u,kind:a.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:a.metadata},x=t.length,m=0;for(let y=0;y<t.length;y++){let v=e.indexOf(t[y].text,m);if(v!==-1){if(v>=b){x=y;break}m=v+t[y].text.length}}let f=[...t];return f.splice(x,0,g),{patch:{text:e,completedParams:f,newParamId:g.id,filterBase:b,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:b,activeDropdownIndex:-1},caretPos:b}}var V=class{constructor(e){this.deps=e}start(e){let t=this.deps.store.get();if(t.editingParam?.id===e)return;let i=t.completedParams.find(o=>o.id===e);if(!i)return;let r=0,s=-1;for(let o of t.completedParams){let a=t.text.indexOf(o.text,r);if(a!==-1){if(o.id===e){s=a;break}r=a+o.text.length}}s<0||this.deps.store.set({editingParam:i,editingAnchor:s,editingTail:s+i.text.length,caretOffset:s+i.text.length,activeDropdownIndex:-1})}exit(){this.deps.store.get().editingParam&&this.deps.store.set({editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1})}replaceRange(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null||!t.completedParams.some(d=>d.id===i.id))return!1;let o=t.text.slice(0,r)+e+t.text.slice(s),a=r+e.length;return this.deps.store.set(d=>({text:o,completedParams:d.completedParams.filter(l=>l.id!==i.id),editingTail:a,caretOffset:a,activeDropdownIndex:-1})),this.deps.scheduleSetCursor(a),this.tryPromote(),!0}caretAfterInput(e){let t=this.deps.store.get(),i={caretOffset:e};t.editingParam&&t.editingAnchor!=null&&e!=null&&(e<t.editingAnchor?(i.editingParam=null,i.editingAnchor=null,i.editingTail=null,i.activeDropdownIndex=-1):t.editingTail!=null&&(i.editingTail=Math.max(t.editingTail,e))),this.deps.store.set(i),this.tryPromote()}caretMove(e){let t=this.deps.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null&&e!=null&&(e<t.editingAnchor||e>t.editingTail)){this.deps.store.set({caretOffset:e,editingParam:null,editingAnchor:null,editingTail:null,activeDropdownIndex:-1});return}this.deps.store.set({caretOffset:e})}selectOption(e){let t=this.deps.store.get(),i=t.editingParam,r=t.editingAnchor,s=t.editingTail;if(!i||r==null||s==null)return;this.deps.fireTelemetry("option",{raw_query:S(t.text,t.completedParams).rawQuery,selected_option:e.text,other_options:i.options.filter(m=>m.text!==e.text).map(m=>m.text)});let o=t.text.slice(0,r),a=t.text.slice(s),d=r===0&&e.text.length>0?e.text[0].toUpperCase()+e.text.slice(1):e.text,l=a.length===0||a[0]!==" ",p=l?`${d} `:d,c=o+p+a,u=r+p.length+(l?0:1),h={id:crypto.randomUUID(),placeholder:"",type:i.suggestionType,text:d,kind:e.kind,suggestionType:i.suggestionType,suggestionPlaceholder:i.suggestionPlaceholder,options:i.options,metadata:e.metadata},b=t.completedParams.findIndex(m=>m.id===i.id),g=t.completedParams.filter(m=>m.id!==i.id),x=b>=0?Math.min(b,g.length):g.length;g.splice(x,0,h),this.deps.store.set({text:c,completedParams:g,newParamId:h.id,filterBase:u,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:u,activeDropdownIndex:-1,pillTapped:!1,skipNextFetch:!0,inSelectionAnimation:!0}),this.deps.startSelectionAnimationTimer(),this.deps.scheduleSetCursor(u)}tryPromote(){let e=this.deps.store.get();if(!e.editingParam||e.editingAnchor==null||e.editingTail==null)return;let t=j({mode:"edit",text:e.text,completedParams:e.completedParams,editingParam:e.editingParam,editingAnchor:e.editingAnchor,editingTail:e.editingTail});t&&(this.deps.store.set(t.patch),this.deps.scheduleSetCursor(t.caretPos))}};function z(n,e,t){return e?{key:"enter",hint:"to proceed"}:t?{key:"tab",hint:"to skip"}:n?{key:"\u2192",hint:"to skip"}:{key:"tab",hint:"to select"}}var Ce="data-aia-key";function X(n,e,t){let i=new Map;for(let o of Array.from(n.children)){let a=o.getAttribute(Ce);a!=null&&i.set(a,o)}let r=new Set,s=[];for(let o=0;o<e.length;o++){let a=e[o],d=t.keyOf(a,o);r.add(d);let l=i.get(d);l||(l=t.create(a,o),l.setAttribute(Ce,d)),t.update?.(l,a,o),n.children[o]!==l&&n.insertBefore(l,n.children[o]??null),s.push(l)}for(let[o,a]of i)r.has(o)||a.remove();return s}var Ee=[125,69];function we(n,e){return e?1:n===0?.7:n===1?.4:.2}function Y(n,e,t,i,r=!1,s=!1,o=!1){let a=n.querySelector(".magicx-aia-pill-list");if(a||(a=document.createElement("span"),a.className="magicx-aia-pill-list",n.appendChild(a)),s&&e.length===0){a.setAttribute("data-aia-pill-list-loading",""),a.innerHTML="";for(let d=0;d<Ee.length;d++){let l=Ee[d],p=document.createElement("span");p.setAttribute("data-aia-pill-skeleton",""),p.className=`magicx-aia-pill magicx-aia-pill--skeleton${r?" magicx-aia-pill--rounded":""}`,p.style.width=`${l}px`,p.style.opacity=String(we(d,!1)),a.appendChild(p)}return}s?a.setAttribute("data-aia-pill-list-loading",""):a.removeAttribute("data-aia-pill-list-loading");for(let d of a.querySelectorAll("[data-aia-pill-skeleton]"))d.remove();X(a,e,{keyOf:d=>`${d.type}-${d.text}`,create:d=>{let l=document.createElement("button");return l.type="button",l.tabIndex=-1,l.setAttribute("data-aia-pill",""),l.setAttribute("contenteditable","false"),l.textContent=d.text,l.addEventListener("mousedown",p=>p.preventDefault()),l},update:(d,l,p)=>{let c=d,u=o&&p===t&&!s,h=["magicx-aia-pill"];r&&h.push("magicx-aia-pill--rounded"),u&&h.push("magicx-aia-pill--active"),s&&h.push("magicx-aia-pill--skeleton"),c.className=h.join(" "),c.style.width="",c.style.opacity=String(we(p,u)),s?(c.setAttribute("data-aia-loading",""),c.disabled=!0,c.onclick=null):(c.removeAttribute("data-aia-loading"),c.disabled=!1,c.onclick=()=>i(p))}})}function ae(n){n.querySelector(".magicx-aia-pill-list")?.remove()}function Ae(n,e,t,i,r,s,o){let a=n.querySelector(".aia-grid");if(e.length===0){a?.remove();return}a||(a=document.createElement("div"),a.className="aia-grid magicx-aia-grid",a.setAttribute("data-scroll",""),a.style.setProperty("--aia-grid-min","250px"),a.style.setProperty("--aia-grid-max","250px"),a.style.setProperty("--aia-grid-gap","0"),n.appendChild(a)),rt(a,e,t,i,r,s,o)}function rt(n,e,t,i,r,s,o){let a=o?"1":"0";X(n,e,{keyOf:d=>`${d.text}\0${a}`,create:d=>ot(d,o),update:(d,l,p)=>{let c=p===t&&!o;d.id=`${s}-option-${p}`,d.dataset.aiaIndex=String(p),d.setAttribute("aria-selected",String(c)),d.classList.toggle("magicx-aia-option--highlighted",c),!o&&l.is_tappable?(d.onclick=()=>{d.classList.add("magicx-aia-option--pressed"),i(l),setTimeout(()=>d.classList.remove("magicx-aia-option--pressed"),500)},d.onmouseenter=()=>{let u=Number.parseInt(d.dataset.aiaIndex??"-1",10);u>=0&&r(u)}):(d.onclick=null,d.onmouseenter=null)}})}function ot(n,e){let t=document.createElement("div");t.setAttribute("role","option"),t.setAttribute("data-aia-option",""),e&&t.setAttribute("data-aia-loading",""),t.tabIndex=e||!n.is_tappable?-1:0;let i=["magicx-aia-option"];n.is_tappable?i.push("magicx-aia-option--tappable"):i.push("magicx-aia-option--non-tappable"),t.className=i.join(" ");let r=document.createElement("div");r.className="magicx-aia-streaks",t.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-streaks-vert",t.appendChild(s);let o=document.createElement("span");o.className="magicx-aia-option-content";let a=document.createElement("span");if(a.className="magicx-aia-option-text",a.textContent=n.icon?`${n.icon} ${n.text}`:n.text,o.appendChild(a),n.tag){let d=document.createElement("span");d.className="magicx-aia-option-tag",d.textContent=n.tag,o.appendChild(d)}return t.appendChild(o),t}var st=[159,119,164];function J(n){let e=document.createElement("div");return e.id=n,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function Z(n,e){let{filteredOptions:t,activeIndex:i,isOpen:r,isLoading:s,pills:o,showPills:a,isActivePillSelected:d,onSelect:l,onHighlight:p,onPillClick:c}=e,u=a&&o.length>0,h=t.length>0,b=r&&(h||u||s);if(b?n.classList.add("magicx-aia-dropdown--visible"):n.classList.remove("magicx-aia-dropdown--visible"),s?n.setAttribute("data-aia-loading",""):n.removeAttribute("data-aia-loading"),!b)return;let g=n.querySelector(".aia-stack");g||(g=document.createElement("div"),g.className="aia-stack",g.style.setProperty("--aia-stack-space","2px"),n.appendChild(g));let x=u||s&&a,m=g.querySelector(".magicx-aia-pill-bar");x?(m||(m=document.createElement("div"),m.className="magicx-aia-pill-bar aia-cluster",m.setAttribute("data-nowrap",""),m.setAttribute("data-aia-pillbar",""),g.insertBefore(m,g.firstChild)),Y(m,o,0,c,!0,s,d)):m&&m.remove(),Ae(g,t,i,l,p,e.listboxId,s);let f=g.querySelector(".magicx-aia-skeleton-bars");if(s&&!h){if(!f){f=document.createElement("div"),f.className="magicx-aia-skeleton-bars",f.setAttribute("data-aia-skeleton-bars","");for(let T of st){let A=document.createElement("span");A.className="magicx-aia-skeleton-bar",A.style.width=`${T}px`,f.appendChild(A)}g.appendChild(f)}}else f&&f.remove();let y=g.querySelector(".magicx-aia-footer")??lt(),v=i>=0&&!!t[i]?.is_tappable;at(y,z(e.hasTabbedToHighlight,v,e.isInputEmpty)),g.lastElementChild!==y&&g.appendChild(y)}function at(n,{key:e,hint:t}){let i=n.querySelector(".magicx-aia-footer-key"),r=n.querySelector(".magicx-aia-footer-hint");!i||!r||(i.textContent!==e&&(i.textContent=e),r.textContent!==t&&(r.textContent=t))}function lt(){let n=document.createElement("footer");n.className="magicx-aia-footer",n.setAttribute("data-aia-footer","");let e=document.createElement("div");e.className="magicx-aia-footer-divider";let t=document.createElement("div");t.className="aia-cluster",t.setAttribute("data-align","center"),t.setAttribute("data-justify","between"),t.setAttribute("data-nowrap","");let i=document.createElement("div");i.className="aia-cluster",i.setAttribute("data-align","center"),i.style.setProperty("--aia-cluster-gap","5px");let r=document.createElement("kbd");r.className="magicx-aia-footer-key",r.textContent="tab";let s=document.createElement("span");s.className="magicx-aia-footer-hint",s.textContent="to select",i.append(r,s);let o=document.createElement("a");o.className="aia-cluster magicx-aia-footer-brand-link",o.setAttribute("data-align","center"),o.href="https://ai-autocomplete.com",o.target="_blank",o.rel="noopener noreferrer",o.style.setProperty("--aia-cluster-gap","2px");let a=document.createElement("span");a.className="magicx-aia-footer-brand",a.textContent="AI";let d=document.createElement("span");return d.className="magicx-aia-footer-badge",d.textContent="Autocomplete",o.append(a,d),t.append(i,o),n.append(e,t),n}function Ie(n,e){let t=J(e.listboxId);return n.appendChild(t),{dropdown:t}}function le(n,e,t){Z(n.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,isActivePillSelected:e.isActivePillSelected,hasTabbedToHighlight:e.hasTabbedToHighlight,isInputEmpty:e.text.trim().length===0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function ee(n){let{input:e,segments:t,newParamId:i,editingParamId:r,placeholderText:s,isFocused:o}=n,a=t.length===0;e.dataset.aiaEmpty=a?"true":"false",a&&s?e.dataset.placeholder=s:delete e.dataset.placeholder;let d=t.map(x=>`${x.type}:${x.value}`).join("\0"),l=e.dataset.segKey??"",p=e.dataset.newParamId??"",c=e.dataset.editingParamId??"";if(d===l&&(i??"")===p&&(r??"")===c)return;let u=o?C(e):null;e.dataset.segKey=d,e.dataset.newParamId=i??"",e.dataset.editingParamId=r??"";let h=e.ownerDocument??document,b=h.createDocumentFragment(),g=0;for(let x of t)if(g+=x.value.length,x.type==="completed"){let m=h.createElement("strong");m.dataset.seg="completed",m.dataset.paramId=x.param.id;let f=x.param.id===i,y=x.param.id===r,v=["magicx-aia-segment","magicx-aia-segment--completed"];f&&v.push("magicx-aia-shimmer-revealed","magicx-aia-shimmer-sweep"),y&&v.push("magicx-aia-segment--editing"),m.className=v.join(" "),m.textContent=x.value,b.appendChild(m)}else b.appendChild(h.createTextNode(x.value));e.replaceChildren(b),e.dataset.aiaTextLength=String(g),u!=null&&P(e,Math.max(0,Math.min(u,g)))}var dt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function Oe(){let n=document.createElement("button");return n.type="button",n.className="magicx-aia-submit",n.setAttribute("aria-label","Submit"),n.setAttribute("data-aia-submit",""),n.innerHTML=dt,n}function ct(){let n=document.createElement("div");return n.setAttribute("contenteditable","plaintext-only"),n.contentEditable==="plaintext-only"}function De(n,e){let t=e.firstElementChild;if(!t){e.removeAttribute("data-aia-pill-wrapped");return}let i=t.getBoundingClientRect(),r=n.getBoundingClientRect();i.top>=r.bottom-2?e.setAttribute("data-aia-pill-wrapped",""):e.removeAttribute("data-aia-pill-wrapped")}function ke(n,e){let{listboxId:t}=e,i=J(t);n.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",n.appendChild(r);let s=document.createElement("div");s.className="magicx-aia-editor",s.setAttribute("data-aia-editor",""),r.appendChild(s);let o=document.createElement("div");o.className="magicx-aia-input",o.setAttribute("data-aia-input",""),o.setAttribute("contenteditable",ct()?"plaintext-only":"true"),o.setAttribute("role","combobox"),o.setAttribute("aria-autocomplete","list"),o.setAttribute("aria-haspopup","listbox"),o.setAttribute("aria-controls",t),o.setAttribute("aria-expanded","false"),o.setAttribute("spellcheck","true"),o.setAttribute("enterkeyhint","send"),s.appendChild(o);let a=document.createElement("span");a.className="magicx-aia-pill-list-container",a.setAttribute("data-aia-pill-list-container",""),s.appendChild(a);let d=null,l=null;e.submitButton===void 0?(d=Oe(),r.appendChild(d),l=d):e.submitButton!==null&&(l=e.submitButton,l.hasAttribute("data-aia-submit")||l.setAttribute("data-aia-submit",""),r.appendChild(l));let p=new AbortController,{signal:c}=p,u=!1,h=0,b=()=>{let m=L(o),y=m.length>0&&m[0]!==m[0].toUpperCase()?m[0].toUpperCase()+m.slice(1):m;e.handleChange(y)},g=()=>{let m=(o.ownerDocument??document).getSelection();if(!m||m.rangeCount===0)return null;let f=m.anchorNode;return!f||!o.contains(f)?null:(f.nodeType===Node.ELEMENT_NODE?f:f.parentElement)?.closest('strong[data-seg="completed"][data-param-id]')?.dataset.paramId??null};r.addEventListener("click",m=>{m.target?.closest("[data-aia-pill]")||o.focus()},{signal:c}),o.addEventListener("input",()=>{u||(h=performance.now(),b(),e.handleCaretAfterInput(C(o)))},{signal:c});let x=o.ownerDocument??document;if(x.addEventListener("selectionchange",()=>{let m=x.getSelection();if(!m||m.rangeCount===0||!o.contains(m.anchorNode))return;let f=g(),y=e.store.get().editingParam?.id??null;if(f&&f!==y){e.startEditingParam(f);return}performance.now()-h<50||e.handleCaretMove(C(o))},{signal:c}),o.addEventListener("compositionstart",()=>{u=!0},{signal:c}),o.addEventListener("compositionend",()=>{u=!1,b()},{signal:c}),o.addEventListener("beforeinput",m=>{let f=m,y=f.inputType;if(y==="insertParagraph"||y==="insertLineBreak"||y==="insertFromDrop"){m.preventDefault();return}if(y.startsWith("insert")||y.startsWith("delete")){let v=y.startsWith("delete")?"":f.data??"";e.replaceEditingRange(v)&&m.preventDefault()}},{signal:c}),o.addEventListener("paste",m=>{m.preventDefault();let f=(m.clipboardData?.getData("text/plain")??"").replace(/\r?\n/g," ");if(!f)return;let y=o.ownerDocument??document,v=y.getSelection();if(!v||v.rangeCount===0)return;let T=v.getRangeAt(0);if(!o.contains(T.startContainer))return;T.deleteContents();let A=y.createTextNode(f);T.insertNode(A),T.setStartAfter(A),T.collapse(!0),v.removeAllRanges(),v.addRange(T),b()},{signal:c}),o.addEventListener("keydown",m=>e.handleKeyDown(m),{signal:c}),o.addEventListener("focus",()=>e.store.set({isFocused:!0}),{signal:c}),o.addEventListener("blur",()=>e.store.set({isFocused:!1}),{signal:c}),l&&l.addEventListener("click",m=>{let f=e.store.get();if(!(!!f.text||f.completedParams.length>0)||!e.onSubmit)return;m.stopPropagation();let{rawQuery:v,completedParams:T}=S(f.text,f.completedParams);e.onSubmit({query:f.text.trim(),raw_query:v,completed_params:T}),e.afterSubmit?.()},{signal:c}),e.autoFocus!==!1&&o.focus(),typeof ResizeObserver<"u"){let m=new ResizeObserver(()=>De(o,a));m.observe(o),p.signal.addEventListener("abort",()=>m.disconnect(),{once:!0})}return{input:o,inlinePillContainer:a,dropdown:i,submitButton:d,abort:p}}function de(n,e,t){let{input:i,inlinePillContainer:r,dropdown:s,submitButton:o}=n,{pillPlacement:a,setActivePill:d,selectOption:l,store:p}=t;i.setAttribute("aria-expanded",String(e.isDropdownOpen));let c=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";if(c?i.setAttribute("aria-activedescendant",c):i.removeAttribute("aria-activedescendant"),o){let x=!!e.text||e.completedParams.length>0;o.disabled=!x}let u=i.dataset.newParamId??"",h=e.newParamId!==null&&e.newParamId!==u;if(ee({input:i,segments:e.segments,newParamId:e.newParamId,editingParamId:e.editingParam?.id??null,placeholderText:e.placeholderText,isFocused:e.isFocused}),a==="inline"){let x=e.isLoading&&!e.editingParam&&!e.inSelectionAnimation;x||e.actionableSuggestions.length>0?Y(r,e.actionableSuggestions,0,d,!1,x,e.isActivePillSelected):ae(r)}else ae(r);De(i,r),h?(i.focus(),P(i,e.caretOffset??e.text.length)):e.isFocused&&L(i)!==e.text&&P(i,e.text.length);let b=e.editingParam?{type:e.editingParam.suggestionType,text:e.editingParam.suggestionPlaceholder,required:!0,options:e.editingParam.options}:null,g=b??e.actionableSuggestions[0];Z(s,{suggestions:g?[{...g,options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,isLoading:e.isLoading&&!e.editingParam&&!e.inSelectionAnimation,listboxId:t.listboxId,pills:b?[b]:e.actionableSuggestions,showPills:a==="dropdown",isActivePillSelected:e.isActivePillSelected,hasTabbedToHighlight:e.hasTabbedToHighlight,isInputEmpty:e.text.trim().length===0,onSelect:l,onHighlight:x=>p.set({activeDropdownIndex:x}),onPillClick:d})}function Me(n,e){let t=n.actionableSuggestions[0];if(!t)return null;let i=n.filterBase,r=n.text.slice(0,i),s=r.length===0&&n.text.length===0,o=r.length===0&&n.text.length>0&&n.placeholderText.length>0&&n.placeholderText.toLowerCase().startsWith(n.text.toLowerCase());(s||o)&&n.placeholderText&&(r=`${n.placeholderText} `);let a=fe(r,e.text);a>0&&(r=r.slice(0,r.length-a));let d=r.length>0&&r[r.length-1]!==" ",l=`${r}${d?" ":""}${e.text} `,p=(s||o)&&l.length>0?l[0].toUpperCase()+l.slice(1):l,c=p.toLowerCase().lastIndexOf(e.text.toLowerCase()),u=c>=0?p.slice(c,c+e.text.length):e.text,h={id:crypto.randomUUID(),placeholder:"",type:t.type,text:u,kind:e.kind,suggestionType:t.type,suggestionPlaceholder:t.text,options:t.options??[],metadata:e.metadata},b=n.actionableSuggestions.length-1;return{patch:{text:p,filterBase:p.length,completedParams:[...n.completedParams,h],newParamId:h.id,caretOffset:p.length,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:b>0,inSelectionAnimation:!0},telemetry:{selectedOption:e.text,otherOptions:n.filteredOptions.filter(g=>g.text!==e.text).map(g=>g.text)},consumedSuggestion:t,remainingActionable:b}}function te(n){let e=n,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,s={...e,...r},o=e;e=s;for(let a of t)a(s,o)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}function Le(n,e){let t,i,r=s=>(s!==t&&(t=s,i=e(s)),i);return{get:()=>{let s=n.get();return{...s,...r(s)}},set:s=>{typeof s=="function"?n.set(o=>{let a={...o,...r(o)};return s(a)}):n.set(s)},peek:s=>{let o={...n.get(),...s};return{...o,...e(o)}},subscribe:s=>n.subscribe((o,a)=>{let d={...a,...r(a)},l={...o,...r(o)};s(l,d)})}}var ce=!1;function Re(){if(ce||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){ce=!0;return}ce=!0;let n=document.createElement("style");n.setAttribute("data-magicx-aia",""),n.textContent=pt,document.head.appendChild(n)}var pt=`@layer layout {
|
|
2
2
|
.aia-stack {
|
|
3
3
|
display: flex;
|
|
4
4
|
flex-direction: column;
|
|
@@ -57,9 +57,35 @@
|
|
|
57
57
|
@layer layout {
|
|
58
58
|
.aia-grid {
|
|
59
59
|
display: grid;
|
|
60
|
-
grid-template-columns: repeat(
|
|
60
|
+
grid-template-columns: repeat(
|
|
61
|
+
auto-fit,
|
|
62
|
+
minmax(min(var(--aia-grid-min), 100%), var(--aia-grid-max, 1fr))
|
|
63
|
+
);
|
|
61
64
|
gap: var(--aia-grid-gap, 0);
|
|
62
65
|
}
|
|
66
|
+
|
|
67
|
+
/* Scrollable variant \u2014 capped height with a styled thin scrollbar. Rows pack
|
|
68
|
+
from the top instead of stretching to fill the container. */
|
|
69
|
+
.aia-grid[data-scroll] {
|
|
70
|
+
grid-auto-rows: min-content;
|
|
71
|
+
align-content: start;
|
|
72
|
+
justify-content: start;
|
|
73
|
+
padding: var(--aia-grid-scroll-pad, 0);
|
|
74
|
+
max-height: var(--aia-grid-max-height, 192px);
|
|
75
|
+
overflow-y: auto;
|
|
76
|
+
scrollbar-width: thin;
|
|
77
|
+
scrollbar-color: var(--aia-scrollbar-thumb, rgba(255, 255, 255, 0.3)) transparent;
|
|
78
|
+
}
|
|
79
|
+
.aia-grid[data-scroll]::-webkit-scrollbar {
|
|
80
|
+
width: 6px;
|
|
81
|
+
}
|
|
82
|
+
.aia-grid[data-scroll]::-webkit-scrollbar-track {
|
|
83
|
+
background: transparent;
|
|
84
|
+
}
|
|
85
|
+
.aia-grid[data-scroll]::-webkit-scrollbar-thumb {
|
|
86
|
+
background: var(--aia-scrollbar-thumb, rgba(255, 255, 255, 0.3));
|
|
87
|
+
border-radius: 3px;
|
|
88
|
+
}
|
|
63
89
|
}
|
|
64
90
|
|
|
65
91
|
/* ===================================================================
|
|
@@ -79,14 +105,14 @@
|
|
|
79
105
|
|
|
80
106
|
/* --- Input wrapper --- */
|
|
81
107
|
.magicx-aia-input-wrapper {
|
|
82
|
-
padding:
|
|
83
|
-
border: 1px solid var(--aia-
|
|
84
|
-
border-radius:
|
|
85
|
-
background:
|
|
108
|
+
padding: 12px 10px;
|
|
109
|
+
border: 1px solid var(--aia-border, #b0b0b0);
|
|
110
|
+
border-radius: 24px;
|
|
111
|
+
background: var(--aia-surface, #ffffff);
|
|
86
112
|
overflow: hidden;
|
|
87
113
|
display: flex;
|
|
88
114
|
align-items: center;
|
|
89
|
-
gap:
|
|
115
|
+
gap: 12px;
|
|
90
116
|
}
|
|
91
117
|
|
|
92
118
|
/* --- Editor area (wraps the editable input + inline pill list sibling) --- */
|
|
@@ -94,10 +120,10 @@
|
|
|
94
120
|
position: relative;
|
|
95
121
|
flex: 1;
|
|
96
122
|
min-width: 0;
|
|
97
|
-
min-height:
|
|
98
|
-
line-height:
|
|
123
|
+
min-height: 19px;
|
|
124
|
+
line-height: 19px;
|
|
99
125
|
font-family: inherit;
|
|
100
|
-
font-size: var(--aia-written-text-font-size,
|
|
126
|
+
font-size: var(--aia-written-text-font-size, 14px);
|
|
101
127
|
white-space: pre-wrap;
|
|
102
128
|
word-break: break-word;
|
|
103
129
|
overflow-wrap: anywhere;
|
|
@@ -113,7 +139,7 @@
|
|
|
113
139
|
--aia-caret-color,
|
|
114
140
|
var(--aia-written-text-color, var(--aia-color-text-default, #fff))
|
|
115
141
|
);
|
|
116
|
-
font-weight:
|
|
142
|
+
font-weight: 300;
|
|
117
143
|
/* Align the text's inline box with the pill list (also vertical-align: middle)
|
|
118
144
|
so they share a vertical center when pills stretch the line box to ~36px. */
|
|
119
145
|
vertical-align: middle;
|
|
@@ -130,7 +156,7 @@
|
|
|
130
156
|
/* Completed params render as inline bold runs. Specificity stays at (0,2,0)
|
|
131
157
|
so consumers can override with \`.magicx-aia-input strong\`. */
|
|
132
158
|
:where(.magicx-aia-input) strong {
|
|
133
|
-
font-weight:
|
|
159
|
+
font-weight: 600;
|
|
134
160
|
letter-spacing: -0.01em;
|
|
135
161
|
}
|
|
136
162
|
|
|
@@ -193,8 +219,8 @@
|
|
|
193
219
|
/* --- Submit button --- */
|
|
194
220
|
.magicx-aia-submit {
|
|
195
221
|
flex-shrink: 0;
|
|
196
|
-
width:
|
|
197
|
-
height:
|
|
222
|
+
width: 32px;
|
|
223
|
+
height: 32px;
|
|
198
224
|
border-radius: 50%;
|
|
199
225
|
border: none;
|
|
200
226
|
background: var(--aia-submit-bg, var(--aia-color-text-default, #fff));
|
|
@@ -221,12 +247,25 @@
|
|
|
221
247
|
margin-top: 6px;
|
|
222
248
|
display: flex;
|
|
223
249
|
flex-direction: column;
|
|
250
|
+
box-sizing: border-box;
|
|
251
|
+
padding: 4px;
|
|
224
252
|
overflow: hidden;
|
|
225
253
|
container-type: inline-size;
|
|
226
254
|
z-index: 10;
|
|
227
255
|
opacity: 0;
|
|
228
256
|
pointer-events: none;
|
|
229
257
|
transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
258
|
+
/* Solid surface is the default (matches the Figma components). Opt into the
|
|
259
|
+
frosted-glass look with data-aia-surface="glass". */
|
|
260
|
+
background: var(--aia-surface, #ffffff);
|
|
261
|
+
border: 1px solid var(--aia-dropdown-border, #e5e7eb);
|
|
262
|
+
border-radius: 25px;
|
|
263
|
+
box-shadow: var(--aia-dropdown-shadow, 0 8px 12px rgba(0, 0, 0, 0.12));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.magicx-aia-dropdown[data-aia-surface="glass"] {
|
|
267
|
+
background: transparent;
|
|
268
|
+
border-color: transparent;
|
|
230
269
|
box-shadow:
|
|
231
270
|
hsla(0, 0%, 100%, 1) -3.2px -3.2px 3.2px -3.2px inset,
|
|
232
271
|
hsla(0, 0%, 100%, 1) 6.4px 6.4px 1.6px -8px inset,
|
|
@@ -239,7 +278,6 @@
|
|
|
239
278
|
inset 0 0 30px 5px hsla(0, 0%, 0%, 0.05),
|
|
240
279
|
hsla(0, 0%, 0%, 0.08) 0px 0px 30px 2px;
|
|
241
280
|
backdrop-filter: blur(30px);
|
|
242
|
-
border-radius: 28px;
|
|
243
281
|
}
|
|
244
282
|
|
|
245
283
|
.magicx-aia-dropdown--visible {
|
|
@@ -247,9 +285,11 @@
|
|
|
247
285
|
pointer-events: auto;
|
|
248
286
|
}
|
|
249
287
|
|
|
250
|
-
/* --- Pill bar (inside dropdown) ---
|
|
288
|
+
/* --- Pill bar (inside dropdown) ---
|
|
289
|
+
The dropdown owns a uniform 4px pad; each section adds its own 7px/8px inset
|
|
290
|
+
(matches the Figma PillList). */
|
|
251
291
|
.magicx-aia-pill-bar {
|
|
252
|
-
padding:
|
|
292
|
+
padding: 7px 8px;
|
|
253
293
|
}
|
|
254
294
|
|
|
255
295
|
/* --- Fallback loading skeleton bars (only when no cached options) --- */
|
|
@@ -257,12 +297,12 @@
|
|
|
257
297
|
display: flex;
|
|
258
298
|
flex-direction: column;
|
|
259
299
|
gap: 20px;
|
|
260
|
-
padding:
|
|
300
|
+
padding: 7px 8px;
|
|
261
301
|
}
|
|
262
302
|
|
|
263
303
|
.magicx-aia-skeleton-bar {
|
|
264
304
|
display: block;
|
|
265
|
-
height:
|
|
305
|
+
height: 14px;
|
|
266
306
|
border-radius: 999px;
|
|
267
307
|
background: var(--aia-skeleton-bg, var(--aia-pill-bg, rgba(189, 189, 189, 0.51)));
|
|
268
308
|
opacity: 0.5;
|
|
@@ -287,6 +327,73 @@
|
|
|
287
327
|
}
|
|
288
328
|
}
|
|
289
329
|
|
|
330
|
+
/* --- Footer (keyboard hint + AI-Autocomplete branding) ---
|
|
331
|
+
The footer insets its own 15px horizontally (the dropdown only pads
|
|
332
|
+
vertically), so the divider spans the full footer width yet still stays clear
|
|
333
|
+
of the dropdown's rounded edges. */
|
|
334
|
+
.magicx-aia-footer {
|
|
335
|
+
display: flex;
|
|
336
|
+
flex-direction: column;
|
|
337
|
+
gap: 8px;
|
|
338
|
+
padding: 7px 8px;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
.magicx-aia-footer-divider {
|
|
342
|
+
border-top: 0.5px solid var(--aia-footer-divider, rgba(176, 176, 176, 0.4));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
.magicx-aia-footer-key {
|
|
346
|
+
display: inline-flex;
|
|
347
|
+
align-items: center;
|
|
348
|
+
justify-content: center;
|
|
349
|
+
min-width: 30px;
|
|
350
|
+
height: 22px;
|
|
351
|
+
padding: 2px 6px;
|
|
352
|
+
border: 0.5px solid var(--aia-footer-hint-color, #505050);
|
|
353
|
+
border-radius: 5px;
|
|
354
|
+
font-family: inherit;
|
|
355
|
+
font-size: 11px;
|
|
356
|
+
line-height: 18px;
|
|
357
|
+
color: var(--aia-footer-hint-color, #505050);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.magicx-aia-footer-hint {
|
|
361
|
+
font-family: inherit;
|
|
362
|
+
font-size: 11px;
|
|
363
|
+
line-height: 18px;
|
|
364
|
+
color: var(--aia-footer-hint-color, #505050);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
.magicx-aia-footer-brand-link {
|
|
368
|
+
text-decoration: none;
|
|
369
|
+
cursor: pointer;
|
|
370
|
+
transition: opacity 150ms ease-out;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.magicx-aia-footer-brand-link:hover {
|
|
374
|
+
opacity: 0.7;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
.magicx-aia-footer-brand {
|
|
378
|
+
font-family: inherit;
|
|
379
|
+
font-size: 10px;
|
|
380
|
+
line-height: 18px;
|
|
381
|
+
color: var(--aia-footer-brand-color, #b0b0b0);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.magicx-aia-footer-badge {
|
|
385
|
+
display: inline-flex;
|
|
386
|
+
align-items: center;
|
|
387
|
+
height: 23px;
|
|
388
|
+
padding: 2.5px 5.5px;
|
|
389
|
+
border: 0.5px solid var(--aia-footer-badge-border, rgba(189, 189, 189, 0.51));
|
|
390
|
+
border-radius: 999px;
|
|
391
|
+
font-family: inherit;
|
|
392
|
+
font-size: 10px;
|
|
393
|
+
line-height: 18px;
|
|
394
|
+
color: var(--aia-footer-brand-color, #b0b0b0);
|
|
395
|
+
}
|
|
396
|
+
|
|
290
397
|
/* --- Loading mask on real options (preserves layout, hides text) --- */
|
|
291
398
|
.magicx-aia-option[data-aia-loading] {
|
|
292
399
|
cursor: default;
|
|
@@ -306,6 +413,12 @@
|
|
|
306
413
|
box-decoration-break: clone;
|
|
307
414
|
}
|
|
308
415
|
|
|
416
|
+
.magicx-aia-option-tag {
|
|
417
|
+
font-size: 11px;
|
|
418
|
+
margin-left: 6px;
|
|
419
|
+
opacity: 0.5;
|
|
420
|
+
}
|
|
421
|
+
|
|
309
422
|
.magicx-aia-option[data-aia-loading] .magicx-aia-option-tag {
|
|
310
423
|
display: none;
|
|
311
424
|
}
|
|
@@ -326,7 +439,7 @@
|
|
|
326
439
|
z-index: 1;
|
|
327
440
|
pointer-events: auto;
|
|
328
441
|
display: inline-flex;
|
|
329
|
-
gap:
|
|
442
|
+
gap: 7px;
|
|
330
443
|
align-items: center;
|
|
331
444
|
vertical-align: middle;
|
|
332
445
|
}
|
|
@@ -336,49 +449,29 @@
|
|
|
336
449
|
display: inline-flex;
|
|
337
450
|
align-items: center;
|
|
338
451
|
justify-content: center;
|
|
339
|
-
|
|
340
|
-
padding: 13px 13px;
|
|
452
|
+
padding: 7px 8px;
|
|
341
453
|
border: none;
|
|
342
454
|
border-radius: 999px;
|
|
343
455
|
background: rgba(49, 50, 85, 0.25);
|
|
344
456
|
background: color-mix(
|
|
345
457
|
in srgb,
|
|
346
|
-
var(--aia-pill-bg, var(--aia-color-background-supportive, #313255))
|
|
458
|
+
var(--aia-pill-bg, var(--aia-color-background-supportive, #313255)) 30%,
|
|
347
459
|
transparent
|
|
348
460
|
);
|
|
349
461
|
color: var(--aia-pill-color, var(--aia-color-text-muted, #c1c4cb));
|
|
350
462
|
font-family: inherit;
|
|
351
|
-
font-size: var(--aia-pill-font-size,
|
|
352
|
-
|
|
463
|
+
font-size: var(--aia-pill-font-size, 14px);
|
|
464
|
+
font-weight: 500;
|
|
465
|
+
line-height: normal;
|
|
353
466
|
cursor: pointer;
|
|
354
467
|
white-space: nowrap;
|
|
355
468
|
animation: magicx-aia-fadeIn 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
356
|
-
box-shadow:
|
|
357
|
-
hsla(0, 0%, 100%, 1) -3.2px -3.2px 3.2px -3.2px inset,
|
|
358
|
-
hsla(0, 0%, 100%, 1) 6.4px 6.4px 1.6px -8px inset,
|
|
359
|
-
var(--aia-dropdown-bg, transparent) -6.4px 6.4px 1.6px -8px inset,
|
|
360
|
-
var(--aia-dropdown-bg, transparent) 6.4px -6.4px 1.6px -8px inset,
|
|
361
|
-
hsla(0, 0%, 100%, 0.15) -1.6px 0px 0px -1.6px inset,
|
|
362
|
-
hsla(0, 0%, 100%, 0.15) 0px -1.6px 0px -1.6px inset,
|
|
363
|
-
hsla(0, 0%, 100%, 0.3) 0px 1.6px 0px 0px inset,
|
|
364
|
-
hsla(0, 0%, 100%, 0.3) 1.6px 0px 0px 0px inset,
|
|
365
|
-
inset 0 0 30px 5px hsla(0, 0%, 0%, 0.05),
|
|
366
|
-
hsla(0, 0%, 0%, 0.08) 0px 0px 30px 2px;
|
|
367
|
-
backdrop-filter: blur(30px);
|
|
368
469
|
}
|
|
369
470
|
|
|
370
471
|
.magicx-aia-pill--rounded {
|
|
371
472
|
border-radius: 999px;
|
|
372
473
|
}
|
|
373
474
|
|
|
374
|
-
.magicx-aia-pill:hover {
|
|
375
|
-
filter: brightness(1.2);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
.magicx-aia-pill--active {
|
|
379
|
-
outline: 1px solid #5a5b8a;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
475
|
/* Real pill rendered as a skeleton (mirrored from cached pills during loading).
|
|
383
476
|
Preserves the pill's full box so width/height match the previous state. */
|
|
384
477
|
.magicx-aia-pill[data-aia-loading] {
|
|
@@ -420,39 +513,10 @@
|
|
|
420
513
|
}
|
|
421
514
|
}
|
|
422
515
|
|
|
423
|
-
/* --- Options grid ---
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
/* Pack rows from the top instead of stretching to fill the grid container. */
|
|
428
|
-
grid-auto-rows: min-content;
|
|
429
|
-
align-content: start;
|
|
430
|
-
justify-content: start;
|
|
431
|
-
padding: 8px 8px;
|
|
432
|
-
max-height: 192px;
|
|
433
|
-
overflow-y: auto;
|
|
434
|
-
scrollbar-width: thin;
|
|
435
|
-
scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
@container (min-width: 516px) {
|
|
439
|
-
.magicx-aia-grid {
|
|
440
|
-
grid-template-columns: repeat(2, minmax(0, 250px));
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
.magicx-aia-grid::-webkit-scrollbar {
|
|
445
|
-
width: 6px;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
.magicx-aia-grid::-webkit-scrollbar-track {
|
|
449
|
-
background: transparent;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
.magicx-aia-grid::-webkit-scrollbar-thumb {
|
|
453
|
-
background: rgba(255, 255, 255, 0.3);
|
|
454
|
-
border-radius: 3px;
|
|
455
|
-
}
|
|
516
|
+
/* --- Options grid ---
|
|
517
|
+
Layout (auto-fit columns, scroll, scrollbar styling) is provided by the
|
|
518
|
+
\`.aia-grid\` / \`.aia-grid[data-scroll]\` layout primitive (see layout/Grid.css).
|
|
519
|
+
The \`.magicx-aia-grid\` class remains on the element as a public override hook. */
|
|
456
520
|
|
|
457
521
|
/* --- Option item --- */
|
|
458
522
|
.magicx-aia-option {
|
|
@@ -463,14 +527,16 @@
|
|
|
463
527
|
the same baseline at the top edge of the cell. */
|
|
464
528
|
align-items: flex-start;
|
|
465
529
|
font-family: inherit;
|
|
466
|
-
font-size: var(--aia-option-font-size,
|
|
467
|
-
font-weight:
|
|
468
|
-
line-height:
|
|
530
|
+
font-size: var(--aia-option-font-size, 14px);
|
|
531
|
+
font-weight: 300;
|
|
532
|
+
line-height: 18px;
|
|
469
533
|
color: var(--aia-option-color, var(--aia-color-text-muted, #c1c4cb));
|
|
470
534
|
white-space: normal;
|
|
471
535
|
word-break: break-word;
|
|
472
|
-
|
|
473
|
-
|
|
536
|
+
/* 8px radius on the highlighted fill (--aia-option-bg), matching the Figma
|
|
537
|
+
SuggestionItem selection. The 7px/8px inset is the item's own padding. */
|
|
538
|
+
border-radius: 8px;
|
|
539
|
+
padding: 7px 8px;
|
|
474
540
|
animation: magicx-aia-optionFadeIn 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
475
541
|
}
|
|
476
542
|
|
|
@@ -500,12 +566,7 @@
|
|
|
500
566
|
.magicx-aia-option--highlighted {
|
|
501
567
|
color: var(--aia-option-color-selected, var(--aia-color-text-default, #fff));
|
|
502
568
|
background: var(--aia-option-bg, transparent);
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
.magicx-aia-option-tag {
|
|
506
|
-
font-size: 11px;
|
|
507
|
-
margin-left: 6px;
|
|
508
|
-
opacity: 0.5;
|
|
569
|
+
font-weight: 700;
|
|
509
570
|
}
|
|
510
571
|
|
|
511
572
|
.magicx-aia-option--pressed {
|
|
@@ -819,17 +880,21 @@
|
|
|
819
880
|
/* Light mode defaults (base) */
|
|
820
881
|
:where(.magicx-aia),
|
|
821
882
|
:where(.magicx-aia[data-mode="light"]) {
|
|
883
|
+
--aia-surface: #ffffff;
|
|
884
|
+
--aia-border: #b0b0b0;
|
|
885
|
+
--aia-dropdown-border: #e5e7eb;
|
|
886
|
+
--aia-dropdown-shadow: 0 8px 12px rgba(0, 0, 0, 0.12);
|
|
822
887
|
--aia-pill-bg: #bdbdbd;
|
|
823
|
-
--aia-pill-color: #
|
|
824
|
-
--aia-pill-font-size:
|
|
888
|
+
--aia-pill-color: #333539;
|
|
889
|
+
--aia-pill-font-size: 14px;
|
|
825
890
|
|
|
826
|
-
--aia-option-bg:
|
|
827
|
-
--aia-option-color: #
|
|
891
|
+
--aia-option-bg: #eef2ff;
|
|
892
|
+
--aia-option-color: #505050;
|
|
828
893
|
--aia-option-color-selected: #000000;
|
|
829
|
-
--aia-option-font-size:
|
|
894
|
+
--aia-option-font-size: 14px;
|
|
830
895
|
|
|
831
896
|
--aia-written-text-color: #000000;
|
|
832
|
-
--aia-written-text-font-size:
|
|
897
|
+
--aia-written-text-font-size: 14px;
|
|
833
898
|
--aia-caret-color: var(--aia-written-text-color, #000000);
|
|
834
899
|
|
|
835
900
|
--aia-submit-bg: #000000;
|
|
@@ -841,21 +906,30 @@
|
|
|
841
906
|
|
|
842
907
|
--aia-streak-rgb: 99, 102, 241;
|
|
843
908
|
--aia-streak-glass-bg: rgba(99, 102, 241, 0.1);
|
|
909
|
+
|
|
910
|
+
--aia-footer-divider: rgba(176, 176, 176, 0.4);
|
|
911
|
+
--aia-footer-hint-color: #505050;
|
|
912
|
+
--aia-footer-brand-color: #b0b0b0;
|
|
913
|
+
--aia-footer-badge-border: rgba(189, 189, 189, 0.51);
|
|
844
914
|
}
|
|
845
915
|
|
|
846
916
|
/* Dark mode defaults */
|
|
847
917
|
:where(.magicx-aia[data-mode="dark"]) {
|
|
918
|
+
--aia-surface: #000000;
|
|
919
|
+
--aia-border: #505050;
|
|
920
|
+
--aia-dropdown-border: #484848;
|
|
921
|
+
--aia-dropdown-shadow: 0 8px 12px rgba(0, 0, 0, 0.12);
|
|
848
922
|
--aia-pill-bg: #bdbdbd;
|
|
849
|
-
--aia-pill-color: #
|
|
850
|
-
--aia-pill-font-size:
|
|
923
|
+
--aia-pill-color: #b0b0b0;
|
|
924
|
+
--aia-pill-font-size: 14px;
|
|
851
925
|
|
|
852
926
|
--aia-option-bg: transparent;
|
|
853
927
|
--aia-option-color: #b0b0b0;
|
|
854
928
|
--aia-option-color-selected: #ffffff;
|
|
855
|
-
--aia-option-font-size:
|
|
929
|
+
--aia-option-font-size: 14px;
|
|
856
930
|
|
|
857
931
|
--aia-written-text-color: #ffffff;
|
|
858
|
-
--aia-written-text-font-size:
|
|
932
|
+
--aia-written-text-font-size: 14px;
|
|
859
933
|
--aia-caret-color: var(--aia-written-text-color, #ffffff);
|
|
860
934
|
|
|
861
935
|
--aia-submit-bg: #ffffff;
|
|
@@ -867,19 +941,32 @@
|
|
|
867
941
|
|
|
868
942
|
--aia-streak-rgb: 255, 255, 255;
|
|
869
943
|
--aia-streak-glass-bg: rgba(255, 255, 255, 0.1);
|
|
944
|
+
|
|
945
|
+
--aia-footer-divider: rgba(255, 255, 255, 0.15);
|
|
946
|
+
--aia-footer-hint-color: #b0b0b0;
|
|
947
|
+
--aia-footer-brand-color: #505050;
|
|
948
|
+
--aia-footer-badge-border: #505050;
|
|
870
949
|
}
|
|
871
950
|
|
|
872
|
-
/* optionsPosition: dropdown above the input
|
|
951
|
+
/* optionsPosition: dropdown above the input. The sections live inside the
|
|
952
|
+
dropdown's .aia-stack, so the reversal targets the stack (not the dropdown,
|
|
953
|
+
whose only child is the stack). */
|
|
873
954
|
:where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] {
|
|
874
955
|
top: auto;
|
|
875
956
|
bottom: 100%;
|
|
876
957
|
margin-top: 0;
|
|
877
958
|
margin-bottom: 6px;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
:where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] .aia-stack {
|
|
878
962
|
flex-direction: column-reverse;
|
|
879
963
|
}
|
|
880
964
|
|
|
881
|
-
|
|
882
|
-
|
|
965
|
+
/* The footer sits at the top when the dropdown is above, so flip its own
|
|
966
|
+
internal stack too \u2014 the divider should sit BELOW the hint/branding row
|
|
967
|
+
(between the footer and the options beneath it), not above it. */
|
|
968
|
+
:where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] .magicx-aia-footer {
|
|
969
|
+
flex-direction: column-reverse;
|
|
883
970
|
}
|
|
884
971
|
|
|
885
972
|
/* Disable all animations when data-animations="off" */
|
|
@@ -889,5 +976,5 @@
|
|
|
889
976
|
animation-duration: 0s !important;
|
|
890
977
|
transition-duration: 0s !important;
|
|
891
978
|
}
|
|
892
|
-
`;var ee=class{constructor(){this.listeners={}}on(e,t){let i=(...s)=>t(...s),r=this.listeners[e];return r||(r=new Set,this.listeners[e]=r),r.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...t){let i=this.listeners[e];if(i)for(let r of i)r(...t)}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var te=class{constructor(){this.timers=new Map}schedule(e,t,i){this.clear(e);let r=setTimeout(()=>{this.timers.delete(e),t()},i);this.timers.set(e,r)}clear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var D=class{constructor(e,t="auto",i){this.container=e;this.mode=t;this.onResolve=i;this.mediaQuery=null;this.onSystemChange=e=>{this.setResolved(e.matches?"dark":"light")};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.setResolved(this.mediaQuery.matches?"dark":"light")):this.setResolved(this.mode)}setResolved(e){this.container.dataset.mode=e,this.onResolve?.(e)}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function at(n){return(n??R).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function lt(n){return M(n)?`Bearer ${await _(n).getToken()}`:F(n)}async function Le(n){try{let e=at(n.apiConfig?.endpoint),t=N(n.apiConfig),i=await lt(n.apiConfig);i&&(t.Authorization=i);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var dt="newParam",ke="suggestionRemoval",ct="selectionAnimation",pt=650,ut=0;function mt(){return`:ac-${++ut}:`}var Re=500;function _e(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1}}var ne=class{constructor(e,t={}){this.inputStore=Z(_e());this._listboxId=mt();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new te;this.emitter=new ee;this.sessionId=crypto.randomUUID();this.emitSubmit=e=>this.emitter.emit("submit",e);this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",this.store=De(this.inputStore,i=>Pe(i,this.opts)),t.onSubmit&&this.emitter.on("submit",t.onSubmit),t.onError&&this.emitter.on("error",t.onError),t.onChange&&this.emitter.on("change",t.onChange),t.onParamsChange&&this.emitter.on("paramsChange",t.onParamsChange),t.onStateChange&&this.emitter.on("stateChange",t.onStateChange),t.onFocus&&this.emitter.on("focus",t.onFocus),t.onBlur&&this.emitter.on("blur",t.onBlur),t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new W(this.store,{onPillSelected:({rawQuery:i,selectedPill:r,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:i,selected_pill:r,other_pills:s})}}),this.reEdit=new j({store:this.store,scheduleSetCursor:i=>this.scheduleSetCursor(i),fireTelemetry:(i,r)=>this.fireTelemetry(i,r),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer()}),this.fetchController=new H(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,{onAutoMatch:({active:i,matched:r,rawQuery:s})=>{this.fireTelemetry("option",{raw_query:s,selected_option:r.text,other_options:(i.options??[]).filter(o=>o.text!==r.text).map(o=>o.text)})}}),this.keyboardController=new q(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:i=>this.selectOption(i),removeParamAtCaret:i=>this.removeParamAtCaret(i),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.emitter.emit("change",i.text),i.completedParams!==r.completedParams&&this.emitter.emit("paramsChange",i.completedParams),i.isFocused!==r.isFocused&&(i.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",i)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.renderMode!=="headless"&&(Me(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let e=this.store.get().isFocused;this.store.set({..._e(),isFocused:e,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let t=this.store.get().text.length;this.store.set({caretOffset:t,isFocused:!0}),this.scheduleSetCursor(t)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:i,completedParams:r}=t,s=0;for(let o=0;o<r.length;o++){let a=r[o],l=i.indexOf(a.text,s);if(l===-1)continue;let d=l,p=l+a.text.length;if(e>d&&e<=p){let c=U(i,e),m=i.slice(0,c)+i.slice(e),b=r.filter((g,h)=>h!==o);return this.store.set(g=>({text:m,filterBase:Math.min(g.filterBase,m.length),completedParams:b,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(c),!0}s=p}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?(t.input.focus(),P(t.input,e)):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){this.reEdit.start(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.store.subscribe(t=>e(t))}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){return this.emitter.on(e,t)}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.reEdit.selectOption(e);return}let i=Oe(t,e);if(i&&(this.fireTelemetry("option",{raw_query:S(t.text,t.completedParams).rawQuery,selected_option:i.telemetry.selectedOption,other_options:i.telemetry.otherOptions}),this.store.set(i.patch),this.startSelectionAnimationTimer(),this.timers.clear(ke),i.remainingActionable>0)){let r=i.consumedSuggestion;this.timers.schedule(ke,()=>{this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==r)}))},Re)}}startSelectionAnimationTimer(){this.timers.schedule(ct,()=>this.store.set({inSelectionAnimation:!1}),Re)}fireTelemetry(e,t){let i=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");Le({source:i,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new D(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=Ae(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&ae(this.domRefs,this.store.get(),t)}),ae(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Ee(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&se(this.dropdownRefs,this.store.get(),e)}),se(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&this.timers.schedule(dt,()=>this.store.set({newParamId:null}),pt)}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=ve(e,t.completedParams);r.length>0&&this.store.set({completedParams:i}),this.maybePromoteExactMatch(e)}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(a=>a.id===e.editingParam?.id))return;let t=e.caretOffset??e.editingAnchor,i=e.text.slice(e.editingAnchor,t);if(E(e.editingParam.options,i).some(a=>a.is_tappable))return;this.reEdit.exit();let{rawQuery:s,completedParams:o}=S(e.text,e.completedParams);this.fetchController.doFetch(s,o)}maybePromoteExactMatch(e){let t=this.store.get(),i=G({mode:"fresh",text:e,completedParams:t.completedParams,suggestions:t.suggestions,filterBase:t.filterBase,filterInProgress:t.filterInProgress});i&&this.store.set(i.patch)}};0&&(module.exports={AIAutocomplete,ModeController,buildQuery,createStore,cursorIsAtEnd,extractPlainText,getCursorOffset,plainTextLength,previousGraphemeBoundary,renderEditableContent,setCursorOffset});
|
|
979
|
+
`;var ne=class{constructor(){this.listeners={}}on(e,t){let i=(...s)=>t(...s),r=this.listeners[e];return r||(r=new Set,this.listeners[e]=r),r.add(i),()=>{this.listeners[e]?.delete(i)}}emit(e,...t){let i=this.listeners[e];if(i)for(let r of i)r(...t)}hasListeners(e){return(this.listeners[e]?.size??0)>0}clear(){this.listeners={}}};var ie=class{constructor(){this.timers=new Map}schedule(e,t,i){this.clear(e);let r=setTimeout(()=>{this.timers.delete(e),t()},i);this.timers.set(e,r)}clear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}clearAll(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear()}};var k=class{constructor(e,t="auto",i){this.container=e;this.mode=t;this.onResolve=i;this.mediaQuery=null;this.onSystemChange=e=>{this.setResolved(e.matches?"dark":"light")};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.setResolved(this.mediaQuery.matches?"dark":"light")):this.setResolved(this.mode)}setResolved(e){this.container.dataset.mode=e,this.onResolve?.(e)}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function ut(n){return(n??N).replace(/\/suggest(\?|#|$)/,"/telemetry/events$1")}async function mt(n){return M(n)?`Bearer ${await _(n).getToken()}`:F(n)}async function Ne(n){try{let e=ut(n.apiConfig?.endpoint),t=H(n.apiConfig),i=await mt(n.apiConfig);i&&(t.Authorization=i);let r=JSON.stringify({source:n.source,session_id:n.sessionId,type:n.type,at:new Date().toISOString(),query_data:n.queryData});await fetch(e,{method:"POST",headers:t,body:r})}catch{}}var gt="newParam",_e="suggestionRemoval",ft="selectionAnimation",ht=650,bt=0;function xt(){return`:ac-${++bt}:`}var He=500;function Fe(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,editingParam:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,hasTabbedToHighlight:!1}}var re=class{constructor(e,t={}){this.inputStore=te(Fe());this._listboxId=xt();this.modeController=null;this.unsubscribers=[];this.domRefs=null;this.dropdownRefs=null;this.timers=new ie;this.emitter=new ne;this.sessionId=crypto.randomUUID();this.emitSubmit=e=>this.emitter.emit("submit",e);this.emitError=e=>this.emitter.emit("error",e);this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",this.store=Le(this.inputStore,i=>Te(i,this.opts)),t.onSubmit&&this.emitter.on("submit",t.onSubmit),t.onError&&this.emitter.on("error",t.onError),t.onChange&&this.emitter.on("change",t.onChange),t.onParamsChange&&this.emitter.on("paramsChange",t.onParamsChange),t.onStateChange&&this.emitter.on("stateChange",t.onStateChange),t.onFocus&&this.emitter.on("focus",t.onFocus),t.onBlur&&this.emitter.on("blur",t.onBlur),t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new W(this.store,{onPillSelected:({rawQuery:i,selectedPill:r,otherPills:s})=>{this.fireTelemetry("pill",{raw_query:i,selected_pill:r,other_pills:s})}}),this.reEdit=new V({store:this.store,scheduleSetCursor:i=>this.scheduleSetCursor(i),fireTelemetry:(i,r)=>this.fireTelemetry(i,r),startSelectionAnimationTimer:()=>this.startSelectionAnimationTimer()}),this.fetchController=new B(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.emitter.hasListeners("error")?this.emitError:void 0,()=>this.sessionId,{onAutoMatch:({active:i,matched:r,rawQuery:s})=>{this.fireTelemetry("option",{raw_query:s,selected_option:r.text,other_options:(i.options??[]).filter(o=>o.text!==r.text).map(o=>o.text)})}}),this.keyboardController=new G(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.emitter.hasListeners("submit")?this.emitSubmit:void 0,getOptionsPosition:()=>this.opts.optionsPosition??"below",afterSubmit:this.renderMode==="full"?()=>this.reset():void 0,selectOption:i=>this.selectOption(i),removeParamAtCaret:i=>this.removeParamAtCaret(i),exitEditMode:()=>this.exitEditMode()}),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.emitter.emit("change",i.text),i.completedParams!==r.completedParams&&this.emitter.emit("paramsChange",i.completedParams),i.isFocused!==r.isFocused&&(i.isFocused?this.emitter.emit("focus"):this.emitter.emit("blur")),this.emitter.emit("stateChange",i)})),this.unsubscribers.push(this.store.subscribe(()=>this.maybeExitReEditOnNoMatch())),this.renderMode!=="headless"&&(Re(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.input.focus()}blur(){this.domRefs?.input.blur()}reset(){let e=this.store.get().isFocused;this.store.set({...Fe(),isFocused:e,skipNextFetch:!0}),this.sessionId=crypto.randomUUID(),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.timers.clearAll(),this.emitter.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs?.abort.abort(),this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e);let t=this.store.get().text.length;this.store.set({caretOffset:t,isFocused:!0}),this.scheduleSetCursor(t)}removeLastParam(){this.pillsController.removeLastParam()}removeParamAtCaret(e){let t=this.store.get(),{text:i,completedParams:r}=t,s=0;for(let o=0;o<r.length;o++){let a=r[o],d=i.indexOf(a.text,s);if(d===-1)continue;let l=d,p=d+a.text.length;if(e>l&&e<=p){let c=U(i,e),u=i.slice(0,c)+i.slice(e),h=r.filter((b,g)=>g!==o);return this.store.set(b=>({text:u,filterBase:Math.min(b.filterBase,u.length),completedParams:h,pillTapped:!1,activeDropdownIndex:-1})),this.scheduleSetCursor(c),!0}s=p}return!1}scheduleSetCursor(e){queueMicrotask(()=>{let t=this.domRefs;t?(t.input.focus(),P(t.input,e)):this.opts.setCursor?.(e)})}clearNewParamId(){this.store.set({newParamId:null})}startEditingParam(e){this.reEdit.start(e)}replaceEditingRange(e){return this.reEdit.replaceRange(e)}exitEditMode(){this.reEdit.exit()}handleCaretAfterInput(e){this.reEdit.caretAfterInput(e)}handleCaretMove(e){this.reEdit.caretMove(e)}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}setFocused(e){this.store.get().isFocused!==e&&this.store.set({isFocused:e})}subscribe(e){return this.store.subscribe(t=>e(t))}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){return this.emitter.on(e,t)}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),(e.dropdownTrigger!==void 0||e.closeDropdownOnBlur!==void 0||e.showNonTappableOptions!==void 0)&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get();if(t.editingParam&&t.editingAnchor!=null&&t.editingTail!=null){this.reEdit.selectOption(e);return}let i=Me(t,e);if(i&&(this.fireTelemetry("option",{raw_query:S(t.text,t.completedParams).rawQuery,selected_option:i.telemetry.selectedOption,other_options:i.telemetry.otherOptions}),this.store.set(i.patch),this.startSelectionAnimationTimer(),this.timers.clear(_e),i.remainingActionable>0)){let r=i.consumedSuggestion;this.timers.schedule(_e,()=>{this.store.set(s=>({suggestions:s.suggestions.filter(o=>o!==r)}))},He)}}startSelectionAnimationTimer(){this.timers.schedule(ft,()=>this.store.set({inSelectionAnimation:!1}),He)}fireTelemetry(e,t){let i=this.opts.source??(this.renderMode==="full"?"full-sdk":"headless-sdk");Ne({source:i,sessionId:this.sessionId,type:e,queryData:t,apiConfig:this.opts.apiConfig})}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new k(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.emitter.hasListeners("submit")?e.emitSubmit:void 0},afterSubmit:()=>e.reset(),submitButton:this.opts.submitButton,autoFocus:this.opts.autoFocus??!0,selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i),startEditingParam:i=>this.startEditingParam(i),handleCaretAfterInput:i=>this.handleCaretAfterInput(i),handleCaretMove:i=>this.handleCaretMove(i),replaceEditingRange:i=>this.replaceEditingRange(i)};this.domRefs=ke(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&de(this.domRefs,this.store.get(),t)}),de(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Ie(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&le(this.dropdownRefs,this.store.get(),e)}),le(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&this.timers.schedule(gt,()=>this.store.set({newParamId:null}),ht)}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=Se(e,t.completedParams);r.length>0&&this.store.set({completedParams:i}),this.maybePromoteExactMatch(e)}maybeExitReEditOnNoMatch(){let e=this.store.get();if(!e.editingParam||e.editingAnchor==null||e.completedParams.some(a=>a.id===e.editingParam?.id))return;let t=e.caretOffset??e.editingAnchor,i=e.text.slice(e.editingAnchor,t);if(w(e.editingParam.options,i).some(a=>a.is_tappable))return;this.reEdit.exit();let{rawQuery:s,completedParams:o}=S(e.text,e.completedParams);this.fetchController.doFetch(s,o)}maybePromoteExactMatch(e){let t=this.store.get(),i=j({mode:"fresh",text:e,completedParams:t.completedParams,suggestions:t.suggestions,filterBase:t.filterBase,filterInProgress:t.filterInProgress});i&&this.store.set(i.patch)}};0&&(module.exports={AIAutocomplete,ModeController,buildQuery,createStore,cursorIsAtEnd,extractPlainText,getCursorOffset,getFooterHint,plainTextLength,previousGraphemeBoundary,renderEditableContent,setCursorOffset});
|
|
893
980
|
//# sourceMappingURL=index.js.map
|