@askdialog/dialog-react 0.0.0-beta-20260820152544 → 0.0.0-beta-20260825154538

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.
@@ -203,7 +203,7 @@ const _ = ({
203
203
  f(() => {
204
204
  E({
205
205
  method: "react",
206
- version: "0.0.0-beta-20260820152544"
206
+ version: "0.0.0-beta-20260825154538"
207
207
  }), A("pdp-block");
208
208
  }, []);
209
209
  const u = S(
@@ -590,7 +590,7 @@ const _ = ({
590
590
  }), f(() => {
591
591
  E({
592
592
  method: "react",
593
- version: "0.0.0-beta-20260820152544"
593
+ version: "0.0.0-beta-20260825154538"
594
594
  });
595
595
  const a = r();
596
596
  return () => {
@@ -1 +1 @@
1
- (function(g,s){typeof exports=="object"&&typeof module<"u"?s(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"],s):(g=typeof globalThis<"u"?globalThis:g||self,s(g["dialog-react"]={},g["react/jsx-runtime"],g.React,g.dialogSdk,g.ReactDOM))})(this,(function(g,s,d,p,N){"use strict";const P=({title:e="Your expert",description:t="A question about this product?"})=>s.jsxs("div",{className:"dialog-block-header-container",children:[s.jsx("div",{className:"dialog-block-title",children:e}),s.jsx("div",{className:"dialog-block-description",children:t})]}),m=({color:e="#181825"})=>s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[s.jsxs("g",{clipPath:"url(#clip0_466_934)",children:[s.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"}),s.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"})]}),s.jsx("defs",{children:s.jsx("clipPath",{id:"clip0_466_934",children:s.jsx("rect",{width:"20",height:"20",fill:"white"})})})]}),E=({client:e,questions:t,productId:r,productTitle:o,selectedVariantId:i})=>{const l=a=>{e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:i,question:a,fromQuestionSuggestion:!0})};return s.jsx(s.Fragment,{children:t.map(a=>s.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>l(a.question),children:[s.jsx(m,{color:e.theme.primaryColor}),s.jsx("span",{className:"dialog-block-suggestions-item-label",children:a.question})]},a.question))})},L=()=>s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"})]}),_=({client:e,questions:t,isLoading:r,productId:o,productTitle:i,selectedVariantId:l})=>s.jsx("div",{className:"dialog-block-suggestions-container",children:r||!t?s.jsx(L,{}):s.jsx(E,{client:e,questions:t,productId:o,productTitle:i,selectedVariantId:l})}),A=({color:e="#ffffff"})=>s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:s.jsx("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),C=({client:e,placeholder:t="Ask anything...",productId:r,productTitle:o,selectedVariantId:i})=>{const l=d.useRef(null),[a,n]=d.useState(""),c=()=>{var u;(u=l.current)==null||u.focus()},h=()=>{const u=a;u.trim()&&(e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:i,question:u,fromQuestionSuggestion:!0}),n(""))},b=u=>{u.key==="Enter"&&h()};return s.jsxs("div",{className:"dialog-input-wrapper",onClick:c,children:[s.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:l,value:a,onChange:u=>n(u.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:t,onKeyDown:b}),s.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!a.trim(),onClick:h,children:s.jsx(A,{color:e.theme.ctaTextColor})})]})},y=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),D=e=>{if(!e)return;const t=document.body;Object.keys(e).forEach(r=>{const o=r,i=y(r);if(e[o]!==void 0){if(typeof e[o]=="object"){Object.keys(e[o]).forEach(l=>{var n;const a=l;if(a!==void 0){const c=y(l),h=e[o];t.style.setProperty(`--dialog-theme-${i}-${c}`,(n=h[a])==null?void 0:n.toString())}});return}if(o==="ctaBorderType"){const l=e[o]==="rounded"?"24px":"0";t.style.setProperty(`--dialog-theme-${i}`,l);return}t.style.setProperty(`--dialog-theme-${i}`,e[o].toString())}})},M=({theme:e,children:t})=>(d.useEffect(()=>{e&&D(e)},[e]),s.jsx(s.Fragment,{children:t})),I=({client:e,productId:t,productTitle:r,selectedVariantId:o,enableInput:i=!0})=>{const[l,a]=d.useState(!0),[n,c]=d.useState(void 0);d.useEffect(()=>{p.registerDialogInstallation({method:"react",version:"0.0.0-beta-20260820152544"}),p.addAuditCapability("pdp-block")},[]);const h=d.useMemo(()=>l?"":n==null?void 0:n.assistantName,[n,l]),b=d.useMemo(()=>l?"":n==null?void 0:n.description,[n,l]),u=d.useMemo(()=>l?"":n==null?void 0:n.inputPlaceholder,[n,l]),S=d.useMemo(()=>{var f;return p.resolveTextDirection((f=e.getLocalizationInformations())==null?void 0:f.languageCode)},[e]);return d.useEffect(()=>{let f=!0;return(async()=>{a(!0),c(void 0);try{const v=await e.getSuggestions(t);f&&c(v)}catch(v){console.error("error",v)}finally{f&&a(!1)}})(),()=>{f=!1}},[e,t]),s.jsx(M,{theme:e.theme,children:s.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",dir:S,children:[s.jsx(P,{title:h,description:b}),s.jsx(_,{client:e,questions:n==null?void 0:n.questions,isLoading:l,productId:t,productTitle:r,selectedVariantId:o}),i&&s.jsx(C,{client:e,placeholder:u,productId:t,productTitle:r,selectedVariantId:o})]})})},F=()=>s.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:s.jsx("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O="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",T=({color:e="currentColor"})=>s.jsx("svg",{width:16,height:16,viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:s.jsx("path",{d:O,fill:e})}),B=({controller:e,placeholder:t="Search products...",autoFocus:r=!1,submitAriaLabel:o="Search"})=>{const[i,l]=d.useState(""),a=n=>{n.preventDefault(),e.submit(i)};return s.jsxs("form",{className:"dialog-search-bar",role:"search",onSubmit:a,children:[s.jsxs("div",{className:"dialog-search-bar-field",children:[s.jsx("span",{className:"dialog-search-bar-icon",children:s.jsx(T,{})}),s.jsx("input",{type:"text",name:"dialog-search-query",className:"dialog-search-bar-input",value:i,"aria-label":t,placeholder:t,autoFocus:r,onChange:n=>{l(n.target.value),e.setQuery(n.target.value)}})]}),s.jsx("button",{type:"submit",className:"dialog-search-bar-submit","aria-label":o,children:s.jsx(F,{})})]})},w=({controller:e,state:t})=>{const r=t.response;return r===void 0||r.nbPages<=1?null:s.jsxs("nav",{"aria-label":"Search results pages",className:"dialog-search-pagination",children:[s.jsx("button",{type:"button",disabled:r.page===0,onClick:()=>e.setPage(r.page-1),children:"Previous"}),s.jsxs("span",{children:["Page ",r.page+1," / ",r.nbPages]}),s.jsx("button",{type:"button",disabled:r.page>=r.nbPages-1,onClick:()=>e.setPage(r.page+1),children:"Next"})]})},q=e=>{if(e===void 0)return"";const{min:t,max:r}=e,o=({amount:i,currencyCode:l})=>new Intl.NumberFormat(void 0,{style:"currency",currency:l}).format(Number(i));try{return t.amount===r.amount?o(t):`${o(t)} – ${o(r)}`}catch{return""}},x=e=>{try{const{protocol:t}=new URL(e,window.location.href);return t==="http:"||t==="https:"?e:void 0}catch{return}},k=({controller:e,hit:t,index:r})=>{const o=d.useRef(null);d.useEffect(()=>{o.current!==null&&e.observeResult(o.current,r)},[e,t,r]);const i=u=>{const S=u.metaKey||u.ctrlKey||u.shiftKey||u.altKey;e.selectResult(r,{navigate:!S})&&u.preventDefault()},l=u=>{u.button===1&&e.selectResult(r,{navigate:!1})},{product:a}=t,n=a.title??a.id,c=q(a.priceRange),h=a.url===void 0?void 0:x(a.url),b=s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dialog-search-card-image",children:a.imageUrl!==void 0&&s.jsx("img",{src:a.imageUrl,alt:n,loading:"lazy"})}),s.jsxs("div",{className:"dialog-search-card-info",children:[s.jsx("p",{className:"dialog-search-card-title",children:n}),c!==""&&s.jsx("p",{className:"dialog-search-card-price",children:c})]})]});return s.jsx("li",{ref:o,className:"dialog-search-card",children:h===void 0?s.jsx("div",{className:"dialog-search-card-body",children:b}):s.jsx("a",{className:"dialog-search-card-body",href:h,onClick:i,onAuxClick:l,children:b})})},H=e=>{const t=d.useRef(null),[r,o]=d.useState(void 0),[i,l]=d.useState(0);return d.useLayoutEffect(()=>{if(!e)return;const a=()=>{const n=t.current;if(n===null)return;const c=n.previousElementSibling??n,{top:h,bottom:b,left:u,width:S}=c.getBoundingClientRect();l(window.innerHeight),o(f=>f!==void 0&&f.top===h&&f.bottom===b&&f.left===u&&f.width===S?f:{top:h,bottom:b,left:u,width:S})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[e]),{anchorRef:t,rect:r,viewportHeight:i}},V=(e,t)=>{const[r,o]=d.useState(!1),i=d.useRef(null),l=e.status!==p.SearchStatus.IDLE&&!r;return d.useEffect(()=>{o(!1)},[e.query]),d.useEffect(()=>{if(!l)return;const a=n=>{var S,f;const c=n.target;if(!(c instanceof Node))return;const h=(S=t.current)==null?void 0:S.previousElementSibling,b=((f=i.current)==null?void 0:f.contains(c))??!1,u=(h==null?void 0:h.contains(c))??!1;!b&&!u&&o(!0)};return document.addEventListener("pointerdown",a),()=>document.removeEventListener("pointerdown",a)},[l,t]),d.useEffect(()=>{var c;const a=(c=t.current)==null?void 0:c.previousElementSibling;if(a==null)return;const n=()=>o(!1);return a.addEventListener("focusin",n),()=>a.removeEventListener("focusin",n)},[t]),{isOpen:l,panelRef:i}},K=e=>e instanceof p.DialogSearchError?`Search failed (${e.status}${e.code?` ${e.code}`:""}): ${e.message}`:"Search failed: network error. Check your connection and try again.",$=(e,t)=>e.bottom>0&&e.top<t,X=(e,t)=>{const r=t-e.bottom-8-16,o=e.top-8-16,i={left:e.left,width:e.width};return r<200&&o>r?{...i,bottom:t-e.top+8,maxHeight:Math.max(o,0)}:{...i,top:e.bottom+8,maxHeight:Math.max(r,0)}},j=(e,t)=>{const r=t.response;switch(t.status){case p.SearchStatus.LOADING:return s.jsxs("p",{role:"status",className:"dialog-search-status",children:["Searching “",t.query,"”…"]});case p.SearchStatus.ERROR:return s.jsxs("div",{className:"dialog-search-error",children:[s.jsx("p",{role:"alert",className:"dialog-search-status dialog-search-status-error",children:K(t.error)}),s.jsx("button",{type:"button",className:"dialog-search-retry",onClick:()=>e.retry(),children:"Retry"})]});case p.SearchStatus.EMPTY:return s.jsxs("p",{role:"status",className:"dialog-search-status",children:["No products match “",r==null?void 0:r.query,"”."]});case p.SearchStatus.SUCCESS:return r===void 0?null:s.jsxs(s.Fragment,{children:[s.jsxs("p",{role:"status",className:"dialog-search-status",children:[r.nbHits," result",r.nbHits>1?"s":""]}),s.jsx("ul",{className:"dialog-search-results",children:r.hits.map((o,i)=>s.jsx(k,{controller:e,hit:o,index:i},o.id))}),s.jsx(w,{controller:e,state:t})]});default:return null}},W=({controller:e,state:t})=>{const r=t.status!==p.SearchStatus.IDLE,{anchorRef:o,rect:i,viewportHeight:l}=H(r),{isOpen:a,panelRef:n}=V(t,o);return s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:o}),a&&i!==void 0&&$(i,l)&&N.createPortal(s.jsx("div",{ref:n,className:"dialog-search-panel",style:X(i,l),children:j(e,t)}),document.body)]})},Q={status:p.SearchStatus.IDLE,query:"",page:0},U=e=>{const t=d.useRef(e);t.current=e;const r=d.useRef(void 0),o=d.useCallback(()=>{if(r.current===void 0){const{client:c,surface:h="search_page",...b}=t.current;r.current=p.createSearchController({search:(u,S)=>c.search(u,S),analytics:{surface:h,trackViewSearchResults:u=>c.trackViewSearchResults(u),trackSelectSearchResult:u=>c.trackSelectSearchResult(u)},...b})}return r.current},[]),i=d.useRef(void 0);i.current??(i.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}}),d.useEffect(()=>{p.registerDialogInstallation({method:"react",version:"0.0.0-beta-20260820152544"});const c=o();return()=>{c.dispose(),r.current===c&&(r.current=void 0)}},[o]);const l=d.useCallback(c=>o().subscribe(c),[o]),a=d.useCallback(()=>o().getState(),[o]),n=d.useSyncExternalStore(l,a,()=>Q);return{controller:i.current,state:n}};g.DialogInput=C,g.DialogProductBlock=I,g.DialogSearchBar=B,g.DialogSearchPagination=w,g.DialogSearchProductCard=k,g.DialogSearchResults=W,g.useDialogSearch=U,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(g,s){typeof exports=="object"&&typeof module<"u"?s(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"],s):(g=typeof globalThis<"u"?globalThis:g||self,s(g["dialog-react"]={},g["react/jsx-runtime"],g.React,g.dialogSdk,g.ReactDOM))})(this,(function(g,s,d,p,N){"use strict";const P=({title:e="Your expert",description:t="A question about this product?"})=>s.jsxs("div",{className:"dialog-block-header-container",children:[s.jsx("div",{className:"dialog-block-title",children:e}),s.jsx("div",{className:"dialog-block-description",children:t})]}),m=({color:e="#181825"})=>s.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[s.jsxs("g",{clipPath:"url(#clip0_466_934)",children:[s.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"}),s.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"})]}),s.jsx("defs",{children:s.jsx("clipPath",{id:"clip0_466_934",children:s.jsx("rect",{width:"20",height:"20",fill:"white"})})})]}),E=({client:e,questions:t,productId:r,productTitle:o,selectedVariantId:i})=>{const l=a=>{e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:i,question:a,fromQuestionSuggestion:!0})};return s.jsx(s.Fragment,{children:t.map(a=>s.jsxs("button",{className:"dialog-block-suggestions-item",onClick:()=>l(a.question),children:[s.jsx(m,{color:e.theme.primaryColor}),s.jsx("span",{className:"dialog-block-suggestions-item-label",children:a.question})]},a.question))})},L=()=>s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"}),s.jsx("div",{className:"dialog-block-suggestions-skeleton-item"})]}),_=({client:e,questions:t,isLoading:r,productId:o,productTitle:i,selectedVariantId:l})=>s.jsx("div",{className:"dialog-block-suggestions-container",children:r||!t?s.jsx(L,{}):s.jsx(E,{client:e,questions:t,productId:o,productTitle:i,selectedVariantId:l})}),A=({color:e="#ffffff"})=>s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:s.jsx("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:e,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),C=({client:e,placeholder:t="Ask anything...",productId:r,productTitle:o,selectedVariantId:i})=>{const l=d.useRef(null),[a,n]=d.useState(""),c=()=>{var u;(u=l.current)==null||u.focus()},h=()=>{const u=a;u.trim()&&(e.sendProductMessage({productId:r,productTitle:o,selectedVariantId:i,question:u,fromQuestionSuggestion:!0}),n(""))},b=u=>{u.key==="Enter"&&h()};return s.jsxs("div",{className:"dialog-input-wrapper",onClick:c,children:[s.jsx("input",{id:"dialog-ask-anything-input-ai-input",ref:l,value:a,onChange:u=>n(u.target.value),className:"dialog-ask-anything-input-ai-input",placeholder:t,onKeyDown:b}),s.jsx("button",{id:"send-message-button-ai-input",className:"dialog-input-submit",disabled:!a.trim(),onClick:h,children:s.jsx(A,{color:e.theme.ctaTextColor})})]})},y=e=>e.replace(/([A-Z])/g,"-$1").toLowerCase(),D=e=>{if(!e)return;const t=document.body;Object.keys(e).forEach(r=>{const o=r,i=y(r);if(e[o]!==void 0){if(typeof e[o]=="object"){Object.keys(e[o]).forEach(l=>{var n;const a=l;if(a!==void 0){const c=y(l),h=e[o];t.style.setProperty(`--dialog-theme-${i}-${c}`,(n=h[a])==null?void 0:n.toString())}});return}if(o==="ctaBorderType"){const l=e[o]==="rounded"?"24px":"0";t.style.setProperty(`--dialog-theme-${i}`,l);return}t.style.setProperty(`--dialog-theme-${i}`,e[o].toString())}})},M=({theme:e,children:t})=>(d.useEffect(()=>{e&&D(e)},[e]),s.jsx(s.Fragment,{children:t})),I=({client:e,productId:t,productTitle:r,selectedVariantId:o,enableInput:i=!0})=>{const[l,a]=d.useState(!0),[n,c]=d.useState(void 0);d.useEffect(()=>{p.registerDialogInstallation({method:"react",version:"0.0.0-beta-20260825154538"}),p.addAuditCapability("pdp-block")},[]);const h=d.useMemo(()=>l?"":n==null?void 0:n.assistantName,[n,l]),b=d.useMemo(()=>l?"":n==null?void 0:n.description,[n,l]),u=d.useMemo(()=>l?"":n==null?void 0:n.inputPlaceholder,[n,l]),S=d.useMemo(()=>{var f;return p.resolveTextDirection((f=e.getLocalizationInformations())==null?void 0:f.languageCode)},[e]);return d.useEffect(()=>{let f=!0;return(async()=>{a(!0),c(void 0);try{const v=await e.getSuggestions(t);f&&c(v)}catch(v){console.error("error",v)}finally{f&&a(!1)}})(),()=>{f=!1}},[e,t]),s.jsx(M,{theme:e.theme,children:s.jsxs("div",{id:"dialog-instant",className:"dialog-block-container",dir:S,children:[s.jsx(P,{title:h,description:b}),s.jsx(_,{client:e,questions:n==null?void 0:n.questions,isLoading:l,productId:t,productTitle:r,selectedVariantId:o}),i&&s.jsx(C,{client:e,placeholder:u,productId:t,productTitle:r,selectedVariantId:o})]})})},F=()=>s.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:s.jsx("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O="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",T=({color:e="currentColor"})=>s.jsx("svg",{width:16,height:16,viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:s.jsx("path",{d:O,fill:e})}),B=({controller:e,placeholder:t="Search products...",autoFocus:r=!1,submitAriaLabel:o="Search"})=>{const[i,l]=d.useState(""),a=n=>{n.preventDefault(),e.submit(i)};return s.jsxs("form",{className:"dialog-search-bar",role:"search",onSubmit:a,children:[s.jsxs("div",{className:"dialog-search-bar-field",children:[s.jsx("span",{className:"dialog-search-bar-icon",children:s.jsx(T,{})}),s.jsx("input",{type:"text",name:"dialog-search-query",className:"dialog-search-bar-input",value:i,"aria-label":t,placeholder:t,autoFocus:r,onChange:n=>{l(n.target.value),e.setQuery(n.target.value)}})]}),s.jsx("button",{type:"submit",className:"dialog-search-bar-submit","aria-label":o,children:s.jsx(F,{})})]})},w=({controller:e,state:t})=>{const r=t.response;return r===void 0||r.nbPages<=1?null:s.jsxs("nav",{"aria-label":"Search results pages",className:"dialog-search-pagination",children:[s.jsx("button",{type:"button",disabled:r.page===0,onClick:()=>e.setPage(r.page-1),children:"Previous"}),s.jsxs("span",{children:["Page ",r.page+1," / ",r.nbPages]}),s.jsx("button",{type:"button",disabled:r.page>=r.nbPages-1,onClick:()=>e.setPage(r.page+1),children:"Next"})]})},q=e=>{if(e===void 0)return"";const{min:t,max:r}=e,o=({amount:i,currencyCode:l})=>new Intl.NumberFormat(void 0,{style:"currency",currency:l}).format(Number(i));try{return t.amount===r.amount?o(t):`${o(t)} – ${o(r)}`}catch{return""}},x=e=>{try{const{protocol:t}=new URL(e,window.location.href);return t==="http:"||t==="https:"?e:void 0}catch{return}},k=({controller:e,hit:t,index:r})=>{const o=d.useRef(null);d.useEffect(()=>{o.current!==null&&e.observeResult(o.current,r)},[e,t,r]);const i=u=>{const S=u.metaKey||u.ctrlKey||u.shiftKey||u.altKey;e.selectResult(r,{navigate:!S})&&u.preventDefault()},l=u=>{u.button===1&&e.selectResult(r,{navigate:!1})},{product:a}=t,n=a.title??a.id,c=q(a.priceRange),h=a.url===void 0?void 0:x(a.url),b=s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"dialog-search-card-image",children:a.imageUrl!==void 0&&s.jsx("img",{src:a.imageUrl,alt:n,loading:"lazy"})}),s.jsxs("div",{className:"dialog-search-card-info",children:[s.jsx("p",{className:"dialog-search-card-title",children:n}),c!==""&&s.jsx("p",{className:"dialog-search-card-price",children:c})]})]});return s.jsx("li",{ref:o,className:"dialog-search-card",children:h===void 0?s.jsx("div",{className:"dialog-search-card-body",children:b}):s.jsx("a",{className:"dialog-search-card-body",href:h,onClick:i,onAuxClick:l,children:b})})},H=e=>{const t=d.useRef(null),[r,o]=d.useState(void 0),[i,l]=d.useState(0);return d.useLayoutEffect(()=>{if(!e)return;const a=()=>{const n=t.current;if(n===null)return;const c=n.previousElementSibling??n,{top:h,bottom:b,left:u,width:S}=c.getBoundingClientRect();l(window.innerHeight),o(f=>f!==void 0&&f.top===h&&f.bottom===b&&f.left===u&&f.width===S?f:{top:h,bottom:b,left:u,width:S})};return a(),window.addEventListener("scroll",a,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",a,!0),window.removeEventListener("resize",a)}},[e]),{anchorRef:t,rect:r,viewportHeight:i}},V=(e,t)=>{const[r,o]=d.useState(!1),i=d.useRef(null),l=e.status!==p.SearchStatus.IDLE&&!r;return d.useEffect(()=>{o(!1)},[e.query]),d.useEffect(()=>{if(!l)return;const a=n=>{var S,f;const c=n.target;if(!(c instanceof Node))return;const h=(S=t.current)==null?void 0:S.previousElementSibling,b=((f=i.current)==null?void 0:f.contains(c))??!1,u=(h==null?void 0:h.contains(c))??!1;!b&&!u&&o(!0)};return document.addEventListener("pointerdown",a),()=>document.removeEventListener("pointerdown",a)},[l,t]),d.useEffect(()=>{var c;const a=(c=t.current)==null?void 0:c.previousElementSibling;if(a==null)return;const n=()=>o(!1);return a.addEventListener("focusin",n),()=>a.removeEventListener("focusin",n)},[t]),{isOpen:l,panelRef:i}},K=e=>e instanceof p.DialogSearchError?`Search failed (${e.status}${e.code?` ${e.code}`:""}): ${e.message}`:"Search failed: network error. Check your connection and try again.",$=(e,t)=>e.bottom>0&&e.top<t,X=(e,t)=>{const r=t-e.bottom-8-16,o=e.top-8-16,i={left:e.left,width:e.width};return r<200&&o>r?{...i,bottom:t-e.top+8,maxHeight:Math.max(o,0)}:{...i,top:e.bottom+8,maxHeight:Math.max(r,0)}},j=(e,t)=>{const r=t.response;switch(t.status){case p.SearchStatus.LOADING:return s.jsxs("p",{role:"status",className:"dialog-search-status",children:["Searching “",t.query,"”…"]});case p.SearchStatus.ERROR:return s.jsxs("div",{className:"dialog-search-error",children:[s.jsx("p",{role:"alert",className:"dialog-search-status dialog-search-status-error",children:K(t.error)}),s.jsx("button",{type:"button",className:"dialog-search-retry",onClick:()=>e.retry(),children:"Retry"})]});case p.SearchStatus.EMPTY:return s.jsxs("p",{role:"status",className:"dialog-search-status",children:["No products match “",r==null?void 0:r.query,"”."]});case p.SearchStatus.SUCCESS:return r===void 0?null:s.jsxs(s.Fragment,{children:[s.jsxs("p",{role:"status",className:"dialog-search-status",children:[r.nbHits," result",r.nbHits>1?"s":""]}),s.jsx("ul",{className:"dialog-search-results",children:r.hits.map((o,i)=>s.jsx(k,{controller:e,hit:o,index:i},o.id))}),s.jsx(w,{controller:e,state:t})]});default:return null}},W=({controller:e,state:t})=>{const r=t.status!==p.SearchStatus.IDLE,{anchorRef:o,rect:i,viewportHeight:l}=H(r),{isOpen:a,panelRef:n}=V(t,o);return s.jsxs(s.Fragment,{children:[s.jsx("div",{ref:o}),a&&i!==void 0&&$(i,l)&&N.createPortal(s.jsx("div",{ref:n,className:"dialog-search-panel",style:X(i,l),children:j(e,t)}),document.body)]})},Q={status:p.SearchStatus.IDLE,query:"",page:0},U=e=>{const t=d.useRef(e);t.current=e;const r=d.useRef(void 0),o=d.useCallback(()=>{if(r.current===void 0){const{client:c,surface:h="search_page",...b}=t.current;r.current=p.createSearchController({search:(u,S)=>c.search(u,S),analytics:{surface:h,trackViewSearchResults:u=>c.trackViewSearchResults(u),trackSelectSearchResult:u=>c.trackSelectSearchResult(u)},...b})}return r.current},[]),i=d.useRef(void 0);i.current??(i.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}}),d.useEffect(()=>{p.registerDialogInstallation({method:"react",version:"0.0.0-beta-20260825154538"});const c=o();return()=>{c.dispose(),r.current===c&&(r.current=void 0)}},[o]);const l=d.useCallback(c=>o().subscribe(c),[o]),a=d.useCallback(()=>o().getState(),[o]),n=d.useSyncExternalStore(l,a,()=>Q);return{controller:i.current,state:n}};g.DialogInput=C,g.DialogProductBlock=I,g.DialogSearchBar=B,g.DialogSearchPagination=w,g.DialogSearchProductCard=k,g.DialogSearchResults=W,g.useDialogSearch=U,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askdialog/dialog-react",
3
- "version": "0.0.0-beta-20260820152544",
3
+ "version": "0.0.0-beta-20260825154538",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/dialog-react.umd.js",
@@ -19,14 +19,14 @@
19
19
  "dist"
20
20
  ],
21
21
  "peerDependencies": {
22
- "@askdialog/dialog-sdk": "0.0.0-beta-20260820152544",
22
+ "@askdialog/dialog-sdk": "0.0.0-beta-20260825154538",
23
23
  "react": "^19.0.0",
24
24
  "react-dom": "^19.0.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/react": "^19.2.7",
28
28
  "@types/react-dom": "^19.2.3",
29
- "@askdialog/dialog-sdk": "0.0.0-beta-20260820152544"
29
+ "@askdialog/dialog-sdk": "0.0.0-beta-20260825154538"
30
30
  },
31
31
  "author": "Dialog",
32
32
  "publishConfig": {