@askdialog/dialog-vue 3.2.0 → 3.4.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.
@@ -1,4 +1,4 @@
1
- (function(a,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(a=typeof globalThis<"u"?globalThis:a||self,e(a["dialog-vue"]={},a.Vue))})(this,(function(a,e){"use strict";const E=new Set(["ar","he","iw","fa","ur"]),T=o=>o!==void 0&&E.has(o.trim().toLowerCase().slice(0,2)),I=o=>T(o)?"rtl":"ltr";var _;(function(o){o.OPEN_ASSISTANT="open_assistant",o.CLOSE_ASSISTANT="close_assistant",o.SEND_MESSAGE="PRODUCT_QUESTION",o.SEND_GENERIC_QUESTION="GENERIC_QUESTION",o.TRACK_ADD_TO_CART="TRACK_ADD_TO_CART",o.TRACK_SUBMIT_CHECKOUT="TRACK_SUBMIT_CHECKOUT",o.TRACK_VIEW_SEARCH_RESULTS="TRACK_VIEW_SEARCH_RESULTS",o.TRACK_SELECT_SEARCH_RESULT="TRACK_SELECT_SEARCH_RESULT"})(_||(_={}));var C;(function(o){o.USER_OPENED_ASSISTANT="userOpenedAssistant",o.USER_CLOSED_ASSISTANT="userClosedAssistant",o.USER_SENT_MESSAGE="userSentMessage",o.USER_CLICKED_ON_PRODUCT_CARD="userClickedOnProductCard",o.USER_OPENED_RECOMMENDATION="userOpenedRecommendation",o.USER_ADDED_TO_CART="userAddedToCart",o.USER_SEND_POSITIVE_FEEDBACK="userSendPositiveFeedback",o.USER_SEND_NEGATIVE_FEEDBACK="userSendNegativeFeedback"})(C||(C={})),_.TRACK_ADD_TO_CART,_.TRACK_SUBMIT_CHECKOUT,_.TRACK_VIEW_SEARCH_RESULTS,_.TRACK_SELECT_SEARCH_RESULT;const h="multiple installation methods detected:",R=()=>typeof window>"u"?void 0:window,S=()=>{const o=R();if(o!==void 0)return o.dialog=o.dialog??{},o.dialog.audit=o.dialog.audit??{methods:[],context:{},capabilities:[],warnings:[]},o.dialog.audit},b=o=>{if(o.warnings=o.warnings.filter(t=>!t.startsWith(h)),o.methods.length>=2){const t=o.methods.map(n=>n.method).join(", ");o.warnings.push(`${h} ${t}`)}},A=(o,t)=>t===void 0?o:{version:(o==null?void 0:o.version)??t.version,commit:(o==null?void 0:o.commit)??t.commit},N=o=>{const t=S();if(t===void 0)return;const n=t.methods.find(i=>i.method===o.method);if(n===void 0){t.methods.push({...o,registeredAt:new Date().toISOString()}),b(t);return}n.version=n.version??o.version,n.build=A(n.build,o.build),n.source=n.source??o.source},B=o=>{const t=S();t!==void 0&&(t.capabilities.includes(o)||t.capabilities.push(o))},V={class:"dialog-block-header-container"},L={class:"dialog-block-title"},D={class:"dialog-block-description"},w=e.defineComponent({__name:"DialogBlockHeader",props:{title:{},description:{}},setup(o){const t=o;return(n,i)=>(e.openBlock(),e.createElementBlock("div",V,[e.createElementVNode("div",L,e.toDisplayString(t.title??"Your expert"),1),e.createElementVNode("div",D,e.toDisplayString(t.description??"A question about this product?"),1)]))}}),m=(o,t)=>{const n=o.__vccOpts||o;for(const[i,d]of t)n[i]=d;return n},y=m(w,[["__scopeId","data-v-28e6dda7"]]),O={width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},$={"clip-path":"url(#clip0_466_934)"},U=["stroke"],K=["stroke"],P=e.defineComponent({__name:"AiStarsIcon",props:{color:{}},setup(o){const t=o;return(n,i)=>(e.openBlock(),e.createElementBlock("svg",O,[e.createElementVNode("g",$,[e.createElementVNode("path",{d:`M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011
1
+ (function(S,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(S=typeof globalThis<"u"?globalThis:S||self,e(S["dialog-vue"]={},S.Vue))})(this,(function(S,e){"use strict";var St=Object.defineProperty;var kt=(S,e,B)=>e in S?St(S,e,{enumerable:!0,configurable:!0,writable:!0,value:B}):S[e]=B;var V=(S,e,B)=>kt(S,typeof e!="symbol"?e+"":e,B);const B=new Set(["ar","he","iw","fa","ur"]),Q=o=>o!==void 0&&B.has(o.trim().toLowerCase().slice(0,2)),W=o=>Q(o)?"rtl":"ltr";var D;(function(o){o.OPEN_ASSISTANT="open_assistant",o.CLOSE_ASSISTANT="close_assistant",o.SEND_MESSAGE="PRODUCT_QUESTION",o.SEND_GENERIC_QUESTION="GENERIC_QUESTION",o.TRACK_ADD_TO_CART="TRACK_ADD_TO_CART",o.TRACK_SUBMIT_CHECKOUT="TRACK_SUBMIT_CHECKOUT",o.TRACK_VIEW_SEARCH_RESULTS="TRACK_VIEW_SEARCH_RESULTS",o.TRACK_SELECT_SEARCH_RESULT="TRACK_SELECT_SEARCH_RESULT"})(D||(D={}));var $;(function(o){o.USER_OPENED_ASSISTANT="userOpenedAssistant",o.USER_CLOSED_ASSISTANT="userClosedAssistant",o.USER_SENT_MESSAGE="userSentMessage",o.USER_CLICKED_ON_PRODUCT_CARD="userClickedOnProductCard",o.USER_OPENED_RECOMMENDATION="userOpenedRecommendation",o.USER_ADDED_TO_CART="userAddedToCart",o.USER_SEND_POSITIVE_FEEDBACK="userSendPositiveFeedback",o.USER_SEND_NEGATIVE_FEEDBACK="userSendNegativeFeedback"})($||($={})),D.TRACK_ADD_TO_CART,D.TRACK_SUBMIT_CHECKOUT,D.TRACK_VIEW_SEARCH_RESULTS,D.TRACK_SELECT_SEARCH_RESULT;class Y extends Error{constructor({status:n,code:r,message:i}){super(i);V(this,"status");V(this,"code");this.name="DialogSearchError",this.status=n,this.code=r}}const P="multiple installation methods detected:",z=()=>typeof window>"u"?void 0:window,O=()=>{const o=z();if(o!==void 0)return o.dialog=o.dialog??{},o.dialog.audit=o.dialog.audit??{methods:[],context:{},capabilities:[],warnings:[]},o.dialog.audit},X=o=>{if(o.warnings=o.warnings.filter(t=>!t.startsWith(P)),o.methods.length>=2){const t=o.methods.map(n=>n.method).join(", ");o.warnings.push(`${P} ${t}`)}},Z=(o,t)=>t===void 0?o:{version:(o==null?void 0:o.version)??t.version,commit:(o==null?void 0:o.commit)??t.commit},U=o=>{const t=O();if(t===void 0)return;const n=t.methods.find(r=>r.method===o.method);if(n===void 0){t.methods.push({...o,registeredAt:new Date().toISOString()}),X(t);return}n.version=n.version??o.version,n.build=Z(n.build,o.build),n.source=n.source??o.source},v=o=>{const t=O();t!==void 0&&(t.capabilities.includes(o)||t.capabilities.push(o))},y={IDLE:"idle",LOADING:"loading",SUCCESS:"success",EMPTY:"empty",ERROR:"error"},J=.5,ee=500,te=1500,oe=100;function ne({emit:o,visibilityThreshold:t=J,dwellMs:n=ee,idleFlushMs:r=te,maxItemsPerEvent:i=oe}){let c,a=[];const s=new Set,p=new Map,_=new Map;let d;const u=()=>{clearTimeout(d),!(c===void 0||a.length===0)&&(o({...c,items:a}),a=[])},g=m=>{if(c===void 0)return;const E=`${c.query_id}:${m.product_id}`;if(!s.has(E)){if(s.add(E),a.push(m),a.length>=i){u();return}clearTimeout(d),d=setTimeout(u,r)}},C=m=>{const E=_.get(m);E!==void 0&&(clearTimeout(E),_.delete(m))},l=new IntersectionObserver(m=>{for(const E of m){const h=p.get(E.target);h!==void 0&&(E.intersectionRatio>=t?_.has(E.target)||_.set(E.target,setTimeout(()=>{_.delete(E.target),g(h)},n)):C(E.target))}},{threshold:t}),k=()=>{l.disconnect();for(const m of _.values())clearTimeout(m);_.clear(),p.clear()},b=()=>{u()},w=m=>{if(m.persisted){s.clear();for(const E of p.keys())C(E),l.unobserve(E),l.observe(E)}};return window.addEventListener("pagehide",b),window.addEventListener("pageshow",w),{setContext(m){u(),c!==void 0&&c.query_id!==m.query_id&&s.clear(),c=m,k()},observe(m,E){p.set(m,E),l.observe(m)},forceImpression(m){g(m),u()},flush:u,disconnect(){u(),k(),window.removeEventListener("pagehide",b),window.removeEventListener("pageshow",w)}}}const M=(o,t)=>({product_id:o.hits[t].product.id,position:o.page*o.hitsPerPage+t+1});function re(o){let t,n;const r=()=>(t??(t=ne({emit:o.trackViewSearchResults})),t);return{onResponse(i){n={query_id:i.queryId,surface:o.surface,search_type:"lexical",page:i.page+1,total_hits:i.nbHits,query_length:[...i.query].length},r().setContext(n),i.nbHits===0&&o.trackViewSearchResults({...n,items:[]})},observeResult(i,c,a){r().observe(i,M(c,a))},select(i,c){if(n===void 0)return;const a=M(i,c);r().forceImpression(a),o.trackSelectSearchResult({...n,items:[a]})},dispose(){t==null||t.disconnect()}}}const se=250,ce=12,ae=2,q={status:y.IDLE,query:"",page:0,response:void 0,error:void 0};function ie({search:o,analytics:t,navigate:n,debounceMs:r=se,hitsPerPage:i=ce,locale:c,countryCode:a}){let s=q;const p=new Set,_=re(t);let d,u,g,C=0,l=!1;const k=h=>{s={...s,...h};for(const f of p)f(s)},b=()=>{clearTimeout(d),g==null||g.abort(),g=void 0},w=(h,f)=>{const T={query:h,page:f,hitsPerPage:i};c!==void 0&&(T.locale=c),a!==void 0&&(T.countryCode=a);const R=s.response;return(R==null?void 0:R.query)===h&&(T.queryId=R.queryId),T},m=async(h,f)=>{b(),g=new AbortController;const T=++C,R=w(h,f);k({status:y.LOADING,query:h,page:f});try{const I=await o(R,{signal:g.signal});if(T!==C)return;_.onResponse(I),k({status:I.nbHits===0?y.EMPTY:y.SUCCESS,response:I,error:void 0})}catch(I){if(I instanceof DOMException&&I.name==="AbortError"||T!==C)return;k({status:y.ERROR,error:I,response:void 0})}},E=h=>{const f=h.trim();if(b(),u=void 0,[...f].length<ae){C+=1,k(q);return}return f};return{setQuery(h){const f=l?void 0:E(h);f!==void 0&&(u=f,d=setTimeout(()=>{u=void 0,m(f,0)},r))},submit(h){const f=l?void 0:E(h);f!==void 0&&m(f,0)},setPage(h){if(!l){if(u!==void 0){const f=u;u=void 0,m(f,0);return}s.query!==""&&m(s.query,h)}},retry(){l||s.status!==y.ERROR||m(s.query,s.page)},observeResult(h,f){s.response!==void 0&&_.observeResult(h,s.response,f)},selectResult(h,f){const T=s.response;if(T===void 0)return!1;_.select(T,h);const R=T.hits[h].product.url;return((f==null?void 0:f.navigate)??!0)&&n!==void 0&&R!==void 0?(n(R,T.hits[h]),!0):!1},subscribe(h){return p.add(h),()=>{p.delete(h)}},getState:()=>s,dispose(){l=!0,b(),C+=1,u=void 0,p.clear(),_.dispose()}}}const le={class:"dialog-block-header-container"},de={class:"dialog-block-title"},ue={class:"dialog-block-description"},pe=e.defineComponent({__name:"DialogBlockHeader",props:{title:{},description:{}},setup(o){const t=o;return(n,r)=>(e.openBlock(),e.createElementBlock("div",le,[e.createElementVNode("div",de,e.toDisplayString(t.title??"Your expert"),1),e.createElementVNode("div",ue,e.toDisplayString(t.description??"A question about this product?"),1)]))}}),N=(o,t)=>{const n=o.__vccOpts||o;for(const[r,i]of t)n[r]=i;return n},me=N(pe,[["__scopeId","data-v-28e6dda7"]]),_e={width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},he={"clip-path":"url(#clip0_466_934)"},fe=["stroke"],ge=["stroke"],Ee=e.defineComponent({__name:"AiStarsIcon",props:{color:{}},setup(o){const t=o;return(n,r)=>(e.openBlock(),e.createElementBlock("svg",_e,[e.createElementVNode("g",he,[e.createElementVNode("path",{d:`M5.41675 10.8333L6.07046 12.1408C6.2917 12.5832 6.40232 12.8045 6.55011
2
2
  12.9962C6.68124 13.1663 6.83375 13.3188 7.00388 13.45C7.19559 13.5977 7.41684
3
3
  13.7084 7.85932 13.9296L9.16675 14.5833L7.85932 15.237C7.41684 15.4583 7.19559
4
4
  15.5689 7.00388 15.7167C6.83375 15.8478 6.68124 16.0003 6.55011 16.1704C6.40232
@@ -7,7 +7,7 @@
7
7
  15.7167C3.6379 15.5689 3.41666 15.4583 2.97418 15.237L1.66675 14.5833L2.97418
8
8
  13.9296C3.41666 13.7084 3.6379 13.5977 3.82962 13.45C3.99974 13.3188 4.15225
9
9
  13.1663 4.28339 12.9962C4.43117 12.8045 4.54179 12.5832 4.76303 12.1408L5.41675
10
- 10.8333Z`,stroke:t.color||"#181825","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,8,U),e.createElementVNode("path",{d:`M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175
10
+ 10.8333Z`,stroke:t.color||"#181825","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,8,fe),e.createElementVNode("path",{d:`M12.5001 1.66666L13.4823 4.22034C13.7173 4.83136 13.8348 5.13688 14.0175
11
11
  5.39386C14.1795 5.62162 14.3785 5.82061 14.6062 5.98256C14.8632 6.16529 15.1687
12
12
  6.2828 15.7797 6.5178L18.3334 7.49999L15.7797 8.48217C15.1687 8.71718 14.8632
13
13
  8.83469 14.6062 9.01742C14.3785 9.17937 14.1795 9.37836 14.0175 9.60612C13.8348
@@ -16,4 +16,4 @@
16
16
  9.01742C10.137 8.83469 9.83145 8.71718 9.22043 8.48217L6.66675 7.49999L9.22043
17
17
  6.5178C9.83145 6.28279 10.137 6.16529 10.3939 5.98256C10.6217 5.82061 10.8207
18
18
  5.62162 10.9827 5.39386C11.1654 5.13688 11.2829 4.83136 11.5179 4.22034L12.5001
19
- 1.66666Z`,stroke:t.color||"#181825","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,8,K)]),i[0]||(i[0]=e.createElementVNode("defs",null,[e.createElementVNode("clipPath",{id:"clip0_466_934"},[e.createElementVNode("rect",{width:"20",height:"20",fill:"white"})])],-1))]))}}),M=["onClick"],q={class:"dialog-block-suggestions-item-label"},x=m(e.defineComponent({__name:"DialogBlockSuggestions",props:{client:{},questions:{},productId:{},productTitle:{},selectedVariantId:{}},setup(o){const t=o,n=i=>{t.client.sendProductMessage({productId:t.productId,productTitle:t.productTitle,selectedVariantId:t.selectedVariantId,question:i,fromQuestionSuggestion:!0})};return(i,d)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.questions,c=>(e.openBlock(),e.createElementBlock("button",{key:c.question,class:"dialog-block-suggestions-item",onClick:l=>n(c.question)},[e.createVNode(P,{class:"dialog-block-suggestions-item-icon",color:t.client.theme.primaryColor},null,8,["color"]),e.createElementVNode("span",q,e.toDisplayString(c.question),1)],8,M))),128))}}),[["__scopeId","data-v-db34d4b4"]]),H={};function F(o,t){return e.openBlock(),e.createElementBlock(e.Fragment,null,[t[0]||(t[0]=e.createElementVNode("div",{class:"dialog-block-suggestions-skeleton-item"},null,-1)),t[1]||(t[1]=e.createElementVNode("div",{class:"dialog-block-suggestions-skeleton-item"},null,-1)),t[2]||(t[2]=e.createElementVNode("div",{class:"dialog-block-suggestions-skeleton-item"},null,-1))],64)}const j=m(H,[["render",F],["__scopeId","data-v-26a64b58"]]),G={class:"dialog-block-suggestions-container"},Q=m(e.defineComponent({__name:"DialogBlockSuggestionsContainer",props:{client:{},questions:{},isLoading:{type:Boolean},productId:{},productTitle:{},selectedVariantId:{}},setup(o){const t=o;return(n,i)=>(e.openBlock(),e.createElementBlock("div",G,[t.isLoading||!t.questions?(e.openBlock(),e.createBlock(j,{key:0})):(e.openBlock(),e.createBlock(x,{key:1,client:t.client,questions:t.questions,"product-id":t.productId,"product-title":t.productTitle,"selected-variant-id":t.selectedVariantId},null,8,["client","questions","product-id","product-title","selected-variant-id"]))]))}}),[["__scopeId","data-v-18c9e78b"]]),W={width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Z=["stroke"],z=e.defineComponent({__name:"ArrowIcon",props:{color:{}},setup(o){const t=o;return(n,i)=>(e.openBlock(),e.createElementBlock("svg",W,[e.createElementVNode("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:t.color||"#ffffff","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,8,Z)]))}}),X=["placeholder"],Y=["disabled"],k=m(e.defineComponent({__name:"DialogInput",props:{client:{},placeholder:{},productId:{},productTitle:{},selectedVariantId:{}},setup(o){const t=o,n=e.ref(),i=e.ref(""),d=()=>{var l;(l=n.value)==null||l.focus()},c=()=>{const l=i.value;l.trim()&&(t.client.sendProductMessage({productId:t.productId,productTitle:t.productTitle,selectedVariantId:t.selectedVariantId,question:l,fromQuestionSuggestion:!0}),i.value="")};return(l,r)=>(e.openBlock(),e.createElementBlock("div",{class:"dialog-input-wrapper",onClick:d},[e.withDirectives(e.createElementVNode("input",{id:"dialog-ask-anything-input-ai-input",ref_key:"inputRef",ref:n,"onUpdate:modelValue":r[0]||(r[0]=u=>i.value=u),class:"dialog-ask-anything-input-ai-input",placeholder:t.placeholder??"Ask anything...",onKeydown:e.withKeys(c,["enter"])},null,40,X),[[e.vModelText,i.value]]),e.createElementVNode("button",{id:"send-message-button-ai-input",class:"dialog-input-submit",disabled:!i.value.trim(),onClick:c},[e.createVNode(z,{color:t.client.theme.ctaTextColor},null,8,["color"])],8,Y)]))}}),[["__scopeId","data-v-4f5901c9"]]),J=e.defineComponent({__name:"ThemeProvider",props:{theme:{}},setup(o){const t=o,n=document.body,i=c=>c.replace(/([A-Z])/g,"-$1").toLowerCase(),d=c=>{c&&Object.keys(c).forEach(l=>{const r=l,u=i(l);if(c[r]!==void 0){if(typeof c[r]=="object"){Object.keys(c[r]).forEach(g=>{var p;const s=g;if(s!==void 0){const f=i(g),te=c[r];n.style.setProperty(`--dialog-theme-${u}-${f}`,(p=te[s])==null?void 0:p.toString())}});return}if(r==="ctaBorderType"){const g=c[r]==="rounded"?"24px":"0";n.style.setProperty(`--dialog-theme-${u}`,g);return}n.style.setProperty(`--dialog-theme-${u}`,c[r].toString())}})};return e.onMounted(()=>{t.theme&&d(t.theme)}),e.watch(()=>t.theme,c=>{c&&d(c)},{deep:!0}),(c,l)=>e.renderSlot(c.$slots,"default")}}),v=["dir"],ee=m(e.defineComponent({__name:"DialogProductBlock",props:{client:{},productId:{},productTitle:{},selectedVariantId:{default:void 0},enableInput:{type:Boolean,default:!0}},setup(o){const t=o;e.onMounted(()=>{N({method:"vue",version:"3.2.0"}),B("pdp-block")});const n=e.ref(!0),i=e.ref(void 0),d=e.ref(0),c=e.computed(()=>{var s;return n.value?"":(s=i.value)==null?void 0:s.assistantName}),l=e.computed(()=>{var s;return n.value?"":(s=i.value)==null?void 0:s.description}),r=e.computed(()=>{var s;return n.value?"":(s=i.value)==null?void 0:s.inputPlaceholder}),u=e.computed(()=>{var s;return I((s=t.client.getLocalizationInformations())==null?void 0:s.languageCode)}),g=async()=>{const s=++d.value;n.value=!0,i.value=void 0;try{const p=await t.client.getSuggestions(t.productId);s===d.value&&(i.value=p)}catch(p){console.error("error",p)}finally{s===d.value&&(n.value=!1)}};return e.watch(()=>[t.client,t.productId],()=>{g()},{immediate:!0}),(s,p)=>(e.openBlock(),e.createBlock(J,{theme:t.client.theme},{default:e.withCtx(()=>{var f;return[e.createElementVNode("div",{id:"dialog-instant",class:"dialog-block-container",dir:u.value},[e.createVNode(y,{title:c.value,description:l.value},null,8,["title","description"]),e.createVNode(Q,{client:t.client,questions:(f=i.value)==null?void 0:f.questions,"is-loading":n.value,"product-id":t.productId,"product-title":t.productTitle,"selected-variant-id":t==null?void 0:t.selectedVariantId},null,8,["client","questions","is-loading","product-id","product-title","selected-variant-id"]),t.enableInput?(e.openBlock(),e.createBlock(k,{key:0,client:t.client,placeholder:r.value,"product-id":t.productId,"product-title":t.productTitle,"selected-variant-id":t==null?void 0:t.selectedVariantId},null,8,["client","placeholder","product-id","product-title","selected-variant-id"])):e.createCommentVNode("",!0)],8,v)]}),_:1},8,["theme"]))}}),[["__scopeId","data-v-c57aa677"]]);a.DialogInput=k,a.DialogProductBlock=ee,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
19
+ 1.66666Z`,stroke:t.color||"#181825","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,8,ge)]),r[0]||(r[0]=e.createElementVNode("defs",null,[e.createElementVNode("clipPath",{id:"clip0_466_934"},[e.createElementVNode("rect",{width:"20",height:"20",fill:"white"})])],-1))]))}}),Se=["onClick"],ke={class:"dialog-block-suggestions-item-label"},Ce=N(e.defineComponent({__name:"DialogBlockSuggestions",props:{client:{},questions:{},productId:{},productTitle:{},selectedVariantId:{}},setup(o){const t=o,n=r=>{t.client.sendProductMessage({productId:t.productId,productTitle:t.productTitle,selectedVariantId:t.selectedVariantId,question:r,fromQuestionSuggestion:!0})};return(r,i)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.questions,c=>(e.openBlock(),e.createElementBlock("button",{key:c.question,class:"dialog-block-suggestions-item",onClick:a=>n(c.question)},[e.createVNode(Ee,{class:"dialog-block-suggestions-item-icon",color:t.client.theme.primaryColor},null,8,["color"]),e.createElementVNode("span",ke,e.toDisplayString(c.question),1)],8,Se))),128))}}),[["__scopeId","data-v-db34d4b4"]]),be={};function ye(o,t){return e.openBlock(),e.createElementBlock(e.Fragment,null,[t[0]||(t[0]=e.createElementVNode("div",{class:"dialog-block-suggestions-skeleton-item"},null,-1)),t[1]||(t[1]=e.createElementVNode("div",{class:"dialog-block-suggestions-skeleton-item"},null,-1)),t[2]||(t[2]=e.createElementVNode("div",{class:"dialog-block-suggestions-skeleton-item"},null,-1))],64)}const Te=N(be,[["render",ye],["__scopeId","data-v-26a64b58"]]),we={class:"dialog-block-suggestions-container"},Re=N(e.defineComponent({__name:"DialogBlockSuggestionsContainer",props:{client:{},questions:{},isLoading:{type:Boolean},productId:{},productTitle:{},selectedVariantId:{}},setup(o){const t=o;return(n,r)=>(e.openBlock(),e.createElementBlock("div",we,[t.isLoading||!t.questions?(e.openBlock(),e.createBlock(Te,{key:0})):(e.openBlock(),e.createBlock(Ce,{key:1,client:t.client,questions:t.questions,"product-id":t.productId,"product-title":t.productTitle,"selected-variant-id":t.selectedVariantId},null,8,["client","questions","product-id","product-title","selected-variant-id"]))]))}}),[["__scopeId","data-v-18c9e78b"]]),Ie={width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Ne=["stroke"],Be=e.defineComponent({__name:"ArrowIcon",props:{color:{}},setup(o){const t=o;return(n,r)=>(e.openBlock(),e.createElementBlock("svg",Ie,[e.createElementVNode("path",{d:"M10 16.6667V3.33334M10 3.33334L5 8.33334M10 3.33334L15 8.33334",stroke:t.color||"#ffffff","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,8,Ne)]))}}),De=["placeholder"],Ae=["disabled"],x=N(e.defineComponent({__name:"DialogInput",props:{client:{},placeholder:{},productId:{},productTitle:{},selectedVariantId:{}},setup(o){const t=o,n=e.ref(),r=e.ref(""),i=()=>{var a;(a=n.value)==null||a.focus()},c=()=>{const a=r.value;a.trim()&&(t.client.sendProductMessage({productId:t.productId,productTitle:t.productTitle,selectedVariantId:t.selectedVariantId,question:a,fromQuestionSuggestion:!0}),r.value="")};return(a,s)=>(e.openBlock(),e.createElementBlock("div",{class:"dialog-input-wrapper",onClick:i},[e.withDirectives(e.createElementVNode("input",{id:"dialog-ask-anything-input-ai-input",ref_key:"inputRef",ref:n,"onUpdate:modelValue":s[0]||(s[0]=p=>r.value=p),class:"dialog-ask-anything-input-ai-input",placeholder:t.placeholder??"Ask anything...",onKeydown:e.withKeys(c,["enter"])},null,40,De),[[e.vModelText,r.value]]),e.createElementVNode("button",{id:"send-message-button-ai-input",class:"dialog-input-submit",disabled:!r.value.trim(),onClick:c},[e.createVNode(Be,{color:t.client.theme.ctaTextColor},null,8,["color"])],8,Ae)]))}}),[["__scopeId","data-v-4f5901c9"]]),Le=e.defineComponent({__name:"ThemeProvider",props:{theme:{}},setup(o){const t=o,n=document.body,r=c=>c.replace(/([A-Z])/g,"-$1").toLowerCase(),i=c=>{c&&Object.keys(c).forEach(a=>{const s=a,p=r(a);if(c[s]!==void 0){if(typeof c[s]=="object"){Object.keys(c[s]).forEach(_=>{var u;const d=_;if(d!==void 0){const g=r(_),C=c[s];n.style.setProperty(`--dialog-theme-${p}-${g}`,(u=C[d])==null?void 0:u.toString())}});return}if(s==="ctaBorderType"){const _=c[s]==="rounded"?"24px":"0";n.style.setProperty(`--dialog-theme-${p}`,_);return}n.style.setProperty(`--dialog-theme-${p}`,c[s].toString())}})};return e.onMounted(()=>{t.theme&&i(t.theme)}),e.watch(()=>t.theme,c=>{c&&i(c)},{deep:!0}),(c,a)=>e.renderSlot(c.$slots,"default")}}),Ve=["dir"],$e=N(e.defineComponent({__name:"DialogProductBlock",props:{client:{},productId:{},productTitle:{},selectedVariantId:{default:void 0},enableInput:{type:Boolean,default:!0}},setup(o){const t=o;e.onMounted(()=>{U({method:"vue",version:"3.4.0"}),v("pdp-block")});const n=e.ref(!0),r=e.ref(void 0),i=e.ref(0),c=e.computed(()=>{var d;return n.value?"":(d=r.value)==null?void 0:d.assistantName}),a=e.computed(()=>{var d;return n.value?"":(d=r.value)==null?void 0:d.description}),s=e.computed(()=>{var d;return n.value?"":(d=r.value)==null?void 0:d.inputPlaceholder}),p=e.computed(()=>{var d;return W((d=t.client.getLocalizationInformations())==null?void 0:d.languageCode)}),_=async()=>{const d=++i.value;n.value=!0,r.value=void 0;try{const u=await t.client.getSuggestions(t.productId);d===i.value&&(r.value=u)}catch(u){console.error("error",u)}finally{d===i.value&&(n.value=!1)}};return e.watch(()=>[t.client,t.productId],()=>{_()},{immediate:!0}),(d,u)=>(e.openBlock(),e.createBlock(Le,{theme:t.client.theme},{default:e.withCtx(()=>{var g;return[e.createElementVNode("div",{id:"dialog-instant",class:"dialog-block-container",dir:p.value},[e.createVNode(me,{title:c.value,description:a.value},null,8,["title","description"]),e.createVNode(Re,{client:t.client,questions:(g=r.value)==null?void 0:g.questions,"is-loading":n.value,"product-id":t.productId,"product-title":t.productTitle,"selected-variant-id":t==null?void 0:t.selectedVariantId},null,8,["client","questions","is-loading","product-id","product-title","selected-variant-id"]),t.enableInput?(e.openBlock(),e.createBlock(x,{key:0,client:t.client,placeholder:s.value,"product-id":t.productId,"product-title":t.productTitle,"selected-variant-id":t==null?void 0:t.selectedVariantId},null,8,["client","placeholder","product-id","product-title","selected-variant-id"])):e.createCommentVNode("",!0)],8,Ve)]}),_:1},8,["theme"]))}}),[["__scopeId","data-v-c57aa677"]]),Pe={},Oe={width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"};function Ue(o,t){return e.openBlock(),e.createElementBlock("svg",Oe,t[0]||(t[0]=[e.createElementVNode("path",{d:"M8 13V3M8 3L3 8M8 3L13 8",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},null,-1)]))}const Me=N(Pe,[["render",Ue]]),qe={width:"16",height:"16",viewBox:"0 0 12 12",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"},xe=["fill"],He="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",Ke=e.defineComponent({__name:"ShurikenIcon",props:{color:{}},setup(o){const t=o;return(n,r)=>(e.openBlock(),e.createElementBlock("svg",qe,[e.createElementVNode("path",{d:He,fill:t.color||"currentColor"},null,8,xe)]))}}),Fe={class:"dialog-search-bar-field"},Ge={class:"dialog-search-bar-icon"},je=["aria-label","placeholder","autofocus"],Qe=["aria-label"],We=e.defineComponent({__name:"DialogSearchBar",props:{controller:{},placeholder:{default:"Search products..."},autoFocus:{type:Boolean,default:!1},submitAriaLabel:{default:"Search"}},setup(o){const t=o,n=e.ref(""),r=()=>{t.controller.setQuery(n.value)},i=()=>{t.controller.submit(n.value)};return(c,a)=>(e.openBlock(),e.createElementBlock("form",{class:"dialog-search-bar",role:"search",onSubmit:e.withModifiers(i,["prevent"])},[e.createElementVNode("div",Fe,[e.createElementVNode("span",Ge,[e.createVNode(Ke)]),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":a[0]||(a[0]=s=>n.value=s),type:"text",name:"dialog-search-query",class:"dialog-search-bar-input","aria-label":t.placeholder,placeholder:t.placeholder,autofocus:t.autoFocus,onInput:r},null,40,je),[[e.vModelText,n.value]])]),e.createElementVNode("button",{type:"submit",class:"dialog-search-bar-submit","aria-label":t.submitAriaLabel},[e.createVNode(Me)],8,Qe)],32))}}),Ye={key:0,"aria-label":"Search results pages",class:"dialog-search-pagination"},ze=["disabled"],Xe=["disabled"],H=e.defineComponent({__name:"DialogSearchPagination",props:{controller:{},state:{}},setup(o){const t=o,n=e.computed(()=>t.state.response);return(r,i)=>n.value!==void 0&&n.value.nbPages>1?(e.openBlock(),e.createElementBlock("nav",Ye,[e.createElementVNode("button",{type:"button",disabled:n.value.page===0,onClick:i[0]||(i[0]=c=>t.controller.setPage(n.value.page-1))}," Previous ",8,ze),e.createElementVNode("span",null," Page "+e.toDisplayString(n.value.page+1)+" / "+e.toDisplayString(n.value.nbPages),1),e.createElementVNode("button",{type:"button",disabled:n.value.page>=n.value.nbPages-1,onClick:i[1]||(i[1]=c=>t.controller.setPage(n.value.page+1))}," Next ",8,Xe)])):e.createCommentVNode("",!0)}}),L=({amount:o,currencyCode:t},n)=>new Intl.NumberFormat(n,{style:"currency",currency:t}).format(Number(o)),K=({min:o,max:t},n)=>o.amount===t.amount?L(o,n):`${L(o,n)} – ${L(t,n)}`,Ze=(o,t)=>{if(o===void 0)return"";try{return K(o,t)}catch{return""}},ve=(o,t)=>{const n=o.priceRange,r=o.compareAtPriceRange;if(n===void 0||r===void 0||Number(r.min.amount)<=Number(n.min.amount))return"";try{return K(r,t)}catch{return""}},Je=o=>{try{const{protocol:t}=new URL(o,window.location.href);return t==="http:"||t==="https:"?o:void 0}catch{return}},et={class:"dialog-search-card-image"},tt=["src","alt"],ot={class:"dialog-search-card-info"},nt={class:"dialog-search-card-title"},rt={key:0,class:"dialog-search-card-price"},st={key:0,class:"dialog-search-card-compare-at"},F=e.defineComponent({__name:"DialogSearchProductCardContent",props:{hit:{},locale:{}},setup(o){const t=o,n=e.computed(()=>t.hit.product.title??t.hit.product.id),r=e.computed(()=>Ze(t.hit.product.priceRange,t.locale)),i=e.computed(()=>ve(t.hit.product,t.locale));return(c,a)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",et,[t.hit.product.imageUrl!==void 0?(e.openBlock(),e.createElementBlock("img",{key:0,src:t.hit.product.imageUrl,alt:n.value,loading:"lazy"},null,8,tt)):e.createCommentVNode("",!0)]),e.createElementVNode("div",ot,[e.createElementVNode("p",nt,e.toDisplayString(n.value),1),r.value!==""?(e.openBlock(),e.createElementBlock("p",rt,[e.createTextVNode(e.toDisplayString(r.value),1),i.value!==""?(e.openBlock(),e.createElementBlock("s",st,e.toDisplayString(" "+i.value),1)):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0)])],64))}}),ct={key:0,class:"dialog-search-card-body"},at=["href"],G=e.defineComponent({__name:"DialogSearchProductCard",props:{controller:{},hit:{},index:{},locale:{}},setup(o){const t=o,n=e.ref();e.watch(()=>t.hit,()=>{n.value!==void 0&&t.controller.observeResult(n.value,t.index)},{immediate:!0,flush:"post"});const r=a=>{const s=a.metaKey||a.ctrlKey||a.shiftKey||a.altKey;t.controller.selectResult(t.index,{navigate:!s})&&a.preventDefault()},i=a=>{a.button===1&&t.controller.selectResult(t.index,{navigate:!1})},c=e.computed(()=>t.hit.product.url===void 0?void 0:Je(t.hit.product.url));return(a,s)=>(e.openBlock(),e.createElementBlock("li",{ref_key:"cardRef",ref:n,class:"dialog-search-card"},[c.value===void 0?(e.openBlock(),e.createElementBlock("div",ct,[e.createVNode(F,{hit:t.hit,locale:t.locale},null,8,["hit","locale"])])):(e.openBlock(),e.createElementBlock("a",{key:1,class:"dialog-search-card-body",href:c.value,onClick:r,onAuxclick:i},[e.createVNode(F,{hit:t.hit,locale:t.locale},null,8,["hit","locale"])],40,at))],512))}}),it=o=>{const t=e.ref(),n=e.ref(void 0),r=e.ref(0);return e.watch(o,(i,c,a)=>{if(!i)return;const s=()=>{const p=t.value;if(p===void 0)return;const _=p.previousElementSibling??p,{top:d,bottom:u,left:g,width:C}=_.getBoundingClientRect();r.value=window.innerHeight;const l=n.value;(l===void 0||l.top!==d||l.bottom!==u||l.left!==g||l.width!==C)&&(n.value={top:d,bottom:u,left:g,width:C})};s(),window.addEventListener("scroll",s,!0),window.addEventListener("resize",s),a(()=>{window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",s)})},{immediate:!0,flush:"post"}),{anchorRef:t,rect:n,viewportHeight:r}},lt=(o,t)=>{const n=e.ref(!1),r=e.ref(),i=e.computed(()=>o.value.status!==y.IDLE&&!n.value);e.watch(()=>o.value.query,()=>{n.value=!1}),e.watch(i,(a,s,p)=>{if(!a)return;const _=d=>{var k,b;const u=d.target;if(!(u instanceof Node))return;const g=(k=t.value)==null?void 0:k.previousElementSibling,C=((b=r.value)==null?void 0:b.contains(u))??!1,l=(g==null?void 0:g.contains(u))??!1;!C&&!l&&(n.value=!0)};document.addEventListener("pointerdown",_),p(()=>document.removeEventListener("pointerdown",_))},{immediate:!0});const c=()=>{n.value=!1};return e.onMounted(()=>{var a,s;(s=(a=t.value)==null?void 0:a.previousElementSibling)==null||s.addEventListener("focusin",c)}),e.onUnmounted(()=>{var a,s;(s=(a=t.value)==null?void 0:a.previousElementSibling)==null||s.removeEventListener("focusin",c)}),{isOpen:i,panelRef:r}},dt={key:0,role:"status",class:"dialog-search-status"},ut={key:1,class:"dialog-search-error"},pt={role:"alert",class:"dialog-search-status dialog-search-status-error"},mt={key:2,role:"status",class:"dialog-search-status"},_t={role:"status",class:"dialog-search-status"},ht={class:"dialog-search-results"},A=8,j=16,ft=200,gt=e.defineComponent({__name:"DialogSearchResults",props:{controller:{},state:{},locale:{}},setup(o){const t=o,n=l=>l instanceof Y?`Search failed (${l.status}${l.code?` ${l.code}`:""}): ${l.message}`:"Search failed: network error. Check your connection and try again.",r=(l,k)=>l.bottom>0&&l.top<k,i=(l,k)=>{const b=k-l.bottom-A-j,w=l.top-A-j,m={left:`${l.left}px`,width:`${l.width}px`};return b<ft&&w>b?{...m,bottom:`${k-l.top+A}px`,maxHeight:`${Math.max(w,0)}px`}:{...m,top:`${l.bottom+A}px`,maxHeight:`${Math.max(b,0)}px`}},c=e.computed(()=>t.state),a=e.computed(()=>t.state.status!==y.IDLE),{anchorRef:s,rect:p,viewportHeight:_}=it(a),{isOpen:d,panelRef:u}=lt(c,s),g=e.computed(()=>d.value&&p.value!==void 0&&r(p.value,_.value)),C=e.computed(()=>p.value===void 0?void 0:i(p.value,_.value));return(l,k)=>{var b;return e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{ref_key:"anchorRef",ref:s},null,512),g.value?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:"body"},[e.createElementVNode("div",{ref_key:"panelRef",ref:u,class:"dialog-search-panel",style:e.normalizeStyle(C.value)},[t.state.status===e.unref(y).LOADING?(e.openBlock(),e.createElementBlock("p",dt," Searching “"+e.toDisplayString(t.state.query)+"”… ",1)):t.state.status===e.unref(y).ERROR?(e.openBlock(),e.createElementBlock("div",ut,[e.createElementVNode("p",pt,e.toDisplayString(n(t.state.error)),1),e.createElementVNode("button",{type:"button",class:"dialog-search-retry",onClick:k[0]||(k[0]=w=>t.controller.retry())}," Retry ")])):t.state.status===e.unref(y).EMPTY?(e.openBlock(),e.createElementBlock("p",mt," No products match “"+e.toDisplayString((b=t.state.response)==null?void 0:b.query)+"”. ",1)):t.state.status===e.unref(y).SUCCESS&&t.state.response!==void 0?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[e.createElementVNode("p",_t,e.toDisplayString(t.state.response.nbHits)+" result"+e.toDisplayString(t.state.response.nbHits>1?"s":""),1),e.createElementVNode("ul",ht,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.state.response.hits,(w,m)=>(e.openBlock(),e.createBlock(G,{key:w.id,controller:t.controller,hit:w,index:m,locale:t.locale},null,8,["controller","hit","index","locale"]))),128))]),e.createVNode(H,{controller:t.controller,state:t.state},null,8,["controller","state"])],64)):e.createCommentVNode("",!0)],4)])):e.createCommentVNode("",!0)],64)}}}),Et=o=>{const{client:t,surface:n="search_page",...r}=o,i=ie({search:(s,p)=>t.search(s,p),analytics:{surface:n,trackViewSearchResults:s=>t.trackViewSearchResults(s),trackSelectSearchResult:s=>t.trackSelectSearchResult(s)},...r}),c=e.shallowRef(i.getState()),a=i.subscribe(()=>{c.value=i.getState()});return e.onMounted(()=>{U({method:"vue",version:"3.4.0"})}),e.onUnmounted(()=>{a(),i.dispose()}),{controller:i,state:c}};S.DialogInput=x,S.DialogProductBlock=$e,S.DialogSearchBar=We,S.DialogSearchPagination=H,S.DialogSearchProductCard=G,S.DialogSearchResults=gt,S.useDialogSearch=Et,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,2 @@
1
+ declare const _default: import('vue').DefineComponent<{}, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, SVGSVGElement>;
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ type __VLS_Props = {
2
+ color?: string;
3
+ };
4
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, SVGSVGElement>;
5
+ export default _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@askdialog/dialog-vue",
3
3
  "private": false,
4
- "version": "3.2.0",
4
+ "version": "3.4.0",
5
5
  "type": "module",
6
6
  "main": "./dist/dialog-vue.umd.js",
7
7
  "module": "./dist/dialog-vue.js",
@@ -29,7 +29,7 @@
29
29
  "eslint-plugin-vue": "^10.0.0",
30
30
  "vite-plugin-eslint": "^1.8.1",
31
31
  "vue-tsc": "^2.2.4",
32
- "@askdialog/dialog-sdk": "2.8.0"
32
+ "@askdialog/dialog-sdk": "2.9.0"
33
33
  },
34
34
  "author": "Dialog",
35
35
  "publishConfig": {