@askdialog/dialog-react 2.8.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/dist/components/DialogSearch/DialogSearchCollections.d.ts +2 -2
- package/dist/components/DialogSearch/DialogSearchProductCard.d.ts +2 -2
- package/dist/components/DialogSearch/DialogSearchProducts.d.ts +2 -2
- package/dist/components/DialogSearch/searchCollections.d.ts +3 -3
- package/dist/components/DialogSearch/searchDisplay.d.ts +4 -4
- package/dist/components/DialogSearch/useDialogSearch.d.ts +6 -4
- package/dist/dialog-react.css +1 -1
- package/dist/dialog-react.js +323 -329
- package/dist/dialog-react.umd.cjs +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react/jsx-runtime"),require("react"),require("@askdialog/dialog-sdk"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@askdialog/dialog-sdk","react-dom"],t):(b=typeof globalThis<"u"?globalThis:b||self,t(b["dialog-react"]={},b["react/jsx-runtime"],b.React,b.dialogSdk,b.ReactDOM))})(this,(function(b,t,u,v,F){"use strict";const k={en:{placeholder:"Ask the AI a question",aiDisclosure:"You're chatting with an AI assistant. It can make mistakes, so please double-check important information",askSomethingElse:"Ask something else"},fr:{placeholder:"Posez une question à l'IA",aiDisclosure:"Vous discutez avec un assistant IA. Il peut se tromper, pensez à vérifier les informations importantes",askSomethingElse:"Posez une autre question"},es:{placeholder:"Haz una pregunta a la IA",aiDisclosure:"Estás chateando con un asistente de IA. Puede cometer errores, así que verifica la información importante",askSomethingElse:"Pregunta otra cosa"}},E=e=>{var r;const s=((r=e==null?void 0:e.split("-")[0])==null?void 0:r.toLowerCase())??"en";return k[s]??k.en},z=({client:e,questions:s,disabled:r,productId:o,productTitle:a,selectedVariantId:l})=>{const i=()=>{e.openAssistantWithSuggestions({questions:s??[],product:{id:o,title:a,selectedVariantId:l}})};return t.jsx("button",{type:"button",className:"dialog-ask-something-else",disabled:r,onClick:i,children:E(e.locale).askSomethingElse})},V=({title:e="Your expert",description:s="A question about this product?"})=>t.jsxs("div",{className:"dialog-block-header-container",children:[t.jsx("div",{className:"dialog-block-title",children:e}),t.jsx("div",{className:"dialog-block-description",children:s})]}),K=({color:e="#181825"})=>t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.jsxs("g",{clipPath:"url(#clip0_466_934)",children:[t.jsx("path",{d:"M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011 12.9962C6.68124 13.1663 6.83375 13.3188 7.00388 13.45C7.19559 13.5977 7.41684 13.7084 7.85932 13.9296L9.16675 14.5833L7.85932 15.237C7.41684 15.4583 7.19559 15.5689 7.00388 15.7167C6.83375 15.8478 6.68124 16.0003 6.55011 16.1704C6.40232 16.3622 6.2917 16.5834 6.07046 17.0259L5.41675 18.3333L4.76303 17.0259C4.54179 16.5834 4.43117 16.3622 4.28339 16.1704C4.15225 16.0003 3.99974 15.8478 3.82962 15.7167C3.6379 15.5689 3.41666 15.4583 2.97418 15.237L1.66675 14.5833L2.97418 13.9296C3.41666 13.7084 3.6379 13.5977 3.82962 13.45C3.99974 13.3188 4.15225 13.1663 4.28339 12.9962C4.43117 12.8045 4.54179 12.5832 4.76303 12.1408L5.41675 10.8333Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175 5.39386C14.1795 5.62162 14.3785 5.82061 14.6062 5.98256C14.8632 6.16529 15.1687 6.2828 15.7797 6.5178L18.3334 7.49999L15.7797 8.48217C15.1687 8.71718 14.8632 8.83469 14.6062 9.01742C14.3785 9.17937 14.1795 9.37836 14.0175 9.60612C13.8348 9.8631 13.7173 10.1686 13.4823 10.7796L12.5001 13.3333L11.5179 10.7796C11.2829 10.1686 11.1654 9.8631 10.9827 9.60612C10.8207 9.37836 10.6217 9.17937 10.3939 9.01742C10.137 8.83469 9.83145 8.71718 9.22043 8.48217L6.66675 7.49999L9.22043 6.5178C9.83145 6.28279 10.137 6.16529 10.3939 5.98256C10.6217 5.82061 10.8207 5.62162 10.9827 5.39386C11.1654 5.13688 11.2829 4.83136 11.5179 4.22034L12.5001 1.66666Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),t.jsx("defs",{children:t.jsx("clipPath",{id:"clip0_466_934",children:t.jsx("rect",{width:"20",height:"20",fill:"white"})})})]}),j=({client:e,questions:s,productId:r,productTitle:o,selectedVariantId:a})=>{const l=i=>{e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:a,question:i,fromQuestionSuggestion:!0})};return t.jsx(t.Fragment,{children:s.map(i=>t.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>l(i.question),children:[t.jsx(K,{color:e.theme.primaryColor}),t.jsx("span",{className:"dialog-block-suggestions-item-label",children:i.question})]},i.question))})},U=()=>t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),t.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),t.jsx("div",{className:"dialog-block-suggestions-skeleton-item"})]}),Q=({client:e,questions:s,isLoading:r,productId:o,productTitle:a,selectedVariantId:l})=>t.jsx("div",{className:"dialog-block-suggestions-container",children:r||!s?t.jsx(U,{}):t.jsx(j,{client:e,questions:s,productId:o,productTitle:a,selectedVariantId:l})}),W=({color:e="#ffffff"})=>t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),P=({client:e,productId:s,productTitle:r,selectedVariantId:o})=>{const a=u.useRef(null),[l,i]=u.useState(""),n=E(e.locale),c=()=>{var d;(d=a.current)==null||d.focus()},h=()=>{const d=l;d.trim()&&(e.sendProductMessage({productId:s,productTitle:r,selectedVariantId:o,question:d,fromQuestionSuggestion:!0}),i(""))},p=d=>{d.key==="Enter"&&h()};return t.jsxs("div",{className:"dialog-input-container",children:[t.jsxs("div",{className:"dialog-input-wrapper",onClick:c,children:[t.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:a,value:l,onChange:d=>i(d.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:n.placeholder,"aria-describedby":"dialog-input-ai-disclosure",onKeyDown:p}),t.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!l.trim(),onClick:h,children:t.jsx(W,{color:e.theme.ctaTextColor})})]}),t.jsx("p",{id:"dialog-input-ai-disclosure",className:"dialog-input-ai-disclosure",children:n.aiDisclosure})]})},A=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),Z=e=>{if(!e)return;const s=document.body;Object.keys(e).forEach(r=>{const o=r,a=A(r);if(e[o]!==void 0){if(typeof e[o]=="object"){Object.keys(e[o]).forEach(l=>{var n;const i=l;if(i!==void 0){const c=A(l),h=e[o];s.style.setProperty(`--dialog-theme-${a}-${c}`,(n=h[i])==null?void 0:n.toString())}});return}if(o==="ctaBorderType"){const l=e[o]==="rounded"?"24px":"0";s.style.setProperty(`--dialog-theme-${a}`,l);return}s.style.setProperty(`--dialog-theme-${a}`,e[o].toString())}})},X=({theme:e,children:s})=>(u.useEffect(()=>{e&&Z(e)},[e]),t.jsx(t.Fragment,{children:s})),G=2,Y=5,J=({client:e,productId:s,productTitle:r,selectedVariantId:o,enableInput:a=!1})=>{var g;const[l,i]=u.useState(!0),[n,c]=u.useState(void 0);u.useEffect(()=>{v.registerDialogInstallation({method:"react",version:"2.8.0"}),v.addAuditCapability("pdp-block")},[]);const h=u.useMemo(()=>l?"":n==null?void 0:n.assistantName,[n,l]),p=u.useMemo(()=>l?"":n==null?void 0:n.description,[n,l]),d=u.useMemo(()=>l?"":n==null?void 0:n.inputPlaceholder,[n,l]),f=u.useMemo(()=>{var C;return v.resolveTextDirection((C=e.getLocalizationInformations())==null?void 0:C.languageCode)},[e]);return u.useEffect(()=>{let C=!0;return(async()=>{i(!0),c(void 0);try{const N=await e.getSuggestions(s,{limit:Y});C&&c(N)}catch(N){console.error("error",N)}finally{C&&i(!1)}})(),()=>{C=!1}},[e,s]),t.jsx(X,{theme:e.theme,children:t.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",dir:f,children:[t.jsx(V,{title:h,description:p}),t.jsx(Q,{client:e,questions:(g=n==null?void 0:n.questions)==null?void 0:g.slice(0,G),isLoading:l,productId:s,productTitle:r,selectedVariantId:o}),a?t.jsx(P,{client:e,placeholder:d,productId:s,productTitle:r,selectedVariantId:o}):t.jsx(z,{client:e,questions:n==null?void 0:n.questions,disabled:l,productId:s,productTitle:r,selectedVariantId:o})]})})},R=()=>t.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),ee="M5.3217 0.588255C5.63241 -0.196084 6.36759 -0.196085 6.6783 0.588254C6.98901 1.37259 7.68193 2.82807 8.42693 3.57307C9.17193 4.31807 10.6274 5.01099 11.4117 5.3217C12.1961 5.63241 12.1961 6.36759 11.4117 6.6783C10.6274 6.98901 9.17193 7.68193 8.42693 8.42693C7.68193 9.17193 6.98901 10.6274 6.6783 11.4117C6.36759 12.1961 5.63241 12.1961 5.3217 11.4117C5.01099 10.6274 4.31807 9.17193 3.57307 8.42693C2.82808 7.68193 1.37259 6.98901 0.588255 6.6783C-0.196084 6.36759 -0.196085 5.63241 0.588254 5.3217C1.37259 5.01099 2.82807 4.31807 3.57307 3.57307C4.31807 2.82808 5.01099 1.37259 5.3217 0.588255Z",se=({color:e="currentColor"})=>t.jsx("svg",{width:16,height:16,viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:ee,fill:e})}),te=({controller:e,placeholder:s="Search products...",autoFocus:r=!1,submitAriaLabel:o="Search"})=>{const[a,l]=u.useState(""),i=n=>{n.preventDefault(),e.submit(a)};return t.jsxs("form",{className:"dialog-search-bar",role:"search",onSubmit:i,children:[t.jsxs("div",{className:"dialog-search-bar-field",children:[t.jsx("span",{className:"dialog-search-bar-icon",children:t.jsx(se,{})}),t.jsx("input",{type:"text",name:"dialog-search-query",className:"dialog-search-bar-input",value:a,"aria-label":s,placeholder:s,autoFocus:r,onChange:n=>{l(n.target.value),e.setQuery(n.target.value)}})]}),t.jsx("button",{type:"submit",className:"dialog-search-bar-submit","aria-label":o,children:t.jsx(R,{})})]})},oe=(e,s)=>{try{return new Intl.NumberFormat(s).format(e)}catch{return String(e)}},I={en:e=>({searching:s=>`Searching “${s}”…`,noResults:"No matching products",retry:"Retry",collectionsLabel:"Collections",productsLabel:"Products",collectionsCount:s=>s===1?"1 collection":`${e(s)} collections`,resultsCount:s=>s===1?"1 result":`${e(s)} results`,seeAllLabel:s=>s===1?"See the result":`See all ${e(s)} results`,previous:"Previous",next:"Next",pageOf:(s,r)=>`Page ${e(s)} / ${e(r)}`}),fr:e=>({searching:s=>`Recherche de « ${s} »…`,noResults:"Aucun produit correspondant",retry:"Réessayer",collectionsLabel:"Collections",productsLabel:"Produits",collectionsCount:s=>s===1?"1 collection":`${e(s)} collections`,resultsCount:s=>s===1?"1 résultat":`${e(s)} résultats`,seeAllLabel:s=>s===1?"Voir le résultat":`Voir les ${e(s)} résultats`,previous:"Précédent",next:"Suivant",pageOf:(s,r)=>`Page ${e(s)} / ${e(r)}`}),de:e=>({searching:s=>`Suche nach „${s}“…`,noResults:"Keine passenden Produkte",retry:"Erneut versuchen",collectionsLabel:"Kollektionen",productsLabel:"Produkte",collectionsCount:s=>s===1?"1 Kollektion":`${e(s)} Kollektionen`,resultsCount:s=>s===1?"1 Ergebnis":`${e(s)} Ergebnisse`,seeAllLabel:s=>s===1?"Das Ergebnis anzeigen":`Alle ${e(s)} Ergebnisse anzeigen`,previous:"Zurück",next:"Weiter",pageOf:(s,r)=>`Seite ${e(s)} / ${e(r)}`}),es:e=>({searching:s=>`Buscando «${s}»…`,noResults:"No hay productos que coincidan",retry:"Reintentar",collectionsLabel:"Colecciones",productsLabel:"Productos",collectionsCount:s=>s===1?"1 colección":`${e(s)} colecciones`,resultsCount:s=>s===1?"1 resultado":`${e(s)} resultados`,seeAllLabel:s=>s===1?"Ver el resultado":`Ver los ${e(s)} resultados`,previous:"Anterior",next:"Siguiente",pageOf:(s,r)=>`Página ${e(s)} / ${e(r)}`}),it:e=>({searching:s=>`Ricerca di “${s}”…`,noResults:"Nessun prodotto corrispondente",retry:"Riprova",collectionsLabel:"Collezioni",productsLabel:"Prodotti",collectionsCount:s=>s===1?"1 collezione":`${e(s)} collezioni`,resultsCount:s=>s===1?"1 risultato":`${e(s)} risultati`,seeAllLabel:s=>s===1?"Vedi il risultato":`Vedi tutti i ${e(s)} risultati`,previous:"Precedente",next:"Successivo",pageOf:(s,r)=>`Pagina ${e(s)} / ${e(r)}`})},x=e=>{var o;const s=((o=e==null?void 0:e.split("-")[0])==null?void 0:o.toLowerCase())??"en";return(I[s]??I.en)(a=>oe(a,e))},$=e=>e.status!==v.SearchStatus.LOADING&&e.response!==void 0&&e.response.nbPages>1,D=({controller:e,state:s,locale:r})=>{const o=s.response;if(o===void 0||!$(s))return null;const a=x(r);return t.jsxs("nav",{"aria-label":"Search results pages",className:"dialog-search-pagination",children:[t.jsx("button",{type:"button",disabled:o.page===0,onClick:()=>e.setPage(o.page-1),children:a.previous}),t.jsx("span",{children:a.pageOf(o.page+1,o.nbPages)}),t.jsx("button",{type:"button",disabled:o.page>=o.nbPages-1,onClick:()=>e.setPage(o.page+1),children:a.next})]})},M=e=>e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").replace(/ẞ/gu,"ß").toUpperCase().toLowerCase().replace(/ς/g,"σ"),re=(e,s)=>{const r={before:"",match:e,after:""},o=M(s.trim());if(o==="")return r;const a=[...e],l=[];let i="";a.forEach((p,d)=>{const f=M(p);for(let g=0;g<f.length;g+=1)l.push(d);i+=f});const n=i.indexOf(o);if(n===-1)return r;const c=l[n],h=l[n+o.length-1]+1;return{before:a.slice(0,c).join(""),match:a.slice(c,h).join(""),after:a.slice(h).join("")}},T=({title:e,query:s})=>{const{before:r,match:o,after:a}=re(e,s);return t.jsxs(t.Fragment,{children:[r!==""&&t.jsx("span",{className:"dialog-search-muted",children:r}),t.jsx("span",{className:"dialog-search-match",children:o}),a!==""&&t.jsx("span",{className:"dialog-search-muted",children:a})]})},ae=({amount:e,currencyCode:s},r)=>s===void 0?new Intl.NumberFormat(r).format(Number(e)):new Intl.NumberFormat(r,{style:"currency",currency:s}).format(Number(e)),ne=(e,s)=>{if(e===void 0)return"";try{return ae(e.min,s)}catch{return""}},le=e=>{try{const{protocol:s}=new URL(e,window.location.href);return s==="http:"||s==="https:"?e:void 0}catch{return}},O=e=>e.url===void 0||e.url===""?void 0:le(e.url),_=e=>e.title??e.handle??e.objectID,q=({controller:e,hit:s,index:r,locale:o,query:a=""})=>{const l=u.useRef(null);u.useEffect(()=>{l.current!==null&&e.observeResult(l.current,r)},[e,s,r]);const i=d=>{const f=d.metaKey||d.ctrlKey||d.shiftKey||d.altKey;e.selectResult(r,{navigate:!f})&&d.preventDefault()},n=d=>{d.button===1&&e.selectResult(r,{navigate:!1})},c=ne(s.priceRange,o),h=O(s),p=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"dialog-search-product-thumb","aria-hidden":!0,children:s.imageUrl!==void 0&&s.imageUrl!==""&&t.jsx("img",{src:s.imageUrl,alt:"",loading:"lazy"})}),t.jsx("span",{className:"dialog-search-product-title",children:t.jsx(T,{title:_(s),query:a})}),c!==""&&t.jsx("span",{className:"dialog-search-product-price",children:c})]});return t.jsx("li",{ref:l,className:"dialog-search-card",children:h===void 0?t.jsx("div",{className:"dialog-search-product",children:p}):t.jsx("a",{className:"dialog-search-product",href:h,onClick:i,onAuxClick:n,children:p})})},ce=()=>t.jsx("svg",{width:16,height:16,viewBox:"0 0 256 256",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:"M221.66,133.66l-72,72a8,8,0,0,1-11.32-11.32L196.69,136H40a8,8,0,0,1,0-16H196.69L138.34,61.66a8,8,0,0,1,11.32-11.32l72,72A8,8,0,0,1,221.66,133.66Z"})}),ie=()=>t.jsx("svg",{width:12,height:12,viewBox:"0 0 256 256",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:"M181.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L164.69,128,90.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,181.66,133.66Z"})}),H=e=>(e??[]).flatMap(s=>{const r=O(s);return r===void 0?[]:[{collection:s,href:r}]}),de=({collections:e,query:s,messages:r})=>{const o=H(e);return o.length===0?null:t.jsxs("aside",{className:"dialog-search-collections",children:[t.jsxs("div",{className:"dialog-search-section-head",children:[t.jsx("p",{className:"dialog-search-label",children:r.collectionsLabel}),t.jsx("span",{className:"dialog-search-count",children:r.collectionsCount(o.length)})]}),t.jsx("ul",{className:"dialog-search-collection-list",children:o.map(({collection:a,href:l})=>t.jsx("li",{children:t.jsxs("a",{className:"dialog-search-collection",href:l,children:[t.jsx("span",{className:"dialog-search-collection-thumb","aria-hidden":!0,children:a.imageUrl!==void 0&&a.imageUrl!==""&&t.jsx("img",{src:a.imageUrl,alt:"",loading:"lazy"})}),t.jsx("span",{className:"dialog-search-collection-title",children:t.jsx(T,{title:_(a),query:s})}),t.jsx("span",{className:"dialog-search-caret",children:t.jsx(ie,{})})]})},a.objectID))})]})},ue=({controller:e,response:s,locale:r,messages:o})=>t.jsxs("section",{className:"dialog-search-products",children:[t.jsx("div",{className:"dialog-search-section-head",children:t.jsxs("p",{className:"dialog-search-label",children:[o.productsLabel,s.nbHits>0&&t.jsx("span",{className:"dialog-search-label-count",children:` · ${o.resultsCount(s.nbHits)}`})]})}),t.jsx("ul",{className:"dialog-search-results",children:s.hits.length===0?t.jsx("li",{className:"dialog-search-empty",role:"status",children:o.noResults}):s.hits.map((a,l)=>t.jsx(q,{controller:e,hit:a,index:l,locale:r,query:s.query},a.objectID))})]}),y=8,S=16,he=200,ge=1440,pe=(e,s)=>e.bottom>0&&e.top<s,fe=(e,s)=>{const r=Math.min(ge,s-2*S),o=e.left+e.width/2-r/2;return{left:Math.min(Math.max(o,S),s-S-r),width:r}},be=(e,s,r)=>{const o=r-e.bottom-y-S,a=e.top-y-S,l=fe(e,s);return o<he&&a>o?{...l,bottom:r-e.top+y,maxHeight:Math.max(a,0)}:{...l,top:e.bottom+y,maxHeight:Math.max(o,0)}},ve=e=>{const s=e.trim().replace(/^#/,"");if(!/^(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(s))return;const r=s.length<=4?[...s].map(o=>o+o).join(""):s;return[0,2,4].map(o=>Number.parseInt(r.slice(o,o+2),16))},Ce=e=>{const s=/^rgba?\((\d+), (\d+), (\d+)(?:, [\d.]+)?\)$/.exec(e);if(s!==null)return[s[1],s[2],s[3]].map(Number)},Se=e=>{if(typeof document>"u")return;const s=document.createElement("span");if(s.style.color=e,s.style.color==="")return;document.body.appendChild(s);const r=Ce(getComputedStyle(s).color);return s.remove(),r},ye=e=>ve(e)??Se(e),me=e=>{const s=e/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4},B=e=>{const s=ye(e);if(s===void 0)return;const[r,o,a]=s.map(me);return .2126*r+.7152*o+.0722*a},we="#181825",Le="#ffffff",Ne="straight",w=.5,L={light:{panel:"#ffffff",side:"#fafbfc",text:"#111827","text-sec":"#6b7280",border:"#eceef2",hover:"#eef2f7",thumb:"#eef1f5"},dark:{panel:"#15171c",side:"#1b1e25",text:"#f3f4f6","text-sec":"#9ca3af",border:"#2b2f38",hover:"#242830",thumb:"#2b2f38"}},ke={rectangle:{"r-panel":"4px","r-item":"4px","r-thumb":"2px","r-btn":"4px"},"rectangle-rounded":{"r-panel":"16px","r-item":"10px","r-thumb":"8px","r-btn":"10px"}},m=e=>e===void 0||e.trim()===""?void 0:e.trim(),Ee=e=>{const s=e===void 0?void 0:B(e);return s===void 0?"light":s<w?"dark":"light"},Pe=(e,s)=>{const r=B(e);return r===void 0?L[s].text:(s==="light"?r<w:r>=w)?e:L[s].text},Ae=e=>{const s=Ee(m(e==null?void 0:e.backgroundColor)),r=(e==null?void 0:e.ctaBorderType)===Ne?"rectangle":"rectangle-rounded",o=m(e==null?void 0:e.primaryColor)??we,a=m(e==null?void 0:e.fontFamily),l={...L[s],...ke[r],primary:o,accent:Pe(o,s),"cta-text":m(e==null?void 0:e.ctaTextColor)??Le,...a===void 0?{}:{font:a}};return Object.fromEntries(Object.entries(l).map(([i,n])=>[`--dso-${i}`,n]))},Ie=e=>{const s=u.useRef(null),[r,o]=u.useState(void 0),[a,l]=u.useState({width:0,height:0});return u.useLayoutEffect(()=>{if(!e)return;const i=()=>{const n=s.current;if(n===null)return;const c=n.previousElementSibling??n,{top:h,bottom:p,left:d,width:f}=c.getBoundingClientRect();l(g=>g.width===window.innerWidth&&g.height===window.innerHeight?g:{width:window.innerWidth,height:window.innerHeight}),o(g=>g!==void 0&&g.top===h&&g.bottom===p&&g.left===d&&g.width===f?g:{top:h,bottom:p,left:d,width:f})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[e]),{anchorRef:s,rect:r,viewport:a}},xe=(e,s)=>{const[r,o]=u.useState(!1),a=u.useRef(null),l=e.status!==v.SearchStatus.IDLE&&!r;return u.useEffect(()=>{o(!1)},[e.query]),u.useEffect(()=>{if(!l)return;const i=n=>{var f,g;const c=n.target;if(!(c instanceof Node))return;const h=(f=s.current)==null?void 0:f.previousElementSibling,p=((g=a.current)==null?void 0:g.contains(c))??!1,d=(h==null?void 0:h.contains(c))??!1;!p&&!d&&o(!0)};return document.addEventListener("pointerdown",i),()=>document.removeEventListener("pointerdown",i)},[l,s]),u.useEffect(()=>{var c;const i=(c=s.current)==null?void 0:c.previousElementSibling;if(i==null)return;const n=()=>o(!1);return i.addEventListener("focusin",n),()=>i.removeEventListener("focusin",n)},[s]),{isOpen:l,panelRef:a}},$e=e=>e instanceof v.DialogSearchError?`Search failed (${e.status}${e.code?` ${e.code}`:""}): ${e.message}`:"Search failed: network error. Check your connection and try again.",De=(e,s)=>{var f,g;const{controller:r,state:o,locale:a,seeAllHref:l}=e,{status:i,response:n}=o;if(i===v.SearchStatus.ERROR)return t.jsxs("div",{className:"dialog-search-error",children:[t.jsx("p",{role:"alert",className:"dialog-search-status dialog-search-status-error",children:$e(o.error)}),t.jsx("button",{type:"button",className:"dialog-search-retry",onClick:()=>r.retry(),children:s.retry})]});if(n===void 0)return t.jsx("p",{role:"status",className:"dialog-search-status",children:s.searching(o.query)});const c=((g=(f=o.sections)==null?void 0:f.collections)==null?void 0:g.hits)??[],h=H(c).length>0,p=l!==void 0&&n.nbHits>0,d=!p&&$(o);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:`dialog-search-body${h?"":" dialog-search-body--no-collections"}`,children:[t.jsx(de,{collections:c,query:n.query,messages:s}),t.jsx(ue,{controller:r,response:n,locale:a,messages:s})]}),(p||d)&&t.jsx("div",{className:"dialog-search-footer",children:p?t.jsxs("a",{className:"dialog-search-cta",href:l(n.query),children:[s.seeAllLabel(n.nbHits),t.jsx(ce,{})]}):t.jsx(D,{controller:r,state:o,locale:a})})]})},Me=e=>{const{state:s,locale:r,theme:o,layout:a="list"}=e,l=s.status!==v.SearchStatus.IDLE,{anchorRef:i,rect:n,viewport:c}=Ie(l),{isOpen:h,panelRef:p}=xe(s,i),d=x(r),f=u.useMemo(()=>Ae(o),[o]);return t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:i}),h&&n!==void 0&&pe(n,c.height)&&F.createPortal(t.jsx("div",{ref:p,className:`dialog-search-panel dialog-search-panel--${a}`,style:{...be(n,c.width,c.height),...f},children:De(e,d)}),document.body)]})},Te={status:v.SearchStatus.IDLE,query:"",page:0},Oe=e=>{const s=u.useRef(e);s.current=e;const r=u.useRef(void 0),o=u.useCallback(()=>{if(r.current===void 0){const{client:c,surface:h="search_page",...p}=s.current;r.current=v.createSearchController({search:(d,f)=>c.search(d,f),analytics:{surface:h,trackViewSearchResults:d=>c.trackViewSearchResults(d),trackSelectSearchResult:d=>c.trackSelectSearchResult(d)},...p})}return r.current},[]),a=u.useRef(void 0);a.current??(a.current={setQuery:c=>o().setQuery(c),submit:c=>o().submit(c),setPage:c=>o().setPage(c),retry:()=>o().retry(),observeResult:(c,h)=>o().observeResult(c,h),selectResult:(c,h)=>o().selectResult(c,h),subscribe:c=>o().subscribe(c),getState:()=>o().getState(),dispose:()=>{var c;(c=r.current)==null||c.dispose(),r.current=void 0}}),u.useEffect(()=>{v.registerDialogInstallation({method:"react",version:"2.8.0"});const c=o();return()=>{c.dispose(),r.current===c&&(r.current=void 0)}},[o]);const l=u.useCallback(c=>o().subscribe(c),[o]),i=u.useCallback(()=>o().getState(),[o]),n=u.useSyncExternalStore(l,i,()=>Te);return{controller:a.current,state:n,theme:e.client.theme}};b.DialogInput=P,b.DialogProductBlock=J,b.DialogSearchBar=te,b.DialogSearchPagination=D,b.DialogSearchProductCard=q,b.DialogSearchResults=Me,b.useDialogSearch=Oe,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(b,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("react/jsx-runtime"),require("react"),require("@askdialog/dialog-sdk"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@askdialog/dialog-sdk","react-dom"],t):(b=typeof globalThis<"u"?globalThis:b||self,t(b["dialog-react"]={},b["react/jsx-runtime"],b.React,b.dialogSdk,b.ReactDOM))})(this,(function(b,t,d,C,F){"use strict";const k={en:{placeholder:"Ask the AI a question",aiDisclosure:"You're chatting with an AI assistant. It can make mistakes, so please double-check important information",askSomethingElse:"Ask something else"},fr:{placeholder:"Posez une question à l'IA",aiDisclosure:"Vous discutez avec un assistant IA. Il peut se tromper, pensez à vérifier les informations importantes",askSomethingElse:"Posez une autre question"},es:{placeholder:"Haz una pregunta a la IA",aiDisclosure:"Estás chateando con un asistente de IA. Puede cometer errores, así que verifica la información importante",askSomethingElse:"Pregunta otra cosa"}},E=e=>{var r;const s=((r=e==null?void 0:e.split("-")[0])==null?void 0:r.toLowerCase())??"en";return k[s]??k.en},z=({client:e,questions:s,disabled:r,productId:o,productTitle:a,selectedVariantId:c})=>{const i=()=>{e.openAssistantWithSuggestions({questions:s??[],product:{id:o,title:a,selectedVariantId:c}})};return t.jsx("button",{type:"button",className:"dialog-ask-something-else",disabled:r,onClick:i,children:E(e.locale).askSomethingElse})},V=({title:e="Your expert",description:s="A question about this product?"})=>t.jsxs("div",{className:"dialog-block-header-container",children:[t.jsx("div",{className:"dialog-block-title",children:e}),t.jsx("div",{className:"dialog-block-description",children:s})]}),K=({color:e="#181825"})=>t.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[t.jsxs("g",{clipPath:"url(#clip0_466_934)",children:[t.jsx("path",{d:"M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011 12.9962C6.68124 13.1663 6.83375 13.3188 7.00388 13.45C7.19559 13.5977 7.41684 13.7084 7.85932 13.9296L9.16675 14.5833L7.85932 15.237C7.41684 15.4583 7.19559 15.5689 7.00388 15.7167C6.83375 15.8478 6.68124 16.0003 6.55011 16.1704C6.40232 16.3622 6.2917 16.5834 6.07046 17.0259L5.41675 18.3333L4.76303 17.0259C4.54179 16.5834 4.43117 16.3622 4.28339 16.1704C4.15225 16.0003 3.99974 15.8478 3.82962 15.7167C3.6379 15.5689 3.41666 15.4583 2.97418 15.237L1.66675 14.5833L2.97418 13.9296C3.41666 13.7084 3.6379 13.5977 3.82962 13.45C3.99974 13.3188 4.15225 13.1663 4.28339 12.9962C4.43117 12.8045 4.54179 12.5832 4.76303 12.1408L5.41675 10.8333Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175 5.39386C14.1795 5.62162 14.3785 5.82061 14.6062 5.98256C14.8632 6.16529 15.1687 6.2828 15.7797 6.5178L18.3334 7.49999L15.7797 8.48217C15.1687 8.71718 14.8632 8.83469 14.6062 9.01742C14.3785 9.17937 14.1795 9.37836 14.0175 9.60612C13.8348 9.8631 13.7173 10.1686 13.4823 10.7796L12.5001 13.3333L11.5179 10.7796C11.2829 10.1686 11.1654 9.8631 10.9827 9.60612C10.8207 9.37836 10.6217 9.17937 10.3939 9.01742C10.137 8.83469 9.83145 8.71718 9.22043 8.48217L6.66675 7.49999L9.22043 6.5178C9.83145 6.28279 10.137 6.16529 10.3939 5.98256C10.6217 5.82061 10.8207 5.62162 10.9827 5.39386C11.1654 5.13688 11.2829 4.83136 11.5179 4.22034L12.5001 1.66666Z",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),t.jsx("defs",{children:t.jsx("clipPath",{id:"clip0_466_934",children:t.jsx("rect",{width:"20",height:"20",fill:"white"})})})]}),j=({client:e,questions:s,productId:r,productTitle:o,selectedVariantId:a})=>{const c=i=>{e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:a,question:i,fromQuestionSuggestion:!0})};return t.jsx(t.Fragment,{children:s.map(i=>t.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>c(i.question),children:[t.jsx(K,{color:e.theme.primaryColor}),t.jsx("span",{className:"dialog-block-suggestions-item-label",children:i.question})]},i.question))})},U=()=>t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),t.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),t.jsx("div",{className:"dialog-block-suggestions-skeleton-item"})]}),Q=({client:e,questions:s,isLoading:r,productId:o,productTitle:a,selectedVariantId:c})=>t.jsx("div",{className:"dialog-block-suggestions-container",children:r||!s?t.jsx(U,{}):t.jsx(j,{client:e,questions:s,productId:o,productTitle:a,selectedVariantId:c})}),W=({color:e="#ffffff"})=>t.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:t.jsx("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),P=({client:e,productId:s,productTitle:r,selectedVariantId:o})=>{const a=d.useRef(null),[c,i]=d.useState(""),n=E(e.locale),l=()=>{var u;(u=a.current)==null||u.focus()},g=()=>{const u=c;u.trim()&&(e.sendProductMessage({productId:s,productTitle:r,selectedVariantId:o,question:u,fromQuestionSuggestion:!0}),i(""))},p=u=>{u.key==="Enter"&&g()};return t.jsxs("div",{className:"dialog-input-container",children:[t.jsxs("div",{className:"dialog-input-wrapper",onClick:l,children:[t.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:a,value:c,onChange:u=>i(u.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:n.placeholder,"aria-describedby":"dialog-input-ai-disclosure",onKeyDown:p}),t.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!c.trim(),onClick:g,children:t.jsx(W,{color:e.theme.ctaTextColor})})]}),t.jsx("p",{id:"dialog-input-ai-disclosure",className:"dialog-input-ai-disclosure",children:n.aiDisclosure})]})},A=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),Z=e=>{if(!e)return;const s=document.body;Object.keys(e).forEach(r=>{const o=r,a=A(r);if(e[o]!==void 0){if(typeof e[o]=="object"){Object.keys(e[o]).forEach(c=>{var n;const i=c;if(i!==void 0){const l=A(c),g=e[o];s.style.setProperty(`--dialog-theme-${a}-${l}`,(n=g[i])==null?void 0:n.toString())}});return}if(o==="ctaBorderType"){const c=e[o]==="rounded"?"24px":"0";s.style.setProperty(`--dialog-theme-${a}`,c);return}s.style.setProperty(`--dialog-theme-${a}`,e[o].toString())}})},X=({theme:e,children:s})=>(d.useEffect(()=>{e&&Z(e)},[e]),t.jsx(t.Fragment,{children:s})),G=2,Y=5,J=({client:e,productId:s,productTitle:r,selectedVariantId:o,enableInput:a=!1})=>{var h;const[c,i]=d.useState(!0),[n,l]=d.useState(void 0);d.useEffect(()=>{C.registerDialogInstallation({method:"react",version:"2.10.0"}),C.addAuditCapability("pdp-block")},[]);const g=d.useMemo(()=>c?"":n==null?void 0:n.assistantName,[n,c]),p=d.useMemo(()=>c?"":n==null?void 0:n.description,[n,c]),u=d.useMemo(()=>c?"":n==null?void 0:n.inputPlaceholder,[n,c]),f=d.useMemo(()=>{var v;return C.resolveTextDirection((v=e.getLocalizationInformations())==null?void 0:v.languageCode)},[e]);return d.useEffect(()=>{let v=!0;return(async()=>{i(!0),l(void 0);try{const N=await e.getSuggestions(s,{limit:Y});v&&l(N)}catch(N){console.error("error",N)}finally{v&&i(!1)}})(),()=>{v=!1}},[e,s]),t.jsx(X,{theme:e.theme,children:t.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",dir:f,children:[t.jsx(V,{title:g,description:p}),t.jsx(Q,{client:e,questions:(h=n==null?void 0:n.questions)==null?void 0:h.slice(0,G),isLoading:c,productId:s,productTitle:r,selectedVariantId:o}),a?t.jsx(P,{client:e,placeholder:u,productId:s,productTitle:r,selectedVariantId:o}):t.jsx(z,{client:e,questions:n==null?void 0:n.questions,disabled:c,productId:s,productTitle:r,selectedVariantId:o})]})})},R=()=>t.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),ee="M5.3217 0.588255C5.63241 -0.196084 6.36759 -0.196085 6.6783 0.588254C6.98901 1.37259 7.68193 2.82807 8.42693 3.57307C9.17193 4.31807 10.6274 5.01099 11.4117 5.3217C12.1961 5.63241 12.1961 6.36759 11.4117 6.6783C10.6274 6.98901 9.17193 7.68193 8.42693 8.42693C7.68193 9.17193 6.98901 10.6274 6.6783 11.4117C6.36759 12.1961 5.63241 12.1961 5.3217 11.4117C5.01099 10.6274 4.31807 9.17193 3.57307 8.42693C2.82808 7.68193 1.37259 6.98901 0.588255 6.6783C-0.196084 6.36759 -0.196085 5.63241 0.588254 5.3217C1.37259 5.01099 2.82807 4.31807 3.57307 3.57307C4.31807 2.82808 5.01099 1.37259 5.3217 0.588255Z",se=({color:e="currentColor"})=>t.jsx("svg",{width:16,height:16,viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:ee,fill:e})}),te=({controller:e,placeholder:s="Search products...",autoFocus:r=!1,submitAriaLabel:o="Search"})=>{const[a,c]=d.useState(""),i=n=>{n.preventDefault(),e.submit(a)};return t.jsxs("form",{className:"dialog-search-bar",role:"search",onSubmit:i,children:[t.jsxs("div",{className:"dialog-search-bar-field",children:[t.jsx("span",{className:"dialog-search-bar-icon",children:t.jsx(se,{})}),t.jsx("input",{type:"text",name:"dialog-search-query",className:"dialog-search-bar-input",value:a,"aria-label":s,placeholder:s,autoFocus:r,onChange:n=>{c(n.target.value),e.setQuery(n.target.value)}})]}),t.jsx("button",{type:"submit",className:"dialog-search-bar-submit","aria-label":o,children:t.jsx(R,{})})]})},oe=(e,s)=>{try{return new Intl.NumberFormat(s).format(e)}catch{return String(e)}},I={en:e=>({searching:s=>`Searching “${s}”…`,noResults:"No matching products",retry:"Retry",collectionsLabel:"Collections",productsLabel:"Products",collectionsCount:s=>s===1?"1 collection":`${e(s)} collections`,resultsCount:s=>s===1?"1 result":`${e(s)} results`,seeAllLabel:s=>s===1?"See the result":`See all ${e(s)} results`,previous:"Previous",next:"Next",pageOf:(s,r)=>`Page ${e(s)} / ${e(r)}`}),fr:e=>({searching:s=>`Recherche de « ${s} »…`,noResults:"Aucun produit correspondant",retry:"Réessayer",collectionsLabel:"Collections",productsLabel:"Produits",collectionsCount:s=>s===1?"1 collection":`${e(s)} collections`,resultsCount:s=>s===1?"1 résultat":`${e(s)} résultats`,seeAllLabel:s=>s===1?"Voir le résultat":`Voir les ${e(s)} résultats`,previous:"Précédent",next:"Suivant",pageOf:(s,r)=>`Page ${e(s)} / ${e(r)}`}),de:e=>({searching:s=>`Suche nach „${s}“…`,noResults:"Keine passenden Produkte",retry:"Erneut versuchen",collectionsLabel:"Kollektionen",productsLabel:"Produkte",collectionsCount:s=>s===1?"1 Kollektion":`${e(s)} Kollektionen`,resultsCount:s=>s===1?"1 Ergebnis":`${e(s)} Ergebnisse`,seeAllLabel:s=>s===1?"Das Ergebnis anzeigen":`Alle ${e(s)} Ergebnisse anzeigen`,previous:"Zurück",next:"Weiter",pageOf:(s,r)=>`Seite ${e(s)} / ${e(r)}`}),es:e=>({searching:s=>`Buscando «${s}»…`,noResults:"No hay productos que coincidan",retry:"Reintentar",collectionsLabel:"Colecciones",productsLabel:"Productos",collectionsCount:s=>s===1?"1 colección":`${e(s)} colecciones`,resultsCount:s=>s===1?"1 resultado":`${e(s)} resultados`,seeAllLabel:s=>s===1?"Ver el resultado":`Ver los ${e(s)} resultados`,previous:"Anterior",next:"Siguiente",pageOf:(s,r)=>`Página ${e(s)} / ${e(r)}`}),it:e=>({searching:s=>`Ricerca di “${s}”…`,noResults:"Nessun prodotto corrispondente",retry:"Riprova",collectionsLabel:"Collezioni",productsLabel:"Prodotti",collectionsCount:s=>s===1?"1 collezione":`${e(s)} collezioni`,resultsCount:s=>s===1?"1 risultato":`${e(s)} risultati`,seeAllLabel:s=>s===1?"Vedi il risultato":`Vedi tutti i ${e(s)} risultati`,previous:"Precedente",next:"Successivo",pageOf:(s,r)=>`Pagina ${e(s)} / ${e(r)}`})},x=e=>{var o;const s=((o=e==null?void 0:e.split("-")[0])==null?void 0:o.toLowerCase())??"en";return(I[s]??I.en)(a=>oe(a,e))},$=e=>e.status!==C.SearchStatus.LOADING&&e.response!==void 0&&e.response.nbPages>1,D=({controller:e,state:s,locale:r})=>{const o=s.response;if(o===void 0||!$(s))return null;const a=x(r);return t.jsxs("nav",{"aria-label":"Search results pages",className:"dialog-search-pagination",children:[t.jsx("button",{type:"button",disabled:o.page===0,onClick:()=>e.setPage(o.page-1),children:a.previous}),t.jsx("span",{children:a.pageOf(o.page+1,o.nbPages)}),t.jsx("button",{type:"button",disabled:o.page>=o.nbPages-1,onClick:()=>e.setPage(o.page+1),children:a.next})]})},M=e=>e.normalize("NFD").replace(new RegExp("\\p{M}","gu"),"").replace(/ẞ/gu,"ß").toUpperCase().toLowerCase().replace(/ς/g,"σ"),re=(e,s)=>{const r={before:"",match:e,after:""},o=M(s.trim());if(o==="")return r;const a=[...e],c=[];let i="";a.forEach((p,u)=>{const f=M(p);for(let h=0;h<f.length;h+=1)c.push(u);i+=f});const n=i.indexOf(o);if(n===-1)return r;const l=c[n],g=c[n+o.length-1]+1;return{before:a.slice(0,l).join(""),match:a.slice(l,g).join(""),after:a.slice(g).join("")}},T=({title:e,query:s})=>{const{before:r,match:o,after:a}=re(e,s);return t.jsxs(t.Fragment,{children:[r!==""&&t.jsx("span",{className:"dialog-search-muted",children:r}),t.jsx("span",{className:"dialog-search-match",children:o}),a!==""&&t.jsx("span",{className:"dialog-search-muted",children:a})]})},ae=e=>e.product_image||e.image||void 0,O=e=>{if(!(e===void 0||e===""))try{const{protocol:s}=new URL(e,window.location.href);return s==="http:"||s==="https:"?e:void 0}catch{return}},ne=e=>O(e.url),_=e=>e.title??e.handle??e.objectID,q=({controller:e,hit:s,index:r,locale:o,query:a=""})=>{const c=d.useRef(null);d.useEffect(()=>{c.current!==null&&e.observeResult(c.current,r)},[e,s,r]);const i=h=>{const v=h.metaKey||h.ctrlKey||h.shiftKey||h.altKey;e.selectResult(r,{navigate:!v})&&h.preventDefault()},n=h=>{h.button===1&&e.selectResult(r,{navigate:!1})},l=C.formatSearchPrice(s,o),g=C.formatSearchCompareAtPrice(s,o),p=O(e.productUrl(s)),u=ae(s),f=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"dialog-search-product-thumb","aria-hidden":!0,children:u!==void 0&&t.jsx("img",{src:u,alt:"",loading:"lazy"})}),t.jsx("span",{className:"dialog-search-product-title",children:t.jsx(T,{title:_(s),query:a})}),l!==""&&t.jsxs("span",{className:"dialog-search-product-price",children:[g!==""&&t.jsx("s",{className:"dialog-search-product-compare-at",children:g}),l]})]});return t.jsx("li",{ref:c,className:"dialog-search-card",children:p===void 0?t.jsx("div",{className:"dialog-search-product",children:f}):t.jsx("a",{className:"dialog-search-product",href:p,onClick:i,onAuxClick:n,children:f})})},ce=()=>t.jsx("svg",{width:16,height:16,viewBox:"0 0 256 256",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:"M221.66,133.66l-72,72a8,8,0,0,1-11.32-11.32L196.69,136H40a8,8,0,0,1,0-16H196.69L138.34,61.66a8,8,0,0,1,11.32-11.32l72,72A8,8,0,0,1,221.66,133.66Z"})}),le=()=>t.jsx("svg",{width:12,height:12,viewBox:"0 0 256 256",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:t.jsx("path",{d:"M181.66,133.66l-80,80a8,8,0,0,1-11.32-11.32L164.69,128,90.34,53.66a8,8,0,0,1,11.32-11.32l80,80A8,8,0,0,1,181.66,133.66Z"})}),H=e=>(e??[]).flatMap(s=>{const r=ne(s);return r===void 0?[]:[{collection:s,href:r}]}),ie=({collections:e,query:s,messages:r})=>{const o=H(e);return o.length===0?null:t.jsxs("aside",{className:"dialog-search-collections",children:[t.jsxs("div",{className:"dialog-search-section-head",children:[t.jsx("p",{className:"dialog-search-label",children:r.collectionsLabel}),t.jsx("span",{className:"dialog-search-count",children:r.collectionsCount(o.length)})]}),t.jsx("ul",{className:"dialog-search-collection-list",children:o.map(({collection:a,href:c})=>t.jsx("li",{children:t.jsxs("a",{className:"dialog-search-collection",href:c,children:[t.jsx("span",{className:"dialog-search-collection-thumb","aria-hidden":!0,children:a.image?t.jsx("img",{src:a.image,alt:"",loading:"lazy"}):null}),t.jsx("span",{className:"dialog-search-collection-title",children:t.jsx(T,{title:_(a),query:s})}),t.jsx("span",{className:"dialog-search-caret",children:t.jsx(le,{})})]})},a.objectID))})]})},de=({controller:e,response:s,locale:r,messages:o})=>t.jsxs("section",{className:"dialog-search-products",children:[t.jsx("div",{className:"dialog-search-section-head",children:t.jsxs("p",{className:"dialog-search-label",children:[o.productsLabel,s.nbHits>0&&t.jsx("span",{className:"dialog-search-label-count",children:` · ${o.resultsCount(s.nbHits)}`})]})}),t.jsx("ul",{className:"dialog-search-results",children:s.hits.length===0?t.jsx("li",{className:"dialog-search-empty",role:"status",children:o.noResults}):s.hits.map((a,c)=>t.jsx(q,{controller:e,hit:a,index:c,locale:r,query:s.query},a.objectID))})]}),y=8,S=16,ue=200,he=1440,ge=(e,s)=>e.bottom>0&&e.top<s,pe=(e,s)=>{const r=Math.min(he,s-2*S),o=e.left+e.width/2-r/2;return{left:Math.min(Math.max(o,S),s-S-r),width:r}},fe=(e,s,r)=>{const o=r-e.bottom-y-S,a=e.top-y-S,c=pe(e,s);return o<ue&&a>o?{...c,bottom:r-e.top+y,maxHeight:Math.max(a,0)}:{...c,top:e.bottom+y,maxHeight:Math.max(o,0)}},be=e=>{const s=e.trim().replace(/^#/,"");if(!/^(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(s))return;const r=s.length<=4?[...s].map(o=>o+o).join(""):s;return[0,2,4].map(o=>Number.parseInt(r.slice(o,o+2),16))},Ce=e=>{const s=/^rgba?\((\d+), (\d+), (\d+)(?:, [\d.]+)?\)$/.exec(e);if(s!==null)return[s[1],s[2],s[3]].map(Number)},ve=e=>{if(typeof document>"u")return;const s=document.createElement("span");if(s.style.color=e,s.style.color==="")return;document.body.appendChild(s);const r=Ce(getComputedStyle(s).color);return s.remove(),r},Se=e=>be(e)??ve(e),ye=e=>{const s=e/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4},B=e=>{const s=Se(e);if(s===void 0)return;const[r,o,a]=s.map(ye);return .2126*r+.7152*o+.0722*a},me="#181825",we="#ffffff",Le="straight",w=.5,L={light:{panel:"#ffffff",side:"#fafbfc",text:"#111827","text-sec":"#6b7280",border:"#eceef2",hover:"#eef2f7",thumb:"#eef1f5"},dark:{panel:"#15171c",side:"#1b1e25",text:"#f3f4f6","text-sec":"#9ca3af",border:"#2b2f38",hover:"#242830",thumb:"#2b2f38"}},Ne={rectangle:{"r-panel":"4px","r-item":"4px","r-thumb":"2px","r-btn":"4px"},"rectangle-rounded":{"r-panel":"16px","r-item":"10px","r-thumb":"8px","r-btn":"10px"}},m=e=>e===void 0||e.trim()===""?void 0:e.trim(),ke=e=>{const s=e===void 0?void 0:B(e);return s===void 0?"light":s<w?"dark":"light"},Ee=(e,s)=>{const r=B(e);return r===void 0?L[s].text:(s==="light"?r<w:r>=w)?e:L[s].text},Pe=e=>{const s=ke(m(e==null?void 0:e.backgroundColor)),r=(e==null?void 0:e.ctaBorderType)===Le?"rectangle":"rectangle-rounded",o=m(e==null?void 0:e.primaryColor)??me,a=m(e==null?void 0:e.fontFamily),c={...L[s],...Ne[r],primary:o,accent:Ee(o,s),"cta-text":m(e==null?void 0:e.ctaTextColor)??we,...a===void 0?{}:{font:a}};return Object.fromEntries(Object.entries(c).map(([i,n])=>[`--dso-${i}`,n]))},Ae=e=>{const s=d.useRef(null),[r,o]=d.useState(void 0),[a,c]=d.useState({width:0,height:0});return d.useLayoutEffect(()=>{if(!e)return;const i=()=>{const n=s.current;if(n===null)return;const l=n.previousElementSibling??n,{top:g,bottom:p,left:u,width:f}=l.getBoundingClientRect();c(h=>h.width===window.innerWidth&&h.height===window.innerHeight?h:{width:window.innerWidth,height:window.innerHeight}),o(h=>h!==void 0&&h.top===g&&h.bottom===p&&h.left===u&&h.width===f?h:{top:g,bottom:p,left:u,width:f})};return i(),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),()=>{window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i)}},[e]),{anchorRef:s,rect:r,viewport:a}},Ie=(e,s)=>{const[r,o]=d.useState(!1),a=d.useRef(null),c=e.status!==C.SearchStatus.IDLE&&!r;return d.useEffect(()=>{o(!1)},[e.query]),d.useEffect(()=>{if(!c)return;const i=n=>{var f,h;const l=n.target;if(!(l instanceof Node))return;const g=(f=s.current)==null?void 0:f.previousElementSibling,p=((h=a.current)==null?void 0:h.contains(l))??!1,u=(g==null?void 0:g.contains(l))??!1;!p&&!u&&o(!0)};return document.addEventListener("pointerdown",i),()=>document.removeEventListener("pointerdown",i)},[c,s]),d.useEffect(()=>{var l;const i=(l=s.current)==null?void 0:l.previousElementSibling;if(i==null)return;const n=()=>o(!1);return i.addEventListener("focusin",n),()=>i.removeEventListener("focusin",n)},[s]),{isOpen:c,panelRef:a}},xe=e=>e instanceof C.DialogSearchError?`Search failed (${e.status}${e.code?` ${e.code}`:""}): ${e.message}`:"Search failed: network error. Check your connection and try again.",$e=(e,s)=>{var f,h;const{controller:r,state:o,locale:a,seeAllHref:c}=e,{status:i,response:n}=o;if(i===C.SearchStatus.ERROR)return t.jsxs("div",{className:"dialog-search-error",children:[t.jsx("p",{role:"alert",className:"dialog-search-status dialog-search-status-error",children:xe(o.error)}),t.jsx("button",{type:"button",className:"dialog-search-retry",onClick:()=>r.retry(),children:s.retry})]});if(n===void 0)return t.jsx("p",{role:"status",className:"dialog-search-status",children:s.searching(o.query)});const l=((h=(f=o.sections)==null?void 0:f.collections)==null?void 0:h.hits)??[],g=H(l).length>0,p=c!==void 0&&n.nbHits>0,u=!p&&$(o);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:`dialog-search-body${g?"":" dialog-search-body--no-collections"}`,children:[t.jsx(ie,{collections:l,query:n.query,messages:s}),t.jsx(de,{controller:r,response:n,locale:a,messages:s})]}),(p||u)&&t.jsx("div",{className:"dialog-search-footer",children:p?t.jsxs("a",{className:"dialog-search-cta",href:c(n.query),children:[s.seeAllLabel(n.nbHits),t.jsx(ce,{})]}):t.jsx(D,{controller:r,state:o,locale:a})})]})},De=e=>{const{state:s,locale:r,theme:o,layout:a="list"}=e,c=s.status!==C.SearchStatus.IDLE,{anchorRef:i,rect:n,viewport:l}=Ae(c),{isOpen:g,panelRef:p}=Ie(s,i),u=x(r),f=d.useMemo(()=>Pe(o),[o]);return t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:i}),g&&n!==void 0&&ge(n,l.height)&&F.createPortal(t.jsx("div",{ref:p,className:`dialog-search-panel dialog-search-panel--${a}`,style:{...fe(n,l.width,l.height),...f},children:$e(e,u)}),document.body)]})},Me={status:C.SearchStatus.IDLE,query:"",page:0},Te=e=>{const s=d.useRef(e);s.current=e;const r=d.useRef(void 0),o=d.useCallback(()=>{if(r.current===void 0){const{client:l,surface:g="search_page",...p}=s.current;r.current=C.createSearchController({search:(u,f)=>l.search(u,f),analytics:{surface:g,trackViewSearchResults:u=>l.trackViewSearchResults(u),trackSelectSearchResult:u=>l.trackSelectSearchResult(u)},...p})}return r.current},[]),a=d.useRef(void 0);a.current??(a.current={setQuery:l=>o().setQuery(l),submit:l=>o().submit(l),setPage:l=>o().setPage(l),retry:()=>o().retry(),observeResult:(l,g)=>o().observeResult(l,g),selectResult:(l,g)=>o().selectResult(l,g),productUrl:l=>o().productUrl(l),subscribe:l=>o().subscribe(l),getState:()=>o().getState(),dispose:()=>{var l;(l=r.current)==null||l.dispose(),r.current=void 0}}),d.useEffect(()=>{C.registerDialogInstallation({method:"react",version:"2.10.0"});const l=o();return()=>{l.dispose(),r.current===l&&(r.current=void 0)}},[o]);const c=d.useCallback(l=>o().subscribe(l),[o]),i=d.useCallback(()=>o().getState(),[o]),n=d.useSyncExternalStore(c,i,()=>Me);return{controller:a.current,state:n,theme:e.client.theme}};b.DialogInput=P,b.DialogProductBlock=J,b.DialogSearchBar=te,b.DialogSearchPagination=D,b.DialogSearchProductCard=q,b.DialogSearchResults=De,b.useDialogSearch=Te,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askdialog/dialog-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/dialog-react.umd.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "^19.2.7",
|
|
28
28
|
"@types/react-dom": "^19.2.3",
|
|
29
|
-
"@askdialog/dialog-sdk": "2.
|
|
29
|
+
"@askdialog/dialog-sdk": "2.17.0"
|
|
30
30
|
},
|
|
31
31
|
"author": "Dialog",
|
|
32
32
|
"publishConfig": {
|