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