@magicx-eng/ai-autocomplete-react 0.39.1 → 0.39.3
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 +22 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -214,6 +214,12 @@
|
|
|
214
214
|
transition: opacity var(--aia-placeholder-fade, 120ms) ease-out;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/* The core updates state only at compositionend, so the editor still reads empty during IME composition.
|
|
218
|
+
Hide the placeholder beside the composing text. */
|
|
219
|
+
.aia-input-IW-P-[data-aia-empty="true"][data-placeholder][data-aia-composing]::before {
|
|
220
|
+
content: none;
|
|
221
|
+
}
|
|
222
|
+
|
|
217
223
|
.aia-input-IW-P-[data-aia-placeholder-leaving]::before {
|
|
218
224
|
opacity: 0;
|
|
219
225
|
}
|
|
@@ -621,14 +627,20 @@
|
|
|
621
627
|
crossing it at half strength. --aia-surface is what the dropdown paints
|
|
622
628
|
itself with, so theming the surface retints the fade with it. z-index: -1
|
|
623
629
|
keeps it under the footer's own content but, via the footer's stacking
|
|
624
|
-
context, above the option rows.
|
|
630
|
+
context, above the option rows.
|
|
631
|
+
The gradient is solid from the footer's top edge, so no option shows
|
|
632
|
+
behind the hint, badge or scroll arrow. */
|
|
625
633
|
[data-aia-dropdown] [data-aia-footer]::before {
|
|
626
634
|
content: "";
|
|
627
635
|
position: absolute;
|
|
628
636
|
inset: var(--aia-footer-fade-inset, -20px 0 0);
|
|
629
637
|
z-index: -1;
|
|
630
638
|
pointer-events: none;
|
|
631
|
-
background: linear-gradient(
|
|
639
|
+
background: linear-gradient(
|
|
640
|
+
to bottom,
|
|
641
|
+
transparent,
|
|
642
|
+
var(--aia-surface, #ffffff) var(--aia-footer-fade-lead, 20px)
|
|
643
|
+
);
|
|
632
644
|
}
|
|
633
645
|
|
|
634
646
|
/* The glass surface is translucent \u2014 there's no solid color to dissolve into,
|
|
@@ -710,7 +722,11 @@
|
|
|
710
722
|
/* ...and the fade runs the other way, out of the footer and down into the list. */
|
|
711
723
|
:where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] [data-aia-footer]::before,
|
|
712
724
|
[data-aia-dropdown][data-options-position="above"] [data-aia-footer]::before {
|
|
713
|
-
background: linear-gradient(
|
|
725
|
+
background: linear-gradient(
|
|
726
|
+
to top,
|
|
727
|
+
transparent,
|
|
728
|
+
var(--aia-surface, #ffffff) var(--aia-footer-fade-lead, 20px)
|
|
729
|
+
);
|
|
714
730
|
}
|
|
715
731
|
|
|
716
732
|
/* Disable all animations when data-animations="off" */
|
|
@@ -2286,7 +2302,7 @@
|
|
|
2286
2302
|
opacity: 0;
|
|
2287
2303
|
}
|
|
2288
2304
|
}
|
|
2289
|
-
`,document.head.appendChild(e)}var te={item:"aia-item-d4vpD",content:"aia-content-T-Qba",riseIn:"aia-riseIn-etXZT",fadeIn:"aia-fadeIn-I8u35",tappable:"aia-tappable-70KcX",nonTappable:"aia-nonTappable-xSZM-",highlighted:"aia-highlighted-Hb0SU",tag:"aia-tag-e3Fwe",pressed:"aia-pressed-98o-r",pressCompress:"aia-pressCompress-ICV3q",scrollHint:"aia-scrollHint-xKXPt",skeletonPulse:"aia-skeletonPulse-plvdD",text:"aia-text-yqoh9",skeletonBarIn:"aia-skeletonBarIn-ZlEM0",parameter:"aia-parameter-Dt2zF",icon:"aia-icon-Qw938",count:"aia-count-IpYbQ",image:"aia-image-YZAbO",skeletonOut:"aia-skeletonOut-x6NRd"};var V=require("react/jsx-runtime");function Kt({option:e,isHighlighted:a,onSelect:t,onHighlight:i,onUnhighlight:o,id:r,loading:n,showIcon:p=!0,showImage:d=!0,showCount:x=!0,scrollHint:T,enterDelayMs:I=0}){let[m]=(0,fe.useState)(I),[w,E]=(0,fe.useState)(!1),B=d?(0,ie.optionImageSources)(e.image_url):[],H=B[0]??null,[Q,M]=(0,fe.useState)([]),A=B.find(D=>!Q.includes(D))??null,q=(0,fe.useMemo)(()=>!H&&p&&e.icon_svg?(0,ie.sanitizeOptionIconSvg)(e.icon_svg):null,[H,p,e.icon_svg]),K=x?(0,ie.formatOptionCount)(e.item_count):null,
|
|
2305
|
+
`,document.head.appendChild(e)}var te={item:"aia-item-d4vpD",content:"aia-content-T-Qba",riseIn:"aia-riseIn-etXZT",fadeIn:"aia-fadeIn-I8u35",tappable:"aia-tappable-70KcX",nonTappable:"aia-nonTappable-xSZM-",highlighted:"aia-highlighted-Hb0SU",tag:"aia-tag-e3Fwe",pressed:"aia-pressed-98o-r",pressCompress:"aia-pressCompress-ICV3q",scrollHint:"aia-scrollHint-xKXPt",skeletonPulse:"aia-skeletonPulse-plvdD",text:"aia-text-yqoh9",skeletonBarIn:"aia-skeletonBarIn-ZlEM0",parameter:"aia-parameter-Dt2zF",icon:"aia-icon-Qw938",count:"aia-count-IpYbQ",image:"aia-image-YZAbO",skeletonOut:"aia-skeletonOut-x6NRd"};var V=require("react/jsx-runtime");function Kt({option:e,isHighlighted:a,onSelect:t,onHighlight:i,onUnhighlight:o,id:r,loading:n,showIcon:p=!0,showImage:d=!0,showCount:x=!0,scrollHint:T,enterDelayMs:I=0}){let[m]=(0,fe.useState)(I),[w,E]=(0,fe.useState)(!1),B=d?(0,ie.optionImageSources)(e.image_url):[],H=B[0]??null,[Q,M]=(0,fe.useState)([]),A=B.find(D=>!Q.includes(D))??null,q=(0,fe.useMemo)(()=>!H&&p&&e.icon_svg?(0,ie.sanitizeOptionIconSvg)(e.icon_svg):null,[H,p,e.icon_svg]),K=x?(0,ie.formatOptionCount)(e.item_count):null,k=(0,fe.useRef)(void 0);(0,fe.useEffect)(()=>()=>clearTimeout(k.current),[]);let G=()=>{n||!e.is_tappable||w||(E(!0),t(e),clearTimeout(k.current),k.current=setTimeout(()=>E(!1),170))},Y=[te.item,a&&!n?te.highlighted:"",e.is_tappable?te.tappable:te.nonTappable,w?te.pressed:"",T?te.scrollHint:""].filter(Boolean).join(" ");return(0,V.jsx)("div",{id:r,role:"option","data-aia-option":"","data-aia-loading":n?"":void 0,"data-aia-icon":q&&e.icon?e.icon:void 0,"data-aia-image":H?"":void 0,"data-aia-item-count":K!==null?e.item_count:void 0,"aria-selected":a,className:Y,style:{[ie.OPTION_ENTER_DELAY_VAR]:`${m}ms`},tabIndex:n||!e.is_tappable?-1:0,onClick:G,onKeyDown:D=>{!n&&e.is_tappable&&(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),G())},onMouseEnter:!n&&e.is_tappable?i:void 0,onMouseLeave:o,children:(0,V.jsxs)("span",{className:te.content,children:[H&&(0,V.jsx)("span",{className:`${te.image} magicx-aia-option-image`,"aria-hidden":"true",children:(0,V.jsx)("img",{src:A??H,alt:"",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",draggable:!1,hidden:A===null,onError:()=>{A!==null&&M(D=>[...D,A])}})}),q&&(0,V.jsx)("span",{className:`${te.icon} magicx-aia-option-icon`,"aria-hidden":"true",dangerouslySetInnerHTML:{__html:q}}),(0,V.jsxs)("span",{className:te.text,children:[e.matchedText?(0,ie.highlightParts)((0,ie.optionLabel)(e),e.matchedText).map((D,le)=>D.bold?(0,V.jsx)("strong",{children:D.text},le):D.text):(0,ie.optionLabel)(e),e.parameterLabel&&(0,V.jsxs)(V.Fragment,{children:[" ",(0,V.jsx)("span",{className:`${te.parameter} magicx-aia-option-parameter`,children:e.parameterLabel})]})]}),e.tag&&(0,V.jsx)("span",{className:te.tag,children:e.tag}),K!==null&&(0,V.jsx)("span",{className:`${te.count} magicx-aia-option-count`,children:K})]})})}var yt=require("react/jsx-runtime");function fa(){let[e,a]=(0,be.useState)($.isOptionsGridMobileViewport);return(0,be.useEffect)(()=>{if(typeof window>"u"||!window.matchMedia)return;let t=window.matchMedia($.OPTIONS_GRID_MOBILE_QUERY),i=()=>a(t.matches);return i(),t.addEventListener("change",i),()=>t.removeEventListener("change",i)},[]),e}function Gt({options:e,activeIndex:a,onSelect:t,onHighlight:i,onUnhighlight:o,listboxId:r,loading:n,groupKey:p="",optionsPosition:d="below",showIcons:x=!0,showImages:T=!0,showCounts:I=!0}){let m=fa(),w=(0,be.useRef)(null),[E,B]=(0,be.useState)(null),H=(0,be.useRef)(null);(0,be.useLayoutEffect)(()=>{if(n&&(0,$.sameOptionRows)(H.current,e))return;H.current=n?null:e;let M=w.current,q=M&&!n&&(0,$.needsOptionsGridMeasurement)(e.length,m)?(0,$.measureOptionsGrid)(M):null;B(q?(0,$.planOptionsGrid)(e.length,m,q.rowWidths,q.gridWidth):null)},[e,m,n]);let Q=E??(0,$.planOptionsGrid)(e.length,m,null,null);return(0,yt.jsx)(Bt,{min:"250px",max:"1fr",gap:"0",scroll:!0,scrollResetKey:p,template:Q.template,maxHeight:Q.maxHeight,innerRef:M=>{w.current=M},"data-aia-group":p,children:e.map((M,A)=>(0,yt.jsx)(Kt,{option:M,isHighlighted:A===a,onSelect:t,onHighlight:()=>i(A),onUnhighlight:o?()=>o(A):void 0,id:`${r}-option-${A}`,loading:n,showIcon:x,showImage:T,showCount:I,scrollHint:!n&&Q.scrollHintIndices.includes(A),enterDelayMs:n?0:(0,$.optionEnterDelayMs)(A,Q.cols,e.length,d)},`${p}\0${M.text}`))})}if(typeof document<"u"&&!document.getElementById("ac-style-8414cd5f")){let e=document.createElement("style");e.id="ac-style-8414cd5f",e.textContent=`.aia-stack {
|
|
2290
2306
|
display: flex;
|
|
2291
2307
|
flex-direction: column;
|
|
2292
2308
|
gap: var(--aia-stack-space, 0.5rem);
|
|
@@ -2301,7 +2317,7 @@
|
|
|
2301
2317
|
align-items: end;
|
|
2302
2318
|
}
|
|
2303
2319
|
/* data-align="stretch" is the flex default \u2014 no rule needed. */
|
|
2304
|
-
`,document.head.appendChild(e)}var _t=require("react/jsx-runtime");function Wt({space:e,align:a="stretch",className:t,children:i,...o}){let r=e?{"--aia-stack-space":e}:void 0;return(0,_t.jsx)("div",{className:t?`aia-stack ${t}`:"aia-stack","data-align":a,style:r,...o,children:i})}var W=require("react/jsx-runtime"),ba=[159,119,164],wa=()=>{},qt=()=>{};function va(e){let a=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[t,i]=(0,j.useState)(a);if((0,j.useEffect)(()=>{if(e!=="auto"||typeof window>"u"||typeof window.matchMedia!="function")return;let o=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>i(o.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[e]),e!==void 0)return e==="auto"?t?"dark":"light":e}function xa(e,a){let t=(0,j.useRef)(null);(0,j.useEffect)(()=>{let i=e.current,o=a.current;if(!i||!o)return;let r=i.querySelector(".aia-grid[data-scroll]");if(t.current&&t.current.grid!==r&&(t.current.controller.destroy(),t.current=null),r&&!t.current){t.current={grid:r,controller:(0,ae.attachScrollArrow)({dropdown:i,grid:r,button:o})};return}t.current?.controller.update()}),(0,j.useEffect)(()=>()=>{t.current?.controller.destroy(),t.current=null},[])}function ya(e,a){let t=(0,j.useRef)(a);t.current=a;let i=(0,j.useRef)(null);(0,j.useEffect)(()=>{let o=e.current;if(o){if(!i.current){i.current=(0,ae.attachViewportFit)({dropdown:o,isOpen:()=>t.current});return}i.current.update()}}),(0,j.useEffect)(()=>()=>{i.current?.destroy(),i.current=null},[])}function lt({suggestions:e,activeIndex:a,onSelect:t,onHighlight:i,onUnhighlight:o,isOpen:r,id:n,className:p,pills:d,onPillClick:x,showPills:T=!0,onSkip:I,showSkipButton:m=!0,showOptionIcons:w=!0,showOptionImages:E=!0,showOptionCounts:B=!0,skipDisabled:H=!1,activeSelected:Q=!1,isLoading:M=!1,skeletonExiting:A=!1,isInputEmpty:q=!1,language:K,products:
|
|
2320
|
+
`,document.head.appendChild(e)}var _t=require("react/jsx-runtime");function Wt({space:e,align:a="stretch",className:t,children:i,...o}){let r=e?{"--aia-stack-space":e}:void 0;return(0,_t.jsx)("div",{className:t?`aia-stack ${t}`:"aia-stack","data-align":a,style:r,...o,children:i})}var W=require("react/jsx-runtime"),ba=[159,119,164],wa=()=>{},qt=()=>{};function va(e){let a=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[t,i]=(0,j.useState)(a);if((0,j.useEffect)(()=>{if(e!=="auto"||typeof window>"u"||typeof window.matchMedia!="function")return;let o=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>i(o.matches);return o.addEventListener("change",r),()=>o.removeEventListener("change",r)},[e]),e!==void 0)return e==="auto"?t?"dark":"light":e}function xa(e,a){let t=(0,j.useRef)(null);(0,j.useEffect)(()=>{let i=e.current,o=a.current;if(!i||!o)return;let r=i.querySelector(".aia-grid[data-scroll]");if(t.current&&t.current.grid!==r&&(t.current.controller.destroy(),t.current=null),r&&!t.current){t.current={grid:r,controller:(0,ae.attachScrollArrow)({dropdown:i,grid:r,button:o})};return}t.current?.controller.update()}),(0,j.useEffect)(()=>()=>{t.current?.controller.destroy(),t.current=null},[])}function ya(e,a){let t=(0,j.useRef)(a);t.current=a;let i=(0,j.useRef)(null);(0,j.useEffect)(()=>{let o=e.current;if(o){if(!i.current){i.current=(0,ae.attachViewportFit)({dropdown:o,isOpen:()=>t.current});return}i.current.update()}}),(0,j.useEffect)(()=>()=>{i.current?.destroy(),i.current=null},[])}function lt({suggestions:e,activeIndex:a,onSelect:t,onHighlight:i,onUnhighlight:o,isOpen:r,id:n,className:p,pills:d,onPillClick:x,showPills:T=!0,onSkip:I,showSkipButton:m=!0,showOptionIcons:w=!0,showOptionImages:E=!0,showOptionCounts:B=!0,skipDisabled:H=!1,activeSelected:Q=!1,isLoading:M=!1,skeletonExiting:A=!1,isInputEmpty:q=!1,language:K,products:k,onProductSelect:G,onProductFocusChange:Y,productsLayout:D="row",productImageFallback:le="image",formatType:Pe="options",dateView:X=null,selectedDateIso:Se=null,selectedDateRange:He=null,dateRangeStart:Ie=null,onPreviousMonth:g,onNextMonth:Ke,optionsPosition:we="below",mode:Te}){let ve=va(Te),Ee=ve!==void 0,oe=(0,j.useRef)(null),de=(0,j.useRef)(null);xa(oe,de),(0,j.useEffect)(()=>{if(oe.current)return(0,ae.containScroll)(oe.current)},[]);let l=e[0]?.options??[],f=!!(d&&d.length>0&&x),b=!!(k&&k.length>0),v=r&&(l.length>0||T&&f||M||b);ya(oe,v);let C={suggestions:e,activeIndex:a,pills:d,showPills:T,showSkipButton:m,showOptionIcons:w,showOptionImages:E,showOptionCounts:B,skipDisabled:H,activeSelected:Q,isLoading:M,skeletonExiting:A,isInputEmpty:q,products:k,formatType:Pe,dateView:X,selectedDateIso:Se,selectedDateRange:He,dateRangeStart:Ie},R=(0,j.useRef)(C);v&&(R.current=C);let h=v?C:R.current,U=(0,ae.uiStringsFor)(K),ne=h.suggestions[0],re=ne?.options??[],Ae=h.activeIndex>=0&&!!re[h.activeIndex]?.is_tappable,xe=(0,ae.labelTraditionalAutocomplete)(h.pills??[],U.keepTyping),pe=!!(xe.length>0&&x),Re=h.showPills&&pe,Ge=h.showPills&&!pe&&h.isLoading,y=Re||Ge,De=pe&&(0,ae.hasSkippablePill)(xe)&&h.showSkipButton&&!h.isInputEmpty&&!!I,Oe=xe[0]?.text,ye=(0,ae.isCalendarFormat)(h.formatType)&&h.dateView!=null,u=re.length>0&&!ye,We=re.length>0&&ye&&!h.isLoading,Qe=h.isLoading&&!u&&!We,Le=h.products??[];return(0,W.jsxs)("div",{ref:oe,id:n,role:"listbox","data-aia-dropdown":"","data-options-position":we,"data-mode":ve,"data-aia-loading":h.isLoading?"":void 0,"data-aia-skeleton-exiting":h.skeletonExiting?"":void 0,"data-aia-has-products":Le.length>0?"":void 0,className:`${Ee?"magicx-aia ":""}${ke.dropdown} ${v?ke.visible:""} ${p??""}`,onMouseDown:he=>he.preventDefault(),children:[(0,W.jsxs)(Wt,{space:"8px",children:[(y||De)&&(0,W.jsxs)($e,{noWrap:!0,className:ke.pillBar,"data-aia-pillbar":"",children:[y&&(0,W.jsx)("span",{className:ke.pillScroll,"data-aia-pill-scroll":"",children:(0,W.jsx)(rt,{pills:xe,activePillIndex:0,activeSelected:h.activeSelected,onSelectPill:x??(()=>{}),rounded:!0,loading:h.isLoading})}),De&&(0,W.jsx)("button",{type:"button",tabIndex:-1,className:ke.skip,"data-aia-skip":"",disabled:h.isLoading||h.skipDisabled,"aria-label":Oe?`${U.skipLabel} ${Oe}`:U.skipLabel,onClick:I,children:U.skip})]}),u&&(0,W.jsx)(Gt,{options:re,activeIndex:h.activeIndex,onSelect:t,onHighlight:i,onUnhighlight:o,listboxId:n,loading:h.isLoading,groupKey:ne?`${ne.parameter} ${ne.text}`:"",optionsPosition:we,showIcons:h.showOptionIcons,showImages:h.showOptionImages,showCounts:h.showOptionCounts}),We&&h.dateView&&(0,W.jsx)(Dt,{options:re,activeIndex:h.activeIndex,listboxId:n,view:h.dateView,selection:{selectedIso:h.selectedDateIso??null,selectedRange:h.selectedDateRange??null,rangeStart:h.dateRangeStart??null},onSelect:t,onHighlight:i,onUnhighlight:o,onPreviousMonth:g??qt,onNextMonth:Ke??qt}),Qe&&(0,W.jsx)("div",{className:ke.skeletonBars,"data-aia-skeleton-bars":"",children:ba.map(he=>(0,W.jsx)("span",{className:ke.skeletonBar,style:{width:he}},`bar-${he}`))}),(0,W.jsx)(Nt,{products:Le,listboxId:n,onSelect:G??wa,onFocusChange:Y,focusable:v,layout:D,imageFallback:le,strings:U}),(0,W.jsx)(Ot,{isOptionHighlighted:Ae,isInputEmpty:h.isInputEmpty,strings:U})]}),(0,W.jsx)("button",{ref:de,type:"button",tabIndex:-1,className:ke.scrollArrow,"data-aia-scroll-arrow":"","aria-label":U.scrollArrow,"aria-hidden":"true",children:(0,W.jsx)("svg",{viewBox:"0 0 16 16",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",children:(0,W.jsx)("path",{d:"M4 6.5 8 10.5l4-4"})})})]})}var Be=require("@magicx-eng/ai-autocomplete-vanilla");var jt=require("@magicx-eng/ai-autocomplete-vanilla");if(typeof document<"u"&&!document.getElementById("ac-style-fdee06e6")){let e=document.createElement("style");e.id="ac-style-fdee06e6",e.textContent=`.aia-submitButton-otz7H {
|
|
2305
2321
|
flex-shrink: 0;
|
|
2306
2322
|
width: 32px;
|
|
2307
2323
|
height: 32px;
|
|
@@ -2354,5 +2370,5 @@
|
|
|
2354
2370
|
);
|
|
2355
2371
|
cursor: default;
|
|
2356
2372
|
}
|
|
2357
|
-
`,document.head.appendChild(e)}var Ut={submitButton:"aia-submitButton-otz7H"};var dt=require("react/jsx-runtime");function Qt({disabled:e,onClick:a,label:t=(0,jt.uiStringsFor)().submit}){return(0,dt.jsx)("button",{type:"button","data-aia-submit":"",className:Ut.submitButton,disabled:e,onClick:i=>{i.stopPropagation(),a()},"aria-label":t,children:(0,dt.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":t,children:(0,dt.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}var Fe=require("@magicx-eng/ai-autocomplete-vanilla"),C=require("react");var kt=require("react");function Yt(e){let a=(0,kt.useRef)(e);a.current=e;let t=Object.keys(e??{}).sort().join("\0"),i=(0,kt.useRef)({key:"",overrides:void 0});if(i.current.key!==t){let o={};for(let r of Object.keys(e??{})){let n=(p,d,x)=>{let T=a.current?.[r];return T?T(p,d,x):[]};o[r]=n}i.current={key:t,overrides:e?o:void 0}}return{overrides:i.current.overrides,key:t}}var Ct=require("react");function Zt(e){let a=(0,Ct.useRef)(e);a.current=e;let t=(0,Ct.useRef)(null);t.current===null&&(t.current={fetch:(o,r)=>{let n=a.current;return n?n.fetch(o,r):Promise.reject(new Error("products config removed"))},transform:o=>a.current?.transform(o)??[],get limit(){return a.current?.limit}});let i=e!==void 0;return{config:i?t.current:void 0,enabled:i}}var ka={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,dropdownSuggestion:null,skeletonRequested:!1,skeletonExiting:!1,activeFormatType:"options",dateView:null,dateRangeStart:null,placeholderText:"",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};function ct({onSubmit:e,onResult:a,onError:t,optionOverrides:i,maskCompletedText:o,apiConfig:r,additionalContext:n,language:p,productId:d,visitorId:x,columns:T=2,dropdownTrigger:I,optionsPosition:m,closeDropdownOnBlur:w,showNonTappableOptions:E,showOptionIcons:B,showOptionImages:H,showOptionCounts:Q,showSkipButton:M,showProducts:A,productImageFallback:q="image",onFocus:K,onBlur:P,value:G,completedParams:Y,onChange:D,onParamsChange:le,products:Pe,mapProducts:X,onProductSelect:Se,source:He,setCursor:Ie}){let g=(0,C.useRef)(null),[Ke,we]=(0,C.useState)(null),Te=(0,C.useRef)(e);Te.current=e;let ve=(0,C.useRef)(a);ve.current=a;let Ee=(0,C.useRef)(t);Ee.current=t;let oe=(0,C.useRef)(D);oe.current=D;let de=(0,C.useRef)(le);de.current=le;let l=(0,C.useRef)(K);l.current=K;let f=(0,C.useRef)(P);f.current=P;let b=(0,C.useRef)(Ie);b.current=Ie;let v=(0,C.useRef)(Se);v.current=Se;let k=(0,C.useRef)(x);k.current=x;let R=(0,C.useRef)(()=>{let c=k.current;return typeof c=="function"?c():c}).current,h=Zt(Pe),U=(0,C.useRef)(X);U.current=X;let ne=(0,C.useRef)((c,J)=>{let O=U.current;return O?O(c,J):c}).current,re=X?ne:void 0,Ae=Yt(i);(0,C.useEffect)(()=>{if(typeof document>"u")return;let c=new Fe.AIAutocomplete(document.createElement("div"),{renderMode:"headless",apiConfig:r,additionalContext:n,language:p,productId:d,visitorId:R,optionOverrides:Ae.overrides,maskCompletedText:o,columns:T,dropdownTrigger:I,optionsPosition:m,closeDropdownOnBlur:w,showNonTappableOptions:E,showProducts:A,source:He,value:G,completedParams:Y,onSubmit:(...O)=>Te.current?.(...O),onResult:(...O)=>ve.current?.(...O),onError:(...O)=>Ee.current?.(...O),onChange:(...O)=>oe.current?.(...O),onParamsChange:(...O)=>de.current?.(...O),onFocus:()=>l.current?.(),onBlur:()=>f.current?.(),onProductSelect:O=>v.current?.(O),setCursor:O=>b.current?.(O),products:h.config,mapProducts:re});g.current=c,we(c.getState());let J=c.subscribe(O=>we(O));return()=>{J(),c.destroy(),g.current===c&&(g.current=null)}},[]),(0,C.useEffect)(()=>{G!==void 0&&g.current?.setValue(G)},[G]),(0,C.useEffect)(()=>{Y!==void 0&&g.current?.setCompletedParams(Y)},[Y]);let xe=JSON.stringify(r??null),pe;try{pe=JSON.stringify(n??null)}catch{pe="[unstringifiable]"}(0,C.useEffect)(()=>{g.current?.update({apiConfig:r,additionalContext:n,language:p,productId:d,optionOverrides:Ae.overrides,dropdownTrigger:I,optionsPosition:m,closeDropdownOnBlur:w,showNonTappableOptions:E,showProducts:A})},[xe,pe,p,d,Ae.key,I,m,w,E,A]);let Re=(0,C.useRef)(!1);(0,C.useEffect)(()=>{if(!Re.current){Re.current=!0;return}g.current?.update({products:h.config})},[h.enabled]),(0,C.useEffect)(()=>{g.current?.update({mapProducts:re})},[re]);let Ge=(0,C.useRef)(null);Ge.current===null&&(Ge.current={handleTextChange:c=>g.current?.handleTextChange(c),handleKeyDown:c=>{let J="nativeEvent"in c?c.nativeEvent:c;g.current?.handleKeyDown(J)},setFocused:c=>g.current?.setFocused(c),startEditingParam:c=>g.current?.startEditingParam(c),exitEditMode:()=>g.current?.exitEditMode(),handleCaretAfterInput:c=>g.current?.handleCaretAfterInput(c),handleCaretMove:c=>g.current?.handleCaretMove(c),replaceEditingRange:c=>g.current?.replaceEditingRange(c)??!1,setActivePill:c=>g.current?.setActivePill(c),skipActivePill:()=>g.current?.skipActivePill(),removeLastParam:()=>g.current?.removeLastParam(),clearNewParamId:()=>g.current?.clearNewParamId(),reset:()=>g.current?.reset(),refreshProducts:()=>g.current?.refreshProducts(),recordSubmit:c=>g.current?.recordSubmit(c),selectOption:c=>g.current?.selectOption(c),selectProduct:c=>g.current?.selectProduct(c),setActiveDropdownIndex:c=>g.current?.setActiveDropdownIndex(c),clearHighlight:c=>g.current?.clearHighlight(c),showPreviousMonth:()=>g.current?.showPreviousMonth(),showNextMonth:()=>g.current?.showNextMonth(),handleFocus:()=>g.current?.setFocused(!0),handleBlur:()=>g.current?.setFocused(!1)});let y=Ge.current,De=(0,C.useCallback)(c=>{let J=c.target.value,gt=J.length>0&&!c.nativeEvent?.isComposing&&J[0]!==J[0].toUpperCase()?J[0].toUpperCase()+J.slice(1):J;g.current?.handleTextChange(gt)},[]),Oe=(0,C.useCallback)(c=>{g.current?.handleKeyDown(c.nativeEvent)},[]),ye=g.current,u=Ke??ka,We=G!==void 0?G:u.text,Qe=Y!==void 0?Y:u.completedParams,Le=u.actionableSuggestions,he=Le[0],Je=(0,Fe.withoutTraditionalAutocomplete)(Le),_e=ye?.listboxId??"",ht=u.activeDropdownIndex>=0&&ye?`${_e}-option-${u.activeDropdownIndex}`:void 0,ze=u.editingParam,qe=u.editingIdentified,Ye=ze?{parameter:ze.suggestionParameter,text:ze.suggestionPlaceholder,required:!0,options:ze.options}:qe?{parameter:qe.parameter,text:(0,Fe.identifiedParamLabel)(qe.parameter),required:!0,options:[]}:null,et=u.dropdownSuggestion??Ye??he,ut=Ye?[Ye]:Le,Ze=(0,Fe.dateSelectionFor)(u),tt=!ye||u.dropdownLoading;return{completedParams:Qe,skippedParams:u.skippedParams,identifiedParams:u.identifiedParams,suggestionPills:Je,setActivePill:y.setActivePill,skipActivePill:y.skipActivePill,removeLastParam:y.removeLastParam,segments:u.segments,newParamId:u.newParamId,clearNewParamId:y.clearNewParamId,suggestions:u.suggestions,activeIndex:u.activeDropdownIndex,isReady:u.isReady,isLoading:tt,isFocused:u.isFocused,isDropdownOpen:u.isDropdownOpen,isActivePillSelected:u.isActivePillSelected,placeholderText:u.placeholderText,listboxId:_e,error:u.error,products:u.products,customFields:u.customFields,selectProduct:y.selectProduct,handleTextChange:y.handleTextChange,handleKeyDown:y.handleKeyDown,setFocused:y.setFocused,editingParam:ze,editingIdentified:qe,editingAnchor:u.editingAnchor,caretOffset:u.caretOffset,startEditingParam:y.startEditingParam,exitEditMode:y.exitEditMode,handleCaretAfterInput:y.handleCaretAfterInput,handleCaretMove:y.handleCaretMove,replaceEditingRange:y.replaceEditingRange,inputProps:{value:We,placeholder:u.placeholderText||void 0,onChange:De,onKeyDown:Oe,onFocus:y.handleFocus,onBlur:y.handleBlur,role:"combobox","aria-expanded":u.isDropdownOpen,"aria-activedescendant":ht,"aria-autocomplete":"list","aria-controls":_e},reset:y.reset,refreshProducts:y.refreshProducts,recordSubmit:y.recordSubmit,dropdownProps:{suggestions:et?[{...et,options:u.dropdownOptions}]:[],activeIndex:u.activeDropdownIndex,onSelect:y.selectOption,onHighlight:y.setActiveDropdownIndex,onUnhighlight:y.clearHighlight,isOpen:u.isDropdownOpen,id:_e,pills:ut,activeSelected:u.isActivePillSelected,onPillClick:y.setActivePill,onSkip:y.skipActivePill,showSkipButton:(M??!0)&&!ze&&!qe,showOptionIcons:B??!0,showOptionImages:H??!0,showOptionCounts:Q??!0,skipDisabled:u.inSelectionAnimation,isLoading:tt,skeletonExiting:u.skeletonExiting,isInputEmpty:We.trim().length===0,language:p,products:u.products,productImageFallback:q,onProductSelect:y.selectProduct,onProductFocusChange:y.setFocused,formatType:u.activeFormatType,dateView:u.dateView,selectedDateIso:Ze.selectedIso,selectedDateRange:Ze.selectedRange,dateRangeStart:Ze.rangeStart,onPreviousMonth:y.showPreviousMonth,onNextMonth:y.showNextMonth,optionsPosition:m??"below"}}}var _=require("@magicx-eng/ai-autocomplete-vanilla"),S=require("react"),pt;function Ca(){if(pt!==void 0)return pt;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),pt=e.contentEditable==="plaintext-only",pt}function Vt(e){let{segments:a,showChipIcons:t=!0,showChipImages:i=!0,newParamId:o,editingParam:r,editingIdentified:n,editingAnchor:p,caretOffset:d,placeholderText:x,isFocused:T,isDropdownOpen:I,listboxId:m,activeDescendantId:w,autoFocus:E,handleTextChange:B,handleKeyDown:H,handleCaretAfterInput:Q,handleCaretMove:M,startEditingParam:A,replaceEditingRange:q,setFocused:K}=e,P=(0,S.useRef)(null),G=(0,S.useRef)(!1),Y=(0,S.useRef)(""),D=(0,S.useRef)(""),le=(0,S.useRef)(null),Pe=(0,S.useRef)(0);le.current=d,(0,S.useEffect)(()=>{if(!E)return;let l=P.current;if(!l)return;document.activeElement===l?K(!0):l.focus();let f=l.ownerDocument??document,b=f.getSelection(),v=b&&b.rangeCount>0&&l.contains(b.anchorNode);if(b&&!v){let k=f.createRange();k.selectNodeContents(l),k.collapse(!0),b.removeAllRanges(),b.addRange(k)}},[E,K]),(0,S.useEffect)(()=>{let l=P.current;if(!l)return;let f=l.ownerDocument??document,b=()=>{let v=f.getSelection();if(!v||v.rangeCount===0||!v.anchorNode||!l.contains(v.anchorNode))return;let k=v.anchorNode,R=k.nodeType===Node.ELEMENT_NODE?k:k.parentElement,U=(v.isCollapsed?R?.closest("strong[data-param-id]"):null)?.dataset.paramId??null,ne=r?.id??n?.id??null;if(U&&U!==ne){A(U);return}performance.now()-Pe.current<50||M((0,_.getCursorOffset)(l))};return f.addEventListener("selectionchange",b),()=>f.removeEventListener("selectionchange",b)},[r,n,A,M]),(0,S.useEffect)(()=>{let l=P.current;if(!l)return;let f=b=>{let v=(0,_.chipIdFromTap)(l,b.target);v&&(A(v),(0,_.keepCaretOnChip)(l,v))};return l.addEventListener("click",f),()=>l.removeEventListener("click",f)},[A]),(0,S.useLayoutEffect)(()=>{let l=P.current;l&&(0,_.renderEditableContent)({input:l,segments:a,newParamId:o,editingParamId:r?.id??null,placeholderText:x??"",isFocused:T,showChipIcons:t,showChipImages:i})},[a,o,r,x,T,t,i]),(0,S.useLayoutEffect)(()=>{let l=Y.current,f=o??"";if(Y.current=f,!f||f===l)return;let b=P.current;if(!b)return;b.focus();let v=le.current??(0,_.plainTextLength)(b);(0,_.setCursorOffset)(b,v)},[o]),(0,S.useLayoutEffect)(()=>{let l=D.current,f=r?.id??"";if(D.current=f,!f||f===l||p==null)return;let b=P.current;b&&(0,_.setCursorOffset)(b,p)},[r,p]);let X=(0,S.useCallback)(()=>{if(G.current)return;let l=P.current;if(!l)return;let f=(0,_.extractPlainText)(l),v=f.length>0&&f[0]!==f[0].toUpperCase()?f[0].toUpperCase()+f.slice(1):f;B(v)},[B]),Se=(0,S.useCallback)(()=>{Pe.current=performance.now(),X();let l=P.current;l&&Q((0,_.getCursorOffset)(l))},[X,Q]);(0,S.useEffect)(()=>{let l=P.current;if(!l)return;let f=b=>{let v=b,k=v.inputType;if(k==="insertParagraph"||k==="insertLineBreak"||k==="insertFromDrop"){b.preventDefault();return}if(k.startsWith("insert")||k.startsWith("delete")){let R=k.startsWith("delete")?"":v.data??"";q(R)&&b.preventDefault()}};return l.addEventListener("beforeinput",f),()=>l.removeEventListener("beforeinput",f)},[q]);let He=(0,S.useCallback)(()=>{G.current=!0},[]),Ie=(0,S.useCallback)(()=>{G.current=!1,X()},[X]),g=(0,S.useCallback)(l=>{l.preventDefault();let f=P.current;if(!f)return;let b=(l.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!b)return;let v=f.ownerDocument??document,k=v.getSelection();if(!k||k.rangeCount===0)return;let R=k.getRangeAt(0);if(!f.contains(R.startContainer))return;R.deleteContents();let h=v.createTextNode(b);R.insertNode(h),R.setStartAfter(h),R.collapse(!0),k.removeAllRanges(),k.addRange(R),X()},[X]),Ke=(0,S.useCallback)(l=>H(l),[H]),we=(0,S.useCallback)(()=>K(!0),[K]),Te=(0,S.useCallback)(()=>K(!1),[K]),ve=(0,S.useCallback)(()=>P.current?.focus(),[]),Ee=(0,S.useCallback)(()=>P.current?.blur(),[]),oe=(0,S.useCallback)(()=>{let l=P.current;return l?(0,_.extractPlainText)(l):""},[]),de=Ca()?"plaintext-only":"true";return{inputRef:P,editorProps:{ref:P,contentEditable:de,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":m,"aria-expanded":I,"aria-activedescendant":w,spellCheck:!0,enterKeyHint:"send",onInput:Se,onKeyDown:Ke,onCompositionStart:He,onCompositionEnd:Ie,onPaste:g,onFocus:we,onBlur:Te},getPlainText:oe,focus:ve,blur:Ee}}var ce=require("react/jsx-runtime");function Pa(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var $t=(0,F.forwardRef)(function({onSubmit:a,onResult:t,onError:i,optionOverrides:o,maskCompletedText:r,className:n,apiConfig:p,additionalContext:d,language:x,productId:T,visitorId:I,columns:m,pillPlacement:w="dropdown",mode:E="auto",optionsPosition:B="below",animations:H=!0,dropdownTrigger:Q,closeDropdownOnBlur:M,showNonTappableOptions:A,showOptionIcons:q=!0,showChipIcons:K=!0,showChipImages:P=!0,showOptionImages:G=!0,showOptionCounts:Y=!0,showSkipButton:D,showProducts:le,productsLayout:Pe,productImageFallback:X,autoFocus:Se=!0,onFocus:He,onBlur:Ie,value:g,completedParams:Ke,onChange:we,onParamsChange:Te,products:ve,mapProducts:Ee,onProductSelect:oe,submitButton:de,resetOnSubmit:l=!0},f){let b=(0,F.useRef)(null),v=(0,F.useRef)(null),k=(0,F.useRef)(()=>{}),R=(0,F.useRef)(null),h=(0,F.useRef)(null);(0,F.useEffect)(()=>{let L=b.current;if(L)return R.current?R.current.setMode(E):R.current=new Be.ModeController(L,E),()=>{R.current?.destroy(),R.current=null}},[E]);let U=(0,F.useCallback)(L=>{let ue=h.current?.current;ue&&(ue.focus(),(0,Be.setCursorOffset)(ue,L))},[]),{completedParams:ne,skippedParams:re,identifiedParams:Ae,isReady:xe,customFields:pe,suggestionPills:Re,setActivePill:Ge,skipActivePill:y,segments:De,newParamId:Oe,clearNewParamId:ye,placeholderText:u,isFocused:We,isDropdownOpen:Qe,isActivePillSelected:Le,isLoading:he,activeIndex:Je,listboxId:_e,handleTextChange:ht,handleKeyDown:ze,setFocused:qe,editingParam:Ye,editingIdentified:et,editingAnchor:ut,caretOffset:Ze,startEditingParam:tt,handleCaretAfterInput:c,handleCaretMove:J,replaceEditingRange:O,dropdownProps:gt,reset:at,refreshProducts:Pt,recordSubmit:St}=ct({onSubmit:L=>k.current(L),onResult:t,onError:i,optionOverrides:o,maskCompletedText:r,apiConfig:p,additionalContext:d,language:x,productId:T,visitorId:I,columns:m,dropdownTrigger:Q,optionsPosition:B,closeDropdownOnBlur:M,showNonTappableOptions:A,showOptionIcons:q,showOptionImages:G,showOptionCounts:Y,showSkipButton:D,showProducts:le,onFocus:He,onBlur:Ie,value:g,completedParams:Ke,onChange:we,onParamsChange:Te,products:ve,mapProducts:Ee,onProductSelect:oe,source:"full-sdk",setCursor:U});(0,F.useEffect)(()=>{if(!Oe)return;let L=window.setTimeout(()=>ye(),650);return()=>window.clearTimeout(L)},[Oe,ye]);let Xt=Je>=0?`${_e}-option-${Je}`:void 0,{inputRef:mt,editorProps:Jt,focus:it,blur:It,getPlainText:Tt}=Vt({segments:De,newParamId:Oe,editingParam:Ye,editingIdentified:et,editingAnchor:ut,caretOffset:Ze,placeholderText:u,isFocused:We,showChipIcons:K,showChipImages:P,isDropdownOpen:Qe,listboxId:_e,activeDescendantId:Xt,autoFocus:Se,handleTextChange:ht,handleKeyDown:ze,handleCaretAfterInput:c,handleCaretMove:J,startEditingParam:tt,replaceEditingRange:O,setFocused:qe});h.current=mt,(0,F.useLayoutEffect)(()=>{let L=v.current,ue=mt.current;if(!L||!ue)return;let Ve=()=>{let At=L.firstElementChild;if(!At)return;let ia=At.getBoundingClientRect(),oa=ue.getBoundingClientRect();ia.top>=oa.bottom-2?L.setAttribute("data-aia-pill-wrapped",""):L.removeAttribute("data-aia-pill-wrapped")};Ve();let Et=new ResizeObserver(Ve);return Et.observe(ue),()=>Et.disconnect()},[De,Re.length,he,mt]),(0,F.useImperativeHandle)(f,()=>({focus:it,blur:It,reset:at,refreshProducts:Pt,setMode:L=>R.current?.setMode(L),skipActivePill:y}),[it,It,at,Pt,y]);let ot=!!De.length||ne.length>0,ft=(0,F.useCallback)(L=>{if(!ot)return;let ue=Tt(),Ve=(0,Be.buildSubmitResult)(ue,ne,re,{identifiedParams:Ae,isReady:xe,customFields:pe});L&&St(Ve),a(Ve),l&&at()},[St,l,ot,ne,re,Ae,xe,pe,a,at,Tt]);k.current=()=>ft(!1);let ea=(0,F.useCallback)(L=>{L.target?.closest("[data-aia-pill]")||it()},[it]),ta=w==="inline",aa=w==="dropdown";return(0,ce.jsxs)("div",{ref:b,className:`magicx-aia ${Ue.container} ${n??""}`,"data-pill-placement":w,"data-options-position":B,"data-animations":H?"on":"off","data-mode":Pa(E),children:[(0,ce.jsx)(lt,{...gt,showPills:aa,productsLayout:Pe,productImageFallback:X}),(0,ce.jsxs)("div",{className:Ue.inputWrapper,"data-aia-input-wrapper":"",onClick:ea,children:[(0,ce.jsxs)("div",{className:Ue.editorArea,"data-aia-editor":"",children:[(0,ce.jsx)("div",{...Jt,className:Ue.input,"data-aia-input":""}),ta&&(he||Re.length>0)&&(0,ce.jsx)("span",{ref:v,className:Ue.pillListContainer,"data-aia-pill-list-container":"",children:(0,ce.jsx)(rt,{pills:Re,activePillIndex:0,activeSelected:Le,onSelectPill:Ge,loading:he})})]}),de===null?null:de===void 0?(0,ce.jsx)(Qt,{disabled:!ot,onClick:()=>ft(!0),label:(0,Be.uiStringsFor)(x).submit}):(0,ce.jsx)("span",{"data-aia-submit":"","data-aia-submit-slot":"",className:Ue.submitSlot,onClick:L=>{ot&&(L.stopPropagation(),ft(!0))},children:de})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,DATE_RANGE_META_END,DATE_RANGE_META_START,DEFAULT_OPTION_COUNT_UNIT,PRODUCT_PATH_PREFIX,WEEKDAY_LABELS,buildSubmitResult,cellDay,cellIso,dateCellMarks,formatDate,formatDateRange,formatOptionCount,isoDate,monthLabel,optionCountLabel,optionHasImage,optionImageSources,optionImageSrc,optionLabel,parseDate,parseLooseDate,parseLooseDateRange,productFromMatchedItem,productImageSources,productsFromCustomFields,sanitizeOptionIconSvg,selectedRangeFor,useAIAutocomplete,visibleDateRange,withSkippedParams});
|
|
2373
|
+
`,document.head.appendChild(e)}var Ut={submitButton:"aia-submitButton-otz7H"};var dt=require("react/jsx-runtime");function Qt({disabled:e,onClick:a,label:t=(0,jt.uiStringsFor)().submit}){return(0,dt.jsx)("button",{type:"button","data-aia-submit":"",className:Ut.submitButton,disabled:e,onClick:i=>{i.stopPropagation(),a()},"aria-label":t,children:(0,dt.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":t,children:(0,dt.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}var Fe=require("@magicx-eng/ai-autocomplete-vanilla"),P=require("react");var kt=require("react");function Yt(e){let a=(0,kt.useRef)(e);a.current=e;let t=Object.keys(e??{}).sort().join("\0"),i=(0,kt.useRef)({key:"",overrides:void 0});if(i.current.key!==t){let o={};for(let r of Object.keys(e??{})){let n=(p,d,x)=>{let T=a.current?.[r];return T?T(p,d,x):[]};o[r]=n}i.current={key:t,overrides:e?o:void 0}}return{overrides:i.current.overrides,key:t}}var Ct=require("react");function Zt(e){let a=(0,Ct.useRef)(e);a.current=e;let t=(0,Ct.useRef)(null);t.current===null&&(t.current={fetch:(o,r)=>{let n=a.current;return n?n.fetch(o,r):Promise.reject(new Error("products config removed"))},transform:o=>a.current?.transform(o)??[],get limit(){return a.current?.limit}});let i=e!==void 0;return{config:i?t.current:void 0,enabled:i}}var ka={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,dropdownSuggestion:null,skeletonRequested:!1,skeletonExiting:!1,activeFormatType:"options",dateView:null,dateRangeStart:null,placeholderText:"",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};function ct({onSubmit:e,onResult:a,onError:t,optionOverrides:i,maskCompletedText:o,apiConfig:r,additionalContext:n,language:p,productId:d,visitorId:x,columns:T=2,dropdownTrigger:I,optionsPosition:m,closeDropdownOnBlur:w,showNonTappableOptions:E,showOptionIcons:B,showOptionImages:H,showOptionCounts:Q,showSkipButton:M,showProducts:A,productImageFallback:q="image",onFocus:K,onBlur:k,value:G,completedParams:Y,onChange:D,onParamsChange:le,products:Pe,mapProducts:X,onProductSelect:Se,source:He,setCursor:Ie}){let g=(0,P.useRef)(null),[Ke,we]=(0,P.useState)(null),Te=(0,P.useRef)(e);Te.current=e;let ve=(0,P.useRef)(a);ve.current=a;let Ee=(0,P.useRef)(t);Ee.current=t;let oe=(0,P.useRef)(D);oe.current=D;let de=(0,P.useRef)(le);de.current=le;let l=(0,P.useRef)(K);l.current=K;let f=(0,P.useRef)(k);f.current=k;let b=(0,P.useRef)(Ie);b.current=Ie;let v=(0,P.useRef)(Se);v.current=Se;let C=(0,P.useRef)(x);C.current=x;let R=(0,P.useRef)(()=>{let c=C.current;return typeof c=="function"?c():c}).current,h=Zt(Pe),U=(0,P.useRef)(X);U.current=X;let ne=(0,P.useRef)((c,J)=>{let O=U.current;return O?O(c,J):c}).current,re=X?ne:void 0,Ae=Yt(i);(0,P.useEffect)(()=>{if(typeof document>"u")return;let c=new Fe.AIAutocomplete(document.createElement("div"),{renderMode:"headless",apiConfig:r,additionalContext:n,language:p,productId:d,visitorId:R,optionOverrides:Ae.overrides,maskCompletedText:o,columns:T,dropdownTrigger:I,optionsPosition:m,closeDropdownOnBlur:w,showNonTappableOptions:E,showProducts:A,source:He,value:G,completedParams:Y,onSubmit:(...O)=>Te.current?.(...O),onResult:(...O)=>ve.current?.(...O),onError:(...O)=>Ee.current?.(...O),onChange:(...O)=>oe.current?.(...O),onParamsChange:(...O)=>de.current?.(...O),onFocus:()=>l.current?.(),onBlur:()=>f.current?.(),onProductSelect:O=>v.current?.(O),setCursor:O=>b.current?.(O),products:h.config,mapProducts:re});g.current=c,we(c.getState());let J=c.subscribe(O=>we(O));return()=>{J(),c.destroy(),g.current===c&&(g.current=null)}},[]),(0,P.useEffect)(()=>{G!==void 0&&g.current?.setValue(G)},[G]),(0,P.useEffect)(()=>{Y!==void 0&&g.current?.setCompletedParams(Y)},[Y]);let xe=JSON.stringify(r??null),pe;try{pe=JSON.stringify(n??null)}catch{pe="[unstringifiable]"}(0,P.useEffect)(()=>{g.current?.update({apiConfig:r,additionalContext:n,language:p,productId:d,optionOverrides:Ae.overrides,dropdownTrigger:I,optionsPosition:m,closeDropdownOnBlur:w,showNonTappableOptions:E,showProducts:A})},[xe,pe,p,d,Ae.key,I,m,w,E,A]);let Re=(0,P.useRef)(!1);(0,P.useEffect)(()=>{if(!Re.current){Re.current=!0;return}g.current?.update({products:h.config})},[h.enabled]),(0,P.useEffect)(()=>{g.current?.update({mapProducts:re})},[re]);let Ge=(0,P.useRef)(null);Ge.current===null&&(Ge.current={handleTextChange:c=>g.current?.handleTextChange(c),handleKeyDown:c=>{let J="nativeEvent"in c?c.nativeEvent:c;g.current?.handleKeyDown(J)},setFocused:c=>g.current?.setFocused(c),startEditingParam:c=>g.current?.startEditingParam(c),exitEditMode:()=>g.current?.exitEditMode(),handleCaretAfterInput:c=>g.current?.handleCaretAfterInput(c),handleCaretMove:c=>g.current?.handleCaretMove(c),replaceEditingRange:c=>g.current?.replaceEditingRange(c)??!1,setActivePill:c=>g.current?.setActivePill(c),skipActivePill:()=>g.current?.skipActivePill(),removeLastParam:()=>g.current?.removeLastParam(),clearNewParamId:()=>g.current?.clearNewParamId(),reset:()=>g.current?.reset(),refreshProducts:()=>g.current?.refreshProducts(),recordSubmit:c=>g.current?.recordSubmit(c),selectOption:c=>g.current?.selectOption(c),selectProduct:c=>g.current?.selectProduct(c),setActiveDropdownIndex:c=>g.current?.setActiveDropdownIndex(c),clearHighlight:c=>g.current?.clearHighlight(c),showPreviousMonth:()=>g.current?.showPreviousMonth(),showNextMonth:()=>g.current?.showNextMonth(),handleFocus:()=>g.current?.setFocused(!0),handleBlur:()=>g.current?.setFocused(!1)});let y=Ge.current,De=(0,P.useCallback)(c=>{let J=c.target.value,gt=J.length>0&&!c.nativeEvent?.isComposing&&J[0]!==J[0].toUpperCase()?J[0].toUpperCase()+J.slice(1):J;g.current?.handleTextChange(gt)},[]),Oe=(0,P.useCallback)(c=>{g.current?.handleKeyDown(c.nativeEvent)},[]),ye=g.current,u=Ke??ka,We=G!==void 0?G:u.text,Qe=Y!==void 0?Y:u.completedParams,Le=u.actionableSuggestions,he=Le[0],Je=(0,Fe.withoutTraditionalAutocomplete)(Le),_e=ye?.listboxId??"",ht=u.activeDropdownIndex>=0&&ye?`${_e}-option-${u.activeDropdownIndex}`:void 0,ze=u.editingParam,qe=u.editingIdentified,Ye=ze?{parameter:ze.suggestionParameter,text:ze.suggestionPlaceholder,required:!0,options:ze.options}:qe?{parameter:qe.parameter,text:(0,Fe.identifiedParamLabel)(qe.parameter),required:!0,options:[]}:null,et=u.dropdownSuggestion??Ye??he,ut=Ye?[Ye]:Le,Ze=(0,Fe.dateSelectionFor)(u),tt=!ye||u.dropdownLoading;return{completedParams:Qe,skippedParams:u.skippedParams,identifiedParams:u.identifiedParams,suggestionPills:Je,setActivePill:y.setActivePill,skipActivePill:y.skipActivePill,removeLastParam:y.removeLastParam,segments:u.segments,newParamId:u.newParamId,clearNewParamId:y.clearNewParamId,suggestions:u.suggestions,activeIndex:u.activeDropdownIndex,isReady:u.isReady,isLoading:tt,isFocused:u.isFocused,isDropdownOpen:u.isDropdownOpen,isActivePillSelected:u.isActivePillSelected,placeholderText:u.placeholderText,listboxId:_e,error:u.error,products:u.products,customFields:u.customFields,selectProduct:y.selectProduct,handleTextChange:y.handleTextChange,handleKeyDown:y.handleKeyDown,setFocused:y.setFocused,editingParam:ze,editingIdentified:qe,editingAnchor:u.editingAnchor,caretOffset:u.caretOffset,startEditingParam:y.startEditingParam,exitEditMode:y.exitEditMode,handleCaretAfterInput:y.handleCaretAfterInput,handleCaretMove:y.handleCaretMove,replaceEditingRange:y.replaceEditingRange,inputProps:{value:We,placeholder:u.placeholderText||void 0,onChange:De,onKeyDown:Oe,onFocus:y.handleFocus,onBlur:y.handleBlur,role:"combobox","aria-expanded":u.isDropdownOpen,"aria-activedescendant":ht,"aria-autocomplete":"list","aria-controls":_e},reset:y.reset,refreshProducts:y.refreshProducts,recordSubmit:y.recordSubmit,dropdownProps:{suggestions:et?[{...et,options:u.dropdownOptions}]:[],activeIndex:u.activeDropdownIndex,onSelect:y.selectOption,onHighlight:y.setActiveDropdownIndex,onUnhighlight:y.clearHighlight,isOpen:u.isDropdownOpen,id:_e,pills:ut,activeSelected:u.isActivePillSelected,onPillClick:y.setActivePill,onSkip:y.skipActivePill,showSkipButton:(M??!0)&&!ze&&!qe,showOptionIcons:B??!0,showOptionImages:H??!0,showOptionCounts:Q??!0,skipDisabled:u.inSelectionAnimation,isLoading:tt,skeletonExiting:u.skeletonExiting,isInputEmpty:We.trim().length===0,language:p,products:u.products,productImageFallback:q,onProductSelect:y.selectProduct,onProductFocusChange:y.setFocused,formatType:u.activeFormatType,dateView:u.dateView,selectedDateIso:Ze.selectedIso,selectedDateRange:Ze.selectedRange,dateRangeStart:Ze.rangeStart,onPreviousMonth:y.showPreviousMonth,onNextMonth:y.showNextMonth,optionsPosition:m??"below"}}}var _=require("@magicx-eng/ai-autocomplete-vanilla"),S=require("react"),pt;function Ca(){if(pt!==void 0)return pt;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),pt=e.contentEditable==="plaintext-only",pt}function Vt(e){let{segments:a,showChipIcons:t=!0,showChipImages:i=!0,newParamId:o,editingParam:r,editingIdentified:n,editingAnchor:p,caretOffset:d,placeholderText:x,isFocused:T,isDropdownOpen:I,listboxId:m,activeDescendantId:w,autoFocus:E,handleTextChange:B,handleKeyDown:H,handleCaretAfterInput:Q,handleCaretMove:M,startEditingParam:A,replaceEditingRange:q,setFocused:K}=e,k=(0,S.useRef)(null),G=(0,S.useRef)(!1),Y=(0,S.useRef)(""),D=(0,S.useRef)(""),le=(0,S.useRef)(null),Pe=(0,S.useRef)(0);le.current=d,(0,S.useEffect)(()=>{if(!E)return;let l=k.current;if(!l)return;document.activeElement===l?K(!0):l.focus();let f=l.ownerDocument??document,b=f.getSelection(),v=b&&b.rangeCount>0&&l.contains(b.anchorNode);if(b&&!v){let C=f.createRange();C.selectNodeContents(l),C.collapse(!0),b.removeAllRanges(),b.addRange(C)}},[E,K]),(0,S.useEffect)(()=>{let l=k.current;if(!l)return;let f=l.ownerDocument??document,b=()=>{let v=f.getSelection();if(!v||v.rangeCount===0||!v.anchorNode||!l.contains(v.anchorNode))return;let C=v.anchorNode,R=C.nodeType===Node.ELEMENT_NODE?C:C.parentElement,U=(v.isCollapsed?R?.closest("strong[data-param-id]"):null)?.dataset.paramId??null,ne=r?.id??n?.id??null;if(U&&U!==ne){A(U);return}performance.now()-Pe.current<50||M((0,_.getCursorOffset)(l))};return f.addEventListener("selectionchange",b),()=>f.removeEventListener("selectionchange",b)},[r,n,A,M]),(0,S.useEffect)(()=>{let l=k.current;if(!l)return;let f=b=>{let v=(0,_.chipIdFromTap)(l,b.target);v&&(A(v),(0,_.keepCaretOnChip)(l,v))};return l.addEventListener("click",f),()=>l.removeEventListener("click",f)},[A]),(0,S.useLayoutEffect)(()=>{let l=k.current;l&&(0,_.renderEditableContent)({input:l,segments:a,newParamId:o,editingParamId:r?.id??null,placeholderText:x??"",isFocused:T,showChipIcons:t,showChipImages:i})},[a,o,r,x,T,t,i]),(0,S.useLayoutEffect)(()=>{let l=Y.current,f=o??"";if(Y.current=f,!f||f===l)return;let b=k.current;if(!b)return;b.focus();let v=le.current??(0,_.plainTextLength)(b);(0,_.setCursorOffset)(b,v)},[o]),(0,S.useLayoutEffect)(()=>{let l=D.current,f=r?.id??"";if(D.current=f,!f||f===l||p==null)return;let b=k.current;b&&(0,_.setCursorOffset)(b,p)},[r,p]);let X=(0,S.useCallback)(()=>{if(G.current)return;let l=k.current;if(!l)return;let f=(0,_.extractPlainText)(l),v=f.length>0&&f[0]!==f[0].toUpperCase()?f[0].toUpperCase()+f.slice(1):f;B(v)},[B]),Se=(0,S.useCallback)(()=>{Pe.current=performance.now(),X();let l=k.current;l&&Q((0,_.getCursorOffset)(l))},[X,Q]);(0,S.useEffect)(()=>{let l=k.current;if(!l)return;let f=b=>{let v=b,C=v.inputType;if(C==="insertParagraph"||C==="insertLineBreak"||C==="insertFromDrop"){b.preventDefault();return}if(C.startsWith("insert")||C.startsWith("delete")){let R=C.startsWith("delete")?"":v.data??"";q(R)&&b.preventDefault()}};return l.addEventListener("beforeinput",f),()=>l.removeEventListener("beforeinput",f)},[q]);let He=(0,S.useCallback)(()=>{G.current=!0,k.current?.setAttribute("data-aia-composing","true")},[]),Ie=(0,S.useCallback)(()=>{G.current=!1,k.current?.removeAttribute("data-aia-composing"),X()},[X]),g=(0,S.useCallback)(l=>{l.preventDefault();let f=k.current;if(!f)return;let b=(l.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!b)return;let v=f.ownerDocument??document,C=v.getSelection();if(!C||C.rangeCount===0)return;let R=C.getRangeAt(0);if(!f.contains(R.startContainer))return;R.deleteContents();let h=v.createTextNode(b);R.insertNode(h),R.setStartAfter(h),R.collapse(!0),C.removeAllRanges(),C.addRange(R),X()},[X]),Ke=(0,S.useCallback)(l=>H(l),[H]),we=(0,S.useCallback)(()=>K(!0),[K]),Te=(0,S.useCallback)(()=>K(!1),[K]),ve=(0,S.useCallback)(()=>k.current?.focus(),[]),Ee=(0,S.useCallback)(()=>k.current?.blur(),[]),oe=(0,S.useCallback)(()=>{let l=k.current;return l?(0,_.extractPlainText)(l):""},[]),de=Ca()?"plaintext-only":"true";return{inputRef:k,editorProps:{ref:k,contentEditable:de,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":m,"aria-expanded":I,"aria-activedescendant":w,spellCheck:!0,enterKeyHint:"send",onInput:Se,onKeyDown:Ke,onCompositionStart:He,onCompositionEnd:Ie,onPaste:g,onFocus:we,onBlur:Te},getPlainText:oe,focus:ve,blur:Ee}}var ce=require("react/jsx-runtime");function Pa(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var $t=(0,F.forwardRef)(function({onSubmit:a,onResult:t,onError:i,optionOverrides:o,maskCompletedText:r,className:n,apiConfig:p,additionalContext:d,language:x,productId:T,visitorId:I,columns:m,pillPlacement:w="dropdown",mode:E="auto",optionsPosition:B="below",animations:H=!0,dropdownTrigger:Q,closeDropdownOnBlur:M,showNonTappableOptions:A,showOptionIcons:q=!0,showChipIcons:K=!0,showChipImages:k=!0,showOptionImages:G=!0,showOptionCounts:Y=!0,showSkipButton:D,showProducts:le,productsLayout:Pe,productImageFallback:X,autoFocus:Se=!0,onFocus:He,onBlur:Ie,value:g,completedParams:Ke,onChange:we,onParamsChange:Te,products:ve,mapProducts:Ee,onProductSelect:oe,submitButton:de,resetOnSubmit:l=!0},f){let b=(0,F.useRef)(null),v=(0,F.useRef)(null),C=(0,F.useRef)(()=>{}),R=(0,F.useRef)(null),h=(0,F.useRef)(null);(0,F.useEffect)(()=>{let L=b.current;if(L)return R.current?R.current.setMode(E):R.current=new Be.ModeController(L,E),()=>{R.current?.destroy(),R.current=null}},[E]);let U=(0,F.useCallback)(L=>{let ue=h.current?.current;ue&&(ue.focus(),(0,Be.setCursorOffset)(ue,L))},[]),{completedParams:ne,skippedParams:re,identifiedParams:Ae,isReady:xe,customFields:pe,suggestionPills:Re,setActivePill:Ge,skipActivePill:y,segments:De,newParamId:Oe,clearNewParamId:ye,placeholderText:u,isFocused:We,isDropdownOpen:Qe,isActivePillSelected:Le,isLoading:he,activeIndex:Je,listboxId:_e,handleTextChange:ht,handleKeyDown:ze,setFocused:qe,editingParam:Ye,editingIdentified:et,editingAnchor:ut,caretOffset:Ze,startEditingParam:tt,handleCaretAfterInput:c,handleCaretMove:J,replaceEditingRange:O,dropdownProps:gt,reset:at,refreshProducts:Pt,recordSubmit:St}=ct({onSubmit:L=>C.current(L),onResult:t,onError:i,optionOverrides:o,maskCompletedText:r,apiConfig:p,additionalContext:d,language:x,productId:T,visitorId:I,columns:m,dropdownTrigger:Q,optionsPosition:B,closeDropdownOnBlur:M,showNonTappableOptions:A,showOptionIcons:q,showOptionImages:G,showOptionCounts:Y,showSkipButton:D,showProducts:le,onFocus:He,onBlur:Ie,value:g,completedParams:Ke,onChange:we,onParamsChange:Te,products:ve,mapProducts:Ee,onProductSelect:oe,source:"full-sdk",setCursor:U});(0,F.useEffect)(()=>{if(!Oe)return;let L=window.setTimeout(()=>ye(),650);return()=>window.clearTimeout(L)},[Oe,ye]);let Xt=Je>=0?`${_e}-option-${Je}`:void 0,{inputRef:mt,editorProps:Jt,focus:it,blur:It,getPlainText:Tt}=Vt({segments:De,newParamId:Oe,editingParam:Ye,editingIdentified:et,editingAnchor:ut,caretOffset:Ze,placeholderText:u,isFocused:We,showChipIcons:K,showChipImages:k,isDropdownOpen:Qe,listboxId:_e,activeDescendantId:Xt,autoFocus:Se,handleTextChange:ht,handleKeyDown:ze,handleCaretAfterInput:c,handleCaretMove:J,startEditingParam:tt,replaceEditingRange:O,setFocused:qe});h.current=mt,(0,F.useLayoutEffect)(()=>{let L=v.current,ue=mt.current;if(!L||!ue)return;let Ve=()=>{let At=L.firstElementChild;if(!At)return;let ia=At.getBoundingClientRect(),oa=ue.getBoundingClientRect();ia.top>=oa.bottom-2?L.setAttribute("data-aia-pill-wrapped",""):L.removeAttribute("data-aia-pill-wrapped")};Ve();let Et=new ResizeObserver(Ve);return Et.observe(ue),()=>Et.disconnect()},[De,Re.length,he,mt]),(0,F.useImperativeHandle)(f,()=>({focus:it,blur:It,reset:at,refreshProducts:Pt,setMode:L=>R.current?.setMode(L),skipActivePill:y}),[it,It,at,Pt,y]);let ot=!!De.length||ne.length>0,ft=(0,F.useCallback)(L=>{if(!ot)return;let ue=Tt(),Ve=(0,Be.buildSubmitResult)(ue,ne,re,{identifiedParams:Ae,isReady:xe,customFields:pe});L&&St(Ve),a(Ve),l&&at()},[St,l,ot,ne,re,Ae,xe,pe,a,at,Tt]);C.current=()=>ft(!1);let ea=(0,F.useCallback)(L=>{L.target?.closest("[data-aia-pill]")||it()},[it]),ta=w==="inline",aa=w==="dropdown";return(0,ce.jsxs)("div",{ref:b,className:`magicx-aia ${Ue.container} ${n??""}`,"data-pill-placement":w,"data-options-position":B,"data-animations":H?"on":"off","data-mode":Pa(E),children:[(0,ce.jsx)(lt,{...gt,showPills:aa,productsLayout:Pe,productImageFallback:X}),(0,ce.jsxs)("div",{className:Ue.inputWrapper,"data-aia-input-wrapper":"",onClick:ea,children:[(0,ce.jsxs)("div",{className:Ue.editorArea,"data-aia-editor":"",children:[(0,ce.jsx)("div",{...Jt,className:Ue.input,"data-aia-input":""}),ta&&(he||Re.length>0)&&(0,ce.jsx)("span",{ref:v,className:Ue.pillListContainer,"data-aia-pill-list-container":"",children:(0,ce.jsx)(rt,{pills:Re,activePillIndex:0,activeSelected:Le,onSelectPill:Ge,loading:he})})]}),de===null?null:de===void 0?(0,ce.jsx)(Qt,{disabled:!ot,onClick:()=>ft(!0),label:(0,Be.uiStringsFor)(x).submit}):(0,ce.jsx)("span",{"data-aia-submit":"","data-aia-submit-slot":"",className:Ue.submitSlot,onClick:L=>{ot&&(L.stopPropagation(),ft(!0))},children:de})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,DATE_RANGE_META_END,DATE_RANGE_META_START,DEFAULT_OPTION_COUNT_UNIT,PRODUCT_PATH_PREFIX,WEEKDAY_LABELS,buildSubmitResult,cellDay,cellIso,dateCellMarks,formatDate,formatDateRange,formatOptionCount,isoDate,monthLabel,optionCountLabel,optionHasImage,optionImageSources,optionImageSrc,optionLabel,parseDate,parseLooseDate,parseLooseDateRange,productFromMatchedItem,productImageSources,productsFromCustomFields,sanitizeOptionIconSvg,selectedRangeFor,useAIAutocomplete,visibleDateRange,withSkippedParams});
|
|
2358
2374
|
//# sourceMappingURL=index.js.map
|