@magicx-eng/ai-autocomplete-react 0.31.0 → 0.32.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.mjs CHANGED
@@ -262,7 +262,7 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
262
262
  opacity: 0;
263
263
  }
264
264
  }
265
- `,document.head.appendChild(e)}var ye={container:"aia-container-KKjFU",inputWrapper:"aia-inputWrapper-FLq1b",editorArea:"aia-editorArea-7rBWq",input:"aia-input-IW-P-",pillListContainer:"aia-pillListContainer-h92IA",submitSlot:"aia-submitSlot-GhuCM",aiaPillReveal:"aia-aiaPillReveal-wf05b"};import{attachScrollArrow as Ua,containScroll as ja,isCalendarFormat as Ya,SCROLL_ARROW_LABEL as Qa}from"@magicx-eng/ai-autocomplete-vanilla";import{useEffect as Ue,useRef as qe,useState as Za}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
265
+ `,document.head.appendChild(e)}var ye={container:"aia-container-KKjFU",inputWrapper:"aia-inputWrapper-FLq1b",editorArea:"aia-editorArea-7rBWq",input:"aia-input-IW-P-",pillListContainer:"aia-pillListContainer-h92IA",submitSlot:"aia-submitSlot-GhuCM",aiaPillReveal:"aia-aiaPillReveal-wf05b"};import{attachScrollArrow as Ua,containScroll as ja,isCalendarFormat as Qa,SCROLL_ARROW_LABEL as Ya}from"@magicx-eng/ai-autocomplete-vanilla";import{useEffect as Ue,useRef as qe,useState as Za}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-0ae03977")){let e=document.createElement("style");e.id="ac-style-0ae03977",e.textContent=`/*
266
266
  * Built-in appearance defaults \u2014 zero specificity via :where().
267
267
  * Consumer CSS always wins without !important.
268
268
  *
@@ -689,6 +689,10 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
689
689
  /* The fade exists to dissolve rows sliding under the footer. With the strip
690
690
  in between it has nothing to dissolve and would just wash over the cards. */
691
691
  --aia-footer-fade-lead: 0px;
692
+ /* Nor does the footer's row need to fill a band that is not reserved: it
693
+ holds that height only to cover the band (the footer-row rule), and here
694
+ an empty row would just leave a blank strip under the cards. */
695
+ --aia-footer-row-min-height: 0px;
692
696
  }
693
697
 
694
698
  :where(.magicx-aia[data-options-position="above"]) [data-aia-dropdown] .aia-stack,
@@ -1268,6 +1272,19 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
1268
1272
  pointer-events: none;
1269
1273
  }
1270
1274
 
1275
+ /* The hint / branding row is at least --aia-footer-row-height tall, the
1276
+ height the footer band under the options grid reserves for it
1277
+ (appearance.css). The badge is normally the row's tallest item and holds it
1278
+ there; without it \u2014 a consumer hiding the brand link, or a phone, where the
1279
+ keyboard hint is hidden too \u2014 the row shrank to the hint's 22px or to
1280
+ nothing, the footer's plate stopped short of the band and the rows scrolling
1281
+ under it showed below the footer (on a phone, the grid ran past the
1282
+ dropdown's bottom edge). The product strip zeroes the band and this floor
1283
+ with it (--aia-footer-row-min-height, appearance.css). */
1284
+ .aia-row-BgZ6Q {
1285
+ min-height: var(--aia-footer-row-min-height, var(--aia-footer-row-height, 23px));
1286
+ }
1287
+
1271
1288
  .aia-hintGroup-ZzbPf {
1272
1289
  min-width: 0;
1273
1290
  }
@@ -1378,7 +1395,7 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
1378
1395
  justify-content: flex-end;
1379
1396
  }
1380
1397
  }
1381
- `,document.head.appendChild(e)}var se={footer:"aia-footer-qQQ7x",hintGroup:"aia-hintGroup-ZzbPf",brandLink:"aia-brandLink-r4f3R",key:"aia-key-Bz1H-",hint:"aia-hint-GKEOH",brand:"aia-brand-Al-lR",badge:"aia-badge-Fk9vg",row:"aia-row-BgZ6Q"};import{jsx as Le,jsxs as Xe}from"react/jsx-runtime";function bt({isOptionHighlighted:e=!1,isInputEmpty:o=!1}){let{key:t,hint:n}=ca(e,o),[r,i]=ha(la);return pa(()=>{i(da())},[]),Le("footer",{className:se.footer,"data-aia-footer":"",children:Xe(De,{justify:"between",noWrap:!0,className:se.row,children:[Xe(De,{gap:"5px",className:se.hintGroup,children:[Le("kbd",{className:se.key,children:t}),Le("span",{className:se.hint,children:n})]}),Xe("a",{className:se.brandLink,href:r,target:"_blank",rel:"noopener noreferrer",children:[Le("span",{className:se.brand,children:"AI"}),Le("span",{className:se.badge,children:"Autocomplete"})]})]})})}if(typeof document<"u"&&!document.getElementById("ac-style-199d0432")){let e=document.createElement("style");e.id="ac-style-199d0432",e.textContent=`/* ParamPill (Figma "ParamPill") \u2014 unfilled suggestion pill: transparent fill,
1398
+ `,document.head.appendChild(e)}var se={footer:"aia-footer-qQQ7x",row:"aia-row-BgZ6Q",hintGroup:"aia-hintGroup-ZzbPf",brandLink:"aia-brandLink-r4f3R",key:"aia-key-Bz1H-",hint:"aia-hint-GKEOH",brand:"aia-brand-Al-lR",badge:"aia-badge-Fk9vg"};import{jsx as Le,jsxs as Xe}from"react/jsx-runtime";function bt({isOptionHighlighted:e=!1,isInputEmpty:o=!1}){let{key:t,hint:n}=ca(e,o),[r,i]=ha(la);return pa(()=>{i(da())},[]),Le("footer",{className:se.footer,"data-aia-footer":"",children:Xe(De,{justify:"between",noWrap:!0,className:se.row,children:[Xe(De,{gap:"5px",className:se.hintGroup,children:[Le("kbd",{className:se.key,children:t}),Le("span",{className:se.hint,children:n})]}),Xe("a",{className:se.brandLink,href:r,target:"_blank",rel:"noopener noreferrer",children:[Le("span",{className:se.brand,children:"AI"}),Le("span",{className:se.badge,children:"Autocomplete"})]})]})})}if(typeof document<"u"&&!document.getElementById("ac-style-199d0432")){let e=document.createElement("style");e.id="ac-style-199d0432",e.textContent=`/* ParamPill (Figma "ParamPill") \u2014 unfilled suggestion pill: transparent fill,
1382
1399
  no outline. ~28px via 6px padding + 14px text + the 1px border (border-box).
1383
1400
  The border is kept as a 1px transparent line so the box stays the same size
1384
1401
  as it was when the outline was dashed. */
@@ -1464,7 +1481,7 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
1464
1481
  align-items: center;
1465
1482
  vertical-align: middle;
1466
1483
  }
