@dropins/storefront-pdp 0.2.3-beta1 → 0.2.3-beta2
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 +1 @@
|
|
|
1
|
-
import*as pe from"@dropins/tools/preact-compat.js";import{useState as J,Children as de,useRef as ye,useMemo as ve,useEffect as te,useCallback as Y}from"@dropins/tools/preact-compat.js";import{debounce as Le,classes as E,VComponent as H,toLanguageTag as Ne,Slot as G}from"@dropins/tools/lib.js";import{Button as we,Icon as be,Price as Se,Picker as We,ColorSwatch as Ue,ImageSwatch as He,TextSwatch as Ve,Incrementer as qe,Breadcrumbs as je,Image as De}from"@dropins/tools/components.js";import{jsxs as U,jsx as t,Fragment as Pe}from"@dropins/tools/preact-jsx-runtime.js";import{useText as z}from"@dropins/tools/i18n.js";import{c as xe,d as $e}from"../chunks/getRefinedProduct.js";import{events as Ge}from"@dropins/tools/event-bus.js";import{c as Oe}from"../chunks/initialize.js";import"@dropins/tools/fetch-graphql.js";const ze=e=>pe.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},pe.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),Fe=e=>pe.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},pe.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 5.64001L5.62988 18.37",stroke:"currentColor"}),pe.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 18.37L5.62988 5.64001",stroke:"currentColor"})),Ke=24,ge=16,_e=2,Qe="32";var Be=(e=>(e[e.small=16]="small",e[e.medium=24]="medium",e[e.large=64]="large",e))(Be||{});const me=({show:e=1,scrollbar:o=!1,peak:p=!1,arrows:_=!1,controls:s="dots",arrowsOnMainImage:y=!1,loop:h=!1,gap:P=null,direction:l="horizontal",width:le="100%",height:d="100%",defaultIndex:b=0,className:V,children:q,thumbnails:C=null,isZoomed:S,...f})=>{const u=z("PDP.Carousel.label").label,n=z("PDP.Carousel.Slide.label").label,L=z("PDP.Carousel.Previous.label").label,M=z("PDP.Carousel.Next.label").label,A=z("PDP.Carousel.Controls.Button.label").label,[g,r]=J(()=>ke(e)),O=Math.ceil(de.count(q)/g),R=p?Ke:0,j=P?Be[P]:0,X=de.count(q)%g,[k,B]=J(h?b+1:b),ne=ye([]),[ce,he]=J(0),[ie,re]=J(0),oe=ve(()=>de.toArray(C),[C]),$=ve(()=>{const c=de.toArray(q).reduce((i,N,D)=>D%g===0?[...i,[N]]:[...i.slice(0,-1),[...i[i.length-1],N]],[]);return!h||c.length===1?c:h&&de.count(q)%g===0?[c[O-1]].concat(c).concat([c[0],c[1]]):[de.toArray(q).slice(-g)].concat(c).concat([c[0],c[1]])},[q,g,O,h]),F=ye(null),K=ye(null),I=s==="thumbnailsRow"||s==="thumbnailsColumn";te(()=>{const c=document.body,i=Le(()=>{var T,ee;he(((T=F.current)==null?void 0:T.offsetWidth)??0),re(((ee=F.current)==null?void 0:ee.offsetHeight)??0);const D=window.innerWidth,W=ke(e,D);W!==g&&r(W)},50),N=new ResizeObserver(i);return N.observe(c),()=>{N.unobserve(c)}},[g,e]);const ae=Y(c=>{const i=h?c-1:c,N=ne==null?void 0:ne.current[0],D=(N==null?void 0:N.offsetWidth)+ge,W=(N==null?void 0:N.offsetHeight)+ge,T=K.current,ee=s==="thumbnailsRow",Ae=s==="thumbnailsColumn",se=ee?T==null?void 0:T.offsetWidth:T==null?void 0:T.offsetHeight,Q=ee?D:W;(ee||Ae)&&se&&(Q*(i+1)>se&&(T.style.scrollBehavior="smooth",ee?T.scrollLeft=(i+_e)*Q:T.scrollTop=(i+_e)*Q),(ee?T.scrollLeft:T.scrollTop)>Q*i&&(T.style.scrollBehavior="smooth",ee?T.scrollLeft=(i-_e)*Q:T.scrollTop=(i-_e)*Q))},[s,h]);te(()=>{ae(k)},[k,ae]);const a=Y((c,i,N)=>{I&&ae(c);const D=F.current,W=R?D.offsetWidth-R:D.offsetWidth-R+j;if(!Array.from(D.querySelectorAll("[data-index]")).filter(se=>{const Q=Number(se.getAttribute("data-index"));return!isNaN(Q)&&Q>-1})[c])return;if(N){const se=c===0?O:0,Q=W*(O+(X||g)/g);if(D.scrollLeft>=0&&D.scrollLeft<W-5){a(1,!0);return}if(D.scrollLeft>Q-W&&D.scrollLeft<=Q){a(O,!0);return}D.style.scrollBehavior="auto",D.scrollLeft=se===0?0:Q,a(se===0?1:O,!0);return}const Ae=(D.offsetWidth-j)/g*$[c].length-R;D.style.scrollBehavior=i?"smooth":"auto",D.scrollLeft=$[c].length===g?W*c:W*(c-1)+Ae},[j,O,R,g,X,$,ae,s]),m=Y(()=>{if(h){const i=k-1;a(i,!0,k===1);return}const c=k<=0?0:k-1;a(c,!0)},[k,a,h]),v=Y(()=>{const c=$.length-1;if(h){const N=k+1;a(N,!0,k===O);return}const i=k>=c?c:k+1;a(i,!0)},[$.length,h,k,a,O]);te(()=>{const c=i=>{i.key==="ArrowLeft"&&(i.preventDefault(),m()),i.key==="ArrowRight"&&(i.preventDefault(),v())};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c)}},[v,m]),te(()=>{a(h?b+1:b,!1)},[b,a,h]);const w=Le(()=>{const c=F.current,i=R?c.offsetWidth-R:c.offsetWidth-R+j,N=c.scrollLeft/i,D=Math.round(N)-N<1?Math.round(N):Math.ceil(N);if(I&&ae(D),h){const W=i*(O+(X||g)/g);if(Math.ceil(c.scrollLeft)>=Math.ceil(W)-5){c.style.scrollBehavior="auto",c.scrollLeft=c.offsetWidth*1+(Math.ceil(c.scrollLeft)-Math.ceil(W)-R);return}if(c.scrollLeft===0){c.style.scrollBehavior="auto",c.scrollLeft=W-c.offsetWidth+R;return}}k!==D&&B(D)},100);te(()=>{const c=F.current;return c==null||c.addEventListener("scroll",w),()=>{c==null||c.removeEventListener("scroll",w)}},[w]);const x=(c,i,N)=>t(we,{className:E([["pdp-carousel__button",!c],[`pdp-carousel__button--${i}`,!c],[`pdp-carousel__button--${s}`,c]]),style:{"--height":`${ie}px`},variant:"tertiary","aria-label":i==="next"?M:L,onClick:N,disabled:h?!1:i==="next"?k>=$.length-1:k<1,children:t(be,{className:E([["pdp-carousel__button__icon",!c],[`pdp-carousel__button__icon--${i}`,!c],[`pdp-carousel__button__icon--${s}--${i}`,c]]),size:Qe,source:ze})}),Z=_&&$.length!=1&&x(I,"prev",m),ue=_&&$.length!=1&&x(I,"next",v),fe=_&&$.length!=1&&x(!1,"prev",m),Te=_&&$.length!=1&&x(!1,"next",v);return U("div",{role:"region","aria-roledescription":u,className:E(["pdp-carousel",["pdp-carousel--main-image-controls",y],["pdp-carousel--arrows",_&&!I],[`pdp-carousel--${s}`,I],V]),style:{"--flex-carousel":s==="thumbnailsColumn"?"row-reverse":"column","--gap":I?"0":"var(--spacing-small)","--width":le},...f,children:[t("div",{ref:F,className:E(["pdp-carousel__wrapper",`pdp-carousel__wrapper--${l}`,["pdp-carousel__wrapper--scrollbar",o],["pdp-carousel__wrapper--peak",p]]),style:{"--total-width":s==="thumbnailsColumn"?"81.6%":"100%","--height":s==="thumbnailsColumn"?"auto":d,"--gap":P?`var(--spacing-${P})`:"0px","--per-page":g},tabIndex:0,children:$.map((c,i)=>{const N=c.length<g;return t("div",{role:"group","aria-roledescription":n,"data-index":i,className:E(["pdp-carousel__slide",`pdp-carousel__slide--${l}`,["pdp-carousel__slide--active",k===i],["pdp-carousel__slide--orphan",N]]),style:{"--length":c.length},children:c},i)})}),!I&&U(Pe,{children:[Z,ue]}),I&&y&&U(Pe,{children:[fe,Te]}),s&&$.length!=1&&U("div",{className:E([[`pdp-carousel__controls__container--${s}`,I],["pdp-carousel__controls__container--no-arrows",!_||y]]),style:{"--width":s==="thumbnailsRow"?`${ce}px`:le,"--height":`${ie}px`,"--nr-thumbnails":oe.length},children:[(I||S)&&!y&&Z,t("div",{ref:K,className:E([[`pdp-carousel__controls__wrapper--${s}`,I],["pdp-carousel__controls__wrapper",I]]),children:t("div",{role:"group","aria-label":A,className:E(["pdp-carousel__controls",[`pdp-carousel__controls--${s}`,I]]),children:(h?$.slice(0,O):$).map((c,i)=>{const N=h?O:$.length,D=h?k-1===i:k===i;return I?U("label",{className:E(["pdp-carousel__thumbnail__container"]),ref:W=>{W&&(ne.current[i]=W)},children:[t("input",{type:"radio",name:"carousel-thumbnails","aria-label":A.replace("{key}",String(i+1)).replace("{total}",String(N)),checked:D&&ce!==0,onChange:()=>{a(h?i+1:i,!0)},...f,className:E(["pdp-carousel__thumbnail",["pdp-carousel__thumbnail--selected",D&&ce!==0]])}),t("span",{className:E(["pdp-carousel__thumbnail__span"]),children:oe[i]})]},i):t("button",{"aria-label":A.replace("{key}",String(i+1)).replace("{total}",String(N)),onClick:()=>{a(h?i+1:i,!0)},className:E(["pdp-carousel__controls__button",["pdp-carousel__controls__button--active",D]])},i)})})}),(I||S)&&!y&&ue]})]})};function ke(e,o=0){if(typeof e=="number")return e;const{small:p,medium:_,large:s}=e,h=[{breakpoint:1024,value:s},{breakpoint:786,value:_},{breakpoint:0,value:p}].find(({breakpoint:P})=>o>P);return h?h.value:p}const Xe=({title:e,breadcrumbs:o,galleryContent:p,infoContent:_,productContent:s,sku:y,outOfStock:h,shortDescription:P,description:l,attributes:le,images:d,options:b,price:V,specialPrice:q,className:C,children:S,quantity:f,actions:u,carouselConfig:n,...L})=>{var k,B,ne,ce,he,ie,re,oe,$;const M=z("PDP.Product.RegularPrice.label").label,A=z("PDP.Product.SpecialPrice.label").label,g=z("PDP.Product.OutOfStock.label").label,r=z("PDP.Product.Image.label").label,[O,R]=J(null),j=d!=null&&d.length?d.map((F,K)=>{var I;return t(H,{node:F,loading:K===0?"eager":"lazy",alt:((I=e==null?void 0:e.props)==null?void 0:I.children)&&(r==null?void 0:r.replace("{product}",e.props.children.toString()).replace("{key}",String(K+1)).replace("{total}",String(d.length))),onClick:()=>R(K)},K)}):t("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0}),X=(k=n==null?void 0:n.thumbnails)!=null&&k.length?n.thumbnails.map((F,K)=>{var I;return t(H,{node:F,loading:(n==null?void 0:n.thumbnailsLoadingMode)||"lazy",alt:((I=e==null?void 0:e.props)==null?void 0:I.children)&&(r==null?void 0:r.replace("{product}",e.props.children.toString()).replace("{key}",String(K+1)).replace("{total}",String(d.length)))},K)}):t("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0});return U("div",{...L,className:E(["pdp-product",C]),children:[o&&t(H,{node:o,className:"pdp-product__breadcrumbs"}),U("div",{className:"pdp-product__column-container pdp-product__gallery-column",children:[t("div",{className:"pdp-product__column-body",children:(B=n==null?void 0:n.controls)!=null&&B.desktop?t(me,{className:"pdp-product__overlay__carousel",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?n.controls.desktop:"dots",arrowsOnMainImage:n==null?void 0:n.arrowsOnMainImage,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,peak:((ne=n==null?void 0:n.thumbnails)==null?void 0:ne.length)>1&&((ce=n==null?void 0:n.peak)==null?void 0:ce.desktop)||!1,gap:(n==null?void 0:n.gap)||null,width:"100%",height:"100%",defaultIndex:O||0,thumbnails:X,children:j}):t(Ze,{className:"pdp-product__images",gap:"small",children:j})}),p&&t(H,{node:p,className:"pdp-product__gallery-content"})]}),U("div",{className:"pdp-product__column-container pdp-product__content-column",children:[U("div",{className:"pdp-product__column-body",children:[U("div",{className:"pdp-product__header",children:[e&&t(H,{node:e,className:"pdp-product__title"}),y&&t(H,{node:y,className:"pdp-product__sku"})]}),U("div",{className:"pdp-product__prices",children:[q&&t(H,{node:q,className:E(["pdp-product__price-special","pdp-product__price"]),"aria-label":A,role:"text"}),V&&t(H,{node:V,className:E(["pdp-product__price-regular","pdp-product__price--grey"]),"aria-label":M,role:"text"})]}),(he=n==null?void 0:n.controls)!=null&&he.mobile&&((ie=n==null?void 0:n.controls)==null?void 0:ie.mobile)==="thumbnailsRow"?t(me,{className:"pdp-product__images pdp-product__images--carousel pdp-product__images--carousel--thumbnails",width:"100%",height:"auto",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"thumbnailsRow":null,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,peak:((re=n==null?void 0:n.thumbnails)==null?void 0:re.length)>1&&((oe=n==null?void 0:n.peak)==null?void 0:oe.mobile)||!1,gap:(n==null?void 0:n.gap)||null,thumbnails:X,children:j}):t(me,{className:"pdp-product__images pdp-product__images--carousel",peak:(($=n==null?void 0:n.peak)==null?void 0:$.mobile)&&(d==null?void 0:d.length)>1,gap:(n==null?void 0:n.gap)||null,width:"100%",height:"auto",arrows:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"dots":null,loop:(n==null?void 0:n.loopable)&&(d==null?void 0:d.length)>1,children:j}),U("div",{className:E(["pdp-product__actions",["pdp-product__actions--out-of-stock",h]]),children:[h&&t("div",{className:"pdp-product__out-of-stock__text",children:g}),b&&t(H,{node:b,className:E(["pdp-product__options"])}),f&&t("div",{className:"pdp-product__quantity",children:t(H,{node:f})}),u&&t(H,{node:u,className:E(["pdp-product__buttons"])})]}),P&&t(H,{node:P,className:E(["pdp-product__short_description"])}),l&&t(H,{node:l,className:E(["pdp-product__description"])}),le?t("div",{className:"pdp-product__attributes",children:le}):null]}),_&&t(H,{node:_,className:"pdp-product__info-content"})]}),s&&t(H,{node:s,className:"pdp-product__content"}),O===null?null:t(Je,{className:"pdp-product__overlay",onClose:()=>R(null),centered:!0,children:t(me,{className:"pdp-product__overlay__carousel",arrows:(d==null?void 0:d.length)>1,width:"100%",height:"100%",defaultIndex:O||0,loop:(d==null?void 0:d.length)>1,controls:(d==null?void 0:d.length)>1?"dots":null,isZoomed:!0,children:j})})]})},Ze=({children:e,gap:o=null,className:p,style:_,...s})=>{const y=de.count(e);return t("div",{...s,className:E(["pdp-gallery-grid",p]),style:{"--gap":o?`var(--spacing-${o})`:"0px",..._},children:de.map(e,(h,P)=>t("div",{className:"pdp-gallery-grid__item",children:t(H,{node:h,loading:P===0?"eager":"lazy"},h.props.src)},y+P))})},Ie=({amount:e,currency:o,locale:p,variant:_,sale:s,minimumAmount:y,maximumAmount:h,className:P,...l})=>t(Pe,{children:e||y===h?t("div",{className:"pdp-price-range",...l,children:t(Se,{amount:e||y,currency:o,locale:p,variant:_,sale:s,className:P})}):U("div",{className:"pdp-price-range",...l,children:[t(Se,{amount:y,currency:o,locale:p,className:P}),t("span",{className:"pdp-price-range__label",children:"-"}),t(Se,{amount:h,currency:o,locale:p,className:P})]})}),Je=({centered:e,onClose:o,className:p,children:_,...s})=>{const y=z("PDP.Overlay.Close.label").label,h=Y(()=>{o==null||o()},[o]);return te(()=>{const P=l=>{l.key==="Escape"&&h()};return document.addEventListener("keydown",P),()=>{document.removeEventListener("keydown",P)}},[h]),te(()=>{const P=document.scrollingElement,l=P.style.overflow;return P.style.overflow="hidden",()=>{P.style.overflow=l}},[]),U("div",{...s,className:E(["pdp-overlay",["pdp-overlay--centered",e],p]),children:[t("div",{className:"pdp-overlay__content",children:_}),t(we,{"aria-label":y,variant:"tertiary",className:"pdp-overlay__close-button",onClick:h,icon:t(Fe,{})})]})},Ye=["text","image","color","dropdown"],Ce=e=>e.map(o=>({...o,text:o.label,disabled:!o.inStock})),et=({options:e,hideSelectedValue:o,onValues:p,onErrors:_,defaultOptions:s,selectionsToUpdate:y,className:h,children:P,...l})=>{const le=z("PDP.Swatches.Required.label").label,[d,b]=J(()=>e==null?void 0:e.reduce((f,u)=>{const{items:n}=u,L=n==null?void 0:n.find(A=>s==null?void 0:s.includes(A.id)),M=n==null?void 0:n.find(A=>A.selected);return L?{...f,[u.id]:{label:L.label,value:L.id}}:M?{...f,[u.id]:{label:M.label,value:M.id}}:f},{}));te(()=>{y==null||y.forEach(S=>{b(f=>{var L;const u=(L=S==null?void 0:S.items)==null?void 0:L.find(M=>M.selected);return u?{...f,[S.id]:{label:u==null?void 0:u.label,value:u==null?void 0:u.id}}:f})})},[y,b]),ve(()=>{const S=e==null?void 0:e.reduce((f,u)=>{var n;return(n=u==null?void 0:u.items)==null||n.forEach(L=>{var A;const M=((A=d[u.id])==null?void 0:A.value)===L.id;u.required&&!M&&(f[u.id]=le)}),f},{});return _==null||_(S),S},[d]);const V=Y((S,f,u)=>{b(n=>{const L={...n,[S]:{label:f,value:u}};return p==null||p(L,u),L})},[p]),q=(S,f)=>{var n;const u=((n=f.selectedOptions[0])==null?void 0:n.label)??"";V(S,u,f.value)},C=Y(({items:S,id:f,required:u,type:n,selected:L,label:M})=>t("div",{className:E(["pdp-swatches__options"]),children:(n==null?void 0:n.toLowerCase())==="dropdown"?t(We,{"aria-label":M,handleSelect:A=>q(f,A.target),options:Ce(S),value:L}):S==null?void 0:S.map(A=>{const g={key:A.id,id:A.id,name:f,value:A.value,label:A.label,groupAriaLabel:M,selected:L===A.id,outOfStock:!A.inStock,required:u===null?!0:u,onValue:()=>{V(f,A.label,A.id)}};switch(n){case"text":return t(Ve,{...g,label:A.label});case"image":return t(He,{...g,src:A.value,alt:A.label});case"color":return t(Ue,{...g,size:"large",color:A.value});default:return console.warn(`Invalid swatch type ${n}`),null}})}),[V]);return t("div",{...l,className:E(["pdp-swatches",h]),children:e==null?void 0:e.map(({type:S,label:f,id:u,multiple:n,required:L,items:M})=>{var A;if(!S){console.warn("Bundle product not supported on UI.");return}return Ye.includes(S)||console.warn(`Invalid swatch type ${S}`),n&&console.warn("Multiple selection swatches are not currently supported."),U("div",{id:`swatch-item-${u}`,"data-slot-key":`product-swatch--${u}`,className:"pdp-swatches__field",children:[t("div",{className:"pdp-swatches__field__label",children:d[u]?o?`${f}`:`${f}: ${d[u].label}`:f}),t(C,{id:u,type:S,required:L,items:M,label:f,selected:(A=d[u])==null?void 0:A.value})]},`swatch-item-${u}`)})})};function tt(e,o="en_US"){if(!Me(e))throw Error("Invalid date string");return e.split(" ")[1]||(e=`${e} 00:00:00`),new Date(e).toLocaleDateString(Ne(o)).toString()}function Me(e){if(![/^\d{4}-\d{2}-\d{2}$/,/^\d{1,2}\/\d{1,2}\/\d{4}$/,/^\d{2}\/\d{2}\/\d{4}$/,/^\d{4}\/\d{2}\/\d{2}$/,/^\d{1,2}\.\d{1,2}\.\d{4}$/,/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/].some(_=>_.test(e)))return!1;const p=new Date(e);return!isNaN(p.getTime())}function nt(e){const o=new URLSearchParams(window.location.search);Object.entries(e).forEach(([_,s])=>{s===null?o.delete(_):o.set(_,String(s))});let p=window.location.pathname;p+=`?${o.toString()}`,p+=window.location.hash,window.history.replaceState({},"",p)}function rt(){const e=new URLSearchParams(window.location.search),o={};return e.forEach((p,_)=>{o[_]=p}),o}function lt(e){var o,p,_,s,y,h,P,l;return{productId:Number(e==null?void 0:e.externalId),name:e==null?void 0:e.name,sku:e==null?void 0:e.sku,topLevelSku:e==null?void 0:e.externalParentId,specialToDate:void 0,specialFromDate:void 0,newToDate:void 0,newFromDate:void 0,createdAt:void 0,updatedAt:void 0,manufacturer:void 0,countryOfManufacture:void 0,categories:void 0,productType:void 0,pricing:{regularPrice:((p=(o=e==null?void 0:e.prices)==null?void 0:o.regular)==null?void 0:p.amount)||0,minimalPrice:void 0,maximalPrice:void 0,specialPrice:(s=(_=e==null?void 0:e.prices)==null?void 0:_.final)==null?void 0:s.amount,tierPricing:void 0,currencyCode:((h=(y=e==null?void 0:e.prices)==null?void 0:y.final)==null?void 0:h.currency)||"USD"},canonicalUrl:e==null?void 0:e.url,mainImageUrl:(l=(P=e==null?void 0:e.images)==null?void 0:P[0])==null?void 0:l.url}}const ct={PRODUCT_CONTEXT:"productContext"},at={PRODUCT_PAGE_VIEW:"product-page-view"};function Re(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function dt(e,o){const p=Re();p.push({[e]:null}),p.push({[e]:o})}function it(e,o){Re().push(_=>{const s=_.getState?_.getState():{};_.push({event:e,eventInfo:{...s,...o}})})}function Ee(e){const o=lt(e);dt(ct.PRODUCT_CONTEXT,o),it(at.PRODUCT_PAGE_VIEW)}const ot=({sku:e,hideSku:o,hideQuantity:p,hideShortDescription:_,hideDescription:s,hideAttributes:y,hideURLParams:h,hideSelectedOptionValue:P,slots:l,children:le,initialData:d,carousel:b,optionsConfig:V,useACDL:q,onAddToCart:C,...S})=>{var F,K,I,ae;const f=z("PDP.Product.AddToCart.label").label,u=z("PDP.Product.Incrementer.label").label,n=z("PDP.Product.Details.label").label,[L,M]=J(Oe.getConfig().defaultLocale||"en-US"),[A,g]=J(),[r=null,O]=J(d),[R,j]=J(()=>{const a={sku:e,quantity:1};return r!=null&&r.optionUIDs&&(a.optionsUIDs=r.optionUIDs),a}),[X,k]=J(()=>{var a,m;return!(r!=null&&r.options&&((a=r==null?void 0:r.options)==null?void 0:a.length)>0&&((m=r==null?void 0:r.optionUIDs)==null?void 0:m.length)!==(r==null?void 0:r.options.length))}),B={data:r,values:R,valid:X};te(()=>{const a=Ge.on("locale",m=>{m!==L&&(M(m),xe(e).then(O))});return()=>{a==null||a.off()}},[L,e]),te(()=>{q&&d&&Object.keys(d).length>0&&Ee(d)},[d]);const ne=Y(a=>{j(m=>({...m,...a}))},[]),ce=Y(a=>{var v;let m=Object.keys(a).map(w=>a[w].value).filter(w=>w!==void 0);h||nt({optionsUIDs:m.join(",")}),j(w=>({...w,optionsUIDs:m})),k((m==null?void 0:m.length)===((v=r==null?void 0:r.options)==null?void 0:v.length)),$e(e,m,V==null?void 0:V.anchorOptions).then(w=>{var x;O(w),(x=V==null?void 0:V.anchorOptions)!=null&&x.length&&he(w,m),q&&(w==null?void 0:w.sku)!==e&&Ee(w)})},[e]),he=Y((a,m)=>{var x;const v=(a==null?void 0:a.optionUIDs)??[];m.every(Z=>v.includes(Z))||(g(a==null?void 0:a.options),j(Z=>({...Z,optionsUIDs:v})),k((v==null?void 0:v.length)===((x=a==null?void 0:a.options)==null?void 0:x.length)))},[e]),ie=Y(a=>{Object.keys(a).length!==0&&k(!1)},[]),re=ve(()=>{var a;return(a=r==null?void 0:r.attributes)==null?void 0:a.map(({label:m,value:v},w)=>{const x=Me(v)?tt(v,L):v.toString();return U("li",{children:[m,": ",t("span",{dangerouslySetInnerHTML:{__html:x}})]},w)})},[r==null?void 0:r.attributes,L]),oe=!p&&(r!=null&&r.inStock)?t(G,{name:"Quantity",slot:l==null?void 0:l.Quantity,context:{...B},children:t(qe,{name:"quantity",defaultValue:R.quantity.toString(),min:1,"aria-label":u,className:"pdp-product__quantity",onValue:a=>{ne({quantity:Number(a)})}},"quantity")}):void 0,$=()=>{if(r!=null&&r.options)return t(G,{name:"Options",slot:l==null?void 0:l.Options,context:{...B},children:t(et,{options:r.options,defaultOptions:R.optionsUIDs,selectionsToUpdate:A,hideSelectedValue:P,onValues:ce,onErrors:ie})})};return t("div",{...S,children:t(Xe,{title:t(G,{name:"Title",slot:l==null?void 0:l.Title,context:{...B},children:r==null?void 0:r.name}),sku:o?void 0:t(G,{name:"SKU",slot:l==null?void 0:l.SKU,context:{...B},children:r==null?void 0:r.sku}),options:$(),breadcrumbs:(l==null?void 0:l.Breadcrumbs)&&t(G,{name:"Breadcrumbs",slot:l==null?void 0:l.Breadcrumbs,context:{...B,setSeparator(a){this._registerMethod((...m)=>{const v=a(...m),w=v&&t(be,{source:v});this._setProps(x=>({...x,separator:w}))})},appendLink(a){this._registerMethod((...m)=>{const{text:v,...w}=a(...m),x=t("a",{...w,children:v});this._setProps(Z=>({...Z,categories:[...Z.categories||[],x]}))})},appendHTMLElement(a){this._registerMethod((...m)=>{const v=a(...m),w=this._htmlElementToVNode(v);this._setProps(x=>({...x,categories:[...x.categories||[],w]}))})}},render:({separator:a,categories:m})=>t(je,{separator:a,categories:m})}),quantity:oe,actions:t(G,{name:"Actions",slot:l==null?void 0:l.Actions,context:{...B,appendButton(a){this._registerMethod((...m)=>{const v=a(...m);if(!v)return;const{text:w,icon:x,...Z}=v,ue=t(we,{type:"button",...Z,icon:x&&t(be,{source:x}),children:w});this._setProps(fe=>({children:[...fe.children||[],ue]}))})}},children:!(l!=null&&l.Actions)&&t(we,{size:"medium",type:"submit",icon:t(be,{source:"Cart"}),disabled:!(r!=null&&r.inStock)||!X,"aria-label":f,onClick:()=>C==null?void 0:C(R),children:f})}),shortDescription:_?void 0:t(G,{name:"ShortDescription",slot:l==null?void 0:l.ShortDescription,context:{...B},children:t("div",{dangerouslySetInnerHTML:{__html:(r==null?void 0:r.shortDescription)??""}})}),description:s?void 0:t(G,{name:"Description",slot:l==null?void 0:l.Description,context:{...B},children:t("div",{dangerouslySetInnerHTML:{__html:(r==null?void 0:r.description)??""}})}),images:((F=r==null?void 0:r.images)==null?void 0:F.map(({label:a,url:m})=>{var v,w;return t(De,{title:a,alt:a,src:m,width:((v=b==null?void 0:b.imageParams)==null?void 0:v.width)??960,height:((w=b==null?void 0:b.imageParams)==null?void 0:w.height)??1191,params:(b==null?void 0:b.imageParams)??{width:960}},m)}))??[],specialPrice:(K=r==null?void 0:r.prices)!=null&&K.visible?t(G,{name:"SpecialPrice",slot:l==null?void 0:l.SpecialPrice,context:{...B},children:t(Ie,{...r.prices.final,locale:Ne(L)})}):void 0,price:(I=r==null?void 0:r.prices)!=null&&I.visible&&r.prices.regular&&r.prices.final.amount!==(r==null?void 0:r.prices.regular.amount)?t(G,{name:"RegularPrice",slot:l==null?void 0:l.RegularPrice,context:{...B},children:t(Ie,{...r.prices.regular,locale:Ne(L)})}):void 0,carouselConfig:{...b,thumbnails:b&&Object.keys(b).length?((ae=r==null?void 0:r.images)==null?void 0:ae.map(({label:a,url:m})=>{var v,w;return t(De,{title:a,alt:a,src:m,width:((v=b==null?void 0:b.thumbnailParams)==null?void 0:v.width)??200,height:((w=b==null?void 0:b.thumbnailParams)==null?void 0:w.height)??248,params:(b==null?void 0:b.thumbnailParams)??{width:200}},m)}))??[]:[]},outOfStock:!(r!=null&&r.inStock),attributes:y?void 0:t(G,{name:"Attributes",slot:l==null?void 0:l.Attributes,context:{...B},children:re!=null&&re.length?U(Pe,{children:[n,t("ul",{children:re})]}):null}),galleryContent:(l==null?void 0:l.GalleryContent)&&t(G,{name:"GalleryContent",slot:l.GalleryContent,context:{...B}}),infoContent:(l==null?void 0:l.InfoContent)&&t(G,{name:"InfoContent",slot:l.InfoContent,context:{...B}}),productContent:(l==null?void 0:l.Content)&&t(G,{name:"Content",slot:l.Content,context:{...B}})})})};ot.getInitialData=async function({sku:e,optionsConfig:o}){var _,s,y,h,P,l;const p=((_=rt().optionsUIDs)==null?void 0:_.split(","))||((l=(P=(h=(y=(s=Oe)==null?void 0:s.getConfig())==null?void 0:y.models)==null?void 0:h.ProductDetails)==null?void 0:P.initialData)==null?void 0:l.optionsUIDs);return p!=null&&p.length?await $e(e,p,o==null?void 0:o.anchorOptions):await xe(e)};export{ot as ProductDetails,ot as default};
|
|
1
|
+
import*as pe from"@dropins/tools/preact-compat.js";import{useState as X,Children as ae,useRef as ye,useMemo as we,useEffect as ne,useCallback as Z}from"@dropins/tools/preact-compat.js";import{debounce as Le,classes as k,VComponent as H,toLanguageTag as Ne,Slot as j}from"@dropins/tools/lib.js";import{Button as Pe,Icon as ve,Price as Se,Picker as Ue,ColorSwatch as He,ImageSwatch as Ve,TextSwatch as qe,Incrementer as je,Breadcrumbs as Ge,Image as De}from"@dropins/tools/components.js";import{jsxs as U,jsx as n,Fragment as fe}from"@dropins/tools/preact-jsx-runtime.js";import{useText as V}from"@dropins/tools/i18n.js";import{c as xe,d as $e}from"../chunks/getRefinedProduct.js";import{events as ze}from"@dropins/tools/event-bus.js";import{c as Oe}from"../chunks/initialize.js";import"@dropins/tools/fetch-graphql.js";const Fe=e=>pe.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},pe.createElement("path",{d:"M7.74512 9.87701L12.0001 14.132L16.2551 9.87701",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"square",strokeLinejoin:"round"})),Ke=e=>pe.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},pe.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 5.64001L5.62988 18.37",stroke:"currentColor"}),pe.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M18.3599 18.37L5.62988 5.64001",stroke:"currentColor"})),Qe=24,ge=16,me=2,Xe="32";var Be=(e=>(e[e.small=16]="small",e[e.medium=24]="medium",e[e.large=64]="large",e))(Be||{});const be=({show:e=1,scrollbar:o=!1,peak:u=!1,arrows:m=!1,controls:h="dots",arrowsOnMainImage:y=!1,loop:p=!1,gap:f=null,direction:l="horizontal",width:K="100%",height:a="100%",defaultIndex:b=0,className:B,children:q,thumbnails:J=null,isZoomed:N,...A})=>{const _=V("PDP.Carousel.label").label,r=V("PDP.Carousel.Slide.label").label,D=V("PDP.Carousel.Previous.label").label,M=V("PDP.Carousel.Next.label").label,S=V("PDP.Carousel.Controls.label").label,Y=V("PDP.Carousel.Controls.Button.label").label,[t,le]=X(()=>ke(e)),x=Math.ceil(ae.count(q)/t),$=u?Qe:0,C=f?Be[f]:0,F=ae.count(q)%t,[v,oe]=X(p?b+1:b),re=ye([]),[ce,se]=X(0),[ee,he]=X(0),de=we(()=>ae.toArray(J),[J]),I=we(()=>{const c=ae.toArray(q).reduce((i,L,g)=>g%t===0?[...i,[L]]:[...i.slice(0,-1),[...i[i.length-1],L]],[]);return!p||c.length===1?c:p&&ae.count(q)%t===0?[c[x-1]].concat(c).concat([c[0],c[1]]):[ae.toArray(q).slice(-t)].concat(c).concat([c[0],c[1]])},[q,t,x,p]),T=ye(null),Q=ye(null),O=h==="thumbnailsRow"||h==="thumbnailsColumn";ne(()=>{const c=document.body,i=Le(()=>{var R,te;se(((R=T.current)==null?void 0:R.offsetWidth)??0),he(((te=T.current)==null?void 0:te.offsetHeight)??0);const g=window.innerWidth,W=ke(e,g);W!==t&&le(W)},50),L=new ResizeObserver(i);return L.observe(c),()=>{L.unobserve(c)}},[t,e]);const d=Z(c=>{const i=p?c-1:c,L=re==null?void 0:re.current[0],g=(L==null?void 0:L.offsetWidth)+ge,W=(L==null?void 0:L.offsetHeight)+ge,R=Q.current,te=h==="thumbnailsRow",Ae=h==="thumbnailsColumn",ie=te?R==null?void 0:R.offsetWidth:R==null?void 0:R.offsetHeight,z=te?g:W;(te||Ae)&&ie&&(z*(i+1)>ie&&(R.style.scrollBehavior="smooth",te?R.scrollLeft=(i+me)*z:R.scrollTop=(i+me)*z),(te?R.scrollLeft:R.scrollTop)>z*i&&(R.style.scrollBehavior="smooth",te?R.scrollLeft=(i-me)*z:R.scrollTop=(i-me)*z))},[h,p]);ne(()=>{d(v)},[v,d]);const s=Z((c,i,L)=>{O&&d(c);const g=T.current,W=$?g.offsetWidth-$:g.offsetWidth-$+C;if(!Array.from(g.querySelectorAll("[data-index]")).filter(ie=>{const z=Number(ie.getAttribute("data-index"));return!isNaN(z)&&z>-1})[c])return;if(L){const ie=c===0?x:0,z=W*(x+(F||t)/t);if(g.scrollLeft>=0&&g.scrollLeft<W-5){s(1,!0);return}if(g.scrollLeft>z-W&&g.scrollLeft<=z){s(x,!0);return}g.style.scrollBehavior="auto",g.scrollLeft=ie===0?0:z,s(ie===0?1:x,!0);return}const Ae=(g.offsetWidth-C)/t*I[c].length-$;g.style.scrollBehavior=i?"smooth":"auto",g.scrollLeft=I[c].length===t?W*c:W*(c-1)+Ae},[C,x,$,t,F,I,d,h]),P=Z(()=>{if(p){const i=v-1;s(i,!0,v===1);return}const c=v<=0?0:v-1;s(c,!0)},[v,s,p]),w=Z(()=>{const c=I.length-1;if(p){const L=v+1;s(L,!0,v===x);return}const i=v>=c?c:v+1;s(i,!0)},[I.length,p,v,s,x]);ne(()=>{const c=i=>{i.key==="ArrowLeft"&&(i.preventDefault(),P()),i.key==="ArrowRight"&&(i.preventDefault(),w())};return window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c)}},[w,P]),ne(()=>{s(p?b+1:b,!1)},[b,s,p]);const E=Le(()=>{const c=T.current,i=$?c.offsetWidth-$:c.offsetWidth-$+C,L=c.scrollLeft/i,g=Math.round(L)-L<1?Math.round(L):Math.ceil(L);if(O&&d(g),p){const W=i*(x+(F||t)/t);if(Math.ceil(c.scrollLeft)>=Math.ceil(W)-5){c.style.scrollBehavior="auto",c.scrollLeft=c.offsetWidth*1+(Math.ceil(c.scrollLeft)-Math.ceil(W)-$);return}if(c.scrollLeft===0){c.style.scrollBehavior="auto",c.scrollLeft=W-c.offsetWidth+$;return}}v!==g&&oe(g)},100);ne(()=>{const c=T.current;return c==null||c.addEventListener("scroll",E),()=>{c==null||c.removeEventListener("scroll",E)}},[E]);const G=(c,i,L)=>n(Pe,{className:k([["pdp-carousel__button",!c],[`pdp-carousel__button--${i}`,!c],[`pdp-carousel__button--${h}`,c]]),style:{"--height":`${ee}px`},variant:"tertiary","aria-label":i==="next"?M:D,onClick:L,disabled:p?!1:i==="next"?v>=I.length-1:v<1,children:n(ve,{className:k([["pdp-carousel__button__icon",!c],[`pdp-carousel__button__icon--${i}`,!c],[`pdp-carousel__button__icon--${h}--${i}`,c]]),size:Xe,source:Fe})}),ue=m&&I.length!=1&&G(O,"prev",P),_e=m&&I.length!=1&&G(O,"next",w),Te=m&&I.length!=1&&G(!1,"prev",P),We=m&&I.length!=1&&G(!1,"next",w);return U("div",{role:"region","aria-roledescription":_,className:k(["pdp-carousel",["pdp-carousel--main-image-controls",y],["pdp-carousel--arrows",m&&!O],[`pdp-carousel--${h}`,O],B]),style:{"--flex-carousel":h==="thumbnailsColumn"?"row-reverse":"column","--gap":O?"0":"var(--spacing-small)","--width":K},...A,children:[n("div",{ref:T,className:k(["pdp-carousel__wrapper",`pdp-carousel__wrapper--${l}`,["pdp-carousel__wrapper--scrollbar",o],["pdp-carousel__wrapper--peak",u]]),style:{"--total-width":h==="thumbnailsColumn"?"81.6%":"100%","--height":h==="thumbnailsColumn"?"auto":a,"--gap":f?`var(--spacing-${f})`:"0px","--per-page":t},tabIndex:0,children:I.map((c,i)=>{const L=c.length<t;return n("div",{role:"group","aria-roledescription":r,"data-index":i,className:k(["pdp-carousel__slide",`pdp-carousel__slide--${l}`,["pdp-carousel__slide--active",v===i],["pdp-carousel__slide--orphan",L]]),style:{"--length":c.length},children:c},i)})}),!O&&U(fe,{children:[ue,_e]}),O&&y&&U(fe,{children:[Te,We]}),h&&I.length!=1&&U("div",{className:k([[`pdp-carousel__controls__container--${h}`,O],["pdp-carousel__controls__container--no-arrows",!m||y]]),style:{"--width":h==="thumbnailsRow"?`${ce}px`:K,"--height":`${ee}px`,"--nr-thumbnails":de.length},children:[(O||N)&&!y&&ue,n("div",{ref:Q,className:k([[`pdp-carousel__controls__wrapper--${h}`,O],["pdp-carousel__controls__wrapper",O]]),children:n("div",{role:"group","aria-label":S,className:k(["pdp-carousel__controls",[`pdp-carousel__controls--${h}`,O]]),children:(p?I.slice(0,x):I).map((c,i)=>{const L=p?x:I.length,g=p?v-1===i:v===i;return O?U("label",{className:k(["pdp-carousel__thumbnail__container"]),ref:W=>{W&&(re.current[i]=W)},children:[n("input",{type:"radio",name:"carousel-thumbnails","aria-label":Y.replace("{key}",String(i+1)).replace("{total}",String(L)),checked:g&&ce!==0,onChange:()=>{s(p?i+1:i,!0)},...A,className:k(["pdp-carousel__thumbnail",["pdp-carousel__thumbnail--selected",g&&ce!==0]])}),n("span",{className:k(["pdp-carousel__thumbnail__span"]),children:de[i]})]},i):n("button",{"aria-label":Y.replace("{key}",String(i+1)).replace("{total}",String(L)),onClick:()=>{s(p?i+1:i,!0)},className:k(["pdp-carousel__controls__button",["pdp-carousel__controls__button--active",g]])},i)})})}),(O||N)&&!y&&_e]})]})};function ke(e,o=0){if(typeof e=="number")return e;const{small:u,medium:m,large:h}=e,p=[{breakpoint:1024,value:h},{breakpoint:786,value:m},{breakpoint:0,value:u}].find(({breakpoint:f})=>o>f);return p?p.value:u}const Ze=({title:e,breadcrumbs:o,galleryContent:u,infoContent:m,productContent:h,sku:y,outOfStock:p,shortDescription:f,description:l,attributes:K,images:a,options:b,price:B,specialPrice:q,className:J,children:N,quantity:A,actions:_,carouselConfig:r,...D})=>{var F,v,oe,re,ce,se,ee,he,de;const M=V("PDP.Product.RegularPrice.label").label,S=V("PDP.Product.SpecialPrice.label").label,Y=V("PDP.Product.OutOfStock.label").label,t=V("PDP.Product.Image.label").label,[le,x]=X(null),$=a!=null&&a.length?a.map((I,T)=>{var Q;return n(H,{node:I,loading:T===0?"eager":"lazy",alt:((Q=e==null?void 0:e.props)==null?void 0:Q.children)&&(t==null?void 0:t.replace("{product}",e.props.children.toString()).replace("{key}",String(T+1)).replace("{total}",String(a.length))),onClick:()=>x(T)},T)}):n("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0}),C=(F=r==null?void 0:r.thumbnails)!=null&&F.length?r.thumbnails.map((I,T)=>{var Q;return n(H,{node:I,loading:(r==null?void 0:r.thumbnailsLoadingMode)||"lazy",alt:((Q=e==null?void 0:e.props)==null?void 0:Q.children)&&(t==null?void 0:t.replace("{product}",e.props.children.toString()).replace("{key}",String(T+1)).replace("{total}",String(a.length)))},T)}):n("img",{src:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",className:"pdp-product__images__placeholder","aria-hidden":!0});return U("div",{...D,className:k(["pdp-product",J]),children:[o&&n(H,{node:o,className:"pdp-product__breadcrumbs"}),U("div",{className:"pdp-product__column-container pdp-product__gallery-column",children:[n("div",{className:"pdp-product__column-body",children:(v=r==null?void 0:r.controls)!=null&&v.desktop?n(be,{className:"pdp-product__overlay__carousel",arrows:(a==null?void 0:a.length)>1,controls:(a==null?void 0:a.length)>1?r.controls.desktop:"dots",arrowsOnMainImage:r==null?void 0:r.arrowsOnMainImage,loop:(r==null?void 0:r.loopable)&&(a==null?void 0:a.length)>1,peak:((oe=r==null?void 0:r.thumbnails)==null?void 0:oe.length)>1&&((re=r==null?void 0:r.peak)==null?void 0:re.desktop)||!1,gap:(r==null?void 0:r.gap)||null,width:"100%",height:"100%",defaultIndex:le||0,thumbnails:C,children:$}):n(Je,{className:"pdp-product__images",gap:"small",children:$})}),u&&n(H,{node:u,className:"pdp-product__gallery-content"})]}),U("div",{className:"pdp-product__column-container pdp-product__content-column",children:[U("div",{className:"pdp-product__column-body",children:[U("div",{className:"pdp-product__header",children:[e&&n(H,{node:e,className:"pdp-product__title"}),y&&n(H,{node:y,className:"pdp-product__sku"})]}),U("div",{className:"pdp-product__prices",children:[q&&n(H,{node:q,className:k(["pdp-product__price-special","pdp-product__price"]),"aria-label":S,role:"text"}),B&&n(H,{node:B,className:k(["pdp-product__price-regular","pdp-product__price--grey"]),"aria-label":M,role:"text"})]}),(ce=r==null?void 0:r.controls)!=null&&ce.mobile&&((se=r==null?void 0:r.controls)==null?void 0:se.mobile)==="thumbnailsRow"?n(be,{className:"pdp-product__images pdp-product__images--carousel pdp-product__images--carousel--thumbnails",width:"100%",height:"auto",arrows:(a==null?void 0:a.length)>1,controls:(a==null?void 0:a.length)>1?"thumbnailsRow":null,loop:(r==null?void 0:r.loopable)&&(a==null?void 0:a.length)>1,peak:((ee=r==null?void 0:r.thumbnails)==null?void 0:ee.length)>1&&((he=r==null?void 0:r.peak)==null?void 0:he.mobile)||!1,gap:(r==null?void 0:r.gap)||null,thumbnails:C,children:$}):n(be,{className:"pdp-product__images pdp-product__images--carousel",peak:((de=r==null?void 0:r.peak)==null?void 0:de.mobile)&&(a==null?void 0:a.length)>1,gap:(r==null?void 0:r.gap)||null,width:"100%",height:"auto",arrows:(a==null?void 0:a.length)>1,controls:(a==null?void 0:a.length)>1?"dots":null,loop:(r==null?void 0:r.loopable)&&(a==null?void 0:a.length)>1,children:$}),U("div",{className:k(["pdp-product__actions",["pdp-product__actions--out-of-stock",p]]),children:[p&&n("div",{className:"pdp-product__out-of-stock__text",children:Y}),b&&n(H,{node:b,className:k(["pdp-product__options"])}),A&&n("div",{className:"pdp-product__quantity",children:n(H,{node:A})}),_&&n(H,{node:_,className:k(["pdp-product__buttons"])})]}),f&&n(H,{node:f,className:k(["pdp-product__short_description"])}),l&&n(H,{node:l,className:k(["pdp-product__description"])}),K?n("div",{className:"pdp-product__attributes",children:K}):null]}),m&&n(H,{node:m,className:"pdp-product__info-content"})]}),h&&n(H,{node:h,className:"pdp-product__content"}),le===null?null:n(Ye,{className:"pdp-product__overlay",onClose:()=>x(null),centered:!0,children:n(be,{className:"pdp-product__overlay__carousel",arrows:(a==null?void 0:a.length)>1,width:"100%",height:"100%",defaultIndex:le||0,loop:(a==null?void 0:a.length)>1,controls:(a==null?void 0:a.length)>1?"dots":null,isZoomed:!0,children:$})})]})},Je=({children:e,gap:o=null,className:u,style:m,...h})=>{const y=ae.count(e);return n("div",{...h,className:k(["pdp-gallery-grid",u]),style:{"--gap":o?`var(--spacing-${o})`:"0px",...m},children:ae.map(e,(p,f)=>n("div",{className:"pdp-gallery-grid__item",children:n(H,{node:p,loading:f===0?"eager":"lazy"},p.props.src)},y+f))})},Ie=({amount:e,currency:o,locale:u,variant:m,sale:h,minimumAmount:y,maximumAmount:p,className:f,...l})=>n(fe,{children:e||y===p?n("div",{className:"pdp-price-range",...l,children:n(Se,{amount:e||y,currency:o,locale:u,variant:m,sale:h,className:f})}):U("div",{className:"pdp-price-range",...l,children:[n(Se,{amount:y,currency:o,locale:u,className:f}),n("span",{className:"pdp-price-range__label",children:"-"}),n(Se,{amount:p,currency:o,locale:u,className:f})]})}),Ye=({centered:e,onClose:o,className:u,children:m,...h})=>{const y=V("PDP.Overlay.Close.label").label,p=Z(()=>{o==null||o()},[o]);return ne(()=>{const f=l=>{l.key==="Escape"&&p()};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f)}},[p]),ne(()=>{const f=document.scrollingElement,l=f.style.overflow;return f.style.overflow="hidden",()=>{f.style.overflow=l}},[]),U("div",{...h,className:k(["pdp-overlay",["pdp-overlay--centered",e],u]),children:[n("div",{className:"pdp-overlay__content",children:m}),n(Pe,{"aria-label":y,variant:"tertiary",className:"pdp-overlay__close-button",onClick:p,icon:n(Ke,{})})]})},Ce=["text","image","color","dropdown"],et=e=>e.map(o=>({...o,text:o.label,disabled:!o.inStock})),tt=({options:e,hideSelectedValue:o,onValues:u,onErrors:m,defaultOptions:h,selectionsToUpdate:y,className:p,children:f,...l})=>{const K=V("PDP.Swatches.Required.label").label,[a,b]=X(()=>e==null?void 0:e.reduce((A,_)=>{const{items:r}=_,D=r==null?void 0:r.find(S=>h==null?void 0:h.includes(S.id)),M=r==null?void 0:r.find(S=>S.selected);return D?{...A,[_.id]:{label:D.label,value:D.id}}:M?{...A,[_.id]:{label:M.label,value:M.id}}:A},{}));ne(()=>{y==null||y.forEach(N=>{b(A=>{var D;const _=(D=N==null?void 0:N.items)==null?void 0:D.find(M=>M.selected);return _?{...A,[N.id]:{label:_==null?void 0:_.label,value:_==null?void 0:_.id}}:A})})},[y,b]),we(()=>{const N=e==null?void 0:e.reduce((A,_)=>{var r;return(r=_==null?void 0:_.items)==null||r.forEach(D=>{var S;const M=((S=a[_.id])==null?void 0:S.value)===D.id;_.required&&!M&&(A[_.id]=K)}),A},{});return m==null||m(N),N},[a]);const B=Z((N,A,_)=>{b(r=>{const D={...r,[N]:{label:A,value:_}};return u==null||u(D,_),D})},[u]),q=(N,A)=>{var r;const _=((r=A.selectedOptions[0])==null?void 0:r.label)??"";B(N,_,A.value)},J=Z(({items:N,id:A,required:_,type:r,selected:D,label:M})=>n("div",{className:k(["pdp-swatches__options"]),children:(r==null?void 0:r.toLowerCase())==="dropdown"?n(Ue,{"aria-label":M,handleSelect:S=>q(A,S.target),options:et(N),value:D}):N==null?void 0:N.map(S=>{const Y={key:S.id,id:S.id,name:A,value:S.value,label:S.label,groupAriaLabel:M,selected:D===S.id,outOfStock:!S.inStock,required:_===null?!0:_,onValue:()=>{B(A,S.label,S.id)}};switch(r){case"text":return n(qe,{...Y,label:S.label});case"image":return n(Ve,{...Y,src:S.value,alt:S.label});case"color":return n(He,{...Y,size:"large",color:S.value});default:return console.warn(`Invalid swatch type ${r}`),null}})}),[B]);return n("div",{...l,className:k(["pdp-swatches",p]),children:e==null?void 0:e.map(({type:N,label:A,id:_,multiple:r,required:D,items:M})=>{var S;if(!N){console.warn("Bundle product not supported on UI.");return}return Ce.includes(N)||console.warn(`Invalid swatch type ${N}`),r&&console.warn("Multiple selection swatches are not currently supported."),U("div",{id:`swatch-item-${_}`,"data-slot-key":`product-swatch--${_}`,className:"pdp-swatches__field",children:[n("div",{className:"pdp-swatches__field__label",children:a[_]?o?`${A}`:`${A}: ${a[_].label}`:A}),n(J,{id:_,type:N,required:D,items:M,label:A,selected:(S=a[_])==null?void 0:S.value})]},`swatch-item-${_}`)})})};function nt(e,o="en_US"){if(!Me(e))throw Error("Invalid date string");return e.split(" ")[1]||(e=`${e} 00:00:00`),new Date(e).toLocaleDateString(Ne(o)).toString()}function Me(e){if(![/^\d{4}-\d{2}-\d{2}$/,/^\d{1,2}\/\d{1,2}\/\d{4}$/,/^\d{2}\/\d{2}\/\d{4}$/,/^\d{4}\/\d{2}\/\d{2}$/,/^\d{1,2}\.\d{1,2}\.\d{4}$/,/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/].some(m=>m.test(e)))return!1;const u=new Date(e);return!isNaN(u.getTime())}function rt(e){const o=new URLSearchParams(window.location.search);Object.entries(e).forEach(([m,h])=>{h===null?o.delete(m):o.set(m,String(h))});let u=window.location.pathname;u+=`?${o.toString()}`,u+=window.location.hash,window.history.replaceState({},"",u)}function lt(){const e=new URLSearchParams(window.location.search),o={};return e.forEach((u,m)=>{o[m]=u}),o}function ct(e){var o,u,m,h,y,p,f,l,K,a,b,B;return{productId:Number(e==null?void 0:e.externalId),name:e==null?void 0:e.name,sku:e==null?void 0:e.sku,topLevelSku:e==null?void 0:e.externalParentId,specialToDate:void 0,specialFromDate:void 0,newToDate:void 0,newFromDate:void 0,createdAt:void 0,updatedAt:void 0,manufacturer:void 0,countryOfManufacture:void 0,categories:void 0,productType:void 0,pricing:{regularPrice:((u=(o=e==null?void 0:e.prices)==null?void 0:o.regular)==null?void 0:u.amount)||0,minimalPrice:(h=(m=e==null?void 0:e.prices)==null?void 0:m.final)==null?void 0:h.minimumAmount,maximalPrice:(p=(y=e==null?void 0:e.prices)==null?void 0:y.final)==null?void 0:p.maximumAmount,specialPrice:(l=(f=e==null?void 0:e.prices)==null?void 0:f.final)==null?void 0:l.amount,tierPricing:void 0,currencyCode:((a=(K=e==null?void 0:e.prices)==null?void 0:K.final)==null?void 0:a.currency)||"USD"},canonicalUrl:e==null?void 0:e.url,mainImageUrl:(B=(b=e==null?void 0:e.images)==null?void 0:b[0])==null?void 0:B.url}}const at={PRODUCT_CONTEXT:"productContext"},dt={PRODUCT_PAGE_VIEW:"product-page-view"};function Re(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function it(e,o){const u=Re();u.push({[e]:null}),u.push({[e]:o})}function ot(e,o){Re().push(m=>{const h=m.getState?m.getState():{};m.push({event:e,eventInfo:{...h,...o}})})}function Ee(e){const o=ct(e);it(at.PRODUCT_CONTEXT,o),ot(dt.PRODUCT_PAGE_VIEW)}const st=({sku:e,hideSku:o,hideQuantity:u,hideShortDescription:m,hideDescription:h,hideAttributes:y,hideURLParams:p,hideSelectedOptionValue:f,slots:l,children:K,initialData:a,carousel:b,optionsConfig:B,useACDL:q,onAddToCart:J,...N})=>{var I,T,Q,O;const A=V("PDP.Product.AddToCart.label").label,_=V("PDP.Product.Incrementer.label").label,r=V("PDP.Product.Details.label").label,[D,M]=X(Oe.getConfig().defaultLocale||"en-US"),[S,Y]=X(),[t=null,le]=X(a),[x,$]=X(()=>{const d={sku:e,quantity:1};return t!=null&&t.optionUIDs&&(d.optionsUIDs=t.optionUIDs),d}),[C,F]=X(()=>{var d,s;return!(t!=null&&t.options&&((d=t==null?void 0:t.options)==null?void 0:d.length)>0&&((s=t==null?void 0:t.optionUIDs)==null?void 0:s.length)!==(t==null?void 0:t.options.length))}),v={data:t,values:x,valid:C};ne(()=>{const d=ze.on("locale",s=>{s!==D&&(M(s),xe(e).then(le))});return()=>{d==null||d.off()}},[D,e]),ne(()=>{q&&a&&Object.keys(a).length>0&&Ee(a)},[a]);const oe=Z(d=>{$(s=>({...s,...d}))},[]),re=Z(d=>{var P;let s=Object.keys(d).map(w=>d[w].value).filter(w=>w!==void 0);p||rt({optionsUIDs:s.join(",")}),$(w=>({...w,optionsUIDs:s})),F((s==null?void 0:s.length)===((P=t==null?void 0:t.options)==null?void 0:P.length)),$e(e,s,B==null?void 0:B.anchorOptions).then(w=>{var E;le(w),(E=B==null?void 0:B.anchorOptions)!=null&&E.length&&ce(w,s),q&&(w==null?void 0:w.sku)!==e&&Ee(w)})},[e]),ce=Z((d,s)=>{var E;const P=(d==null?void 0:d.optionUIDs)??[];s.every(G=>P.includes(G))||(Y(d==null?void 0:d.options),$(G=>({...G,optionsUIDs:P})),F((P==null?void 0:P.length)===((E=d==null?void 0:d.options)==null?void 0:E.length)))},[e]),se=Z(d=>{Object.keys(d).length!==0&&F(!1)},[]),ee=we(()=>{var d;return(d=t==null?void 0:t.attributes)==null?void 0:d.map(({label:s,value:P},w)=>{const E=Me(P)?nt(P,D):P.toString();return U("li",{children:[s,": ",n("span",{dangerouslySetInnerHTML:{__html:E}})]},w)})},[t==null?void 0:t.attributes,D]),he=!u&&(t!=null&&t.inStock)?n(j,{name:"Quantity",slot:l==null?void 0:l.Quantity,context:{...v},children:n(je,{name:"quantity",defaultValue:x.quantity.toString(),min:1,"aria-label":_,className:"pdp-product__quantity",onValue:d=>{oe({quantity:Number(d)})}},"quantity")}):void 0,de=()=>{if(t!=null&&t.options)return n(j,{name:"Options",slot:l==null?void 0:l.Options,context:{...v},children:n(tt,{options:t.options,defaultOptions:x.optionsUIDs,selectionsToUpdate:S,hideSelectedValue:f,onValues:re,onErrors:se})})};return n("div",{...N,children:n(Ze,{title:n(j,{name:"Title",slot:l==null?void 0:l.Title,context:{...v},children:t==null?void 0:t.name}),sku:o?void 0:n(j,{name:"SKU",slot:l==null?void 0:l.SKU,context:{...v},children:t==null?void 0:t.sku}),options:de(),breadcrumbs:(l==null?void 0:l.Breadcrumbs)&&n(j,{name:"Breadcrumbs",slot:l==null?void 0:l.Breadcrumbs,context:{...v,setSeparator(d){this._registerMethod((...s)=>{const P=d(...s),w=P&&n(ve,{source:P});this._setProps(E=>({...E,separator:w}))})},appendLink(d){this._registerMethod((...s)=>{const{text:P,...w}=d(...s),E=n("a",{...w,children:P});this._setProps(G=>({...G,categories:[...G.categories||[],E]}))})},appendHTMLElement(d){this._registerMethod((...s)=>{const P=d(...s),w=this._htmlElementToVNode(P);this._setProps(E=>({...E,categories:[...E.categories||[],w]}))})}},render:({separator:d,categories:s})=>n(Ge,{separator:d,categories:s})}),quantity:he,actions:n(j,{name:"Actions",slot:l==null?void 0:l.Actions,context:{...v,appendButton(d){this._registerMethod((...s)=>{const P=d(...s);if(!P)return;const{text:w,icon:E,...G}=P,ue=n(Pe,{type:"button",...G,icon:E&&n(ve,{source:E}),children:w});this._setProps(_e=>({children:[..._e.children||[],ue]}))})}},children:!(l!=null&&l.Actions)&&n(Pe,{size:"medium",type:"submit",icon:n(ve,{source:"Cart"}),disabled:!(t!=null&&t.inStock)||!C,"aria-label":A,onClick:()=>J==null?void 0:J(x),children:A})}),shortDescription:m?void 0:n(j,{name:"ShortDescription",slot:l==null?void 0:l.ShortDescription,context:{...v},children:n("div",{dangerouslySetInnerHTML:{__html:(t==null?void 0:t.shortDescription)??""}})}),description:h?void 0:n(j,{name:"Description",slot:l==null?void 0:l.Description,context:{...v},children:n("div",{dangerouslySetInnerHTML:{__html:(t==null?void 0:t.description)??""}})}),images:((I=t==null?void 0:t.images)==null?void 0:I.map(({label:d,url:s})=>{var P,w;return n(De,{title:d,alt:d,src:s,width:((P=b==null?void 0:b.imageParams)==null?void 0:P.width)??960,height:((w=b==null?void 0:b.imageParams)==null?void 0:w.height)??1191,params:(b==null?void 0:b.imageParams)??{width:960}},s)}))??[],specialPrice:(T=t==null?void 0:t.prices)!=null&&T.visible?n(j,{name:"SpecialPrice",slot:l==null?void 0:l.SpecialPrice,context:{...v},children:n(Ie,{...t.prices.final,locale:Ne(D)})}):void 0,price:(Q=t==null?void 0:t.prices)!=null&&Q.visible&&t.prices.regular&&t.prices.final.amount!==(t==null?void 0:t.prices.regular.amount)?n(j,{name:"RegularPrice",slot:l==null?void 0:l.RegularPrice,context:{...v},children:n(Ie,{...t.prices.regular,locale:Ne(D)})}):void 0,carouselConfig:{...b,thumbnails:b&&Object.keys(b).length?((O=t==null?void 0:t.images)==null?void 0:O.map(({label:d,url:s})=>{var P,w;return n(De,{title:d,alt:d,src:s,width:((P=b==null?void 0:b.thumbnailParams)==null?void 0:P.width)??200,height:((w=b==null?void 0:b.thumbnailParams)==null?void 0:w.height)??248,params:(b==null?void 0:b.thumbnailParams)??{width:200}},s)}))??[]:[]},outOfStock:!(t!=null&&t.inStock),attributes:y?void 0:n(j,{name:"Attributes",slot:l==null?void 0:l.Attributes,context:{...v},children:ee!=null&&ee.length?U(fe,{children:[r,n("ul",{children:ee})]}):null}),galleryContent:(l==null?void 0:l.GalleryContent)&&n(j,{name:"GalleryContent",slot:l.GalleryContent,context:{...v}}),infoContent:(l==null?void 0:l.InfoContent)&&n(j,{name:"InfoContent",slot:l.InfoContent,context:{...v}}),productContent:(l==null?void 0:l.Content)&&n(j,{name:"Content",slot:l.Content,context:{...v}})})})};st.getInitialData=async function({sku:e,optionsConfig:o}){var m,h,y,p,f,l;const u=((m=lt().optionsUIDs)==null?void 0:m.split(","))||((l=(f=(p=(y=(h=Oe)==null?void 0:h.getConfig())==null?void 0:y.models)==null?void 0:p.ProductDetails)==null?void 0:f.initialData)==null?void 0:l.optionsUIDs);return u!=null&&u.length?await $e(e,u,o==null?void 0:o.anchorOptions):await xe(e)};export{st as ProductDetails,st as default};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-pdp", "version": "0.2.3-
|
|
1
|
+
{"name": "@dropins/storefront-pdp", "version": "0.2.3-beta2", "@dropins/tools": "0.25.0"}
|