@magicx-eng/ai-autocomplete-react 0.60.0 → 0.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3775,5 +3775,5 @@ import{buildSubmitResult as hs,cellDay as us,cellIso as ms,DATE_RANGE_META_END a
|
|
|
3775
3775
|
transition: none;
|
|
3776
3776
|
}
|
|
3777
3777
|
}
|
|
3778
|
-
`,document.head.appendChild(e)}var yt={submitButton:"aia-submitButton-otz7H"};import{jsx as Da}from"react/jsx-runtime";function kt({disabled:e,ready:n,onClick:a,label:t=Do().submit}){return Da("button",{type:"button","data-aia-submit":"",className:yt.submitButton,disabled:e,"data-aia-ready":n?"":void 0,onClick:o=>{o.stopPropagation(),a()},"aria-label":t,children:Da("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":t,children:Da("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as Mo,dateSelectionFor as No,editingSuggestion as Fo,identifiedParamLabel as Ho,withoutTraditionalAutocomplete as Bo}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as It,useEffect as ea,useMemo as Wo,useRef as ee,useState as Go}from"react";import{useRef as Ct}from"react";function St(e){let n=Ct(e);n.current=e;let a=Object.keys(e??{}).sort().join("\0"),t=Ct({key:"",overrides:void 0});if(t.current.key!==a){let o={};for(let s of Object.keys(e??{})){let r=(l,w,v)=>{let y=n.current?.[s];return y?y(l,w,v):[]};o[s]=r}t.current={key:a,overrides:e?o:void 0}}return{overrides:t.current.overrides,key:a}}import{useRef as Tt}from"react";function Pt(e){let n=Tt(e);n.current=e;let a=Tt(null);a.current===null&&(a.current={fetch:(o,s)=>{let r=n.current;return r?r.fetch(o,s):Promise.reject(new Error("products config removed"))},transform:o=>n.current?.transform(o)??[],get limit(){return n.current?.limit}});let t=e!==void 0;return{config:t?a.current:void 0,enabled:t}}var Et={text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],traditionalAutocomplete:!1,customFields:null,optionSearch:null,activeDropdownIndex:-1,newParamId:null,isLoading:!0,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],dropdownLoading:!0,dropdownOptions:[],skeletonOptions:null,skeletonSuggestion:null,skeletonPicked:null,dropdownSuggestion:null,skeletonRequested:!1,skeletonExiting:!1,activeFormatType:"options",dateView:null,dateRangeStart:null,dateReferences:[],dateFloor:null,timeView:null,multiSelectView:null,dropdownMultiSelect:null,multiSelectDraft:null,locationView:null,locationSearch:null,locationAutocomplete:!0,locationFieldFocused:!1,placeholderText:"",leadInText:"",optionQuery:"",isSearchingOptions:!1,isDropdownOpen:!1,isActivePillSelected:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,dropdownHeld:!1,editingParam:null,editingIdentified:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,dateViewMonth:null,pendingRangeStart:null,timeDraft:null};function Ma({onSubmit:e,onResult:n,onError:a,optionOverrides:t,maskCompletedText:o,apiConfig:s,additionalContext:r,language:l,currency:w,productId:v,visitorId:y,columns:b=2,dropdownTrigger:h,optionsPosition:p,closeDropdownOnBlur:x,prependPlaceholder:E,allOption:q,showNonTappableOptions:M,locationSearch:R,showOptionIcons:ae,showOptionImages:T,showOptionCounts:z,showSkipButton:U,showProducts:F,productImageFallback:te="image",onFocus:Q,onBlur:P,value:B,completedParams:W,onChange:Y,onParamsChange:re,products:I,mapProducts:D,onProductSelect:c,onProductAddToCart:S,source:He,setCursor:xe}){let f=ee(null),[Be,ye]=Go(null),Oe=ee(e);Oe.current=e;let Le=ee(n);Le.current=n;let ze=ee(a);ze.current=a;let ke=ee(Y);ke.current=Y;let g=ee(re);g.current=re;let k=ee(Q);k.current=Q;let C=ee(P);C.current=P;let A=ee(xe);A.current=xe;let L=ee(c);L.current=c;let j=ee(S);j.current=S;let ie=ee(y);ie.current=y;let ue=ee(()=>{let d=ie.current;return typeof d=="function"?d():d}).current,de=Pt(I),We=ee(D);We.current=D;let $=ee((d,G)=>{let N=We.current;return N?N(d,G):d}).current,Ce=D?$:void 0,Ge=St(t);ea(()=>{if(typeof document>"u")return;let d=new Mo(document.createElement("div"),{renderMode:"headless",apiConfig:s,additionalContext:r,language:l,currency:w,productId:v,visitorId:ue,optionOverrides:Ge.overrides,maskCompletedText:o,columns:b,dropdownTrigger:h,optionsPosition:p,closeDropdownOnBlur:x,prependPlaceholder:E,allOption:q,showNonTappableOptions:M,locationSearch:R,showProducts:F,source:He,value:B,completedParams:W,onSubmit:(...N)=>Oe.current?.(...N),onResult:(...N)=>Le.current?.(...N),onError:(...N)=>ze.current?.(...N),onChange:(...N)=>ke.current?.(...N),onParamsChange:(...N)=>g.current?.(...N),onFocus:()=>k.current?.(),onBlur:()=>C.current?.(),onProductSelect:N=>L.current?.(N),onProductAddToCart:N=>j.current?.(N),setCursor:N=>A.current?.(N),products:de.config,mapProducts:Ce});f.current=d,ye(d.getState());let G=d.subscribe(N=>ye(N));return()=>{G(),d.destroy(),f.current===d&&(f.current=null)}},[]),ea(()=>{B!==void 0&&f.current?.setValue(B)},[B]),ea(()=>{W!==void 0&&f.current?.setCompletedParams(W)},[W]);let na=JSON.stringify(s??null),me;try{me=JSON.stringify(r??null)}catch{me="[unstringifiable]"}ea(()=>{f.current?.update({apiConfig:s,additionalContext:r,language:l,currency:w,productId:v,optionOverrides:Ge.overrides,dropdownTrigger:h,optionsPosition:p,closeDropdownOnBlur:x,prependPlaceholder:E,allOption:q,showNonTappableOptions:M,locationSearch:R,showProducts:F})},[na,me,l,w?.code,w?.rate,w?.country,v,Ge.key,h,p,x,E,q,M,R,F]);let Ye=ee(!1);ea(()=>{if(!Ye.current){Ye.current=!0;return}f.current?.update({products:de.config})},[de.enabled]),ea(()=>{f.current?.update({mapProducts:Ce})},[Ce]);let De=ee(null);De.current===null&&(De.current={handleTextChange:d=>f.current?.handleTextChange(d),handleCompositionText:d=>f.current?.handleCompositionText(d),handleKeyDown:d=>{let G="nativeEvent"in d?d.nativeEvent:d;f.current?.handleKeyDown(G)},setFocused:d=>f.current?.setFocused(d),startEditingParam:d=>f.current?.startEditingParam(d),removeParam:d=>f.current?.removeParam(d)??!1,exitEditMode:()=>f.current?.exitEditMode(),handleCaretAfterInput:d=>f.current?.handleCaretAfterInput(d),handleCaretMove:d=>f.current?.handleCaretMove(d),replaceEditingRange:d=>f.current?.replaceEditingRange(d)??!1,setActivePill:d=>f.current?.setActivePill(d),skipActivePill:()=>f.current?.skipActivePill(),removeLastParam:()=>f.current?.removeLastParam(),clearNewParamId:()=>f.current?.clearNewParamId(),reset:()=>f.current?.reset(),refreshProducts:()=>f.current?.refreshProducts(),prepareSubmit:()=>f.current?.prepareSubmit(),getState:()=>f.current?.getState()??Et,recordSubmit:d=>f.current?.recordSubmit(d),selectOption:(d,G)=>f.current?.selectOption(d,G),selectProduct:d=>f.current?.selectProduct(d),addProductToCart:d=>{let G=f.current;return!G||!j.current?Promise.resolve():G.addProductToCart(d)},setActiveDropdownIndex:d=>f.current?.setActiveDropdownIndex(d),clearHighlight:d=>f.current?.clearHighlight(d),showPreviousMonth:()=>f.current?.showPreviousMonth(),showNextMonth:()=>f.current?.showNextMonth(),setTime:d=>f.current?.setTime(d),commitTime:()=>f.current?.commitTime(),toggleMultiSelectOption:d=>f.current?.toggleMultiSelectOption(d),commitMultiSelect:()=>f.current?.commitMultiSelect(),setLocationQuery:d=>f.current?.setLocationQuery(d),moveLocationHighlight:d=>f.current?.moveLocationHighlight(d),commitLocation:d=>f.current?.commitLocation(d),setLocationFieldFocused:d=>f.current?.setLocationFieldFocused(d),handleFocus:()=>f.current?.setFocused(!0),handleBlur:()=>f.current?.setFocused(!1)});let m=De.current,Se=It(d=>{let G=d.target.value,$e=G.length>0&&!d.nativeEvent?.isComposing&&G[0]!==G[0].toUpperCase()?G[0].toUpperCase()+G.slice(1):G;f.current?.handleTextChange($e)},[]),Ke=It(d=>{f.current?.handleKeyDown(d.nativeEvent)},[]),i=f.current,u=Be??Et,Te=B!==void 0?B:u.text,Pe=W!==void 0?W:u.completedParams,ge=u.actionableSuggestions,Ie=ge[0],Me=Wo(()=>Bo(ge),[ge]),fe=i?.listboxId??"",ra=u.activeDropdownIndex>=0&&i?`${fe}-option-${u.activeDropdownIndex}`:void 0,Ee=u.editingParam,be=u.editingIdentified,Ne=Ee?Fo(Ee):be?{parameter:be.parameter,text:Ho(be.parameter),required:!0,options:[]}:null,qe=u.dropdownSuggestion??Ne??Ie,je=Ne?[Ne]:ge,Ae=No(u),_e=!i||u.dropdownLoading;return{completedParams:Pe,multiSelectView:u.multiSelectView,toggleMultiSelectOption:m.toggleMultiSelectOption,commitMultiSelect:m.commitMultiSelect,skippedParams:u.skippedParams,identifiedParams:u.identifiedParams,suggestionPills:Me,setActivePill:m.setActivePill,skipActivePill:m.skipActivePill,removeLastParam:m.removeLastParam,segments:u.segments,newParamId:u.newParamId,clearNewParamId:m.clearNewParamId,suggestions:u.suggestions,activeIndex:u.activeDropdownIndex,isReady:u.isReady,isLoading:_e,isFocused:u.isFocused,isDropdownOpen:u.isDropdownOpen,isActivePillSelected:u.isActivePillSelected,placeholderText:u.placeholderText,listboxId:fe,error:u.error,products:u.products,customFields:u.customFields,selectProduct:m.selectProduct,addProductToCart:m.addProductToCart,handleTextChange:m.handleTextChange,handleCompositionText:m.handleCompositionText,handleKeyDown:m.handleKeyDown,setFocused:m.setFocused,editingParam:Ee,editingIdentified:be,editingAnchor:u.editingAnchor,caretOffset:u.caretOffset,startEditingParam:m.startEditingParam,removeParam:m.removeParam,exitEditMode:m.exitEditMode,handleCaretAfterInput:m.handleCaretAfterInput,handleCaretMove:m.handleCaretMove,replaceEditingRange:m.replaceEditingRange,inputProps:{value:Te,placeholder:u.placeholderText||void 0,onChange:Se,onKeyDown:Ke,onFocus:m.handleFocus,onBlur:m.handleBlur,role:"combobox","aria-expanded":u.isDropdownOpen,"aria-activedescendant":ra,"aria-autocomplete":"list","aria-controls":fe},reset:m.reset,refreshProducts:m.refreshProducts,prepareSubmit:m.prepareSubmit,getState:m.getState,recordSubmit:m.recordSubmit,dropdownProps:{suggestions:qe?[{...qe,options:u.dropdownOptions}]:[],activeIndex:u.activeDropdownIndex,onSelect:m.selectOption,onHighlight:m.setActiveDropdownIndex,onUnhighlight:m.clearHighlight,isOpen:u.isDropdownOpen,id:fe,pills:je,activeSelected:u.isActivePillSelected,onPillClick:m.setActivePill,onSkip:m.skipActivePill,showSkipButton:(U??!0)&&!Ee&&!be,showOptionIcons:ae??!0,showOptionImages:T??!0,showOptionCounts:z??!0,skipDisabled:u.inSelectionAnimation,isLoading:_e,skeletonExiting:u.skeletonExiting,isInputEmpty:Te.trim().length===0,language:l,products:u.products,productImageFallback:te,onProductSelect:m.selectProduct,onProductAddToCart:S?m.addProductToCart:void 0,onProductFocusChange:m.setFocused,formatType:u.activeFormatType,dateView:u.dateView,selectedDateIso:Ae.selectedIso,selectedDateRange:Ae.selectedRange,dateRangeStart:Ae.rangeStart,dateReferences:Ae.references,onPreviousMonth:m.showPreviousMonth,onNextMonth:m.showNextMonth,timeView:u.timeView,multiSelectView:u.dropdownMultiSelect,onMultiSelectCommit:m.commitMultiSelect,onTimeChange:m.setTime,onTimeCommit:m.commitTime,locationView:u.locationView,isReediting:u.editingParam!=null,onLocationQuery:m.setLocationQuery,onLocationMove:m.moveLocationHighlight,onLocationCommit:m.commitLocation,onLocationFocusChange:m.setLocationFieldFocused,isFocused:u.isFocused||u.locationFieldFocused,optionsPosition:p??"below"}}}import{attachChipRemove as Ko,cancelStartingHint as qo,chipIdFromTap as _o,extractPlainText as At,getCursorOffset as Rt,keepCaretOnChip as Vo,plainTextLength as Uo,renderEditableContent as Qo,setCursorOffset as Ot,startingHintOptions as Yo}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as he,useEffect as aa,useLayoutEffect as Na,useRef as ta}from"react";var ya;function jo(){if(ya!==void 0)return ya;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),ya=e.contentEditable==="plaintext-only",ya}function Lt(e){let{segments:n,showChipIcons:a=!0,showChipImages:t=!0,showChipRemove:o=!1,removeParam:s,newParamId:r,editingParam:l,editingIdentified:w,editingAnchor:v,caretOffset:y,placeholderText:b,hintSuggestions:h,isFocused:p,isDropdownOpen:x,listboxId:E,activeDescendantId:q,autoFocus:M,handleTextChange:R,handleCompositionText:ae,handleKeyDown:T,handleCaretAfterInput:z,handleCaretMove:U,startEditingParam:F,replaceEditingRange:te,setFocused:Q}=e,P=ta(null),B=ta(!1),W=ta(""),Y=ta(""),re=ta(null),I=ta(0);re.current=y,aa(()=>{if(!M)return;let g=P.current;if(!g)return;document.activeElement===g?Q(!0):g.focus();let k=g.ownerDocument??document,C=k.getSelection(),A=C&&C.rangeCount>0&&g.contains(C.anchorNode);if(C&&!A){let L=k.createRange();L.selectNodeContents(g),L.collapse(!0),C.removeAllRanges(),C.addRange(L)}},[M,Q]),aa(()=>{let g=P.current;if(!g)return;let k=g.ownerDocument??document,C=()=>{let A=k.getSelection();if(!A||A.rangeCount===0||!A.anchorNode||!g.contains(A.anchorNode))return;let L=A.anchorNode,j=L.nodeType===Node.ELEMENT_NODE?L:L.parentElement,ue=(A.isCollapsed?j?.closest("strong[data-param-id]"):null)?.dataset.paramId??null,de=l?.id??w?.id??null;if(ue&&ue!==de){F(ue);return}performance.now()-I.current<50||U(Rt(g))};return k.addEventListener("selectionchange",C),()=>k.removeEventListener("selectionchange",C)},[l,w,F,U]),aa(()=>{let g=P.current;if(!g)return;let k=C=>{let A=_o(g,C.target);A&&(F(A),Vo(g,A))};return g.addEventListener("click",k),()=>g.removeEventListener("click",k)},[F]),aa(()=>{let g=P.current;if(!(!g||!s||!o))return Ko(g,s)},[s,o]),Na(()=>{let g=P.current;g&&Qo({input:g,segments:n,newParamId:r,editingParamId:l?.id??null,placeholderText:b??"",isFocused:p,showChipIcons:a,showChipImages:t,showChipRemove:o,hintOptions:Yo(h??[])})},[n,r,l,b,h,p,a,t,o]),aa(()=>{let g=P.current;return()=>{g&&qo(g)}},[]),Na(()=>{let g=W.current,k=r??"";if(W.current=k,!k||k===g)return;let C=P.current;if(!C)return;C.focus();let A=re.current??Uo(C);Ot(C,A)},[r]),Na(()=>{let g=Y.current,k=l?.id??"";if(Y.current=k,!k||k===g||v==null)return;let C=P.current;C&&Ot(C,v)},[l,v]);let D=he(()=>{let g=P.current;if(!g)return;let k=At(g),A=k.length>0&&k[0]!==k[0].toUpperCase()?k[0].toUpperCase()+k.slice(1):k;if(B.current){ae(A);return}R(A)},[R,ae]),c=he(()=>{I.current=performance.now(),D();let g=P.current;g&&z(Rt(g))},[D,z]);aa(()=>{let g=P.current;if(!g)return;let k=C=>{let A=C,L=A.inputType;if(L==="insertParagraph"||L==="insertLineBreak"||L==="insertFromDrop"){C.preventDefault();return}if(L.startsWith("insert")||L.startsWith("delete")){let j=L.startsWith("delete")?"":A.data??"";te(j)&&C.preventDefault()}};return g.addEventListener("beforeinput",k),()=>g.removeEventListener("beforeinput",k)},[te]);let S=he(()=>{B.current=!0,P.current?.setAttribute("data-aia-composing","true")},[]),He=he(()=>{B.current=!1,P.current?.removeAttribute("data-aia-composing"),D()},[D]),xe=he(g=>{g.preventDefault();let k=P.current;if(!k)return;let C=(g.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!C)return;let A=k.ownerDocument??document,L=A.getSelection();if(!L||L.rangeCount===0)return;let j=L.getRangeAt(0);if(!k.contains(j.startContainer))return;j.deleteContents();let ie=A.createTextNode(C);j.insertNode(ie),j.setStartAfter(ie),j.collapse(!0),L.removeAllRanges(),L.addRange(j),D()},[D]),f=he(g=>T(g),[T]),Be=he(()=>Q(!0),[Q]),ye=he(()=>Q(!1),[Q]),Oe=he(()=>P.current?.focus(),[]),Le=he(()=>P.current?.blur(),[]),ze=he(()=>{let g=P.current;return g?At(g):""},[]),ke=jo()?"plaintext-only":"true";return{inputRef:P,editorProps:{ref:P,contentEditable:ke,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":E,"aria-expanded":x,"aria-activedescendant":q,spellCheck:!0,enterKeyHint:"send",onInput:c,onKeyDown:f,onCompositionStart:S,onCompositionEnd:He,onPaste:xe,onFocus:Be,onBlur:ye},getPlainText:ze,focus:Oe,blur:Le}}import{jsx as oa,jsxs as Ha}from"react/jsx-runtime";function nn(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var rn=$o(function({onSubmit:n,onResult:a,onError:t,optionOverrides:o,maskCompletedText:s,className:r,apiConfig:l,additionalContext:w,language:v,currency:y,productId:b,visitorId:h,columns:p,pillPlacement:x="dropdown",mode:E="auto",optionsPosition:q="below",animations:M=!0,optionsStyle:R="floating",dropdownTrigger:ae,closeDropdownOnBlur:T,prependPlaceholder:z,allOption:U,showNonTappableOptions:F,locationSearch:te,showOptionIcons:Q=!0,showChipIcons:P=!0,showChipImages:B=!0,showChipRemove:W=!1,showOptionImages:Y=!0,showOptionCounts:re=!0,showSkipButton:I,showProducts:D,productsLayout:c,productImageFallback:S,autoFocus:He=!0,onFocus:xe,onBlur:f,value:Be,completedParams:ye,onChange:Oe,onParamsChange:Le,products:ze,mapProducts:ke,onProductSelect:g,onProductAddToCart:k,submitButton:C,resetOnSubmit:A=!0,seeAllResults:L=!1},j){let ie=ia(null),ue=ia(null),de=ia(null),We=ia(()=>{}),$=ia(null),Ce=ia(null);Fa(()=>{let H=ie.current;if(H)return $.current?$.current.setMode(E):$.current=new en(H,E),()=>{$.current?.destroy(),$.current=null}},[E]);let Ge=ka(H=>{let oe=Ce.current?.current;oe&&(oe.focus(),an(oe,H))},[]),{completedParams:na,suggestionPills:me,setActivePill:Ye,skipActivePill:De,segments:m,newParamId:Se,clearNewParamId:Ke,placeholderText:i,isFocused:u,isDropdownOpen:Te,isActivePillSelected:Pe,isLoading:ge,isReady:Ie,activeIndex:Me,listboxId:fe,handleTextChange:ra,handleCompositionText:Ee,handleKeyDown:be,setFocused:Ne,editingParam:qe,editingIdentified:je,editingAnchor:Ae,caretOffset:_e,startEditingParam:d,removeParam:G,handleCaretAfterInput:N,handleCaretMove:$e,replaceEditingRange:O,dropdownProps:Ba,reset:ma,refreshProducts:Wa,prepareSubmit:Ga,getState:Ka,recordSubmit:qa}=Ma({onSubmit:H=>We.current(H),onResult:a,onError:t,optionOverrides:o,maskCompletedText:s,apiConfig:l,additionalContext:w,language:v,currency:y,productId:b,visitorId:h,columns:p,dropdownTrigger:ae,optionsPosition:q,closeDropdownOnBlur:T,prependPlaceholder:z,allOption:U,showNonTappableOptions:F,locationSearch:te,showOptionIcons:Q,showOptionImages:Y,showOptionCounts:re,showSkipButton:I,showProducts:D,onFocus:xe,onBlur:f,value:Be,completedParams:ye,onChange:Oe,onParamsChange:Le,products:ze,mapProducts:ke,onProductSelect:g,onProductAddToCart:k,source:"full-sdk",setCursor:Ge});Fa(()=>{if(!Se)return;let H=window.setTimeout(()=>Ke(),650);return()=>window.clearTimeout(H)},[Se,Ke]);let zt=Me>=0?`${fe}-option-${Me}`:void 0,{inputRef:Ca,editorProps:Dt,focus:ga,blur:_a,getPlainText:Va}=Lt({segments:m,newParamId:Se,editingParam:qe,editingIdentified:je,editingAnchor:Ae,caretOffset:_e,placeholderText:i,hintSuggestions:x==="inline"?[]:me,isFocused:u,showChipIcons:P,showChipImages:B,showChipRemove:W,removeParam:G,isDropdownOpen:Te,listboxId:fe,activeDescendantId:zt,autoFocus:He,handleTextChange:ra,handleCompositionText:Ee,handleKeyDown:be,handleCaretAfterInput:N,handleCaretMove:$e,startEditingParam:d,replaceEditingRange:O,setFocused:Ne});Ce.current=Ca,Xo(()=>{let H=ue.current,oe=Ca.current;if(!H||!oe)return;let la=()=>{let Qa=H.firstElementChild;if(!Qa)return;let Wt=Qa.getBoundingClientRect(),Gt=oe.getBoundingClientRect();Wt.top>=Gt.bottom-2?H.setAttribute("data-aia-pill-wrapped",""):H.removeAttribute("data-aia-pill-wrapped")};la();let Ua=new ResizeObserver(la);return Ua.observe(oe),()=>Ua.disconnect()},[m,me.length,ge,Ca]),Fa(()=>{let H=de.current;if(H)return on(H)},[]),Zo(j,()=>({focus:ga,blur:_a,reset:ma,refreshProducts:Wa,setMode:H=>$.current?.setMode(H),skipActivePill:De}),[ga,_a,ma,Wa,De]);let Ze=!!m.length||na.length>0,sa=ka(H=>{if(!Ze)return;H&&Ga();let oe=Ka(),la=Jo(Va(),oe.completedParams,oe.skippedParams,{identifiedParams:oe.identifiedParams,isReady:oe.isReady,customFields:oe.customFields});H&&qa(la),n(la),A&&ma()},[qa,A,Ze,Ga,Ka,n,ma,Va]);We.current=()=>sa(!1);let Mt=L&&!Ba.isInputEmpty&&Ze,Nt=ka(()=>sa(!0),[sa]),Ft=ka(H=>{H.target?.closest("[data-aia-pill]")||document.activeElement?.closest("[data-aia-location]")||ga()},[ga]),Ht=x==="inline",Bt=x==="dropdown";return Ha("div",{ref:ie,className:`magicx-aia ${Ve.container} ${r??""}`,"data-pill-placement":x,"data-options-position":q,"data-animations":M?"on":"off","data-aia-options-style":R,"data-mode":nn(E),children:[oa(za,{...Ba,showPills:Bt,productsLayout:c,productImageFallback:S,onSeeAllResults:Mt?Nt:void 0,fullWidth:L}),Ha("div",{className:Ve.inputWrapper,"data-aia-input-wrapper":"",onClick:Ft,children:[Ha("div",{ref:de,className:Ve.editorArea,"data-aia-editor":"",children:[oa("div",{...Dt,className:Ve.input,"data-aia-input":""}),Ht&&(ge||me.length>0)&&oa("span",{ref:ue,className:Ve.pillListContainer,"data-aia-pill-list-container":"",children:oa(ba,{pills:me,activePillIndex:0,activeSelected:Pe,onSelectPill:Ye,loading:ge})})]}),C===null?null:C===void 0?oa(kt,{disabled:!Ze,ready:Ze&&Ie,onClick:()=>sa(!0),label:tn(v).submit}):oa("span",{"data-aia-submit":"","data-aia-submit-slot":"",className:Ve.submitSlot,onClick:H=>{Ze&&(H.stopPropagation(),sa(!0))},children:C})]})]})});export{rn as AIAutocomplete,za as AIAutocompleteDropdown,gs as DATE_RANGE_META_END,fs as DATE_RANGE_META_START,bs as DEFAULT_OPTION_COUNT_UNIT,Ts as LOCATION_META_KEY,zs as PRODUCT_PATH_PREFIX,qs as TIME_META_KEY,Vs as WEEKDAY_LABELS,hs as buildSubmitResult,us as cellDay,ms as cellIso,ws as dateCellMarks,vs as formatDate,xs as formatDateRange,ys as formatOptionCount,ks as formatPlace,Cs as formatTime,Ss as isoDate,Ps as monthLabel,Is as optionCountLabel,Es as optionHasImage,As as optionImageSources,Rs as optionImageSrc,Os as optionLabel,Ls as optionsShowLeadingVisuals,Ds as parseDate,Ms as parseLooseDate,Ns as parseLooseDateRange,Fs as parseTime,Hs as productFromMatchedItem,Bs as productImageSources,Ws as productsFromCustomFields,Gs as sanitizeOptionIconSvg,Ks as selectedRangeFor,Ma as useAIAutocomplete,_s as visibleDateRange,Us as withSkippedParams};
|
|
3778
|
+
`,document.head.appendChild(e)}var yt={submitButton:"aia-submitButton-otz7H"};import{jsx as Da}from"react/jsx-runtime";function kt({disabled:e,ready:n,onClick:a,label:t=Do().submit}){return Da("button",{type:"button","data-aia-submit":"",className:yt.submitButton,disabled:e,"data-aia-ready":n?"":void 0,onClick:o=>{o.stopPropagation(),a()},"aria-label":t,children:Da("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":t,children:Da("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as Mo,dateSelectionFor as No,editingSuggestion as Fo,identifiedParamLabel as Ho,withoutTraditionalAutocomplete as Bo}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as It,useEffect as ea,useMemo as Wo,useRef as ee,useState as Go}from"react";import{useRef as Ct}from"react";function St(e){let n=Ct(e);n.current=e;let a=Object.keys(e??{}).sort().join("\0"),t=Ct({key:"",overrides:void 0});if(t.current.key!==a){let o={};for(let s of Object.keys(e??{})){let r=(l,w,v)=>{let y=n.current?.[s];return y?y(l,w,v):[]};o[s]=r}t.current={key:a,overrides:e?o:void 0}}return{overrides:t.current.overrides,key:a}}import{useRef as Tt}from"react";function Pt(e){let n=Tt(e);n.current=e;let a=Tt(null);a.current===null&&(a.current={fetch:(o,s)=>{let r=n.current;return r?r.fetch(o,s):Promise.reject(new Error("products config removed"))},transform:o=>n.current?.transform(o)??[],get limit(){return n.current?.limit}});let t=e!==void 0;return{config:t?a.current:void 0,enabled:t}}var Et={text:"",composing:null,completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],traditionalAutocomplete:!1,customFields:null,optionSearch:null,activeDropdownIndex:-1,newParamId:null,isLoading:!0,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],dropdownLoading:!0,dropdownOptions:[],skeletonOptions:null,skeletonSuggestion:null,skeletonPicked:null,dropdownSuggestion:null,skeletonRequested:!1,skeletonExiting:!1,activeFormatType:"options",dateView:null,dateRangeStart:null,dateReferences:[],dateFloor:null,timeView:null,multiSelectView:null,dropdownMultiSelect:null,multiSelectDraft:null,locationView:null,locationSearch:null,locationAutocomplete:!0,locationFieldFocused:!1,placeholderText:"",leadInText:"",optionQuery:"",isSearchingOptions:!1,isDropdownOpen:!1,isActivePillSelected:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:"",isFocused:!1,dropdownHeld:!1,editingParam:null,editingIdentified:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,dateViewMonth:null,pendingRangeStart:null,timeDraft:null};function Ma({onSubmit:e,onResult:n,onError:a,optionOverrides:t,maskCompletedText:o,apiConfig:s,additionalContext:r,language:l,currency:w,productId:v,visitorId:y,columns:b=2,dropdownTrigger:h,optionsPosition:p,closeDropdownOnBlur:x,prependPlaceholder:E,allOption:q,showNonTappableOptions:M,locationSearch:R,showOptionIcons:ae,showOptionImages:T,showOptionCounts:z,showSkipButton:U,showProducts:F,productImageFallback:te="image",onFocus:Q,onBlur:P,value:B,completedParams:W,onChange:Y,onParamsChange:re,products:I,mapProducts:D,onProductSelect:c,onProductAddToCart:S,source:He,setCursor:xe}){let f=ee(null),[Be,ye]=Go(null),Oe=ee(e);Oe.current=e;let Le=ee(n);Le.current=n;let ze=ee(a);ze.current=a;let ke=ee(Y);ke.current=Y;let g=ee(re);g.current=re;let k=ee(Q);k.current=Q;let C=ee(P);C.current=P;let A=ee(xe);A.current=xe;let L=ee(c);L.current=c;let j=ee(S);j.current=S;let ie=ee(y);ie.current=y;let ue=ee(()=>{let d=ie.current;return typeof d=="function"?d():d}).current,de=Pt(I),We=ee(D);We.current=D;let $=ee((d,G)=>{let N=We.current;return N?N(d,G):d}).current,Ce=D?$:void 0,Ge=St(t);ea(()=>{if(typeof document>"u")return;let d=new Mo(document.createElement("div"),{renderMode:"headless",apiConfig:s,additionalContext:r,language:l,currency:w,productId:v,visitorId:ue,optionOverrides:Ge.overrides,maskCompletedText:o,columns:b,dropdownTrigger:h,optionsPosition:p,closeDropdownOnBlur:x,prependPlaceholder:E,allOption:q,showNonTappableOptions:M,locationSearch:R,showProducts:F,source:He,value:B,completedParams:W,onSubmit:(...N)=>Oe.current?.(...N),onResult:(...N)=>Le.current?.(...N),onError:(...N)=>ze.current?.(...N),onChange:(...N)=>ke.current?.(...N),onParamsChange:(...N)=>g.current?.(...N),onFocus:()=>k.current?.(),onBlur:()=>C.current?.(),onProductSelect:N=>L.current?.(N),onProductAddToCart:N=>j.current?.(N),setCursor:N=>A.current?.(N),products:de.config,mapProducts:Ce});f.current=d,ye(d.getState());let G=d.subscribe(N=>ye(N));return()=>{G(),d.destroy(),f.current===d&&(f.current=null)}},[]),ea(()=>{B!==void 0&&f.current?.setValue(B)},[B]),ea(()=>{W!==void 0&&f.current?.setCompletedParams(W)},[W]);let na=JSON.stringify(s??null),me;try{me=JSON.stringify(r??null)}catch{me="[unstringifiable]"}ea(()=>{f.current?.update({apiConfig:s,additionalContext:r,language:l,currency:w,productId:v,optionOverrides:Ge.overrides,dropdownTrigger:h,optionsPosition:p,closeDropdownOnBlur:x,prependPlaceholder:E,allOption:q,showNonTappableOptions:M,locationSearch:R,showProducts:F})},[na,me,l,w?.code,w?.rate,w?.country,v,Ge.key,h,p,x,E,q,M,R,F]);let Ye=ee(!1);ea(()=>{if(!Ye.current){Ye.current=!0;return}f.current?.update({products:de.config})},[de.enabled]),ea(()=>{f.current?.update({mapProducts:Ce})},[Ce]);let De=ee(null);De.current===null&&(De.current={handleTextChange:d=>f.current?.handleTextChange(d),handleCompositionText:d=>f.current?.handleCompositionText(d),handleKeyDown:d=>{let G="nativeEvent"in d?d.nativeEvent:d;f.current?.handleKeyDown(G)},setFocused:d=>f.current?.setFocused(d),startEditingParam:d=>f.current?.startEditingParam(d),removeParam:d=>f.current?.removeParam(d)??!1,exitEditMode:()=>f.current?.exitEditMode(),handleCaretAfterInput:d=>f.current?.handleCaretAfterInput(d),handleCaretMove:d=>f.current?.handleCaretMove(d),replaceEditingRange:d=>f.current?.replaceEditingRange(d)??!1,setActivePill:d=>f.current?.setActivePill(d),skipActivePill:()=>f.current?.skipActivePill(),removeLastParam:()=>f.current?.removeLastParam(),clearNewParamId:()=>f.current?.clearNewParamId(),reset:()=>f.current?.reset(),refreshProducts:()=>f.current?.refreshProducts(),prepareSubmit:()=>f.current?.prepareSubmit(),getState:()=>f.current?.getState()??Et,recordSubmit:d=>f.current?.recordSubmit(d),selectOption:(d,G)=>f.current?.selectOption(d,G),selectProduct:d=>f.current?.selectProduct(d),addProductToCart:d=>{let G=f.current;return!G||!j.current?Promise.resolve():G.addProductToCart(d)},setActiveDropdownIndex:d=>f.current?.setActiveDropdownIndex(d),clearHighlight:d=>f.current?.clearHighlight(d),showPreviousMonth:()=>f.current?.showPreviousMonth(),showNextMonth:()=>f.current?.showNextMonth(),setTime:d=>f.current?.setTime(d),commitTime:()=>f.current?.commitTime(),toggleMultiSelectOption:d=>f.current?.toggleMultiSelectOption(d),commitMultiSelect:()=>f.current?.commitMultiSelect(),setLocationQuery:d=>f.current?.setLocationQuery(d),moveLocationHighlight:d=>f.current?.moveLocationHighlight(d),commitLocation:d=>f.current?.commitLocation(d),setLocationFieldFocused:d=>f.current?.setLocationFieldFocused(d),handleFocus:()=>f.current?.setFocused(!0),handleBlur:()=>f.current?.setFocused(!1)});let m=De.current,Se=It(d=>{let G=d.target.value,$e=G.length>0&&!d.nativeEvent?.isComposing&&G[0]!==G[0].toUpperCase()?G[0].toUpperCase()+G.slice(1):G;f.current?.handleTextChange($e)},[]),Ke=It(d=>{f.current?.handleKeyDown(d.nativeEvent)},[]),i=f.current,u=Be??Et,Te=B!==void 0?B:u.text,Pe=W!==void 0?W:u.completedParams,ge=u.actionableSuggestions,Ie=ge[0],Me=Wo(()=>Bo(ge),[ge]),fe=i?.listboxId??"",ra=u.activeDropdownIndex>=0&&i?`${fe}-option-${u.activeDropdownIndex}`:void 0,Ee=u.editingParam,be=u.editingIdentified,Ne=Ee?Fo(Ee):be?{parameter:be.parameter,text:Ho(be.parameter),required:!0,options:[]}:null,qe=u.dropdownSuggestion??Ne??Ie,je=Ne?[Ne]:ge,Ae=No(u),_e=!i||u.dropdownLoading;return{completedParams:Pe,multiSelectView:u.multiSelectView,toggleMultiSelectOption:m.toggleMultiSelectOption,commitMultiSelect:m.commitMultiSelect,skippedParams:u.skippedParams,identifiedParams:u.identifiedParams,suggestionPills:Me,setActivePill:m.setActivePill,skipActivePill:m.skipActivePill,removeLastParam:m.removeLastParam,segments:u.segments,newParamId:u.newParamId,clearNewParamId:m.clearNewParamId,suggestions:u.suggestions,activeIndex:u.activeDropdownIndex,isReady:u.isReady,isLoading:_e,isFocused:u.isFocused,isDropdownOpen:u.isDropdownOpen,isActivePillSelected:u.isActivePillSelected,placeholderText:u.placeholderText,listboxId:fe,error:u.error,products:u.products,customFields:u.customFields,selectProduct:m.selectProduct,addProductToCart:m.addProductToCart,handleTextChange:m.handleTextChange,handleCompositionText:m.handleCompositionText,handleKeyDown:m.handleKeyDown,setFocused:m.setFocused,editingParam:Ee,editingIdentified:be,editingAnchor:u.editingAnchor,caretOffset:u.caretOffset,startEditingParam:m.startEditingParam,removeParam:m.removeParam,exitEditMode:m.exitEditMode,handleCaretAfterInput:m.handleCaretAfterInput,handleCaretMove:m.handleCaretMove,replaceEditingRange:m.replaceEditingRange,inputProps:{value:Te,placeholder:u.placeholderText||void 0,onChange:Se,onKeyDown:Ke,onFocus:m.handleFocus,onBlur:m.handleBlur,role:"combobox","aria-expanded":u.isDropdownOpen,"aria-activedescendant":ra,"aria-autocomplete":"list","aria-controls":fe},reset:m.reset,refreshProducts:m.refreshProducts,prepareSubmit:m.prepareSubmit,getState:m.getState,recordSubmit:m.recordSubmit,dropdownProps:{suggestions:qe?[{...qe,options:u.dropdownOptions}]:[],activeIndex:u.activeDropdownIndex,onSelect:m.selectOption,onHighlight:m.setActiveDropdownIndex,onUnhighlight:m.clearHighlight,isOpen:u.isDropdownOpen,id:fe,pills:je,activeSelected:u.isActivePillSelected,onPillClick:m.setActivePill,onSkip:m.skipActivePill,showSkipButton:(U??!0)&&!Ee&&!be,showOptionIcons:ae??!0,showOptionImages:T??!0,showOptionCounts:z??!0,skipDisabled:u.inSelectionAnimation,isLoading:_e,skeletonExiting:u.skeletonExiting,isInputEmpty:Te.trim().length===0,language:l,products:u.products,productImageFallback:te,onProductSelect:m.selectProduct,onProductAddToCart:S?m.addProductToCart:void 0,onProductFocusChange:m.setFocused,formatType:u.activeFormatType,dateView:u.dateView,selectedDateIso:Ae.selectedIso,selectedDateRange:Ae.selectedRange,dateRangeStart:Ae.rangeStart,dateReferences:Ae.references,onPreviousMonth:m.showPreviousMonth,onNextMonth:m.showNextMonth,timeView:u.timeView,multiSelectView:u.dropdownMultiSelect,onMultiSelectCommit:m.commitMultiSelect,onTimeChange:m.setTime,onTimeCommit:m.commitTime,locationView:u.locationView,isReediting:u.editingParam!=null,onLocationQuery:m.setLocationQuery,onLocationMove:m.moveLocationHighlight,onLocationCommit:m.commitLocation,onLocationFocusChange:m.setLocationFieldFocused,isFocused:u.isFocused||u.locationFieldFocused,optionsPosition:p??"below"}}}import{attachChipRemove as Ko,cancelStartingHint as qo,chipIdFromTap as _o,extractPlainText as At,getCursorOffset as Rt,keepCaretOnChip as Vo,plainTextLength as Uo,renderEditableContent as Qo,setCursorOffset as Ot,startingHintOptions as Yo}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as he,useEffect as aa,useLayoutEffect as Na,useRef as ta}from"react";var ya;function jo(){if(ya!==void 0)return ya;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),ya=e.contentEditable==="plaintext-only",ya}function Lt(e){let{segments:n,showChipIcons:a=!0,showChipImages:t=!0,showChipRemove:o=!1,removeParam:s,newParamId:r,editingParam:l,editingIdentified:w,editingAnchor:v,caretOffset:y,placeholderText:b,hintSuggestions:h,isFocused:p,isDropdownOpen:x,listboxId:E,activeDescendantId:q,autoFocus:M,handleTextChange:R,handleCompositionText:ae,handleKeyDown:T,handleCaretAfterInput:z,handleCaretMove:U,startEditingParam:F,replaceEditingRange:te,setFocused:Q}=e,P=ta(null),B=ta(!1),W=ta(""),Y=ta(""),re=ta(null),I=ta(0);re.current=y,aa(()=>{if(!M)return;let g=P.current;if(!g)return;document.activeElement===g?Q(!0):g.focus();let k=g.ownerDocument??document,C=k.getSelection(),A=C&&C.rangeCount>0&&g.contains(C.anchorNode);if(C&&!A){let L=k.createRange();L.selectNodeContents(g),L.collapse(!0),C.removeAllRanges(),C.addRange(L)}},[M,Q]),aa(()=>{let g=P.current;if(!g)return;let k=g.ownerDocument??document,C=()=>{let A=k.getSelection();if(!A||A.rangeCount===0||!A.anchorNode||!g.contains(A.anchorNode))return;let L=A.anchorNode,j=L.nodeType===Node.ELEMENT_NODE?L:L.parentElement,ue=(A.isCollapsed?j?.closest("strong[data-param-id]"):null)?.dataset.paramId??null,de=l?.id??w?.id??null;if(ue&&ue!==de){F(ue);return}performance.now()-I.current<50||U(Rt(g))};return k.addEventListener("selectionchange",C),()=>k.removeEventListener("selectionchange",C)},[l,w,F,U]),aa(()=>{let g=P.current;if(!g)return;let k=C=>{let A=_o(g,C.target);A&&(F(A),Vo(g,A))};return g.addEventListener("click",k),()=>g.removeEventListener("click",k)},[F]),aa(()=>{let g=P.current;if(!(!g||!s||!o))return Ko(g,s)},[s,o]),Na(()=>{let g=P.current;g&&Qo({input:g,segments:n,newParamId:r,editingParamId:l?.id??null,placeholderText:b??"",isFocused:p,showChipIcons:a,showChipImages:t,showChipRemove:o,hintOptions:Yo(h??[])})},[n,r,l,b,h,p,a,t,o]),aa(()=>{let g=P.current;return()=>{g&&qo(g)}},[]),Na(()=>{let g=W.current,k=r??"";if(W.current=k,!k||k===g)return;let C=P.current;if(!C)return;C.focus();let A=re.current??Uo(C);Ot(C,A)},[r]),Na(()=>{let g=Y.current,k=l?.id??"";if(Y.current=k,!k||k===g||v==null)return;let C=P.current;C&&Ot(C,v)},[l,v]);let D=he(()=>{let g=P.current;if(!g)return;let k=At(g),A=k.length>0&&k[0]!==k[0].toUpperCase()?k[0].toUpperCase()+k.slice(1):k;if(B.current){ae(A);return}R(A)},[R,ae]),c=he(()=>{I.current=performance.now(),D();let g=P.current;g&&z(Rt(g))},[D,z]);aa(()=>{let g=P.current;if(!g)return;let k=C=>{let A=C,L=A.inputType;if(L==="insertParagraph"||L==="insertLineBreak"||L==="insertFromDrop"){C.preventDefault();return}if(L.startsWith("insert")||L.startsWith("delete")){let j=L.startsWith("delete")?"":A.data??"";te(j)&&C.preventDefault()}};return g.addEventListener("beforeinput",k),()=>g.removeEventListener("beforeinput",k)},[te]);let S=he(()=>{B.current=!0,P.current?.setAttribute("data-aia-composing","true")},[]),He=he(()=>{B.current=!1,P.current?.removeAttribute("data-aia-composing"),D()},[D]),xe=he(g=>{g.preventDefault();let k=P.current;if(!k)return;let C=(g.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!C)return;let A=k.ownerDocument??document,L=A.getSelection();if(!L||L.rangeCount===0)return;let j=L.getRangeAt(0);if(!k.contains(j.startContainer))return;j.deleteContents();let ie=A.createTextNode(C);j.insertNode(ie),j.setStartAfter(ie),j.collapse(!0),L.removeAllRanges(),L.addRange(j),D()},[D]),f=he(g=>T(g),[T]),Be=he(()=>Q(!0),[Q]),ye=he(()=>Q(!1),[Q]),Oe=he(()=>P.current?.focus(),[]),Le=he(()=>P.current?.blur(),[]),ze=he(()=>{let g=P.current;return g?At(g):""},[]),ke=jo()?"plaintext-only":"true";return{inputRef:P,editorProps:{ref:P,contentEditable:ke,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":E,"aria-expanded":x,"aria-activedescendant":q,spellCheck:!0,enterKeyHint:"send",onInput:c,onKeyDown:f,onCompositionStart:S,onCompositionEnd:He,onPaste:xe,onFocus:Be,onBlur:ye},getPlainText:ze,focus:Oe,blur:Le}}import{jsx as oa,jsxs as Ha}from"react/jsx-runtime";function nn(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var rn=$o(function({onSubmit:n,onResult:a,onError:t,optionOverrides:o,maskCompletedText:s,className:r,apiConfig:l,additionalContext:w,language:v,currency:y,productId:b,visitorId:h,columns:p,pillPlacement:x="dropdown",mode:E="auto",optionsPosition:q="below",animations:M=!0,optionsStyle:R="floating",dropdownTrigger:ae,closeDropdownOnBlur:T,prependPlaceholder:z,allOption:U,showNonTappableOptions:F,locationSearch:te,showOptionIcons:Q=!0,showChipIcons:P=!0,showChipImages:B=!0,showChipRemove:W=!1,showOptionImages:Y=!0,showOptionCounts:re=!0,showSkipButton:I,showProducts:D,productsLayout:c,productImageFallback:S,autoFocus:He=!0,onFocus:xe,onBlur:f,value:Be,completedParams:ye,onChange:Oe,onParamsChange:Le,products:ze,mapProducts:ke,onProductSelect:g,onProductAddToCart:k,submitButton:C,resetOnSubmit:A=!0,seeAllResults:L=!1},j){let ie=ia(null),ue=ia(null),de=ia(null),We=ia(()=>{}),$=ia(null),Ce=ia(null);Fa(()=>{let H=ie.current;if(H)return $.current?$.current.setMode(E):$.current=new en(H,E),()=>{$.current?.destroy(),$.current=null}},[E]);let Ge=ka(H=>{let oe=Ce.current?.current;oe&&(oe.focus(),an(oe,H))},[]),{completedParams:na,suggestionPills:me,setActivePill:Ye,skipActivePill:De,segments:m,newParamId:Se,clearNewParamId:Ke,placeholderText:i,isFocused:u,isDropdownOpen:Te,isActivePillSelected:Pe,isLoading:ge,isReady:Ie,activeIndex:Me,listboxId:fe,handleTextChange:ra,handleCompositionText:Ee,handleKeyDown:be,setFocused:Ne,editingParam:qe,editingIdentified:je,editingAnchor:Ae,caretOffset:_e,startEditingParam:d,removeParam:G,handleCaretAfterInput:N,handleCaretMove:$e,replaceEditingRange:O,dropdownProps:Ba,reset:ma,refreshProducts:Wa,prepareSubmit:Ga,getState:Ka,recordSubmit:qa}=Ma({onSubmit:H=>We.current(H),onResult:a,onError:t,optionOverrides:o,maskCompletedText:s,apiConfig:l,additionalContext:w,language:v,currency:y,productId:b,visitorId:h,columns:p,dropdownTrigger:ae,optionsPosition:q,closeDropdownOnBlur:T,prependPlaceholder:z,allOption:U,showNonTappableOptions:F,locationSearch:te,showOptionIcons:Q,showOptionImages:Y,showOptionCounts:re,showSkipButton:I,showProducts:D,onFocus:xe,onBlur:f,value:Be,completedParams:ye,onChange:Oe,onParamsChange:Le,products:ze,mapProducts:ke,onProductSelect:g,onProductAddToCart:k,source:"full-sdk",setCursor:Ge});Fa(()=>{if(!Se)return;let H=window.setTimeout(()=>Ke(),650);return()=>window.clearTimeout(H)},[Se,Ke]);let zt=Me>=0?`${fe}-option-${Me}`:void 0,{inputRef:Ca,editorProps:Dt,focus:ga,blur:_a,getPlainText:Va}=Lt({segments:m,newParamId:Se,editingParam:qe,editingIdentified:je,editingAnchor:Ae,caretOffset:_e,placeholderText:i,hintSuggestions:x==="inline"?[]:me,isFocused:u,showChipIcons:P,showChipImages:B,showChipRemove:W,removeParam:G,isDropdownOpen:Te,listboxId:fe,activeDescendantId:zt,autoFocus:He,handleTextChange:ra,handleCompositionText:Ee,handleKeyDown:be,handleCaretAfterInput:N,handleCaretMove:$e,startEditingParam:d,replaceEditingRange:O,setFocused:Ne});Ce.current=Ca,Xo(()=>{let H=ue.current,oe=Ca.current;if(!H||!oe)return;let la=()=>{let Qa=H.firstElementChild;if(!Qa)return;let Wt=Qa.getBoundingClientRect(),Gt=oe.getBoundingClientRect();Wt.top>=Gt.bottom-2?H.setAttribute("data-aia-pill-wrapped",""):H.removeAttribute("data-aia-pill-wrapped")};la();let Ua=new ResizeObserver(la);return Ua.observe(oe),()=>Ua.disconnect()},[m,me.length,ge,Ca]),Fa(()=>{let H=de.current;if(H)return on(H)},[]),Zo(j,()=>({focus:ga,blur:_a,reset:ma,refreshProducts:Wa,setMode:H=>$.current?.setMode(H),skipActivePill:De}),[ga,_a,ma,Wa,De]);let Ze=!!m.length||na.length>0,sa=ka(H=>{if(!Ze)return;H&&Ga();let oe=Ka(),la=Jo(Va(),oe.completedParams,oe.skippedParams,{identifiedParams:oe.identifiedParams,isReady:oe.isReady,customFields:oe.customFields});H&&qa(la),n(la),A&&ma()},[qa,A,Ze,Ga,Ka,n,ma,Va]);We.current=()=>sa(!1);let Mt=L&&!Ba.isInputEmpty&&Ze,Nt=ka(()=>sa(!0),[sa]),Ft=ka(H=>{H.target?.closest("[data-aia-pill]")||document.activeElement?.closest("[data-aia-location]")||ga()},[ga]),Ht=x==="inline",Bt=x==="dropdown";return Ha("div",{ref:ie,className:`magicx-aia ${Ve.container} ${r??""}`,"data-pill-placement":x,"data-options-position":q,"data-animations":M?"on":"off","data-aia-options-style":R,"data-mode":nn(E),children:[oa(za,{...Ba,showPills:Bt,productsLayout:c,productImageFallback:S,onSeeAllResults:Mt?Nt:void 0,fullWidth:L}),Ha("div",{className:Ve.inputWrapper,"data-aia-input-wrapper":"",onClick:Ft,children:[Ha("div",{ref:de,className:Ve.editorArea,"data-aia-editor":"",children:[oa("div",{...Dt,className:Ve.input,"data-aia-input":""}),Ht&&(ge||me.length>0)&&oa("span",{ref:ue,className:Ve.pillListContainer,"data-aia-pill-list-container":"",children:oa(ba,{pills:me,activePillIndex:0,activeSelected:Pe,onSelectPill:Ye,loading:ge})})]}),C===null?null:C===void 0?oa(kt,{disabled:!Ze,ready:Ze&&Ie,onClick:()=>sa(!0),label:tn(v).submit}):oa("span",{"data-aia-submit":"","data-aia-submit-slot":"",className:Ve.submitSlot,onClick:H=>{Ze&&(H.stopPropagation(),sa(!0))},children:C})]})]})});export{rn as AIAutocomplete,za as AIAutocompleteDropdown,gs as DATE_RANGE_META_END,fs as DATE_RANGE_META_START,bs as DEFAULT_OPTION_COUNT_UNIT,Ts as LOCATION_META_KEY,zs as PRODUCT_PATH_PREFIX,qs as TIME_META_KEY,Vs as WEEKDAY_LABELS,hs as buildSubmitResult,us as cellDay,ms as cellIso,ws as dateCellMarks,vs as formatDate,xs as formatDateRange,ys as formatOptionCount,ks as formatPlace,Cs as formatTime,Ss as isoDate,Ps as monthLabel,Is as optionCountLabel,Es as optionHasImage,As as optionImageSources,Rs as optionImageSrc,Os as optionLabel,Ls as optionsShowLeadingVisuals,Ds as parseDate,Ms as parseLooseDate,Ns as parseLooseDateRange,Fs as parseTime,Hs as productFromMatchedItem,Bs as productImageSources,Ws as productsFromCustomFields,Gs as sanitizeOptionIconSvg,Ks as selectedRangeFor,Ma as useAIAutocomplete,_s as visibleDateRange,Us as withSkippedParams};
|
|
3779
3779
|
//# sourceMappingURL=index.mjs.map
|