1467
- `,document.head.appendChild(e)}var et={list:"aia-list-qvLqO"};import{jsx as Ge}from"react/jsx-runtime";var ma=[125,69];function wt(e){return e===0?"first":e===1?"next":"last"}function We({pills:e,activePillIndex:o,onSelectPill:t,activeSelected:n,rounded:r,loading:i}){return i&&e.length===0?Ge("span",{className:et.list,"data-aia-pill-list-loading":"",children:ma.map((a,l)=>Ge("span",{"data-aia-pill-skeleton":"",className:`${be.pill} ${r?be.rounded:""} ${be.skeleton}`,style:{width:a,opacity:Je[wt(l)]}},`skel-${a}`))}):Ge("span",{className:et.list,"data-aia-pill-list-loading":i?"":void 0,children:e.map((a,l)=>{let y=!!n&&l===o;return Ge(vt,{label:a.text,state:y?"selected":wt(l),selected:y,rounded:r,loading:i,onClick:()=>t(l)},`${a.type}-${a.text}`)})})}import{attachProductRowWheel as ga,productInitial as fa}from"@magicx-eng/ai-autocomplete-vanilla";import{useEffect as ba,useRef as va,useState as wa}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-fef1688d")){let e=document.createElement("style");e.id="ac-style-fef1688d",e.textContent=`/* Product strip \u2014 the React counterpart of the vanilla core's strip rules
1484
+ `,document.head.appendChild(e)}var et={list:"aia-list-qvLqO"};import{jsx as Ge}from"react/jsx-runtime";var ma=[125,69];function wt(e){return e===0?"first":e===1?"next":"last"}function We({pills:e,activePillIndex:o,onSelectPill:t,activeSelected:n,rounded:r,loading:i}){return i&&e.length===0?Ge("span",{className:et.list,"data-aia-pill-list-loading":"",children:ma.map((a,l)=>Ge("span",{"data-aia-pill-skeleton":"",className:`${be.pill} ${r?be.rounded:""} ${be.skeleton}`,style:{width:a,opacity:Je[wt(l)]}},`skel-${a}`))}):Ge("span",{className:et.list,"data-aia-pill-list-loading":i?"":void 0,children:e.map((a,l)=>{let y=!!n&&l===o;return Ge(vt,{label:a.text,state:y?"selected":wt(l),selected:y,rounded:r,loading:i,onClick:()=>t(l)},`${a.parameter}-${a.text}`)})})}import{attachProductRowWheel as ga,productInitial as fa}from"@magicx-eng/ai-autocomplete-vanilla";import{useEffect as ba,useRef as va,useState as wa}from"react";if(typeof document<"u"&&!document.getElementById("ac-style-fef1688d")){let e=document.createElement("style");e.id="ac-style-fef1688d",e.textContent=`/* Product strip \u2014 the React counterpart of the vanilla core's strip rules
1468
1485
  (packages/vanilla/src/styles.css). Same tokens, same defaults, so a consumer
1469
1486
  theming one package sees the same result in the other.
1470
1487
 
@@ -2196,7 +2213,7 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
2196
2213
  align-items: end;
2197
2214
  }
2198
2215
  /* data-align="stretch" is the flex default \u2014 no rule needed. */
2199
- `,document.head.appendChild(e)}import{jsx as qa}from"react/jsx-runtime";function Tt({space:e,align:o="stretch",className:t,children:n,...r}){let i=e?{"--aia-stack-space":e}:void 0;return qa("div",{className:t?`aia-stack ${t}`:"aia-stack","data-align":o,style:i,...r,children:n})}import{jsx as j,jsxs as at}from"react/jsx-runtime";var $a=[159,119,164],Va=()=>{},At=()=>{};function Xa(e){let o=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[t,n]=Za(o);if(Ue(()=>{if(e!=="auto"||typeof window>"u"||typeof window.matchMedia!="function")return;let r=window.matchMedia("(prefers-color-scheme: dark)"),i=()=>n(r.matches);return r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),e!==void 0)return e==="auto"?t?"dark":"light":e}function Ja(e,o){let t=qe(null);Ue(()=>{let n=e.current,r=o.current;if(!n||!r)return;let i=n.querySelector(".aia-grid[data-scroll]");if(t.current&&t.current.grid!==i&&(t.current.controller.destroy(),t.current=null),i&&!t.current){t.current={grid:i,controller:Ua({dropdown:n,grid:i,button:r})};return}t.current?.controller.update()}),Ue(()=>()=>{t.current?.controller.destroy(),t.current=null},[])}function it({suggestions:e,activeIndex:o,onSelect:t,onHighlight:n,onUnhighlight:r,isOpen:i,id:a,className:l,pills:y,onPillClick:v,showPills:w=!0,onSkip:P,showSkipButton:u=!0,showOptionIcons:x=!0,showOptionImages:T=!0,showOptionCounts:I=!0,skipDisabled:K=!1,activeSelected:L=!1,isLoading:A=!1,skeletonExiting:S=!1,isInputEmpty:z=!1,products:E,onProductSelect:C,onProductFocusChange:H,productsLayout:X="row",productImageFallback:de="image",formatType:J="options",dateView:ce=null,selectedDateIso:G=null,selectedDateRange:g=null,dateRangeStart:ve=null,onPreviousMonth:pe,onNextMonth:he,optionsPosition:ee="below",mode:ue}){let te=Xa(ue),Q=te!==void 0,_=qe(null),ae=qe(null);Ja(_,ae),Ue(()=>{if(_.current)return ja(_.current)},[]);let ie=e[0]?.options??[],d=!!(y&&y.length>0&&v),m=!!(E&&E.length>0),h=i&&(ie.length>0||w&&d||A||m),f={suggestions:e,activeIndex:o,pills:y,showPills:w,showSkipButton:u,showOptionIcons:x,showOptionImages:T,showOptionCounts:I,skipDisabled:K,activeSelected:L,isLoading:A,skeletonExiting:S,isInputEmpty:z,products:E,formatType:J,dateView:ce,selectedDateIso:G,selectedDateRange:g,dateRangeStart:ve},k=qe(f);h&&(k.current=f);let s=h?f:k.current,M=s.suggestions[0],N=M?.options??[],Z=s.activeIndex>=0&&!!N[s.activeIndex]?.is_tappable,b=!!(s.pills&&s.pills.length>0&&v),we=s.showPills&&b,Ae=s.showPills&&!b&&s.isLoading,oe=we||Ae,c=b&&s.showSkipButton&&!s.isInputEmpty&&!!P,ne=s.pills?.[0]?.text,xe=Ya(s.formatType)&&s.dateView!=null,me=N.length>0&&!xe,Ce=N.length>0&&xe&&!s.isLoading,ge=s.isLoading&&!me&&!Ce,Pe=s.products??[];return at("div",{ref:_,id:a,role:"listbox","data-aia-dropdown":"","data-options-position":ee,"data-mode":te,"data-aia-loading":s.isLoading?"":void 0,"data-aia-skeleton-exiting":s.skeletonExiting?"":void 0,"data-aia-has-products":Pe.length>0?"":void 0,className:`${Q?"magicx-aia ":""}${re.dropdown} ${h?re.visible:""} ${l??""}`,onMouseDown:B=>B.preventDefault(),children:[at(Tt,{space:"8px",children:[(oe||c)&&at(De,{noWrap:!0,className:re.pillBar,"data-aia-pillbar":"",children:[oe&&j("span",{className:re.pillScroll,"data-aia-pill-scroll":"",children:j(We,{pills:s.pills??[],activePillIndex:0,activeSelected:s.activeSelected,onSelectPill:v??(()=>{}),rounded:!0,loading:s.isLoading})}),c&&j("button",{type:"button",tabIndex:-1,className:re.skip,"data-aia-skip":"",disabled:s.isLoading||s.skipDisabled,"aria-label":ne?`Skip ${ne}`:"Skip",onClick:P,children:"skip"})]}),me&&j(Et,{options:N,activeIndex:s.activeIndex,onSelect:t,onHighlight:n,onUnhighlight:r,listboxId:a,loading:s.isLoading,groupKey:M?`${M.type} ${M.text}`:"",optionsPosition:ee,showIcons:s.showOptionIcons,showImages:s.showOptionImages,showCounts:s.showOptionCounts}),Ce&&s.dateView&&j(gt,{options:N,activeIndex:s.activeIndex,listboxId:a,view:s.dateView,selection:{selectedIso:s.selectedDateIso??null,selectedRange:s.selectedDateRange??null,rangeStart:s.dateRangeStart??null},onSelect:t,onHighlight:n,onUnhighlight:r,onPreviousMonth:pe??At,onNextMonth:he??At}),ge&&j("div",{className:re.skeletonBars,"data-aia-skeleton-bars":"",children:$a.map(B=>j("span",{className:re.skeletonBar,style:{width:B}},`bar-${B}`))}),j(xt,{products:Pe,listboxId:a,onSelect:C??Va,onFocusChange:H,focusable:h,layout:X,imageFallback:de}),j(bt,{isOptionHighlighted:Z,isInputEmpty:s.isInputEmpty})]}),j("button",{ref:ae,type:"button",tabIndex:-1,className:re.scrollArrow,"data-aia-scroll-arrow":"","aria-label":Qa,"aria-hidden":"true",children:j("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:j("path",{d:"M4 6.5 8 10.5l4-4"})})})]})}import{buildSubmitResult as ui,ModeController as mi,setCursorOffset as gi}from"@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 {
2216
+ `,document.head.appendChild(e)}import{jsx as qa}from"react/jsx-runtime";function Tt({space:e,align:o="stretch",className:t,children:n,...r}){let i=e?{"--aia-stack-space":e}:void 0;return qa("div",{className:t?`aia-stack ${t}`:"aia-stack","data-align":o,style:i,...r,children:n})}import{jsx as j,jsxs as at}from"react/jsx-runtime";var $a=[159,119,164],Va=()=>{},At=()=>{};function Xa(e){let o=()=>typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-color-scheme: dark)").matches,[t,n]=Za(o);if(Ue(()=>{if(e!=="auto"||typeof window>"u"||typeof window.matchMedia!="function")return;let r=window.matchMedia("(prefers-color-scheme: dark)"),i=()=>n(r.matches);return r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[e]),e!==void 0)return e==="auto"?t?"dark":"light":e}function Ja(e,o){let t=qe(null);Ue(()=>{let n=e.current,r=o.current;if(!n||!r)return;let i=n.querySelector(".aia-grid[data-scroll]");if(t.current&&t.current.grid!==i&&(t.current.controller.destroy(),t.current=null),i&&!t.current){t.current={grid:i,controller:Ua({dropdown:n,grid:i,button:r})};return}t.current?.controller.update()}),Ue(()=>()=>{t.current?.controller.destroy(),t.current=null},[])}function it({suggestions:e,activeIndex:o,onSelect:t,onHighlight:n,onUnhighlight:r,isOpen:i,id:a,className:l,pills:y,onPillClick:v,showPills:w=!0,onSkip:P,showSkipButton:u=!0,showOptionIcons:x=!0,showOptionImages:T=!0,showOptionCounts:I=!0,skipDisabled:K=!1,activeSelected:L=!1,isLoading:A=!1,skeletonExiting:S=!1,isInputEmpty:z=!1,products:E,onProductSelect:C,onProductFocusChange:H,productsLayout:X="row",productImageFallback:de="image",formatType:J="options",dateView:ce=null,selectedDateIso:G=null,selectedDateRange:g=null,dateRangeStart:ve=null,onPreviousMonth:pe,onNextMonth:he,optionsPosition:ee="below",mode:ue}){let te=Xa(ue),Y=te!==void 0,_=qe(null),ae=qe(null);Ja(_,ae),Ue(()=>{if(_.current)return ja(_.current)},[]);let ie=e[0]?.options??[],d=!!(y&&y.length>0&&v),m=!!(E&&E.length>0),h=i&&(ie.length>0||w&&d||A||m),f={suggestions:e,activeIndex:o,pills:y,showPills:w,showSkipButton:u,showOptionIcons:x,showOptionImages:T,showOptionCounts:I,skipDisabled:K,activeSelected:L,isLoading:A,skeletonExiting:S,isInputEmpty:z,products:E,formatType:J,dateView:ce,selectedDateIso:G,selectedDateRange:g,dateRangeStart:ve},k=qe(f);h&&(k.current=f);let s=h?f:k.current,M=s.suggestions[0],N=M?.options??[],Z=s.activeIndex>=0&&!!N[s.activeIndex]?.is_tappable,b=!!(s.pills&&s.pills.length>0&&v),we=s.showPills&&b,Ae=s.showPills&&!b&&s.isLoading,oe=we||Ae,c=b&&s.showSkipButton&&!s.isInputEmpty&&!!P,ne=s.pills?.[0]?.text,xe=Qa(s.formatType)&&s.dateView!=null,me=N.length>0&&!xe,Ce=N.length>0&&xe&&!s.isLoading,ge=s.isLoading&&!me&&!Ce,Pe=s.products??[];return at("div",{ref:_,id:a,role:"listbox","data-aia-dropdown":"","data-options-position":ee,"data-mode":te,"data-aia-loading":s.isLoading?"":void 0,"data-aia-skeleton-exiting":s.skeletonExiting?"":void 0,"data-aia-has-products":Pe.length>0?"":void 0,className:`${Y?"magicx-aia ":""}${re.dropdown} ${h?re.visible:""} ${l??""}`,onMouseDown:B=>B.preventDefault(),children:[at(Tt,{space:"8px",children:[(oe||c)&&at(De,{noWrap:!0,className:re.pillBar,"data-aia-pillbar":"",children:[oe&&j("span",{className:re.pillScroll,"data-aia-pill-scroll":"",children:j(We,{pills:s.pills??[],activePillIndex:0,activeSelected:s.activeSelected,onSelectPill:v??(()=>{}),rounded:!0,loading:s.isLoading})}),c&&j("button",{type:"button",tabIndex:-1,className:re.skip,"data-aia-skip":"",disabled:s.isLoading||s.skipDisabled,"aria-label":ne?`Skip ${ne}`:"Skip",onClick:P,children:"skip"})]}),me&&j(Et,{options:N,activeIndex:s.activeIndex,onSelect:t,onHighlight:n,onUnhighlight:r,listboxId:a,loading:s.isLoading,groupKey:M?`${M.parameter} ${M.text}`:"",optionsPosition:ee,showIcons:s.showOptionIcons,showImages:s.showOptionImages,showCounts:s.showOptionCounts}),Ce&&s.dateView&&j(gt,{options:N,activeIndex:s.activeIndex,listboxId:a,view:s.dateView,selection:{selectedIso:s.selectedDateIso??null,selectedRange:s.selectedDateRange??null,rangeStart:s.dateRangeStart??null},onSelect:t,onHighlight:n,onUnhighlight:r,onPreviousMonth:pe??At,onNextMonth:he??At}),ge&&j("div",{className:re.skeletonBars,"data-aia-skeleton-bars":"",children:$a.map(B=>j("span",{className:re.skeletonBar,style:{width:B}},`bar-${B}`))}),j(xt,{products:Pe,listboxId:a,onSelect:C??Va,onFocusChange:H,focusable:h,layout:X,imageFallback:de}),j(bt,{isOptionHighlighted:Z,isInputEmpty:s.isInputEmpty})]}),j("button",{ref:ae,type:"button",tabIndex:-1,className:re.scrollArrow,"data-aia-scroll-arrow":"","aria-label":Ya,"aria-hidden":"true",children:j("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:j("path",{d:"M4 6.5 8 10.5l4-4"})})})]})}import{buildSubmitResult as ui,ModeController as mi,setCursorOffset as gi}from"@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 {
2200
2217
  flex-shrink: 0;
2201
2218
  width: 32px;
2202
2219
  height: 32px;
@@ -2249,5 +2266,5 @@ import{buildSubmitResult as dn,cellDay as cn,cellIso as pn,DATE_RANGE_META_END a
2249
2266
  );
2250
2267
  cursor: default;
2251
2268
  }
2252
- `,document.head.appendChild(e)}var Rt={submitButton:"aia-submitButton-otz7H"};import{jsx as ot}from"react/jsx-runtime";function Ot({disabled:e,onClick:o}){return ot("button",{type:"button","data-aia-submit":"",className:Rt.submitButton,disabled:e,onClick:t=>{t.stopPropagation(),o()},"aria-label":"Submit",children:ot("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:ot("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as ei,dateSelectionFor as ti,identifiedParamLabel as ai}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Nt,useEffect as ze,useRef as F,useState as ii}from"react";import{useRef as Dt}from"react";function Lt(e){let o=Dt(e);o.current=e;let t=Object.keys(e??{}).sort().join("\0"),n=Dt({key:"",overrides:void 0});if(n.current.key!==t){let r={};for(let i of Object.keys(e??{})){let a=(l,y,v)=>{let w=o.current?.[i];return w?w(l,y,v):[]};r[i]=a}n.current={key:t,overrides:e?r:void 0}}return{overrides:n.current.overrides,key:t}}import{useRef as zt}from"react";function Mt(e){let o=zt(e);o.current=e;let t=zt(null);t.current===null&&(t.current={fetch:(r,i)=>{let a=o.current;return a?a.fetch(r,i):Promise.reject(new Error("products config removed"))},transform:r=>o.current?.transform(r)??[],get limit(){return o.current?.limit}});let n=e!==void 0;return{config:n?t.current:void 0,enabled:n}}var oi={text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],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,editingParam:null,editingIdentified:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,dateViewMonth:null,pendingRangeStart:null};function nt({onSubmit:e,onResult:o,onError:t,optionOverrides:n,maskCompletedText:r,apiConfig:i,additionalContext:a,visitorId:l,columns:y=2,dropdownTrigger:v,optionsPosition:w,closeDropdownOnBlur:P,showNonTappableOptions:u,showOptionIcons:x,showOptionImages:T,showOptionCounts:I,showSkipButton:K,showProducts:L,productImageFallback:A="image",onFocus:S,onBlur:z,value:E,completedParams:C,onChange:H,onParamsChange:X,products:de,onProductSelect:J,source:ce,setCursor:G}){let g=F(null),[ve,pe]=ii(null),he=F(e);he.current=e;let ee=F(o);ee.current=o;let ue=F(t);ue.current=t;let te=F(H);te.current=H;let Q=F(X);Q.current=X;let _=F(S);_.current=S;let ae=F(z);ae.current=z;let ie=F(G);ie.current=G;let d=F(J);d.current=J;let m=F(l);m.current=l;let h=F(()=>{let p=m.current;return typeof p=="function"?p():p}).current,f=Mt(de),k=Lt(n);ze(()=>{if(typeof document>"u")return;let p=new ei(document.createElement("div"),{renderMode:"headless",apiConfig:i,additionalContext:a,visitorId:h,optionOverrides:k.overrides,maskCompletedText:r,columns:y,dropdownTrigger:v,optionsPosition:w,closeDropdownOnBlur:P,showNonTappableOptions:u,showProducts:L,source:ce,value:E,completedParams:C,onSubmit:(...D)=>he.current?.(...D),onResult:(...D)=>ee.current?.(...D),onError:(...D)=>ue.current?.(...D),onChange:(...D)=>te.current?.(...D),onParamsChange:(...D)=>Q.current?.(...D),onFocus:()=>_.current?.(),onBlur:()=>ae.current?.(),onProductSelect:D=>d.current?.(D),setCursor:D=>ie.current?.(D),products:f.config});g.current=p,pe(p.getState());let q=p.subscribe(D=>pe(D));return()=>{q(),p.destroy(),g.current===p&&(g.current=null)}},[]),ze(()=>{E!==void 0&&g.current?.setValue(E)},[E]),ze(()=>{C!==void 0&&g.current?.setCompletedParams(C)},[C]);let s=JSON.stringify(i??null),M;try{M=JSON.stringify(a??null)}catch{M="[unstringifiable]"}ze(()=>{g.current?.update({apiConfig:i,additionalContext:a,optionOverrides:k.overrides,dropdownTrigger:v,optionsPosition:w,closeDropdownOnBlur:P,showNonTappableOptions:u,showProducts:L})},[s,M,k.key,v,w,P,u,L]);let N=F(!1);ze(()=>{if(!N.current){N.current=!0;return}g.current?.update({products:f.config})},[f.enabled]);let Z=F(null);Z.current===null&&(Z.current={handleTextChange:p=>g.current?.handleTextChange(p),handleKeyDown:p=>{let q="nativeEvent"in p?p.nativeEvent:p;g.current?.handleKeyDown(q)},setFocused:p=>g.current?.setFocused(p),startEditingParam:p=>g.current?.startEditingParam(p),exitEditMode:()=>g.current?.exitEditMode(),handleCaretAfterInput:p=>g.current?.handleCaretAfterInput(p),handleCaretMove:p=>g.current?.handleCaretMove(p),replaceEditingRange:p=>g.current?.replaceEditingRange(p)??!1,setActivePill:p=>g.current?.setActivePill(p),skipActivePill:()=>g.current?.skipActivePill(),removeLastParam:()=>g.current?.removeLastParam(),clearNewParamId:()=>g.current?.clearNewParamId(),reset:()=>g.current?.reset(),recordSubmit:p=>g.current?.recordSubmit(p),selectOption:p=>g.current?.selectOption(p),selectProduct:p=>g.current?.selectProduct(p),setActiveDropdownIndex:p=>g.current?.setActiveDropdownIndex(p),clearHighlight:p=>g.current?.clearHighlight(p),showPreviousMonth:()=>g.current?.showPreviousMonth(),showNextMonth:()=>g.current?.showNextMonth(),handleFocus:()=>g.current?.setFocused(!0),handleBlur:()=>g.current?.setFocused(!1)});let b=Z.current,we=Nt(p=>{let q=p.target.value,Ze=q.length>0&&!p.nativeEvent?.isComposing&&q[0]!==q[0].toUpperCase()?q[0].toUpperCase()+q.slice(1):q;g.current?.handleTextChange(Ze)},[]),Ae=Nt(p=>{g.current?.handleKeyDown(p.nativeEvent)},[]),oe=g.current,c=ve??oi,ne=E!==void 0?E:c.text,xe=C!==void 0?C:c.completedParams,me=c.actionableSuggestions,Ce=me[0],ge=oe?.listboxId??"",Pe=c.activeDropdownIndex>=0&&oe?`${ge}-option-${c.activeDropdownIndex}`:void 0,B=c.editingParam,fe=c.editingIdentified,Se=B?{type:B.suggestionType,text:B.suggestionPlaceholder,required:!0,options:B.options}:fe?{type:fe.type,text:ai(fe.type),required:!0,options:[]}:null,Ne=c.dropdownSuggestion??Se??Ce,Qe=Se?[Se]:me,Re=ti(c),Be=!oe||c.dropdownLoading;return{completedParams:xe,skippedParams:c.skippedParams,identifiedParams:c.identifiedParams,suggestionPills:me,setActivePill:b.setActivePill,skipActivePill:b.skipActivePill,removeLastParam:b.removeLastParam,segments:c.segments,newParamId:c.newParamId,clearNewParamId:b.clearNewParamId,suggestions:c.suggestions,activeIndex:c.activeDropdownIndex,isReady:c.isReady,isLoading:Be,isFocused:c.isFocused,isDropdownOpen:c.isDropdownOpen,isActivePillSelected:c.isActivePillSelected,placeholderText:c.placeholderText,listboxId:ge,error:c.error,products:c.products,customFields:c.customFields,selectProduct:b.selectProduct,handleTextChange:b.handleTextChange,handleKeyDown:b.handleKeyDown,setFocused:b.setFocused,editingParam:B,editingIdentified:fe,editingAnchor:c.editingAnchor,caretOffset:c.caretOffset,startEditingParam:b.startEditingParam,exitEditMode:b.exitEditMode,handleCaretAfterInput:b.handleCaretAfterInput,handleCaretMove:b.handleCaretMove,replaceEditingRange:b.replaceEditingRange,inputProps:{value:ne,placeholder:c.placeholderText||void 0,onChange:we,onKeyDown:Ae,onFocus:b.handleFocus,onBlur:b.handleBlur,role:"combobox","aria-expanded":c.isDropdownOpen,"aria-activedescendant":Pe,"aria-autocomplete":"list","aria-controls":ge},reset:b.reset,recordSubmit:b.recordSubmit,dropdownProps:{suggestions:Ne?[{...Ne,options:c.dropdownOptions}]:[],activeIndex:c.activeDropdownIndex,onSelect:b.selectOption,onHighlight:b.setActiveDropdownIndex,onUnhighlight:b.clearHighlight,isOpen:c.isDropdownOpen,id:ge,pills:Qe,activeSelected:c.isActivePillSelected,onPillClick:b.setActivePill,onSkip:b.skipActivePill,showSkipButton:(K??!0)&&!B&&!fe,showOptionIcons:x??!0,showOptionImages:T??!0,showOptionCounts:I??!0,skipDisabled:c.inSelectionAnimation,isLoading:Be,skeletonExiting:c.skeletonExiting,isInputEmpty:ne.trim().length===0,products:c.products,productImageFallback:A,onProductSelect:b.selectProduct,onProductFocusChange:b.setFocused,formatType:c.activeFormatType,dateView:c.dateView,selectedDateIso:Re.selectedIso,selectedDateRange:Re.selectedRange,dateRangeStart:Re.rangeStart,onPreviousMonth:b.showPreviousMonth,onNextMonth:b.showNextMonth,optionsPosition:w??"below"}}}import{chipIdFromTap as ni,extractPlainText as Bt,getCursorOffset as Ht,keepCaretOnChip as ri,plainTextLength as si,renderEditableContent as li,setCursorOffset as Ft}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Y,useEffect as je,useLayoutEffect as rt,useRef as Ee}from"react";var Ye;function di(){if(Ye!==void 0)return Ye;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),Ye=e.contentEditable==="plaintext-only",Ye}function Kt(e){let{segments:o,showChipIcons:t=!0,showChipImages:n=!0,newParamId:r,editingParam:i,editingIdentified:a,editingAnchor:l,caretOffset:y,placeholderText:v,isFocused:w,isDropdownOpen:P,listboxId:u,activeDescendantId:x,autoFocus:T,handleTextChange:I,handleKeyDown:K,handleCaretAfterInput:L,handleCaretMove:A,startEditingParam:S,replaceEditingRange:z,setFocused:E}=e,C=Ee(null),H=Ee(!1),X=Ee(""),de=Ee(""),J=Ee(null),ce=Ee(0);J.current=y,je(()=>{if(!T)return;let d=C.current;if(!d)return;document.activeElement===d?E(!0):d.focus();let m=d.ownerDocument??document,h=m.getSelection(),f=h&&h.rangeCount>0&&d.contains(h.anchorNode);if(h&&!f){let k=m.createRange();k.selectNodeContents(d),k.collapse(!0),h.removeAllRanges(),h.addRange(k)}},[T,E]),je(()=>{let d=C.current;if(!d)return;let m=d.ownerDocument??document,h=()=>{let f=m.getSelection();if(!f||f.rangeCount===0||!f.anchorNode||!d.contains(f.anchorNode))return;let k=f.anchorNode,s=k.nodeType===Node.ELEMENT_NODE?k:k.parentElement,N=(f.isCollapsed?s?.closest("strong[data-param-id]"):null)?.dataset.paramId??null,Z=i?.id??a?.id??null;if(N&&N!==Z){S(N);return}performance.now()-ce.current<50||A(Ht(d))};return m.addEventListener("selectionchange",h),()=>m.removeEventListener("selectionchange",h)},[i,a,S,A]),je(()=>{let d=C.current;if(!d)return;let m=h=>{let f=ni(d,h.target);f&&(S(f),ri(d,f))};return d.addEventListener("click",m),()=>d.removeEventListener("click",m)},[S]),rt(()=>{let d=C.current;d&&li({input:d,segments:o,newParamId:r,editingParamId:i?.id??null,placeholderText:v??"",isFocused:w,showChipIcons:t,showChipImages:n})},[o,r,i,v,w,t,n]),rt(()=>{let d=X.current,m=r??"";if(X.current=m,!m||m===d)return;let h=C.current;if(!h)return;h.focus();let f=J.current??si(h);Ft(h,f)},[r]),rt(()=>{let d=de.current,m=i?.id??"";if(de.current=m,!m||m===d||l==null)return;let h=C.current;h&&Ft(h,l)},[i,l]);let G=Y(()=>{if(H.current)return;let d=C.current;if(!d)return;let m=Bt(d),f=m.length>0&&m[0]!==m[0].toUpperCase()?m[0].toUpperCase()+m.slice(1):m;I(f)},[I]),g=Y(()=>{ce.current=performance.now(),G();let d=C.current;d&&L(Ht(d))},[G,L]);je(()=>{let d=C.current;if(!d)return;let m=h=>{let f=h,k=f.inputType;if(k==="insertParagraph"||k==="insertLineBreak"||k==="insertFromDrop"){h.preventDefault();return}if(k.startsWith("insert")||k.startsWith("delete")){let s=k.startsWith("delete")?"":f.data??"";z(s)&&h.preventDefault()}};return d.addEventListener("beforeinput",m),()=>d.removeEventListener("beforeinput",m)},[z]);let ve=Y(()=>{H.current=!0},[]),pe=Y(()=>{H.current=!1,G()},[G]),he=Y(d=>{d.preventDefault();let m=C.current;if(!m)return;let h=(d.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!h)return;let f=m.ownerDocument??document,k=f.getSelection();if(!k||k.rangeCount===0)return;let s=k.getRangeAt(0);if(!m.contains(s.startContainer))return;s.deleteContents();let M=f.createTextNode(h);s.insertNode(M),s.setStartAfter(M),s.collapse(!0),k.removeAllRanges(),k.addRange(s),G()},[G]),ee=Y(d=>K(d),[K]),ue=Y(()=>E(!0),[E]),te=Y(()=>E(!1),[E]),Q=Y(()=>C.current?.focus(),[]),_=Y(()=>C.current?.blur(),[]),ae=Y(()=>{let d=C.current;return d?Bt(d):""},[]),ie=di()?"plaintext-only":"true";return{inputRef:C,editorProps:{ref:C,contentEditable:ie,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":u,"aria-expanded":P,"aria-activedescendant":x,spellCheck:!0,enterKeyHint:"send",onInput:g,onKeyDown:ee,onCompositionStart:ve,onCompositionEnd:pe,onPaste:he,onFocus:ue,onBlur:te},getPlainText:ae,focus:Q,blur:_}}import{jsx as Te,jsxs as lt}from"react/jsx-runtime";function fi(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var bi=ci(function({onSubmit:o,onResult:t,onError:n,optionOverrides:r,maskCompletedText:i,className:a,apiConfig:l,additionalContext:y,visitorId:v,columns:w,pillPlacement:P="dropdown",mode:u="auto",optionsPosition:x="below",animations:T=!0,dropdownTrigger:I,closeDropdownOnBlur:K,showNonTappableOptions:L,showOptionIcons:A=!0,showChipIcons:S=!0,showChipImages:z=!0,showOptionImages:E=!0,showOptionCounts:C=!0,showSkipButton:H,showProducts:X,productsLayout:de,productImageFallback:J,autoFocus:ce=!0,onFocus:G,onBlur:g,value:ve,completedParams:pe,onChange:he,onParamsChange:ee,products:ue,onProductSelect:te,submitButton:Q,resetOnSubmit:_=!0},ae){let ie=Me(null),d=Me(null),m=Me(()=>{}),h=Me(null),f=Me(null);Gt(()=>{let R=ie.current;if(R)return h.current?h.current.setMode(u):h.current=new mi(R,u),()=>{h.current?.destroy(),h.current=null}},[u]);let k=st(R=>{let $=f.current?.current;$&&($.focus(),gi($,R))},[]),{completedParams:s,skippedParams:M,identifiedParams:N,isReady:Z,customFields:b,suggestionPills:we,setActivePill:Ae,skipActivePill:oe,segments:c,newParamId:ne,clearNewParamId:xe,placeholderText:me,isFocused:Ce,isDropdownOpen:ge,isActivePillSelected:Pe,isLoading:B,activeIndex:fe,listboxId:Se,handleTextChange:Ne,handleKeyDown:Qe,setFocused:Re,editingParam:Be,editingIdentified:p,editingAnchor:q,caretOffset:D,startEditingParam:Ze,handleCaretAfterInput:Wt,handleCaretMove:_t,replaceEditingRange:qt,dropdownProps:Ut,reset:He,recordSubmit:dt}=nt({onSubmit:R=>m.current(R),onResult:t,onError:n,optionOverrides:r,maskCompletedText:i,apiConfig:l,additionalContext:y,visitorId:v,columns:w,dropdownTrigger:I,optionsPosition:x,closeDropdownOnBlur:K,showNonTappableOptions:L,showOptionIcons:A,showOptionImages:E,showOptionCounts:C,showSkipButton:H,showProducts:X,onFocus:G,onBlur:g,value:ve,completedParams:pe,onChange:he,onParamsChange:ee,products:ue,onProductSelect:te,source:"full-sdk",setCursor:k});Gt(()=>{if(!ne)return;let R=window.setTimeout(()=>xe(),650);return()=>window.clearTimeout(R)},[ne,xe]);let jt=fe>=0?`${Se}-option-${fe}`:void 0,{inputRef:$e,editorProps:Yt,focus:Fe,blur:ct,getPlainText:pt}=Kt({segments:c,newParamId:ne,editingParam:Be,editingIdentified:p,editingAnchor:q,caretOffset:D,placeholderText:me,isFocused:Ce,showChipIcons:S,showChipImages:z,isDropdownOpen:ge,listboxId:Se,activeDescendantId:jt,autoFocus:ce,handleTextChange:Ne,handleKeyDown:Qe,handleCaretAfterInput:Wt,handleCaretMove:_t,startEditingParam:Ze,replaceEditingRange:qt,setFocused:Re});f.current=$e,hi(()=>{let R=d.current,$=$e.current;if(!R||!$)return;let Oe=()=>{let ut=R.firstElementChild;if(!ut)return;let Vt=ut.getBoundingClientRect(),Xt=$.getBoundingClientRect();Vt.top>=Xt.bottom-2?R.setAttribute("data-aia-pill-wrapped",""):R.removeAttribute("data-aia-pill-wrapped")};Oe();let ht=new ResizeObserver(Oe);return ht.observe($),()=>ht.disconnect()},[c,we.length,B,$e]),pi(ae,()=>({focus:Fe,blur:ct,reset:He,setMode:R=>h.current?.setMode(R),skipActivePill:oe}),[Fe,ct,He,oe]);let Ke=!!c.length||s.length>0,Ve=st(R=>{if(!Ke)return;let $=pt(),Oe=ui($,s,M,{identifiedParams:N,isReady:Z,customFields:b});R&&dt(Oe),o(Oe),_&&He()},[dt,_,Ke,s,M,N,Z,b,o,He,pt]);m.current=()=>Ve(!1);let Qt=st(R=>{R.target?.closest("[data-aia-pill]")||Fe()},[Fe]),Zt=P==="inline",$t=P==="dropdown";return lt("div",{ref:ie,className:`magicx-aia ${ye.container} ${a??""}`,"data-pill-placement":P,"data-options-position":x,"data-animations":T?"on":"off","data-mode":fi(u),children:[Te(it,{...Ut,showPills:$t,productsLayout:de,productImageFallback:J}),lt("div",{className:ye.inputWrapper,"data-aia-input-wrapper":"",onClick:Qt,children:[lt("div",{className:ye.editorArea,"data-aia-editor":"",children:[Te("div",{...Yt,className:ye.input,"data-aia-input":""}),Zt&&(B||we.length>0)&&Te("span",{ref:d,className:ye.pillListContainer,"data-aia-pill-list-container":"",children:Te(We,{pills:we,activePillIndex:0,activeSelected:Pe,onSelectPill:Ae,loading:B})})]}),Q===null?null:Q===void 0?Te(Ot,{disabled:!Ke,onClick:()=>Ve(!0)}):Te("span",{"data-aia-submit":"","data-aia-submit-slot":"",className:ye.submitSlot,onClick:R=>{Ke&&(R.stopPropagation(),Ve(!0))},children:Q})]})]})});export{bi as AIAutocomplete,it as AIAutocompleteDropdown,hn as DATE_RANGE_META_END,un as DATE_RANGE_META_START,mn as DEFAULT_OPTION_COUNT_UNIT,Sn as PRODUCT_PATH_PREFIX,zn as WEEKDAY_LABELS,dn as buildSubmitResult,cn as cellDay,pn as cellIso,gn as dateCellMarks,fn as formatDate,bn as formatDateRange,vn as formatOptionCount,wn as isoDate,xn as monthLabel,yn as optionCountLabel,kn as optionHasImage,Cn as optionImageSrc,Pn as optionLabel,In as parseDate,En as parseLooseDate,Tn as parseLooseDateRange,An as productFromMatchedItem,Rn as productsFromCustomFields,On as sanitizeOptionIconSvg,Dn as selectedRangeFor,nt as useAIAutocomplete,Ln as visibleDateRange,Mn as withSkippedParams};
2269
+ `,document.head.appendChild(e)}var Rt={submitButton:"aia-submitButton-otz7H"};import{jsx as ot}from"react/jsx-runtime";function Ot({disabled:e,onClick:o}){return ot("button",{type:"button","data-aia-submit":"",className:Rt.submitButton,disabled:e,onClick:t=>{t.stopPropagation(),o()},"aria-label":"Submit",children:ot("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:ot("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})}import{AIAutocomplete as ei,dateSelectionFor as ti,identifiedParamLabel as ai}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Nt,useEffect as ze,useRef as F,useState as ii}from"react";import{useRef as Dt}from"react";function Lt(e){let o=Dt(e);o.current=e;let t=Object.keys(e??{}).sort().join("\0"),n=Dt({key:"",overrides:void 0});if(n.current.key!==t){let r={};for(let i of Object.keys(e??{})){let a=(l,y,v)=>{let w=o.current?.[i];return w?w(l,y,v):[]};r[i]=a}n.current={key:t,overrides:e?r:void 0}}return{overrides:n.current.overrides,key:t}}import{useRef as zt}from"react";function Mt(e){let o=zt(e);o.current=e;let t=zt(null);t.current===null&&(t.current={fetch:(r,i)=>{let a=o.current;return a?a.fetch(r,i):Promise.reject(new Error("products config removed"))},transform:r=>o.current?.transform(r)??[],get limit(){return o.current?.limit}});let n=e!==void 0;return{config:n?t.current:void 0,enabled:n}}var oi={text:"",completedParams:[],identifiedParams:[],skippedParams:[],pendingSpan:null,suggestions:[],products:[],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,editingParam:null,editingIdentified:null,editingAnchor:null,editingTail:null,caretOffset:null,inSelectionAnimation:!1,dateViewMonth:null,pendingRangeStart:null};function nt({onSubmit:e,onResult:o,onError:t,optionOverrides:n,maskCompletedText:r,apiConfig:i,additionalContext:a,visitorId:l,columns:y=2,dropdownTrigger:v,optionsPosition:w,closeDropdownOnBlur:P,showNonTappableOptions:u,showOptionIcons:x,showOptionImages:T,showOptionCounts:I,showSkipButton:K,showProducts:L,productImageFallback:A="image",onFocus:S,onBlur:z,value:E,completedParams:C,onChange:H,onParamsChange:X,products:de,onProductSelect:J,source:ce,setCursor:G}){let g=F(null),[ve,pe]=ii(null),he=F(e);he.current=e;let ee=F(o);ee.current=o;let ue=F(t);ue.current=t;let te=F(H);te.current=H;let Y=F(X);Y.current=X;let _=F(S);_.current=S;let ae=F(z);ae.current=z;let ie=F(G);ie.current=G;let d=F(J);d.current=J;let m=F(l);m.current=l;let h=F(()=>{let p=m.current;return typeof p=="function"?p():p}).current,f=Mt(de),k=Lt(n);ze(()=>{if(typeof document>"u")return;let p=new ei(document.createElement("div"),{renderMode:"headless",apiConfig:i,additionalContext:a,visitorId:h,optionOverrides:k.overrides,maskCompletedText:r,columns:y,dropdownTrigger:v,optionsPosition:w,closeDropdownOnBlur:P,showNonTappableOptions:u,showProducts:L,source:ce,value:E,completedParams:C,onSubmit:(...D)=>he.current?.(...D),onResult:(...D)=>ee.current?.(...D),onError:(...D)=>ue.current?.(...D),onChange:(...D)=>te.current?.(...D),onParamsChange:(...D)=>Y.current?.(...D),onFocus:()=>_.current?.(),onBlur:()=>ae.current?.(),onProductSelect:D=>d.current?.(D),setCursor:D=>ie.current?.(D),products:f.config});g.current=p,pe(p.getState());let q=p.subscribe(D=>pe(D));return()=>{q(),p.destroy(),g.current===p&&(g.current=null)}},[]),ze(()=>{E!==void 0&&g.current?.setValue(E)},[E]),ze(()=>{C!==void 0&&g.current?.setCompletedParams(C)},[C]);let s=JSON.stringify(i??null),M;try{M=JSON.stringify(a??null)}catch{M="[unstringifiable]"}ze(()=>{g.current?.update({apiConfig:i,additionalContext:a,optionOverrides:k.overrides,dropdownTrigger:v,optionsPosition:w,closeDropdownOnBlur:P,showNonTappableOptions:u,showProducts:L})},[s,M,k.key,v,w,P,u,L]);let N=F(!1);ze(()=>{if(!N.current){N.current=!0;return}g.current?.update({products:f.config})},[f.enabled]);let Z=F(null);Z.current===null&&(Z.current={handleTextChange:p=>g.current?.handleTextChange(p),handleKeyDown:p=>{let q="nativeEvent"in p?p.nativeEvent:p;g.current?.handleKeyDown(q)},setFocused:p=>g.current?.setFocused(p),startEditingParam:p=>g.current?.startEditingParam(p),exitEditMode:()=>g.current?.exitEditMode(),handleCaretAfterInput:p=>g.current?.handleCaretAfterInput(p),handleCaretMove:p=>g.current?.handleCaretMove(p),replaceEditingRange:p=>g.current?.replaceEditingRange(p)??!1,setActivePill:p=>g.current?.setActivePill(p),skipActivePill:()=>g.current?.skipActivePill(),removeLastParam:()=>g.current?.removeLastParam(),clearNewParamId:()=>g.current?.clearNewParamId(),reset:()=>g.current?.reset(),recordSubmit:p=>g.current?.recordSubmit(p),selectOption:p=>g.current?.selectOption(p),selectProduct:p=>g.current?.selectProduct(p),setActiveDropdownIndex:p=>g.current?.setActiveDropdownIndex(p),clearHighlight:p=>g.current?.clearHighlight(p),showPreviousMonth:()=>g.current?.showPreviousMonth(),showNextMonth:()=>g.current?.showNextMonth(),handleFocus:()=>g.current?.setFocused(!0),handleBlur:()=>g.current?.setFocused(!1)});let b=Z.current,we=Nt(p=>{let q=p.target.value,Ze=q.length>0&&!p.nativeEvent?.isComposing&&q[0]!==q[0].toUpperCase()?q[0].toUpperCase()+q.slice(1):q;g.current?.handleTextChange(Ze)},[]),Ae=Nt(p=>{g.current?.handleKeyDown(p.nativeEvent)},[]),oe=g.current,c=ve??oi,ne=E!==void 0?E:c.text,xe=C!==void 0?C:c.completedParams,me=c.actionableSuggestions,Ce=me[0],ge=oe?.listboxId??"",Pe=c.activeDropdownIndex>=0&&oe?`${ge}-option-${c.activeDropdownIndex}`:void 0,B=c.editingParam,fe=c.editingIdentified,Se=B?{parameter:B.suggestionParameter,text:B.suggestionPlaceholder,required:!0,options:B.options}:fe?{parameter:fe.parameter,text:ai(fe.parameter),required:!0,options:[]}:null,Ne=c.dropdownSuggestion??Se??Ce,Ye=Se?[Se]:me,Re=ti(c),Be=!oe||c.dropdownLoading;return{completedParams:xe,skippedParams:c.skippedParams,identifiedParams:c.identifiedParams,suggestionPills:me,setActivePill:b.setActivePill,skipActivePill:b.skipActivePill,removeLastParam:b.removeLastParam,segments:c.segments,newParamId:c.newParamId,clearNewParamId:b.clearNewParamId,suggestions:c.suggestions,activeIndex:c.activeDropdownIndex,isReady:c.isReady,isLoading:Be,isFocused:c.isFocused,isDropdownOpen:c.isDropdownOpen,isActivePillSelected:c.isActivePillSelected,placeholderText:c.placeholderText,listboxId:ge,error:c.error,products:c.products,customFields:c.customFields,selectProduct:b.selectProduct,handleTextChange:b.handleTextChange,handleKeyDown:b.handleKeyDown,setFocused:b.setFocused,editingParam:B,editingIdentified:fe,editingAnchor:c.editingAnchor,caretOffset:c.caretOffset,startEditingParam:b.startEditingParam,exitEditMode:b.exitEditMode,handleCaretAfterInput:b.handleCaretAfterInput,handleCaretMove:b.handleCaretMove,replaceEditingRange:b.replaceEditingRange,inputProps:{value:ne,placeholder:c.placeholderText||void 0,onChange:we,onKeyDown:Ae,onFocus:b.handleFocus,onBlur:b.handleBlur,role:"combobox","aria-expanded":c.isDropdownOpen,"aria-activedescendant":Pe,"aria-autocomplete":"list","aria-controls":ge},reset:b.reset,recordSubmit:b.recordSubmit,dropdownProps:{suggestions:Ne?[{...Ne,options:c.dropdownOptions}]:[],activeIndex:c.activeDropdownIndex,onSelect:b.selectOption,onHighlight:b.setActiveDropdownIndex,onUnhighlight:b.clearHighlight,isOpen:c.isDropdownOpen,id:ge,pills:Ye,activeSelected:c.isActivePillSelected,onPillClick:b.setActivePill,onSkip:b.skipActivePill,showSkipButton:(K??!0)&&!B&&!fe,showOptionIcons:x??!0,showOptionImages:T??!0,showOptionCounts:I??!0,skipDisabled:c.inSelectionAnimation,isLoading:Be,skeletonExiting:c.skeletonExiting,isInputEmpty:ne.trim().length===0,products:c.products,productImageFallback:A,onProductSelect:b.selectProduct,onProductFocusChange:b.setFocused,formatType:c.activeFormatType,dateView:c.dateView,selectedDateIso:Re.selectedIso,selectedDateRange:Re.selectedRange,dateRangeStart:Re.rangeStart,onPreviousMonth:b.showPreviousMonth,onNextMonth:b.showNextMonth,optionsPosition:w??"below"}}}import{chipIdFromTap as ni,extractPlainText as Bt,getCursorOffset as Ht,keepCaretOnChip as ri,plainTextLength as si,renderEditableContent as li,setCursorOffset as Ft}from"@magicx-eng/ai-autocomplete-vanilla";import{useCallback as Q,useEffect as je,useLayoutEffect as rt,useRef as Ee}from"react";var Qe;function di(){if(Qe!==void 0)return Qe;if(typeof document>"u")return!1;let e=document.createElement("div");return e.setAttribute("contenteditable","plaintext-only"),Qe=e.contentEditable==="plaintext-only",Qe}function Kt(e){let{segments:o,showChipIcons:t=!0,showChipImages:n=!0,newParamId:r,editingParam:i,editingIdentified:a,editingAnchor:l,caretOffset:y,placeholderText:v,isFocused:w,isDropdownOpen:P,listboxId:u,activeDescendantId:x,autoFocus:T,handleTextChange:I,handleKeyDown:K,handleCaretAfterInput:L,handleCaretMove:A,startEditingParam:S,replaceEditingRange:z,setFocused:E}=e,C=Ee(null),H=Ee(!1),X=Ee(""),de=Ee(""),J=Ee(null),ce=Ee(0);J.current=y,je(()=>{if(!T)return;let d=C.current;if(!d)return;document.activeElement===d?E(!0):d.focus();let m=d.ownerDocument??document,h=m.getSelection(),f=h&&h.rangeCount>0&&d.contains(h.anchorNode);if(h&&!f){let k=m.createRange();k.selectNodeContents(d),k.collapse(!0),h.removeAllRanges(),h.addRange(k)}},[T,E]),je(()=>{let d=C.current;if(!d)return;let m=d.ownerDocument??document,h=()=>{let f=m.getSelection();if(!f||f.rangeCount===0||!f.anchorNode||!d.contains(f.anchorNode))return;let k=f.anchorNode,s=k.nodeType===Node.ELEMENT_NODE?k:k.parentElement,N=(f.isCollapsed?s?.closest("strong[data-param-id]"):null)?.dataset.paramId??null,Z=i?.id??a?.id??null;if(N&&N!==Z){S(N);return}performance.now()-ce.current<50||A(Ht(d))};return m.addEventListener("selectionchange",h),()=>m.removeEventListener("selectionchange",h)},[i,a,S,A]),je(()=>{let d=C.current;if(!d)return;let m=h=>{let f=ni(d,h.target);f&&(S(f),ri(d,f))};return d.addEventListener("click",m),()=>d.removeEventListener("click",m)},[S]),rt(()=>{let d=C.current;d&&li({input:d,segments:o,newParamId:r,editingParamId:i?.id??null,placeholderText:v??"",isFocused:w,showChipIcons:t,showChipImages:n})},[o,r,i,v,w,t,n]),rt(()=>{let d=X.current,m=r??"";if(X.current=m,!m||m===d)return;let h=C.current;if(!h)return;h.focus();let f=J.current??si(h);Ft(h,f)},[r]),rt(()=>{let d=de.current,m=i?.id??"";if(de.current=m,!m||m===d||l==null)return;let h=C.current;h&&Ft(h,l)},[i,l]);let G=Q(()=>{if(H.current)return;let d=C.current;if(!d)return;let m=Bt(d),f=m.length>0&&m[0]!==m[0].toUpperCase()?m[0].toUpperCase()+m.slice(1):m;I(f)},[I]),g=Q(()=>{ce.current=performance.now(),G();let d=C.current;d&&L(Ht(d))},[G,L]);je(()=>{let d=C.current;if(!d)return;let m=h=>{let f=h,k=f.inputType;if(k==="insertParagraph"||k==="insertLineBreak"||k==="insertFromDrop"){h.preventDefault();return}if(k.startsWith("insert")||k.startsWith("delete")){let s=k.startsWith("delete")?"":f.data??"";z(s)&&h.preventDefault()}};return d.addEventListener("beforeinput",m),()=>d.removeEventListener("beforeinput",m)},[z]);let ve=Q(()=>{H.current=!0},[]),pe=Q(()=>{H.current=!1,G()},[G]),he=Q(d=>{d.preventDefault();let m=C.current;if(!m)return;let h=(d.clipboardData.getData("text/plain")??"").replace(/\r?\n/g," ");if(!h)return;let f=m.ownerDocument??document,k=f.getSelection();if(!k||k.rangeCount===0)return;let s=k.getRangeAt(0);if(!m.contains(s.startContainer))return;s.deleteContents();let M=f.createTextNode(h);s.insertNode(M),s.setStartAfter(M),s.collapse(!0),k.removeAllRanges(),k.addRange(s),G()},[G]),ee=Q(d=>K(d),[K]),ue=Q(()=>E(!0),[E]),te=Q(()=>E(!1),[E]),Y=Q(()=>C.current?.focus(),[]),_=Q(()=>C.current?.blur(),[]),ae=Q(()=>{let d=C.current;return d?Bt(d):""},[]),ie=di()?"plaintext-only":"true";return{inputRef:C,editorProps:{ref:C,contentEditable:ie,suppressContentEditableWarning:!0,tabIndex:0,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":u,"aria-expanded":P,"aria-activedescendant":x,spellCheck:!0,enterKeyHint:"send",onInput:g,onKeyDown:ee,onCompositionStart:ve,onCompositionEnd:pe,onPaste:he,onFocus:ue,onBlur:te},getPlainText:ae,focus:Y,blur:_}}import{jsx as Te,jsxs as lt}from"react/jsx-runtime";function fi(e){return e!=="auto"?e:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var bi=ci(function({onSubmit:o,onResult:t,onError:n,optionOverrides:r,maskCompletedText:i,className:a,apiConfig:l,additionalContext:y,visitorId:v,columns:w,pillPlacement:P="dropdown",mode:u="auto",optionsPosition:x="below",animations:T=!0,dropdownTrigger:I,closeDropdownOnBlur:K,showNonTappableOptions:L,showOptionIcons:A=!0,showChipIcons:S=!0,showChipImages:z=!0,showOptionImages:E=!0,showOptionCounts:C=!0,showSkipButton:H,showProducts:X,productsLayout:de,productImageFallback:J,autoFocus:ce=!0,onFocus:G,onBlur:g,value:ve,completedParams:pe,onChange:he,onParamsChange:ee,products:ue,onProductSelect:te,submitButton:Y,resetOnSubmit:_=!0},ae){let ie=Me(null),d=Me(null),m=Me(()=>{}),h=Me(null),f=Me(null);Gt(()=>{let R=ie.current;if(R)return h.current?h.current.setMode(u):h.current=new mi(R,u),()=>{h.current?.destroy(),h.current=null}},[u]);let k=st(R=>{let $=f.current?.current;$&&($.focus(),gi($,R))},[]),{completedParams:s,skippedParams:M,identifiedParams:N,isReady:Z,customFields:b,suggestionPills:we,setActivePill:Ae,skipActivePill:oe,segments:c,newParamId:ne,clearNewParamId:xe,placeholderText:me,isFocused:Ce,isDropdownOpen:ge,isActivePillSelected:Pe,isLoading:B,activeIndex:fe,listboxId:Se,handleTextChange:Ne,handleKeyDown:Ye,setFocused:Re,editingParam:Be,editingIdentified:p,editingAnchor:q,caretOffset:D,startEditingParam:Ze,handleCaretAfterInput:Wt,handleCaretMove:_t,replaceEditingRange:qt,dropdownProps:Ut,reset:He,recordSubmit:dt}=nt({onSubmit:R=>m.current(R),onResult:t,onError:n,optionOverrides:r,maskCompletedText:i,apiConfig:l,additionalContext:y,visitorId:v,columns:w,dropdownTrigger:I,optionsPosition:x,closeDropdownOnBlur:K,showNonTappableOptions:L,showOptionIcons:A,showOptionImages:E,showOptionCounts:C,showSkipButton:H,showProducts:X,onFocus:G,onBlur:g,value:ve,completedParams:pe,onChange:he,onParamsChange:ee,products:ue,onProductSelect:te,source:"full-sdk",setCursor:k});Gt(()=>{if(!ne)return;let R=window.setTimeout(()=>xe(),650);return()=>window.clearTimeout(R)},[ne,xe]);let jt=fe>=0?`${Se}-option-${fe}`:void 0,{inputRef:$e,editorProps:Qt,focus:Fe,blur:ct,getPlainText:pt}=Kt({segments:c,newParamId:ne,editingParam:Be,editingIdentified:p,editingAnchor:q,caretOffset:D,placeholderText:me,isFocused:Ce,showChipIcons:S,showChipImages:z,isDropdownOpen:ge,listboxId:Se,activeDescendantId:jt,autoFocus:ce,handleTextChange:Ne,handleKeyDown:Ye,handleCaretAfterInput:Wt,handleCaretMove:_t,startEditingParam:Ze,replaceEditingRange:qt,setFocused:Re});f.current=$e,hi(()=>{let R=d.current,$=$e.current;if(!R||!$)return;let Oe=()=>{let ut=R.firstElementChild;if(!ut)return;let Vt=ut.getBoundingClientRect(),Xt=$.getBoundingClientRect();Vt.top>=Xt.bottom-2?R.setAttribute("data-aia-pill-wrapped",""):R.removeAttribute("data-aia-pill-wrapped")};Oe();let ht=new ResizeObserver(Oe);return ht.observe($),()=>ht.disconnect()},[c,we.length,B,$e]),pi(ae,()=>({focus:Fe,blur:ct,reset:He,setMode:R=>h.current?.setMode(R),skipActivePill:oe}),[Fe,ct,He,oe]);let Ke=!!c.length||s.length>0,Ve=st(R=>{if(!Ke)return;let $=pt(),Oe=ui($,s,M,{identifiedParams:N,isReady:Z,customFields:b});R&&dt(Oe),o(Oe),_&&He()},[dt,_,Ke,s,M,N,Z,b,o,He,pt]);m.current=()=>Ve(!1);let Yt=st(R=>{R.target?.closest("[data-aia-pill]")||Fe()},[Fe]),Zt=P==="inline",$t=P==="dropdown";return lt("div",{ref:ie,className:`magicx-aia ${ye.container} ${a??""}`,"data-pill-placement":P,"data-options-position":x,"data-animations":T?"on":"off","data-mode":fi(u),children:[Te(it,{...Ut,showPills:$t,productsLayout:de,productImageFallback:J}),lt("div",{className:ye.inputWrapper,"data-aia-input-wrapper":"",onClick:Yt,children:[lt("div",{className:ye.editorArea,"data-aia-editor":"",children:[Te("div",{...Qt,className:ye.input,"data-aia-input":""}),Zt&&(B||we.length>0)&&Te("span",{ref:d,className:ye.pillListContainer,"data-aia-pill-list-container":"",children:Te(We,{pills:we,activePillIndex:0,activeSelected:Pe,onSelectPill:Ae,loading:B})})]}),Y===null?null:Y===void 0?Te(Ot,{disabled:!Ke,onClick:()=>Ve(!0)}):Te("span",{"data-aia-submit":"","data-aia-submit-slot":"",className:ye.submitSlot,onClick:R=>{Ke&&(R.stopPropagation(),Ve(!0))},children:Y})]})]})});export{bi as AIAutocomplete,it as AIAutocompleteDropdown,hn as DATE_RANGE_META_END,un as DATE_RANGE_META_START,mn as DEFAULT_OPTION_COUNT_UNIT,Sn as PRODUCT_PATH_PREFIX,zn as WEEKDAY_LABELS,dn as buildSubmitResult,cn as cellDay,pn as cellIso,gn as dateCellMarks,fn as formatDate,bn as formatDateRange,vn as formatOptionCount,wn as isoDate,xn as monthLabel,yn as optionCountLabel,kn as optionHasImage,Cn as optionImageSrc,Pn as optionLabel,In as parseDate,En as parseLooseDate,Tn as parseLooseDateRange,An as productFromMatchedItem,Rn as productsFromCustomFields,On as sanitizeOptionIconSvg,Dn as selectedRangeFor,nt as useAIAutocomplete,Ln as visibleDateRange,Mn as withSkippedParams};
2253
2270
  //# sourceMappingURL=index.mjs.map